Skip to content

Commit d646087

Browse files
committed
removed some duplicate code
1 parent 56e394d commit d646087

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

frontends/common.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,25 +2084,22 @@ DeclareOneMemberVar(Module *P, AST *ident, AST *type, int is_private)
20842084
return r;
20852085
}
20862086

2087+
//
2088+
// check to see if an identifier is already declared
2089+
// if it is, return the typ of it
2090+
// slightly different from FindDeclaration, which returns
2091+
// the declaration itself
2092+
//
20872093
static AST *
20882094
AlreadyDeclared(AST *pendinglist, AST *newIdentifier)
20892095
{
2090-
AST *entry;
2091-
AST *ident;
2092-
AST *typ;
2093-
while (pendinglist) {
2094-
entry = pendinglist->left;
2095-
pendinglist = pendinglist->right;
2096-
if (entry && entry->kind == AST_DECLARE_VAR) {
2097-
ident = entry->right;
2098-
if (AstUses(ident, newIdentifier)) {
2099-
typ = entry->left;
2100-
if (typ == NULL) {
2101-
typ = ast_type_generic;
2102-
}
2103-
return typ;
2104-
}
2105-
}
2096+
const char *name = GetIdentifierName(newIdentifier);
2097+
AST *decl = FindDeclaration(pendinglist, name);
2098+
if (!decl) return decl;
2099+
if (decl && decl->kind == AST_DECLARE_VAR) {
2100+
AST *typ = decl->left;
2101+
if (!typ) typ = ast_type_generic;
2102+
return typ;
21062103
}
21072104
return NULL;
21082105
}

0 commit comments

Comments
 (0)