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 // TODO: String is case sensitive..
231 // What should we do about it?
232 /*public class CaseSensitiveString : String
234 int OnCompare(CaseSensitiveString string2)
238 result = strcmpi(this, string2);
239 else if(!this && string2)
241 else if(this && !string2)
247 public struct ContextStringPair
249 String string, context;
251 // TODO: Should this be automated somehow?
258 int OnCompare(ContextStringPair b)
261 result = (string && b.string) ? strcmp(string, b.string) :
262 (!string && b.string) ? 1 : (string && !b.string) ? -1 : 0;
263 if(result) return result;
265 result = (context && b.context) ? strcmp(context, b.context) :
266 (!context && b.context) ? 1 : (context && !b.context) ? -1 : 0;
267 // TODO: Support these
268 // result = CaseSensitiveString::OnCompare(string, b.string);
269 // result = ((CaseSensitiveString)string).OnCompare(b.string);
274 Map<ContextStringPair, List<Location> > intlStrings { };
276 Expression MkExpIntlString(char * string, char * context)
278 OldList * list = MkList();
281 ContextStringPair pair { };
283 int len = strlen(string);
285 pair.string = new byte[len-2+1]; memcpy(pair.string, string+1, len-2); pair.string[len-2] = '\0';
286 if(context) { len = strlen(context); pair.context = new byte[len-2+1]; memcpy(pair.context, context+1, len-2); pair.context[len-2] = '\0'; }
288 list = intlStrings[pair];
292 intlStrings[pair] = list;
301 ListAdd(list, QMkExpId("__thisModule"));
302 ListAdd(list, MkExpString(string));
305 int lenString = strlen(string), lenContext = strlen(context);
306 char * msgid = new char[lenString-2 + lenContext-2 + 4];
308 memcpy(msgid+1, context+1, lenContext-2);
309 msgid[1+lenContext-2] = 4; // EOT
310 memcpy(msgid+1+lenContext-2+1, string+1, lenString-2);
311 memcpy(msgid+1+lenContext-2+1+lenString-2, "\"", 2);
312 ListAdd(list, MkExpString(msgid));
316 ListAdd(list, QMkExpId("null"));
317 return MkExpCall(QMkExpId("GetTranslatedString"), list);
320 Expression MkExpOp(Expression exp1, int op, Expression exp2)
331 exp.loc.start = exp1 ? exp1.loc.start : exp2.loc.start;
332 exp.loc.end = exp2 ? exp2.loc.end : exp1.loc.end;
337 Expression MkExpBrackets(OldList expressions)
344 if(expressions && expressions.first)
346 exp.loc.start = ((Expression)expressions.first).loc.start;
347 exp.loc.end = ((Expression)expressions.last).loc.end;
352 Expression MkExpIndex(Expression expression, OldList index)
354 return { type = indexExp, index.exp = expression, index.index = index };
357 Expression MkExpCall(Expression expression, OldList arguments)
359 return { type = callExp, call.exp = expression, call.arguments = arguments };
362 Expression MkExpMember(Expression expression, Identifier member)
364 return { type = memberExp, member.exp = expression, member.member = member };
367 Expression MkExpPointer(Expression expression, Identifier member)
369 return { type = pointerExp, member.exp = expression, member.member = member };
372 Expression MkExpTypeSize(TypeName typeName)
374 return { type = typeSizeExp, typeName = typeName };
377 Expression MkExpClassSize(Specifier _class)
379 return { type = classSizeExp, _class = _class };
382 Expression MkExpCast(TypeName typeName, Expression expression)
384 return { type = castExp, cast.typeName = typeName, cast.exp = expression };
387 Expression MkExpCondition(Expression cond, OldList expressions, Expression elseExp)
389 return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp };
392 Expression MkExpRenew(Expression memExp, TypeName type, Expression size)
394 return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
397 Expression MkExpRenew0(Expression memExp, TypeName type, Expression size)
399 return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
402 Expression MkExpNew(TypeName type, Expression size)
404 return { type = newExp, _new.typeName = type, _new.size = size };
407 Expression MkExpNew0(TypeName type, Expression size)
409 return { type = new0Exp, _new.typeName = type, _new.size = size };
412 Expression MkExpVaArg(Expression exp, TypeName type)
414 return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type };
417 Specifier MkSpecifier(int specifier)
419 return { type = baseSpecifier, specifier = specifier };
422 Specifier MkSpecifierTypeOf(Expression expression)
424 return { type = typeOfSpecifier, expression = expression };
427 Specifier MkSpecifierSubClass(Specifier _class)
429 return { type = subClassSpecifier, _class = _class };
432 Specifier MkSpecifierExtended(char * name)
434 return { type = extendedSpecifier, name = CopyString(name) };
437 Specifier MkEnum(Identifier id, OldList list)
441 type = enumSpecifier;
445 if(list && (!declMode || !id))
451 type = ProcessType(&specs, null);
455 Symbol symbol { string = CopyString(id.string), isStruct = true, type = type };
457 if(strstr(symbol.string, "::"))
458 curContext.hasNameSpace = true;
459 if(!curContext.structSymbols.Add((BTNode)symbol))
462 for(e = list.first; e; e = e.next)
464 Symbol symbol { string = CopyString(e.id.string), type = type };
466 if(strstr(symbol.string, "::"))
467 curContext.hasNameSpace = true;
468 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
476 Specifier MkStructOrUnion(SpecifierType type, Identifier id, OldList definitions)
478 Specifier spec { type = type, id = id };
479 if(id && FindType(curContext, id.string))
480 declMode = defaultAccess;
481 spec.definitions = definitions;
482 if(definitions && id && !declMode)
487 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specs, null), isStruct = true };
488 if(!curContext.structSymbols.Add((BTNode)symbol))
494 void AddStructDefinitions(Specifier spec, OldList definitions)
496 spec.definitions = definitions;
497 if(definitions && spec.id && !declMode)
502 symbol = Symbol { string = CopyString(spec.id.string), type = ProcessType(specs, null), isStruct = true };
503 if(!curContext.parent.structSymbols.Add((BTNode)symbol))
508 public Declarator MkDeclaratorIdentifier(Identifier id)
510 return { type = identifierDeclarator, identifier = id };
513 Declarator MkDeclaratorFunction(Declarator declarator, OldList parameters)
515 return { type = functionDeclarator, declarator = declarator, function.parameters = parameters };
518 Declarator MkDeclaratorExtended(char * extended, Declarator declarator)
520 return { type = extendedDeclarator, declarator = declarator, extended.extended = extended };
523 Declarator MkDeclaratorExtendedEnd(char * extended, Declarator declarator)
525 return { type = extendedDeclaratorEnd, declarator = declarator, extended.extended = extended };
528 Declarator MkStructDeclarator(Declarator declarator, Expression exp)
530 return { type = structDeclarator, declarator = declarator, structDecl.exp = exp };
533 Declarator MkDeclaratorBrackets(Declarator declarator)
535 return { type = bracketsDeclarator, declarator = declarator };
538 Declarator MkDeclaratorArray(Declarator declarator, Expression exp)
540 return { type = arrayDeclarator, declarator = declarator, array.exp = exp };
543 Declarator MkDeclaratorEnumArray(Declarator declarator, Specifier _class)
545 return { type = arrayDeclarator, declarator = declarator, array.enumClass = _class };
548 Declarator MkDeclaratorPointer(Pointer pointer, Declarator declarator)
550 return { type = pointerDeclarator, declarator = declarator, pointer.pointer = pointer };
553 Enumerator MkEnumerator(Identifier id, Expression exp)
555 return { id = id, exp = exp };
558 Pointer MkPointer(OldList qualifiers, Pointer pointer)
560 return { qualifiers = qualifiers, pointer = pointer };
563 Initializer MkInitializerAssignment(Expression exp)
565 /*if(yylloc.start.line == 1)
567 return { type = expInitializer, exp = exp, loc = yylloc };
570 Initializer MkInitializerList(OldList list)
572 /*if(yylloc.start.line == 1)
574 return { type = listInitializer, list = list, loc = yylloc };
577 InitDeclarator MkInitDeclarator(Declarator declarator, Initializer initializer)
579 return { declarator = declarator, initializer = initializer };
582 public TypeName MkTypeName(OldList qualifiers, Declarator declarator)
584 return { qualifiers = qualifiers, declarator = declarator };
587 public Identifier GetDeclId(Declarator decl)
589 while(decl && decl.type != identifierDeclarator)
590 decl = decl.declarator;
591 return decl ? decl.identifier : null;
594 Declaration MkDeclarationClassInst(Instantiation inst)
596 return { type = instDeclaration, inst = inst, loc = yylloc };
599 Declaration MkDeclarationInst(Instantiation inst)
601 Declaration decl { type = instDeclaration, inst = inst, loc = yylloc };
603 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
606 int len = 0, stringLen;
609 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
610 len += defaultNameSpaceLen;
616 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
617 len += currentNameSpaceLen;
622 stringLen = strlen(inst.exp.identifier.string);
623 memcpy(name + len, inst.exp.identifier.string, stringLen);
626 delete inst.exp.identifier.string;
627 inst.exp.identifier.string = CopyString(name);
632 string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
633 type = MkClassTypeSymbol(inst._class.symbol);
635 symbol.idCode = symbol.id = curContext.nextID++;
636 if(strstr(symbol.string, "::"))
637 curContext.hasNameSpace = true;
638 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
639 excludedSymbols->Add(symbol);
640 decl.symbol = inst.symbol = symbol;
644 Declaration MkDeclarationDefine(Identifier id, Expression exp)
646 Declaration decl { type = defineDeclaration, id = id, exp = exp, loc = yylloc };
647 char expString[1024];
650 PrintExpression(exp, expString);
652 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
655 int len = 0, stringLen;
658 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
659 len += defaultNameSpaceLen;
665 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
666 len += currentNameSpaceLen;
670 stringLen = strlen(id.string);
671 memcpy(name + len, id.string, stringLen);
675 id.string = CopyString(name);
678 if(!eSystem_FindDefine(privateModule, id.string))
679 eSystem_RegisterDefine(id.string, expString, privateModule, buildingECERECOMModule ? baseSystemAccess : publicAccess);
681 Compiler_Warning("Redefinition of %s ignored\n", id.string);
685 Declaration MkDeclaration(OldList specifiers, OldList initDeclarators)
687 Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
688 bool variable = true;
690 if(specifiers != null)
693 for(spec = specifiers.first; spec; spec = spec.next)
695 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
697 if(initDeclarators != null)
701 for(d = initDeclarators.first; d; d = d.next)
703 if(GetDeclId(d.declarator).string)
707 string = CopyString(GetDeclId(d.declarator).string);
708 type = ProcessType(specifiers, d.declarator);
710 type.id = type.idCode = curContext.nextID++;
712 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
713 excludedSymbols->Add(type);
714 decl.symbol = d.declarator.symbol = type;
720 for(; spec; spec = spec.next)
722 if(spec.type == nameSpecifier && spec.name)
726 string = CopyString(spec.name);
727 type = ProcessType(specifiers, null);
729 type.id = type.idCode = curContext.nextID++;
730 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
731 excludedSymbols->Add(type);
740 else if(spec.type == baseSpecifier &&
741 (spec.specifier == STRUCT || spec.specifier == UNION))
745 if(variable && initDeclarators)
748 for(d = initDeclarators.first; d; d = d.next)
750 Identifier id = GetDeclId(d.declarator);
751 if(id && id.string && id.string[0])
757 if(curContext == globalContext && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
760 int len = 0, stringLen;
763 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
764 len += defaultNameSpaceLen;
770 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
771 len += currentNameSpaceLen;
775 stringLen = strlen(id.string);
776 memcpy(name + len, id.string, stringLen);
780 id.string = CopyString(name);
783 // Avoid memory leaks on duplicated symbols (BinaryTree::Add Would Fail)
784 symbol = (Symbol)(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.FindString(id.string);
787 symbol = Symbol { string = CopyString(id.string), type = ProcessType(specifiers, d.declarator) };
788 if(strstr(symbol.string, "::"))
789 curContext.hasNameSpace = true;
790 if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
791 excludedSymbols->Add(symbol);
792 // TODO: Add better support to count declarators
793 if(symbol.type && symbol.type.kind == arrayType && !symbol.type.arraySizeExp && d.initializer)
795 if(d.initializer.type == listInitializer)
798 sprintf(string, "%d",d.initializer.list->count);
799 symbol.type.arraySizeExp = MkExpConstant(string);
800 symbol.type.freeExp = true;
802 else if(d.initializer.type == expInitializer && d.initializer.exp.type == stringExp && d.initializer.exp.string)
807 bool escaped = false;
808 char * s = d.initializer.exp.string;
810 // MAKE MORE ACCURATE
811 for(c = 1; (ch = s[c]); c++)
813 if(ch == '\\' && !escaped)
822 sprintf(string, "%d", count);
823 symbol.type.arraySizeExp = MkExpConstant(string);
824 symbol.type.freeExp = true;
827 symbol.id = symbol.idCode = curContext.nextID++;
829 decl.symbol = d.declarator.symbol = symbol;
836 decl.symbol = Symbol { };
837 decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
838 excludedSymbols->Add(decl.symbol);
843 Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifier extStorage)
845 return { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
848 Statement MkLabeledStmt(Identifier id, Statement statement)
850 return { type = labeledStmt, labeled.id = id, labeled.stmt = statement, loc = yylloc };
853 Statement MkCaseStmt(Expression exp, Statement statement)
855 return { type = caseStmt, caseStmt.exp = exp, caseStmt.stmt = statement, loc = yylloc };
858 Statement MkCompoundStmt(OldList declarations, OldList statements)
860 return { type = compoundStmt, compound.declarations = declarations, compound.statements = statements, loc = yylloc };
863 Statement MkExpressionStmt(OldList expressions)
865 return { type = expressionStmt, expressions = expressions, loc = yylloc };
868 Statement MkBadDeclStmt(Declaration decl)
870 return { type = badDeclarationStmt, decl = decl, loc = yylloc };
873 Statement MkIfStmt(OldList exp, Statement statement, Statement elseStmt)
875 return { type = ifStmt, ifStmt.exp = exp, ifStmt.stmt = statement, ifStmt.elseStmt = elseStmt, loc = yylloc };
878 Statement MkSwitchStmt(OldList exp, Statement statement)
880 // To know it's a switch compound... (Don't want declarations in there... bugs)
882 statement.compound.isSwitch = true;
883 return { type = switchStmt, switchStmt.exp = exp, switchStmt.stmt = statement, loc = yylloc };
886 Statement MkWhileStmt(OldList exp, Statement statement)
888 return { type = whileStmt, whileStmt.exp = exp, whileStmt.stmt = statement, loc = yylloc };
891 Statement MkDoWhileStmt(Statement statement, OldList exp)
893 return { type = doWhileStmt, doWhile.exp = exp, doWhile.stmt = statement, loc = yylloc };
896 Statement MkForStmt(Statement init, Statement check, OldList inc, Statement statement)
898 return { type = forStmt, forStmt.init = init, forStmt.check = check, forStmt.increment = inc, forStmt.stmt = statement, loc = yylloc };
901 Statement MkForEachStmt(Identifier id, OldList exp, OldList filter, Statement statement)
903 return { type = forEachStmt, forEachStmt.id = id, forEachStmt.exp = exp, forEachStmt.filter = filter, forEachStmt.stmt = statement, loc = yylloc };
906 Statement MkGotoStmt(Identifier id)
908 return { type = gotoStmt, gotoStmt.id = id, loc = yylloc };
911 Statement MkContinueStmt()
913 return { type = continueStmt, loc = yylloc };
916 Statement MkBreakStmt()
918 return { type = breakStmt, loc = yylloc };
921 Statement MkReturnStmt(OldList exp)
923 return { type = returnStmt, expressions = exp, loc = yylloc };
926 FunctionDefinition MkFunction(OldList specifiers, Declarator declarator, OldList declarationList)
928 return { specifiers = specifiers, declarator = declarator, declarations = declarationList };
931 void ProcessFunctionBody(FunctionDefinition func, Statement body)
933 Declarator declarator = func.declarator;
934 Declarator funcDecl = GetFuncDecl(declarator);
939 if(funcDecl && funcDecl.function.parameters && body)
941 Context context = body.compound.context;
943 for(param = funcDecl.function.parameters->first; param; param = param.next)
947 Symbol symbol = null;
948 Identifier id = GetDeclId(param.declarator);
949 char * string = id ? id.string : null;
952 for(symbol = (Symbol)context.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
953 if(!strcmp(symbol.string, string))
955 // This parameter is not shadowed by a local declaration
958 symbol = Symbol { string = CopyString(id.string), type = ProcessType(param.qualifiers, param.declarator), isParam = true };
959 if(!context.symbols.Add((BTNode)symbol))
960 excludedSymbols->Add(symbol);
962 // TODO: Fix this, the parameters' IDs should really be smaller...
963 symbol.id = context.nextID++;
964 param.declarator.symbol = symbol;
971 if(!declarator.symbol)
973 Identifier id = GetDeclId(declarator);
975 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess && strcmp(id.string, "__on_register_module"))
978 int len = 0, stringLen;
981 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
982 len += defaultNameSpaceLen;
988 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
989 len += currentNameSpaceLen;
993 stringLen = strlen(id.string);
994 memcpy(name + len, id.string, stringLen);
998 id.string = CopyString(name);
1000 symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
1001 symbol.idCode = symbol.id = globalContext.nextID++;
1002 if(strstr(symbol.string, "::"))
1003 globalContext.hasNameSpace = true;
1004 if(!globalContext.symbols.Add((BTNode)symbol))
1005 excludedSymbols->Add(symbol);
1006 declarator.symbol = symbol;
1010 symbol = declarator.symbol;
1011 excludedSymbols->Remove(declarator.symbol);
1012 delete symbol.string;
1013 symbol.string = CopyString(GetDeclId(declarator).string);
1014 if(strstr(symbol.string, "::"))
1015 globalContext.hasNameSpace = true;
1016 if(!globalContext.symbols.Add((BTNode)symbol))
1017 excludedSymbols->Add(symbol);
1020 symbol.type = ProcessType(func.specifiers, declarator);
1022 if(symbol.type && (symbol.type.kind == functionType || symbol.type.kind == methodType))
1024 if(!symbol.type.params.count)
1026 Type type { refCount = 1 };
1027 symbol.type.params.Add(type);
1036 External MkExternalFunction(FunctionDefinition function)
1038 External external { type = functionExternal, function = function, symbol = function.declarator.symbol };
1039 if(function.specifiers)
1042 for(spec = function.specifiers->first; spec; spec = spec.next)
1043 if(spec.type == baseSpecifier && spec.specifier == STATIC)
1045 declMode = staticAccess;
1050 if(external.symbol && !external.symbol.methodExternal)
1051 external.symbol.methodExternal = external;
1055 External MkExternalImport(char * name, ImportType importType, AccessMode importAccess)
1057 External external { type = importExternal };
1058 int len = strlen(name) - 2;
1059 external.importString = new char[len + 1];
1060 strncpy(external.importString, name+1, len);
1061 external.importString[len] = '\0';
1066 Time startTime = GetTime();
1069 ImportModule(external.importString, importType, importAccess, true);
1070 ImportModule(external.importString, importType, importAccess, false);
1072 time = GetTime() - startTime;
1073 printf("Importing took %.3f seconds for %s\n", time, external.importString);
1074 externalImportTotalTime += time;
1080 External MkExternalDeclaration(Declaration declaration)
1082 External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
1083 InitDeclarator d = (declaration && declaration.declarators) ? declaration.declarators->last : null;
1084 if(declaration && declaration.type == initDeclaration && declaration.specifiers)
1087 for(spec = declaration.specifiers->first; spec; spec = spec.next)
1088 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1090 declMode = defaultAccess;
1093 else if(spec.type == baseSpecifier && spec.specifier == STATIC)
1095 declMode = staticAccess;
1099 if(declaration && declaration.symbol && !declaration.symbol.methodExternal)
1100 declaration.symbol.methodExternal = external;
1104 External MkExternalNameSpace(Identifier identifier)
1106 External external { type = nameSpaceExternal, id = identifier };
1107 currentNameSpace = identifier ? identifier.string : null;
1108 currentNameSpaceLen = currentNameSpace ? strlen(currentNameSpace) : 0;
1112 void SetClassTemplateArgs(Specifier spec, OldList templateArgs)
1114 if(spec.type == nameSpecifier)
1116 Symbol symbol = spec.symbol;
1117 spec.templateArgs = templateArgs;
1118 if(templateArgs && templateArgs.first)
1120 char templateString[1024];
1121 TemplateArgument arg;
1122 strcpy(templateString, symbol ? symbol.string : spec.name);
1123 strcat(templateString, "<");
1124 for(arg = templateArgs.first; arg; arg = arg.next)
1132 char expString[1024];
1133 Class backupThisClass = thisClass;
1135 expString[0] = '\0';
1136 // Will this work here?
1138 Location oldLocation = yylloc;
1139 File backFileInput = fileInput;
1144 // TESTING THIS SCANNER RESUME STUFF
1147 yylloc = oldLocation;
1148 fileInput = backFileInput;
1151 fileInput.Seek(yylloc.start.pos, start);
1152 resetScannerPos(&yylloc.start);
1157 //ProcessExpressionType(arg.expression);
1158 //ComputeExpression(arg.expression);
1159 PrintExpression(arg.expression, expString);
1160 strcat(argument, expString);
1161 thisClass = backupThisClass;
1166 strcat(argument, arg.identifier.string);
1171 char * typeString = StringFromSpecDecl(arg.templateDatatype.specifiers, arg.templateDatatype.decl);
1172 strcat(argument, typeString);
1179 if(arg.prev) strcat(templateString, ", ");
1182 strcat(templateString, arg.name.string);
1183 strcat(templateString, " = ");
1185 strcat(templateString, argument);
1189 int len = strlen(templateString);
1190 if(templateString[len-1] == '>') templateString[len++] = ' ';
1191 templateString[len++] = '>';
1192 templateString[len++] = '\0';
1194 // printf("SetClassTemplateArgs templateString: %s\n", templateString);
1195 symbol = FindClass(templateString);
1196 if(!symbol && spec.symbol)
1198 // If class was only decl'ed, invoke DeclClass on this templated class as well
1199 symbol = _DeclClass(MAXINT, templateString);
1201 // Add a reference to all templated class to the basic class
1203 spec.symbol.templatedClasses.Add(OldLink { data = symbol });
1205 spec.symbol = symbol;
1206 spec.name = CopyString(symbol ? symbol.string : templateString);
1210 FreeList(templateArgs, FreeTemplateArgument);
1213 Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
1215 Specifier spec { type = nameSpecifier };
1221 TemplatedType templatedType = FindTemplateTypeParameter(curContext, name);
1224 spec.templateParameter = templatedType.param;
1225 spec.type = templateTypeSpecifier;
1229 symbol = FindClass(name);
1231 if(symbol && symbol.registered && symbol.registered.isRemote == 1)
1233 char className[1024];
1234 strcpy(className, "DCOMClient_");
1235 if(!strncmp(name, className, strlen(className)))
1236 spec.name = CopyString(name);
1239 strcat(className, name);
1240 spec.name = CopyString(className);
1244 spec.name = CopyString(symbol.string);
1246 spec.name = CopyString(name);
1247 spec.symbol = symbol;
1248 if(templateArgs != null)
1249 SetClassTemplateArgs(spec, templateArgs);
1254 public Specifier MkSpecifierName(char * name)
1256 return _MkSpecifierName(name, null, null);
1259 public Specifier MkSpecifierNameArgs(char * name, OldList * templateArgs)
1261 return _MkSpecifierName(name, null, templateArgs);
1265 Specifier MkClassName(char * string)
1267 return { type = SpecifierClass, name = CopyString(string) };
1270 ClassFunction MkClassFunction(OldList specifiers, Specifier _class, Declarator decl, OldList declList)
1272 return { specifiers = specifiers, /*_class = _class,*/ declarator = decl, declarations = declList };
1275 void ProcessClassFunctionBody(ClassFunction func, Statement body)
1279 Declarator decl = func.declarator;
1281 //Declarator decl = GetFuncDecl(func.declarator);
1282 Declarator funcDecl = GetFuncDecl(func.declarator);
1286 if(decl && !decl.symbol)
1288 OldList * symbolSpecs = MkList();
1290 // WHAT WILL WE DO WITH THIS? Double instances?
1291 //if(decl.function.parameters && body)
1292 if(funcDecl && funcDecl.function.parameters && body)
1294 Context context = body.compound.context;
1296 for(param = funcDecl.function.parameters->first; param; param = param.next)
1298 if(param.declarator)
1300 Symbol symbol = null;
1301 Identifier id = GetDeclId(param.declarator);
1302 char * string = id ? id.string : null;
1305 symbol = (Symbol)context.symbols.FindString(string);
1307 // This parameter is not shadowed by a local declaration
1312 string = CopyString(id.string);
1313 type = ProcessType(param.qualifiers, param.declarator);
1317 // TODO: Fix this, the parameters' IDs should really be smaller...
1318 symbol.idCode = symbol.id = context.nextID++;
1319 if(!context.symbols.Add((BTNode)symbol))
1320 excludedSymbols->Add(symbol);
1322 param.declarator.symbol = symbol;
1327 //////////////////////////////////
1335 Identifier id = GetDeclId(funcDecl);
1339 for(c = strlen(id.string)-1; c >= 0; c--)
1341 if(id.string[c] == ':')
1343 char * string = CopyString(id.string + c + 1);
1344 id.string[c - 1] = 0;
1345 id._class = MkSpecifierName(id.string);
1351 symbol.string = CopyString(id.string);
1358 for(spec = func.specifiers->first; spec; spec = spec.next)
1359 symbolSpecs->Add(CopySpecifier(spec));
1361 symbol.type = ProcessType(symbolSpecs, decl);
1362 symbol.idCode = symbol.id = globalContext.nextID++;
1363 decl.symbol = symbol;
1365 excludedSymbols->Add(symbol);
1367 FreeList(symbolSpecs, FreeSpecifier);
1371 OldList * MkSpecsClass(Specifier _class)
1373 OldList * list = MkList();
1374 ListAdd(list, _class);
1378 MemberInit MkMemberInit(OldList ids, Initializer initializer)
1380 return { identifiers = ids, initializer = initializer };
1383 MemberInit MkMemberInitExp(Expression idExp, Initializer initializer)
1385 MemberInit init { initializer = initializer, identifiers = MkList() };
1388 for(exp = idExp; exp && exp.type == memberExp; exp = exp.member.exp)
1390 init.identifiers->Insert(null, exp.member.member);
1391 exp.member.member = null;
1393 if(exp && exp.type == identifierExp)
1395 init.identifiers->Insert(null, exp.identifier);
1396 exp.identifier = null;
1398 FreeExpression(idExp);
1402 MembersInit MkMembersInitList(OldList dataMembers)
1404 return { type = dataMembersInit, dataMembers = dataMembers };
1407 MembersInit MkMembersInitMethod(ClassFunction function)
1409 return { type = methodMembersInit, function = function };
1412 Instantiation MkInstantiation(Specifier _class, Expression exp, OldList members)
1414 return { _class = _class, exp = exp, members = members };
1417 Instantiation MkInstantiationNamed(OldList specs, Expression exp, OldList members)
1419 Instantiation inst { exp = exp, members = members };
1424 for(spec = specs.first; spec; spec = spec.next)
1425 if(spec.type == nameSpecifier /*classSpecifier*/)
1432 FreeList(specs, FreeSpecifier);
1436 Compiler_Error("Expecting class specifier\n");
1437 inst._class = MkSpecifierName /*MkClassName*/("");
1445 ClassDef MkClassDefAccessOverride(AccessMode access, Identifier id)
1447 return { type = accessOverrideClassDef, id = id, memberAccess = access };
1450 ClassDef MkClassDefMemberAccess()
1452 return { type = memberAccessClassDef };
1455 ClassDef MkClassDefDeclaration(Declaration decl)
1457 return { type = declarationClassDef, decl = decl };
1460 ClassDef MkClassDefClassData(Declaration decl)
1462 return { type = classDataClassDef, decl = decl };
1465 ClassDef MkClassDefDesigner(char * designer)
1467 return { type = classDesignerClassDef, designer = CopyString(designer) };
1470 ClassDef MkClassDefNoExpansion()
1472 return { type = classNoExpansionClassDef };
1475 ClassDef MkClassDefFixed()
1477 return { type = classFixedClassDef };
1480 ClassDef MkClassDefDesignerDefaultProperty(Identifier id)
1482 return { type = designerDefaultPropertyClassDef, defaultProperty = id };
1485 ClassDef MkClassDefDefaultProperty(OldList defProperties)
1487 return { type = defaultPropertiesClassDef, defProperties = defProperties };
1490 ClassDef MkClassDefFunction(ClassFunction function)
1493 if(function && function.declarator)
1495 Declarator funcDecl = GetFuncDecl(function.declarator);
1496 if(funcDecl && funcDecl.declarator && funcDecl.declarator.type == bracketsDeclarator)
1498 def.type = declarationClassDef;
1499 def.decl = MkStructDeclaration(function.specifiers, MkListOne(MkStructDeclarator(function.declarator, null)), null);
1500 function.declarator = null;
1501 function.specifiers = null;
1502 FreeClassFunction(function);
1506 def.type = functionClassDef;
1507 def.function = function;
1511 Symbol DeclClassAddNameSpace(int symbolID, char * className)
1514 int len = 0, stringLen;
1516 if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1518 if(defaultNameSpace)
1520 memcpy(name, defaultNameSpace, defaultNameSpaceLen);
1521 len += defaultNameSpaceLen;
1525 if(currentNameSpace)
1527 memcpy(name + len, currentNameSpace, currentNameSpaceLen);
1528 len += currentNameSpaceLen;
1533 stringLen = strlen(className);
1534 memcpy(name + len, className, stringLen);
1537 return _DeclClass(symbolID, name);
1540 Symbol DeclClass(int symbolID, char * name)
1542 if(strchr(name, ':'))
1543 return _DeclClass(symbolID, name);
1545 return DeclClassAddNameSpace(symbolID, name);
1548 Symbol _DeclClass(int symbolID, char * name)
1550 Symbol symbol = FindClass(name);
1554 Context classContext;
1555 for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
1561 if(name[0] == ':' && name[1] == ':')
1565 string = CopyString(name);
1566 idCode = symbolID, id = symbolID;
1568 if(!globalContext.classes.Add((BTNode)symbol))
1569 excludedSymbols->Add(symbol);
1574 for(c = 0; (ch = name[c]); c++)
1576 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
1582 if(start && c - start)
1583 symbol.shortName = CopyString(name + start);
1587 symbol.idCode = symbol.id = symbolID;
1591 void SetupBaseSpecs(Symbol symbol, OldList baseSpecs)
1593 if(baseSpecs && baseSpecs.first && ((Specifier)baseSpecs.first).type == nameSpecifier)
1598 strcpy(name, ((Specifier)baseSpecs.first).name);
1599 tpl = strchr(name, '<');
1602 baseClass = FindClass(name);
1606 for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
1608 TemplatedType type { key = copy.key, param = copy.param };
1609 if(!curContext.templateTypes.Add((BTNode)type))
1613 else if(baseClass.registered)
1616 for(sClass = baseClass.registered; sClass; sClass = sClass.base)
1618 ClassTemplateParameter p;
1619 for(p = sClass.templateParams.first; p; p = p.next)
1621 //OldList * specs = MkList();
1622 //Declarator decl = null;
1623 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
1626 TemplateParameter param = p.param;
1630 p.param = param = TemplateParameter
1632 identifier = MkIdentifier(p.name), type = p.type,
1633 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
1636 type = TemplatedType { key = (uint)p.name, param = param };
1637 if(!curContext.templateTypes.Add((BTNode)type))
1646 ClassDefinition MkClass(Symbol symbol, OldList baseSpecs, OldList definitions)
1648 ClassDefinition classDef;
1649 SetupBaseSpecs(symbol, baseSpecs);
1652 FreeContext(symbol.ctx);
1655 symbol.ctx = curContext;
1656 classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
1657 curContext.classDef = classDef;
1661 Expression MkExpInstance(Instantiation inst)
1663 return { type = instanceExp, instance = inst };
1666 External MkExternalClass(ClassDefinition _class)
1668 return { type = classExternal, _class = _class, symbol = _class.symbol };
1671 PropertyDef MkProperty(OldList specs, Declarator decl, Identifier id, Statement setStmt, Statement getStmt)
1681 Type type = ProcessType(specs, decl);
1684 char typeString[1024];
1685 typeString[0] = '\0';
1686 PrintType(type, typeString, false, true);
1687 id = MkIdentifier(typeString);
1688 prop.conversion = true;
1694 string = CopyString(id.string);
1697 symbol.idCode = symbol.id = globalContext.nextID++;
1698 excludedSymbols->Add(symbol);
1699 globalContext.nextID++;
1700 globalContext.nextID++;
1701 prop.symbol = symbol;
1705 ClassDef MkClassDefProperty(PropertyDef propertyDef)
1707 return { type = propertyClassDef, propertyDef = propertyDef };
1710 ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
1712 return { type = classPropertyClassDef, propertyDef = propertyDef };
1715 ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
1717 return { type = classPropertyValueClassDef, id = id, initializer = initializer };
1720 int CheckType(char * text)
1723 Time startTime = GetTime();
1725 if(FindTemplateTypeParameter(curContext, text))
1728 checkTypeTotalTime += GetTime() - startTime;
1732 if(FindType(curContext, text))
1735 checkTypeTotalTime += GetTime() - startTime;
1742 checkTypeTotalTime += GetTime() - startTime;
1744 return TYPE_NAME; //CLASS_NAME;
1747 checkTypeTotalTime += GetTime() - startTime;
1754 return CheckType(yytext);
1757 Context PushContext()
1759 Context ctx { parent = curContext };
1764 void PopContext(Context ctx)
1766 curContext = ctx.parent;
1769 Symbol FindType(Context ctx, char * name)
1774 type = (Symbol)ctx.types.FindString(name);
1775 if(!type && ctx.parent)
1776 type = FindType(ctx.parent, name);
1781 TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
1783 TemplatedType templatedType = null;
1786 templatedType = (TemplatedType)ctx.templateTypes.FindString(name);
1787 if(!templatedType && ctx.parent)
1788 templatedType = FindTemplateTypeParameter(ctx.parent, name);
1790 return templatedType;
1793 bool ModuleAccess(Module searchIn, Module searchFor)
1795 SubModule subModule;
1797 if(searchFor == searchIn)
1800 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
1802 if(subModule.importMode == publicAccess /*|| searchIn == searchIn.application*/)
1804 if(ModuleAccess(subModule.module, searchFor))
1811 ModuleImport FindModule(Module moduleToFind)
1813 ModuleImport module;
1814 if(!moduleToFind.name)
1816 for(module = imports->first; module; module = module.next)
1817 if(module.name && !strcmp(module.name, moduleToFind.name))
1821 module = ModuleImport
1823 name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
1824 importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
1826 imports->Add(module);
1832 // TO REMOVE: OBSOLETE...
1833 static void GetFullClassNameSpace(NameSpace * ns, char * name)
1837 GetFullClassNameSpace(ns->parent, name);
1838 strcat(name, ns->name);
1843 static char * GetFullClassName(Class c, char * name)
1845 NameSpace * nameSpace;
1847 GetFullClassNameSpace(c.nameSpace, name);
1848 strcat(name, c.name);
1853 public Symbol FindClass(char * name)
1856 Time startTime = GetTime();
1860 bool global = false;
1861 char fullName[1024];
1863 if(name[0] == ':' && name[1] == ':')
1869 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1871 int len = 0, stringLen;
1872 if(defaultNameSpace)
1874 memcpy(fullName, defaultNameSpace, defaultNameSpaceLen);
1875 len += defaultNameSpaceLen;
1876 fullName[len++] = ':';
1877 fullName[len++] = ':';
1879 if(currentNameSpace)
1881 memcpy(fullName + len, currentNameSpace, currentNameSpaceLen);
1882 len += currentNameSpaceLen;
1883 fullName[len++] = ':';
1884 fullName[len++] = ':';
1886 stringLen = strlen(name);
1887 memcpy(fullName + len, name, stringLen);
1890 cl = globalContext ? (Symbol)globalContext.classes.FindString(fullName) : null;
1894 cl = globalContext ? (Symbol)globalContext.classes.FindString(name) : null;
1899 Time startTime = GetTime();
1901 // Ignore name space name when searching
1902 for(cl = globalContext ? (Symbol)globalContext.classes.first : null; cl; cl = (Symbol)((BTNode)cl).next)
1906 char * string = cl.string;
1908 for(c = 0; (ch = string[c]); c++)
1910 if(ch == '.' || (ch == ':' && string[c+1] == ':'))
1916 if(start && c - start)
1918 if(!strcmp(string + start, name))
1922 if(cl.shortName && !strcmp(cl.shortName, name))
1926 findClassIgnoreNSTotalTime += GetTime() - startTime;
1932 if(!global && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
1933 _class = eSystem_FindClass(privateModule, fullName);
1935 _class = eSystem_FindClass(privateModule, name);
1939 name = _class.fullName;
1941 cl = (Symbol)globalContext.classes.FindString(name);
1946 string = CopyString(name);
1947 registered = _class;
1954 cl.module = FindModule(_class.module);
1956 cl.module = mainModule;
1957 if(!globalContext.classes.Add((BTNode)cl))
1958 excludedSymbols->Add(cl);
1959 if(strcmp(name, _class.name))
1960 cl.shortName = CopyString(_class.name);
1965 findClassTotalTime += GetTime() - startTime;
1970 void CopyTypeInto(Type type, Type src)
1973 type.name = CopyString(src.name);
1974 type.enumName = CopyString(src.enumName);
1977 if(src.kind == enumType)
1981 type.members.Clear();
1982 // This must have been a mistake: member = **type**.members.first
1983 for(member = src.members.first; member; member = member.next)
1985 type.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
1988 else if(src.kind == structType || src.kind == unionType)
1991 // Tricky stuff... will be removed from list only when ref count reaches 0
1992 for(member = type.members.first; member; member = member.next)
1995 else if(src.kind == functionType)
1998 type.returnType.refCount++;
1999 for(param = type.params.first; param; param = param.next)
2002 else if(src.kind == pointerType || src.kind == arrayType)
2004 type.type.refCount++;
2005 if(src.kind == arrayType)
2007 if(type.arraySizeExp)
2008 type.arraySizeExp = CopyExpression(type.arraySizeExp);
2014 public Type ProcessType(OldList specs, Declarator decl)
2017 bool isTypedef = false;
2018 if(!specs || specs.first)
2020 Declarator funcDecl = GetFuncDecl(decl);
2022 bool dllExport = false;
2024 specType.kind = intType;
2025 specType.isSigned = true;
2026 specType.refCount = 1;
2028 type = Type { refCount = 1 };
2030 while(decl && (decl.type == structDeclarator || decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd))
2032 if(decl.type == structDeclarator && decl.structDecl.exp)
2034 ProcessExpressionType(decl.structDecl.exp);
2035 ComputeExpression(decl.structDecl.exp);
2036 if(decl.structDecl.exp.type == constantExp)
2037 specType.bitFieldCount = strtoul(decl.structDecl.exp.constant, null, 0);
2039 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended &&
2040 (!strcmp(decl.extended.extended, "__declspec(dllexport)") || !strcmp(decl.extended.extended, "dllexport")))
2044 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended &&
2045 (strstr(decl.extended.extended, "__attribute__")))
2047 specType.keepCast = true;
2049 decl = decl.declarator;
2052 // If we'll be using the specType
2053 if(funcDecl || !decl || decl.type == identifierDeclarator)
2058 bool isLong = false;
2059 for(spec = specs.first; spec; spec = spec.next)
2061 if(spec.type == extendedSpecifier && (!strcmp(spec.name, "__declspec(dllexport)") || !strcmp(spec.name, "dllexport")))
2065 if(spec.type == extendedSpecifier && strstr(spec.name, "__attribute__"))
2067 specType.keepCast = true;
2070 if(spec.specifier != CONST && (specType.kind == structType || specType.kind == unionType))
2073 specType = { kind = intType, isSigned = true, refCount = 1 };
2076 if(spec.type == baseSpecifier)
2078 if(spec.specifier == TYPEDEF) isTypedef = true;
2079 else if(spec.specifier == VOID) specType.kind = voidType;
2080 else if(spec.specifier == CHAR) specType.kind = charType;
2081 else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
2082 else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
2083 else if(spec.specifier == INT64) specType.kind = int64Type;
2084 else if(spec.specifier == VALIST)
2085 specType.kind = vaListType;
2086 else if(spec.specifier == SHORT) specType.kind = shortType;
2087 else if(spec.specifier == LONG)
2090 specType.kind = int64Type;
2092 specType.kind = intType;
2094 // specType.kind = longType;
2096 else if(spec.specifier == FLOAT) specType.kind = floatType;
2097 else if(spec.specifier == DOUBLE) specType.kind = doubleType;
2098 else if(spec.specifier == SIGNED) specType.isSigned = true;
2099 else if(spec.specifier == UNSIGNED) specType.isSigned = false;
2100 else if(spec.specifier == CONST) specType.constant = true;
2101 else if(spec.specifier == TYPED_OBJECT)
2103 specType.classObjectType = typedObject; specType.kind = classType; specType._class = FindClass("class");
2105 else if(spec.specifier == ANY_OBJECT)
2107 specType.classObjectType = anyObject; specType.kind = classType; specType._class = FindClass("class");
2109 else if(spec.specifier == CLASS)
2111 specType.classObjectType = classPointer; specType.kind = classType; specType._class = FindClass("class");
2113 else if(spec.specifier == THISCLASS)
2114 specType.kind = thisClassType;
2116 else if(spec.type == nameSpecifier)
2118 Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
2119 if(symbol && symbol.type)
2121 // Free Type Contents:
2126 CopyTypeInto(specType, symbol.type);
2127 specType.typeName = CopyString(symbol.type.name);
2129 else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
2131 // key.sym enum values need FindClass:
2132 specType._class = spec.name ? FindClass(spec.name) : null;
2133 // specType._class = spec.symbol;
2134 specType.kind = classType;
2135 if(!specType._class)
2136 specType.kind = intType;
2139 else if(spec.type == enumSpecifier)
2142 specType.kind = enumType;
2143 specType.enumName = spec.id ? CopyString(spec.id.string) : null;
2149 for(e = spec.list->first; e; e = e.next)
2151 // TOFIX: NamedItem i { } causes cryptic error, bad .c!
2152 NamedLink i { name = CopyString(e.id.string) };
2153 specType.members.Add(i);
2155 if(e.exp && ComputeExpression(e.exp), e.exp.isConstant && e.exp.expType.kind == intType)
2156 value.data = (void *) nextValue = strtol(e.exp.string, null, 0);
2158 value.data = (void *)nextValue++;
2166 for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
2167 if(decl.declarators)
2170 for(d = decl.declarators.first; d; d = d.next)
2172 Type memberType = ProcessType(decl.specifiers, d);
2173 specType.members.Add(memberType);
2176 else if(decl.specifiers)
2178 Type memberType = ProcessType(decl.specifiers, null);
2179 specType.members.Add(memberType);
2184 else if(spec.type == templateTypeSpecifier)
2187 printf("spec %x\n", spec);
2188 printf("template param %x\n", spec.templateParameter);
2189 printf("identifier %x\n", spec.templateParameter.identifier);
2190 printf("string %x\n", spec.templateParameter.identifier.string);
2192 specType.kind = templateType;
2193 specType.templateParameter = spec.templateParameter;
2195 else if(spec.type == structSpecifier || spec.type == unionSpecifier)
2197 Symbol _class = spec.id ? FindClass(spec.id.string) : null;
2200 if(!_class.registered || _class.registered.type != structClass)
2201 specType.directClassAccess = true;
2202 specType._class = _class;
2203 specType.kind = classType;
2206 if(spec.type == structSpecifier)
2207 specType.kind = structType;
2208 else if(spec.type == unionSpecifier)
2209 specType.kind = unionType;
2212 // TESTING THIS HERE... Had 0 type size
2213 if(!spec.definitions && !isTypedef)
2215 Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
2216 if(symbol && symbol.type)
2218 specType = *symbol.type;
2219 specType.name = CopyString(symbol.type.name);
2220 specType.typeName = CopyString(spec.name);
2221 specType.enumName = CopyString(symbol.type.enumName);
2222 specType.refCount = 1;
2224 if(symbol.type.kind == enumType)
2228 specType.members.Clear();
2229 for(member = symbol.type.members.first; member; member = member.next)
2231 NamedLink item { name = CopyString(member.name), data = member.data };
2232 specType.members.Add(item);
2235 else if(symbol.type.kind == structType || symbol.type.kind == unionType)
2238 // Tricky stuff... will be removed from list only when ref count reaches 0
2239 for(member = specType.members.first; member; member = member.next)
2242 else if(symbol.type.kind == functionType)
2245 specType.returnType.refCount++;
2246 for(param = specType.params.first; param; param = param.next)
2249 else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
2251 specType.type.refCount++;
2252 if(symbol.type.kind == arrayType)
2254 if(specType.arraySizeExp)
2255 specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
2261 specType.enumName = CopyString(spec.id.string);
2264 specType.enumName = CopyString(spec.id.string);
2267 if(spec.definitions)
2270 for(def = spec.definitions->first; def; def = def.next)
2272 if(def.type == declarationClassDef && def.decl.type == structDeclaration)
2274 Declaration decl = def.decl;
2275 if(decl.declarators)
2278 for(d = decl.declarators->first; d; d = d.next)
2280 Type memberType = ProcessType(decl.specifiers, d);
2281 specType.members.Add(memberType);
2284 else if(decl.specifiers)
2286 Type memberType = ProcessType(decl.specifiers, null);
2287 specType.members.Add(memberType);
2294 else if(spec.type == subClassSpecifier)
2296 specType.kind = specType.kind = subClassType;
2297 specType._class = spec._class.symbol; // FindClass(spec._class.name);
2300 else if(spec.type == classSpecifier)
2302 specType._class = FindClass(spec.name);
2303 specType.kind = classType;
2309 specType.kind = ellipsisType;
2314 Declarator d = funcDecl.declarator;
2318 funcType.kind = functionType;
2319 funcType.refCount = 1;
2320 if(funcDecl.function.parameters)
2322 for(param = funcDecl.function.parameters->first; param; param = param.next)
2325 if(param.typedObject)
2327 Type typedObjectType
2330 byReference = param.byReference;
2331 kind = TypeTypedObject;
2333 funcType.params.Add(typedObjectType);
2336 funcType.params.Add(ProcessType(param.qualifiers, param.declarator));
2340 // Function returning a pointer...
2341 if(decl.type == pointerDeclarator)
2343 Pointer pointer = decl.pointer.pointer;
2345 funcType.returnType = ptrType;
2346 funcType.returnType.refCount = 1;
2349 ptrType.kind = pointerType;
2350 pointer = pointer.pointer;
2353 ptrType.type = Type { refCount = 1 };
2354 ptrType = ptrType.type;
2357 ptrType.type = Type { refCount = 1 };
2358 *ptrType.type = specType;
2362 funcType.returnType = Type { refCount = 1 };
2363 *funcType.returnType = specType;
2366 // TESTING: Added extendedDeclarator here
2367 while(d && (d.type == bracketsDeclarator || d.type == extendedDeclarator || d.type == extendedDeclaratorEnd))
2369 if((d.type == extendedDeclarator || d.type == extendedDeclaratorEnd) && d.extended.extended &&
2370 (!strcmp(d.extended.extended, "__declspec(dllexport)") || !strcmp(d.extended.extended, "dllexport")))
2377 funcType.dllExport = dllExport;
2379 if(d && d.type == pointerDeclarator)
2384 if(d.declarator && d.declarator.type == arrayDeclarator)
2386 // Arrays of pointers to functions (extremely tricky :()
2387 Pointer pointer = d.pointer.pointer;
2389 // TO WORK ON: Fixed the order for the array...
2390 type.kind = arrayType;
2391 type.arraySizeExp = CopyExpression(d.declarator.array.exp);
2392 type.freeExp = true;
2393 if(d.declarator.array.enumClass)
2394 type.enumClass = d.declarator.array.enumClass.symbol; // FindClass(d.declarator.array.enumClass.name);
2395 if(d.declarator.declarator && d.declarator.declarator.type == arrayDeclarator)
2397 Type tmpType = type;
2399 type = ProcessType(null, d.declarator.declarator);
2401 type.type = tmpType;
2402 tmpType.type = inType;
2405 type.type = ProcessType(null, d.declarator.declarator);
2407 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2411 ptrType.kind = pointerType;
2412 pointer = pointer.pointer;
2415 ptrType.type = Type { refCount = 1 };
2416 ptrType = ptrType.type;
2419 ptrType.type = ProcessType(specs, null);
2423 // WARNING: Not caring if this declarator contains a declarator between
2424 // the pointer and the function other than brackets (like in the case of array of pointers to functions)...
2425 // *********** Could it ever go in here??? Yes: void (* converters_table[10]) (); ***********
2426 Pointer pointer = d.pointer.pointer;
2431 ptrType.kind = pointerType;
2432 ptrType.type = Type { refCount = 1 };
2433 pointer = pointer.pointer;
2435 ptrType = ptrType.type;
2439 *ptrType.type = funcType;
2443 if(id._class && !id._class.name)
2444 ptrType.type.staticMethod = true;
2447 // TODO : Ensure classSym has been resolved here... (Is this gonna cause problems? Supposed to do this later...)
2450 if(id._class && id._class.name)
2452 id.classSym = id._class.symbol; // FindClass(id._class.name);
2453 /* TODO: Name Space Fix ups
2455 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
2460 ptrType.type.thisClass = id.classSym;
2461 if(ptrType.type.thisClass && strcmp(ptrType.type.thisClass.string, "class"))
2462 ptrType.type.extraParam = true;
2463 else if(id._class && id._class.name && !strcmp(id._class.name, "any_object"))
2465 ptrType.type.extraParam = true;
2466 ptrType.type.thisClass = FindClass("class");
2470 type.name = CopyString(id.string);
2473 else if(!d || d.type == identifierDeclarator)
2479 if(d.identifier._class && d.identifier._class.type == templateTypeSpecifier)
2481 type.thisClassTemplate = d.identifier._class.templateParameter;
2482 type.extraParam = true;
2486 if(d.identifier._class && !d.identifier._class.name)
2487 type.staticMethod = true;
2490 if(d.identifier._class && d.identifier._class.name && d.identifier._class.name[strlen(d.identifier._class.name)-1] == '&')
2492 type.thisClass = FindClass("class");
2493 type.byReference = true;
2496 type.thisClass = d.identifier._class ? d.identifier._class.symbol /*FindClass(d.identifier._class.name)*/ : null;
2497 if(type.thisClass && strcmp(type.thisClass.string, "class"))
2499 type.extraParam = true;
2501 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "any_object"))
2503 type.extraParam = true;
2504 type.thisClass = FindClass("class");
2506 else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "class"))
2508 //type.extraParam = true;
2509 type.thisClass = FindClass("class");
2510 type.classObjectType = classPointer;
2514 type.name = CopyString(d.identifier.string);
2519 else if(decl && decl.type == pointerDeclarator)
2521 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2523 // Arrays of pointers (tricky :))
2525 Pointer pointer = decl.pointer.pointer;
2528 // TO WORK ON: Fixed the order for the array...
2529 type.kind = arrayType;
2530 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2531 type.freeExp = true;
2532 if(decl.declarator.array.enumClass)
2533 type.enumClass = decl.declarator.array.enumClass.symbol; // FindClass(decl.declarator.array.enumClass.name);
2534 if(decl.declarator.declarator && decl.declarator.declarator.type == arrayDeclarator)
2536 Type tmpType = type;
2538 type = ProcessType(null, decl.declarator.declarator);
2540 type.type = tmpType;
2541 tmpType.type = inType;
2544 type.type = ProcessType(null, decl.declarator.declarator);
2546 type.type = ProcessType(null, decl.declarator.declarator);
2547 type.kind = arrayType;
2548 type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
2549 type.arraySizeExp.freeExp = true;
2550 if(decl.array.enumClass)
2551 type.enumClass = FindClass(decl.array.enumClass.name);
2554 for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
2558 ptrType.kind = pointerType;
2559 pointer = pointer.pointer;
2562 ptrType.type = Type { refCount = 1 };
2563 ptrType = ptrType.type;
2566 ptrType.type = ProcessType(specs, null);
2567 id = GetDeclId(decl);
2568 if(id) type.name = CopyString(id.string);
2573 Pointer pointer = decl.pointer.pointer;
2574 Type ptrType = type;
2576 if(type.classObjectType)
2578 type.byReference = true;
2584 ptrType.kind = pointerType;
2585 pointer = pointer.pointer;
2588 ptrType.type = Type { refCount = 1 };
2589 ptrType = ptrType.type;
2592 ptrType.type = ProcessType(specs, decl.declarator);
2594 if(type.type.classObjectType)
2596 Type subType = type.type;
2597 type.classObjectType = subType.classObjectType;
2598 type.kind = subType.kind;
2599 type._class = subType._class;
2600 type.byReference = true;
2604 id = GetDeclId(decl);
2605 if(id) type.name = CopyString(id.string);
2609 else if(decl && decl.type == arrayDeclarator)
2613 type.kind = arrayType;
2615 type.arraySizeExp = CopyExpression(decl.array.exp);
2616 type.freeExp = true;
2617 if(decl.array.enumClass)
2618 type.enumClass = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
2619 id = GetDeclId(decl);
2621 // TO WORK ON: Fixed the order for the array...
2622 if(decl.declarator && decl.declarator.type == arrayDeclarator)
2624 Type tmpType = type;
2626 type = ProcessType(specs, decl.declarator);
2628 type.type = tmpType;
2629 tmpType.type = inType;
2632 type.type = ProcessType(specs, decl.declarator);
2637 type.name = CopyString(id.string);
2642 if(!decl || decl.type == identifierDeclarator)
2646 type.name = decl ? CopyString(decl.identifier.string) : null;
2655 public Type ProcessTypeString(char * string, bool staticMethod)
2657 OldList * specs = MkList();
2658 Declarator decl = SpecDeclFromString(string, specs, null);
2659 Type type = ProcessType(specs, decl);
2660 if(type && !type.thisClass && staticMethod) type.staticMethod = true;
2661 FreeList(specs, FreeSpecifier);
2662 if(decl) FreeDeclarator(decl);
2666 Type MkClassTypeSymbol(Symbol symbol)
2670 Type type { kind = classType, _class = symbol };
2673 // Defaults to an int instead...
2674 type.kind = intType;
2682 public Type MkClassType(char * name)
2686 Type type { kind = classType, _class = FindClass(name) };
2689 // Defaults to an int instead...
2690 type.kind = intType;
2698 AsmField MkAsmField(char * command, Expression expression)
2700 return { command = command, expression = expression };
2703 Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
2705 return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
2706 asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
2707 asmStmt.clobberedFields = clobberedFields };
2710 ClassDef MkClassDefPropertyWatch(PropertyWatch watcher)
2712 return { type = propertyWatchClassDef, propertyWatch = watcher };
2715 Statement MkFireWatchersStmt(Expression object, OldList watches)
2717 return { type = fireWatchersStmt, _watch.object = object, _watch.watches = watches };
2720 Statement MkStopWatchingStmt(Expression watcher, Expression object, OldList watches)
2722 return { type = stopWatchingStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2725 Statement MkWatchStmt(Expression watcher, Expression object, OldList watches)
2727 return { type = watchStmt, _watch.watcher = watcher, _watch.object = object, _watch.watches = watches };
2730 PropertyWatch MkDeleteWatch(Statement compound)
2732 return { compound = compound, deleteWatch = true };
2735 PropertyWatch MkPropertyWatch(OldList properties, Statement compound)
2737 return { compound = compound, properties = properties };
2740 Expression MkExpClass(OldList * specifiers, Declarator decl)
2742 return { type = classExp, _classExp.specifiers = specifiers, _classExp.decl = decl };
2745 Expression MkExpClassData(Identifier id)
2747 return { type = classDataExp, classData.id = id };
2751 External MkExternalDBTable(DBTableDef table)
2753 return { type = dbtableExternal, table = table };
2756 DBTableDef MkDBTableDef(char * name, Symbol symbol, OldList * definitions)
2758 return { name = name, symbol = symbol, definitions = definitions };
2761 DBTableEntry MkDBFieldEntry(TypeName type, Identifier id, char * name)
2763 return { type = fieldEntry, dataType = type, id = id, name = name };
2766 DBIndexItem MkDBIndexItem(Identifier id, Order order)
2768 return { id = id, order = order };
2771 DBTableEntry MkDBIndexEntry(OldList * items, Identifier id)
2773 return { type = indexEntry, items = items, id = id };
2776 Expression MkExpDBOpen(Expression ds, Expression dbName)
2778 return { type = dbopenExp, dbopen.ds = ds, dbopen.name = dbName };
2781 Expression MkExpDBField(char * table, Identifier id)
2783 return { type = dbfieldExp, db.table = table, db.id = id };
2786 Expression MkExpDBIndex(char * table, Identifier id)
2788 return { type = dbindexExp, db.table = table, db.id = id };
2791 Expression MkExpDBTable(char * table)
2793 return { type = dbtableExp, db.table = table };
2796 Expression MkExpArray(OldList * expressions)
2798 return { type = arrayExp, list = expressions };
2801 Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplateParameterType tplType)
2803 Expression argExp = null;
2804 Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
2808 ClassTemplateParameter curParam;
2810 for(sClass = _class; sClass; sClass = sClass.base)
2813 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2815 if(!strcmp(curParam.name, paramName))
2817 for(sClass = sClass.base; sClass; sClass = sClass.base)
2818 id += sClass.templateParams.count;
2826 if(curParam && curParam.type != tplType)
2832 char className[1024];
2833 Expression classExp;
2835 sprintf(idString, "%d", id);
2836 strcpy(className, "__ecereClass_");
2837 FullClassNameCat(className, _class.fullName, true);
2838 MangleClassName(className);
2839 DeclareClass(FindClass(_class.fullName), className);
2841 argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
2842 (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
2843 MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
2849 Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
2851 return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
2854 /*char * CreateMsgID(char * string, char * context)
2856 int lenString = strlen(string), lenContext = strlen(context);
2857 char * msgid = new char[lenString + lenContext + 20];
2858 memcpy(msgid, string, lenString);
2859 memcpy(msgid+lenString, " [msgctxt: ", 11);
2860 memcpy(msgid+lenString+11, context, lenContext);
2861 memcpy(msgid+lenString+11+lenContext, "]", 2);
2865 public void OutputIntlStrings()
2867 if(intlStrings.count)
2869 char * srcFile = GetSourceFile();
2870 char * objFile = GetOutputFile();
2871 char srcFileFixed[MAX_LOCATION];
2872 char potFile[MAX_LOCATION];
2874 ChangeExtension(objFile, "bowl", potFile);
2875 f = FileOpen(potFile, write);
2878 char * filePrefix = "";
2879 if(!(srcFile[0] && (srcFile[1] == ':' || srcFile[0] == '/')))
2880 filePrefix = (GetRuntimePlatform() == win32) ? ".\\" : "./";
2881 GetSystemPathBuffer(srcFileFixed, srcFile);
2882 for(s : intlStrings)
2884 // TOFIX: (#654) ContextStringPair * pair = &s;
2885 ContextStringPair pair = &s;
2887 f.Printf("#: %s%s:%d\n", filePrefix, srcFileFixed, l.start.line);
2888 // PoEdit now preserves and distinguish msgctxt
2890 f.Printf("msgctxt \"%s\"\n", pair.context);
2891 f.Printf("msgid \"%s\"\n", pair.string);
2892 f.Printf("msgstr \"%s\"\n\n", pair.string);
2900 default extern OldList * ast;
2901 default extern int yyparse ();
2903 public void SetAST(OldList * list) { ast = list; }
2904 public OldList * GetAST() { return ast; }
2905 public void ParseEc()