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 Map<String, Location> intlStrings { };
230 Expression MkExpIntlString(char * string)
234 MapIterator<String, Location> it { map = intlStrings };
235 if(!it.Index(string, false))
237 intlStrings[string] = yylloc;
240 return MkExpCall(QMkExpId("gettext"), MkListOne(MkExpString(string)));
243 Expression MkExpOp(Expression exp1, int op, Expression exp2)
254 exp.loc.start = exp1 ? exp1.loc.start : exp2.loc.start;
255 exp.loc.end = exp2 ? exp2.loc.end : exp1.loc.end;
260 Expression MkExpBrackets(OldList expressions)
267 if(expressions && expressions.first)
269 exp.loc.start = ((Expression)expressions.first).loc.start;
270 exp.loc.end = ((Expression)expressions.last).loc.end;
275 Expression MkExpIndex(Expression expression, OldList index)
277 return { type = indexExp, index.exp = expression, index.index = index };
280 Expression MkExpCall(Expression expression, OldList arguments)
282 return { type = callExp, call.exp = expression, call.arguments = arguments };
285 Expression MkExpMember(Expression expression, Identifier member)
287 return { type = memberExp, member.exp = expression, member.member = member };
290 Expression MkExpPointer(Expression expression, Identifier member)
292 return { type = pointerExp, member.exp = expression, member.member = member };
295 Expression MkExpTypeSize(TypeName typeName)
297 return { type = typeSizeExp, typeName = typeName };
300 Expression MkExpClassSize(Specifier _class)
302 return { type = classSizeExp, _class = _class };
305 Expression MkExpCast(TypeName typeName, Expression expression)
307 return { type = castExp, cast.typeName = typeName, cast.exp = expression };
310 Expression MkExpCondition(Expression cond, OldList expressions, Expression elseExp)
312 return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp };
315 Expression MkExpRenew(Expression memExp, TypeName type, Expression size)
317 return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
320 Expression MkExpRenew0(Expression memExp, TypeName type, Expression size)
322 return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
325 Expression MkExpNew(TypeName type, Expression size)
327 return { type = newExp, _new.typeName = type, _new.size = size };
330 Expression MkExpNew0(TypeName type, Expression size)
332 return { type = new0Exp, _new.typeName = type, _new.size = size };
335 Expression MkExpVaArg(Expression exp, TypeName type)
337 return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type };
340 Specifier MkSpecifier(int specifier)
342 return { type = baseSpecifier, specifier = specifier };
345 Specifier MkSpecifierTypeOf(Expression expression)
347 return { type = typeOfSpecifier, expression = expression };
350 Specifier MkSpecifierSubClass(Specifier _class)
352 return { type = subClassSpecifier, _class = _class };
355 Specifier MkSpecifierExtended(char * name)
357 return { type = extendedSpecifier, name = CopyString(name) };
360 Specifier MkEnum(Identifier id, OldList list)
364 type = enumSpecifier;
368 if(list && (!declMode || !id))
374 type = ProcessType(&specs, null);
378 curContext.structSymbols.Add((BTNode)Symbol { string = CopyString(id.string), isStruct = true, type = type });
381 for(e = list.first; e; e = e.next)
383 (curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)Symbol { string = CopyString(e.id.string), type = type });
391 Specifier MkStructOrUnion(SpecifierType type, Identifier id, OldList definitions)
393 Specifier spec { type = type, id = id };
394 if(id && FindType(curContext, id.string))
395 declMode = defaultAccess;
396 spec.definitions = definitions;
397 if(definitions && id && !declMode)
401 curContext.structSymbols.Add((BTNode)Symbol { string = CopyString(id.string), type = ProcessType(specs, null), isStruct = true });
406 void AddStructDefinitions(Specifier spec, OldList definitions)
408 spec.definitions = definitions;
409 if(definitions && spec.id && !declMode)
413 curContext.parent.structSymbols.Add((BTNode)Symbol { string = CopyString(spec.id.string), type = ProcessType(specs, null), isStruct = true });
417 public Declarator MkDeclaratorIdentifier(Identifier id)
419 return { type = identifierDeclarator, identifier = id };
422 Declarator MkDeclaratorFunction(Declarator declarator, OldList parameters)
424 return { type = functionDeclarator, declarator = declarator, function.parameters = parameters };
427 Declarator MkDeclaratorExtended(char * extended, Declarator declarator)
429 return { type = extendedDeclarator, declarator = declarator, extended.extended = extended };
432 Declarator MkDeclaratorExtendedEnd(char * extended, Declarator declarator)
434 return { type = extendedDeclaratorEnd, declarator = declarator, extended.extended = extended };
437 Declarator MkStructDeclarator(Declarator declarator, Expression exp)
439 return { type = structDeclarator, declarator = declarator, structDecl.exp = exp };
442 Declarator MkDeclaratorBrackets(Declarator declarator)
444 return { type = bracketsDeclarator, declarator = declarator };
447 Declarator MkDeclaratorArray(Declarator declarator, Expression exp)
449 return { type = arrayDeclarator, declarator = declarator, array.exp = exp };
452 Declarator MkDeclaratorEnumArray(Declarator declarator, Specifier _class)
454 return { type = arrayDeclarator, declarator = declarator, array.enumClass = _class };
457 Declarator MkDeclaratorPointer(Pointer pointer, Declarator declarator)
459 return { type = pointerDeclarator, declarator = declarator, pointer.pointer = pointer };
462 Enumerator MkEnumerator(Identifier id, Expression exp)
464 return { id = id, exp = exp };
467 Pointer MkPointer(OldList qualifiers, Pointer pointer)
469 return { qualifiers = qualifiers, pointer = pointer };
472 Initializer MkInitializerAssignment(Expression exp)
474 /*if(yylloc.start.line == 1)
476 return { type = expInitializer, exp = exp, loc = yylloc };
479 Initializer MkInitializerList(OldList list)
481 /*if(yylloc.start.line == 1)
483 return { type = listInitializer, list = list, loc = yylloc };
486 InitDeclarator MkInitDeclarator(Declarator declarator, Initializer initializer)
488 return { declarator = declarator, initializer = initializer };
491 public TypeName MkTypeName(OldList qualifiers, Declarator declarator)
493 return { qualifiers = qualifiers, declarator = declarator };
496 public Identifier GetDeclId(Declarator decl)
498 while(decl && decl.type != identifierDeclarator)
499 decl = decl.declarator;
500 return decl ? decl.identifier : null;
503 Declaration MkDeclarationClassInst(Instantiation inst)
505 return { type = instDeclaration, inst = inst, loc = yylloc };
508 Declaration MkDeclarationInst(Instantiation inst)
510 Declaration decl { type = instDeclaration, inst = inst, loc = yylloc };
512 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
515 int len = 0, stringLen;
518 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
519 len += defaultNameSpaceLen;
525 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
526 len += currentNameSpaceLen;
531 stringLen = strlen(inst.exp.identifier.string);
532 memcpy(name + len, inst.exp.identifier.string, stringLen);
535 delete inst.exp.identifier.string;
536 inst.exp.identifier.string = CopyString(name);
541 string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
542 type = MkClassTypeSymbol(inst._class.symbol);
544 symbol.idCode = symbol.id = curContext.nextID++;
545 (curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol);
546 decl.symbol = inst.symbol = symbol;
550 Declaration MkDeclarationDefine(Identifier id, Expression exp)
552 Declaration decl { type = defineDeclaration, id = id, exp = exp, loc = yylloc };
553 char expString[1024];
556 PrintExpression(exp, expString);
558 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
561 int len = 0, stringLen;
564 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
565 len += defaultNameSpaceLen;
571 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
572 len += currentNameSpaceLen;
576 stringLen = strlen(id.string);
577 memcpy(name + len, id.string, stringLen);
581 id.string = CopyString(name);
584 if(!eSystem_FindDefine(privateModule, id.string))
585 eSystem_RegisterDefine(id.string, expString, privateModule, buildingECERECOMModule ? baseSystemAccess : publicAccess);
587 Compiler_Warning("Redefinition of %s ignored\n", id.string);
591 Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
593 Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
594 bool variable = true;
596 if(specifiers != null)
599 for(spec = specifiers.first; spec; spec = spec.next)
601 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
603 if(initDeclarators != null)
607 for(d = initDeclarators.first; d; d = d.next)
609 if(GetDeclId(d.declarator).string)
613 string = CopyString(GetDeclId(d.declarator).string);
614 type = ProcessType(specifiers, d.declarator);
616 type.id = type.idCode = curContext.nextID++;
618 (curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type);
619 decl.symbol = d.declarator.symbol = type;
625 for(; spec; spec = spec.next)
627 if(spec.type == nameSpecifier && spec.name)
631 string = CopyString(spec.name);
632 type = ProcessType(specifiers, null);
634 type.id = type.idCode = curContext.nextID++;
635 (curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type);
643 else if(spec.type == baseSpecifier &&
644 (spec.specifier == STRUCT || spec.specifier == UNION))
648 if(variable && initDeclarators)
651 for(d = initDeclarators.first; d; d = d.next)
653 Identifier id = GetDeclId(d.declarator);
654 if(id && id.string && id.string[0])
660 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
663 int len = 0, stringLen;
666 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
667 len += defaultNameSpaceLen;
673 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
674 len += currentNameSpaceLen;
678 stringLen = strlen(id.string);
679 memcpy(name + len, id.string, stringLen);
683 id.string = CopyString(name);
686 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specifiers, d.declarator) };
687 (curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol);
688 // TODO: Add better support to count declarators
689 if(symbol.type && symbol.type.kind == arrayType && !symbol.type.arraySizeExp && d.initializer)
691 if(d.initializer.type == listInitializer)
694 sprintf(string, "%d",d.initializer.list->count);
695 symbol.type.arraySizeExp = MkExpConstant(string);
696 symbol.type.freeExp = true;
698 else if(d.initializer.type == expInitializer && d.initializer.exp.type == stringExp && d.initializer.exp.string)
703 bool escaped = false;
704 char * s = d.initializer.exp.string;
706 // MAKE MORE ACCURATE
707 for(c = 1; (ch = s[c]); c++)
709 if(ch == '\\' && !escaped)
718 sprintf(string, "%d", count);
719 symbol.type.arraySizeExp = MkExpConstant(string);
720 symbol.type.freeExp = true;
723 symbol.id = symbol.idCode = curContext.nextID++;
724 decl.symbol = d.declarator.symbol = symbol;
731 decl.symbol = Symbol { };
732 decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
733 excludedSymbols->Add(decl.symbol);
738 Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifier extStorage)
740 return { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
743 Statement MkLabeledStmt(Identifier id, Statement statement)
745 return { type = labeledStmt, labeled.id = id, labeled.stmt = statement, loc = yylloc };
748 Statement MkCaseStmt(Expression exp, Statement statement)
750 return { type = caseStmt, caseStmt.exp = exp, caseStmt.stmt = statement, loc = yylloc };
753 Statement MkCompoundStmt(OldList declarations, OldList statements)
755 return { type = compoundStmt, compound.declarations = declarations, compound.statements = statements, loc = yylloc };
758 Statement MkExpressionStmt(OldList expressions)
760 return { type = expressionStmt, expressions = expressions, loc = yylloc };
763 Statement MkBadDeclStmt(Declaration decl)
765 return { type = badDeclarationStmt, decl = decl, loc = yylloc };
768 Statement MkIfStmt(OldList exp, Statement statement, Statement elseStmt)
770 return { type = ifStmt, ifStmt.exp = exp, ifStmt.stmt = statement, ifStmt.elseStmt = elseStmt, loc = yylloc };
773 Statement MkSwitchStmt(OldList exp, Statement statement)
775 // To know it's a switch compound... (Don't want declarations in there... bugs)
777 statement.compound.isSwitch = true;
778 return { type = switchStmt, switchStmt.exp = exp, switchStmt.stmt = statement, loc = yylloc };
781 Statement MkWhileStmt(OldList exp, Statement statement)
783 return { type = whileStmt, whileStmt.exp = exp, whileStmt.stmt = statement, loc = yylloc };
786 Statement MkDoWhileStmt(Statement statement, OldList exp)
788 return { type = doWhileStmt, doWhile.exp = exp, doWhile.stmt = statement, loc = yylloc };
791 Statement MkForStmt(Statement init, Statement check, OldList inc, Statement statement)
793 return { type = forStmt, forStmt.init = init, forStmt.check = check, forStmt.increment = inc, forStmt.stmt = statement, loc = yylloc };
796 Statement MkForEachStmt(Identifier id, OldList exp, OldList filter, Statement statement)
798 return { type = forEachStmt, forEachStmt.id = id, forEachStmt.exp = exp, forEachStmt.filter = filter, forEachStmt.stmt = statement, loc = yylloc };
801 Statement MkGotoStmt(Identifier id)
803 return { type = gotoStmt, gotoStmt.id = id, loc = yylloc };
806 Statement MkContinueStmt()
808 return { type = continueStmt, loc = yylloc };
811 Statement MkBreakStmt()
813 return { type = breakStmt, loc = yylloc };
816 Statement MkReturnStmt(OldList exp)
818 return { type = returnStmt, expressions = exp, loc = yylloc };
821 FunctionDefinition MkFunction(OldList specifiers, Declarator declarator, OldList declarationList)
823 return { specifiers = specifiers, declarator = declarator, declarations = declarationList };
826 void ProcessFunctionBody(FunctionDefinition func, Statement body)
828 Declarator declarator = func.declarator;
829 Declarator funcDecl = GetFuncDecl(declarator);
834 if(funcDecl && funcDecl.function.parameters && body)
836 Context context = body.compound.context;
838 for(param = funcDecl.function.parameters->first; param; param = param.next)
842 Symbol symbol = null;
843 Identifier id = GetDeclId(param.declarator);
844 char * string = id ? id.string : null;
847 for(symbol = (Symbol)context.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
848 if(!strcmp(symbol.string, string))
850 // This parameter is not shadowed by a local declaration
853 symbol = Symbol { string = CopyString(id.string), type = ProcessType(param.qualifiers, param.declarator), isParam = true };
854 context.symbols.Add((BTNode)symbol);
856 // TODO: Fix this, the parameters' IDs should really be smaller...
857 symbol.id = context.nextID++;
858 param.declarator.symbol = symbol;
865 if(!declarator.symbol)
867 Identifier id = GetDeclId(declarator);
869 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess && strcmp(id.string, "__on_register_module"))
872 int len = 0, stringLen;
875 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
876 len += defaultNameSpaceLen;
882 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
883 len += currentNameSpaceLen;
887 stringLen = strlen(id.string);
888 memcpy(name + len, id.string, stringLen);
892 id.string = CopyString(name);
894 symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
895 symbol.idCode = symbol.id = globalContext.nextID++;
896 globalContext.symbols.Add((BTNode)symbol);
897 declarator.symbol = symbol;
901 symbol = declarator.symbol;
902 excludedSymbols->Remove(declarator.symbol);
903 delete symbol.string;
904 symbol.string = CopyString(GetDeclId(declarator).string);
905 globalContext.symbols.Add((BTNode)symbol);
908 symbol.type = ProcessType(func.specifiers, declarator);
910 if(symbol.type && (symbol.type.kind == functionType || symbol.type.kind == methodType))
912 if(!symbol.type.params.count)
914 Type type { refCount = 1 };
915 symbol.type.params.Add(type);
924 External MkExternalFunction(FunctionDefinition function)
926 External external { type = functionExternal, function = function, symbol = function.declarator.symbol };
927 if(function.specifiers)
930 for(spec = function.specifiers->first; spec; spec = spec.next)
931 if(spec.type == baseSpecifier && spec.specifier == STATIC)
933 declMode = staticAccess;
938 if(external.symbol && !external.symbol.methodExternal)
939 external.symbol.methodExternal = external;
943 External MkExternalImport(char * name, ImportType importType, AccessMode importAccess)
945 External external { type = importExternal };
946 int len = strlen(name) - 2;
947 external.importString = new char[len + 1];
948 strncpy(external.importString, name+1, len);
949 external.importString[len] = '\0';
954 Time startTime = GetTime();
957 ImportModule(external.importString, importType, importAccess, true);
958 ImportModule(external.importString, importType, importAccess, false);
960 time = GetTime() - startTime;
961 printf("Importing took %.3f seconds for %s\n", time, external.importString);
962 externalImportTotalTime += time;
968 External MkExternalDeclaration(Declaration declaration)
970 External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
971 InitDeclarator d = (declaration && declaration.declarators) ? declaration.declarators->last : null;
972 if(declaration && declaration.type == initDeclaration && declaration.specifiers)
975 for(spec = declaration.specifiers->first; spec; spec = spec.next)
976 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
978 declMode = defaultAccess;
981 else if(spec.type == baseSpecifier && spec.specifier == STATIC)
983 declMode = staticAccess;
987 if(declaration && declaration.symbol && !declaration.symbol.methodExternal)
988 declaration.symbol.methodExternal = external;
992 External MkExternalNameSpace(Identifier identifier)
994 External external { type = nameSpaceExternal, id = identifier };
995 currentNameSpace = identifier ? identifier.string : null;
996 currentNameSpaceLen = currentNameSpace ? strlen(currentNameSpace) : 0;
1000 void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
1002 if(spec.type == nameSpecifier)
1004 Symbol symbol = spec.symbol;
1005 spec.templateArgs = templateArgs;
1006 if(templateArgs && templateArgs.first)
1008 char templateString[1024];
1009 TemplateArgument arg;
1010 strcpy(templateString, symbol ? symbol.string : spec.name);
1011 strcat(templateString, "<");
1012 for(arg = templateArgs.first; arg; arg = arg.next)
1020 char expString[1024];
1021 Class backupThisClass = thisClass;
1023 expString[0] = '\0';
1024 // Will this work here?
1026 Location oldLocation = yylloc;
1027 File backFileInput = fileInput;
1032 // TESTING THIS SCANNER RESUME STUFF
1035 yylloc = oldLocation;
1036 fileInput = backFileInput;
1039 fileInput.Seek(yylloc.start.pos, start);
1040 resetScannerPos(&yylloc.start);
1045 //ProcessExpressionType(arg.expression);
1046 //ComputeExpression(arg.expression);
1047 PrintExpression(arg.expression, expString);
1048 strcat(argument, expString);
1049 thisClass = backupThisClass;
1054 strcat(argument, arg.identifier.string);
1059 char * typeString = StringFromSpecDecl(arg.templateDatatype.specifiers, arg.templateDatatype.decl);
1060 strcat(argument, typeString);
1067 if(arg.prev) strcat(templateString, ", ");
1070 strcat(templateString, arg.name.string);
1071 strcat(templateString, " = ");
1073 strcat(templateString, argument);
1077 int len = strlen(templateString);
1078 if(templateString[len-1] == '>') templateString[len++] = ' ';
1079 templateString[len++] = '>';
1080 templateString[len++] = '\0';
1082 // printf("SetClassTemplateArgs templateString: %s\n", templateString);
1083 symbol = FindClass(templateString);
1084 if(!symbol && spec.symbol)
1086 // If class was only decl'ed, invoke DeclClass on this templated class as well
1087 symbol = _DeclClass(MAXINT, templateString);
1089 // Add a reference to all templated class to the basic class
1091 spec.symbol.templatedClasses.Add(OldLink { data = symbol });
1093 spec.symbol = symbol;
1094 spec.name = CopyString(symbol ? symbol.string : templateString);
1098 FreeList(templateArgs, FreeTemplateArgument);
1101 Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
1103 Specifier spec { type = nameSpecifier };
1109 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
1112 spec.templateParameter = templatedType.param;
1113 spec.type = templateTypeSpecifier;
1117 symbol = FindClass(name);
1119 if(symbol && symbol.registered && symbol.registered.isRemote == 1)
1121 char className[1024];
1122 strcpy(className, "DCOMClient_");
1123 if(!strncmp(name, className, strlen(className)))
1124 spec.name = CopyString(name);
1127 strcat(className, name);
1128 spec.name = CopyString(className);
1132 spec.name = CopyString(symbol.string);
1134 spec.name = CopyString(name);
1135 spec.symbol = symbol;
1136 if(templateArgs != null)
1137 SetClassTemplateArgs(spec, templateArgs);
1142 public Specifier MkSpecifierName(char * name)
1144 return _MkSpecifierName(name, null, null);
1147 public Specifier MkSpecifierNameArgs(char * name, OldList * templateArgs)
1149 return _MkSpecifierName(name, null, templateArgs);
1153 Specifier MkClassName(char * string)
1155 return { type = SpecifierClass, name = CopyString(string) };
1158 ClassFunction MkClassFunction(OldList specifiers, Specifier _class, Declarator decl, OldList declList)
1160 return { specifiers = specifiers, /*_class = _class,*/ declarator = decl, declarations = declList };
1163 void ProcessClassFunctionBody(ClassFunction func, Statement body)
1167 Declarator decl = func.declarator;
1169 //Declarator decl = GetFuncDecl(func.declarator);
1170 Declarator funcDecl = GetFuncDecl(func.declarator);
1174 if(decl && !decl.symbol)
1176 OldList * symbolSpecs = MkList();
1178 // WHAT WILL WE DO WITH THIS? Double instances?
1179 //if(decl.function.parameters && body)
1180 if(funcDecl && funcDecl.function.parameters && body)
1182 Context context = body.compound.context;
1184 for(param = funcDecl.function.parameters->first; param; param = param.next)
1186 if(param.declarator)
1188 Symbol symbol = null;
1189 Identifier id = GetDeclId(param.declarator);
1190 char * string = id ? id.string : null;
1193 symbol = (Symbol)context.symbols.FindString(string);
1195 // This parameter is not shadowed by a local declaration
1200 string = CopyString(id.string);
1201 type = ProcessType(param.qualifiers, param.declarator);
1205 // TODO: Fix this, the parameters' IDs should really be smaller...
1206 symbol.idCode = symbol.id = context.nextID++;
1207 context.symbols.Add((BTNode)symbol);
1209 param.declarator.symbol = symbol;
1214 //////////////////////////////////
1222 Identifier id = GetDeclId(funcDecl);
1226 for(c = strlen(id.string)-1; c >= 0; c--)
1228 if(id.string[c] == ':')
1230 char * string = CopyString(id.string + c + 1);
1231 id.string[c - 1] = 0;
1232 id._class = MkSpecifierName(id.string);
1238 symbol.string = CopyString(id.string);
1245 for(spec = func.specifiers->first; spec; spec = spec.next)
1246 symbolSpecs->Add(CopySpecifier(spec));
1248 symbol.type = ProcessType(symbolSpecs, decl);
1249 symbol.idCode = symbol.id = globalContext.nextID++;
1250 decl.symbol = symbol;
1252 excludedSymbols->Add(symbol);
1254 FreeList(symbolSpecs, FreeSpecifier);
1258 OldList * MkSpecsClass(Specifier _class)
1260 OldList * list = MkList();
1261 ListAdd(list, _class);
1265 MemberInit MkMemberInit(OldList ids, Initializer initializer)
1267 return { identifiers = ids, initializer = initializer };
1270 MemberInit MkMemberInitExp(Expression idExp, Initializer initializer)
1272 MemberInit init { initializer = initializer, identifiers = MkList() };
1275 for(exp = idExp; exp && exp.type == memberExp; exp = exp.member.exp)
1277 init.identifiers->Insert(null, exp.member.member);
1278 exp.member.member = null;
1280 if(exp && exp.type == identifierExp)
1282 init.identifiers->Insert(null, exp.identifier);
1283 exp.identifier = null;
1285 FreeExpression(idExp);
1289 MembersInit MkMembersInitList(OldList dataMembers)
1291 return { type = dataMembersInit, dataMembers = dataMembers };
1294 MembersInit MkMembersInitMethod(ClassFunction function)
1296 return { type = methodMembersInit, function = function };
1299 Instantiation MkInstantiation(Specifier _class, Expression exp, OldList members)
1301 return { _class = _class, exp = exp, members = members };
1304 Instantiation MkInstantiationNamed(OldList specs, Expression exp, OldList members)
1306 Instantiation inst { exp = exp, members = members };
1311 for(spec = specs.first; spec; spec = spec.next)
1312 if(spec.type == nameSpecifier /*classSpecifier*/)
1319 FreeList(specs, FreeSpecifier);
1323 Compiler_Error("Expecting class specifier\n");
1324 inst._class = MkSpecifierName /*MkClassName*/("");
1332 ClassDef MkClassDefAccessOverride(AccessMode access, Identifier id)
1334 return { type = accessOverrideClassDef, id = id, memberAccess = access };
1337 ClassDef MkClassDefMemberAccess()
1339 return { type = memberAccessClassDef };
1342 ClassDef MkClassDefDeclaration(Declaration decl)
1344 return { type = declarationClassDef, decl = decl };
1347 ClassDef MkClassDefClassData(Declaration decl)
1349 return { type = classDataClassDef, decl = decl };
1352 ClassDef MkClassDefDesigner(char * designer)
1354 return { type = classDesignerClassDef, designer = CopyString(designer) };
1357 ClassDef MkClassDefNoExpansion()
1359 return { type = classNoExpansionClassDef };
1362 ClassDef MkClassDefFixed()
1364 return { type = classFixedClassDef };
1367 ClassDef MkClassDefDesignerDefaultProperty(Identifier id)
1369 return { type = designerDefaultPropertyClassDef, defaultProperty = id };
1372 ClassDef MkClassDefDefaultProperty(OldList defProperties)
1374 return { type = defaultPropertiesClassDef, defProperties = defProperties };
1377 ClassDef MkClassDefFunction(ClassFunction function)
1380 if(function && function.declarator)
1382 Declarator funcDecl = GetFuncDecl(function.declarator);
1383 if(funcDecl && funcDecl.declarator && funcDecl.declarator.type == bracketsDeclarator)
1385 def.type = declarationClassDef;
1386 def.decl = MkStructDeclaration(function.specifiers, MkListOne(MkStructDeclarator(function.declarator, null)), null);
1387 function.declarator = null;
1388 function.specifiers = null;
1389 FreeClassFunction(function);
1393 def.type = functionClassDef;
1394 def.function = function;
1398 Symbol DeclClassAddNameSpace(int symbolID, char * className)
1401 int len = 0, stringLen;
1403 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1405 if(defaultNameSpace)
1407 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1408 len += defaultNameSpaceLen;
1412 if(currentNameSpace)
1414 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1415 len += currentNameSpaceLen;
1420 stringLen = strlen(className);
1421 memcpy(name + len, className, stringLen);
1424 return _DeclClass(symbolID, name);
1427 Symbol DeclClass(int symbolID, char * name)
1429 if(strchr(name, ':'))
1430 return _DeclClass(symbolID, name);
1432 return DeclClassAddNameSpace(symbolID, name);
1435 Symbol _DeclClass(int symbolID, char * name)
1437 Symbol symbol = FindClass(name);
1441 Context classContext;
1442 for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
1448 if(name[0] == ':' && name[1] == ':')
1452 string = CopyString(name);
1453 idCode = symbolID, id = symbolID;
1455 globalContext.classes.Add((BTNode)symbol);
1460 for(c = 0; (ch = name[c]); c++)
1462 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
1468 if(start && c - start)
1469 symbol.shortName = CopyString(name + start);
1473 symbol.idCode = symbol.id = symbolID;
1477 void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
1479 if(baseSpecs && baseSpecs.first && ((Specifier)baseSpecs.first).type == nameSpecifier)
1484 strcpy(name, ((Specifier)baseSpecs.first).name);
1485 tpl = strchr(name, '<');
1488 baseClass = FindClass(name);
1492 for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
1494 TemplatedType type { key = copy.key, param = copy.param };
1495 curContext.templateTypes.Add((BTNode)type);
1498 else if(baseClass.registered)
1501 for(sClass = baseClass.registered; sClass; sClass = sClass.base)
1503 ClassTemplateParameter p;
1504 for(p = sClass.templateParams.first; p; p = p.next)
1506 //OldList * specs = MkList();
1507 //Declarator decl = null;
1508 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
1511 TemplateParameter param = p.param;
1515 p.param = param = TemplateParameter
1517 identifier = MkIdentifier(p.name), type = p.type,
1518 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
1521 type = TemplatedType { key = (uint)p.name, param = param };
1522 curContext.templateTypes.Add((BTNode)type);
1530 ClassDefinition MkClass(Symbol symbol, OldList baseSpecs, OldList definitions)
1532 ClassDefinition classDef;
1533 SetupBaseSpecs(symbol, baseSpecs);
1534 symbol.ctx = curContext;
1535 classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
1536 curContext.classDef = classDef;
1540 Expression MkExpInstance(Instantiation inst)
1542 return { type = instanceExp, instance = inst };
1545 External MkExternalClass(ClassDefinition _class)
1547 return { type = classExternal, _class = _class, symbol = _class.symbol };
1550 PropertyDef MkProperty(OldList specs, Declarator decl, Identifier id, Statement setStmt, Statement getStmt)
1560 Type type = ProcessType(specs, decl);
1563 char typeString[1024];
1564 typeString[0] = '\0';
1565 PrintType(type, typeString, false, true);
1566 id = MkIdentifier(typeString);
1567 prop.conversion = true;
1573 string = CopyString(id.string);
1576 symbol.idCode = symbol.id = globalContext.nextID++;
1577 excludedSymbols->Add(symbol);
1578 globalContext.nextID++;
1579 globalContext.nextID++;
1580 prop.symbol = symbol;
1584 ClassDef MkClassDefProperty(PropertyDef propertyDef)
1586 return { type = propertyClassDef, propertyDef = propertyDef };
1589 ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
1591 return { type = classPropertyClassDef, propertyDef = propertyDef };
1594 ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
1596 return { type = classPropertyValueClassDef, id = id, initializer = initializer };
1599 int CheckType(char * text)
1602 Time startTime = GetTime();
1604 if(FindTemplateTypeParameter(curContext, text))
1607 checkTypeTotalTime += GetTime() - startTime;
1611 if(FindType(curContext, text))
1614 checkTypeTotalTime += GetTime() - startTime;
1621 checkTypeTotalTime += GetTime() - startTime;
1623 return TYPE_NAME; //CLASS_NAME;
1626 checkTypeTotalTime += GetTime() - startTime;
1633 return CheckType(yytext);
1636 Context PushContext()
1638 Context ctx { parent = curContext };
1643 void PopContext(Context ctx)
1645 curContext = ctx.parent;
1648 Symbol FindType(Context ctx, char * name)
1653 type = (Symbol)ctx.types.FindString(name);
1654 if(!type && ctx.parent)
1655 type = FindType(ctx.parent, name);
1660 TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
1662 TemplatedType templatedType = null;
1665 templatedType = (TemplatedType)ctx.templateTypes.FindString(name);
1666 if(!templatedType && ctx.parent)
1667 templatedType = FindTemplateTypeParameter(ctx.parent, name);
1669 return templatedType;
1672 bool ModuleAccess(Module searchIn, Module searchFor)
1674 SubModule subModule;
1676 if(searchFor == searchIn)
1679 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
1681 if(subModule.importMode == publicAccess /*|| searchIn == searchIn.application*/)
1683 if(ModuleAccess(subModule.module, searchFor))
1690 ModuleImport FindModule(Module moduleToFind)
1692 ModuleImport module;
1693 if(!moduleToFind.name)
1695 for(module = imports->first; module; module = module.next)
1696 if(module.name && !strcmp(module.name, moduleToFind.name))
1700 module = ModuleImport
1702 name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
1703 importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
1705 imports->Add(module);
1711 // TO REMOVE: OBSOLETE...
1712 static void GetFullClassNameSpace(NameSpace * ns, char * name)
1716 GetFullClassNameSpace(ns->parent, name);
1717 strcat(name, ns->name);
1722 static char * GetFullClassName(Class c, char * name)
1724 NameSpace * nameSpace;
1726 GetFullClassNameSpace(c.nameSpace, name);
1727 strcat(name, c.name);
1732 public Symbol FindClass(char * name)
1735 Time startTime = GetTime();
1739 bool global = false;
1740 char fullName[1024];
1742 if(name[0] == ':' && name[1] == ':')
1748 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1750 int len = 0, stringLen;
1751 if(defaultNameSpace)
1753 memcpy(fullName, defaultNameSpace, defaultNameSpaceLen);
1754 len += defaultNameSpaceLen;
1755 fullName[len++] = ':';
1756 fullName[len++] = ':';
1758 if(currentNameSpace)
1760 memcpy(fullName + len, currentNameSpace, currentNameSpaceLen);
1761 len += currentNameSpaceLen;
1762 fullName[len++] = ':';
1763 fullName[len++] = ':';
1765 stringLen = strlen(name);
1766 memcpy(fullName + len, name, stringLen);
1769 cl = globalContext ? (Symbol)globalContext.classes.FindString(fullName) : null;
1773 cl = globalContext ? (Symbol)globalContext.classes.FindString(name) : null;
1778 Time startTime = GetTime();
1780 // Ignore name space name when searching
1781 for(cl = globalContext ? (Symbol)globalContext.classes.first : null; cl; cl = (Symbol)((BTNode)cl).next)
1785 char * string = cl.string;
1787 for(c = 0; (ch = string[c]); c++)
1789 if(ch == '.' || (ch == ':' && string[c+1] == ':'))
1795 if(start && c - start)
1797 if(!strcmp(string + start, name))
1801 if(cl.shortName && !strcmp(cl.shortName, name))
1805 findClassIgnoreNSTotalTime += GetTime() - startTime;
1811 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1812 _class = eSystem_FindClass(privateModule, fullName);
1814 _class = eSystem_FindClass(privateModule, name);
1818 name = _class.fullName;
1820 cl = (Symbol)globalContext.classes.FindString(name);
1825 string = CopyString(name);
1826 registered = _class;
1833 cl.module = FindModule(_class.module);
1835 cl.module = mainModule;
1836 globalContext.classes.Add((BTNode)cl);
1837 if(strcmp(name, _class.name))
1838 cl.shortName = CopyString(_class.name);
1843 findClassTotalTime += GetTime() - startTime;
1848 void CopyTypeInto(Type type, Type src)
1851 type.name = CopyString(src.name);
1852 type.enumName = CopyString(src.enumName);
1855 if(src.kind == enumType)
1859 type.members.Clear();
1860 for(member = type.members.first; member; member = member.next)
1862 type.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
1865 else if(src.kind == structType || src.kind == unionType)
1868 // Tricky stuff... will be removed from list only when ref count reaches 0
1869 for(member = type.members.first; member; member = member.next)
1872 else if(src.kind == functionType)
1875 type.returnType.refCount++;
1876 for(param = type.params.first; param; param = param.next)
1879 else if(src.kind == pointerType || src.kind == arrayType)
1881 type.type.refCount++;
1882 if(src.kind == arrayType)
1884 if(type.arraySizeExp)
1885 type.arraySizeExp = CopyExpression(type.arraySizeExp);
1891 public Type ProcessType(OldList specs, Declarator decl)
1894 bool isTypedef = false;
1895 if(!specs || specs.first)
1897 Declarator funcDecl = GetFuncDecl(decl);
1899 bool dllExport = false;
1901 specType.kind = intType;
1902 specType.isSigned = true;
1903 specType.refCount = 1;
1905 type = Type { refCount = 1 };
1907 while(decl && (decl.type == structDeclarator || decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd))
1909 if(decl.type == structDeclarator && decl.structDecl.exp)
1911 ProcessExpressionType(decl.structDecl.exp);
1912 ComputeExpression(decl.structDecl.exp);
1913 if(decl.structDecl.exp.type == constantExp)
1914 specType.bitFieldCount = strtoul(decl.structDecl.exp.constant, null, 0);
1916 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended &&
1917 (!strcmp(decl.extended.extended, "__declspec(dllexport)") || !strcmp(decl.extended.extended, "dllexport")))
1921 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended &&
1922 (strstr(decl.extended.extended, "__attribute__")))
1924 specType.keepCast = true;
1926 decl = decl.declarator;
1929 // If we'll be using the specType
1930 if(funcDecl || !decl || decl.type == identifierDeclarator)
1935 bool isLong = false;
1936 for(spec = specs.first; spec; spec = spec.next)
1938 if(spec.type == extendedSpecifier && (!strcmp(spec.name, "__declspec(dllexport)") || !strcmp(spec.name, "dllexport")))
1942 if(spec.type == extendedSpecifier && strstr(spec.name, "__attribute__"))
1944 specType.keepCast = true;
1947 if(specType.kind == structType || specType.kind == unionType)
1950 specType = { kind = intType, isSigned = true, refCount = 1 };
1953 if(spec.type == baseSpecifier)
1955 if(spec.specifier == TYPEDEF) isTypedef = true;
1956 else if(spec.specifier == VOID) specType.kind = voidType;
1957 else if(spec.specifier == CHAR) specType.kind = charType;
1958 else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
1959 else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
1960 else if(spec.specifier == INT64) specType.kind = int64Type;
1961 else if(spec.specifier == VALIST)
1962 specType.kind = vaListType;
1963 else if(spec.specifier == SHORT) specType.kind = shortType;
1964 else if(spec.specifier == LONG)
1967 specType.kind = int64Type;
1969 specType.kind = intType;
1971 // specType.kind = longType;
1973 else if(spec.specifier == FLOAT) specType.kind = floatType;
1974 else if(spec.specifier == DOUBLE) specType.kind = doubleType;
1975 else if(spec.specifier == SIGNED) specType.isSigned = true;
1976 else if(spec.specifier == UNSIGNED) specType.isSigned = false;
1977 else if(spec.specifier == CONST) specType.constant = true;
1978 else if(spec.specifier == TYPED_OBJECT)
1980 specType.classObjectType = typedObject; specType.kind = classType; specType._class = FindClass("class");
1982 else if(spec.specifier == ANY_OBJECT)
1984 specType.classObjectType = anyObject; specType.kind = classType; specType._class = FindClass("class");
1986 else if(spec.specifier == CLASS)
1988 specType.classObjectType = classPointer; specType.kind = classType; specType._class = FindClass("class");
1990 else if(spec.specifier == THISCLASS)
1991 specType.kind = thisClassType;
1993 else if(spec.type == nameSpecifier)
1995 Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
1996 if(symbol && symbol.type)
1998 CopyTypeInto(specType, symbol.type);
1999 specType.typeName = CopyString(symbol.type.name);
2001 else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
2003 // key.sym enum values need FindClass:
2004 specType._class = spec.name ? FindClass(spec.name) : null;
2005 // specType._class = spec.symbol;
2006 specType.kind = classType;
2007 if(!specType._class)
2008 specType.kind = intType;
2011 else if(spec.type == enumSpecifier)
2014 specType.kind = enumType;
2015 specType.enumName = spec.id ? CopyString(spec.id.string) : null;
2021 for(e = spec.list->first; e; e = e.next)
2023 specType.members.Add(NamedItem { name = CopyString(e.id.string) });
2025 if(e.exp && ComputeExpression(e.exp), e.exp.isConstant && e.exp.expType.kind == intType)
2026 value.data = (void *) nextValue = strtol(e.exp.string, null, 0);
2028 value.data = (void *)nextValue++;
2036 for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
2037 if(decl.declarators)
2040 for(d = decl.declarators.first; d; d = d.next)
2042 Type memberType = ProcessType(decl.specifiers, d);
2043 specType.members.Add(memberType);
2046 else if(decl.specifiers)
2048 Type memberType = ProcessType(decl.specifiers, null);
2049 specType.members.Add(memberType);
2054 else if(spec.type == templateTypeSpecifier)
2057 printf("spec %x\n", spec);
2058 printf("template param %x\n", spec.templateParameter);
2059 printf("identifier %x\n", spec.templateParameter.identifier);
2060 printf("string %x\n", spec.templateParameter.identifier.string);
2062 specType.kind = templateType;
2063 specType.templateParameter = spec.templateParameter;
2065 else if(spec.type == structSpecifier || spec.type == unionSpecifier)
2067 Symbol _class = spec.id ? FindClass(spec.id.string) : null;
2070 if(!_class.registered || _class.registered.type != structClass)
2071 specType.directClassAccess = true;
2072 specType._class = _class;
2073 specType.kind = classType;
2076 if(spec.type == structSpecifier)
2077 specType.kind = structType;
2078 else if(spec.type == unionSpecifier)
2079 specType.kind = unionType;
2082 // TESTING THIS HERE... Had 0 type size
2083 if(!spec.definitions && !isTypedef)
2085 Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
2086 if(symbol && symbol.type)
2088 specType = *symbol.type;
2089 specType.name = CopyString(symbol.type.name);
2090 specType.typeName = CopyString(spec.name);
2091 specType.enumName = CopyString(symbol.type.enumName);
2092 specType.refCount = 1;
2094 if(symbol.type.kind == enumType)
2098 specType.members.Clear();
2099 for(member = specType.members.first; member; member = member.next)
2101 specType.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
2104 else if(symbol.type.kind == structType || symbol.type.kind == unionType)
2107 // Tricky stuff... will be removed from list only when ref count reaches 0
2108 for(member = specType.members.first; member; member = member.next)
2111 else if(symbol.type.kind == functionType)
2114 specType.returnType.refCount++;
2115 for(param = specType.params.first; param; param = param.next)
2118 else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
2120 specType.type.refCount++;
2121 if(symbol.type.kind == arrayType)
2123 if(specType.arraySizeExp)
2124 specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
2130 specType.enumName = CopyString(spec.id.string);
2133 specType.enumName = CopyString(spec.id.string);
2136 if(spec.definitions)
2139 for(def = spec.definitions->first; def; def = def.next)
2141 if(def.type == declarationClassDef && def.decl.type == structDeclaration)
2143 Declaration decl = def.decl;
2144 if(decl.declarators)
2147 for(d = decl.declarators->first; d; d = d.next)
2149 Type memberType = ProcessType(decl.specifiers, d);
2150 specType.members.Add(memberType);
2153 else if(decl.specifiers)
2155 Type memberType = ProcessType(decl.specifiers, null);
2156 specType.members.Add(memberType);
2163 else if(spec.type == subClassSpecifier)
2165 specType.kind = specType.kind = subClassType;
2166 specType._class = spec._class.symbol; // FindClass(spec._class.name);
2169 else if(spec.type == classSpecifier)
2171 specType._class = FindClass(spec.name);
2172 specType.kind = classType;
2178 specType.kind = ellipsisType;
2183 Declarator d = funcDecl.declarator;
2187 funcType.kind = functionType;
2188 funcType.refCount = 1;
2189 if(funcDecl.function.parameters)
2191 for(param = funcDecl.function.parameters->first; param; param = param.next)
2194 if(param.typedObject)
2196 Type typedObjectType
2199 byReference = param.byReference;
2200 kind = TypeTypedObject;
2202 funcType.params.Add(typedObjectType);
2205 funcType.params.Add(ProcessType(param.qualifiers, param.declarator));
2209 // Function returning a pointer...
2210 if(decl.type == pointerDeclarator)
2212 Pointer pointer = decl.pointer.pointer;
2214 funcType.returnType = ptrType;
2215 funcType.returnType.refCount = 1;
2218 ptrType.kind = pointerType;
2219 pointer = pointer.pointer;
2222 ptrType.type = Type { refCount = 1 };
2223 ptrType = ptrType.type;
2226 ptrType.type = Type { refCount = 1 };
2227 *ptrType.type = specType;
2231 funcType.returnType = Type { refCount = 1 };
2232 *funcType.returnType = specType;
2235 // TESTING: Added extendedDeclarator here
2236 while(d && (d.type == bracketsDeclarator || d.type == extendedDeclarator || d.type == extendedDeclaratorEnd))
2238 if((d.type == extendedDeclarator || d.type == extendedDeclaratorEnd) && d.extended.extended &&
2239 (!strcmp(d.extended.extended, "__declspec(dllexport)") || !strcmp(d.extended.extended, "dllexport")))
2246 funcType.dllExport = dllExport;
2248 if(d && d.type == pointerDeclarator)
2253 if(d.declarator && d.declarator.type == arrayDeclarator)
2255 // Arrays of pointers to functions (extremely tricky :()
2256 Pointer pointer = d.pointer.pointer;
2258 // TO WORK ON: Fixed the order for the array...
2259 type.kind = arrayType;
2260 type.arraySizeExp = CopyExpression(d.declarator.array.exp);
2261 type.freeExp = true;
2262 if(d.declarator.array.enumClass)
2263 type.enumClass = d.declarator.array.enumClass.symbol; // FindClass(d.declarator.array.enumClass.name);
2264 if(d.declarator.declarator && d.declarator.declarator.type == arrayDeclarator)
2266 Type tmpType = type;
2268 type = ProcessType(null, d.declarator.declarator);
2270 type.type = tmpType;
2271 tmpType.type = inType;
2274 type.type = ProcessType(null, d.declarator.declarator);
2276 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2280 ptrType.kind = pointerType;
2281 pointer = pointer.pointer;
2284 ptrType.type = Type { refCount = 1 };
2285 ptrType = ptrType.type;
2288 ptrType.type = ProcessType(specs, null);
2292 // WARNING: Not caring if this declarator contains a declarator between
2293 // the pointer and the function other than brackets (like in the case of array of pointers to functions)...
2294 // *********** Could it ever go in here??? Yes: void (* converters_table[10]) (); ***********
2295 Pointer pointer = d.pointer.pointer;
2300 ptrType.kind = pointerType;
2301 ptrType.type = Type { refCount = 1 };
2302 pointer = pointer.pointer;
2304 ptrType = ptrType.type;
2308 *ptrType.type = funcType;
2312 if(id._class && !id._class.name)
2313 ptrType.type.staticMethod = true;
2316 // TODO : Ensure classSym has been resolved here... (Is this gonna cause problems? Supposed to do this later...)
2319 if(id._class && id._class.name)
2321 id.classSym = id._class.symbol; // FindClass(id._class.name);
2322 /* TODO: Name Space Fix ups
2324 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
2329 ptrType.type.thisClass = id.classSym;
2330 if(ptrType.type.thisClass && strcmp(ptrType.type.thisClass.string, "class"))
2331 ptrType.type.extraParam = true;
2332 else if(id._class && id._class.name && !strcmp(id._class.name, "any_object"))
2334 ptrType.type.extraParam = true;
2335 ptrType.type.thisClass = FindClass("class");
2339 type.name = CopyString(id.string);
2342 else if(!d || d.type == identifierDeclarator)
2348 if(d.identifier._class && d.identifier._class.type == templateTypeSpecifier)
2350 type.thisClassTemplate = d.identifier._class.templateParameter;
2351 type.extraParam = true;
2355 if(d.identifier._class && !d.identifier._class.name)
2356 type.staticMethod = true;
2359 if(d.identifier._class && d.identifier._class.name && d.identifier._class.name[strlen(d.identifier._class.name)-1] == '&')
2361 type.thisClass = FindClass("class");
2362 type.byReference = true;
2365 type.thisClass = d.identifier._class ? d.identifier._class.symbol /*FindClass(d.identifier._class.name)*/ : null;
2366 if(type.thisClass && strcmp(type.thisClass.string, "class"))
2368 type.extraParam = true;
2370 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "any_object"))
2372 type.extraParam = true;
2373 type.thisClass = FindClass("class");
2375 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "class"))
2377 //type.extraParam = true;
2378 type.thisClass = FindClass("class");
2379 type.classObjectType = classPointer;
2383 type.name = CopyString(d.identifier.string);
2388 else if(decl && decl.type == pointerDeclarator)
2390 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2392 // Arrays of pointers (tricky :))
2394 Pointer pointer = decl.pointer.pointer;
2397 // TO WORK ON: Fixed the order for the array...
2398 type.kind = arrayType;
2399 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2400 type.freeExp = true;
2401 if(decl.declarator.array.enumClass)
2402 type.enumClass = decl.declarator.array.enumClass.symbol; // FindClass(decl.declarator.array.enumClass.name);
2403 if(decl.declarator.declarator && decl.declarator.declarator.type == arrayDeclarator)
2405 Type tmpType = type;
2407 type = ProcessType(null, decl.declarator.declarator);
2409 type.type = tmpType;
2410 tmpType.type = inType;
2413 type.type = ProcessType(null, decl.declarator.declarator);
2415 type.type = ProcessType(null, decl.declarator.declarator);
2416 type.kind = arrayType;
2417 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2418 type.arraySizeExp.freeExp = true;
2419 if(decl.array.enumClass)
2420 type.enumClass = FindClass(decl.array.enumClass.name);
2423 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2427 ptrType.kind = pointerType;
2428 pointer = pointer.pointer;
2431 ptrType.type = Type { refCount = 1 };
2432 ptrType = ptrType.type;
2435 ptrType.type = ProcessType(specs, null);
2436 id = GetDeclId(decl);
2437 if(id) type.name = CopyString(id.string);
2442 Pointer pointer = decl.pointer.pointer;
2443 Type ptrType = type;
2445 if(type.classObjectType)
2447 type.byReference = true;
2453 ptrType.kind = pointerType;
2454 pointer = pointer.pointer;
2457 ptrType.type = Type { refCount = 1 };
2458 ptrType = ptrType.type;
2461 ptrType.type = ProcessType(specs, decl.declarator);
2463 if(type.type.classObjectType)
2465 Type subType = type.type;
2466 type.classObjectType = subType.classObjectType;
2467 type.kind = subType.kind;
2468 type._class = subType._class;
2469 type.byReference = true;
2473 id = GetDeclId(decl);
2474 if(id) type.name = CopyString(id.string);
2478 else if(decl && decl.type == arrayDeclarator)
2482 type.kind = arrayType;
2484 type.arraySizeExp = CopyExpression(decl.array.exp);
2485 type.freeExp = true;
2486 if(decl.array.enumClass)
2487 type.enumClass = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
2488 id = GetDeclId(decl);
2490 // TO WORK ON: Fixed the order for the array...
2491 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2493 Type tmpType = type;
2495 type = ProcessType(specs, decl.declarator);
2497 type.type = tmpType;
2498 tmpType.type = inType;
2501 type.type = ProcessType(specs, decl.declarator);
2506 type.name = CopyString(id.string);
2511 if(!decl || decl.type == identifierDeclarator)
2515 type.name = decl ? CopyString(decl.identifier.string) : null;
2523 public Type ProcessTypeString(char * string, bool staticMethod)
2525 OldList * specs = MkList();
2526 Declarator decl = SpecDeclFromString(string, specs, null);
2527 Type type = ProcessType(specs, decl);
2528 if(type && !type.thisClass && staticMethod) type.staticMethod = true;
2529 FreeList(specs, FreeSpecifier);
2530 if(decl) FreeDeclarator(decl);
2534 Type MkClassTypeSymbol(Symbol symbol)
2538 Type type { kind = classType, _class = symbol };
2541 // Defaults to an int instead...
2542 type.kind = intType;
2550 public Type MkClassType(char * name)
2554 Type type { kind = classType, _class = FindClass(name) };
2557 // Defaults to an int instead...
2558 type.kind = intType;
2566 AsmField MkAsmField(char * command, Expression expression)
2568 return { command = command, expression = expression };
2571 Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
2573 return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
2574 asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
2575 asmStmt.clobberedFields = clobberedFields };
2578 ClassDef MkClassDefPropertyWatch(PropertyWatch watcher)
2580 return { type = propertyWatchClassDef, propertyWatch = watcher };
2583 Statement MkFireWatchersStmt(Expression object, OldList watches)
2585 return { type = fireWatchersStmt, _watch.object = object, _watch.watches = watches };
2588 Statement MkStopWatchingStmt(Expression watcher, Expression object, OldList watches)
2590 return { type = stopWatchingStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2593 Statement MkWatchStmt(Expression watcher, Expression object, OldList watches)
2595 return { type = watchStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2598 PropertyWatch MkDeleteWatch(Statement compound)
2600 return { compound = compound, deleteWatch = true };
2603 PropertyWatch MkPropertyWatch(OldList properties, Statement compound)
2605 return { compound = compound, properties = properties };
2608 Expression MkExpClass(OldList * specifiers, Declarator decl)
2610 return { type = classExp, _classExp.specifiers = specifiers, _classExp.decl = decl };
2613 Expression MkExpClassData(Identifier id)
2615 return { type = classDataExp, classData.id = id };
2619 External MkExternalDBTable(DBTableDef table)
2621 return { type = dbtableExternal, table = table };
2624 DBTableDef MkDBTableDef(char * name, Symbol symbol, OldList * definitions)
2626 return { name = name, symbol = symbol, definitions = definitions };
2629 DBTableEntry MkDBFieldEntry(TypeName type, Identifier id, char * name)
2631 return { type = fieldEntry, dataType = type, id = id, name = name };
2634 DBIndexItem MkDBIndexItem(Identifier id, Order order)
2636 return { id = id, order = order };
2639 DBTableEntry MkDBIndexEntry(OldList * items, Identifier id)
2641 return { type = indexEntry, items = items, id = id };
2644 Expression MkExpDBOpen(Expression ds, Expression dbName)
2646 return { type = dbopenExp, dbopen.ds = ds, dbopen.name = dbName };
2649 Expression MkExpDBField(char * table, Identifier id)
2651 return { type = dbfieldExp, db.table = table, db.id = id };
2654 Expression MkExpDBIndex(char * table, Identifier id)
2656 return { type = dbindexExp, db.table = table, db.id = id };
2659 Expression MkExpDBTable(char * table)
2661 return { type = dbtableExp, db.table = table };
2664 Expression MkExpArray(OldList * expressions)
2666 return { type = arrayExp, list = expressions };
2669 Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplateParameterType tplType)
2671 Expression argExp = null;
2672 Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
2676 ClassTemplateParameter curParam;
2678 for(sClass = _class; sClass; sClass = sClass.base)
2681 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2683 if(!strcmp(curParam.name, paramName))
2685 for(sClass = sClass.base; sClass; sClass = sClass.base)
2686 id += sClass.templateParams.count;
2694 if(curParam && curParam.type != tplType)
2700 char className[1024];
2701 Expression classExp;
2703 sprintf(idString, "%d", id);
2704 strcpy(className, "__ecereClass_");
2705 FullClassNameCat(className, _class.fullName, true);
2706 MangleClassName(className);
2707 DeclareClass(FindClass(_class.fullName), className);
2709 argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
2710 (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
2711 MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
2717 Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
2719 return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
2722 public void OutputIntlStrings()
2724 if(intlStrings.count)
2726 char * srcFile = GetSourceFile();
2727 char * objFile = GetOutputFile();
2728 char potFile[MAX_LOCATION];
2730 ChangeExtension(objFile, "bowl", potFile);
2731 f = FileOpen(potFile, write);
2734 for(s : intlStrings)
2736 f.Printf("# %s %d\n", srcFile, s.start.line);
2737 f.Printf("msgid %s\n", &s);
2738 f.Printf("msgstr %s\n\n", &s);