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 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;
622 for(spec = qualifiers.first; spec; spec = spec.next)
624 if(gotType && !declarator && ((spec.type == nameSpecifier && spec.name) || (spec.type == baseSpecifier && gotFullType)))
627 if(spec.type == nameSpecifier)
629 char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
630 s = colon ? colon + 2 : spec.name;
632 else if(spec.type == baseSpecifier)
634 if(spec.specifier == INT64) s = "int64";
638 typeName.declarator = declarator = MkDeclaratorIdentifier(MkIdentifier(CopyString(s)));
639 qualifiers.Remove(spec);
643 if(spec.type != extendedSpecifier)
645 if(spec.type != baseSpecifier || (spec.specifier != UNSIGNED && spec.specifier != SIGNED && spec.specifier != LONG))
654 public Identifier GetDeclId(Declarator decl)
656 while(decl && decl.type != identifierDeclarator)
657 decl = decl.declarator;
658 return decl ? decl.identifier : null;
661 Declaration MkDeclarationClassInst(Instantiation inst)
663 return { type = instDeclaration, inst = inst, loc = yylloc };
666 Declaration MkDeclarationInst(Instantiation inst)
668 Declaration decl { type = instDeclaration, inst = inst, loc = yylloc };
670 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
673 int len = 0, stringLen;
676 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
677 len += defaultNameSpaceLen;
683 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
684 len += currentNameSpaceLen;
689 stringLen = strlen(inst.exp.identifier.string);
690 memcpy(name + len, inst.exp.identifier.string, stringLen);
693 delete inst.exp.identifier.string;
694 inst.exp.identifier.string = CopyString(name);
699 string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
700 type = MkClassTypeSymbol(inst._class.symbol);
702 symbol.idCode = symbol.id = curContext.nextID++;
703 if(strstr(symbol.string, "::"))
704 curContext.hasNameSpace = true;
705 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
706 excludedSymbols->Add(symbol);
707 decl.symbol = inst.symbol = symbol;
711 Declaration MkDeclarationDefine(Identifier id, Expression exp)
713 Declaration decl { type = defineDeclaration, id = id, exp = exp, loc = yylloc };
714 char expString[1024];
717 PrintExpression(exp, expString);
719 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
722 int len = 0, stringLen;
725 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
726 len += defaultNameSpaceLen;
732 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
733 len += currentNameSpaceLen;
737 stringLen = strlen(id.string);
738 memcpy(name + len, id.string, stringLen);
742 id.string = CopyString(name);
745 if(!eSystem_FindDefine(privateModule, id.string))
746 eSystem_RegisterDefine(id.string, expString, privateModule, buildingECERECOMModule ? baseSystemAccess : publicAccess);
748 Compiler_Warning($"Redefinition of %s ignored\n", id.string);
752 Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
754 Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
755 bool variable = true;
757 if(specifiers != null)
759 bool gotType = false;
761 for(spec = specifiers.first; spec; spec = spec.next)
763 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
765 if(initDeclarators != null)
769 for(d = initDeclarators.first; d; d = d.next)
771 if(GetDeclId(d.declarator).string)
775 string = CopyString(GetDeclId(d.declarator).string);
776 type = ProcessType(specifiers, d.declarator);
778 type.id = type.idCode = curContext.nextID++;
780 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
781 excludedSymbols->Add(type);
782 decl.symbol = d.declarator.symbol = type;
788 //for(spec = spec.next; spec; spec = spec.next)
789 spec = specifiers.last;
791 if((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier)
794 if(spec.type == nameSpecifier)
796 char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
797 s = colon ? colon + 2 : spec.name;
799 else if(spec.type == baseSpecifier)
801 if(spec.specifier == INT64) s = "int64";
805 Symbol type { string = CopyString(s), type = ProcessType(specifiers, null) };
806 type.id = type.idCode = curContext.nextID++;
808 decl.declarators = initDeclarators = MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(CopyString(s))), null));
809 specifiers.Remove(spec);
811 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
812 excludedSymbols->Add(type);
820 else if(spec.type == baseSpecifier &&
821 (spec.specifier == STRUCT || spec.specifier == UNION))
825 if(gotType && initDeclarators == null && !spec.next && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
828 if(spec.type == nameSpecifier)
830 char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
831 s = colon ? colon + 2 : spec.name;
833 else if(spec.type == baseSpecifier)
835 if(spec.specifier == INT64) s = "int64";
839 decl.declarators = initDeclarators = MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(CopyString(s))), null));
840 specifiers.Remove(spec);
845 if(spec.type != extendedSpecifier)
849 if(variable && initDeclarators)
852 for(d = initDeclarators.first; d; d = d.next)
854 Identifier id = GetDeclId(d.declarator);
855 if(id && id.string && id.string[0])
861 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
864 int len = 0, stringLen;
867 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
868 len += defaultNameSpaceLen;
874 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
875 len += currentNameSpaceLen;
879 stringLen = strlen(id.string);
880 memcpy(name + len, id.string, stringLen);
884 id.string = CopyString(name);
887 // Avoid memory leaks on duplicated symbols (BinaryTree::Add Would Fail)
888 symbol = (Symbol)(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.FindString(id.string);
891 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specifiers, d.declarator) };
892 if(strstr(symbol.string, "::"))
893 curContext.hasNameSpace = true;
894 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
895 excludedSymbols->Add(symbol);
896 // TODO: Add better support to count declarators
897 if(symbol.type && symbol.type.kind == arrayType && !symbol.type.arraySizeExp && d.initializer)
899 if(d.initializer.type == listInitializer)
902 sprintf(string, "%d",d.initializer.list->count);
903 symbol.type.arraySizeExp = MkExpConstant(string);
904 symbol.type.freeExp = true;
906 else if(d.initializer.type == expInitializer && d.initializer.exp.type == stringExp && d.initializer.exp.string)
911 bool escaped = false;
912 char * s = d.initializer.exp.string;
914 // MAKE MORE ACCURATE
915 for(c = 1; (ch = s[c]); c++)
917 if(ch == '\\' && !escaped)
926 sprintf(string, "%d", count);
927 symbol.type.arraySizeExp = MkExpConstant(string);
928 symbol.type.freeExp = true;
931 symbol.id = symbol.idCode = curContext.nextID++;
933 decl.symbol = d.declarator.symbol = symbol;
940 decl.symbol = Symbol { };
941 decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
942 excludedSymbols->Add(decl.symbol);
947 Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifier extStorage)
949 Declaration decl { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
950 if(specifiers != null)
952 bool gotType = false;
954 for(spec = specifiers.first; spec; spec = spec.next)
956 if(gotType && declarators == null && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
959 if(spec.type == nameSpecifier)
961 char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
962 s = colon ? colon + 2 : spec.name;
964 else if(spec.type == baseSpecifier)
966 if(spec.specifier == INT64) s = "int64";
970 decl.declarators = declarators = MkListOne(MkDeclaratorIdentifier(MkIdentifier(CopyString(s))));
971 specifiers.Remove(spec);
975 if(spec.type != extendedSpecifier)
982 Statement MkLabeledStmt(Identifier id, Statement statement)
984 return { type = labeledStmt, labeled.id = id, labeled.stmt = statement, loc = yylloc };
987 Statement MkCaseStmt(Expression exp, Statement statement)
989 return { type = caseStmt, caseStmt.exp = exp, caseStmt.stmt = statement, loc = yylloc };
992 Statement MkCompoundStmt(OldList declarations, OldList statements)
994 return { type = compoundStmt, compound.declarations = declarations, compound.statements = statements, loc = yylloc };
997 Statement MkExpressionStmt(OldList expressions)
999 return { type = expressionStmt, expressions = expressions, loc = yylloc };
1002 Statement MkBadDeclStmt(Declaration decl)
1004 return { type = badDeclarationStmt, decl = decl, loc = yylloc };
1007 Statement MkIfStmt(OldList exp, Statement statement, Statement elseStmt)
1009 return { type = ifStmt, ifStmt.exp = exp, ifStmt.stmt = statement, ifStmt.elseStmt = elseStmt, loc = yylloc };
1012 Statement MkSwitchStmt(OldList exp, Statement statement)
1014 // To know it's a switch compound... (Don't want declarations in there... bugs)
1016 statement.compound.isSwitch = true;
1017 return { type = switchStmt, switchStmt.exp = exp, switchStmt.stmt = statement, loc = yylloc };
1020 Statement MkWhileStmt(OldList exp, Statement statement)
1022 return { type = whileStmt, whileStmt.exp = exp, whileStmt.stmt = statement, loc = yylloc };
1025 Statement MkDoWhileStmt(Statement statement, OldList exp)
1027 return { type = doWhileStmt, doWhile.exp = exp, doWhile.stmt = statement, loc = yylloc };
1030 Statement MkForStmt(Statement init, Statement check, OldList inc, Statement statement)
1032 return { type = forStmt, forStmt.init = init, forStmt.check = check, forStmt.increment = inc, forStmt.stmt = statement, loc = yylloc };
1035 Statement MkForEachStmt(Identifier id, OldList exp, OldList filter, Statement statement)
1037 return { type = forEachStmt, forEachStmt.id = id, forEachStmt.exp = exp, forEachStmt.filter = filter, forEachStmt.stmt = statement, loc = yylloc };
1040 Statement MkGotoStmt(Identifier id)
1042 return { type = gotoStmt, gotoStmt.id = id, loc = yylloc };
1045 Statement MkContinueStmt()
1047 return { type = continueStmt, loc = yylloc };
1050 Statement MkBreakStmt()
1052 return { type = breakStmt, loc = yylloc };
1055 Statement MkReturnStmt(OldList exp)
1057 return { type = returnStmt, expressions = exp, loc = yylloc };
1060 FunctionDefinition MkFunction(OldList specifiers, Declarator declarator, OldList declarationList)
1062 return { specifiers = specifiers, declarator = declarator, declarations = declarationList };
1065 void ProcessFunctionBody(FunctionDefinition func, Statement body)
1067 Declarator declarator = func.declarator;
1068 Declarator funcDecl = GetFuncDecl(declarator);
1073 if(funcDecl && funcDecl.function.parameters && body)
1075 Context context = body.compound.context;
1077 for(param = funcDecl.function.parameters->first; param; param = param.next)
1079 if(param.declarator)
1081 Symbol symbol = null;
1082 Identifier id = GetDeclId(param.declarator);
1083 char * string = id ? id.string : null;
1086 for(symbol = (Symbol)context.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
1087 if(!strcmp(symbol.string, string))
1089 // This parameter is not shadowed by a local declaration
1092 symbol = Symbol { string = CopyString(id.string), type = ProcessType(param.qualifiers, param.declarator), isParam = true };
1093 if(!context.symbols.Add((BTNode)symbol))
1094 excludedSymbols->Add(symbol);
1096 // TODO: Fix this, the parameters' IDs should really be smaller...
1097 symbol.id = context.nextID++;
1098 param.declarator.symbol = symbol;
1105 if(!declarator.symbol)
1107 Identifier id = GetDeclId(declarator);
1109 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess && strcmp(id.string, "__on_register_module"))
1112 int len = 0, stringLen;
1113 if(defaultNameSpace)
1115 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1116 len += defaultNameSpaceLen;
1120 if(currentNameSpace)
1122 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1123 len += currentNameSpaceLen;
1127 stringLen = strlen(id.string);
1128 memcpy(name + len, id.string, stringLen);
1132 id.string = CopyString(name);
1134 symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
1135 symbol.idCode = symbol.id = globalContext.nextID++;
1136 if(strstr(symbol.string, "::"))
1137 globalContext.hasNameSpace = true;
1138 if(!globalContext.symbols.Add((BTNode)symbol))
1139 excludedSymbols->Add(symbol);
1140 declarator.symbol = symbol;
1144 symbol = declarator.symbol;
1145 excludedSymbols->Remove(declarator.symbol);
1146 delete symbol.string;
1147 symbol.string = CopyString(GetDeclId(declarator).string);
1148 if(strstr(symbol.string, "::"))
1149 globalContext.hasNameSpace = true;
1150 if(!globalContext.symbols.Add((BTNode)symbol))
1151 excludedSymbols->Add(symbol);
1154 symbol.type = ProcessType(func.specifiers, declarator);
1156 if(symbol.type && (symbol.type.kind == functionType || symbol.type.kind == methodType))
1158 if(!symbol.type.params.count)
1160 Type type { refCount = 1 };
1161 symbol.type.params.Add(type);
1170 External MkExternalFunction(FunctionDefinition function)
1172 External external { type = functionExternal, function = function, symbol = function.declarator.symbol };
1173 if(function.specifiers)
1176 for(spec = function.specifiers->first; spec; spec = spec.next)
1177 if(spec.type == baseSpecifier && spec.specifier == STATIC)
1179 declMode = staticAccess;
1184 if(external.symbol && !external.symbol.methodExternal)
1185 external.symbol.methodExternal = external;
1189 External MkExternalImport(char * name, ImportType importType, AccessMode importAccess)
1191 External external { type = importExternal };
1192 int len = strlen(name) - 2;
1193 external.importString = new char[len + 1];
1194 strncpy(external.importString, name+1, len);
1195 external.importString[len] = '\0';
1200 Time startTime = GetTime();
1203 ImportModule(external.importString, importType, importAccess, true);
1204 ImportModule(external.importString, importType, importAccess, false);
1206 time = GetTime() - startTime;
1207 printf("Importing took %.3f seconds for %s\n", time, external.importString);
1208 externalImportTotalTime += time;
1214 External MkExternalDeclaration(Declaration declaration)
1216 External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
1217 InitDeclarator d = (declaration && declaration.declarators) ? declaration.declarators->last : null;
1218 if(declaration && declaration.type == initDeclaration && declaration.specifiers)
1221 for(spec = declaration.specifiers->first; spec; spec = spec.next)
1222 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1224 declMode = defaultAccess;
1227 else if(spec.type == baseSpecifier && spec.specifier == STATIC)
1229 declMode = staticAccess;
1233 if(declaration && declaration.symbol && !declaration.symbol.methodExternal)
1234 declaration.symbol.methodExternal = external;
1238 External MkExternalNameSpace(Identifier identifier)
1240 External external { type = nameSpaceExternal, id = identifier };
1241 currentNameSpace = identifier ? identifier.string : null;
1242 currentNameSpaceLen = currentNameSpace ? strlen(currentNameSpace) : 0;
1246 void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
1248 if(spec.type == nameSpecifier)
1250 Symbol symbol = spec.symbol;
1251 spec.templateArgs = templateArgs;
1252 if(templateArgs && templateArgs.first)
1254 char templateString[1024];
1255 TemplateArgument arg;
1256 strcpy(templateString, symbol ? symbol.string : spec.name);
1257 strcat(templateString, "<");
1258 for(arg = templateArgs.first; arg; arg = arg.next)
1266 char expString[1024];
1267 Class backupThisClass = thisClass;
1269 expString[0] = '\0';
1270 // Will this work here?
1272 Location oldLocation = yylloc;
1273 File backFileInput = fileInput;
1278 // TESTING THIS SCANNER RESUME STUFF
1281 yylloc = oldLocation;
1282 fileInput = backFileInput;
1285 fileInput.Seek(yylloc.start.pos, start);
1286 resetScannerPos(&yylloc.start);
1291 //ProcessExpressionType(arg.expression);
1292 //ComputeExpression(arg.expression);
1293 PrintExpression(arg.expression, expString);
1294 strcat(argument, expString);
1295 thisClass = backupThisClass;
1300 strcat(argument, arg.identifier.string);
1305 char * typeString = StringFromSpecDecl(arg.templateDatatype.specifiers, arg.templateDatatype.decl);
1306 strcat(argument, typeString);
1313 if(arg.prev) strcat(templateString, ", ");
1316 strcat(templateString, arg.name.string);
1317 strcat(templateString, " = ");
1319 strcat(templateString, argument);
1323 int len = strlen(templateString);
1324 if(templateString[len-1] == '>') templateString[len++] = ' ';
1325 templateString[len++] = '>';
1326 templateString[len++] = '\0';
1328 // printf("SetClassTemplateArgs templateString: %s\n", templateString);
1329 symbol = FindClass(templateString);
1330 if(!symbol && spec.symbol)
1332 // If class was only decl'ed, invoke DeclClass on this templated class as well
1333 symbol = _DeclClass(MAXINT, templateString);
1335 // Add a reference to all templated class to the basic class
1337 spec.symbol.templatedClasses.Add(OldLink { data = symbol });
1339 spec.symbol = symbol;
1340 spec.name = CopyString(symbol ? symbol.string : templateString);
1344 FreeList(templateArgs, FreeTemplateArgument);
1347 Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
1349 Specifier spec { type = nameSpecifier };
1355 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
1358 spec.templateParameter = templatedType.param;
1359 spec.type = templateTypeSpecifier;
1363 symbol = FindClass(name);
1365 if(symbol && symbol.registered && symbol.registered.isRemote == 1)
1367 char className[1024];
1368 strcpy(className, "DCOMClient_");
1369 if(!strncmp(name, className, strlen(className)))
1370 spec.name = CopyString(name);
1373 strcat(className, name);
1374 spec.name = CopyString(className);
1378 spec.name = CopyString(symbol.string);
1380 spec.name = CopyString(name);
1381 spec.symbol = symbol;
1382 if(templateArgs != null)
1383 SetClassTemplateArgs(spec, templateArgs);
1388 public Specifier MkSpecifierName(char * name)
1390 return _MkSpecifierName(name, null, null);
1393 public Specifier MkSpecifierNameArgs(char * name, OldList * templateArgs)
1395 return _MkSpecifierName(name, null, templateArgs);
1399 Specifier MkClassName(char * string)
1401 return { type = SpecifierClass, name = CopyString(string) };
1404 ClassFunction MkClassFunction(OldList specifiers, Specifier _class, Declarator decl, OldList declList)
1406 return { specifiers = specifiers, /*_class = _class,*/ declarator = decl, declarations = declList };
1409 void ProcessClassFunctionBody(ClassFunction func, Statement body)
1413 Declarator decl = func.declarator;
1415 //Declarator decl = GetFuncDecl(func.declarator);
1416 Declarator funcDecl = GetFuncDecl(func.declarator);
1420 if(decl && !decl.symbol)
1422 OldList * symbolSpecs = MkList();
1424 // WHAT WILL WE DO WITH THIS? Double instances?
1425 //if(decl.function.parameters && body)
1426 if(funcDecl && funcDecl.function.parameters && body)
1428 Context context = body.compound.context;
1430 for(param = funcDecl.function.parameters->first; param; param = param.next)
1432 if(param.declarator)
1434 Symbol symbol = null;
1435 Identifier id = GetDeclId(param.declarator);
1436 char * string = id ? id.string : null;
1439 symbol = (Symbol)context.symbols.FindString(string);
1441 // This parameter is not shadowed by a local declaration
1446 string = CopyString(id.string);
1447 type = ProcessType(param.qualifiers, param.declarator);
1451 // TODO: Fix this, the parameters' IDs should really be smaller...
1452 symbol.idCode = symbol.id = context.nextID++;
1453 if(!context.symbols.Add((BTNode)symbol))
1454 excludedSymbols->Add(symbol);
1456 param.declarator.symbol = symbol;
1461 //////////////////////////////////
1469 Identifier id = GetDeclId(funcDecl);
1473 for(c = strlen(id.string)-1; c >= 0; c--)
1475 if(id.string[c] == ':')
1477 char * string = CopyString(id.string + c + 1);
1478 id.string[c - 1] = 0;
1479 id._class = MkSpecifierName(id.string);
1485 symbol.string = CopyString(id.string);
1492 for(spec = func.specifiers->first; spec; spec = spec.next)
1493 symbolSpecs->Add(CopySpecifier(spec));
1495 symbol.type = ProcessType(symbolSpecs, decl);
1496 symbol.idCode = symbol.id = globalContext.nextID++;
1497 decl.symbol = symbol;
1499 excludedSymbols->Add(symbol);
1501 FreeList(symbolSpecs, FreeSpecifier);
1505 OldList * MkSpecsClass(Specifier _class)
1507 OldList * list = MkList();
1508 ListAdd(list, _class);
1512 MemberInit MkMemberInit(OldList ids, Initializer initializer)
1514 return { identifiers = ids, initializer = initializer };
1517 MemberInit MkMemberInitExp(Expression idExp, Initializer initializer)
1519 MemberInit init { initializer = initializer, identifiers = MkList() };
1522 for(exp = idExp; exp && exp.type == memberExp; exp = exp.member.exp)
1524 init.identifiers->Insert(null, exp.member.member);
1525 exp.member.member = null;
1527 if(exp && exp.type == identifierExp)
1529 init.identifiers->Insert(null, exp.identifier);
1530 exp.identifier = null;
1532 FreeExpression(idExp);
1536 MembersInit MkMembersInitList(OldList dataMembers)
1538 return { type = dataMembersInit, dataMembers = dataMembers };
1541 MembersInit MkMembersInitMethod(ClassFunction function)
1543 return { type = methodMembersInit, function = function };
1546 Instantiation MkInstantiation(Specifier _class, Expression exp, OldList members)
1548 return { _class = _class, exp = exp, members = members };
1551 Instantiation MkInstantiationNamed(OldList specs, Expression exp, OldList members)
1553 Instantiation inst { exp = exp, members = members };
1558 for(spec = specs.first; spec; spec = spec.next)
1559 if(spec.type == nameSpecifier /*classSpecifier*/)
1566 FreeList(specs, FreeSpecifier);
1570 Compiler_Error($"Expecting class specifier\n");
1571 inst._class = MkSpecifierName /*MkClassName*/("");
1579 ClassDef MkClassDefAccessOverride(AccessMode access, Identifier id)
1581 return { type = accessOverrideClassDef, id = id, memberAccess = access };
1584 ClassDef MkClassDefMemberAccess()
1586 return { type = memberAccessClassDef };
1589 ClassDef MkClassDefDeclaration(Declaration decl)
1591 return { type = declarationClassDef, decl = decl };
1594 ClassDef MkClassDefClassData(Declaration decl)
1596 return { type = classDataClassDef, decl = decl };
1599 ClassDef MkClassDefDesigner(char * designer)
1601 return { type = classDesignerClassDef, designer = CopyString(designer) };
1604 ClassDef MkClassDefNoExpansion()
1606 return { type = classNoExpansionClassDef };
1609 ClassDef MkClassDefFixed()
1611 return { type = classFixedClassDef };
1614 ClassDef MkClassDefDesignerDefaultProperty(Identifier id)
1616 return { type = designerDefaultPropertyClassDef, defaultProperty = id };
1619 ClassDef MkClassDefDefaultProperty(OldList defProperties)
1621 return { type = defaultPropertiesClassDef, defProperties = defProperties };
1624 ClassDef MkClassDefFunction(ClassFunction function)
1627 if(function && function.declarator)
1629 Declarator funcDecl = GetFuncDecl(function.declarator);
1630 if(funcDecl && funcDecl.declarator && funcDecl.declarator.type == bracketsDeclarator)
1632 def.type = declarationClassDef;
1633 def.decl = MkStructDeclaration(function.specifiers, MkListOne(MkStructDeclarator(function.declarator, null)), null);
1634 function.declarator = null;
1635 function.specifiers = null;
1636 FreeClassFunction(function);
1640 def.type = functionClassDef;
1641 def.function = function;
1645 Symbol DeclClassAddNameSpace(int symbolID, char * className)
1648 int len = 0, stringLen;
1650 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1652 if(defaultNameSpace)
1654 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1655 len += defaultNameSpaceLen;
1659 if(currentNameSpace)
1661 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1662 len += currentNameSpaceLen;
1667 stringLen = strlen(className);
1668 memcpy(name + len, className, stringLen);
1671 return _DeclClass(symbolID, name);
1674 Symbol DeclClass(int symbolID, char * name)
1676 if(strchr(name, ':'))
1677 return _DeclClass(symbolID, name);
1679 return DeclClassAddNameSpace(symbolID, name);
1682 Symbol _DeclClass(int symbolID, char * name)
1684 Symbol symbol = FindClass(name);
1688 Context classContext;
1689 for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
1695 if(name[0] == ':' && name[1] == ':')
1699 string = CopyString(name);
1700 idCode = symbolID, id = symbolID;
1702 if(!globalContext.classes.Add((BTNode)symbol))
1703 excludedSymbols->Add(symbol);
1708 for(c = 0; (ch = name[c]); c++)
1710 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
1716 if(start && c - start)
1717 symbol.shortName = CopyString(name + start);
1721 symbol.idCode = symbol.id = symbolID;
1725 void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
1727 if(baseSpecs && baseSpecs.first && ((Specifier)baseSpecs.first).type == nameSpecifier)
1732 strcpy(name, ((Specifier)baseSpecs.first).name);
1733 tpl = strchr(name, '<');
1736 baseClass = FindClass(name);
1740 for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
1742 TemplatedType type { key = copy.key, param = copy.param };
1743 if(!curContext.templateTypes.Add((BTNode)type))
1747 else if(baseClass.registered)
1750 for(sClass = baseClass.registered; sClass; sClass = sClass.base)
1752 ClassTemplateParameter p;
1753 for(p = sClass.templateParams.first; p; p = p.next)
1755 //OldList * specs = MkList();
1756 //Declarator decl = null;
1757 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
1760 TemplateParameter param = p.param;
1764 p.param = param = TemplateParameter
1766 identifier = MkIdentifier(p.name), type = p.type,
1767 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
1770 type = TemplatedType { key = (uintptr)p.name, param = param };
1771 if(!curContext.templateTypes.Add((BTNode)type))
1780 ClassDefinition MkClass(Symbol symbol, OldList baseSpecs, OldList definitions)
1782 ClassDefinition classDef;
1783 SetupBaseSpecs(symbol, baseSpecs);
1786 ClassDefinition classDef = symbol.ctx.classDef;
1789 // This can occur if two instances of a class are defined...
1790 // To avoid dangling 'parent' Contexts, we free the previous class definition
1792 for(external = ast->first; external; external = external.next)
1794 if(external.type == classExternal && external._class == classDef)
1796 ast->Remove(external);
1797 FreeExternal(external);
1802 FreeContext(symbol.ctx);
1805 symbol.ctx = curContext;
1806 classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
1807 curContext.classDef = classDef;
1811 Expression MkExpInstance(Instantiation inst)
1813 return { type = instanceExp, instance = inst };
1816 External MkExternalClass(ClassDefinition _class)
1818 return { type = classExternal, _class = _class, symbol = _class.symbol };
1821 PropertyDef MkProperty(OldList specs, Declarator decl, Identifier id, Statement setStmt, Statement getStmt)
1831 Type type = ProcessType(specs, decl);
1834 char typeString[1024];
1835 typeString[0] = '\0';
1836 PrintType(type, typeString, false, true);
1837 id = MkIdentifier(typeString);
1838 prop.conversion = true;
1844 string = CopyString(id.string);
1847 symbol.idCode = symbol.id = globalContext.nextID++;
1848 excludedSymbols->Add(symbol);
1849 globalContext.nextID++;
1850 globalContext.nextID++;
1851 prop.symbol = symbol;
1855 ClassDef MkClassDefProperty(PropertyDef propertyDef)
1857 return { type = propertyClassDef, propertyDef = propertyDef };
1860 ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
1862 return { type = classPropertyClassDef, propertyDef = propertyDef };
1865 ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
1867 return { type = classPropertyValueClassDef, id = id, initializer = initializer };
1870 int CheckType(char * text)
1873 Time startTime = GetTime();
1875 if(FindTemplateTypeParameter(curContext, text))
1878 checkTypeTotalTime += GetTime() - startTime;
1882 if(FindType(curContext, text))
1885 checkTypeTotalTime += GetTime() - startTime;
1892 checkTypeTotalTime += GetTime() - startTime;
1894 return TYPE_NAME; //CLASS_NAME;
1897 checkTypeTotalTime += GetTime() - startTime;
1904 return CheckType(yytext);
1907 Context PushContext()
1909 Context ctx { parent = curContext };
1914 void PopContext(Context ctx)
1916 curContext = ctx.parent;
1919 Symbol FindType(Context ctx, char * name)
1924 //char output[8192];
1925 type = (Symbol)ctx.types.FindString(name);
1926 /*if(!strcmp(name, "intptr_t") && !type)
1928 ctx.types.Print(output, depthOrder);
1931 if(!type && ctx.parent)
1932 type = FindType(ctx.parent, name);
1937 TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
1939 TemplatedType templatedType = null;
1942 templatedType = (TemplatedType)ctx.templateTypes.FindString(name);
1943 if(!templatedType && ctx.parent)
1944 templatedType = FindTemplateTypeParameter(ctx.parent, name);
1946 return templatedType;
1949 bool ModuleAccess(Module searchIn, Module searchFor)
1951 SubModule subModule;
1953 if(searchFor == searchIn)
1956 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
1958 if(subModule.importMode == publicAccess /*|| searchIn == searchIn.application*/)
1960 if(ModuleAccess(subModule.module, searchFor))
1967 ModuleImport FindModule(Module moduleToFind)
1969 ModuleImport module;
1970 if(!moduleToFind.name)
1972 for(module = imports->first; module; module = module.next)
1973 if(module.name && !strcmp(module.name, moduleToFind.name))
1977 module = ModuleImport
1979 name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
1980 importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
1982 imports->Add(module);
1988 // TO REMOVE: OBSOLETE...
1989 static void GetFullClassNameSpace(NameSpace * ns, char * name)
1993 GetFullClassNameSpace(ns->parent, name);
1994 strcat(name, ns->name);
1999 static char * GetFullClassName(Class c, char * name)
2001 NameSpace * nameSpace;
2003 GetFullClassNameSpace(c.nameSpace, name);
2004 strcat(name, c.name);
2009 public Symbol FindClass(char * name)
2012 Time startTime = GetTime();
2016 bool global = false;
2017 char fullName[1024];
2019 if(name[0] == ':' && name[1] == ':')
2025 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
2027 int len = 0, stringLen;
2028 if(defaultNameSpace)
2030 memcpy(fullName, defaultNameSpace, defaultNameSpaceLen);
2031 len += defaultNameSpaceLen;
2032 fullName[len++] = ':';
2033 fullName[len++] = ':';
2035 if(currentNameSpace)
2037 memcpy(fullName + len, currentNameSpace, currentNameSpaceLen);
2038 len += currentNameSpaceLen;
2039 fullName[len++] = ':';
2040 fullName[len++] = ':';
2042 stringLen = strlen(name);
2043 memcpy(fullName + len, name, stringLen);
2046 cl = globalContext ? (Symbol)globalContext.classes.FindString(fullName) : null;
2050 cl = globalContext ? (Symbol)globalContext.classes.FindString(name) : null;
2055 Time startTime = GetTime();
2057 // Ignore name space name when searching
2058 for(cl = globalContext ? (Symbol)globalContext.classes.first : null; cl; cl = (Symbol)((BTNode)cl).next)
2062 char * string = cl.string;
2064 for(c = 0; (ch = string[c]); c++)
2066 if(ch == '.' || (ch == ':' && string[c+1] == ':'))
2072 if(start && c - start)
2074 if(!strcmp(string + start, name))
2078 if(cl.shortName && !strcmp(cl.shortName, name))
2082 findClassIgnoreNSTotalTime += GetTime() - startTime;
2088 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
2089 _class = eSystem_FindClass(privateModule, fullName);
2091 _class = eSystem_FindClass(privateModule, name);
2095 name = _class.fullName;
2097 cl = (Symbol)globalContext.classes.FindString(name);
2102 string = CopyString(name);
2103 registered = _class;
2110 cl.module = FindModule(_class.module);
2112 cl.module = mainModule;
2113 if(!globalContext.classes.Add((BTNode)cl))
2114 excludedSymbols->Add(cl);
2115 if(strcmp(name, _class.name))
2116 cl.shortName = CopyString(_class.name);
2121 findClassTotalTime += GetTime() - startTime;
2126 void CopyTypeInto(Type type, Type src)
2129 type.name = CopyString(src.name);
2130 type.enumName = CopyString(src.enumName);
2133 if(src.kind == enumType)
2137 type.members.Clear();
2138 // This must have been a mistake: member = **type**.members.first
2139 for(member = src.members.first; member; member = member.next)
2141 type.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
2144 else if(src.kind == structType || src.kind == unionType)
2147 // Tricky stuff... will be removed from list only when ref count reaches 0
2148 for(member = type.members.first; member; member = member.next)
2151 else if(src.kind == functionType)
2154 type.returnType.refCount++;
2155 for(param = type.params.first; param; param = param.next)
2158 else if(src.kind == pointerType || src.kind == arrayType)
2160 type.type.refCount++;
2161 if(src.kind == arrayType)
2163 if(type.arraySizeExp)
2164 type.arraySizeExp = CopyExpression(type.arraySizeExp);
2171 // *** TOADD: ********************************************************
2172 while(decl && (decl.type == structDeclarator || decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd))
2174 if(decl.type == structDeclarator && decl.structDecl.exp)
2176 ProcessExpressionType(decl.structDecl.exp);
2177 ComputeExpression(decl.structDecl.exp);
2178 if(decl.structDecl.exp.type == constantExp)
2179 specType.bitFieldCount = strtoul(decl.structDecl.exp.constant, null, 0);
2181 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended && decl.extended.extended.type == extDeclString &&
2182 decl.extended.extended.s && (!strcmp(decl.extended.extended.s, "__declspec(dllexport)") || !strcmp(decl.extended.extended.s, "dllexport")))
2186 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended && decl.extended.extended.type == extDeclAttrib)
2188 specType.keepCast = true;
2190 decl = decl.declarator;
2193 // *** TOADD: ********************************************************
2197 if(id._class && !id._class.name)
2198 ptrType.type.staticMethod = true;
2201 // TODO : Ensure classSym has been resolved here... (Is this gonna cause problems? Supposed to do this later...)
2204 if(id._class && id._class.name)
2206 id.classSym = id._class.symbol; // FindClass(id._class.name);
2207 /* TODO: Name Space Fix ups
2209 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
2214 ptrType.type.thisClass = id.classSym;
2215 if(ptrType.type.thisClass && strcmp(ptrType.type.thisClass.string, "class"))
2216 ptrType.type.extraParam = true;
2217 else if(id._class && id._class.name && !strcmp(id._class.name, "any_object"))
2219 ptrType.type.extraParam = true;
2220 ptrType.type.thisClass = FindClass("class");
2224 type.name = CopyString(id.string);
2226 // *** TOADD: ********************************************************
2227 if(d.type == identifierDeclarator)
2229 if(d.identifier._class && d.identifier._class.type == templateTypeSpecifier)
2231 type.thisClassTemplate = d.identifier._class.templateParameter;
2232 type.extraParam = true;
2236 if(d.identifier._class && !d.identifier._class.name)
2237 type.staticMethod = true;
2240 if(d.identifier._class && d.identifier._class.name && d.identifier._class.name[strlen(d.identifier._class.name)-1] == '&')
2242 type.thisClass = FindClass("class");
2243 type.byReference = true;
2246 type.thisClass = d.identifier._class ? d.identifier._class.symbol /*FindClass(d.identifier._class.name)*/ : null;
2247 if(type.thisClass && strcmp(type.thisClass.string, "class"))
2249 type.extraParam = true;
2251 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "any_object"))
2253 type.extraParam = true;
2254 type.thisClass = FindClass("class");
2256 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "class"))
2258 //type.extraParam = true;
2259 type.thisClass = FindClass("class");
2260 type.classObjectType = classPointer;
2264 type.name = CopyString(d.identifier.string);
2267 // *** TOADD: ********************************************************
2268 if(type.classObjectType)
2270 type.byReference = true;
2274 if(type.type.classObjectType)
2276 Type subType = type.type;
2277 type.classObjectType = subType.classObjectType;
2278 type.kind = subType.kind;
2279 type._class = subType._class;
2280 type.byReference = true;
2287 static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis)
2289 Type specType { refCount = 1, kind = intType, isSigned = true };
2292 bool isTypedef = false;
2293 bool dllExport = false;
2295 bool isLong = false;
2296 for(spec = specs.first; spec; spec = spec.next)
2298 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && spec.extDecl.s && (!strcmp(spec.extDecl.s, "__declspec(dllexport)") || !strcmp(spec.extDecl.s, "dllexport")))
2302 if(spec.type == extendedSpecifier && spec.extDecl.type == extDeclAttrib)
2304 specType.keepCast = true;
2307 if(spec.specifier != CONST && (specType.kind == structType || specType.kind == unionType))
2310 specType = { kind = intType, isSigned = true, refCount = 1 };
2313 if(spec.type == baseSpecifier)
2315 if(spec.specifier == TYPEDEF) isTypedef = true;
2316 else if(spec.specifier == VOID) specType.kind = voidType;
2317 else if(spec.specifier == CHAR) specType.kind = charType;
2318 else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
2319 else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
2320 else if(spec.specifier == INT64) specType.kind = int64Type;
2321 else if(spec.specifier == VALIST)
2322 specType.kind = vaListType;
2323 else if(spec.specifier == SHORT) specType.kind = shortType;
2324 else if(spec.specifier == LONG)
2327 specType.kind = int64Type;
2329 specType.kind = intType;
2332 else if(spec.specifier == FLOAT) specType.kind = floatType;
2333 else if(spec.specifier == DOUBLE) specType.kind = doubleType;
2334 else if(spec.specifier == SIGNED) specType.isSigned = true;
2335 else if(spec.specifier == UNSIGNED) specType.isSigned = false;
2336 else if(spec.specifier == CONST)
2337 specType.constant = true;
2338 else if(spec.specifier == TYPED_OBJECT)
2340 specType.classObjectType = typedObject; specType.kind = classType; specType._class = FindClass("class");
2342 else if(spec.specifier == ANY_OBJECT)
2344 specType.classObjectType = anyObject; specType.kind = classType; specType._class = FindClass("class");
2346 else if(spec.specifier == CLASS)
2348 specType.classObjectType = classPointer; specType.kind = classType; specType._class = FindClass("class");
2350 else if(spec.specifier == THISCLASS)
2351 specType.kind = thisClassType;
2353 else if(spec.type == nameSpecifier)
2355 if(spec.name && (!strcmp(spec.name, "intptr") || !strcmp(spec.name, "uintptr")))
2357 specType.kind = intPtrType;
2358 if(!strcmp(spec.name, "uintptr"))
2359 specType.isSigned = false;
2361 else if(spec.name && (!strcmp(spec.name, "uintsize") || !strcmp(spec.name, "intsize")))
2363 specType.kind = intSizeType;
2364 if(!strcmp(spec.name, "uintsize"))
2365 specType.isSigned = false;
2369 Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
2370 if(symbol && symbol.type)
2372 // Free Type Contents:
2377 CopyTypeInto(specType, symbol.type);
2378 specType.typeName = CopyString(symbol.type.name);
2380 else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
2382 // key.sym enum values need FindClass:
2383 specType._class = spec.name ? FindClass(spec.name) : null;
2384 specType.kind = classType;
2385 if(!specType._class)
2386 specType.kind = intType;
2390 else if(spec.type == enumSpecifier)
2393 specType.kind = enumType;
2394 specType.enumName = spec.id ? CopyString(spec.id.string) : null;
2400 for(e = spec.list->first; e; e = e.next)
2402 // TOFIX: NamedItem i { } causes cryptic error, bad .c!
2403 NamedLink i { name = CopyString(e.id.string) };
2404 specType.members.Add(i);
2408 else if(spec.type == templateTypeSpecifier)
2410 specType.kind = templateType;
2411 specType.templateParameter = spec.templateParameter;
2413 else if(spec.type == structSpecifier || spec.type == unionSpecifier)
2415 Symbol _class = spec.id ? FindClass(spec.id.string) : null;
2418 if(!_class.registered || _class.registered.type != structClass)
2419 specType.directClassAccess = true;
2420 specType._class = _class;
2421 specType.kind = classType;
2424 if(spec.type == structSpecifier)
2425 specType.kind = structType;
2426 else if(spec.type == unionSpecifier)
2427 specType.kind = unionType;
2430 // TESTING THIS HERE... Had 0 type size
2431 if(!spec.definitions && !isTypedef)
2433 Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
2434 if(symbol && symbol.type)
2436 specType = *symbol.type;
2437 specType.name = CopyString(symbol.type.name);
2438 specType.typeName = CopyString(spec.name);
2439 specType.enumName = CopyString(symbol.type.enumName);
2440 specType.refCount = 1;
2442 if(symbol.type.kind == enumType)
2446 specType.members.Clear();
2447 for(member = symbol.type.members.first; member; member = member.next)
2449 NamedLink item { name = CopyString(member.name), data = member.data };
2450 specType.members.Add(item);
2453 else if(symbol.type.kind == structType || symbol.type.kind == unionType)
2456 // Tricky stuff... will be removed from list only when ref count reaches 0
2457 for(member = specType.members.first; member; member = member.next)
2460 else if(symbol.type.kind == functionType)
2463 specType.returnType.refCount++;
2464 for(param = specType.params.first; param; param = param.next)
2467 else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
2469 specType.type.refCount++;
2470 if(symbol.type.kind == arrayType)
2472 if(specType.arraySizeExp)
2473 specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
2479 specType.enumName = CopyString(spec.id.string);
2482 specType.enumName = CopyString(spec.id.string);
2485 if(spec.definitions)
2488 for(def = spec.definitions->first; def; def = def.next)
2490 if(def.type == declarationClassDef && def.decl.type == structDeclaration)
2492 Declaration decl = def.decl;
2493 if(decl.declarators)
2496 for(d = decl.declarators->first; d; d = d.next)
2498 Type memberType = ProcessType(decl.specifiers, d);
2499 specType.members.Add(memberType);
2502 else if(decl.specifiers)
2504 Type memberType = ProcessType(decl.specifiers, null);
2505 specType.members.Add(memberType);
2512 else if(spec.type == subClassSpecifier)
2514 specType.kind = specType.kind = subClassType;
2515 specType._class = spec._class.symbol;
2519 else if(assumeEllipsis)
2520 specType.kind = ellipsisType;
2524 public Type ProcessType(OldList specs, Declarator decl)
2526 return _ProcessType(specs, decl, null);
2529 public Type _ProcessType(OldList specs, Declarator decl, Type parentType)
2531 Type type = parentType;
2532 Declarator subDecl = decl ? decl.declarator : null;
2534 type = ProcessTypeSpecs(specs, decl == null);
2539 case extendedDeclarator:
2540 case extendedDeclaratorEnd:
2541 case bracketsDeclarator:
2542 case structDeclarator:
2544 case functionDeclarator:
2546 type = { refCount = 1, kind = functionType, returnType = type };
2547 if(decl.function.parameters)
2550 for(param = decl.function.parameters->first; param; param = param.next)
2551 type.params.Add(ProcessType(param.qualifiers, param.declarator));
2555 case arrayDeclarator:
2557 type = { refCount = 1, kind = arrayType, arraySizeExp = CopyExpression(decl.array.exp), freeExp = true, type = type };
2558 if(decl.array.enumClass)
2559 type.enumClass = decl.array.enumClass.symbol;
2562 case pointerDeclarator:
2564 Pointer pointer = decl.pointer.pointer;
2567 OldList * qualifiers = pointer.qualifiers;
2568 type = { refCount = 1, kind = pointerType, type = type };
2572 for(spec = qualifiers->first; spec; spec = spec.next)
2574 if(spec.type == baseSpecifier && spec.specifier == CONST)
2575 type.constant = true;
2578 pointer = pointer.pointer;
2582 case identifierDeclarator:
2584 Identifier id = decl.identifier;
2585 type.name = CopyString(id.string);
2589 PrintLn("Unhandled Declarator Type: ", decl.type);
2593 type = _ProcessType(null, subDecl, type);
2597 public Type ProcessTypeString(char * string, bool staticMethod)
2599 OldList * specs = MkList();
2600 Declarator decl = SpecDeclFromString(string, specs, null);
2601 Type type = ProcessType(specs, decl);
2602 if(type && !type.thisClass && staticMethod) type.staticMethod = true;
2603 FreeList(specs, FreeSpecifier);
2604 if(decl) FreeDeclarator(decl);
2608 Type MkClassTypeSymbol(Symbol symbol)
2612 Type type { kind = classType, _class = symbol };
2615 // Defaults to an int instead...
2616 type.kind = intType;
2624 public Type MkClassType(char * name)
2628 Type type { kind = classType, _class = FindClass(name) };
2631 // Defaults to an int instead...
2632 type.kind = intType;
2640 AsmField MkAsmField(char * command, Expression expression)
2642 return { command = command, expression = expression };
2645 Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
2647 return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
2648 asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
2649 asmStmt.clobberedFields = clobberedFields };
2652 ClassDef MkClassDefPropertyWatch(PropertyWatch watcher)
2654 return { type = propertyWatchClassDef, propertyWatch = watcher };
2657 Statement MkFireWatchersStmt(Expression object, OldList watches)
2659 return { type = fireWatchersStmt, _watch.object = object, _watch.watches = watches };
2662 Statement MkStopWatchingStmt(Expression watcher, Expression object, OldList watches)
2664 return { type = stopWatchingStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2667 Statement MkWatchStmt(Expression watcher, Expression object, OldList watches)
2669 return { type = watchStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2672 PropertyWatch MkDeleteWatch(Statement compound)
2674 return { compound = compound, deleteWatch = true };
2677 PropertyWatch MkPropertyWatch(OldList properties, Statement compound)
2679 return { compound = compound, properties = properties };
2682 Expression MkExpClass(OldList * specifiers, Declarator decl)
2684 return { type = classExp, _classExp.specifiers = specifiers, _classExp.decl = decl };
2687 Expression MkExpClassData(Identifier id)
2689 return { type = classDataExp, classData.id = id };
2693 External MkExternalDBTable(DBTableDef table)
2695 return { type = dbtableExternal, table = table };
2698 DBTableDef MkDBTableDef(char * name, Symbol symbol, OldList * definitions)
2700 return { name = name, symbol = symbol, definitions = definitions };
2703 DBTableEntry MkDBFieldEntry(TypeName type, Identifier id, char * name)
2705 return { type = fieldEntry, dataType = type, id = id, name = name };
2708 DBIndexItem MkDBIndexItem(Identifier id, Order order)
2710 return { id = id, order = order };
2713 DBTableEntry MkDBIndexEntry(OldList * items, Identifier id)
2715 return { type = indexEntry, items = items, id = id };
2718 Expression MkExpDBOpen(Expression ds, Expression dbName)
2720 return { type = dbopenExp, dbopen.ds = ds, dbopen.name = dbName };
2723 Expression MkExpDBField(char * table, Identifier id)
2725 return { type = dbfieldExp, db.table = table, db.id = id };
2728 Expression MkExpDBIndex(char * table, Identifier id)
2730 return { type = dbindexExp, db.table = table, db.id = id };
2733 Expression MkExpDBTable(char * table)
2735 return { type = dbtableExp, db.table = table };
2738 Expression MkExpArray(OldList * expressions)
2740 return { type = arrayExp, list = expressions };
2743 Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplateParameterType tplType)
2745 Expression argExp = null;
2746 Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
2750 ClassTemplateParameter curParam;
2752 for(sClass = _class; sClass; sClass = sClass.base)
2755 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2757 if(!strcmp(curParam.name, paramName))
2759 for(sClass = sClass.base; sClass; sClass = sClass.base)
2760 id += sClass.templateParams.count;
2768 if(curParam && curParam.type != tplType)
2774 char className[1024];
2775 Expression classExp;
2777 sprintf(idString, "%d", id);
2778 strcpy(className, "__ecereClass_");
2779 FullClassNameCat(className, _class.fullName, true);
2780 MangleClassName(className);
2781 DeclareClass(FindClass(_class.fullName), className);
2783 argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
2784 (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
2785 MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
2791 Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
2793 return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
2796 /*char * CreateMsgID(char * string, char * context)
2798 int lenString = strlen(string), lenContext = strlen(context);
2799 char * msgid = new char[lenString + lenContext + 20];
2800 memcpy(msgid, string, lenString);
2801 memcpy(msgid+lenString, " [msgctxt: ", 11);
2802 memcpy(msgid+lenString+11, context, lenContext);
2803 memcpy(msgid+lenString+11+lenContext, "]", 2);
2807 public void OutputIntlStrings()
2809 if(intlStrings.count)
2811 char * srcFile = GetSourceFile();
2812 char * objFile = GetOutputFile();
2813 char srcFileFixed[MAX_LOCATION];
2814 char potFile[MAX_LOCATION];
2816 ChangeExtension(objFile, "bowl", potFile);
2817 f = FileOpen(potFile, write);
2820 char * filePrefix = "";
2821 if(!(srcFile[0] && (srcFile[1] == ':' || srcFile[0] == '/')))
2822 filePrefix = "./"; //(GetRuntimePlatform() == win32) ? ".\\" : "./";
2823 // GetSystemPathBuffer(srcFileFixed, srcFile);
2824 GetSlashPathBuffer(srcFileFixed, srcFile);
2825 for(s : intlStrings)
2827 // TOFIX: (#654) ContextStringPair * pair = &s;
2828 ContextStringPair pair = &s;
2830 f.Printf("#: %s%s:%d\n", filePrefix, srcFileFixed, l.start.line);
2831 // PoEdit now preserves and distinguish msgctxt
2833 f.Printf("msgctxt \"%s\"\n", pair.context);
2834 f.Printf("msgid \"%s\"\n", pair.string);
2835 f.Printf("msgstr \"%s\"\n\n", pair.string);
2843 default extern OldList * ast;
2844 default extern int yyparse ();
2846 public void SetAST(OldList * list) { ast = list; }
2847 public OldList * GetAST() { return ast; }
2848 public void ParseEc()