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("typed_object"); //"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 TypeName MkTypeNameGuessDecl(OldList qualifiers, Declarator declarator)
616 TypeName typeName { qualifiers = qualifiers, declarator = declarator };
617 if(qualifiers != null)
619 bool gotType = false;
620 bool gotFullType = false;
621 Specifier spec, next;
622 for(spec = qualifiers.first; spec; spec = next)
625 if(gotType && !declarator && ((spec.type == nameSpecifier && spec.name) || (spec.type == baseSpecifier && gotFullType)))
628 if(spec.type == nameSpecifier)
630 char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
631 s = colon ? colon + 2 : spec.name;
633 else if(spec.type == baseSpecifier)
635 if(spec.specifier == INT64) s = "int64";
639 typeName.declarator = declarator = MkDeclaratorIdentifier(MkIdentifier(s));
640 qualifiers.Remove(spec);
645 if(spec && spec.type != extendedSpecifier)
647 if(spec.type != baseSpecifier || (spec.specifier != UNSIGNED && spec.specifier != SIGNED && spec.specifier != LONG))
656 public Identifier GetDeclId(Declarator decl)
658 while(decl && decl.type != identifierDeclarator)
659 decl = decl.declarator;
660 return decl ? decl.identifier : null;
663 Declaration MkDeclarationClassInst(Instantiation inst)
665 return { type = instDeclaration, inst = inst, loc = yylloc };
668 Declaration MkDeclarationInst(Instantiation inst)
670 Declaration decl { type = instDeclaration, inst = inst, loc = yylloc };
672 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
675 int len = 0, stringLen;
678 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
679 len += defaultNameSpaceLen;
685 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
686 len += currentNameSpaceLen;
691 stringLen = strlen(inst.exp.identifier.string);
692 memcpy(name + len, inst.exp.identifier.string, stringLen);
695 delete inst.exp.identifier.string;
696 inst.exp.identifier.string = CopyString(name);
701 string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
702 type = MkClassTypeSymbol(inst._class.symbol);
704 symbol.idCode = symbol.id = curContext.nextID++;
705 if(strstr(symbol.string, "::"))
706 curContext.hasNameSpace = true;
707 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
708 excludedSymbols->Add(symbol);
709 decl.symbol = inst.symbol = symbol;
713 Declaration MkDeclarationDefine(Identifier id, Expression exp)
715 Declaration decl { type = defineDeclaration, id = id, exp = exp, loc = yylloc };
716 char expString[1024];
719 PrintExpression(exp, expString);
721 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
724 int len = 0, stringLen;
727 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
728 len += defaultNameSpaceLen;
734 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
735 len += currentNameSpaceLen;
739 stringLen = strlen(id.string);
740 memcpy(name + len, id.string, stringLen);
744 id.string = CopyString(name);
747 if(!eSystem_FindDefine(privateModule, id.string))
748 eSystem_RegisterDefine(id.string, expString, privateModule, buildingECERECOMModule ? baseSystemAccess : publicAccess);
750 Compiler_Warning($"Redefinition of %s ignored\n", id.string);
754 Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
756 Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
757 bool variable = true;
759 if(specifiers != null)
761 bool gotType = false;
762 Specifier spec, next;
763 for(spec = specifiers.first; spec; spec = next)
766 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
768 if(initDeclarators != null)
772 for(d = initDeclarators.first; d; d = d.next)
774 if(GetDeclId(d.declarator).string)
778 string = CopyString(GetDeclId(d.declarator).string);
779 type = ProcessType(specifiers, d.declarator);
781 type.id = type.idCode = curContext.nextID++;
783 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
784 excludedSymbols->Add(type);
785 decl.symbol = d.declarator.symbol = type;
791 //for(spec = spec.next; spec; spec = spec.next)
792 spec = specifiers.last;
794 if((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier)
797 if(spec.type == nameSpecifier)
799 char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
800 s = colon ? colon + 2 : spec.name;
802 else if(spec.type == baseSpecifier)
804 if(spec.specifier == INT64) s = "int64";
808 Symbol type { string = CopyString(s), type = ProcessType(specifiers, null) };
809 type.id = type.idCode = curContext.nextID++;
811 decl.declarators = initDeclarators = MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
812 specifiers.Remove(spec);
814 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
815 excludedSymbols->Add(type);
823 else if(spec.type == baseSpecifier &&
824 (spec.specifier == STRUCT || spec.specifier == UNION))
828 if(gotType && initDeclarators == null && !spec.next && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
831 if(spec.type == nameSpecifier)
833 char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
834 s = colon ? colon + 2 : spec.name;
836 else if(spec.type == baseSpecifier)
838 if(spec.specifier == INT64) s = "int64";
842 decl.declarators = initDeclarators = MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
843 specifiers.Remove(spec);
849 if(spec && spec.type != extendedSpecifier)
853 if(variable && initDeclarators)
856 for(d = initDeclarators.first; d; d = d.next)
858 Identifier id = GetDeclId(d.declarator);
859 if(id && id.string && id.string[0])
865 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
868 int len = 0, stringLen;
871 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
872 len += defaultNameSpaceLen;
878 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
879 len += currentNameSpaceLen;
883 stringLen = strlen(id.string);
884 memcpy(name + len, id.string, stringLen);
888 id.string = CopyString(name);
891 // Avoid memory leaks on duplicated symbols (BinaryTree::Add Would Fail)
892 symbol = (Symbol)(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.FindString(id.string);
895 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specifiers, d.declarator) };
896 if(strstr(symbol.string, "::"))
897 curContext.hasNameSpace = true;
898 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
899 excludedSymbols->Add(symbol);
900 // TODO: Add better support to count declarators
901 if(symbol.type && symbol.type.kind == arrayType && !symbol.type.arraySizeExp && d.initializer)
903 if(d.initializer.type == listInitializer)
906 sprintf(string, "%d",d.initializer.list->count);
907 symbol.type.arraySizeExp = MkExpConstant(string);
908 symbol.type.freeExp = true;
910 else if(d.initializer.type == expInitializer && d.initializer.exp.type == stringExp && d.initializer.exp.string)
915 bool escaped = false;
916 char * s = d.initializer.exp.string;
918 // MAKE MORE ACCURATE
919 for(c = 1; (ch = s[c]); c++)
921 if(ch == '\\' && !escaped)
930 sprintf(string, "%d", count);
931 symbol.type.arraySizeExp = MkExpConstant(string);
932 symbol.type.freeExp = true;
935 symbol.id = symbol.idCode = curContext.nextID++;
937 decl.symbol = d.declarator.symbol = symbol;
944 decl.symbol = Symbol { };
945 decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
946 excludedSymbols->Add(decl.symbol);
951 Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifier extStorage)
953 Declaration decl { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
954 if(specifiers != null)
956 bool gotType = false;
957 Specifier spec, next;
958 for(spec = specifiers.first; spec; spec = next)
961 if(gotType && declarators == null && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
964 if(spec.type == nameSpecifier)
966 char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
967 s = colon ? colon + 2 : spec.name;
969 else if(spec.type == baseSpecifier)
971 if(spec.specifier == INT64) s = "int64";
975 decl.declarators = declarators = MkListOne(MkDeclaratorIdentifier(MkIdentifier(s)));
976 specifiers.Remove(spec);
981 if(spec && spec.type != extendedSpecifier)
988 Statement MkLabeledStmt(Identifier id, Statement statement)
990 return { type = labeledStmt, labeled.id = id, labeled.stmt = statement, loc = yylloc };
993 Statement MkCaseStmt(Expression exp, Statement statement)
995 return { type = caseStmt, caseStmt.exp = exp, caseStmt.stmt = statement, loc = yylloc };
998 Statement MkCompoundStmt(OldList declarations, OldList statements)
1000 return { type = compoundStmt, compound.declarations = declarations, compound.statements = statements, loc = yylloc };
1003 Statement MkExpressionStmt(OldList expressions)
1005 return { type = expressionStmt, expressions = expressions, loc = yylloc };
1008 Statement MkBadDeclStmt(Declaration decl)
1010 return { type = badDeclarationStmt, decl = decl, loc = yylloc };
1013 Statement MkIfStmt(OldList exp, Statement statement, Statement elseStmt)
1015 return { type = ifStmt, ifStmt.exp = exp, ifStmt.stmt = statement, ifStmt.elseStmt = elseStmt, loc = yylloc };
1018 Statement MkSwitchStmt(OldList exp, Statement statement)
1020 // To know it's a switch compound... (Don't want declarations in there... bugs)
1022 statement.compound.isSwitch = true;
1023 return { type = switchStmt, switchStmt.exp = exp, switchStmt.stmt = statement, loc = yylloc };
1026 Statement MkWhileStmt(OldList exp, Statement statement)
1028 return { type = whileStmt, whileStmt.exp = exp, whileStmt.stmt = statement, loc = yylloc };
1031 Statement MkDoWhileStmt(Statement statement, OldList exp)
1033 return { type = doWhileStmt, doWhile.exp = exp, doWhile.stmt = statement, loc = yylloc };
1036 Statement MkForStmt(Statement init, Statement check, OldList inc, Statement statement)
1038 return { type = forStmt, forStmt.init = init, forStmt.check = check, forStmt.increment = inc, forStmt.stmt = statement, loc = yylloc };
1041 Statement MkForEachStmt(Identifier id, OldList exp, OldList filter, Statement statement)
1043 return { type = forEachStmt, forEachStmt.id = id, forEachStmt.exp = exp, forEachStmt.filter = filter, forEachStmt.stmt = statement, loc = yylloc };
1046 Statement MkGotoStmt(Identifier id)
1048 return { type = gotoStmt, gotoStmt.id = id, loc = yylloc };
1051 Statement MkContinueStmt()
1053 return { type = continueStmt, loc = yylloc };
1056 Statement MkBreakStmt()
1058 return { type = breakStmt, loc = yylloc };
1061 Statement MkReturnStmt(OldList exp)
1063 return { type = returnStmt, expressions = exp, loc = yylloc };
1066 FunctionDefinition MkFunction(OldList specifiers, Declarator declarator, OldList declarationList)
1068 return { specifiers = specifiers, declarator = declarator, declarations = declarationList };
1071 void ProcessFunctionBody(FunctionDefinition func, Statement body)
1073 Declarator declarator = func.declarator;
1074 Declarator funcDecl = GetFuncDecl(declarator);
1079 if(funcDecl && funcDecl.function.parameters && body)
1081 Context context = body.compound.context;
1083 for(param = funcDecl.function.parameters->first; param; param = param.next)
1085 if(param.declarator)
1087 Symbol symbol = null;
1088 Identifier id = GetDeclId(param.declarator);
1089 char * string = id ? id.string : null;
1092 for(symbol = (Symbol)context.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
1093 if(!strcmp(symbol.string, string))
1095 // This parameter is not shadowed by a local declaration
1098 symbol = Symbol { string = CopyString(id.string), type = ProcessType(param.qualifiers, param.declarator), isParam = true };
1099 if(!context.symbols.Add((BTNode)symbol))
1100 excludedSymbols->Add(symbol);
1102 // TODO: Fix this, the parameters' IDs should really be smaller...
1103 symbol.id = context.nextID++;
1104 param.declarator.symbol = symbol;
1111 if(!declarator.symbol)
1113 Identifier id = GetDeclId(declarator);
1115 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess && strcmp(id.string, "__on_register_module"))
1118 int len = 0, stringLen;
1119 if(defaultNameSpace)
1121 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1122 len += defaultNameSpaceLen;
1126 if(currentNameSpace)
1128 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1129 len += currentNameSpaceLen;
1133 stringLen = strlen(id.string);
1134 memcpy(name + len, id.string, stringLen);
1138 id.string = CopyString(name);
1140 symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
1141 symbol.idCode = symbol.id = globalContext.nextID++;
1142 if(strstr(symbol.string, "::"))
1143 globalContext.hasNameSpace = true;
1144 if(!globalContext.symbols.Add((BTNode)symbol))
1145 excludedSymbols->Add(symbol);
1146 declarator.symbol = symbol;
1150 symbol = declarator.symbol;
1151 excludedSymbols->Remove(declarator.symbol);
1152 delete symbol.string;
1153 symbol.string = CopyString(GetDeclId(declarator).string);
1154 if(strstr(symbol.string, "::"))
1155 globalContext.hasNameSpace = true;
1156 if(!globalContext.symbols.Add((BTNode)symbol))
1157 excludedSymbols->Add(symbol);
1160 symbol.type = ProcessType(func.specifiers, declarator);
1162 if(symbol.type && (symbol.type.kind == functionType || symbol.type.kind == methodType))
1164 if(!symbol.type.params.count)
1166 Type type { refCount = 1 };
1167 symbol.type.params.Add(type);
1176 External MkExternalFunction(FunctionDefinition function)
1178 External external { type = functionExternal, function = function, symbol = function.declarator.symbol };
1179 if(function.specifiers)
1182 for(spec = function.specifiers->first; spec; spec = spec.next)
1183 if(spec.type == baseSpecifier && spec.specifier == STATIC)
1185 declMode = staticAccess;
1190 if(external.symbol && !external.symbol.methodExternal)
1191 external.symbol.methodExternal = external;
1195 External MkExternalImport(char * name, ImportType importType, AccessMode importAccess)
1197 External external { type = importExternal };
1198 int len = strlen(name) - 2;
1199 external.importString = new char[len + 1];
1200 strncpy(external.importString, name+1, len);
1201 external.importString[len] = '\0';
1206 Time startTime = GetTime();
1209 ImportModule(external.importString, importType, importAccess, true);
1210 ImportModule(external.importString, importType, importAccess, false);
1212 time = GetTime() - startTime;
1213 printf("Importing took %.3f seconds for %s\n", time, external.importString);
1214 externalImportTotalTime += time;
1220 External MkExternalDeclaration(Declaration declaration)
1222 External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
1223 InitDeclarator d = (declaration && declaration.declarators) ? declaration.declarators->last : null;
1224 if(declaration && declaration.type == initDeclaration && declaration.specifiers)
1227 for(spec = declaration.specifiers->first; spec; spec = spec.next)
1228 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1230 declMode = defaultAccess;
1233 else if(spec.type == baseSpecifier && spec.specifier == STATIC)
1235 declMode = staticAccess;
1239 if(declaration && declaration.symbol && !declaration.symbol.methodExternal)
1240 declaration.symbol.methodExternal = external;
1244 External MkExternalNameSpace(Identifier identifier)
1246 External external { type = nameSpaceExternal, id = identifier };
1247 currentNameSpace = identifier ? identifier.string : null;
1248 currentNameSpaceLen = currentNameSpace ? strlen(currentNameSpace) : 0;
1252 void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
1254 if(spec.type == nameSpecifier)
1256 Symbol symbol = spec.symbol;
1257 spec.templateArgs = templateArgs;
1258 if(templateArgs && templateArgs.first)
1260 char templateString[1024];
1261 TemplateArgument arg;
1262 strcpy(templateString, symbol ? symbol.string : spec.name);
1263 strcat(templateString, "<");
1264 for(arg = templateArgs.first; arg; arg = arg.next)
1272 char expString[1024];
1273 Class backupThisClass = thisClass;
1275 expString[0] = '\0';
1276 // Will this work here?
1278 Location oldLocation = yylloc;
1279 File backFileInput = fileInput;
1284 // TESTING THIS SCANNER RESUME STUFF
1287 yylloc = oldLocation;
1288 fileInput = backFileInput;
1291 fileInput.Seek(yylloc.start.pos, start);
1292 resetScannerPos(&yylloc.start);
1297 //ProcessExpressionType(arg.expression);
1298 //ComputeExpression(arg.expression);
1299 PrintExpression(arg.expression, expString);
1300 strcat(argument, expString);
1301 thisClass = backupThisClass;
1306 strcat(argument, arg.identifier.string);
1311 char * typeString = StringFromSpecDecl(arg.templateDatatype.specifiers, arg.templateDatatype.decl);
1312 strcat(argument, typeString);
1319 if(arg.prev) strcat(templateString, ", ");
1322 strcat(templateString, arg.name.string);
1323 strcat(templateString, " = ");
1325 strcat(templateString, argument);
1329 int len = strlen(templateString);
1330 if(templateString[len-1] == '>') templateString[len++] = ' ';
1331 templateString[len++] = '>';
1332 templateString[len++] = '\0';
1334 // printf("SetClassTemplateArgs templateString: %s\n", templateString);
1335 symbol = FindClass(templateString);
1336 if(!symbol && spec.symbol)
1338 // If class was only decl'ed, invoke DeclClass on this templated class as well
1339 symbol = _DeclClass(MAXINT, templateString);
1341 // Add a reference to all templated class to the basic class
1343 spec.symbol.templatedClasses.Add(OldLink { data = symbol });
1345 spec.symbol = symbol;
1346 spec.name = CopyString(symbol ? symbol.string : templateString);
1350 FreeList(templateArgs, FreeTemplateArgument);
1353 Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
1355 Specifier spec { type = nameSpecifier };
1361 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
1364 spec.templateParameter = templatedType.param;
1365 spec.type = templateTypeSpecifier;
1369 symbol = FindClass(name);
1371 if(symbol && symbol.registered && symbol.registered.isRemote == 1)
1373 char className[1024];
1374 strcpy(className, "DCOMClient_");
1375 if(!strncmp(name, className, strlen(className)))
1376 spec.name = CopyString(name);
1379 strcat(className, name);
1380 spec.name = CopyString(className);
1384 spec.name = CopyString(symbol.string);
1386 spec.name = CopyString(name);
1387 spec.symbol = symbol;
1388 if(templateArgs != null)
1389 SetClassTemplateArgs(spec, templateArgs);
1394 public Specifier MkSpecifierName(char * name)
1396 return _MkSpecifierName(name, null, null);
1399 public Specifier MkSpecifierNameArgs(char * name, OldList * templateArgs)
1401 return _MkSpecifierName(name, null, templateArgs);
1405 Specifier MkClassName(char * string)
1407 return { type = SpecifierClass, name = CopyString(string) };
1410 ClassFunction MkClassFunction(OldList specifiers, Specifier _class, Declarator decl, OldList declList)
1412 return { specifiers = specifiers, /*_class = _class,*/ declarator = decl, declarations = declList };
1415 void ProcessClassFunctionBody(ClassFunction func, Statement body)
1419 Declarator decl = func.declarator;
1421 //Declarator decl = GetFuncDecl(func.declarator);
1422 Declarator funcDecl = GetFuncDecl(func.declarator);
1426 if(decl && !decl.symbol)
1428 OldList * symbolSpecs = MkList();
1430 // WHAT WILL WE DO WITH THIS? Double instances?
1431 //if(decl.function.parameters && body)
1432 if(funcDecl && funcDecl.function.parameters && body)
1434 Context context = body.compound.context;
1436 for(param = funcDecl.function.parameters->first; param; param = param.next)
1438 if(param.declarator)
1440 Symbol symbol = null;
1441 Identifier id = GetDeclId(param.declarator);
1442 char * string = id ? id.string : null;
1445 symbol = (Symbol)context.symbols.FindString(string);
1447 // This parameter is not shadowed by a local declaration
1452 string = CopyString(id.string);
1453 type = ProcessType(param.qualifiers, param.declarator);
1457 // TODO: Fix this, the parameters' IDs should really be smaller...
1458 symbol.idCode = symbol.id = context.nextID++;
1459 if(!context.symbols.Add((BTNode)symbol))
1460 excludedSymbols->Add(symbol);
1462 param.declarator.symbol = symbol;
1467 //////////////////////////////////
1475 Identifier id = GetDeclId(funcDecl);
1479 for(c = strlen(id.string)-1; c >= 0; c--)
1481 if(id.string[c] == ':')
1483 char * string = CopyString(id.string + c + 1);
1484 id.string[c - 1] = 0;
1485 id._class = MkSpecifierName(id.string);
1491 symbol.string = CopyString(id.string);
1498 for(spec = func.specifiers->first; spec; spec = spec.next)
1499 symbolSpecs->Add(CopySpecifier(spec));
1501 symbol.type = ProcessType(symbolSpecs, decl);
1502 symbol.idCode = symbol.id = globalContext.nextID++;
1503 decl.symbol = symbol;
1505 excludedSymbols->Add(symbol);
1507 FreeList(symbolSpecs, FreeSpecifier);
1511 OldList * MkSpecsClass(Specifier _class)
1513 OldList * list = MkList();
1514 ListAdd(list, _class);
1518 MemberInit MkMemberInit(OldList ids, Initializer initializer)
1520 return { identifiers = ids, initializer = initializer };
1523 MemberInit MkMemberInitExp(Expression idExp, Initializer initializer)
1525 MemberInit init { initializer = initializer, identifiers = MkList() };
1528 for(exp = idExp; exp && exp.type == memberExp; exp = exp.member.exp)
1530 init.identifiers->Insert(null, exp.member.member);
1531 exp.member.member = null;
1533 if(exp && exp.type == identifierExp)
1535 init.identifiers->Insert(null, exp.identifier);
1536 exp.identifier = null;
1538 FreeExpression(idExp);
1542 MembersInit MkMembersInitList(OldList dataMembers)
1544 return { type = dataMembersInit, dataMembers = dataMembers };
1547 MembersInit MkMembersInitMethod(ClassFunction function)
1549 return { type = methodMembersInit, function = function };
1552 Instantiation MkInstantiation(Specifier _class, Expression exp, OldList members)
1554 return { _class = _class, exp = exp, members = members };
1557 Instantiation MkInstantiationNamed(OldList specs, Expression exp, OldList members)
1559 Instantiation inst { exp = exp, members = members };
1564 for(spec = specs.first; spec; spec = spec.next)
1565 if(spec.type == nameSpecifier /*classSpecifier*/)
1572 FreeList(specs, FreeSpecifier);
1576 Compiler_Error($"Expecting class specifier\n");
1577 inst._class = MkSpecifierName /*MkClassName*/("");
1585 ClassDef MkClassDefAccessOverride(AccessMode access, Identifier id)
1587 return { type = accessOverrideClassDef, id = id, memberAccess = access };
1590 ClassDef MkClassDefMemberAccess()
1592 return { type = memberAccessClassDef };
1595 ClassDef MkClassDefDeclaration(Declaration decl)
1597 return { type = declarationClassDef, decl = decl };
1600 ClassDef MkClassDefClassData(Declaration decl)
1602 return { type = classDataClassDef, decl = decl };
1605 ClassDef MkClassDefDesigner(char * designer)
1607 return { type = classDesignerClassDef, designer = CopyString(designer) };
1610 ClassDef MkClassDefNoExpansion()
1612 return { type = classNoExpansionClassDef };
1615 ClassDef MkClassDefFixed()
1617 return { type = classFixedClassDef };
1620 ClassDef MkClassDefDesignerDefaultProperty(Identifier id)
1622 return { type = designerDefaultPropertyClassDef, defaultProperty = id };
1625 ClassDef MkClassDefDefaultProperty(OldList defProperties)
1627 return { type = defaultPropertiesClassDef, defProperties = defProperties };
1630 ClassDef MkClassDefFunction(ClassFunction function)
1633 if(function && function.declarator)
1635 Declarator funcDecl = GetFuncDecl(function.declarator);
1636 if(funcDecl && funcDecl.declarator && funcDecl.declarator.type == bracketsDeclarator)
1638 def.type = declarationClassDef;
1639 def.decl = MkStructDeclaration(function.specifiers, MkListOne(MkStructDeclarator(function.declarator, null)), null);
1640 function.declarator = null;
1641 function.specifiers = null;
1642 FreeClassFunction(function);
1646 def.type = functionClassDef;
1647 def.function = function;
1651 Symbol DeclClassAddNameSpace(int symbolID, char * className)
1654 int len = 0, stringLen;
1656 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1658 if(defaultNameSpace)
1660 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1661 len += defaultNameSpaceLen;
1665 if(currentNameSpace)
1667 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1668 len += currentNameSpaceLen;
1673 stringLen = strlen(className);
1674 memcpy(name + len, className, stringLen);
1677 return _DeclClass(symbolID, name);
1680 Symbol DeclClass(int symbolID, char * name)
1682 if(strchr(name, ':'))
1683 return _DeclClass(symbolID, name);
1685 return DeclClassAddNameSpace(symbolID, name);
1688 Symbol _DeclClass(int symbolID, char * name)
1690 Symbol symbol = FindClass(name);
1694 Context classContext;
1695 for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
1701 if(name[0] == ':' && name[1] == ':')
1705 string = CopyString(name);
1706 idCode = symbolID, id = symbolID;
1708 if(!globalContext.classes.Add((BTNode)symbol))
1709 excludedSymbols->Add(symbol);
1714 for(c = 0; (ch = name[c]); c++)
1716 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
1722 if(start && c - start)
1723 symbol.shortName = CopyString(name + start);
1727 symbol.idCode = symbol.id = symbolID;
1731 void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
1733 if(baseSpecs && baseSpecs.first && ((Specifier)baseSpecs.first).type == nameSpecifier)
1738 strcpy(name, ((Specifier)baseSpecs.first).name);
1739 tpl = strchr(name, '<');
1742 baseClass = FindClass(name);
1746 for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
1748 TemplatedType type { key = copy.key, param = copy.param };
1749 if(!curContext.templateTypes.Add((BTNode)type))
1753 else if(baseClass.registered)
1756 for(sClass = baseClass.registered; sClass; sClass = sClass.base)
1758 ClassTemplateParameter p;
1759 for(p = sClass.templateParams.first; p; p = p.next)
1761 //OldList * specs = MkList();
1762 //Declarator decl = null;
1763 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
1766 TemplateParameter param = p.param;
1770 p.param = param = TemplateParameter
1772 identifier = MkIdentifier(p.name), type = p.type,
1773 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
1776 type = TemplatedType { key = (uintptr)p.name, param = param };
1777 if(!curContext.templateTypes.Add((BTNode)type))
1786 ClassDefinition MkClass(Symbol symbol, OldList baseSpecs, OldList definitions)
1788 ClassDefinition classDef;
1789 SetupBaseSpecs(symbol, baseSpecs);
1792 ClassDefinition classDef = symbol.ctx.classDef;
1795 // This can occur if two instances of a class are defined...
1796 // To avoid dangling 'parent' Contexts, we free the previous class definition
1798 for(external = ast->first; external; external = external.next)
1800 if(external.type == classExternal && external._class == classDef)
1802 ast->Remove(external);
1803 FreeExternal(external);
1808 FreeContext(symbol.ctx);
1811 symbol.ctx = curContext;
1812 classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
1813 curContext.classDef = classDef;
1817 Expression MkExpInstance(Instantiation inst)
1819 return { type = instanceExp, instance = inst };
1822 External MkExternalClass(ClassDefinition _class)
1824 return { type = classExternal, _class = _class, symbol = _class.symbol };
1827 PropertyDef MkProperty(OldList specs, Declarator decl, Identifier id, Statement setStmt, Statement getStmt)
1837 Type type = ProcessType(specs, decl);
1840 char typeString[1024];
1841 typeString[0] = '\0';
1842 PrintTypeNoConst(type, typeString, false, true);
1843 id = MkIdentifier(typeString);
1844 prop.conversion = true;
1850 string = CopyString(id.string);
1853 symbol.idCode = symbol.id = globalContext.nextID++;
1854 excludedSymbols->Add(symbol);
1855 globalContext.nextID++;
1856 globalContext.nextID++;
1857 prop.symbol = symbol;
1861 ClassDef MkClassDefProperty(PropertyDef propertyDef)
1863 return { type = propertyClassDef, propertyDef = propertyDef };
1866 ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
1868 return { type = classPropertyClassDef, propertyDef = propertyDef };
1871 ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
1873 return { type = classPropertyValueClassDef, id = id, initializer = initializer };
1876 int CheckType(char * text)
1879 Time startTime = GetTime();
1881 if(FindTemplateTypeParameter(curContext, text))
1884 checkTypeTotalTime += GetTime() - startTime;
1888 if(FindType(curContext, text))
1891 checkTypeTotalTime += GetTime() - startTime;
1898 checkTypeTotalTime += GetTime() - startTime;
1900 return TYPE_NAME; //CLASS_NAME;
1903 checkTypeTotalTime += GetTime() - startTime;
1910 return CheckType(yytext);
1913 Context PushContext()
1915 Context ctx { parent = curContext };
1920 void PopContext(Context ctx)
1922 curContext = ctx.parent;
1925 Symbol FindType(Context ctx, char * name)
1930 //char output[8192];
1931 type = (Symbol)ctx.types.FindString(name);
1932 /*if(!strcmp(name, "intptr_t") && !type)
1934 ctx.types.Print(output, depthOrder);
1937 if(!type && ctx.parent)
1938 type = FindType(ctx.parent, name);
1943 TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
1945 TemplatedType templatedType = null;
1948 templatedType = (TemplatedType)ctx.templateTypes.FindString(name);
1949 if(!templatedType && ctx.parent)
1950 templatedType = FindTemplateTypeParameter(ctx.parent, name);
1952 return templatedType;
1955 bool ModuleAccess(Module searchIn, Module searchFor)
1957 SubModule subModule;
1959 if(searchFor == searchIn)
1962 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
1964 if(subModule.importMode == publicAccess /*|| searchIn == searchIn.application*/)
1966 if(ModuleAccess(subModule.module, searchFor))
1973 ModuleImport FindModule(Module moduleToFind)
1975 ModuleImport module;
1976 if(!moduleToFind.name)
1978 for(module = imports->first; module; module = module.next)
1979 if(module.name && !strcmp(module.name, moduleToFind.name))
1983 module = ModuleImport
1985 name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
1986 importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
1988 imports->Add(module);
1994 // TO REMOVE: OBSOLETE...
1995 static void GetFullClassNameSpace(NameSpace * ns, char * name)
1999 GetFullClassNameSpace(ns->parent, name);
2000 strcat(name, ns->name);
2005 static char * GetFullClassName(Class c, char * name)
2007 NameSpace * nameSpace;
2009 GetFullClassNameSpace(c.nameSpace, name);
2010 strcat(name, c.name);
2015 public Symbol FindClass(char * name)
2018 Time startTime = GetTime();
2022 bool global = false;
2023 char fullName[1024];
2025 if(name[0] == ':' && name[1] == ':')
2031 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
2033 int len = 0, stringLen;
2034 if(defaultNameSpace)
2036 memcpy(fullName, defaultNameSpace, defaultNameSpaceLen);
2037 len += defaultNameSpaceLen;
2038 fullName[len++] = ':';
2039 fullName[len++] = ':';
2041 if(currentNameSpace)
2043 memcpy(fullName + len, currentNameSpace, currentNameSpaceLen);
2044 len += currentNameSpaceLen;
2045 fullName[len++] = ':';
2046 fullName[len++] = ':';
2048 stringLen = strlen(name);
2049 memcpy(fullName + len, name, stringLen);
2052 cl = globalContext ? (Symbol)globalContext.classes.FindString(fullName) : null;
2056 cl = globalContext ? (Symbol)globalContext.classes.FindString(name) : null;
2061 Time startTime = GetTime();
2063 // Ignore name space name when searching
2064 for(cl = globalContext ? (Symbol)globalContext.classes.first : null; cl; cl = (Symbol)((BTNode)cl).next)
2068 char * string = cl.string;
2070 for(c = 0; (ch = string[c]); c++)
2072 if(ch == '.' || (ch == ':' && string[c+1] == ':'))
2078 if(start && c - start)
2080 if(!strcmp(string + start, name))
2084 if(cl.shortName && !strcmp(cl.shortName, name))
2088 findClassIgnoreNSTotalTime += GetTime() - startTime;
2094 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
2095 _class = eSystem_FindClass(privateModule, fullName);
2097 _class = eSystem_FindClass(privateModule, name);
2101 name = _class.fullName;
2103 cl = (Symbol)globalContext.classes.FindString(name);
2108 string = CopyString(name);
2109 registered = _class;
2116 cl.module = FindModule(_class.module);
2118 cl.module = mainModule;
2119 if(!globalContext.classes.Add((BTNode)cl))
2120 excludedSymbols->Add(cl);
2121 if(strcmp(name, _class.name))
2122 cl.shortName = CopyString(_class.name);
2127 findClassTotalTime += GetTime() - startTime;
2132 void CopyTypeInto(Type type, Type src)
2135 type.name = CopyString(src.name);
2138 if(src.kind == enumType)
2142 type.members.Clear();
2143 // This must have been a mistake: member = **type**.members.first
2144 for(member = src.members.first; member; member = member.next)
2146 type.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
2148 type.enumName = CopyString(src.enumName);
2150 else if(src.kind == structType || src.kind == unionType)
2153 // Tricky stuff... will be removed from list only when ref count reaches 0
2154 for(member = type.members.first; member; member = member.next)
2156 type.enumName = CopyString(src.enumName);
2158 else if(src.kind == functionType)
2161 type.returnType.refCount++;
2162 for(param = type.params.first; param; param = param.next)
2165 else if(src.kind == pointerType || src.kind == arrayType)
2167 type.type.refCount++;
2168 if(src.kind == arrayType)
2170 if(type.arraySizeExp)
2171 type.arraySizeExp = CopyExpression(type.arraySizeExp);
2177 static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeName)
2179 Type specType { refCount = 1, kind = intType, isSigned = true };
2182 bool isTypedef = false;
2184 bool isLong = false;
2185 for(spec = specs.first; spec; spec = spec.next)
2187 if(spec.type == extendedSpecifier)
2189 ExtDecl extDecl = spec.extDecl;
2190 if(extDecl.type == extDeclString)
2192 String s = spec.extDecl.s;
2193 if(!strcmp(spec.extDecl.s, "__declspec(dllexport)") || !strcmp(spec.extDecl.s, "dllexport"))
2194 specType.dllExport = true;
2195 else if(!strcmp(spec.extDecl.s, "__declspec(stdcall)") || !strcmp(spec.extDecl.s, "stdcall"))
2196 specType.attrStdcall = true;
2198 else if(extDecl.type == extDeclAttrib)
2200 OldList * attribs = extDecl.attr.attribs;
2204 for(attr = attribs->first; attr; attr = attr.next)
2206 String s = attr.attr;
2209 if(!strcmp(s, "dllexport"))
2210 specType.dllExport = true;
2211 else if(!strcmp(s, "stdcall"))
2212 specType.attrStdcall = true;
2216 specType.keepCast = true;
2220 if(spec.specifier != CONST && (specType.kind == structType || specType.kind == unionType))
2223 specType = { kind = intType, isSigned = true, refCount = 1 };
2226 if(isTypedef && keepTypeName)
2228 specType.kind = dummyType;
2231 else if(spec.type == baseSpecifier)
2233 if(spec.specifier == TYPEDEF)
2235 else if(spec.specifier == VOID) specType.kind = voidType;
2236 else if(spec.specifier == CHAR) specType.kind = charType;
2237 else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType && !isLong) specType.kind = intType; }
2238 else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
2239 else if(spec.specifier == INT64) specType.kind = int64Type;
2240 else if(spec.specifier == VALIST)
2241 specType.kind = vaListType;
2242 else if(spec.specifier == SHORT) specType.kind = shortType;
2243 else if(spec.specifier == LONG)
2245 if(isLong || (targetBits == 64 && targetPlatform != win32))
2246 specType.kind = int64Type;
2248 specType.kind = intType;
2251 else if(spec.specifier == FLOAT) specType.kind = floatType;
2252 else if(spec.specifier == DOUBLE) specType.kind = doubleType;
2253 else if(spec.specifier == SIGNED) specType.isSigned = true;
2254 else if(spec.specifier == UNSIGNED) specType.isSigned = false;
2255 else if(spec.specifier == CONST)
2256 specType.constant = true;
2257 else if(spec.specifier == TYPED_OBJECT || spec.specifier == ANY_OBJECT || spec.specifier == CLASS)
2259 switch(spec.specifier)
2261 case TYPED_OBJECT: specType.classObjectType = typedObject; break;
2262 case ANY_OBJECT: specType.classObjectType = anyObject; break;
2263 case CLASS: specType.classObjectType = classPointer; break;
2265 specType.kind = classType;
2266 specType._class = FindClass("class");
2268 else if(spec.specifier == THISCLASS)
2269 specType.kind = thisClassType;
2271 else if(spec.type == nameSpecifier)
2273 if(spec.name && (!strcmp(spec.name, "intptr") || !strcmp(spec.name, "uintptr")))
2275 specType.kind = intPtrType;
2276 if(!strcmp(spec.name, "uintptr"))
2277 specType.isSigned = false;
2279 else if(spec.name && (!strcmp(spec.name, "uintsize") || !strcmp(spec.name, "intsize")))
2281 specType.kind = intSizeType;
2282 if(!strcmp(spec.name, "uintsize"))
2283 specType.isSigned = false;
2287 Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
2288 if(symbol && symbol.type)
2290 // Free Type Contents:
2295 CopyTypeInto(specType, symbol.type);
2296 specType.typeName = CopyString(symbol.type.name);
2298 else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
2300 // key.sym enum values need FindClass:
2301 specType._class = spec.name ? FindClass(spec.name) : null;
2302 specType.kind = classType;
2303 if(!specType._class)
2304 specType.kind = intType;
2308 else if(spec.type == enumSpecifier)
2310 specType.kind = enumType;
2311 specType.enumName = spec.id ? CopyString(spec.id.string) : null;
2317 for(e = spec.list->first; e; e = e.next)
2319 // TOFIX: NamedItem i { } causes cryptic error, bad .c!
2320 NamedLink i { name = CopyString(e.id.string) };
2321 specType.members.Add(i);
2325 else if(spec.type == templateTypeSpecifier)
2327 specType.kind = templateType;
2328 specType.templateParameter = spec.templateParameter;
2330 else if(spec.type == structSpecifier || spec.type == unionSpecifier)
2332 Symbol _class = spec.id ? FindClass(spec.id.string) : null;
2335 if(!_class.registered || _class.registered.type != structClass)
2336 specType.directClassAccess = true;
2337 specType._class = _class;
2338 specType.kind = classType;
2341 if(spec.type == structSpecifier)
2342 specType.kind = structType;
2343 else if(spec.type == unionSpecifier)
2344 specType.kind = unionType;
2347 // TESTING THIS HERE... Had 0 type size
2348 if(!spec.definitions && !isTypedef)
2350 Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
2351 if(symbol && symbol.type)
2353 specType = *symbol.type;
2354 specType.name = CopyString(symbol.type.name);
2355 specType.typeName = CopyString(spec.name);
2356 specType.enumName = CopyString(symbol.type.enumName);
2357 specType.refCount = 1;
2359 if(symbol.type.kind == enumType)
2363 specType.members.Clear();
2364 for(member = symbol.type.members.first; member; member = member.next)
2366 NamedLink item { name = CopyString(member.name), data = member.data };
2367 specType.members.Add(item);
2370 else if(symbol.type.kind == structType || symbol.type.kind == unionType)
2373 // Tricky stuff... will be removed from list only when ref count reaches 0
2374 for(member = specType.members.first; member; member = member.next)
2377 else if(symbol.type.kind == functionType)
2380 specType.returnType.refCount++;
2381 for(param = specType.params.first; param; param = param.next)
2384 else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
2386 specType.type.refCount++;
2387 if(symbol.type.kind == arrayType)
2389 if(specType.arraySizeExp)
2390 specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
2396 specType.enumName = CopyString(spec.id.string);
2399 specType.enumName = CopyString(spec.id.string);
2402 if(spec.definitions)
2405 for(def = spec.definitions->first; def; def = def.next)
2407 if(def.type == declarationClassDef && def.decl.type == structDeclaration)
2409 Declaration decl = def.decl;
2410 if(decl.declarators)
2413 for(d = decl.declarators->first; d; d = d.next)
2415 Type memberType = ProcessType(decl.specifiers, d);
2416 specType.members.Add(memberType);
2419 else if(decl.specifiers)
2421 Type memberType = ProcessType(decl.specifiers, null);
2422 specType.members.Add(memberType);
2429 else if(spec.type == subClassSpecifier)
2431 specType.kind = specType.kind = subClassType;
2432 specType._class = spec._class.symbol;
2436 else if(assumeEllipsis)
2437 specType.kind = ellipsisType;
2441 static Type ProcessTypeDecls(OldList specs, Declarator decl, Type parentType)
2443 Type type = parentType;
2444 Declarator subDecl = decl ? decl.declarator : null;
2446 type = ProcessTypeSpecs(specs, decl == null, (decl && decl.type == extendedDeclaratorEnd) ? true : false);
2451 case bracketsDeclarator: break;
2452 case extendedDeclarator:
2453 case extendedDeclaratorEnd:
2455 ExtDecl extDecl = decl.extended.extended;
2458 switch(extDecl.type)
2462 String s = extDecl.s;
2465 if(!strcmp(s, "__declspec(dllexport)") || !strcmp(s, "dllexport"))
2466 type.dllExport = true;
2467 else if(!strcmp(s, "__declspec(stdcall)") || !strcmp(s, "stdcall"))
2468 type.attrStdcall = true;
2474 OldList * attribs = extDecl.attr.attribs;
2478 for(attr = attribs->first; attr; attr = attr.next)
2480 String s = attr.attr;
2483 if(!strcmp(s, "dllexport"))
2484 type.dllExport = true;
2485 else if(!strcmp(s, "stdcall"))
2486 type.attrStdcall = true;
2490 type.keepCast = true;
2497 case structDeclarator:
2499 Expression exp = decl.structDecl.exp;
2502 ProcessExpressionType(exp);
2503 ComputeExpression(exp);
2504 if(exp.type == constantExp)
2505 type.bitFieldCount = strtoul(exp.constant, null, 0);
2509 case functionDeclarator:
2511 type = { refCount = 1, kind = functionType, returnType = type, dllExport = type.dllExport, attrStdcall = type.attrStdcall };
2512 if(decl.function.parameters)
2515 for(param = decl.function.parameters->first; param; param = param.next)
2516 type.params.Add(ProcessType(param.qualifiers, param.declarator));
2520 case arrayDeclarator:
2522 type = { refCount = 1, kind = arrayType, arraySizeExp = CopyExpression(decl.array.exp), freeExp = true, type = type, dllExport = type.dllExport, attrStdcall = type.attrStdcall };
2523 if(decl.array.enumClass)
2524 type.enumClass = decl.array.enumClass.symbol;
2527 case pointerDeclarator:
2529 Pointer pointer = decl.pointer.pointer;
2532 OldList * qualifiers = pointer.qualifiers;
2533 if(type.classObjectType)
2534 type.byReference = true;
2536 type = { refCount = 1, kind = pointerType, type = type, dllExport = type.dllExport, attrStdcall = type.attrStdcall };
2540 for(spec = qualifiers->first; spec; spec = spec.next)
2542 if(spec.type == baseSpecifier && spec.specifier == CONST)
2543 type.constant = true;
2546 pointer = pointer.pointer;
2550 case identifierDeclarator:
2552 Identifier id = decl.identifier;
2553 Specifier _class = id._class;
2555 type.name = CopyString(id.string);
2558 if(_class.type == templateTypeSpecifier)
2560 type.thisClassTemplate = _class.templateParameter;
2561 type.extraParam = true;
2565 String name = _class.name;
2567 type.staticMethod = true;
2571 id.classSym = _class.symbol; // FindClass(_class.name);
2572 /* TODO: Name Space Fix ups
2573 id.nameSpace = eSystem_FindNameSpace(privateModule, _class.name);
2576 if(name[strlen(name)-1] == '&')
2578 type.thisClass = FindClass("class");
2579 type.byReference = true;
2582 type.thisClass = _class.symbol;
2584 if(type.thisClass && strcmp(type.thisClass.string, "class"))
2585 type.extraParam = true;
2586 else if(!strcmp(name, "any_object"))
2588 type.extraParam = true;
2589 type.thisClass = FindClass("class");
2591 else if(!strcmp(name, "class"))
2593 type.thisClass = FindClass("class");
2594 type.classObjectType = classPointer; // This is used for class properties
2596 else if(!strcmp(name, "typed_object") || !strcmp(name, "typed_object&"))
2598 type.thisClass = FindClass("class");
2599 type.classObjectType = typedObject;
2607 PrintLn("Unhandled Declarator Type: ", decl.type);
2612 Type curType = type;
2613 type = ProcessTypeDecls(null, subDecl, type);
2614 if(curType && type.kind != functionType)
2616 curType.thisClassTemplate = type.thisClassTemplate;
2617 curType.extraParam = type.extraParam;
2618 curType.staticMethod = type.staticMethod;
2619 curType.thisClass = type.thisClass;
2620 curType.byReference = type.byReference;
2621 curType.classObjectType = type.classObjectType;
2627 public Type ProcessType(OldList specs, Declarator decl)
2629 return ProcessTypeDecls(specs, decl, null);
2632 public Type ProcessTypeString(char * string, bool staticMethod)
2634 OldList * specs = MkList();
2635 Declarator decl = SpecDeclFromString(string, specs, null);
2636 Type type = ProcessType(specs, decl);
2637 if(type && !type.thisClass && staticMethod) type.staticMethod = true;
2638 FreeList(specs, FreeSpecifier);
2639 if(decl) FreeDeclarator(decl);
2643 Type MkClassTypeSymbol(Symbol symbol)
2647 Type type { kind = classType, _class = symbol };
2650 // Defaults to an int instead...
2651 type.kind = intType;
2659 public Type MkClassType(char * name)
2663 Type type { kind = classType, _class = FindClass(name) };
2666 // Defaults to an int instead...
2667 type.kind = intType;
2675 AsmField MkAsmField(char * command, Expression expression)
2677 return { command = command, expression = expression };
2680 Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
2682 return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
2683 asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
2684 asmStmt.clobberedFields = clobberedFields };
2687 ClassDef MkClassDefPropertyWatch(PropertyWatch watcher)
2689 return { type = propertyWatchClassDef, propertyWatch = watcher };
2692 Statement MkFireWatchersStmt(Expression object, OldList watches)
2694 return { type = fireWatchersStmt, _watch.object = object, _watch.watches = watches };
2697 Statement MkStopWatchingStmt(Expression watcher, Expression object, OldList watches)
2699 return { type = stopWatchingStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2702 Statement MkWatchStmt(Expression watcher, Expression object, OldList watches)
2704 return { type = watchStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2707 PropertyWatch MkDeleteWatch(Statement compound)
2709 return { compound = compound, deleteWatch = true };
2712 PropertyWatch MkPropertyWatch(OldList properties, Statement compound)
2714 return { compound = compound, properties = properties };
2717 Expression MkExpClass(OldList * specifiers, Declarator decl)
2719 return { type = classExp, _classExp.specifiers = specifiers, _classExp.decl = decl };
2722 Expression MkExpClassData(Identifier id)
2724 return { type = classDataExp, classData.id = id };
2728 External MkExternalDBTable(DBTableDef table)
2730 return { type = dbtableExternal, table = table };
2733 DBTableDef MkDBTableDef(char * name, Symbol symbol, OldList * definitions)
2735 return { name = name, symbol = symbol, definitions = definitions };
2738 DBTableEntry MkDBFieldEntry(TypeName type, Identifier id, char * name)
2740 return { type = fieldEntry, dataType = type, id = id, name = name };
2743 DBIndexItem MkDBIndexItem(Identifier id, Order order)
2745 return { id = id, order = order };
2748 DBTableEntry MkDBIndexEntry(OldList * items, Identifier id)
2750 return { type = indexEntry, items = items, id = id };
2753 Expression MkExpDBOpen(Expression ds, Expression dbName)
2755 return { type = dbopenExp, dbopen.ds = ds, dbopen.name = dbName };
2758 Expression MkExpDBField(char * table, Identifier id)
2760 return { type = dbfieldExp, db.table = table, db.id = id };
2763 Expression MkExpDBIndex(char * table, Identifier id)
2765 return { type = dbindexExp, db.table = table, db.id = id };
2768 Expression MkExpDBTable(char * table)
2770 return { type = dbtableExp, db.table = table };
2773 Expression MkExpArray(OldList * expressions)
2775 return { type = arrayExp, list = expressions };
2778 Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplateParameterType tplType)
2780 Expression argExp = null;
2781 Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
2785 ClassTemplateParameter curParam;
2787 for(sClass = _class; sClass; sClass = sClass.base)
2790 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2792 if(!strcmp(curParam.name, paramName))
2794 for(sClass = sClass.base; sClass; sClass = sClass.base)
2795 id += sClass.templateParams.count;
2803 if(curParam && curParam.type != tplType)
2809 char className[1024];
2810 Expression classExp;
2812 sprintf(idString, "%d", id);
2813 strcpy(className, "__ecereClass_");
2814 FullClassNameCat(className, _class.fullName, true);
2815 MangleClassName(className);
2816 DeclareClass(FindClass(_class.fullName), className);
2818 argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
2819 (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
2820 MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
2826 Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
2828 return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
2831 /*char * CreateMsgID(char * string, char * context)
2833 int lenString = strlen(string), lenContext = strlen(context);
2834 char * msgid = new char[lenString + lenContext + 20];
2835 memcpy(msgid, string, lenString);
2836 memcpy(msgid+lenString, " [msgctxt: ", 11);
2837 memcpy(msgid+lenString+11, context, lenContext);
2838 memcpy(msgid+lenString+11+lenContext, "]", 2);
2842 public void OutputIntlStrings()
2844 if(intlStrings.count)
2846 char * srcFile = GetSourceFile();
2847 char * objFile = GetOutputFile();
2848 char srcFileFixed[MAX_LOCATION];
2849 char potFile[MAX_LOCATION];
2851 ChangeExtension(objFile, "bowl", potFile);
2852 f = FileOpen(potFile, write);
2855 char * filePrefix = "";
2856 if(!(srcFile[0] && (srcFile[1] == ':' || srcFile[0] == '/')))
2857 filePrefix = "./"; //(GetRuntimePlatform() == win32) ? ".\\" : "./";
2858 // GetSystemPathBuffer(srcFileFixed, srcFile);
2859 GetSlashPathBuffer(srcFileFixed, srcFile);
2860 for(s : intlStrings)
2862 // TOFIX: (#654) ContextStringPair * pair = &s;
2863 ContextStringPair pair = &s;
2865 f.Printf("#: %s%s:%d\n", filePrefix, srcFileFixed, l.start.line);
2866 // PoEdit now preserves and distinguish msgctxt
2868 f.Printf("msgctxt \"%s\"\n", pair.context);
2869 f.Printf("msgid \"%s\"\n", pair.string);
2870 f.Printf("msgstr \"%s\"\n\n", pair.string);
2878 default extern OldList * ast;
2879 default extern int yyparse ();
2881 public void SetAST(OldList * list) { ast = list; }
2882 public OldList * GetAST() { return ast; }
2883 public void ParseEc()