compiler/libec Improvements to conversion from AST->Type class, and to outputting... typeImprovements
authorJerome St-Louis <jerome@ecere.com>
Tue, 9 Apr 2013 06:23:13 +0000 (02:23 -0400)
committerJerome St-Louis <jerome@ecere.com>
Tue, 9 Apr 2013 06:23:13 +0000 (02:23 -0400)
compiler/ecc/ecc.ec
compiler/libec/src/ast.ec
compiler/libec/src/pass15.ec
compiler/libec/src/shortcuts.ec

index ecbbada..0dfdc21 100644 (file)
@@ -115,6 +115,93 @@ static void OutputImports(char * fileName)
    delete f;
 }
 
+bool TestType(String string, String expected)
+{
+   bool result = true;
+   char typeString[1024] = { 0 };
+   Type type = ProcessTypeString(string, false);
+   PrintType(type, typeString, true, true);
+   if(strcmp(typeString, expected ? expected : string))
+   {
+      PrintLn("FAILED: ", string, " -> ", typeString);
+      result = false;
+   }
+   return result;
+}
+
+void TestTypes()
+{
+   int succeeded = 0, count = 0;
+   
+   //count++, succeeded += TestType("int (* f[8])[10]", null);
+   count++, succeeded += TestType("void (* signal(int, void (*)(int)))(int)", null);
+   count++, succeeded += TestType("void (* signal(double))()", null);
+   count++, succeeded += TestType("void (* bla)(int)", null);
+   count++, succeeded += TestType("int f(void (*[10])())", null);
+   count++, succeeded += TestType("void (*[10])()", null);
+   count++, succeeded += TestType("void (* converters_table[10])()", null);
+   count++, succeeded += TestType("int (* f[8])[10]", null);
+   
+   count++, succeeded += TestType("int f[8][10]", null);
+   count++, succeeded += TestType("int f[10]", null);
+   count++, succeeded += TestType("void *", null);
+   count++, succeeded += TestType("char * x", "char * x");
+   count++, succeeded += TestType("char * x", null);
+   count++, succeeded += TestType("char (* x[3])()", null);
+   count++, succeeded += TestType("char (*(* x[3])())", "char * (* x[3])()");
+   count++, succeeded += TestType("char (* x())", "char * x()");
+   count++, succeeded += TestType("char (* (* x[3])())[5]", null);
+   count++, succeeded += TestType("char (* f())[5]", null);
+   count++, succeeded += TestType("char * (* f())[5]", null);
+   count++, succeeded += TestType("char * (* * f())[5][2][3]", null);
+   count++, succeeded += TestType("char * (* * (* f)())[5][2][3]", null);
+   count++, succeeded += TestType("char * (* (* * (* f)())[5][2])[3]", null);
+   count++, succeeded += TestType("void (* (* bar)[5])()", null);
+   count++, succeeded += TestType("const int * (* const f)(char[10])", null);
+   count++, succeeded += TestType("const int", null);
+   count++, succeeded += TestType("int * const *", null);
+   count++, succeeded += TestType("int * const", null);
+   count++, succeeded += TestType("const int *", null);
+   
+   count++, succeeded += TestType("char * const (* (* const bar)[5])(int)", null);
+   count++, succeeded += TestType("char * const (* (* (* const bar)[5][6])(int))[2]", null);
+   count++, succeeded += TestType("int * * a", null);
+
+   count++, succeeded += TestType("char * const (* bar)()", null);
+
+   count++, succeeded += TestType("char * const (* const (* const bar)[5])(int)", null);
+   
+   count++, succeeded += TestType("char * (* const (* bar)[5])(int)", null);
+   count++, succeeded += TestType("void (* * const bar[5])()", null);
+   count++, succeeded += TestType("void (* * const bar)()", null);
+   count++, succeeded += TestType("void (* const * bar)()", null);
+   count++, succeeded += TestType("const int * * foo", null); // this prevents you from doing: **foo = 0;
+   count++, succeeded += TestType("int * const * bar", null); // this prevents you from doing: *bar = 0;
+   count++, succeeded += TestType("int * * const two", null); // this prevents you from doing: two = 0;
+
+   count++, succeeded += TestType("dllexport int TestFunction()", null); // this prevents you from doing: two = 0;
+   count++, succeeded += TestType("any_object TestFunction(any_object, typed_object & param)", null); // this prevents you from doing: two = 0;
+
+   count++, succeeded += TestType("void typed_object::OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags)", null);
+   count++, succeeded += TestType("int typed_object::OnCompare(any_object object)", null);
+   count++, succeeded += TestType("void typed_object&::OnCopy(any_object newData)", null);
+   count++, succeeded += TestType("void typed_object::OnFree(void)", null);
+   count++, succeeded += TestType("char * typed_object::OnGetString(char * tempString, void * fieldData, bool * needClass)", null);
+   count++, succeeded += TestType("bool typed_object&::OnGetDataFromString(char * string)", null);
+   count++, succeeded += TestType("Window typed_object::OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)", null);
+   count++, succeeded += TestType("void typed_object::OnSerialize(IOChannel channel)", null);
+   count++, succeeded += TestType("void typed_object&::OnUnserialize(IOChannel channel)", null);
+   count++, succeeded += TestType("bool typed_object&::OnSaveEdit(Window window, void * object)", null);
+
+   count++, succeeded += TestType("void PrintLn(typed_object object, ...)", null);
+   count++, succeeded += TestType("void PrintLn(typed_object object, ...)", null);
+   count++, succeeded += TestType("thisclass RemoveSwapRight()", null);
+   count++, succeeded += TestType("LinkElement<thisclass> link", null);
+   count++, succeeded += TestType("struct { thisclass prev; thisclass next; }", null);
+
+   PrintLn("\n", succeeded, " / ", count, " tests succeeded.");
+}
+
 class CompilerApp : Application
 {
    void Main()
@@ -329,6 +416,10 @@ class CompilerApp : Application
          SetTargetBits(targetBits);
          SetEchoOn(false);
 
+#ifdef _DEBUG
+         TestTypes();
+#endif
+
          privateModule = (Module)__ecere_COM_Initialize(true | (targetBits == sizeof(uintptr)*8 ? 0 : targetBits == 64 ? 2 : targetBits==32 ? 4 : 0) | 8, 1, null);
          SetPrivateModule(privateModule);
 
index a758930..9b40f48 100644 (file)
@@ -2167,22 +2167,8 @@ void CopyTypeInto(Type type, Type src)
    }
 }
 
-public Type ProcessType(OldList specs, Declarator decl)
-{
-   Type type = null;
-   bool isTypedef = false;
-   if(!specs || specs.first)
-   {
-      Declarator funcDecl = GetFuncDecl(decl);
-      Type specType { };
-      bool dllExport = false;
-
-      specType.kind = intType;
-      specType.isSigned = true;   
-      specType.refCount = 1;
-
-      type = Type { refCount = 1 };
-
+#if 0
+      // *** TOADD: ********************************************************
       while(decl && (decl.type == structDeclarator || decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd))
       {
          if(decl.type == structDeclarator && decl.structDecl.exp)
@@ -2204,621 +2190,407 @@ public Type ProcessType(OldList specs, Declarator decl)
          decl = decl.declarator;
       }
 
-      // If we'll be using the specType
-      if(funcDecl || !decl || decl.type == identifierDeclarator)
+      // *** TOADD: ********************************************************
+      id = GetDeclId(d);
+      if(id)
       {
-         Specifier spec;
-         if(specs != null)
+         if(id._class && !id._class.name)
+            ptrType.type.staticMethod =  true;
+         else 
          {
-            bool isLong = false;
-            for(spec = specs.first; spec; spec = spec.next)
+            // TODO : Ensure classSym has been resolved here... (Is this gonna cause problems? Supposed to do this later...)
+            if(!id.classSym)
             {
-               if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && spec.extDecl.s && (!strcmp(spec.extDecl.s, "__declspec(dllexport)") || !strcmp(spec.extDecl.s, "dllexport")))
-               {
-                  dllExport = true;
-               }
-               if(spec.type == extendedSpecifier && spec.extDecl.type == extDeclAttrib)
-               {
-                  specType.keepCast = true;
-               }
-
-               if(spec.specifier != CONST && (specType.kind == structType || specType.kind == unionType))
-               {
-                  FreeType(specType);
-                  specType = { kind = intType, isSigned = true, refCount = 1 };
-               }
-
-               if(spec.type == baseSpecifier)
+               if(id._class && id._class.name)
                {
-                  if(spec.specifier == TYPEDEF) isTypedef = true;
-                  else if(spec.specifier == VOID) specType.kind = voidType;
-                  else if(spec.specifier == CHAR) specType.kind = charType;
-                  else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
-                  else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
-                  else if(spec.specifier == INT64) specType.kind = int64Type;
-                  else if(spec.specifier == VALIST) 
-                     specType.kind = vaListType;
-                  else if(spec.specifier == SHORT) specType.kind = shortType;
-                  else if(spec.specifier == LONG) 
-                  {
-                     if(isLong)
-                        specType.kind = int64Type;
-                     else
-                        specType.kind = intType;
-                     isLong = true;
-                     // specType.kind = longType;
-                  }
-                  else if(spec.specifier == FLOAT) specType.kind = floatType;
-                  else if(spec.specifier == DOUBLE) specType.kind = doubleType;
-                  else if(spec.specifier == SIGNED) specType.isSigned = true;
-                  else if(spec.specifier == UNSIGNED) specType.isSigned = false;
-                  else if(spec.specifier == CONST) specType.constant = true;
-                  else if(spec.specifier == TYPED_OBJECT) 
-                  { 
-                     specType.classObjectType = typedObject; specType.kind = classType; specType._class = FindClass("class"); 
-                  }
-                  else if(spec.specifier == ANY_OBJECT) 
-                  { 
-                     specType.classObjectType = anyObject; specType.kind = classType; specType._class = FindClass("class"); 
-                  }
-                  else if(spec.specifier == CLASS)
-                  {
-                     specType.classObjectType = classPointer; specType.kind = classType; specType._class = FindClass("class");
-                  }
-                  else if(spec.specifier == THISCLASS)
-                     specType.kind = thisClassType;
+                  id.classSym = id._class.symbol; // FindClass(id._class.name);
+                  /* TODO: Name Space Fix ups
+                  if(!id.classSym)
+                     id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
+                  */
                }
-               else if(spec.type == nameSpecifier)
-               {
-                  if(spec.name && (!strcmp(spec.name, "intptr") || !strcmp(spec.name, "uintptr")))
-                  {
-                     specType.kind = intPtrType;
-                     if(!strcmp(spec.name, "uintptr"))
-                        specType.isSigned = false;
-                  }
-                  else if(spec.name && (!strcmp(spec.name, "uintsize") || !strcmp(spec.name, "intsize")))
-                  {
-                     specType.kind = intSizeType;
-                     if(!strcmp(spec.name, "uintsize"))
-                        specType.isSigned = false;
-                  }
-                  else
-                  {
-                     Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
-                     if(symbol && symbol.type)
-                     {
-                        // Free Type Contents:
-                        Type dummy { };
-                        *dummy = *specType;
-                        FreeType(dummy);
+            }
 
-                        CopyTypeInto(specType, symbol.type);
-                        specType.typeName = CopyString(symbol.type.name);
-                     }
-                     else if(!isTypedef) // !specType.kind)    // TESTING THIS FOR enum / typedef problem
-                     {
-                        // key.sym enum values need FindClass:
-                        specType._class = spec.name ? FindClass(spec.name) : null;
-                        // specType._class = spec.symbol; 
-                        specType.kind = classType;
-                        if(!specType._class)
-                           specType.kind = intType;
-                     }
-                  }
-               }
-               else if(spec.type == enumSpecifier)
-               {
+            ptrType.type.thisClass = id.classSym;
+            if(ptrType.type.thisClass && strcmp(ptrType.type.thisClass.string, "class"))
+               ptrType.type.extraParam = true;
+            else if(id._class && id._class.name && !strcmp(id._class.name, "any_object"))
+            {
+               ptrType.type.extraParam = true;
+               ptrType.type.thisClass = FindClass("class");
+            }
+         }
 
-                  specType.kind = enumType;
-                  specType.enumName = spec.id ? CopyString(spec.id.string) : null;
+         type.name = CopyString(id.string);
 
-                  if(spec.list)
-                  {
-                     Enumerator e;
-                     int nextValue = 0;
-                     for(e = spec.list->first; e; e = e.next)
-                     {
-                        // TOFIX: NamedItem i { } causes cryptic error, bad .c!
-                        NamedLink i { name = CopyString(e.id.string) };
-                        specType.members.Add(i);
-                        /*
-                        if(e.exp && ComputeExpression(e.exp), e.exp.isConstant && e.exp.expType.kind == intType)
-                           value.data = (void *) nextValue = strtol(e.exp.string, null, 0);
-                        else
-                           value.data = (void *)nextValue++;
-                        */
-                     }
-                  }
-                  /*
-                  if(spec.list)
-                  {
-                     Declaration decl;
-                     for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
-                        if(decl.declarators)
-                        {
-                           Declarator d;
-                           for(d = decl.declarators.first; d; d = d.next)
-                           {
-                              Type memberType = ProcessType(decl.specifiers, d);
-                              specType.members.Add(memberType);
-                           }
-                        }
-                        else if(decl.specifiers)
-                        {
-                           Type memberType = ProcessType(decl.specifiers, null);
-                           specType.members.Add(memberType);
-                        }
-                  }
-                  */
-               }
-               else if(spec.type == templateTypeSpecifier)
+      // *** TOADD: ********************************************************
+      if(d.type == identifierDeclarator)
+      {
+         if(d.identifier._class && d.identifier._class.type == templateTypeSpecifier)
+         {
+            type.thisClassTemplate = d.identifier._class.templateParameter;
+            type.extraParam = true;
+         }
+         else
+         {
+            if(d.identifier._class && !d.identifier._class.name)
+               type.staticMethod = true;
+            else
+            {
+               if(d.identifier._class && d.identifier._class.name && d.identifier._class.name[strlen(d.identifier._class.name)-1] == '&')
                {
-                  /*
-                  printf("spec %x\n", spec);
-                  printf("template param %x\n", spec.templateParameter);
-                  printf("identifier %x\n", spec.templateParameter.identifier);
-                  printf("string %x\n", spec.templateParameter.identifier.string);
-                  */
-                  specType.kind = templateType;
-                  specType.templateParameter = spec.templateParameter;
+                  type.thisClass = FindClass("class");
+                  type.byReference = true;
                }
-               else if(spec.type == structSpecifier || spec.type == unionSpecifier)
+               else
+                  type.thisClass = d.identifier._class ? d.identifier._class.symbol /*FindClass(d.identifier._class.name)*/ : null;
+               if(type.thisClass && strcmp(type.thisClass.string, "class"))
                {
-                  Symbol _class = spec.id ? FindClass(spec.id.string) : null;
-                  if(_class)
-                  {
-                     if(!_class.registered || _class.registered.type != structClass)
-                        specType.directClassAccess = true;
-                     specType._class = _class;
-                     specType.kind = classType;
-                     break;
-                  }
-                  if(spec.type == structSpecifier)
-                     specType.kind = structType;
-                  else if(spec.type == unionSpecifier)
-                     specType.kind = unionType;
-                  if(spec.id)
-                  {
-                     // TESTING THIS HERE... Had 0 type size 
-                     if(!spec.definitions && !isTypedef)
-                     {
-                        Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
-                        if(symbol && symbol.type)
-                        {
-                           specType = *symbol.type;
-                           specType.name = CopyString(symbol.type.name);
-                           specType.typeName = CopyString(spec.name);
-                           specType.enumName = CopyString(symbol.type.enumName);
-                           specType.refCount = 1;
-
-                           if(symbol.type.kind == enumType)
-                           {
-                              NamedLink member;
-
-                              specType.members.Clear();
-                              for(member = symbol.type.members.first; member; member = member.next)
-                              {
-                                 NamedLink item { name = CopyString(member.name), data = member.data };
-                                 specType.members.Add(item);
-                              }
-                           }
-                           else if(symbol.type.kind == structType || symbol.type.kind == unionType)
-                           {
-                              Type member;
-                              // Tricky stuff... will be removed from list only when ref count reaches 0
-                              for(member = specType.members.first; member; member = member.next)
-                                 member.refCount++;
-                           }
-                           else if(symbol.type.kind == functionType)
-                           {
-                              Type param;
-                              specType.returnType.refCount++;
-                              for(param = specType.params.first; param; param = param.next)
-                                 param.refCount++;
-                           }
-                           else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
-                           {
-                              specType.type.refCount++;
-                              if(symbol.type.kind == arrayType)
-                              {
-                                 if(specType.arraySizeExp)
-                                    specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
-                              }
-
-                           }
-                        }
-                        else
-                           specType.enumName = CopyString(spec.id.string);
-                     }
-                     else
-                        specType.enumName = CopyString(spec.id.string);
-                  }
-
-                  if(spec.definitions)
-                  {
-                     ClassDef def;
-                     for(def = spec.definitions->first; def; def = def.next)
-                     {
-                        if(def.type == declarationClassDef && def.decl.type == structDeclaration)
-                        {
-                           Declaration decl = def.decl;
-                           if(decl.declarators)
-                           {
-                              Declarator d;
-                              for(d = decl.declarators->first; d; d = d.next)
-                              {
-                                 Type memberType = ProcessType(decl.specifiers, d);
-                                 specType.members.Add(memberType);
-                              }
-                           }
-                           else if(decl.specifiers)
-                           {
-                              Type memberType = ProcessType(decl.specifiers, null);
-                              specType.members.Add(memberType);
-                           }
-                        }
-                     }
-                  }
-                  break;
+                  type.extraParam = true;
                }
-               else if(spec.type == subClassSpecifier)
+               else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "any_object"))
                {
-                  specType.kind = specType.kind = subClassType;
-                  specType._class = spec._class.symbol; // FindClass(spec._class.name);
+                  type.extraParam = true;
+                  type.thisClass = FindClass("class");
                }
-               /*
-               else if(spec.type == classSpecifier)
+               else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "class"))
                {
-                  specType._class = FindClass(spec.name);
-                  specType.kind = classType;
+                  //type.extraParam = true;
+                  type.thisClass = FindClass("class");
+                  type.classObjectType = classPointer;
                }
-               */
             }
          }
-         else if(!decl)
-            specType.kind = ellipsisType;
+         type.name = CopyString(d.identifier.string);
       }
 
-      if(funcDecl)
+      // *** TOADD: ********************************************************
+      if(type.classObjectType)
       {
-         Declarator d = funcDecl.declarator;
-         Type funcType { };
-         TypeName param;
-
-         funcType.kind = functionType;
-         funcType.refCount = 1;
-         if(funcDecl.function.parameters)
+         type.byReference = true;
+      }
+      else
+      {
+         if(type.type.classObjectType)
          {
-            for(param = funcDecl.function.parameters->first; param; param = param.next)
-            {
-               /*
-               if(param.typedObject)
-               {
-                  Type typedObjectType
-                  {
-                     refCount = 1;
-                     byReference = param.byReference;
-                     kind = TypeTypedObject;
-                  };
-                  funcType.params.Add(typedObjectType);
-               }
-               else*/
-                  funcType.params.Add(ProcessType(param.qualifiers, param.declarator));
-            }
+            Type subType = type.type;
+            type.classObjectType = subType.classObjectType;
+            type.kind = subType.kind;
+            type._class = subType._class;
+            type.byReference = true;
+
+            FreeType(subType);
          }
+      }
+#endif
 
-         // Function returning a pointer...
-         if(decl.type == pointerDeclarator)
+static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis)
+{
+   Type specType { refCount = 1, kind = intType, isSigned = true };
+   if(specs != null)
+   {
+      bool isTypedef = false;
+      bool dllExport = false;
+      Specifier spec;
+      bool isLong = false;
+      for(spec = specs.first; spec; spec = spec.next)
+      {
+         if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && spec.extDecl.s && (!strcmp(spec.extDecl.s, "__declspec(dllexport)") || !strcmp(spec.extDecl.s, "dllexport")))
          {
-            Pointer pointer = decl.pointer.pointer;
-            Type ptrType { };
-            funcType.returnType = ptrType;
-            funcType.returnType.refCount = 1;
-            while(pointer)
-            {
-               ptrType.kind = pointerType;
-               pointer = pointer.pointer;
-               if(pointer)
-               {
-                  ptrType.type = Type { refCount = 1 };
-                  ptrType = ptrType.type;
-               }
-            }
-            ptrType.type = Type { refCount = 1 };
-            *ptrType.type = specType;
+            dllExport = true;
          }
-         else
+         if(spec.type == extendedSpecifier && spec.extDecl.type == extDeclAttrib)
          {
-            funcType.returnType = Type { refCount = 1 };
-            *funcType.returnType = specType;
+            specType.keepCast = true;
          }
 
-         // TESTING: Added extendedDeclarator here
-         while(d && (d.type == bracketsDeclarator || d.type == extendedDeclarator || d.type == extendedDeclaratorEnd))
+         if(spec.specifier != CONST && (specType.kind == structType || specType.kind == unionType))
          {
-            if((d.type == extendedDeclarator || d.type == extendedDeclaratorEnd) && d.extended.extended && d.extended.extended.type == extDeclString &&
-               d.extended.extended.s && (!strcmp(d.extended.extended.s, "__declspec(dllexport)") || !strcmp(d.extended.extended.s, "dllexport")))
+            FreeType(specType);
+            specType = { kind = intType, isSigned = true, refCount = 1 };
+         }
+
+         if(spec.type == baseSpecifier)
+         {
+            if(spec.specifier == TYPEDEF) isTypedef = true;
+            else if(spec.specifier == VOID) specType.kind = voidType;
+            else if(spec.specifier == CHAR) specType.kind = charType;
+            else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
+            else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
+            else if(spec.specifier == INT64) specType.kind = int64Type;
+            else if(spec.specifier == VALIST) 
+               specType.kind = vaListType;
+            else if(spec.specifier == SHORT) specType.kind = shortType;
+            else if(spec.specifier == LONG) 
             {
-               dllExport = true;            
+               if(isLong)
+                  specType.kind = int64Type;
+               else
+                  specType.kind = intType;
+               isLong = true;
             }
-            d = d.declarator;
+            else if(spec.specifier == FLOAT) specType.kind = floatType;
+            else if(spec.specifier == DOUBLE) specType.kind = doubleType;
+            else if(spec.specifier == SIGNED) specType.isSigned = true;
+            else if(spec.specifier == UNSIGNED) specType.isSigned = false;
+            else if(spec.specifier == CONST)
+               specType.constant = true;
+            else if(spec.specifier == TYPED_OBJECT) 
+            { 
+               specType.classObjectType = typedObject; specType.kind = classType; specType._class = FindClass("class"); 
+            }
+            else if(spec.specifier == ANY_OBJECT) 
+            { 
+               specType.classObjectType = anyObject; specType.kind = classType; specType._class = FindClass("class"); 
+            }
+            else if(spec.specifier == CLASS)
+            {
+               specType.classObjectType = classPointer; specType.kind = classType; specType._class = FindClass("class");
+            }
+            else if(spec.specifier == THISCLASS)
+               specType.kind = thisClassType;
          }
-
-         funcType.dllExport = dllExport;
-
-         if(d && d.type == pointerDeclarator)
+         else if(spec.type == nameSpecifier)
          {
-            Type ptrType;
-            Identifier id;
-
-            if(d.declarator && d.declarator.type == arrayDeclarator)
+            if(spec.name && (!strcmp(spec.name, "intptr") || !strcmp(spec.name, "uintptr")))
             {
-               // Arrays of pointers to functions (extremely tricky :()
-               Pointer pointer = d.pointer.pointer;
-
-               // TO WORK ON: Fixed the order for the array...
-               type.kind = arrayType;
-               type.arraySizeExp = CopyExpression(d.declarator.array.exp);
-               type.freeExp = true;
-               if(d.declarator.array.enumClass)
-                  type.enumClass = d.declarator.array.enumClass.symbol; // FindClass(d.declarator.array.enumClass.name);
-               if(d.declarator.declarator && d.declarator.declarator.type == arrayDeclarator)
+               specType.kind = intPtrType;
+               if(!strcmp(spec.name, "uintptr"))
+                  specType.isSigned = false;
+            }
+            else if(spec.name && (!strcmp(spec.name, "uintsize") || !strcmp(spec.name, "intsize")))
+            {
+               specType.kind = intSizeType;
+               if(!strcmp(spec.name, "uintsize"))
+                  specType.isSigned = false;
+            }
+            else
+            {
+               Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
+               if(symbol && symbol.type)
                {
-                  Type tmpType = type;
-                  Type inType;
-                  type = ProcessType(null, d.declarator.declarator);
-                  inType = type.type;
-                  type.type = tmpType;
-                  tmpType.type = inType;
-               }
-               else
-                  type.type = ProcessType(null, d.declarator.declarator);
+                  // Free Type Contents:
+                  Type dummy { };
+                  *dummy = *specType;
+                  FreeType(dummy);
 
-               for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
-
-               while(pointer)
+                  CopyTypeInto(specType, symbol.type);
+                  specType.typeName = CopyString(symbol.type.name);
+               }
+               else if(!isTypedef) // !specType.kind)    // TESTING THIS FOR enum / typedef problem
                {
-                  ptrType.kind = pointerType;
-                  pointer = pointer.pointer;
-                  if(pointer)
-                  {
-                     ptrType.type = Type { refCount = 1 };
-                     ptrType = ptrType.type;
-                  }
+                  // key.sym enum values need FindClass:
+                  specType._class = spec.name ? FindClass(spec.name) : null;
+                  specType.kind = classType;
+                  if(!specType._class)
+                     specType.kind = intType;
                }
-               ptrType.type = ProcessType(specs, null);
             }
-            else
-            {
-               // WARNING: Not caring if this declarator contains a declarator between
-               //          the pointer and the function other than brackets (like in the case of array of pointers to functions)...
-               // *********** Could it ever go in here???  Yes: void (* converters_table[10]) (); ***********
-               Pointer pointer = d.pointer.pointer;
+         }
+         else if(spec.type == enumSpecifier)
+         {
+
+            specType.kind = enumType;
+            specType.enumName = spec.id ? CopyString(spec.id.string) : null;
 
-               ptrType = type;
-               while(pointer)
+            if(spec.list)
+            {
+               Enumerator e;
+               int nextValue = 0;
+               for(e = spec.list->first; e; e = e.next)
                {
-                  ptrType.kind = pointerType;
-                  ptrType.type = Type { refCount = 1 };
-                  pointer = pointer.pointer;
-                  if(pointer)
-                     ptrType = ptrType.type;
+                  // TOFIX: NamedItem i { } causes cryptic error, bad .c!
+                  NamedLink i { name = CopyString(e.id.string) };
+                  specType.members.Add(i);
                }
             }
-
-            *ptrType.type = funcType;
-            id = GetDeclId(d);
-            if(id)
+         }
+         else if(spec.type == templateTypeSpecifier)
+         {
+            specType.kind = templateType;
+            specType.templateParameter = spec.templateParameter;
+         }
+         else if(spec.type == structSpecifier || spec.type == unionSpecifier)
+         {
+            Symbol _class = spec.id ? FindClass(spec.id.string) : null;
+            if(_class)
+            {
+               if(!_class.registered || _class.registered.type != structClass)
+                  specType.directClassAccess = true;
+               specType._class = _class;
+               specType.kind = classType;
+               break;
+            }
+            if(spec.type == structSpecifier)
+               specType.kind = structType;
+            else if(spec.type == unionSpecifier)
+               specType.kind = unionType;
+            if(spec.id)
             {
-               if(id._class && !id._class.name)
-                  ptrType.type.staticMethod =  true;
-               else 
+               // TESTING THIS HERE... Had 0 type size 
+               if(!spec.definitions && !isTypedef)
                {
-                  // TODO : Ensure classSym has been resolved here... (Is this gonna cause problems? Supposed to do this later...)
-                  if(!id.classSym)
+                  Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
+                  if(symbol && symbol.type)
                   {
-                     if(id._class && id._class.name)
+                     specType = *symbol.type;
+                     specType.name = CopyString(symbol.type.name);
+                     specType.typeName = CopyString(spec.name);
+                     specType.enumName = CopyString(symbol.type.enumName);
+                     specType.refCount = 1;
+
+                     if(symbol.type.kind == enumType)
                      {
-                        id.classSym = id._class.symbol; // FindClass(id._class.name);
-                        /* TODO: Name Space Fix ups
-                        if(!id.classSym)
-                           id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
-                        */
+                        NamedLink member;
+
+                        specType.members.Clear();
+                        for(member = symbol.type.members.first; member; member = member.next)
+                        {
+                           NamedLink item { name = CopyString(member.name), data = member.data };
+                           specType.members.Add(item);
+                        }
                      }
-                  }
+                     else if(symbol.type.kind == structType || symbol.type.kind == unionType)
+                     {
+                        Type member;
+                        // Tricky stuff... will be removed from list only when ref count reaches 0
+                        for(member = specType.members.first; member; member = member.next)
+                           member.refCount++;
+                     }
+                     else if(symbol.type.kind == functionType)
+                     {
+                        Type param;
+                        specType.returnType.refCount++;
+                        for(param = specType.params.first; param; param = param.next)
+                           param.refCount++;
+                     }
+                     else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
+                     {
+                        specType.type.refCount++;
+                        if(symbol.type.kind == arrayType)
+                        {
+                           if(specType.arraySizeExp)
+                              specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
+                        }
 
-                  ptrType.type.thisClass = id.classSym;
-                  if(ptrType.type.thisClass && strcmp(ptrType.type.thisClass.string, "class"))
-                     ptrType.type.extraParam = true;
-                  else if(id._class && id._class.name && !strcmp(id._class.name, "any_object"))
-                  {
-                     ptrType.type.extraParam = true;
-                     ptrType.type.thisClass = FindClass("class");
+                     }
                   }
+                  else
+                     specType.enumName = CopyString(spec.id.string);
                }
-
-               type.name = CopyString(id.string);
+               else
+                  specType.enumName = CopyString(spec.id.string);
             }
-         }
-         else if(!d || d.type == identifierDeclarator)
-         {
 
-            *type = funcType;
-            if(d)
+            if(spec.definitions)
             {
-               if(d.identifier._class && d.identifier._class.type == templateTypeSpecifier)
+               ClassDef def;
+               for(def = spec.definitions->first; def; def = def.next)
                {
-                  type.thisClassTemplate = d.identifier._class.templateParameter;
-                  type.extraParam = true;
-               }
-               else
-               {
-                  if(d.identifier._class && !d.identifier._class.name)
-                     type.staticMethod = true;
-                  else
+                  if(def.type == declarationClassDef && def.decl.type == structDeclaration)
                   {
-                     if(d.identifier._class && d.identifier._class.name && d.identifier._class.name[strlen(d.identifier._class.name)-1] == '&')
-                     {
-                        type.thisClass = FindClass("class");
-                        type.byReference = true;
-                     }
-                     else
-                        type.thisClass = d.identifier._class ? d.identifier._class.symbol /*FindClass(d.identifier._class.name)*/ : null;
-                     if(type.thisClass && strcmp(type.thisClass.string, "class"))
+                     Declaration decl = def.decl;
+                     if(decl.declarators)
                      {
-                        type.extraParam = true;
-                     }
-                     else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "any_object"))
-                     {
-                        type.extraParam = true;
-                        type.thisClass = FindClass("class");
+                        Declarator d;
+                        for(d = decl.declarators->first; d; d = d.next)
+                        {
+                           Type memberType = ProcessType(decl.specifiers, d);
+                           specType.members.Add(memberType);
+                        }
                      }
-                     else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "class"))
+                     else if(decl.specifiers)
                      {
-                        //type.extraParam = true;
-                        type.thisClass = FindClass("class");
-                        type.classObjectType = classPointer;
+                        Type memberType = ProcessType(decl.specifiers, null);
+                        specType.members.Add(memberType);
                      }
                   }
                }
-               type.name = CopyString(d.identifier.string);
             }
+            break;
+         }
+         else if(spec.type == subClassSpecifier)
+         {
+            specType.kind = specType.kind = subClassType;
+            specType._class = spec._class.symbol;
          }
-         delete funcType;
       }
-      else if(decl && decl.type == pointerDeclarator)
+   }
+   else if(assumeEllipsis)
+      specType.kind = ellipsisType;
+   return specType;     
+}
+
+public Type ProcessType(OldList specs, Declarator decl)
+{
+   return _ProcessType(specs, decl, null);
+}
+
+public Type _ProcessType(OldList specs, Declarator decl, Type parentType)
+{
+   Type type = parentType;
+   Declarator subDecl = decl ? decl.declarator : null;
+   if(!parentType)
+      type = ProcessTypeSpecs(specs, decl == null);
+   if(decl)
+   {
+      switch(decl.type)
       {
-         if(decl.declarator && decl.declarator.type == arrayDeclarator)
+         case extendedDeclarator:
+         case extendedDeclaratorEnd:
+         case bracketsDeclarator:
+         case structDeclarator:
+            break;
+         case functionDeclarator:
          {
-            // Arrays of pointers (tricky :))
-            Identifier id;
-            Pointer pointer = decl.pointer.pointer;
-            Type ptrType;
-
-            // TO WORK ON: Fixed the order for the array...
-            type.kind = arrayType;
-            type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
-            type.freeExp = true;
-            if(decl.declarator.array.enumClass)
-               type.enumClass = decl.declarator.array.enumClass.symbol; // FindClass(decl.declarator.array.enumClass.name);
-            if(decl.declarator.declarator && decl.declarator.declarator.type == arrayDeclarator)
+            type = { refCount = 1, kind = functionType, returnType = type };
+            if(decl.function.parameters)
             {
-               Type tmpType = type;
-               Type inType;
-               type = ProcessType(null, decl.declarator.declarator);
-               inType = type.type;
-               type.type = tmpType;
-               tmpType.type = inType;
+               TypeName param;
+               for(param = decl.function.parameters->first; param; param = param.next)
+                  type.params.Add(ProcessType(param.qualifiers, param.declarator));
             }
-            else
-               type.type = ProcessType(null, decl.declarator.declarator);
-            /*
-            type.type = ProcessType(null, decl.declarator.declarator);
-            type.kind = arrayType;
-            type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
-            type.arraySizeExp.freeExp = true;
+            break;
+         }
+         case arrayDeclarator:
+         {
+            type = { refCount = 1, kind = arrayType, arraySizeExp = CopyExpression(decl.array.exp), freeExp = true, type = type };
             if(decl.array.enumClass)
-               type.enumClass = FindClass(decl.array.enumClass.name);
-            */
-
-            for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
-
-            while(pointer)
-            {
-               ptrType.kind = pointerType;
-               pointer = pointer.pointer;
-               if(pointer)
-               {
-                  ptrType.type = Type { refCount = 1 };
-                  ptrType = ptrType.type;
-               }
-            }
-            ptrType.type = ProcessType(specs, null);
-            id = GetDeclId(decl);
-            if(id) type.name = CopyString(id.string);
+               type.enumClass = decl.array.enumClass.symbol; 
+            break;
          }
-         else
+         case pointerDeclarator:
          {
-            Identifier id;
             Pointer pointer = decl.pointer.pointer;
-            Type ptrType = type;
-
-            if(type.classObjectType)
-            {
-               type.byReference = true;
-            }
-            else
+            while(pointer)
             {
-               while(pointer)
+               OldList * qualifiers = pointer.qualifiers;
+               type = { refCount = 1, kind = pointerType, type = type };
+               if(qualifiers)
                {
-                  ptrType.kind = pointerType;
-                  pointer = pointer.pointer;
-                  if(pointer)
+                  Specifier spec;
+                  for(spec = qualifiers->first; spec; spec = spec.next)
                   {
-                     ptrType.type = Type { refCount = 1 };
-                     ptrType = ptrType.type;
+                     if(spec.type == baseSpecifier && spec.specifier == CONST)
+                        type.constant = true;
                   }
                }
-               ptrType.type = ProcessType(specs, decl.declarator);
-
-               if(type.type.classObjectType)
-               {
-                  Type subType = type.type;
-                  type.classObjectType = subType.classObjectType;
-                  type.kind = subType.kind;
-                  type._class = subType._class;
-                  type.byReference = true;
-
-                  FreeType(subType);
-               }
-               id = GetDeclId(decl);
-               if(id) type.name = CopyString(id.string);
+               pointer = pointer.pointer;
             }
+            break;
          }
-      }
-      else if(decl && decl.type == arrayDeclarator)
-      {
-         Identifier id;
-
-         type.kind = arrayType;
-         
-         type.arraySizeExp = CopyExpression(decl.array.exp);
-         type.freeExp = true;
-         if(decl.array.enumClass)
-            type.enumClass = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
-         id = GetDeclId(decl);
-
-         // TO WORK ON: Fixed the order for the array...
-         if(decl.declarator && decl.declarator.type == arrayDeclarator)
-         {
-            Type tmpType = type;
-            Type inType;
-            type = ProcessType(specs, decl.declarator);
-            inType = type.type;
-            type.type = tmpType;
-            tmpType.type = inType;
-         }
-         else
-            type.type = ProcessType(specs, decl.declarator);
-
-         if(id)
+         case identifierDeclarator:
          {
-            delete type.name;
+            Identifier id = decl.identifier;
             type.name = CopyString(id.string);
+            break;
          }
+         default:
+            PrintLn("Unhandled Declarator Type: ", decl.type);
       }
-      else
-      {
-         if(!decl || decl.type == identifierDeclarator)
-         {
-            *type = specType;
-            delete type.name;
-            type.name = decl ? CopyString(decl.identifier.string) : null;
-
-         }   
-      }
-      delete specType;
    }
+   if(subDecl)
+      type = _ProcessType(null, subDecl, type);
    return type;
 }
 
index d7071df..f140449 100644 (file)
@@ -269,7 +269,7 @@ public char * PrintUShort(unsigned short result)
    if(result > 32767)
       sprintf(temp, "0x%X", (int)result);
    else
-      sprintf(temp, "%d", result);
+      sprintf(temp, "%d", (int)result);
    return CopyString(temp);
 }
 
@@ -279,7 +279,7 @@ public char * PrintChar(char result)
    if(result > 0 && isprint(result))
       sprintf(temp, "'%c'", result);
    else if(result < 0)
-      sprintf(temp, "%d", result);
+      sprintf(temp, "%d", (int)result);
    else
       //sprintf(temp, "%#X", result);
       sprintf(temp, "0x%X", (unsigned char)result);
@@ -757,7 +757,8 @@ public int ComputeTypeSize(Type type)
             }
 
             size = ComputeTypeSize(type.type) * type.arraySize;
-            type.alignment = type.type.alignment;
+            if(type.type)
+               type.alignment = type.type.alignment;
             
             break;
          case structType:
@@ -3373,9 +3374,9 @@ bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type de
                         char constant[256];
                         sourceExp.type = constantExp;
                         if(!strcmp(baseClass.dataTypeString, "int"))
-                           sprintf(constant, "%d",value.data);
+                           sprintf(constant, "%d",(int)value.data);
                         else
-                           sprintf(constant, "0x%X",value.data);
+                           sprintf(constant, "0x%X",(int)value.data);
                         sourceExp.constant = CopyString(constant);
                         //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
                      }
@@ -3918,9 +3919,9 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
                            char constant[256];
                            sourceExp.type = constantExp;
                            if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
-                              sprintf(constant, "%d",value.data);
+                              sprintf(constant, "%d", (int) value.data);
                            else
-                              sprintf(constant, "0x%X",value.data);
+                              sprintf(constant, "0x%X", (int) value.data);
                            sourceExp.constant = CopyString(constant);
                            //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
                         }
@@ -6385,63 +6386,39 @@ static void GetTypeSpecs(Type type, OldList * specs)
    }
 }
 
+static void PrintArraySize(Type arrayType, char * string)
+{
+   char size[256];
+   size[0] = '\0';
+   strcat(size, "[");
+   if(arrayType.enumClass)
+      strcat(size, arrayType.enumClass.string);
+   else if(arrayType.arraySizeExp)
+      PrintExpression(arrayType.arraySizeExp, size);
+   strcat(size, "]");
+   strcat(string, size);
+}
+
 // WARNING : This function expects a null terminated string since it recursively concatenate...
-static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
+static void PrintTypeSpecs(Type type, char * string, bool fullName)
 {
    if(type)
    {
+      if(type.constant)
+         strcat(string, "const ");
       switch(type.kind)
       {
          case classType:
-            if(type._class && type._class.string)
+         {
+            Symbol c = type._class;
+            if(c && c.string)
             {
                // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
                //       look into merging with thisclass ?
                if(type.classObjectType == typedObject)
                   strcat(string, "typed_object");
-               else if(fullName)
-                  strcat(string, type._class.string);
                else
-               {
-                  if(type._class.registered)
-                     strcat(string, type._class.registered.name);
-                  else
-                     strcat(string, type._class.string);                     
-               }
-            }
-            break;
-         case pointerType:
-         {
-            /*Type funcType;
-            for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
-            if(funcType && funcType.kind == functionType)
-            {
-               Type param;
-               PrintType(funcType.returnType, string, false, fullName);
-               strcat(string, "(*");
-               if(printName || funcType.thisClass)
-               {
-                  strcat(string, " ");
-                  if(funcType.thisClass)
-                  {
-                     strcat(string, funcType.thisClass.string);
-                     strcat(string, "::");
-                  }
-                  if(type.name)
-                     strcat(string, type.name);
-               }
-               strcat(string, ")(");
-               for(param = funcType.params.first; param; param = param.next)
-               {
-                  PrintType(param, string, false, fullName);
-                  if(param.next) strcat(string, ", ");
-               }
-               strcat(string, ")");               
-            }
-            else*/
-            {
-               _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
-               strcat(string, " *");
+                  strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
             }
             break;
          }
@@ -6461,17 +6438,11 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
                strcat(string, type.enumName);
             }
             else if(type.typeName)
-            {
                strcat(string, type.typeName);
-            }
             else
             {
-               /*
-               strcat(string, "struct ");
-               strcat(string,"(unnamed)");
-               */
                Type member;
-               strcat(string, "struct {");
+               strcat(string, "struct { ");
                for(member = type.members.first; member; member = member.next)
                {
                   PrintType(member, string, true, fullName);
@@ -6487,9 +6458,7 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
                strcat(string, type.enumName);
             }
             else if(type.typeName)
-            {
                strcat(string, type.typeName);
-            }
             else
             {
                strcat(string, "union ");
@@ -6503,125 +6472,13 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
                strcat(string, type.enumName);
             }
             else if(type.typeName)
-            {
                strcat(string, type.typeName);
-            }
             else
                strcat(string, "enum");
             break;
-         case functionType:
-         {
-            if(printFunction)
-            {
-               if(type.dllExport)
-                  strcat(string, "dllexport ");
-               PrintType(type.returnType, string, false, fullName);
-               strcat(string, " ");
-            }
-            
-            // DANGER: Testing This
-            if(printName)
-            {
-               if(type.name)
-               {
-                  if(fullName)
-                     strcat(string, type.name);
-                  else
-                  {
-                     char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
-                     if(name) name += 2; else name = type.name;
-                     strcat(string, name);
-                  }
-               }
-            }
-
-            if(printFunction)
-            {
-               Type param;
-               strcat(string, "(");
-               for(param = type.params.first; param; param = param.next)
-               {
-                  PrintType(param, string, true, fullName);
-                  if(param.next) strcat(string, ", ");
-               }
-               strcat(string, ")");
-            }
-            break;
-         }
-         case arrayType:
-         {
-            /*Type funcType;
-            for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
-            if(funcType && funcType.kind == functionType)
-            {
-               Type param;
-               PrintType(funcType.returnType, string, false, fullName);
-               strcat(string, "(*");
-               if(printName || funcType.thisClass)
-               {
-                  strcat(string, " ");
-                  if(funcType.thisClass)
-                  {
-                     strcat(string, funcType.thisClass.string);
-                     strcat(string, "::");
-                  }
-                  if(type.name)
-                     strcat(string, type.name);
-               }
-               strcat(string, ")(");
-               for(param = funcType.params.first; param; param = param.next)
-               {
-                  PrintType(param, string, false, fullName);
-                  if(param.next) strcat(string, ", ");
-               }
-               strcat(string, ")");               
-            }
-            else*/
-            {
-               char baseType[1024], size[256];
-               Type arrayType = type;
-               baseType[0] = '\0';
-               size[0] = '\0';
-
-               while(arrayType.kind == TypeKind::arrayType)
-               {
-                  strcat(size, "[");
-                  if(arrayType.enumClass)
-                     strcat(size, arrayType.enumClass.string);
-                  else if(arrayType.arraySizeExp)
-                     PrintExpression(arrayType.arraySizeExp, size);
-                  //sprintf(string, "%s[%s]", baseType, size); 
-                  strcat(size, "]");
-
-                  arrayType = arrayType.arrayType;
-               }
-               _PrintType(arrayType, baseType, printName, printFunction, fullName);
-               strcat(string, baseType);
-               strcat(string, size);
-            }
-
-            /*
-               PrintType(type.arrayType, baseType, printName, fullName);
-               if(type.enumClass)
-                  strcpy(size, type.enumClass.string);
-               else if(type.arraySizeExp)
-                  PrintExpression(type.arraySizeExp, size);
-               //sprintf(string, "%s[%s]", baseType, size); 
-               strcat(string, baseType);
-               strcat(string, "[");
-               strcat(string, size); 
-               strcat(string, "]");
-               */
-
-            printName = false;
-            break;
-         }
          case ellipsisType:
             strcat(string, "...");
             break;
-         case methodType:
-            _PrintType(type.method.dataType, string, false, printFunction, fullName);
-            break;
          case subClassType:
             strcat(string, "subclass(");
             strcat(string, type._class ? type._class.string : "int");
@@ -6634,44 +6491,78 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
             strcat(string, "thisclass");
             break;
          case vaListType:
-         strcat(string, "__builtin_va_list");
+            strcat(string, "__builtin_va_list");
             break;
       }
-      if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
-      {
-         strcat(string, " ");
+   }
+}
+
+static void PrintName(Type type, char * string, bool fullName)
+{
+   if(type.name && type.name[0])
+   {
+      strcat(string, " ");
+      if(fullName)
          strcat(string, type.name);
+      else
+      {
+         char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
+         if(name) name += 2; else name = type.name;
+         strcat(string, name);
       }
    }
 }
 
-// *****
-// TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
-// *****
-void PrintType(Type type, char * string, bool printName, bool fullName)
+static void PrePrintType(Type type, char * string, bool printName, bool fullName)
 {
-   Type funcType;
-   for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
-   if(funcType && funcType.kind == functionType && type != funcType)
+   if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
    {
-      char typeString[1024];
-      Type param;
+      if((type.kind == functionType || type.kind == methodType) && type.dllExport)
+         strcat(string, "dllexport ");
+      if(type.constant && (type.kind == functionType || type.kind == methodType))
+         strcat(string, " const");
+      PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, printName, fullName);
+      if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
+         strcat(string, " (");
+      if(type.kind == pointerType)
+         strcat(string, (type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType) ? "*" : " *");
+      if(type.constant && type.kind == pointerType)
+         strcat(string, " const");
+   }
+   else
+      PrintTypeSpecs(type, string, fullName);
+   if(printName && type.name)
+      PrintName(type, string, fullName);
+}
 
-      PrintType(funcType.returnType, string, false, fullName);
-      strcat(string, "(");
-      _PrintType(type, string, printName, false, fullName);
+static void PostPrintType(Type type, char * string, bool fullName)
+{
+   if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
       strcat(string, ")");
-
+   if(type.kind == arrayType)
+      PrintArraySize(type, string);
+   else if(type.kind == functionType)
+   {
+      Type param;
       strcat(string, "(");
-      for(param = funcType.params.first; param; param = param.next)
+      for(param = type.params.first; param; param = param.next)
       {
          PrintType(param, string, true, fullName);
          if(param.next) strcat(string, ", ");
       }
       strcat(string, ")");
    }
-   else
-      _PrintType(type, string, printName, true, fullName);
+   if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
+      PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
+}
+
+// *****
+// TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
+// *****
+void PrintType(Type type, char * string, bool printName, bool fullName)
+{
+   PrePrintType(type, string, printName, fullName);
+   PostPrintType(type, string, fullName);
    if(type.bitFieldCount)
    {
       char count[100];
@@ -6767,9 +6658,9 @@ static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassChe
                exp.type = constantExp;
                exp.isConstant = true;
                if(!strcmp(baseClass.dataTypeString, "int"))
-                  sprintf(constant, "%d",value.data);
+                  sprintf(constant, "%d",(int)value.data);
                else
-                  sprintf(constant, "0x%X",value.data);
+                  sprintf(constant, "0x%X",(int)value.data);
                exp.constant = CopyString(constant);
                //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
                exp.expType = MkClassType(baseClass.fullName);
index 537ac56..f95fc76 100644 (file)
@@ -149,9 +149,14 @@ char * QMkString(char * source)
 
 public Declarator GetFuncDecl(Declarator decl)
 {
-   while(decl && decl.type != functionDeclarator && decl.type != identifierDeclarator)
+   Declarator funcDecl = null;
+   while(decl && decl.type != identifierDeclarator)
+   {
+      if(decl.type == functionDeclarator)
+         funcDecl = decl;
       decl = decl.declarator;
-   return (decl && decl.type == functionDeclarator) ? decl : null;
+   }
+   return funcDecl;
 }
 
 bool parseTypeError;