Skip to content

Commit 277a65a

Browse files
committed
Check for namespaces in method dereferences
1 parent b167da6 commit 277a65a

File tree

4 files changed

+49
-26
lines changed

4 files changed

+49
-26
lines changed

Changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Version 7.6.1
2+
- Fixed looking up namespaced asm symbols from Spin code
3+
14
Version 7.6.0
25
- Added new Spin2_v52 keywords
36
- Added a warning for missing {Spin2_vXX} comment (very incomplete)

backends/asm/outasm.c

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,12 +4131,10 @@ doGetAddress(IRList *irl, AST *expr, bool isField)
41314131
{
41324132
Symbol *sym;
41334133
Operand *res = NULL;
4134-
const char *name;
41354134
Module *P;
41364135
int off;
41374136

4138-
name = GetUserIdentifierName(expr->right);
4139-
sym = LookupMemberSymbol(expr, ExprType(expr->left), name, &P, NULL);
4137+
sym = LookupMethodRef(expr, &P, NULL);
41404138
if (sym) {
41414139
if (sym->kind == SYM_VARIABLE) {
41424140
Operand *base = CompileExpression(irl, expr->left, NULL);
@@ -4153,6 +4151,7 @@ doGetAddress(IRList *irl, AST *expr, bool isField)
41534151
}
41544152
}
41554153
if (!res) {
4154+
const char *name = GetUserIdentifierName(expr->right);
41564155
ERROR(expr, "Internal error, cannot take address of %s", name);
41574156
res = OPERAND_DUMMY;
41584157
} else if (flags) {
@@ -4594,25 +4593,30 @@ CompileExpression(IRList *irl, AST *expr, Operand *dest)
45944593
int off = 0;
45954594
Module *P;
45964595
const char *name;
4596+
45974597
objtype = ExprType(expr->left);
4598-
if (curfunc && IsSpinLang(curfunc->language) && IsRefType(objtype)) {
4599-
objtype = objtype->left;
4600-
}
4601-
name = GetUserIdentifierName(expr->right);
4602-
if (!objtype) {
4603-
ERROR(expr, "%s is not accessible in this context", GetIdentifierName(expr->left));
4604-
return EmptyOperand();
4605-
} else if (!IsClassType(objtype)) {
4606-
ERROR(expr, "Request for member %s in something that is not a class", name);
4607-
return EmptyOperand();
4608-
}
4609-
if (expr->left && expr->left->kind == AST_OBJECT) {
4610-
// FIXME: we could potentially support calls of static class
4611-
// member functions, but for now, punt
4612-
ERROR(expr, "Use of class name in method references is not supported yet");
4613-
return EmptyOperand();
4598+
if (objtype) {
4599+
if (curfunc && IsSpinLang(curfunc->language) && IsRefType(objtype)) {
4600+
objtype = objtype->left;
4601+
}
4602+
name = GetUserIdentifierName(expr->right);
4603+
if (!objtype) {
4604+
ERROR(expr, "%s is not accessible in this context", GetIdentifierName(expr->left));
4605+
return EmptyOperand();
4606+
} else if (!IsClassType(objtype)) {
4607+
ERROR(expr, "Request for member %s in something that is not a class", name);
4608+
return EmptyOperand();
4609+
}
4610+
if (expr->left && expr->left->kind == AST_OBJECT) {
4611+
// FIXME: we could potentially support calls of static class
4612+
// member functions, but for now, punt
4613+
ERROR(expr, "Use of class name in method references is not supported yet");
4614+
return EmptyOperand();
4615+
}
4616+
sym = LookupMemberSymbol(expr, objtype, name, &P, NULL);
4617+
} else {
4618+
sym = LookupMethodRef(expr, &P, NULL);
46144619
}
4615-
sym = LookupMemberSymbol(expr, objtype, name, &P, NULL);
46164620
if (sym && sym->kind == SYM_FUNCTION) {
46174621
Function *pf = (Function *)sym->v.ptr;
46184622
if (pf->sym_funcptr) {
@@ -4629,7 +4633,11 @@ CompileExpression(IRList *irl, AST *expr, Operand *dest)
46294633
base = LabelRef(irl, sym);
46304634
break;
46314635
default:
4632-
ERROR(expr, "Unable to dereference symbol %s in %s", name, P->classname);
4636+
if (P) {
4637+
ERROR(expr, "Unable to dereference symbol %s in %s", name, P->classname);
4638+
} else {
4639+
ERROR(expr, "Unable to dereference symbol %s", name);
4640+
}
46334641
return EmptyOperand();
46344642
}
46354643
}

backends/bytecode/outbc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//
22
// Bytecode compiler for spin2cpp
33
//
4-
// Copyright 2021-2023 Ada Gottensträter and Total Spectrum Software Inc.
4+
// Copyright 2021-2025 Ada Gottensträter, Total Spectrum Software Inc.,
5+
// and contributors
56
// see the file COPYING for conditions of redistribution
67
//
78

@@ -487,6 +488,12 @@ BCCompileMemOpExEx(BCIRBuffer *irbuf,AST *node,BCContext context, enum MemOpKind
487488
AST *selector = node->right;
488489
Module *P = GetClassPtr(ExprType(node->left));
489490
if (!P) {
491+
// check for a namespace reference
492+
sym = LookupMethodRef(node, NULL, NULL);
493+
if (sym) {
494+
ident = node->right;
495+
goto found_symbol;
496+
}
490497
ERROR(node,"Unable to find object");
491498
return;
492499
}
@@ -640,6 +647,7 @@ BCCompileMemOpExEx(BCIRBuffer *irbuf,AST *node,BCContext context, enum MemOpKind
640647
goto after_typeinfer;
641648
}
642649

650+
found_symbol:
643651
if (!sym) {
644652
if (node->kind == AST_ARRAYREF && indexExpr && !baseExpr) {
645653
memOp.attr.memop.base = MEMOP_BASE_POP;

backends/nucode/outnu.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,15 @@ static NuIrOpcode NuCompileLhsAddress(NuIrList *irl, AST *lhs)
750750
return op;
751751
}
752752
const char *memberName = GetUserIdentifierName(methodname);
753-
if ( !IsClassType(typ) || NULL == (P=GetClassPtr(typ)) ) {
754-
ERROR(lhs, "Request for member %s in something not an object", memberName);
755-
return op;
753+
if (typ) {
754+
if ( !IsClassType(typ) || NULL == (P=GetClassPtr(typ)) ) {
755+
ERROR(lhs, "Request for member %s in something not an object", memberName);
756+
return op;
757+
}
758+
sym = LookupSymbolInTable(&P->objsyms, memberName);
759+
} else {
760+
sym = LookupMethodRef(lhs, NULL, NULL);
756761
}
757-
sym = LookupSymbolInTable(&P->objsyms, memberName);
758762
if (!sym) {
759763
ERROR(lhs, "unknown symbol %s", memberName);
760764
return op;

0 commit comments

Comments
 (0)