Skip to content

Commit 0c5ef6e

Browse files
committed
fix lookup of labels in DAT namespaces
1 parent 97608ac commit 0c5ef6e

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

expr.c

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,22 @@ LookupMemberSymbol(AST *expr, AST *objtype, const char *name, Module **Ptr, int
333333
return sym;
334334
}
335335

336+
/*
337+
* get a namespace symbol table, or NULL if the
338+
* name is not a namespace
339+
*/
340+
SymbolTable *
341+
LookupNamespace(AST *expr)
342+
{
343+
Symbol *sym;
344+
if (!IsIdentifier(expr))
345+
return NULL;
346+
sym = LookupSymbol(GetUserIdentifierName(expr));
347+
if (!sym || sym->kind != SYM_NAMESPACE)
348+
return NULL;
349+
return (SymbolTable *)sym->v.ptr;
350+
}
351+
336352
/*
337353
* look up a symbol from a method reference
338354
* "expr" is the pointer to the method ref
@@ -347,6 +363,12 @@ LookupMethodRef(AST *expr, Module **Ptr, int *valid)
347363
const char *name;
348364

349365
name = GetUserIdentifierName(ident);
366+
if (!type) {
367+
SymbolTable *nametable = LookupNamespace(expr->left);
368+
if (nametable) {
369+
return LookupSymbolInTable(nametable, name);
370+
}
371+
}
350372
return LookupMemberSymbol(expr, type, name, Ptr, valid);
351373

352374
}
@@ -1803,22 +1825,35 @@ EvalExpr(AST *expr, unsigned flags, int *valid, int depth)
18031825
case AST_CONSTREF:
18041826
case AST_METHODREF:
18051827
{
1806-
Module *P;
1828+
Module *P = current;
18071829

18081830
sym = LookupMethodRef(expr, &P, valid);
18091831
if (!sym) {
18101832
return intExpr(0);
18111833
}
1812-
#if 0
1813-
if ((sym->kind != SYM_CONSTANT && sym->kind != SYM_FLOAT_CONSTANT)) {
1814-
if (valid) {
1815-
*valid = 0;
1816-
} else {
1817-
ERROR(expr, "%s is not a constant of %s", GetIdentifierName(expr->right), P->classname);
1834+
switch (sym->kind) {
1835+
case SYM_LABEL:
1836+
/* got a label in a namespace */
1837+
if (flags & PASM_FLAG) {
1838+
Label *lref = (Label *)sym->v.ptr;
1839+
if (lref->flags & LABEL_IN_HUB) {
1840+
return intExpr(lref->hubval);
1841+
}
1842+
if (lref->cogval & 0x03) {
1843+
if (reportError) {
1844+
ERROR(expr, "label %s in COG memory not on longword boundary", sym->user_name);
1845+
} else {
1846+
*valid = 0;
1847+
}
1848+
return intExpr(0);
1849+
}
1850+
return intExpr(lref->cogval >> 2);
18181851
}
1819-
return intExpr(0);
1852+
break;
1853+
default:
1854+
break;
18201855
}
1821-
#endif
1856+
18221857
/* while we're evaluating, use the object context */
18231858
ret = EvalExprInState(P, expr->right, flags, valid, depth+1);
18241859
return ret;

0 commit comments

Comments
 (0)