compiler/libec: Fixed allowing headers to redefine uint typedef (#60)
authorJerome St-Louis <jerome@ecere.com>
Sun, 10 Mar 2013 04:16:17 +0000 (23:16 -0500)
committerJerome St-Louis <jerome@ecere.com>
Sun, 10 Mar 2013 04:16:17 +0000 (23:16 -0500)
- Solves the deadend from now auto-including sys/types.h to get (s)size_t

compiler/bootstrap/libec/bootstrap/output.c
compiler/libec/src/output.ec

index eacb0e8..5630b37 100644 (file)
@@ -1225,7 +1225,7 @@ break;
 }
 }
 
-static void OutputSpecifier(struct Specifier * spec, struct __ecereNameSpace__ecere__com__Instance * f);
+static void OutputSpecifier(struct Specifier * spec, struct __ecereNameSpace__ecere__com__Instance * f, unsigned int typeName);
 
 static void OutputDeclarator(struct Declarator * decl, struct __ecereNameSpace__ecere__com__Instance * f);
 
@@ -1237,7 +1237,7 @@ struct Specifier * spec;
 
 for(spec = (*type->qualifiers).first; spec; spec = spec->next)
 {
-OutputSpecifier(spec, f);
+OutputSpecifier(spec, f, 0x0);
 if(spec->next)
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " ");
 }
@@ -1271,7 +1271,7 @@ struct Specifier * spec;
 
 for(spec = (*exp->_classExp.specifiers).first; spec; spec = spec->next)
 {
-OutputSpecifier(spec, f);
+OutputSpecifier(spec, f, 0x0);
 if(spec->next)
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " ");
 }
@@ -1847,7 +1847,7 @@ struct AsmField * field;
 
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, "__asm__ ");
 if(stmt->asmStmt.spec)
-OutputSpecifier(stmt->asmStmt.spec, f);
+OutputSpecifier(stmt->asmStmt.spec, f, 0x0);
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, "(");
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, stmt->asmStmt.statements);
 if(stmt->asmStmt.inputFields || stmt->asmStmt.outputFields || stmt->asmStmt.clobberedFields)
@@ -1907,7 +1907,7 @@ struct Specifier * spec;
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " ");
 for(spec = (*ptr->qualifiers).first; spec; spec = spec->next)
 {
-OutputSpecifier(spec, f);
+OutputSpecifier(spec, f, 0x0);
 if(spec->next)
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " ");
 }
@@ -2086,7 +2086,7 @@ extern struct Symbol * FindClass(char *  name);
 
 static void OutputClassDef(struct ClassDef * def, struct __ecereNameSpace__ecere__com__Instance * f);
 
-static void OutputSpecifier(struct Specifier * spec, struct __ecereNameSpace__ecere__com__Instance * f)
+static void OutputSpecifier(struct Specifier * spec, struct __ecereNameSpace__ecere__com__Instance * f, unsigned int typeName)
 {
 switch(spec->type)
 {
@@ -2127,10 +2127,10 @@ case INT:
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, "int");
 break;
 case UINT:
-((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, "unsigned int");
+((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, typeName ? "uint" : "unsigned int");
 break;
 case INT64:
-((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, "long long");
+((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, typeName ? "int64" : "long long");
 break;
 case VALIST:
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, "__builtin_va_list");
@@ -2247,7 +2247,7 @@ OutputExpression(spec->expression, f);
 break;
 case 7:
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, "subclass(");
-OutputSpecifier(spec->_class, f);
+OutputSpecifier(spec->_class, f, 0x0);
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, ")");
 break;
 case 8:
@@ -2362,9 +2362,13 @@ break;
 }
 if(decl->specifiers)
 {
+unsigned int inTypeDef = 0x0;
+
 for(spec = (*decl->specifiers).first; spec; spec = spec->next)
 {
-OutputSpecifier(spec, f);
+if(spec->type == 0 && spec->specifier == TYPEDEF)
+inTypeDef = 0x1;
+OutputSpecifier(spec, f, inTypeDef && !spec->next);
 if(spec->next)
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " ");
 }
@@ -2387,7 +2391,7 @@ if(decl->specifiers)
 {
 for(spec = (*decl->specifiers).first; spec; spec = spec->next)
 {
-OutputSpecifier(spec, f);
+OutputSpecifier(spec, f, 0x0);
 if(spec->next)
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " ");
 }
@@ -2407,7 +2411,7 @@ if(d->next)
 if(decl->extStorage)
 {
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " ");
-OutputSpecifier(decl->extStorage, f);
+OutputSpecifier(decl->extStorage, f, 0x0);
 }
 break;
 }
@@ -2444,7 +2448,7 @@ struct Specifier * spec;
 
 for(spec = (*func->specifiers).first; spec; spec = spec->next)
 {
-OutputSpecifier(spec, f);
+OutputSpecifier(spec, f, 0x0);
 if(spec->next)
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " ");
 }
@@ -2551,7 +2555,7 @@ break;
 static void OutputInstance(struct Instantiation * inst, struct __ecereNameSpace__ecere__com__Instance * f)
 {
 if(inst->_class)
-OutputSpecifier(inst->_class, f);
+OutputSpecifier(inst->_class, f, 0x0);
 if(inst->exp)
 {
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " ");
@@ -2594,7 +2598,7 @@ struct Specifier * spec;
 
 for(spec = (*func->specifiers).first; spec; spec = spec->next)
 {
-OutputSpecifier(spec, f);
+OutputSpecifier(spec, f, 0x0);
 if(spec->next)
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " ");
 }
@@ -2665,7 +2669,7 @@ break;
 static void OutputClass(struct ClassDefinition * _class, struct __ecereNameSpace__ecere__com__Instance * f)
 {
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, "class ");
-OutputSpecifier(_class->_class, f);
+OutputSpecifier(_class->_class, f, 0x0);
 if(_class->baseSpecs)
 {
 struct Specifier * spec;
@@ -2673,7 +2677,7 @@ struct Specifier * spec;
 ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char *  string))f->_vTbl[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts])(f, " : ");
 for(spec = (*_class->baseSpecs).first; spec; spec = spec->next)
 {
-OutputSpecifier(spec, f);
+OutputSpecifier(spec, f, 0x0);
 }
 }
 if(_class->definitions)
index b990c60..23f4e9f 100644 (file)
@@ -87,7 +87,7 @@ public void OutputTypeName(TypeName type, File f)
       Specifier spec;
       for(spec = type.qualifiers->first; spec; spec = spec.next)
       {
-         OutputSpecifier(spec, f);
+         OutputSpecifier(spec, f, false);
          if(spec.next) f.Puts(" ");
       }
    }
@@ -113,7 +113,7 @@ public void OutputExpression(Expression exp, File f)
             Specifier spec;
             for(spec = exp._classExp.specifiers->first; spec; spec = spec.next)
             {
-               OutputSpecifier(spec, f);
+               OutputSpecifier(spec, f, false);
                if(spec.next) f.Puts(" ");
             }
             if(exp._classExp.decl) 
@@ -646,7 +646,7 @@ static void OutputStatement(Statement stmt, File f)
          AsmField field;
          f.Puts("__asm__ ");
          if(stmt.asmStmt.spec)
-            OutputSpecifier(stmt.asmStmt.spec, f);
+            OutputSpecifier(stmt.asmStmt.spec, f, false);
          f.Puts("(");
          f.Puts(stmt.asmStmt.statements);
 
@@ -704,7 +704,7 @@ static void OutputPointer(Pointer ptr, File f)
       f.Puts(" ");
       for(spec = ptr.qualifiers->first; spec; spec = spec.next)
       {
-         OutputSpecifier(spec, f);
+         OutputSpecifier(spec, f, false);
          if(spec.next) f.Puts(" ");
       }
    }
@@ -862,7 +862,7 @@ static void OutputExtDecl(ExtDecl extDecl, File f)
       OutputAttrib(extDecl.attr, f);
 }
 
-static void OutputSpecifier(Specifier spec, File f)
+static void OutputSpecifier(Specifier spec, File f, bool typeName)
 {
    switch(spec.type)
    {
@@ -908,12 +908,12 @@ static void OutputSpecifier(Specifier spec, File f)
                f.Puts("int");
                break;
             case UINT:
-               f.Puts("unsigned int");
+               f.Puts(typeName ? "uint" : "unsigned int");
                break;
             case INT64:
                //f.Puts("__int64");
                //f.Puts("int64");
-               f.Puts("long long");
+               f.Puts(typeName ? "int64" : "long long");
                break;
             case VALIST:
                f.Puts("__builtin_va_list");
@@ -1029,7 +1029,7 @@ static void OutputSpecifier(Specifier spec, File f)
          break;
       case subClassSpecifier:
          f.Puts("subclass(");
-         OutputSpecifier(spec._class, f);
+         OutputSpecifier(spec._class, f, false);
          f.Puts(")");                  
          break;
       case templateTypeSpecifier:
@@ -1175,9 +1175,12 @@ static void OutputDeclaration(Declaration decl, File f)
 
          if(decl.specifiers)
          {
+            bool inTypeDef = false;
             for(spec = decl.specifiers->first; spec; spec = spec.next)
             {
-               OutputSpecifier(spec, f);
+               if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
+                  inTypeDef = true;
+               OutputSpecifier(spec, f, inTypeDef && !spec.next);
                if(spec.next) f.Puts(" ");
             }
          }
@@ -1199,7 +1202,7 @@ static void OutputDeclaration(Declaration decl, File f)
          {
             for(spec = decl.specifiers->first; spec; spec = spec.next)
             {
-               OutputSpecifier(spec, f);
+               OutputSpecifier(spec, f, false);
                if(spec.next) f.Puts(" ");
             }
          }
@@ -1217,7 +1220,7 @@ static void OutputDeclaration(Declaration decl, File f)
          if(decl.extStorage)
          {
             f.Puts(" ");
-            OutputSpecifier(decl.extStorage, f);
+            OutputSpecifier(decl.extStorage, f, false);
          }
          break;
       }
@@ -1250,7 +1253,7 @@ static void OutputFunction(FunctionDefinition func, File f)
       Specifier spec;
       for(spec = func.specifiers->first; spec; spec = spec.next)
       {
-         OutputSpecifier(spec, f);
+         OutputSpecifier(spec, f, false);
          if(spec.next) f.Puts(" ");
       }
       f.Puts(" ");
@@ -1354,7 +1357,7 @@ static void OutputMembersInit(MembersInit init, File f)
 static void OutputInstance(Instantiation inst, File f)
 {
    if(inst._class)
-      OutputSpecifier(inst._class, f);
+      OutputSpecifier(inst._class, f, false);
    if(inst.exp)
    {
       f.Puts(" ");
@@ -1395,7 +1398,7 @@ static void OutputClassFunction(ClassFunction func, File f)
       Specifier spec;
       for(spec = func.specifiers->first; spec; spec = spec.next)
       {
-         OutputSpecifier(spec, f);
+         OutputSpecifier(spec, f, false);
          if(spec.next) f.Puts(" ");
       }
       f.Puts(" ");
@@ -1404,7 +1407,7 @@ static void OutputClassFunction(ClassFunction func, File f)
    {
       //if(func.class != (void *)-1)
       if(func.class)
-         OutputSpecifier(func.class, f);
+         OutputSpecifier(func.class, f, false);
       f.Puts("::");
    }*/
    if(func.declarator) OutputDeclarator(func.declarator, f);
@@ -1468,7 +1471,7 @@ static void OutputClassDef(ClassDef def, File f)
 static void OutputClass(ClassDefinition _class, File f)
 {
    f.Puts("class ");
-   OutputSpecifier(_class._class, f);
+   OutputSpecifier(_class._class, f, false);
    if(_class.baseSpecs)
    {
       Specifier spec;
@@ -1476,7 +1479,7 @@ static void OutputClass(ClassDefinition _class, File f)
       f.Puts(" : ");
       for(spec = _class.baseSpecs->first; spec; spec = spec.next)
       {
-         OutputSpecifier(spec, f);
+         OutputSpecifier(spec, f, false);
       }
    }
    if(_class.definitions)