aboutsummaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c42
1 files changed, 12 insertions, 30 deletions
diff --git a/tree.c b/tree.c
index c34b0560..4710ac44 100644
--- a/tree.c
+++ b/tree.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_tree="$Id: tree.c,v 1.12 1994/12/20 21:20:36 roberto Exp roberto $"; 6char *rcs_tree="$Id: tree.c,v 1.13 1995/01/12 14:19:04 roberto Exp roberto $";
7 7
8 8
9#include <string.h> 9#include <string.h>
@@ -102,40 +102,22 @@ Long lua_strcollector (void)
102 return counter; 102 return counter;
103} 103}
104 104
105
105/* 106/*
106** Return next variable. 107** Traverse the constant tree looking for a specific symbol number
107*/ 108*/
108static TreeNode *tree_next (TreeNode *node, char *str) 109static TreeNode *nodebysymbol (TreeNode *root, Word symbol)
109{ 110{
110 if (node == NULL) return NULL; 111 TreeNode *t;
111 else if (str == NULL) return node; 112 if (root == NULL) return NULL;
112 else 113 if (root->varindex == symbol) return root;
113 { 114 t = nodebysymbol(root->left, symbol);
114 int c = lua_strcmp(str, node->ts.str); 115 if (t) return t;
115 if (c == 0) 116 return nodebysymbol(root->right, symbol);
116 return node->left != NULL ? node->left : node->right;
117 else if (c < 0)
118 {
119 TreeNode *result = tree_next(node->left, str);
120 return result != NULL ? result : node->right;
121 }
122 else
123 return tree_next(node->right, str);
124 }
125} 117}
126 118
127TreeNode *lua_varnext (char *n) 119TreeNode *luaI_nodebysymbol (Word symbol)
128{ 120{
129 TreeNode *result; 121 return nodebysymbol(constant_root, symbol);
130 char *name = n;
131 while (1)
132 { /* repeat until a valid (non nil) variable */
133 result = tree_next(constant_root, name);
134 if (result == NULL) return NULL;
135 if (result->varindex != NOT_USED &&
136 s_tag(result->varindex) != LUA_T_NIL)
137 return result;
138 name = result->ts.str;
139 }
140} 122}
141 123