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 public struct ContextStringPair { String string, context; };
230 Map<ContextStringPair, List<Location> > intlStrings { };
232 Expression MkExpIntlString(char * string, char * context)
234 OldList * list = MkList();
237 ContextStringPair pair { };
239 int len = strlen(string);
241 pair.string = new byte[len-2+1]; memcpy(pair.string, string+1, len-2); pair.string[len-2] = '\0';
242 if(context) { len = strlen(context); pair.context = new byte[len-2+1]; memcpy(pair.context, context+1, len-2); pair.context[len-2] = '\0'; }
244 list = intlStrings[pair];
248 intlStrings[pair] = list;
257 ListAdd(list, QMkExpId("__thisModule"));
258 ListAdd(list, MkExpString(string));
261 int lenString = strlen(string), lenContext = strlen(context);
262 char * msgid = new char[lenString-2 + lenContext-2 + 4];
264 memcpy(msgid+1, context+1, lenContext-2);
265 msgid[1+lenContext-2] = 4; // EOT
266 memcpy(msgid+1+lenContext-2+1, string+1, lenString-2);
267 memcpy(msgid+1+lenContext-2+1+lenString-2, "\"", 2);
268 ListAdd(list, MkExpString(msgid));
271 ListAdd(list, QMkExpId("null"));
272 return MkExpCall(QMkExpId("GetTranslatedString"), list);
275 Expression MkExpOp(Expression exp1, int op, Expression exp2)
286 exp.loc.start = exp1 ? exp1.loc.start : exp2.loc.start;
287 exp.loc.end = exp2 ? exp2.loc.end : exp1.loc.end;
292 Expression MkExpBrackets(OldList expressions)
299 if(expressions && expressions.first)
301 exp.loc.start = ((Expression)expressions.first).loc.start;
302 exp.loc.end = ((Expression)expressions.last).loc.end;
307 Expression MkExpIndex(Expression expression, OldList index)
309 return { type = indexExp, index.exp = expression, index.index = index };
312 Expression MkExpCall(Expression expression, OldList arguments)
314 return { type = callExp, call.exp = expression, call.arguments = arguments };
317 Expression MkExpMember(Expression expression, Identifier member)
319 return { type = memberExp, member.exp = expression, member.member = member };
322 Expression MkExpPointer(Expression expression, Identifier member)
324 return { type = pointerExp, member.exp = expression, member.member = member };
327 Expression MkExpTypeSize(TypeName typeName)
329 return { type = typeSizeExp, typeName = typeName };
332 Expression MkExpClassSize(Specifier _class)
334 return { type = classSizeExp, _class = _class };
337 Expression MkExpCast(TypeName typeName, Expression expression)
339 return { type = castExp, cast.typeName = typeName, cast.exp = expression };
342 Expression MkExpCondition(Expression cond, OldList expressions, Expression elseExp)
344 return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp };
347 Expression MkExpRenew(Expression memExp, TypeName type, Expression size)
349 return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
352 Expression MkExpRenew0(Expression memExp, TypeName type, Expression size)
354 return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
357 Expression MkExpNew(TypeName type, Expression size)
359 return { type = newExp, _new.typeName = type, _new.size = size };
362 Expression MkExpNew0(TypeName type, Expression size)
364 return { type = new0Exp, _new.typeName = type, _new.size = size };
367 Expression MkExpVaArg(Expression exp, TypeName type)
369 return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type };
372 Specifier MkSpecifier(int specifier)
374 return { type = baseSpecifier, specifier = specifier };
377 Specifier MkSpecifierTypeOf(Expression expression)
379 return { type = typeOfSpecifier, expression = expression };
382 Specifier MkSpecifierSubClass(Specifier _class)
384 return { type = subClassSpecifier, _class = _class };
387 Specifier MkSpecifierExtended(char * name)
389 return { type = extendedSpecifier, name = CopyString(name) };
392 Specifier MkEnum(Identifier id, OldList list)
396 type = enumSpecifier;
400 if(list && (!declMode || !id))
406 type = ProcessType(&specs, null);
410 curContext.structSymbols.Add((BTNode)Symbol { string = CopyString(id.string), isStruct = true, type = type });
413 for(e = list.first; e; e = e.next)
415 (curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)Symbol { string = CopyString(e.id.string), type = type });
423 Specifier MkStructOrUnion(SpecifierType type, Identifier id, OldList definitions)
425 Specifier spec { type = type, id = id };
426 if(id && FindType(curContext, id.string))
427 declMode = defaultAccess;
428 spec.definitions = definitions;
429 if(definitions && id && !declMode)
433 curContext.structSymbols.Add((BTNode)Symbol { string = CopyString(id.string), type = ProcessType(specs, null), isStruct = true });
438 void AddStructDefinitions(Specifier spec, OldList definitions)
440 spec.definitions = definitions;
441 if(definitions && spec.id && !declMode)
445 curContext.parent.structSymbols.Add((BTNode)Symbol { string = CopyString(spec.id.string), type = ProcessType(specs, null), isStruct = true });
449 public Declarator MkDeclaratorIdentifier(Identifier id)
451 return { type = identifierDeclarator, identifier = id };
454 Declarator MkDeclaratorFunction(Declarator declarator, OldList parameters)
456 return { type = functionDeclarator, declarator = declarator, function.parameters = parameters };
459 Declarator MkDeclaratorExtended(char * extended, Declarator declarator)
461 return { type = extendedDeclarator, declarator = declarator, extended.extended = extended };
464 Declarator MkDeclaratorExtendedEnd(char * extended, Declarator declarator)
466 return { type = extendedDeclaratorEnd, declarator = declarator, extended.extended = extended };
469 Declarator MkStructDeclarator(Declarator declarator, Expression exp)
471 return { type = structDeclarator, declarator = declarator, structDecl.exp = exp };
474 Declarator MkDeclaratorBrackets(Declarator declarator)
476 return { type = bracketsDeclarator, declarator = declarator };
479 Declarator MkDeclaratorArray(Declarator declarator, Expression exp)
481 return { type = arrayDeclarator, declarator = declarator, array.exp = exp };
484 Declarator MkDeclaratorEnumArray(Declarator declarator, Specifier _class)
486 return { type = arrayDeclarator, declarator = declarator, array.enumClass = _class };
489 Declarator MkDeclaratorPointer(Pointer pointer, Declarator declarator)
491 return { type = pointerDeclarator, declarator = declarator, pointer.pointer = pointer };
494 Enumerator MkEnumerator(Identifier id, Expression exp)
496 return { id = id, exp = exp };
499 Pointer MkPointer(OldList qualifiers, Pointer pointer)
501 return { qualifiers = qualifiers, pointer = pointer };
504 Initializer MkInitializerAssignment(Expression exp)
506 /*if(yylloc.start.line == 1)
508 return { type = expInitializer, exp = exp, loc = yylloc };
511 Initializer MkInitializerList(OldList list)
513 /*if(yylloc.start.line == 1)
515 return { type = listInitializer, list = list, loc = yylloc };
518 InitDeclarator MkInitDeclarator(Declarator declarator, Initializer initializer)
520 return { declarator = declarator, initializer = initializer };
523 public TypeName MkTypeName(OldList qualifiers, Declarator declarator)
525 return { qualifiers = qualifiers, declarator = declarator };
528 public Identifier GetDeclId(Declarator decl)
530 while(decl && decl.type != identifierDeclarator)
531 decl = decl.declarator;
532 return decl ? decl.identifier : null;
535 Declaration MkDeclarationClassInst(Instantiation inst)
537 return { type = instDeclaration, inst = inst, loc = yylloc };
540 Declaration MkDeclarationInst(Instantiation inst)
542 Declaration decl { type = instDeclaration, inst = inst, loc = yylloc };
544 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
547 int len = 0, stringLen;
550 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
551 len += defaultNameSpaceLen;
557 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
558 len += currentNameSpaceLen;
563 stringLen = strlen(inst.exp.identifier.string);
564 memcpy(name + len, inst.exp.identifier.string, stringLen);
567 delete inst.exp.identifier.string;
568 inst.exp.identifier.string = CopyString(name);
573 string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
574 type = MkClassTypeSymbol(inst._class.symbol);
576 symbol.idCode = symbol.id = curContext.nextID++;
577 (curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol);
578 decl.symbol = inst.symbol = symbol;
582 Declaration MkDeclarationDefine(Identifier id, Expression exp)
584 Declaration decl { type = defineDeclaration, id = id, exp = exp, loc = yylloc };
585 char expString[1024];
588 PrintExpression(exp, expString);
590 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
593 int len = 0, stringLen;
596 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
597 len += defaultNameSpaceLen;
603 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
604 len += currentNameSpaceLen;
608 stringLen = strlen(id.string);
609 memcpy(name + len, id.string, stringLen);
613 id.string = CopyString(name);
616 if(!eSystem_FindDefine(privateModule, id.string))
617 eSystem_RegisterDefine(id.string, expString, privateModule, buildingECERECOMModule ? baseSystemAccess : publicAccess);
619 Compiler_Warning("Redefinition of %s ignored\n", id.string);
623 Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
625 Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
626 bool variable = true;
628 if(specifiers != null)
631 for(spec = specifiers.first; spec; spec = spec.next)
633 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
635 if(initDeclarators != null)
639 for(d = initDeclarators.first; d; d = d.next)
641 if(GetDeclId(d.declarator).string)
645 string = CopyString(GetDeclId(d.declarator).string);
646 type = ProcessType(specifiers, d.declarator);
648 type.id = type.idCode = curContext.nextID++;
650 (curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type);
651 decl.symbol = d.declarator.symbol = type;
657 for(; spec; spec = spec.next)
659 if(spec.type == nameSpecifier && spec.name)
663 string = CopyString(spec.name);
664 type = ProcessType(specifiers, null);
666 type.id = type.idCode = curContext.nextID++;
667 (curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type);
675 else if(spec.type == baseSpecifier &&
676 (spec.specifier == STRUCT || spec.specifier == UNION))
680 if(variable && initDeclarators)
683 for(d = initDeclarators.first; d; d = d.next)
685 Identifier id = GetDeclId(d.declarator);
686 if(id && id.string && id.string[0])
692 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
695 int len = 0, stringLen;
698 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
699 len += defaultNameSpaceLen;
705 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
706 len += currentNameSpaceLen;
710 stringLen = strlen(id.string);
711 memcpy(name + len, id.string, stringLen);
715 id.string = CopyString(name);
718 // Avoid memory leaks on duplicated symbols (BinaryTree::Add Would Fail)
719 symbol = (Symbol)(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.FindString(id.string);
722 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specifiers, d.declarator) };
723 (curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol);
724 // TODO: Add better support to count declarators
725 if(symbol.type && symbol.type.kind == arrayType && !symbol.type.arraySizeExp && d.initializer)
727 if(d.initializer.type == listInitializer)
730 sprintf(string, "%d",d.initializer.list->count);
731 symbol.type.arraySizeExp = MkExpConstant(string);
732 symbol.type.freeExp = true;
734 else if(d.initializer.type == expInitializer && d.initializer.exp.type == stringExp && d.initializer.exp.string)
739 bool escaped = false;
740 char * s = d.initializer.exp.string;
742 // MAKE MORE ACCURATE
743 for(c = 1; (ch = s[c]); c++)
745 if(ch == '\\' && !escaped)
754 sprintf(string, "%d", count);
755 symbol.type.arraySizeExp = MkExpConstant(string);
756 symbol.type.freeExp = true;
759 symbol.id = symbol.idCode = curContext.nextID++;
761 decl.symbol = d.declarator.symbol = symbol;
768 decl.symbol = Symbol { };
769 decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
770 excludedSymbols->Add(decl.symbol);
775 Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifier extStorage)
777 return { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
780 Statement MkLabeledStmt(Identifier id, Statement statement)
782 return { type = labeledStmt, labeled.id = id, labeled.stmt = statement, loc = yylloc };
785 Statement MkCaseStmt(Expression exp, Statement statement)
787 return { type = caseStmt, caseStmt.exp = exp, caseStmt.stmt = statement, loc = yylloc };
790 Statement MkCompoundStmt(OldList declarations, OldList statements)
792 return { type = compoundStmt, compound.declarations = declarations, compound.statements = statements, loc = yylloc };
795 Statement MkExpressionStmt(OldList expressions)
797 return { type = expressionStmt, expressions = expressions, loc = yylloc };
800 Statement MkBadDeclStmt(Declaration decl)
802 return { type = badDeclarationStmt, decl = decl, loc = yylloc };
805 Statement MkIfStmt(OldList exp, Statement statement, Statement elseStmt)
807 return { type = ifStmt, ifStmt.exp = exp, ifStmt.stmt = statement, ifStmt.elseStmt = elseStmt, loc = yylloc };
810 Statement MkSwitchStmt(OldList exp, Statement statement)
812 // To know it's a switch compound... (Don't want declarations in there... bugs)
814 statement.compound.isSwitch = true;
815 return { type = switchStmt, switchStmt.exp = exp, switchStmt.stmt = statement, loc = yylloc };
818 Statement MkWhileStmt(OldList exp, Statement statement)
820 return { type = whileStmt, whileStmt.exp = exp, whileStmt.stmt = statement, loc = yylloc };
823 Statement MkDoWhileStmt(Statement statement, OldList exp)
825 return { type = doWhileStmt, doWhile.exp = exp, doWhile.stmt = statement, loc = yylloc };
828 Statement MkForStmt(Statement init, Statement check, OldList inc, Statement statement)
830 return { type = forStmt, forStmt.init = init, forStmt.check = check, forStmt.increment = inc, forStmt.stmt = statement, loc = yylloc };
833 Statement MkForEachStmt(Identifier id, OldList exp, OldList filter, Statement statement)
835 return { type = forEachStmt, forEachStmt.id = id, forEachStmt.exp = exp, forEachStmt.filter = filter, forEachStmt.stmt = statement, loc = yylloc };
838 Statement MkGotoStmt(Identifier id)
840 return { type = gotoStmt, gotoStmt.id = id, loc = yylloc };
843 Statement MkContinueStmt()
845 return { type = continueStmt, loc = yylloc };
848 Statement MkBreakStmt()
850 return { type = breakStmt, loc = yylloc };
853 Statement MkReturnStmt(OldList exp)
855 return { type = returnStmt, expressions = exp, loc = yylloc };
858 FunctionDefinition MkFunction(OldList specifiers, Declarator declarator, OldList declarationList)
860 return { specifiers = specifiers, declarator = declarator, declarations = declarationList };
863 void ProcessFunctionBody(FunctionDefinition func, Statement body)
865 Declarator declarator = func.declarator;
866 Declarator funcDecl = GetFuncDecl(declarator);
871 if(funcDecl && funcDecl.function.parameters && body)
873 Context context = body.compound.context;
875 for(param = funcDecl.function.parameters->first; param; param = param.next)
879 Symbol symbol = null;
880 Identifier id = GetDeclId(param.declarator);
881 char * string = id ? id.string : null;
884 for(symbol = (Symbol)context.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
885 if(!strcmp(symbol.string, string))
887 // This parameter is not shadowed by a local declaration
890 symbol = Symbol { string = CopyString(id.string), type = ProcessType(param.qualifiers, param.declarator), isParam = true };
891 context.symbols.Add((BTNode)symbol);
893 // TODO: Fix this, the parameters' IDs should really be smaller...
894 symbol.id = context.nextID++;
895 param.declarator.symbol = symbol;
902 if(!declarator.symbol)
904 Identifier id = GetDeclId(declarator);
906 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess && strcmp(id.string, "__on_register_module"))
909 int len = 0, stringLen;
912 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
913 len += defaultNameSpaceLen;
919 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
920 len += currentNameSpaceLen;
924 stringLen = strlen(id.string);
925 memcpy(name + len, id.string, stringLen);
929 id.string = CopyString(name);
931 symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
932 symbol.idCode = symbol.id = globalContext.nextID++;
933 globalContext.symbols.Add((BTNode)symbol);
934 declarator.symbol = symbol;
938 symbol = declarator.symbol;
939 excludedSymbols->Remove(declarator.symbol);
940 delete symbol.string;
941 symbol.string = CopyString(GetDeclId(declarator).string);
942 globalContext.symbols.Add((BTNode)symbol);
945 symbol.type = ProcessType(func.specifiers, declarator);
947 if(symbol.type && (symbol.type.kind == functionType || symbol.type.kind == methodType))
949 if(!symbol.type.params.count)
951 Type type { refCount = 1 };
952 symbol.type.params.Add(type);
961 External MkExternalFunction(FunctionDefinition function)
963 External external { type = functionExternal, function = function, symbol = function.declarator.symbol };
964 if(function.specifiers)
967 for(spec = function.specifiers->first; spec; spec = spec.next)
968 if(spec.type == baseSpecifier && spec.specifier == STATIC)
970 declMode = staticAccess;
975 if(external.symbol && !external.symbol.methodExternal)
976 external.symbol.methodExternal = external;
980 External MkExternalImport(char * name, ImportType importType, AccessMode importAccess)
982 External external { type = importExternal };
983 int len = strlen(name) - 2;
984 external.importString = new char[len + 1];
985 strncpy(external.importString, name+1, len);
986 external.importString[len] = '\0';
991 Time startTime = GetTime();
994 ImportModule(external.importString, importType, importAccess, true);
995 ImportModule(external.importString, importType, importAccess, false);
997 time = GetTime() - startTime;
998 printf("Importing took %.3f seconds for %s\n", time, external.importString);
999 externalImportTotalTime += time;
1005 External MkExternalDeclaration(Declaration declaration)
1007 External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
1008 InitDeclarator d = (declaration && declaration.declarators) ? declaration.declarators->last : null;
1009 if(declaration && declaration.type == initDeclaration && declaration.specifiers)
1012 for(spec = declaration.specifiers->first; spec; spec = spec.next)
1013 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1015 declMode = defaultAccess;
1018 else if(spec.type == baseSpecifier && spec.specifier == STATIC)
1020 declMode = staticAccess;
1024 if(declaration && declaration.symbol && !declaration.symbol.methodExternal)
1025 declaration.symbol.methodExternal = external;
1029 External MkExternalNameSpace(Identifier identifier)
1031 External external { type = nameSpaceExternal, id = identifier };
1032 currentNameSpace = identifier ? identifier.string : null;
1033 currentNameSpaceLen = currentNameSpace ? strlen(currentNameSpace) : 0;
1037 void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
1039 if(spec.type == nameSpecifier)
1041 Symbol symbol = spec.symbol;
1042 spec.templateArgs = templateArgs;
1043 if(templateArgs && templateArgs.first)
1045 char templateString[1024];
1046 TemplateArgument arg;
1047 strcpy(templateString, symbol ? symbol.string : spec.name);
1048 strcat(templateString, "<");
1049 for(arg = templateArgs.first; arg; arg = arg.next)
1057 char expString[1024];
1058 Class backupThisClass = thisClass;
1060 expString[0] = '\0';
1061 // Will this work here?
1063 Location oldLocation = yylloc;
1064 File backFileInput = fileInput;
1069 // TESTING THIS SCANNER RESUME STUFF
1072 yylloc = oldLocation;
1073 fileInput = backFileInput;
1076 fileInput.Seek(yylloc.start.pos, start);
1077 resetScannerPos(&yylloc.start);
1082 //ProcessExpressionType(arg.expression);
1083 //ComputeExpression(arg.expression);
1084 PrintExpression(arg.expression, expString);
1085 strcat(argument, expString);
1086 thisClass = backupThisClass;
1091 strcat(argument, arg.identifier.string);
1096 char * typeString = StringFromSpecDecl(arg.templateDatatype.specifiers, arg.templateDatatype.decl);
1097 strcat(argument, typeString);
1104 if(arg.prev) strcat(templateString, ", ");
1107 strcat(templateString, arg.name.string);
1108 strcat(templateString, " = ");
1110 strcat(templateString, argument);
1114 int len = strlen(templateString);
1115 if(templateString[len-1] == '>') templateString[len++] = ' ';
1116 templateString[len++] = '>';
1117 templateString[len++] = '\0';
1119 // printf("SetClassTemplateArgs templateString: %s\n", templateString);
1120 symbol = FindClass(templateString);
1121 if(!symbol && spec.symbol)
1123 // If class was only decl'ed, invoke DeclClass on this templated class as well
1124 symbol = _DeclClass(MAXINT, templateString);
1126 // Add a reference to all templated class to the basic class
1128 spec.symbol.templatedClasses.Add(OldLink { data = symbol });
1130 spec.symbol = symbol;
1131 spec.name = CopyString(symbol ? symbol.string : templateString);
1135 FreeList(templateArgs, FreeTemplateArgument);
1138 Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
1140 Specifier spec { type = nameSpecifier };
1146 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
1149 spec.templateParameter = templatedType.param;
1150 spec.type = templateTypeSpecifier;
1154 symbol = FindClass(name);
1156 if(symbol && symbol.registered && symbol.registered.isRemote == 1)
1158 char className[1024];
1159 strcpy(className, "DCOMClient_");
1160 if(!strncmp(name, className, strlen(className)))
1161 spec.name = CopyString(name);
1164 strcat(className, name);
1165 spec.name = CopyString(className);
1169 spec.name = CopyString(symbol.string);
1171 spec.name = CopyString(name);
1172 spec.symbol = symbol;
1173 if(templateArgs != null)
1174 SetClassTemplateArgs(spec, templateArgs);
1179 public Specifier MkSpecifierName(char * name)
1181 return _MkSpecifierName(name, null, null);
1184 public Specifier MkSpecifierNameArgs(char * name, OldList * templateArgs)
1186 return _MkSpecifierName(name, null, templateArgs);
1190 Specifier MkClassName(char * string)
1192 return { type = SpecifierClass, name = CopyString(string) };
1195 ClassFunction MkClassFunction(OldList specifiers, Specifier _class, Declarator decl, OldList declList)
1197 return { specifiers = specifiers, /*_class = _class,*/ declarator = decl, declarations = declList };
1200 void ProcessClassFunctionBody(ClassFunction func, Statement body)
1204 Declarator decl = func.declarator;
1206 //Declarator decl = GetFuncDecl(func.declarator);
1207 Declarator funcDecl = GetFuncDecl(func.declarator);
1211 if(decl && !decl.symbol)
1213 OldList * symbolSpecs = MkList();
1215 // WHAT WILL WE DO WITH THIS? Double instances?
1216 //if(decl.function.parameters && body)
1217 if(funcDecl && funcDecl.function.parameters && body)
1219 Context context = body.compound.context;
1221 for(param = funcDecl.function.parameters->first; param; param = param.next)
1223 if(param.declarator)
1225 Symbol symbol = null;
1226 Identifier id = GetDeclId(param.declarator);
1227 char * string = id ? id.string : null;
1230 symbol = (Symbol)context.symbols.FindString(string);
1232 // This parameter is not shadowed by a local declaration
1237 string = CopyString(id.string);
1238 type = ProcessType(param.qualifiers, param.declarator);
1242 // TODO: Fix this, the parameters' IDs should really be smaller...
1243 symbol.idCode = symbol.id = context.nextID++;
1244 context.symbols.Add((BTNode)symbol);
1246 param.declarator.symbol = symbol;
1251 //////////////////////////////////
1259 Identifier id = GetDeclId(funcDecl);
1263 for(c = strlen(id.string)-1; c >= 0; c--)
1265 if(id.string[c] == ':')
1267 char * string = CopyString(id.string + c + 1);
1268 id.string[c - 1] = 0;
1269 id._class = MkSpecifierName(id.string);
1275 symbol.string = CopyString(id.string);
1282 for(spec = func.specifiers->first; spec; spec = spec.next)
1283 symbolSpecs->Add(CopySpecifier(spec));
1285 symbol.type = ProcessType(symbolSpecs, decl);
1286 symbol.idCode = symbol.id = globalContext.nextID++;
1287 decl.symbol = symbol;
1289 excludedSymbols->Add(symbol);
1291 FreeList(symbolSpecs, FreeSpecifier);
1295 OldList * MkSpecsClass(Specifier _class)
1297 OldList * list = MkList();
1298 ListAdd(list, _class);
1302 MemberInit MkMemberInit(OldList ids, Initializer initializer)
1304 return { identifiers = ids, initializer = initializer };
1307 MemberInit MkMemberInitExp(Expression idExp, Initializer initializer)
1309 MemberInit init { initializer = initializer, identifiers = MkList() };
1312 for(exp = idExp; exp && exp.type == memberExp; exp = exp.member.exp)
1314 init.identifiers->Insert(null, exp.member.member);
1315 exp.member.member = null;
1317 if(exp && exp.type == identifierExp)
1319 init.identifiers->Insert(null, exp.identifier);
1320 exp.identifier = null;
1322 FreeExpression(idExp);
1326 MembersInit MkMembersInitList(OldList dataMembers)
1328 return { type = dataMembersInit, dataMembers = dataMembers };
1331 MembersInit MkMembersInitMethod(ClassFunction function)
1333 return { type = methodMembersInit, function = function };
1336 Instantiation MkInstantiation(Specifier _class, Expression exp, OldList members)
1338 return { _class = _class, exp = exp, members = members };
1341 Instantiation MkInstantiationNamed(OldList specs, Expression exp, OldList members)
1343 Instantiation inst { exp = exp, members = members };
1348 for(spec = specs.first; spec; spec = spec.next)
1349 if(spec.type == nameSpecifier /*classSpecifier*/)
1356 FreeList(specs, FreeSpecifier);
1360 Compiler_Error("Expecting class specifier\n");
1361 inst._class = MkSpecifierName /*MkClassName*/("");
1369 ClassDef MkClassDefAccessOverride(AccessMode access, Identifier id)
1371 return { type = accessOverrideClassDef, id = id, memberAccess = access };
1374 ClassDef MkClassDefMemberAccess()
1376 return { type = memberAccessClassDef };
1379 ClassDef MkClassDefDeclaration(Declaration decl)
1381 return { type = declarationClassDef, decl = decl };
1384 ClassDef MkClassDefClassData(Declaration decl)
1386 return { type = classDataClassDef, decl = decl };
1389 ClassDef MkClassDefDesigner(char * designer)
1391 return { type = classDesignerClassDef, designer = CopyString(designer) };
1394 ClassDef MkClassDefNoExpansion()
1396 return { type = classNoExpansionClassDef };
1399 ClassDef MkClassDefFixed()
1401 return { type = classFixedClassDef };
1404 ClassDef MkClassDefDesignerDefaultProperty(Identifier id)
1406 return { type = designerDefaultPropertyClassDef, defaultProperty = id };
1409 ClassDef MkClassDefDefaultProperty(OldList defProperties)
1411 return { type = defaultPropertiesClassDef, defProperties = defProperties };
1414 ClassDef MkClassDefFunction(ClassFunction function)
1417 if(function && function.declarator)
1419 Declarator funcDecl = GetFuncDecl(function.declarator);
1420 if(funcDecl && funcDecl.declarator && funcDecl.declarator.type == bracketsDeclarator)
1422 def.type = declarationClassDef;
1423 def.decl = MkStructDeclaration(function.specifiers, MkListOne(MkStructDeclarator(function.declarator, null)), null);
1424 function.declarator = null;
1425 function.specifiers = null;
1426 FreeClassFunction(function);
1430 def.type = functionClassDef;
1431 def.function = function;
1435 Symbol DeclClassAddNameSpace(int symbolID, char * className)
1438 int len = 0, stringLen;
1440 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1442 if(defaultNameSpace)
1444 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1445 len += defaultNameSpaceLen;
1449 if(currentNameSpace)
1451 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1452 len += currentNameSpaceLen;
1457 stringLen = strlen(className);
1458 memcpy(name + len, className, stringLen);
1461 return _DeclClass(symbolID, name);
1464 Symbol DeclClass(int symbolID, char * name)
1466 if(strchr(name, ':'))
1467 return _DeclClass(symbolID, name);
1469 return DeclClassAddNameSpace(symbolID, name);
1472 Symbol _DeclClass(int symbolID, char * name)
1474 Symbol symbol = FindClass(name);
1478 Context classContext;
1479 for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
1485 if(name[0] == ':' && name[1] == ':')
1489 string = CopyString(name);
1490 idCode = symbolID, id = symbolID;
1492 globalContext.classes.Add((BTNode)symbol);
1497 for(c = 0; (ch = name[c]); c++)
1499 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
1505 if(start && c - start)
1506 symbol.shortName = CopyString(name + start);
1510 symbol.idCode = symbol.id = symbolID;
1514 void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
1516 if(baseSpecs && baseSpecs.first && ((Specifier)baseSpecs.first).type == nameSpecifier)
1521 strcpy(name, ((Specifier)baseSpecs.first).name);
1522 tpl = strchr(name, '<');
1525 baseClass = FindClass(name);
1529 for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
1531 TemplatedType type { key = copy.key, param = copy.param };
1532 curContext.templateTypes.Add((BTNode)type);
1535 else if(baseClass.registered)
1538 for(sClass = baseClass.registered; sClass; sClass = sClass.base)
1540 ClassTemplateParameter p;
1541 for(p = sClass.templateParams.first; p; p = p.next)
1543 //OldList * specs = MkList();
1544 //Declarator decl = null;
1545 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
1548 TemplateParameter param = p.param;
1552 p.param = param = TemplateParameter
1554 identifier = MkIdentifier(p.name), type = p.type,
1555 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
1558 type = TemplatedType { key = (uint)p.name, param = param };
1559 curContext.templateTypes.Add((BTNode)type);
1567 ClassDefinition MkClass(Symbol symbol, OldList baseSpecs, OldList definitions)
1569 ClassDefinition classDef;
1570 SetupBaseSpecs(symbol, baseSpecs);
1571 symbol.ctx = curContext;
1572 classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
1573 curContext.classDef = classDef;
1577 Expression MkExpInstance(Instantiation inst)
1579 return { type = instanceExp, instance = inst };
1582 External MkExternalClass(ClassDefinition _class)
1584 return { type = classExternal, _class = _class, symbol = _class.symbol };
1587 PropertyDef MkProperty(OldList specs, Declarator decl, Identifier id, Statement setStmt, Statement getStmt)
1597 Type type = ProcessType(specs, decl);
1600 char typeString[1024];
1601 typeString[0] = '\0';
1602 PrintType(type, typeString, false, true);
1603 id = MkIdentifier(typeString);
1604 prop.conversion = true;
1610 string = CopyString(id.string);
1613 symbol.idCode = symbol.id = globalContext.nextID++;
1614 excludedSymbols->Add(symbol);
1615 globalContext.nextID++;
1616 globalContext.nextID++;
1617 prop.symbol = symbol;
1621 ClassDef MkClassDefProperty(PropertyDef propertyDef)
1623 return { type = propertyClassDef, propertyDef = propertyDef };
1626 ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
1628 return { type = classPropertyClassDef, propertyDef = propertyDef };
1631 ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
1633 return { type = classPropertyValueClassDef, id = id, initializer = initializer };
1636 int CheckType(char * text)
1639 Time startTime = GetTime();
1641 if(FindTemplateTypeParameter(curContext, text))
1644 checkTypeTotalTime += GetTime() - startTime;
1648 if(FindType(curContext, text))
1651 checkTypeTotalTime += GetTime() - startTime;
1658 checkTypeTotalTime += GetTime() - startTime;
1660 return TYPE_NAME; //CLASS_NAME;
1663 checkTypeTotalTime += GetTime() - startTime;
1670 return CheckType(yytext);
1673 Context PushContext()
1675 Context ctx { parent = curContext };
1680 void PopContext(Context ctx)
1682 curContext = ctx.parent;
1685 Symbol FindType(Context ctx, char * name)
1690 type = (Symbol)ctx.types.FindString(name);
1691 if(!type && ctx.parent)
1692 type = FindType(ctx.parent, name);
1697 TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
1699 TemplatedType templatedType = null;
1702 templatedType = (TemplatedType)ctx.templateTypes.FindString(name);
1703 if(!templatedType && ctx.parent)
1704 templatedType = FindTemplateTypeParameter(ctx.parent, name);
1706 return templatedType;
1709 bool ModuleAccess(Module searchIn, Module searchFor)
1711 SubModule subModule;
1713 if(searchFor == searchIn)
1716 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
1718 if(subModule.importMode == publicAccess /*|| searchIn == searchIn.application*/)
1720 if(ModuleAccess(subModule.module, searchFor))
1727 ModuleImport FindModule(Module moduleToFind)
1729 ModuleImport module;
1730 if(!moduleToFind.name)
1732 for(module = imports->first; module; module = module.next)
1733 if(module.name && !strcmp(module.name, moduleToFind.name))
1737 module = ModuleImport
1739 name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
1740 importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
1742 imports->Add(module);
1748 // TO REMOVE: OBSOLETE...
1749 static void GetFullClassNameSpace(NameSpace * ns, char * name)
1753 GetFullClassNameSpace(ns->parent, name);
1754 strcat(name, ns->name);
1759 static char * GetFullClassName(Class c, char * name)
1761 NameSpace * nameSpace;
1763 GetFullClassNameSpace(c.nameSpace, name);
1764 strcat(name, c.name);
1769 public Symbol FindClass(char * name)
1772 Time startTime = GetTime();
1776 bool global = false;
1777 char fullName[1024];
1779 if(name[0] == ':' && name[1] == ':')
1785 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1787 int len = 0, stringLen;
1788 if(defaultNameSpace)
1790 memcpy(fullName, defaultNameSpace, defaultNameSpaceLen);
1791 len += defaultNameSpaceLen;
1792 fullName[len++] = ':';
1793 fullName[len++] = ':';
1795 if(currentNameSpace)
1797 memcpy(fullName + len, currentNameSpace, currentNameSpaceLen);
1798 len += currentNameSpaceLen;
1799 fullName[len++] = ':';
1800 fullName[len++] = ':';
1802 stringLen = strlen(name);
1803 memcpy(fullName + len, name, stringLen);
1806 cl = globalContext ? (Symbol)globalContext.classes.FindString(fullName) : null;
1810 cl = globalContext ? (Symbol)globalContext.classes.FindString(name) : null;
1815 Time startTime = GetTime();
1817 // Ignore name space name when searching
1818 for(cl = globalContext ? (Symbol)globalContext.classes.first : null; cl; cl = (Symbol)((BTNode)cl).next)
1822 char * string = cl.string;
1824 for(c = 0; (ch = string[c]); c++)
1826 if(ch == '.' || (ch == ':' && string[c+1] == ':'))
1832 if(start && c - start)
1834 if(!strcmp(string + start, name))
1838 if(cl.shortName && !strcmp(cl.shortName, name))
1842 findClassIgnoreNSTotalTime += GetTime() - startTime;
1848 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1849 _class = eSystem_FindClass(privateModule, fullName);
1851 _class = eSystem_FindClass(privateModule, name);
1855 name = _class.fullName;
1857 cl = (Symbol)globalContext.classes.FindString(name);
1862 string = CopyString(name);
1863 registered = _class;
1870 cl.module = FindModule(_class.module);
1872 cl.module = mainModule;
1873 globalContext.classes.Add((BTNode)cl);
1874 if(strcmp(name, _class.name))
1875 cl.shortName = CopyString(_class.name);
1880 findClassTotalTime += GetTime() - startTime;
1885 void CopyTypeInto(Type type, Type src)
1888 type.name = CopyString(src.name);
1889 type.enumName = CopyString(src.enumName);
1892 if(src.kind == enumType)
1896 type.members.Clear();
1897 for(member = type.members.first; member; member = member.next)
1899 type.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
1902 else if(src.kind == structType || src.kind == unionType)
1905 // Tricky stuff... will be removed from list only when ref count reaches 0
1906 for(member = type.members.first; member; member = member.next)
1909 else if(src.kind == functionType)
1912 type.returnType.refCount++;
1913 for(param = type.params.first; param; param = param.next)
1916 else if(src.kind == pointerType || src.kind == arrayType)
1918 type.type.refCount++;
1919 if(src.kind == arrayType)
1921 if(type.arraySizeExp)
1922 type.arraySizeExp = CopyExpression(type.arraySizeExp);
1928 public Type ProcessType(OldList specs, Declarator decl)
1931 bool isTypedef = false;
1932 if(!specs || specs.first)
1934 Declarator funcDecl = GetFuncDecl(decl);
1936 bool dllExport = false;
1938 specType.kind = intType;
1939 specType.isSigned = true;
1940 specType.refCount = 1;
1942 type = Type { refCount = 1 };
1944 while(decl && (decl.type == structDeclarator || decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd))
1946 if(decl.type == structDeclarator && decl.structDecl.exp)
1948 ProcessExpressionType(decl.structDecl.exp);
1949 ComputeExpression(decl.structDecl.exp);
1950 if(decl.structDecl.exp.type == constantExp)
1951 specType.bitFieldCount = strtoul(decl.structDecl.exp.constant, null, 0);
1953 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended &&
1954 (!strcmp(decl.extended.extended, "__declspec(dllexport)") || !strcmp(decl.extended.extended, "dllexport")))
1958 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended &&
1959 (strstr(decl.extended.extended, "__attribute__")))
1961 specType.keepCast = true;
1963 decl = decl.declarator;
1966 // If we'll be using the specType
1967 if(funcDecl || !decl || decl.type == identifierDeclarator)
1972 bool isLong = false;
1973 for(spec = specs.first; spec; spec = spec.next)
1975 if(spec.type == extendedSpecifier && (!strcmp(spec.name, "__declspec(dllexport)") || !strcmp(spec.name, "dllexport")))
1979 if(spec.type == extendedSpecifier && strstr(spec.name, "__attribute__"))
1981 specType.keepCast = true;
1984 if(specType.kind == structType || specType.kind == unionType)
1987 specType = { kind = intType, isSigned = true, refCount = 1 };
1990 if(spec.type == baseSpecifier)
1992 if(spec.specifier == TYPEDEF) isTypedef = true;
1993 else if(spec.specifier == VOID) specType.kind = voidType;
1994 else if(spec.specifier == CHAR) specType.kind = charType;
1995 else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
1996 else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
1997 else if(spec.specifier == INT64) specType.kind = int64Type;
1998 else if(spec.specifier == VALIST)
1999 specType.kind = vaListType;
2000 else if(spec.specifier == SHORT) specType.kind = shortType;
2001 else if(spec.specifier == LONG)
2004 specType.kind = int64Type;
2006 specType.kind = intType;
2008 // specType.kind = longType;
2010 else if(spec.specifier == FLOAT) specType.kind = floatType;
2011 else if(spec.specifier == DOUBLE) specType.kind = doubleType;
2012 else if(spec.specifier == SIGNED) specType.isSigned = true;
2013 else if(spec.specifier == UNSIGNED) specType.isSigned = false;
2014 else if(spec.specifier == CONST) specType.constant = true;
2015 else if(spec.specifier == TYPED_OBJECT)
2017 specType.classObjectType = typedObject; specType.kind = classType; specType._class = FindClass("class");
2019 else if(spec.specifier == ANY_OBJECT)
2021 specType.classObjectType = anyObject; specType.kind = classType; specType._class = FindClass("class");
2023 else if(spec.specifier == CLASS)
2025 specType.classObjectType = classPointer; specType.kind = classType; specType._class = FindClass("class");
2027 else if(spec.specifier == THISCLASS)
2028 specType.kind = thisClassType;
2030 else if(spec.type == nameSpecifier)
2032 Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
2033 if(symbol && symbol.type)
2035 CopyTypeInto(specType, symbol.type);
2036 specType.typeName = CopyString(symbol.type.name);
2038 else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
2040 // key.sym enum values need FindClass:
2041 specType._class = spec.name ? FindClass(spec.name) : null;
2042 // specType._class = spec.symbol;
2043 specType.kind = classType;
2044 if(!specType._class)
2045 specType.kind = intType;
2048 else if(spec.type == enumSpecifier)
2051 specType.kind = enumType;
2052 specType.enumName = spec.id ? CopyString(spec.id.string) : null;
2058 for(e = spec.list->first; e; e = e.next)
2060 specType.members.Add(NamedItem { name = CopyString(e.id.string) });
2062 if(e.exp && ComputeExpression(e.exp), e.exp.isConstant && e.exp.expType.kind == intType)
2063 value.data = (void *) nextValue = strtol(e.exp.string, null, 0);
2065 value.data = (void *)nextValue++;
2073 for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
2074 if(decl.declarators)
2077 for(d = decl.declarators.first; d; d = d.next)
2079 Type memberType = ProcessType(decl.specifiers, d);
2080 specType.members.Add(memberType);
2083 else if(decl.specifiers)
2085 Type memberType = ProcessType(decl.specifiers, null);
2086 specType.members.Add(memberType);
2091 else if(spec.type == templateTypeSpecifier)
2094 printf("spec %x\n", spec);
2095 printf("template param %x\n", spec.templateParameter);
2096 printf("identifier %x\n", spec.templateParameter.identifier);
2097 printf("string %x\n", spec.templateParameter.identifier.string);
2099 specType.kind = templateType;
2100 specType.templateParameter = spec.templateParameter;
2102 else if(spec.type == structSpecifier || spec.type == unionSpecifier)
2104 Symbol _class = spec.id ? FindClass(spec.id.string) : null;
2107 if(!_class.registered || _class.registered.type != structClass)
2108 specType.directClassAccess = true;
2109 specType._class = _class;
2110 specType.kind = classType;
2113 if(spec.type == structSpecifier)
2114 specType.kind = structType;
2115 else if(spec.type == unionSpecifier)
2116 specType.kind = unionType;
2119 // TESTING THIS HERE... Had 0 type size
2120 if(!spec.definitions && !isTypedef)
2122 Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
2123 if(symbol && symbol.type)
2125 specType = *symbol.type;
2126 specType.name = CopyString(symbol.type.name);
2127 specType.typeName = CopyString(spec.name);
2128 specType.enumName = CopyString(symbol.type.enumName);
2129 specType.refCount = 1;
2131 if(symbol.type.kind == enumType)
2135 specType.members.Clear();
2136 for(member = specType.members.first; member; member = member.next)
2138 specType.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
2141 else if(symbol.type.kind == structType || symbol.type.kind == unionType)
2144 // Tricky stuff... will be removed from list only when ref count reaches 0
2145 for(member = specType.members.first; member; member = member.next)
2148 else if(symbol.type.kind == functionType)
2151 specType.returnType.refCount++;
2152 for(param = specType.params.first; param; param = param.next)
2155 else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
2157 specType.type.refCount++;
2158 if(symbol.type.kind == arrayType)
2160 if(specType.arraySizeExp)
2161 specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
2167 specType.enumName = CopyString(spec.id.string);
2170 specType.enumName = CopyString(spec.id.string);
2173 if(spec.definitions)
2176 for(def = spec.definitions->first; def; def = def.next)
2178 if(def.type == declarationClassDef && def.decl.type == structDeclaration)
2180 Declaration decl = def.decl;
2181 if(decl.declarators)
2184 for(d = decl.declarators->first; d; d = d.next)
2186 Type memberType = ProcessType(decl.specifiers, d);
2187 specType.members.Add(memberType);
2190 else if(decl.specifiers)
2192 Type memberType = ProcessType(decl.specifiers, null);
2193 specType.members.Add(memberType);
2200 else if(spec.type == subClassSpecifier)
2202 specType.kind = specType.kind = subClassType;
2203 specType._class = spec._class.symbol; // FindClass(spec._class.name);
2206 else if(spec.type == classSpecifier)
2208 specType._class = FindClass(spec.name);
2209 specType.kind = classType;
2215 specType.kind = ellipsisType;
2220 Declarator d = funcDecl.declarator;
2224 funcType.kind = functionType;
2225 funcType.refCount = 1;
2226 if(funcDecl.function.parameters)
2228 for(param = funcDecl.function.parameters->first; param; param = param.next)
2231 if(param.typedObject)
2233 Type typedObjectType
2236 byReference = param.byReference;
2237 kind = TypeTypedObject;
2239 funcType.params.Add(typedObjectType);
2242 funcType.params.Add(ProcessType(param.qualifiers, param.declarator));
2246 // Function returning a pointer...
2247 if(decl.type == pointerDeclarator)
2249 Pointer pointer = decl.pointer.pointer;
2251 funcType.returnType = ptrType;
2252 funcType.returnType.refCount = 1;
2255 ptrType.kind = pointerType;
2256 pointer = pointer.pointer;
2259 ptrType.type = Type { refCount = 1 };
2260 ptrType = ptrType.type;
2263 ptrType.type = Type { refCount = 1 };
2264 *ptrType.type = specType;
2268 funcType.returnType = Type { refCount = 1 };
2269 *funcType.returnType = specType;
2272 // TESTING: Added extendedDeclarator here
2273 while(d && (d.type == bracketsDeclarator || d.type == extendedDeclarator || d.type == extendedDeclaratorEnd))
2275 if((d.type == extendedDeclarator || d.type == extendedDeclaratorEnd) && d.extended.extended &&
2276 (!strcmp(d.extended.extended, "__declspec(dllexport)") || !strcmp(d.extended.extended, "dllexport")))
2283 funcType.dllExport = dllExport;
2285 if(d && d.type == pointerDeclarator)
2290 if(d.declarator && d.declarator.type == arrayDeclarator)
2292 // Arrays of pointers to functions (extremely tricky :()
2293 Pointer pointer = d.pointer.pointer;
2295 // TO WORK ON: Fixed the order for the array...
2296 type.kind = arrayType;
2297 type.arraySizeExp = CopyExpression(d.declarator.array.exp);
2298 type.freeExp = true;
2299 if(d.declarator.array.enumClass)
2300 type.enumClass = d.declarator.array.enumClass.symbol; // FindClass(d.declarator.array.enumClass.name);
2301 if(d.declarator.declarator && d.declarator.declarator.type == arrayDeclarator)
2303 Type tmpType = type;
2305 type = ProcessType(null, d.declarator.declarator);
2307 type.type = tmpType;
2308 tmpType.type = inType;
2311 type.type = ProcessType(null, d.declarator.declarator);
2313 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2317 ptrType.kind = pointerType;
2318 pointer = pointer.pointer;
2321 ptrType.type = Type { refCount = 1 };
2322 ptrType = ptrType.type;
2325 ptrType.type = ProcessType(specs, null);
2329 // WARNING: Not caring if this declarator contains a declarator between
2330 // the pointer and the function other than brackets (like in the case of array of pointers to functions)...
2331 // *********** Could it ever go in here??? Yes: void (* converters_table[10]) (); ***********
2332 Pointer pointer = d.pointer.pointer;
2337 ptrType.kind = pointerType;
2338 ptrType.type = Type { refCount = 1 };
2339 pointer = pointer.pointer;
2341 ptrType = ptrType.type;
2345 *ptrType.type = funcType;
2349 if(id._class && !id._class.name)
2350 ptrType.type.staticMethod = true;
2353 // TODO : Ensure classSym has been resolved here... (Is this gonna cause problems? Supposed to do this later...)
2356 if(id._class && id._class.name)
2358 id.classSym = id._class.symbol; // FindClass(id._class.name);
2359 /* TODO: Name Space Fix ups
2361 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
2366 ptrType.type.thisClass = id.classSym;
2367 if(ptrType.type.thisClass && strcmp(ptrType.type.thisClass.string, "class"))
2368 ptrType.type.extraParam = true;
2369 else if(id._class && id._class.name && !strcmp(id._class.name, "any_object"))
2371 ptrType.type.extraParam = true;
2372 ptrType.type.thisClass = FindClass("class");
2376 type.name = CopyString(id.string);
2379 else if(!d || d.type == identifierDeclarator)
2385 if(d.identifier._class && d.identifier._class.type == templateTypeSpecifier)
2387 type.thisClassTemplate = d.identifier._class.templateParameter;
2388 type.extraParam = true;
2392 if(d.identifier._class && !d.identifier._class.name)
2393 type.staticMethod = true;
2396 if(d.identifier._class && d.identifier._class.name && d.identifier._class.name[strlen(d.identifier._class.name)-1] == '&')
2398 type.thisClass = FindClass("class");
2399 type.byReference = true;
2402 type.thisClass = d.identifier._class ? d.identifier._class.symbol /*FindClass(d.identifier._class.name)*/ : null;
2403 if(type.thisClass && strcmp(type.thisClass.string, "class"))
2405 type.extraParam = true;
2407 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "any_object"))
2409 type.extraParam = true;
2410 type.thisClass = FindClass("class");
2412 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "class"))
2414 //type.extraParam = true;
2415 type.thisClass = FindClass("class");
2416 type.classObjectType = classPointer;
2420 type.name = CopyString(d.identifier.string);
2425 else if(decl && decl.type == pointerDeclarator)
2427 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2429 // Arrays of pointers (tricky :))
2431 Pointer pointer = decl.pointer.pointer;
2434 // TO WORK ON: Fixed the order for the array...
2435 type.kind = arrayType;
2436 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2437 type.freeExp = true;
2438 if(decl.declarator.array.enumClass)
2439 type.enumClass = decl.declarator.array.enumClass.symbol; // FindClass(decl.declarator.array.enumClass.name);
2440 if(decl.declarator.declarator && decl.declarator.declarator.type == arrayDeclarator)
2442 Type tmpType = type;
2444 type = ProcessType(null, decl.declarator.declarator);
2446 type.type = tmpType;
2447 tmpType.type = inType;
2450 type.type = ProcessType(null, decl.declarator.declarator);
2452 type.type = ProcessType(null, decl.declarator.declarator);
2453 type.kind = arrayType;
2454 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2455 type.arraySizeExp.freeExp = true;
2456 if(decl.array.enumClass)
2457 type.enumClass = FindClass(decl.array.enumClass.name);
2460 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2464 ptrType.kind = pointerType;
2465 pointer = pointer.pointer;
2468 ptrType.type = Type { refCount = 1 };
2469 ptrType = ptrType.type;
2472 ptrType.type = ProcessType(specs, null);
2473 id = GetDeclId(decl);
2474 if(id) type.name = CopyString(id.string);
2479 Pointer pointer = decl.pointer.pointer;
2480 Type ptrType = type;
2482 if(type.classObjectType)
2484 type.byReference = true;
2490 ptrType.kind = pointerType;
2491 pointer = pointer.pointer;
2494 ptrType.type = Type { refCount = 1 };
2495 ptrType = ptrType.type;
2498 ptrType.type = ProcessType(specs, decl.declarator);
2500 if(type.type.classObjectType)
2502 Type subType = type.type;
2503 type.classObjectType = subType.classObjectType;
2504 type.kind = subType.kind;
2505 type._class = subType._class;
2506 type.byReference = true;
2510 id = GetDeclId(decl);
2511 if(id) type.name = CopyString(id.string);
2515 else if(decl && decl.type == arrayDeclarator)
2519 type.kind = arrayType;
2521 type.arraySizeExp = CopyExpression(decl.array.exp);
2522 type.freeExp = true;
2523 if(decl.array.enumClass)
2524 type.enumClass = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
2525 id = GetDeclId(decl);
2527 // TO WORK ON: Fixed the order for the array...
2528 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2530 Type tmpType = type;
2532 type = ProcessType(specs, decl.declarator);
2534 type.type = tmpType;
2535 tmpType.type = inType;
2538 type.type = ProcessType(specs, decl.declarator);
2543 type.name = CopyString(id.string);
2548 if(!decl || decl.type == identifierDeclarator)
2552 type.name = decl ? CopyString(decl.identifier.string) : null;
2560 public Type ProcessTypeString(char * string, bool staticMethod)
2562 OldList * specs = MkList();
2563 Declarator decl = SpecDeclFromString(string, specs, null);
2564 Type type = ProcessType(specs, decl);
2565 if(type && !type.thisClass && staticMethod) type.staticMethod = true;
2566 FreeList(specs, FreeSpecifier);
2567 if(decl) FreeDeclarator(decl);
2571 Type MkClassTypeSymbol(Symbol symbol)
2575 Type type { kind = classType, _class = symbol };
2578 // Defaults to an int instead...
2579 type.kind = intType;
2587 public Type MkClassType(char * name)
2591 Type type { kind = classType, _class = FindClass(name) };
2594 // Defaults to an int instead...
2595 type.kind = intType;
2603 AsmField MkAsmField(char * command, Expression expression)
2605 return { command = command, expression = expression };
2608 Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
2610 return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
2611 asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
2612 asmStmt.clobberedFields = clobberedFields };
2615 ClassDef MkClassDefPropertyWatch(PropertyWatch watcher)
2617 return { type = propertyWatchClassDef, propertyWatch = watcher };
2620 Statement MkFireWatchersStmt(Expression object, OldList watches)
2622 return { type = fireWatchersStmt, _watch.object = object, _watch.watches = watches };
2625 Statement MkStopWatchingStmt(Expression watcher, Expression object, OldList watches)
2627 return { type = stopWatchingStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2630 Statement MkWatchStmt(Expression watcher, Expression object, OldList watches)
2632 return { type = watchStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2635 PropertyWatch MkDeleteWatch(Statement compound)
2637 return { compound = compound, deleteWatch = true };
2640 PropertyWatch MkPropertyWatch(OldList properties, Statement compound)
2642 return { compound = compound, properties = properties };
2645 Expression MkExpClass(OldList * specifiers, Declarator decl)
2647 return { type = classExp, _classExp.specifiers = specifiers, _classExp.decl = decl };
2650 Expression MkExpClassData(Identifier id)
2652 return { type = classDataExp, classData.id = id };
2656 External MkExternalDBTable(DBTableDef table)
2658 return { type = dbtableExternal, table = table };
2661 DBTableDef MkDBTableDef(char * name, Symbol symbol, OldList * definitions)
2663 return { name = name, symbol = symbol, definitions = definitions };
2666 DBTableEntry MkDBFieldEntry(TypeName type, Identifier id, char * name)
2668 return { type = fieldEntry, dataType = type, id = id, name = name };
2671 DBIndexItem MkDBIndexItem(Identifier id, Order order)
2673 return { id = id, order = order };
2676 DBTableEntry MkDBIndexEntry(OldList * items, Identifier id)
2678 return { type = indexEntry, items = items, id = id };
2681 Expression MkExpDBOpen(Expression ds, Expression dbName)
2683 return { type = dbopenExp, dbopen.ds = ds, dbopen.name = dbName };
2686 Expression MkExpDBField(char * table, Identifier id)
2688 return { type = dbfieldExp, db.table = table, db.id = id };
2691 Expression MkExpDBIndex(char * table, Identifier id)
2693 return { type = dbindexExp, db.table = table, db.id = id };
2696 Expression MkExpDBTable(char * table)
2698 return { type = dbtableExp, db.table = table };
2701 Expression MkExpArray(OldList * expressions)
2703 return { type = arrayExp, list = expressions };
2706 Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplateParameterType tplType)
2708 Expression argExp = null;
2709 Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
2713 ClassTemplateParameter curParam;
2715 for(sClass = _class; sClass; sClass = sClass.base)
2718 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2720 if(!strcmp(curParam.name, paramName))
2722 for(sClass = sClass.base; sClass; sClass = sClass.base)
2723 id += sClass.templateParams.count;
2731 if(curParam && curParam.type != tplType)
2737 char className[1024];
2738 Expression classExp;
2740 sprintf(idString, "%d", id);
2741 strcpy(className, "__ecereClass_");
2742 FullClassNameCat(className, _class.fullName, true);
2743 MangleClassName(className);
2744 DeclareClass(FindClass(_class.fullName), className);
2746 argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
2747 (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
2748 MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
2754 Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
2756 return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
2759 /*char * CreateMsgID(char * string, char * context)
2761 int lenString = strlen(string), lenContext = strlen(context);
2762 char * msgid = new char[lenString + lenContext + 20];
2763 memcpy(msgid, string, lenString);
2764 memcpy(msgid+lenString, " [msgctxt: ", 11);
2765 memcpy(msgid+lenString+11, context, lenContext);
2766 memcpy(msgid+lenString+11+lenContext, "]", 2);
2770 public void OutputIntlStrings()
2772 if(intlStrings.count)
2774 char * srcFile = GetSourceFile();
2775 char * objFile = GetOutputFile();
2776 char srcFileFixed[MAX_LOCATION];
2777 char potFile[MAX_LOCATION];
2779 ChangeExtension(objFile, "bowl", potFile);
2780 f = FileOpen(potFile, write);
2783 char * filePrefix = "";
2784 if(!(srcFile[0] && (srcFile[1] == ':' || srcFile[0] == '/')))
2785 filePrefix = (GetRuntimePlatform() == win32) ? ".\\" : "./";
2786 GetSystemPathBuffer(srcFileFixed, srcFile);
2787 for(s : intlStrings)
2789 // TOFIX: (#654) ContextStringPair * pair = &s;
2790 ContextStringPair pair = &s;
2792 f.Printf("#: %s%s:%d\n", filePrefix, srcFileFixed, l.start.line);
2793 // PoEdit now preserves and distinguish msgctxt
2795 f.Printf("msgctxt \"%s\"\n", pair.context);
2796 f.Printf("msgid \"%s\"\n", pair.string);
2797 f.Printf("msgstr \"%s\"\n\n", pair.string);
2805 default extern OldList * ast;
2806 default extern int yyparse ();
2808 public void SetAST(OldList * list) { ast = list; }
2809 public OldList * GetAST() { return ast; }
2810 public void ParseEc()