compiler/libec: (#439) Removed unused declID from DeclClass()
[sdk] / compiler / libec / src / ast.ec
index 6211bd1..0d58a1b 100644 (file)
@@ -4,21 +4,23 @@ import "ecdefs"
 #include "grammar.h"
 extern char * yytext;
 
-char * defaultNameSpace;
+const char * defaultNameSpace;
 int defaultNameSpaceLen;
-public void SetDefaultNameSpace(char * s) { defaultNameSpace = s; defaultNameSpaceLen = s ? strlen(s) : 0; }
+public void SetDefaultNameSpace(const char * s) { defaultNameSpace = s; defaultNameSpaceLen = s ? strlen(s) : 0; }
 
 bool strictNameSpaces;
 public void SetStrictNameSpaces(bool b) { strictNameSpaces = b; }
 
 AccessMode declMode = privateAccess;
-public void SetDeclMode(AccessMode accessMode) { declMode = accessMode; }
+AccessMode structDeclMode = privateAccess;
+
+public void SetDeclMode(AccessMode accessMode) { structDeclMode = declMode = accessMode; }
 AccessMode defaultDeclMode = privateAccess;
 public void SetDefaultDeclMode(AccessMode accessMode) { defaultDeclMode = accessMode; }
 
-char * currentNameSpace;
+const char * currentNameSpace;
 int currentNameSpaceLen;
-public void SetCurrentNameSpace(char * s) { currentNameSpace = s; currentNameSpaceLen = s ? strlen(s) : 0; }
+public void SetCurrentNameSpace(const char * s) { currentNameSpace = s; currentNameSpaceLen = s ? strlen(s) : 0; }
 
 #ifdef _TIMINGS
 Time findClassTotalTime;
@@ -51,16 +53,16 @@ void ListAddFront(OldList list, void * item)
       list.Insert(null, item);
 }
 
-public Identifier MkIdentifier(char * string)
+public Identifier MkIdentifier(const char * string)
 {
    Identifier id { };
    int c;
-   
+
    id._class = null; // Default class...
 
    if(string)
    {
-      char * namePart;
+      const char * namePart;
       bool gotColon = false;
       for(c = strlen(string)-1; c >= 0; c--)
          if(string[c] == ':')
@@ -119,7 +121,7 @@ public Identifier MkIdentifier(char * string)
                else
                   id.string = CopyString(string);
             }
-         }         
+         }
       }
       else if(gotColon)
       {
@@ -208,7 +210,7 @@ Expression MkExpExtensionInitializer(TypeName typeName, Initializer initializer)
 
 public Expression MkExpIdentifier(Identifier id)
 {
-   return { type = identifierExp, identifier = id };
+   return { type = identifierExp, identifier = id, loc = yylloc };
 }
 
 public Expression MkExpDummy()
@@ -217,14 +219,19 @@ public Expression MkExpDummy()
    return exp;
 }
 
-public Expression MkExpConstant(char * string)
+public Expression MkExpConstant(const char * string)
 {
-   return { type = constantExp, constant = CopyString(string) };
+   return { type = constantExp, constant = CopyString(string), loc = yylloc };
 }
 
-Expression MkExpString(char * string)
+Expression MkExpString(const char * string)
 {
-   return { type = stringExp, string = CopyString(string) };
+   return { type = stringExp, string = CopyString(string), loc = yylloc };
+}
+
+Expression MkExpWideString(const char * string)
+{
+   return { type = stringExp, string = CopyString(string), loc = yylloc, wideString = true };
 }
 
 // TODO: String is case sensitive..
@@ -271,50 +278,63 @@ public struct ContextStringPair
    }
 };
 
-Map<ContextStringPair, List<Location> > intlStrings { };
+Map<ContextStringPair, List<Location>> intlStrings { };
 
-Expression MkExpIntlString(char * string, char * context)
+Expression MkExpIntlString(const char * string, const char * context)
 {
-   OldList * list = MkList();
    if(inCompiler)
    {
-      ContextStringPair pair { };
-      List<Location> list;
-      int len = strlen(string);
+      OldList * list = MkList();
+      String s;
+      if(inCompiler)
+      {
+         ContextStringPair pair { };
+         List<Location> list;
+         int len = strlen(string);
 
-      pair.string = new byte[len-2+1]; memcpy(pair.string, string+1, len-2); pair.string[len-2] = '\0';
-      if(context) { len = strlen(context); pair.context = new byte[len-2+1]; memcpy(pair.context, context+1, len-2); pair.context[len-2] = '\0'; }
+         pair.string = new byte[len-2+1]; memcpy(pair.string, string+1, len-2); pair.string[len-2] = '\0';
+         if(context) { len = strlen(context); pair.context = new byte[len-2+1]; memcpy(pair.context, context+1, len-2); pair.context[len-2] = '\0'; }
 
-      list = intlStrings[pair];
-      if(!list)
-      {
-         list = { };
-         intlStrings[pair] = list;
+         list = intlStrings[pair];
+         if(!list)
+         {
+            list = { };
+            intlStrings[pair] = list;
+         }
+         else
+         {
+            delete pair.string;
+            delete pair.context;
+         }
+         list.Add(yylloc);
       }
-      else
+      //ListAdd(list, QMkExpId("__thisModule"));
+      s = QMkString(i18nModuleName ? i18nModuleName : "");
+      ListAdd(list, MkExpString(s));
+      delete s;
+      ListAdd(list, MkExpString(string));
+      if(context)
       {
-         delete pair.string;
-         delete pair.context;
+         int lenString = strlen(string), lenContext = strlen(context);
+         char * msgid = new char[lenString-2 + lenContext-2 + 4];
+         msgid[0] = '\"';
+         memcpy(msgid+1, context+1, lenContext-2);
+         msgid[1+lenContext-2] = 4; // EOT
+         memcpy(msgid+1+lenContext-2+1, string+1, lenString-2);
+         memcpy(msgid+1+lenContext-2+1+lenString-2, "\"", 2);
+         ListAdd(list, MkExpString(msgid));
+         delete msgid;
       }
-      list.Add(yylloc);
-   }
-   ListAdd(list, QMkExpId("__thisModule"));
-   ListAdd(list, MkExpString(string));
-   if(context)
-   {
-      int lenString = strlen(string), lenContext = strlen(context);
-      char * msgid = new char[lenString-2 + lenContext-2 + 4];
-      msgid[0] = '\"';
-      memcpy(msgid+1, context+1, lenContext-2);
-      msgid[1+lenContext-2] = 4; // EOT
-      memcpy(msgid+1+lenContext-2+1, string+1, lenString-2);
-      memcpy(msgid+1+lenContext-2+1+lenString-2, "\"", 2);
-      ListAdd(list, MkExpString(msgid));
-      delete msgid;
+      else
+         ListAdd(list, QMkExpId("null"));
+      return MkExpCall(QMkExpId("GetTranslatedString"), list);
    }
    else
-      ListAdd(list, QMkExpId("null"));
-   return MkExpCall(QMkExpId("GetTranslatedString"), list);
+   {
+      Expression e = MkExpString(string);
+      e.intlString = true;
+      return e;
+   }
 }
 
 Expression MkExpOp(Expression exp1, int op, Expression exp2)
@@ -356,72 +376,77 @@ Expression MkExpIndex(Expression expression, OldList index)
 
 Expression MkExpCall(Expression expression, OldList arguments)
 {
-   return { type = callExp, call.exp = expression, call.arguments = arguments };
+   return { type = callExp, call.exp = expression, call.arguments = arguments, loc = yylloc };
 }
 
 Expression MkExpMember(Expression expression, Identifier member)
 {
-   return { type = memberExp, member.exp = expression, member.member = member };
+   return { type = memberExp, member.exp = expression, member.member = member, loc = yylloc };
 }
 
 Expression MkExpPointer(Expression expression, Identifier member)
 {
-   return { type = pointerExp, member.exp = expression, member.member = member };
+   return { type = pointerExp, member.exp = expression, member.member = member, loc = yylloc };
 }
 
 Expression MkExpTypeSize(TypeName typeName)
 {
-   return { type = typeSizeExp, typeName = typeName };
+   return { type = typeSizeExp, typeName = typeName, loc = yylloc };
 }
 
 Expression MkExpTypeAlign(TypeName typeName)
 {
-   return { type = typeAlignExp, typeName = typeName };
+   return { type = typeAlignExp, typeName = typeName, loc = yylloc };
 }
 
 Expression MkExpClassSize(Specifier _class)
 {
-   return { type = classSizeExp, _class = _class };
+   return { type = classSizeExp, _class = _class, loc = yylloc };
 }
 
 Expression MkExpCast(TypeName typeName, Expression expression)
 {
-   return { type = castExp, cast.typeName = typeName, cast.exp = expression };
+   return { type = castExp, cast.typeName = typeName, cast.exp = expression, loc = yylloc };
 }
 
 Expression MkExpCondition(Expression cond, OldList expressions, Expression elseExp)
 {
-   return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp };
+   return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp, loc = yylloc };
 }
 
 Expression MkExpRenew(Expression memExp, TypeName type, Expression size)
 {
-   return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
+   return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size, loc = yylloc };
 }
 
 Expression MkExpRenew0(Expression memExp, TypeName type, Expression size)
 {
-   return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
+   return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size, loc = yylloc };
 }
 
 Expression MkExpNew(TypeName type, Expression size)
 {
-   return { type = newExp, _new.typeName = type, _new.size = size };
+   return { type = newExp, _new.typeName = type, _new.size = size, loc = yylloc };
 }
 
 Expression MkExpNew0(TypeName type, Expression size)
 {
-   return { type = new0Exp, _new.typeName = type, _new.size = size };
+   return { type = new0Exp, _new.typeName = type, _new.size = size, loc = yylloc };
 }
 
 Expression MkExpVaArg(Expression exp, TypeName type)
 {
-   return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type };
+   return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type, loc = yylloc };
 }
 
 Specifier MkSpecifier(int specifier)
 {
-   return { type = baseSpecifier, specifier = specifier };
+   if(specifier == _BOOL && (declMode != defaultAccess && defaultDeclMode != defaultAccess))
+      return MkSpecifierName("bool");
+   else if(specifier == _BOOL || specifier == BOOL)
+      return { type = baseSpecifier, specifier = specifier };
+   else
+      return { type = baseSpecifier, specifier = specifier };
 }
 
 Specifier MkSpecifierTypeOf(Expression expression)
@@ -441,7 +466,7 @@ Specifier MkSpecifierExtended(ExtDecl extDecl)
 
 Specifier MkEnum(Identifier id, OldList list)
 {
-   Specifier spec 
+   Specifier spec
    {
       type = enumSpecifier;
       id = id;
@@ -482,9 +507,9 @@ Specifier MkStructOrUnion(SpecifierType type, Identifier id, OldList definitions
 {
    Specifier spec { type = type, id = id };
    if(id && FindType(curContext, id.string))
-      declMode = defaultAccess;
+      structDeclMode = defaultAccess;
    spec.definitions = definitions;
-   if(definitions && id && !declMode)
+   if(definitions && id && structDeclMode == defaultAccess)
    {
       OldList specs { };
       Symbol symbol;
@@ -655,7 +680,7 @@ public TypeName MkTypeNameGuessDecl(OldList qualifiers, Declarator declarator)
          next = spec.next;
          if(gotType && !declarator && ((spec.type == nameSpecifier && spec.name) || (spec.type == baseSpecifier && gotFullType)))
          {
-            String s = null;
+            const String s = null;
             if(spec.type == nameSpecifier)
             {
                char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
@@ -744,7 +769,6 @@ Declaration MkDeclarationInst(Instantiation inst)
       string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
       type = MkClassTypeSymbol(inst._class.symbol);
    };
-   symbol.idCode = symbol.id = curContext.nextID++;
    if(strstr(symbol.string, "::"))
       curContext.hasNameSpace = true;
    if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
@@ -798,7 +822,7 @@ Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
 {
    Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
    bool variable = true;
-   
+
    if(specifiers != null)
    {
       bool gotType = false;
@@ -811,7 +835,7 @@ Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
             if(initDeclarators != null)
             {
                InitDeclarator d;
-         
+
                for(d = initDeclarators.first; d; d = d.next)
                {
                   if(GetDeclId(d.declarator).string)
@@ -821,7 +845,6 @@ Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
                         string = CopyString(GetDeclId(d.declarator).string);
                         type = ProcessType(specifiers, d.declarator);
                      };
-                     type.id = type.idCode = curContext.nextID++;
 
                      if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
                         excludedSymbols->Add(type);
@@ -836,10 +859,10 @@ Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
                {
                   if((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier)
                   {
-                     String s = null;
+                     const String s = null;
                      if(spec.type == nameSpecifier)
                      {
-                        char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
+                        const char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
                         s = colon ? colon + 2 : spec.name;
                      }
                      else if(spec.type == baseSpecifier)
@@ -849,7 +872,6 @@ Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
                      if(s)
                      {
                         Symbol type { string = CopyString(s), type = ProcessType(specifiers, null) };
-                        type.id = type.idCode = curContext.nextID++;
                         decl.symbol = type;
                         decl.declarators = initDeclarators = MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
                         specifiers.Remove(spec);
@@ -863,14 +885,14 @@ Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
             variable = false;
             break;
          }
-         else if(spec.type == baseSpecifier && 
+         else if(spec.type == baseSpecifier &&
             (spec.specifier == STRUCT || spec.specifier == UNION))
             variable = false;
          else
          {
             if(gotType && initDeclarators == null && !spec.next && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
             {
-               String s = null;
+               const String s = null;
                if(spec.type == nameSpecifier)
                {
                   char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
@@ -930,7 +952,7 @@ Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
                   delete id.string;
                   id.string = CopyString(name);
                }
-               
+
                // Avoid memory leaks on duplicated symbols (BinaryTree::Add Would Fail)
                symbol = (Symbol)(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.FindString(id.string);
                if(!symbol)
@@ -975,7 +997,6 @@ Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
                         symbol.type.freeExp = true;
                      }
                   }
-                  symbol.id = symbol.idCode = curContext.nextID++;
                }
                decl.symbol = d.declarator.symbol = symbol;
             }
@@ -985,7 +1006,6 @@ Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
    else
    {
       decl.symbol = Symbol { };
-      decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
       excludedSymbols->Add(decl.symbol);
    }
    return decl;
@@ -1003,10 +1023,10 @@ Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifi
          next = spec.next;
          if(gotType && declarators == null && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
          {
-            String s = null;
+            const String s = null;
             if(spec.type == nameSpecifier)
             {
-               char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
+               const char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
                s = colon ? colon + 2 : spec.name;
             }
             else if(spec.type == baseSpecifier)
@@ -1130,7 +1150,7 @@ FunctionDefinition _MkFunction(OldList specifiers, Declarator declarator, OldLis
                   Specifier spec = tn.qualifiers ? tn.qualifiers->first : null;
                   if(!tn.declarator && !tn.prev && !tn.next && spec && !spec.next && spec.type == baseSpecifier && spec.specifier == VOID);
                   else
-                     Compiler_Error("parameter name omitted\n");
+                     Compiler_Error($"parameter name omitted\n");
                   break;
                }
             }
@@ -1171,8 +1191,6 @@ void ProcessFunctionBody(FunctionDefinition func, Statement body)
                   if(!context.symbols.Add((BTNode)symbol))
                      excludedSymbols->Add(symbol);
 
-                  // TODO: Fix this, the parameters' IDs should really be smaller...
-                  symbol.id = context.nextID++;
                   param.declarator.symbol = symbol;
                }
             }
@@ -1210,7 +1228,6 @@ void ProcessFunctionBody(FunctionDefinition func, Statement body)
          id.string = CopyString(name);
       }
       symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
-      symbol.idCode = symbol.id = globalContext.nextID++;
       if(strstr(symbol.string, "::"))
          globalContext.hasNameSpace = true;
       if(!globalContext.symbols.Add((BTNode)symbol))
@@ -1254,7 +1271,7 @@ External MkExternalFunction(FunctionDefinition function)
       for(spec = function.specifiers->first; spec; spec = spec.next)
          if(spec.type == baseSpecifier && spec.specifier == STATIC)
          {
-            declMode = staticAccess;
+            structDeclMode = declMode = staticAccess;
             break;
          }
    }
@@ -1292,19 +1309,18 @@ External MkExternalImport(char * name, ImportType importType, AccessMode importA
 External MkExternalDeclaration(Declaration declaration)
 {
    External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
-   InitDeclarator d = (declaration && declaration.declarators) ? declaration.declarators->last : null;
    if(declaration && declaration.type == initDeclaration && declaration.specifiers)
    {
       Specifier spec;
       for(spec = declaration.specifiers->first; spec; spec = spec.next)
          if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
          {
-            declMode = defaultAccess;
+            structDeclMode = declMode = defaultAccess;
             break;
          }
          else if(spec.type == baseSpecifier && spec.specifier == STATIC)
          {
-            declMode = staticAccess;
+            structDeclMode = declMode = staticAccess;
             break;
          }
    }
@@ -1360,7 +1376,7 @@ void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
                   fileInput = backFileInput;
                   if(fileInput)
                   {
-                     fileInput.Seek(yylloc.start.pos, start); 
+                     fileInput.Seek(yylloc.start.pos, start);
                      resetScannerPos(&yylloc.start);
                      yychar = -2;
                   }
@@ -1408,7 +1424,8 @@ void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
          if(!symbol && spec.symbol)
          {
             // If class was only decl'ed, invoke DeclClass on this templated class as well
-            symbol = _DeclClass(MAXINT, templateString);
+            symbol = _DeclClass(templateString);
+            symbol.notYetDeclared = true;
          }
          // Add a reference to all templated class to the basic class
          if(spec.symbol)
@@ -1422,7 +1439,7 @@ void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
       FreeList(templateArgs, FreeTemplateArgument);
 }
 
-Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
+Specifier _MkSpecifierName(const char * name, Symbol symbol, OldList templateArgs)
 {
    Specifier spec { type = nameSpecifier };
 
@@ -1453,7 +1470,7 @@ Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
          }
       }
       else if(symbol)
-         spec.name = CopyString(symbol.string);   
+         spec.name = CopyString(symbol.string);
       else
          spec.name = CopyString(name);
       spec.symbol = symbol;
@@ -1463,18 +1480,18 @@ Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
    return spec;
 }
 
-public Specifier MkSpecifierName(char * name)
+public Specifier MkSpecifierName(const char * name)
 {
    return _MkSpecifierName(name, null, null);
 }
 
-public Specifier MkSpecifierNameArgs(char * name, OldList * templateArgs)
+public Specifier MkSpecifierNameArgs(const char * name, OldList * templateArgs)
 {
    return _MkSpecifierName(name, null, templateArgs);
 }
 
 /*
-Specifier MkClassName(char * string)
+Specifier MkClassName(const char * string)
 {
    return { type = SpecifierClass, name = CopyString(string) };
 }
@@ -1526,8 +1543,6 @@ void ProcessClassFunctionBody(ClassFunction func, Statement body)
                      isParam = true;
                   };
 
-                  // TODO: Fix this, the parameters' IDs should really be smaller...
-                  symbol.idCode = symbol.id = context.nextID++;
                   if(!context.symbols.Add((BTNode)symbol))
                      excludedSymbols->Add(symbol);
 
@@ -1540,7 +1555,7 @@ void ProcessClassFunctionBody(ClassFunction func, Statement body)
 
       symbol = Symbol
       {
-         
+
       };
 
       {
@@ -1571,7 +1586,6 @@ void ProcessClassFunctionBody(ClassFunction func, Statement body)
             symbolSpecs->Add(CopySpecifier(spec));
       }
       symbol.type = ProcessType(symbolSpecs, decl);
-      symbol.idCode = symbol.id = globalContext.nextID++;
       decl.symbol = symbol;
 
       excludedSymbols->Add(symbol);
@@ -1642,7 +1656,7 @@ Instantiation MkInstantiationNamed(OldList specs, Expression exp, OldList member
          }
 
       FreeList(specs, FreeSpecifier);
-         
+
       if(!spec)
       {
          Compiler_Error($"Expecting class specifier\n");
@@ -1674,7 +1688,7 @@ ClassDef MkClassDefClassData(Declaration decl)
    return { type = classDataClassDef, decl = decl };
 }
 
-ClassDef MkClassDefDesigner(char * designer)
+ClassDef MkClassDefDesigner(const char * designer)
 {
    return { type = classDesignerClassDef, designer = CopyString(designer) };
 }
@@ -1720,7 +1734,7 @@ ClassDef MkClassDefFunction(ClassFunction function)
    return def;
 }
 
-Symbol DeclClassAddNameSpace(int symbolID, char * className)
+Symbol DeclClassAddNameSpace(const char * className)
 {
    char name[1024];
    int len = 0, stringLen;
@@ -1746,18 +1760,18 @@ Symbol DeclClassAddNameSpace(int symbolID, char * className)
    memcpy(name + len, className, stringLen);
    len += stringLen;
    name[len] = 0;
-   return _DeclClass(symbolID, name);
+   return _DeclClass(name);
 }
 
-Symbol DeclClass(int symbolID, char * name)
+Symbol DeclClass(const char * name)
 {
    if(strchr(name, ':'))
-      return _DeclClass(symbolID, name);
+      return _DeclClass(name);
    else
-      return DeclClassAddNameSpace(symbolID, name);
+      return DeclClassAddNameSpace(name);
 }
 
-Symbol _DeclClass(int symbolID, char * name)
+Symbol _DeclClass(const char * name)
 {
    Symbol symbol = FindClass(name);
    if(!symbol)
@@ -1767,7 +1781,7 @@ Symbol _DeclClass(int symbolID, char * name)
       for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
       if(classContext)
       {
-         
+
       }
       */
       if(name[0] == ':' && name[1] == ':')
@@ -1775,7 +1789,7 @@ Symbol _DeclClass(int symbolID, char * name)
       symbol = Symbol
       {
          string = CopyString(name);
-         idCode = symbolID, id = symbolID;
+         // notYetDeclared = true;
       };
       if(!globalContext.classes.Add((BTNode)symbol))
          excludedSymbols->Add(symbol);
@@ -1795,8 +1809,6 @@ Symbol _DeclClass(int symbolID, char * name)
             symbol.shortName = CopyString(name + start);
       }
    }
-   if(symbolID)
-      symbol.idCode = symbol.id = symbolID;
    return symbol;
 }
 
@@ -1810,9 +1822,9 @@ void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
       strcpy(name, ((Specifier)baseSpecs.first).name);
       tpl = strchr(name, '<');
       if(tpl) *tpl = 0;
-      
+
       baseClass = FindClass(name);
-      if(baseClass.ctx)
+      if(baseClass && baseClass.ctx)
       {
          TemplatedType copy;
          for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
@@ -1822,7 +1834,7 @@ void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
                delete type;
          }
       }
-      else if(baseClass.registered)
+      else if(baseClass && baseClass.registered)
       {
          Class sClass;
          for(sClass = baseClass.registered; sClass; sClass = sClass.base)
@@ -1841,7 +1853,7 @@ void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
                   {
                      p.param = param = TemplateParameter
                      {
-                        identifier = MkIdentifier(p.name), type = p.type, 
+                        identifier = MkIdentifier(p.name), type = p.type,
                         dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
                      };
                   }
@@ -1881,7 +1893,7 @@ ClassDefinition MkClass(Symbol symbol, OldList baseSpecs, OldList definitions)
       delete symbol.ctx;
    }
    symbol.ctx = curContext;
-   classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
+   classDef = { symbol = symbol, _class = MkSpecifierName(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
    curContext.classDef = classDef;
    return classDef;
 }
@@ -1922,30 +1934,27 @@ PropertyDef MkProperty(OldList specs, Declarator decl, Identifier id, Statement
       string = CopyString(id.string);
       type = type;
    };
-   symbol.idCode = symbol.id = globalContext.nextID++;
    excludedSymbols->Add(symbol);
-   globalContext.nextID++;
-   globalContext.nextID++;
    prop.symbol = symbol;
    return prop;
 }
 
 ClassDef MkClassDefProperty(PropertyDef propertyDef)
 {
-   return { type = propertyClassDef, propertyDef = propertyDef };
+   return { type = propertyClassDef, propertyDef = propertyDef, loc = yylloc };
 }
 
 ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
 {
-   return { type = classPropertyClassDef, propertyDef = propertyDef };
+   return { type = classPropertyClassDef, propertyDef = propertyDef, loc = yylloc };
 }
 
 ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
 {
-   return { type = classPropertyValueClassDef, id = id, initializer = initializer };
+   return { type = classPropertyValueClassDef, id = id, initializer = initializer, loc = yylloc };
 }
 
-int CheckType(char * text)
+int CheckType(const char * text)
 {
 #ifdef _TIMINGS
    Time startTime = GetTime();
@@ -1994,10 +2003,10 @@ void PopContext(Context ctx)
    curContext = ctx.parent;
 }
 
-Symbol FindType(Context ctx, char * name)
+Symbol FindType(Context ctx, const char * name)
 {
    Symbol type = null;
-   if(curContext)
+   if(ctx)
    {
       //char output[8192];
       type = (Symbol)ctx.types.FindString(name);
@@ -2012,7 +2021,19 @@ Symbol FindType(Context ctx, char * name)
    return type;
 }
 
-TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
+Symbol FindStruct(Context ctx, const char * name)
+{
+   Symbol type = null;
+   if(ctx)
+   {
+      type = (Symbol)ctx.structSymbols.FindString(name);
+      if(!type && ctx.parent)
+         type = FindStruct(ctx.parent, name);
+   }
+   return type;
+}
+
+TemplatedType FindTemplateTypeParameter(Context ctx, const char * name)
 {
    TemplatedType templatedType = null;
    if(curContext)
@@ -2027,7 +2048,7 @@ TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
 bool ModuleAccess(Module searchIn, Module searchFor)
 {
    SubModule subModule;
-   
+
    if(searchFor == searchIn)
       return true;
 
@@ -2052,8 +2073,8 @@ ModuleImport FindModule(Module moduleToFind)
          break;
    if(!module)
    {
-      module = ModuleImport 
-      { 
+      module = ModuleImport
+      {
          name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
          importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
       };
@@ -2070,7 +2091,7 @@ static void GetFullClassNameSpace(NameSpace * ns, char * name)
    {
       GetFullClassNameSpace(ns->parent, name);
       strcat(name, ns->name);
-      strcat(name, "::");      
+      strcat(name, "::");
    }
 }
 
@@ -2084,9 +2105,9 @@ static char * GetFullClassName(Class c, char * name)
 }
 */
 
-public Symbol FindClass(char * name)
+public Symbol FindClass(const char * name)
 {
-#ifdef _DEBUG
+#ifdef _TIMINGS
    Time startTime = GetTime();
 #endif
    Symbol cl = null;
@@ -2154,7 +2175,7 @@ public Symbol FindClass(char * name)
          }
          */
          if(cl.shortName && !strcmp(cl.shortName, name))
-            break;            
+            break;
       }
 #ifdef _TIMINGS
       findClassIgnoreNSTotalTime += GetTime() - startTime;
@@ -2179,8 +2200,7 @@ public Symbol FindClass(char * name)
             {
                string = CopyString(name);
                registered = _class;
-               id = MAXINT;
-               idCode = MAXINT;
+               notYetDeclared = true;
                imported = true;
             };
             _class.symbol = cl;
@@ -2205,17 +2225,18 @@ void CopyTypeInto(Type type, Type src)
 {
    type = *src;
    type.name = CopyString(src.name);
+   type.typeName = CopyString(src.typeName);
    type.refCount = 1;
 
    if(src.kind == enumType)
    {
-      NamedLink member;
+      NamedLink64 member;
 
       type.members.Clear();
       // This must have been a mistake: member = **type**.members.first
       for(member = src.members.first; member; member = member.next)
       {
-         type.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
+         type.members.Add(NamedLink64 { name = CopyString(member.name), data = member.data });
       }
       type.enumName = CopyString(src.enumName);
    }
@@ -2242,7 +2263,6 @@ void CopyTypeInto(Type type, Type src)
          if(type.arraySizeExp)
             type.arraySizeExp = CopyExpression(type.arraySizeExp);
       }
-
    }
 }
 
@@ -2261,7 +2281,6 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
             ExtDecl extDecl = spec.extDecl;
             if(extDecl.type == extDeclString)
             {
-               String s = spec.extDecl.s;
                if(!strcmp(spec.extDecl.s, "__declspec(dllexport)") || !strcmp(spec.extDecl.s, "dllexport"))
                   specType.dllExport = true;
                else if(!strcmp(spec.extDecl.s, "__declspec(stdcall)") || !strcmp(spec.extDecl.s, "stdcall"))
@@ -2307,12 +2326,14 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
             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 && !isLong) specType.kind = intType; }
+            else if(spec.specifier == _BOOL || spec.specifier == BOOL)
+               specType.kind = _BoolType;
             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) 
+            else if(spec.specifier == VALIST)
                specType.kind = vaListType;
             else if(spec.specifier == SHORT) specType.kind = shortType;
-            else if(spec.specifier == LONG) 
+            else if(spec.specifier == LONG)
             {
                if(isLong || (targetBits == 64 && targetPlatform != win32))
                   specType.kind = int64Type;
@@ -2327,7 +2348,7 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
             else if(spec.specifier == CONST)
                specType.constant = true;
             else if(spec.specifier == TYPED_OBJECT || spec.specifier == ANY_OBJECT || spec.specifier == CLASS)
-            { 
+            {
                switch(spec.specifier)
                {
                   case TYPED_OBJECT:   specType.classObjectType = typedObject;   break;
@@ -2359,12 +2380,15 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
                Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
                if(symbol && symbol.type)
                {
+                  // Keep constant qualifier
+                  bool isConstant = specType.constant;
                   // Free Type Contents:
                   Type dummy { };
                   *dummy = *specType;
                   FreeType(dummy);
 
                   CopyTypeInto(specType, symbol.type);
+                  specType.constant = isConstant;
                   specType.typeName = CopyString(symbol.type.name);
                }
                else if(!isTypedef) // !specType.kind)    // TESTING THIS FOR enum / typedef problem
@@ -2385,11 +2409,11 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
             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) };
+                  NamedLink64 i { name = CopyString(e.id.string) };
+                  if(e.exp && e.exp.type == constantExp && e.exp.constant)
+                     i.data = strtoll(e.exp.constant, null, 0);
                   specType.members.Add(i);
                }
             }
@@ -2404,19 +2428,21 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
             Symbol _class = spec.id ? FindClass(spec.id.string) : null;
             if(_class)
             {
+               specType.declaredWithStruct = true;
                if(!_class.registered || _class.registered.type != structClass)
-                  specType.directClassAccess = true;
+                  specType.directClassAccess = true;     // TODO: Need to clarify what 'directClassAccess' is about
                specType._class = _class;
                specType.kind = classType;
                break;
             }
+            specType.members.Clear();
             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 
+               // 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;
@@ -2430,12 +2456,12 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
 
                      if(symbol.type.kind == enumType)
                      {
-                        NamedLink member;
+                        NamedLink64 member;
 
                         specType.members.Clear();
                         for(member = symbol.type.members.first; member; member = member.next)
                         {
-                           NamedLink item { name = CopyString(member.name), data = member.data };
+                           NamedLink64 item { name = CopyString(member.name), data = member.data };
                            specType.members.Add(item);
                         }
                      }
@@ -2500,14 +2526,14 @@ static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeNa
          }
          else if(spec.type == subClassSpecifier)
          {
-            specType.kind = specType.kind = subClassType;
+            specType.kind = subClassType;
             specType._class = spec._class.symbol;
          }
       }
    }
    else if(assumeEllipsis)
       specType.kind = ellipsisType;
-   return specType;     
+   return specType;
 }
 
 static Type ProcessTypeDecls(OldList specs, Declarator decl, Type parentType)
@@ -2593,7 +2619,7 @@ static Type ProcessTypeDecls(OldList specs, Declarator decl, Type parentType)
          {
             type = { refCount = 1, kind = arrayType, arraySizeExp = CopyExpression(decl.array.exp), freeExp = true, type = type, dllExport = type.dllExport, attrStdcall = type.attrStdcall };
             if(decl.array.enumClass)
-               type.enumClass = decl.array.enumClass.symbol; 
+               type.enumClass = decl.array.enumClass.symbol;
             break;
          }
          case pointerDeclarator:
@@ -2701,7 +2727,7 @@ public Type ProcessType(OldList specs, Declarator decl)
    return ProcessTypeDecls(specs, decl, null);
 }
 
-public Type ProcessTypeString(char * string, bool staticMethod)
+public Type ProcessTypeString(const char * string, bool staticMethod)
 {
    OldList * specs = MkList();
    Declarator decl = SpecDeclFromString(string, specs, null);
@@ -2728,7 +2754,7 @@ Type MkClassTypeSymbol(Symbol symbol)
    return null;
 }
 
-public Type MkClassType(char * name)
+public Type MkClassType(const char * name)
 {
    if(name)
    {
@@ -2744,15 +2770,15 @@ public Type MkClassType(char * name)
    return null;
 }
 
-AsmField MkAsmField(char * command, Expression expression)
+AsmField MkAsmField(char * command, Expression expression, Identifier symbolic)
 {
-   return { command = command, expression = expression };
+   return { command = command, expression = expression, symbolic = symbolic };
 }
 
 Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
 {
-   return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements, 
-      asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields, 
+   return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
+      asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
       asmStmt.clobberedFields = clobberedFields };
 }
 
@@ -2847,7 +2873,7 @@ Expression MkExpArray(OldList * expressions)
    return { type = arrayExp, list = expressions };
 }
 
-Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplateParameterType tplType)
+Expression GetTemplateArgExpByName(const char * paramName, Class curClass, TemplateParameterType tplType)
 {
    Expression argExp = null;
    Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
@@ -2879,20 +2905,18 @@ Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplatePar
       {
          char idString[32];
          char className[1024];
-         Expression classExp;
-         
+
          sprintf(idString, "%d", id);
          strcpy(className, "__ecereClass_");
          FullClassNameCat(className, _class.fullName, true);
-         MangleClassName(className);
-         DeclareClass(FindClass(_class.fullName), className);
+         DeclareClass(curExternal, FindClass(_class.fullName), className);
 
          argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
-               (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/, 
+               (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
                MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
       }
    }
-   return argExp; 
+   return argExp;
 }
 
 Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
@@ -2900,7 +2924,7 @@ Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool point
    return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
 }
 
-/*char * CreateMsgID(char * string, char * context)
+/*char * CreateMsgID(const char * string, const char * context)
 {
    int lenString = strlen(string), lenContext = strlen(context);
    char * msgid = new char[lenString + lenContext + 20];
@@ -2915,8 +2939,8 @@ public void OutputIntlStrings()
 {
    if(intlStrings.count)
    {
-      char * srcFile = GetSourceFile();
-      char * objFile = GetOutputFile();
+      const char * srcFile = GetSourceFile();
+      const char * objFile = GetOutputFile();
       char srcFileFixed[MAX_LOCATION];
       char potFile[MAX_LOCATION];
       File f;
@@ -2924,11 +2948,12 @@ public void OutputIntlStrings()
       f = FileOpen(potFile, write);
       if(f)
       {
-         char * filePrefix = "";
+         const char * filePrefix = "";
          if(!(srcFile[0] && (srcFile[1] == ':' || srcFile[0] == '/')))
-            filePrefix = "./"; //(GetRuntimePlatform() == win32) ? ".\\" : "./";
+            filePrefix = "./"; //(__runtimePlatform == win32) ? ".\\" : "./";
          // GetSystemPathBuffer(srcFileFixed, srcFile);
          GetSlashPathBuffer(srcFileFixed, srcFile);
+
          for(s : intlStrings)
          {
             // TOFIX: (#654) ContextStringPair * pair = &s;
@@ -2949,6 +2974,7 @@ public void OutputIntlStrings()
 
 default extern OldList * ast;
 default extern int yyparse ();
+default extern int yylex ();
 
 public void SetAST(OldList * list) { ast = list; }
 public OldList * GetAST() { return ast; }
@@ -2956,3 +2982,13 @@ public void ParseEc()
 {
    yyparse();
 }
+
+public int LexEc()
+{
+   return yylex();
+}
+
+public const char * GetYYText()
+{
+   return yytext;
+}