compiler/libec: Fixed usage of virtual methods in basic types (#250, #347)
authorJerome St-Louis <jerome@ecere.com>
Sun, 28 Apr 2013 21:20:29 +0000 (17:20 -0400)
committerJerome St-Louis <jerome@ecere.com>
Sun, 28 Apr 2013 23:05:23 +0000 (19:05 -0400)
compiler/libec/src/pass15.ec
compiler/libec/src/pass2.ec

index 874f9e9..91dbc7a 100644 (file)
@@ -9223,7 +9223,9 @@ void ProcessExpressionType(Expression exp)
          }
          // TODO: *** This seems to be where we should add method support for all basic types ***
          if(type && (type.kind == templateType));
-         else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
+         else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
+                          type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType ||
+                          type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType))
          {
             Identifier id = exp.member.member;
             TypeKind typeKind = type.kind;
@@ -9234,8 +9236,37 @@ void ProcessExpressionType(Expression exp)
                typeKind = classType;
             }
 
-            if(id && (typeKind == intType || typeKind == enumType))
-               _class = eSystem_FindClass(privateModule, "int");
+            if(id)
+            {
+               if(typeKind == intType || typeKind == enumType)
+                  _class = eSystem_FindClass(privateModule, "int");
+               else if(!_class)
+               {
+                  if(type.kind == classType && type._class && type._class.registered)
+                  {
+                     _class = type._class.registered;
+                  }
+                  else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
+                  {
+                     _class = FindClass("char *").registered;
+                  }
+                  else if(type.kind == pointerType)
+                  {
+                     _class = eSystem_FindClass(privateModule, "uintptr");
+                     FreeType(exp.expType);
+                     exp.expType = ProcessTypeString("uintptr", false);
+                     exp.byReference = false;
+                  }
+                  else
+                  {
+                     char string[1024] = "";
+                     Symbol classSym;
+                     PrintTypeNoConst(type, string, false, true);
+                     classSym = FindClass(string);
+                     if(classSym) _class = classSym.registered;
+                  }
+               }
+            }
 
             if(_class && id)
             {
index 43e6ac6..03e35b6 100644 (file)
@@ -1862,7 +1862,7 @@ static void ProcessExpression(Expression exp)
                               else if(checkedExp.type == castExp)
                                  checkedExp = checkedExp.cast.exp;
                            }
-                           newExp = MkExpOp(null, '&', checkedExp);
+                           newExp = (typedObject && !memberExp.member.exp.expType.classObjectType) ? checkedExp : MkExpOp(null, '&', checkedExp);
                            if(parentExp && (parentExp.type == bracketsExp || parentExp.type == extensionExpressionExp))
                            {
                               parentExp.list->Remove(checkedExp);
@@ -1874,6 +1874,13 @@ static void ProcessExpression(Expression exp)
                               // Add a dereference level here
                               parentExp.cast.typeName.declarator = MkDeclaratorPointer(MkPointer(null, null), parentExp.cast.typeName.declarator);
                            }
+                           if(typedObject && !memberExp.member.exp.expType.classObjectType)
+                           {
+                              Type destType { refCount = 1, kind = classType, classObjectType = ClassObjectType::anyObject };
+                              (parentExp ? parentExp : newExp).expType = checkedExp.expType;
+                              (parentExp ? parentExp : newExp).destType = destType;
+                              if(checkedExp.expType) checkedExp.expType.refCount++;
+                           }
                            exp.call.arguments->Insert(null, parentExp ? parentExp : newExp);
                         }
                         else
@@ -1950,6 +1957,8 @@ static void ProcessExpression(Expression exp)
                         _class = eSystem_FindClass(privateModule, "uintptr");
                         FreeType(e.expType);
                         e.expType = ProcessTypeString("uintptr", false);
+                        // Assume null pointers means 'no object' rather than an object holding a null pointer
+                        e.byReference = e.isConstant ? true : false;
                      }
                      else
                      {