#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 declMode = privateAccess;
-public void SetDeclMode(AccessMode accessMode) { declMode = accessMode; }
+AccessMode structDeclMode = privateAccess;
+
+public void SetDeclMode(AccessMode accessMode) { structDeclMode = declMode = accessMode; }
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;
-
+
id._class = null; // Default class...
if(string)
{
- char * namePart;
+ const char * namePart;
bool gotColon = false;
for(c = strlen(string)-1; c >= 0; c--)
if(string[c] == ':')
// TODO: Do these better, keep in string?
if(!strcmp(name, "typed_object"))
{
- id._class = MkSpecifierName("class");
+ id._class = MkSpecifierName("typed_object"); //"class");
id.string = CopyString(namePart);
}
else if(!strcmp(name, "property"))
else
id.string = CopyString(string);
}
- }
+ }
}
else if(gotColon)
{
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 { };
+Map<ContextStringPair, List<Location>> intlStrings { };
-Expression MkExpIntlString(char * string, char * context)
+Expression MkExpIntlString(const char * string, const char * context)
{
- OldList * list = MkList();
if(inCompiler)
{
- ContextStringPair pair { };
- List<Location> list;
- int len = strlen(string);
+ OldList * list = MkList();
+ String s;
+ if(inCompiler)
+ {
+ ContextStringPair pair { };
+ List<Location> list;
+ int len = strlen(string);
- pair.string = new byte[len-2+1]; memcpy(pair.string, string+1, len-2); pair.string[len-2] = '\0';
- if(context) { len = strlen(context); pair.context = new byte[len-2+1]; memcpy(pair.context, context+1, len-2); pair.context[len-2] = '\0'; }
+ pair.string = new byte[len-2+1]; memcpy(pair.string, string+1, len-2); pair.string[len-2] = '\0';
+ if(context) { len = strlen(context); pair.context = new byte[len-2+1]; memcpy(pair.context, context+1, len-2); pair.context[len-2] = '\0'; }
- list = intlStrings[pair];
- if(!list)
- {
- list = { };
- intlStrings[pair] = list;
+ list = intlStrings[pair];
+ if(!list)
+ {
+ list = { };
+ intlStrings[pair] = list;
+ }
+ else
+ {
+ delete pair.string;
+ delete pair.context;
+ }
+ list.Add(yylloc);
}
- else
+ //ListAdd(list, QMkExpId("__thisModule"));
+ s = QMkString(i18nModuleName ? i18nModuleName : "");
+ ListAdd(list, MkExpString(s));
+ delete s;
+ ListAdd(list, MkExpString(string));
+ if(context)
{
- delete pair.string;
- delete pair.context;
+ int lenString = strlen(string), lenContext = strlen(context);
+ char * msgid = new char[lenString-2 + lenContext-2 + 4];
+ msgid[0] = '\"';
+ memcpy(msgid+1, context+1, lenContext-2);
+ msgid[1+lenContext-2] = 4; // EOT
+ memcpy(msgid+1+lenContext-2+1, string+1, lenString-2);
+ memcpy(msgid+1+lenContext-2+1+lenString-2, "\"", 2);
+ ListAdd(list, MkExpString(msgid));
+ delete msgid;
}
- list.Add(yylloc);
- }
- ListAdd(list, QMkExpId("__thisModule"));
- ListAdd(list, MkExpString(string));
- if(context)
- {
- int lenString = strlen(string), lenContext = strlen(context);
- char * msgid = new char[lenString-2 + lenContext-2 + 4];
- msgid[0] = '\"';
- memcpy(msgid+1, context+1, lenContext-2);
- msgid[1+lenContext-2] = 4; // EOT
- memcpy(msgid+1+lenContext-2+1, string+1, lenString-2);
- memcpy(msgid+1+lenContext-2+1+lenString-2, "\"", 2);
- ListAdd(list, MkExpString(msgid));
- delete msgid;
+ else
+ ListAdd(list, QMkExpId("null"));
+ return MkExpCall(QMkExpId("GetTranslatedString"), list);
}
else
- ListAdd(list, QMkExpId("null"));
- return MkExpCall(QMkExpId("GetTranslatedString"), list);
+ {
+ Expression e = MkExpString(string);
+ e.intlString = true;
+ return e;
+ }
}
Expression MkExpOp(Expression exp1, int op, Expression exp2)
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)
{
- return { type = baseSpecifier, specifier = specifier };
+ if(specifier == _BOOL && (declMode != defaultAccess && defaultDeclMode != defaultAccess))
+ return MkSpecifierName("bool");
+ else if(specifier == _BOOL || specifier == BOOL)
+ return { type = baseSpecifier, specifier = specifier };
+ else
+ return { type = baseSpecifier, specifier = specifier };
}
Specifier MkSpecifierTypeOf(Expression expression)
Specifier MkEnum(Identifier id, OldList list)
{
- Specifier spec
+ Specifier spec
{
type = enumSpecifier;
id = id;
{
Specifier spec { type = type, id = id };
if(id && FindType(curContext, id.string))
- declMode = defaultAccess;
+ structDeclMode = defaultAccess;
spec.definitions = definitions;
- if(definitions && id && !declMode)
+ if(definitions && id && structDeclMode == defaultAccess)
{
OldList specs { };
Symbol symbol;
public TypeName MkTypeName(OldList qualifiers, Declarator declarator)
{
+ if(qualifiers != null)
+ {
+ Declarator parentDecl = declarator;
+ Declarator decl = declarator;
+ while(decl && decl.type == arrayDeclarator)
+ decl = decl.declarator;
+ if(decl && decl.type == identifierDeclarator && decl.identifier.string && CheckType(decl.identifier.string) == TYPE_NAME)
+ {
+ Specifier spec;
+ // Check if we're missing a real type specifier here
+ for(spec = qualifiers.first; spec; spec = spec.next)
+ {
+ if(spec.type == baseSpecifier)
+ {
+ if(spec.specifier == CONST || spec.specifier == VOLATILE ||
+ spec.specifier == EXTERN || spec.specifier == STATIC ||
+ spec.specifier == AUTO || spec.specifier == REGISTER)
+ continue;
+ break;
+ }
+ else if(spec.type != extendedSpecifier)
+ break;
+ }
+ if(!spec)
+ {
+ // This is actually a type
+ ListAdd(qualifiers, MkSpecifierName(decl.identifier.string));
+ FreeDeclarator(decl);
+ parentDecl.declarator = null;
+ }
+ }
+ }
+ return { qualifiers = qualifiers, declarator = declarator };
+}
+
+public TypeName MkTypeNameGuessDecl(OldList qualifiers, Declarator declarator)
+{
+ if(qualifiers != null)
+ {
+ bool gotType = false;
+ bool gotFullType = false;
+ Specifier spec, next;
+ for(spec = qualifiers.first; spec; spec = next)
+ {
+ next = spec.next;
+ if(gotType && !declarator && ((spec.type == nameSpecifier && spec.name) || (spec.type == baseSpecifier && gotFullType)))
+ {
+ const String s = null;
+ if(spec.type == nameSpecifier)
+ {
+ char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
+ s = colon ? colon + 2 : spec.name;
+ }
+ else if(spec.type == baseSpecifier)
+ {
+ if(spec.specifier == INT64) s = "int64";
+ }
+ if(s)
+ {
+ declarator = MkDeclaratorIdentifier(MkIdentifier(s));
+ qualifiers.Remove(spec);
+ FreeSpecifier(spec);
+ spec = null;
+ }
+ }
+ if(spec && spec.type != extendedSpecifier)
+ {
+ if(spec.type == baseSpecifier)
+ {
+ if(spec.specifier == CONST || spec.specifier == VOLATILE ||
+ spec.specifier == EXTERN || spec.specifier == STATIC ||
+ spec.specifier == AUTO || spec.specifier == REGISTER)
+ continue;
+ else if(spec.specifier != UNSIGNED && spec.specifier != SIGNED && spec.specifier != LONG)
+ gotFullType = true;
+ gotType = true;
+ }
+ else
+ {
+ gotFullType = true;
+ gotType = true;
+ }
+ }
+ }
+ }
return { qualifiers = qualifiers, declarator = declarator };
}
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))
{
Declaration decl { type = initDeclaration, declarators = initDeclarators, specifiers = specifiers, loc = yylloc };
bool variable = true;
-
+
if(specifiers != null)
{
- Specifier spec;
- for(spec = specifiers.first; spec; spec = spec.next)
+ bool gotType = false;
+ Specifier spec, next;
+ for(spec = specifiers.first; spec; spec = next)
{
+ next = spec.next;
if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
{
if(initDeclarators != null)
{
InitDeclarator d;
-
+
for(d = initDeclarators.first; d; d = d.next)
{
if(GetDeclId(d.declarator).string)
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);
}
else if(spec.next)
{
- for(; spec; spec = spec.next)
+ //for(spec = spec.next; spec; spec = spec.next)
+ spec = specifiers.last;
{
- if(spec.type == nameSpecifier && spec.name)
+ if((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier)
{
- Symbol type
+ const String s = null;
+ if(spec.type == nameSpecifier)
{
- string = CopyString(spec.name);
- type = ProcessType(specifiers, null);
- };
- type.id = type.idCode = curContext.nextID++;
- if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
- excludedSymbols->Add(type);
-
- decl.symbol = type;
+ const char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
+ s = colon ? colon + 2 : spec.name;
+ }
+ else if(spec.type == baseSpecifier)
+ {
+ if(spec.specifier == INT64) s = "int64";
+ }
+ if(s)
+ {
+ Symbol type { string = CopyString(s), type = ProcessType(specifiers, null) };
+ decl.symbol = type;
+ decl.declarators = initDeclarators = MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
+ specifiers.Remove(spec);
+ FreeSpecifier(spec);
+ if(!(curContext.templateTypesOnly ? curContext.parent : curContext).types.Add((BTNode)type))
+ excludedSymbols->Add(type);
+ }
}
}
}
variable = false;
break;
}
- else if(spec.type == baseSpecifier &&
+ else if(spec.type == baseSpecifier &&
(spec.specifier == STRUCT || spec.specifier == UNION))
variable = false;
+ else
+ {
+ if(gotType && initDeclarators == null && !spec.next && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
+ {
+ const String s = null;
+ if(spec.type == nameSpecifier)
+ {
+ char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
+ s = colon ? colon + 2 : spec.name;
+ }
+ else if(spec.type == baseSpecifier)
+ {
+ if(spec.specifier == INT64) s = "int64";
+ }
+ if(s)
+ {
+ decl.declarators = initDeclarators = MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
+ specifiers.Remove(spec);
+ FreeSpecifier(spec);
+ spec = null;
+ }
+ }
+ }
+ if(spec && spec.type != extendedSpecifier)
+ gotType = true;
}
}
if(variable && initDeclarators)
delete id.string;
id.string = CopyString(name);
}
-
+
// Avoid memory leaks on duplicated symbols (BinaryTree::Add Would Fail)
symbol = (Symbol)(curContext.templateTypesOnly ? curContext.parent : curContext).symbols.FindString(id.string);
if(!symbol)
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;
Declaration MkStructDeclaration(OldList specifiers, OldList declarators, Specifier extStorage)
{
- return { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
+ Declaration decl { type = structDeclaration, declarators = declarators, specifiers = specifiers, extStorage = extStorage, loc = yylloc };
+ if(specifiers != null)
+ {
+ bool gotType = false;
+ Specifier spec, next;
+ for(spec = specifiers.first; spec; spec = next)
+ {
+ next = spec.next;
+ if(gotType && declarators == null && ((spec.type == nameSpecifier && spec.name) || spec.type == baseSpecifier))
+ {
+ const String s = null;
+ if(spec.type == nameSpecifier)
+ {
+ const char * colon = RSearchString(spec.name, "::", strlen(spec.name), true, false);
+ s = colon ? colon + 2 : spec.name;
+ }
+ else if(spec.type == baseSpecifier)
+ {
+ if(spec.specifier == INT64) s = "int64";
+ }
+ if(s)
+ {
+ decl.declarators = declarators = MkListOne(MkStructDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
+ specifiers.Remove(spec);
+ FreeSpecifier(spec);
+ spec = null;
+ }
+ }
+ if(spec && spec.type != extendedSpecifier)
+ gotType = true;
+ }
+ }
+ return decl;
}
Statement MkLabeledStmt(Identifier id, Statement statement)
FunctionDefinition MkFunction(OldList specifiers, Declarator declarator, OldList declarationList)
{
+ return _MkFunction(specifiers, declarator, declarationList, true);
+}
+
+FunctionDefinition _MkFunction(OldList specifiers, Declarator declarator, OldList declarationList, bool errorOnOmit)
+{
+ if(errorOnOmit)
+ {
+ Declarator funcDecl = GetFuncDecl(declarator);
+ if(funcDecl && funcDecl.function.parameters)
+ {
+ TypeName tn;
+ for(tn = funcDecl.function.parameters->first; tn; tn = tn.next)
+ {
+ if(tn.qualifiers || tn.declarator)
+ {
+ Identifier declID = tn.declarator ? GetDeclId(tn.declarator) : null;
+ if(!declID)
+ {
+ // Check for (void)
+ Specifier spec = tn.qualifiers ? tn.qualifiers->first : null;
+ if(!tn.declarator && !tn.prev && !tn.next && spec && !spec.next && spec.type == baseSpecifier && spec.specifier == VOID);
+ else
+ Compiler_Error($"parameter name omitted\n");
+ break;
+ }
+ }
+ }
+ }
+ }
return { specifiers = specifiers, declarator = declarator, declarations = declarationList };
}
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))
for(spec = function.specifiers->first; spec; spec = spec.next)
if(spec.type == baseSpecifier && spec.specifier == STATIC)
{
- declMode = staticAccess;
+ structDeclMode = declMode = staticAccess;
break;
}
}
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;
for(spec = declaration.specifiers->first; spec; spec = spec.next)
if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
{
- declMode = defaultAccess;
+ structDeclMode = declMode = defaultAccess;
break;
}
else if(spec.type == baseSpecifier && spec.specifier == STATIC)
{
- declMode = staticAccess;
+ structDeclMode = declMode = staticAccess;
break;
}
}
fileInput = backFileInput;
if(fileInput)
{
- fileInput.Seek(yylloc.start.pos, start);
+ fileInput.Seek(yylloc.start.pos, start);
resetScannerPos(&yylloc.start);
yychar = -2;
}
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)
- spec.name = CopyString(symbol.string);
+ {
+ 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);
symbol = Symbol
{
-
+
};
{
symbolSpecs->Add(CopySpecifier(spec));
}
symbol.type = ProcessType(symbolSpecs, decl);
- symbol.idCode = symbol.id = globalContext.nextID++;
decl.symbol = symbol;
excludedSymbols->Add(symbol);
}
FreeList(specs, FreeSpecifier);
-
+
if(!spec)
{
Compiler_Error($"Expecting class specifier\n");
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)
{
/*
for(classContext = curContext; classContext && !classContext.classDef; classContext = classContext.parent);
if(classContext)
{
-
+
}
*/
if(name[0] == ':' && name[1] == ':')
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;
}
strcpy(name, ((Specifier)baseSpecs.first).name);
tpl = strchr(name, '<');
if(tpl) *tpl = 0;
-
+
baseClass = FindClass(name);
- if(baseClass.ctx)
+ if(baseClass && baseClass.ctx)
{
TemplatedType copy;
for(copy = (TemplatedType)baseClass.ctx.templateTypes.first; copy; copy = (TemplatedType)copy.next)
delete type;
}
}
- else if(baseClass.registered)
+ else if(baseClass && baseClass.registered)
{
Class sClass;
for(sClass = baseClass.registered; sClass; sClass = sClass.base)
{
p.param = param = TemplateParameter
{
- identifier = MkIdentifier(p.name), type = p.type,
+ identifier = MkIdentifier(p.name), type = p.type,
dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
};
}
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;
}
{
char typeString[1024];
typeString[0] = '\0';
- PrintType(type, typeString, false, true);
+ PrintTypeNoConst(type, typeString, false, true);
id = MkIdentifier(typeString);
prop.conversion = true;
}
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);
+ /*if(!strcmp(name, "intptr_t") && !type)
+ {
+ ctx.types.Print(output, depthOrder);
+ puts(output);
+ }*/
if(!type && ctx.parent)
type = FindType(ctx.parent, 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)
bool ModuleAccess(Module searchIn, Module searchFor)
{
SubModule subModule;
-
+
if(searchFor == searchIn)
return true;
break;
if(!module)
{
- module = ModuleImport
- {
+ module = ModuleImport
+ {
name = CopyString(moduleToFind.name), importType = moduleToFind.importType,
importAccess = ModuleAccess(privateModule, moduleToFind) ? publicAccess : privateAccess
};
{
GetFullClassNameSpace(ns->parent, name);
strcat(name, ns->name);
- strcat(name, "::");
+ strcat(name, "::");
}
}
}
*/
-public Symbol FindClass(char * name)
+public Symbol FindClass(const char * name)
{
-#ifdef _DEBUG
+#ifdef _TIMINGS
Time startTime = GetTime();
#endif
Symbol cl = null;
}
*/
if(cl.shortName && !strcmp(cl.shortName, name))
- break;
+ break;
}
#ifdef _TIMINGS
findClassIgnoreNSTotalTime += GetTime() - startTime;
{
string = CopyString(name);
registered = _class;
- id = MAXINT;
- idCode = MAXINT;
+ notYetDeclared = true;
imported = true;
};
_class.symbol = cl;
{
type = *src;
type.name = CopyString(src.name);
- type.enumName = CopyString(src.enumName);
+ 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);
}
else if(src.kind == structType || src.kind == unionType)
{
// Tricky stuff... will be removed from list only when ref count reaches 0
for(member = type.members.first; member; member = member.next)
member.refCount++;
+ type.enumName = CopyString(src.enumName);
}
else if(src.kind == functionType)
{
if(type.arraySizeExp)
type.arraySizeExp = CopyExpression(type.arraySizeExp);
}
-
}
}
-public Type ProcessType(OldList specs, Declarator decl)
+static Type ProcessTypeSpecs(OldList specs, bool assumeEllipsis, bool keepTypeName)
{
- Type type = null;
- bool isTypedef = false;
- if(!specs || specs.first)
+ Type specType { refCount = 1, kind = intType, isSigned = true };
+ if(specs != null)
{
- Declarator funcDecl = GetFuncDecl(decl);
- Type specType { };
- bool dllExport = false;
-
- specType.kind = intType;
- specType.isSigned = true;
- specType.refCount = 1;
-
- type = Type { refCount = 1 };
-
- while(decl && (decl.type == structDeclarator || decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd))
+ bool isTypedef = false;
+ Specifier spec;
+ bool isLong = false;
+ for(spec = specs.first; spec; spec = spec.next)
{
- if(decl.type == structDeclarator && decl.structDecl.exp)
+ if(spec.type == extendedSpecifier)
{
- ProcessExpressionType(decl.structDecl.exp);
- ComputeExpression(decl.structDecl.exp);
- if(decl.structDecl.exp.type == constantExp)
- specType.bitFieldCount = strtoul(decl.structDecl.exp.constant, null, 0);
+ ExtDecl extDecl = spec.extDecl;
+ if(extDecl.type == extDeclString)
+ {
+ 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"))
+ specType.attrStdcall = true;
+ }
+ else if(extDecl.type == extDeclAttrib)
+ {
+ OldList * attribs = extDecl.attr.attribs;
+ if(attribs)
+ {
+ Attribute attr;
+ for(attr = attribs->first; attr; attr = attr.next)
+ {
+ String s = attr.attr;
+ if(s)
+ {
+ if(!strcmp(s, "dllexport"))
+ specType.dllExport = true;
+ else if(!strcmp(s, "stdcall"))
+ specType.attrStdcall = true;
+ }
+ }
+ }
+ specType.keepCast = true;
+ }
}
- if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended && decl.extended.extended.type == extDeclString &&
- decl.extended.extended.s && (!strcmp(decl.extended.extended.s, "__declspec(dllexport)") || !strcmp(decl.extended.extended.s, "dllexport")))
+
+ if(spec.specifier != CONST && (specType.kind == structType || specType.kind == unionType))
{
- dllExport = true;
+ FreeType(specType);
+ specType = { kind = intType, isSigned = true, refCount = 1 };
}
- if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended && decl.extended.extended.type == extDeclAttrib)
+
+ if(isTypedef && keepTypeName)
{
- specType.keepCast = true;
+ specType.kind = dummyType;
+ return specType;
}
- decl = decl.declarator;
- }
-
- // If we'll be using the specType
- if(funcDecl || !decl || decl.type == identifierDeclarator)
- {
- Specifier spec;
- if(specs != null)
+ else if(spec.type == baseSpecifier)
{
- bool isLong = false;
- for(spec = specs.first; spec; spec = spec.next)
+ if(spec.specifier == TYPEDEF)
+ isTypedef = true;
+ else if(spec.specifier == VOID) specType.kind = voidType;
+ else if(spec.specifier == CHAR) specType.kind = charType;
+ else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType && !isLong) specType.kind = intType; }
+ else if(spec.specifier == _BOOL || spec.specifier == BOOL)
+ specType.kind = _BoolType;
+ else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
+ else if(spec.specifier == INT64) specType.kind = int64Type;
+ else if(spec.specifier == VALIST)
+ specType.kind = vaListType;
+ else if(spec.specifier == SHORT) specType.kind = shortType;
+ else if(spec.specifier == LONG)
+ {
+ if(isLong || (targetBits == 64 && targetPlatform != win32))
+ specType.kind = int64Type;
+ else
+ specType.kind = intType;
+ isLong = true;
+ }
+ else if(spec.specifier == FLOAT) specType.kind = floatType;
+ else if(spec.specifier == DOUBLE) specType.kind = doubleType;
+ else if(spec.specifier == SIGNED) specType.isSigned = true;
+ else if(spec.specifier == UNSIGNED) specType.isSigned = false;
+ else if(spec.specifier == CONST)
+ specType.constant = true;
+ else if(spec.specifier == TYPED_OBJECT || spec.specifier == ANY_OBJECT || spec.specifier == CLASS)
{
- if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && spec.extDecl.s && (!strcmp(spec.extDecl.s, "__declspec(dllexport)") || !strcmp(spec.extDecl.s, "dllexport")))
+ switch(spec.specifier)
{
- dllExport = true;
+ case TYPED_OBJECT: specType.classObjectType = typedObject; break;
+ case ANY_OBJECT: specType.classObjectType = anyObject; break;
+ case CLASS: specType.classObjectType = classPointer; break;
}
- if(spec.type == extendedSpecifier && spec.extDecl.type == extDeclAttrib)
+ specType.kind = classType;
+ specType._class = FindClass("class");
+ }
+ else if(spec.specifier == THISCLASS)
+ specType.kind = thisClassType;
+ }
+ else if(spec.type == nameSpecifier)
+ {
+ if(spec.name && (!strcmp(spec.name, "intptr") || !strcmp(spec.name, "uintptr")))
+ {
+ specType.kind = intPtrType;
+ if(!strcmp(spec.name, "uintptr"))
+ specType.isSigned = false;
+ }
+ else if(spec.name && (!strcmp(spec.name, "uintsize") || !strcmp(spec.name, "intsize")))
+ {
+ specType.kind = intSizeType;
+ if(!strcmp(spec.name, "uintsize"))
+ specType.isSigned = false;
+ }
+ else
+ {
+ Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
+ if(symbol && symbol.type)
{
- specType.keepCast = true;
+ // Keep constant qualifier
+ bool isConstant = specType.constant;
+ // Free Type Contents:
+ Type dummy { };
+ *dummy = *specType;
+ FreeType(dummy);
+
+ CopyTypeInto(specType, symbol.type);
+ specType.constant = isConstant;
+ specType.typeName = CopyString(symbol.type.name);
}
-
- if(spec.specifier != CONST && (specType.kind == structType || specType.kind == unionType))
+ else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
{
- FreeType(specType);
- specType = { kind = intType, isSigned = true, refCount = 1 };
+ // key.sym enum values need FindClass:
+ specType._class = spec.name ? FindClass(spec.name) : null;
+ specType.kind = classType;
+ if(!specType._class)
+ specType.kind = intType;
}
+ }
+ }
+ else if(spec.type == enumSpecifier)
+ {
+ specType.kind = enumType;
+ specType.enumName = spec.id ? CopyString(spec.id.string) : null;
- if(spec.type == baseSpecifier)
+ if(spec.list)
+ {
+ Enumerator e;
+ for(e = spec.list->first; e; e = e.next)
{
- if(spec.specifier == TYPEDEF) isTypedef = true;
- else if(spec.specifier == VOID) specType.kind = voidType;
- else if(spec.specifier == CHAR) specType.kind = charType;
- else if(spec.specifier == INT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; }
- else if(spec.specifier == UINT) { if(specType.kind != shortType && specType.kind != longType) specType.kind = intType; specType.isSigned = false; }
- else if(spec.specifier == INT64) specType.kind = int64Type;
- else if(spec.specifier == VALIST)
- specType.kind = vaListType;
- else if(spec.specifier == SHORT) specType.kind = shortType;
- else if(spec.specifier == LONG)
- {
- if(isLong)
- specType.kind = int64Type;
- else
- specType.kind = intType;
- isLong = true;
- // specType.kind = longType;
- }
- else if(spec.specifier == FLOAT) specType.kind = floatType;
- else if(spec.specifier == DOUBLE) specType.kind = doubleType;
- else if(spec.specifier == SIGNED) specType.isSigned = true;
- else if(spec.specifier == UNSIGNED) specType.isSigned = false;
- else if(spec.specifier == CONST) specType.constant = true;
- else if(spec.specifier == TYPED_OBJECT)
- {
- specType.classObjectType = typedObject; specType.kind = classType; specType._class = FindClass("class");
- }
- else if(spec.specifier == ANY_OBJECT)
- {
- specType.classObjectType = anyObject; specType.kind = classType; specType._class = FindClass("class");
- }
- else if(spec.specifier == CLASS)
- {
- specType.classObjectType = classPointer; specType.kind = classType; specType._class = FindClass("class");
- }
- else if(spec.specifier == THISCLASS)
- specType.kind = thisClassType;
+ NamedLink64 i { name = CopyString(e.id.string) };
+ if(e.exp && e.exp.type == constantExp && e.exp.constant)
+ i.data = strtoll(e.exp.constant, null, 0);
+ specType.members.Add(i);
}
- else if(spec.type == nameSpecifier)
+ }
+ }
+ else if(spec.type == templateTypeSpecifier)
+ {
+ specType.kind = templateType;
+ specType.templateParameter = spec.templateParameter;
+ }
+ else if(spec.type == structSpecifier || spec.type == unionSpecifier)
+ {
+ Symbol _class = spec.id ? FindClass(spec.id.string) : null;
+ if(_class)
+ {
+ specType.declaredWithStruct = true;
+ if(!_class.registered || _class.registered.type != structClass)
+ specType.directClassAccess = true; // TODO: Need to clarify what 'directClassAccess' is about
+ specType._class = _class;
+ specType.kind = classType;
+ break;
+ }
+ specType.members.Clear();
+ if(spec.type == structSpecifier)
+ specType.kind = structType;
+ else if(spec.type == unionSpecifier)
+ specType.kind = unionType;
+ if(spec.id)
+ {
+ // TESTING THIS HERE... Had 0 type size
+ if(!spec.definitions && !isTypedef)
{
- if(spec.name && (!strcmp(spec.name, "intptr") || !strcmp(spec.name, "uintptr")))
+ Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
+ if(symbol && symbol.type)
{
- specType.kind = intPtrType;
- if(!strcmp(spec.name, "uintptr"))
- specType.isSigned = false;
- }
- else if(spec.name && (!strcmp(spec.name, "uintsize") || !strcmp(spec.name, "intsize")))
- {
- specType.kind = intSizeType;
- if(!strcmp(spec.name, "uintsize"))
- specType.isSigned = false;
- }
- else
- {
- Symbol symbol = spec.name ? FindType(curContext, spec.name) : null;
- if(symbol && symbol.type)
+ specType = *symbol.type;
+ specType.name = CopyString(symbol.type.name);
+ specType.typeName = CopyString(spec.name);
+ specType.enumName = CopyString(symbol.type.enumName);
+ specType.refCount = 1;
+
+ if(symbol.type.kind == enumType)
{
- // Free Type Contents:
- Type dummy { };
- *dummy = *specType;
- FreeType(dummy);
+ NamedLink64 member;
- CopyTypeInto(specType, symbol.type);
- specType.typeName = CopyString(symbol.type.name);
+ specType.members.Clear();
+ for(member = symbol.type.members.first; member; member = member.next)
+ {
+ NamedLink64 item { name = CopyString(member.name), data = member.data };
+ specType.members.Add(item);
+ }
}
- else if(!isTypedef) // !specType.kind) // TESTING THIS FOR enum / typedef problem
+ else if(symbol.type.kind == structType || symbol.type.kind == unionType)
{
- // key.sym enum values need FindClass:
- specType._class = spec.name ? FindClass(spec.name) : null;
- // specType._class = spec.symbol;
- specType.kind = classType;
- if(!specType._class)
- specType.kind = intType;
+ Type member;
+ // Tricky stuff... will be removed from list only when ref count reaches 0
+ for(member = specType.members.first; member; member = member.next)
+ member.refCount++;
}
- }
- }
- else if(spec.type == enumSpecifier)
- {
-
- specType.kind = enumType;
- specType.enumName = spec.id ? CopyString(spec.id.string) : null;
-
- if(spec.list)
- {
- Enumerator e;
- int nextValue = 0;
- for(e = spec.list->first; e; e = e.next)
+ else if(symbol.type.kind == functionType)
{
- // TOFIX: NamedItem i { } causes cryptic error, bad .c!
- NamedLink i { name = CopyString(e.id.string) };
- specType.members.Add(i);
- /*
- if(e.exp && ComputeExpression(e.exp), e.exp.isConstant && e.exp.expType.kind == intType)
- value.data = (void *) nextValue = strtol(e.exp.string, null, 0);
- else
- value.data = (void *)nextValue++;
- */
+ Type param;
+ specType.returnType.refCount++;
+ for(param = specType.params.first; param; param = param.next)
+ param.refCount++;
}
- }
- /*
- if(spec.list)
- {
- Declaration decl;
- for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
- if(decl.declarators)
- {
- Declarator d;
- for(d = decl.declarators.first; d; d = d.next)
- {
- Type memberType = ProcessType(decl.specifiers, d);
- specType.members.Add(memberType);
- }
- }
- else if(decl.specifiers)
+ else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
+ {
+ specType.type.refCount++;
+ if(symbol.type.kind == arrayType)
{
- Type memberType = ProcessType(decl.specifiers, null);
- specType.members.Add(memberType);
+ if(specType.arraySizeExp)
+ specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
}
+
+ }
}
- */
- }
- else if(spec.type == templateTypeSpecifier)
- {
- /*
- printf("spec %x\n", spec);
- printf("template param %x\n", spec.templateParameter);
- printf("identifier %x\n", spec.templateParameter.identifier);
- printf("string %x\n", spec.templateParameter.identifier.string);
- */
- specType.kind = templateType;
- specType.templateParameter = spec.templateParameter;
+ else
+ specType.enumName = CopyString(spec.id.string);
}
- else if(spec.type == structSpecifier || spec.type == unionSpecifier)
+ else
+ specType.enumName = CopyString(spec.id.string);
+ }
+
+ if(spec.definitions)
+ {
+ ClassDef def;
+ for(def = spec.definitions->first; def; def = def.next)
{
- Symbol _class = spec.id ? FindClass(spec.id.string) : null;
- if(_class)
+ if(def.type == declarationClassDef && def.decl.type == structDeclaration)
{
- if(!_class.registered || _class.registered.type != structClass)
- specType.directClassAccess = true;
- specType._class = _class;
- specType.kind = classType;
- break;
- }
- if(spec.type == structSpecifier)
- specType.kind = structType;
- else if(spec.type == unionSpecifier)
- specType.kind = unionType;
- if(spec.id)
- {
- // TESTING THIS HERE... Had 0 type size
- if(!spec.definitions && !isTypedef)
+ Declaration decl = def.decl;
+ if(decl.declarators)
{
- Symbol symbol = spec.id.string ? FindSymbol(spec.id.string, curContext, globalContext, true, false) : null;
- if(symbol && symbol.type)
+ Declarator d;
+ for(d = decl.declarators->first; d; d = d.next)
{
- specType = *symbol.type;
- specType.name = CopyString(symbol.type.name);
- specType.typeName = CopyString(spec.name);
- specType.enumName = CopyString(symbol.type.enumName);
- specType.refCount = 1;
-
- if(symbol.type.kind == enumType)
- {
- NamedLink member;
-
- specType.members.Clear();
- for(member = symbol.type.members.first; member; member = member.next)
- {
- NamedLink item { name = CopyString(member.name), data = member.data };
- specType.members.Add(item);
- }
- }
- else if(symbol.type.kind == structType || symbol.type.kind == unionType)
- {
- Type member;
- // Tricky stuff... will be removed from list only when ref count reaches 0
- for(member = specType.members.first; member; member = member.next)
- member.refCount++;
- }
- else if(symbol.type.kind == functionType)
- {
- Type param;
- specType.returnType.refCount++;
- for(param = specType.params.first; param; param = param.next)
- param.refCount++;
- }
- else if(symbol.type.kind == pointerType || symbol.type.kind == arrayType)
- {
- specType.type.refCount++;
- if(symbol.type.kind == arrayType)
- {
- if(specType.arraySizeExp)
- specType.arraySizeExp = CopyExpression(specType.arraySizeExp);
- }
-
- }
+ Type memberType = ProcessType(decl.specifiers, d);
+ specType.members.Add(memberType);
}
- else
- specType.enumName = CopyString(spec.id.string);
}
- else
- specType.enumName = CopyString(spec.id.string);
- }
-
- if(spec.definitions)
- {
- ClassDef def;
- for(def = spec.definitions->first; def; def = def.next)
+ else if(decl.specifiers)
{
- if(def.type == declarationClassDef && def.decl.type == structDeclaration)
- {
- Declaration decl = def.decl;
- if(decl.declarators)
- {
- Declarator d;
- for(d = decl.declarators->first; d; d = d.next)
- {
- Type memberType = ProcessType(decl.specifiers, d);
- specType.members.Add(memberType);
- }
- }
- else if(decl.specifiers)
- {
- Type memberType = ProcessType(decl.specifiers, null);
- specType.members.Add(memberType);
- }
- }
+ Type memberType = ProcessType(decl.specifiers, null);
+ specType.members.Add(memberType);
}
}
- break;
}
- else if(spec.type == subClassSpecifier)
- {
- specType.kind = specType.kind = subClassType;
- specType._class = spec._class.symbol; // FindClass(spec._class.name);
- }
- /*
- else if(spec.type == classSpecifier)
- {
- specType._class = FindClass(spec.name);
- specType.kind = classType;
- }
- */
}
+ break;
+ }
+ else if(spec.type == subClassSpecifier)
+ {
+ specType.kind = subClassType;
+ specType._class = spec._class.symbol;
}
- else if(!decl)
- specType.kind = ellipsisType;
}
+ }
+ else if(assumeEllipsis)
+ specType.kind = ellipsisType;
+ return specType;
+}
- if(funcDecl)
+static Type ProcessTypeDecls(OldList specs, Declarator decl, Type parentType)
+{
+ Type type = parentType;
+ Declarator subDecl = decl ? decl.declarator : null;
+ if(!parentType)
+ type = ProcessTypeSpecs(specs, decl == null, (decl && decl.type == extendedDeclaratorEnd) ? true : false);
+ if(decl)
+ {
+ switch(decl.type)
{
- Declarator d = funcDecl.declarator;
- Type funcType { };
- TypeName param;
-
- funcType.kind = functionType;
- funcType.refCount = 1;
- if(funcDecl.function.parameters)
+ case bracketsDeclarator: break;
+ case extendedDeclarator:
+ case extendedDeclaratorEnd:
{
- for(param = funcDecl.function.parameters->first; param; param = param.next)
+ ExtDecl extDecl = decl.extended.extended;
+ if(extDecl)
{
- /*
- if(param.typedObject)
+ switch(extDecl.type)
{
- Type typedObjectType
+ case extDeclString:
{
- refCount = 1;
- byReference = param.byReference;
- kind = TypeTypedObject;
- };
- funcType.params.Add(typedObjectType);
+ String s = extDecl.s;
+ if(s)
+ {
+ if(!strcmp(s, "__declspec(dllexport)") || !strcmp(s, "dllexport"))
+ type.dllExport = true;
+ else if(!strcmp(s, "__declspec(stdcall)") || !strcmp(s, "stdcall"))
+ type.attrStdcall = true;
+ }
+ break;
+ }
+ case extDeclAttrib:
+ {
+ OldList * attribs = extDecl.attr.attribs;
+ if(attribs)
+ {
+ Attribute attr;
+ for(attr = attribs->first; attr; attr = attr.next)
+ {
+ String s = attr.attr;
+ if(s)
+ {
+ if(!strcmp(s, "dllexport"))
+ type.dllExport = true;
+ else if(!strcmp(s, "stdcall"))
+ type.attrStdcall = true;
+ }
+ }
+ }
+ type.keepCast = true;
+ break;
+ }
}
- else*/
- funcType.params.Add(ProcessType(param.qualifiers, param.declarator));
}
+ break;
}
-
- // Function returning a pointer...
- if(decl.type == pointerDeclarator)
+ case structDeclarator:
{
- Pointer pointer = decl.pointer.pointer;
- Type ptrType { };
- funcType.returnType = ptrType;
- funcType.returnType.refCount = 1;
- while(pointer)
+ Expression exp = decl.structDecl.exp;
+ if(exp)
{
- ptrType.kind = pointerType;
- pointer = pointer.pointer;
- if(pointer)
- {
- ptrType.type = Type { refCount = 1 };
- ptrType = ptrType.type;
- }
+ ProcessExpressionType(exp);
+ ComputeExpression(exp);
+ if(exp.type == constantExp)
+ type.bitFieldCount = (uint)strtoul(exp.constant, null, 0);
}
- ptrType.type = Type { refCount = 1 };
- *ptrType.type = specType;
- }
- else
- {
- funcType.returnType = Type { refCount = 1 };
- *funcType.returnType = specType;
+ break;
}
-
- // TESTING: Added extendedDeclarator here
- while(d && (d.type == bracketsDeclarator || d.type == extendedDeclarator || d.type == extendedDeclaratorEnd))
+ case functionDeclarator:
{
- if((d.type == extendedDeclarator || d.type == extendedDeclaratorEnd) && d.extended.extended && d.extended.extended.type == extDeclString &&
- d.extended.extended.s && (!strcmp(d.extended.extended.s, "__declspec(dllexport)") || !strcmp(d.extended.extended.s, "dllexport")))
+ type = { refCount = 1, kind = functionType, returnType = type, dllExport = type.dllExport, attrStdcall = type.attrStdcall };
+ if(decl.function.parameters)
{
- dllExport = true;
+ TypeName param;
+ for(param = decl.function.parameters->first; param; param = param.next)
+ type.params.Add(ProcessType(param.qualifiers, param.declarator));
}
- d = d.declarator;
+ break;
}
-
- funcType.dllExport = dllExport;
-
- if(d && d.type == pointerDeclarator)
+ case arrayDeclarator:
{
- Type ptrType;
- Identifier id;
-
- if(d.declarator && d.declarator.type == arrayDeclarator)
+ type = { refCount = 1, kind = arrayType, arraySizeExp = CopyExpression(decl.array.exp), freeExp = true, type = type, dllExport = type.dllExport, attrStdcall = type.attrStdcall };
+ if(decl.array.enumClass)
+ type.enumClass = decl.array.enumClass.symbol;
+ break;
+ }
+ case pointerDeclarator:
+ {
+ Pointer pointer = decl.pointer.pointer;
+ while(pointer)
{
- // Arrays of pointers to functions (extremely tricky :()
- Pointer pointer = d.pointer.pointer;
-
- // TO WORK ON: Fixed the order for the array...
- type.kind = arrayType;
- type.arraySizeExp = CopyExpression(d.declarator.array.exp);
- type.freeExp = true;
- if(d.declarator.array.enumClass)
- type.enumClass = d.declarator.array.enumClass.symbol; // FindClass(d.declarator.array.enumClass.name);
- if(d.declarator.declarator && d.declarator.declarator.type == arrayDeclarator)
- {
- Type tmpType = type;
- Type inType;
- type = ProcessType(null, d.declarator.declarator);
- inType = type.type;
- type.type = tmpType;
- tmpType.type = inType;
- }
+ OldList * qualifiers = pointer.qualifiers;
+ if(type.classObjectType)
+ type.byReference = true;
else
- type.type = ProcessType(null, d.declarator.declarator);
-
- for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
-
- while(pointer)
- {
- ptrType.kind = pointerType;
- pointer = pointer.pointer;
- if(pointer)
- {
- ptrType.type = Type { refCount = 1 };
- ptrType = ptrType.type;
- }
- }
- ptrType.type = ProcessType(specs, null);
- }
- else
- {
- // WARNING: Not caring if this declarator contains a declarator between
- // the pointer and the function other than brackets (like in the case of array of pointers to functions)...
- // *********** Could it ever go in here??? Yes: void (* converters_table[10]) (); ***********
- Pointer pointer = d.pointer.pointer;
-
- ptrType = type;
- while(pointer)
- {
- ptrType.kind = pointerType;
- ptrType.type = Type { refCount = 1 };
- pointer = pointer.pointer;
- if(pointer)
- ptrType = ptrType.type;
- }
- }
-
- *ptrType.type = funcType;
- id = GetDeclId(d);
- if(id)
- {
- if(id._class && !id._class.name)
- ptrType.type.staticMethod = true;
- else
+ type = { refCount = 1, kind = pointerType, type = type, dllExport = type.dllExport, attrStdcall = type.attrStdcall };
+ if(qualifiers)
{
- // TODO : Ensure classSym has been resolved here... (Is this gonna cause problems? Supposed to do this later...)
- if(!id.classSym)
+ Specifier spec;
+ for(spec = qualifiers->first; spec; spec = spec.next)
{
- if(id._class && id._class.name)
- {
- id.classSym = id._class.symbol; // FindClass(id._class.name);
- /* TODO: Name Space Fix ups
- if(!id.classSym)
- id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
- */
- }
- }
-
- ptrType.type.thisClass = id.classSym;
- if(ptrType.type.thisClass && strcmp(ptrType.type.thisClass.string, "class"))
- ptrType.type.extraParam = true;
- else if(id._class && id._class.name && !strcmp(id._class.name, "any_object"))
- {
- ptrType.type.extraParam = true;
- ptrType.type.thisClass = FindClass("class");
+ if(spec.type == baseSpecifier && spec.specifier == CONST)
+ type.constant = true;
}
}
-
- type.name = CopyString(id.string);
+ pointer = pointer.pointer;
}
+ break;
}
- else if(!d || d.type == identifierDeclarator)
+ case identifierDeclarator:
{
-
- *type = funcType;
- if(d)
+ Identifier id = decl.identifier;
+ Specifier _class = id._class;
+ delete type.name;
+ type.name = CopyString(id.string);
+ if(_class)
{
- if(d.identifier._class && d.identifier._class.type == templateTypeSpecifier)
+ if(_class.type == templateTypeSpecifier)
{
- type.thisClassTemplate = d.identifier._class.templateParameter;
+ type.thisClassTemplate = _class.templateParameter;
type.extraParam = true;
}
else
{
- if(d.identifier._class && !d.identifier._class.name)
+ String name = _class.name;
+ if(!name)
type.staticMethod = true;
else
{
- if(d.identifier._class && d.identifier._class.name && d.identifier._class.name[strlen(d.identifier._class.name)-1] == '&')
+ if(!id.classSym)
+ id.classSym = _class.symbol; // FindClass(_class.name);
+ /* TODO: Name Space Fix ups
+ id.nameSpace = eSystem_FindNameSpace(privateModule, _class.name);
+ */
+
+ if(name[strlen(name)-1] == '&')
{
type.thisClass = FindClass("class");
type.byReference = true;
}
else
- type.thisClass = d.identifier._class ? d.identifier._class.symbol /*FindClass(d.identifier._class.name)*/ : null;
+ type.thisClass = _class.symbol;
+
if(type.thisClass && strcmp(type.thisClass.string, "class"))
+ type.extraParam = true;
+ else if(!strcmp(name, "any_object"))
{
type.extraParam = true;
+ type.thisClass = FindClass("class");
}
- else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "any_object"))
+ else if(!strcmp(name, "class"))
{
- type.extraParam = true;
type.thisClass = FindClass("class");
+ type.classObjectType = classPointer; // This is used for class properties
}
- else if(d.identifier._class && d.identifier._class.name && !strcmp(d.identifier._class.name, "class"))
+ else if(!strcmp(name, "typed_object") || !strcmp(name, "typed_object&"))
{
- //type.extraParam = true;
type.thisClass = FindClass("class");
- type.classObjectType = classPointer;
+ type.classObjectType = typedObject;
}
}
}
- type.name = CopyString(d.identifier.string);
- }
- }
- delete funcType;
- }
- else if(decl && decl.type == pointerDeclarator)
- {
- if(decl.declarator && decl.declarator.type == arrayDeclarator)
- {
- // Arrays of pointers (tricky :))
- Identifier id;
- Pointer pointer = decl.pointer.pointer;
- Type ptrType;
-
- // TO WORK ON: Fixed the order for the array...
- type.kind = arrayType;
- type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
- type.freeExp = true;
- if(decl.declarator.array.enumClass)
- type.enumClass = decl.declarator.array.enumClass.symbol; // FindClass(decl.declarator.array.enumClass.name);
- if(decl.declarator.declarator && decl.declarator.declarator.type == arrayDeclarator)
- {
- Type tmpType = type;
- Type inType;
- type = ProcessType(null, decl.declarator.declarator);
- inType = type.type;
- type.type = tmpType;
- tmpType.type = inType;
- }
- else
- type.type = ProcessType(null, decl.declarator.declarator);
- /*
- type.type = ProcessType(null, decl.declarator.declarator);
- type.kind = arrayType;
- type.arraySizeExp = CopyExpression(decl.declarator.array.exp);
- type.arraySizeExp.freeExp = true;
- if(decl.array.enumClass)
- type.enumClass = FindClass(decl.array.enumClass.name);
- */
-
- for(ptrType = type.type; ptrType && ptrType.kind && ptrType.type; ptrType = ptrType.type);
-
- while(pointer)
- {
- ptrType.kind = pointerType;
- pointer = pointer.pointer;
- if(pointer)
- {
- ptrType.type = Type { refCount = 1 };
- ptrType = ptrType.type;
- }
- }
- ptrType.type = ProcessType(specs, null);
- id = GetDeclId(decl);
- if(id) type.name = CopyString(id.string);
- }
- else
- {
- Identifier id;
- Pointer pointer = decl.pointer.pointer;
- Type ptrType = type;
-
- if(type.classObjectType)
- {
- type.byReference = true;
- }
- else
- {
- while(pointer)
- {
- ptrType.kind = pointerType;
- pointer = pointer.pointer;
- if(pointer)
- {
- ptrType.type = Type { refCount = 1 };
- ptrType = ptrType.type;
- }
- }
- ptrType.type = ProcessType(specs, decl.declarator);
-
- if(type.type.classObjectType)
- {
- Type subType = type.type;
- type.classObjectType = subType.classObjectType;
- type.kind = subType.kind;
- type._class = subType._class;
- type.byReference = true;
-
- FreeType(subType);
- }
- id = GetDeclId(decl);
- if(id) type.name = CopyString(id.string);
}
+ break;
}
+ default:
+ PrintLn("Unhandled Declarator Type: ", decl.type);
}
- else if(decl && decl.type == arrayDeclarator)
- {
- Identifier id;
-
- type.kind = arrayType;
-
- type.arraySizeExp = CopyExpression(decl.array.exp);
- type.freeExp = true;
- if(decl.array.enumClass)
- type.enumClass = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
- id = GetDeclId(decl);
-
- // TO WORK ON: Fixed the order for the array...
- if(decl.declarator && decl.declarator.type == arrayDeclarator)
- {
- Type tmpType = type;
- Type inType;
- type = ProcessType(specs, decl.declarator);
- inType = type.type;
- type.type = tmpType;
- tmpType.type = inType;
- }
- else
- type.type = ProcessType(specs, decl.declarator);
-
- if(id)
- {
- delete type.name;
- type.name = CopyString(id.string);
- }
- }
- else
+ }
+ if(subDecl)
+ {
+ Type curType = type;
+ type = ProcessTypeDecls(null, subDecl, type);
+ if(curType && type.kind != functionType)
{
- if(!decl || decl.type == identifierDeclarator)
- {
- *type = specType;
- delete type.name;
- type.name = decl ? CopyString(decl.identifier.string) : null;
-
- }
+ curType.thisClassTemplate = type.thisClassTemplate;
+ curType.extraParam = type.extraParam;
+ curType.staticMethod = type.staticMethod;
+ curType.thisClass = type.thisClass;
+ curType.byReference = type.byReference;
+ curType.classObjectType = type.classObjectType;
}
- delete specType;
}
return type;
}
-public Type ProcessTypeString(char * string, bool staticMethod)
+public Type ProcessType(OldList specs, Declarator decl)
+{
+ return ProcessTypeDecls(specs, decl, null);
+}
+
+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 null;
}
-AsmField MkAsmField(char * command, Expression expression)
+AsmField MkAsmField(char * command, Expression expression, Identifier symbolic)
{
- return { command = command, expression = expression };
+ return { command = command, expression = expression, symbolic = symbolic };
}
Statement MkAsmStmt(Specifier spec, char * statements, OldList inputFields, OldList outputFields, OldList clobberedFields)
{
- return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
- asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
+ return { type = asmStmt, asmStmt.spec = spec, asmStmt.statements = statements,
+ asmStmt.inputFields = inputFields, asmStmt.outputFields = outputFields,
asmStmt.clobberedFields = clobberedFields };
}
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))*/,
+ (MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class")) /*MkExpIdentifier(MkIdentifier(className))*/,
MkIdentifier("templateArgs")), MkListOne(MkExpConstant(idString)));
}
}
- return argExp;
+ return argExp;
}
Expression GetTemplateArgExp(TemplateParameter param, Class curClass, bool pointer)
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;
default extern OldList * ast;
default extern int yyparse ();
+default extern int yylex ();
public void SetAST(OldList * list) { ast = list; }
public OldList * GetAST() { return ast; }
{
yyparse();
}
+
+public int LexEc()
+{
+ return yylex();
+}
+
+public const char * GetYYText()
+{
+ return yytext;
+}