3 #define YYLTYPE Location
7 const char * defaultNameSpace;
8 int defaultNameSpaceLen;
9 public void SetDefaultNameSpace(const 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 AccessMode structDeclMode = privateAccess;
17 public void SetDeclMode(AccessMode accessMode) { structDeclMode = declMode = accessMode; }
18 AccessMode defaultDeclMode = privateAccess;
19 public void SetDefaultDeclMode(AccessMode accessMode) { defaultDeclMode = accessMode; }
21 const char * currentNameSpace;
22 int currentNameSpaceLen;
23 public void SetCurrentNameSpace(const char * s) { currentNameSpace = s; currentNameSpaceLen = s ? strlen(s) : 0; }
26 Time findClassTotalTime;
27 Time checkTypeTotalTime;
28 Time externalImportTotalTime;
29 Time findClassIgnoreNSTotalTime;
32 public OldList * MkList()
34 return new0 OldList[1];
37 public OldList * MkListOne(void * item)
39 OldList * list = new0 OldList[1];
44 void ListAdd(OldList list, void * item)
50 void ListAddFront(OldList list, void * item)
53 list.Insert(null, item);
56 public Identifier MkIdentifier(const char * string)
61 id._class = null; // Default class...
65 const char * namePart;
66 bool gotColon = false;
67 for(c = strlen(string)-1; c >= 0; c--)
74 namePart = string+c+1;
75 while(c >= 0 && string[c] == ':') c--;
81 memcpy(name, string, c+1);
83 // TODO: Do these better, keep in string?
84 if(!strcmp(name, "typed_object"))
86 id._class = MkSpecifierName("typed_object"); //"class");
87 id.string = CopyString(namePart);
89 else if(!strcmp(name, "property"))
91 id._class = MkSpecifierName("property");
92 id.string = CopyString(namePart);
94 else if(!strcmp(name, "typed_object&"))
96 id._class = MkSpecifierName("typed_object&");
97 id.string = CopyString(namePart);
99 else if(!strcmp(name, "any_object"))
101 id._class = MkSpecifierName("any_object");
102 id.string = CopyString(namePart);
106 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
109 id._class = Specifier { type = templateTypeSpecifier, templateParameter = templatedType.param };
110 //id._class = MkSpecifierName(name);
111 id.string = CopyString(namePart);
115 symbol = FindClass(name);
118 id._class = _MkSpecifierName(symbol.string, symbol, null);
119 id.string = CopyString(namePart);
122 id.string = CopyString(string);
128 id._class = MkSpecifierName(null);
129 id.string = CopyString(namePart);
132 id.string = CopyString(string);
135 id.string = CopyString("");
139 public TemplateParameter MkTypeTemplateParameter(Identifier identifier, TemplateDatatype baseTplDatatype, TemplateArgument defaultArgument)
141 if(identifier.string)
143 TemplateParameter param { type = TemplateParameterType::type, identifier = identifier, dataType = baseTplDatatype, defaultArgument = defaultArgument };
144 TemplatedType type { key = (uintptr)identifier.string, param = param };
145 if(!curContext.templateTypes.Add((BTNode)type))
152 public TemplateParameter MkIdentifierTemplateParameter(Identifier identifier, TemplateMemberType memberType, TemplateArgument defaultArgument)
154 if(identifier.string)
156 TemplateParameter param { type = TemplateParameterType::identifier, identifier = identifier, memberType = memberType, defaultArgument = defaultArgument };
162 public TemplateParameter MkExpressionTemplateParameter(Identifier identifier, TemplateDatatype dataType, TemplateArgument defaultArgument)
164 if(identifier.string)
166 TemplateParameter param { type = TemplateParameterType::expression, identifier = identifier, dataType = dataType, defaultArgument = defaultArgument };
172 public TemplateDatatype MkTemplateDatatype(OldList * specifiers, Declarator decl)
174 TemplateDatatype datatype { specifiers = specifiers, decl = decl };
178 public TemplateArgument MkTemplateTypeArgument(TemplateDatatype tplDatatype)
180 TemplateArgument argument { type = type, templateDatatype = tplDatatype };
184 public TemplateArgument MkTemplateExpressionArgument(Expression expr)
186 TemplateArgument argument { type = expression, expression = expr };
190 public TemplateArgument MkTemplateIdentifierArgument(Identifier ident)
192 TemplateArgument argument { type = identifier, identifier = ident };
196 Expression MkExpExtensionCompound(Statement compound)
198 return { type = extensionCompoundExp, compound = compound };
201 Expression MkExpExtensionExpression(OldList * expressions)
203 return { type = extensionExpressionExp, list = expressions, loc = yylloc };
206 Expression MkExpExtensionInitializer(TypeName typeName, Initializer initializer)
208 return { type = extensionInitializerExp, initializer.typeName = typeName, initializer.initializer = initializer, loc = yylloc };
211 public Expression MkExpIdentifier(Identifier id)
213 return { type = identifierExp, identifier = id, loc = yylloc };
216 public Expression MkExpDummy()
218 Expression exp { type = dummyExp };
222 public Expression MkExpConstant(const char * string)
224 return { type = constantExp, constant = CopyString(string), loc = yylloc };
227 Expression MkExpString(const char * string)
229 return { type = stringExp, string = CopyString(string), loc = yylloc };
232 // TODO: String is case sensitive..
233 // What should we do about it?
234 /*public class CaseSensitiveString : String
236 int OnCompare(CaseSensitiveString string2)
240 result = strcmpi(this, string2);
241 else if(!this && string2)
243 else if(this && !string2)
249 public struct ContextStringPair
251 String string, context;
253 // TODO: Should this be automated somehow?
260 int OnCompare(ContextStringPair b)
263 result = (string && b.string) ? strcmp(string, b.string) :
264 (!string && b.string) ? 1 : (string && !b.string) ? -1 : 0;
265 if(result) return result;
267 result = (context && b.context) ? strcmp(context, b.context) :
268 (!context && b.context) ? 1 : (context && !b.context) ? -1 : 0;
269 // TODO: Support these
270 // result = CaseSensitiveString::OnCompare(string, b.string);
271 // result = ((CaseSensitiveString)string).OnCompare(b.string);
276 Map<ContextStringPair, List<Location>> intlStrings { };
278 Expression MkExpIntlString(const char * string, const char * context)
282 OldList * list = MkList();
286 ContextStringPair pair { };
288 int len = strlen(string);
290 pair.string = new byte[len-2+1]; memcpy(pair.string, string+1, len-2); pair.string[len-2] = '\0';
291 if(context) { len = strlen(context); pair.context = new byte[len-2+1]; memcpy(pair.context, context+1, len-2); pair.context[len-2] = '\0'; }
293 list = intlStrings[pair];
297 intlStrings[pair] = list;
306 //ListAdd(list, QMkExpId("__thisModule"));
307 s = QMkString(i18nModuleName ? i18nModuleName : "");
308 ListAdd(list, MkExpString(s));
310 ListAdd(list, MkExpString(string));
313 int lenString = strlen(string), lenContext = strlen(context);
314 char * msgid = new char[lenString-2 + lenContext-2 + 4];
316 memcpy(msgid+1, context+1, lenContext-2);
317 msgid[1+lenContext-2] = 4; // EOT
318 memcpy(msgid+1+lenContext-2+1, string+1, lenString-2);
319 memcpy(msgid+1+lenContext-2+1+lenString-2, "\"", 2);
320 ListAdd(list, MkExpString(msgid));
324 ListAdd(list, QMkExpId("null"));
325 return MkExpCall(QMkExpId("GetTranslatedString"), list);
329 Expression e = MkExpString(string);
335 Expression MkExpOp(Expression exp1, int op, Expression exp2)
346 exp.loc.start = exp1 ? exp1.loc.start : exp2.loc.start;
347 exp.loc.end = exp2 ? exp2.loc.end : exp1.loc.end;
352 Expression MkExpBrackets(OldList expressions)
359 if(expressions && expressions.first)
361 exp.loc.start = ((Expression)expressions.first).loc.start;
362 exp.loc.end = ((Expression)expressions.last).loc.end;
367 Expression MkExpIndex(Expression expression, OldList index)
369 return { type = indexExp, index.exp = expression, index.index = index };
372 Expression MkExpCall(Expression expression, OldList arguments)
374 return { type = callExp, call.exp = expression, call.arguments = arguments, loc = yylloc };
377 Expression MkExpMember(Expression expression, Identifier member)
379 return { type = memberExp, member.exp = expression, member.member = member, loc = yylloc };
382 Expression MkExpPointer(Expression expression, Identifier member)
384 return { type = pointerExp, member.exp = expression, member.member = member, loc = yylloc };
387 Expression MkExpTypeSize(TypeName typeName)
389 return { type = typeSizeExp, typeName = typeName, loc = yylloc };
392 Expression MkExpTypeAlign(TypeName typeName)
394 return { type = typeAlignExp, typeName = typeName, loc = yylloc };
397 Expression MkExpClassSize(Specifier _class)
399 return { type = classSizeExp, _class = _class, loc = yylloc };
402 Expression MkExpCast(TypeName typeName, Expression expression)
404 return { type = castExp, cast.typeName = typeName, cast.exp = expression, loc = yylloc };
407 Expression MkExpCondition(Expression cond, OldList expressions, Expression elseExp)
409 return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp, loc = yylloc };
412 Expression MkExpRenew(Expression memExp, TypeName type, Expression size)
414 return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size, loc = yylloc };
417 Expression MkExpRenew0(Expression memExp, TypeName type, Expression size)
419 return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size, loc = yylloc };
422 Expression MkExpNew(TypeName type, Expression size)
424 return { type = newExp, _new.typeName = type, _new.size = size, loc = yylloc };
427 Expression MkExpNew0(TypeName type, Expression size)
429 return { type = new0Exp, _new.typeName = type, _new.size = size, loc = yylloc };
432 Expression MkExpVaArg(Expression exp, TypeName type)
434 return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type, loc = yylloc };
437 Specifier MkSpecifier(int specifier)
439 if(specifier == _BOOL && (declMode != defaultAccess && defaultDeclMode != defaultAccess))
440 return MkSpecifierName("bool");
441 else if(specifier == _BOOL || specifier == BOOL)
442 return { type = baseSpecifier, specifier = specifier };
444 return { type = baseSpecifier, specifier = specifier };
447 Specifier MkSpecifierTypeOf(Expression expression)
449 return { type = typeOfSpecifier, expression = expression };
452 Specifier MkSpecifierSubClass(Specifier _class)
454 return { type = subClassSpecifier, _class = _class };
457 Specifier MkSpecifierExtended(ExtDecl extDecl)
459 return { type = extendedSpecifier, extDecl = extDecl /*name = CopyString(name)*/ };
462 Specifier MkEnum(Identifier id, OldList list)
466 type = enumSpecifier;
470 if(list && (!declMode || !id))
476 type = ProcessType(&specs, null);
480 Symbol symbol { string = CopyString(id.string), isStruct = true, type = type };
482 if(strstr(symbol.string, "::"))
483 curContext.hasNameSpace = true;
484 if(!curContext.structSymbols.Add((BTNode)symbol))
487 for(e = list.first; e; e = e.next)
489 Symbol symbol { string = CopyString(e.id.string), type = type };
491 if(strstr(symbol.string, "::"))
492 curContext.hasNameSpace = true;
493 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
501 Specifier MkStructOrUnion(SpecifierType type, Identifier id, OldList definitions)
503 Specifier spec { type = type, id = id };
504 if(id && FindType(curContext, id.string))
505 structDeclMode = defaultAccess;
506 spec.definitions = definitions;
507 if(definitions && id && structDeclMode == defaultAccess)
512 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specs, null), isStruct = true };
513 if(!curContext.structSymbols.Add((BTNode)symbol))
519 void AddStructDefinitions(Specifier spec, OldList definitions)
521 spec.definitions = definitions;
522 if(definitions && spec.id && !declMode)
527 symbol = Symbol { string = CopyString(spec.id.string), type = ProcessType(specs, null), isStruct = true };
528 if(!curContext.parent.structSymbols.Add((BTNode)symbol))
533 Attribute MkAttribute(String attr, Expression exp)
535 return { attr = attr, exp = exp };
538 Attrib MkAttrib(int type, OldList * attribs)
540 return { type = type, attribs = attribs };
543 ExtDecl MkExtDeclString(String s)
545 return { type = extDeclString, s = s };
549 ExtDecl MkExtDeclAttrib(Attrib attr)
551 return { type = extDeclAttrib, attr = attr };
555 public Declarator MkDeclaratorIdentifier(Identifier id)
557 return { type = identifierDeclarator, identifier = id };
560 Declarator MkDeclaratorFunction(Declarator declarator, OldList parameters)
562 return { type = functionDeclarator, declarator = declarator, function.parameters = parameters };
565 Declarator MkDeclaratorExtended(ExtDecl extended, Declarator declarator)
567 return { type = extendedDeclarator, declarator = declarator, extended.extended = extended };
570 Declarator MkDeclaratorExtendedEnd(ExtDecl extended, Declarator declarator)
572 return { type = extendedDeclaratorEnd, declarator = declarator, extended.extended = extended };
575 Declarator MkStructDeclarator(Declarator declarator, Expression exp)
577 return { type = structDeclarator, declarator = declarator, structDecl.exp = exp };
580 Declarator MkDeclaratorBrackets(Declarator declarator)
582 return { type = bracketsDeclarator, declarator = declarator };
585 Declarator MkDeclaratorArray(Declarator declarator, Expression exp)
587 return { type = arrayDeclarator, declarator = declarator, array.exp = exp };
590 Declarator MkDeclaratorEnumArray(Declarator declarator, Specifier _class)
592 return { type = arrayDeclarator, declarator = declarator, array.enumClass = _class };
595 Declarator MkDeclaratorPointer(Pointer pointer, Declarator declarator)
597 return { type = pointerDeclarator, declarator = declarator, pointer.pointer = pointer };
600 Enumerator MkEnumerator(Identifier id, Expression exp)
602 return { id = id, exp = exp };
605 Pointer MkPointer(OldList qualifiers, Pointer pointer)
607 return { qualifiers = qualifiers, pointer = pointer };
610 Initializer MkInitializerAssignment(Expression exp)
612 /*if(yylloc.start.line == 1)
614 return { type = expInitializer, exp = exp, loc = yylloc };
617 Initializer MkInitializerList(OldList list)
619 /*if(yylloc.start.line == 1)
621 return { type = listInitializer, list = list, loc = yylloc };
624 InitDeclarator MkInitDeclarator(Declarator declarator, Initializer initializer)
626 return { declarator = declarator, initializer = initializer };
629 public TypeName MkTypeName(OldList qualifiers, Declarator declarator)
631 if(qualifiers != null)
633 Declarator parentDecl = declarator;
634 Declarator decl = declarator;
635 while(decl && decl.type == arrayDeclarator)
636 decl = decl.declarator;
637 if(decl && decl.type == identifierDeclarator && decl.identifier.string && CheckType(decl.identifier.string) == TYPE_NAME)
640 // Check if we're missing a real type specifier here
641 for(spec = qualifiers.first; spec; spec = spec.next)
643 if(spec.type == baseSpecifier)
645 if(spec.specifier == CONST || spec.specifier == VOLATILE ||
646 spec.specifier == EXTERN || spec.specifier == STATIC ||
647 spec.specifier == AUTO || spec.specifier == REGISTER)
651 else if(spec.type != extendedSpecifier)
656 // This is actually a type
657 ListAdd(qualifiers, MkSpecifierName(decl.identifier.string));
658 FreeDeclarator(decl);
659 parentDecl.declarator = null;
663 return { qualifiers = qualifiers, declarator = declarator };
666 public TypeName MkTypeNameGuessDecl(OldList qualifiers, Declarator declarator)
668 if(qualifiers != null)
670 bool gotType = false;
671 bool gotFullType = false;
672 Specifier spec, next;
673 for(spec = qualifiers.first; spec; spec = next)
676 if(gotType && !declarator && ((spec.type == nameSpecifier && spec.name) || (spec.type == baseSpecifier && gotFullType)))
678 const String s = null;
679 if(spec.type == nameSpecifier)
681 char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
682 s = colon ? colon + 2 : spec.name;
684 else if(spec.type == baseSpecifier)
686 if(spec.specifier == INT64) s = "int64";
690 declarator = MkDeclaratorIdentifier(MkIdentifier(s));
691 qualifiers.Remove(spec);
696 if(spec && spec.type != extendedSpecifier)
698 if(spec.type == baseSpecifier)
700 if(spec.specifier == CONST || spec.specifier == VOLATILE ||
701 spec.specifier == EXTERN || spec.specifier == STATIC ||
702 spec.specifier == AUTO || spec.specifier == REGISTER)
704 else if(spec.specifier != UNSIGNED && spec.specifier != SIGNED && spec.specifier != LONG)
716 return { qualifiers = qualifiers, declarator = declarator };
719 public Identifier GetDeclId(Declarator decl)
721 while(decl && decl.type != identifierDeclarator)
722 decl = decl.declarator;
723 return decl ? decl.identifier : null;
726 Declaration MkDeclarationClassInst(Instantiation inst)
728 return { type = instDeclaration, inst = inst, loc = yylloc };
731 Declaration MkDeclarationInst(Instantiation inst)
733 Declaration decl { type = instDeclaration, inst = inst, loc = yylloc };
735 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
738 int len = 0, stringLen;
741 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
742 len += defaultNameSpaceLen;
748 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
749 len += currentNameSpaceLen;
754 stringLen = strlen(inst.exp.identifier.string);
755 memcpy(name + len, inst.exp.identifier.string, stringLen);
758 delete inst.exp.identifier.string;
759 inst.exp.identifier.string = CopyString(name);
764 string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
765 type = MkClassTypeSymbol(inst._class.symbol);
767 symbol.idCode = symbol.id = curContext.nextID++;
768 if(strstr(symbol.string, "::"))
769 curContext.hasNameSpace = true;
770 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
771 excludedSymbols->Add(symbol);
772 decl.symbol = inst.symbol = symbol;
776 Declaration MkDeclarationDefine(Identifier id, Expression exp)
778 Declaration decl { type = defineDeclaration, id = id, exp = exp, loc = yylloc };
779 char expString[1024];
782 PrintExpression(exp, expString);
784 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
787 int len = 0, stringLen;
790 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
791 len += defaultNameSpaceLen;
797 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
798 len += currentNameSpaceLen;
802 stringLen = strlen(id.string);
803 memcpy(name + len, id.string, stringLen);
807 id.string = CopyString(name);
810 if(!eSystem_FindDefine(privateModule, id.string))
811 eSystem_RegisterDefine(id.string, expString, privateModule, buildingECERECOMModule ? baseSystemAccess : publicAccess);
813 Compiler_Warning($"Redefinition of %s ignored\n", id.string);
817 Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
819 Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
820 bool variable = true;
822 if(specifiers != null)
824 bool gotType = false;
825 Specifier spec, next;
826 for(spec = specifiers.first; spec; spec = next)
829 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
831 if(initDeclarators != null)
835 for(d = initDeclarators.first; d; d = d.next)
837 if(GetDeclId(d.declarator).string)
841 string = CopyString(GetDeclId(d.declarator).string);
842 type = ProcessType(specifiers, d.declarator);
844 type.id = type.idCode = curContext.nextID++;
846 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
847 excludedSymbols->Add(type);
848 decl.symbol = d.declarator.symbol = type;
854 //for(spec = spec.next; spec; spec = spec.next)
855 spec = specifiers.last;
857 if((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier)
859 const String s = null;
860 if(spec.type == nameSpecifier)
862 const char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
863 s = colon ? colon + 2 : spec.name;
865 else if(spec.type == baseSpecifier)
867 if(spec.specifier == INT64) s = "int64";
871 Symbol type { string = CopyString(s), type = ProcessType(specifiers, null) };
872 type.id = type.idCode = curContext.nextID++;
874 decl.declarators = initDeclarators = MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
875 specifiers.Remove(spec);
877 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
878 excludedSymbols->Add(type);
886 else if(spec.type == baseSpecifier &&
887 (spec.specifier == STRUCT || spec.specifier == UNION))
891 if(gotType && initDeclarators == null && !spec.next && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
893 const String s = null;
894 if(spec.type == nameSpecifier)
896 char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
897 s = colon ? colon + 2 : spec.name;
899 else if(spec.type == baseSpecifier)
901 if(spec.specifier == INT64) s = "int64";
905 decl.declarators = initDeclarators = MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
906 specifiers.Remove(spec);
912 if(spec && spec.type != extendedSpecifier)
916 if(variable && initDeclarators)
919 for(d = initDeclarators.first; d; d = d.next)
921 Identifier id = GetDeclId(d.declarator);
922 if(id && id.string && id.string[0])
928 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
931 int len = 0, stringLen;
934 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
935 len += defaultNameSpaceLen;
941 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
942 len += currentNameSpaceLen;
946 stringLen = strlen(id.string);
947 memcpy(name + len, id.string, stringLen);
951 id.string = CopyString(name);
954 // Avoid memory leaks on duplicated symbols (BinaryTree::Add Would Fail)
955 symbol = (Symbol)(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.FindString(id.string);
958 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specifiers, d.declarator) };
959 if(strstr(symbol.string, "::"))
960 curContext.hasNameSpace = true;
961 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
962 excludedSymbols->Add(symbol);
963 // TODO: Add better support to count declarators
964 if(symbol.type && symbol.type.kind == arrayType && !symbol.type.arraySizeExp && d.initializer)
966 if(d.initializer.type == listInitializer)
969 sprintf(string, "%d",d.initializer.list->count);
970 symbol.type.arraySizeExp = MkExpConstant(string);
971 symbol.type.freeExp = true;
973 else if(d.initializer.type == expInitializer && d.initializer.exp.type == stringExp && d.initializer.exp.string)
978 bool escaped = false;
979 char * s = d.initializer.exp.string;
981 // MAKE MORE ACCURATE
982 for(c = 1; (ch = s[c]); c++)
984 if(ch == '\\' && !escaped)
993 sprintf(string, "%d", count);
994 symbol.type.arraySizeExp = MkExpConstant(string);
995 symbol.type.freeExp = true;
998 symbol.id = symbol.idCode = curContext.nextID++;
1000 decl.symbol = d.declarator.symbol = symbol;
1007 decl.symbol = Symbol { };
1008 decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
1009 excludedSymbols->Add(decl.symbol);
1014 Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifier extStorage)
1016 Declaration decl { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
1017 if(specifiers != null)
1019 bool gotType = false;
1020 Specifier spec, next;
1021 for(spec = specifiers.first; spec; spec = next)
1024 if(gotType && declarators == null && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
1026 const String s = null;
1027 if(spec.type == nameSpecifier)
1029 const char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
1030 s = colon ? colon + 2 : spec.name;
1032 else if(spec.type == baseSpecifier)
1034 if(spec.specifier == INT64) s = "int64";
1038 decl.declarators = declarators = MkListOne(MkStructDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
1039 specifiers.Remove(spec);
1040 FreeSpecifier(spec);
1044 if(spec && spec.type != extendedSpecifier)
1051 Statement MkLabeledStmt(Identifier id, Statement statement)
1053 return { type = labeledStmt, labeled.id = id, labeled.stmt = statement, loc = yylloc };
1056 Statement MkCaseStmt(Expression exp, Statement statement)
1058 return { type = caseStmt, caseStmt.exp = exp, caseStmt.stmt = statement, loc = yylloc };
1061 Statement MkCompoundStmt(OldList declarations, OldList statements)
1063 return { type = compoundStmt, compound.declarations = declarations, compound.statements = statements, loc = yylloc };
1066 Statement MkExpressionStmt(OldList expressions)
1068 return { type = expressionStmt, expressions = expressions, loc = yylloc };
1071 Statement MkBadDeclStmt(Declaration decl)
1073 return { type = badDeclarationStmt, decl = decl, loc = yylloc };
1076 Statement MkIfStmt(OldList exp, Statement statement, Statement elseStmt)
1078 return { type = ifStmt, ifStmt.exp = exp, ifStmt.stmt = statement, ifStmt.elseStmt = elseStmt, loc = yylloc };
1081 Statement MkSwitchStmt(OldList exp, Statement statement)
1083 // To know it's a switch compound... (Don't want declarations in there... bugs)
1085 statement.compound.isSwitch = true;
1086 return { type = switchStmt, switchStmt.exp = exp, switchStmt.stmt = statement, loc = yylloc };
1089 Statement MkWhileStmt(OldList exp, Statement statement)
1091 return { type = whileStmt, whileStmt.exp = exp, whileStmt.stmt = statement, loc = yylloc };
1094 Statement MkDoWhileStmt(Statement statement, OldList exp)
1096 return { type = doWhileStmt, doWhile.exp = exp, doWhile.stmt = statement, loc = yylloc };
1099 Statement MkForStmt(Statement init, Statement check, OldList inc, Statement statement)
1101 return { type = forStmt, forStmt.init = init, forStmt.check = check, forStmt.increment = inc, forStmt.stmt = statement, loc = yylloc };
1104 Statement MkForEachStmt(Identifier id, OldList exp, OldList filter, Statement statement)
1106 return { type = forEachStmt, forEachStmt.id = id, forEachStmt.exp = exp, forEachStmt.filter = filter, forEachStmt.stmt = statement, loc = yylloc };
1109 Statement MkGotoStmt(Identifier id)
1111 return { type = gotoStmt, gotoStmt.id = id, loc = yylloc };
1114 Statement MkContinueStmt()
1116 return { type = continueStmt, loc = yylloc };
1119 Statement MkBreakStmt()
1121 return { type = breakStmt, loc = yylloc };
1124 Statement MkReturnStmt(OldList exp)
1126 return { type = returnStmt, expressions = exp, loc = yylloc };
1129 FunctionDefinition MkFunction(OldList specifiers, Declarator declarator, OldList declarationList)
1131 return _MkFunction(specifiers, declarator, declarationList, true);
1134 FunctionDefinition _MkFunction(OldList specifiers, Declarator declarator, OldList declarationList, bool errorOnOmit)
1138 Declarator funcDecl = GetFuncDecl(declarator);
1139 if(funcDecl && funcDecl.function.parameters)
1142 for(tn = funcDecl.function.parameters->first; tn; tn = tn.next)
1144 if(tn.qualifiers || tn.declarator)
1146 Identifier declID = tn.declarator ? GetDeclId(tn.declarator) : null;
1150 Specifier spec = tn.qualifiers ? tn.qualifiers->first : null;
1151 if(!tn.declarator && !tn.prev && !tn.next && spec && !spec.next && spec.type == baseSpecifier && spec.specifier == VOID);
1153 Compiler_Error($"parameter name omitted\n");
1160 return { specifiers = specifiers, declarator = declarator, declarations = declarationList };
1163 void ProcessFunctionBody(FunctionDefinition func, Statement body)
1165 Declarator declarator = func.declarator;
1166 Declarator funcDecl = GetFuncDecl(declarator);
1171 if(funcDecl && funcDecl.function.parameters && body)
1173 Context context = body.compound.context;
1175 for(param = funcDecl.function.parameters->first; param; param = param.next)
1177 if(param.declarator)
1179 Symbol symbol = null;
1180 Identifier id = GetDeclId(param.declarator);
1181 char * string = id ? id.string : null;
1184 for(symbol = (Symbol)context.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
1185 if(!strcmp(symbol.string, string))
1187 // This parameter is not shadowed by a local declaration
1190 symbol = Symbol { string = CopyString(id.string), type = ProcessType(param.qualifiers, param.declarator), isParam = true };
1191 if(!context.symbols.Add((BTNode)symbol))
1192 excludedSymbols->Add(symbol);
1194 // TODO: Fix this, the parameters' IDs should really be smaller...
1195 symbol.id = context.nextID++;
1196 param.declarator.symbol = symbol;
1203 if(!declarator.symbol)
1205 Identifier id = GetDeclId(declarator);
1207 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess && strcmp(id.string, "__on_register_module"))
1210 int len = 0, stringLen;
1211 if(defaultNameSpace)
1213 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1214 len += defaultNameSpaceLen;
1218 if(currentNameSpace)
1220 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1221 len += currentNameSpaceLen;
1225 stringLen = strlen(id.string);
1226 memcpy(name + len, id.string, stringLen);
1230 id.string = CopyString(name);
1232 symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
1233 symbol.idCode = symbol.id = globalContext.nextID++;
1234 if(strstr(symbol.string, "::"))
1235 globalContext.hasNameSpace = true;
1236 if(!globalContext.symbols.Add((BTNode)symbol))
1237 excludedSymbols->Add(symbol);
1238 declarator.symbol = symbol;
1242 symbol = declarator.symbol;
1243 excludedSymbols->Remove(declarator.symbol);
1244 delete symbol.string;
1245 symbol.string = CopyString(GetDeclId(declarator).string);
1246 if(strstr(symbol.string, "::"))
1247 globalContext.hasNameSpace = true;
1248 if(!globalContext.symbols.Add((BTNode)symbol))
1249 excludedSymbols->Add(symbol);
1252 symbol.type = ProcessType(func.specifiers, declarator);
1254 if(symbol.type && (symbol.type.kind == functionType || symbol.type.kind == methodType))
1256 if(!symbol.type.params.count)
1258 Type type { refCount = 1 };
1259 symbol.type.params.Add(type);
1268 External MkExternalFunction(FunctionDefinition function)
1270 External external { type = functionExternal, function = function, symbol = function.declarator.symbol };
1271 if(function.specifiers)
1274 for(spec = function.specifiers->first; spec; spec = spec.next)
1275 if(spec.type == baseSpecifier && spec.specifier == STATIC)
1277 structDeclMode = declMode = staticAccess;
1282 if(external.symbol && !external.symbol.methodExternal)
1283 external.symbol.methodExternal = external;
1287 External MkExternalImport(char * name, ImportType importType, AccessMode importAccess)
1289 External external { type = importExternal };
1290 int len = strlen(name) - 2;
1291 external.importString = new char[len + 1];
1292 strncpy(external.importString, name+1, len);
1293 external.importString[len] = '\0';
1298 Time startTime = GetTime();
1301 ImportModule(external.importString, importType, importAccess, true);
1302 ImportModule(external.importString, importType, importAccess, false);
1304 time = GetTime() - startTime;
1305 printf("Importing took %.3f seconds for %s\n", time, external.importString);
1306 externalImportTotalTime += time;
1312 External MkExternalDeclaration(Declaration declaration)
1314 External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
1315 if(declaration && declaration.type == initDeclaration && declaration.specifiers)
1318 for(spec = declaration.specifiers->first; spec; spec = spec.next)
1319 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1321 structDeclMode = declMode = defaultAccess;
1324 else if(spec.type == baseSpecifier && spec.specifier == STATIC)
1326 structDeclMode = declMode = staticAccess;
1330 if(declaration && declaration.symbol && !declaration.symbol.methodExternal)
1331 declaration.symbol.methodExternal = external;
1335 External MkExternalNameSpace(Identifier identifier)
1337 External external { type = nameSpaceExternal, id = identifier };
1338 currentNameSpace = identifier ? identifier.string : null;
1339 currentNameSpaceLen = currentNameSpace ? strlen(currentNameSpace) : 0;
1343 void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
1345 if(spec.type == nameSpecifier)
1347 Symbol symbol = spec.symbol;
1348 spec.templateArgs = templateArgs;
1349 if(templateArgs && templateArgs.first)
1351 char templateString[1024];
1352 TemplateArgument arg;
1353 strcpy(templateString, symbol ? symbol.string : spec.name);
1354 strcat(templateString, "<");
1355 for(arg = templateArgs.first; arg; arg = arg.next)
1363 char expString[1024];
1364 Class backupThisClass = thisClass;
1366 expString[0] = '\0';
1367 // Will this work here?
1369 Location oldLocation = yylloc;
1370 File backFileInput = fileInput;
1375 // TESTING THIS SCANNER RESUME STUFF
1378 yylloc = oldLocation;
1379 fileInput = backFileInput;
1382 fileInput.Seek(yylloc.start.pos, start);
1383 resetScannerPos(&yylloc.start);
1388 //ProcessExpressionType(arg.expression);
1389 //ComputeExpression(arg.expression);
1390 PrintExpression(arg.expression, expString);
1391 strcat(argument, expString);
1392 thisClass = backupThisClass;
1397 strcat(argument, arg.identifier.string);
1402 char * typeString = StringFromSpecDecl(arg.templateDatatype.specifiers, arg.templateDatatype.decl);
1403 strcat(argument, typeString);
1410 if(arg.prev) strcat(templateString, ", ");
1413 strcat(templateString, arg.name.string);
1414 strcat(templateString, " = ");
1416 strcat(templateString, argument);
1420 int len = strlen(templateString);
1421 if(templateString[len-1] == '>') templateString[len++] = ' ';
1422 templateString[len++] = '>';
1423 templateString[len++] = '\0';
1425 // printf("SetClassTemplateArgs templateString: %s\n", templateString);
1426 symbol = FindClass(templateString);
1427 if(!symbol && spec.symbol)
1429 // If class was only decl'ed, invoke DeclClass on this templated class as well
1430 symbol = _DeclClass(MAXINT, templateString);
1432 // Add a reference to all templated class to the basic class
1434 spec.symbol.templatedClasses.Add(OldLink { data = symbol });
1436 spec.symbol = symbol;
1437 spec.name = CopyString(symbol ? symbol.string : templateString);
1441 FreeList(templateArgs, FreeTemplateArgument);
1444 Specifier _MkSpecifierName(const char * name, Symbol symbol, OldList templateArgs)
1446 Specifier spec { type = nameSpecifier };
1452 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
1455 spec.templateParameter = templatedType.param;
1456 spec.type = templateTypeSpecifier;
1460 symbol = FindClass(name);
1462 if(symbol && symbol.registered && symbol.registered.isRemote == 1)
1464 char className[1024];
1465 strcpy(className, "DCOMClient_");
1466 if(!strncmp(name, className, strlen(className)))
1467 spec.name = CopyString(name);
1470 strcat(className, name);
1471 spec.name = CopyString(className);
1475 spec.name = CopyString(symbol.string);
1477 spec.name = CopyString(name);
1478 spec.symbol = symbol;
1479 if(templateArgs != null)
1480 SetClassTemplateArgs(spec, templateArgs);
1485 public Specifier MkSpecifierName(const char * name)
1487 return _MkSpecifierName(name, null, null);
1490 public Specifier MkSpecifierNameArgs(const char * name, OldList * templateArgs)
1492 return _MkSpecifierName(name, null, templateArgs);
1496 Specifier MkClassName(const char * string)
1498 return { type = SpecifierClass, name = CopyString(string) };
1501 ClassFunction MkClassFunction(OldList specifiers, Specifier _class, Declarator decl, OldList declList)
1503 return { specifiers = specifiers, /*_class = _class,*/ declarator = decl, declarations = declList };
1506 void ProcessClassFunctionBody(ClassFunction func, Statement body)
1510 Declarator decl = func.declarator;
1512 //Declarator decl = GetFuncDecl(func.declarator);
1513 Declarator funcDecl = GetFuncDecl(func.declarator);
1517 if(decl && !decl.symbol)
1519 OldList * symbolSpecs = MkList();
1521 // WHAT WILL WE DO WITH THIS? Double instances?
1522 //if(decl.function.parameters && body)
1523 if(funcDecl && funcDecl.function.parameters && body)
1525 Context context = body.compound.context;
1527 for(param = funcDecl.function.parameters->first; param; param = param.next)
1529 if(param.declarator)
1531 Symbol symbol = null;
1532 Identifier id = GetDeclId(param.declarator);
1533 char * string = id ? id.string : null;
1536 symbol = (Symbol)context.symbols.FindString(string);
1538 // This parameter is not shadowed by a local declaration
1543 string = CopyString(id.string);
1544 type = ProcessType(param.qualifiers, param.declarator);
1548 // TODO: Fix this, the parameters' IDs should really be smaller...
1549 symbol.idCode = symbol.id = context.nextID++;
1550 if(!context.symbols.Add((BTNode)symbol))
1551 excludedSymbols->Add(symbol);
1553 param.declarator.symbol = symbol;
1558 //////////////////////////////////
1566 Identifier id = GetDeclId(funcDecl);
1570 for(c = strlen(id.string)-1; c >= 0; c--)
1572 if(id.string[c] == ':')
1574 char * string = CopyString(id.string + c + 1);
1575 id.string[c - 1] = 0;
1576 id._class = MkSpecifierName(id.string);
1582 symbol.string = CopyString(id.string);
1589 for(spec = func.specifiers->first; spec; spec = spec.next)
1590 symbolSpecs->Add(CopySpecifier(spec));
1592 symbol.type = ProcessType(symbolSpecs, decl);
1593 symbol.idCode = symbol.id = globalContext.nextID++;
1594 decl.symbol = symbol;
1596 excludedSymbols->Add(symbol);
1598 FreeList(symbolSpecs, FreeSpecifier);
1602 OldList * MkSpecsClass(Specifier _class)
1604 OldList * list = MkList();
1605 ListAdd(list, _class);
1609 MemberInit MkMemberInit(OldList ids, Initializer initializer)
1611 return { identifiers = ids, initializer = initializer };
1614 MemberInit MkMemberInitExp(Expression idExp, Initializer initializer)
1616 MemberInit init { initializer = initializer, identifiers = MkList() };
1619 for(exp = idExp; exp && exp.type == memberExp; exp = exp.member.exp)
1621 init.identifiers->Insert(null, exp.member.member);
1622 exp.member.member = null;
1624 if(exp && exp.type == identifierExp)
1626 init.identifiers->Insert(null, exp.identifier);
1627 exp.identifier = null;
1629 FreeExpression(idExp);
1633 MembersInit MkMembersInitList(OldList dataMembers)
1635 return { type = dataMembersInit, dataMembers = dataMembers };
1638 MembersInit MkMembersInitMethod(ClassFunction function)
1640 return { type = methodMembersInit, function = function };
1643 Instantiation MkInstantiation(Specifier _class, Expression exp, OldList members)
1645 return { _class = _class, exp = exp, members = members };
1648 Instantiation MkInstantiationNamed(OldList specs, Expression exp, OldList members)
1650 Instantiation inst { exp = exp, members = members };
1655 for(spec = specs.first; spec; spec = spec.next)
1656 if(spec.type == nameSpecifier /*classSpecifier*/)
1663 FreeList(specs, FreeSpecifier);
1667 Compiler_Error($"Expecting class specifier\n");
1668 inst._class = MkSpecifierName /*MkClassName*/("");
1676 ClassDef MkClassDefAccessOverride(AccessMode access, Identifier id)
1678 return { type = accessOverrideClassDef, id = id, memberAccess = access };
1681 ClassDef MkClassDefMemberAccess()
1683 return { type = memberAccessClassDef };
1686 ClassDef MkClassDefDeclaration(Declaration decl)
1688 return { type = declarationClassDef, decl = decl };
1691 ClassDef MkClassDefClassData(Declaration decl)
1693 return { type = classDataClassDef, decl = decl };
1696 ClassDef MkClassDefDesigner(const char * designer)
1698 return { type = classDesignerClassDef, designer = CopyString(designer) };
1701 ClassDef MkClassDefNoExpansion()
1703 return { type = classNoExpansionClassDef };
1706 ClassDef MkClassDefFixed()
1708 return { type = classFixedClassDef };
1711 ClassDef MkClassDefDesignerDefaultProperty(Identifier id)
1713 return { type = designerDefaultPropertyClassDef, defaultProperty = id };
1716 ClassDef MkClassDefDefaultProperty(OldList defProperties)
1718 return { type = defaultPropertiesClassDef, defProperties = defProperties };
1721 ClassDef MkClassDefFunction(ClassFunction function)
1724 if(function && function.declarator)
1726 Declarator funcDecl = GetFuncDecl(function.declarator);
1727 if(funcDecl && funcDecl.declarator && funcDecl.declarator.type == bracketsDeclarator)
1729 def.type = declarationClassDef;
1730 def.decl = MkStructDeclaration(function.specifiers, MkListOne(MkStructDeclarator(function.declarator, null)), null);
1731 function.declarator = null;
1732 function.specifiers = null;
1733 FreeClassFunction(function);
1737 def.type = functionClassDef;
1738 def.function = function;
1742 Symbol DeclClassAddNameSpace(int symbolID, const char * className)
1745 int len = 0, stringLen;
1747 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1749 if(defaultNameSpace)
1751 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1752 len += defaultNameSpaceLen;
1756 if(currentNameSpace)
1758 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1759 len += currentNameSpaceLen;
1764 stringLen = strlen(className);
1765 memcpy(name + len, className, stringLen);
1768 return _DeclClass(symbolID, name);
1771 Symbol DeclClass(int symbolID, const char * name)
1773 if(strchr(name, ':'))
1774 return _DeclClass(symbolID, name);
1776 return DeclClassAddNameSpace(symbolID, name);
1779 Symbol _DeclClass(int symbolID, const char * name)
1781 Symbol symbol = FindClass(name);
1785 Context classContext;
1786 for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
1792 if(name[0] == ':' && name[1] == ':')
1796 string = CopyString(name);
1797 idCode = symbolID, id = symbolID;
1799 if(!globalContext.classes.Add((BTNode)symbol))
1800 excludedSymbols->Add(symbol);
1805 for(c = 0; (ch = name[c]); c++)
1807 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
1813 if(start && c - start)
1814 symbol.shortName = CopyString(name + start);
1818 symbol.idCode = symbol.id = symbolID;
1822 void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
1824 if(baseSpecs && baseSpecs.first && ((Specifier)baseSpecs.first).type == nameSpecifier)
1829 strcpy(name, ((Specifier)baseSpecs.first).name);
1830 tpl = strchr(name, '<');
1833 baseClass = FindClass(name);
1834 if(baseClass && baseClass.ctx)
1837 for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
1839 TemplatedType type { key = copy.key, param = copy.param };
1840 if(!curContext.templateTypes.Add((BTNode)type))
1844 else if(baseClass && baseClass.registered)
1847 for(sClass = baseClass.registered; sClass; sClass = sClass.base)
1849 ClassTemplateParameter p;
1850 for(p = sClass.templateParams.first; p; p = p.next)
1852 //OldList * specs = MkList();
1853 //Declarator decl = null;
1854 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
1857 TemplateParameter param = p.param;
1861 p.param = param = TemplateParameter
1863 identifier = MkIdentifier(p.name), type = p.type,
1864 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
1867 type = TemplatedType { key = (uintptr)p.name, param = param };
1868 if(!curContext.templateTypes.Add((BTNode)type))
1877 ClassDefinition MkClass(Symbol symbol, OldList baseSpecs, OldList definitions)
1879 ClassDefinition classDef;
1880 SetupBaseSpecs(symbol, baseSpecs);
1883 ClassDefinition classDef = symbol.ctx.classDef;
1886 // This can occur if two instances of a class are defined...
1887 // To avoid dangling 'parent' Contexts, we free the previous class definition
1889 for(external = ast->first; external; external = external.next)
1891 if(external.type == classExternal && external._class == classDef)
1893 ast->Remove(external);
1894 FreeExternal(external);
1899 FreeContext(symbol.ctx);
1902 symbol.ctx = curContext;
1903 classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
1904 curContext.classDef = classDef;
1908 Expression MkExpInstance(Instantiation inst)
1910 return { type = instanceExp, instance = inst };
1913 External MkExternalClass(ClassDefinition _class)
1915 return { type = classExternal, _class = _class, symbol = _class.symbol };
1918 PropertyDef MkProperty(OldList specs, Declarator decl, Identifier id, Statement setStmt, Statement getStmt)
1928 Type type = ProcessType(specs, decl);
1931 char typeString[1024];
1932 typeString[0] = '\0';
1933 PrintTypeNoConst(type, typeString, false, true);
1934 id = MkIdentifier(typeString);
1935 prop.conversion = true;
1941 string = CopyString(id.string);
1944 symbol.idCode = symbol.id = globalContext.nextID++;
1945 excludedSymbols->Add(symbol);
1946 globalContext.nextID++;
1947 globalContext.nextID++;
1948 prop.symbol = symbol;
1952 ClassDef MkClassDefProperty(PropertyDef propertyDef)
1954 return { type = propertyClassDef, propertyDef = propertyDef, loc = yylloc };
1957 ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
1959 return { type = classPropertyClassDef, propertyDef = propertyDef, loc = yylloc };
1962 ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
1964 return { type = classPropertyValueClassDef, id = id, initializer = initializer, loc = yylloc };
1967 int CheckType(const char * text)
1970 Time startTime = GetTime();
1972 if(FindTemplateTypeParameter(curContext, text))
1975 checkTypeTotalTime += GetTime() - startTime;
1979 if(FindType(curContext, text))
1982 checkTypeTotalTime += GetTime() - startTime;
1989 checkTypeTotalTime += GetTime() - startTime;
1991 return TYPE_NAME; //CLASS_NAME;
1994 checkTypeTotalTime += GetTime() - startTime;
2001 return CheckType(yytext);
2004 Context PushContext()
2006 Context ctx { parent = curContext };
2011 void PopContext(Context ctx)
2013 curContext = ctx.parent;
2016 Symbol FindType(Context ctx, const char * name)
2021 //char output[8192];
2022 type = (Symbol)ctx.types.FindString(name);
2023 /*if(!strcmp(name, "intptr_t") && !type)
2025 ctx.types.Print(output, depthOrder);
2028 if(!type && ctx.parent)
2029 type = FindType(ctx.parent, name);
2034 TemplatedType FindTemplateTypeParameter(Context ctx, const char * name)
2036 TemplatedType templatedType = null;
2039 templatedType = (TemplatedType)ctx.templateTypes.FindString(name);
2040 if(!templatedType && ctx.parent)
2041 templatedType = FindTemplateTypeParameter(ctx.parent, name);
2043 return templatedType;
2046 bool ModuleAccess(Module searchIn, Module searchFor)
2048 SubModule subModule;
2050 if(searchFor == searchIn)
2053 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
2055 if(subModule.importMode == publicAccess /*|| searchIn == searchIn.application*/)
2057 if(ModuleAccess(subModule.module, searchFor))
2064 ModuleImport FindModule(Module moduleToFind)
2066 ModuleImport module;
2067 if(!moduleToFind.name)
2069 for(module = imports->first; module; module = module.next)
2070 if(module.name && !strcmp(module.name, moduleToFind.name))
2074 module = ModuleImport
2076 name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
2077 importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
2079 imports->Add(module);
2085 // TO REMOVE: OBSOLETE...
2086 static void GetFullClassNameSpace(NameSpace * ns, char * name)
2090 GetFullClassNameSpace(ns->parent, name);
2091 strcat(name, ns->name);
2096 static char * GetFullClassName(Class c, char * name)
2098 NameSpace * nameSpace;
2100 GetFullClassNameSpace(c.nameSpace, name);
2101 strcat(name, c.name);
2106 public Symbol FindClass(const char * name)
2109 Time startTime = GetTime();
2113 bool global = false;
2114 char fullName[1024];
2116 if(name[0] == ':' && name[1] == ':')
2122 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
2124 int len = 0, stringLen;
2125 if(defaultNameSpace)
2127 memcpy(fullName, defaultNameSpace, defaultNameSpaceLen);
2128 len += defaultNameSpaceLen;
2129 fullName[len++] = ':';
2130 fullName[len++] = ':';
2132 if(currentNameSpace)
2134 memcpy(fullName + len, currentNameSpace, currentNameSpaceLen);
2135 len += currentNameSpaceLen;
2136 fullName[len++] = ':';
2137 fullName[len++] = ':';
2139 stringLen = strlen(name);
2140 memcpy(fullName + len, name, stringLen);
2143 cl = globalContext ? (Symbol)globalContext.classes.FindString(fullName) : null;
2147 cl = globalContext ? (Symbol)globalContext.classes.FindString(name) : null;
2152 Time startTime = GetTime();
2154 // Ignore name space name when searching
2155 for(cl = globalContext ? (Symbol)globalContext.classes.first : null; cl; cl = (Symbol)((BTNode)cl).next)
2159 char * string = cl.string;
2161 for(c = 0; (ch = string[c]); c++)
2163 if(ch == '.' || (ch == ':' && string[c+1] == ':'))
2169 if(start && c - start)
2171 if(!strcmp(string + start, name))
2175 if(cl.shortName && !strcmp(cl.shortName, name))
2179 findClassIgnoreNSTotalTime += GetTime() - startTime;
2185 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
2186 _class = eSystem_FindClass(privateModule, fullName);
2188 _class = eSystem_FindClass(privateModule, name);
2192 name = _class.fullName;
2194 cl = (Symbol)globalContext.classes.FindString(name);
2199 string = CopyString(name);
2200 registered = _class;
2207 cl.module = FindModule(_class.module);
2209 cl.module = mainModule;
2210 if(!globalContext.classes.Add((BTNode)cl))
2211 excludedSymbols->Add(cl);
2212 if(strcmp(name, _class.name))
2213 cl.shortName = CopyString(_class.name);
2218 findClassTotalTime += GetTime() - startTime;
2223 void CopyTypeInto(Type type, Type src)
2226 type.name = CopyString(src.name);
2229 if(src.kind == enumType)
2233 type.members.Clear();
2234 // This must have been a mistake: member = **type**.members.first
2235 for(member = src.members.first; member; member = member.next)
2237 type.members.Add(NamedLink64 { name = CopyString(member.name), data = member.data });
2239 type.enumName = CopyString(src.enumName);
2241 else if(src.kind == structType || src.kind == unionType)
2244 // Tricky stuff... will be removed from list only when ref count reaches 0
2245 for(member = type.members.first; member; member = member.next)
2247 type.enumName = CopyString(src.enumName);
2249 else if(src.kind == functionType)
2252 type.returnType.refCount++;
2253 for(param = type.params.first; param; param = param.next)
2256 else if(src.kind == pointerType || src.kind == arrayType)
2258 type.type.refCount++;
2259 if(src.kind == arrayType)
2261 if(type.arraySizeExp)
2262 type.arraySizeExp = CopyExpression(type.arraySizeExp);
2268 static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeName)
2270 Type specType { refCount = 1, kind = intType, isSigned = true };
2273 bool isTypedef = false;
2275 bool isLong = false;
2276 for(spec = specs.first; spec; spec = spec.next)
2278 if(spec.type == extendedSpecifier)
2280 ExtDecl extDecl = spec.extDecl;
2281 if(extDecl.type == extDeclString)
2283 if(!strcmp(spec.extDecl.s, "__declspec(dllexport)") || !strcmp(spec.extDecl.s, "dllexport"))
2284 specType.dllExport = true;
2285 else if(!strcmp(spec.extDecl.s, "__declspec(stdcall)") || !strcmp(spec.extDecl.s, "stdcall"))
2286 specType.attrStdcall = true;
2288 else if(extDecl.type == extDeclAttrib)
2290 OldList * attribs = extDecl.attr.attribs;
2294 for(attr = attribs->first; attr; attr = attr.next)
2296 String s = attr.attr;
2299 if(!strcmp(s, "dllexport"))
2300 specType.dllExport = true;
2301 else if(!strcmp(s, "stdcall"))
2302 specType.attrStdcall = true;
2306 specType.keepCast = true;
2310 if(spec.specifier != CONST && (specType.kind == structType || specType.kind == unionType))
2313 specType = { kind = intType, isSigned = true, refCount = 1 };
2316 if(isTypedef && keepTypeName)
2318 specType.kind = dummyType;
2321 else if(spec.type == baseSpecifier)
2323 if(spec.specifier == TYPEDEF)
2325 else if(spec.specifier == VOID) specType.kind = voidType;
2326 else if(spec.specifier == CHAR) specType.kind = charType;
2327 else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType && !isLong) specType.kind = intType; }
2328 else if(spec.specifier == _BOOL || spec.specifier == BOOL)
2329 specType.kind = _BoolType;
2330 else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
2331 else if(spec.specifier == INT64) specType.kind = int64Type;
2332 else if(spec.specifier == VALIST)
2333 specType.kind = vaListType;
2334 else if(spec.specifier == SHORT) specType.kind = shortType;
2335 else if(spec.specifier == LONG)
2337 if(isLong || (targetBits == 64 && targetPlatform != win32))
2338 specType.kind = int64Type;
2340 specType.kind = intType;
2343 else if(spec.specifier == FLOAT) specType.kind = floatType;
2344 else if(spec.specifier == DOUBLE) specType.kind = doubleType;
2345 else if(spec.specifier == SIGNED) specType.isSigned = true;
2346 else if(spec.specifier == UNSIGNED) specType.isSigned = false;
2347 else if(spec.specifier == CONST)
2348 specType.constant = true;
2349 else if(spec.specifier == TYPED_OBJECT || spec.specifier == ANY_OBJECT || spec.specifier == CLASS)
2351 switch(spec.specifier)
2353 case TYPED_OBJECT: specType.classObjectType = typedObject; break;
2354 case ANY_OBJECT: specType.classObjectType = anyObject; break;
2355 case CLASS: specType.classObjectType = classPointer; break;
2357 specType.kind = classType;
2358 specType._class = FindClass("class");
2360 else if(spec.specifier == THISCLASS)
2361 specType.kind = thisClassType;
2363 else if(spec.type == nameSpecifier)
2365 if(spec.name && (!strcmp(spec.name, "intptr") || !strcmp(spec.name, "uintptr")))
2367 specType.kind = intPtrType;
2368 if(!strcmp(spec.name, "uintptr"))
2369 specType.isSigned = false;
2371 else if(spec.name && (!strcmp(spec.name, "uintsize") || !strcmp(spec.name, "intsize")))
2373 specType.kind = intSizeType;
2374 if(!strcmp(spec.name, "uintsize"))
2375 specType.isSigned = false;
2379 Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
2380 if(symbol && symbol.type)
2382 // Keep constant qualifier
2383 bool isConstant = specType.constant;
2384 // Free Type Contents:
2389 CopyTypeInto(specType, symbol.type);
2390 specType.constant = isConstant;
2391 specType.typeName = CopyString(symbol.type.name);
2393 else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
2395 // key.sym enum values need FindClass:
2396 specType._class = spec.name ? FindClass(spec.name) : null;
2397 specType.kind = classType;
2398 if(!specType._class)
2399 specType.kind = intType;
2403 else if(spec.type == enumSpecifier)
2405 specType.kind = enumType;
2406 specType.enumName = spec.id ? CopyString(spec.id.string) : null;
2411 for(e = spec.list->first; e; e = e.next)
2413 NamedLink64 i { name = CopyString(e.id.string) };
2414 if(e.exp && e.exp.type == constantExp && e.exp.constant)
2415 i.data = strtoll(e.exp.constant, null, 0);
2416 specType.members.Add(i);
2420 else if(spec.type == templateTypeSpecifier)
2422 specType.kind = templateType;
2423 specType.templateParameter = spec.templateParameter;
2425 else if(spec.type == structSpecifier || spec.type == unionSpecifier)
2427 Symbol _class = spec.id ? FindClass(spec.id.string) : null;
2430 specType.declaredWithStruct = true;
2431 if(!_class.registered || _class.registered.type != structClass)
2432 specType.directClassAccess = true; // TODO: Need to clarify what 'directClassAccess' is about
2433 specType._class = _class;
2434 specType.kind = classType;
2437 specType.members.Clear();
2438 if(spec.type == structSpecifier)
2439 specType.kind = structType;
2440 else if(spec.type == unionSpecifier)
2441 specType.kind = unionType;
2444 // TESTING THIS HERE... Had 0 type size
2445 if(!spec.definitions && !isTypedef)
2447 Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
2448 if(symbol && symbol.type)
2450 specType = *symbol.type;
2451 specType.name = CopyString(symbol.type.name);
2452 specType.typeName = CopyString(spec.name);
2453 specType.enumName = CopyString(symbol.type.enumName);
2454 specType.refCount = 1;
2456 if(symbol.type.kind == enumType)
2460 specType.members.Clear();
2461 for(member = symbol.type.members.first; member; member = member.next)
2463 NamedLink64 item { name = CopyString(member.name), data = member.data };
2464 specType.members.Add(item);
2467 else if(symbol.type.kind == structType || symbol.type.kind == unionType)
2470 // Tricky stuff... will be removed from list only when ref count reaches 0
2471 for(member = specType.members.first; member; member = member.next)
2474 else if(symbol.type.kind == functionType)
2477 specType.returnType.refCount++;
2478 for(param = specType.params.first; param; param = param.next)
2481 else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
2483 specType.type.refCount++;
2484 if(symbol.type.kind == arrayType)
2486 if(specType.arraySizeExp)
2487 specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
2493 specType.enumName = CopyString(spec.id.string);
2496 specType.enumName = CopyString(spec.id.string);
2499 if(spec.definitions)
2502 for(def = spec.definitions->first; def; def = def.next)
2504 if(def.type == declarationClassDef && def.decl.type == structDeclaration)
2506 Declaration decl = def.decl;
2507 if(decl.declarators)
2510 for(d = decl.declarators->first; d; d = d.next)
2512 Type memberType = ProcessType(decl.specifiers, d);
2513 specType.members.Add(memberType);
2516 else if(decl.specifiers)
2518 Type memberType = ProcessType(decl.specifiers, null);
2519 specType.members.Add(memberType);
2526 else if(spec.type == subClassSpecifier)
2528 specType.kind = subClassType;
2529 specType._class = spec._class.symbol;
2533 else if(assumeEllipsis)
2534 specType.kind = ellipsisType;
2538 static Type ProcessTypeDecls(OldList specs, Declarator decl, Type parentType)
2540 Type type = parentType;
2541 Declarator subDecl = decl ? decl.declarator : null;
2543 type = ProcessTypeSpecs(specs, decl == null, (decl && decl.type == extendedDeclaratorEnd) ? true : false);
2548 case bracketsDeclarator: break;
2549 case extendedDeclarator:
2550 case extendedDeclaratorEnd:
2552 ExtDecl extDecl = decl.extended.extended;
2555 switch(extDecl.type)
2559 String s = extDecl.s;
2562 if(!strcmp(s, "__declspec(dllexport)") || !strcmp(s, "dllexport"))
2563 type.dllExport = true;
2564 else if(!strcmp(s, "__declspec(stdcall)") || !strcmp(s, "stdcall"))
2565 type.attrStdcall = true;
2571 OldList * attribs = extDecl.attr.attribs;
2575 for(attr = attribs->first; attr; attr = attr.next)
2577 String s = attr.attr;
2580 if(!strcmp(s, "dllexport"))
2581 type.dllExport = true;
2582 else if(!strcmp(s, "stdcall"))
2583 type.attrStdcall = true;
2587 type.keepCast = true;
2594 case structDeclarator:
2596 Expression exp = decl.structDecl.exp;
2599 ProcessExpressionType(exp);
2600 ComputeExpression(exp);
2601 if(exp.type == constantExp)
2602 type.bitFieldCount = (uint)strtoul(exp.constant, null, 0);
2606 case functionDeclarator:
2608 type = { refCount = 1, kind = functionType, returnType = type, dllExport = type.dllExport, attrStdcall = type.attrStdcall };
2609 if(decl.function.parameters)
2612 for(param = decl.function.parameters->first; param; param = param.next)
2613 type.params.Add(ProcessType(param.qualifiers, param.declarator));
2617 case arrayDeclarator:
2619 type = { refCount = 1, kind = arrayType, arraySizeExp = CopyExpression(decl.array.exp), freeExp = true, type = type, dllExport = type.dllExport, attrStdcall = type.attrStdcall };
2620 if(decl.array.enumClass)
2621 type.enumClass = decl.array.enumClass.symbol;
2624 case pointerDeclarator:
2626 Pointer pointer = decl.pointer.pointer;
2629 OldList * qualifiers = pointer.qualifiers;
2630 if(type.classObjectType)
2631 type.byReference = true;
2633 type = { refCount = 1, kind = pointerType, type = type, dllExport = type.dllExport, attrStdcall = type.attrStdcall };
2637 for(spec = qualifiers->first; spec; spec = spec.next)
2639 if(spec.type == baseSpecifier && spec.specifier == CONST)
2640 type.constant = true;
2643 pointer = pointer.pointer;
2647 case identifierDeclarator:
2649 Identifier id = decl.identifier;
2650 Specifier _class = id._class;
2652 type.name = CopyString(id.string);
2655 if(_class.type == templateTypeSpecifier)
2657 type.thisClassTemplate = _class.templateParameter;
2658 type.extraParam = true;
2662 String name = _class.name;
2664 type.staticMethod = true;
2668 id.classSym = _class.symbol; // FindClass(_class.name);
2669 /* TODO: Name Space Fix ups
2670 id.nameSpace = eSystem_FindNameSpace(privateModule, _class.name);
2673 if(name[strlen(name)-1] == '&')
2675 type.thisClass = FindClass("class");
2676 type.byReference = true;
2679 type.thisClass = _class.symbol;
2681 if(type.thisClass && strcmp(type.thisClass.string, "class"))
2682 type.extraParam = true;
2683 else if(!strcmp(name, "any_object"))
2685 type.extraParam = true;
2686 type.thisClass = FindClass("class");
2688 else if(!strcmp(name, "class"))
2690 type.thisClass = FindClass("class");
2691 type.classObjectType = classPointer; // This is used for class properties
2693 else if(!strcmp(name, "typed_object") || !strcmp(name, "typed_object&"))
2695 type.thisClass = FindClass("class");
2696 type.classObjectType = typedObject;
2704 PrintLn("Unhandled Declarator Type: ", decl.type);
2709 Type curType = type;
2710 type = ProcessTypeDecls(null, subDecl, type);
2711 if(curType && type.kind != functionType)
2713 curType.thisClassTemplate = type.thisClassTemplate;
2714 curType.extraParam = type.extraParam;
2715 curType.staticMethod = type.staticMethod;
2716 curType.thisClass = type.thisClass;
2717 curType.byReference = type.byReference;
2718 curType.classObjectType = type.classObjectType;
2724 public Type ProcessType(OldList specs, Declarator decl)
2726 return ProcessTypeDecls(specs, decl, null);
2729 public Type ProcessTypeString(const char * string, bool staticMethod)
2731 OldList * specs = MkList();
2732 Declarator decl = SpecDeclFromString(string, specs, null);
2733 Type type = ProcessType(specs, decl);
2734 if(type && !type.thisClass && staticMethod) type.staticMethod = true;
2735 FreeList(specs, FreeSpecifier);
2736 if(decl) FreeDeclarator(decl);
2740 Type MkClassTypeSymbol(Symbol symbol)
2744 Type type { kind = classType, _class = symbol };
2747 // Defaults to an int instead...
2748 type.kind = intType;
2756 public Type MkClassType(const char * name)
2760 Type type { kind = classType, _class = FindClass(name) };
2763 // Defaults to an int instead...
2764 type.kind = intType;
2772 AsmField MkAsmField(char * command, Expression expression, Identifier symbolic)
2774 return { command = command, expression = expression, symbolic = symbolic };
2777 Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
2779 return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
2780 asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
2781 asmStmt.clobberedFields = clobberedFields };
2784 ClassDef MkClassDefPropertyWatch(PropertyWatch watcher)
2786 return { type = propertyWatchClassDef, propertyWatch = watcher };
2789 Statement MkFireWatchersStmt(Expression object, OldList watches)
2791 return { type = fireWatchersStmt, _watch.object = object, _watch.watches = watches };
2794 Statement MkStopWatchingStmt(Expression watcher, Expression object, OldList watches)
2796 return { type = stopWatchingStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2799 Statement MkWatchStmt(Expression watcher, Expression object, OldList watches)
2801 return { type = watchStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2804 PropertyWatch MkDeleteWatch(Statement compound)
2806 return { compound = compound, deleteWatch = true };
2809 PropertyWatch MkPropertyWatch(OldList properties, Statement compound)
2811 return { compound = compound, properties = properties };
2814 Expression MkExpClass(OldList * specifiers, Declarator decl)
2816 return { type = classExp, _classExp.specifiers = specifiers, _classExp.decl = decl };
2819 Expression MkExpClassData(Identifier id)
2821 return { type = classDataExp, classData.id = id };
2825 External MkExternalDBTable(DBTableDef table)
2827 return { type = dbtableExternal, table = table };
2830 DBTableDef MkDBTableDef(char * name, Symbol symbol, OldList * definitions)
2832 return { name = name, symbol = symbol, definitions = definitions };
2835 DBTableEntry MkDBFieldEntry(TypeName type, Identifier id, char * name)
2837 return { type = fieldEntry, dataType = type, id = id, name = name };
2840 DBIndexItem MkDBIndexItem(Identifier id, Order order)
2842 return { id = id, order = order };
2845 DBTableEntry MkDBIndexEntry(OldList * items, Identifier id)
2847 return { type = indexEntry, items = items, id = id };
2850 Expression MkExpDBOpen(Expression ds, Expression dbName)
2852 return { type = dbopenExp, dbopen.ds = ds, dbopen.name = dbName };
2855 Expression MkExpDBField(char * table, Identifier id)
2857 return { type = dbfieldExp, db.table = table, db.id = id };
2860 Expression MkExpDBIndex(char * table, Identifier id)
2862 return { type = dbindexExp, db.table = table, db.id = id };
2865 Expression MkExpDBTable(char * table)
2867 return { type = dbtableExp, db.table = table };
2870 Expression MkExpArray(OldList * expressions)
2872 return { type = arrayExp, list = expressions };
2875 Expression GetTemplateArgExpByName(const char * paramName, Class curClass, TemplateParameterType tplType)
2877 Expression argExp = null;
2878 Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
2882 ClassTemplateParameter curParam;
2884 for(sClass = _class; sClass; sClass = sClass.base)
2887 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2889 if(!strcmp(curParam.name, paramName))
2891 for(sClass = sClass.base; sClass; sClass = sClass.base)
2892 id += sClass.templateParams.count;
2900 if(curParam && curParam.type != tplType)
2906 char className[1024];
2908 sprintf(idString, "%d", id);
2909 strcpy(className, "__ecereClass_");
2910 FullClassNameCat(className, _class.fullName, true);
2911 //MangleClassName(className);
2912 DeclareClass(FindClass(_class.fullName), className);
2914 argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
2915 (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
2916 MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
2922 Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
2924 return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
2927 /*char * CreateMsgID(const char * string, const char * context)
2929 int lenString = strlen(string), lenContext = strlen(context);
2930 char * msgid = new char[lenString + lenContext + 20];
2931 memcpy(msgid, string, lenString);
2932 memcpy(msgid+lenString, " [msgctxt: ", 11);
2933 memcpy(msgid+lenString+11, context, lenContext);
2934 memcpy(msgid+lenString+11+lenContext, "]", 2);
2938 public void OutputIntlStrings()
2940 if(intlStrings.count)
2942 const char * srcFile = GetSourceFile();
2943 const char * objFile = GetOutputFile();
2944 char srcFileFixed[MAX_LOCATION];
2945 char potFile[MAX_LOCATION];
2947 ChangeExtension(objFile, "bowl", potFile);
2948 f = FileOpen(potFile, write);
2951 const char * filePrefix = "";
2952 if(!(srcFile[0] && (srcFile[1] == ':' || srcFile[0] == '/')))
2953 filePrefix = "./"; //(GetRuntimePlatform() == win32) ? ".\\" : "./";
2954 // GetSystemPathBuffer(srcFileFixed, srcFile);
2955 GetSlashPathBuffer(srcFileFixed, srcFile);
2957 for(s : intlStrings)
2959 // TOFIX: (#654) ContextStringPair * pair = &s;
2960 ContextStringPair pair = &s;
2962 f.Printf("#: %s%s:%d\n", filePrefix, srcFileFixed, l.start.line);
2963 // PoEdit now preserves and distinguish msgctxt
2965 f.Printf("msgctxt \"%s\"\n", pair.context);
2966 f.Printf("msgid \"%s\"\n", pair.string);
2967 f.Printf("msgstr \"%s\"\n\n", pair.string);
2975 default extern OldList * ast;
2976 default extern int yyparse ();
2977 default extern int yylex ();
2979 public void SetAST(OldList * list) { ast = list; }
2980 public OldList * GetAST() { return ast; }
2981 public void ParseEc()
2991 public const char * GetYYText()