Make forward declarations of external symbols really work.
Until now we had always been treating external variables as "int", and external functions as int (...);
This commit is contained in:
parent
7ecc5556ae
commit
37c54bd22e
|
@ -2610,7 +2610,7 @@ class Compiler : public ErrorSink {
|
|||
}
|
||||
|
||||
virtual void convertR0(Type* pType){
|
||||
fprintf(stderr, "convertR0(pType)\n");
|
||||
fprintf(stderr, "convertR0(pType tag=%d)\n", pType->tag);
|
||||
mpBase->convertR0(pType);
|
||||
}
|
||||
|
||||
|
@ -3672,7 +3672,7 @@ class Compiler : public ErrorSink {
|
|||
#if 0
|
||||
{
|
||||
String buf;
|
||||
decodeToken(buf, tok);
|
||||
decodeToken(buf, tok, true);
|
||||
fprintf(stderr, "%s\n", buf.getUnwrapped());
|
||||
}
|
||||
#endif
|
||||
|
@ -3883,10 +3883,12 @@ class Compiler : public ErrorSink {
|
|||
/* forward reference: try dlsym */
|
||||
if (!n) {
|
||||
n = (intptr_t) dlsym(RTLD_DEFAULT, nameof(t));
|
||||
if (tok == '(') {
|
||||
pVI->pType = mkpIntFn;
|
||||
} else {
|
||||
pVI->pType = mkpInt;
|
||||
if (pVI->pType == NULL) {
|
||||
if (tok == '(') {
|
||||
pVI->pType = mkpIntFn;
|
||||
} else {
|
||||
pVI->pType = mkpInt;
|
||||
}
|
||||
}
|
||||
pVI->pAddress = (void*) n;
|
||||
}
|
||||
|
@ -4156,7 +4158,7 @@ class Compiler : public ErrorSink {
|
|||
|
||||
String temp;
|
||||
if (pType->id != 0) {
|
||||
decodeToken(temp, pType->id);
|
||||
decodeToken(temp, pType->id, false);
|
||||
buffer.append(temp);
|
||||
}
|
||||
|
||||
|
@ -4166,7 +4168,7 @@ class Compiler : public ErrorSink {
|
|||
void decodeTypeImpPrefix(String& buffer, Type* pType) {
|
||||
TypeTag tag = pType->tag;
|
||||
|
||||
if (tag >= TY_INT && tag <= TY_VOID) {
|
||||
if (tag >= TY_INT && tag <= TY_DOUBLE) {
|
||||
switch (tag) {
|
||||
case TY_INT:
|
||||
buffer.appendCStr("int");
|
||||
|
@ -4343,7 +4345,7 @@ class Compiler : public ErrorSink {
|
|||
error("Symbol %s not allowed here", nameof(declName));
|
||||
} else if (nameRequired && ! declName) {
|
||||
String temp;
|
||||
decodeToken(temp, tok);
|
||||
decodeToken(temp, tok, true);
|
||||
error("Expected symbol. Got %s", temp.getUnwrapped());
|
||||
}
|
||||
}
|
||||
|
@ -4395,7 +4397,7 @@ class Compiler : public ErrorSink {
|
|||
Type* pType = acceptPrimitiveType(arena);
|
||||
if (!pType) {
|
||||
String buf;
|
||||
decodeToken(buf, tok);
|
||||
decodeToken(buf, tok, true);
|
||||
error("Expected a type, got %s", buf.getUnwrapped());
|
||||
}
|
||||
return pType;
|
||||
|
@ -4455,7 +4457,7 @@ class Compiler : public ErrorSink {
|
|||
return checkSymbol(tok);
|
||||
}
|
||||
|
||||
void decodeToken(String& buffer, tokenid_t token) {
|
||||
void decodeToken(String& buffer, tokenid_t token, bool quote) {
|
||||
if (token == EOF ) {
|
||||
buffer.printf("EOF");
|
||||
} else if (token == TOK_NUM) {
|
||||
|
@ -4466,10 +4468,16 @@ class Compiler : public ErrorSink {
|
|||
} else {
|
||||
buffer.printf("'%c'", token);
|
||||
}
|
||||
} else if (token >= TOK_KEYWORD && token < TOK_SYMBOL) {
|
||||
buffer.printf("keyword \"%s\"", nameof(token));
|
||||
} else {
|
||||
buffer.printf("symbol \"%s\"", nameof(token));
|
||||
if (quote) {
|
||||
if (token >= TOK_KEYWORD && token < TOK_SYMBOL) {
|
||||
buffer.printf("keyword \"%s\"", nameof(token));
|
||||
} else {
|
||||
buffer.printf("symbol \"%s\"", nameof(token));
|
||||
}
|
||||
} else {
|
||||
buffer.printf("%s", nameof(token));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4477,7 +4485,7 @@ class Compiler : public ErrorSink {
|
|||
bool result = token >= TOK_SYMBOL;
|
||||
if (!result) {
|
||||
String temp;
|
||||
decodeToken(temp, token);
|
||||
decodeToken(temp, token, true);
|
||||
error("Expected symbol. Got %s", temp.getUnwrapped());
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
float fabsf(float);
|
||||
|
||||
int main(void* con, int ft, int launchID)
|
||||
{
|
||||
float f = fabsf(-10.0f);
|
||||
return f;
|
||||
}
|
||||
|
|
@ -262,6 +262,10 @@ Pointer addition: 2
|
|||
Pointer comparison to zero: 0 0 1
|
||||
Pointer comparison: 1 0 0 0 1
|
||||
""")
|
||||
def testRollo3(self):
|
||||
self.compileCheck(["-R", "data/rollo3.c"], """Executing compiled code:
|
||||
result: 10""", """""")
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue