}
}
-int64 _strtoi64(char * string, char ** endString, int base)
-{
- int64 value = 0;
- int sign = 1;
- int c;
- char ch;
- for(c = 0; (ch = string[c]) && isspace(ch); c++);
- if(ch =='+') c++;
- else if(ch == '-') { sign = -1; c++; };
- if(!base)
- {
- if(ch == 0 && string[c+1] == 'x')
- {
- base = 16;
- c+=2;
- }
- else if(ch == '0')
- {
- base = 8;
- c++;
- }
- else
- base = 10;
- }
- for( ;(ch = string[c]); c++)
- {
- if(ch == '0')
- ch = 0;
- else if(ch >= '1' && ch <= '9')
- ch -= '1';
- else if(ch >= 'a' && ch <= 'z')
- ch -= 'a';
- else if(ch >= 'A' && ch <= 'Z')
- ch -= 'A';
- else
- {
- if(endString)
- *endString = string + c;
- // Invalid character
- break;
- }
- if(ch < base)
- {
- value *= base;
- value += ch;
- }
- else
- {
- if(endString)
- *endString = string + c;
- // Invalid character
- break;
- }
- }
- return sign*value;
-}
-
-uint64 _strtoui64(char * string, char ** endString, int base)
-{
- uint64 value = 0;
- int sign = 1;
- int c;
- char ch;
- for(c = 0; (ch = string[c]) && isspace(ch); c++);
- if(ch =='+') c++;
- else if(ch == '-') { sign = -1; c++; };
- if(!base)
- {
- if(ch == 0 && string[c+1] == 'x')
- {
- base = 16;
- c+=2;
- }
- else if(ch == '0')
- {
- base = 8;
- c++;
- }
- else
- base = 10;
- }
- for( ;(ch = string[c]); c++)
- {
- if(ch == '0')
- ch = 0;
- else if(ch >= '1' && ch <= '9')
- ch -= '1';
- else if(ch >= 'a' && ch <= 'z')
- ch -= 'a';
- else if(ch >= 'A' && ch <= 'Z')
- ch -= 'A';
- else
- {
- if(endString) *endString = string + c;
- // Invalid character
- break;
- }
- if(ch < base)
- {
- value *= base;
- value += ch;
- }
- else
- {
- if(endString)
- *endString = string + c;
- // Invalid character
- break;
- }
- }
- return sign*value;
-}
-
Type ProcessTemplateParameterType(TemplateParameter param)
{
if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
case shortType:
case intType:
case int64Type:
+ case intPtrType:
+ case intSizeType:
if(type1.passAsTemplate && !type2.passAsTemplate)
return true;
return type1.isSigned != type2.isSigned;
Property prop = eClass_FindProperty(_class, id.string, privateModule);
Method method = null;
DataMember member = null;
- ClassProperty classProp;
+ ClassProperty classProp = null;
if(!prop)
{
method = eClass_FindMethod(_class, id.string, privateModule);
Operand op2 = GetOperand(exp); \
if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
else if(op2.kind == intType) *value2 = (t) op2.ui; \
- if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
+ else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
+ else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
+ else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
+ else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
+ else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
else if(op2.kind == shortType) *value2 = (t) op2.us; \
else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
else if(op2.kind == charType) *value2 = (t) op2.uc; \
else if(op2.kind == floatType) *value2 = (t) op2.f; \
else if(op2.kind == doubleType) *value2 = (t) op2.d; \
- else if(op2.kind == pointerType) *value2 = (t) op2.ui; \
+ else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
else \
return false; \
return true; \
}
-GETVALUE(Int, int);
-GETVALUE(UInt, unsigned int);
-GETVALUE(Int64, int64);
-GETVALUE(UInt64, uint64);
-GETVALUE(Short, short);
-GETVALUE(UShort, unsigned short);
-GETVALUE(Char, char);
-GETVALUE(UChar, unsigned char);
-GETVALUE(Float, float);
-GETVALUE(Double, double);
+// To help the deubugger currently not preprocessing...
+#define HELP(x) x
+
+GETVALUE(Int, HELP(int));
+GETVALUE(UInt, HELP(unsigned int));
+GETVALUE(Int64, HELP(int64));
+GETVALUE(UInt64, HELP(uint64));
+GETVALUE(IntPtr, HELP(intptr));
+GETVALUE(UIntPtr, HELP(uintptr));
+GETVALUE(IntSize, HELP(intsize));
+GETVALUE(UIntSize, HELP(uintsize));
+GETVALUE(Short, HELP(short));
+GETVALUE(UShort, HELP(unsigned short));
+GETVALUE(Char, HELP(char));
+GETVALUE(UChar, HELP(unsigned char));
+GETVALUE(Float, HELP(float));
+GETVALUE(Double, HELP(double));
void ComputeExpression(Expression exp);
DataMember member = isMember ? (DataMember) _class : null;
Context context = isMember ? null : SetupTemplatesContext(_class);
if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
- (_class.type == bitClass || _class.structSize == _class.offset) && _class.computeSize))
+ (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
{
int c;
int unionMemberOffset = 0;
int bitFields = 0;
+ /*
+ if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
+ _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
+ */
+
+ if(member)
+ {
+ member.memberOffset = 0;
+ if(targetBits < sizeof(void *) * 8)
+ member.structAlignment = 0;
+ }
+ else if(targetBits < sizeof(void *) * 8)
+ _class.structAlignment = 0;
+
+ // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
+ if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
+ _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
+
if(!member && _class.destructionWatchOffset)
_class.memberOffset += sizeof(OldList);
{
if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
{
- /*if(dataMember.dataType)
- printf("");*/
dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
/*if(!dataMember.dataType)
dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
alignment = dataMember.dataType.alignment;
}
-#ifdef _DEBUG
- if(!size)
- {
- // printf("");
- }
-#endif
if(isMember)
{
// TESTING THIS PADDING CODE
}
else
{
+ int alignment;
+
ComputeClassMembers((Class)dataMember, true);
+ alignment = dataMember.structAlignment;
if(isMember)
{
- // THERE WASN'T A MAX HERE ? member.structAlignment = dataMember.structAlignment;
- member.structAlignment = Max(member.structAlignment, dataMember.structAlignment);
+ if(alignment)
+ {
+ if(member.memberOffset % alignment)
+ member.memberOffset += alignment - (member.memberOffset % alignment);
+
+ member.structAlignment = Max(member.structAlignment, alignment);
+ }
dataMember.offset = member.memberOffset;
if(member.type == unionMember)
unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
}
else
{
- _class.structAlignment = Max(_class.structAlignment, dataMember.structAlignment);
+ if(alignment)
+ {
+ if(_class.memberOffset % alignment)
+ _class.memberOffset += alignment - (_class.memberOffset % alignment);
+ _class.structAlignment = Max(_class.structAlignment, alignment);
+ }
dataMember.offset = _class.memberOffset;
_class.memberOffset += dataMember.memberOffset;
}
if(_class.type != bitClass)
{
- _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset;
+ int extra = 0;
+ if(_class.structAlignment)
+ {
+ if(_class.memberOffset % _class.structAlignment)
+ extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
+ }
+ _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
if(!member)
{
Property prop;
case charType: type.alignment = size = sizeof(char); break;
case intType: type.alignment = size = sizeof(int); break;
case int64Type: type.alignment = size = sizeof(int64); break;
+ case intPtrType: type.alignment = size = targetBits / 8; break;
+ case intSizeType: type.alignment = size = targetBits / 8; break;
case longType: type.alignment = size = sizeof(long); break;
case shortType: type.alignment = size = sizeof(short); break;
case floatType: type.alignment = size = sizeof(float); break;
size = type.alignment = ComputeTypeSize(_class.dataType);
}
else
- size = type.alignment = sizeof(Instance *);
+ size = type.alignment = targetBits / 8; // sizeof(Instance *);
break;
}
- case pointerType: case subClassType: size = type.alignment = sizeof(void *); break;
+ case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
case arrayType:
if(type.arraySizeExp)
{
yylloc = oldLoc;
}
GetInt(type.arraySizeExp, &type.arraySize);
-#ifdef _DEBUG
- if(!type.arraySize)
- {
- printf("");
- }
-#endif
}
else if(type.enumClass)
{
if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
{
- type.arraySize = eClass_GetProperty(type.enumClass.registered, "enumSize");
+ type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
}
else
type.arraySize = 0;
TemplateParameter param = type.templateParameter;
Type baseType = ProcessTemplateParameterType(param);
if(baseType)
+ {
size = ComputeTypeSize(baseType);
+ type.alignment = baseType.alignment;
+ }
else
- size = sizeof(uint64);
+ type.alignment = size = sizeof(uint64);
break;
}
case enumType:
{
- size = sizeof(enum { test });
+ type.alignment = size = sizeof(enum { test });
break;
}
case thisClassType:
{
- size = sizeof(void *);
+ type.alignment = size = targetBits / 8; //sizeof(void *);
break;
}
}
}
-/*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass)
+/*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
{
// This function is in need of a major review when implementing private members etc.
DataMember topMember = isMember ? (DataMember) _class : null;
int alignment, size;
DataMember member;
Context context = isMember ? null : SetupTemplatesContext(_class);
+ if(addedPadding)
+ *addedPadding = false;
if(!isMember && _class.base)
{
{
// DANGER: Testing this noHeadClass here...
if(_class.type == structClass || _class.type == noHeadClass)
- /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass);
+ /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
else
maxSize -= _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
}
OldList * specs = MkList(), * list = MkList();
size = 0;
- AddMembers(list, (Class)member, true, &size, topClass);
+ AddMembers(list, (Class)member, true, &size, topClass, null);
ListAdd(specs,
MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
}
else if(totalSize < maxSize && _class.type != systemClass)
{
- char sizeString[50];
- sprintf(sizeString, "%d", maxSize - totalSize);
- ListAdd(declarations,
- MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
- MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
+ int autoPadding = 0;
+ if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
+ autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
+ if(totalSize + autoPadding < maxSize)
+ {
+ char sizeString[50];
+ sprintf(sizeString, "%d", maxSize - totalSize);
+ ListAdd(declarations,
+ MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
+ MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
+ if(addedPadding)
+ *addedPadding = true;
+ }
}
if(context)
FinishTemplatesContext(context);
External external = null;
Symbol classSym = FindClass(name);
- if(!inCompiler || !classSym) return null;
+ if(!inCompiler || !classSym) return;
// We don't need any declaration for bit classes...
if(classSym.registered &&
(classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
- return null;
+ return;
/*if(classSym.registered.templateClass)
return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
classSym.declaring--;
}
- return null;
+ return;
}
//if(!skipNoHead)
if(!skipNoHead)
{
+ bool addedPadding = false;
classSym.declaredStructSym = true;
declarations = MkList();
- AddMembers(declarations, classSym.registered, false, null, classSym.registered);
+ AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
//ListAdd(specifiers, MkSpecifier(TYPEDEF));
//ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
- if(!declarations->count)
+ if(!declarations->count || (declarations->count == 1 && addedPadding))
{
- FreeList(declarations, null);
+ FreeList(declarations, FreeClassDef);
declarations = null;
}
}
{
if(param.type == type && param.identifier)
{
- TemplatedType type { key = (uint)param.identifier.string, param = param };
+ TemplatedType type { key = (uintptr)param.identifier.string, param = param };
curContext.templateTypes.Add((BTNode)type);
}
}
dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
};
}
- type = TemplatedType { key = (uint)p.name, param = param };
+ type = TemplatedType { key = (uintptr)p.name, param = param };
curContext.templateTypes.Add((BTNode)type);
}
}
{
Specifier spec;
for(spec = specifiers->first; spec; spec = spec.next)
- if(spec.type == extendedSpecifier && !strcmp(spec.name, "dllexport"))
+ if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
{
specifiers->Remove(spec);
FreeSpecifier(spec);
/*source.kind != voidType && source.kind != structType && source.kind != unionType */
- /*&& (source.kind != classType /*|| source._class.registered.type != structClass)*/)
+ /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
return true;
if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
((dest.kind == classType && (!dest._class || !dest._class.registered || dest._class.registered.type == structClass || dest._class.registered.type == normalClass || dest._class.registered.type == noHeadClass || dest._class.registered.type == systemClass))
return true;
else if(dest.kind == shortType && source.kind == charType)
return true;
- else if(dest.kind == intType && (source.kind == shortType || source.kind == charType))
+ else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == intSizeType /* Exception here for size_t */))
return true;
- else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType))
+ else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
+ return true;
+ else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
+ return true;
+ else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
return true;
else if(source.kind == enumType &&
- (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type))
+ (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
return true;
else if(dest.kind == enumType &&
- (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || dest.kind == int64Type))
+ (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
return true;
else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
{
Type source = sourceExp.expType;
Type realDest = dest;
+ Type backupSourceExpType = null;
if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
return true;
if(tempType._class)
MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
- FreeType(sourceExp.expType);
+ // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
+ backupSourceExpType = sourceExp.expType;
sourceExp.expType = dest; dest.refCount++;
-
//sourceExp.expType = MkClassType(_class.fullName);
flag = true;
FreeType(source);
FreeType(dest);
+ if(backupSourceExpType) FreeType(backupSourceExpType);
return true;
}
}
FreeType(source);
if(inCompiler) FreeType(dest);
+ if(backupSourceExpType) FreeType(backupSourceExpType);
return true;
}
{
FreeType(source);
FreeType(dest);
+ if(backupSourceExpType)
+ {
+ // Failed to convert: revert previous exp type
+ if(sourceExp.expType) FreeType(sourceExp.expType);
+ sourceExp.expType = backupSourceExpType;
+ }
return false;
}
}
{
FreeType(source);
FreeType(dest);
+ if(backupSourceExpType)
+ {
+ // Failed to convert: revert previous exp type
+ if(sourceExp.expType) FreeType(sourceExp.expType);
+ sourceExp.expType = backupSourceExpType;
+ }
return false;
}
FreeType(dest);
FreeType(source);
+ if(backupSourceExpType) FreeType(backupSourceExpType);
+
return true;
}
else
}
op.kind = intType;
break;
+ case intPtrType:
+ if(type.isSigned)
+ {
+ op.i64 = (int64)_strtoi64(exp.constant, null, 0);
+ op.ops = intOps;
+ }
+ else
+ {
+ op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
+ op.ops = uintOps;
+ }
+ op.kind = intType;
+ break;
+ case intSizeType:
+ if(type.isSigned)
+ {
+ op.i64 = (int64)_strtoi64(exp.constant, null, 0);
+ op.ops = intOps;
+ }
+ else
+ {
+ op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
+ op.ops = uintOps;
+ }
+ op.kind = intType;
+ break;
case floatType:
op.f = (float)strtod(exp.constant, null);
op.ops = floatOps;
case arrayType:
case pointerType:
case classType:
- op.p = (unsigned char *)strtoul(exp.constant, null, 0);
+ op.ui64 = _strtoui64(exp.constant, null, 0);
op.kind = pointerType;
op.ops = uintOps;
// op.ptrSize =
exp.type = constantExp;
break;
}
+ case intPtrType:
+ {
+ FreeExpContents(exp);
+ // TODO: This should probably use proper type
+ exp.constant = PrintInt64((int64)*(intptr*)ptr);
+ exp.type = constantExp;
+ break;
+ }
+ case intSizeType:
+ {
+ FreeExpContents(exp);
+ // TODO: This should probably use proper type
+ exp.constant = PrintInt64((int64)*(intptr*)ptr);
+ exp.type = constantExp;
+ break;
+ }
default:
Compiler_Error($"Unhandled type populating instance\n");
}
exp.type = constantExp;
break;
}
+ case intPtrType:
+ {
+ exp.constant = PrintInt64((int64)*(intptr*)ptr);
+ exp.type = constantExp;
+ break;
+ }
default:
Compiler_Error($"Unhandled type populating instance\n");
}
GetInt64(value, (int64*)ptr);
break;
}
+ case intPtrType:
+ {
+ GetIntPtr(value, (intptr*)ptr);
+ break;
+ }
+ case intSizeType:
+ {
+ GetIntSize(value, (intsize*)ptr);
+ break;
+ }
case floatType:
{
GetFloat(value, (float*)ptr);
Set(inst.data, _strtoi64(value.constant, null, 0));
break;
}
+ case intPtrType:
+ {
+ void (*Set)(void *, intptr) = (void *)prop.Set;
+ Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
+ break;
+ }
+ case intSizeType:
+ {
+ void (*Set)(void *, intsize) = (void *)prop.Set;
+ Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
+ break;
+ }
}
}
else if(value.type == stringExp)
{
char temp[1024];
ReadString(temp, value.string);
- prop.Set(inst.data, temp);
+ ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
}
}
}
else
bits |= ((uint64)part << bitMember.pos);
break;
+ case intPtrType:
+ if(type.isSigned)
+ {
+ bits |= ((intptr)part << bitMember.pos);
+ }
+ else
+ {
+ bits |= ((uintptr)part << bitMember.pos);
+ }
+ break;
+ case intSizeType:
+ if(type.isSigned)
+ {
+ bits |= ((ssize_t)(intsize)part << bitMember.pos);
+ }
+ else
+ {
+ bits |= ((size_t) (uintsize)part << bitMember.pos);
+ }
+ break;
}
}
}
PopulateInstance(exp.instance);
break;
}
+ case intPtrType:
+ {
+ // TOFIX:
+ intptr intValue;
+ void (*Set)(void *, intptr) = (void *)prop.Set;
+
+ exp.instance = Instantiation { };
+ exp.instance.data = new0 byte[_class.structSize];
+ exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+ exp.instance.loc = exp.loc;
+ exp.type = instanceExp;
+
+ GetIntPtr(value, &intValue);
+
+ Set(exp.instance.data, intValue);
+ PopulateInstance(exp.instance);
+ break;
+ }
+ case intSizeType:
+ {
+ // TOFIX:
+ intsize intValue;
+ void (*Set)(void *, intsize) = (void *)prop.Set;
+
+ exp.instance = Instantiation { };
+ exp.instance.data = new0 byte[_class.structSize];
+ exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+ exp.instance.loc = exp.loc;
+ exp.type = instanceExp;
+
+ GetIntSize(value, &intValue);
+
+ Set(exp.instance.data, intValue);
+ PopulateInstance(exp.instance);
+ break;
+ }
case doubleType:
{
double doubleValue;
exp.type = constantExp;
}
break;
+ case intPtrType:
+ if(type.isSigned)
+ {
+ intptr value;
+ GetIntPtr(e, &value);
+ FreeExpContents(exp);
+ exp.constant = PrintInt64((int64)value);
+ exp.type = constantExp;
+ }
+ else
+ {
+ uintptr value;
+ GetUIntPtr(e, &value);
+ FreeExpContents(exp);
+ exp.constant = PrintUInt64((uint64)value);
+ exp.type = constantExp;
+ }
+ break;
+ case intSizeType:
+ if(type.isSigned)
+ {
+ intsize value;
+ GetIntSize(e, &value);
+ FreeExpContents(exp);
+ exp.constant = PrintInt64((int64)value);
+ exp.type = constantExp;
+ }
+ else
+ {
+ uintsize value;
+ GetUIntSize(e, &value);
+ FreeExpContents(exp);
+ exp.constant = PrintUInt64((uint64)value);
+ exp.type = constantExp;
+ }
+ break;
case floatType:
{
float value;
static void GetTypeSpecs(Type type, OldList * specs)
{
- if(!type.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
+ if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
switch(type.kind)
{
case classType:
case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
+ case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
+ case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
case intType:
default:
ListAdd(specs, MkSpecifier(INT)); break;
case voidType: strcat(string, "void"); break;
case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
+ case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
+ case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
case floatType: strcat(string, "float"); break;
strcat(string, name);
}
}
-#ifdef _DEBUG
- else
- {
- printf("");
- }
-#endif
}
if(printFunction)
case vaListType:
strcat(string, "__builtin_va_list");
break;
-#ifdef _DEBUG
- default:
- printf("");
-#endif
}
if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
{
}
}
+// *****
+// TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
+// *****
void PrintType(Type type, char * string, bool printName, bool fullName)
{
Type funcType;
strcat(string, "(");
_PrintType(type, string, printName, false, fullName);
strcat(string, ")");
- /*
- if(type.name)
- strcat(string, type.name);
- else
- {
- printf("");
- }
- */
+
strcat(string, "(");
for(param = funcType.params.first; param; param = param.next)
{
{
char constant[256];
exp.type = constantExp;
- sprintf(constant, "%d",classProp.Get(_class));
+ sprintf(constant, "%d", (int)classProp.Get(_class));
exp.constant = CopyString(constant);
}
}
{
exp.instance._class = MkSpecifierName(exp.destType._class.string);
}
-#ifdef _DEBUG
- else
- {
- printf("");
- }
-#endif
}
//classSym = FindClass(exp.instance._class.fullName);
if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
{
- if(exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
+ if(exp.op.exp2.expType.kind == intSizeType || exp.op.exp2.expType.kind == intPtrType || exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
{
if(exp.op.op != '=' && type1.type.kind == voidType)
Compiler_Error($"void *: unknown size\n");
}
}
- if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
+ if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == intSizeType || type2.kind == intPtrType || type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
{
if(type1.kind != classType && type1.type.kind == voidType)
Compiler_Error($"void *: unknown size\n");
exp.expType = type1;
if(type1) type1.refCount++;
}
- else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
+ else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == intSizeType || type1.kind == intPtrType || type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
{
if(type2.kind != classType && type2.type.kind == voidType)
Compiler_Error($"void *: unknown size\n");
{
Expression idExp = exp.call.exp;
Identifier id = idExp.identifier;
- if(!strcmp(id.string, "__ENDIAN_PAD"))
+ if(!strcmp(id.string, "__builtin_frame_address"))
+ {
+ exp.expType = ProcessTypeString("void *", true);
+ if(exp.call.arguments && exp.call.arguments->first)
+ ProcessExpressionType(exp.call.arguments->first);
+ break;
+ }
+ else if(!strcmp(id.string, "__ENDIAN_PAD"))
{
exp.expType = ProcessTypeString("int", true);
if(exp.call.arguments && exp.call.arguments->first)
if(!type) emptyParams = true;
// WORKING ON THIS:
- if(functionType.extraParam && e)
+ if(functionType.extraParam && e && functionType.thisClass)
{
e.destType = MkClassType(functionType.thisClass.string);
e = e.next;
}
else
{
- e.destType = type;
- if(type) type.refCount++;
+ if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
+ {
+ e.destType = type.prev;
+ e.destType.refCount++;
+ }
+ else
+ {
+ e.destType = type;
+ if(type) type.refCount++;
+ }
}
// Don't reach the end for the ellipsis
if(type && type.kind != ellipsisType)
}
}
+void DeclareFunctionUtil(String s)
+{
+ GlobalFunction function = eSystem_FindFunction(privateModule, s);
+ if(function)
+ {
+ char name[1024];
+ name[0] = 0;
+ if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
+ strcpy(name, "__ecereFunction_");
+ FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
+ DeclareFunction(function, name);
+ }
+}
+
void ComputeDataTypes()
{
External external;
External temp { };
+ External after = null;
+
currentClass = null;
containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
- temp.symbol = Symbol { id = -1000, idCode = -1000 };
-
- // WHERE SHOULD THIS GO?
- // curExternal = ast->first;
- ast->Insert(null, temp);
+ for(external = ast->first; external; external = external.next)
+ {
+ if(external.type == declarationExternal)
+ {
+ Declaration decl = external.declaration;
+ if(decl)
+ {
+ OldList * decls = decl.declarators;
+ if(decls)
+ {
+ InitDeclarator initDecl = decls->first;
+ if(initDecl)
+ {
+ Declarator declarator = initDecl.declarator;
+ if(declarator && declarator.type == identifierDeclarator)
+ {
+ Identifier id = declarator.identifier;
+ if(id && id.string)
+ {
+ if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
+ {
+ external.symbol.id = -1001, external.symbol.idCode = -1001;
+ after = external;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ temp.symbol = Symbol { id = -1000, idCode = -1000 };
+ ast->Insert(after, temp);
curExternal = temp;
+ DeclareFunctionUtil("eSystem_New");
+ DeclareFunctionUtil("eSystem_New0");
+ DeclareFunctionUtil("eSystem_Renew");
+ DeclareFunctionUtil("eSystem_Renew0");
+ DeclareFunctionUtil("eClass_GetProperty");
+
DeclareStruct("ecere::com::Class", false);
DeclareStruct("ecere::com::Instance", false);
DeclareStruct("ecere::com::Property", false);