3 #define YYLTYPE Location
7 char * defaultNameSpace;
8 int defaultNameSpaceLen;
9 public void SetDefaultNameSpace(char * s) { defaultNameSpace = s; defaultNameSpaceLen = s ? strlen(s) : 0; }
11 bool strictNameSpaces;
12 public void SetStrictNameSpaces(bool b) { strictNameSpaces = b; }
14 AccessMode declMode = privateAccess;
15 public void SetDeclMode(AccessMode accessMode) { declMode = accessMode; }
16 AccessMode defaultDeclMode = privateAccess;
17 public void SetDefaultDeclMode(AccessMode accessMode) { defaultDeclMode = accessMode; }
19 char * currentNameSpace;
20 int currentNameSpaceLen;
21 public void SetCurrentNameSpace(char * s) { currentNameSpace = s; currentNameSpaceLen = s ? strlen(s) : 0; }
24 Time findClassTotalTime;
25 Time checkTypeTotalTime;
26 Time externalImportTotalTime;
27 Time findClassIgnoreNSTotalTime;
30 public OldList * MkList()
32 return new0 OldList[1];
35 public OldList * MkListOne(void * item)
37 OldList * list = new0 OldList[1];
42 void ListAdd(OldList list, void * item)
48 void ListAddFront(OldList list, void * item)
51 list.Insert(null, item);
54 public Identifier MkIdentifier(char * string)
59 id._class = null; // Default class...
64 bool gotColon = false;
65 for(c = strlen(string)-1; c >= 0; c--)
72 namePart = string+c+1;
73 while(c >= 0 && string[c] == ':') c--;
79 memcpy(name, string, c+1);
81 // TODO: Do these better, keep in string?
82 if(!strcmp(name, "typed_object"))
84 id._class = MkSpecifierName("class");
85 id.string = CopyString(namePart);
87 else if(!strcmp(name, "property"))
89 id._class = MkSpecifierName("property");
90 id.string = CopyString(namePart);
92 else if(!strcmp(name, "typed_object&"))
94 id._class = MkSpecifierName("typed_object&");
95 id.string = CopyString(namePart);
97 else if(!strcmp(name, "any_object"))
99 id._class = MkSpecifierName("any_object");
100 id.string = CopyString(namePart);
104 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
107 id._class = Specifier { type = templateTypeSpecifier, templateParameter = templatedType.param };
108 //id._class = MkSpecifierName(name);
109 id.string = CopyString(namePart);
113 symbol = FindClass(name);
116 id._class = _MkSpecifierName(symbol.string, symbol, null);
117 id.string = CopyString(namePart);
120 id.string = CopyString(string);
126 id._class = MkSpecifierName(null);
127 id.string = CopyString(namePart);
130 id.string = CopyString(string);
133 id.string = CopyString("");
137 public TemplateParameter MkTypeTemplateParameter(Identifier identifier, TemplateDatatype baseTplDatatype, TemplateArgument defaultArgument)
139 if(identifier.string)
141 TemplateParameter param { type = TemplateParameterType::type, identifier = identifier, dataType = baseTplDatatype, defaultArgument = defaultArgument };
142 TemplatedType type { key = (uintptr)identifier.string, param = param };
143 if(!curContext.templateTypes.Add((BTNode)type))
150 public TemplateParameter MkIdentifierTemplateParameter(Identifier identifier, TemplateMemberType memberType, TemplateArgument defaultArgument)
152 if(identifier.string)
154 TemplateParameter param { type = TemplateParameterType::identifier, identifier = identifier, memberType = memberType, defaultArgument = defaultArgument };
160 public TemplateParameter MkExpressionTemplateParameter(Identifier identifier, TemplateDatatype dataType, TemplateArgument defaultArgument)
162 if(identifier.string)
164 TemplateParameter param { type = TemplateParameterType::expression, identifier = identifier, dataType = dataType, defaultArgument = defaultArgument };
170 public TemplateDatatype MkTemplateDatatype(OldList * specifiers, Declarator decl)
172 TemplateDatatype datatype { specifiers = specifiers, decl = decl };
176 public TemplateArgument MkTemplateTypeArgument(TemplateDatatype tplDatatype)
178 TemplateArgument argument { type = type, templateDatatype = tplDatatype };
182 public TemplateArgument MkTemplateExpressionArgument(Expression expr)
184 TemplateArgument argument { type = expression, expression = expr };
188 public TemplateArgument MkTemplateIdentifierArgument(Identifier ident)
190 TemplateArgument argument { type = identifier, identifier = ident };
194 Expression MkExpExtensionCompound(Statement compound)
196 return { type = extensionCompoundExp, compound = compound };
199 Expression MkExpExtensionExpression(OldList * expressions)
201 return { type = extensionExpressionExp, list = expressions, loc = yylloc };
204 Expression MkExpExtensionInitializer(TypeName typeName, Initializer initializer)
206 return { type = extensionInitializerExp, initializer.typeName = typeName, initializer.initializer = initializer, loc = yylloc };
209 public Expression MkExpIdentifier(Identifier id)
211 return { type = identifierExp, identifier = id };
214 public Expression MkExpDummy()
216 Expression exp { type = dummyExp };
220 public Expression MkExpConstant(char * string)
222 return { type = constantExp, constant = CopyString(string) };
225 Expression MkExpString(char * string)
227 return { type = stringExp, string = CopyString(string) };
230 // TODO: String is case sensitive..
231 // What should we do about it?
232 /*public class CaseSensitiveString : String
234 int OnCompare(CaseSensitiveString string2)
238 result = strcmpi(this, string2);
239 else if(!this && string2)
241 else if(this && !string2)
247 public struct ContextStringPair
249 String string, context;
251 // TODO: Should this be automated somehow?
258 int OnCompare(ContextStringPair b)
261 result = (string && b.string) ? strcmp(string, b.string) :
262 (!string && b.string) ? 1 : (string && !b.string) ? -1 : 0;
263 if(result) return result;
265 result = (context && b.context) ? strcmp(context, b.context) :
266 (!context && b.context) ? 1 : (context && !b.context) ? -1 : 0;
267 // TODO: Support these
268 // result = CaseSensitiveString::OnCompare(string, b.string);
269 // result = ((CaseSensitiveString)string).OnCompare(b.string);
274 Map<ContextStringPair, List<Location> > intlStrings { };
276 Expression MkExpIntlString(char * string, char * context)
278 OldList * list = MkList();
281 ContextStringPair pair { };
283 int len = strlen(string);
285 pair.string = new byte[len-2+1]; memcpy(pair.string, string+1, len-2); pair.string[len-2] = '\0';
286 if(context) { len = strlen(context); pair.context = new byte[len-2+1]; memcpy(pair.context, context+1, len-2); pair.context[len-2] = '\0'; }
288 list = intlStrings[pair];
292 intlStrings[pair] = list;
301 ListAdd(list, QMkExpId("__thisModule"));
302 ListAdd(list, MkExpString(string));
305 int lenString = strlen(string), lenContext = strlen(context);
306 char * msgid = new char[lenString-2 + lenContext-2 + 4];
308 memcpy(msgid+1, context+1, lenContext-2);
309 msgid[1+lenContext-2] = 4; // EOT
310 memcpy(msgid+1+lenContext-2+1, string+1, lenString-2);
311 memcpy(msgid+1+lenContext-2+1+lenString-2, "\"", 2);
312 ListAdd(list, MkExpString(msgid));
316 ListAdd(list, QMkExpId("null"));
317 return MkExpCall(QMkExpId("GetTranslatedString"), list);
320 Expression MkExpOp(Expression exp1, int op, Expression exp2)
331 exp.loc.start = exp1 ? exp1.loc.start : exp2.loc.start;
332 exp.loc.end = exp2 ? exp2.loc.end : exp1.loc.end;
337 Expression MkExpBrackets(OldList expressions)
344 if(expressions && expressions.first)
346 exp.loc.start = ((Expression)expressions.first).loc.start;
347 exp.loc.end = ((Expression)expressions.last).loc.end;
352 Expression MkExpIndex(Expression expression, OldList index)
354 return { type = indexExp, index.exp = expression, index.index = index };
357 Expression MkExpCall(Expression expression, OldList arguments)
359 return { type = callExp, call.exp = expression, call.arguments = arguments };
362 Expression MkExpMember(Expression expression, Identifier member)
364 return { type = memberExp, member.exp = expression, member.member = member };
367 Expression MkExpPointer(Expression expression, Identifier member)
369 return { type = pointerExp, member.exp = expression, member.member = member };
372 Expression MkExpTypeSize(TypeName typeName)
374 return { type = typeSizeExp, typeName = typeName };
377 Expression MkExpTypeAlign(TypeName typeName)
379 return { type = typeAlignExp, typeName = typeName };
382 Expression MkExpClassSize(Specifier _class)
384 return { type = classSizeExp, _class = _class };
387 Expression MkExpCast(TypeName typeName, Expression expression)
389 return { type = castExp, cast.typeName = typeName, cast.exp = expression };
392 Expression MkExpCondition(Expression cond, OldList expressions, Expression elseExp)
394 return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp };
397 Expression MkExpRenew(Expression memExp, TypeName type, Expression size)
399 return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
402 Expression MkExpRenew0(Expression memExp, TypeName type, Expression size)
404 return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
407 Expression MkExpNew(TypeName type, Expression size)
409 return { type = newExp, _new.typeName = type, _new.size = size };
412 Expression MkExpNew0(TypeName type, Expression size)
414 return { type = new0Exp, _new.typeName = type, _new.size = size };
417 Expression MkExpVaArg(Expression exp, TypeName type)
419 return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type };
422 Specifier MkSpecifier(int specifier)
424 return { type = baseSpecifier, specifier = specifier };
427 Specifier MkSpecifierTypeOf(Expression expression)
429 return { type = typeOfSpecifier, expression = expression };
432 Specifier MkSpecifierSubClass(Specifier _class)
434 return { type = subClassSpecifier, _class = _class };
437 Specifier MkSpecifierExtended(ExtDecl extDecl)
439 return { type = extendedSpecifier, extDecl = extDecl /*name = CopyString(name)*/ };
442 Specifier MkEnum(Identifier id, OldList list)
446 type = enumSpecifier;
450 if(list && (!declMode || !id))
456 type = ProcessType(&specs, null);
460 Symbol symbol { string = CopyString(id.string), isStruct = true, type = type };
462 if(strstr(symbol.string, "::"))
463 curContext.hasNameSpace = true;
464 if(!curContext.structSymbols.Add((BTNode)symbol))
467 for(e = list.first; e; e = e.next)
469 Symbol symbol { string = CopyString(e.id.string), type = type };
471 if(strstr(symbol.string, "::"))
472 curContext.hasNameSpace = true;
473 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
481 Specifier MkStructOrUnion(SpecifierType type, Identifier id, OldList definitions)
483 Specifier spec { type = type, id = id };
484 if(id && FindType(curContext, id.string))
485 declMode = defaultAccess;
486 spec.definitions = definitions;
487 if(definitions && id && !declMode)
492 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specs, null), isStruct = true };
493 if(!curContext.structSymbols.Add((BTNode)symbol))
499 void AddStructDefinitions(Specifier spec, OldList definitions)
501 spec.definitions = definitions;
502 if(definitions && spec.id && !declMode)
507 symbol = Symbol { string = CopyString(spec.id.string), type = ProcessType(specs, null), isStruct = true };
508 if(!curContext.parent.structSymbols.Add((BTNode)symbol))
513 Attribute MkAttribute(String attr, Expression exp)
515 return { attr = attr, exp = exp };
518 Attrib MkAttrib(int type, OldList * attribs)
520 return { type = type, attribs = attribs };
523 ExtDecl MkExtDeclString(String s)
525 return { type = extDeclString, s = s };
529 ExtDecl MkExtDeclAttrib(Attrib attr)
531 return { type = extDeclAttrib, attr = attr };
535 public Declarator MkDeclaratorIdentifier(Identifier id)
537 return { type = identifierDeclarator, identifier = id };
540 Declarator MkDeclaratorFunction(Declarator declarator, OldList parameters)
542 return { type = functionDeclarator, declarator = declarator, function.parameters = parameters };
545 Declarator MkDeclaratorExtended(ExtDecl extended, Declarator declarator)
547 return { type = extendedDeclarator, declarator = declarator, extended.extended = extended };
550 Declarator MkDeclaratorExtendedEnd(ExtDecl extended, Declarator declarator)
552 return { type = extendedDeclaratorEnd, declarator = declarator, extended.extended = extended };
555 Declarator MkStructDeclarator(Declarator declarator, Expression exp)
557 return { type = structDeclarator, declarator = declarator, structDecl.exp = exp };
560 Declarator MkDeclaratorBrackets(Declarator declarator)
562 return { type = bracketsDeclarator, declarator = declarator };
565 Declarator MkDeclaratorArray(Declarator declarator, Expression exp)
567 return { type = arrayDeclarator, declarator = declarator, array.exp = exp };
570 Declarator MkDeclaratorEnumArray(Declarator declarator, Specifier _class)
572 return { type = arrayDeclarator, declarator = declarator, array.enumClass = _class };
575 Declarator MkDeclaratorPointer(Pointer pointer, Declarator declarator)
577 return { type = pointerDeclarator, declarator = declarator, pointer.pointer = pointer };
580 Enumerator MkEnumerator(Identifier id, Expression exp)
582 return { id = id, exp = exp };
585 Pointer MkPointer(OldList qualifiers, Pointer pointer)
587 return { qualifiers = qualifiers, pointer = pointer };
590 Initializer MkInitializerAssignment(Expression exp)
592 /*if(yylloc.start.line == 1)
594 return { type = expInitializer, exp = exp, loc = yylloc };
597 Initializer MkInitializerList(OldList list)
599 /*if(yylloc.start.line == 1)
601 return { type = listInitializer, list = list, loc = yylloc };
604 InitDeclarator MkInitDeclarator(Declarator declarator, Initializer initializer)
606 return { declarator = declarator, initializer = initializer };
609 public TypeName MkTypeName(OldList qualifiers, Declarator declarator)
611 return { qualifiers = qualifiers, declarator = declarator };
614 public Identifier GetDeclId(Declarator decl)
616 while(decl && decl.type != identifierDeclarator)
617 decl = decl.declarator;
618 return decl ? decl.identifier : null;
621 Declaration MkDeclarationClassInst(Instantiation inst)
623 return { type = instDeclaration, inst = inst, loc = yylloc };
626 Declaration MkDeclarationInst(Instantiation inst)
628 Declaration decl { type = instDeclaration, inst = inst, loc = yylloc };
630 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
633 int len = 0, stringLen;
636 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
637 len += defaultNameSpaceLen;
643 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
644 len += currentNameSpaceLen;
649 stringLen = strlen(inst.exp.identifier.string);
650 memcpy(name + len, inst.exp.identifier.string, stringLen);
653 delete inst.exp.identifier.string;
654 inst.exp.identifier.string = CopyString(name);
659 string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
660 type = MkClassTypeSymbol(inst._class.symbol);
662 symbol.idCode = symbol.id = curContext.nextID++;
663 if(strstr(symbol.string, "::"))
664 curContext.hasNameSpace = true;
665 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
666 excludedSymbols->Add(symbol);
667 decl.symbol = inst.symbol = symbol;
671 Declaration MkDeclarationDefine(Identifier id, Expression exp)
673 Declaration decl { type = defineDeclaration, id = id, exp = exp, loc = yylloc };
674 char expString[1024];
677 PrintExpression(exp, expString);
679 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
682 int len = 0, stringLen;
685 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
686 len += defaultNameSpaceLen;
692 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
693 len += currentNameSpaceLen;
697 stringLen = strlen(id.string);
698 memcpy(name + len, id.string, stringLen);
702 id.string = CopyString(name);
705 if(!eSystem_FindDefine(privateModule, id.string))
706 eSystem_RegisterDefine(id.string, expString, privateModule, buildingECERECOMModule ? baseSystemAccess : publicAccess);
708 Compiler_Warning($"Redefinition of %s ignored\n", id.string);
712 Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
714 Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
715 bool variable = true;
717 if(specifiers != null)
720 for(spec = specifiers.first; spec; spec = spec.next)
722 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
724 if(initDeclarators != null)
728 for(d = initDeclarators.first; d; d = d.next)
730 if(GetDeclId(d.declarator).string)
734 string = CopyString(GetDeclId(d.declarator).string);
735 type = ProcessType(specifiers, d.declarator);
737 type.id = type.idCode = curContext.nextID++;
739 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
740 excludedSymbols->Add(type);
741 decl.symbol = d.declarator.symbol = type;
747 for(; spec; spec = spec.next)
749 if(spec.type == nameSpecifier && spec.name)
753 string = CopyString(spec.name);
754 type = ProcessType(specifiers, null);
756 type.id = type.idCode = curContext.nextID++;
757 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
758 excludedSymbols->Add(type);
767 else if(spec.type == baseSpecifier &&
768 (spec.specifier == STRUCT || spec.specifier == UNION))
772 if(variable && initDeclarators)
775 for(d = initDeclarators.first; d; d = d.next)
777 Identifier id = GetDeclId(d.declarator);
778 if(id && id.string && id.string[0])
784 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
787 int len = 0, stringLen;
790 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
791 len += defaultNameSpaceLen;
797 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
798 len += currentNameSpaceLen;
802 stringLen = strlen(id.string);
803 memcpy(name + len, id.string, stringLen);
807 id.string = CopyString(name);
810 // Avoid memory leaks on duplicated symbols (BinaryTree::Add Would Fail)
811 symbol = (Symbol)(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.FindString(id.string);
814 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specifiers, d.declarator) };
815 if(strstr(symbol.string, "::"))
816 curContext.hasNameSpace = true;
817 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
818 excludedSymbols->Add(symbol);
819 // TODO: Add better support to count declarators
820 if(symbol.type && symbol.type.kind == arrayType && !symbol.type.arraySizeExp && d.initializer)
822 if(d.initializer.type == listInitializer)
825 sprintf(string, "%d",d.initializer.list->count);
826 symbol.type.arraySizeExp = MkExpConstant(string);
827 symbol.type.freeExp = true;
829 else if(d.initializer.type == expInitializer && d.initializer.exp.type == stringExp && d.initializer.exp.string)
834 bool escaped = false;
835 char * s = d.initializer.exp.string;
837 // MAKE MORE ACCURATE
838 for(c = 1; (ch = s[c]); c++)
840 if(ch == '\\' && !escaped)
849 sprintf(string, "%d", count);
850 symbol.type.arraySizeExp = MkExpConstant(string);
851 symbol.type.freeExp = true;
854 symbol.id = symbol.idCode = curContext.nextID++;
856 decl.symbol = d.declarator.symbol = symbol;
863 decl.symbol = Symbol { };
864 decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
865 excludedSymbols->Add(decl.symbol);
870 Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifier extStorage)
872 return { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
875 Statement MkLabeledStmt(Identifier id, Statement statement)
877 return { type = labeledStmt, labeled.id = id, labeled.stmt = statement, loc = yylloc };
880 Statement MkCaseStmt(Expression exp, Statement statement)
882 return { type = caseStmt, caseStmt.exp = exp, caseStmt.stmt = statement, loc = yylloc };
885 Statement MkCompoundStmt(OldList declarations, OldList statements)
887 return { type = compoundStmt, compound.declarations = declarations, compound.statements = statements, loc = yylloc };
890 Statement MkExpressionStmt(OldList expressions)
892 return { type = expressionStmt, expressions = expressions, loc = yylloc };
895 Statement MkBadDeclStmt(Declaration decl)
897 return { type = badDeclarationStmt, decl = decl, loc = yylloc };
900 Statement MkIfStmt(OldList exp, Statement statement, Statement elseStmt)
902 return { type = ifStmt, ifStmt.exp = exp, ifStmt.stmt = statement, ifStmt.elseStmt = elseStmt, loc = yylloc };
905 Statement MkSwitchStmt(OldList exp, Statement statement)
907 // To know it's a switch compound... (Don't want declarations in there... bugs)
909 statement.compound.isSwitch = true;
910 return { type = switchStmt, switchStmt.exp = exp, switchStmt.stmt = statement, loc = yylloc };
913 Statement MkWhileStmt(OldList exp, Statement statement)
915 return { type = whileStmt, whileStmt.exp = exp, whileStmt.stmt = statement, loc = yylloc };
918 Statement MkDoWhileStmt(Statement statement, OldList exp)
920 return { type = doWhileStmt, doWhile.exp = exp, doWhile.stmt = statement, loc = yylloc };
923 Statement MkForStmt(Statement init, Statement check, OldList inc, Statement statement)
925 return { type = forStmt, forStmt.init = init, forStmt.check = check, forStmt.increment = inc, forStmt.stmt = statement, loc = yylloc };
928 Statement MkForEachStmt(Identifier id, OldList exp, OldList filter, Statement statement)
930 return { type = forEachStmt, forEachStmt.id = id, forEachStmt.exp = exp, forEachStmt.filter = filter, forEachStmt.stmt = statement, loc = yylloc };
933 Statement MkGotoStmt(Identifier id)
935 return { type = gotoStmt, gotoStmt.id = id, loc = yylloc };
938 Statement MkContinueStmt()
940 return { type = continueStmt, loc = yylloc };
943 Statement MkBreakStmt()
945 return { type = breakStmt, loc = yylloc };
948 Statement MkReturnStmt(OldList exp)
950 return { type = returnStmt, expressions = exp, loc = yylloc };
953 FunctionDefinition MkFunction(OldList specifiers, Declarator declarator, OldList declarationList)
955 return { specifiers = specifiers, declarator = declarator, declarations = declarationList };
958 void ProcessFunctionBody(FunctionDefinition func, Statement body)
960 Declarator declarator = func.declarator;
961 Declarator funcDecl = GetFuncDecl(declarator);
966 if(funcDecl && funcDecl.function.parameters && body)
968 Context context = body.compound.context;
970 for(param = funcDecl.function.parameters->first; param; param = param.next)
974 Symbol symbol = null;
975 Identifier id = GetDeclId(param.declarator);
976 char * string = id ? id.string : null;
979 for(symbol = (Symbol)context.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
980 if(!strcmp(symbol.string, string))
982 // This parameter is not shadowed by a local declaration
985 symbol = Symbol { string = CopyString(id.string), type = ProcessType(param.qualifiers, param.declarator), isParam = true };
986 if(!context.symbols.Add((BTNode)symbol))
987 excludedSymbols->Add(symbol);
989 // TODO: Fix this, the parameters' IDs should really be smaller...
990 symbol.id = context.nextID++;
991 param.declarator.symbol = symbol;
998 if(!declarator.symbol)
1000 Identifier id = GetDeclId(declarator);
1002 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess && strcmp(id.string, "__on_register_module"))
1005 int len = 0, stringLen;
1006 if(defaultNameSpace)
1008 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1009 len += defaultNameSpaceLen;
1013 if(currentNameSpace)
1015 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1016 len += currentNameSpaceLen;
1020 stringLen = strlen(id.string);
1021 memcpy(name + len, id.string, stringLen);
1025 id.string = CopyString(name);
1027 symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
1028 symbol.idCode = symbol.id = globalContext.nextID++;
1029 if(strstr(symbol.string, "::"))
1030 globalContext.hasNameSpace = true;
1031 if(!globalContext.symbols.Add((BTNode)symbol))
1032 excludedSymbols->Add(symbol);
1033 declarator.symbol = symbol;
1037 symbol = declarator.symbol;
1038 excludedSymbols->Remove(declarator.symbol);
1039 delete symbol.string;
1040 symbol.string = CopyString(GetDeclId(declarator).string);
1041 if(strstr(symbol.string, "::"))
1042 globalContext.hasNameSpace = true;
1043 if(!globalContext.symbols.Add((BTNode)symbol))
1044 excludedSymbols->Add(symbol);
1047 symbol.type = ProcessType(func.specifiers, declarator);
1049 if(symbol.type && (symbol.type.kind == functionType || symbol.type.kind == methodType))
1051 if(!symbol.type.params.count)
1053 Type type { refCount = 1 };
1054 symbol.type.params.Add(type);
1063 External MkExternalFunction(FunctionDefinition function)
1065 External external { type = functionExternal, function = function, symbol = function.declarator.symbol };
1066 if(function.specifiers)
1069 for(spec = function.specifiers->first; spec; spec = spec.next)
1070 if(spec.type == baseSpecifier && spec.specifier == STATIC)
1072 declMode = staticAccess;
1077 if(external.symbol && !external.symbol.methodExternal)
1078 external.symbol.methodExternal = external;
1082 External MkExternalImport(char * name, ImportType importType, AccessMode importAccess)
1084 External external { type = importExternal };
1085 int len = strlen(name) - 2;
1086 external.importString = new char[len + 1];
1087 strncpy(external.importString, name+1, len);
1088 external.importString[len] = '\0';
1093 Time startTime = GetTime();
1096 ImportModule(external.importString, importType, importAccess, true);
1097 ImportModule(external.importString, importType, importAccess, false);
1099 time = GetTime() - startTime;
1100 printf("Importing took %.3f seconds for %s\n", time, external.importString);
1101 externalImportTotalTime += time;
1107 External MkExternalDeclaration(Declaration declaration)
1109 External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
1110 InitDeclarator d = (declaration && declaration.declarators) ? declaration.declarators->last : null;
1111 if(declaration && declaration.type == initDeclaration && declaration.specifiers)
1114 for(spec = declaration.specifiers->first; spec; spec = spec.next)
1115 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1117 declMode = defaultAccess;
1120 else if(spec.type == baseSpecifier && spec.specifier == STATIC)
1122 declMode = staticAccess;
1126 if(declaration && declaration.symbol && !declaration.symbol.methodExternal)
1127 declaration.symbol.methodExternal = external;
1131 External MkExternalNameSpace(Identifier identifier)
1133 External external { type = nameSpaceExternal, id = identifier };
1134 currentNameSpace = identifier ? identifier.string : null;
1135 currentNameSpaceLen = currentNameSpace ? strlen(currentNameSpace) : 0;
1139 void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
1141 if(spec.type == nameSpecifier)
1143 Symbol symbol = spec.symbol;
1144 spec.templateArgs = templateArgs;
1145 if(templateArgs && templateArgs.first)
1147 char templateString[1024];
1148 TemplateArgument arg;
1149 strcpy(templateString, symbol ? symbol.string : spec.name);
1150 strcat(templateString, "<");
1151 for(arg = templateArgs.first; arg; arg = arg.next)
1159 char expString[1024];
1160 Class backupThisClass = thisClass;
1162 expString[0] = '\0';
1163 // Will this work here?
1165 Location oldLocation = yylloc;
1166 File backFileInput = fileInput;
1171 // TESTING THIS SCANNER RESUME STUFF
1174 yylloc = oldLocation;
1175 fileInput = backFileInput;
1178 fileInput.Seek(yylloc.start.pos, start);
1179 resetScannerPos(&yylloc.start);
1184 //ProcessExpressionType(arg.expression);
1185 //ComputeExpression(arg.expression);
1186 PrintExpression(arg.expression, expString);
1187 strcat(argument, expString);
1188 thisClass = backupThisClass;
1193 strcat(argument, arg.identifier.string);
1198 char * typeString = StringFromSpecDecl(arg.templateDatatype.specifiers, arg.templateDatatype.decl);
1199 strcat(argument, typeString);
1206 if(arg.prev) strcat(templateString, ", ");
1209 strcat(templateString, arg.name.string);
1210 strcat(templateString, " = ");
1212 strcat(templateString, argument);
1216 int len = strlen(templateString);
1217 if(templateString[len-1] == '>') templateString[len++] = ' ';
1218 templateString[len++] = '>';
1219 templateString[len++] = '\0';
1221 // printf("SetClassTemplateArgs templateString: %s\n", templateString);
1222 symbol = FindClass(templateString);
1223 if(!symbol && spec.symbol)
1225 // If class was only decl'ed, invoke DeclClass on this templated class as well
1226 symbol = _DeclClass(MAXINT, templateString);
1228 // Add a reference to all templated class to the basic class
1230 spec.symbol.templatedClasses.Add(OldLink { data = symbol });
1232 spec.symbol = symbol;
1233 spec.name = CopyString(symbol ? symbol.string : templateString);
1237 FreeList(templateArgs, FreeTemplateArgument);
1240 Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
1242 Specifier spec { type = nameSpecifier };
1248 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
1251 spec.templateParameter = templatedType.param;
1252 spec.type = templateTypeSpecifier;
1256 symbol = FindClass(name);
1258 if(symbol && symbol.registered && symbol.registered.isRemote == 1)
1260 char className[1024];
1261 strcpy(className, "DCOMClient_");
1262 if(!strncmp(name, className, strlen(className)))
1263 spec.name = CopyString(name);
1266 strcat(className, name);
1267 spec.name = CopyString(className);
1271 spec.name = CopyString(symbol.string);
1273 spec.name = CopyString(name);
1274 spec.symbol = symbol;
1275 if(templateArgs != null)
1276 SetClassTemplateArgs(spec, templateArgs);
1281 public Specifier MkSpecifierName(char * name)
1283 return _MkSpecifierName(name, null, null);
1286 public Specifier MkSpecifierNameArgs(char * name, OldList * templateArgs)
1288 return _MkSpecifierName(name, null, templateArgs);
1292 Specifier MkClassName(char * string)
1294 return { type = SpecifierClass, name = CopyString(string) };
1297 ClassFunction MkClassFunction(OldList specifiers, Specifier _class, Declarator decl, OldList declList)
1299 return { specifiers = specifiers, /*_class = _class,*/ declarator = decl, declarations = declList };
1302 void ProcessClassFunctionBody(ClassFunction func, Statement body)
1306 Declarator decl = func.declarator;
1308 //Declarator decl = GetFuncDecl(func.declarator);
1309 Declarator funcDecl = GetFuncDecl(func.declarator);
1313 if(decl && !decl.symbol)
1315 OldList * symbolSpecs = MkList();
1317 // WHAT WILL WE DO WITH THIS? Double instances?
1318 //if(decl.function.parameters && body)
1319 if(funcDecl && funcDecl.function.parameters && body)
1321 Context context = body.compound.context;
1323 for(param = funcDecl.function.parameters->first; param; param = param.next)
1325 if(param.declarator)
1327 Symbol symbol = null;
1328 Identifier id = GetDeclId(param.declarator);
1329 char * string = id ? id.string : null;
1332 symbol = (Symbol)context.symbols.FindString(string);
1334 // This parameter is not shadowed by a local declaration
1339 string = CopyString(id.string);
1340 type = ProcessType(param.qualifiers, param.declarator);
1344 // TODO: Fix this, the parameters' IDs should really be smaller...
1345 symbol.idCode = symbol.id = context.nextID++;
1346 if(!context.symbols.Add((BTNode)symbol))
1347 excludedSymbols->Add(symbol);
1349 param.declarator.symbol = symbol;
1354 //////////////////////////////////
1362 Identifier id = GetDeclId(funcDecl);
1366 for(c = strlen(id.string)-1; c >= 0; c--)
1368 if(id.string[c] == ':')
1370 char * string = CopyString(id.string + c + 1);
1371 id.string[c - 1] = 0;
1372 id._class = MkSpecifierName(id.string);
1378 symbol.string = CopyString(id.string);
1385 for(spec = func.specifiers->first; spec; spec = spec.next)
1386 symbolSpecs->Add(CopySpecifier(spec));
1388 symbol.type = ProcessType(symbolSpecs, decl);
1389 symbol.idCode = symbol.id = globalContext.nextID++;
1390 decl.symbol = symbol;
1392 excludedSymbols->Add(symbol);
1394 FreeList(symbolSpecs, FreeSpecifier);
1398 OldList * MkSpecsClass(Specifier _class)
1400 OldList * list = MkList();
1401 ListAdd(list, _class);
1405 MemberInit MkMemberInit(OldList ids, Initializer initializer)
1407 return { identifiers = ids, initializer = initializer };
1410 MemberInit MkMemberInitExp(Expression idExp, Initializer initializer)
1412 MemberInit init { initializer = initializer, identifiers = MkList() };
1415 for(exp = idExp; exp && exp.type == memberExp; exp = exp.member.exp)
1417 init.identifiers->Insert(null, exp.member.member);
1418 exp.member.member = null;
1420 if(exp && exp.type == identifierExp)
1422 init.identifiers->Insert(null, exp.identifier);
1423 exp.identifier = null;
1425 FreeExpression(idExp);
1429 MembersInit MkMembersInitList(OldList dataMembers)
1431 return { type = dataMembersInit, dataMembers = dataMembers };
1434 MembersInit MkMembersInitMethod(ClassFunction function)
1436 return { type = methodMembersInit, function = function };
1439 Instantiation MkInstantiation(Specifier _class, Expression exp, OldList members)
1441 return { _class = _class, exp = exp, members = members };
1444 Instantiation MkInstantiationNamed(OldList specs, Expression exp, OldList members)
1446 Instantiation inst { exp = exp, members = members };
1451 for(spec = specs.first; spec; spec = spec.next)
1452 if(spec.type == nameSpecifier /*classSpecifier*/)
1459 FreeList(specs, FreeSpecifier);
1463 Compiler_Error($"Expecting class specifier\n");
1464 inst._class = MkSpecifierName /*MkClassName*/("");
1472 ClassDef MkClassDefAccessOverride(AccessMode access, Identifier id)
1474 return { type = accessOverrideClassDef, id = id, memberAccess = access };
1477 ClassDef MkClassDefMemberAccess()
1479 return { type = memberAccessClassDef };
1482 ClassDef MkClassDefDeclaration(Declaration decl)
1484 return { type = declarationClassDef, decl = decl };
1487 ClassDef MkClassDefClassData(Declaration decl)
1489 return { type = classDataClassDef, decl = decl };
1492 ClassDef MkClassDefDesigner(char * designer)
1494 return { type = classDesignerClassDef, designer = CopyString(designer) };
1497 ClassDef MkClassDefNoExpansion()
1499 return { type = classNoExpansionClassDef };
1502 ClassDef MkClassDefFixed()
1504 return { type = classFixedClassDef };
1507 ClassDef MkClassDefDesignerDefaultProperty(Identifier id)
1509 return { type = designerDefaultPropertyClassDef, defaultProperty = id };
1512 ClassDef MkClassDefDefaultProperty(OldList defProperties)
1514 return { type = defaultPropertiesClassDef, defProperties = defProperties };
1517 ClassDef MkClassDefFunction(ClassFunction function)
1520 if(function && function.declarator)
1522 Declarator funcDecl = GetFuncDecl(function.declarator);
1523 if(funcDecl && funcDecl.declarator && funcDecl.declarator.type == bracketsDeclarator)
1525 def.type = declarationClassDef;
1526 def.decl = MkStructDeclaration(function.specifiers, MkListOne(MkStructDeclarator(function.declarator, null)), null);
1527 function.declarator = null;
1528 function.specifiers = null;
1529 FreeClassFunction(function);
1533 def.type = functionClassDef;
1534 def.function = function;
1538 Symbol DeclClassAddNameSpace(int symbolID, char * className)
1541 int len = 0, stringLen;
1543 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1545 if(defaultNameSpace)
1547 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1548 len += defaultNameSpaceLen;
1552 if(currentNameSpace)
1554 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1555 len += currentNameSpaceLen;
1560 stringLen = strlen(className);
1561 memcpy(name + len, className, stringLen);
1564 return _DeclClass(symbolID, name);
1567 Symbol DeclClass(int symbolID, char * name)
1569 if(strchr(name, ':'))
1570 return _DeclClass(symbolID, name);
1572 return DeclClassAddNameSpace(symbolID, name);
1575 Symbol _DeclClass(int symbolID, char * name)
1577 Symbol symbol = FindClass(name);
1581 Context classContext;
1582 for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
1588 if(name[0] == ':' && name[1] == ':')
1592 string = CopyString(name);
1593 idCode = symbolID, id = symbolID;
1595 if(!globalContext.classes.Add((BTNode)symbol))
1596 excludedSymbols->Add(symbol);
1601 for(c = 0; (ch = name[c]); c++)
1603 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
1609 if(start && c - start)
1610 symbol.shortName = CopyString(name + start);
1614 symbol.idCode = symbol.id = symbolID;
1618 void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
1620 if(baseSpecs && baseSpecs.first && ((Specifier)baseSpecs.first).type == nameSpecifier)
1625 strcpy(name, ((Specifier)baseSpecs.first).name);
1626 tpl = strchr(name, '<');
1629 baseClass = FindClass(name);
1633 for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
1635 TemplatedType type { key = copy.key, param = copy.param };
1636 if(!curContext.templateTypes.Add((BTNode)type))
1640 else if(baseClass.registered)
1643 for(sClass = baseClass.registered; sClass; sClass = sClass.base)
1645 ClassTemplateParameter p;
1646 for(p = sClass.templateParams.first; p; p = p.next)
1648 //OldList * specs = MkList();
1649 //Declarator decl = null;
1650 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
1653 TemplateParameter param = p.param;
1657 p.param = param = TemplateParameter
1659 identifier = MkIdentifier(p.name), type = p.type,
1660 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
1663 type = TemplatedType { key = (uintptr)p.name, param = param };
1664 if(!curContext.templateTypes.Add((BTNode)type))
1673 ClassDefinition MkClass(Symbol symbol, OldList baseSpecs, OldList definitions)
1675 ClassDefinition classDef;
1676 SetupBaseSpecs(symbol, baseSpecs);
1679 ClassDefinition classDef = symbol.ctx.classDef;
1682 // This can occur if two instances of a class are defined...
1683 // To avoid dangling 'parent' Contexts, we free the previous class definition
1685 for(external = ast->first; external; external = external.next)
1687 if(external.type == classExternal && external._class == classDef)
1689 ast->Remove(external);
1690 FreeExternal(external);
1695 FreeContext(symbol.ctx);
1698 symbol.ctx = curContext;
1699 classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
1700 curContext.classDef = classDef;
1704 Expression MkExpInstance(Instantiation inst)
1706 return { type = instanceExp, instance = inst };
1709 External MkExternalClass(ClassDefinition _class)
1711 return { type = classExternal, _class = _class, symbol = _class.symbol };
1714 PropertyDef MkProperty(OldList specs, Declarator decl, Identifier id, Statement setStmt, Statement getStmt)
1724 Type type = ProcessType(specs, decl);
1727 char typeString[1024];
1728 typeString[0] = '\0';
1729 PrintType(type, typeString, false, true);
1730 id = MkIdentifier(typeString);
1731 prop.conversion = true;
1737 string = CopyString(id.string);
1740 symbol.idCode = symbol.id = globalContext.nextID++;
1741 excludedSymbols->Add(symbol);
1742 globalContext.nextID++;
1743 globalContext.nextID++;
1744 prop.symbol = symbol;
1748 ClassDef MkClassDefProperty(PropertyDef propertyDef)
1750 return { type = propertyClassDef, propertyDef = propertyDef };
1753 ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
1755 return { type = classPropertyClassDef, propertyDef = propertyDef };
1758 ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
1760 return { type = classPropertyValueClassDef, id = id, initializer = initializer };
1763 int CheckType(char * text)
1766 Time startTime = GetTime();
1768 if(FindTemplateTypeParameter(curContext, text))
1771 checkTypeTotalTime += GetTime() - startTime;
1775 if(FindType(curContext, text))
1778 checkTypeTotalTime += GetTime() - startTime;
1785 checkTypeTotalTime += GetTime() - startTime;
1787 return TYPE_NAME; //CLASS_NAME;
1790 checkTypeTotalTime += GetTime() - startTime;
1797 return CheckType(yytext);
1800 Context PushContext()
1802 Context ctx { parent = curContext };
1807 void PopContext(Context ctx)
1809 curContext = ctx.parent;
1812 Symbol FindType(Context ctx, char * name)
1817 type = (Symbol)ctx.types.FindString(name);
1818 if(!type && ctx.parent)
1819 type = FindType(ctx.parent, name);
1824 TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
1826 TemplatedType templatedType = null;
1829 templatedType = (TemplatedType)ctx.templateTypes.FindString(name);
1830 if(!templatedType && ctx.parent)
1831 templatedType = FindTemplateTypeParameter(ctx.parent, name);
1833 return templatedType;
1836 bool ModuleAccess(Module searchIn, Module searchFor)
1838 SubModule subModule;
1840 if(searchFor == searchIn)
1843 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
1845 if(subModule.importMode == publicAccess /*|| searchIn == searchIn.application*/)
1847 if(ModuleAccess(subModule.module, searchFor))
1854 ModuleImport FindModule(Module moduleToFind)
1856 ModuleImport module;
1857 if(!moduleToFind.name)
1859 for(module = imports->first; module; module = module.next)
1860 if(module.name && !strcmp(module.name, moduleToFind.name))
1864 module = ModuleImport
1866 name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
1867 importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
1869 imports->Add(module);
1875 // TO REMOVE: OBSOLETE...
1876 static void GetFullClassNameSpace(NameSpace * ns, char * name)
1880 GetFullClassNameSpace(ns->parent, name);
1881 strcat(name, ns->name);
1886 static char * GetFullClassName(Class c, char * name)
1888 NameSpace * nameSpace;
1890 GetFullClassNameSpace(c.nameSpace, name);
1891 strcat(name, c.name);
1896 public Symbol FindClass(char * name)
1899 Time startTime = GetTime();
1903 bool global = false;
1904 char fullName[1024];
1906 if(name[0] == ':' && name[1] == ':')
1912 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1914 int len = 0, stringLen;
1915 if(defaultNameSpace)
1917 memcpy(fullName, defaultNameSpace, defaultNameSpaceLen);
1918 len += defaultNameSpaceLen;
1919 fullName[len++] = ':';
1920 fullName[len++] = ':';
1922 if(currentNameSpace)
1924 memcpy(fullName + len, currentNameSpace, currentNameSpaceLen);
1925 len += currentNameSpaceLen;
1926 fullName[len++] = ':';
1927 fullName[len++] = ':';
1929 stringLen = strlen(name);
1930 memcpy(fullName + len, name, stringLen);
1933 cl = globalContext ? (Symbol)globalContext.classes.FindString(fullName) : null;
1937 cl = globalContext ? (Symbol)globalContext.classes.FindString(name) : null;
1942 Time startTime = GetTime();
1944 // Ignore name space name when searching
1945 for(cl = globalContext ? (Symbol)globalContext.classes.first : null; cl; cl = (Symbol)((BTNode)cl).next)
1949 char * string = cl.string;
1951 for(c = 0; (ch = string[c]); c++)
1953 if(ch == '.' || (ch == ':' && string[c+1] == ':'))
1959 if(start && c - start)
1961 if(!strcmp(string + start, name))
1965 if(cl.shortName && !strcmp(cl.shortName, name))
1969 findClassIgnoreNSTotalTime += GetTime() - startTime;
1975 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1976 _class = eSystem_FindClass(privateModule, fullName);
1978 _class = eSystem_FindClass(privateModule, name);
1982 name = _class.fullName;
1984 cl = (Symbol)globalContext.classes.FindString(name);
1989 string = CopyString(name);
1990 registered = _class;
1997 cl.module = FindModule(_class.module);
1999 cl.module = mainModule;
2000 if(!globalContext.classes.Add((BTNode)cl))
2001 excludedSymbols->Add(cl);
2002 if(strcmp(name, _class.name))
2003 cl.shortName = CopyString(_class.name);
2008 findClassTotalTime += GetTime() - startTime;
2013 void CopyTypeInto(Type type, Type src)
2016 type.name = CopyString(src.name);
2017 type.enumName = CopyString(src.enumName);
2020 if(src.kind == enumType)
2024 type.members.Clear();
2025 // This must have been a mistake: member = **type**.members.first
2026 for(member = src.members.first; member; member = member.next)
2028 type.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
2031 else if(src.kind == structType || src.kind == unionType)
2034 // Tricky stuff... will be removed from list only when ref count reaches 0
2035 for(member = type.members.first; member; member = member.next)
2038 else if(src.kind == functionType)
2041 type.returnType.refCount++;
2042 for(param = type.params.first; param; param = param.next)
2045 else if(src.kind == pointerType || src.kind == arrayType)
2047 type.type.refCount++;
2048 if(src.kind == arrayType)
2050 if(type.arraySizeExp)
2051 type.arraySizeExp = CopyExpression(type.arraySizeExp);
2057 public Type ProcessType(OldList specs, Declarator decl)
2060 bool isTypedef = false;
2061 if(!specs || specs.first)
2063 Declarator funcDecl = GetFuncDecl(decl);
2065 bool dllExport = false;
2067 specType.kind = intType;
2068 specType.isSigned = true;
2069 specType.refCount = 1;
2071 type = Type { refCount = 1 };
2073 while(decl && (decl.type == structDeclarator || decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd))
2075 if(decl.type == structDeclarator && decl.structDecl.exp)
2077 ProcessExpressionType(decl.structDecl.exp);
2078 ComputeExpression(decl.structDecl.exp);
2079 if(decl.structDecl.exp.type == constantExp)
2080 specType.bitFieldCount = strtoul(decl.structDecl.exp.constant, null, 0);
2082 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended && decl.extended.extended.type == extDeclString &&
2083 decl.extended.extended.s && (!strcmp(decl.extended.extended.s, "__declspec(dllexport)") || !strcmp(decl.extended.extended.s, "dllexport")))
2087 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended && decl.extended.extended.type == extDeclAttrib)
2089 specType.keepCast = true;
2091 decl = decl.declarator;
2094 // If we'll be using the specType
2095 if(funcDecl || !decl || decl.type == identifierDeclarator)
2100 bool isLong = false;
2101 for(spec = specs.first; spec; spec = spec.next)
2103 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && spec.extDecl.s && (!strcmp(spec.extDecl.s, "__declspec(dllexport)") || !strcmp(spec.extDecl.s, "dllexport")))
2107 if(spec.type == extendedSpecifier && spec.extDecl.type == extDeclAttrib)
2109 specType.keepCast = true;
2112 if(spec.specifier != CONST && (specType.kind == structType || specType.kind == unionType))
2115 specType = { kind = intType, isSigned = true, refCount = 1 };
2118 if(spec.type == baseSpecifier)
2120 if(spec.specifier == TYPEDEF) isTypedef = true;
2121 else if(spec.specifier == VOID) specType.kind = voidType;
2122 else if(spec.specifier == CHAR) specType.kind = charType;
2123 else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
2124 else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
2125 else if(spec.specifier == INT64) specType.kind = int64Type;
2126 else if(spec.specifier == VALIST)
2127 specType.kind = vaListType;
2128 else if(spec.specifier == SHORT) specType.kind = shortType;
2129 else if(spec.specifier == LONG)
2132 specType.kind = int64Type;
2134 specType.kind = intType;
2136 // specType.kind = longType;
2138 else if(spec.specifier == FLOAT) specType.kind = floatType;
2139 else if(spec.specifier == DOUBLE) specType.kind = doubleType;
2140 else if(spec.specifier == SIGNED) specType.isSigned = true;
2141 else if(spec.specifier == UNSIGNED) specType.isSigned = false;
2142 else if(spec.specifier == CONST) specType.constant = true;
2143 else if(spec.specifier == TYPED_OBJECT)
2145 specType.classObjectType = typedObject; specType.kind = classType; specType._class = FindClass("class");
2147 else if(spec.specifier == ANY_OBJECT)
2149 specType.classObjectType = anyObject; specType.kind = classType; specType._class = FindClass("class");
2151 else if(spec.specifier == CLASS)
2153 specType.classObjectType = classPointer; specType.kind = classType; specType._class = FindClass("class");
2155 else if(spec.specifier == THISCLASS)
2156 specType.kind = thisClassType;
2158 else if(spec.type == nameSpecifier)
2160 if(spec.name && (!strcmp(spec.name, "intptr") || !strcmp(spec.name, "uintptr")))
2162 specType.kind = intPtrType;
2163 if(!strcmp(spec.name, "uintptr"))
2164 specType.isSigned = false;
2166 else if(spec.name && (!strcmp(spec.name, "uintsize") || !strcmp(spec.name, "intsize")))
2168 specType.kind = intSizeType;
2169 if(!strcmp(spec.name, "uintsize"))
2170 specType.isSigned = false;
2174 Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
2175 if(symbol && symbol.type)
2177 // Free Type Contents:
2182 CopyTypeInto(specType, symbol.type);
2183 specType.typeName = CopyString(symbol.type.name);
2185 else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
2187 // key.sym enum values need FindClass:
2188 specType._class = spec.name ? FindClass(spec.name) : null;
2189 // specType._class = spec.symbol;
2190 specType.kind = classType;
2191 if(!specType._class)
2192 specType.kind = intType;
2196 else if(spec.type == enumSpecifier)
2199 specType.kind = enumType;
2200 specType.enumName = spec.id ? CopyString(spec.id.string) : null;
2206 for(e = spec.list->first; e; e = e.next)
2208 // TOFIX: NamedItem i { } causes cryptic error, bad .c!
2209 NamedLink i { name = CopyString(e.id.string) };
2210 specType.members.Add(i);
2212 if(e.exp && ComputeExpression(e.exp), e.exp.isConstant && e.exp.expType.kind == intType)
2213 value.data = (void *) nextValue = strtol(e.exp.string, null, 0);
2215 value.data = (void *)nextValue++;
2223 for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
2224 if(decl.declarators)
2227 for(d = decl.declarators.first; d; d = d.next)
2229 Type memberType = ProcessType(decl.specifiers, d);
2230 specType.members.Add(memberType);
2233 else if(decl.specifiers)
2235 Type memberType = ProcessType(decl.specifiers, null);
2236 specType.members.Add(memberType);
2241 else if(spec.type == templateTypeSpecifier)
2244 printf("spec %x\n", spec);
2245 printf("template param %x\n", spec.templateParameter);
2246 printf("identifier %x\n", spec.templateParameter.identifier);
2247 printf("string %x\n", spec.templateParameter.identifier.string);
2249 specType.kind = templateType;
2250 specType.templateParameter = spec.templateParameter;
2252 else if(spec.type == structSpecifier || spec.type == unionSpecifier)
2254 Symbol _class = spec.id ? FindClass(spec.id.string) : null;
2257 if(!_class.registered || _class.registered.type != structClass)
2258 specType.directClassAccess = true;
2259 specType._class = _class;
2260 specType.kind = classType;
2263 if(spec.type == structSpecifier)
2264 specType.kind = structType;
2265 else if(spec.type == unionSpecifier)
2266 specType.kind = unionType;
2269 // TESTING THIS HERE... Had 0 type size
2270 if(!spec.definitions && !isTypedef)
2272 Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
2273 if(symbol && symbol.type)
2275 specType = *symbol.type;
2276 specType.name = CopyString(symbol.type.name);
2277 specType.typeName = CopyString(spec.name);
2278 specType.enumName = CopyString(symbol.type.enumName);
2279 specType.refCount = 1;
2281 if(symbol.type.kind == enumType)
2285 specType.members.Clear();
2286 for(member = symbol.type.members.first; member; member = member.next)
2288 NamedLink item { name = CopyString(member.name), data = member.data };
2289 specType.members.Add(item);
2292 else if(symbol.type.kind == structType || symbol.type.kind == unionType)
2295 // Tricky stuff... will be removed from list only when ref count reaches 0
2296 for(member = specType.members.first; member; member = member.next)
2299 else if(symbol.type.kind == functionType)
2302 specType.returnType.refCount++;
2303 for(param = specType.params.first; param; param = param.next)
2306 else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
2308 specType.type.refCount++;
2309 if(symbol.type.kind == arrayType)
2311 if(specType.arraySizeExp)
2312 specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
2318 specType.enumName = CopyString(spec.id.string);
2321 specType.enumName = CopyString(spec.id.string);
2324 if(spec.definitions)
2327 for(def = spec.definitions->first; def; def = def.next)
2329 if(def.type == declarationClassDef && def.decl.type == structDeclaration)
2331 Declaration decl = def.decl;
2332 if(decl.declarators)
2335 for(d = decl.declarators->first; d; d = d.next)
2337 Type memberType = ProcessType(decl.specifiers, d);
2338 specType.members.Add(memberType);
2341 else if(decl.specifiers)
2343 Type memberType = ProcessType(decl.specifiers, null);
2344 specType.members.Add(memberType);
2351 else if(spec.type == subClassSpecifier)
2353 specType.kind = specType.kind = subClassType;
2354 specType._class = spec._class.symbol; // FindClass(spec._class.name);
2357 else if(spec.type == classSpecifier)
2359 specType._class = FindClass(spec.name);
2360 specType.kind = classType;
2366 specType.kind = ellipsisType;
2371 Declarator d = funcDecl.declarator;
2375 funcType.kind = functionType;
2376 funcType.refCount = 1;
2377 if(funcDecl.function.parameters)
2379 for(param = funcDecl.function.parameters->first; param; param = param.next)
2382 if(param.typedObject)
2384 Type typedObjectType
2387 byReference = param.byReference;
2388 kind = TypeTypedObject;
2390 funcType.params.Add(typedObjectType);
2393 funcType.params.Add(ProcessType(param.qualifiers, param.declarator));
2397 // Function returning a pointer...
2398 if(decl.type == pointerDeclarator)
2400 Pointer pointer = decl.pointer.pointer;
2402 funcType.returnType = ptrType;
2403 funcType.returnType.refCount = 1;
2406 ptrType.kind = pointerType;
2407 pointer = pointer.pointer;
2410 ptrType.type = Type { refCount = 1 };
2411 ptrType = ptrType.type;
2414 ptrType.type = Type { refCount = 1 };
2415 *ptrType.type = specType;
2419 funcType.returnType = Type { refCount = 1 };
2420 *funcType.returnType = specType;
2423 // TESTING: Added extendedDeclarator here
2424 while(d && (d.type == bracketsDeclarator || d.type == extendedDeclarator || d.type == extendedDeclaratorEnd))
2426 if((d.type == extendedDeclarator || d.type == extendedDeclaratorEnd) && d.extended.extended && d.extended.extended.type == extDeclString &&
2427 d.extended.extended.s && (!strcmp(d.extended.extended.s, "__declspec(dllexport)") || !strcmp(d.extended.extended.s, "dllexport")))
2434 funcType.dllExport = dllExport;
2436 if(d && d.type == pointerDeclarator)
2441 if(d.declarator && d.declarator.type == arrayDeclarator)
2443 // Arrays of pointers to functions (extremely tricky :()
2444 Pointer pointer = d.pointer.pointer;
2446 // TO WORK ON: Fixed the order for the array...
2447 type.kind = arrayType;
2448 type.arraySizeExp = CopyExpression(d.declarator.array.exp);
2449 type.freeExp = true;
2450 if(d.declarator.array.enumClass)
2451 type.enumClass = d.declarator.array.enumClass.symbol; // FindClass(d.declarator.array.enumClass.name);
2452 if(d.declarator.declarator && d.declarator.declarator.type == arrayDeclarator)
2454 Type tmpType = type;
2456 type = ProcessType(null, d.declarator.declarator);
2458 type.type = tmpType;
2459 tmpType.type = inType;
2462 type.type = ProcessType(null, d.declarator.declarator);
2464 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2468 ptrType.kind = pointerType;
2469 pointer = pointer.pointer;
2472 ptrType.type = Type { refCount = 1 };
2473 ptrType = ptrType.type;
2476 ptrType.type = ProcessType(specs, null);
2480 // WARNING: Not caring if this declarator contains a declarator between
2481 // the pointer and the function other than brackets (like in the case of array of pointers to functions)...
2482 // *********** Could it ever go in here??? Yes: void (* converters_table[10]) (); ***********
2483 Pointer pointer = d.pointer.pointer;
2488 ptrType.kind = pointerType;
2489 ptrType.type = Type { refCount = 1 };
2490 pointer = pointer.pointer;
2492 ptrType = ptrType.type;
2496 *ptrType.type = funcType;
2500 if(id._class && !id._class.name)
2501 ptrType.type.staticMethod = true;
2504 // TODO : Ensure classSym has been resolved here... (Is this gonna cause problems? Supposed to do this later...)
2507 if(id._class && id._class.name)
2509 id.classSym = id._class.symbol; // FindClass(id._class.name);
2510 /* TODO: Name Space Fix ups
2512 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
2517 ptrType.type.thisClass = id.classSym;
2518 if(ptrType.type.thisClass && strcmp(ptrType.type.thisClass.string, "class"))
2519 ptrType.type.extraParam = true;
2520 else if(id._class && id._class.name && !strcmp(id._class.name, "any_object"))
2522 ptrType.type.extraParam = true;
2523 ptrType.type.thisClass = FindClass("class");
2527 type.name = CopyString(id.string);
2530 else if(!d || d.type == identifierDeclarator)
2536 if(d.identifier._class && d.identifier._class.type == templateTypeSpecifier)
2538 type.thisClassTemplate = d.identifier._class.templateParameter;
2539 type.extraParam = true;
2543 if(d.identifier._class && !d.identifier._class.name)
2544 type.staticMethod = true;
2547 if(d.identifier._class && d.identifier._class.name && d.identifier._class.name[strlen(d.identifier._class.name)-1] == '&')
2549 type.thisClass = FindClass("class");
2550 type.byReference = true;
2553 type.thisClass = d.identifier._class ? d.identifier._class.symbol /*FindClass(d.identifier._class.name)*/ : null;
2554 if(type.thisClass && strcmp(type.thisClass.string, "class"))
2556 type.extraParam = true;
2558 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "any_object"))
2560 type.extraParam = true;
2561 type.thisClass = FindClass("class");
2563 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "class"))
2565 //type.extraParam = true;
2566 type.thisClass = FindClass("class");
2567 type.classObjectType = classPointer;
2571 type.name = CopyString(d.identifier.string);
2576 else if(decl && decl.type == pointerDeclarator)
2578 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2580 // Arrays of pointers (tricky :))
2582 Pointer pointer = decl.pointer.pointer;
2585 // TO WORK ON: Fixed the order for the array...
2586 type.kind = arrayType;
2587 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2588 type.freeExp = true;
2589 if(decl.declarator.array.enumClass)
2590 type.enumClass = decl.declarator.array.enumClass.symbol; // FindClass(decl.declarator.array.enumClass.name);
2591 if(decl.declarator.declarator && decl.declarator.declarator.type == arrayDeclarator)
2593 Type tmpType = type;
2595 type = ProcessType(null, decl.declarator.declarator);
2597 type.type = tmpType;
2598 tmpType.type = inType;
2601 type.type = ProcessType(null, decl.declarator.declarator);
2603 type.type = ProcessType(null, decl.declarator.declarator);
2604 type.kind = arrayType;
2605 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2606 type.arraySizeExp.freeExp = true;
2607 if(decl.array.enumClass)
2608 type.enumClass = FindClass(decl.array.enumClass.name);
2611 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2615 ptrType.kind = pointerType;
2616 pointer = pointer.pointer;
2619 ptrType.type = Type { refCount = 1 };
2620 ptrType = ptrType.type;
2623 ptrType.type = ProcessType(specs, null);
2624 id = GetDeclId(decl);
2625 if(id) type.name = CopyString(id.string);
2630 Pointer pointer = decl.pointer.pointer;
2631 Type ptrType = type;
2633 if(type.classObjectType)
2635 type.byReference = true;
2641 ptrType.kind = pointerType;
2642 pointer = pointer.pointer;
2645 ptrType.type = Type { refCount = 1 };
2646 ptrType = ptrType.type;
2649 ptrType.type = ProcessType(specs, decl.declarator);
2651 if(type.type.classObjectType)
2653 Type subType = type.type;
2654 type.classObjectType = subType.classObjectType;
2655 type.kind = subType.kind;
2656 type._class = subType._class;
2657 type.byReference = true;
2661 id = GetDeclId(decl);
2662 if(id) type.name = CopyString(id.string);
2666 else if(decl && decl.type == arrayDeclarator)
2670 type.kind = arrayType;
2672 type.arraySizeExp = CopyExpression(decl.array.exp);
2673 type.freeExp = true;
2674 if(decl.array.enumClass)
2675 type.enumClass = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
2676 id = GetDeclId(decl);
2678 // TO WORK ON: Fixed the order for the array...
2679 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2681 Type tmpType = type;
2683 type = ProcessType(specs, decl.declarator);
2685 type.type = tmpType;
2686 tmpType.type = inType;
2689 type.type = ProcessType(specs, decl.declarator);
2694 type.name = CopyString(id.string);
2699 if(!decl || decl.type == identifierDeclarator)
2703 type.name = decl ? CopyString(decl.identifier.string) : null;
2712 public Type ProcessTypeString(char * string, bool staticMethod)
2714 OldList * specs = MkList();
2715 Declarator decl = SpecDeclFromString(string, specs, null);
2716 Type type = ProcessType(specs, decl);
2717 if(type && !type.thisClass && staticMethod) type.staticMethod = true;
2718 FreeList(specs, FreeSpecifier);
2719 if(decl) FreeDeclarator(decl);
2723 Type MkClassTypeSymbol(Symbol symbol)
2727 Type type { kind = classType, _class = symbol };
2730 // Defaults to an int instead...
2731 type.kind = intType;
2739 public Type MkClassType(char * name)
2743 Type type { kind = classType, _class = FindClass(name) };
2746 // Defaults to an int instead...
2747 type.kind = intType;
2755 AsmField MkAsmField(char * command, Expression expression)
2757 return { command = command, expression = expression };
2760 Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
2762 return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
2763 asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
2764 asmStmt.clobberedFields = clobberedFields };
2767 ClassDef MkClassDefPropertyWatch(PropertyWatch watcher)
2769 return { type = propertyWatchClassDef, propertyWatch = watcher };
2772 Statement MkFireWatchersStmt(Expression object, OldList watches)
2774 return { type = fireWatchersStmt, _watch.object = object, _watch.watches = watches };
2777 Statement MkStopWatchingStmt(Expression watcher, Expression object, OldList watches)
2779 return { type = stopWatchingStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2782 Statement MkWatchStmt(Expression watcher, Expression object, OldList watches)
2784 return { type = watchStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2787 PropertyWatch MkDeleteWatch(Statement compound)
2789 return { compound = compound, deleteWatch = true };
2792 PropertyWatch MkPropertyWatch(OldList properties, Statement compound)
2794 return { compound = compound, properties = properties };
2797 Expression MkExpClass(OldList * specifiers, Declarator decl)
2799 return { type = classExp, _classExp.specifiers = specifiers, _classExp.decl = decl };
2802 Expression MkExpClassData(Identifier id)
2804 return { type = classDataExp, classData.id = id };
2808 External MkExternalDBTable(DBTableDef table)
2810 return { type = dbtableExternal, table = table };
2813 DBTableDef MkDBTableDef(char * name, Symbol symbol, OldList * definitions)
2815 return { name = name, symbol = symbol, definitions = definitions };
2818 DBTableEntry MkDBFieldEntry(TypeName type, Identifier id, char * name)
2820 return { type = fieldEntry, dataType = type, id = id, name = name };
2823 DBIndexItem MkDBIndexItem(Identifier id, Order order)
2825 return { id = id, order = order };
2828 DBTableEntry MkDBIndexEntry(OldList * items, Identifier id)
2830 return { type = indexEntry, items = items, id = id };
2833 Expression MkExpDBOpen(Expression ds, Expression dbName)
2835 return { type = dbopenExp, dbopen.ds = ds, dbopen.name = dbName };
2838 Expression MkExpDBField(char * table, Identifier id)
2840 return { type = dbfieldExp, db.table = table, db.id = id };
2843 Expression MkExpDBIndex(char * table, Identifier id)
2845 return { type = dbindexExp, db.table = table, db.id = id };
2848 Expression MkExpDBTable(char * table)
2850 return { type = dbtableExp, db.table = table };
2853 Expression MkExpArray(OldList * expressions)
2855 return { type = arrayExp, list = expressions };
2858 Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplateParameterType tplType)
2860 Expression argExp = null;
2861 Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
2865 ClassTemplateParameter curParam;
2867 for(sClass = _class; sClass; sClass = sClass.base)
2870 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2872 if(!strcmp(curParam.name, paramName))
2874 for(sClass = sClass.base; sClass; sClass = sClass.base)
2875 id += sClass.templateParams.count;
2883 if(curParam && curParam.type != tplType)
2889 char className[1024];
2890 Expression classExp;
2892 sprintf(idString, "%d", id);
2893 strcpy(className, "__ecereClass_");
2894 FullClassNameCat(className, _class.fullName, true);
2895 MangleClassName(className);
2896 DeclareClass(FindClass(_class.fullName), className);
2898 argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
2899 (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
2900 MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
2906 Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
2908 return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
2911 /*char * CreateMsgID(char * string, char * context)
2913 int lenString = strlen(string), lenContext = strlen(context);
2914 char * msgid = new char[lenString + lenContext + 20];
2915 memcpy(msgid, string, lenString);
2916 memcpy(msgid+lenString, " [msgctxt: ", 11);
2917 memcpy(msgid+lenString+11, context, lenContext);
2918 memcpy(msgid+lenString+11+lenContext, "]", 2);
2922 public void OutputIntlStrings()
2924 if(intlStrings.count)
2926 char * srcFile = GetSourceFile();
2927 char * objFile = GetOutputFile();
2928 char srcFileFixed[MAX_LOCATION];
2929 char potFile[MAX_LOCATION];
2931 ChangeExtension(objFile, "bowl", potFile);
2932 f = FileOpen(potFile, write);
2935 char * filePrefix = "";
2936 if(!(srcFile[0] && (srcFile[1] == ':' || srcFile[0] == '/')))
2937 filePrefix = "./"; //(GetRuntimePlatform() == win32) ? ".\\" : "./";
2938 // GetSystemPathBuffer(srcFileFixed, srcFile);
2939 GetSlashPathBuffer(srcFileFixed, srcFile);
2940 for(s : intlStrings)
2942 // TOFIX: (#654) ContextStringPair * pair = &s;
2943 ContextStringPair pair = &s;
2945 f.Printf("#: %s%s:%d\n", filePrefix, srcFileFixed, l.start.line);
2946 // PoEdit now preserves and distinguish msgctxt
2948 f.Printf("msgctxt \"%s\"\n", pair.context);
2949 f.Printf("msgid \"%s\"\n", pair.string);
2950 f.Printf("msgstr \"%s\"\n\n", pair.string);
2958 default extern OldList * ast;
2959 default extern int yyparse ();
2961 public void SetAST(OldList * list) { ast = list; }
2962 public OldList * GetAST() { return ast; }
2963 public void ParseEc()