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 if(!curContext.templateTypes.Add((BTNode)type))
150 public TemplateParameter MkIdentifierTemplateParameter(Identifier identifier, TemplateMemberType memberType, TemplateArgument defaultArgument)
152 if(identifier.string)
154 TemplateParameter param { type = TemplateParameterType::identifier, identifier = identifier, memberType = memberType, defaultArgument = defaultArgument };
160 public TemplateParameter MkExpressionTemplateParameter(Identifier identifier, TemplateDatatype dataType, TemplateArgument defaultArgument)
162 if(identifier.string)
164 TemplateParameter param { type = TemplateParameterType::expression, identifier = identifier, dataType = dataType, defaultArgument = defaultArgument };
170 public TemplateDatatype MkTemplateDatatype(OldList * specifiers, Declarator decl)
172 TemplateDatatype datatype { specifiers = specifiers, decl = decl };
176 public TemplateArgument MkTemplateTypeArgument(TemplateDatatype tplDatatype)
178 TemplateArgument argument { type = type, templateDatatype = tplDatatype };
182 public TemplateArgument MkTemplateExpressionArgument(Expression expr)
184 TemplateArgument argument { type = expression, expression = expr };
188 public TemplateArgument MkTemplateIdentifierArgument(Identifier ident)
190 TemplateArgument argument { type = identifier, identifier = ident };
194 Expression MkExpExtensionCompound(Statement compound)
196 return { type = extensionCompoundExp, compound = compound };
199 Expression MkExpExtensionExpression(OldList * expressions)
201 return { type = extensionExpressionExp, list = expressions, loc = yylloc };
204 Expression MkExpExtensionInitializer(TypeName typeName, Initializer initializer)
206 return { type = extensionInitializerExp, initializer.typeName = typeName, initializer.initializer = initializer, loc = yylloc };
209 public Expression MkExpIdentifier(Identifier id)
211 return { type = identifierExp, identifier = id };
214 public Expression MkExpDummy()
216 Expression exp { type = dummyExp };
220 public Expression MkExpConstant(char * string)
222 return { type = constantExp, constant = CopyString(string) };
225 Expression MkExpString(char * string)
227 return { type = stringExp, string = CopyString(string) };
230 public struct ContextStringPair { String string, context; };
232 Map<ContextStringPair, List<Location> > intlStrings { };
234 Expression MkExpIntlString(char * string, char * context)
236 OldList * list = MkList();
239 ContextStringPair pair { };
241 int len = strlen(string);
243 pair.string = new byte[len-2+1]; memcpy(pair.string, string+1, len-2); pair.string[len-2] = '\0';
244 if(context) { len = strlen(context); pair.context = new byte[len-2+1]; memcpy(pair.context, context+1, len-2); pair.context[len-2] = '\0'; }
246 list = intlStrings[pair];
250 intlStrings[pair] = list;
259 ListAdd(list, QMkExpId("__thisModule"));
260 ListAdd(list, MkExpString(string));
263 int lenString = strlen(string), lenContext = strlen(context);
264 char * msgid = new char[lenString-2 + lenContext-2 + 4];
266 memcpy(msgid+1, context+1, lenContext-2);
267 msgid[1+lenContext-2] = 4; // EOT
268 memcpy(msgid+1+lenContext-2+1, string+1, lenString-2);
269 memcpy(msgid+1+lenContext-2+1+lenString-2, "\"", 2);
270 ListAdd(list, MkExpString(msgid));
273 ListAdd(list, QMkExpId("null"));
274 return MkExpCall(QMkExpId("GetTranslatedString"), list);
277 Expression MkExpOp(Expression exp1, int op, Expression exp2)
288 exp.loc.start = exp1 ? exp1.loc.start : exp2.loc.start;
289 exp.loc.end = exp2 ? exp2.loc.end : exp1.loc.end;
294 Expression MkExpBrackets(OldList expressions)
301 if(expressions && expressions.first)
303 exp.loc.start = ((Expression)expressions.first).loc.start;
304 exp.loc.end = ((Expression)expressions.last).loc.end;
309 Expression MkExpIndex(Expression expression, OldList index)
311 return { type = indexExp, index.exp = expression, index.index = index };
314 Expression MkExpCall(Expression expression, OldList arguments)
316 return { type = callExp, call.exp = expression, call.arguments = arguments };
319 Expression MkExpMember(Expression expression, Identifier member)
321 return { type = memberExp, member.exp = expression, member.member = member };
324 Expression MkExpPointer(Expression expression, Identifier member)
326 return { type = pointerExp, member.exp = expression, member.member = member };
329 Expression MkExpTypeSize(TypeName typeName)
331 return { type = typeSizeExp, typeName = typeName };
334 Expression MkExpClassSize(Specifier _class)
336 return { type = classSizeExp, _class = _class };
339 Expression MkExpCast(TypeName typeName, Expression expression)
341 return { type = castExp, cast.typeName = typeName, cast.exp = expression };
344 Expression MkExpCondition(Expression cond, OldList expressions, Expression elseExp)
346 return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp };
349 Expression MkExpRenew(Expression memExp, TypeName type, Expression size)
351 return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
354 Expression MkExpRenew0(Expression memExp, TypeName type, Expression size)
356 return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
359 Expression MkExpNew(TypeName type, Expression size)
361 return { type = newExp, _new.typeName = type, _new.size = size };
364 Expression MkExpNew0(TypeName type, Expression size)
366 return { type = new0Exp, _new.typeName = type, _new.size = size };
369 Expression MkExpVaArg(Expression exp, TypeName type)
371 return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type };
374 Specifier MkSpecifier(int specifier)
376 return { type = baseSpecifier, specifier = specifier };
379 Specifier MkSpecifierTypeOf(Expression expression)
381 return { type = typeOfSpecifier, expression = expression };
384 Specifier MkSpecifierSubClass(Specifier _class)
386 return { type = subClassSpecifier, _class = _class };
389 Specifier MkSpecifierExtended(char * name)
391 return { type = extendedSpecifier, name = CopyString(name) };
394 Specifier MkEnum(Identifier id, OldList list)
398 type = enumSpecifier;
402 if(list && (!declMode || !id))
408 type = ProcessType(&specs, null);
412 Symbol symbol { string = CopyString(id.string), isStruct = true, type = type };
414 if(strstr(symbol.string, "::"))
415 curContext.hasNameSpace = true;
416 if(!curContext.structSymbols.Add((BTNode)symbol))
419 for(e = list.first; e; e = e.next)
421 Symbol symbol { string = CopyString(e.id.string), type = type };
423 if(strstr(symbol.string, "::"))
424 curContext.hasNameSpace = true;
425 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
433 Specifier MkStructOrUnion(SpecifierType type, Identifier id, OldList definitions)
435 Specifier spec { type = type, id = id };
436 if(id && FindType(curContext, id.string))
437 declMode = defaultAccess;
438 spec.definitions = definitions;
439 if(definitions && id && !declMode)
444 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specs, null), isStruct = true };
445 if(!curContext.structSymbols.Add((BTNode)symbol))
451 void AddStructDefinitions(Specifier spec, OldList definitions)
453 spec.definitions = definitions;
454 if(definitions && spec.id && !declMode)
459 symbol = Symbol { string = CopyString(spec.id.string), type = ProcessType(specs, null), isStruct = true };
460 if(!curContext.parent.structSymbols.Add((BTNode)symbol))
465 public Declarator MkDeclaratorIdentifier(Identifier id)
467 return { type = identifierDeclarator, identifier = id };
470 Declarator MkDeclaratorFunction(Declarator declarator, OldList parameters)
472 return { type = functionDeclarator, declarator = declarator, function.parameters = parameters };
475 Declarator MkDeclaratorExtended(char * extended, Declarator declarator)
477 return { type = extendedDeclarator, declarator = declarator, extended.extended = extended };
480 Declarator MkDeclaratorExtendedEnd(char * extended, Declarator declarator)
482 return { type = extendedDeclaratorEnd, declarator = declarator, extended.extended = extended };
485 Declarator MkStructDeclarator(Declarator declarator, Expression exp)
487 return { type = structDeclarator, declarator = declarator, structDecl.exp = exp };
490 Declarator MkDeclaratorBrackets(Declarator declarator)
492 return { type = bracketsDeclarator, declarator = declarator };
495 Declarator MkDeclaratorArray(Declarator declarator, Expression exp)
497 return { type = arrayDeclarator, declarator = declarator, array.exp = exp };
500 Declarator MkDeclaratorEnumArray(Declarator declarator, Specifier _class)
502 return { type = arrayDeclarator, declarator = declarator, array.enumClass = _class };
505 Declarator MkDeclaratorPointer(Pointer pointer, Declarator declarator)
507 return { type = pointerDeclarator, declarator = declarator, pointer.pointer = pointer };
510 Enumerator MkEnumerator(Identifier id, Expression exp)
512 return { id = id, exp = exp };
515 Pointer MkPointer(OldList qualifiers, Pointer pointer)
517 return { qualifiers = qualifiers, pointer = pointer };
520 Initializer MkInitializerAssignment(Expression exp)
522 /*if(yylloc.start.line == 1)
524 return { type = expInitializer, exp = exp, loc = yylloc };
527 Initializer MkInitializerList(OldList list)
529 /*if(yylloc.start.line == 1)
531 return { type = listInitializer, list = list, loc = yylloc };
534 InitDeclarator MkInitDeclarator(Declarator declarator, Initializer initializer)
536 return { declarator = declarator, initializer = initializer };
539 public TypeName MkTypeName(OldList qualifiers, Declarator declarator)
541 return { qualifiers = qualifiers, declarator = declarator };
544 public Identifier GetDeclId(Declarator decl)
546 while(decl && decl.type != identifierDeclarator)
547 decl = decl.declarator;
548 return decl ? decl.identifier : null;
551 Declaration MkDeclarationClassInst(Instantiation inst)
553 return { type = instDeclaration, inst = inst, loc = yylloc };
556 Declaration MkDeclarationInst(Instantiation inst)
558 Declaration decl { type = instDeclaration, inst = inst, loc = yylloc };
560 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
563 int len = 0, stringLen;
566 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
567 len += defaultNameSpaceLen;
573 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
574 len += currentNameSpaceLen;
579 stringLen = strlen(inst.exp.identifier.string);
580 memcpy(name + len, inst.exp.identifier.string, stringLen);
583 delete inst.exp.identifier.string;
584 inst.exp.identifier.string = CopyString(name);
589 string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
590 type = MkClassTypeSymbol(inst._class.symbol);
592 symbol.idCode = symbol.id = curContext.nextID++;
593 if(strstr(symbol.string, "::"))
594 curContext.hasNameSpace = true;
595 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
596 excludedSymbols->Add(symbol);
597 decl.symbol = inst.symbol = symbol;
601 Declaration MkDeclarationDefine(Identifier id, Expression exp)
603 Declaration decl { type = defineDeclaration, id = id, exp = exp, loc = yylloc };
604 char expString[1024];
607 PrintExpression(exp, expString);
609 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
612 int len = 0, stringLen;
615 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
616 len += defaultNameSpaceLen;
622 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
623 len += currentNameSpaceLen;
627 stringLen = strlen(id.string);
628 memcpy(name + len, id.string, stringLen);
632 id.string = CopyString(name);
635 if(!eSystem_FindDefine(privateModule, id.string))
636 eSystem_RegisterDefine(id.string, expString, privateModule, buildingECERECOMModule ? baseSystemAccess : publicAccess);
638 Compiler_Warning("Redefinition of %s ignored\n", id.string);
642 Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
644 Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
645 bool variable = true;
647 if(specifiers != null)
650 for(spec = specifiers.first; spec; spec = spec.next)
652 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
654 if(initDeclarators != null)
658 for(d = initDeclarators.first; d; d = d.next)
660 if(GetDeclId(d.declarator).string)
664 string = CopyString(GetDeclId(d.declarator).string);
665 type = ProcessType(specifiers, d.declarator);
667 type.id = type.idCode = curContext.nextID++;
669 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
670 excludedSymbols->Add(type);
671 decl.symbol = d.declarator.symbol = type;
677 for(; spec; spec = spec.next)
679 if(spec.type == nameSpecifier && spec.name)
683 string = CopyString(spec.name);
684 type = ProcessType(specifiers, null);
686 type.id = type.idCode = curContext.nextID++;
687 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
688 excludedSymbols->Add(type);
697 else if(spec.type == baseSpecifier &&
698 (spec.specifier == STRUCT || spec.specifier == UNION))
702 if(variable && initDeclarators)
705 for(d = initDeclarators.first; d; d = d.next)
707 Identifier id = GetDeclId(d.declarator);
708 if(id && id.string && id.string[0])
714 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
717 int len = 0, stringLen;
720 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
721 len += defaultNameSpaceLen;
727 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
728 len += currentNameSpaceLen;
732 stringLen = strlen(id.string);
733 memcpy(name + len, id.string, stringLen);
737 id.string = CopyString(name);
740 // Avoid memory leaks on duplicated symbols (BinaryTree::Add Would Fail)
741 symbol = (Symbol)(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.FindString(id.string);
744 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specifiers, d.declarator) };
745 if(strstr(symbol.string, "::"))
746 curContext.hasNameSpace = true;
747 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
748 excludedSymbols->Add(symbol);
749 // TODO: Add better support to count declarators
750 if(symbol.type && symbol.type.kind == arrayType && !symbol.type.arraySizeExp && d.initializer)
752 if(d.initializer.type == listInitializer)
755 sprintf(string, "%d",d.initializer.list->count);
756 symbol.type.arraySizeExp = MkExpConstant(string);
757 symbol.type.freeExp = true;
759 else if(d.initializer.type == expInitializer && d.initializer.exp.type == stringExp && d.initializer.exp.string)
764 bool escaped = false;
765 char * s = d.initializer.exp.string;
767 // MAKE MORE ACCURATE
768 for(c = 1; (ch = s[c]); c++)
770 if(ch == '\\' && !escaped)
779 sprintf(string, "%d", count);
780 symbol.type.arraySizeExp = MkExpConstant(string);
781 symbol.type.freeExp = true;
784 symbol.id = symbol.idCode = curContext.nextID++;
786 decl.symbol = d.declarator.symbol = symbol;
793 decl.symbol = Symbol { };
794 decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
795 excludedSymbols->Add(decl.symbol);
800 Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifier extStorage)
802 return { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
805 Statement MkLabeledStmt(Identifier id, Statement statement)
807 return { type = labeledStmt, labeled.id = id, labeled.stmt = statement, loc = yylloc };
810 Statement MkCaseStmt(Expression exp, Statement statement)
812 return { type = caseStmt, caseStmt.exp = exp, caseStmt.stmt = statement, loc = yylloc };
815 Statement MkCompoundStmt(OldList declarations, OldList statements)
817 return { type = compoundStmt, compound.declarations = declarations, compound.statements = statements, loc = yylloc };
820 Statement MkExpressionStmt(OldList expressions)
822 return { type = expressionStmt, expressions = expressions, loc = yylloc };
825 Statement MkBadDeclStmt(Declaration decl)
827 return { type = badDeclarationStmt, decl = decl, loc = yylloc };
830 Statement MkIfStmt(OldList exp, Statement statement, Statement elseStmt)
832 return { type = ifStmt, ifStmt.exp = exp, ifStmt.stmt = statement, ifStmt.elseStmt = elseStmt, loc = yylloc };
835 Statement MkSwitchStmt(OldList exp, Statement statement)
837 // To know it's a switch compound... (Don't want declarations in there... bugs)
839 statement.compound.isSwitch = true;
840 return { type = switchStmt, switchStmt.exp = exp, switchStmt.stmt = statement, loc = yylloc };
843 Statement MkWhileStmt(OldList exp, Statement statement)
845 return { type = whileStmt, whileStmt.exp = exp, whileStmt.stmt = statement, loc = yylloc };
848 Statement MkDoWhileStmt(Statement statement, OldList exp)
850 return { type = doWhileStmt, doWhile.exp = exp, doWhile.stmt = statement, loc = yylloc };
853 Statement MkForStmt(Statement init, Statement check, OldList inc, Statement statement)
855 return { type = forStmt, forStmt.init = init, forStmt.check = check, forStmt.increment = inc, forStmt.stmt = statement, loc = yylloc };
858 Statement MkForEachStmt(Identifier id, OldList exp, OldList filter, Statement statement)
860 return { type = forEachStmt, forEachStmt.id = id, forEachStmt.exp = exp, forEachStmt.filter = filter, forEachStmt.stmt = statement, loc = yylloc };
863 Statement MkGotoStmt(Identifier id)
865 return { type = gotoStmt, gotoStmt.id = id, loc = yylloc };
868 Statement MkContinueStmt()
870 return { type = continueStmt, loc = yylloc };
873 Statement MkBreakStmt()
875 return { type = breakStmt, loc = yylloc };
878 Statement MkReturnStmt(OldList exp)
880 return { type = returnStmt, expressions = exp, loc = yylloc };
883 FunctionDefinition MkFunction(OldList specifiers, Declarator declarator, OldList declarationList)
885 return { specifiers = specifiers, declarator = declarator, declarations = declarationList };
888 void ProcessFunctionBody(FunctionDefinition func, Statement body)
890 Declarator declarator = func.declarator;
891 Declarator funcDecl = GetFuncDecl(declarator);
896 if(funcDecl && funcDecl.function.parameters && body)
898 Context context = body.compound.context;
900 for(param = funcDecl.function.parameters->first; param; param = param.next)
904 Symbol symbol = null;
905 Identifier id = GetDeclId(param.declarator);
906 char * string = id ? id.string : null;
909 for(symbol = (Symbol)context.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
910 if(!strcmp(symbol.string, string))
912 // This parameter is not shadowed by a local declaration
915 symbol = Symbol { string = CopyString(id.string), type = ProcessType(param.qualifiers, param.declarator), isParam = true };
916 if(!context.symbols.Add((BTNode)symbol))
917 excludedSymbols->Add(symbol);
919 // TODO: Fix this, the parameters' IDs should really be smaller...
920 symbol.id = context.nextID++;
921 param.declarator.symbol = symbol;
928 if(!declarator.symbol)
930 Identifier id = GetDeclId(declarator);
932 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess && strcmp(id.string, "__on_register_module"))
935 int len = 0, stringLen;
938 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
939 len += defaultNameSpaceLen;
945 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
946 len += currentNameSpaceLen;
950 stringLen = strlen(id.string);
951 memcpy(name + len, id.string, stringLen);
955 id.string = CopyString(name);
957 symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
958 symbol.idCode = symbol.id = globalContext.nextID++;
959 if(strstr(symbol.string, "::"))
960 globalContext.hasNameSpace = true;
961 if(!globalContext.symbols.Add((BTNode)symbol))
962 excludedSymbols->Add(symbol);
963 declarator.symbol = symbol;
967 symbol = declarator.symbol;
968 excludedSymbols->Remove(declarator.symbol);
969 delete symbol.string;
970 symbol.string = CopyString(GetDeclId(declarator).string);
971 if(strstr(symbol.string, "::"))
972 globalContext.hasNameSpace = true;
973 if(!globalContext.symbols.Add((BTNode)symbol))
974 excludedSymbols->Add(symbol);
977 symbol.type = ProcessType(func.specifiers, declarator);
979 if(symbol.type && (symbol.type.kind == functionType || symbol.type.kind == methodType))
981 if(!symbol.type.params.count)
983 Type type { refCount = 1 };
984 symbol.type.params.Add(type);
993 External MkExternalFunction(FunctionDefinition function)
995 External external { type = functionExternal, function = function, symbol = function.declarator.symbol };
996 if(function.specifiers)
999 for(spec = function.specifiers->first; spec; spec = spec.next)
1000 if(spec.type == baseSpecifier && spec.specifier == STATIC)
1002 declMode = staticAccess;
1007 if(external.symbol && !external.symbol.methodExternal)
1008 external.symbol.methodExternal = external;
1012 External MkExternalImport(char * name, ImportType importType, AccessMode importAccess)
1014 External external { type = importExternal };
1015 int len = strlen(name) - 2;
1016 external.importString = new char[len + 1];
1017 strncpy(external.importString, name+1, len);
1018 external.importString[len] = '\0';
1023 Time startTime = GetTime();
1026 ImportModule(external.importString, importType, importAccess, true);
1027 ImportModule(external.importString, importType, importAccess, false);
1029 time = GetTime() - startTime;
1030 printf("Importing took %.3f seconds for %s\n", time, external.importString);
1031 externalImportTotalTime += time;
1037 External MkExternalDeclaration(Declaration declaration)
1039 External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
1040 InitDeclarator d = (declaration && declaration.declarators) ? declaration.declarators->last : null;
1041 if(declaration && declaration.type == initDeclaration && declaration.specifiers)
1044 for(spec = declaration.specifiers->first; spec; spec = spec.next)
1045 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1047 declMode = defaultAccess;
1050 else if(spec.type == baseSpecifier && spec.specifier == STATIC)
1052 declMode = staticAccess;
1056 if(declaration && declaration.symbol && !declaration.symbol.methodExternal)
1057 declaration.symbol.methodExternal = external;
1061 External MkExternalNameSpace(Identifier identifier)
1063 External external { type = nameSpaceExternal, id = identifier };
1064 currentNameSpace = identifier ? identifier.string : null;
1065 currentNameSpaceLen = currentNameSpace ? strlen(currentNameSpace) : 0;
1069 void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
1071 if(spec.type == nameSpecifier)
1073 Symbol symbol = spec.symbol;
1074 spec.templateArgs = templateArgs;
1075 if(templateArgs && templateArgs.first)
1077 char templateString[1024];
1078 TemplateArgument arg;
1079 strcpy(templateString, symbol ? symbol.string : spec.name);
1080 strcat(templateString, "<");
1081 for(arg = templateArgs.first; arg; arg = arg.next)
1089 char expString[1024];
1090 Class backupThisClass = thisClass;
1092 expString[0] = '\0';
1093 // Will this work here?
1095 Location oldLocation = yylloc;
1096 File backFileInput = fileInput;
1101 // TESTING THIS SCANNER RESUME STUFF
1104 yylloc = oldLocation;
1105 fileInput = backFileInput;
1108 fileInput.Seek(yylloc.start.pos, start);
1109 resetScannerPos(&yylloc.start);
1114 //ProcessExpressionType(arg.expression);
1115 //ComputeExpression(arg.expression);
1116 PrintExpression(arg.expression, expString);
1117 strcat(argument, expString);
1118 thisClass = backupThisClass;
1123 strcat(argument, arg.identifier.string);
1128 char * typeString = StringFromSpecDecl(arg.templateDatatype.specifiers, arg.templateDatatype.decl);
1129 strcat(argument, typeString);
1136 if(arg.prev) strcat(templateString, ", ");
1139 strcat(templateString, arg.name.string);
1140 strcat(templateString, " = ");
1142 strcat(templateString, argument);
1146 int len = strlen(templateString);
1147 if(templateString[len-1] == '>') templateString[len++] = ' ';
1148 templateString[len++] = '>';
1149 templateString[len++] = '\0';
1151 // printf("SetClassTemplateArgs templateString: %s\n", templateString);
1152 symbol = FindClass(templateString);
1153 if(!symbol && spec.symbol)
1155 // If class was only decl'ed, invoke DeclClass on this templated class as well
1156 symbol = _DeclClass(MAXINT, templateString);
1158 // Add a reference to all templated class to the basic class
1160 spec.symbol.templatedClasses.Add(OldLink { data = symbol });
1162 spec.symbol = symbol;
1163 spec.name = CopyString(symbol ? symbol.string : templateString);
1167 FreeList(templateArgs, FreeTemplateArgument);
1170 Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
1172 Specifier spec { type = nameSpecifier };
1178 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
1181 spec.templateParameter = templatedType.param;
1182 spec.type = templateTypeSpecifier;
1186 symbol = FindClass(name);
1188 if(symbol && symbol.registered && symbol.registered.isRemote == 1)
1190 char className[1024];
1191 strcpy(className, "DCOMClient_");
1192 if(!strncmp(name, className, strlen(className)))
1193 spec.name = CopyString(name);
1196 strcat(className, name);
1197 spec.name = CopyString(className);
1201 spec.name = CopyString(symbol.string);
1203 spec.name = CopyString(name);
1204 spec.symbol = symbol;
1205 if(templateArgs != null)
1206 SetClassTemplateArgs(spec, templateArgs);
1211 public Specifier MkSpecifierName(char * name)
1213 return _MkSpecifierName(name, null, null);
1216 public Specifier MkSpecifierNameArgs(char * name, OldList * templateArgs)
1218 return _MkSpecifierName(name, null, templateArgs);
1222 Specifier MkClassName(char * string)
1224 return { type = SpecifierClass, name = CopyString(string) };
1227 ClassFunction MkClassFunction(OldList specifiers, Specifier _class, Declarator decl, OldList declList)
1229 return { specifiers = specifiers, /*_class = _class,*/ declarator = decl, declarations = declList };
1232 void ProcessClassFunctionBody(ClassFunction func, Statement body)
1236 Declarator decl = func.declarator;
1238 //Declarator decl = GetFuncDecl(func.declarator);
1239 Declarator funcDecl = GetFuncDecl(func.declarator);
1243 if(decl && !decl.symbol)
1245 OldList * symbolSpecs = MkList();
1247 // WHAT WILL WE DO WITH THIS? Double instances?
1248 //if(decl.function.parameters && body)
1249 if(funcDecl && funcDecl.function.parameters && body)
1251 Context context = body.compound.context;
1253 for(param = funcDecl.function.parameters->first; param; param = param.next)
1255 if(param.declarator)
1257 Symbol symbol = null;
1258 Identifier id = GetDeclId(param.declarator);
1259 char * string = id ? id.string : null;
1262 symbol = (Symbol)context.symbols.FindString(string);
1264 // This parameter is not shadowed by a local declaration
1269 string = CopyString(id.string);
1270 type = ProcessType(param.qualifiers, param.declarator);
1274 // TODO: Fix this, the parameters' IDs should really be smaller...
1275 symbol.idCode = symbol.id = context.nextID++;
1276 if(!context.symbols.Add((BTNode)symbol))
1277 excludedSymbols->Add(symbol);
1279 param.declarator.symbol = symbol;
1284 //////////////////////////////////
1292 Identifier id = GetDeclId(funcDecl);
1296 for(c = strlen(id.string)-1; c >= 0; c--)
1298 if(id.string[c] == ':')
1300 char * string = CopyString(id.string + c + 1);
1301 id.string[c - 1] = 0;
1302 id._class = MkSpecifierName(id.string);
1308 symbol.string = CopyString(id.string);
1315 for(spec = func.specifiers->first; spec; spec = spec.next)
1316 symbolSpecs->Add(CopySpecifier(spec));
1318 symbol.type = ProcessType(symbolSpecs, decl);
1319 symbol.idCode = symbol.id = globalContext.nextID++;
1320 decl.symbol = symbol;
1322 excludedSymbols->Add(symbol);
1324 FreeList(symbolSpecs, FreeSpecifier);
1328 OldList * MkSpecsClass(Specifier _class)
1330 OldList * list = MkList();
1331 ListAdd(list, _class);
1335 MemberInit MkMemberInit(OldList ids, Initializer initializer)
1337 return { identifiers = ids, initializer = initializer };
1340 MemberInit MkMemberInitExp(Expression idExp, Initializer initializer)
1342 MemberInit init { initializer = initializer, identifiers = MkList() };
1345 for(exp = idExp; exp && exp.type == memberExp; exp = exp.member.exp)
1347 init.identifiers->Insert(null, exp.member.member);
1348 exp.member.member = null;
1350 if(exp && exp.type == identifierExp)
1352 init.identifiers->Insert(null, exp.identifier);
1353 exp.identifier = null;
1355 FreeExpression(idExp);
1359 MembersInit MkMembersInitList(OldList dataMembers)
1361 return { type = dataMembersInit, dataMembers = dataMembers };
1364 MembersInit MkMembersInitMethod(ClassFunction function)
1366 return { type = methodMembersInit, function = function };
1369 Instantiation MkInstantiation(Specifier _class, Expression exp, OldList members)
1371 return { _class = _class, exp = exp, members = members };
1374 Instantiation MkInstantiationNamed(OldList specs, Expression exp, OldList members)
1376 Instantiation inst { exp = exp, members = members };
1381 for(spec = specs.first; spec; spec = spec.next)
1382 if(spec.type == nameSpecifier /*classSpecifier*/)
1389 FreeList(specs, FreeSpecifier);
1393 Compiler_Error("Expecting class specifier\n");
1394 inst._class = MkSpecifierName /*MkClassName*/("");
1402 ClassDef MkClassDefAccessOverride(AccessMode access, Identifier id)
1404 return { type = accessOverrideClassDef, id = id, memberAccess = access };
1407 ClassDef MkClassDefMemberAccess()
1409 return { type = memberAccessClassDef };
1412 ClassDef MkClassDefDeclaration(Declaration decl)
1414 return { type = declarationClassDef, decl = decl };
1417 ClassDef MkClassDefClassData(Declaration decl)
1419 return { type = classDataClassDef, decl = decl };
1422 ClassDef MkClassDefDesigner(char * designer)
1424 return { type = classDesignerClassDef, designer = CopyString(designer) };
1427 ClassDef MkClassDefNoExpansion()
1429 return { type = classNoExpansionClassDef };
1432 ClassDef MkClassDefFixed()
1434 return { type = classFixedClassDef };
1437 ClassDef MkClassDefDesignerDefaultProperty(Identifier id)
1439 return { type = designerDefaultPropertyClassDef, defaultProperty = id };
1442 ClassDef MkClassDefDefaultProperty(OldList defProperties)
1444 return { type = defaultPropertiesClassDef, defProperties = defProperties };
1447 ClassDef MkClassDefFunction(ClassFunction function)
1450 if(function && function.declarator)
1452 Declarator funcDecl = GetFuncDecl(function.declarator);
1453 if(funcDecl && funcDecl.declarator && funcDecl.declarator.type == bracketsDeclarator)
1455 def.type = declarationClassDef;
1456 def.decl = MkStructDeclaration(function.specifiers, MkListOne(MkStructDeclarator(function.declarator, null)), null);
1457 function.declarator = null;
1458 function.specifiers = null;
1459 FreeClassFunction(function);
1463 def.type = functionClassDef;
1464 def.function = function;
1468 Symbol DeclClassAddNameSpace(int symbolID, char * className)
1471 int len = 0, stringLen;
1473 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1475 if(defaultNameSpace)
1477 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1478 len += defaultNameSpaceLen;
1482 if(currentNameSpace)
1484 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1485 len += currentNameSpaceLen;
1490 stringLen = strlen(className);
1491 memcpy(name + len, className, stringLen);
1494 return _DeclClass(symbolID, name);
1497 Symbol DeclClass(int symbolID, char * name)
1499 if(strchr(name, ':'))
1500 return _DeclClass(symbolID, name);
1502 return DeclClassAddNameSpace(symbolID, name);
1505 Symbol _DeclClass(int symbolID, char * name)
1507 Symbol symbol = FindClass(name);
1511 Context classContext;
1512 for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
1518 if(name[0] == ':' && name[1] == ':')
1522 string = CopyString(name);
1523 idCode = symbolID, id = symbolID;
1525 if(!globalContext.classes.Add((BTNode)symbol))
1526 excludedSymbols->Add(symbol);
1531 for(c = 0; (ch = name[c]); c++)
1533 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
1539 if(start && c - start)
1540 symbol.shortName = CopyString(name + start);
1544 symbol.idCode = symbol.id = symbolID;
1548 void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
1550 if(baseSpecs && baseSpecs.first && ((Specifier)baseSpecs.first).type == nameSpecifier)
1555 strcpy(name, ((Specifier)baseSpecs.first).name);
1556 tpl = strchr(name, '<');
1559 baseClass = FindClass(name);
1563 for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
1565 TemplatedType type { key = copy.key, param = copy.param };
1566 if(!curContext.templateTypes.Add((BTNode)type))
1570 else if(baseClass.registered)
1573 for(sClass = baseClass.registered; sClass; sClass = sClass.base)
1575 ClassTemplateParameter p;
1576 for(p = sClass.templateParams.first; p; p = p.next)
1578 //OldList * specs = MkList();
1579 //Declarator decl = null;
1580 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
1583 TemplateParameter param = p.param;
1587 p.param = param = TemplateParameter
1589 identifier = MkIdentifier(p.name), type = p.type,
1590 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
1593 type = TemplatedType { key = (uint)p.name, param = param };
1594 if(!curContext.templateTypes.Add((BTNode)type))
1603 ClassDefinition MkClass(Symbol symbol, OldList baseSpecs, OldList definitions)
1605 ClassDefinition classDef;
1606 SetupBaseSpecs(symbol, baseSpecs);
1607 symbol.ctx = curContext;
1608 classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
1609 curContext.classDef = classDef;
1613 Expression MkExpInstance(Instantiation inst)
1615 return { type = instanceExp, instance = inst };
1618 External MkExternalClass(ClassDefinition _class)
1620 return { type = classExternal, _class = _class, symbol = _class.symbol };
1623 PropertyDef MkProperty(OldList specs, Declarator decl, Identifier id, Statement setStmt, Statement getStmt)
1633 Type type = ProcessType(specs, decl);
1636 char typeString[1024];
1637 typeString[0] = '\0';
1638 PrintType(type, typeString, false, true);
1639 id = MkIdentifier(typeString);
1640 prop.conversion = true;
1646 string = CopyString(id.string);
1649 symbol.idCode = symbol.id = globalContext.nextID++;
1650 excludedSymbols->Add(symbol);
1651 globalContext.nextID++;
1652 globalContext.nextID++;
1653 prop.symbol = symbol;
1657 ClassDef MkClassDefProperty(PropertyDef propertyDef)
1659 return { type = propertyClassDef, propertyDef = propertyDef };
1662 ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
1664 return { type = classPropertyClassDef, propertyDef = propertyDef };
1667 ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
1669 return { type = classPropertyValueClassDef, id = id, initializer = initializer };
1672 int CheckType(char * text)
1675 Time startTime = GetTime();
1677 if(FindTemplateTypeParameter(curContext, text))
1680 checkTypeTotalTime += GetTime() - startTime;
1684 if(FindType(curContext, text))
1687 checkTypeTotalTime += GetTime() - startTime;
1694 checkTypeTotalTime += GetTime() - startTime;
1696 return TYPE_NAME; //CLASS_NAME;
1699 checkTypeTotalTime += GetTime() - startTime;
1706 return CheckType(yytext);
1709 Context PushContext()
1711 Context ctx { parent = curContext };
1716 void PopContext(Context ctx)
1718 curContext = ctx.parent;
1721 Symbol FindType(Context ctx, char * name)
1726 type = (Symbol)ctx.types.FindString(name);
1727 if(!type && ctx.parent)
1728 type = FindType(ctx.parent, name);
1733 TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
1735 TemplatedType templatedType = null;
1738 templatedType = (TemplatedType)ctx.templateTypes.FindString(name);
1739 if(!templatedType && ctx.parent)
1740 templatedType = FindTemplateTypeParameter(ctx.parent, name);
1742 return templatedType;
1745 bool ModuleAccess(Module searchIn, Module searchFor)
1747 SubModule subModule;
1749 if(searchFor == searchIn)
1752 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
1754 if(subModule.importMode == publicAccess /*|| searchIn == searchIn.application*/)
1756 if(ModuleAccess(subModule.module, searchFor))
1763 ModuleImport FindModule(Module moduleToFind)
1765 ModuleImport module;
1766 if(!moduleToFind.name)
1768 for(module = imports->first; module; module = module.next)
1769 if(module.name && !strcmp(module.name, moduleToFind.name))
1773 module = ModuleImport
1775 name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
1776 importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
1778 imports->Add(module);
1784 // TO REMOVE: OBSOLETE...
1785 static void GetFullClassNameSpace(NameSpace * ns, char * name)
1789 GetFullClassNameSpace(ns->parent, name);
1790 strcat(name, ns->name);
1795 static char * GetFullClassName(Class c, char * name)
1797 NameSpace * nameSpace;
1799 GetFullClassNameSpace(c.nameSpace, name);
1800 strcat(name, c.name);
1805 public Symbol FindClass(char * name)
1808 Time startTime = GetTime();
1812 bool global = false;
1813 char fullName[1024];
1815 if(name[0] == ':' && name[1] == ':')
1821 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1823 int len = 0, stringLen;
1824 if(defaultNameSpace)
1826 memcpy(fullName, defaultNameSpace, defaultNameSpaceLen);
1827 len += defaultNameSpaceLen;
1828 fullName[len++] = ':';
1829 fullName[len++] = ':';
1831 if(currentNameSpace)
1833 memcpy(fullName + len, currentNameSpace, currentNameSpaceLen);
1834 len += currentNameSpaceLen;
1835 fullName[len++] = ':';
1836 fullName[len++] = ':';
1838 stringLen = strlen(name);
1839 memcpy(fullName + len, name, stringLen);
1842 cl = globalContext ? (Symbol)globalContext.classes.FindString(fullName) : null;
1846 cl = globalContext ? (Symbol)globalContext.classes.FindString(name) : null;
1851 Time startTime = GetTime();
1853 // Ignore name space name when searching
1854 for(cl = globalContext ? (Symbol)globalContext.classes.first : null; cl; cl = (Symbol)((BTNode)cl).next)
1858 char * string = cl.string;
1860 for(c = 0; (ch = string[c]); c++)
1862 if(ch == '.' || (ch == ':' && string[c+1] == ':'))
1868 if(start && c - start)
1870 if(!strcmp(string + start, name))
1874 if(cl.shortName && !strcmp(cl.shortName, name))
1878 findClassIgnoreNSTotalTime += GetTime() - startTime;
1884 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1885 _class = eSystem_FindClass(privateModule, fullName);
1887 _class = eSystem_FindClass(privateModule, name);
1891 name = _class.fullName;
1893 cl = (Symbol)globalContext.classes.FindString(name);
1898 string = CopyString(name);
1899 registered = _class;
1906 cl.module = FindModule(_class.module);
1908 cl.module = mainModule;
1909 if(!globalContext.classes.Add((BTNode)cl))
1910 excludedSymbols->Add(cl);
1911 if(strcmp(name, _class.name))
1912 cl.shortName = CopyString(_class.name);
1917 findClassTotalTime += GetTime() - startTime;
1922 void CopyTypeInto(Type type, Type src)
1925 type.name = CopyString(src.name);
1926 type.enumName = CopyString(src.enumName);
1929 if(src.kind == enumType)
1933 type.members.Clear();
1934 // This must have been a mistake: member = **type**.members.first
1935 for(member = src.members.first; member; member = member.next)
1937 type.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
1940 else if(src.kind == structType || src.kind == unionType)
1943 // Tricky stuff... will be removed from list only when ref count reaches 0
1944 for(member = type.members.first; member; member = member.next)
1947 else if(src.kind == functionType)
1950 type.returnType.refCount++;
1951 for(param = type.params.first; param; param = param.next)
1954 else if(src.kind == pointerType || src.kind == arrayType)
1956 type.type.refCount++;
1957 if(src.kind == arrayType)
1959 if(type.arraySizeExp)
1960 type.arraySizeExp = CopyExpression(type.arraySizeExp);
1966 public Type ProcessType(OldList specs, Declarator decl)
1969 bool isTypedef = false;
1970 if(!specs || specs.first)
1972 Declarator funcDecl = GetFuncDecl(decl);
1974 bool dllExport = false;
1976 specType.kind = intType;
1977 specType.isSigned = true;
1978 specType.refCount = 1;
1980 type = Type { refCount = 1 };
1982 while(decl && (decl.type == structDeclarator || decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd))
1984 if(decl.type == structDeclarator && decl.structDecl.exp)
1986 ProcessExpressionType(decl.structDecl.exp);
1987 ComputeExpression(decl.structDecl.exp);
1988 if(decl.structDecl.exp.type == constantExp)
1989 specType.bitFieldCount = strtoul(decl.structDecl.exp.constant, null, 0);
1991 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended &&
1992 (!strcmp(decl.extended.extended, "__declspec(dllexport)") || !strcmp(decl.extended.extended, "dllexport")))
1996 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended &&
1997 (strstr(decl.extended.extended, "__attribute__")))
1999 specType.keepCast = true;
2001 decl = decl.declarator;
2004 // If we'll be using the specType
2005 if(funcDecl || !decl || decl.type == identifierDeclarator)
2010 bool isLong = false;
2011 for(spec = specs.first; spec; spec = spec.next)
2013 if(spec.type == extendedSpecifier && (!strcmp(spec.name, "__declspec(dllexport)") || !strcmp(spec.name, "dllexport")))
2017 if(spec.type == extendedSpecifier && strstr(spec.name, "__attribute__"))
2019 specType.keepCast = true;
2022 if(spec.specifier != CONST && (specType.kind == structType || specType.kind == unionType))
2025 specType = { kind = intType, isSigned = true, refCount = 1 };
2028 if(spec.type == baseSpecifier)
2030 if(spec.specifier == TYPEDEF) isTypedef = true;
2031 else if(spec.specifier == VOID) specType.kind = voidType;
2032 else if(spec.specifier == CHAR) specType.kind = charType;
2033 else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
2034 else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
2035 else if(spec.specifier == INT64) specType.kind = int64Type;
2036 else if(spec.specifier == VALIST)
2037 specType.kind = vaListType;
2038 else if(spec.specifier == SHORT) specType.kind = shortType;
2039 else if(spec.specifier == LONG)
2042 specType.kind = int64Type;
2044 specType.kind = intType;
2046 // specType.kind = longType;
2048 else if(spec.specifier == FLOAT) specType.kind = floatType;
2049 else if(spec.specifier == DOUBLE) specType.kind = doubleType;
2050 else if(spec.specifier == SIGNED) specType.isSigned = true;
2051 else if(spec.specifier == UNSIGNED) specType.isSigned = false;
2052 else if(spec.specifier == CONST) specType.constant = true;
2053 else if(spec.specifier == TYPED_OBJECT)
2055 specType.classObjectType = typedObject; specType.kind = classType; specType._class = FindClass("class");
2057 else if(spec.specifier == ANY_OBJECT)
2059 specType.classObjectType = anyObject; specType.kind = classType; specType._class = FindClass("class");
2061 else if(spec.specifier == CLASS)
2063 specType.classObjectType = classPointer; specType.kind = classType; specType._class = FindClass("class");
2065 else if(spec.specifier == THISCLASS)
2066 specType.kind = thisClassType;
2068 else if(spec.type == nameSpecifier)
2070 Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
2071 if(symbol && symbol.type)
2073 // Free Type Contents:
2078 CopyTypeInto(specType, symbol.type);
2079 specType.typeName = CopyString(symbol.type.name);
2081 else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
2083 // key.sym enum values need FindClass:
2084 specType._class = spec.name ? FindClass(spec.name) : null;
2085 // specType._class = spec.symbol;
2086 specType.kind = classType;
2087 if(!specType._class)
2088 specType.kind = intType;
2091 else if(spec.type == enumSpecifier)
2094 specType.kind = enumType;
2095 specType.enumName = spec.id ? CopyString(spec.id.string) : null;
2101 for(e = spec.list->first; e; e = e.next)
2103 // TOFIX: NamedItem i { } causes cryptic error, bad .c!
2104 NamedLink i { name = CopyString(e.id.string) };
2105 specType.members.Add(i);
2107 if(e.exp && ComputeExpression(e.exp), e.exp.isConstant && e.exp.expType.kind == intType)
2108 value.data = (void *) nextValue = strtol(e.exp.string, null, 0);
2110 value.data = (void *)nextValue++;
2118 for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
2119 if(decl.declarators)
2122 for(d = decl.declarators.first; d; d = d.next)
2124 Type memberType = ProcessType(decl.specifiers, d);
2125 specType.members.Add(memberType);
2128 else if(decl.specifiers)
2130 Type memberType = ProcessType(decl.specifiers, null);
2131 specType.members.Add(memberType);
2136 else if(spec.type == templateTypeSpecifier)
2139 printf("spec %x\n", spec);
2140 printf("template param %x\n", spec.templateParameter);
2141 printf("identifier %x\n", spec.templateParameter.identifier);
2142 printf("string %x\n", spec.templateParameter.identifier.string);
2144 specType.kind = templateType;
2145 specType.templateParameter = spec.templateParameter;
2147 else if(spec.type == structSpecifier || spec.type == unionSpecifier)
2149 Symbol _class = spec.id ? FindClass(spec.id.string) : null;
2152 if(!_class.registered || _class.registered.type != structClass)
2153 specType.directClassAccess = true;
2154 specType._class = _class;
2155 specType.kind = classType;
2158 if(spec.type == structSpecifier)
2159 specType.kind = structType;
2160 else if(spec.type == unionSpecifier)
2161 specType.kind = unionType;
2164 // TESTING THIS HERE... Had 0 type size
2165 if(!spec.definitions && !isTypedef)
2167 Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
2168 if(symbol && symbol.type)
2170 specType = *symbol.type;
2171 specType.name = CopyString(symbol.type.name);
2172 specType.typeName = CopyString(spec.name);
2173 specType.enumName = CopyString(symbol.type.enumName);
2174 specType.refCount = 1;
2176 if(symbol.type.kind == enumType)
2180 specType.members.Clear();
2181 for(member = symbol.type.members.first; member; member = member.next)
2183 NamedLink item { name = CopyString(member.name), data = member.data };
2184 specType.members.Add(item);
2187 else if(symbol.type.kind == structType || symbol.type.kind == unionType)
2190 // Tricky stuff... will be removed from list only when ref count reaches 0
2191 for(member = specType.members.first; member; member = member.next)
2194 else if(symbol.type.kind == functionType)
2197 specType.returnType.refCount++;
2198 for(param = specType.params.first; param; param = param.next)
2201 else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
2203 specType.type.refCount++;
2204 if(symbol.type.kind == arrayType)
2206 if(specType.arraySizeExp)
2207 specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
2213 specType.enumName = CopyString(spec.id.string);
2216 specType.enumName = CopyString(spec.id.string);
2219 if(spec.definitions)
2222 for(def = spec.definitions->first; def; def = def.next)
2224 if(def.type == declarationClassDef && def.decl.type == structDeclaration)
2226 Declaration decl = def.decl;
2227 if(decl.declarators)
2230 for(d = decl.declarators->first; d; d = d.next)
2232 Type memberType = ProcessType(decl.specifiers, d);
2233 specType.members.Add(memberType);
2236 else if(decl.specifiers)
2238 Type memberType = ProcessType(decl.specifiers, null);
2239 specType.members.Add(memberType);
2246 else if(spec.type == subClassSpecifier)
2248 specType.kind = specType.kind = subClassType;
2249 specType._class = spec._class.symbol; // FindClass(spec._class.name);
2252 else if(spec.type == classSpecifier)
2254 specType._class = FindClass(spec.name);
2255 specType.kind = classType;
2261 specType.kind = ellipsisType;
2266 Declarator d = funcDecl.declarator;
2270 funcType.kind = functionType;
2271 funcType.refCount = 1;
2272 if(funcDecl.function.parameters)
2274 for(param = funcDecl.function.parameters->first; param; param = param.next)
2277 if(param.typedObject)
2279 Type typedObjectType
2282 byReference = param.byReference;
2283 kind = TypeTypedObject;
2285 funcType.params.Add(typedObjectType);
2288 funcType.params.Add(ProcessType(param.qualifiers, param.declarator));
2292 // Function returning a pointer...
2293 if(decl.type == pointerDeclarator)
2295 Pointer pointer = decl.pointer.pointer;
2297 funcType.returnType = ptrType;
2298 funcType.returnType.refCount = 1;
2301 ptrType.kind = pointerType;
2302 pointer = pointer.pointer;
2305 ptrType.type = Type { refCount = 1 };
2306 ptrType = ptrType.type;
2309 ptrType.type = Type { refCount = 1 };
2310 *ptrType.type = specType;
2314 funcType.returnType = Type { refCount = 1 };
2315 *funcType.returnType = specType;
2318 // TESTING: Added extendedDeclarator here
2319 while(d && (d.type == bracketsDeclarator || d.type == extendedDeclarator || d.type == extendedDeclaratorEnd))
2321 if((d.type == extendedDeclarator || d.type == extendedDeclaratorEnd) && d.extended.extended &&
2322 (!strcmp(d.extended.extended, "__declspec(dllexport)") || !strcmp(d.extended.extended, "dllexport")))
2329 funcType.dllExport = dllExport;
2331 if(d && d.type == pointerDeclarator)
2336 if(d.declarator && d.declarator.type == arrayDeclarator)
2338 // Arrays of pointers to functions (extremely tricky :()
2339 Pointer pointer = d.pointer.pointer;
2341 // TO WORK ON: Fixed the order for the array...
2342 type.kind = arrayType;
2343 type.arraySizeExp = CopyExpression(d.declarator.array.exp);
2344 type.freeExp = true;
2345 if(d.declarator.array.enumClass)
2346 type.enumClass = d.declarator.array.enumClass.symbol; // FindClass(d.declarator.array.enumClass.name);
2347 if(d.declarator.declarator && d.declarator.declarator.type == arrayDeclarator)
2349 Type tmpType = type;
2351 type = ProcessType(null, d.declarator.declarator);
2353 type.type = tmpType;
2354 tmpType.type = inType;
2357 type.type = ProcessType(null, d.declarator.declarator);
2359 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2363 ptrType.kind = pointerType;
2364 pointer = pointer.pointer;
2367 ptrType.type = Type { refCount = 1 };
2368 ptrType = ptrType.type;
2371 ptrType.type = ProcessType(specs, null);
2375 // WARNING: Not caring if this declarator contains a declarator between
2376 // the pointer and the function other than brackets (like in the case of array of pointers to functions)...
2377 // *********** Could it ever go in here??? Yes: void (* converters_table[10]) (); ***********
2378 Pointer pointer = d.pointer.pointer;
2383 ptrType.kind = pointerType;
2384 ptrType.type = Type { refCount = 1 };
2385 pointer = pointer.pointer;
2387 ptrType = ptrType.type;
2391 *ptrType.type = funcType;
2395 if(id._class && !id._class.name)
2396 ptrType.type.staticMethod = true;
2399 // TODO : Ensure classSym has been resolved here... (Is this gonna cause problems? Supposed to do this later...)
2402 if(id._class && id._class.name)
2404 id.classSym = id._class.symbol; // FindClass(id._class.name);
2405 /* TODO: Name Space Fix ups
2407 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
2412 ptrType.type.thisClass = id.classSym;
2413 if(ptrType.type.thisClass && strcmp(ptrType.type.thisClass.string, "class"))
2414 ptrType.type.extraParam = true;
2415 else if(id._class && id._class.name && !strcmp(id._class.name, "any_object"))
2417 ptrType.type.extraParam = true;
2418 ptrType.type.thisClass = FindClass("class");
2422 type.name = CopyString(id.string);
2425 else if(!d || d.type == identifierDeclarator)
2431 if(d.identifier._class && d.identifier._class.type == templateTypeSpecifier)
2433 type.thisClassTemplate = d.identifier._class.templateParameter;
2434 type.extraParam = true;
2438 if(d.identifier._class && !d.identifier._class.name)
2439 type.staticMethod = true;
2442 if(d.identifier._class && d.identifier._class.name && d.identifier._class.name[strlen(d.identifier._class.name)-1] == '&')
2444 type.thisClass = FindClass("class");
2445 type.byReference = true;
2448 type.thisClass = d.identifier._class ? d.identifier._class.symbol /*FindClass(d.identifier._class.name)*/ : null;
2449 if(type.thisClass && strcmp(type.thisClass.string, "class"))
2451 type.extraParam = true;
2453 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "any_object"))
2455 type.extraParam = true;
2456 type.thisClass = FindClass("class");
2458 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "class"))
2460 //type.extraParam = true;
2461 type.thisClass = FindClass("class");
2462 type.classObjectType = classPointer;
2466 type.name = CopyString(d.identifier.string);
2471 else if(decl && decl.type == pointerDeclarator)
2473 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2475 // Arrays of pointers (tricky :))
2477 Pointer pointer = decl.pointer.pointer;
2480 // TO WORK ON: Fixed the order for the array...
2481 type.kind = arrayType;
2482 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2483 type.freeExp = true;
2484 if(decl.declarator.array.enumClass)
2485 type.enumClass = decl.declarator.array.enumClass.symbol; // FindClass(decl.declarator.array.enumClass.name);
2486 if(decl.declarator.declarator && decl.declarator.declarator.type == arrayDeclarator)
2488 Type tmpType = type;
2490 type = ProcessType(null, decl.declarator.declarator);
2492 type.type = tmpType;
2493 tmpType.type = inType;
2496 type.type = ProcessType(null, decl.declarator.declarator);
2498 type.type = ProcessType(null, decl.declarator.declarator);
2499 type.kind = arrayType;
2500 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2501 type.arraySizeExp.freeExp = true;
2502 if(decl.array.enumClass)
2503 type.enumClass = FindClass(decl.array.enumClass.name);
2506 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2510 ptrType.kind = pointerType;
2511 pointer = pointer.pointer;
2514 ptrType.type = Type { refCount = 1 };
2515 ptrType = ptrType.type;
2518 ptrType.type = ProcessType(specs, null);
2519 id = GetDeclId(decl);
2520 if(id) type.name = CopyString(id.string);
2525 Pointer pointer = decl.pointer.pointer;
2526 Type ptrType = type;
2528 if(type.classObjectType)
2530 type.byReference = true;
2536 ptrType.kind = pointerType;
2537 pointer = pointer.pointer;
2540 ptrType.type = Type { refCount = 1 };
2541 ptrType = ptrType.type;
2544 ptrType.type = ProcessType(specs, decl.declarator);
2546 if(type.type.classObjectType)
2548 Type subType = type.type;
2549 type.classObjectType = subType.classObjectType;
2550 type.kind = subType.kind;
2551 type._class = subType._class;
2552 type.byReference = true;
2556 id = GetDeclId(decl);
2557 if(id) type.name = CopyString(id.string);
2561 else if(decl && decl.type == arrayDeclarator)
2565 type.kind = arrayType;
2567 type.arraySizeExp = CopyExpression(decl.array.exp);
2568 type.freeExp = true;
2569 if(decl.array.enumClass)
2570 type.enumClass = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
2571 id = GetDeclId(decl);
2573 // TO WORK ON: Fixed the order for the array...
2574 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2576 Type tmpType = type;
2578 type = ProcessType(specs, decl.declarator);
2580 type.type = tmpType;
2581 tmpType.type = inType;
2584 type.type = ProcessType(specs, decl.declarator);
2589 type.name = CopyString(id.string);
2594 if(!decl || decl.type == identifierDeclarator)
2598 type.name = decl ? CopyString(decl.identifier.string) : null;
2607 public Type ProcessTypeString(char * string, bool staticMethod)
2609 OldList * specs = MkList();
2610 Declarator decl = SpecDeclFromString(string, specs, null);
2611 Type type = ProcessType(specs, decl);
2612 if(type && !type.thisClass && staticMethod) type.staticMethod = true;
2613 FreeList(specs, FreeSpecifier);
2614 if(decl) FreeDeclarator(decl);
2618 Type MkClassTypeSymbol(Symbol symbol)
2622 Type type { kind = classType, _class = symbol };
2625 // Defaults to an int instead...
2626 type.kind = intType;
2634 public Type MkClassType(char * name)
2638 Type type { kind = classType, _class = FindClass(name) };
2641 // Defaults to an int instead...
2642 type.kind = intType;
2650 AsmField MkAsmField(char * command, Expression expression)
2652 return { command = command, expression = expression };
2655 Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
2657 return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
2658 asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
2659 asmStmt.clobberedFields = clobberedFields };
2662 ClassDef MkClassDefPropertyWatch(PropertyWatch watcher)
2664 return { type = propertyWatchClassDef, propertyWatch = watcher };
2667 Statement MkFireWatchersStmt(Expression object, OldList watches)
2669 return { type = fireWatchersStmt, _watch.object = object, _watch.watches = watches };
2672 Statement MkStopWatchingStmt(Expression watcher, Expression object, OldList watches)
2674 return { type = stopWatchingStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2677 Statement MkWatchStmt(Expression watcher, Expression object, OldList watches)
2679 return { type = watchStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2682 PropertyWatch MkDeleteWatch(Statement compound)
2684 return { compound = compound, deleteWatch = true };
2687 PropertyWatch MkPropertyWatch(OldList properties, Statement compound)
2689 return { compound = compound, properties = properties };
2692 Expression MkExpClass(OldList * specifiers, Declarator decl)
2694 return { type = classExp, _classExp.specifiers = specifiers, _classExp.decl = decl };
2697 Expression MkExpClassData(Identifier id)
2699 return { type = classDataExp, classData.id = id };
2703 External MkExternalDBTable(DBTableDef table)
2705 return { type = dbtableExternal, table = table };
2708 DBTableDef MkDBTableDef(char * name, Symbol symbol, OldList * definitions)
2710 return { name = name, symbol = symbol, definitions = definitions };
2713 DBTableEntry MkDBFieldEntry(TypeName type, Identifier id, char * name)
2715 return { type = fieldEntry, dataType = type, id = id, name = name };
2718 DBIndexItem MkDBIndexItem(Identifier id, Order order)
2720 return { id = id, order = order };
2723 DBTableEntry MkDBIndexEntry(OldList * items, Identifier id)
2725 return { type = indexEntry, items = items, id = id };
2728 Expression MkExpDBOpen(Expression ds, Expression dbName)
2730 return { type = dbopenExp, dbopen.ds = ds, dbopen.name = dbName };
2733 Expression MkExpDBField(char * table, Identifier id)
2735 return { type = dbfieldExp, db.table = table, db.id = id };
2738 Expression MkExpDBIndex(char * table, Identifier id)
2740 return { type = dbindexExp, db.table = table, db.id = id };
2743 Expression MkExpDBTable(char * table)
2745 return { type = dbtableExp, db.table = table };
2748 Expression MkExpArray(OldList * expressions)
2750 return { type = arrayExp, list = expressions };
2753 Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplateParameterType tplType)
2755 Expression argExp = null;
2756 Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
2760 ClassTemplateParameter curParam;
2762 for(sClass = _class; sClass; sClass = sClass.base)
2765 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2767 if(!strcmp(curParam.name, paramName))
2769 for(sClass = sClass.base; sClass; sClass = sClass.base)
2770 id += sClass.templateParams.count;
2778 if(curParam && curParam.type != tplType)
2784 char className[1024];
2785 Expression classExp;
2787 sprintf(idString, "%d", id);
2788 strcpy(className, "__ecereClass_");
2789 FullClassNameCat(className, _class.fullName, true);
2790 MangleClassName(className);
2791 DeclareClass(FindClass(_class.fullName), className);
2793 argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
2794 (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
2795 MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
2801 Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
2803 return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
2806 /*char * CreateMsgID(char * string, char * context)
2808 int lenString = strlen(string), lenContext = strlen(context);
2809 char * msgid = new char[lenString + lenContext + 20];
2810 memcpy(msgid, string, lenString);
2811 memcpy(msgid+lenString, " [msgctxt: ", 11);
2812 memcpy(msgid+lenString+11, context, lenContext);
2813 memcpy(msgid+lenString+11+lenContext, "]", 2);
2817 public void OutputIntlStrings()
2819 if(intlStrings.count)
2821 char * srcFile = GetSourceFile();
2822 char * objFile = GetOutputFile();
2823 char srcFileFixed[MAX_LOCATION];
2824 char potFile[MAX_LOCATION];
2826 ChangeExtension(objFile, "bowl", potFile);
2827 f = FileOpen(potFile, write);
2830 char * filePrefix = "";
2831 if(!(srcFile[0] && (srcFile[1] == ':' || srcFile[0] == '/')))
2832 filePrefix = (GetRuntimePlatform() == win32) ? ".\\" : "./";
2833 GetSystemPathBuffer(srcFileFixed, srcFile);
2834 for(s : intlStrings)
2836 // TOFIX: (#654) ContextStringPair * pair = &s;
2837 ContextStringPair pair = &s;
2839 f.Printf("#: %s%s:%d\n", filePrefix, srcFileFixed, l.start.line);
2840 // PoEdit now preserves and distinguish msgctxt
2842 f.Printf("msgctxt \"%s\"\n", pair.context);
2843 f.Printf("msgid \"%s\"\n", pair.string);
2844 f.Printf("msgstr \"%s\"\n\n", pair.string);
2852 default extern OldList * ast;
2853 default extern int yyparse ();
2855 public void SetAST(OldList * list) { ast = list; }
2856 public OldList * GetAST() { return ast; }
2857 public void ParseEc()