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 = (uint)identifier.string, param = param };
143 curContext.templateTypes.Add((BTNode)type);
149 public TemplateParameter MkIdentifierTemplateParameter(Identifier identifier, TemplateMemberType memberType, TemplateArgument defaultArgument)
151 if(identifier.string)
153 TemplateParameter param { type = TemplateParameterType::identifier, identifier = identifier, memberType = memberType, defaultArgument = defaultArgument };
159 public TemplateParameter MkExpressionTemplateParameter(Identifier identifier, TemplateDatatype dataType, TemplateArgument defaultArgument)
161 if(identifier.string)
163 TemplateParameter param { type = TemplateParameterType::expression, identifier = identifier, dataType = dataType, defaultArgument = defaultArgument };
169 public TemplateDatatype MkTemplateDatatype(OldList * specifiers, Declarator decl)
171 TemplateDatatype datatype { specifiers = specifiers, decl = decl };
175 public TemplateArgument MkTemplateTypeArgument(TemplateDatatype tplDatatype)
177 TemplateArgument argument { type = type, templateDatatype = tplDatatype };
181 public TemplateArgument MkTemplateExpressionArgument(Expression expr)
183 TemplateArgument argument { type = expression, expression = expr };
187 public TemplateArgument MkTemplateIdentifierArgument(Identifier ident)
189 TemplateArgument argument { type = identifier, identifier = ident };
193 Expression MkExpExtensionCompound(Statement compound)
195 return { type = extensionCompoundExp, compound = compound };
198 Expression MkExpExtensionExpression(OldList * expressions)
200 return { type = extensionExpressionExp, list = expressions, loc = yylloc };
203 Expression MkExpExtensionInitializer(TypeName typeName, Initializer initializer)
205 return { type = extensionInitializerExp, initializer.typeName = typeName, initializer.initializer = initializer, loc = yylloc };
208 public Expression MkExpIdentifier(Identifier id)
210 return { type = identifierExp, identifier = id };
213 public Expression MkExpDummy()
215 return { type = dummyExp };
218 public Expression MkExpConstant(char * string)
220 return { type = constantExp, constant = CopyString(string) };
223 Expression MkExpString(char * string)
225 return { type = stringExp, string = CopyString(string) };
228 struct ContextStringPair { String string, context; };
230 Map<ContextStringPair, List<Location> > intlStrings { };
232 Expression MkExpIntlString(char * string, char * context)
234 OldList * list = MkList();
237 MapIterator<ContextStringPair, List<Location>> it { map = intlStrings };
238 ContextStringPair pair {string, context};
239 List<Location> list = intlStrings[pair];
243 pair.string = CopyString(string);
244 pair.context = CopyString(context);
245 intlStrings[pair] = list;
248 // if(!it.Index({string, context }, false))
250 ListAdd(list, QMkExpId("__thisModule"));
251 ListAdd(list, MkExpString(string));
254 int lenString = strlen(string), lenContext = strlen(context);
255 char * msgid = new char[lenString-2 + lenContext-2 + 4];
257 memcpy(msgid+1, string+1, lenString-2);
258 msgid[1+lenString-2] = 4; // EOT
259 memcpy(msgid+1+lenString-2+1, context+1, lenContext-2);
260 memcpy(msgid+1+lenString-2+1+lenContext-2, "\"", 2);
261 ListAdd(list, MkExpString(msgid));
264 ListAdd(list, QMkExpId("null"));
265 return MkExpCall(QMkExpId("GetTranslatedString"), list);
268 Expression MkExpOp(Expression exp1, int op, Expression exp2)
279 exp.loc.start = exp1 ? exp1.loc.start : exp2.loc.start;
280 exp.loc.end = exp2 ? exp2.loc.end : exp1.loc.end;
285 Expression MkExpBrackets(OldList expressions)
292 if(expressions && expressions.first)
294 exp.loc.start = ((Expression)expressions.first).loc.start;
295 exp.loc.end = ((Expression)expressions.last).loc.end;
300 Expression MkExpIndex(Expression expression, OldList index)
302 return { type = indexExp, index.exp = expression, index.index = index };
305 Expression MkExpCall(Expression expression, OldList arguments)
307 return { type = callExp, call.exp = expression, call.arguments = arguments };
310 Expression MkExpMember(Expression expression, Identifier member)
312 return { type = memberExp, member.exp = expression, member.member = member };
315 Expression MkExpPointer(Expression expression, Identifier member)
317 return { type = pointerExp, member.exp = expression, member.member = member };
320 Expression MkExpTypeSize(TypeName typeName)
322 return { type = typeSizeExp, typeName = typeName };
325 Expression MkExpClassSize(Specifier _class)
327 return { type = classSizeExp, _class = _class };
330 Expression MkExpCast(TypeName typeName, Expression expression)
332 return { type = castExp, cast.typeName = typeName, cast.exp = expression };
335 Expression MkExpCondition(Expression cond, OldList expressions, Expression elseExp)
337 return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp };
340 Expression MkExpRenew(Expression memExp, TypeName type, Expression size)
342 return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
345 Expression MkExpRenew0(Expression memExp, TypeName type, Expression size)
347 return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
350 Expression MkExpNew(TypeName type, Expression size)
352 return { type = newExp, _new.typeName = type, _new.size = size };
355 Expression MkExpNew0(TypeName type, Expression size)
357 return { type = new0Exp, _new.typeName = type, _new.size = size };
360 Expression MkExpVaArg(Expression exp, TypeName type)
362 return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type };
365 Specifier MkSpecifier(int specifier)
367 return { type = baseSpecifier, specifier = specifier };
370 Specifier MkSpecifierTypeOf(Expression expression)
372 return { type = typeOfSpecifier, expression = expression };
375 Specifier MkSpecifierSubClass(Specifier _class)
377 return { type = subClassSpecifier, _class = _class };
380 Specifier MkSpecifierExtended(char * name)
382 return { type = extendedSpecifier, name = CopyString(name) };
385 Specifier MkEnum(Identifier id, OldList list)
389 type = enumSpecifier;
393 if(list && (!declMode || !id))
399 type = ProcessType(&specs, null);
403 curContext.structSymbols.Add((BTNode)Symbol { string = CopyString(id.string), isStruct = true, type = type });
406 for(e = list.first; e; e = e.next)
408 (curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)Symbol { string = CopyString(e.id.string), type = type });
416 Specifier MkStructOrUnion(SpecifierType type, Identifier id, OldList definitions)
418 Specifier spec { type = type, id = id };
419 if(id && FindType(curContext, id.string))
420 declMode = defaultAccess;
421 spec.definitions = definitions;
422 if(definitions && id && !declMode)
426 curContext.structSymbols.Add((BTNode)Symbol { string = CopyString(id.string), type = ProcessType(specs, null), isStruct = true });
431 void AddStructDefinitions(Specifier spec, OldList definitions)
433 spec.definitions = definitions;
434 if(definitions && spec.id && !declMode)
438 curContext.parent.structSymbols.Add((BTNode)Symbol { string = CopyString(spec.id.string), type = ProcessType(specs, null), isStruct = true });
442 public Declarator MkDeclaratorIdentifier(Identifier id)
444 return { type = identifierDeclarator, identifier = id };
447 Declarator MkDeclaratorFunction(Declarator declarator, OldList parameters)
449 return { type = functionDeclarator, declarator = declarator, function.parameters = parameters };
452 Declarator MkDeclaratorExtended(char * extended, Declarator declarator)
454 return { type = extendedDeclarator, declarator = declarator, extended.extended = extended };
457 Declarator MkDeclaratorExtendedEnd(char * extended, Declarator declarator)
459 return { type = extendedDeclaratorEnd, declarator = declarator, extended.extended = extended };
462 Declarator MkStructDeclarator(Declarator declarator, Expression exp)
464 return { type = structDeclarator, declarator = declarator, structDecl.exp = exp };
467 Declarator MkDeclaratorBrackets(Declarator declarator)
469 return { type = bracketsDeclarator, declarator = declarator };
472 Declarator MkDeclaratorArray(Declarator declarator, Expression exp)
474 return { type = arrayDeclarator, declarator = declarator, array.exp = exp };
477 Declarator MkDeclaratorEnumArray(Declarator declarator, Specifier _class)
479 return { type = arrayDeclarator, declarator = declarator, array.enumClass = _class };
482 Declarator MkDeclaratorPointer(Pointer pointer, Declarator declarator)
484 return { type = pointerDeclarator, declarator = declarator, pointer.pointer = pointer };
487 Enumerator MkEnumerator(Identifier id, Expression exp)
489 return { id = id, exp = exp };
492 Pointer MkPointer(OldList qualifiers, Pointer pointer)
494 return { qualifiers = qualifiers, pointer = pointer };
497 Initializer MkInitializerAssignment(Expression exp)
499 /*if(yylloc.start.line == 1)
501 return { type = expInitializer, exp = exp, loc = yylloc };
504 Initializer MkInitializerList(OldList list)
506 /*if(yylloc.start.line == 1)
508 return { type = listInitializer, list = list, loc = yylloc };
511 InitDeclarator MkInitDeclarator(Declarator declarator, Initializer initializer)
513 return { declarator = declarator, initializer = initializer };
516 public TypeName MkTypeName(OldList qualifiers, Declarator declarator)
518 return { qualifiers = qualifiers, declarator = declarator };
521 public Identifier GetDeclId(Declarator decl)
523 while(decl && decl.type != identifierDeclarator)
524 decl = decl.declarator;
525 return decl ? decl.identifier : null;
528 Declaration MkDeclarationClassInst(Instantiation inst)
530 return { type = instDeclaration, inst = inst, loc = yylloc };
533 Declaration MkDeclarationInst(Instantiation inst)
535 Declaration decl { type = instDeclaration, inst = inst, loc = yylloc };
537 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
540 int len = 0, stringLen;
543 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
544 len += defaultNameSpaceLen;
550 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
551 len += currentNameSpaceLen;
556 stringLen = strlen(inst.exp.identifier.string);
557 memcpy(name + len, inst.exp.identifier.string, stringLen);
560 delete inst.exp.identifier.string;
561 inst.exp.identifier.string = CopyString(name);
566 string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
567 type = MkClassTypeSymbol(inst._class.symbol);
569 symbol.idCode = symbol.id = curContext.nextID++;
570 (curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol);
571 decl.symbol = inst.symbol = symbol;
575 Declaration MkDeclarationDefine(Identifier id, Expression exp)
577 Declaration decl { type = defineDeclaration, id = id, exp = exp, loc = yylloc };
578 char expString[1024];
581 PrintExpression(exp, expString);
583 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
586 int len = 0, stringLen;
589 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
590 len += defaultNameSpaceLen;
596 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
597 len += currentNameSpaceLen;
601 stringLen = strlen(id.string);
602 memcpy(name + len, id.string, stringLen);
606 id.string = CopyString(name);
609 if(!eSystem_FindDefine(privateModule, id.string))
610 eSystem_RegisterDefine(id.string, expString, privateModule, buildingECERECOMModule ? baseSystemAccess : publicAccess);
612 Compiler_Warning("Redefinition of %s ignored\n", id.string);
616 Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
618 Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
619 bool variable = true;
621 if(specifiers != null)
624 for(spec = specifiers.first; spec; spec = spec.next)
626 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
628 if(initDeclarators != null)
632 for(d = initDeclarators.first; d; d = d.next)
634 if(GetDeclId(d.declarator).string)
638 string = CopyString(GetDeclId(d.declarator).string);
639 type = ProcessType(specifiers, d.declarator);
641 type.id = type.idCode = curContext.nextID++;
643 (curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type);
644 decl.symbol = d.declarator.symbol = type;
650 for(; spec; spec = spec.next)
652 if(spec.type == nameSpecifier && spec.name)
656 string = CopyString(spec.name);
657 type = ProcessType(specifiers, null);
659 type.id = type.idCode = curContext.nextID++;
660 (curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type);
668 else if(spec.type == baseSpecifier &&
669 (spec.specifier == STRUCT || spec.specifier == UNION))
673 if(variable && initDeclarators)
676 for(d = initDeclarators.first; d; d = d.next)
678 Identifier id = GetDeclId(d.declarator);
679 if(id && id.string && id.string[0])
685 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
688 int len = 0, stringLen;
691 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
692 len += defaultNameSpaceLen;
698 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
699 len += currentNameSpaceLen;
703 stringLen = strlen(id.string);
704 memcpy(name + len, id.string, stringLen);
708 id.string = CopyString(name);
711 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specifiers, d.declarator) };
712 (curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol);
713 // TODO: Add better support to count declarators
714 if(symbol.type && symbol.type.kind == arrayType && !symbol.type.arraySizeExp && d.initializer)
716 if(d.initializer.type == listInitializer)
719 sprintf(string, "%d",d.initializer.list->count);
720 symbol.type.arraySizeExp = MkExpConstant(string);
721 symbol.type.freeExp = true;
723 else if(d.initializer.type == expInitializer && d.initializer.exp.type == stringExp && d.initializer.exp.string)
728 bool escaped = false;
729 char * s = d.initializer.exp.string;
731 // MAKE MORE ACCURATE
732 for(c = 1; (ch = s[c]); c++)
734 if(ch == '\\' && !escaped)
743 sprintf(string, "%d", count);
744 symbol.type.arraySizeExp = MkExpConstant(string);
745 symbol.type.freeExp = true;
748 symbol.id = symbol.idCode = curContext.nextID++;
749 decl.symbol = d.declarator.symbol = symbol;
756 decl.symbol = Symbol { };
757 decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
758 excludedSymbols->Add(decl.symbol);
763 Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifier extStorage)
765 return { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
768 Statement MkLabeledStmt(Identifier id, Statement statement)
770 return { type = labeledStmt, labeled.id = id, labeled.stmt = statement, loc = yylloc };
773 Statement MkCaseStmt(Expression exp, Statement statement)
775 return { type = caseStmt, caseStmt.exp = exp, caseStmt.stmt = statement, loc = yylloc };
778 Statement MkCompoundStmt(OldList declarations, OldList statements)
780 return { type = compoundStmt, compound.declarations = declarations, compound.statements = statements, loc = yylloc };
783 Statement MkExpressionStmt(OldList expressions)
785 return { type = expressionStmt, expressions = expressions, loc = yylloc };
788 Statement MkBadDeclStmt(Declaration decl)
790 return { type = badDeclarationStmt, decl = decl, loc = yylloc };
793 Statement MkIfStmt(OldList exp, Statement statement, Statement elseStmt)
795 return { type = ifStmt, ifStmt.exp = exp, ifStmt.stmt = statement, ifStmt.elseStmt = elseStmt, loc = yylloc };
798 Statement MkSwitchStmt(OldList exp, Statement statement)
800 // To know it's a switch compound... (Don't want declarations in there... bugs)
802 statement.compound.isSwitch = true;
803 return { type = switchStmt, switchStmt.exp = exp, switchStmt.stmt = statement, loc = yylloc };
806 Statement MkWhileStmt(OldList exp, Statement statement)
808 return { type = whileStmt, whileStmt.exp = exp, whileStmt.stmt = statement, loc = yylloc };
811 Statement MkDoWhileStmt(Statement statement, OldList exp)
813 return { type = doWhileStmt, doWhile.exp = exp, doWhile.stmt = statement, loc = yylloc };
816 Statement MkForStmt(Statement init, Statement check, OldList inc, Statement statement)
818 return { type = forStmt, forStmt.init = init, forStmt.check = check, forStmt.increment = inc, forStmt.stmt = statement, loc = yylloc };
821 Statement MkForEachStmt(Identifier id, OldList exp, OldList filter, Statement statement)
823 return { type = forEachStmt, forEachStmt.id = id, forEachStmt.exp = exp, forEachStmt.filter = filter, forEachStmt.stmt = statement, loc = yylloc };
826 Statement MkGotoStmt(Identifier id)
828 return { type = gotoStmt, gotoStmt.id = id, loc = yylloc };
831 Statement MkContinueStmt()
833 return { type = continueStmt, loc = yylloc };
836 Statement MkBreakStmt()
838 return { type = breakStmt, loc = yylloc };
841 Statement MkReturnStmt(OldList exp)
843 return { type = returnStmt, expressions = exp, loc = yylloc };
846 FunctionDefinition MkFunction(OldList specifiers, Declarator declarator, OldList declarationList)
848 return { specifiers = specifiers, declarator = declarator, declarations = declarationList };
851 void ProcessFunctionBody(FunctionDefinition func, Statement body)
853 Declarator declarator = func.declarator;
854 Declarator funcDecl = GetFuncDecl(declarator);
859 if(funcDecl && funcDecl.function.parameters && body)
861 Context context = body.compound.context;
863 for(param = funcDecl.function.parameters->first; param; param = param.next)
867 Symbol symbol = null;
868 Identifier id = GetDeclId(param.declarator);
869 char * string = id ? id.string : null;
872 for(symbol = (Symbol)context.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
873 if(!strcmp(symbol.string, string))
875 // This parameter is not shadowed by a local declaration
878 symbol = Symbol { string = CopyString(id.string), type = ProcessType(param.qualifiers, param.declarator), isParam = true };
879 context.symbols.Add((BTNode)symbol);
881 // TODO: Fix this, the parameters' IDs should really be smaller...
882 symbol.id = context.nextID++;
883 param.declarator.symbol = symbol;
890 if(!declarator.symbol)
892 Identifier id = GetDeclId(declarator);
894 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess && strcmp(id.string, "__on_register_module"))
897 int len = 0, stringLen;
900 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
901 len += defaultNameSpaceLen;
907 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
908 len += currentNameSpaceLen;
912 stringLen = strlen(id.string);
913 memcpy(name + len, id.string, stringLen);
917 id.string = CopyString(name);
919 symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
920 symbol.idCode = symbol.id = globalContext.nextID++;
921 globalContext.symbols.Add((BTNode)symbol);
922 declarator.symbol = symbol;
926 symbol = declarator.symbol;
927 excludedSymbols->Remove(declarator.symbol);
928 delete symbol.string;
929 symbol.string = CopyString(GetDeclId(declarator).string);
930 globalContext.symbols.Add((BTNode)symbol);
933 symbol.type = ProcessType(func.specifiers, declarator);
935 if(symbol.type && (symbol.type.kind == functionType || symbol.type.kind == methodType))
937 if(!symbol.type.params.count)
939 Type type { refCount = 1 };
940 symbol.type.params.Add(type);
949 External MkExternalFunction(FunctionDefinition function)
951 External external { type = functionExternal, function = function, symbol = function.declarator.symbol };
952 if(function.specifiers)
955 for(spec = function.specifiers->first; spec; spec = spec.next)
956 if(spec.type == baseSpecifier && spec.specifier == STATIC)
958 declMode = staticAccess;
963 if(external.symbol && !external.symbol.methodExternal)
964 external.symbol.methodExternal = external;
968 External MkExternalImport(char * name, ImportType importType, AccessMode importAccess)
970 External external { type = importExternal };
971 int len = strlen(name) - 2;
972 external.importString = new char[len + 1];
973 strncpy(external.importString, name+1, len);
974 external.importString[len] = '\0';
979 Time startTime = GetTime();
982 ImportModule(external.importString, importType, importAccess, true);
983 ImportModule(external.importString, importType, importAccess, false);
985 time = GetTime() - startTime;
986 printf("Importing took %.3f seconds for %s\n", time, external.importString);
987 externalImportTotalTime += time;
993 External MkExternalDeclaration(Declaration declaration)
995 External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
996 InitDeclarator d = (declaration && declaration.declarators) ? declaration.declarators->last : null;
997 if(declaration && declaration.type == initDeclaration && declaration.specifiers)
1000 for(spec = declaration.specifiers->first; spec; spec = spec.next)
1001 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1003 declMode = defaultAccess;
1006 else if(spec.type == baseSpecifier && spec.specifier == STATIC)
1008 declMode = staticAccess;
1012 if(declaration && declaration.symbol && !declaration.symbol.methodExternal)
1013 declaration.symbol.methodExternal = external;
1017 External MkExternalNameSpace(Identifier identifier)
1019 External external { type = nameSpaceExternal, id = identifier };
1020 currentNameSpace = identifier ? identifier.string : null;
1021 currentNameSpaceLen = currentNameSpace ? strlen(currentNameSpace) : 0;
1025 void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
1027 if(spec.type == nameSpecifier)
1029 Symbol symbol = spec.symbol;
1030 spec.templateArgs = templateArgs;
1031 if(templateArgs && templateArgs.first)
1033 char templateString[1024];
1034 TemplateArgument arg;
1035 strcpy(templateString, symbol ? symbol.string : spec.name);
1036 strcat(templateString, "<");
1037 for(arg = templateArgs.first; arg; arg = arg.next)
1045 char expString[1024];
1046 Class backupThisClass = thisClass;
1048 expString[0] = '\0';
1049 // Will this work here?
1051 Location oldLocation = yylloc;
1052 File backFileInput = fileInput;
1057 // TESTING THIS SCANNER RESUME STUFF
1060 yylloc = oldLocation;
1061 fileInput = backFileInput;
1064 fileInput.Seek(yylloc.start.pos, start);
1065 resetScannerPos(&yylloc.start);
1070 //ProcessExpressionType(arg.expression);
1071 //ComputeExpression(arg.expression);
1072 PrintExpression(arg.expression, expString);
1073 strcat(argument, expString);
1074 thisClass = backupThisClass;
1079 strcat(argument, arg.identifier.string);
1084 char * typeString = StringFromSpecDecl(arg.templateDatatype.specifiers, arg.templateDatatype.decl);
1085 strcat(argument, typeString);
1092 if(arg.prev) strcat(templateString, ", ");
1095 strcat(templateString, arg.name.string);
1096 strcat(templateString, " = ");
1098 strcat(templateString, argument);
1102 int len = strlen(templateString);
1103 if(templateString[len-1] == '>') templateString[len++] = ' ';
1104 templateString[len++] = '>';
1105 templateString[len++] = '\0';
1107 // printf("SetClassTemplateArgs templateString: %s\n", templateString);
1108 symbol = FindClass(templateString);
1109 if(!symbol && spec.symbol)
1111 // If class was only decl'ed, invoke DeclClass on this templated class as well
1112 symbol = _DeclClass(MAXINT, templateString);
1114 // Add a reference to all templated class to the basic class
1116 spec.symbol.templatedClasses.Add(OldLink { data = symbol });
1118 spec.symbol = symbol;
1119 spec.name = CopyString(symbol ? symbol.string : templateString);
1123 FreeList(templateArgs, FreeTemplateArgument);
1126 Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
1128 Specifier spec { type = nameSpecifier };
1134 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
1137 spec.templateParameter = templatedType.param;
1138 spec.type = templateTypeSpecifier;
1142 symbol = FindClass(name);
1144 if(symbol && symbol.registered && symbol.registered.isRemote == 1)
1146 char className[1024];
1147 strcpy(className, "DCOMClient_");
1148 if(!strncmp(name, className, strlen(className)))
1149 spec.name = CopyString(name);
1152 strcat(className, name);
1153 spec.name = CopyString(className);
1157 spec.name = CopyString(symbol.string);
1159 spec.name = CopyString(name);
1160 spec.symbol = symbol;
1161 if(templateArgs != null)
1162 SetClassTemplateArgs(spec, templateArgs);
1167 public Specifier MkSpecifierName(char * name)
1169 return _MkSpecifierName(name, null, null);
1172 public Specifier MkSpecifierNameArgs(char * name, OldList * templateArgs)
1174 return _MkSpecifierName(name, null, templateArgs);
1178 Specifier MkClassName(char * string)
1180 return { type = SpecifierClass, name = CopyString(string) };
1183 ClassFunction MkClassFunction(OldList specifiers, Specifier _class, Declarator decl, OldList declList)
1185 return { specifiers = specifiers, /*_class = _class,*/ declarator = decl, declarations = declList };
1188 void ProcessClassFunctionBody(ClassFunction func, Statement body)
1192 Declarator decl = func.declarator;
1194 //Declarator decl = GetFuncDecl(func.declarator);
1195 Declarator funcDecl = GetFuncDecl(func.declarator);
1199 if(decl && !decl.symbol)
1201 OldList * symbolSpecs = MkList();
1203 // WHAT WILL WE DO WITH THIS? Double instances?
1204 //if(decl.function.parameters && body)
1205 if(funcDecl && funcDecl.function.parameters && body)
1207 Context context = body.compound.context;
1209 for(param = funcDecl.function.parameters->first; param; param = param.next)
1211 if(param.declarator)
1213 Symbol symbol = null;
1214 Identifier id = GetDeclId(param.declarator);
1215 char * string = id ? id.string : null;
1218 symbol = (Symbol)context.symbols.FindString(string);
1220 // This parameter is not shadowed by a local declaration
1225 string = CopyString(id.string);
1226 type = ProcessType(param.qualifiers, param.declarator);
1230 // TODO: Fix this, the parameters' IDs should really be smaller...
1231 symbol.idCode = symbol.id = context.nextID++;
1232 context.symbols.Add((BTNode)symbol);
1234 param.declarator.symbol = symbol;
1239 //////////////////////////////////
1247 Identifier id = GetDeclId(funcDecl);
1251 for(c = strlen(id.string)-1; c >= 0; c--)
1253 if(id.string[c] == ':')
1255 char * string = CopyString(id.string + c + 1);
1256 id.string[c - 1] = 0;
1257 id._class = MkSpecifierName(id.string);
1263 symbol.string = CopyString(id.string);
1270 for(spec = func.specifiers->first; spec; spec = spec.next)
1271 symbolSpecs->Add(CopySpecifier(spec));
1273 symbol.type = ProcessType(symbolSpecs, decl);
1274 symbol.idCode = symbol.id = globalContext.nextID++;
1275 decl.symbol = symbol;
1277 excludedSymbols->Add(symbol);
1279 FreeList(symbolSpecs, FreeSpecifier);
1283 OldList * MkSpecsClass(Specifier _class)
1285 OldList * list = MkList();
1286 ListAdd(list, _class);
1290 MemberInit MkMemberInit(OldList ids, Initializer initializer)
1292 return { identifiers = ids, initializer = initializer };
1295 MemberInit MkMemberInitExp(Expression idExp, Initializer initializer)
1297 MemberInit init { initializer = initializer, identifiers = MkList() };
1300 for(exp = idExp; exp && exp.type == memberExp; exp = exp.member.exp)
1302 init.identifiers->Insert(null, exp.member.member);
1303 exp.member.member = null;
1305 if(exp && exp.type == identifierExp)
1307 init.identifiers->Insert(null, exp.identifier);
1308 exp.identifier = null;
1310 FreeExpression(idExp);
1314 MembersInit MkMembersInitList(OldList dataMembers)
1316 return { type = dataMembersInit, dataMembers = dataMembers };
1319 MembersInit MkMembersInitMethod(ClassFunction function)
1321 return { type = methodMembersInit, function = function };
1324 Instantiation MkInstantiation(Specifier _class, Expression exp, OldList members)
1326 return { _class = _class, exp = exp, members = members };
1329 Instantiation MkInstantiationNamed(OldList specs, Expression exp, OldList members)
1331 Instantiation inst { exp = exp, members = members };
1336 for(spec = specs.first; spec; spec = spec.next)
1337 if(spec.type == nameSpecifier /*classSpecifier*/)
1344 FreeList(specs, FreeSpecifier);
1348 Compiler_Error("Expecting class specifier\n");
1349 inst._class = MkSpecifierName /*MkClassName*/("");
1357 ClassDef MkClassDefAccessOverride(AccessMode access, Identifier id)
1359 return { type = accessOverrideClassDef, id = id, memberAccess = access };
1362 ClassDef MkClassDefMemberAccess()
1364 return { type = memberAccessClassDef };
1367 ClassDef MkClassDefDeclaration(Declaration decl)
1369 return { type = declarationClassDef, decl = decl };
1372 ClassDef MkClassDefClassData(Declaration decl)
1374 return { type = classDataClassDef, decl = decl };
1377 ClassDef MkClassDefDesigner(char * designer)
1379 return { type = classDesignerClassDef, designer = CopyString(designer) };
1382 ClassDef MkClassDefNoExpansion()
1384 return { type = classNoExpansionClassDef };
1387 ClassDef MkClassDefFixed()
1389 return { type = classFixedClassDef };
1392 ClassDef MkClassDefDesignerDefaultProperty(Identifier id)
1394 return { type = designerDefaultPropertyClassDef, defaultProperty = id };
1397 ClassDef MkClassDefDefaultProperty(OldList defProperties)
1399 return { type = defaultPropertiesClassDef, defProperties = defProperties };
1402 ClassDef MkClassDefFunction(ClassFunction function)
1405 if(function && function.declarator)
1407 Declarator funcDecl = GetFuncDecl(function.declarator);
1408 if(funcDecl && funcDecl.declarator && funcDecl.declarator.type == bracketsDeclarator)
1410 def.type = declarationClassDef;
1411 def.decl = MkStructDeclaration(function.specifiers, MkListOne(MkStructDeclarator(function.declarator, null)), null);
1412 function.declarator = null;
1413 function.specifiers = null;
1414 FreeClassFunction(function);
1418 def.type = functionClassDef;
1419 def.function = function;
1423 Symbol DeclClassAddNameSpace(int symbolID, char * className)
1426 int len = 0, stringLen;
1428 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1430 if(defaultNameSpace)
1432 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1433 len += defaultNameSpaceLen;
1437 if(currentNameSpace)
1439 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1440 len += currentNameSpaceLen;
1445 stringLen = strlen(className);
1446 memcpy(name + len, className, stringLen);
1449 return _DeclClass(symbolID, name);
1452 Symbol DeclClass(int symbolID, char * name)
1454 if(strchr(name, ':'))
1455 return _DeclClass(symbolID, name);
1457 return DeclClassAddNameSpace(symbolID, name);
1460 Symbol _DeclClass(int symbolID, char * name)
1462 Symbol symbol = FindClass(name);
1466 Context classContext;
1467 for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
1473 if(name[0] == ':' && name[1] == ':')
1477 string = CopyString(name);
1478 idCode = symbolID, id = symbolID;
1480 globalContext.classes.Add((BTNode)symbol);
1485 for(c = 0; (ch = name[c]); c++)
1487 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
1493 if(start && c - start)
1494 symbol.shortName = CopyString(name + start);
1498 symbol.idCode = symbol.id = symbolID;
1502 void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
1504 if(baseSpecs && baseSpecs.first && ((Specifier)baseSpecs.first).type == nameSpecifier)
1509 strcpy(name, ((Specifier)baseSpecs.first).name);
1510 tpl = strchr(name, '<');
1513 baseClass = FindClass(name);
1517 for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
1519 TemplatedType type { key = copy.key, param = copy.param };
1520 curContext.templateTypes.Add((BTNode)type);
1523 else if(baseClass.registered)
1526 for(sClass = baseClass.registered; sClass; sClass = sClass.base)
1528 ClassTemplateParameter p;
1529 for(p = sClass.templateParams.first; p; p = p.next)
1531 //OldList * specs = MkList();
1532 //Declarator decl = null;
1533 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
1536 TemplateParameter param = p.param;
1540 p.param = param = TemplateParameter
1542 identifier = MkIdentifier(p.name), type = p.type,
1543 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
1546 type = TemplatedType { key = (uint)p.name, param = param };
1547 curContext.templateTypes.Add((BTNode)type);
1555 ClassDefinition MkClass(Symbol symbol, OldList baseSpecs, OldList definitions)
1557 ClassDefinition classDef;
1558 SetupBaseSpecs(symbol, baseSpecs);
1559 symbol.ctx = curContext;
1560 classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
1561 curContext.classDef = classDef;
1565 Expression MkExpInstance(Instantiation inst)
1567 return { type = instanceExp, instance = inst };
1570 External MkExternalClass(ClassDefinition _class)
1572 return { type = classExternal, _class = _class, symbol = _class.symbol };
1575 PropertyDef MkProperty(OldList specs, Declarator decl, Identifier id, Statement setStmt, Statement getStmt)
1585 Type type = ProcessType(specs, decl);
1588 char typeString[1024];
1589 typeString[0] = '\0';
1590 PrintType(type, typeString, false, true);
1591 id = MkIdentifier(typeString);
1592 prop.conversion = true;
1598 string = CopyString(id.string);
1601 symbol.idCode = symbol.id = globalContext.nextID++;
1602 excludedSymbols->Add(symbol);
1603 globalContext.nextID++;
1604 globalContext.nextID++;
1605 prop.symbol = symbol;
1609 ClassDef MkClassDefProperty(PropertyDef propertyDef)
1611 return { type = propertyClassDef, propertyDef = propertyDef };
1614 ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
1616 return { type = classPropertyClassDef, propertyDef = propertyDef };
1619 ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
1621 return { type = classPropertyValueClassDef, id = id, initializer = initializer };
1624 int CheckType(char * text)
1627 Time startTime = GetTime();
1629 if(FindTemplateTypeParameter(curContext, text))
1632 checkTypeTotalTime += GetTime() - startTime;
1636 if(FindType(curContext, text))
1639 checkTypeTotalTime += GetTime() - startTime;
1646 checkTypeTotalTime += GetTime() - startTime;
1648 return TYPE_NAME; //CLASS_NAME;
1651 checkTypeTotalTime += GetTime() - startTime;
1658 return CheckType(yytext);
1661 Context PushContext()
1663 Context ctx { parent = curContext };
1668 void PopContext(Context ctx)
1670 curContext = ctx.parent;
1673 Symbol FindType(Context ctx, char * name)
1678 type = (Symbol)ctx.types.FindString(name);
1679 if(!type && ctx.parent)
1680 type = FindType(ctx.parent, name);
1685 TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
1687 TemplatedType templatedType = null;
1690 templatedType = (TemplatedType)ctx.templateTypes.FindString(name);
1691 if(!templatedType && ctx.parent)
1692 templatedType = FindTemplateTypeParameter(ctx.parent, name);
1694 return templatedType;
1697 bool ModuleAccess(Module searchIn, Module searchFor)
1699 SubModule subModule;
1701 if(searchFor == searchIn)
1704 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
1706 if(subModule.importMode == publicAccess /*|| searchIn == searchIn.application*/)
1708 if(ModuleAccess(subModule.module, searchFor))
1715 ModuleImport FindModule(Module moduleToFind)
1717 ModuleImport module;
1718 if(!moduleToFind.name)
1720 for(module = imports->first; module; module = module.next)
1721 if(module.name && !strcmp(module.name, moduleToFind.name))
1725 module = ModuleImport
1727 name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
1728 importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
1730 imports->Add(module);
1736 // TO REMOVE: OBSOLETE...
1737 static void GetFullClassNameSpace(NameSpace * ns, char * name)
1741 GetFullClassNameSpace(ns->parent, name);
1742 strcat(name, ns->name);
1747 static char * GetFullClassName(Class c, char * name)
1749 NameSpace * nameSpace;
1751 GetFullClassNameSpace(c.nameSpace, name);
1752 strcat(name, c.name);
1757 public Symbol FindClass(char * name)
1760 Time startTime = GetTime();
1764 bool global = false;
1765 char fullName[1024];
1767 if(name[0] == ':' && name[1] == ':')
1773 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1775 int len = 0, stringLen;
1776 if(defaultNameSpace)
1778 memcpy(fullName, defaultNameSpace, defaultNameSpaceLen);
1779 len += defaultNameSpaceLen;
1780 fullName[len++] = ':';
1781 fullName[len++] = ':';
1783 if(currentNameSpace)
1785 memcpy(fullName + len, currentNameSpace, currentNameSpaceLen);
1786 len += currentNameSpaceLen;
1787 fullName[len++] = ':';
1788 fullName[len++] = ':';
1790 stringLen = strlen(name);
1791 memcpy(fullName + len, name, stringLen);
1794 cl = globalContext ? (Symbol)globalContext.classes.FindString(fullName) : null;
1798 cl = globalContext ? (Symbol)globalContext.classes.FindString(name) : null;
1803 Time startTime = GetTime();
1805 // Ignore name space name when searching
1806 for(cl = globalContext ? (Symbol)globalContext.classes.first : null; cl; cl = (Symbol)((BTNode)cl).next)
1810 char * string = cl.string;
1812 for(c = 0; (ch = string[c]); c++)
1814 if(ch == '.' || (ch == ':' && string[c+1] == ':'))
1820 if(start && c - start)
1822 if(!strcmp(string + start, name))
1826 if(cl.shortName && !strcmp(cl.shortName, name))
1830 findClassIgnoreNSTotalTime += GetTime() - startTime;
1836 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1837 _class = eSystem_FindClass(privateModule, fullName);
1839 _class = eSystem_FindClass(privateModule, name);
1843 name = _class.fullName;
1845 cl = (Symbol)globalContext.classes.FindString(name);
1850 string = CopyString(name);
1851 registered = _class;
1858 cl.module = FindModule(_class.module);
1860 cl.module = mainModule;
1861 globalContext.classes.Add((BTNode)cl);
1862 if(strcmp(name, _class.name))
1863 cl.shortName = CopyString(_class.name);
1868 findClassTotalTime += GetTime() - startTime;
1873 void CopyTypeInto(Type type, Type src)
1876 type.name = CopyString(src.name);
1877 type.enumName = CopyString(src.enumName);
1880 if(src.kind == enumType)
1884 type.members.Clear();
1885 for(member = type.members.first; member; member = member.next)
1887 type.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
1890 else if(src.kind == structType || src.kind == unionType)
1893 // Tricky stuff... will be removed from list only when ref count reaches 0
1894 for(member = type.members.first; member; member = member.next)
1897 else if(src.kind == functionType)
1900 type.returnType.refCount++;
1901 for(param = type.params.first; param; param = param.next)
1904 else if(src.kind == pointerType || src.kind == arrayType)
1906 type.type.refCount++;
1907 if(src.kind == arrayType)
1909 if(type.arraySizeExp)
1910 type.arraySizeExp = CopyExpression(type.arraySizeExp);
1916 public Type ProcessType(OldList specs, Declarator decl)
1919 bool isTypedef = false;
1920 if(!specs || specs.first)
1922 Declarator funcDecl = GetFuncDecl(decl);
1924 bool dllExport = false;
1926 specType.kind = intType;
1927 specType.isSigned = true;
1928 specType.refCount = 1;
1930 type = Type { refCount = 1 };
1932 while(decl && (decl.type == structDeclarator || decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd))
1934 if(decl.type == structDeclarator && decl.structDecl.exp)
1936 ProcessExpressionType(decl.structDecl.exp);
1937 ComputeExpression(decl.structDecl.exp);
1938 if(decl.structDecl.exp.type == constantExp)
1939 specType.bitFieldCount = strtoul(decl.structDecl.exp.constant, null, 0);
1941 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended &&
1942 (!strcmp(decl.extended.extended, "__declspec(dllexport)") || !strcmp(decl.extended.extended, "dllexport")))
1946 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended &&
1947 (strstr(decl.extended.extended, "__attribute__")))
1949 specType.keepCast = true;
1951 decl = decl.declarator;
1954 // If we'll be using the specType
1955 if(funcDecl || !decl || decl.type == identifierDeclarator)
1960 bool isLong = false;
1961 for(spec = specs.first; spec; spec = spec.next)
1963 if(spec.type == extendedSpecifier && (!strcmp(spec.name, "__declspec(dllexport)") || !strcmp(spec.name, "dllexport")))
1967 if(spec.type == extendedSpecifier && strstr(spec.name, "__attribute__"))
1969 specType.keepCast = true;
1972 if(specType.kind == structType || specType.kind == unionType)
1975 specType = { kind = intType, isSigned = true, refCount = 1 };
1978 if(spec.type == baseSpecifier)
1980 if(spec.specifier == TYPEDEF) isTypedef = true;
1981 else if(spec.specifier == VOID) specType.kind = voidType;
1982 else if(spec.specifier == CHAR) specType.kind = charType;
1983 else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
1984 else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
1985 else if(spec.specifier == INT64) specType.kind = int64Type;
1986 else if(spec.specifier == VALIST)
1987 specType.kind = vaListType;
1988 else if(spec.specifier == SHORT) specType.kind = shortType;
1989 else if(spec.specifier == LONG)
1992 specType.kind = int64Type;
1994 specType.kind = intType;
1996 // specType.kind = longType;
1998 else if(spec.specifier == FLOAT) specType.kind = floatType;
1999 else if(spec.specifier == DOUBLE) specType.kind = doubleType;
2000 else if(spec.specifier == SIGNED) specType.isSigned = true;
2001 else if(spec.specifier == UNSIGNED) specType.isSigned = false;
2002 else if(spec.specifier == CONST) specType.constant = true;
2003 else if(spec.specifier == TYPED_OBJECT)
2005 specType.classObjectType = typedObject; specType.kind = classType; specType._class = FindClass("class");
2007 else if(spec.specifier == ANY_OBJECT)
2009 specType.classObjectType = anyObject; specType.kind = classType; specType._class = FindClass("class");
2011 else if(spec.specifier == CLASS)
2013 specType.classObjectType = classPointer; specType.kind = classType; specType._class = FindClass("class");
2015 else if(spec.specifier == THISCLASS)
2016 specType.kind = thisClassType;
2018 else if(spec.type == nameSpecifier)
2020 Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
2021 if(symbol && symbol.type)
2023 CopyTypeInto(specType, symbol.type);
2024 specType.typeName = CopyString(symbol.type.name);
2026 else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
2028 // key.sym enum values need FindClass:
2029 specType._class = spec.name ? FindClass(spec.name) : null;
2030 // specType._class = spec.symbol;
2031 specType.kind = classType;
2032 if(!specType._class)
2033 specType.kind = intType;
2036 else if(spec.type == enumSpecifier)
2039 specType.kind = enumType;
2040 specType.enumName = spec.id ? CopyString(spec.id.string) : null;
2046 for(e = spec.list->first; e; e = e.next)
2048 specType.members.Add(NamedItem { name = CopyString(e.id.string) });
2050 if(e.exp && ComputeExpression(e.exp), e.exp.isConstant && e.exp.expType.kind == intType)
2051 value.data = (void *) nextValue = strtol(e.exp.string, null, 0);
2053 value.data = (void *)nextValue++;
2061 for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
2062 if(decl.declarators)
2065 for(d = decl.declarators.first; d; d = d.next)
2067 Type memberType = ProcessType(decl.specifiers, d);
2068 specType.members.Add(memberType);
2071 else if(decl.specifiers)
2073 Type memberType = ProcessType(decl.specifiers, null);
2074 specType.members.Add(memberType);
2079 else if(spec.type == templateTypeSpecifier)
2082 printf("spec %x\n", spec);
2083 printf("template param %x\n", spec.templateParameter);
2084 printf("identifier %x\n", spec.templateParameter.identifier);
2085 printf("string %x\n", spec.templateParameter.identifier.string);
2087 specType.kind = templateType;
2088 specType.templateParameter = spec.templateParameter;
2090 else if(spec.type == structSpecifier || spec.type == unionSpecifier)
2092 Symbol _class = spec.id ? FindClass(spec.id.string) : null;
2095 if(!_class.registered || _class.registered.type != structClass)
2096 specType.directClassAccess = true;
2097 specType._class = _class;
2098 specType.kind = classType;
2101 if(spec.type == structSpecifier)
2102 specType.kind = structType;
2103 else if(spec.type == unionSpecifier)
2104 specType.kind = unionType;
2107 // TESTING THIS HERE... Had 0 type size
2108 if(!spec.definitions && !isTypedef)
2110 Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
2111 if(symbol && symbol.type)
2113 specType = *symbol.type;
2114 specType.name = CopyString(symbol.type.name);
2115 specType.typeName = CopyString(spec.name);
2116 specType.enumName = CopyString(symbol.type.enumName);
2117 specType.refCount = 1;
2119 if(symbol.type.kind == enumType)
2123 specType.members.Clear();
2124 for(member = specType.members.first; member; member = member.next)
2126 specType.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
2129 else if(symbol.type.kind == structType || symbol.type.kind == unionType)
2132 // Tricky stuff... will be removed from list only when ref count reaches 0
2133 for(member = specType.members.first; member; member = member.next)
2136 else if(symbol.type.kind == functionType)
2139 specType.returnType.refCount++;
2140 for(param = specType.params.first; param; param = param.next)
2143 else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
2145 specType.type.refCount++;
2146 if(symbol.type.kind == arrayType)
2148 if(specType.arraySizeExp)
2149 specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
2155 specType.enumName = CopyString(spec.id.string);
2158 specType.enumName = CopyString(spec.id.string);
2161 if(spec.definitions)
2164 for(def = spec.definitions->first; def; def = def.next)
2166 if(def.type == declarationClassDef && def.decl.type == structDeclaration)
2168 Declaration decl = def.decl;
2169 if(decl.declarators)
2172 for(d = decl.declarators->first; d; d = d.next)
2174 Type memberType = ProcessType(decl.specifiers, d);
2175 specType.members.Add(memberType);
2178 else if(decl.specifiers)
2180 Type memberType = ProcessType(decl.specifiers, null);
2181 specType.members.Add(memberType);
2188 else if(spec.type == subClassSpecifier)
2190 specType.kind = specType.kind = subClassType;
2191 specType._class = spec._class.symbol; // FindClass(spec._class.name);
2194 else if(spec.type == classSpecifier)
2196 specType._class = FindClass(spec.name);
2197 specType.kind = classType;
2203 specType.kind = ellipsisType;
2208 Declarator d = funcDecl.declarator;
2212 funcType.kind = functionType;
2213 funcType.refCount = 1;
2214 if(funcDecl.function.parameters)
2216 for(param = funcDecl.function.parameters->first; param; param = param.next)
2219 if(param.typedObject)
2221 Type typedObjectType
2224 byReference = param.byReference;
2225 kind = TypeTypedObject;
2227 funcType.params.Add(typedObjectType);
2230 funcType.params.Add(ProcessType(param.qualifiers, param.declarator));
2234 // Function returning a pointer...
2235 if(decl.type == pointerDeclarator)
2237 Pointer pointer = decl.pointer.pointer;
2239 funcType.returnType = ptrType;
2240 funcType.returnType.refCount = 1;
2243 ptrType.kind = pointerType;
2244 pointer = pointer.pointer;
2247 ptrType.type = Type { refCount = 1 };
2248 ptrType = ptrType.type;
2251 ptrType.type = Type { refCount = 1 };
2252 *ptrType.type = specType;
2256 funcType.returnType = Type { refCount = 1 };
2257 *funcType.returnType = specType;
2260 // TESTING: Added extendedDeclarator here
2261 while(d && (d.type == bracketsDeclarator || d.type == extendedDeclarator || d.type == extendedDeclaratorEnd))
2263 if((d.type == extendedDeclarator || d.type == extendedDeclaratorEnd) && d.extended.extended &&
2264 (!strcmp(d.extended.extended, "__declspec(dllexport)") || !strcmp(d.extended.extended, "dllexport")))
2271 funcType.dllExport = dllExport;
2273 if(d && d.type == pointerDeclarator)
2278 if(d.declarator && d.declarator.type == arrayDeclarator)
2280 // Arrays of pointers to functions (extremely tricky :()
2281 Pointer pointer = d.pointer.pointer;
2283 // TO WORK ON: Fixed the order for the array...
2284 type.kind = arrayType;
2285 type.arraySizeExp = CopyExpression(d.declarator.array.exp);
2286 type.freeExp = true;
2287 if(d.declarator.array.enumClass)
2288 type.enumClass = d.declarator.array.enumClass.symbol; // FindClass(d.declarator.array.enumClass.name);
2289 if(d.declarator.declarator && d.declarator.declarator.type == arrayDeclarator)
2291 Type tmpType = type;
2293 type = ProcessType(null, d.declarator.declarator);
2295 type.type = tmpType;
2296 tmpType.type = inType;
2299 type.type = ProcessType(null, d.declarator.declarator);
2301 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2305 ptrType.kind = pointerType;
2306 pointer = pointer.pointer;
2309 ptrType.type = Type { refCount = 1 };
2310 ptrType = ptrType.type;
2313 ptrType.type = ProcessType(specs, null);
2317 // WARNING: Not caring if this declarator contains a declarator between
2318 // the pointer and the function other than brackets (like in the case of array of pointers to functions)...
2319 // *********** Could it ever go in here??? Yes: void (* converters_table[10]) (); ***********
2320 Pointer pointer = d.pointer.pointer;
2325 ptrType.kind = pointerType;
2326 ptrType.type = Type { refCount = 1 };
2327 pointer = pointer.pointer;
2329 ptrType = ptrType.type;
2333 *ptrType.type = funcType;
2337 if(id._class && !id._class.name)
2338 ptrType.type.staticMethod = true;
2341 // TODO : Ensure classSym has been resolved here... (Is this gonna cause problems? Supposed to do this later...)
2344 if(id._class && id._class.name)
2346 id.classSym = id._class.symbol; // FindClass(id._class.name);
2347 /* TODO: Name Space Fix ups
2349 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
2354 ptrType.type.thisClass = id.classSym;
2355 if(ptrType.type.thisClass && strcmp(ptrType.type.thisClass.string, "class"))
2356 ptrType.type.extraParam = true;
2357 else if(id._class && id._class.name && !strcmp(id._class.name, "any_object"))
2359 ptrType.type.extraParam = true;
2360 ptrType.type.thisClass = FindClass("class");
2364 type.name = CopyString(id.string);
2367 else if(!d || d.type == identifierDeclarator)
2373 if(d.identifier._class && d.identifier._class.type == templateTypeSpecifier)
2375 type.thisClassTemplate = d.identifier._class.templateParameter;
2376 type.extraParam = true;
2380 if(d.identifier._class && !d.identifier._class.name)
2381 type.staticMethod = true;
2384 if(d.identifier._class && d.identifier._class.name && d.identifier._class.name[strlen(d.identifier._class.name)-1] == '&')
2386 type.thisClass = FindClass("class");
2387 type.byReference = true;
2390 type.thisClass = d.identifier._class ? d.identifier._class.symbol /*FindClass(d.identifier._class.name)*/ : null;
2391 if(type.thisClass && strcmp(type.thisClass.string, "class"))
2393 type.extraParam = true;
2395 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "any_object"))
2397 type.extraParam = true;
2398 type.thisClass = FindClass("class");
2400 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "class"))
2402 //type.extraParam = true;
2403 type.thisClass = FindClass("class");
2404 type.classObjectType = classPointer;
2408 type.name = CopyString(d.identifier.string);
2413 else if(decl && decl.type == pointerDeclarator)
2415 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2417 // Arrays of pointers (tricky :))
2419 Pointer pointer = decl.pointer.pointer;
2422 // TO WORK ON: Fixed the order for the array...
2423 type.kind = arrayType;
2424 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2425 type.freeExp = true;
2426 if(decl.declarator.array.enumClass)
2427 type.enumClass = decl.declarator.array.enumClass.symbol; // FindClass(decl.declarator.array.enumClass.name);
2428 if(decl.declarator.declarator && decl.declarator.declarator.type == arrayDeclarator)
2430 Type tmpType = type;
2432 type = ProcessType(null, decl.declarator.declarator);
2434 type.type = tmpType;
2435 tmpType.type = inType;
2438 type.type = ProcessType(null, decl.declarator.declarator);
2440 type.type = ProcessType(null, decl.declarator.declarator);
2441 type.kind = arrayType;
2442 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2443 type.arraySizeExp.freeExp = true;
2444 if(decl.array.enumClass)
2445 type.enumClass = FindClass(decl.array.enumClass.name);
2448 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2452 ptrType.kind = pointerType;
2453 pointer = pointer.pointer;
2456 ptrType.type = Type { refCount = 1 };
2457 ptrType = ptrType.type;
2460 ptrType.type = ProcessType(specs, null);
2461 id = GetDeclId(decl);
2462 if(id) type.name = CopyString(id.string);
2467 Pointer pointer = decl.pointer.pointer;
2468 Type ptrType = type;
2470 if(type.classObjectType)
2472 type.byReference = true;
2478 ptrType.kind = pointerType;
2479 pointer = pointer.pointer;
2482 ptrType.type = Type { refCount = 1 };
2483 ptrType = ptrType.type;
2486 ptrType.type = ProcessType(specs, decl.declarator);
2488 if(type.type.classObjectType)
2490 Type subType = type.type;
2491 type.classObjectType = subType.classObjectType;
2492 type.kind = subType.kind;
2493 type._class = subType._class;
2494 type.byReference = true;
2498 id = GetDeclId(decl);
2499 if(id) type.name = CopyString(id.string);
2503 else if(decl && decl.type == arrayDeclarator)
2507 type.kind = arrayType;
2509 type.arraySizeExp = CopyExpression(decl.array.exp);
2510 type.freeExp = true;
2511 if(decl.array.enumClass)
2512 type.enumClass = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
2513 id = GetDeclId(decl);
2515 // TO WORK ON: Fixed the order for the array...
2516 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2518 Type tmpType = type;
2520 type = ProcessType(specs, decl.declarator);
2522 type.type = tmpType;
2523 tmpType.type = inType;
2526 type.type = ProcessType(specs, decl.declarator);
2531 type.name = CopyString(id.string);
2536 if(!decl || decl.type == identifierDeclarator)
2540 type.name = decl ? CopyString(decl.identifier.string) : null;
2548 public Type ProcessTypeString(char * string, bool staticMethod)
2550 OldList * specs = MkList();
2551 Declarator decl = SpecDeclFromString(string, specs, null);
2552 Type type = ProcessType(specs, decl);
2553 if(type && !type.thisClass && staticMethod) type.staticMethod = true;
2554 FreeList(specs, FreeSpecifier);
2555 if(decl) FreeDeclarator(decl);
2559 Type MkClassTypeSymbol(Symbol symbol)
2563 Type type { kind = classType, _class = symbol };
2566 // Defaults to an int instead...
2567 type.kind = intType;
2575 public Type MkClassType(char * name)
2579 Type type { kind = classType, _class = FindClass(name) };
2582 // Defaults to an int instead...
2583 type.kind = intType;
2591 AsmField MkAsmField(char * command, Expression expression)
2593 return { command = command, expression = expression };
2596 Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
2598 return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
2599 asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
2600 asmStmt.clobberedFields = clobberedFields };
2603 ClassDef MkClassDefPropertyWatch(PropertyWatch watcher)
2605 return { type = propertyWatchClassDef, propertyWatch = watcher };
2608 Statement MkFireWatchersStmt(Expression object, OldList watches)
2610 return { type = fireWatchersStmt, _watch.object = object, _watch.watches = watches };
2613 Statement MkStopWatchingStmt(Expression watcher, Expression object, OldList watches)
2615 return { type = stopWatchingStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2618 Statement MkWatchStmt(Expression watcher, Expression object, OldList watches)
2620 return { type = watchStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2623 PropertyWatch MkDeleteWatch(Statement compound)
2625 return { compound = compound, deleteWatch = true };
2628 PropertyWatch MkPropertyWatch(OldList properties, Statement compound)
2630 return { compound = compound, properties = properties };
2633 Expression MkExpClass(OldList * specifiers, Declarator decl)
2635 return { type = classExp, _classExp.specifiers = specifiers, _classExp.decl = decl };
2638 Expression MkExpClassData(Identifier id)
2640 return { type = classDataExp, classData.id = id };
2644 External MkExternalDBTable(DBTableDef table)
2646 return { type = dbtableExternal, table = table };
2649 DBTableDef MkDBTableDef(char * name, Symbol symbol, OldList * definitions)
2651 return { name = name, symbol = symbol, definitions = definitions };
2654 DBTableEntry MkDBFieldEntry(TypeName type, Identifier id, char * name)
2656 return { type = fieldEntry, dataType = type, id = id, name = name };
2659 DBIndexItem MkDBIndexItem(Identifier id, Order order)
2661 return { id = id, order = order };
2664 DBTableEntry MkDBIndexEntry(OldList * items, Identifier id)
2666 return { type = indexEntry, items = items, id = id };
2669 Expression MkExpDBOpen(Expression ds, Expression dbName)
2671 return { type = dbopenExp, dbopen.ds = ds, dbopen.name = dbName };
2674 Expression MkExpDBField(char * table, Identifier id)
2676 return { type = dbfieldExp, db.table = table, db.id = id };
2679 Expression MkExpDBIndex(char * table, Identifier id)
2681 return { type = dbindexExp, db.table = table, db.id = id };
2684 Expression MkExpDBTable(char * table)
2686 return { type = dbtableExp, db.table = table };
2689 Expression MkExpArray(OldList * expressions)
2691 return { type = arrayExp, list = expressions };
2694 Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplateParameterType tplType)
2696 Expression argExp = null;
2697 Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
2701 ClassTemplateParameter curParam;
2703 for(sClass = _class; sClass; sClass = sClass.base)
2706 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2708 if(!strcmp(curParam.name, paramName))
2710 for(sClass = sClass.base; sClass; sClass = sClass.base)
2711 id += sClass.templateParams.count;
2719 if(curParam && curParam.type != tplType)
2725 char className[1024];
2726 Expression classExp;
2728 sprintf(idString, "%d", id);
2729 strcpy(className, "__ecereClass_");
2730 FullClassNameCat(className, _class.fullName, true);
2731 MangleClassName(className);
2732 DeclareClass(FindClass(_class.fullName), className);
2734 argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
2735 (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
2736 MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
2742 Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
2744 return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
2747 /*char * CreateMsgID(char * string, char * context)
2749 int lenString = strlen(string), lenContext = strlen(context);
2750 char * msgid = new char[lenString + lenContext + 20];
2751 memcpy(msgid, string, lenString);
2752 memcpy(msgid+lenString, " [msgctxt: ", 11);
2753 memcpy(msgid+lenString+11, context, lenContext);
2754 memcpy(msgid+lenString+11+lenContext, "]", 2);
2758 public void OutputIntlStrings()
2760 if(intlStrings.count)
2762 char * srcFile = GetSourceFile();
2763 char * objFile = GetOutputFile();
2764 char potFile[MAX_LOCATION];
2766 ChangeExtension(objFile, "bowl", potFile);
2767 f = FileOpen(potFile, write);
2770 char * filePrefix = "";
2771 if(!(srcFile[0] && (srcFile[1] == ':' || srcFile[0] == '/')))
2772 filePrefix = (GetRuntimePlatform() == win32) ? ".\\" : "./";
2773 for(s : intlStrings)
2775 // TOFIX: (#654) ContextStringPair * pair = &s;
2776 ContextStringPair pair = &s;
2778 f.Printf("#: %s%s:%d\n", filePrefix, srcFile, l.start.line);
2779 /* PoEdit does not support msgctxt yet so we'll bundle them in the msgid for now
2781 f.Printf("msgctxt %s\n", pair.context);
2782 f.Printf("msgid %s\n", pair.string);
2786 int lenString = strlen(pair.string), lenContext = strlen(pair.context);
2787 char * msgid = new char[lenString-2 + lenContext-2 + 4];
2789 memcpy(msgid+1, pair.string+1, lenString-2);
2790 msgid[1+lenString-2] = 4; // EOT
2791 memcpy(msgid+1+lenString-2+1, pair.context+1, lenContext-2);
2792 memcpy(msgid+1+lenString-2+1+lenContext-2, "\"", 2);
2794 f.Printf("msgid %s\n", msgid);
2798 f.Printf("msgid %s\n", pair.string);
2799 f.Printf("msgstr %s\n\n", pair.string);
2807 default extern OldList * ast;
2808 default extern int yyparse ();
2810 public void SetAST(OldList * list) { ast = list; }
2811 public OldList * GetAST() { return ast; }
2812 public void ParseEc()