compiler/libec: Changes to reflect uint64 type for class properties
authorJerome St-Louis <jerome@ecere.com>
Sun, 10 Feb 2013 22:15:51 +0000 (17:15 -0500)
committerJerome St-Louis <jerome@ecere.com>
Sat, 16 Feb 2013 06:03:02 +0000 (01:03 -0500)
- Always returned in return value (even for struct)

compiler/libec/src/pass0.ec
compiler/libec/src/pass1.ec
compiler/libec/src/pass15.ec
compiler/libec/src/pass2.ec

index 13768e6..1bc4b1c 100644 (file)
@@ -1219,7 +1219,7 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
                      propertyDef.symbol.externalSet = (External)func;
                      if(!propertyDef.conversion && regClass.type == normalClass)
                         func.propSet = propertyDef.symbol;
-                     
+
                      /*
 
                      func.declarator.symbol = Symbol { id = propertyDef.symbol.id + 1 };
@@ -1259,7 +1259,7 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
                      func.declarator.symbol = propertyDef.symbol;
                      //func.declarator.propSymbol = propertyDef.symbol;
                      propertyDef.symbol.externalIsSet = (External)func;
-                     
+
                      /*
 
                      func.declarator.symbol = Symbol { id = propertyDef.symbol,id + 1, external = (External)func };
@@ -1357,28 +1357,56 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
 
                      declId = MkDeclaratorIdentifier(MkIdentifier(name));
                   
-                     if(propertyDef.symbol.type && propertyDef.symbol.type.kind == TypeKind::classType && propertyDef.symbol.type._class && propertyDef.symbol.type._class.registered && 
+                     // Class properties returns a uint64 even for struct types
+                     /*if(propertyDef.symbol.type && propertyDef.symbol.type.kind == TypeKind::classType && propertyDef.symbol.type._class && propertyDef.symbol.type._class.registered && 
                         propertyDef.symbol.type._class.registered.type == structClass)
                      {
-                        ListAdd(params, MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier), MkDeclaratorIdentifier(MkIdentifier("value"))));
-                        decl = PlugDeclarator(propertyDef.declarator, MkDeclaratorFunction(declId, params));
+                        // ListAdd(params, MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier), MkDeclaratorIdentifier(MkIdentifier("value"))));
+                        //decl = PlugDeclarator(propertyDef.declarator, MkDeclaratorFunction(declId, params));
+                        decl = MkDeclaratorFunction(declId, params);
+                        ListAdd(params, MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorIdentifier(MkIdentifier("_value"))));
+
                         func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, decl, null);
+                        {
+                           Declarator ptrDecl;
+                           Statement body = propertyDef.getStmt;
+                           decl = PlugDeclarator(propertyDef.declarator, MkDeclaratorFunction(declId, params));
+                           if(!body.compound.declarations)
+                              body.compound.declarations = MkList();
+                           ListAdd(body.compound.declarations,
+                              MkDeclaration(CopyList(propertyDef.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(
+                                 ptrDecl = MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("value"))), MkInitializerAssignment(MkExpCast(MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier), CopyDeclarator(propertyDef.declarator)), 
+                                    MkExpIdentifier(MkIdentifier("_value"))))))));
+                           {
+                              Symbol sym = ptrDecl.symbol;
+                              sym.isParam = true;
+                              FreeType(sym.type);
+                              sym.type = ProcessType(propertyDef.specifiers, propertyDef.declarator);
+                           }
+                        }
                      }
                      else
+                     */
                      {
                         decl = PlugDeclarator(propertyDef.declarator, MkDeclaratorFunction(declId, params));
-                        func = MkClassFunction(CopyList(propertyDef.specifiers, CopySpecifier), null, decl, null);
+                        //func = MkClassFunction(CopyList(propertyDef.specifiers, CopySpecifier), null, decl, null);
+                        func = MkClassFunction(MkListOne(MkSpecifierName("uint64")), null, decl, null);
                      }
-                  
+
                      ProcessClassFunctionBody(func, propertyDef.getStmt);
                      func.declarator.symbol = propertyDef.symbol;
                      propertyDef.symbol.externalGet = (External)func;
-               
+
                      func.dontMangle = true;
+
                      newDef = MkClassDefFunction(func);
                      definitions.Insert(after, newDef);
                      after = newDef;
 
+                     func.type = ProcessType(propertyDef.specifiers, MkDeclaratorFunction(propertyDef.declarator, null));
+                     if(func.type.returnType.kind == TypeKind::classType && func.type.returnType._class && func.type.returnType._class.registered && func.type.returnType._class.registered.type == structClass)
+                        func.type.returnType.byReference = true;
+
                      if(inCompiler) 
                         propertyDef.getStmt = null;
                      else
@@ -1386,7 +1414,10 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
                   }
                   if(propertyDef.setStmt && propertyDef.id)
                   {
+                     Context prevCurContext;
                      OldList * specifiers = MkList();
+                     Statement body = propertyDef.setStmt;
+                     Declarator ptrDecl;
 
                      strcpy(name, "class::__ecereClassProp_");
                      FullClassNameCat(name, symbol.string, false);
@@ -1395,13 +1426,40 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
                      MangleClassName(name);
 
                      params = MkList();
-
+                     /*
                      ListAdd(params, MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier), 
                         PlugDeclarator(propertyDef.declarator, 
                            MkDeclaratorIdentifier(MkIdentifier("value")))));
+                     */
+
+                     prevCurContext = curContext;
+                     curContext = body.compound.context;
+
+                     ListAdd(params, MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorIdentifier(MkIdentifier("_value"))));
 
                      decl = MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(name)), params);
+                     if(!body.compound.declarations)
+                        body.compound.declarations = MkList();
 
+                     if(propertyDef.symbol.type && propertyDef.symbol.type.kind == TypeKind::classType && propertyDef.symbol.type._class && propertyDef.symbol.type._class.registered &&
+                        propertyDef.symbol.type._class.registered.type == structClass)
+                        ptrDecl = MkDeclaratorPointer(MkPointer(null, null), PlugDeclarator(propertyDef.declarator, MkDeclaratorIdentifier(MkIdentifier("value"))));
+                     else
+                        ptrDecl = PlugDeclarator(propertyDef.declarator, MkDeclaratorIdentifier(MkIdentifier("value")));
+
+                     ListAdd(body.compound.declarations,
+                        MkDeclaration(CopyList(propertyDef.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(ptrDecl,
+                              MkInitializerAssignment(MkExpCast(MkTypeName(CopyList(propertyDef.specifiers, CopySpecifier), CopyDeclarator(propertyDef.declarator)),
+                              MkExpIdentifier(MkIdentifier("_value"))))))));
+
+                     curContext = prevCurContext;
+
+                     {
+                        Symbol sym = ptrDecl.symbol;
+                        sym.isParam = true;
+                        FreeType(sym.type);
+                        sym.type = ProcessType(propertyDef.specifiers, propertyDef.declarator);
+                     }
                      ListAdd(specifiers, MkSpecifier(VOID));
 
                      func = MkClassFunction(specifiers, null, decl, null);
@@ -1418,6 +1476,7 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
                         propertyDef.setStmt = null;
                      else
                         func.body = null;
+
                   }
                }
             }
index 59a19e4..bb32546 100644 (file)
@@ -64,6 +64,8 @@ External ProcessClassFunction(Class owningClass, ClassFunction func, OldList def
       {
          /*FunctionDefinition*/ function = MkFunction(func.specifiers, func.declarator, null);
          function.propSet = func.propSet;
+         function.type = func.type;
+         if(func.type) func.type.refCount++;
          ProcessFunctionBody(function, func.body);
          external = MkExternalFunction(function);
          
index d48d30e..3d46086 100644 (file)
@@ -826,7 +826,7 @@ public int ComputeTypeSize(Type type)
             {
                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;
index cd73a64..c41aeb0 100644 (file)
@@ -3036,6 +3036,9 @@ static void ProcessStatement(Statement stmt)
             for(exp = stmt.expressions->first; exp; exp = exp.next)
             {
                ProcessExpression(exp);
+               // TOCHECK: This was added 2013/02/09 as part of 64 bit port for structs in class properties to automatically be returned by reference
+               if(!exp.next && exp.destType && exp.destType.byReference)
+                  FixReference(exp, true);
             }
          }
          break;