#define ACCESS_CLASSDATA(_class, baseClass) \
(_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
-#include <stdarg.h>
+// #include <stdarg.h>
-// WARNING: PropertyDefine, ClassDefine and DataMemberDefine must remain compatible
+// WARNING: PropertyDefine, ClassDefine and DataMemberDefine must remain compatible
struct ClassDefine : Definition
{
char * base;
bool isVirtual;
};
-// WARNING: PropertyDefine, ClassDefine and DataMemberDefine must remain compatible
+// WARNING: PropertyDefine, ClassDefine and DataMemberDefine must remain compatible
class PropertyDefine : struct
{
PropertyDefine prev, next;
bool hasSet, hasGet;
};
-// WARNING: PropertyDefine, ClassDefine and DataMemberDefine must remain compatible
+// WARNING: PropertyDefine, ClassDefine and DataMemberDefine must remain compatible
class DataMemberDefine : struct
{
DataMemberDefine prev, next;
if(decl.type == structDeclaration)
{
Declarator d;
-
+
if(decl.declarators)
{
for(d = decl.declarators->first; d; d = d.next)
{
+ Identifier declId = GetDeclId(d);
//if(d.type != DeclaratorFunction)
+ if(declId)
{
- Identifier declId = GetDeclId(d);
-
- dataMemberDefine = DataMemberDefine
+ dataMemberDefine = DataMemberDefine
{
isProperty = MemberType::dataMember;
memberType = normalMember;
if(posExp.isConstant)
bitPos = strtol(posExp.constant, null, 0);
FreeExpression(posExp);
-
+
}
d.structDecl.exp = null;
PrintType(dataType, typeString, false, true);
if(member)
- dataMember = eMember_AddDataMember(member, declId.string,
+ dataMember = eMember_AddDataMember(member, declId.string,
typeString, /*ComputeTypeSize(dataType)*/ 0, 0, def.memberAccess);
else
- dataMember = eClass_AddDataMember(regClass, declId.string,
+ dataMember = eClass_AddDataMember(regClass, declId.string,
typeString, /*ComputeTypeSize(dataType)*/ 0, 0, def.memberAccess);
if(dataMember)
dataMember.dataType = dataType;
memberType = (spec.type == SpecifierType::unionSpecifier) ? unionMember : structMember;
};
parentMemberDefine.dataMembers.Add(dataMemberDefine);
-
+
AddDefinitions(null, dataMemberDefine, null, dataMember, spec.definitions);
if(member)
PrintType(dataType, typeString, false, true);
if(member)
- dataMember = eMember_AddDataMember(member, id.string,
+ dataMember = eMember_AddDataMember(member, id.string,
typeString, /*ComputeTypeSize(dataType)*/ 0, 0, def.memberAccess);
else
- dataMember = eClass_AddDataMember(regClass, id.string,
+ dataMember = eClass_AddDataMember(regClass, id.string,
typeString, /*ComputeTypeSize(dataType)*/ 0, 0, def.memberAccess);
//delete dataTypeString;
if(prop)
{
prop.symbol = Symbol
- {
+ {
string = CopyString(propertyDef.symbol.string);
id = propertyDef.symbol.id;
type = propertyDef.symbol.type;
member = eClass_AddDataMember(regClass, def.id.string, null, 0, 0, def.memberAccess);
- dataMemberDefine = DataMemberDefine
+ dataMemberDefine = DataMemberDefine
{
isProperty = dataMember;
memberType = normalMember;
}
}
}
- else if(baseType.kind == structType || baseType.kind == unionType)
+ else if(baseType.kind == structType || baseType.kind == unionType)
{
classType = noHeadClass;
baseName[0] = '\0';
}
- else
+ else
unitType = true;
FreeType(baseType);
unionDefine = DataMemberDefine
{
isProperty = dataMember;
- memberType = DataMemberType::unionMember;
+ memberType = DataMemberType::unionMember;
};
classDefine.propertiesAndMembers.Add(unionDefine);
switch(param.type)
{
case type:
- defaultArg.dataTypeString =
+ defaultArg.dataTypeString =
StringFromSpecDecl(param.defaultArgument.templateDatatype.specifiers, param.defaultArgument.templateDatatype.decl);
break;
case identifier:
else
strcpy(memberString, param.defaultArgument.identifier._class.name);
}
-
+
if(memberString[0])
{
strcat(memberString, "::");
char * typeString = param.dataType ? StringFromSpecDecl(param.dataType.specifiers, param.dataType.decl) : null;
eClass_AddTemplateParameter(regClass, param.identifier.string, param.type, typeString, defaultArg);
- /*eClass_AddTemplateParameter(regClass, param.identifier.string, param.type,
+ /*eClass_AddTemplateParameter(regClass, param.identifier.string, param.type,
(param.type == type) ? eSystem_FindClass(regClass.module, typeString) : CopyString(typeString), defaultArg);*/
// delete typeString;
}
refCount = 1;
};
e.exp.destType = destType;
-
+
// Set parsingType to avoid producing errors
SetParsingType(true);
ProcessExpressionType(e.exp);
}
else
// Sort of an error
- eEnum_AddValue(regClass, e.id.string);
+ eEnum_AddValue(regClass, e.id.string);
}
else
eEnum_AddValue(regClass, e.id.string);
Specifier specifier;
for(specifier = declaration.specifiers->first; specifier; specifier = specifier.next)
{
- if((specifier.type == enumSpecifier || specifier.type == structSpecifier || specifier.type == unionSpecifier) && specifier.id && specifier.id.string &&
+ if((specifier.type == enumSpecifier || specifier.type == structSpecifier || specifier.type == unionSpecifier) && specifier.id && specifier.id.string &&
(declaration.declMode || specifier.baseSpecs || (specifier.type == enumSpecifier && specifier.definitions)))
{
Symbol symbol = FindClass(specifier.id.string);
typeString[0] = '\0';
PrintType(function.declarator.symbol.type, typeString, true, true);
functionDefine = FunctionDefine
- {
+ {
type = functionDefinition;
name = CopyString(function.declarator.symbol.string);
dataType = CopyString(typeString);
Specifier specifier;
for(specifier = declaration.specifiers->first; specifier; specifier = specifier.next)
{
- if((specifier.type == enumSpecifier) && specifier.id && specifier.id.string &&
+ if((specifier.type == enumSpecifier) && specifier.id && specifier.id.string &&
(declaration.declMode || specifier.baseSpecs || (specifier.type == enumSpecifier && specifier.definitions)))
{
Symbol symbol = FindClass(specifier.id.string);
}
f.Printf(" .\n");
}
-
+
if(!classDefine.isStatic)
{
if(classDefine.methods.first)
}
f.Printf(" .\n");
delete f;
- }
+ }
}
class PrecompApp : Application
int argc = 0;*/
Platform targetPlatform = GetRuntimePlatform();
+ int targetBits = GetHostBits();
/*
for(c = 0; c<this.argc; c++)
{
argc++;
}*/
+#ifdef _DEBUG
+ printf("\nArguments given:\n");
+ for(c=1; c<argc; c++)
+ printf(" %s", argv[c]);
+ printf("\n\n");
+ for(c=1; c<argc; c++)
+ PrintLn("Arg", c, ": ", argv[c]);
+ printf("\n");
+ //getch();
+#endif
+
for(c = 1; c<argc; c++)
{
char * arg = argv[c];
if(arg[0] == '-')
{
- if(!strcmp(arg + 1, "m32"))
+ if(!strcmp(arg + 1, "m32") || !strcmp(arg + 1, "m64"))
{
- int argLen = strlen(arg);
- int newLen = cppOptionsLen + 1 + argLen;
+ int newLen = cppOptionsLen + 1 + strlen(arg);
cppOptions = renew cppOptions char[newLen + 1];
cppOptions[cppOptionsLen] = ' ';
- strcpy(cppOptions + cppOptionsLen + 1, arg);
+ strcpy(cppOptions + cppOptionsLen + 1, arg);
cppOptionsLen = newLen;
+ targetBits = !strcmp(arg + 1, "m32") ? 32 : 64;
}
- else if(arg[1] == 'D')
+ else if(!strcmp(arg + 1, "t32") || !strcmp(arg + 1, "t64"))
{
- int argLen = strlen(arg);
- int newLen = cppOptionsLen + 1 + argLen;
- cppOptions = renew cppOptions char[newLen + 1];
- cppOptions[cppOptionsLen] = ' ';
- strcpy(cppOptions + cppOptionsLen + 1, arg);
- cppOptionsLen = newLen;
+ targetBits = !strcmp(arg + 1, "t32") ? 32 : 64;
}
- else if(arg[1] == 'I')
+ else if(arg[1] == 'D' || arg[1] == 'I')
{
- int argLen = strlen(arg);
- int newLen = cppOptionsLen + argLen + 3;
- cppOptions = renew cppOptions char[newLen + 1];
- cppOptions[cppOptionsLen] = ' ';
- cppOptions[cppOptionsLen+1] = '-';
- cppOptions[cppOptionsLen+2] = 'I';
- cppOptions[cppOptionsLen+3] = '"';
- strcpy(cppOptions + cppOptionsLen + 4, arg+2);
- cppOptions[newLen-1] = '\"';
- cppOptions[newLen] = '\0';
- cppOptionsLen = newLen;
+ char * buf;
+ int size = cppOptionsLen + 1 + strlen(arg) * 2 + 1;
+ cppOptions = renew cppOptions char[size];
+ buf = cppOptions + cppOptionsLen;
+ *buf++ = ' ';
+ PassArg(buf, arg);
+ cppOptionsLen = cppOptionsLen + 1 + strlen(buf);
}
else if(!strcmp(arg+1, "t"))
{
{
if(c + 1 < argc)
{
- int argLen = strlen(arg);
- int arg1Len = strlen(argv[c+1]);
- int newLen = cppOptionsLen + argLen + arg1Len + 4;
- cppOptions = renew cppOptions char[newLen + 1];
- cppOptions[cppOptionsLen] = ' ';
- strcpy(cppOptions + cppOptionsLen + 1, arg);
- cppOptions[cppOptionsLen+argLen+1] = ' ';
- cppOptions[cppOptionsLen+argLen+2] = '"';
- arg = argv[++c];
- strcpy(cppOptions + cppOptionsLen + argLen + 3, arg);
- cppOptions[newLen-1] = '\"';
- cppOptions[newLen] = '\0';
- cppOptionsLen = newLen;
+ char * buf;
+ char * arg1 = argv[++c];
+ int size = cppOptionsLen + 1 + strlen(arg) * 2 + strlen(arg1) * 2 + 1;
+ cppOptions = renew cppOptions char[size];
+ buf = cppOptions + cppOptionsLen;
+ *buf++ = ' ';
+ buf = PassArg(buf, arg);
+ *buf++ = ' ';
+ buf = PassArg(buf, arg1);
+ cppOptionsLen = buf - cppOptions;
}
else
valid = false;
}
+ else if(!strcmp(arg+1, "fno-diagnostics-show-caret"))
+ {
+ char * buf;
+ int size = cppOptionsLen + 1 + strlen(arg) * 2 + 1;
+ cppOptions = renew cppOptions char[size];
+ buf = cppOptions + cppOptionsLen;
+ *buf++ = ' ';
+ PassArg(buf, arg);
+ cppOptionsLen = cppOptionsLen + 1 + strlen(buf);
+ }
else if(!strcmp(arg+1, "symbols"))
{
if(c + 1 < argc)
{
if(c + 1 < argc)
{
- SetDefaultNameSpace(argv[c+1]); //defaultNameSpace = argv[c+1];
+ SetDefaultNameSpace(argv[c+1]);
//defaultNameSpaceLen = strlen(argv[c+1]);
c++;
}
SetOutputFile(defaultSymFile);
}
}
-
+
if(!valid)
- printf("Syntax:\n ecp [-t <target platform>] [-cpp <c preprocessor>] [-o <output>] [-symbols <outputdir>] [-I<includedir>]* [-isystem <sysincludedir>]* [-D<definition>]* -c <input>\n");
+ {
+ printf($"Syntax:\n ecp [-t <target platform>] [-cpp <c preprocessor>] [-o <output>] [-symbols <outputdir>] [-I<includedir>]* [-isystem <sysincludedir>]* [-D<definition>]* -c <input>\n");
+ }
else
{
- char command[1024];
DualPipe cppOutput;
-
+ // TODO: Improve this
+ char command[MAX_F_STRING*3];
+ SetGlobalData(&globalData);
+ SetExcludedSymbols(&_excludedSymbols);
SetGlobalContext(globalContext);
- SetTopContext(globalContext);
SetCurrentContext(globalContext);
- SetExcludedSymbols(&_excludedSymbols);
- SetGlobalData(&globalData);
+ SetTopContext(globalContext);
SetDefines(&::defines);
SetImports(&imports);
- SetPrecompDefines(&precompDefines);
SetInPreCompiler(true);
+ SetPrecompDefines(&precompDefines);
SetTargetPlatform(targetPlatform);
+ SetTargetBits(targetBits);
SetEchoOn(false);
- privateModule = (Module)__ecere_COM_Initialize(true, 1, null);
+ privateModule = (Module)__ecere_COM_Initialize(true | (targetBits == sizeof(uintptr)*8 ? 0 : targetBits == 64 ? 2 : targetBits==32 ? 4 : 0) | 8, 1, null);
SetPrivateModule(privateModule);
globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
-
+ globalContext.types.Add((BTNode)Symbol { string = CopyString("intptr_t"), type = ProcessTypeString("intptr", false) });
+ globalContext.types.Add((BTNode)Symbol { string = CopyString("uintptr_t"), type = ProcessTypeString("uintptr", false) });
+ globalContext.types.Add((BTNode)Symbol { string = CopyString("ssize_t"), type = ProcessTypeString("intsize", false) });
+ globalContext.types.Add((BTNode)Symbol { string = CopyString("size_t"), type = ProcessTypeString("uintsize", false) });
+
{
char * outputFilePath = GetOutputFile();
if(FileExists(outputFilePath))
DeleteFile(outputFilePath);
}
-
- sprintf(command, "%s%s -x c -E \"%s\"", cppCommand, cppOptions ? cppOptions : "", GetSourceFile());
+ snprintf(command, sizeof(command), "%s%s -x c -E \"%s\"", cppCommand, cppOptions ? cppOptions : "", GetSourceFile());
+ command[sizeof(command)-1] = 0;
+#ifdef _DEBUG
+ PrintLn("ECP Executing:");
+ PrintLn(command);
+#endif
if((cppOutput = DualPipeOpen({ output = true }, command)))
{
int exitCode;
SetYydebug(false);
delete fileInput;
SetFileInput(null);
-
+
ast = GetAST();
if(!exitCode)
{
if(!this.exitCode)
OutputSymbols(GetOutputFile());
}
+ else
+ this.exitCode = exitCode;
if(ast)
{
::defines.Free(FreeModuleDefine);
imports.Free(FreeModuleImport);
- precompDefines.Free(FreeDefinition);
+ precompDefines.Free(FreeDefinition);
FreeTypeData(privateModule);
FreeIncludeFiles();
*/
SetSymbolsDir(null); // Free symbols dir
-#ifdef _DEBUG
+#if defined(_DEBUG) && defined(__WIN32__)
// CheckMemory();
+ PrintLn("Done.");
getch();
#endif
}