}
}
-public void OutputTypeName(TypeName type, File f)
+public void OutputTypeName(TypeName type, File f, bool typeName)
{
/*if(type.typedObject)
{
Specifier spec;
for(spec = type.qualifiers->first; spec; spec = spec.next)
{
- OutputSpecifier(spec, f);
+ OutputSpecifier(spec, f, typeName);
if(spec.next) f.Puts(" ");
}
}
Specifier spec;
for(spec = exp._classExp.specifiers->first; spec; spec = spec.next)
{
- OutputSpecifier(spec, f);
+ OutputSpecifier(spec, f, false);
if(spec.next) f.Puts(" ");
}
if(exp._classExp.decl)
case newExp:
f.Puts("new ");
f.Puts(" ");
- OutputTypeName(exp._renew.typeName, f);
+ OutputTypeName(exp._renew.typeName, f, false);
f.Puts("[");
OutputExpression(exp._renew.size, f);
f.Puts("]");
case new0Exp:
f.Puts("new0 ");
f.Puts(" ");
- OutputTypeName(exp._renew.typeName, f);
+ OutputTypeName(exp._renew.typeName, f, false);
f.Puts("[");
OutputExpression(exp._renew.size, f);
f.Puts("]");
f.Puts("renew ");
OutputExpression(exp._renew.exp, f);
f.Puts(" ");
- OutputTypeName(exp._renew.typeName, f);
+ OutputTypeName(exp._renew.typeName, f, false);
f.Puts("[");
OutputExpression(exp._renew.size, f);
f.Puts("]");
f.Puts("renew0 ");
OutputExpression(exp._renew.exp, f);
f.Puts(" ");
- OutputTypeName(exp._renew.typeName, f);
+ OutputTypeName(exp._renew.typeName, f, false);
f.Puts("[");
OutputExpression(exp._renew.size, f);
f.Puts("]");
break;
case typeSizeExp:
f.Puts("sizeof(");
- OutputTypeName(exp.typeName, f);
+ OutputTypeName(exp.typeName, f, false);
f.Puts(")");
break;
case typeAlignExp:
f.Puts("__alignof__(");
- OutputTypeName(exp.typeName, f);
+ OutputTypeName(exp.typeName, f, false);
f.Puts(")");
break;
case extensionInitializerExp:
f.Puts("__extension__ (");
if(exp.initializer.typeName)
- OutputTypeName(exp.initializer.typeName, f);
+ OutputTypeName(exp.initializer.typeName, f, false);
f.Puts(")");
if(exp.initializer.initializer)
OutputInitializer(exp.initializer.initializer, f);
break;
case castExp:
f.Puts("(");
- OutputTypeName(exp.cast.typeName, f);
+ OutputTypeName(exp.cast.typeName, f, false);
f.Puts(")");
if(exp.cast.exp)
OutputExpression(exp.cast.exp, f);
f.Puts("__builtin_va_arg(");
OutputExpression(exp.vaArg.exp, f);
f.Puts(", ");
- OutputTypeName(exp.vaArg.typeName, f);
+ OutputTypeName(exp.vaArg.typeName, f, false);
f.Puts(")");
break;
case arrayExp:
}
}
+static void GetSourceName(char * name, const char * src)
+{
+ name[0] = 0;
+ if(src)
+ {
+ if(!strchr(src, '/') && !strchr(src, '\\'))
+ StripLastDirectory(sourceFile, name);
+ PathCat(name, src);
+ }
+ else if(sourceFile)
+ PathCat(name, sourceFile);
+ ChangeCh(name, '\\', '/');
+}
+
static void OutputStatement(Statement stmt, File f)
{
char name[MAX_FILENAME] = "";
char origName[MAX_FILENAME] = "";
- /*
- if(sourceFile)
- eString_GetLastDirectory(sourceFile, name);
- */
-
if(inCompiler)
{
- if(yylloc.start.included)
- {
- //GetWorkingDir(name, sizeof(name));
- PathCat(name, GetIncludeFileFromID(yylloc.start.included));
- }
- else if(sourceFile)
- {
- //GetWorkingDir(name, sizeof(name));
- PathCat(name, sourceFile);
- }
- ChangeCh(name, '\\', '/');
+ GetSourceName(name, stmt.loc.start.included ? GetIncludeFileFromID(stmt.loc.start.included) : null);
- //GetWorkingDir(origName, sizeof(origName));
PathCat(origName, outputFile);
ChangeCh(origName, '\\', '/');
}
switch(stmt.type)
{
+ case badDeclarationStmt:
+ OutputDeclaration(stmt.decl, f);
+ break;
case labeledStmt:
OutputIdentifier(stmt.labeled.id, f);
f.Puts(":\n");
}
else
{
- PrintType(exp.expType, string, true, true);
+ // Printing 'name' as a hack when we're dealing with typedefs with extended attributes
+ PrintTypeNoConst(exp.expType, string, exp.expType.kind == dummyType ? true : false, true);
decl = SpecDeclFromString(string, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal")));
}
typeName = MkTypeName(specs, decl);
InstDeclPassTypeName(typeName, false);
- OutputTypeName(typeName, f);
+ OutputTypeName(typeName, f, false);
f.Printf(";");
FreeTypeName(typeName);
}
AsmField field;
f.Puts("__asm__ ");
if(stmt.asmStmt.spec)
- OutputSpecifier(stmt.asmStmt.spec, f);
+ OutputSpecifier(stmt.asmStmt.spec, f, false);
f.Puts("(");
f.Puts(stmt.asmStmt.statements);
}
}
f.Puts(");\n");
+ outputLine++;
break;
}
}
f.Puts(" ");
for(spec = ptr.qualifiers->first; spec; spec = spec.next)
{
- OutputSpecifier(spec, f);
+ OutputSpecifier(spec, f, false);
if(spec.next) f.Puts(" ");
}
}
Symbol _class = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
if(_class && _class.registered)
{
- f.Printf("%d", eClass_GetProperty(_class.registered, "enumSize"));
+ f.Printf("%d", (int)eClass_GetProperty(_class.registered, "enumSize"));
}
}
f.Puts("]");
{
for(param = decl.function.parameters->first; param; param = param.next)
{
- OutputTypeName(param, f);
+ OutputTypeName(param, f, false);
if(param.next)
f.Puts(", ");
}
OutputAttrib(extDecl.attr, f);
}
-static void OutputSpecifier(Specifier spec, File f)
+static void OutputSpecifier(Specifier spec, File f, bool typeName)
{
switch(spec.type)
{
f.Puts("int");
break;
case UINT:
- f.Puts("unsigned int");
+ f.Puts(typeName ? "uint" : "unsigned int");
break;
case INT64:
//f.Puts("__int64");
//f.Puts("int64");
- f.Puts("long long");
+ f.Puts(typeName ? "int64" : "long long");
break;
case VALIST:
f.Puts("__builtin_va_list");
case unionSpecifier:
{
f.Puts((spec.type == structSpecifier) ? "struct" : "union");
+ if(spec.extDeclStruct)
+ {
+ f.Puts(" ");
+ OutputExtDecl(spec.extDeclStruct, f);
+ }
if(spec.id)
{
f.Puts(" ");
//OutputDeclaration(decl, f);
OutputClassDef(def, f);
}
- f.Puts("}");
+ f.Puts("} __attribute__ ((gcc_struct))");
}
break;
}
break;
case subClassSpecifier:
f.Puts("subclass(");
- OutputSpecifier(spec._class, f);
+ OutputSpecifier(spec._class, f, false);
f.Puts(")");
break;
case templateTypeSpecifier:
char name[MAX_FILENAME] = "";
char origName[MAX_FILENAME] = "";
- /*
- if(sourceFile)
- eString_GetLastDirectory(sourceFile, name);
- */
-
if(inCompiler)
{
- if(yylloc.start.included)
- {
- //GetWorkingDir(name, sizeof(name));
- PathCat(name, GetIncludeFileFromID(yylloc.start.included));
- }
- else if(sourceFile)
- {
- //GetWorkingDir(name, sizeof(name));
- PathCat(name, sourceFile);
- }
- ChangeCh(name, '\\', '/');
+ GetSourceName(name, initializer.loc.start.included ? GetIncludeFileFromID(initializer.loc.start.included) : null);
- //GetWorkingDir(origName, sizeof(origName));
PathCat(origName, outputFile);
ChangeCh(origName, '\\', '/');
}
if(d.initializer)
{
char name[MAX_FILENAME] = "";
- /*
- if(sourceFile)
- GetLastDirectory(sourceFile, name);
- */
- if(yylloc.start.included)
- {
- //GetWorkingDir(name, sizeof(name));
- PathCat(name, GetIncludeFileFromID(yylloc.start.included));
- }
- else if(sourceFile)
- {
- //GetWorkingDir(name, sizeof(name));
- PathCat(name, sourceFile);
- }
- ChangeCh(name, '\\', '/');
+ GetSourceName(name, decl.loc.start.included ? GetIncludeFileFromID(decl.loc.start.included) : null);
if(inCompiler && outputLineNumbers && decl.loc.start.line)
{
if(decl.specifiers)
{
+ bool inTypeDef = false;
for(spec = decl.specifiers->first; spec; spec = spec.next)
{
- OutputSpecifier(spec, f);
+ if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
+ inTypeDef = true;
+ OutputSpecifier(spec, f, inTypeDef && !spec.next);
if(spec.next) f.Puts(" ");
}
}
{
for(spec = decl.specifiers->first; spec; spec = spec.next)
{
- OutputSpecifier(spec, f);
+ OutputSpecifier(spec, f, false);
if(spec.next) f.Puts(" ");
}
}
if(decl.extStorage)
{
f.Puts(" ");
- OutputSpecifier(decl.extStorage, f);
+ OutputSpecifier(decl.extStorage, f, false);
}
break;
}
Specifier spec;
for(spec = func.specifiers->first; spec; spec = spec.next)
{
- OutputSpecifier(spec, f);
+ OutputSpecifier(spec, f, false);
if(spec.next) f.Puts(" ");
}
f.Puts(" ");
char name[1024] = "";
Identifier id = GetDeclId(func.declarator);
- if(yylloc.start.included)
- {
- //GetWorkingDir(name, sizeof(name));
- PathCat(name, GetIncludeFileFromID(yylloc.start.included));
- }
- else if(sourceFile)
- {
- //GetWorkingDir(name, sizeof(name));
- PathCat(name, sourceFile);
- }
- ChangeCh(name, '\\', '/');
+ GetSourceName(name, func.loc.start.included ? GetIncludeFileFromID(func.loc.start.included) : null);
f.Printf("{\n");
f.Printf(" __ecereNameSpace__ecere__com__MemoryGuard_PushLoc(\"%s:%s\");\n", name, id.string);
static void OutputInstance(Instantiation inst, File f)
{
if(inst._class)
- OutputSpecifier(inst._class, f);
+ OutputSpecifier(inst._class, f, false);
if(inst.exp)
{
f.Puts(" ");
Specifier spec;
for(spec = func.specifiers->first; spec; spec = spec.next)
{
- OutputSpecifier(spec, f);
+ OutputSpecifier(spec, f, false);
if(spec.next) f.Puts(" ");
}
f.Puts(" ");
{
//if(func.class != (void *)-1)
if(func.class)
- OutputSpecifier(func.class, f);
+ OutputSpecifier(func.class, f, false);
f.Puts("::");
}*/
if(func.declarator) OutputDeclarator(func.declarator, f);
static void OutputClass(ClassDefinition _class, File f)
{
f.Puts("class ");
- OutputSpecifier(_class._class, f);
+ OutputSpecifier(_class._class, f, false);
if(_class.baseSpecs)
{
Specifier spec;
f.Puts(" : ");
for(spec = _class.baseSpecs->first; spec; spec = spec.next)
{
- OutputSpecifier(spec, f);
+ OutputSpecifier(spec, f, false);
}
}
if(_class.definitions)
{
External external;
- outputLine = 25;
+ outputLine = 31;
for(external = ast.first; external; external = external.next)
{
typeName.qualifiers = specs;
typeName.declarator = decl;
- OutputTypeName(typeName, f);
+ OutputTypeName(typeName, f, true);
delete typeName;