if(!list) list = eInstance_New(c);
list.Add(e);
}
- if(peekToken().type == sep)
+ if(sep && peekToken().type == sep)
readToken();
- else
+ else if(sep || peekToken().type == '}')
break;
}
return list;
-/*
-public class ClassFunction : struct
-{
-public:
- ClassFunction prev, next;
- Location loc;
- OldList * specifiers;
- ASTDeclarator declarator;
- OldList * declarations;
- Statement body;
- Class _class;
- OldList attached; // For IDE
- AccessMode declMode;
-
- // COMPILING DATA
- Type type;
- Symbol propSet;
-
- bool isVirtual;
- bool isConstructor, isDestructor;
- bool dontMangle;
- int id, idCode;
-};
+import "externals"
+/*
public class MembersInit : struct
{
public:
bool variable;
bool takeOutExp;
};
+*/
-public class ClassDefinition : struct
+/*
+public class ASTClassDefinition : struct
{
public:
- ClassDefinition prev, next;
- Location loc;
- Specifier _class;
- // Specifier base;
- OldList * baseSpecs;
- OldList * definitions;
+ ASTSpecifier _class;
+ SpecsList baseSpecs;
+ SpecsList definitions;
Symbol symbol;
Location blockStart;
Location nameLoc;
bool isWatchable;
Expression category;
};
+*/
-public class ClassDef : struct
+public class ClassDefList : ASTList<ASTClassDef>
{
-public:
- ClassDef prev, next;
- Location loc;
- ClassDefType type;
- union
+ ClassDefList ::parse()
{
- Declaration decl;
- ClassFunction function;
- OldList * defProperties;
- PropertyDef propertyDef;
- ASTPropertyWatch propertyWatch;
- char * designer;
- Identifier defaultProperty;
- struct
- {
- Identifier id;
- Initializer initializer;
- };
- };
+ return (ClassDefList)ASTList::parse(class(ClassDefList), ASTClassDef::parse, 0);
+ }
+
+ void printSep()
+ {
+ PrintLn("");
+ }
+}
+
+public class ASTClassDef : ASTNode
+{
+public:
AccessMode memberAccess;
// IDE
void * object;
+
+ ASTClassDef ::parse()
+ {
+ SpecsList specs = SpecsList::parse();
+ InitDeclList decls = InitDeclList::parse();
+
+ if(peekToken().type == '{')
+ return ClassDefFunction::parse(specs, decls);
+ else if(specs || decls)
+ return ClassDefDeclaration::parse(specs, decls);
+ else
+ {
+ readToken(); // Error
+ return null;
+ }
+ }
};
+
+public class ClassDefClassPropertyValue : ASTClassDef
+{
+ ASTIdentifier id;
+ ASTInitializer initializer;
+}
+
+public class ClassDefDeclaration : ASTClassDef
+{
+ ASTDeclaration decl;
+
+ ClassDefDeclaration ::parse(SpecsList specs, InitDeclList decls)
+ {
+ ASTDeclaration decl = ASTDeclaration::parse(specs, decls);
+ if(decl)
+ {
+ return { decl = decl };
+ }
+ return null;
+ }
+
+ void print()
+ {
+ printIndent();
+ if(decl) decl.print();
+ }
+}
+
+public class ASTClassFunction : ASTFunctionDefinition
+{
+public:
+ Class _class;
+ //List attached; // For IDE
+ AccessMode declMode;
+
+ // COMPILING DATA
+ Type type;
+ Symbol propSet;
+
+ bool isVirtual;
+ bool isConstructor, isDestructor;
+ bool dontMangle;
+ // int id, idCode;
+
+ ASTClassFunction ::parse(SpecsList specs, InitDeclList decls)
+ {
+ return (ASTClassFunction)ASTFunctionDefinition::parse(specs, decls);
+ }
+};
+
+public class ClassDefFunction : ASTClassDef
+{
+ ASTClassFunction function;
+
+ ClassDefFunction ::parse(SpecsList specs, InitDeclList decls)
+ {
+ ASTClassFunction function = ASTClassFunction::parse(specs, decls);
+ if(function)
+ {
+ return { function = function };
+ }
+ return null;
+ }
+
+ void print()
+ {
+ if(function) function.print();
+ }
+}
+
+/*
+ List<ASTMemberInit> defProperties;
+ ASTPropertyDef propertyDef;
+ ASTPropertyWatch propertyWatch;
+ String designer;
+ ASTIdentifier defaultProperty;
*/
}
}
+public class DeclStruct : ASTDeclarator
+{
+ ASTDeclarator declarator;
+ Expression exp;
+ Expression posExp;
+ Attrib attrib;
+
+ DeclStruct ::parse()
+ {
+ return { declarator = ASTDeclarator::parse(); };
+ }
+}
+
/*
union
{
struct
{
- Expression exp;
- Expression posExp;
- Attrib attrib;
} structDecl;
struct
{
void print()
{
PrintLn("");
+ printIndent();
if(specifiers)
{
for(s : specifiers)
ASTDeclarator decl = (decls && decls[0]) ? decls[0].declarator : null;
if(decl && decls[0]) decls[0].declarator = null;
delete decls;
- function.specifiers = (void *)specs; // TOFIX: #768
+ function.specifiers = specs;
function.declarator = decl;
function.body = StmtCompound::parse();
return function;
return isQualifier || this == CHAR || this == SHORT || this == INT || this == UINT || this == INT64 || this == LONG || this == SIGNED ||
this == UNSIGNED || this == FLOAT || this == DOUBLE || this == VOID ||
this == VALIST || this == THISCLASS || this == TYPED_OBJECT || this == ANY_OBJECT ||
- this == TYPEDEF || this == STRUCT || this == UNION || this == ENUM ||
+ this == TYPEDEF || this == STRUCT || this == CLASS || this == UNION || this == ENUM ||
this == TYPEOF || this == SUBCLASS;
}
}
case STRUCT: Print("struct"); break;
case UNION: Print("union"); break;
case ENUM: Print("enum"); break;
+ case CLASS: Print("class"); break;
case TYPEOF: Print("typeof"); break;
case SUBCLASS: Print("subclass"); break;
import "astNode"
+import "classes"
// Specifiers
public class ASTSpecifier : ASTNode
{
public:
- SpecifierType type;
/* struct
{
//ExtDecl extDecl;
//Symbol symbol;
//OldList * templateArgs;
};
- struct
- {
- Identifier id;
- OldList * list;
- OldList * baseSpecs;
- OldList * definitions;
- bool addNameSpace;
- Context ctx;
- ExtDecl extDeclStruct;
- };
Expression expression;
NewSpecifier _class;
TemplateParameter templateParameter;
while(true)
{
peekToken();
- if(nextToken.type.isSpecifier)
+ if(nextToken.type == STRUCT || nextToken.type == UNION)
+ {
+ ASTSpecifier s = SpecClass::parse();
+ if(s)
+ {
+ if(!specs) specs = { };
+ specs.Add(s);
+ }
+ break;
+ }
+ else if(nextToken.type.isSpecifier)
{
readToken();
if(!specs) specs = { };
}
}
+public class ASTEnumerator : struct
+{
+public:
+ ASTIdentifier id;
+ ASTExpression exp;
+};
+
+public class SpecClass : ASTSpecifier
+{
+ TokenType type;
+ ASTIdentifier id;
+ List<ASTEnumerator> enumerators;
+ SpecsList baseSpecs;
+ ClassDefList definitions;
+ bool addNameSpace;
+ Context ctx;
+ // ExtDecl extDeclStruct;
+
+ SpecClass ::parse()
+ {
+ SpecClass spec { };
+ spec.type = readToken().type;
+ if(peekToken().type == IDENTIFIER)
+ spec.id = ASTIdentifier::parse();
+ if(peekToken().type == '{')
+ {
+ readToken();
+ spec.definitions = ClassDefList::parse();
+ if(peekToken().type == '}')
+ readToken();
+ }
+ return spec;
+ }
+
+ void print()
+ {
+ type.print();
+ Print(" ");
+ if(id) id.print();
+ if(definitions)
+ {
+ PrintLn("\n{");
+ indent++;
+ definitions.print();
+ indent--;
+ Print("\n}");
+ }
+ }
+}
+
/*
public class Attribute : struct
{
};
}
*/
-
-/*
-public class Enumerator : struct
-{
-public:
- Enumerator prev, next;
- Location loc;
- Identifier id;
- Expression exp;
-};
-*/
}
}
int indent;
-void PrintIndent()
+void printIndent()
{
int i;
for(i = 0; i < indent; i++)
void print()
{
+ printIndent();
PrintLn("{");
indent++;
if(declarations)
{
for(d : declarations)
{
- PrintIndent();
+ printIndent();
d.print();
PrintLn("");
}
if(s._class == class(StmtCase))
indent = caseIndent;
if(s._class != class(StmtLabeled))
- PrintIndent();
+ printIndent();
s.print();
if(s._class == class(StmtExpression))
PrintLn("");
indent--;
if(indent == caseIndent)
indent--;
- PrintIndent();
+ printIndent();
PrintLn("}");
}
if(stmt)
{
if(stmt._class != class(StmtCompound)) indent++;
- PrintIndent();
+ printIndent();
stmt.print();
if(stmt._class == class(StmtExpression)) PrintLn("");
if(stmt._class != class(StmtCompound)) indent--;
}
if(elseStmt)
{
- PrintIndent();
+ printIndent();
Print("else");
if(elseStmt._class != class(StmtCompound)) { PrintLn(""); indent++; }
- PrintIndent();
+ printIndent();
if(elseStmt._class != class(StmtCompound)) elseStmt.print();
if(elseStmt._class == class(StmtExpression)) PrintLn("");
indent--;
if(stmt)
{
caseIndent = indent+1;
- PrintIndent();
stmt.print();
indent = caseIndent-1;
}
if(stmt)
{
if(stmt._class != class(StmtCompound)) indent++;
- PrintIndent();
+ printIndent();
stmt.print();
if(stmt._class == class(StmtExpression)) PrintLn("");
}
if(stmt)
{
if(stmt._class != class(StmtCompound)) indent++;
- PrintIndent();
+ printIndent();
stmt.print();
if(stmt._class == class(StmtExpression)) PrintLn("");
if(stmt._class != class(StmtCompound)) indent--;
void print()
{
- if(decl) decl.print();
+ if(decl) { decl.print(); PrintLn(""); }
}
}
+struct InventoryItem
+{
+ float price;
+ String name;
+
+ void Print()
+ {
+ int a;
+ PrintLn(a + 4);
+ }
+} item, * itemPtr;
+
+class SomeClass
+{
+
+}
+
int a;
+typedef int bla;
+
int SomeFunction(int * p)
{
int b[3][4] =
int c, d, e = 4;
const String name = "Foo";
b * a;
+ bla blo;
b = ((a + 3) * a) - (3.1415 * 180 / a);
a = b = 5*(2 + 10);