#include "grammar.h"
extern char * yytext;
-char * defaultNameSpace;
+const char * defaultNameSpace;
int defaultNameSpaceLen;
-public void SetDefaultNameSpace(char * s) { defaultNameSpace = s; defaultNameSpaceLen = s ? strlen(s) : 0; }
+public void SetDefaultNameSpace(const char * s) { defaultNameSpace = s; defaultNameSpaceLen = s ? strlen(s) : 0; }
bool strictNameSpaces;
public void SetStrictNameSpaces(bool b) { strictNameSpaces = b; }
AccessMode defaultDeclMode = privateAccess;
public void SetDefaultDeclMode(AccessMode accessMode) { defaultDeclMode = accessMode; }
-char * currentNameSpace;
+const char * currentNameSpace;
int currentNameSpaceLen;
-public void SetCurrentNameSpace(char * s) { currentNameSpace = s; currentNameSpaceLen = s ? strlen(s) : 0; }
+public void SetCurrentNameSpace(const char * s) { currentNameSpace = s; currentNameSpaceLen = s ? strlen(s) : 0; }
#ifdef _TIMINGS
Time findClassTotalTime;
list.Insert(null, item);
}
-public Identifier MkIdentifier(char * string)
+public Identifier MkIdentifier(const char * string)
{
Identifier id { };
int c;
if(string)
{
- char * namePart;
+ const char * namePart;
bool gotColon = false;
for(c = strlen(string)-1; c >= 0; c--)
if(string[c] == ':')
public Expression MkExpIdentifier(Identifier id)
{
- return { type = identifierExp, identifier = id };
+ return { type = identifierExp, identifier = id, loc = yylloc };
}
public Expression MkExpDummy()
return exp;
}
-public Expression MkExpConstant(char * string)
+public Expression MkExpConstant(const char * string)
{
- return { type = constantExp, constant = CopyString(string) };
+ return { type = constantExp, constant = CopyString(string), loc = yylloc };
}
-Expression MkExpString(char * string)
+Expression MkExpString(const char * string)
{
- return { type = stringExp, string = CopyString(string) };
+ return { type = stringExp, string = CopyString(string), loc = yylloc };
+}
+
+Expression MkExpWideString(const char * string)
+{
+ return { type = stringExp, string = CopyString(string), loc = yylloc, wideString = true };
}
// TODO: String is case sensitive..
Map<ContextStringPair, List<Location>> intlStrings { };
-Expression MkExpIntlString(char * string, char * context)
+Expression MkExpIntlString(const char * string, const char * context)
{
if(inCompiler)
{
OldList * list = MkList();
+ String s;
if(inCompiler)
{
ContextStringPair pair { };
list.Add(yylloc);
}
//ListAdd(list, QMkExpId("__thisModule"));
- ListAdd(list, MkExpString(QMkString(i18nModuleName ? i18nModuleName : "")));
+ s = QMkString(i18nModuleName ? i18nModuleName : "");
+ ListAdd(list, MkExpString(s));
+ delete s;
ListAdd(list, MkExpString(string));
if(context)
{
Expression MkExpCall(Expression expression, OldList arguments)
{
- return { type = callExp, call.exp = expression, call.arguments = arguments };
+ return { type = callExp, call.exp = expression, call.arguments = arguments, loc = yylloc };
}
Expression MkExpMember(Expression expression, Identifier member)
{
- return { type = memberExp, member.exp = expression, member.member = member };
+ return { type = memberExp, member.exp = expression, member.member = member, loc = yylloc };
}
Expression MkExpPointer(Expression expression, Identifier member)
{
- return { type = pointerExp, member.exp = expression, member.member = member };
+ return { type = pointerExp, member.exp = expression, member.member = member, loc = yylloc };
}
Expression MkExpTypeSize(TypeName typeName)
{
- return { type = typeSizeExp, typeName = typeName };
+ return { type = typeSizeExp, typeName = typeName, loc = yylloc };
}
Expression MkExpTypeAlign(TypeName typeName)
{
- return { type = typeAlignExp, typeName = typeName };
+ return { type = typeAlignExp, typeName = typeName, loc = yylloc };
}
Expression MkExpClassSize(Specifier _class)
{
- return { type = classSizeExp, _class = _class };
+ return { type = classSizeExp, _class = _class, loc = yylloc };
}
Expression MkExpCast(TypeName typeName, Expression expression)
{
- return { type = castExp, cast.typeName = typeName, cast.exp = expression };
+ return { type = castExp, cast.typeName = typeName, cast.exp = expression, loc = yylloc };
}
Expression MkExpCondition(Expression cond, OldList expressions, Expression elseExp)
{
- return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp };
+ return { type = conditionExp, cond.cond = cond, cond.exp = expressions, cond.elseExp = elseExp, loc = yylloc };
}
Expression MkExpRenew(Expression memExp, TypeName type, Expression size)
{
- return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
+ return { type = renewExp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size, loc = yylloc };
}
Expression MkExpRenew0(Expression memExp, TypeName type, Expression size)
{
- return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size };
+ return { type = renew0Exp, _renew.exp = memExp, _renew.typeName = type, _renew.size = size, loc = yylloc };
}
Expression MkExpNew(TypeName type, Expression size)
{
- return { type = newExp, _new.typeName = type, _new.size = size };
+ return { type = newExp, _new.typeName = type, _new.size = size, loc = yylloc };
}
Expression MkExpNew0(TypeName type, Expression size)
{
- return { type = new0Exp, _new.typeName = type, _new.size = size };
+ return { type = new0Exp, _new.typeName = type, _new.size = size, loc = yylloc };
}
Expression MkExpVaArg(Expression exp, TypeName type)
{
- return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type };
+ return { type = vaArgExp, vaArg.exp = exp, vaArg.typeName = type, loc = yylloc };
}
Specifier MkSpecifier(int specifier)
next = spec.next;
if(gotType && !declarator && ((spec.type == nameSpecifier && spec.name) || (spec.type == baseSpecifier && gotFullType)))
{
- String s = null;
+ const String s = null;
if(spec.type == nameSpecifier)
{
char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
string = (inst.exp.type == identifierExp) ? CopyString(inst.exp.identifier.string) : null;
type = MkClassTypeSymbol(inst._class.symbol);
};
- symbol.idCode = symbol.id = curContext.nextID++;
if(strstr(symbol.string, "::"))
curContext.hasNameSpace = true;
if(!(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.Add((BTNode)symbol))
string = CopyString(GetDeclId(d.declarator).string);
type = ProcessType(specifiers, d.declarator);
};
- type.id = type.idCode = curContext.nextID++;
if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
excludedSymbols->Add(type);
{
if((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier)
{
- String s = null;
+ const String s = null;
if(spec.type == nameSpecifier)
{
- char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
+ const char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
s = colon ? colon + 2 : spec.name;
}
else if(spec.type == baseSpecifier)
if(s)
{
Symbol type { string = CopyString(s), type = ProcessType(specifiers, null) };
- type.id = type.idCode = curContext.nextID++;
decl.symbol = type;
decl.declarators = initDeclarators = MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
specifiers.Remove(spec);
{
if(gotType && initDeclarators == null && !spec.next && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
{
- String s = null;
+ const String s = null;
if(spec.type == nameSpecifier)
{
char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
symbol.type.freeExp = true;
}
}
- symbol.id = symbol.idCode = curContext.nextID++;
}
decl.symbol = d.declarator.symbol = symbol;
}
else
{
decl.symbol = Symbol { };
- decl.symbol.id = decl.symbol.idCode = curContext.nextID++;
excludedSymbols->Add(decl.symbol);
}
return decl;
next = spec.next;
if(gotType && declarators == null && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
{
- String s = null;
+ const String s = null;
if(spec.type == nameSpecifier)
{
- char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
+ const char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
s = colon ? colon + 2 : spec.name;
}
else if(spec.type == baseSpecifier)
if(!context.symbols.Add((BTNode)symbol))
excludedSymbols->Add(symbol);
- // TODO: Fix this, the parameters' IDs should really be smaller...
- symbol.id = context.nextID++;
param.declarator.symbol = symbol;
}
}
id.string = CopyString(name);
}
symbol = Symbol { string = CopyString(id.string), type = ProcessType(func.specifiers, declarator) };
- symbol.idCode = symbol.id = globalContext.nextID++;
if(strstr(symbol.string, "::"))
globalContext.hasNameSpace = true;
if(!globalContext.symbols.Add((BTNode)symbol))
External MkExternalDeclaration(Declaration declaration)
{
External external { type = declarationExternal, declaration = declaration, symbol = declaration ? declaration.symbol : null };
- InitDeclarator d = (declaration && declaration.declarators) ? declaration.declarators->last : null;
if(declaration && declaration.type == initDeclaration && declaration.specifiers)
{
Specifier spec;
if(!symbol && spec.symbol)
{
// If class was only decl'ed, invoke DeclClass on this templated class as well
- symbol = _DeclClass(MAXINT, templateString);
+ symbol = _DeclClass(null, templateString);
+ symbol.notYetDeclared = true;
}
// Add a reference to all templated class to the basic class
if(spec.symbol)
FreeList(templateArgs, FreeTemplateArgument);
}
-Specifier _MkSpecifierName(char * name, Symbol symbol, OldList templateArgs)
+Specifier _MkSpecifierName(const char * name, Symbol symbol, OldList templateArgs)
{
Specifier spec { type = nameSpecifier };
}
}
else if(symbol)
+ {
+ char nameSpace[1024];
+ char * c = strstr(name, symbol.string);
spec.name = CopyString(symbol.string);
+ if(c && c >= name + 2 && c[-1] == ':' && c[-2] == ':')
+ {
+ if(c > name + 2)
+ {
+ memcpy(nameSpace, name, c - name - 2);
+ nameSpace[c-name] = 0;
+ spec.nsSpec = _MkSpecifierName(nameSpace, null, null);
+ }
+ else
+ spec.nsSpec = _MkSpecifierName(null, null, null);
+ }
+ }
else
spec.name = CopyString(name);
spec.symbol = symbol;
return spec;
}
-public Specifier MkSpecifierName(char * name)
+public Specifier MkSpecifierName(const char * name)
{
return _MkSpecifierName(name, null, null);
}
-public Specifier MkSpecifierNameArgs(char * name, OldList * templateArgs)
+public Specifier MkSpecifierNameArgs(const char * name, OldList * templateArgs)
{
return _MkSpecifierName(name, null, templateArgs);
}
/*
-Specifier MkClassName(char * string)
+Specifier MkClassName(const char * string)
{
return { type = SpecifierClass, name = CopyString(string) };
}
isParam = true;
};
- // TODO: Fix this, the parameters' IDs should really be smaller...
- symbol.idCode = symbol.id = context.nextID++;
if(!context.symbols.Add((BTNode)symbol))
excludedSymbols->Add(symbol);
symbolSpecs->Add(CopySpecifier(spec));
}
symbol.type = ProcessType(symbolSpecs, decl);
- symbol.idCode = symbol.id = globalContext.nextID++;
decl.symbol = symbol;
excludedSymbols->Add(symbol);
return { type = classDataClassDef, decl = decl };
}
-ClassDef MkClassDefDesigner(char * designer)
+ClassDef MkClassDefDesigner(const char * designer)
{
return { type = classDesignerClassDef, designer = CopyString(designer) };
}
return def;
}
-Symbol DeclClassAddNameSpace(int symbolID, char * className)
+Symbol DeclClassAddNameSpace(Specifier _class, const char * className)
{
char name[1024];
int len = 0, stringLen;
name[0] = '\0';
- if((currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess)
+ if(className[0] != ':' && (currentNameSpace || defaultNameSpace) && declMode != defaultAccess && defaultDeclMode != defaultAccess && (!_class || _class.name))
{
if(defaultNameSpace)
{
memcpy(name + len, className, stringLen);
len += stringLen;
name[len] = 0;
- return _DeclClass(symbolID, name);
+ return _DeclClass(_class, name);
}
-Symbol DeclClass(int symbolID, char * name)
+Symbol DeclClass(Specifier _class, const char * name)
{
- if(strchr(name, ':'))
- return _DeclClass(symbolID, name);
+ if(_class || strchr(name, ':'))
+ return _DeclClass(_class, name);
else
- return DeclClassAddNameSpace(symbolID, name);
+ return DeclClassAddNameSpace(_class, name);
}
-Symbol _DeclClass(int symbolID, char * name)
+Symbol _DeclClass(Specifier _class, const char * name)
{
- Symbol symbol = FindClass(name);
+ Symbol symbol;
+ char nameBuffer[1024];
+ if(_class)
+ {
+ strcpy(nameBuffer, _class.name ? _class.name : "");
+ strcat(nameBuffer, "::");
+ strcat(nameBuffer, name);
+ name = nameBuffer;
+ }
+
+ symbol = FindClass(name);
if(!symbol)
{
/*
symbol = Symbol
{
string = CopyString(name);
- idCode = symbolID, id = symbolID;
+ notYetDeclared = true;
};
if(!globalContext.classes.Add((BTNode)symbol))
excludedSymbols->Add(symbol);
symbol.shortName = CopyString(name + start);
}
}
- if(symbolID)
- symbol.idCode = symbol.id = symbolID;
return symbol;
}
delete symbol.ctx;
}
symbol.ctx = curContext;
- classDef = { symbol = symbol, _class = MkSpecifierName /*MkClassName*/(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
+ classDef = { symbol = symbol, _class = MkSpecifierName(symbol.string), baseSpecs = baseSpecs, definitions = definitions, nameLoc = symbol.nameLoc };
curContext.classDef = classDef;
return classDef;
}
string = CopyString(id.string);
type = type;
};
- symbol.idCode = symbol.id = globalContext.nextID++;
excludedSymbols->Add(symbol);
- globalContext.nextID++;
- globalContext.nextID++;
prop.symbol = symbol;
return prop;
}
ClassDef MkClassDefProperty(PropertyDef propertyDef)
{
- return { type = propertyClassDef, propertyDef = propertyDef };
+ return { type = propertyClassDef, propertyDef = propertyDef, loc = yylloc };
}
ClassDef MkClassDefClassProperty(PropertyDef propertyDef)
{
- return { type = classPropertyClassDef, propertyDef = propertyDef };
+ return { type = classPropertyClassDef, propertyDef = propertyDef, loc = yylloc };
}
ClassDef MkClassDefClassPropertyValue(Identifier id, Initializer initializer)
{
- return { type = classPropertyValueClassDef, id = id, initializer = initializer };
+ return { type = classPropertyValueClassDef, id = id, initializer = initializer, loc = yylloc };
}
-int CheckType(char * text)
+int CheckType(const char * text)
{
#ifdef _TIMINGS
Time startTime = GetTime();
curContext = ctx.parent;
}
-Symbol FindType(Context ctx, char * name)
+Symbol FindType(Context ctx, const char * name)
{
Symbol type = null;
- if(curContext)
+ if(ctx)
{
//char output[8192];
type = (Symbol)ctx.types.FindString(name);
return type;
}
-TemplatedType FindTemplateTypeParameter(Context ctx, char * name)
+Symbol FindStruct(Context ctx, const char * name)
+{
+ Symbol type = null;
+ if(ctx)
+ {
+ type = (Symbol)ctx.structSymbols.FindString(name);
+ if(!type && ctx.parent)
+ type = FindStruct(ctx.parent, name);
+ }
+ return type;
+}
+
+TemplatedType FindTemplateTypeParameter(Context ctx, const char * name)
{
TemplatedType templatedType = null;
if(curContext)
}
*/
-public Symbol FindClass(char * name)
+public Symbol FindClass(const char * name)
{
-#ifdef _DEBUG
+#ifdef _TIMINGS
Time startTime = GetTime();
#endif
Symbol cl = null;
{
string = CopyString(name);
registered = _class;
- id = MAXINT;
- idCode = MAXINT;
+ notYetDeclared = true;
imported = true;
};
_class.symbol = cl;
void CopyTypeInto(Type type, Type src)
{
type = *src;
+
type.name = CopyString(src.name);
+ type.typeName = CopyString(src.typeName);
type.refCount = 1;
if(src.kind == enumType)
{
- NamedLink member;
+ NamedLink64 member;
type.members.Clear();
// This must have been a mistake: member = **type**.members.first
for(member = src.members.first; member; member = member.next)
{
- type.members.Add(NamedLink { name = CopyString(member.name), data = member.data });
+ type.members.Add(NamedLink64 { name = CopyString(member.name), data = member.data });
}
type.enumName = CopyString(src.enumName);
}
if(type.arraySizeExp)
type.arraySizeExp = CopyExpression(type.arraySizeExp);
}
-
}
}
ExtDecl extDecl = spec.extDecl;
if(extDecl.type == extDeclString)
{
- String s = spec.extDecl.s;
if(!strcmp(spec.extDecl.s, "__declspec(dllexport)") || !strcmp(spec.extDecl.s, "dllexport"))
specType.dllExport = true;
else if(!strcmp(spec.extDecl.s, "__declspec(stdcall)") || !strcmp(spec.extDecl.s, "stdcall"))
Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
if(symbol && symbol.type)
{
+ // Keep constant qualifier
+ bool isConstant = specType.constant;
// Free Type Contents:
Type dummy { };
*dummy = *specType;
FreeType(dummy);
CopyTypeInto(specType, symbol.type);
+ specType.constant = isConstant;
+ delete specType.typeName;
specType.typeName = CopyString(symbol.type.name);
}
else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
if(spec.list)
{
Enumerator e;
- int nextValue = 0;
for(e = spec.list->first; e; e = e.next)
{
- NamedLink i { name = CopyString(e.id.string) };
+ NamedLink64 i { name = CopyString(e.id.string) };
if(e.exp && e.exp.type == constantExp && e.exp.constant)
- i.data = (void *)strtol(e.exp.constant, null, 0);
+ i.data = strtoll(e.exp.constant, null, 0);
specType.members.Add(i);
}
}
if(symbol.type.kind == enumType)
{
- NamedLink member;
+ NamedLink64 member;
specType.members.Clear();
for(member = symbol.type.members.first; member; member = member.next)
{
- NamedLink item { name = CopyString(member.name), data = member.data };
+ NamedLink64 item { name = CopyString(member.name), data = member.data };
specType.members.Add(item);
}
}
}
else if(spec.type == subClassSpecifier)
{
- specType.kind = specType.kind = subClassType;
+ specType.kind = subClassType;
specType._class = spec._class.symbol;
}
}
return ProcessTypeDecls(specs, decl, null);
}
-public Type ProcessTypeString(char * string, bool staticMethod)
+public Type ProcessTypeString(const char * string, bool staticMethod)
{
OldList * specs = MkList();
Declarator decl = SpecDeclFromString(string, specs, null);
return null;
}
-public Type MkClassType(char * name)
+public Type MkClassType(const char * name)
{
if(name)
{
return { type = arrayExp, list = expressions };
}
-Expression GetTemplateArgExpByName(char * paramName, Class curClass, TemplateParameterType tplType)
+Expression GetTemplateArgExpByName(const char * paramName, Class curClass, TemplateParameterType tplType)
{
Expression argExp = null;
Class _class = curClass ? curClass : ((curExternal && curExternal.type == functionExternal && curExternal.function) ? curExternal.function._class : null);
{
char idString[32];
char className[1024];
- Expression classExp;
sprintf(idString, "%d", id);
strcpy(className, "__ecereClass_");
FullClassNameCat(className, _class.fullName, true);
- MangleClassName(className);
- DeclareClass(FindClass(_class.fullName), className);
+ DeclareClass(curExternal, FindClass(_class.fullName), className);
argExp = MkExpIndex((/*pointer ? MkExpPointer : */MkExpMember)
(MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
return param.identifier ? GetTemplateArgExpByName(param.identifier.string, curClass, type) : null;
}
-/*char * CreateMsgID(char * string, char * context)
+/*char * CreateMsgID(const char * string, const char * context)
{
int lenString = strlen(string), lenContext = strlen(context);
char * msgid = new char[lenString + lenContext + 20];
{
if(intlStrings.count)
{
- char * srcFile = GetSourceFile();
- char * objFile = GetOutputFile();
+ const char * srcFile = GetSourceFile();
+ const char * objFile = GetOutputFile();
char srcFileFixed[MAX_LOCATION];
char potFile[MAX_LOCATION];
File f;
f = FileOpen(potFile, write);
if(f)
{
- char * filePrefix = "";
+ const char * filePrefix = "";
if(!(srcFile[0] && (srcFile[1] == ':' || srcFile[0] == '/')))
- filePrefix = "./"; //(GetRuntimePlatform() == win32) ? ".\\" : "./";
+ filePrefix = "./"; //(__runtimePlatform == win32) ? ".\\" : "./";
// GetSystemPathBuffer(srcFileFixed, srcFile);
GetSlashPathBuffer(srcFileFixed, srcFile);
+
for(s : intlStrings)
{
// TOFIX: (#654) ContextStringPair * pair = &s;