compiler/libec: Fixed crash on inheriting off a struct
[sdk] / compiler / libec / src / ast.ec
index 27e523a..341bd9d 100644 (file)
@@ -1015,7 +1015,7 @@ Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifi
             }
             if(s)
             {
-               decl.declarators = declarators = MkListOne(MkDeclaratorIdentifier(MkIdentifier(s)));
+               decl.declarators = declarators = MkListOne(MkStructDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
                specifiers.Remove(spec);
                FreeSpecifier(spec);
                spec = null;
@@ -1812,7 +1812,7 @@ void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
       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 +1822,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)
@@ -2404,12 +2404,14 @@ 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)
@@ -2949,6 +2951,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 +2959,13 @@ public void ParseEc()
 {
    yyparse();
 }
+
+public int LexEc()
+{
+   return yylex();
+}
+
+public const char * GetYYText()
+{
+   return yytext;
+}