compiler/libec: Fixed passing of typed objects in ellipsis functions; Fixed string...
[sdk] / compiler / libec / src / pass15.ec
index 7ffebe1..1d32137 100644 (file)
@@ -58,119 +58,6 @@ Time findSymbolTotalTime;
    }
 }
 
-int64 _strtoi64(char * string, char ** endString, int base)
-{
-   int64 value = 0;
-   int sign = 1;
-   int c;
-   char ch;
-   for(c = 0; (ch = string[c]) && isspace(ch); c++);
-   if(ch =='+') c++;
-   else if(ch == '-') { sign = -1; c++; };
-   if(!base)
-   {
-      if(ch == 0 && string[c+1] == 'x')
-      {
-         base = 16;
-         c+=2;
-      }
-      else if(ch == '0')
-      {
-         base = 8;
-         c++;
-      }
-      else
-         base = 10;
-   }
-   for( ;(ch = string[c]); c++)
-   {
-      if(ch == '0')
-         ch = 0;
-      else if(ch >= '1' && ch <= '9')
-         ch -= '1';
-      else if(ch >= 'a' && ch <= 'z') 
-         ch -= 'a'; 
-      else if(ch >= 'A' && ch <= 'Z') 
-         ch -= 'A';
-      else
-      {
-         if(endString)
-            *endString = string + c;
-         // Invalid character
-         break;
-      }
-      if(ch < base)
-      {
-         value *= base;
-         value += ch;
-      }
-      else
-      {
-         if(endString)
-            *endString = string + c;
-         // Invalid character
-         break;
-      }
-   }
-   return sign*value;
-}
-
-uint64 _strtoui64(char * string, char ** endString, int base)
-{
-   uint64 value = 0;
-   int sign = 1;
-   int c;
-   char ch;
-   for(c = 0; (ch = string[c]) && isspace(ch); c++);
-   if(ch =='+') c++;
-   else if(ch == '-') { sign = -1; c++; };
-   if(!base)
-   {
-      if(ch == 0 && string[c+1] == 'x')
-      {
-         base = 16;
-         c+=2;
-      }
-      else if(ch == '0')
-      {
-         base = 8;
-         c++;
-      }
-      else
-         base = 10;
-   }
-   for( ;(ch = string[c]); c++)
-   {
-      if(ch == '0')
-         ch = 0;
-      else if(ch >= '1' && ch <= '9')
-         ch -= '1';
-      else if(ch >= 'a' && ch <= 'z') 
-         ch -= 'a'; 
-      else if(ch >= 'A' && ch <= 'Z') 
-         ch -= 'A';
-      else
-      {
-         if(endString) *endString = string + c;
-         // Invalid character
-         break;
-      }
-      if(ch < base)
-      {
-         value *= base;
-         value += ch;
-      }
-      else
-      {
-         if(endString)
-            *endString = string + c;
-         // Invalid character
-         break;
-      }
-   }
-   return sign*value;
-}
-
 Type ProcessTemplateParameterType(TemplateParameter param)
 {
    if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
@@ -205,6 +92,8 @@ bool NeedCast(Type type1, Type type2)
          case shortType:
          case intType:
          case int64Type:
+         case intPtrType:
+         case intSizeType:
             if(type1.passAsTemplate && !type2.passAsTemplate)
                return true;
             return type1.isSigned != type2.isSigned;
@@ -242,7 +131,7 @@ static void ReplaceClassMembers(Expression exp, Class _class)
          Property prop = eClass_FindProperty(_class, id.string, privateModule);
          Method method = null;
          DataMember member = null;
-         ClassProperty classProp;
+         ClassProperty classProp = null;
          if(!prop)
          {
             method = eClass_FindMethod(_class, id.string, privateModule);
@@ -429,30 +318,41 @@ public char * PrintDouble(double result)
       Operand op2 = GetOperand(exp);                        \
       if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
       else if(op2.kind == intType) *value2 = (t) op2.ui;                 \
-      if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
+      else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
       else if(op2.kind == int64Type) *value2 = (t) op2.ui64;                 \
+      else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
+      else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
+      else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
+      else if(op2.kind == intPtrType) *value2 = (t) op2.ui64;                 \
       else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s;   \
       else if(op2.kind == shortType) *value2 = (t) op2.us;                        \
       else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c;    \
       else if(op2.kind == charType) *value2 = (t) op2.uc;                         \
       else if(op2.kind == floatType) *value2 = (t) op2.f;                         \
       else if(op2.kind == doubleType) *value2 = (t) op2.d;                        \
-      else if(op2.kind == pointerType) *value2 = (t) op2.ui;                        \
+      else if(op2.kind == pointerType) *value2 = (t) op2.ui64;                    \
       else                                                                          \
          return false;                                                              \
       return true;                                                                  \
    }
 
-GETVALUE(Int, int);
-GETVALUE(UInt, unsigned int);
-GETVALUE(Int64, int64);
-GETVALUE(UInt64, uint64);
-GETVALUE(Short, short);
-GETVALUE(UShort, unsigned short);
-GETVALUE(Char, char);
-GETVALUE(UChar, unsigned char);
-GETVALUE(Float, float);
-GETVALUE(Double, double);
+// To help the deubugger currently not preprocessing...
+#define HELP(x) x
+
+GETVALUE(Int, HELP(int));
+GETVALUE(UInt, HELP(unsigned int));
+GETVALUE(Int64, HELP(int64));
+GETVALUE(UInt64, HELP(uint64));
+GETVALUE(IntPtr, HELP(intptr));
+GETVALUE(UIntPtr, HELP(uintptr));
+GETVALUE(IntSize, HELP(intsize));
+GETVALUE(UIntSize, HELP(uintsize));
+GETVALUE(Short, HELP(short));
+GETVALUE(UShort, HELP(unsigned short));
+GETVALUE(Char, HELP(char));
+GETVALUE(UChar, HELP(unsigned char));
+GETVALUE(Float, HELP(float));
+GETVALUE(Double, HELP(double));
 
 void ComputeExpression(Expression exp);
 
@@ -461,12 +361,30 @@ void ComputeClassMembers(Class _class, bool isMember)
    DataMember member = isMember ? (DataMember) _class : null;
    Context context = isMember ? null : SetupTemplatesContext(_class);
    if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) && 
-                 (_class.type == bitClass || _class.structSize == _class.offset) && _class.computeSize))
+                 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
    {
       int c;
       int unionMemberOffset = 0;
       int bitFields = 0;
 
+      /*
+      if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
+         _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
+      */
+
+      if(member)
+      {
+         member.memberOffset = 0;
+         if(targetBits < sizeof(void *) * 8)
+            member.structAlignment = 0;
+      }
+      else if(targetBits < sizeof(void *) * 8)
+         _class.structAlignment = 0;
+
+      // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
+      if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
+         _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
+
       if(!member && _class.destructionWatchOffset)
          _class.memberOffset += sizeof(OldList);
 
@@ -481,8 +399,6 @@ void ComputeClassMembers(Class _class, bool isMember)
             {
                if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
                {
-                  /*if(dataMember.dataType)
-                     printf("");*/
                   dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
                   /*if(!dataMember.dataType)
                      dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
@@ -579,12 +495,6 @@ void ComputeClassMembers(Class _class, bool isMember)
                      alignment = dataMember.dataType.alignment;
                   }
 
-#ifdef _DEBUG
-                  if(!size)
-                  {
-                     // printf("");
-                  }
-#endif
                   if(isMember)
                   {
                      // TESTING THIS PADDING CODE
@@ -621,12 +531,20 @@ void ComputeClassMembers(Class _class, bool isMember)
                }
                else
                {
+                  int alignment;
+
                   ComputeClassMembers((Class)dataMember, true);
+                  alignment = dataMember.structAlignment;
 
                   if(isMember)
                   {
-                     // THERE WASN'T A MAX HERE ? member.structAlignment = dataMember.structAlignment;
-                     member.structAlignment = Max(member.structAlignment, dataMember.structAlignment);
+                     if(alignment)
+                     {
+                        if(member.memberOffset % alignment)
+                           member.memberOffset += alignment - (member.memberOffset % alignment);
+
+                        member.structAlignment = Max(member.structAlignment, alignment);
+                     }
                      dataMember.offset = member.memberOffset;
                      if(member.type == unionMember)
                         unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
@@ -635,7 +553,12 @@ void ComputeClassMembers(Class _class, bool isMember)
                   }
                   else
                   {
-                     _class.structAlignment = Max(_class.structAlignment, dataMember.structAlignment);
+                     if(alignment)
+                     {
+                        if(_class.memberOffset % alignment)
+                           _class.memberOffset += alignment - (_class.memberOffset % alignment);
+                        _class.structAlignment = Max(_class.structAlignment, alignment);
+                     }
                      dataMember.offset = _class.memberOffset;
                      _class.memberOffset += dataMember.memberOffset;
                   }
@@ -694,7 +617,13 @@ void ComputeClassMembers(Class _class, bool isMember)
 
          if(_class.type != bitClass)
          {
-            _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset;
+            int extra = 0;
+            if(_class.structAlignment)
+            {
+               if(_class.memberOffset % _class.structAlignment)
+                  extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
+            }
+            _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
             if(!member)
             {
                Property prop;
@@ -758,6 +687,8 @@ public int ComputeTypeSize(Type type)
          case charType: type.alignment = size = sizeof(char); break;
          case intType: type.alignment = size = sizeof(int); break;
          case int64Type: type.alignment = size = sizeof(int64); break;
+         case intPtrType: type.alignment = size = targetBits / 8; break;
+         case intSizeType: type.alignment = size = targetBits / 8; break;
          case longType: type.alignment = size = sizeof(long); break;
          case shortType: type.alignment = size = sizeof(short); break;
          case floatType: type.alignment = size = sizeof(float); break;
@@ -785,10 +716,10 @@ public int ComputeTypeSize(Type type)
                size = type.alignment = ComputeTypeSize(_class.dataType);
             }
             else
-               size = type.alignment = sizeof(Instance *);
+               size = type.alignment = targetBits / 8; // sizeof(Instance *);
             break;
          }
-         case pointerType: case subClassType: size = type.alignment = sizeof(void *); break;
+         case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
          case arrayType: 
             if(type.arraySizeExp)
             {
@@ -809,18 +740,12 @@ public int ComputeTypeSize(Type type)
                   yylloc = oldLoc;
                }
                GetInt(type.arraySizeExp, &type.arraySize);
-#ifdef _DEBUG
-               if(!type.arraySize)
-               {
-                  printf("");
-               }
-#endif
             }
             else if(type.enumClass)
             {
                if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
                {
-                  type.arraySize = eClass_GetProperty(type.enumClass.registered, "enumSize");
+                  type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
                }
                else
                   type.arraySize = 0;
@@ -878,19 +803,22 @@ public int ComputeTypeSize(Type type)
             TemplateParameter param = type.templateParameter;
             Type baseType = ProcessTemplateParameterType(param);
             if(baseType)
+            {
                size = ComputeTypeSize(baseType);
+               type.alignment = baseType.alignment;
+            }
             else
-               size = sizeof(uint64);
+               type.alignment = size = sizeof(uint64);
             break;
          }
          case enumType:
          {
-            size = sizeof(enum { test });
+            type.alignment = size = sizeof(enum { test });
             break;
          }
          case thisClassType:
          {
-            size = sizeof(void *);
+            type.alignment = size = targetBits / 8; //sizeof(void *);
             break;
          }
       }
@@ -901,7 +829,7 @@ public int ComputeTypeSize(Type type)
 }
 
 
-/*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass)
+/*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
 {
    // This function is in need of a major review when implementing private members etc.
    DataMember topMember = isMember ? (DataMember) _class : null;
@@ -910,6 +838,8 @@ public int ComputeTypeSize(Type type)
    int alignment, size;
    DataMember member;
    Context context = isMember ? null : SetupTemplatesContext(_class);
+   if(addedPadding)
+      *addedPadding = false;
 
    if(!isMember && _class.base)
    {
@@ -918,7 +848,7 @@ public int ComputeTypeSize(Type type)
       {
          // DANGER: Testing this noHeadClass here...
          if(_class.type == structClass || _class.type == noHeadClass)
-            /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass);
+            /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
          else
             maxSize -= _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
       }
@@ -977,7 +907,7 @@ public int ComputeTypeSize(Type type)
                OldList * specs = MkList(), * list = MkList();
                
                size = 0;
-               AddMembers(list, (Class)member, true, &size, topClass);
+               AddMembers(list, (Class)member, true, &size, topClass, null);
                ListAdd(specs, 
                   MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
                ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
@@ -1003,11 +933,19 @@ public int ComputeTypeSize(Type type)
    }
    else if(totalSize < maxSize && _class.type != systemClass)
    {
-      char sizeString[50];
-      sprintf(sizeString, "%d", maxSize - totalSize);
-      ListAdd(declarations, 
-         MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)), 
-         MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
+      int autoPadding = 0;
+      if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
+         autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
+      if(totalSize + autoPadding < maxSize)
+      {
+         char sizeString[50];
+         sprintf(sizeString, "%d", maxSize - totalSize);
+         ListAdd(declarations, 
+            MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)), 
+            MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
+         if(addedPadding)
+            *addedPadding = true;
+      }
    }
    if(context)
       FinishTemplatesContext(context);
@@ -1063,12 +1001,12 @@ void DeclareStruct(char * name, bool skipNoHead)
    External external = null;
    Symbol classSym = FindClass(name);
 
-   if(!inCompiler || !classSym) return null;
+   if(!inCompiler || !classSym) return;
 
    // We don't need any declaration for bit classes...
    if(classSym.registered && 
       (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
-      return null;
+      return;
 
    /*if(classSym.registered.templateClass)
       return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
@@ -1096,7 +1034,7 @@ void DeclareStruct(char * name, bool skipNoHead)
             DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
             classSym.declaring--;
          }
-         return null;
+         return;
       }
       
       //if(!skipNoHead)
@@ -1110,18 +1048,19 @@ void DeclareStruct(char * name, bool skipNoHead)
 
       if(!skipNoHead)
       {
+         bool addedPadding = false;
          classSym.declaredStructSym = true;
 
          declarations = MkList();
 
-         AddMembers(declarations, classSym.registered, false, null, classSym.registered);
+         AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
 
          //ListAdd(specifiers, MkSpecifier(TYPEDEF));
          //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
 
-         if(!declarations->count)
+         if(!declarations->count || (declarations->count == 1 && addedPadding))
          {
-            FreeList(declarations, null);
+            FreeList(declarations, FreeClassDef);
             declarations = null;
          }
       }
@@ -2263,7 +2202,7 @@ public Context SetupTemplatesContext(Class _class)
       {
          if(param.type == type && param.identifier)
          {
-            TemplatedType type { key = (uint)param.identifier.string, param = param };
+            TemplatedType type { key = (uintptr)param.identifier.string, param = param };
             curContext.templateTypes.Add((BTNode)type);
          }
       }
@@ -2292,7 +2231,7 @@ public Context SetupTemplatesContext(Class _class)
                      dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
                   };
                }
-               type = TemplatedType { key = (uint)p.name, param = param };
+               type = TemplatedType { key = (uintptr)p.name, param = param };
                curContext.templateTypes.Add((BTNode)type);
             }
          }
@@ -3174,15 +3113,19 @@ public bool MatchTypes(Type source, Type dest, OldList conversions, Class owning
          return true;
       else if(dest.kind == shortType && source.kind == charType)
          return true;
-      else if(dest.kind == intType && (source.kind == shortType || source.kind == charType))
+      else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == intSizeType /* Exception here for size_t */))
          return true;
-      else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType))
+      else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
+         return true;
+      else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
+         return true;
+      else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
          return true;
       else if(source.kind == enumType &&
-         (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type))
+         (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
           return true;
       else if(dest.kind == enumType &&
-         (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || dest.kind == int64Type))
+         (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
           return true;
       else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && 
               ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
@@ -3495,6 +3438,7 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
 {
    Type source = sourceExp.expType;
    Type realDest = dest;
+   Type backupSourceExpType = null;
 
    if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
       return true;
@@ -3571,9 +3515,9 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
                if(tempType._class)
                   MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
 
-               FreeType(sourceExp.expType);
+               // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
+               backupSourceExpType = sourceExp.expType;
                sourceExp.expType = dest; dest.refCount++;
-
                //sourceExp.expType = MkClassType(_class.fullName);
                flag = true;            
 
@@ -3639,6 +3583,7 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
 
             FreeType(source);
             FreeType(dest);
+            if(backupSourceExpType) FreeType(backupSourceExpType);
             return true;
          }
       }
@@ -3775,6 +3720,7 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
                FreeType(source);
                if(inCompiler) FreeType(dest);
 
+               if(backupSourceExpType) FreeType(backupSourceExpType);
                return true;
             }
 
@@ -3830,6 +3776,12 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
          {
             FreeType(source);
             FreeType(dest);
+            if(backupSourceExpType)
+            {
+               // Failed to convert: revert previous exp type
+               if(sourceExp.expType) FreeType(sourceExp.expType);
+               sourceExp.expType = backupSourceExpType;
+            }
             return false;
          }
       }
@@ -3879,6 +3831,12 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
       {
          FreeType(source);
          FreeType(dest);
+         if(backupSourceExpType)
+         {
+            // Failed to convert: revert previous exp type
+            if(sourceExp.expType) FreeType(sourceExp.expType);
+            sourceExp.expType = backupSourceExpType;
+         }
          return false;
       }
 
@@ -3915,6 +3873,8 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
 
       FreeType(dest);
       FreeType(source);
+      if(backupSourceExpType) FreeType(backupSourceExpType);
+
       return true;
    }
    else
@@ -4258,6 +4218,32 @@ public Operand GetOperand(Expression exp)
                }
                op.kind = intType;
                break;
+            case intPtrType:
+               if(type.isSigned)
+               {
+                  op.i64 = (int64)_strtoi64(exp.constant, null, 0);
+                  op.ops = intOps;
+               }
+               else
+               {
+                  op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
+                  op.ops = uintOps;
+               }
+               op.kind = intType;
+               break;
+            case intSizeType:
+               if(type.isSigned)
+               {
+                  op.i64 = (int64)_strtoi64(exp.constant, null, 0);
+                  op.ops = intOps;
+               }
+               else
+               {
+                  op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
+                  op.ops = uintOps;
+               }
+               op.kind = intType;
+               break;
             case floatType:
                op.f = (float)strtod(exp.constant, null);
                op.ops = floatOps;
@@ -4272,7 +4258,7 @@ public Operand GetOperand(Expression exp)
             case arrayType:
             case pointerType:
             case classType:
-               op.p = (unsigned char *)strtoul(exp.constant, null, 0);
+               op.ui64 = _strtoui64(exp.constant, null, 0);
                op.kind = pointerType;
                op.ops = uintOps;
                // op.ptrSize = 
@@ -4382,6 +4368,22 @@ static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberLi
                   exp.type = constantExp;
                   break;
                }
+               case intPtrType:
+               {
+                  FreeExpContents(exp);
+                  // TODO: This should probably use proper type
+                  exp.constant = PrintInt64((int64)*(intptr*)ptr);
+                  exp.type = constantExp;
+                  break;
+               }
+               case intSizeType:
+               {
+                  FreeExpContents(exp);
+                  // TODO: This should probably use proper type
+                  exp.constant = PrintInt64((int64)*(intptr*)ptr);
+                  exp.type = constantExp;
+                  break;
+               }
                default:
                   Compiler_Error($"Unhandled type populating instance\n");
             }
@@ -4483,6 +4485,12 @@ void PopulateInstance(Instantiation inst)
                      exp.type = constantExp;
                      break;
                   }
+                  case intPtrType:
+                  {
+                     exp.constant = PrintInt64((int64)*(intptr*)ptr);
+                     exp.type = constantExp;
+                     break;
+                  }
                   default:
                      Compiler_Error($"Unhandled type populating instance\n");
                }
@@ -4679,6 +4687,16 @@ void ComputeInstantiation(Expression exp)
                                        GetInt64(value, (int64*)ptr);
                                        break;
                                     }
+                                    case intPtrType:
+                                    {
+                                       GetIntPtr(value, (intptr*)ptr);
+                                       break;
+                                    }
+                                    case intSizeType:
+                                    {
+                                       GetIntSize(value, (intsize*)ptr);
+                                       break;
+                                    }
                                     case floatType:
                                     {
                                        GetFloat(value, (float*)ptr);
@@ -4741,13 +4759,25 @@ void ComputeInstantiation(Expression exp)
                                        Set(inst.data, _strtoi64(value.constant, null, 0));
                                        break;
                                     }
+                                    case intPtrType:
+                                    {
+                                       void (*Set)(void *, intptr) = (void *)prop.Set;
+                                       Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
+                                       break;
+                                    }
+                                    case intSizeType:
+                                    {
+                                       void (*Set)(void *, intsize) = (void *)prop.Set;
+                                       Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
+                                       break;
+                                    }
                                  }
                               }
                               else if(value.type == stringExp)
                               {
                                  char temp[1024];
                                  ReadString(temp, value.string);
-                                 prop.Set(inst.data, temp);
+                                 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
                               }
                            }
                         }
@@ -4852,6 +4882,26 @@ void ComputeInstantiation(Expression exp)
                                     else
                                        bits |= ((uint64)part << bitMember.pos);
                                     break;
+                                 case intPtrType:
+                                    if(type.isSigned)
+                                    {
+                                       bits |= ((intptr)part << bitMember.pos);
+                                    }
+                                    else
+                                    {
+                                       bits |= ((uintptr)part << bitMember.pos);
+                                    }
+                                    break;
+                                 case intSizeType:
+                                    if(type.isSigned)
+                                    {
+                                       bits |= ((ssize_t)(intsize)part << bitMember.pos);
+                                    }
+                                    else
+                                    {
+                                       bits |= ((size_t) (uintsize)part << bitMember.pos);
+                                    }
+                                    break;
                               }
                            }
                         }
@@ -5453,6 +5503,42 @@ void ComputeExpression(Expression exp)
                                  PopulateInstance(exp.instance);
                                  break;
                               }
+                              case intPtrType:
+                              {
+                                 // TOFIX:
+                                 intptr intValue;
+                                 void (*Set)(void *, intptr) = (void *)prop.Set;
+
+                                 exp.instance = Instantiation { };
+                                 exp.instance.data = new0 byte[_class.structSize];
+                                 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+                                 exp.instance.loc = exp.loc;
+                                 exp.type = instanceExp;
+                              
+                                 GetIntPtr(value, &intValue);
+
+                                 Set(exp.instance.data, intValue);
+                                 PopulateInstance(exp.instance);
+                                 break;
+                              }
+                              case intSizeType:
+                              {
+                                 // TOFIX:
+                                 intsize intValue;
+                                 void (*Set)(void *, intsize) = (void *)prop.Set;
+
+                                 exp.instance = Instantiation { };
+                                 exp.instance.data = new0 byte[_class.structSize];
+                                 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+                                 exp.instance.loc = exp.loc;
+                                 exp.type = instanceExp;
+
+                                 GetIntSize(value, &intValue);
+
+                                 Set(exp.instance.data, intValue);
+                                 PopulateInstance(exp.instance);
+                                 break;
+                              }
                               case doubleType:
                               {
                                  double doubleValue;
@@ -5742,6 +5828,42 @@ void ComputeExpression(Expression exp)
                      exp.type = constantExp;
                   }
                   break;
+               case intPtrType:
+                  if(type.isSigned)
+                  {
+                     intptr value;
+                     GetIntPtr(e, &value);
+                     FreeExpContents(exp);
+                     exp.constant = PrintInt64((int64)value);
+                     exp.type = constantExp;
+                  }
+                  else
+                  {
+                     uintptr value;
+                     GetUIntPtr(e, &value);
+                     FreeExpContents(exp);
+                     exp.constant = PrintUInt64((uint64)value);
+                     exp.type = constantExp;
+                  }
+                  break;
+               case intSizeType:
+                  if(type.isSigned)
+                  {
+                     intsize value;
+                     GetIntSize(e, &value);
+                     FreeExpContents(exp);
+                     exp.constant = PrintInt64((int64)value);
+                     exp.type = constantExp;
+                  }
+                  else
+                  {
+                     uintsize value;
+                     GetUIntSize(e, &value);
+                     FreeExpContents(exp);
+                     exp.constant = PrintUInt64((uint64)value);
+                     exp.type = constantExp;
+                  }
+                  break;
                case floatType:
                {
                   float value;
@@ -6231,7 +6353,7 @@ static void ProcessDeclaration(Declaration decl);
 
 static void GetTypeSpecs(Type type, OldList * specs)
 {
-   if(!type.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
+   if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
    switch(type.kind)
    {
       case classType: 
@@ -6249,6 +6371,8 @@ static void GetTypeSpecs(Type type, OldList * specs)
       case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
       case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
       case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
+      case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
+      case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
       case intType: 
       default:
          ListAdd(specs, MkSpecifier(INT)); break;
@@ -6318,6 +6442,8 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
          case voidType: strcat(string, "void"); break;
          case intType:  strcat(string, type.isSigned ? "int" : "uint"); break;
          case int64Type:  strcat(string, type.isSigned ? "int64" : "uint64"); break;
+         case intPtrType:  strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
+         case intSizeType:  strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
          case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
          case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
          case floatType: strcat(string, "float"); break;
@@ -6401,12 +6527,6 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
                      strcat(string, name);
                   }
                }
-#ifdef _DEBUG
-               else
-               {
-                  printf("");
-               }
-#endif
             }
 
             if(printFunction)
@@ -6510,10 +6630,6 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
          case vaListType:
          strcat(string, "__builtin_va_list");
             break;
-#ifdef _DEBUG
-         default:
-            printf("");
-#endif
       }
       if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
       {
@@ -6539,14 +6655,7 @@ void PrintType(Type type, char * string, bool printName, bool fullName)
       strcat(string, "(");
       _PrintType(type, string, printName, false, fullName);
       strcat(string, ")");
-      /*
-      if(type.name)
-         strcat(string, type.name);
-      else
-      {
-         printf("");
-      }
-      */
+
       strcat(string, "(");
       for(param = funcType.params.first; param; param = param.next)
       {
@@ -6717,7 +6826,7 @@ static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassChe
          {
             char constant[256];
             exp.type = constantExp;
-            sprintf(constant, "%d",classProp.Get(_class));
+            sprintf(constant, "%d", (int)classProp.Get(_class));
             exp.constant = CopyString(constant);
          }
       }
@@ -7390,12 +7499,6 @@ void ProcessExpressionType(Expression exp)
             {
                exp.instance._class = MkSpecifierName(exp.destType._class.string);
             }
-#ifdef _DEBUG
-            else 
-            {
-               printf("");               
-            }
-#endif
          }
 
          //classSym = FindClass(exp.instance._class.fullName);
@@ -7756,7 +7859,7 @@ void ProcessExpressionType(Expression exp)
 
             if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
             {
-               if(exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
+               if(exp.op.exp2.expType.kind == intSizeType || exp.op.exp2.expType.kind == intPtrType || exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
                {
                   if(exp.op.op != '=' && type1.type.kind == voidType) 
                      Compiler_Error($"void *: unknown size\n");
@@ -7913,14 +8016,14 @@ void ProcessExpressionType(Expression exp)
                      }
                   }
                   
-                  if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
+                  if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == intSizeType || type2.kind == intPtrType || type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
                   {
                      if(type1.kind != classType && type1.type.kind == voidType) 
                         Compiler_Error($"void *: unknown size\n");
                      exp.expType = type1;
                      if(type1) type1.refCount++;
                   }
-                  else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
+                  else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == intSizeType || type1.kind == intPtrType || type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
                   {
                      if(type2.kind != classType && type2.type.kind == voidType) 
                         Compiler_Error($"void *: unknown size\n");
@@ -8469,7 +8572,14 @@ void ProcessExpressionType(Expression exp)
          {
             Expression idExp = exp.call.exp;
             Identifier id = idExp.identifier;
-            if(!strcmp(id.string, "__ENDIAN_PAD"))
+            if(!strcmp(id.string, "__builtin_frame_address"))
+            {
+               exp.expType = ProcessTypeString("void *", true);
+               if(exp.call.arguments && exp.call.arguments->first)
+                  ProcessExpressionType(exp.call.arguments->first);
+               break;
+            }
+            else if(!strcmp(id.string, "__ENDIAN_PAD"))
             {
                exp.expType = ProcessTypeString("int", true);
                if(exp.call.arguments && exp.call.arguments->first)
@@ -8693,7 +8803,7 @@ void ProcessExpressionType(Expression exp)
             if(!type) emptyParams = true;
 
             // WORKING ON THIS:
-            if(functionType.extraParam && e)
+            if(functionType.extraParam && e && functionType.thisClass)
             {
                e.destType = MkClassType(functionType.thisClass.string);
                e = e.next;
@@ -8809,8 +8919,16 @@ void ProcessExpressionType(Expression exp)
                }
                else
                {
-                  e.destType = type;
-                  if(type) type.refCount++;
+                  if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
+                  {
+                     e.destType = type.prev;
+                     e.destType.refCount++;
+                  }
+                  else
+                  {
+                     e.destType = type;
+                     if(type) type.refCount++;
+                  }
                }
                // Don't reach the end for the ellipsis
                if(type && type.kind != ellipsisType)
@@ -12061,22 +12179,72 @@ static void ProcessClass(OldList definitions, Symbol symbol)
    }
 }
 
+void DeclareFunctionUtil(String s)
+{
+   GlobalFunction function = eSystem_FindFunction(privateModule, s);
+   if(function)
+   {
+      char name[1024];
+      name[0] = 0;
+      if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
+         strcpy(name, "__ecereFunction_");
+      FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
+      DeclareFunction(function, name);
+   }
+}
+
 void ComputeDataTypes()
 {
    External external;
    External temp { };
+   External after = null;
+
    currentClass = null;
 
    containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
 
-   temp.symbol = Symbol { id = -1000, idCode = -1000 };
-
-   // WHERE SHOULD THIS GO?
-   // curExternal = ast->first;
-   ast->Insert(null, temp);
+   for(external = ast->first; external; external = external.next)
+   {
+      if(external.type == declarationExternal)
+      {
+         Declaration decl = external.declaration;
+         if(decl)
+         {
+            OldList * decls = decl.declarators;
+            if(decls)
+            {
+               InitDeclarator initDecl = decls->first;
+               if(initDecl)
+               {
+                  Declarator declarator = initDecl.declarator;
+                  if(declarator && declarator.type == identifierDeclarator)
+                  {
+                     Identifier id = declarator.identifier;
+                     if(id && id.string)
+                     {
+                        if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
+                        {
+                           external.symbol.id = -1001, external.symbol.idCode = -1001;
+                           after = external;
+                        }
+                     }
+                  }
+               }
+            }
+         }
+       }
+   }
 
+   temp.symbol = Symbol { id = -1000, idCode = -1000 };
+   ast->Insert(after, temp);
    curExternal = temp;
 
+   DeclareFunctionUtil("eSystem_New");
+   DeclareFunctionUtil("eSystem_New0");
+   DeclareFunctionUtil("eSystem_Renew");
+   DeclareFunctionUtil("eSystem_Renew0");
+   DeclareFunctionUtil("eClass_GetProperty");
+
    DeclareStruct("ecere::com::Class", false);
    DeclareStruct("ecere::com::Instance", false);
    DeclareStruct("ecere::com::Property", false);