mirror of https://github.com/lua/lua
'nextvar' now traverses the symbol array, instead of the constant tree.
This commit is contained in:
parent
970995c3f2
commit
15f40fddca
42
tree.c
42
tree.c
|
@ -3,7 +3,7 @@
|
||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_tree="$Id: tree.c,v 1.12 1994/12/20 21:20:36 roberto Exp roberto $";
|
char *rcs_tree="$Id: tree.c,v 1.13 1995/01/12 14:19:04 roberto Exp roberto $";
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -102,40 +102,22 @@ Long lua_strcollector (void)
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Return next variable.
|
** Traverse the constant tree looking for a specific symbol number
|
||||||
*/
|
*/
|
||||||
static TreeNode *tree_next (TreeNode *node, char *str)
|
static TreeNode *nodebysymbol (TreeNode *root, Word symbol)
|
||||||
{
|
{
|
||||||
if (node == NULL) return NULL;
|
TreeNode *t;
|
||||||
else if (str == NULL) return node;
|
if (root == NULL) return NULL;
|
||||||
else
|
if (root->varindex == symbol) return root;
|
||||||
{
|
t = nodebysymbol(root->left, symbol);
|
||||||
int c = lua_strcmp(str, node->ts.str);
|
if (t) return t;
|
||||||
if (c == 0)
|
return nodebysymbol(root->right, symbol);
|
||||||
return node->left != NULL ? node->left : node->right;
|
|
||||||
else if (c < 0)
|
|
||||||
{
|
|
||||||
TreeNode *result = tree_next(node->left, str);
|
|
||||||
return result != NULL ? result : node->right;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return tree_next(node->right, str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeNode *lua_varnext (char *n)
|
TreeNode *luaI_nodebysymbol (Word symbol)
|
||||||
{
|
{
|
||||||
TreeNode *result;
|
return nodebysymbol(constant_root, symbol);
|
||||||
char *name = n;
|
|
||||||
while (1)
|
|
||||||
{ /* repeat until a valid (non nil) variable */
|
|
||||||
result = tree_next(constant_root, name);
|
|
||||||
if (result == NULL) return NULL;
|
|
||||||
if (result->varindex != NOT_USED &&
|
|
||||||
s_tag(result->varindex) != LUA_T_NIL)
|
|
||||||
return result;
|
|
||||||
name = result->ts.str;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
tree.h
4
tree.h
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
** tree.h
|
** tree.h
|
||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
** $Id: tree.h,v 1.8 1994/12/20 21:20:36 roberto Exp roberto $
|
** $Id: tree.h,v 1.9 1995/01/12 14:19:04 roberto Exp roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef tree_h
|
#ifndef tree_h
|
||||||
|
@ -32,6 +32,6 @@ typedef struct TreeNode
|
||||||
TaggedString *lua_createstring (char *str);
|
TaggedString *lua_createstring (char *str);
|
||||||
TreeNode *lua_constcreate (char *str);
|
TreeNode *lua_constcreate (char *str);
|
||||||
Long lua_strcollector (void);
|
Long lua_strcollector (void);
|
||||||
TreeNode *lua_varnext (char *n);
|
TreeNode *luaI_nodebysymbol (Word symbol);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue