{
TempFile f { };
int count;
+ bool backOutputLineNumbers = outputLineNumbers;
+ outputLineNumbers = false;
if(exp)
OutputExpression(exp, f);
count += f.Read(string + count, 1, 1023);
string[count] = '\0';
delete f;
- }
-}
-
-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;
- }
+ outputLineNumbers = backOutputLineNumbers;
}
- return sign*value;
}
Type ProcessTemplateParameterType(TemplateParameter param)
{
switch(type1.kind)
{
+ case _BoolType:
case charType:
case shortType:
case intType:
case int64Type:
case intPtrType:
+ case intSizeType:
if(type1.passAsTemplate && !type2.passAsTemplate)
return true;
return type1.isSigned != type2.isSigned;
case classType:
return type1._class != type2._class;
case pointerType:
- return NeedCast(type1.type, type2.type);
+ return (type1.type && type2.type && type1.type.constant != type2.type.constant) || NeedCast(type1.type, type2.type);
default:
return true; //false; ????
}
public char * PrintInt(int64 result)
{
char temp[100];
- if(result > MAXINT64)
- sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
+ if(result > MAXINT)
+ sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
else
- sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
+ sprintf(temp, FORMAT64D /*"%I64d"*/, result);
+ if(result > MAXINT || result < MININT)
+ strcat(temp, "LL");
return CopyString(temp);
}
{
char temp[100];
if(result > MAXDWORD)
- sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
+ sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
else
sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
+ if(result > MAXDWORD)
+ strcat(temp, "LL");
return CopyString(temp);
}
if(result > 32767)
sprintf(temp, "0x%X", (int)result);
else
- sprintf(temp, "%d", result);
+ sprintf(temp, "%d", (int)result);
return CopyString(temp);
}
if(result > 0 && isprint(result))
sprintf(temp, "'%c'", result);
else if(result < 0)
- sprintf(temp, "%d", result);
+ sprintf(temp, "%d", (int)result);
else
//sprintf(temp, "%#X", result);
sprintf(temp, "0x%X", (unsigned char)result);
public char * PrintFloat(float result)
{
char temp[350];
- sprintf(temp, "%.16ff", result);
+ if(result.isInf)
+ {
+ if(result.signBit)
+ strcpy(temp, "-inf");
+ else
+ strcpy(temp, "inf");
+ }
+ else if(result.isNan)
+ {
+ if(result.signBit)
+ strcpy(temp, "-nan");
+ else
+ strcpy(temp, "nan");
+ }
+ else
+ sprintf(temp, "%.16ff", result);
return CopyString(temp);
}
public char * PrintDouble(double result)
{
char temp[350];
- sprintf(temp, "%.16f", result);
+ if(result.isInf)
+ {
+ if(result.signBit)
+ strcpy(temp, "-inf");
+ else
+ strcpy(temp, "inf");
+ }
+ else if(result.isNan)
+ {
+ if(result.signBit)
+ strcpy(temp, "-nan");
+ else
+ strcpy(temp, "nan");
+ }
+ else
+ sprintf(temp, "%.16f", result);
return CopyString(temp);
}
//public Operand GetOperand(Expression exp);
#define GETVALUE(name, t) \
- public bool Get##name(Expression exp, t * value2) \
+ public bool GetOp##name(Operand op2, t * value2) \
{ \
- 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 == intPtrType && op2.type.isSigned) *value2 = (t) op2.iptr; \
- else if(op2.kind == intPtrType) *value2 = (t) op2.uiptr; \
+ 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 == _BoolType || 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; \
+ } \
+ public bool Get##name(Expression exp, t * value2) \
+ { \
+ Operand op2 = GetOperand(exp); \
+ return GetOp##name(op2, value2); \
}
-GETVALUE(Int, int);
-GETVALUE(UInt, unsigned int);
-GETVALUE(Int64, int64);
-GETVALUE(UInt64, uint64);
-GETVALUE(IntPtr, intptr);
-GETVALUE(UIntPtr, uintptr);
-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))
+ if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
+ (_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);
int alignment = 0;
// Prevent infinite recursion
- if(dataMember.dataType.kind != classType ||
+ if(dataMember.dataType.kind != classType ||
((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
_class.type != structClass)))
ComputeTypeSize(dataMember.dataType);
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;
}
{
member.memberOffset = unionMemberOffset;
}
-
+
if(!isMember)
{
/*if(_class.type == structClass)
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;
{
Class _class;
OldLink subModule;
-
+
for(subModule = module.modules.first; subModule; subModule = subModule.next)
ComputeModuleClasses(subModule.data);
for(_class = module.classes.first; _class; _class = _class.next)
type.computing = true;
switch(type.kind)
{
+ case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
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 = sizeof(intptr); 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 - (size % type.alignment);
}
- else if(_class && (_class.type == unitClass ||
- _class.type == enumClass ||
+ else if(_class && (_class.type == unitClass ||
+ _class.type == enumClass ||
_class.type == bitClass))
{
if(!_class.dataType)
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 arrayType:
+ case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
+ case arrayType:
if(type.arraySizeExp)
{
ProcessExpressionType(type.arraySizeExp);
ComputeExpression(type.arraySizeExp);
- if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
+ if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
+ type.arraySizeExp.expType.kind != shortType &&
+ type.arraySizeExp.expType.kind != charType &&
+ type.arraySizeExp.expType.kind != longType &&
+ type.arraySizeExp.expType.kind != int64Type &&
+ type.arraySizeExp.expType.kind != intSizeType &&
+ type.arraySizeExp.expType.kind != intPtrType &&
+ type.arraySizeExp.expType.kind != enumType &&
(type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
{
Location oldLoc = yylloc;
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;
}
size = ComputeTypeSize(type.type) * type.arraySize;
- type.alignment = type.type.alignment;
-
+ if(type.type)
+ type.alignment = type.type.alignment;
+
break;
case structType:
{
for(member = type.members.first; member; member = member.next)
{
uint addSize = ComputeTypeSize(member);
-
+
member.offset = size;
if(member.alignment && size % member.alignment)
member.offset += member.alignment - (size % member.alignment);
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;
uint totalSize = 0;
uint maxSize = 0;
- int alignment, size;
+ int alignment;
+ uint 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;
+ {
+ uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
+ if(maxSize > baseSize)
+ maxSize -= baseSize;
+ else
+ maxSize = 0;
+ }
}
}
OldList * specs = MkList(), * decls = MkList();
Declarator decl;
- decl = SpecDeclFromString(member.dataTypeString, specs,
+ decl = SpecDeclFromString(member.dataTypeString, specs,
MkDeclaratorIdentifier(MkIdentifier(member.name)));
ListAdd(decls, MkStructDeclarator(decl, null));
ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
case structMember:
{
OldList * specs = MkList(), * list = MkList();
-
+
size = 0;
- AddMembers(list, (Class)member, true, &size, topClass);
- ListAdd(specs,
+ 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)));
alignment = member.structAlignment;
}
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);
static int DeclareMembers(Class _class, bool isMember)
{
DataMember topMember = isMember ? (DataMember) _class : null;
- uint totalSize = 0;
DataMember member;
Context context = isMember ? null : SetupTemplatesContext(_class);
-
+
if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
DeclareMembers(_class.base, false);
return topMember ? topMember.memberID : _class.memberID;
}
-void DeclareStruct(char * name, bool skipNoHead)
+void DeclareStruct(const char * name, bool skipNoHead)
{
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 &&
+ 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);
OldList * specifiers, * declarators;
OldList * declarations = null;
char structName[1024];
- external = (classSym.registered && classSym.registered.type == structClass) ?
+ Specifier spec = null;
+ external = (classSym.registered && classSym.registered.type == structClass) ?
classSym.pointerExternal : classSym.structExternal;
// TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
classSym.declaring--;
}
- return null;
+ return;
}
-
+
//if(!skipNoHead)
DeclareMembers(classSym.registered, false);
structName[0] = 0;
FullClassNameCat(structName, name, false);
- /*if(!external)
+ if(external && external.declaration && external.declaration.specifiers)
+ {
+ for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
+ {
+ if(spec.type == structSpecifier || spec.type == unionSpecifier)
+ break;
+ }
+ }
+
+ /*if(!external)
external = MkExternalDeclaration(null);*/
- if(!skipNoHead)
+ if(!skipNoHead && (!spec || !spec.definitions))
{
+ 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(skipNoHead || declarations)
{
- if(external && external.declaration)
+ if(spec)
{
- ((Specifier)external.declaration.specifiers->first).definitions = declarations;
+ if(declarations)
+ spec.definitions = declarations;
if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
{
}
else
{
- if(!external)
+ if(!external)
external = MkExternalDeclaration(null);
specifiers = MkList();
classSym._import.properties.Add(symbol._import);
}
imported = true;
- if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
+ // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
+ if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
+ prop._class.module.importType != staticImport)
dllImport = true;
}
declarators = MkList();
params = MkList();
- ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
+ ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
MkDeclaratorIdentifier(MkIdentifier("this"))));
d = MkDeclaratorIdentifier(MkIdentifier(getName));
d = PlugDeclarator(typeDecl, d);
else
{
- ListAdd(params, MkTypeName(specifiers,
+ ListAdd(params, MkTypeName(specifiers,
PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
specifiers = MkList();
}
d = MkDeclaratorFunction(d, params);
-
+
//if(imported)
if(dllImport)
specifiers->Insert(null, MkSpecifier(EXTERN));
// TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
if(!prop.conversion || prop._class.type == structClass)
{
- ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
+ ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
MkDeclaratorIdentifier(MkIdentifier("this"))));
}
{
OldList * list = MkList();
- ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
+ ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
MkDeclaratorIdentifier(MkIdentifier(propName))), null));
if(!imported)
MangleClassName(propName);
- ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
+ ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
MkDeclaratorIdentifier(MkIdentifier(propName))), null));
}
decl = MkDeclaration(specifiers, list);
{
*curMember = thisMember;
*curClass = thisMember._class;
- memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
+ memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
*subMemberStackPos = _subMemberStackPos;
}
found = true;
ClassTemplateArgument arg = _class.templateArgs[id];
if(arg.dataTypeString)
{
+ bool constant = type.constant;
// FreeType(type);
type = ProcessTypeString(arg.dataTypeString, false);
+ if(type.kind == classType && constant) type.constant = true;
+ else if(type.kind == pointerType)
+ {
+ Type t = type.type;
+ while(t.kind == pointerType) t = t.type;
+ if(constant) t.constant = constant;
+ }
freeType = true;
if(type && _class.templateClass)
type.passAsTemplate = true;
int c;
int paramCount = 0;
int lastParam = -1;
-
+
char templateString[1024];
ClassTemplateParameter param;
sprintf(templateString, "%s<", expClass.templateClass.fullName);
int id = p;
Class sClass;
ClassTemplateArgument arg;
- for(sClass = cClass.base; sClass; sClass = sClass.base)
+ for(sClass = cClass.base; sClass; sClass = sClass.base)
{
if(sClass.templateClass) sClass = sClass.templateClass;
id += sClass.templateParams.count;
Class nextClass;
if(sClass.templateClass) sClass = sClass.templateClass;
- for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
+ for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
{
if(nextClass.templateClass) nextClass = nextClass.templateClass;
p += nextClass.templateParams.count;
}
-
+
for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
{
if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
Expression exp;
char * string = PrintHexUInt64(arg.expression.ui64);
exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
+ delete string;
ProcessExpressionType(exp);
ComputeExpression(exp);
lastParam = p;
}
p++;
- }
+ }
}
}
{
}
}
//else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
- else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
+ else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
{
Compiler_Error($"incompatible instance method %s\n", ident.string);
}
MembersInit members;
Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
Class _class;
-
+
/*if(!inst._class.symbol)
inst._class.symbol = FindClass(inst._class.name);*/
classSym = inst._class.symbol;
strcat(name, nameID.string);
strcat(name, "_");
sprintf(number, "_%08d", instMethodID++);
- strcat(name, number);
+ strcat(name, number);
nameID.string = CopyString(name);
}
{
Symbol symbol = declarator.symbol;
Method method = eClass_FindMethod(_class, unmangled, privateModule);
-
+
if(method && method.type == virtualMethod)
{
symbol.method = method;
if(!symbol.type.thisClass)
{
- if(method.dataType.thisClass && currentClass &&
+ if(method.dataType.thisClass && currentClass &&
eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
{
if(!currentClass.symbol)
if(inCompiler)
{
-
- Type type = declarator.symbol.type;
+ //Type type = declarator.symbol.type;
External oldExternal = curExternal;
// *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
delete declarator.symbol.string;
declarator.symbol.string = CopyString(name);
}
-
+
if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
{
printf("TOCHECK: Will this ever be in a list? Yes.\n");
}
*/
-
+
//curExternal = curExternal.prev;
//afterExternal = afterExternal->next;
{
//Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
- Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
+ Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
-
+
//externalDecl = MkExternalDeclaration(decl);
-
+
//***** ast->Insert(external.prev, externalDecl);
//ast->Insert(curExternal.prev, externalDecl);
externalDecl.declaration = decl;
// ADD DATA TYPE HERE...
p.param = param = TemplateParameter
{
- identifier = MkIdentifier(p.name), type = p.type,
+ identifier = MkIdentifier(p.name), type = p.type,
dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
};
}
}
}
-public void DeclareMethod(Method method, char * name)
+public void DeclareMethod(Method method, const char * name)
{
Symbol symbol = method.symbol;
if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
if(!classSym._import)
{
ModuleImport module;
-
+
if(method._class.module && method._class.module.name)
module = FindModule(method._class.module);
else
}
/*
if(!method.thisClass || strcmp(method.thisClass, "void"))
- symbol.type.params.Insert(null,
+ symbol.type.params.Insert(null,
MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
*/
}
if(!method.dataType.dllExport)
{
imported = true;
- if(method._class.module != privateModule && method._class.module.importType != staticImport)
+ if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
dllImport = true;
}
}
{
Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
TypeName thisParam = MkTypeName(MkListOne(
- MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
+ MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
(_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
else if(!funcDecl.function.parameters)
{
funcDecl.function.parameters = MkList();
- funcDecl.function.parameters->Insert(null,
+ funcDecl.function.parameters->Insert(null,
MkTypeName(MkListOne(MkSpecifier(VOID)),null));
}*/
}
int p = 0;
ClassTemplateParameter param;
int lastParam = -1;
-
+
char className[1024];
strcpy(className, _class.fullName);
for(param = _class.templateParams.first; param; param = param.next)
return CopyString(className);
}
else
- return CopyString(_class.fullName);
+ return CopyString(_class.fullName);
}
Type ReplaceThisClassType(Class _class)
int lastParam = -1;
char className[1024];
strcpy(className, _class.fullName);
-
+
for(param = _class.templateParams.first; param; param = param.next)
{
// if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
if(funcDecl && !funcDecl.function.parameters)
{
funcDecl.function.parameters = MkList();
- funcDecl.function.parameters->Insert(null,
+ funcDecl.function.parameters->Insert(null,
MkTypeName(MkListOne(MkSpecifier(VOID)),null));
}
Type resultType;
};
-public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
+public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
+ bool isConversionExploration, bool warnConst)
{
if(source && dest)
{
+ if(warnConst &&
+ ((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
+ ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
+ {
+ Class sourceClass = source.kind == classType ? source._class.registered : null;
+ Class destClass = dest.kind == classType ? dest._class.registered : null;
+ if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
+ (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
+ {
+ Type sourceType = source, destType = dest;
+ while(sourceType.type && (sourceType.kind == pointerType || sourceType.kind == arrayType)) sourceType = sourceType.type;
+ while(destType.type && (destType.kind == pointerType || destType.kind == arrayType)) destType = destType.type;
+ if(!destType.constant && sourceType.constant)
+ Compiler_Warning($"discarding const qualifier\n");
+ }
+ }
// Property convert;
if(source.kind == templateType && dest.kind != templateType)
if(type) dest = type;
}
- if((dest.classObjectType == typedObject && source.classObjectType != anyObject) || (dest.classObjectType == anyObject && source.classObjectType != typedObject))
+ if(dest.classObjectType == typedObject)
{
- return true;
+ if(source.classObjectType != anyObject)
+ return true;
+ else
+ {
+ // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
+ if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
+ {
+ return true;
+ }
+ }
}
-
- if(source.classObjectType == anyObject && dest.classObjectType != typedObject)
+ else
{
- return true;
+ if(source.classObjectType == anyObject)
+ return true;
+ if(dest.classObjectType == anyObject && source.classObjectType != typedObject)
+ return true;
}
-
+
if((dest.kind == structType && source.kind == structType) ||
(dest.kind == unionType && source.kind == unionType))
{
|| source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
/*source.kind != voidType && source.kind != structType && source.kind != unionType */
-
+
/*&& (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))
|| dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
-
/* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
/*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
// Don't match enum inheriting from other enum if resolving enumeration values
// TESTING: !dest.classObjectType
else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
- (enumBaseType ||
- (!source._class.registered || source._class.registered.type != enumClass) ||
+ (enumBaseType ||
+ (!source._class.registered || source._class.registered.type != enumClass) ||
(!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
return true;
else
{
// Added this so that DefinedColor = Color doesn't go through ColorRGB property
- if(enumBaseType &&
+ if(enumBaseType &&
dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
- source._class && source._class.registered && source._class.registered.type != enumClass)
+ ((source._class && source._class.registered && source._class.registered.type != enumClass) || source.kind == classType)) // Added this here for a base enum to be acceptable for a derived enum (#139)
{
if(eClass_IsDerived(dest._class.registered, source._class.registered))
{
if(!convert.dataType)
convert.dataType = ProcessTypeString(convert.dataTypeString, false);
- if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
+ // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
+ if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
+ MatchTypes(convert.dataType, dest, conversions, null, null,
+ (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
+ convert.dataType.kind == classType, false, true, warnConst))
{
if(!conversions && !convert.Get)
return true;
else if(conversions != null)
{
- if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
- convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
+ if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
+ convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
(dest.kind != classType || dest._class.registered != _class.base))
return true;
else
Conversion conv { convert = convert, isGet = true };
// conversions.Add(conv);
conversions.Insert(after, conv);
+
return true;
}
}
{
if(convert.memberAccess == publicAccess || _class.module == privateModule)
{
+ Type constType = null;
+ bool success = false;
// Conversion after = (conversions != null) ? conversions.last : null;
if(!convert.dataType)
convert.dataType = ProcessTypeString(convert.dataTypeString, false);
+
+ if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
+ {
+ Type ptrType { };
+ constType = { kind = pointerType, refCount = 1, type = ptrType };
+ CopyTypeInto(ptrType, convert.dataType.type);
+ ptrType.refCount++;
+ ptrType.constant = true;
+ }
+
// Just added this equality check to prevent recursion.... Make it safer?
// Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
- if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
+ if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
{
if(!conversions && !convert.Set)
- return true;
+ success = true;
else if(conversions != null)
{
- if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
- convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
+ if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
+ convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
(source.kind != classType || source._class.registered != _class.base))
- return true;
+ success = true;
else
{
// *** Testing this! ***
Conversion conv { convert = convert };
conversions.Add(conv);
//conversions.Insert(after, conv);
- return true;
+ success = true;
}
}
}
+ if(success)
+ return true;
+ if(constType)
+ FreeType(constType);
}
}
}
/*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
{
- if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
+ if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
(source.kind != classType || source._class.registered.type != structClass))
return true;
}*/
if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
!strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
{
- if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
+ if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
{
return true;
}
if(!convert.dataType)
convert.dataType = ProcessTypeString(convert.dataTypeString, false);
- if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
+ if(convert.dataType != source &&
+ (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
+ MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
{
if(!conversions && !convert.Get)
return true;
else if(conversions != null)
{
- if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
- convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
+ if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
+ convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
(dest.kind != classType || dest._class.registered != _class.base))
return true;
else
{
if(!source._class.registered.dataType)
source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
- if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
+ if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
{
- return true;
+ if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false, warnConst))
+ return true;
+ // For bool to be accepted by byte, short, etc.
+ else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
+ return true;
}
}
}
if(source.kind == classType || source.kind == subClassType)
;
- else if(dest.kind == source.kind &&
+ else if(dest.kind == source.kind &&
(dest.kind != structType && dest.kind != unionType &&
dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
return true;
// RECENTLY ADDED THESE
else if(dest.kind == doubleType && source.kind == floatType)
return true;
- else if(dest.kind == shortType && source.kind == charType)
+ else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
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 == _BoolType || 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 == _BoolType || 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))
+ else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
+ return true;
+ else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || 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 == intPtrType))
+ (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || 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 || source.kind == int64Type || source.kind == intPtrType))
+ else if(dest.kind == enumType && !isConversionExploration &&
+ (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || 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) &&
+ 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 paramSource, paramDest;
- if(dest.kind == methodType)
+ if(dest.kind == methodType)
owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
- if(source.kind == methodType)
+ if(source.kind == methodType)
owningClassSource = source.methodClass ? source.methodClass : source.method._class;
if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
- if(dest.kind == methodType)
+ if(dest.kind == methodType)
dest = dest.method.dataType;
- if(source.kind == methodType)
+ if(source.kind == methodType)
source = source.method.dataType;
paramSource = source.params.first;
paramDest = dest.params.first;
if(paramDest && paramDest.kind == voidType) paramDest = null;
-
- if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
+
+ if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
!(source.staticMethod || (!source.thisClass && !owningClassSource)))
{
// Source thisClass must be derived from destination thisClass
if(owningClassDest)
Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
else
- Compiler_Error($"overriding class expected to be derived from method class\n");
+ Compiler_Error($"overriding class expected to be derived from method class\n");
return false;
}
}
//if(owningClass)
Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
//else
- //Compiler_Error($"overriding class expected to be derived from method class\n");
+ //Compiler_Error($"overriding class expected to be derived from method class\n");
return false;
}
}
// Source return type must be derived from destination return type
- if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
+ if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
{
Compiler_Warning($"incompatible return type for function\n");
return false;
}
// Check parameters
-
+
for(; paramDest; paramDest = paramDest.next)
{
if(!paramSource)
}
// paramDest must be derived from paramSource
- if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
- (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
+ if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
+ (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
{
char type[1024];
type[0] = 0;
PrintType(paramDest, type, false, true);
Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
-
+
if(paramDestType != paramDest)
FreeType(paramDestType);
return false;
if(paramDestType != paramDest)
FreeType(paramDestType);
}
-
+
paramSource = paramSource.next;
}
if(paramSource)
{
return true;
}
- else if((dest.kind == pointerType || dest.kind == arrayType) &&
+ else if((dest.kind == pointerType || dest.kind == arrayType) &&
(source.kind == arrayType || source.kind == pointerType))
{
- if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
+ if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
return true;
}
}
FreeType(convert.resultType);
}
-bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
+bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
char * string, OldList conversions)
{
BTNamedLink link;
_class.symbol = FindClass(_class.fullName);
type._class = _class.symbol;
- if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
+ if(MatchTypes(type, dest, &converts, null, null, true, false, false, false, false))
{
NamedLink value;
Class enumClass = eSystem_FindClass(privateModule, "enum");
char constant[256];
sourceExp.type = constantExp;
if(!strcmp(baseClass.dataTypeString, "int"))
- sprintf(constant, "%d",value.data);
+ sprintf(constant, "%d",(int)value.data);
else
- sprintf(constant, "0x%X",value.data);
+ sprintf(constant, "0x%X",(int)value.data);
sourceExp.constant = CopyString(constant);
//for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
}
-
+
while(converts.first)
{
Conversion convert = converts.first;
public bool ModuleVisibility(Module searchIn, Module searchFor)
{
SubModule subModule;
-
+
if(searchFor == searchIn)
return true;
return false;
}
-bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
+bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
{
- Type source = sourceExp.expType;
+ Type source;
Type realDest = dest;
+ Type backupSourceExpType = null;
+ Expression computedExp = sourceExp;
+ dest.refCount++;
+
+ if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
+ dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
+ {
+ computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
+ ComputeExpression(computedExp /*sourceExp*/);
+ }
+
+ source = sourceExp.expType;
if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
+ {
+ if(computedExp != sourceExp)
+ {
+ FreeExpression(computedExp);
+ computedExp = sourceExp;
+ }
+ FreeType(dest);
return true;
+ }
if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
{
if(source._class && source._class.registered && source._class.registered.type == unitClass)
{
Class sourceBase, destBase;
- for(sourceBase = source._class.registered;
+ for(sourceBase = source._class.registered;
sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
sourceBase = sourceBase.base);
- for(destBase = dest._class.registered;
+ for(destBase = dest._class.registered;
destBase && destBase.base && destBase.base.type != systemClass;
destBase = destBase.base);
//if(source._class.registered == dest._class.registered)
if(sourceBase == destBase)
- return true;
- }
+ {
+ if(computedExp != sourceExp)
+ {
+ FreeExpression(computedExp);
+ computedExp = sourceExp;
+ }
+ FreeType(dest);
+ return true;
+ }
+ }
}
if(source)
int64 value = MAXINT;
source.refCount++;
- dest.refCount++;
- if(sourceExp.type == constantExp)
+ if(computedExp.type == constantExp)
{
if(source.isSigned)
- value = strtoll(sourceExp.constant, null, 0);
+ value = strtoll(computedExp.constant, null, 0);
else
- value = strtoull(sourceExp.constant, null, 0);
+ value = strtoull(computedExp.constant, null, 0);
}
- else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
+ else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
{
if(source.isSigned)
- value = -strtoll(sourceExp.op.exp2.constant, null, 0);
+ value = -strtoll(computedExp.op.exp2.constant, null, 0);
else
- value = -strtoull(sourceExp.op.exp2.constant, null, 0);
+ value = -strtoull(computedExp.op.exp2.constant, null, 0);
+ }
+ if(computedExp != sourceExp)
+ {
+ FreeExpression(computedExp);
+ computedExp = sourceExp;
}
- if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
+ if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
!strcmp(source._class.registered.fullName, "ecere::com::unichar"))
{
FreeType(source);
tempType._class = _class.symbol;
tempType.truth = dest.truth;
if(tempType._class)
- MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
+ MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
- 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;
+ flag = true;
delete tempType;
}
{
if(!dest._class.registered.dataType)
dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
- if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
+ if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
{
FreeType(source);
FreeType(sourceExp.expType);
source = sourceExp.expType = MkClassType(dest._class.string);
source.refCount++;
-
+
//source.kind = classType;
//source._class = dest._class;
}
FreeType(source);
source = sourceExp.expType = MkClassType(dest._class.string);
source.refCount++;
-
+
//source.kind = classType;
//source._class = dest._class;
}
FreeType(source);
FreeType(dest);
+ if(backupSourceExpType) FreeType(backupSourceExpType);
return true;
}
}
{
Class _class = source._class ? source._class.registered : null;
- if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
+ if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
{
/*
if(dest.kind != classType)
// Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
if(!source._class.registered.dataType)
source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
-
+
FreeType(dest);
dest = MkClassType(source._class.string);
//if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
// dest = MkClassType(source._class.string);
}
*/
-
+
if(dest.kind != classType)
{
Type tempType { };
tempType.classObjectType = source.classObjectType;
if(tempType._class)
- MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
-
+ MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
+
// PUT THIS BACK TESTING UNITS?
if(conversions.last)
{
((Conversion)(conversions.last)).resultType = dest;
dest.refCount++;
}
-
+
FreeType(sourceExp.expType);
sourceExp.expType = MkClassType(_class.fullName);
sourceExp.expType.truth = source.truth;
dest = MkClassType(source._class.string);
dest.truth = source.truth;
dest.classObjectType = source.classObjectType;
-
+
FreeType(source);
source = _class.dataType;
source.refCount++;
if(!flag)
{
- if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
+ if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
{
FreeType(source);
FreeType(dest);
if(dest.kind == classType)
{
Class _class = dest._class ? dest._class.registered : null;
- if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
+ bool fittingValue = false;
+ if(_class && _class.type == enumClass)
+ {
+ Class enumClass = eSystem_FindClass(privateModule, "enum");
+ EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
+ if(c && value >= 0 && value <= c.largest)
+ fittingValue = true;
+ }
+
+ if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
(/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
{
if(_class.type == normalClass || _class.type == noHeadClass)
FreeType(source);
if(inCompiler) FreeType(dest);
+ if(backupSourceExpType) FreeType(backupSourceExpType);
return true;
}
}
// Accept lower precision types for units, since we want to keep the unit type
- if(dest.kind == doubleType &&
+ if(dest.kind == doubleType &&
(source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
- source.kind == charType))
+ source.kind == charType || source.kind == _BoolType))
{
specs = MkListOne(MkSpecifier(DOUBLE));
}
- else if(dest.kind == floatType &&
+ else if(dest.kind == floatType &&
(source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
- source.kind == doubleType))
+ source.kind == _BoolType || source.kind == doubleType))
{
specs = MkListOne(MkSpecifier(FLOAT));
}
else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
- source.kind == floatType || source.kind == doubleType))
+ source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
{
specs = MkList();
if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
ListAdd(specs, MkSpecifier(INT64));
}
else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
- source.kind == floatType || source.kind == doubleType))
+ source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
{
specs = MkList();
if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
ListAdd(specs, MkSpecifier(INT));
}
- else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
+ else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
source.kind == floatType || source.kind == doubleType))
{
specs = MkList();
if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
ListAdd(specs, MkSpecifier(SHORT));
}
- else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
+ else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
source.kind == floatType || source.kind == doubleType))
{
specs = MkList();
{
FreeType(source);
FreeType(dest);
+ if(backupSourceExpType)
+ {
+ // Failed to convert: revert previous exp type
+ if(sourceExp.expType) FreeType(sourceExp.expType);
+ sourceExp.expType = backupSourceExpType;
+ }
return false;
}
}
- else if(dest.kind == doubleType &&
+ else if(dest.kind == doubleType &&
(source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
- source.kind == charType))
+ source.kind == _BoolType || source.kind == charType))
{
specs = MkListOne(MkSpecifier(DOUBLE));
}
- else if(dest.kind == floatType &&
- (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
+ else if(dest.kind == floatType &&
+ (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
{
specs = MkListOne(MkSpecifier(FLOAT));
}
- else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
+ else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
+ (value == 1 || value == 0))
+ {
+ specs = MkList();
+ ListAdd(specs, MkSpecifier(BOOL));
+ }
+ else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
(dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
{
specs = MkList();
if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
ListAdd(specs, MkSpecifier(CHAR));
}
- else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
+ else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
(source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
{
specs = MkList();
if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
ListAdd(specs, MkSpecifier(SHORT));
}
- else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
+ else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
{
specs = MkList();
if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
ListAdd(specs, MkSpecifier(INT));
}
- else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
+ else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
{
specs = MkList();
if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
ListAdd(specs, MkSpecifier(INT64));
}
- else if(dest.kind == enumType &&
- (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
+ else if(dest.kind == enumType &&
+ (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
{
specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
}
{
FreeType(source);
FreeType(dest);
+ if(backupSourceExpType)
+ {
+ // Failed to convert: revert previous exp type
+ if(sourceExp.expType) FreeType(sourceExp.expType);
+ sourceExp.expType = backupSourceExpType;
+ }
return false;
}
- if(!flag)
+ if(!flag && !sourceExp.opDestType)
{
Expression newExp { };
*newExp = *sourceExp;
}
else
sourceExp.cast.exp = newExp;
-
+
FreeType(sourceExp.expType);
sourceExp.expType = null;
ProcessExpressionType(sourceExp);
FreeType(dest);
FreeType(source);
+ if(backupSourceExpType) FreeType(backupSourceExpType);
+
return true;
}
else
{
+ if(computedExp != sourceExp)
+ {
+ FreeExpression(computedExp);
+ computedExp = sourceExp;
+ }
+
while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
if(sourceExp.type == identifierExp)
{
char constant[256];
sourceExp.type = constantExp;
if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
- sprintf(constant, "%d",value.data);
+ sprintf(constant, "%d", (int) value.data);
else
- sprintf(constant, "0x%X",value.data);
+ sprintf(constant, "0x%X", (int) value.data);
sourceExp.constant = CopyString(constant);
//for(;_class.base && _class.base.type != systemClass; _class = _class.base);
}
+ FreeType(dest);
return true;
}
}
// Loop through all enum classes
if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
+ {
+ FreeType(dest);
return true;
+ }
}
+ FreeType(dest);
}
return false;
}
{ \
t value2 = op2.m; \
exp.type = constantExp; \
- exp.string = p(op1.m o value2); \
+ exp.string = p((t)(op1.m o value2)); \
if(!exp.expType) \
{ exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
return true; \
}
-#define BINARY_DIVIDE(o, name, m, t, p) \
+#define BINARY_DIVIDEINT(o, name, m, t, p) \
static bool name(Expression exp, Operand op1, Operand op2) \
{ \
t value2 = op2.m; \
return true; \
}
+#define BINARY_DIVIDEREAL(o, name, m, t, p) \
+ static bool name(Expression exp, Operand op1, Operand op2) \
+ { \
+ t value2 = op2.m; \
+ exp.type = constantExp; \
+ exp.string = p(op1.m o value2); \
+ if(!exp.expType) \
+ { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
+ return true; \
+ }
+
#define UNARY(o, name, m, t, p) \
static bool name(Expression exp, Operand op1) \
{ \
exp.type = constantExp; \
- exp.string = p(o op1.m); \
+ exp.string = p((t)(o op1.m)); \
if(!exp.expType) \
{ exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
return true; \
#define OPERATOR_ALL(macro, o, name) \
macro(o, Int##name, i, int, PrintInt) \
macro(o, UInt##name, ui, unsigned int, PrintUInt) \
+ macro(o, Int64##name, i64, int64, PrintInt64) \
+ macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
macro(o, Short##name, s, short, PrintShort) \
macro(o, UShort##name, us, unsigned short, PrintUShort) \
macro(o, Char##name, c, char, PrintChar) \
#define OPERATOR_INTTYPES(macro, o, name) \
macro(o, Int##name, i, int, PrintInt) \
macro(o, UInt##name, ui, unsigned int, PrintUInt) \
+ macro(o, Int64##name, i64, int64, PrintInt64) \
+ macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
macro(o, Short##name, s, short, PrintShort) \
macro(o, UShort##name, us, unsigned short, PrintUShort) \
macro(o, Char##name, c, char, PrintChar) \
macro(o, UChar##name, uc, unsigned char, PrintUChar)
+#define OPERATOR_REALTYPES(macro, o, name) \
+ macro(o, Float##name, f, float, PrintFloat) \
+ macro(o, Double##name, d, double, PrintDouble)
// binary arithmetic
OPERATOR_ALL(BINARY, +, Add)
OPERATOR_ALL(BINARY, -, Sub)
OPERATOR_ALL(BINARY, *, Mul)
-OPERATOR_ALL(BINARY_DIVIDE, /, Div)
-OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
+OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
+OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
+OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
// unary arithmetic
OPERATOR_ALL(UNARY, -, Neg)
OPERATOR_ALL(BINARY, +=, AddAsign)
OPERATOR_ALL(BINARY, -=, SubAsign)
OPERATOR_ALL(BINARY, *=, MulAsign)
-OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
-OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
+OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
+OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
+OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
// binary bitwise
OPERATOR_INTTYPES(BINARY, &, BitAnd)
OPERATOR_ALL(BINARY, <=, SmaEqu)
// tertiary condition operator
-OPERATOR_ALL(TERTIARY, ?, Cond)
+OPERATOR_INTTYPES(TERTIARY, ?, Cond)
//Add, Sub, Mul, Div, Mod, , Neg, Inc, Dec, Asign, AddAsign, SubAsign, MulAsign, DivAsign, ModAsign, BitAnd, BitOr, BitXor, LShift, RShift, BitNot, AndAsign, OrAsign, XorAsign, LShiftAsign, RShiftAsign, Not, Equ, Nqu, And, Or, Grt, Sma, GrtEqu, SmaEqu
#define OPERATOR_TABLE_ALL(name, type) \
OPERATOR_TABLE_ALL(int, Int)
OPERATOR_TABLE_ALL(uint, UInt)
+OPERATOR_TABLE_ALL(int64, Int64)
+OPERATOR_TABLE_ALL(uint64, UInt64)
OPERATOR_TABLE_ALL(short, Short)
OPERATOR_TABLE_ALL(ushort, UShort)
OPERATOR_TABLE_INTTYPES(float, Float)
case 'v': output[d] = '\v'; break;
case '\\': output[d] = '\\'; break;
case '\"': output[d] = '\"'; break;
- default: output[d++] = '\\'; output[d] = ch;
- //default: output[d] = ch;
+ case '\'': output[d] = '\''; break;
+ default: output[d] = ch;
}
d++;
escaped = false;
}
- else
+ else
{
- if(ch == '\"')
+ if(ch == '\"')
quoted ^= true;
else if(quoted)
{
output[d] = '\0';
}
-public Operand GetOperand(Expression exp)
+// String Unescape Copy
+
+// TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
+// This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
+public int UnescapeString(char * d, char * s, int len)
{
- Operand op { };
- Type type = exp.expType;
- if(type)
+ int j = 0, k = 0;
+ char ch;
+ while(j < len && (ch = s[j]))
{
- while(type.kind == classType &&
- type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
+ switch(ch)
+ {
+ case '\\':
+ switch((ch = s[++j]))
+ {
+ case 'n': d[k] = '\n'; break;
+ case 't': d[k] = '\t'; break;
+ case 'a': d[k] = '\a'; break;
+ case 'b': d[k] = '\b'; break;
+ case 'f': d[k] = '\f'; break;
+ case 'r': d[k] = '\r'; break;
+ case 'v': d[k] = '\v'; break;
+ case '\\': d[k] = '\\'; break;
+ case '\"': d[k] = '\"'; break;
+ case '\'': d[k] = '\''; break;
+ default: d[k] = '\\'; d[k] = ch;
+ }
+ break;
+ default:
+ d[k] = ch;
+ }
+ j++, k++;
+ }
+ d[k] = '\0';
+ return k;
+}
+
+public char * OffsetEscapedString(char * s, int len, int offset)
+{
+ char ch;
+ int j = 0, k = 0;
+ while(j < len && k < offset && (ch = s[j]))
+ {
+ if(ch == '\\') ++j;
+ j++, k++;
+ }
+ return (k == offset) ? s + j : null;
+}
+
+public Operand GetOperand(Expression exp)
+{
+ Operand op { };
+ Type type = exp.expType;
+ if(type)
+ {
+ while(type.kind == classType &&
+ type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
{
if(!type._class.registered.dataType)
type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
type = type._class.registered.dataType;
-
+
+ }
+ if(exp.type == stringExp && op.kind == pointerType)
+ {
+ op.ui64 = (uint64)exp.string;
+ op.kind = pointerType;
+ op.ops = uint64Ops;
}
- op.kind = type.kind;
- op.type = exp.expType;
- if(exp.isConstant && exp.type == constantExp)
+ else if(exp.isConstant && exp.type == constantExp)
{
+ op.kind = type.kind;
+ op.type = exp.expType;
+
switch(op.kind)
{
+ case _BoolType:
case charType:
{
if(exp.constant[0] == '\'')
+ {
op.c = exp.constant[1];
+ op.ops = charOps;
+ }
else if(type.isSigned)
{
op.c = (char)strtol(exp.constant, null, 0);
if(type.isSigned)
{
op.i64 = (int64)_strtoi64(exp.constant, null, 0);
- op.ops = intOps;
+ op.ops = int64Ops;
}
else
{
op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
- op.ops = uintOps;
+ op.ops = uint64Ops;
}
- op.kind = intType;
+ op.kind = int64Type;
break;
case intPtrType:
if(type.isSigned)
{
- op.iptr = (intptr)_strtoi64(exp.constant, null, 0);
- op.ops = intOps;
+ op.i64 = (int64)_strtoi64(exp.constant, null, 0);
+ op.ops = int64Ops;
}
else
{
- op.uiptr = (uintptr)_strtoui64(exp.constant, null, 0);
- op.ops = uintOps;
+ op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
+ op.ops = uint64Ops;
}
- op.kind = intType;
+ op.kind = int64Type;
+ break;
+ case intSizeType:
+ if(type.isSigned)
+ {
+ op.i64 = (int64)_strtoi64(exp.constant, null, 0);
+ op.ops = int64Ops;
+ }
+ else
+ {
+ op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
+ op.ops = uint64Ops;
+ }
+ op.kind = int64Type;
break;
case floatType:
- op.f = (float)strtod(exp.constant, null);
+ if(!strcmp(exp.constant, "inf")) op.f = float::inf();
+ else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
+ else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
+ else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
+ else
+ op.f = (float)strtod(exp.constant, null);
op.ops = floatOps;
break;
case doubleType:
- op.d = (double)strtod(exp.constant, null);
+ if(!strcmp(exp.constant, "inf")) op.d = double::inf();
+ else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
+ else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
+ else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
+ else
+ op.d = (double)strtod(exp.constant, null);
op.ops = doubleOps;
break;
//case classType: For when we have operator overloading...
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 =
+ op.ops = uint64Ops;
+ // op.ptrSize =
break;
}
}
return op;
}
-static void UnusedFunction()
+static __attribute__((unused)) void UnusedFunction()
{
int a;
a.OnGetString(0,0,0);
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;
Class _class = classSym.registered;
DataMember dataMember;
OldList * memberList = MkList();
- inst.members = MkListOne(MkMembersInitList(memberList));
+ // Added this check and ->Add to prevent memory leaks on bad code
+ if(!inst.members)
+ inst.members = MkListOne(MkMembersInitList(memberList));
+ else
+ inst.members->Add(MkMembersInitList(memberList));
for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
{
if(!dataMember.isProperty)
exp.type = identifierExp;
exp.destType = MkClassType(_class.fullName);
ProcessExpressionType(exp);
- }
+ }
}
if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
{
if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
{
- // Don't recompute the instantiation...
+ // Don't recompute the instantiation...
// Non Simple classes will have become constants by now
- if(inst.data)
+ if(inst.data)
return;
if(_class.type == normalClass || _class.type == noHeadClass)
+ {
inst.data = (byte *)eInstance_New(_class);
+ if(_class.type == normalClass)
+ ((Instance)inst.data)._refCount++;
+ }
else
inst.data = new0 byte[_class.structSize];
}
else
{
dataMember = curMember;
-
+
// CHANGED THIS HERE
eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
+
+ // 2013/17/29 -- It seems that this was missing here!
+ if(_class.type == normalClass)
+ dataMemberOffset += _class.base.structSize;
// dataMemberOffset = dataMember.offset;
}
found = true;
{
curMember = dataMember;
curClass = dataMember._class;
- memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
+ memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
subMemberStackPos = _subMemberStackPos;
}
}
{
Expression value = member.initializer.exp;
Type type = null;
+ bool deepMember = false;
if(prop)
{
type = prop.dataType;
{
if(!dataMember.dataType)
dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
-
+
type = dataMember.dataType;
}
if(ident && ident.next)
{
+ deepMember = true;
+
// for(; ident && type; ident = ident.next)
for(ident = ident.next; ident && type; ident = ident.next)
{
type = prop.dataType;
else
{
- dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
+ dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
ident.string, &dataMemberOffset, privateModule, null, null);
if(dataMember)
type = dataMember.dataType;
if(type) type.refCount++;
ComputeExpression(value);
}
- if(value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
+ if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
{
if(type.kind == classType)
{
if(dataMember)
{
void * ptr = inst.data + dataMemberOffset;
-
+
if(value.type == constantExp)
{
switch(type.kind)
GetIntPtr(value, (intptr*)ptr);
break;
}
+ case intSizeType:
+ {
+ GetIntSize(value, (intsize*)ptr);
+ break;
+ }
case floatType:
{
GetFloat(value, (float*)ptr);
{
if(value.type == instanceExp && value.instance.data)
{
- void (*Set)(void *, void *) = (void *)prop.Set;
- Set(inst.data, value.instance.data);
- PopulateInstance(inst);
+ if(type.kind == classType)
+ {
+ Class _class = type._class.registered;
+ if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
+ {
+ void (*Set)(void *, void *) = (void *)prop.Set;
+ Set(inst.data, value.instance.data);
+ PopulateInstance(inst);
+ }
+ }
}
else if(value.type == constantExp)
{
case intType:
{
void (*Set)(void *, int) = (void *)prop.Set;
- Set(inst.data, strtol(value.constant, null, 0));
+ Set(inst.data, (int)strtol(value.constant, null, 0));
break;
}
case int64Type:
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 if(_class.type == unitClass)
+ else if(!deepMember && type && _class.type == unitClass)
{
if(prop)
{
}
}
}
- else if(_class.type == bitClass)
+ else if(!deepMember && type && _class.type == bitClass)
{
if(prop)
{
{
BitMember bitMember = (BitMember) dataMember;
Type type;
- int part = 0;
- GetInt(value, &part);
+ uint64 part;
bits = (bits & ~bitMember.mask);
if(!bitMember.dataType)
bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
-
type = bitMember.dataType;
-
if(type.kind == classType && type._class && type._class.registered)
{
if(!type._class.registered.dataType)
- type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
+ type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
type = type._class.registered.dataType;
}
-
switch(type.kind)
{
- case charType:
- if(type.isSigned)
- bits |= ((char)part << bitMember.pos);
- else
- bits |= ((unsigned char)part << bitMember.pos);
- break;
- case shortType:
- if(type.isSigned)
- bits |= ((short)part << bitMember.pos);
- else
- bits |= ((unsigned short)part << bitMember.pos);
- break;
+ case _BoolType:
+ case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
+ case shortType: { uint16 v; type.isSigned ? GetShort(value, (uint16 *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
case intType:
- case longType:
- if(type.isSigned)
- bits |= ((int)part << bitMember.pos);
- else
- bits |= ((unsigned int)part << bitMember.pos);
- break;
- case int64Type:
- if(type.isSigned)
- bits |= ((int64)part << bitMember.pos);
- 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 longType: { uint v; type.isSigned ? GetInt(value, (uint *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
+ case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (uint64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
+ case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (uintptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
+ case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (uintsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
}
+ bits |= part << bitMember.pos;
}
}
}
ComputeExpression(member.initializer.exp);
exp.constant = member.initializer.exp.constant;
exp.type = constantExp;
-
+
member.initializer.exp.constant = null;
}
}
}
}
+static bool Promote(Operand op, TypeKind kind, bool isSigned)
+{
+ bool result = false;
+ switch(kind)
+ {
+ case shortType:
+ if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
+ result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
+ break;
+ case intType:
+ case longType:
+ if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
+ result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
+ break;
+ case int64Type:
+ if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
+ op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
+ result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
+ break;
+ case floatType:
+ if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
+ op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
+ result = GetOpFloat(op, &op.f);
+ break;
+ case doubleType:
+ if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
+ op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
+ result = GetOpDouble(op, &op.d);
+ break;
+ case pointerType:
+ if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
+ op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
+ result = GetOpUIntPtr(op, &op.ui64);
+ break;
+ case enumType:
+ if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
+ op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
+ result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
+ break;
+ case intPtrType:
+ if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
+ result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
+ break;
+ case intSizeType:
+ if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
+ result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
+ break;
+ }
+ return result;
+}
+
void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
{
if(exp.op.op == SIZEOF)
}
else
{
+ if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
+ {
+ if(Promote(op2, op1.kind, op1.type.isSigned))
+ op2.kind = op1.kind, op2.ops = op1.ops;
+ else if(Promote(op1, op2.kind, op2.type.isSigned))
+ op1.kind = op2.kind, op1.ops = op2.ops;
+ }
switch(exp.op.op)
{
// binary arithmetic
// We don't care about operations with only exp2 (INC_OP, DEC_OP...)
if(exp.op.exp2)
- ComputeExpression(exp.op.exp2);
+ {
+ Expression e = exp.op.exp2;
+
+ while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
+ {
+ if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
+ {
+ if(e.type == extensionCompoundExp)
+ e = ((Statement)e.compound.compound.statements->last).expressions->last;
+ else
+ e = e.list->last;
+ }
+ }
+ if(exp.op.op == TokenType::sizeOf && e && e.expType)
+ {
+ if(e.type == stringExp && e.string)
+ {
+ char * string = e.string;
+ int len = strlen(string);
+ char * tmp = new char[len-2+1];
+ len = UnescapeString(tmp, string + 1, len - 2);
+ delete tmp;
+ FreeExpContents(exp);
+ exp.type = constantExp;
+ exp.constant = PrintUInt(len + 1);
+ }
+ else
+ {
+ Type type = e.expType;
+ type.refCount++;
+ FreeExpContents(exp);
+ exp.type = constantExp;
+ exp.constant = PrintUInt(ComputeTypeSize(type));
+ FreeType(type);
+ }
+ break;
+ }
+ else
+ ComputeExpression(exp.op.exp2);
+ }
if(exp.op.exp1)
{
ComputeExpression(exp.op.exp1);
if(op2.type) op2.type.refCount++;
}
}
- else
+ else
{
exp1 = exp.op.exp2;
op1 = GetOperand(exp1);
case '-':
if(exp.op.exp1)
{
- if(op1.ops.Sub)
+ if(op1.ops.Sub)
{
FreeExpContents(exp);
op1.ops.Sub(exp, op1, op2);
}
else
{
- if(op1.ops.Neg)
+ if(op1.ops.Neg)
{
FreeExpContents(exp);
op1.ops.Neg(exp, op1);
break;
// Binary only operators
case '/':
- if(op1.ops.Div)
+ if(op1.ops.Div)
{
FreeExpContents(exp);
op1.ops.Div(exp, op1, op2);
}
break;
case '|':
- if(op1.ops.BitOr)
+ if(op1.ops.BitOr)
{
FreeExpContents(exp);
op1.ops.BitOr(exp, op1, op2);
}
break;
case '^':
- if(op1.ops.BitXor)
+ if(op1.ops.BitXor)
{
FreeExpContents(exp);
op1.ops.BitXor(exp, op1, op2);
if(!n)
{
OldList * list = exp.list;
+ Expression prev = exp.prev;
+ Expression next = exp.next;
ComputeExpression(e);
//FreeExpContents(exp);
FreeType(exp.expType);
FreeType(exp.destType);
*exp = *e;
+ exp.prev = prev;
+ exp.next = next;
delete e;
delete list;
}
char string[256];
Symbol classSym;
string[0] = '\0';
- PrintType(type, string, false, true);
+ PrintTypeNoConst(type, string, false, true);
classSym = FindClass(string);
_class = classSym ? classSym.registered : null;
}
_class = classSym ? classSym.registered : null;
prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
}
-
+
if(prop)
{
if(prop.compiled)
double value;
double (*Get)(double);
GetDouble(exp.member.exp, &value);
-
+
if(convertTo)
Get = (void *)prop.Set;
else
void (*Set)(void *, void *) = (void *)prop.Set;
exp.instance = Instantiation { };
exp.instance.data = new0 byte[_class.structSize];
- exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+ exp.instance._class = MkSpecifierName(_class.fullName);
exp.instance.loc = exp.loc;
exp.type = instanceExp;
Set(exp.instance.data, value.instance.data);
exp.instance = Instantiation { };
exp.instance.data = new0 byte[_class.structSize];
- exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+ exp.instance._class = MkSpecifierName(_class.fullName);
exp.instance.loc = exp.loc;
exp.type = instanceExp;
-
+
GetInt(value, &intValue);
Set(exp.instance.data, intValue);
exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
exp.instance.loc = exp.loc;
exp.type = instanceExp;
-
+
GetInt64(value, &intValue);
Set(exp.instance.data, intValue);
exp.instance = Instantiation { };
exp.instance.data = new0 byte[_class.structSize];
- exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+ exp.instance._class = MkSpecifierName(_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(_class.fullName);
+ exp.instance.loc = exp.loc;
+ exp.type = instanceExp;
+
+ GetIntSize(value, &intValue);
+
+ Set(exp.instance.data, intValue);
+ PopulateInstance(exp.instance);
+ break;
+ }
+ case floatType:
+ {
+ float floatValue;
+ void (*Set)(void *, float) = (void *)prop.Set;
+
+ exp.instance = Instantiation { };
+ exp.instance.data = new0 byte[_class.structSize];
+ exp.instance._class = MkSpecifierName(_class.fullName);
+ exp.instance.loc = exp.loc;
+ exp.type = instanceExp;
+
+ GetFloat(value, &floatValue);
+
+ Set(exp.instance.data, floatValue);
+ PopulateInstance(exp.instance);
+ break;
+ }
case doubleType:
{
double doubleValue;
exp.instance = Instantiation { };
exp.instance.data = new0 byte[_class.structSize];
- exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+ exp.instance._class = MkSpecifierName(_class.fullName);
exp.instance.loc = exp.loc;
exp.type = instanceExp;
-
+
GetDouble(value, &doubleValue);
Set(exp.instance.data, doubleValue);
exp.instance = Instantiation { };
exp.instance.data = new0 byte[_class.structSize];
- exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+ exp.instance._class = MkSpecifierName(_class.fullName);
exp.instance.loc = exp.loc;
//exp.instance.fullSet = true;
exp.type = instanceExp;
exp.instance = Instantiation { };
exp.instance.data = new0 byte[_class.structSize];
- exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+ exp.instance._class = MkSpecifierName(_class.fullName);
exp.instance.loc = exp.loc;
//exp.instance.fullSet = true;
exp.type = instanceExp;
Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
FreeExpContents(exp);
exp.constant = PrintUInt(ComputeTypeSize(type));
- exp.type = constantExp;
+ exp.type = constantExp;
FreeType(type);
break;
}
FullClassNameCat(className, classSym.string, true);
MangleClassName(className);
+ DeclareClass(classSym, className);
+
FreeExpContents(exp);
exp.type = pointerExp;
exp.member.exp = MkExpIdentifier(MkIdentifier(className));
type = _class.dataType;
}
}
-
+
switch(type.kind)
{
+ case _BoolType:
case charType:
if(type.isSigned)
{
- char value;
- GetChar(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintChar(value);
- exp.type = constantExp;
+ char value = 0;
+ if(GetChar(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintChar(value);
+ exp.type = constantExp;
+ }
}
else
{
- unsigned char value;
- GetUChar(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintUChar(value);
- exp.type = constantExp;
+ unsigned char value = 0;
+ if(GetUChar(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintUChar(value);
+ exp.type = constantExp;
+ }
}
break;
case shortType:
if(type.isSigned)
{
- short value;
- GetShort(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintShort(value);
- exp.type = constantExp;
+ short value = 0;
+ if(GetShort(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintShort(value);
+ exp.type = constantExp;
+ }
}
else
{
- unsigned short value;
- GetUShort(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintUShort(value);
- exp.type = constantExp;
+ unsigned short value = 0;
+ if(GetUShort(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintUShort(value);
+ exp.type = constantExp;
+ }
}
break;
case intType:
if(type.isSigned)
{
- int value;
- GetInt(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintInt(value);
- exp.type = constantExp;
+ int value = 0;
+ if(GetInt(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintInt(value);
+ exp.type = constantExp;
+ }
}
else
{
- unsigned int value;
- GetUInt(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintUInt(value);
- exp.type = constantExp;
+ unsigned int value = 0;
+ if(GetUInt(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintUInt(value);
+ exp.type = constantExp;
+ }
}
break;
case int64Type:
if(type.isSigned)
{
- int64 value;
- GetInt64(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintInt64(value);
- exp.type = constantExp;
+ int64 value = 0;
+ if(GetInt64(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintInt64(value);
+ exp.type = constantExp;
+ }
}
else
{
- uint64 value;
- GetUInt64(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintUInt64(value);
- exp.type = constantExp;
+ uint64 value = 0;
+ if(GetUInt64(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintUInt64(value);
+ exp.type = constantExp;
+ }
}
break;
case intPtrType:
if(type.isSigned)
{
- intptr value;
- GetIntPtr(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintInt64((int64)value);
- exp.type = constantExp;
+ intptr value = 0;
+ if(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;
+ uintptr value = 0;
+ if(GetUIntPtr(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintUInt64((uint64)value);
+ exp.type = constantExp;
+ }
+ }
+ break;
+ case intSizeType:
+ if(type.isSigned)
+ {
+ intsize value = 0;
+ if(GetIntSize(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintInt64((int64)value);
+ exp.type = constantExp;
+ }
+ }
+ else
+ {
+ uintsize value = 0;
+ if(GetUIntSize(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintUInt64((uint64)value);
+ exp.type = constantExp;
+ }
}
break;
case floatType:
{
- float value;
- GetFloat(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintFloat(value);
- exp.type = constantExp;
+ float value = 0;
+ if(GetFloat(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintFloat(value);
+ exp.type = constantExp;
+ }
break;
}
case doubleType:
- {
- double value;
- GetDouble(e, &value);
- FreeExpContents(exp);
- exp.constant = PrintDouble(value);
- exp.type = constantExp;
+ {
+ double value = 0;
+ if(GetDouble(e, &value))
+ {
+ FreeExpContents(exp);
+ exp.constant = PrintDouble(value);
+ exp.type = constantExp;
+ }
break;
}
}
if(op2.type) FreeType(op2.type);
if(op3.type) FreeType(op3.type);
break;
- }
+ }
}
}
-static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
+static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
{
bool result = true;
if(destType)
if(destType.kind == voidType)
return false;
- if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
+ if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
result = false;
if(converts.count)
{
// TODO: Check this...
*newExp = *exp;
+ newExp.prev = null;
+ newExp.next = null;
newExp.destType = null;
if(convert.isGet)
}
else
{
-
+
/*if(exp.isConstant)
{
// Color { ColorRGB = [exp] };
if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
{
- result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
+ result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
}
if(!result && exp.expType && exp.destType)
{
- if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
+ if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
- (exp.expType.kind == classType && exp.destType.kind == pointerType &&
+ (exp.expType.kind == classType && exp.destType.kind == pointerType &&
exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
result = true;
}
if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
{
Expression newExp { };
- Statement compound;
Context context;
*newExp = *exp;
if(exp.destType) exp.destType.refCount++;
OldList * unionDefs = MkList();
OldList * statements = MkList();
context = PushContext();
- ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
+ ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
exp.type = extensionCompoundExp;
OldList * unionDefs = MkList();
OldList * statements = MkList();
context = PushContext();
- ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
+ ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
exp.type = extensionCompoundExp;
typeString[0] = '\0';
PrintType(exp.expType, typeString, false, false);
decl = SpecDeclFromString(typeString, specs, null);
-
+
exp.type = castExp;
//exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
exp.cast.typeName = MkTypeName(specs, decl);
// - Tree of all symbols within (stored without namespace)
// - Tree of sub-namespaces
-static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
+static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
{
int nsLen = strlen(nameSpace);
Symbol symbol;
return null;
}
-static Symbol FindWithNameSpace(BinaryTree tree, char * name)
+static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
{
int c;
char nameSpace[1024];
- char * namePart;
+ const char * namePart;
bool gotColon = false;
nameSpace[0] = '\0';
static void ProcessDeclaration(Declaration decl);
-/*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
+/*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
{
#ifdef _DEBUG
//Time startTime = GetTime();
// Modified this recently...
Context tmpContext = curContext;
- curContext = null;
+ curContext = null;
symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
curContext = tmpContext;
static void GetTypeSpecs(Type type, OldList * specs)
{
- if(!type.isSigned && type.kind != intPtrType) ListAdd(specs, MkSpecifier(UNSIGNED));
+ if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
switch(type.kind)
{
- case classType:
+ case classType:
{
if(type._class.registered)
{
case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
+ case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); 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 intType:
+ case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
+ case intType:
default:
ListAdd(specs, MkSpecifier(INT)); break;
}
}
+static void PrintArraySize(Type arrayType, char * string)
+{
+ char size[256];
+ size[0] = '\0';
+ strcat(size, "[");
+ if(arrayType.enumClass)
+ strcat(size, arrayType.enumClass.string);
+ else if(arrayType.arraySizeExp)
+ PrintExpression(arrayType.arraySizeExp, size);
+ strcat(size, "]");
+ strcat(string, size);
+}
+
// WARNING : This function expects a null terminated string since it recursively concatenate...
-static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
+static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
{
if(type)
{
+ if(printConst && type.constant)
+ strcat(string, "const ");
switch(type.kind)
{
case classType:
- if(type._class && type._class.string)
- {
- // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
- // look into merging with thisclass ?
- if(type.classObjectType == typedObject)
- strcat(string, "typed_object");
- else if(fullName)
- strcat(string, type._class.string);
- else
- {
- if(type._class.registered)
- strcat(string, type._class.registered.name);
- else
- strcat(string, type._class.string);
- }
- }
- break;
- case pointerType:
{
- /*Type funcType;
- for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
- if(funcType && funcType.kind == functionType)
- {
- Type param;
- PrintType(funcType.returnType, string, false, fullName);
- strcat(string, "(*");
- if(printName || funcType.thisClass)
- {
- strcat(string, " ");
- if(funcType.thisClass)
- {
- strcat(string, funcType.thisClass.string);
- strcat(string, "::");
- }
- if(type.name)
- strcat(string, type.name);
- }
- strcat(string, ")(");
- for(param = funcType.params.first; param; param = param.next)
- {
- PrintType(param, string, false, fullName);
- if(param.next) strcat(string, ", ");
- }
- strcat(string, ")");
- }
- else*/
+ Symbol c = type._class;
+ // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
+ // look into merging with thisclass ?
+ if(type.classObjectType == typedObject)
+ strcat(string, "typed_object");
+ else if(type.classObjectType == anyObject)
+ strcat(string, "any_object");
+ else
{
- _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
- strcat(string, " *");
+ if(c && c.string)
+ strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
}
+ if(type.byReference)
+ strcat(string, " &");
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 _BoolType: strcat(string, "_Bool"); break;
case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
case floatType: strcat(string, "float"); break;
case doubleType: strcat(string, "double"); break;
strcat(string, type.enumName);
}
else if(type.typeName)
- {
strcat(string, type.typeName);
- }
else
{
- /*
- strcat(string, "struct ");
- strcat(string,"(unnamed)");
- */
Type member;
- strcat(string, "struct {");
+ strcat(string, "struct { ");
for(member = type.members.first; member; member = member.next)
{
PrintType(member, string, true, fullName);
strcat(string, type.enumName);
}
else if(type.typeName)
- {
strcat(string, type.typeName);
- }
else
{
strcat(string, "union ");
strcat(string, type.enumName);
}
else if(type.typeName)
- {
strcat(string, type.typeName);
- }
else
- strcat(string, "enum");
- break;
- case functionType:
- {
- if(printFunction)
- {
- if(type.dllExport)
- strcat(string, "dllexport ");
- PrintType(type.returnType, string, false, fullName);
- strcat(string, " ");
- }
-
- // DANGER: Testing This
- if(printName)
- {
- if(type.name)
- {
- if(fullName)
- strcat(string, type.name);
- else
- {
- char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
- if(name) name += 2; else name = type.name;
- strcat(string, name);
- }
- }
-#ifdef _DEBUG
- else
- {
- printf("");
- }
-#endif
- }
-
- if(printFunction)
- {
- Type param;
- strcat(string, "(");
- for(param = type.params.first; param; param = param.next)
- {
- PrintType(param, string, true, fullName);
- if(param.next) strcat(string, ", ");
- }
- strcat(string, ")");
- }
+ strcat(string, "int"); // "enum");
break;
- }
- case arrayType:
- {
- /*Type funcType;
- for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
- if(funcType && funcType.kind == functionType)
- {
- Type param;
- PrintType(funcType.returnType, string, false, fullName);
- strcat(string, "(*");
- if(printName || funcType.thisClass)
- {
- strcat(string, " ");
- if(funcType.thisClass)
- {
- strcat(string, funcType.thisClass.string);
- strcat(string, "::");
- }
- if(type.name)
- strcat(string, type.name);
- }
- strcat(string, ")(");
- for(param = funcType.params.first; param; param = param.next)
- {
- PrintType(param, string, false, fullName);
- if(param.next) strcat(string, ", ");
- }
- strcat(string, ")");
- }
- else*/
- {
- char baseType[1024], size[256];
- Type arrayType = type;
- baseType[0] = '\0';
- size[0] = '\0';
-
- while(arrayType.kind == TypeKind::arrayType)
- {
- strcat(size, "[");
- if(arrayType.enumClass)
- strcat(size, arrayType.enumClass.string);
- else if(arrayType.arraySizeExp)
- PrintExpression(arrayType.arraySizeExp, size);
- //sprintf(string, "%s[%s]", baseType, size);
- strcat(size, "]");
-
- arrayType = arrayType.arrayType;
- }
- _PrintType(arrayType, baseType, printName, printFunction, fullName);
- strcat(string, baseType);
- strcat(string, size);
- }
-
- /*
- PrintType(type.arrayType, baseType, printName, fullName);
- if(type.enumClass)
- strcpy(size, type.enumClass.string);
- else if(type.arraySizeExp)
- PrintExpression(type.arraySizeExp, size);
- //sprintf(string, "%s[%s]", baseType, size);
- strcat(string, baseType);
- strcat(string, "[");
- strcat(string, size);
- strcat(string, "]");
- */
-
- printName = false;
- break;
- }
case ellipsisType:
strcat(string, "...");
break;
- case methodType:
- _PrintType(type.method.dataType, string, false, printFunction, fullName);
- break;
case subClassType:
strcat(string, "subclass(");
strcat(string, type._class ? type._class.string : "int");
- strcat(string, ")");
+ strcat(string, ")");
break;
case templateType:
strcat(string, type.templateParameter.identifier.string);
strcat(string, "thisclass");
break;
case vaListType:
- strcat(string, "__builtin_va_list");
+ 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))
- {
- strcat(string, " ");
- strcat(string, type.name);
}
}
}
-// *****
-// 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)
+static void PrintName(Type type, char * string, bool fullName)
{
- Type funcType;
- for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
- if(funcType && funcType.kind == functionType && type != funcType)
+ if(type.name && type.name[0])
{
- char typeString[1024];
- Type param;
-
- PrintType(funcType.returnType, string, false, fullName);
- strcat(string, "(");
- _PrintType(type, string, printName, false, fullName);
- strcat(string, ")");
- /*
- if(type.name)
+ if(fullName)
strcat(string, type.name);
else
{
- printf("");
+ char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
+ if(name) name += 2; else name = type.name;
+ strcat(string, name);
}
- */
+ }
+}
+
+static void PrintAttribs(Type type, char * string)
+{
+ if(type)
+ {
+ if(type.dllExport) strcat(string, "dllexport ");
+ if(type.attrStdcall) strcat(string, "stdcall ");
+ }
+}
+
+static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
+{
+ if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
+ {
+ Type attrType = null;
+ if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
+ PrintAttribs(type, string);
+ if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
+ strcat(string, " const");
+ PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
+ if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
+ strcat(string, " (");
+ if(type.kind == pointerType)
+ {
+ if(type.type.kind == functionType || type.type.kind == methodType)
+ PrintAttribs(type.type, string);
+ }
+ if(type.kind == pointerType)
+ {
+ if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
+ strcat(string, "*");
+ else
+ strcat(string, " *");
+ }
+ if(printConst && type.constant && type.kind == pointerType)
+ strcat(string, " const");
+ }
+ else
+ PrintTypeSpecs(type, string, fullName, printConst);
+}
+
+static void PostPrintType(Type type, char * string, bool fullName)
+{
+ if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
+ strcat(string, ")");
+ if(type.kind == arrayType)
+ PrintArraySize(type, string);
+ else if(type.kind == functionType)
+ {
+ Type param;
strcat(string, "(");
- for(param = funcType.params.first; param; param = param.next)
+ for(param = type.params.first; param; param = param.next)
{
PrintType(param, string, true, fullName);
if(param.next) strcat(string, ", ");
}
strcat(string, ")");
}
- else
- _PrintType(type, string, printName, true, fullName);
+ if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
+ PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
+}
+
+// *****
+// TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
+// *****
+static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
+{
+ PrePrintType(type, string, fullName, null, printConst);
+
+ if(type.thisClass || (printName && type.name && type.name[0]))
+ strcat(string, " ");
+ if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
+ {
+ Symbol _class = type.thisClass;
+ if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
+ {
+ if(type.classObjectType == classPointer)
+ strcat(string, "class");
+ else
+ strcat(string, type.byReference ? "typed_object&" : "typed_object");
+ }
+ else if(_class && _class.string)
+ {
+ String s = _class.string;
+ if(fullName)
+ strcat(string, s);
+ else
+ {
+ char * name = RSearchString(s, "::", strlen(s), true, false);
+ if(name) name += 2; else name = s;
+ strcat(string, name);
+ }
+ }
+ strcat(string, "::");
+ }
+
+ if(printName && type.name)
+ PrintName(type, string, fullName);
+ PostPrintType(type, string, fullName);
if(type.bitFieldCount)
{
char count[100];
}
}
+void PrintType(Type type, char * string, bool printName, bool fullName)
+{
+ _PrintType(type, string, printName, fullName, true);
+}
+
+void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
+{
+ _PrintType(type, string, printName, fullName, false);
+}
+
static Type FindMember(Type type, char * string)
{
Type memberType;
return null;
}
+public bool GetParseError() { return parseError; }
+
Expression ParseExpressionString(char * expression)
{
+ parseError = false;
+
fileInput = TempFile { };
fileInput.Write(expression, 1, strlen(expression));
fileInput.Seek(0, start);
exp.type = constantExp;
exp.isConstant = true;
if(!strcmp(baseClass.dataTypeString, "int"))
- sprintf(constant, "%d",value.data);
+ sprintf(constant, "%d",(int)value.data);
else
- sprintf(constant, "0x%X",value.data);
+ sprintf(constant, "0x%X",(int)value.data);
exp.constant = CopyString(constant);
//for(;_class.base && _class.base.type != systemClass; _class = _class.base);
exp.expType = MkClassType(baseClass.fullName);
{
char constant[256];
exp.type = constantExp;
- sprintf(constant, "%d",classProp.Get(_class));
+ sprintf(constant, "%d", (int)classProp.Get(_class));
exp.constant = CopyString(constant);
}
}
void ApplyAnyObjectLogic(Expression e)
{
Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
+#ifdef _DEBUG
+ char debugExpString[4096];
+ debugExpString[0] = '\0';
+ PrintExpression(e, debugExpString);
+#endif
+
if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
{
//if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
char string[1024] = "";
Symbol classSym;
- PrintType(type, string, false, true);
+ PrintTypeNoConst(type, string, false, true);
classSym = FindClass(string);
if(classSym) _class = classSym.registered;
}
- if((_class && (_class.type == enumClass || _class.type == unitClass || _class.type == bitClass || _class.type == systemClass) && strcmp(_class.fullName, "class") && strcmp(_class.fullName, "ecere::com::Class")) || // Patched so that class isn't considered SYSTEM...
- (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
+ if((_class && (_class.type == enumClass || _class.type == unitClass || _class.type == bitClass || _class.type == systemClass) && strcmp(_class.fullName, "class") && strcmp(_class.fullName, "uintptr") && strcmp(_class.fullName, "intptr")) || // Patched so that class isn't considered SYSTEM...
+ (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != intPtrType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
destType.byReference)))
{
if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
newExp = checkedExp.op.exp2;
checkedExp.op.exp2 = null;
FreeExpContents(checkedExp);
-
+
if(e.expType && e.expType.passAsTemplate)
{
char size[100];
}
else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
{
- Expression checkedExp, newExp;
+ Expression checkedExp; //, newExp;
{
// TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
newExp.next = null;
newExp.expType = null;
- PrintType(e.expType, typeString, false, true);
+ PrintTypeNoConst(e.expType, typeString, false, true);
decl = SpecDeclFromString(typeString, specs, null);
newExp.destType = ProcessType(specs, decl);
curContext = context;
- e.type = extensionCompoundExp;
// We need a current compound for this
if(curCompound)
{
char name[100];
OldList * stmts = MkList();
+ e.type = extensionCompoundExp;
sprintf(name, "__internalValue%03X", internalValueCounter++);
if(!curCompound.compound.declarations)
curCompound.compound.declarations = MkList();
/*
e.compound = MkCompoundStmt(
MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
- MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
+ MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
*/
-
+
{
Type type = e.destType;
e.destType = { };
// FixReference(e, true);
}
//#if 0
- if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
+ if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
(e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
(e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
{
- if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
+ if(e.expType.classObjectType && destType && destType.classObjectType) //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
{
return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
}
e.Clear();
e.type = bracketsExp;
- e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
+ e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
((Expression)e.list->first).byReference = true;
// TOFIX: Try this for a nice IDE crash!
//#endif
// The other way around
- else
+ else
//#endif
- if(destType && e.expType &&
+ if(destType && e.expType &&
//e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
- (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
+ (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
!destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
{
if(destType.kind == ellipsisType)
char typeString[1024]; // Watch buffer overruns
Type type;
ClassObjectType backupClassObjectType;
+ bool backupByReference;
if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
type = e.expType;
else
- type = destType;
+ type = destType;
backupClassObjectType = type.classObjectType;
+ backupByReference = type.byReference;
type.classObjectType = none;
+ type.byReference = false;
typeString[0] = '\0';
PrintType(type, typeString, false, true);
decl = SpecDeclFromString(typeString, specs, null);
type.classObjectType = backupClassObjectType;
+ type.byReference = backupByReference;
*thisExp = *e;
thisExp.prev = null;
thisExp.next = null;
e.Clear();
- if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
- (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
+ if( ( type.kind == classType && type._class && type._class.registered &&
+ (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
- (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
+ (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
(!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
{
e.type = opExp;
e.op.op = '*';
e.op.exp1 = null;
e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
+
+ e.expType = { };
+ CopyTypeInto(e.expType, type);
+ e.expType.byReference = false;
+ e.expType.refCount = 1;
}
else
{
e.cast.typeName = MkTypeName(specs, decl);
e.cast.exp = thisExp;
e.byReference = true;
+ e.expType = type;
+ type.refCount++;
}
- e.expType = type;
e.destType = destType;
- type.refCount++;
destType.refCount++;
}
}
}
+void ApplyLocation(Expression exp, Location loc)
+{
+ exp.loc = loc;
+ switch(exp.type)
+ {
+ case opExp:
+ if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
+ if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
+ break;
+ case bracketsExp:
+ if(exp.list)
+ {
+ Expression e;
+ for(e = exp.list->first; e; e = e.next)
+ ApplyLocation(e, loc);
+ }
+ break;
+ case indexExp:
+ if(exp.index.index)
+ {
+ Expression e;
+ for(e = exp.index.index->first; e; e = e.next)
+ ApplyLocation(e, loc);
+ }
+ if(exp.index.exp)
+ ApplyLocation(exp.index.exp, loc);
+ break;
+ case callExp:
+ if(exp.call.arguments)
+ {
+ Expression arg;
+ for(arg = exp.call.arguments->first; arg; arg = arg.next)
+ ApplyLocation(arg, loc);
+ }
+ if(exp.call.exp)
+ ApplyLocation(exp.call.exp, loc);
+ break;
+ case memberExp:
+ case pointerExp:
+ if(exp.member.exp)
+ ApplyLocation(exp.member.exp, loc);
+ break;
+ case castExp:
+ if(exp.cast.exp)
+ ApplyLocation(exp.cast.exp, loc);
+ break;
+ case conditionExp:
+ if(exp.cond.exp)
+ {
+ Expression e;
+ for(e = exp.cond.exp->first; e; e = e.next)
+ ApplyLocation(e, loc);
+ }
+ if(exp.cond.cond)
+ ApplyLocation(exp.cond.cond, loc);
+ if(exp.cond.elseExp)
+ ApplyLocation(exp.cond.elseExp, loc);
+ break;
+ case vaArgExp:
+ if(exp.vaArg.exp)
+ ApplyLocation(exp.vaArg.exp, loc);
+ break;
+ default:
+ break;
+ }
+}
+
void ProcessExpressionType(Expression exp)
{
bool unresolved = false;
Location oldyylloc = yylloc;
bool notByReference = false;
-#ifdef _DEBUG
+#ifdef _DEBUG
char debugExpString[4096];
debugExpString[0] = '\0';
PrintExpression(exp, debugExpString);
#endif
- if(!exp || exp.expType)
+ if(!exp || exp.expType)
return;
//eSystem_Logf("%s\n", expString);
-
+
// Testing this here
yylloc = exp.loc;
switch(exp.type)
case identifierExp:
{
Identifier id = exp.identifier;
- if(!id) return;
+ if(!id || !topContext) return;
// DOING THIS LATER NOW...
if(id._class && id._class.name)
// Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
if(!symbol/* && exp.destType*/)
{
- if(exp.destType && CheckExpressionType(exp, exp.destType, false))
+ if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
break;
else
{
exp.expType = type;
if(type)
type.refCount++;
- if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
+
+ // Commented this out, it was making non-constant enum parameters seen as constant
+ // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
+ if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
// Add missing cases here... enum Classes...
exp.isConstant = true;
// TOCHECK: Why was !strcmp(id.string, "this") commented out?
if(symbol.isParam || !strcmp(id.string, "this"))
{
- if(_class && _class.type == structClass)
+ if(_class && _class.type == structClass && !type.declaredWithStruct)
exp.byReference = true;
-
+
//TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
- /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
- ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
+ /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
+ ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
(type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
{
Identifier id = exp.identifier;
exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
((Expression)exp.list->first).op.exp2.expType = exp.expType;
exp.expType = null;
- ProcessExpressionType(exp);
+ ProcessExpressionType(exp);
}
else if(symbol.isIterator != 4)
{
if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
{
Location backupYylloc = yylloc;
+ File backInput = fileInput;
definedExpStack[definedExpStackPos++] = definedExp;
+
fileInput = TempFile { };
fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
fileInput.Seek(0, start);
resetScanner();
expression_yyparse();
delete fileInput;
+ if(backInput)
+ fileInput = backInput;
yylloc = backupYylloc;
FreeIdentifier(id);
exp.type = bracketsExp;
exp.list = MkListOne(parsedExpression);
- parsedExpression.loc = yylloc;
+ ApplyLocation(parsedExpression, yylloc);
ProcessExpressionType(exp);
definedExpStackPos--;
return;
{
exp.instance._class = MkSpecifierName(exp.destType._class.string);
}
-#ifdef _DEBUG
- else
- {
- printf("");
- }
-#endif
}
//classSym = FindClass(exp.instance._class.fullName);
//_class = classSym ? classSym.registered : null;
ProcessInstantiationType(exp.instance);
+
exp.isConstant = exp.instance.isConstant;
/*
if(exp.instance._class)
{
exp.expType = MkClassType(exp.instance._class.name);
- /*if(exp.expType._class && exp.expType._class.registered &&
+ /*if(exp.expType._class && exp.expType._class.registered &&
(exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
exp.expType.byReference = true;*/
- }
+ }
break;
}
case constantExp:
{
if(!exp.expType)
{
+ char * constant = exp.constant;
Type type
{
refCount = 1;
};
exp.expType = type;
- if(exp.constant[0] == '\'')
+ if(constant[0] == '\'')
{
- if((int)((byte *)exp.constant)[1] > 127)
+ if((int)((byte *)constant)[1] > 127)
{
int nb;
- unichar ch = UTF8GetChar(exp.constant + 1, &nb);
- if(nb < 2) ch = exp.constant[1];
- delete exp.constant;
+ unichar ch = UTF8GetChar(constant + 1, &nb);
+ if(nb < 2) ch = constant[1];
+ delete constant;
exp.constant = PrintUInt(ch);
// type.kind = (ch > 0xFFFF) ? intType : shortType;
type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
type.isSigned = true;
}
}
- else if(strchr(exp.constant, '.'))
- {
- char ch = exp.constant[strlen(exp.constant)-1];
- if(ch == 'f')
- type.kind = floatType;
- else
- type.kind = doubleType;
- type.isSigned = true;
- }
else
{
- if(exp.constant[0] == '0' && exp.constant[1])
- type.isSigned = false;
- else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
- type.isSigned = false;
- else if(strtoll(exp.constant, null, 0) > MAXINT)
- type.isSigned = false;
+ char * dot = strchr(constant, '.');
+ bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
+ char * exponent;
+ if(isHex)
+ {
+ exponent = strchr(constant, 'p');
+ if(!exponent) exponent = strchr(constant, 'P');
+ }
else
+ {
+ exponent = strchr(constant, 'e');
+ if(!exponent) exponent = strchr(constant, 'E');
+ }
+
+ if(dot || exponent)
+ {
+ if(strchr(constant, 'f') || strchr(constant, 'F'))
+ type.kind = floatType;
+ else
+ type.kind = doubleType;
type.isSigned = true;
- type.kind = intType;
+ }
+ else
+ {
+ bool isSigned = constant[0] == '-';
+ char * endP = null;
+ int64 i64 = strtoll(constant, &endP, 0);
+ uint64 ui64 = strtoull(constant, &endP, 0);
+ bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
+ if(isSigned)
+ {
+ if(i64 < MININT)
+ is64Bit = true;
+ }
+ else
+ {
+ if(ui64 > MAXINT)
+ {
+ if(ui64 > MAXDWORD)
+ {
+ is64Bit = true;
+ if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
+ isSigned = true;
+ }
+ }
+ else if(constant[0] != '0' || !constant[1])
+ isSigned = true;
+ }
+ type.kind = is64Bit ? int64Type : intType;
+ type.isSigned = isSigned;
+ }
}
exp.isConstant = true;
+ if(exp.destType && exp.destType.kind == doubleType)
+ type.kind = doubleType;
+ else if(exp.destType && exp.destType.kind == floatType)
+ type.kind = floatType;
+ else if(exp.destType && exp.destType.kind == int64Type)
+ type.kind = int64Type;
}
break;
}
refCount = 1;
kind = charType;
constant = true;
+ isSigned = true;
}
};
break;
bool useDestType = false, useSideType = false;
Location oldyylloc = yylloc;
bool useSideUnit = false;
+ Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
// Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
Type dummy
switch(exp.op.op)
{
// Assignment Operators
- case '=':
+ case '=':
case MUL_ASSIGN:
case DIV_ASSIGN:
case MOD_ASSIGN:
case '+':
case '-':
useSideUnit = true;
+ useSideType = true;
+ useDestType = true;
+ break;
+
+ case LEFT_OP:
+ case RIGHT_OP:
+ useSideType = true;
+ useDestType = true;
+ break;
- // Just added these... testing
case '|':
- case '&':
case '^':
+ useSideType = true;
+ useDestType = true;
+ break;
- // DANGER: Verify units
case '/':
case '%':
+ useSideType = true;
+ useDestType = true;
+ break;
+ case '&':
case '*':
-
- if(exp.op.op != '*' || exp.op.exp1)
+ if(exp.op.exp1)
{
+ // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
useSideType = true;
useDestType = true;
}
}
//dummy.kind = TypeDummy;
-
if(exp.op.exp1)
{
- if(exp.destType && exp.destType.kind == classType &&
- exp.destType._class && exp.destType._class.registered && useDestType &&
-
- ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
- exp.destType._class.registered.type == enumClass ||
- exp.destType._class.registered.type == bitClass
- ))
+ // Added this check here to use the dest type only for units derived from the base unit
+ // So that untyped units will use the side unit as opposed to the untyped destination unit
+ // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
+ if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
+ useDestType = false;
+
+ if(destClass && useDestType &&
+ ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
//(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
{
if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
exp.op.exp1.destType = exp.destType;
+ exp.op.exp1.opDestType = true;
if(exp.destType)
exp.destType.refCount++;
}
{
if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
exp.op.exp1.destType = dummy;
- dummy.refCount++;
+ dummy.refCount++;
}
// TESTING THIS HERE...
if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
- ProcessExpressionType(exp.op.exp1);
+ ProcessExpressionType(exp.op.exp1);
if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
+ exp.op.exp1.opDestType = false;
+
+ // Fix for unit and ++ / --
+ if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
+ exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
+ {
+ exp.op.exp2 = MkExpConstant("1");
+ exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
+ assign = true;
+ }
+
if(exp.op.exp1.destType == dummy)
{
FreeType(dummy);
else
{
exp.op.exp2.destType = exp.destType;
+ if(!exp.op.exp1 || exp.op.op != '&')
+ exp.op.exp2.opDestType = true;
if(exp.destType)
exp.destType.refCount++;
}
}
else
{
- // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
+ // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
if(exp.op.op == MUL_ASSIGN || exp.op.op == DIV_ASSIGN ||exp.op.op == MOD_ASSIGN ||exp.op.op == LEFT_ASSIGN ||exp.op.op == RIGHT_ASSIGN/* ||
exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
else
if(type1) type1.refCount++;
exp.expType = type1;
}
- else if(exp.destType && exp.destType.kind == classType &&
- exp.destType._class && exp.destType._class.registered &&
-
- ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
- (exp.destType._class.registered.type == enumClass && useDestType))
- )
+ else if(destClass &&
+ ((destClass.type == unitClass && useDestType && useSideUnit) ||
+ (destClass.type == enumClass && useDestType)))
{
if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
exp.op.exp2.destType = exp.destType;
+ if(exp.op.op != '&')
+ exp.op.exp2.opDestType = true;
if(exp.destType)
exp.destType.refCount++;
}
}
// TESTING THIS HERE... (DANGEROUS)
- if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
+ if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
(type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
{
FreeType(exp.op.exp2.destType);
type1.refCount++;
}
if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
+ // Cannot lose the cast on a sizeof
+ if(exp.op.op == SIZEOF)
+ {
+ Expression e = exp.op.exp2;
+ while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
+ {
+ if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
+ {
+ if(e.type == extensionCompoundExp)
+ e = ((Statement)e.compound.compound.statements->last).expressions->last;
+ else
+ e = e.list->last;
+ }
+ }
+ if(e.type == castExp && e.cast.exp)
+ e.cast.exp.needCast = true;
+ }
ProcessExpressionType(exp.op.exp2);
+ exp.op.exp2.opDestType = false;
if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
{
- if(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.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)
+ if(exp.op.op != '=' && type1.type.kind == voidType)
Compiler_Error($"void *: unknown size\n");
}
- else if(exp.op.exp2.expType.kind == pointerType || exp.op.exp2.expType.kind == arrayType || exp.op.exp2.expType.kind == functionType || exp.op.exp2.expType.kind == methodType||
+ else if(exp.op.exp2.expType.kind == pointerType || exp.op.exp2.expType.kind == arrayType || exp.op.exp2.expType.kind == functionType || exp.op.exp2.expType.kind == methodType||
(type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
- (exp.op.exp2.expType._class.registered.type == normalClass ||
+ (exp.op.exp2.expType._class.registered.type == normalClass ||
exp.op.exp2.expType._class.registered.type == structClass ||
exp.op.exp2.expType._class.registered.type == noHeadClass)))
{
if(exp.op.op == ADD_ASSIGN)
- Compiler_Error($"cannot add two pointers\n");
+ Compiler_Error($"cannot add two pointers\n");
}
- else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
+ else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
{
if(exp.op.op == ADD_ASSIGN)
- Compiler_Error($"cannot add two pointers\n");
+ Compiler_Error($"cannot add two pointers\n");
}
else if(inCompiler)
{
char type2String[1024];
type1String[0] = '\0';
type2String[0] = '\0';
-
+
PrintType(exp.op.exp2.expType, type1String, false, true);
PrintType(type1, type2String, false, true);
ChangeCh(expString, '\n', ' ');
exp.op.exp2.destType = null;
}
- type2 = exp.op.exp2.expType;
+ if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
+ {
+ type2 = { };
+ type2.refCount = 1;
+ CopyTypeInto(type2, exp.op.exp2.expType);
+ type2.isSigned = true;
+ }
+ else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
+ {
+ type2 = { kind = intType };
+ type2.refCount = 1;
+ type2.isSigned = true;
+ }
+ else
+ {
+ type2 = exp.op.exp2.expType;
+ if(type2) type2.refCount++;
+ }
}
dummy.kind = voidType;
exp.expType = Type
{
refCount = 1;
- kind = intType;
+ kind = intSizeType;
};
exp.isConstant = true;
}
{
if(boolOps)
{
- if(exp.op.exp1)
+ if(exp.op.exp1)
{
if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
exp.op.exp1.destType = MkClassType("bool");
if(!exp.op.exp1.expType)
ProcessExpressionType(exp.op.exp1);
else
- CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
+ CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
FreeType(exp.op.exp1.expType);
exp.op.exp1.expType = MkClassType("bool");
exp.op.exp1.expType.truth = true;
}
- if(exp.op.exp2)
+ if(exp.op.exp2)
{
if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
exp.op.exp2.destType = MkClassType("bool");
if(!exp.op.exp2.expType)
ProcessExpressionType(exp.op.exp2);
else
- CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
+ CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
FreeType(exp.op.exp2.expType);
exp.op.exp2.expType = MkClassType("bool");
exp.op.exp2.expType.truth = true;
}
}
- else if(exp.op.exp1 && exp.op.exp2 &&
- ((useSideType /*&&
- (useSideUnit ||
+ else if(exp.op.exp1 && exp.op.exp2 &&
+ ((useSideType /*&&
+ (useSideUnit ||
((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
(!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
- ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
+ ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
(!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
{
if(type1 && type2 &&
// If either both are class or both are not class
((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
{
- if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
- exp.op.exp2.destType = type1;
- type1.refCount++;
- if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
- exp.op.exp1.destType = type2;
- type2.refCount++;
+ // Added this check for enum subtraction to result in an int type:
+ if(exp.op.op == '-' &&
+ ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
+ (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
+ {
+ Type intType;
+ if(!type1._class.registered.dataType)
+ type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
+ if(!type2._class.registered.dataType)
+ type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
+
+ intType = ProcessTypeString(
+ (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
+
+ if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
+ if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
+ exp.op.exp1.destType = intType;
+ exp.op.exp2.destType = intType;
+ intType.refCount++;
+ }
+ else
+ {
+ if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
+ exp.op.exp2.destType = type1;
+ type1.refCount++;
+ if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
+ exp.op.exp1.destType = type2;
+ type2.refCount++;
+ }
+
// Warning here for adding Radians + Degrees with no destination type
- if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
- type1._class.registered && type1._class.registered.type == unitClass &&
- type2._class.registered && type2._class.registered.type == unitClass &&
+ if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
+ type1._class.registered && type1._class.registered.type == unitClass &&
+ type2._class.registered && type2._class.registered.type == unitClass &&
type1._class.registered != type2._class.registered)
Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
type1._class.string, type2._class.string, type1._class.string);
Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
- MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
+ MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
exp.op.exp1)));
ProcessExpressionType(exp.op.exp1);
{
ProcessExpressionType(classExp);
- exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
+ exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
// ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
// noHeadClass
MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
- OR_OP,
+ OR_OP,
// normalClass
MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
- MkPointer(null, null), null)))),
+ MkPointer(null, null), null)))),
MkExpMember(classExp, MkIdentifier("typeSize"))))))));
if(!exp.op.exp2.expType)
+ {
+ if(type2)
+ FreeType(type2);
type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
+ type2.refCount++;
+ }
ProcessExpressionType(exp.op.exp2);
}
}
}
-
- if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == intPtrType || 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)
+ 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 == intPtrType || 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)
+ if(type2.kind != classType && type2.type.kind == voidType)
Compiler_Error($"void *: unknown size\n");
exp.expType = type2;
if(type2) type2.refCount++;
{
Compiler_Warning($"different levels of indirection\n");
}
- else
+ else
{
bool success = false;
if(type1.kind == pointerType && type2.kind == pointerType)
else if(exp.op.op == '-')
{
// Pointer Subtraction gives integer
- if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
+ if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
{
exp.expType = Type
{
exp.list = MkListOne(MkExpOp(
MkExpBrackets(MkListOne(MkExpOp(
MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
- , exp.op.op,
- MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
-
+ , exp.op.op,
+ MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
+
//MkExpMember(classExp, MkIdentifier("typeSize"))
// ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
// noHeadClass
MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
- OR_OP,
+ OR_OP,
// normalClass
MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
- MkPointer(null, null), null)))),
+ MkPointer(null, null), null)))),
MkExpMember(classExp, MkIdentifier("typeSize")))))
-
+
));
-
+
ProcessExpressionType(((Expression)exp.list->first).op.exp2);
FreeType(dummy);
- return;
+ return;
}
}
}
if(!success && exp.op.exp1.type == constantExp)
{
// If first expression is constant, try to match that first
- if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
+ if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
{
if(exp.expType) FreeType(exp.expType);
exp.expType = exp.op.exp1.destType;
if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
success = true;
}
- else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
+ else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
{
if(exp.expType) FreeType(exp.expType);
exp.expType = exp.op.exp2.destType;
}
else if(!success)
{
- if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
+ if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
{
if(exp.expType) FreeType(exp.expType);
exp.expType = exp.op.exp2.destType;
if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
success = true;
}
- else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
+ else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
{
if(exp.expType) FreeType(exp.expType);
exp.expType = exp.op.exp1.destType;
exp.op.exp1.destType = type2._class.registered.dataType;
if(type2._class.registered.dataType)
type2._class.registered.dataType.refCount++;
- CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
+ CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
exp.expType = type2;
if(type2) type2.refCount++;
}
exp.op.exp2.destType = type1._class.registered.dataType;
if(type1._class.registered.dataType)
type1._class.registered.dataType.refCount++;
- CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
+ CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
exp.expType = type1;
if(type1) type1.refCount++;
}
exp.op.exp2.destType = type1._class.registered.dataType;
exp.op.exp2.destType.refCount++;
- CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
+ CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
+ if(type2)
+ FreeType(type2);
type2 = exp.op.exp2.destType;
+ if(type2) type2.refCount++;
exp.expType = type2;
type2.refCount++;
}
-
+
if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
{
if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
exp.op.exp1.destType = type2._class.registered.dataType;
exp.op.exp1.destType.refCount++;
- CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
+ CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
type1 = exp.op.exp1.destType;
exp.expType = type1;
type1.refCount++;
}
// TESTING THIS NEW CODE
- if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
+ if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
{
- if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
+ bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
+ bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
+ if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
{
- if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
+ // Convert the enum to an int instead for these operators
+ if(op1IsEnum && exp.op.exp2.expType)
{
- if(exp.expType) FreeType(exp.expType);
- exp.expType = exp.op.exp1.expType;
- if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
- valid = true;
+ if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
+ {
+ if(exp.expType) FreeType(exp.expType);
+ exp.expType = exp.op.exp2.expType;
+ if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
+ valid = true;
+ }
+ }
+ else if(op2IsEnum && exp.op.exp1.expType)
+ {
+ if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
+ {
+ if(exp.expType) FreeType(exp.expType);
+ exp.expType = exp.op.exp1.expType;
+ if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
+ valid = true;
+ }
}
}
-
- else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
+ else
{
- if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
+ if(op1IsEnum && exp.op.exp2.expType)
{
- if(exp.expType) FreeType(exp.expType);
- exp.expType = exp.op.exp2.expType;
- if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
- valid = true;
+ if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
+ {
+ if(exp.expType) FreeType(exp.expType);
+ exp.expType = exp.op.exp1.expType;
+ if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
+ valid = true;
+ }
+ }
+ else if(op2IsEnum && exp.op.exp1.expType)
+ {
+ if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
+ {
+ if(exp.expType) FreeType(exp.expType);
+ exp.expType = exp.op.exp2.expType;
+ if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
+ valid = true;
+ }
}
}
}
if(!valid)
{
- if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
- exp.op.exp2.destType = type1;
- type1.refCount++;
+ // Added this first part of the if here to handle 5 + Degrees { 5 } with either a base unit dest or not a unit dest type
+ if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
+ (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
+ {
+ if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
+ exp.op.exp1.destType = type2;
+ type2.refCount++;
+
+ if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
+ {
+ if(exp.expType) FreeType(exp.expType);
+ exp.expType = exp.op.exp1.destType;
+ if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
+ }
+ }
+ else
+ {
+ if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
+ exp.op.exp2.destType = type1;
+ type1.refCount++;
/*
// Maybe this was meant to be an enum...
if(type2._class.registered.dataType)
type2._class.registered.dataType.refCount++;
CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
-
+
//exp.expType = type2._class.registered.dataType; //type2;
//if(type2) type2.refCount++;
}
}
*/
- if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
- {
- if(exp.expType) FreeType(exp.expType);
- exp.expType = exp.op.exp2.destType;
- if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
- }
- else if(type1 && type2)
- {
- char expString1[10240];
- char expString2[10240];
- char type1String[1024];
- char type2String[1024];
- expString1[0] = '\0';
- expString2[0] = '\0';
- type1String[0] = '\0';
- type2String[0] = '\0';
- if(inCompiler)
+ if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
{
- PrintExpression(exp.op.exp1, expString1);
- ChangeCh(expString1, '\n', ' ');
- PrintExpression(exp.op.exp2, expString2);
- ChangeCh(expString2, '\n', ' ');
- PrintType(exp.op.exp1.expType, type1String, false, true);
- PrintType(exp.op.exp2.expType, type2String, false, true);
+ if(exp.expType) FreeType(exp.expType);
+ exp.expType = exp.op.exp2.destType;
+ if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
}
+ else if(type1 && type2)
+ {
+ char expString1[10240];
+ char expString2[10240];
+ char type1String[1024];
+ char type2String[1024];
+ expString1[0] = '\0';
+ expString2[0] = '\0';
+ type1String[0] = '\0';
+ type2String[0] = '\0';
+ if(inCompiler)
+ {
+ PrintExpression(exp.op.exp1, expString1);
+ ChangeCh(expString1, '\n', ' ');
+ PrintExpression(exp.op.exp2, expString2);
+ ChangeCh(expString2, '\n', ' ');
+ PrintType(exp.op.exp1.expType, type1String, false, true);
+ PrintType(exp.op.exp2.expType, type2String, false, true);
+ }
- Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
+ Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
- if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
- {
- exp.expType = exp.op.exp1.expType;
- if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
- }
- else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
- {
- exp.expType = exp.op.exp2.expType;
- if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
+ if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
+ {
+ exp.expType = exp.op.exp1.expType;
+ if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
+ }
+ else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
+ {
+ exp.expType = exp.op.exp2.expType;
+ if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
+ }
}
}
}
{
Type oldType = exp.op.exp1.expType;
exp.op.exp1.expType = null;
- if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
+ if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
FreeType(oldType);
else
exp.op.exp1.expType = oldType;
}
*/
- if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
+ if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
{
if(exp.expType) FreeType(exp.expType);
exp.expType = exp.op.exp1.destType;
exp.op.exp1.destType = type2._class.registered.dataType;
if(type2._class.registered.dataType)
type2._class.registered.dataType.refCount++;
- CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
+ CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
}
if(exp.op.op == '!')
{
exp.op.exp2.destType = type1._class.registered.dataType;
if(type1._class.registered.dataType)
type1._class.registered.dataType.refCount++;
- CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
+ CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
}
exp.expType = type1;
if(type1) type1.refCount++;
}
}
-
+
yylloc = exp.loc;
if(exp.op.exp1 && !exp.op.exp1.expType)
{
yylloc = oldyylloc;
FreeType(dummy);
+ if(type2)
+ FreeType(type2);
break;
}
case bracketsExp:
if(!e.next)
{
FreeType(e.destType);
+ e.opDestType = exp.opDestType;
e.destType = exp.destType;
if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
}
FreeType(exp.expType);
FreeType(exp.destType);
delete exp.list;
-
+
*exp = *e;
exp.prev = prev;
if(exp.index.exp.expType)
{
Type source = exp.index.exp.expType;
- if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
- eClass_IsDerived(source._class.registered, containerClass) &&
- source._class.registered.templateArgs)
+ if(source.kind == classType && source._class && source._class.registered)
{
Class _class = source._class.registered;
- exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
-
- if(exp.index.index && exp.index.index->last)
+ Class c = _class.templateClass ? _class.templateClass : _class;
+ if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
{
- ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
+ exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
+
+ if(exp.index.index && exp.index.index->last)
+ {
+ Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
+
+ if(type.kind == classType) type.constant = true;
+ else if(type.kind == pointerType)
+ {
+ Type t = type;
+ while(t.kind == pointerType) t = t.type;
+ t.constant = true;
+ }
+
+ ((Expression)exp.index.index->last).destType = type;
+ }
}
}
}
{
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)
a = exp.call.arguments->first;
tempExp1 = a;
}
-
+
if(a)
{
exp.call.arguments->Clear();
if(b.expType)
b.expType.refCount++;
ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
- }
+ }
decl = MkDeclaration(specs, decls);
if(!curCompound.compound.declarations)
if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
{
int op = (!strcmp(id.string, "Max")) ? '>' : '<';
- ListAdd(exp.list,
+ ListAdd(exp.list,
MkExpCondition(MkExpBrackets(MkListOne(
MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
}
else if(!strcmp(id.string, "Abs"))
{
- ListAdd(exp.list,
+ ListAdd(exp.list,
MkExpCondition(MkExpBrackets(MkListOne(
MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
else if(!strcmp(id.string, "Sgn"))
{
// ((!(a))?(0):(((a)<0)?(-1):(1)))
- ListAdd(exp.list,
+ ListAdd(exp.list,
MkExpCondition(MkExpBrackets(MkListOne(
MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
{
methodType = functionType;
functionType = methodType.method.dataType;
-
+
//if(functionType.returnType && functionType.returnType.kind == thisClassType)
// TOCHECK: Instead of doing this here could this be done per param?
if(exp.call.exp.expType.usedClass)
{
char typeString[1024];
typeString[0] = '\0';
- PrintType(functionType, typeString, true, true);
+ {
+ Symbol back = functionType.thisClass;
+ // Do not output class specifier here (thisclass was added to this)
+ functionType.thisClass = null;
+ PrintType(functionType, typeString, true, true);
+ functionType.thisClass = back;
+ }
if(strstr(typeString, "thisclass"))
{
OldList * specs = MkList();
Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
decl = SpecDeclFromString(typeString, specs, null);
-
+
// SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
exp.call.exp.expType.usedClass))
thisClassParams = false;
-
+
ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
{
Class backupThisClass = thisClass;
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;
}
// WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
- if(!functionType.staticMethod)
+ // Fixed #141 by adding '&& !functionType.extraParam'
+ if(!functionType.staticMethod && !functionType.extraParam)
{
- if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
+ if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
memberExp.member.exp.expType._class)
{
type = MkClassType(memberExp.member.exp.expType._class.string);
else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
{
type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
+ type.byReference = functionType.byReference;
+ type.typedByReference = functionType.typedByReference;
if(e)
{
+ // Allow manually passing a class for typed object
+ if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
+ e = e.next;
e.destType = type;
e = e.next;
type = functionType.params.first;
}
if(curParam && _class.templateArgs[id].dataTypeString)
{
+ bool constant = type.constant;
ClassTemplateArgument arg = _class.templateArgs[id];
{
Context context = SetupTemplatesContext(_class);
-
+
/*if(!arg.dataType)
arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
templatedType = ProcessTypeString(arg.dataTypeString, false);
FinishTemplatesContext(context);
}
+
+ if(templatedType.kind == classType && constant) templatedType.constant = true;
+ else if(templatedType.kind == pointerType)
+ {
+ Type t = templatedType.type;
+ while(t.kind == pointerType) t = t.type;
+ if(constant) t.constant = constant;
+ }
+
e.destType = templatedType;
if(templatedType)
{
}
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)
Location oldyylloc = yylloc;
yylloc = exp.call.exp.identifier.loc;
- if(strstr(string, "__builtin_") == string);
+ if(strstr(string, "__builtin_") == string)
+ {
+ if(exp.destType)
+ {
+ functionType.returnType = exp.destType;
+ exp.destType.refCount++;
+ }
+ }
else
Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
{
Type type;
Location oldyylloc = yylloc;
- bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
+ bool thisPtr;
+ Expression checkExp = exp.member.exp;
+ while(checkExp)
+ {
+ if(checkExp.type == castExp)
+ checkExp = checkExp.cast.exp;
+ else if(checkExp.type == bracketsExp)
+ checkExp = checkExp.list ? checkExp.list->first : null;
+ else
+ break;
+ }
+
+ thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
exp.thisPtr = thisPtr;
// DOING THIS LATER NOW...
}
ProcessExpressionType(exp.member.exp);
- if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
+ if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
{
exp.isConstant = false;
int c;
int paramCount = 0;
int lastParam = -1;
-
+
char templateString[1024];
ClassTemplateParameter param;
sprintf(templateString, "%s<", expClass.templateClass.fullName);
int p = 0;
Class nextClass;
for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
-
+
for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
{
if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
Expression exp;
char * string = PrintHexUInt64(arg.expression.ui64);
exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
+ delete string;
ProcessExpressionType(exp);
ComputeExpression(exp);
lastParam = p;
}
p++;
- }
+ }
}
}
{
FreeType(exp.expType);
exp.expType = ProcessTypeString(templateString, false);
FinishTemplatesContext(context);
- }
+ }
}
// *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
MkExpBrackets(MkListOne(
MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
- '+',
- MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
+ '+',
+ MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
'+',
MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
-
+
));
}
}
- else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
+ else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
(type.templateParameter.dataType || type.templateParameter.dataTypeString))
{
type = ProcessTemplateParameterType(type.templateParameter);
}
}
-
+ // TODO: *** This seems to be where we should add method support for all basic types ***
if(type && (type.kind == templateType));
- else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
+ else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
+ type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
+ type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
+ (type.kind == pointerType && type.type.kind == charType)))
{
Identifier id = exp.member.member;
TypeKind typeKind = type.kind;
typeKind = classType;
}
- if(id && (typeKind == intType || typeKind == enumType))
- _class = eSystem_FindClass(privateModule, "int");
+ if(id)
+ {
+ if(typeKind == intType || typeKind == enumType)
+ _class = eSystem_FindClass(privateModule, "int");
+ else if(!_class)
+ {
+ if(type.kind == classType && type._class && type._class.registered)
+ {
+ _class = type._class.registered;
+ }
+ else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
+ {
+ _class = FindClass("char *").registered;
+ }
+ else if(type.kind == pointerType)
+ {
+ _class = eSystem_FindClass(privateModule, "uintptr");
+ FreeType(exp.expType);
+ exp.expType = ProcessTypeString("uintptr", false);
+ exp.byReference = true;
+ }
+ else
+ {
+ char string[1024] = "";
+ Symbol classSym;
+ PrintTypeNoConst(type, string, false, true);
+ classSym = FindClass(string);
+ if(classSym) _class = classSym.registered;
+ }
+ }
+ }
if(_class && id)
{
- /*bool thisPtr =
- (exp.member.exp.type == identifierExp &&
+ /*bool thisPtr =
+ (exp.member.exp.type == identifierExp &&
!strcmp(exp.member.exp.identifier.string, "this"));*/
Property prop = null;
Method method = null;
// Prioritize properties over data members otherwise
else
{
+ bool useMemberForNonConst = false;
// First look for Public Members (Unless class specifier is provided, which skips public priority)
if(!id.classSym)
{
prop = eClass_FindProperty(_class, id.string, null);
- if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
+
+ useMemberForNonConst = prop && exp.destType &&
+ ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
+ !strncmp(prop.dataTypeString, "const ", 6);
+
+ if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
member = eClass_FindDataMember(_class, id.string, null, null, null);
}
- if(!prop && !member)
+ if((!prop || useMemberForNonConst) && !member)
{
- method = eClass_FindMethod(_class, id.string, null);
+ method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
if(!method)
{
prop = eClass_FindProperty(_class, id.string, privateModule);
- if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
+
+ useMemberForNonConst |= prop && exp.destType &&
+ ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
+ !strncmp(prop.dataTypeString, "const ", 6);
+
+ if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
}
}
if(member && prop)
{
- if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
+ if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
prop = null;
else
member = null;
}
}
}
- if(!prop && !member)
+ if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
method = eClass_FindMethod(_class, id.string, privateModule);
if(!prop && !member && !method)
{
FreeType(classExp.expType);
classExp.expType = ProcessTypeString("ecere::com::Class", false);
-
+
strcpy(structName, "__ecereClassData_");
FullClassNameCat(structName, type._class.string, false);
exp.type = pointerExp;
exp.member.member = id;
exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
- MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
+ MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
MkExpBrackets(MkListOne(MkExpOp(
- MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
+ MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
MkExpMember(classExp, MkIdentifier("data"))), '+',
MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
)));
}
}
}
-
+
if(prop)
{
exp.member.memberType = propertyMember;
if(!prop.dataType)
ProcessPropertyType(prop);
- exp.expType = prop.dataType;
+ exp.expType = prop.dataType;
if(prop.dataType) prop.dataType.refCount++;
}
else if(member)
}
else if(method)
{
- if(inCompiler)
+ //if(inCompiler)
{
/*if(id._class)
{
FreeExpContents(exp);
exp.type = identifierExp;
exp.identifier = MkIdentifier("class");
- ProcessExpressionType(exp);
+ FreeType(exp.expType);
+ exp.expType = MkClassType("ecere::com::Class");
return;
}
yylloc = exp.member.member.loc;
{
ClassTemplateArgument arg = tClass.templateArgs[id];
Context context = SetupTemplatesContext(tClass);
+ bool constant = exp.expType.constant;
/*if(!arg.dataType)
arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
FreeType(exp.expType);
+
exp.expType = ProcessTypeString(arg.dataTypeString, false);
+ if(exp.expType.kind == classType && constant) exp.expType.constant = true;
+ else if(exp.expType.kind == pointerType)
+ {
+ Type t = exp.expType.type;
+ while(t.kind == pointerType) t = t.type;
+ if(constant) t.constant = constant;
+ }
if(exp.expType)
{
if(exp.expType.kind == thisClassType)
if(!exp.destType)
{
exp.destType = ProcessTypeString(arg.dataTypeString, false);
+ if(exp.destType.kind == classType && constant) exp.destType.constant = true;
+ else if(exp.destType.kind == pointerType)
+ {
+ Type t = exp.destType.type;
+ while(t.kind == pointerType) t = t.type;
+ if(constant) t.constant = constant;
+ }
+
//exp.destType.refCount++;
if(exp.destType.kind == thisClassType)
if(sClass.templateClass) sClass = sClass.templateClass;
for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
{
- if(curParam.type == TemplateParameterType::type &&
+ if(curParam.type == TemplateParameterType::type &&
!strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
{
for(sClass = sClass.base; sClass; sClass = sClass.base)
Type basicType;
/*if(!arg.dataType)
arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
-
+
basicType = ProcessTypeString(arg.dataTypeString, false);
if(basicType)
{
if(tClass.templateClass)
basicType.passAsTemplate = true;
*/
-
+
FreeType(exp.expType);
exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
{
if(!strcmp(paramCur.name, param.name))
{
-
+
break;
}
cp++;
Expression exp;
char * string = PrintHexUInt64(arg.expression.ui64);
exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
+ delete string;
ProcessExpressionType(exp);
ComputeExpression(exp);
{
strcat(templateString, param.name);
strcat(templateString, " = ");
- }
+ }
strcat(templateString, argument);
paramCount++;
lastParam = p;
memberType.refCount++;
}
}
- else
+ else
{
char expString[10240];
expString[0] = '\0';
exp.expType = ReplaceThisClassType(_class);
}
}
- }
+ }
yylloc = oldyylloc;
break;
}
exp.expType = Type
{
refCount = 1;
- kind = intType;
+ kind = intSizeType;
};
// exp.isConstant = true;
break;
exp.expType = Type
{
refCount = 1;
- kind = intType;
+ kind = intSizeType;
};
exp.isConstant = true;
FreeType(exp.cast.exp.destType);
exp.cast.exp.destType = type;
type.refCount++;
+ type.casted = true;
ProcessExpressionType(exp.cast.exp);
+ type.casted = false;
type.count = 0;
exp.expType = type;
//type.refCount++;
-
+
// if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
{
//FreeType(exp.destType);
FreeType(exp.expType);
FreeTypeName(exp.cast.typeName);
-
+
*exp = *castExp;
FreeType(exp.expType);
FreeType(exp.destType);
case extensionInitializerExp:
{
Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
- type.refCount++;
-
// We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
// ProcessInitializer(exp.initializer.initializer, type);
exp.expType = type;
{
Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
ProcessExpressionType(exp.vaArg.exp);
- type.refCount++;
exp.expType = type;
break;
}
exp.destType.refCount++;
}
ProcessStatement(exp.compound);
- exp.expType = ((Expression)last.expressions->last).expType;
- if(((Expression)last.expressions->last).expType)
+ exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
+ if(exp.expType)
exp.expType.refCount++;
}
break;
classExp = MkExpIdentifier(MkIdentifier("class"));
exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
- MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
+ MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
MkExpBrackets(MkListOne(MkExpOp(
- MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
+ MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
MkExpMember(classExp, MkIdentifier("data"))), '+',
MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
)));
case arrayExp:
{
Type type = null;
- char * typeString = null;
+ const char * typeString = null;
char typeStringBuf[1024];
if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
else
{
// if(!MatchType(e.expType, type, null, null, null, false, false, false))
- if(!MatchTypeExpression(e, type, null, false))
+ if(!MatchTypeExpression(e, type, null, false, true))
{
FreeType(type);
type = e.expType;
e.expType = null;
-
+
e = exp.list->first;
ProcessExpressionType(e);
if(e.expType)
{
//if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
- if(!MatchTypeExpression(e, type, null, false))
+ if(!MatchTypeExpression(e, type, null, false, true))
{
FreeType(e.expType);
e.expType = null;
FreeType(type);
type = null;
break;
- }
+ }
}
}
}
if(type)
{
typeStringBuf[0] = '\0';
- PrintType(type, typeStringBuf, false, true);
+ PrintTypeNoConst(type, typeStringBuf, false, true);
typeString = typeStringBuf;
FreeType(type);
type = null;
FreeType(type);
delete exp.list;
}
-
+
DeclareStruct("ecere::com::BuiltInContainer", false);
ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
else if(exp.destType && !exp.destType.keepCast)
{
- if(!CheckExpressionType(exp, exp.destType, false))
+ if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
{
if(!exp.destType.count || unresolved)
{
//CheckExpressionType(exp, exp.destType, false);
if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
- exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
+ exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
(exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
else
{
if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
#ifdef _DEBUG
- CheckExpressionType(exp, exp.destType, false);
+ CheckExpressionType(exp, exp.destType, false, true);
#endif
// Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
PrintType(exp.expType, typeString, false, false);
decl = SpecDeclFromString(typeString, specs, null);
-
+
exp.cast.typeName = MkTypeName(specs, decl);
exp.cast.exp = newExp;
}
}
// Let's try to support any_object & typed_object here:
- ApplyAnyObjectLogic(exp);
+ if(inCompiler)
+ ApplyAnyObjectLogic(exp);
+ // Mark nohead classes as by reference, unless we're casting them to an integral type
if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
- exp.expType._class.registered.type == noHeadClass)
+ exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
+ (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
+ exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
{
exp.byReference = true;
}
- /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
- exp.destType._class.registered.type == noHeadClass)
- {
- exp.byReference = true;
- }*/
yylloc = oldyylloc;
}
static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
{
// THIS CODE WILL FIND NEXT MEMBER...
- if(*curMember)
+ if(*curMember)
{
*curMember = (*curMember).next;
*curMember = (*curMember).members.first;
while(*curMember && (*curMember).isProperty)
- *curMember = (*curMember).next;
+ *curMember = (*curMember).next;
}
}
}
*curMember = (*curMember).members.first;
while(*curMember && (*curMember).isProperty)
- *curMember = (*curMember).next;
+ *curMember = (*curMember).next;
}
}
}
declarator = null;
};
if(!decl.function.parameters)
- decl.function.parameters = MkList();
+ decl.function.parameters = MkList();
decl.function.parameters->Insert(null, param);
id._class = null;
}
if(decl.function.parameters)
{
TypeName param;
-
+
for(param = decl.function.parameters->first; param; param = param.next)
{
if(param.qualifiers && param.qualifiers->first)
qualifiers = MkListOne(MkSpecifier(VOID));
declarator = MkDeclaratorPointer(MkPointer(null,null), d);
};
-
+ if(d.type != pointerDeclarator)
+ newParam.qualifiers->Insert(null, MkSpecifier(CONST));
+
FreeList(param.qualifiers, FreeSpecifier);
param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
else if(spec && spec.specifier == ANY_OBJECT)
{
Declarator d = param.declarator;
-
+
FreeList(param.qualifiers, FreeSpecifier);
param.qualifiers = MkListOne(MkSpecifier(VOID));
- param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
+ if(d.type != pointerDeclarator)
+ param.qualifiers->Insert(null, MkSpecifier(CONST));
+ param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
}
else if(spec.specifier == THISCLASS)
{
if(decl.declarators)
{
InitDeclarator d;
-
+
for(d = decl.declarators->first; d; d = d.next)
{
Type type, subType;
{
ProcessInitializer(d.initializer, type);
- // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
-
+ // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
+
if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
d.initializer.exp.type == instanceExp)
{
- if(type.kind == classType && type._class ==
+ if(type.kind == classType && type._class ==
d.initializer.exp.expType._class)
{
Instantiation inst = d.initializer.exp.instance;
inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
-
+
d.initializer.exp.instance = null;
if(decl.specifiers)
FreeList(decl.specifiers, FreeSpecifier);
ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
}
-
+
{
args = MkList();
ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
}
-
- if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
+
+ if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
(!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
curFunction.propSet.fireWatchersDone = true;
}
Context prevContext = curContext;
if(!stmt.compound.isSwitch)
- {
curCompound = stmt;
- curContext = stmt.compound.context;
- }
+ curContext = stmt.compound.context;
if(stmt.compound.declarations)
{
char iteratorType[1024];
Type source;
Expression e;
- bool isBuiltin = exp && exp->last &&
- (((Expression)exp->last).type == ExpressionType::arrayExp ||
+ bool isBuiltin = exp && exp->last &&
+ (((Expression)exp->last).type == ExpressionType::arrayExp ||
(((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
Expression arrayExp;
- char * typeString = null;
+ const char * typeString = null;
int builtinCount = 0;
for(e = exp ? exp->first : null; e; e = e.next)
Class _class = source ? source._class.registered : null;
Symbol symbol;
Expression expIt = null;
- bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
+ bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
Class arrayClass = eSystem_FindClass(privateModule, "Array");
Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
stmt.type = compoundStmt;
-
+
stmt.compound.context = Context { };
stmt.compound.context.parent = curContext;
curContext = stmt.compound.context;
if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
{
Class mapClass = eSystem_FindClass(privateModule, "Map");
- Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
+ //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
isCustomAVLTree = true;
- if(eClass_IsDerived(source._class.registered, avlTreeClass))
+ /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
isAVLTree = true;
- else if(eClass_IsDerived(source._class.registered, mapClass))
+ else */if(eClass_IsDerived(source._class.registered, mapClass))
isMap = true;
}
else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
- else if(source && eClass_IsDerived(source._class.registered, linkListClass))
+ else if(source && eClass_IsDerived(source._class.registered, linkListClass))
{
Class listClass = eSystem_FindClass(privateModule, "List");
isLinkList = true;
{
Declarator decl;
OldList * specs = MkList();
- decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
+ decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
stmt.compound.declarations = MkListOne(
MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
- MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
+ MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
MkInitializerAssignment(MkExpBrackets(exp))))));
}
else if(isBuiltin)
{
Type type = null;
char typeStringBuf[1024];
-
+
// TODO: Merge this code?
arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
if(((Expression)exp->last).type == castExp)
else
{
// if(!MatchType(e.expType, type, null, null, null, false, false, false))
- if(!MatchTypeExpression(e, type, null, false))
+ if(!MatchTypeExpression(e, type, null, false, true))
{
FreeType(type);
type = e.expType;
e.expType = null;
-
+
e = arrayExp.list->first;
ProcessExpressionType(e);
if(e.expType)
{
//if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
- if(!MatchTypeExpression(e, type, null, false))
+ if(!MatchTypeExpression(e, type, null, false, true))
{
FreeType(e.expType);
e.expType = null;
FreeType(type);
type = null;
break;
- }
+ }
}
}
}
delete arrayExp.list;
}
decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
- stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
+ stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
- ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
- /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
-
+ ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
+ PlugDeclarator(
+ /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
+ ), MkInitializerList(initializers)))));
FreeList(exp, FreeExpression);
}
else
Declarator decl;
OldList * specs = MkList();
- decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
+ decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
stmt.compound.declarations = MkListOne(
MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
- MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
+ MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
MkInitializerAssignment(MkExpBrackets(exp))))));
*/
}
decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
- MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
+ MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
MkInitializerAssignment(MkExpBrackets(exp))))));
}
/*else if(isCustomAVLTree)
decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
- MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
+ MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
MkInitializerAssignment(MkExpBrackets(exp))))));
}*/
else if(_class.templateArgs)
stmt.compound.declarations = MkListOne(
MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
- MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
+ MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
MkInitializerAssignment(MkExpBrackets(exp)))))))));
}
symbol = FindSymbol(id.string, curContext, curContext, false, false);
- if(block && block.type == compoundStmt && block.compound.context)
+ if(block)
{
- block.compound.context.parent = stmt.compound.context;
+ // Reparent sub-contexts in this statement
+ switch(block.type)
+ {
+ case compoundStmt:
+ if(block.compound.context)
+ block.compound.context.parent = stmt.compound.context;
+ break;
+ case ifStmt:
+ if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
+ block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
+ if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
+ block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
+ break;
+ case switchStmt:
+ if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
+ block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
+ break;
+ case whileStmt:
+ if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
+ block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
+ break;
+ case doWhileStmt:
+ if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
+ block.doWhile.stmt.compound.context.parent = stmt.compound.context;
+ break;
+ case forStmt:
+ if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
+ block.forStmt.stmt.compound.context.parent = stmt.compound.context;
+ break;
+ case forEachStmt:
+ if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
+ block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
+ break;
+ /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
+ case labeledStmt:
+ case caseStmt
+ case expressionStmt:
+ case gotoStmt:
+ case continueStmt:
+ case breakStmt
+ case returnStmt:
+ case asmStmt:
+ case badDeclarationStmt:
+ case fireWatchersStmt:
+ case stopWatchingStmt:
+ case watchStmt:
+ */
+ }
}
if(filter)
{
{
stmt.compound.statements = MkListOne(MkForStmt(
MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
- MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
+ MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
block));
stmt.compound.statements = MkListOne(MkForStmt(
MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
- MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
+ MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
block));
Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
stmt.compound.statements = MkListOne(MkForStmt(
MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
- MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
+ MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
block));
{
Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
- if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
+ if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
!strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
{
stmt.compound.statements = MkListOne(MkForStmt(
if(stmt.compound.declarations->first)
ProcessDeclaration(stmt.compound.declarations->first);
- if(symbol)
+ if(symbol)
symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
ProcessStatement(stmt);
{
ClassFunction func;
char watcherName[1024];
- Class watcherClass = watcher ?
+ Class watcherClass = watcher ?
((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
External createdExternal;
// Create a declaration above
{
- Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
+ Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
externalDecl.declaration = decl;
if(decl.symbol && !decl.symbol.pointerExternal)
char getName[1024], setName[1024];
OldList * args = MkList();
- DeclareProperty(prop, setName, getName);
-
+ DeclareProperty(prop, setName, getName);
+
// eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
strcpy(propName, "__ecereProp_");
FullClassNameCat(propName, prop._class.fullName, false);
ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
}
else
- Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
+ Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
}
}
}
if(inCompiler)
{
- _class = object ?
+ _class = object ?
((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
if(_class)
if(!watches)
{
OldList * args;
- // eInstance_StopWatching(object, null, watcher);
+ // eInstance_StopWatching(object, null, watcher);
args = MkList();
ListAdd(args, CopyExpression(object));
ListAdd(args, MkExpConstant("0"));
OldList * args = MkList();
DeclareProperty(prop, setName, getName);
-
- // eInstance_StopWatching(object, prop, watcher);
+
+ // eInstance_StopWatching(object, prop, watcher);
strcpy(propName, "__ecereProp_");
FullClassNameCat(propName, prop._class.fullName, false);
strcat(propName, "_");
ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
}
else
- Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
+ Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
}
}
yylloc = function.loc;
// Process thisClass
-
+
if(type && type.thisClass)
{
Symbol classSym = type.thisClass;
FullClassNameCat(structName, _class.fullName, false);
// [class] this
-
+
funcDecl = GetFuncDecl(function.declarator);
if(funcDecl)
// DANGER: Watch for this... Check if it's a Conversion?
// if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
-
+
// WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
if(!function.propertyNoThis)
{
TypeName thisParam;
-
+
if(type.classObjectType != classPointer)
{
thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
funcDecl.function.parameters->Insert(null, thisParam);
}
}
- }
+ }
}
}
-
+
// Add this to the context
if(function.body)
{
{
thisSymbol.type.classObjectType = ClassObjectType::typedObject;
thisSymbol.type.byReference = type.byReference;
+ thisSymbol.type.typedByReference = type.byReference;
/*
thisSymbol = Symbol { string = CopyString("class") };
function.body.compound.context.symbols.Add(thisSymbol);
}
// Pointer to class data
-
+
if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
{
DataMember member = null;
if(member)
{
char pointerName[1024];
-
+
Declaration decl;
Initializer initializer;
Expression exp, bytePtr;
-
+
strcpy(pointerName, "__ecerePointer_");
FullClassNameCat(pointerName, _class.fullName, false);
{
kind = pointerType;
type = Type { refCount = 1, kind = voidType };
};
-
+
if(function.body)
{
yylloc = function.body.loc;
}
}
}
-
+
// Loop through the function and replace undeclared identifiers
// which are a member of the class (methods, properties or data)
type = regClass ? MkClassType(regClass.fullName) : null;
};
globalContext.symbols.Add((BTNode)thisSymbol);
-
+
for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
{
thisClass = regClass;
Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
globalContext.symbols.Add(thisSymbol);
*/
-
+
thisClass = regClass;
if(prop.setStmt)
{
else if(def.type == propertyWatchClassDef && def.propertyWatch)
{
PropertyWatch propertyWatch = def.propertyWatch;
-
+
thisClass = regClass;
if(propertyWatch.compound)
{
}
}
+void DeclareFunctionUtil(const 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("eSystem_Delete");
+ DeclareFunctionUtil("eClass_GetProperty");
+ DeclareFunctionUtil("eClass_SetProperty");
+ DeclareFunctionUtil("eInstance_FireSelfWatchers");
+ DeclareFunctionUtil("eInstance_SetMethod");
+ DeclareFunctionUtil("eInstance_IncRef");
+ DeclareFunctionUtil("eInstance_StopWatching");
+ DeclareFunctionUtil("eInstance_Watch");
+ DeclareFunctionUtil("eInstance_FireWatchers");
+
DeclareStruct("ecere::com::Class", false);
DeclareStruct("ecere::com::Instance", false);
DeclareStruct("ecere::com::Property", false);
else if(external.type == declarationExternal)
{
currentClass = null;
- ProcessDeclaration(external.declaration);
+ if(external.declaration)
+ ProcessDeclaration(external.declaration);
}
else if(external.type == classExternal)
{
}
currentClass = null;
thisNameSpace = null;
+ curExternal = null;
delete temp.symbol;
delete temp;