compiler/libec: Fixed templates types checking and casts
authorJerome St-Louis <jerome@ecere.com>
Fri, 20 Jun 2014 20:47:48 +0000 (16:47 -0400)
committerJerome St-Louis <jerome@ecere.com>
Fri, 20 Jun 2014 20:47:48 +0000 (16:47 -0400)
compiler/bootstrap/libec/bootstrap/ecdefs.c
compiler/bootstrap/libec/bootstrap/pass15.c
compiler/bootstrap/libec/bootstrap/pass2.c
compiler/libec/src/ecdefs.ec
compiler/libec/src/pass15.ec
compiler/libec/src/pass2.ec

index 88ae093..7165e52 100644 (file)
@@ -1751,6 +1751,8 @@ struct __ecereNameSpace__ecere__com__Class * c = this->__anon1._class->__anon1.r
 
 if(c->type == 2 || c->type == 3 || c->type == 4 || c->type == 1000)
 return 0;
+else if(c->type == 1 && !this->byReference)
+return 0;
 }
 return 1;
 }
index 38f9147..9da7cbc 100644 (file)
@@ -5690,8 +5690,17 @@ tempType->truth = dest->truth;
 if(tempType->__anon1._class)
 MatchTypes(tempSource, tempDest, conversions, (((void *)0)), (((void *)0)), 1, 1, 0, 0, warnConst);
 backupSourceExpType = sourceExp->expType;
+if(dest->passAsTemplate)
+{
+sourceExp->expType = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_Type);
+CopyTypeInto(sourceExp->expType, dest);
+sourceExp->expType->passAsTemplate = 0;
+}
+else
+{
 sourceExp->expType = dest;
 dest->refCount++;
+}
 flag = 1;
 ((tempType ? (__ecereClass_Type->Destructor ? __ecereClass_Type->Destructor((void *)tempType) : 0, __ecereNameSpace__ecere__com__eSystem_Delete(tempType)) : 0), tempType = 0);
 }
@@ -12970,6 +12979,7 @@ if(exp->destType && exp->destType->passAsTemplate && exp->expType && exp->expTyp
 {
 struct Expression * newExp = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_Expression);
 struct Context * context;
+int kind = exp->expType->kind;
 
 *newExp = *exp;
 if(exp->destType)
@@ -12978,7 +12988,18 @@ if(exp->expType)
 exp->expType->refCount++;
 newExp->prev = (((void *)0));
 newExp->next = (((void *)0));
-switch(exp->expType->kind)
+if(exp->expType->kind == 8 && exp->expType->__anon1._class && exp->expType->__anon1._class->__anon1.registered)
+{
+struct __ecereNameSpace__ecere__com__Class * c = exp->expType->__anon1._class->__anon1.registered;
+
+if(c->type == 2 || c->type == 4 || c->type == 3)
+{
+if(!c->dataType)
+c->dataType = ProcessTypeString(c->dataTypeString, 0);
+kind = c->dataType->kind;
+}
+}
+switch(kind)
 {
 case 7:
 if(exp->destType->classObjectType)
@@ -13010,7 +13031,7 @@ break;
 default:
 exp->type = 11;
 exp->__anon1.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), (((void *)0)));
-if(__ecereProp_Type_Get_isPointerType(exp->expType))
+if((exp->expType->kind == 8 && exp->expType->__anon1._class && exp->expType->__anon1._class->__anon1.registered && exp->expType->__anon1._class->__anon1.registered->type == 1) || __ecereProp_Type_Get_isPointerType(exp->expType))
 exp->__anon1.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), (((void *)0))), MkExpBrackets(MkListOne(newExp)));
 else
 exp->__anon1.cast.exp = MkExpBrackets(MkListOne(newExp));
@@ -13022,6 +13043,7 @@ else if(exp->expType && exp->expType->passAsTemplate && exp->destType && ((unsig
 {
 struct Expression * newExp = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_Expression);
 struct Context * context;
+int kind = exp->expType->kind;
 
 *newExp = *exp;
 if(exp->destType)
@@ -13030,7 +13052,18 @@ if(exp->expType)
 exp->expType->refCount++;
 newExp->prev = (((void *)0));
 newExp->next = (((void *)0));
-switch(exp->expType->kind)
+if(exp->expType->kind == 8 && exp->expType->__anon1._class && exp->expType->__anon1._class->__anon1.registered)
+{
+struct __ecereNameSpace__ecere__com__Class * c = exp->expType->__anon1._class->__anon1.registered;
+
+if(c->type == 2 || c->type == 4 || c->type == 3)
+{
+if(!c->dataType)
+c->dataType = ProcessTypeString(c->dataTypeString, 0);
+kind = c->dataType->kind;
+}
+}
+switch(kind)
 {
 case 7:
 if(exp->destType->classObjectType)
@@ -13064,7 +13097,6 @@ case 8:
 if(exp->expType->__anon1._class && exp->expType->__anon1._class->__anon1.registered && exp->expType->__anon1._class->__anon1.registered->type == 1)
 {
 exp->type = 5;
-if(__ecereProp_Type_Get_isPointerType(exp->expType))
 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), (((void *)0))), newExp);
 exp->__anon1.list = MkListOne(MkExpOp((((void *)0)), '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp->expType->__anon1._class->string)), MkDeclaratorPointer(MkPointer((((void *)0)), (((void *)0))), (((void *)0)))), newExp)));
 ProcessExpressionType((*exp->__anon1.list).first);
@@ -13331,10 +13363,11 @@ switch(type->kind)
 case 8:
 {
 struct Symbol * c = type->__anon1._class;
+unsigned int isObjectBaseClass = !c || !c->string || !strcmp(c->string, "class");
 
-if(type->classObjectType == 2)
+if(type->classObjectType == 2 && isObjectBaseClass)
 strcat(string, "typed_object");
-else if(type->classObjectType == 3)
+else if(type->classObjectType == 3 && isObjectBaseClass)
 strcat(string, "any_object");
 else
 {
@@ -14072,12 +14105,32 @@ thisExp->next = (((void *)0));
 __ecereMethod_Expression_Clear(e);
 if((type->kind == 8 && type->__anon1._class && type->__anon1._class->__anon1.registered && (type->__anon1._class->__anon1.registered->type == 1000 || type->__anon1._class->__anon1.registered->type == 2 || type->__anon1._class->__anon1.registered->type == 4 || type->__anon1._class->__anon1.registered->type == 3)) || (type->kind != 13 && type->kind != 22 && type->kind != 12 && type->kind != 8) || (!destType->byReference && byReference && (destType->kind != 13 || type->kind != 13)))
 {
+unsigned int passAsTemplate = thisExp->destType->passAsTemplate;
+struct Type * t;
+
+destType->refCount++;
 e->type = 4;
 e->__anon1.op.op = '*';
 e->__anon1.op.exp1 = (((void *)0));
 e->__anon1.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer((((void *)0)), (((void *)0))), decl)), thisExp);
+t = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_Type);
+CopyTypeInto(t, thisExp->destType);
+t->passAsTemplate = 0;
+FreeType(thisExp->destType);
+thisExp->destType = t;
+t = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_Type);
+CopyTypeInto(t, destType);
+t->passAsTemplate = passAsTemplate;
+FreeType(destType);
+destType = t;
+destType->refCount = 0;
 e->expType = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_Type);
 CopyTypeInto(e->expType, type);
+if(type->passAsTemplate)
+{
+e->expType->classObjectType = 0;
+e->expType->passAsTemplate = 0;
+}
 e->expType->byReference = 0;
 e->expType->refCount = 1;
 }
@@ -14090,6 +14143,8 @@ e->byReference = 1;
 e->expType = type;
 type->refCount++;
 }
+if(e->destType)
+FreeType(e->destType);
 e->destType = destType;
 destType->refCount++;
 }
index c6f7d92..eca65bc 100644 (file)
@@ -3164,8 +3164,13 @@ checkedExp = (*checkedExp->__anon1.list).last;
 else if(checkedExp->type == 11)
 checkedExp = checkedExp->__anon1.cast.exp;
 }
-newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer((((void *)0)), (((void *)0))), (((void *)0)))), MkExpOp((((void *)0)), '&', checkedExp));
+{
+struct Expression * i;
+
+newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer((((void *)0)), (((void *)0))), (((void *)0)))), (i = MkExpOp((((void *)0)), '&', checkedExp)));
+i->byReference = 1;
 newExp->byReference = 1;
+}
 if(parentExp->type == 7)
 {
 __ecereMethod___ecereNameSpace__ecere__sys__OldList_Insert((&*exp->__anon1.call.arguments), e->prev, newExp);
@@ -3875,7 +3880,7 @@ struct Declarator * decl;
 struct __ecereNameSpace__ecere__sys__OldList * specs = MkList();
 char typeString[1024];
 unsigned int castingToDest = 0;
-unsigned int pointerCastExp;
+unsigned int pointerCastExp = 0;
 
 typeString[0] = '\0';
 e->needTemplateCast = 2;
@@ -3911,8 +3916,10 @@ exp->type = 5;
 {
 struct Specifier * spec = specs ? (*specs).first : (((void *)0));
 struct TemplateParameter * tp = (spec && spec->type == 8) ? spec->__anon1.templateParameter : (((void *)0));
+struct Type * type = castingToDest ? exp->destType : exp->expType;
+unsigned int specsDeclPointer = (spec->type == 1 && strcmp(spec->__anon1.__anon1.name, "uint64")) || (decl && decl->type == 5) || (tp && tp->__anon1.dataType && ((tp->__anon1.dataType->decl && tp->__anon1.dataType->decl->type == 5) || (tp->__anon1.dataType->specifiers && ((struct Specifier *)(*tp->__anon1.dataType->specifiers).first)->type == 1 && strcmp(((struct Specifier *)(*tp->__anon1.dataType->specifiers).first)->__anon1.__anon1.name, "uint64"))));
 
-pointerCastExp = (spec->type == 1 && strcmp(spec->__anon1.__anon1.name, "uint64")) || (decl && decl->type == 5) || (tp && tp->__anon1.dataType && ((tp->__anon1.dataType->decl && tp->__anon1.dataType->decl->type == 5) || (tp->__anon1.dataType->specifiers && ((struct Specifier *)(*tp->__anon1.dataType->specifiers).first)->type == 1 && strcmp(((struct Specifier *)(*tp->__anon1.dataType->specifiers).first)->__anon1.__anon1.name, "uint64")))) || (castingToDest ? __ecereProp_Type_Get_isPointerType(exp->destType) : __ecereProp_Type_Get_isPointerType(exp->expType));
+pointerCastExp = type ? ((type->kind == 20 && specsDeclPointer) || __ecereProp_Type_Get_isPointerType(type)) : specsDeclPointer;
 }
 if(pointerCastExp)
 {
index 73b71b0..b1d76b8 100644 (file)
@@ -1360,6 +1360,8 @@ public:
                   Class c = _class.registered;
                   if(c.type == bitClass || c.type == unitClass || c.type == enumClass || c.type == systemClass)
                      return false;
+                  else if(c.type == structClass && !byReference)
+                     return false;
                }
                return true;
             }
index a43a8cd..12b3d33 100644 (file)
@@ -3801,7 +3801,18 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
 
                // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
                backupSourceExpType = sourceExp.expType;
-               sourceExp.expType = dest; dest.refCount++;
+               if(dest.passAsTemplate)
+               {
+                  // Don't carry passAsTemplate
+                  sourceExp.expType = { };
+                  CopyTypeInto(sourceExp.expType, dest);
+                  sourceExp.expType.passAsTemplate = false;
+               }
+               else
+               {
+                  sourceExp.expType = dest;
+                  dest.refCount++;
+               }
                //sourceExp.expType = MkClassType(_class.fullName);
                flag = true;
 
@@ -6650,19 +6661,35 @@ static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla,
 
 void CheckTemplateTypes(Expression exp)
 {
+   /*
+   bool et = exp.expType ? exp.expType.passAsTemplate : false;
+   bool dt = exp.destType ? exp.destType.passAsTemplate : false;
+   */
    Expression nbExp = GetNonBracketsExp(exp);
    if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
       (nbExp == exp || nbExp.type != castExp))
    {
       Expression newExp { };
       Context context;
+      TypeKind kind = exp.expType.kind;
       *newExp = *exp;
       if(exp.destType) exp.destType.refCount++;
       if(exp.expType)  exp.expType.refCount++;
       newExp.prev = null;
       newExp.next = null;
 
-      switch(exp.expType.kind)
+      if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
+      {
+         Class c = exp.expType._class.registered;
+         if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
+         {
+            if(!c.dataType)
+               c.dataType = ProcessTypeString(c.dataTypeString, false);
+            kind = c.dataType.kind;
+         }
+      }
+
+      switch(kind)
       {
          case doubleType:
             if(exp.destType.classObjectType)
@@ -6694,7 +6721,7 @@ void CheckTemplateTypes(Expression exp)
          default:
             exp.type = castExp;
             exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
-            if(exp.expType.isPointerType)
+            if((exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass) || exp.expType.isPointerType)
                exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
             else
                exp.cast.exp = MkExpBrackets(MkListOne(newExp));
@@ -6706,13 +6733,25 @@ void CheckTemplateTypes(Expression exp)
    {
       Expression newExp { };
       Context context;
+      TypeKind kind = exp.expType.kind;
       *newExp = *exp;
       if(exp.destType) exp.destType.refCount++;
       if(exp.expType)  exp.expType.refCount++;
       newExp.prev = null;
       newExp.next = null;
 
-      switch(exp.expType.kind)
+      if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
+      {
+         Class c = exp.expType._class.registered;
+         if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
+         {
+            if(!c.dataType)
+               c.dataType = ProcessTypeString(c.dataTypeString, false);
+            kind = c.dataType.kind;
+         }
+      }
+
+      switch(kind)
       {
          case doubleType:
             if(exp.destType.classObjectType)
@@ -6747,8 +6786,7 @@ void CheckTemplateTypes(Expression exp)
             {
                exp.type = bracketsExp;
 
-               if(exp.expType.isPointerType)
-                  newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
+               newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
                exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
                   MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
                ProcessExpressionType(exp.list->first);
@@ -7019,11 +7057,12 @@ static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printCo
          case classType:
          {
             Symbol c = type._class;
+            bool isObjectBaseClass = !c || !c.string || !strcmp(c.string, "class");
             // 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)
+            if(type.classObjectType == typedObject && isObjectBaseClass)
                strcat(string, "typed_object");
-            else if(type.classObjectType == anyObject)
+            else if(type.classObjectType == anyObject && isObjectBaseClass)
                strcat(string, "any_object");
             else
             {
@@ -7773,13 +7812,36 @@ void ApplyAnyObjectLogic(Expression e)
              (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
              (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
          {
+            bool passAsTemplate = thisExp.destType.passAsTemplate;
+            Type t;
+
+            destType.refCount++;
+
             e.type = opExp;
             e.op.op = '*';
             e.op.exp1 = null;
             e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
 
+            t = { };
+            CopyTypeInto(t, thisExp.destType);
+            t.passAsTemplate = false;
+            FreeType(thisExp.destType);
+            thisExp.destType = t;
+
+            t = { };
+            CopyTypeInto(t, destType);
+            t.passAsTemplate = passAsTemplate;
+            FreeType(destType);
+            destType = t;
+            destType.refCount = 0;
+
             e.expType = { };
             CopyTypeInto(e.expType, type);
+            if(type.passAsTemplate)
+            {
+               e.expType.classObjectType = none;
+               e.expType.passAsTemplate = false;
+            }
             e.expType.byReference = false;
             e.expType.refCount = 1;
          }
@@ -7792,6 +7854,10 @@ void ApplyAnyObjectLogic(Expression e)
             e.expType = type;
             type.refCount++;
          }
+
+         if(e.destType)
+            FreeType(e.destType);
+
          e.destType = destType;
          destType.refCount++;
       }
index 71ed873..8a61abd 100644 (file)
@@ -2280,8 +2280,12 @@ static void ProcessExpression(Expression exp)
                                  else if(checkedExp.type == castExp)
                                     checkedExp = checkedExp.cast.exp;
                               }
-                              newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpOp(null, '&', checkedExp));
-                              newExp.byReference = true;
+                              {
+                                 Expression i;
+                                 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), (i = MkExpOp(null, '&', checkedExp)));
+                                 i.byReference = true;
+                                 newExp.byReference = true;
+                              }
                               if(parentExp.type == callExp)
                               {
                                  exp.call.arguments->Insert(e.prev, newExp);
@@ -3125,7 +3129,7 @@ static void ProcessExpression(Expression exp)
          OldList * specs = MkList();
          char typeString[1024];
          bool castingToDest = false;
-         bool pointerCastExp;
+         bool pointerCastExp = false;
 
          typeString[0] = '\0';
 
@@ -3168,13 +3172,13 @@ static void ProcessExpression(Expression exp)
          {
             Specifier spec = specs ? specs->first : null;
             TemplateParameter tp = (spec && spec.type == templateTypeSpecifier) ? spec.templateParameter : null;
-            pointerCastExp =
-               (spec.type == nameSpecifier && strcmp(spec.name, "uint64")) ||
+            Type type = castingToDest ? exp.destType : exp.expType;
+            bool specsDeclPointer = (spec.type == nameSpecifier && strcmp(spec.name, "uint64")) ||
                (decl && decl.type == pointerDeclarator) ||
                (tp && tp.dataType &&
                   ( (tp.dataType.decl && tp.dataType.decl.type == pointerDeclarator) ||
-                    (tp.dataType.specifiers && ((Specifier)tp.dataType.specifiers->first).type == nameSpecifier && strcmp(((Specifier)tp.dataType.specifiers->first).name, "uint64")) ) )  ||
-               (castingToDest ? exp.destType.isPointerType : exp.expType.isPointerType);
+                    (tp.dataType.specifiers && ((Specifier)tp.dataType.specifiers->first).type == nameSpecifier && strcmp(((Specifier)tp.dataType.specifiers->first).name, "uint64")) ) );
+            pointerCastExp = type ? ((type.kind == templateType && specsDeclPointer) || type.isPointerType) : specsDeclPointer;
          }
 
          if(pointerCastExp)