4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
38 Time findSymbolTotalTime;
41 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
42 /*static */public void PrintExpression(Expression exp, char * string)
50 OutputExpression(exp, f);
52 count = strlen(string);
53 count += f.Read(string + count, 1, 1023);
59 int64 _strtoi64(char * string, char ** endString, int base)
65 for(c = 0; (ch = string[c]) && isspace(ch); c++);
67 else if(ch == '-') { sign = -1; c++; };
70 if(ch == 0 && string[c+1] == 'x')
83 for( ;(ch = string[c]); c++)
87 else if(ch >= '1' && ch <= '9')
89 else if(ch >= 'a' && ch <= 'z')
91 else if(ch >= 'A' && ch <= 'Z')
95 *endString = string + c;
106 *endString = string + c;
114 uint64 _strtoui64(char * string, char ** endString, int base)
120 for(c = 0; (ch = string[c]) && isspace(ch); c++);
122 else if(ch == '-') { sign = -1; c++; };
125 if(ch == 0 && string[c+1] == 'x')
138 for( ;(ch = string[c]); c++)
142 else if(ch >= '1' && ch <= '9')
144 else if(ch >= 'a' && ch <= 'z')
146 else if(ch >= 'A' && ch <= 'Z')
150 if(endString) *endString = string + c;
162 *endString = string + c;
170 Type ProcessTemplateParameterType(TemplateParameter param)
172 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
174 // TOFIX: Will need to free this Type
177 if(param.dataTypeString)
178 param.baseType = ProcessTypeString(param.dataTypeString, false);
180 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
182 return param.baseType;
187 bool NeedCast(Type type1, Type type2)
189 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
191 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
196 if(type1.kind == type2.kind)
204 if(type1.passAsTemplate && !type2.passAsTemplate)
206 return type1.isSigned != type2.isSigned;
208 return type1._class != type2._class;
210 return NeedCast(type1.type, type2.type);
212 return true; //false; ????
218 static void ReplaceClassMembers(Expression exp, Class _class)
220 if(exp.type == identifierExp && exp.identifier)
222 Identifier id = exp.identifier;
224 Symbol symbol = null;
225 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
227 // First, check if the identifier is declared inside the function
228 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
230 symbol = (Symbol)ctx.symbols.FindString(id.string);
235 // If it is not, check if it is a member of the _class
236 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
238 Property prop = eClass_FindProperty(_class, id.string, privateModule);
239 Method method = null;
240 DataMember member = null;
241 ClassProperty classProp;
244 method = eClass_FindMethod(_class, id.string, privateModule);
247 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
248 if(!prop && !method && !member)
250 classProp = eClass_FindClassProperty(_class, id.string);
252 if(prop || method || member || classProp)
254 // Replace by this.[member]
255 exp.type = memberExp;
256 exp.member.member = id;
257 exp.member.memberType = unresolvedMember;
258 exp.member.exp = QMkExpId("this");
259 //exp.member.exp.loc = exp.loc;
260 exp.addedThis = true;
262 else if(_class && _class.templateParams.first)
265 for(sClass = _class; sClass; sClass = sClass.base)
267 if(sClass.templateParams.first)
269 ClassTemplateParameter param;
270 for(param = sClass.templateParams.first; param; param = param.next)
272 if(param.type == expression && !strcmp(param.name, id.string))
274 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
279 OldList * specs = MkList();
281 FreeIdentifier(exp.member.member);
283 ProcessExpressionType(argExp);
285 decl = SpecDeclFromString(param.dataTypeString, specs, null);
287 exp.expType = ProcessType(specs, decl);
289 // *[expType] *[argExp]
290 exp.type = bracketsExp;
291 exp.list = MkListOne(MkExpOp(null, '*',
292 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
303 ////////////////////////////////////////////////////////////////////////
304 // PRINTING ////////////////////////////////////////////////////////////
305 ////////////////////////////////////////////////////////////////////////
307 public char * PrintInt(int64 result)
310 if(result > MAXINT64)
311 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
313 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
314 return CopyString(temp);
317 public char * PrintUInt(uint64 result)
320 if(result > MAXDWORD)
321 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
322 else if(result > MAXINT)
323 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
325 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
326 return CopyString(temp);
329 public char * PrintInt64(int64 result)
332 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
333 return CopyString(temp);
336 public char * PrintUInt64(uint64 result)
339 if(result > MAXINT64)
340 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
342 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
343 return CopyString(temp);
346 public char * PrintHexUInt(uint64 result)
349 if(result > MAXDWORD)
350 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
352 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
353 return CopyString(temp);
356 public char * PrintHexUInt64(uint64 result)
359 if(result > MAXDWORD)
360 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
362 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
363 return CopyString(temp);
366 public char * PrintShort(short result)
369 sprintf(temp, "%d", (unsigned short)result);
370 return CopyString(temp);
373 public char * PrintUShort(unsigned short result)
377 sprintf(temp, "0x%X", (int)result);
379 sprintf(temp, "%d", result);
380 return CopyString(temp);
383 public char * PrintChar(char result)
386 if(result > 0 && isprint(result))
387 sprintf(temp, "'%c'", result);
389 sprintf(temp, "%d", result);
391 //sprintf(temp, "%#X", result);
392 sprintf(temp, "0x%X", (unsigned char)result);
393 return CopyString(temp);
396 public char * PrintUChar(unsigned char result)
399 sprintf(temp, "0x%X", result);
400 return CopyString(temp);
403 public char * PrintFloat(float result)
406 sprintf(temp, "%.16ff", result);
407 return CopyString(temp);
410 public char * PrintDouble(double result)
413 sprintf(temp, "%.16f", result);
414 return CopyString(temp);
417 ////////////////////////////////////////////////////////////////////////
418 ////////////////////////////////////////////////////////////////////////
420 //public Operand GetOperand(Expression exp);
422 #define GETVALUE(name, t) \
423 public bool Get##name(Expression exp, t * value2) \
425 Operand op2 = GetOperand(exp); \
426 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
427 else if(op2.kind == intType) *value2 = (t) op2.ui; \
428 if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
429 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
430 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
431 else if(op2.kind == shortType) *value2 = (t) op2.us; \
432 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
433 else if(op2.kind == charType) *value2 = (t) op2.uc; \
434 else if(op2.kind == floatType) *value2 = (t) op2.f; \
435 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
436 else if(op2.kind == pointerType) *value2 = (t) op2.ui; \
443 GETVALUE(UInt, unsigned int);
444 GETVALUE(Int64, int64);
445 GETVALUE(UInt64, uint64);
446 GETVALUE(Short, short);
447 GETVALUE(UShort, unsigned short);
448 GETVALUE(Char, char);
449 GETVALUE(UChar, unsigned char);
450 GETVALUE(Float, float);
451 GETVALUE(Double, double);
453 void ComputeExpression(Expression exp);
455 void ComputeClassMembers(Class _class, bool isMember)
457 DataMember member = isMember ? (DataMember) _class : null;
458 Context context = isMember ? null : SetupTemplatesContext(_class);
459 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
460 (_class.type == bitClass || _class.structSize == _class.offset) && _class.computeSize))
463 int unionMemberOffset = 0;
466 if(!member && _class.destructionWatchOffset)
467 _class.memberOffset += sizeof(OldList);
469 // To avoid reentrancy...
470 //_class.structSize = -1;
473 DataMember dataMember;
474 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
476 if(!dataMember.isProperty)
478 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
480 /*if(dataMember.dataType)
482 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
483 /*if(!dataMember.dataType)
484 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
492 DataMember dataMember;
493 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
495 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
497 if(!isMember && _class.type == bitClass && dataMember.dataType)
499 BitMember bitMember = (BitMember) dataMember;
503 ComputeTypeSize(dataMember.dataType);
505 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
506 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
508 _class.memberOffset = bitMember.pos + bitMember.size;
509 for(d = 0; d<bitMember.size; d++)
515 bitMember.mask = mask << bitMember.pos;
517 else if(dataMember.type == normalMember && dataMember.dataType)
522 // Prevent infinite recursion
523 if(dataMember.dataType.kind != classType ||
524 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
525 _class.type != structClass)))
526 ComputeTypeSize(dataMember.dataType);
528 if(dataMember.dataType.bitFieldCount)
530 bitFields += dataMember.dataType.bitFieldCount;
537 int size = (bitFields + 7) / 8;
541 // TESTING THIS PADDING CODE
544 member.structAlignment = Max(member.structAlignment, alignment);
546 if(member.memberOffset % alignment)
547 member.memberOffset += alignment - (member.memberOffset % alignment);
550 dataMember.offset = member.memberOffset;
551 if(member.type == unionMember)
552 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
555 member.memberOffset += size;
560 // TESTING THIS PADDING CODE
563 _class.structAlignment = Max(_class.structAlignment, alignment);
565 if(_class.memberOffset % alignment)
566 _class.memberOffset += alignment - (_class.memberOffset % alignment);
569 dataMember.offset = _class.memberOffset;
570 _class.memberOffset += size;
574 size = dataMember.dataType.size;
575 alignment = dataMember.dataType.alignment;
586 // TESTING THIS PADDING CODE
589 member.structAlignment = Max(member.structAlignment, alignment);
591 if(member.memberOffset % alignment)
592 member.memberOffset += alignment - (member.memberOffset % alignment);
595 dataMember.offset = member.memberOffset;
596 if(member.type == unionMember)
597 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
600 member.memberOffset += size;
605 // TESTING THIS PADDING CODE
608 _class.structAlignment = Max(_class.structAlignment, alignment);
610 if(_class.memberOffset % alignment)
611 _class.memberOffset += alignment - (_class.memberOffset % alignment);
614 dataMember.offset = _class.memberOffset;
615 _class.memberOffset += size;
620 ComputeClassMembers((Class)dataMember, true);
624 // THERE WASN'T A MAX HERE ? member.structAlignment = dataMember.structAlignment;
625 member.structAlignment = Max(member.structAlignment, dataMember.structAlignment);
626 dataMember.offset = member.memberOffset;
627 if(member.type == unionMember)
628 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
630 member.memberOffset += dataMember.memberOffset;
634 _class.structAlignment = Max(_class.structAlignment, dataMember.structAlignment);
635 dataMember.offset = _class.memberOffset;
636 _class.memberOffset += dataMember.memberOffset;
644 int size = (bitFields + 7) / 8;
648 // TESTING THIS PADDING CODE
651 member.structAlignment = Max(member.structAlignment, alignment);
653 if(member.memberOffset % alignment)
654 member.memberOffset += alignment - (member.memberOffset % alignment);
657 if(member.type == unionMember)
658 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
661 member.memberOffset += size;
666 // TESTING THIS PADDING CODE
669 _class.structAlignment = Max(_class.structAlignment, alignment);
671 if(_class.memberOffset % alignment)
672 _class.memberOffset += alignment - (_class.memberOffset % alignment);
674 _class.memberOffset += size;
679 if(member && member.type == unionMember)
681 member.memberOffset = unionMemberOffset;
686 /*if(_class.type == structClass)
687 _class.size = _class.memberOffset;
691 if(_class.type != bitClass)
693 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset;
697 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
699 if(prop.isProperty && prop.isWatchable)
701 prop.watcherOffset = _class.structSize;
702 _class.structSize += sizeof(OldList);
710 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
712 Class deriv = derivative.data;
714 if(deriv.computeSize)
716 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
717 deriv.offset = /*_class.offset + */_class.structSize;
718 deriv.memberOffset = 0;
719 // ----------------------
721 deriv.structSize = deriv.offset;
723 ComputeClassMembers(deriv, false);
731 FinishTemplatesContext(context);
734 public void ComputeModuleClasses(Module module)
739 for(subModule = module.modules.first; subModule; subModule = subModule.next)
740 ComputeModuleClasses(subModule.data);
741 for(_class = module.classes.first; _class; _class = _class.next)
742 ComputeClassMembers(_class, false);
746 public int ComputeTypeSize(Type type)
748 uint size = type ? type.size : 0;
749 if(!size && type && !type.computing)
751 type.computing = true;
754 case charType: type.alignment = size = sizeof(char); break;
755 case intType: type.alignment = size = sizeof(int); break;
756 case int64Type: type.alignment = size = sizeof(int64); break;
757 case longType: type.alignment = size = sizeof(long); break;
758 case shortType: type.alignment = size = sizeof(short); break;
759 case floatType: type.alignment = size = sizeof(float); break;
760 case doubleType: type.alignment = size = sizeof(double); break;
763 Class _class = type._class ? type._class.registered : null;
765 if(_class && _class.type == structClass)
767 // Ensure all members are properly registered
768 ComputeClassMembers(_class, false);
769 type.alignment = _class.structAlignment;
770 size = _class.structSize;
771 if(type.alignment && size % type.alignment)
772 size += type.alignment - (size % type.alignment);
775 else if(_class && (_class.type == unitClass ||
776 _class.type == enumClass ||
777 _class.type == bitClass))
780 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
781 size = type.alignment = ComputeTypeSize(_class.dataType);
784 size = type.alignment = sizeof(Instance *);
787 case pointerType: case subClassType: size = type.alignment = sizeof(void *); break;
789 if(type.arraySizeExp)
791 ProcessExpressionType(type.arraySizeExp);
792 ComputeExpression(type.arraySizeExp);
793 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
794 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
796 Location oldLoc = yylloc;
797 // bool isConstant = type.arraySizeExp.isConstant;
798 char expression[10240];
799 expression[0] = '\0';
800 type.arraySizeExp.expType = null;
801 yylloc = type.arraySizeExp.loc;
803 PrintExpression(type.arraySizeExp, expression);
804 Compiler_Error("Array size not constant int (%s)\n", expression);
807 GetInt(type.arraySizeExp, &type.arraySize);
815 else if(type.enumClass)
817 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
819 type.arraySize = eClass_GetProperty(type.enumClass.registered, "enumSize");
826 // Unimplemented auto size
830 size = ComputeTypeSize(type.type) * type.arraySize;
831 type.alignment = type.type.alignment;
837 for(member = type.members.first; member; member = member.next)
839 uint addSize = ComputeTypeSize(member);
841 member.offset = size;
842 if(member.alignment && size % member.alignment)
843 member.offset += member.alignment - (size % member.alignment);
844 size = member.offset;
846 type.alignment = Max(type.alignment, member.alignment);
849 if(type.alignment && size % type.alignment)
850 size += type.alignment - (size % type.alignment);
856 for(member = type.members.first; member; member = member.next)
858 uint addSize = ComputeTypeSize(member);
860 member.offset = size;
861 if(member.alignment && size % member.alignment)
862 member.offset += member.alignment - (size % member.alignment);
863 size = member.offset;
865 type.alignment = Max(type.alignment, member.alignment);
866 size = Max(size, addSize);
868 if(type.alignment && size % type.alignment)
869 size += type.alignment - (size % type.alignment);
874 TemplateParameter param = type.templateParameter;
875 Type baseType = ProcessTemplateParameterType(param);
877 size = ComputeTypeSize(baseType);
879 size = sizeof(uint64);
884 size = sizeof(enum { test });
889 size = sizeof(void *);
894 type.computing = false;
900 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass)
902 // This function is in need of a major review when implementing private members etc.
903 DataMember topMember = isMember ? (DataMember) _class : null;
908 Context context = isMember ? null : SetupTemplatesContext(_class);
910 if(!isMember && _class.base)
912 maxSize = _class.structSize;
913 //if(_class.base.type != systemClass) // Commented out with new Instance _class
915 // DANGER: Testing this noHeadClass here...
916 if(_class.type == structClass || _class.type == noHeadClass)
917 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass);
919 maxSize -= _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
923 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
925 if(!member.isProperty)
931 if(member.dataTypeString)
933 OldList * specs = MkList(), * decls = MkList();
936 decl = SpecDeclFromString(member.dataTypeString, specs,
937 MkDeclaratorIdentifier(MkIdentifier(member.name)));
938 ListAdd(decls, MkStructDeclarator(decl, null));
939 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
942 member.dataType = ProcessType(specs, decl);
944 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
947 Type type = ProcessType(specs, decl);
948 DeclareType(member.dataType, false, false);
952 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
953 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
954 DeclareStruct(member.dataType._class.string, false);
957 ComputeTypeSize(member.dataType);
958 size = member.dataType.size;
959 alignment = member.dataType.alignment;
963 if(totalSize % alignment)
964 totalSize += alignment - (totalSize % alignment);
973 OldList * specs = MkList(), * list = MkList();
976 AddMembers(list, (Class)member, true, &size, topClass);
978 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
979 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
980 alignment = member.structAlignment;
984 if(totalSize % alignment)
985 totalSize += alignment - (totalSize % alignment);
995 if(topMember && topMember.type == unionMember)
996 *retSize = Max(*retSize, totalSize);
998 *retSize += totalSize;
1000 else if(totalSize < maxSize && _class.type != systemClass)
1002 char sizeString[50];
1003 sprintf(sizeString, "%d", maxSize - totalSize);
1004 ListAdd(declarations,
1005 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1006 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1009 FinishTemplatesContext(context);
1010 return topMember ? topMember.memberID : _class.memberID;
1013 static int DeclareMembers(Class _class, bool isMember)
1015 DataMember topMember = isMember ? (DataMember) _class : null;
1018 Context context = isMember ? null : SetupTemplatesContext(_class);
1020 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1021 DeclareMembers(_class.base, false);
1023 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1025 if(!member.isProperty)
1032 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1033 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1034 DeclareStruct(member.dataType._class.string, false);
1036 if(!member.dataType && member.dataTypeString)
1037 member.dataType = ProcessTypeString(member.dataTypeString, false);
1039 DeclareType(member.dataType, false, false);
1045 DeclareMembers((Class)member, true);
1052 FinishTemplatesContext(context);
1054 return topMember ? topMember.memberID : _class.memberID;
1057 void DeclareStruct(char * name, bool skipNoHead)
1059 External external = null;
1060 Symbol classSym = FindClass(name);
1062 if(!inCompiler || !classSym) return null;
1064 // We don't need any declaration for bit classes...
1065 if(classSym.registered &&
1066 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1069 /*if(classSym.registered.templateClass)
1070 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1073 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1075 // Add typedef struct
1077 OldList * specifiers, * declarators;
1078 OldList * declarations = null;
1079 char structName[1024];
1080 external = (classSym.registered && classSym.registered.type == structClass) ?
1081 classSym.pointerExternal : classSym.structExternal;
1083 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1084 // Moved this one up because DeclareClass done later will need it
1086 classSym.declaring++;
1088 if(strchr(classSym.string, '<'))
1090 if(classSym.registered.templateClass)
1092 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1093 classSym.declaring--;
1099 DeclareMembers(classSym.registered, false);
1102 FullClassNameCat(structName, name, false);
1105 external = MkExternalDeclaration(null);*/
1109 classSym.declaredStructSym = true;
1111 declarations = MkList();
1113 AddMembers(declarations, classSym.registered, false, null, classSym.registered);
1115 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1116 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1118 if(!declarations->count)
1120 FreeList(declarations, null);
1121 declarations = null;
1124 if(skipNoHead || declarations)
1126 if(external && external.declaration)
1128 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1130 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1133 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1136 if(classSym.structExternal)
1137 ast->Move(classSym.structExternal, curExternal.prev);
1138 ast->Move(classSym.pointerExternal, curExternal.prev);
1140 classSym.id = curExternal.symbol.idCode;
1141 classSym.idCode = curExternal.symbol.idCode;
1142 // external = classSym.pointerExternal;
1143 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1149 external = MkExternalDeclaration(null);
1151 specifiers = MkList();
1152 declarators = MkList();
1153 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1156 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1157 ListAdd(declarators, MkInitDeclarator(d, null));
1159 external.declaration = decl = MkDeclaration(specifiers, declarators);
1160 if(decl.symbol && !decl.symbol.pointerExternal)
1161 decl.symbol.pointerExternal = external;
1163 // For simple classes, keep the declaration as the external to move around
1164 if(classSym.registered && classSym.registered.type == structClass)
1166 char className[1024];
1167 strcpy(className, "__ecereClass_");
1168 FullClassNameCat(className, classSym.string, true);
1169 MangleClassName(className);
1172 DeclareClass(classSym, className);
1174 external.symbol = classSym;
1175 classSym.pointerExternal = external;
1176 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1177 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1181 char className[1024];
1182 strcpy(className, "__ecereClass_");
1183 FullClassNameCat(className, classSym.string, true);
1184 MangleClassName(className);
1186 // TOFIX: TESTING THIS...
1187 classSym.structExternal = external;
1188 DeclareClass(classSym, className);
1189 external.symbol = classSym;
1193 ast->Insert(curExternal ? curExternal.prev : null, external);
1197 classSym.declaring--;
1199 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1201 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1202 // Moved this one up because DeclareClass done later will need it
1205 classSym.declaring++;
1209 if(classSym.registered)
1210 DeclareMembers(classSym.registered, false);
1213 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1216 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1219 if(classSym.structExternal)
1220 ast->Move(classSym.structExternal, curExternal.prev);
1221 ast->Move(classSym.pointerExternal, curExternal.prev);
1223 classSym.id = curExternal.symbol.idCode;
1224 classSym.idCode = curExternal.symbol.idCode;
1225 // external = classSym.pointerExternal;
1226 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1229 classSym.declaring--;
1234 void DeclareProperty(Property prop, char * setName, char * getName)
1236 Symbol symbol = prop.symbol;
1237 char propName[1024];
1239 strcpy(setName, "__ecereProp_");
1240 FullClassNameCat(setName, prop._class.fullName, false);
1241 strcat(setName, "_Set_");
1242 // strcat(setName, prop.name);
1243 FullClassNameCat(setName, prop.name, true);
1245 strcpy(getName, "__ecereProp_");
1246 FullClassNameCat(getName, prop._class.fullName, false);
1247 strcat(getName, "_Get_");
1248 FullClassNameCat(getName, prop.name, true);
1249 // strcat(getName, prop.name);
1251 strcpy(propName, "__ecereProp_");
1252 FullClassNameCat(propName, prop._class.fullName, false);
1253 strcat(propName, "_");
1254 FullClassNameCat(propName, prop.name, true);
1255 // strcat(propName, prop.name);
1257 // To support "char *" property
1258 MangleClassName(getName);
1259 MangleClassName(setName);
1260 MangleClassName(propName);
1262 if(prop._class.type == structClass)
1263 DeclareStruct(prop._class.fullName, false);
1265 if(!symbol || curExternal.symbol.idCode < symbol.id)
1267 bool imported = false;
1268 bool dllImport = false;
1269 if(!symbol || symbol._import)
1274 if(!prop._class.symbol)
1275 prop._class.symbol = FindClass(prop._class.fullName);
1276 classSym = prop._class.symbol;
1277 if(classSym && !classSym._import)
1279 ModuleImport module;
1281 if(prop._class.module)
1282 module = FindModule(prop._class.module);
1284 module = mainModule;
1286 classSym._import = ClassImport
1288 name = CopyString(prop._class.fullName);
1289 isRemote = prop._class.isRemote;
1291 module.classes.Add(classSym._import);
1293 symbol = prop.symbol = Symbol { };
1294 symbol._import = (ClassImport)PropertyImport
1296 name = CopyString(prop.name);
1297 isVirtual = false; //prop.isVirtual;
1298 hasSet = prop.Set ? true : false;
1299 hasGet = prop.Get ? true : false;
1302 classSym._import.properties.Add(symbol._import);
1305 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1311 Context context = SetupTemplatesContext(prop._class);
1312 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1313 FinishTemplatesContext(context);
1319 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1322 OldList * specifiers, * declarators;
1327 Declarator typeDecl;
1328 bool simple = false;
1330 specifiers = MkList();
1331 declarators = MkList();
1334 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1335 MkDeclaratorIdentifier(MkIdentifier("this"))));
1337 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1340 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1343 Context context = SetupTemplatesContext(prop._class);
1344 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1345 FinishTemplatesContext(context);
1348 // Make sure the simple _class's type is declared
1349 for(spec = specifiers->first; spec; spec = spec.next)
1351 if(spec.type == nameSpecifier /*SpecifierClass*/)
1353 if((!typeDecl || typeDecl.type == identifierDeclarator))
1355 Symbol classSym = spec.symbol; // FindClass(spec.name);
1356 symbol._class = classSym.registered;
1357 if(classSym.registered && classSym.registered.type == structClass)
1359 DeclareStruct(spec.name, false);
1367 d = PlugDeclarator(typeDecl, d);
1370 ListAdd(params, MkTypeName(specifiers,
1371 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1372 specifiers = MkList();
1375 d = MkDeclaratorFunction(d, params);
1379 specifiers->Insert(null, MkSpecifier(EXTERN));
1380 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1381 specifiers->Insert(null, MkSpecifier(STATIC));
1383 ListAdd(specifiers, MkSpecifier(VOID));
1385 ListAdd(declarators, MkInitDeclarator(d, null));
1387 decl = MkDeclaration(specifiers, declarators);
1389 external = MkExternalDeclaration(decl);
1390 ast->Insert(curExternal.prev, external);
1391 external.symbol = symbol;
1392 symbol.externalGet = external;
1394 ReplaceThisClassSpecifiers(specifiers, prop._class);
1397 FreeDeclarator(typeDecl);
1401 // Move declaration higher...
1402 ast->Move(symbol.externalGet, curExternal.prev);
1409 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1412 OldList * specifiers, * declarators;
1417 Declarator typeDecl;
1419 declarators = MkList();
1422 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1423 if(!prop.conversion || prop._class.type == structClass)
1425 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1426 MkDeclaratorIdentifier(MkIdentifier("this"))));
1429 specifiers = MkList();
1432 Context context = SetupTemplatesContext(prop._class);
1433 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1434 MkDeclaratorIdentifier(MkIdentifier("value")));
1435 FinishTemplatesContext(context);
1437 ListAdd(params, MkTypeName(specifiers, d));
1439 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1442 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1443 d = MkDeclaratorFunction(d, params);
1445 // Make sure the simple _class's type is declared
1446 for(spec = specifiers->first; spec; spec = spec.next)
1448 if(spec.type == nameSpecifier /*SpecifierClass*/)
1450 if((!typeDecl || typeDecl.type == identifierDeclarator))
1452 Symbol classSym = spec.symbol; // FindClass(spec.name);
1453 symbol._class = classSym.registered;
1454 if(classSym.registered && classSym.registered.type == structClass)
1455 DeclareStruct(spec.name, false);
1460 ListAdd(declarators, MkInitDeclarator(d, null));
1462 specifiers = MkList();
1465 specifiers->Insert(null, MkSpecifier(EXTERN));
1466 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1467 specifiers->Insert(null, MkSpecifier(STATIC));
1469 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1470 if(!prop.conversion || prop._class.type == structClass)
1471 ListAdd(specifiers, MkSpecifier(VOID));
1473 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1475 decl = MkDeclaration(specifiers, declarators);
1477 external = MkExternalDeclaration(decl);
1478 ast->Insert(curExternal.prev, external);
1479 external.symbol = symbol;
1480 symbol.externalSet = external;
1482 ReplaceThisClassSpecifiers(specifiers, prop._class);
1486 // Move declaration higher...
1487 ast->Move(symbol.externalSet, curExternal.prev);
1491 // Property (for Watchers)
1492 if(!symbol.externalPtr)
1496 OldList * specifiers = MkList();
1499 specifiers->Insert(null, MkSpecifier(EXTERN));
1501 specifiers->Insert(null, MkSpecifier(STATIC));
1503 ListAdd(specifiers, MkSpecifierName("Property"));
1506 OldList * list = MkList();
1507 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1508 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1512 strcpy(propName, "__ecerePropM_");
1513 FullClassNameCat(propName, prop._class.fullName, false);
1514 strcat(propName, "_");
1515 // strcat(propName, prop.name);
1516 FullClassNameCat(propName, prop.name, true);
1518 MangleClassName(propName);
1520 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1521 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1523 decl = MkDeclaration(specifiers, list);
1526 external = MkExternalDeclaration(decl);
1527 ast->Insert(curExternal.prev, external);
1528 external.symbol = symbol;
1529 symbol.externalPtr = external;
1533 // Move declaration higher...
1534 ast->Move(symbol.externalPtr, curExternal.prev);
1537 symbol.id = curExternal.symbol.idCode;
1541 // ***************** EXPRESSION PROCESSING ***************************
1542 public Type Dereference(Type source)
1547 if(source.kind == pointerType || source.kind == arrayType)
1550 source.type.refCount++;
1552 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1560 // Support dereferencing of no head classes for now...
1561 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1567 Compiler_Error("cannot dereference type\n");
1572 static Type Reference(Type source)
1588 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1590 Identifier ident = member.identifiers ? member.identifiers->first : null;
1592 DataMember dataMember = null;
1593 Method method = null;
1594 bool freeType = false;
1596 yylloc = member.loc;
1602 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1606 dataMember = *curMember;
1612 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1613 DataMember _subMemberStack[256];
1614 int _subMemberStackPos = 0;
1616 // FILL MEMBER STACK
1618 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1621 dataMember = thisMember;
1622 if(curMember && thisMember.memberAccess == publicAccess)
1624 *curMember = thisMember;
1625 *curClass = thisMember._class;
1626 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
1627 *subMemberStackPos = _subMemberStackPos;
1634 method = eClass_FindMethod(_class, ident.string, privateModule);
1635 if(method && method.type == virtualMethod)
1647 if(!dataMember.dataType && dataMember.dataTypeString)
1649 //Context context = SetupTemplatesContext(dataMember._class);
1650 Context context = SetupTemplatesContext(_class);
1651 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1652 FinishTemplatesContext(context);
1654 type = dataMember.dataType;
1658 // This is for destination type...
1659 if(!method.dataType)
1660 ProcessMethodType(method);
1661 //DeclareMethod(method);
1662 // method.dataType = ((Symbol)method.symbol)->type;
1663 type = method.dataType;
1666 if(ident && ident.next)
1668 for(ident = ident.next; ident && type; ident = ident.next)
1670 if(type.kind == classType)
1672 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1674 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1676 type = dataMember.dataType;
1678 else if(type.kind == structType || type.kind == unionType)
1681 for(memberType = type.members.first; memberType; memberType = memberType.next)
1683 if(!strcmp(memberType.name, ident.string))
1693 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1694 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1697 ClassTemplateParameter curParam;
1699 for(sClass = _class; sClass; sClass = sClass.base)
1702 if(sClass.templateClass) sClass = sClass.templateClass;
1703 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1705 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1707 for(sClass = sClass.base; sClass; sClass = sClass.base)
1709 if(sClass.templateClass) sClass = sClass.templateClass;
1710 id += sClass.templateParams.count;
1721 ClassTemplateArgument arg = _class.templateArgs[id];
1722 if(arg.dataTypeString)
1725 type = ProcessTypeString(arg.dataTypeString, false);
1727 if(type && _class.templateClass)
1728 type.passAsTemplate = true;
1734 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1735 exp.destType.refCount++;
1741 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1743 Class expClass = type._class.registered;
1744 Class cClass = null;
1749 char templateString[1024];
1750 ClassTemplateParameter param;
1751 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1752 for(cClass = expClass; cClass; cClass = cClass.base)
1755 if(cClass.templateClass) cClass = cClass.templateClass;
1756 for(param = cClass.templateParams.first; param; param = param.next)
1760 ClassTemplateArgument arg;
1761 for(sClass = cClass.base; sClass; sClass = sClass.base)
1763 if(sClass.templateClass) sClass = sClass.templateClass;
1764 id += sClass.templateParams.count;
1766 arg = expClass.templateArgs[id];
1768 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1770 ClassTemplateParameter cParam;
1771 //int p = numParams - sClass.templateParams.count;
1774 if(sClass.templateClass) sClass = sClass.templateClass;
1776 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1778 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1779 p += nextClass.templateParams.count;
1782 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1784 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1786 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1788 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1789 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1801 strcat(argument, arg.name.string);
1802 strcat(argument, " = ");
1808 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1809 char expString[1024];
1810 OldList * specs = MkList();
1811 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1813 char * string = PrintHexUInt64(arg.expression.ui64);
1814 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1816 ProcessExpressionType(exp);
1817 ComputeExpression(exp);
1818 expString[0] = '\0';
1819 PrintExpression(exp, expString);
1820 strcat(argument, expString);
1822 FreeExpression(exp);
1827 strcat(argument, arg.member.name);
1830 case TemplateParameterType::type:
1832 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1833 strcat(argument, arg.dataTypeString);
1839 if(paramCount) strcat(templateString, ", ");
1840 if(lastParam != p - 1)
1842 strcat(templateString, param.name);
1843 strcat(templateString, " = ");
1845 strcat(templateString, argument);
1854 int len = strlen(templateString);
1855 if(templateString[len-1] == '<')
1859 if(templateString[len-1] == '>')
1860 templateString[len++] = ' ';
1861 templateString[len++] = '>';
1863 templateString[len++] = '\0';
1866 Context context = SetupTemplatesContext(_class);
1867 if(freeType) FreeType(type);
1868 type = ProcessTypeString(templateString, false);
1870 FinishTemplatesContext(context);
1874 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1876 ProcessExpressionType(member.initializer.exp);
1877 if(!member.initializer.exp.expType)
1881 char expString[10240];
1882 expString[0] = '\0';
1883 PrintExpression(member.initializer.exp, expString);
1884 ChangeCh(expString, '\n', ' ');
1885 Compiler_Error("unresolved symbol used as an instance method %s\n", expString);
1888 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1889 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1891 Compiler_Error("incompatible instance method %s\n", ident.string);
1894 else if(member.initializer)
1897 FreeType(member.exp.destType);
1898 member.exp.destType = type;
1899 if(member.exp.destType)
1900 member.exp.destType.refCount++;
1901 ProcessExpressionType(member.exp);
1904 ProcessInitializer(member.initializer, type);
1906 if(freeType) FreeType(type);
1910 if(_class && _class.type == unitClass)
1912 if(member.initializer)
1915 FreeType(member.exp.destType);
1916 member.exp.destType = MkClassType(_class.fullName);
1917 ProcessExpressionType(member.initializer, type);
1919 Type type = MkClassType(_class.fullName);
1920 ProcessInitializer(member.initializer, type);
1926 if(member.initializer)
1928 //ProcessExpressionType(member.exp);
1929 ProcessInitializer(member.initializer, null);
1935 Compiler_Error("couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1939 Compiler_Error("couldn't find member %s in class %s\n", ident.string, _class.fullName);
1941 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1945 Compiler_Error("too many initializers for instantiation of class %s\n", _class.fullName);
1950 void ProcessInstantiationType(Instantiation inst)
1955 MembersInit members;
1956 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1959 /*if(!inst._class.symbol)
1960 inst._class.symbol = FindClass(inst._class.name);*/
1961 classSym = inst._class.symbol;
1962 _class = classSym ? classSym.registered : null;
1964 // DANGER: Patch for mutex not declaring its struct when not needed
1965 if(!_class || _class.type != noHeadClass)
1966 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1968 afterExternal = afterExternal ? afterExternal : curExternal;
1971 ProcessExpressionType(inst.exp);
1973 inst.isConstant = true;
1976 DataMember curMember = null;
1977 Class curClass = null;
1978 DataMember subMemberStack[256];
1979 int subMemberStackPos = 0;
1981 for(members = inst.members->first; members; members = members.next)
1983 switch(members.type)
1985 case methodMembersInit:
1988 static uint instMethodID = 0;
1989 External external = curExternal;
1990 Context context = curContext;
1991 Declarator declarator = members.function.declarator;
1992 Identifier nameID = GetDeclId(declarator);
1993 char * unmangled = nameID ? nameID.string : null;
1995 External createdExternal = null;
2000 //members.function.dontMangle = true;
2001 strcpy(name, "__ecereInstMeth_");
2002 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2004 strcat(name, nameID.string);
2006 sprintf(number, "_%08d", instMethodID++);
2007 strcat(name, number);
2008 nameID.string = CopyString(name);
2011 // Do modifications here...
2014 Symbol symbol = declarator.symbol;
2015 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2017 if(method && method.type == virtualMethod)
2019 symbol.method = method;
2020 ProcessMethodType(method);
2022 if(!symbol.type.thisClass)
2024 if(method.dataType.thisClass && currentClass &&
2025 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2027 if(!currentClass.symbol)
2028 currentClass.symbol = FindClass(currentClass.fullName);
2029 symbol.type.thisClass = currentClass.symbol;
2034 _class.symbol = FindClass(_class.fullName);
2035 symbol.type.thisClass = _class.symbol;
2038 // TESTING THIS HERE:
2039 DeclareType(symbol.type, true, true);
2044 Compiler_Error("couldn't find virtual method %s in class %s\n",
2045 unmangled, classSym.string);
2049 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2050 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2054 FreeSpecifier(nameID._class);
2055 nameID._class = null;
2061 Type type = declarator.symbol.type;
2062 External oldExternal = curExternal;
2064 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2065 // *** It was commented out for problems such as
2067 class VirtualDesktop : Window
2069 clientSize = Size { };
2080 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2082 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2085 if(strcmp(declarator.symbol.string, name))
2087 printf("TOCHECK: Look out for this\n");
2088 delete declarator.symbol.string;
2089 declarator.symbol.string = CopyString(name);
2092 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2094 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2095 excludedSymbols->Remove(declarator.symbol);
2096 globalContext.symbols.Add((BTNode)declarator.symbol);
2100 //curExternal = curExternal.prev;
2101 //afterExternal = afterExternal->next;
2103 //ProcessFunction(afterExternal->function);
2105 //curExternal = afterExternal;
2107 External externalDecl;
2108 externalDecl = MkExternalDeclaration(null);
2109 ast->Insert(oldExternal.prev, externalDecl);
2111 // Which function does this process?
2112 if(createdExternal.function)
2114 ProcessFunction(createdExternal.function);
2116 //curExternal = oldExternal;
2119 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2121 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2122 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2124 //externalDecl = MkExternalDeclaration(decl);
2126 //***** ast->Insert(external.prev, externalDecl);
2127 //ast->Insert(curExternal.prev, externalDecl);
2128 externalDecl.declaration = decl;
2129 if(decl.symbol && !decl.symbol.pointerExternal)
2130 decl.symbol.pointerExternal = externalDecl;
2132 // Trying this out...
2133 declarator.symbol.pointerExternal = externalDecl;
2140 curExternal = declarator.symbol.pointerExternal;
2141 ProcessFunction((FunctionDefinition)members.function);
2143 curExternal = external;
2144 curContext = context;
2148 FreeClassFunction(members.function);
2150 // In this pass, turn this into a MemberInitData
2151 exp = QMkExpId(name);
2152 members.type = dataMembersInit;
2153 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2159 case dataMembersInit:
2161 if(members.dataMembers && classSym)
2164 Location oldyyloc = yylloc;
2165 for(member = members.dataMembers->first; member; member = member.next)
2167 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2168 if(member.initializer && !member.initializer.isConstant)
2169 inst.isConstant = false;
2181 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2183 // OPTIMIZATIONS: TESTING THIS...
2186 if(type.kind == functionType)
2191 for(param = type.params.first; param; param = param.next)
2192 DeclareType(param, declarePointers, true);
2194 DeclareType(type.returnType, declarePointers, true);
2196 else if(type.kind == pointerType && declarePointers)
2197 DeclareType(type.type, declarePointers, false);
2198 else if(type.kind == classType)
2200 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2201 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2203 else if(type.kind == structType || type.kind == unionType)
2206 for(member = type.members.first; member; member = member.next)
2207 DeclareType(member, false, false);
2209 else if(type.kind == arrayType)
2210 DeclareType(type.arrayType, declarePointers, false);
2214 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2216 ClassTemplateArgument * arg = null;
2218 ClassTemplateParameter curParam;
2220 for(sClass = _class; sClass; sClass = sClass.base)
2223 if(sClass.templateClass) sClass = sClass.templateClass;
2224 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2226 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2228 for(sClass = sClass.base; sClass; sClass = sClass.base)
2230 if(sClass.templateClass) sClass = sClass.templateClass;
2231 id += sClass.templateParams.count;
2241 arg = &_class.templateArgs[id];
2242 if(arg && param.type == type)
2243 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2248 public Context SetupTemplatesContext(Class _class)
2250 Context context = PushContext();
2251 context.templateTypesOnly = true;
2252 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2254 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2255 for(; param; param = param.next)
2257 if(param.type == type && param.identifier)
2259 TemplatedType type { key = (uint)param.identifier.string, param = param };
2260 curContext.templateTypes.Add((BTNode)type);
2267 for(sClass = _class; sClass; sClass = sClass.base)
2269 ClassTemplateParameter p;
2270 for(p = sClass.templateParams.first; p; p = p.next)
2272 //OldList * specs = MkList();
2273 //Declarator decl = null;
2274 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2277 TemplateParameter param = p.param;
2281 // ADD DATA TYPE HERE...
2282 p.param = param = TemplateParameter
2284 identifier = MkIdentifier(p.name), type = p.type,
2285 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2288 type = TemplatedType { key = (uint)p.name, param = param };
2289 curContext.templateTypes.Add((BTNode)type);
2297 public void FinishTemplatesContext(Context context)
2299 PopContext(context);
2300 FreeContext(context);
2304 public void ProcessMethodType(Method method)
2306 if(!method.dataType)
2308 Context context = SetupTemplatesContext(method._class);
2310 method.dataType = ProcessTypeString(method.dataTypeString, false);
2312 FinishTemplatesContext(context);
2314 if(method.type != virtualMethod && method.dataType)
2316 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2318 if(!method._class.symbol)
2319 method._class.symbol = FindClass(method._class.fullName);
2320 method.dataType.thisClass = method._class.symbol;
2324 // Why was this commented out? Working fine without now...
2327 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2328 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2335 char * par = strstr(type, "(");
2336 char * classOp = null;
2341 for(c = par-type-1; c >= 0; c++)
2343 if(type[c] == ':' && type[c+1] == ':')
2345 classOp = type + c - 1;
2346 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2353 else if(!isspace(type[c]))
2360 int typeLen = strlen(type);
2361 memcpy(temp, classOp, classOpLen);
2362 temp[classOpLen] = '\0';
2364 _class = eSystem_FindClass(module, temp);
2367 method.dataTypeString = new char[typeLen - classOpLen + 1];
2368 memcpy(method.dataTypeString, type, classOp - type);
2369 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2372 method.dataTypeString = type;
2378 public void ProcessPropertyType(Property prop)
2382 Context context = SetupTemplatesContext(prop._class);
2383 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2384 FinishTemplatesContext(context);
2388 public void DeclareMethod(Method method, char * name)
2390 Symbol symbol = method.symbol;
2391 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2393 bool imported = false;
2394 bool dllImport = false;
2396 if(!method.dataType)
2397 method.dataType = ProcessTypeString(method.dataTypeString, false);
2399 if(!symbol || symbol._import || method.type == virtualMethod)
2401 if(!symbol || method.type == virtualMethod)
2404 if(!method._class.symbol)
2405 method._class.symbol = FindClass(method._class.fullName);
2406 classSym = method._class.symbol;
2407 if(!classSym._import)
2409 ModuleImport module;
2411 if(method._class.module && method._class.module.name)
2412 module = FindModule(method._class.module);
2414 module = mainModule;
2415 classSym._import = ClassImport
2417 name = CopyString(method._class.fullName);
2418 isRemote = method._class.isRemote;
2420 module.classes.Add(classSym._import);
2424 symbol = method.symbol = Symbol { };
2428 symbol._import = (ClassImport)MethodImport
2430 name = CopyString(method.name);
2431 isVirtual = method.type == virtualMethod;
2433 classSym._import.methods.Add(symbol._import);
2437 // Set the symbol type
2441 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2443 else if(type.thisClass == (void *)-1)
2445 type.thisClass = null;
2448 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2449 symbol.type = method.dataType;
2450 if(symbol.type) symbol.type.refCount++;
2453 if(!method.thisClass || strcmp(method.thisClass, "void"))
2454 symbol.type.params.Insert(null,
2455 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2458 if(!method.dataType.dllExport)
2461 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2467 if(!method.dataType)
2468 method.dataType = ((Symbol)method.symbol).type;
2469 //ProcessMethodType(method);
2472 if(method.type != virtualMethod && method.dataType)
2473 DeclareType(method.dataType, true, true);
2475 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2477 // We need a declaration here :)
2479 OldList * specifiers, * declarators;
2481 Declarator funcDecl;
2484 specifiers = MkList();
2485 declarators = MkList();
2489 ListAdd(specifiers, MkSpecifier(EXTERN));
2490 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2491 ListAdd(specifiers, MkSpecifier(STATIC));
2493 if(method.type == virtualMethod)
2495 ListAdd(specifiers, MkSpecifier(INT));
2496 d = MkDeclaratorIdentifier(MkIdentifier(name));
2500 d = MkDeclaratorIdentifier(MkIdentifier(name));
2503 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2505 Context context = SetupTemplatesContext(method._class);
2506 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2507 FinishTemplatesContext(context);
2509 funcDecl = GetFuncDecl(d);
2513 Specifier spec, next;
2514 for(spec = specifiers->first; spec; spec = next)
2517 if(spec.type == extendedSpecifier)
2519 specifiers->Remove(spec);
2520 FreeSpecifier(spec);
2525 // Add this parameter if not a static method
2526 if(method.dataType && !method.dataType.staticMethod)
2528 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2530 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2531 TypeName thisParam = MkTypeName(MkListOne(
2532 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2533 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2534 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2535 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2537 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2539 TypeName param = funcDecl.function.parameters->first;
2540 funcDecl.function.parameters->Remove(param);
2541 FreeTypeName(param);
2544 if(!funcDecl.function.parameters)
2545 funcDecl.function.parameters = MkList();
2546 funcDecl.function.parameters->Insert(null, thisParam);
2549 // Make sure we don't have empty parameter declarations for static methods...
2551 else if(!funcDecl.function.parameters)
2553 funcDecl.function.parameters = MkList();
2554 funcDecl.function.parameters->Insert(null,
2555 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2559 ProcessDeclarator(d);
2561 ListAdd(declarators, MkInitDeclarator(d, null));
2563 decl = MkDeclaration(specifiers, declarators);
2565 ReplaceThisClassSpecifiers(specifiers, method._class);
2567 // Keep a different symbol for the function definition than the declaration...
2568 if(symbol.pointerExternal)
2570 Symbol functionSymbol { };
2574 *functionSymbol = *symbol;
2575 functionSymbol.string = CopyString(symbol.string);
2576 if(functionSymbol.type)
2577 functionSymbol.type.refCount++;
2580 excludedSymbols->Add(functionSymbol);
2581 symbol.pointerExternal.symbol = functionSymbol;
2583 external = MkExternalDeclaration(decl);
2585 ast->Insert(curExternal ? curExternal.prev : null, external);
2586 external.symbol = symbol;
2587 symbol.pointerExternal = external;
2591 // Move declaration higher...
2592 ast->Move(symbol.pointerExternal, curExternal.prev);
2595 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2599 char * ReplaceThisClass(Class _class)
2601 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2605 ClassTemplateParameter param;
2608 char className[1024];
2609 strcpy(className, _class.fullName);
2610 for(param = _class.templateParams.first; param; param = param.next)
2612 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2614 if(first) strcat(className, "<");
2615 if(!first) strcat(className, ", ");
2616 if(lastParam + 1 != p)
2618 strcat(className, param.name);
2619 strcat(className, " = ");
2621 strcat(className, param.name);
2629 int len = strlen(className);
2630 if(className[len-1] == '>') className[len++] = ' ';
2631 className[len++] = '>';
2632 className[len++] = '\0';
2634 return CopyString(className);
2637 return CopyString(_class.fullName);
2640 Type ReplaceThisClassType(Class _class)
2642 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2646 ClassTemplateParameter param;
2648 char className[1024];
2649 strcpy(className, _class.fullName);
2651 for(param = _class.templateParams.first; param; param = param.next)
2653 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2655 if(first) strcat(className, "<");
2656 if(!first) strcat(className, ", ");
2657 if(lastParam + 1 != p)
2659 strcat(className, param.name);
2660 strcat(className, " = ");
2662 strcat(className, param.name);
2670 int len = strlen(className);
2671 if(className[len-1] == '>') className[len++] = ' ';
2672 className[len++] = '>';
2673 className[len++] = '\0';
2675 return MkClassType(className);
2676 //return ProcessTypeString(className, false);
2680 return MkClassType(_class.fullName);
2681 //return ProcessTypeString(_class.fullName, false);
2685 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2687 if(specs != null && _class)
2690 for(spec = specs.first; spec; spec = spec.next)
2692 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2694 spec.type = nameSpecifier;
2695 spec.name = ReplaceThisClass(_class);
2696 spec.symbol = FindClass(spec.name); //_class.symbol;
2702 // Returns imported or not
2703 bool DeclareFunction(GlobalFunction function, char * name)
2705 Symbol symbol = function.symbol;
2706 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2708 bool imported = false;
2709 bool dllImport = false;
2711 if(!function.dataType)
2713 function.dataType = ProcessTypeString(function.dataTypeString, false);
2714 if(!function.dataType.thisClass)
2715 function.dataType.staticMethod = true;
2722 ModuleImport module = FindModule(function.module);
2723 // WARNING: This is not added anywhere...
2724 symbol = function.symbol = Symbol { };
2728 if(!function.dataType.dllExport)
2730 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2731 module.functions.Add(symbol._import);
2734 // Set the symbol type
2736 symbol.type = ProcessTypeString(function.dataTypeString, false);
2737 if(!symbol.type.thisClass)
2738 symbol.type.staticMethod = true;
2741 imported = symbol._import ? true : false;
2742 if(imported && function.module != privateModule && function.module.importType != staticImport)
2746 DeclareType(function.dataType, true, true);
2750 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2752 // We need a declaration here :)
2754 OldList * specifiers, * declarators;
2756 Declarator funcDecl;
2759 specifiers = MkList();
2760 declarators = MkList();
2763 ListAdd(specifiers, MkSpecifier(EXTERN));
2766 ListAdd(specifiers, MkSpecifier(STATIC));
2769 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2772 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2774 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2775 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2776 if(function.module.importType == staticImport)
2779 for(spec = specifiers->first; spec; spec = spec.next)
2780 if(spec.type == extendedSpecifier && !strcmp(spec.name, "dllexport"))
2782 specifiers->Remove(spec);
2783 FreeSpecifier(spec);
2788 funcDecl = GetFuncDecl(d);
2790 // Make sure we don't have empty parameter declarations for static methods...
2791 if(funcDecl && !funcDecl.function.parameters)
2793 funcDecl.function.parameters = MkList();
2794 funcDecl.function.parameters->Insert(null,
2795 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2798 ListAdd(declarators, MkInitDeclarator(d, null));
2801 Context oldCtx = curContext;
2802 curContext = globalContext;
2803 decl = MkDeclaration(specifiers, declarators);
2804 curContext = oldCtx;
2807 // Keep a different symbol for the function definition than the declaration...
2808 if(symbol.pointerExternal)
2810 Symbol functionSymbol { };
2813 *functionSymbol = *symbol;
2814 functionSymbol.string = CopyString(symbol.string);
2815 if(functionSymbol.type)
2816 functionSymbol.type.refCount++;
2819 excludedSymbols->Add(functionSymbol);
2821 symbol.pointerExternal.symbol = functionSymbol;
2823 external = MkExternalDeclaration(decl);
2825 ast->Insert(curExternal.prev, external);
2826 external.symbol = symbol;
2827 symbol.pointerExternal = external;
2831 // Move declaration higher...
2832 ast->Move(symbol.pointerExternal, curExternal.prev);
2836 symbol.id = curExternal.symbol.idCode;
2839 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2842 void DeclareGlobalData(GlobalData data)
2844 Symbol symbol = data.symbol;
2845 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2850 symbol = data.symbol = Symbol { };
2853 data.dataType = ProcessTypeString(data.dataTypeString, false);
2854 DeclareType(data.dataType, true, true);
2857 if(!symbol.pointerExternal)
2859 // We need a declaration here :)
2861 OldList * specifiers, * declarators;
2865 specifiers = MkList();
2866 declarators = MkList();
2868 ListAdd(specifiers, MkSpecifier(EXTERN));
2869 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2870 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2872 ListAdd(declarators, MkInitDeclarator(d, null));
2874 decl = MkDeclaration(specifiers, declarators);
2875 external = MkExternalDeclaration(decl);
2877 ast->Insert(curExternal.prev, external);
2878 external.symbol = symbol;
2879 symbol.pointerExternal = external;
2883 // Move declaration higher...
2884 ast->Move(symbol.pointerExternal, curExternal.prev);
2888 symbol.id = curExternal.symbol.idCode;
2893 class Conversion : struct
2895 Conversion prev, next;
2901 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2905 // Property convert;
2907 if(source.kind == templateType && dest.kind != templateType)
2909 Type type = ProcessTemplateParameterType(source.templateParameter);
2910 if(type) source = type;
2913 if(dest.kind == templateType && source.kind != templateType)
2915 Type type = ProcessTemplateParameterType(dest.templateParameter);
2916 if(type) dest = type;
2919 if((dest.classObjectType == typedObject && source.classObjectType != anyObject) || (dest.classObjectType == anyObject && source.classObjectType != typedObject))
2924 if(source.classObjectType == anyObject && dest.classObjectType != typedObject)
2929 if((dest.kind == structType && source.kind == structType) ||
2930 (dest.kind == unionType && source.kind == unionType))
2932 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2933 (source.members.first && source.members.first == dest.members.first))
2937 if(dest.kind == ellipsisType && source.kind != voidType)
2940 if(dest.kind == pointerType && dest.type.kind == voidType &&
2941 ((source.kind == classType && (!source._class || !source._class.registered || source._class.registered.type == structClass || source._class.registered.type == normalClass || source._class.registered.type == noHeadClass || source._class.registered.type == systemClass))
2942 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2944 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2946 /*&& (source.kind != classType /*|| source._class.registered.type != structClass)*/)
2948 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2949 ((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))
2950 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2952 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2954 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2957 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2959 if(source._class.registered && source._class.registered.type == unitClass)
2961 if(conversions != null)
2963 if(source._class.registered == dest._class.registered)
2968 Class sourceBase, destBase;
2969 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2970 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2971 if(sourceBase == destBase)
2975 // Don't match enum inheriting from other enum if resolving enumeration values
2976 // TESTING: !dest.classObjectType
2977 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2979 (!source._class.registered || source._class.registered.type != enumClass) ||
2980 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2984 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2986 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2987 source._class && source._class.registered && source._class.registered.type != enumClass)
2989 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2997 // JUST ADDED THIS...
2998 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3003 // Just added this for Straight conversion of ColorAlpha => Color
3004 if(source.kind == classType)
3007 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3010 for(convert = _class.conversions.first; convert; convert = convert.next)
3012 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3014 Conversion after = (conversions != null) ? conversions.last : null;
3016 if(!convert.dataType)
3017 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3018 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
3020 if(!conversions && !convert.Get)
3022 else if(conversions != null)
3024 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3025 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3026 (dest.kind != classType || dest._class.registered != _class.base))
3030 Conversion conv { convert = convert, isGet = true };
3031 // conversions.Add(conv);
3032 conversions.Insert(after, conv);
3044 if(dest.kind == classType)
3047 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3050 for(convert = _class.conversions.first; convert; convert = convert.next)
3052 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3054 // Conversion after = (conversions != null) ? conversions.last : null;
3056 if(!convert.dataType)
3057 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3058 // Just added this equality check to prevent recursion.... Make it safer?
3059 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3060 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3062 if(!conversions && !convert.Set)
3064 else if(conversions != null)
3066 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3067 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3068 (source.kind != classType || source._class.registered != _class.base))
3072 // *** Testing this! ***
3073 Conversion conv { convert = convert };
3074 conversions.Add(conv);
3075 //conversions.Insert(after, conv);
3083 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3085 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3086 (source.kind != classType || source._class.registered.type != structClass))
3090 // TESTING THIS... IS THIS OK??
3091 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3093 if(!dest._class.registered.dataType)
3094 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3095 // Only support this for classes...
3096 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3097 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3099 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3108 if(source.kind == classType)
3111 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3114 for(convert = _class.conversions.first; convert; convert = convert.next)
3116 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3118 Conversion after = (conversions != null) ? conversions.last : null;
3120 if(!convert.dataType)
3121 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3122 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3124 if(!conversions && !convert.Get)
3126 else if(conversions != null)
3128 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3129 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3130 (dest.kind != classType || dest._class.registered != _class.base))
3134 Conversion conv { convert = convert, isGet = true };
3136 // conversions.Add(conv);
3137 conversions.Insert(after, conv);
3146 // TESTING THIS... IS THIS OK??
3147 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3149 if(!source._class.registered.dataType)
3150 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3151 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3159 if(source.kind == classType || source.kind == subClassType)
3161 else if(dest.kind == source.kind &&
3162 (dest.kind != structType && dest.kind != unionType &&
3163 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3165 // RECENTLY ADDED THESE
3166 else if(dest.kind == doubleType && source.kind == floatType)
3168 else if(dest.kind == shortType && source.kind == charType)
3170 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType))
3172 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType))
3174 else if(source.kind == enumType &&
3175 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type))
3177 else if(dest.kind == enumType &&
3178 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || dest.kind == int64Type))
3180 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3181 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3183 Type paramSource, paramDest;
3185 if(dest.kind == methodType)
3186 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3187 if(source.kind == methodType)
3188 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3190 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3191 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3192 if(dest.kind == methodType)
3193 dest = dest.method.dataType;
3194 if(source.kind == methodType)
3195 source = source.method.dataType;
3197 paramSource = source.params.first;
3198 if(paramSource && paramSource.kind == voidType) paramSource = null;
3199 paramDest = dest.params.first;
3200 if(paramDest && paramDest.kind == voidType) paramDest = null;
3203 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3204 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3206 // Source thisClass must be derived from destination thisClass
3207 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3208 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3210 if(paramDest && paramDest.kind == classType)
3211 Compiler_Error("method class must be derived from %s\n", paramDest._class.string);
3213 Compiler_Error("method class should not take an object\n");
3216 paramDest = paramDest.next;
3218 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3220 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3224 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3226 Compiler_Error("method class must be derived from %s\n", dest.thisClass.string);
3232 // THIS WAS BACKWARDS:
3233 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3234 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3237 Compiler_Error("%s expected to be derived from method class\n", owningClassDest.fullName);
3239 Compiler_Error("overriding class expected to be derived from method class\n");
3243 paramSource = paramSource.next;
3249 // Source thisClass must be derived from destination thisClass
3250 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3252 Compiler_Error("method class must be derived from %s\n", dest.thisClass.string);
3258 // THIS WAS BACKWARDS TOO??
3259 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3260 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3263 Compiler_Error("%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3265 //Compiler_Error("overriding class expected to be derived from method class\n");
3273 // Source return type must be derived from destination return type
3274 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3276 Compiler_Warning("incompatible return type for function\n");
3282 for(; paramDest; paramDest = paramDest.next)
3286 //Compiler_Warning("not enough parameters\n");
3287 Compiler_Error("not enough parameters\n");
3291 Type paramDestType = paramDest;
3292 Type paramSourceType = paramSource;
3293 Type type = paramDestType;
3295 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3296 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3297 paramSource.kind != templateType)
3300 ClassTemplateParameter curParam;
3302 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3305 if(sClass.templateClass) sClass = sClass.templateClass;
3306 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3308 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3310 for(sClass = sClass.base; sClass; sClass = sClass.base)
3312 if(sClass.templateClass) sClass = sClass.templateClass;
3313 id += sClass.templateParams.count;
3324 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3325 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3329 // paramDest must be derived from paramSource
3330 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3331 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3335 PrintType(paramDest, type, false, true);
3336 Compiler_Warning("incompatible parameter %s (expected %s)\n", paramSource.name, type);
3338 if(paramDestType != paramDest)
3339 FreeType(paramDestType);
3342 if(paramDestType != paramDest)
3343 FreeType(paramDestType);
3346 paramSource = paramSource.next;
3350 Compiler_Error("too many parameters\n");
3355 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3359 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3360 (source.kind == arrayType || source.kind == pointerType))
3362 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3369 static void FreeConvert(Conversion convert)
3371 if(convert.resultType)
3372 FreeType(convert.resultType);
3375 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3376 char * string, OldList conversions)
3380 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3382 Class _class = link.data;
3383 if(_class.type == enumClass)
3385 OldList converts { };
3387 type.kind = classType;
3390 _class.symbol = FindClass(_class.fullName);
3391 type._class = _class.symbol;
3393 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3396 Class enumClass = eSystem_FindClass(privateModule, "enum");
3400 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3402 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3403 for(value = e.values.first; value; value = value.next)
3405 if(!strcmp(value.name, string))
3410 FreeExpContents(sourceExp);
3411 FreeType(sourceExp.expType);
3413 sourceExp.isConstant = true;
3414 sourceExp.expType = MkClassType(baseClass.fullName);
3418 sourceExp.type = constantExp;
3419 if(!strcmp(baseClass.dataTypeString, "int"))
3420 sprintf(constant, "%d",value.data);
3422 sprintf(constant, "0x%X",value.data);
3423 sourceExp.constant = CopyString(constant);
3424 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3427 while(converts.first)
3429 Conversion convert = converts.first;
3430 converts.Remove(convert);
3431 conversions.Add(convert);
3440 converts.Free(FreeConvert);
3444 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3445 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3450 public bool ModuleVisibility(Module searchIn, Module searchFor)
3452 SubModule subModule;
3454 if(searchFor == searchIn)
3457 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3459 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3461 if(ModuleVisibility(subModule.module, searchFor))
3468 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3472 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3474 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3476 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3479 for(module = mainModule.application.allModules.first; module; module = module.next)
3481 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3487 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3489 Type source = sourceExp.expType;
3490 Type realDest = dest;
3492 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3495 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3497 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3499 Class sourceBase, destBase;
3500 for(sourceBase = source._class.registered;
3501 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3502 sourceBase = sourceBase.base);
3503 for(destBase = dest._class.registered;
3504 destBase && destBase.base && destBase.base.type != systemClass;
3505 destBase = destBase.base);
3506 //if(source._class.registered == dest._class.registered)
3507 if(sourceBase == destBase)
3516 int64 value = MAXINT;
3521 if(sourceExp.type == constantExp)
3524 value = strtoll(sourceExp.constant, null, 0);
3526 value = strtoull(sourceExp.constant, null, 0);
3528 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3531 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3533 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3536 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3537 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3540 source = Type { kind = intType, isSigned = false, refCount = 1 };
3543 if(dest.kind == classType)
3545 Class _class = dest._class ? dest._class.registered : null;
3547 if(_class && _class.type == unitClass)
3549 if(source.kind != classType)
3552 Type tempDest, tempSource;
3554 for(; _class.base.type != systemClass; _class = _class.base);
3556 tempDest = tempType;
3558 tempType.kind = classType;
3560 _class.symbol = FindClass(_class.fullName);
3562 tempType._class = _class.symbol;
3563 tempType.truth = dest.truth;
3565 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3567 FreeType(sourceExp.expType);
3568 sourceExp.expType = dest; dest.refCount++;
3570 //sourceExp.expType = MkClassType(_class.fullName);
3578 // Why wasn't there something like this?
3579 if(_class && _class.type == bitClass && source.kind != classType)
3581 if(!dest._class.registered.dataType)
3582 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3583 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3586 FreeType(sourceExp.expType);
3587 source = sourceExp.expType = MkClassType(dest._class.string);
3590 //source.kind = classType;
3591 //source._class = dest._class;
3595 // Adding two enumerations
3597 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3599 if(!source._class.registered.dataType)
3600 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3601 if(!dest._class.registered.dataType)
3602 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3604 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3607 source = sourceExp.expType = MkClassType(dest._class.string);
3610 //source.kind = classType;
3611 //source._class = dest._class;
3615 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3617 OldList * specs = MkList();
3621 ReadString(string, sourceExp.string);
3622 decl = SpecDeclFromString(string, specs, null);
3624 FreeExpContents(sourceExp);
3625 FreeType(sourceExp.expType);
3627 sourceExp.type = classExp;
3628 sourceExp._classExp.specifiers = specs;
3629 sourceExp._classExp.decl = decl;
3630 sourceExp.expType = dest;
3635 else if(source.kind == classType)
3637 Class _class = source._class ? source._class.registered : null;
3639 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3642 if(dest.kind != classType)
3644 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3645 if(!source._class.registered.dataType)
3646 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3649 dest = MkClassType(source._class.string);
3650 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3651 // dest = MkClassType(source._class.string);
3655 if(dest.kind != classType)
3658 Type tempDest, tempSource;
3660 if(!source._class.registered.dataType)
3661 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3663 for(; _class.base.type != systemClass; _class = _class.base);
3665 tempSource = tempType;
3666 tempType.kind = classType;
3667 tempType._class = FindClass(_class.fullName);
3668 tempType.truth = source.truth;
3669 tempType.classObjectType = source.classObjectType;
3672 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3674 // PUT THIS BACK TESTING UNITS?
3675 if(conversions.last)
3677 ((Conversion)(conversions.last)).resultType = dest;
3681 FreeType(sourceExp.expType);
3682 sourceExp.expType = MkClassType(_class.fullName);
3683 sourceExp.expType.truth = source.truth;
3684 sourceExp.expType.classObjectType = source.classObjectType;
3686 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3688 if(!sourceExp.destType)
3690 FreeType(sourceExp.destType);
3691 sourceExp.destType = sourceExp.expType;
3692 if(sourceExp.expType)
3693 sourceExp.expType.refCount++;
3696 //source = _class.dataType;
3699 // TOCHECK: TESTING THIS NEW CODE
3700 if(!_class.dataType)
3701 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3703 dest = MkClassType(source._class.string);
3704 dest.truth = source.truth;
3705 dest.classObjectType = source.classObjectType;
3708 source = _class.dataType;
3718 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3728 if(source.kind == classType)
3730 Class _class = source._class.registered;
3731 if(_class.type == unitClass)
3733 if(!_class.dataType)
3734 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3735 source = _class.dataType;
3739 if(dest.kind == classType)
3741 Class _class = dest._class ? dest._class.registered : null;
3742 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3743 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3745 if(_class.type == normalClass || _class.type == noHeadClass)
3747 Expression newExp { };
3748 *newExp = *sourceExp;
3749 if(sourceExp.destType) sourceExp.destType.refCount++;
3750 if(sourceExp.expType) sourceExp.expType.refCount++;
3751 sourceExp.type = castExp;
3752 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3753 sourceExp.cast.exp = newExp;
3754 FreeType(sourceExp.expType);
3755 sourceExp.expType = null;
3756 ProcessExpressionType(sourceExp);
3758 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3761 FreeType(sourceExp.expType);
3762 sourceExp.expType = dest;
3766 if(inCompiler) FreeType(dest);
3771 if(!_class.dataType)
3772 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3774 dest = _class.dataType;
3778 // Accept lower precision types for units, since we want to keep the unit type
3779 if(dest.kind == doubleType &&
3780 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3781 source.kind == charType))
3783 specs = MkListOne(MkSpecifier(DOUBLE));
3785 else if(dest.kind == floatType &&
3786 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3787 source.kind == doubleType))
3789 specs = MkListOne(MkSpecifier(FLOAT));
3791 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3792 source.kind == floatType || source.kind == doubleType))
3795 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3796 ListAdd(specs, MkSpecifier(INT64));
3798 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3799 source.kind == floatType || source.kind == doubleType))
3802 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3803 ListAdd(specs, MkSpecifier(INT));
3805 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
3806 source.kind == floatType || source.kind == doubleType))
3809 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3810 ListAdd(specs, MkSpecifier(SHORT));
3812 else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
3813 source.kind == floatType || source.kind == doubleType))
3816 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3817 ListAdd(specs, MkSpecifier(CHAR));
3826 else if(dest.kind == doubleType &&
3827 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3828 source.kind == charType))
3830 specs = MkListOne(MkSpecifier(DOUBLE));
3832 else if(dest.kind == floatType &&
3833 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3835 specs = MkListOne(MkSpecifier(FLOAT));
3837 else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3838 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3841 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3842 ListAdd(specs, MkSpecifier(CHAR));
3844 else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
3845 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3848 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3849 ListAdd(specs, MkSpecifier(SHORT));
3851 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
3854 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3855 ListAdd(specs, MkSpecifier(INT));
3857 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3860 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3861 ListAdd(specs, MkSpecifier(INT64));
3863 else if(dest.kind == enumType &&
3864 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3866 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3877 Expression newExp { };
3878 *newExp = *sourceExp;
3881 if(sourceExp.destType) sourceExp.destType.refCount++;
3882 if(sourceExp.expType) sourceExp.expType.refCount++;
3884 sourceExp.type = castExp;
3885 if(realDest.kind == classType)
3887 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3888 FreeList(specs, FreeSpecifier);
3891 sourceExp.cast.typeName = MkTypeName(specs, null);
3892 if(newExp.type == opExp)
3894 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3897 sourceExp.cast.exp = newExp;
3899 FreeType(sourceExp.expType);
3900 sourceExp.expType = null;
3901 ProcessExpressionType(sourceExp);
3904 FreeList(specs, FreeSpecifier);
3912 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3913 if(sourceExp.type == identifierExp)
3915 Identifier id = sourceExp.identifier;
3916 if(dest.kind == classType)
3918 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3920 Class _class = dest._class.registered;
3921 Class enumClass = eSystem_FindClass(privateModule, "enum");
3924 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3927 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3928 for(value = e.values.first; value; value = value.next)
3930 if(!strcmp(value.name, id.string))
3935 FreeExpContents(sourceExp);
3936 FreeType(sourceExp.expType);
3938 sourceExp.isConstant = true;
3939 sourceExp.expType = MkClassType(_class.fullName);
3943 sourceExp.type = constantExp;
3944 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3945 sprintf(constant, "%d",value.data);
3947 sprintf(constant, "0x%X",value.data);
3948 sourceExp.constant = CopyString(constant);
3949 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3958 // Loop through all enum classes
3959 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3966 #define TERTIARY(o, name, m, t, p) \
3967 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3969 exp.type = constantExp; \
3970 exp.string = p(op1.m ? op2.m : op3.m); \
3972 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3976 #define BINARY(o, name, m, t, p) \
3977 static bool name(Expression exp, Operand op1, Operand op2) \
3980 exp.type = constantExp; \
3981 exp.string = p(op1.m o value2); \
3983 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3987 #define BINARY_DIVIDE(o, name, m, t, p) \
3988 static bool name(Expression exp, Operand op1, Operand op2) \
3991 exp.type = constantExp; \
3992 exp.string = p(value2 ? (op1.m o value2) : 0); \
3994 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3998 #define UNARY(o, name, m, t, p) \
3999 static bool name(Expression exp, Operand op1) \
4001 exp.type = constantExp; \
4002 exp.string = p(o op1.m); \
4004 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4008 #define OPERATOR_ALL(macro, o, name) \
4009 macro(o, Int##name, i, int, PrintInt) \
4010 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4011 macro(o, Short##name, s, short, PrintShort) \
4012 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4013 macro(o, Char##name, c, char, PrintChar) \
4014 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4015 macro(o, Float##name, f, float, PrintFloat) \
4016 macro(o, Double##name, d, double, PrintDouble)
4018 #define OPERATOR_INTTYPES(macro, o, name) \
4019 macro(o, Int##name, i, int, PrintInt) \
4020 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4021 macro(o, Short##name, s, short, PrintShort) \
4022 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4023 macro(o, Char##name, c, char, PrintChar) \
4024 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4027 // binary arithmetic
4028 OPERATOR_ALL(BINARY, +, Add)
4029 OPERATOR_ALL(BINARY, -, Sub)
4030 OPERATOR_ALL(BINARY, *, Mul)
4031 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4032 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4035 OPERATOR_ALL(UNARY, -, Neg)
4037 // unary arithmetic increment and decrement
4038 OPERATOR_ALL(UNARY, ++, Inc)
4039 OPERATOR_ALL(UNARY, --, Dec)
4041 // binary arithmetic assignment
4042 OPERATOR_ALL(BINARY, =, Asign)
4043 OPERATOR_ALL(BINARY, +=, AddAsign)
4044 OPERATOR_ALL(BINARY, -=, SubAsign)
4045 OPERATOR_ALL(BINARY, *=, MulAsign)
4046 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4047 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4050 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4051 OPERATOR_INTTYPES(BINARY, |, BitOr)
4052 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4053 OPERATOR_INTTYPES(BINARY, <<, LShift)
4054 OPERATOR_INTTYPES(BINARY, >>, RShift)
4057 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4059 // binary bitwise assignment
4060 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4061 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4062 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4063 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4064 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4066 // unary logical negation
4067 OPERATOR_INTTYPES(UNARY, !, Not)
4069 // binary logical equality
4070 OPERATOR_ALL(BINARY, ==, Equ)
4071 OPERATOR_ALL(BINARY, !=, Nqu)
4074 OPERATOR_ALL(BINARY, &&, And)
4075 OPERATOR_ALL(BINARY, ||, Or)
4077 // binary logical relational
4078 OPERATOR_ALL(BINARY, >, Grt)
4079 OPERATOR_ALL(BINARY, <, Sma)
4080 OPERATOR_ALL(BINARY, >=, GrtEqu)
4081 OPERATOR_ALL(BINARY, <=, SmaEqu)
4083 // tertiary condition operator
4084 OPERATOR_ALL(TERTIARY, ?, Cond)
4086 //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
4087 #define OPERATOR_TABLE_ALL(name, type) \
4088 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4090 type##Inc, type##Dec, \
4091 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4092 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4094 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4096 type##Equ, type##Nqu, \
4097 type##And, type##Or, \
4098 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4101 #define OPERATOR_TABLE_INTTYPES(name, type) \
4102 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4104 type##Inc, type##Dec, \
4105 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4106 null, null, null, null, null, \
4108 null, null, null, null, null, \
4110 type##Equ, type##Nqu, \
4111 type##And, type##Or, \
4112 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4115 OPERATOR_TABLE_ALL(int, Int)
4116 OPERATOR_TABLE_ALL(uint, UInt)
4117 OPERATOR_TABLE_ALL(short, Short)
4118 OPERATOR_TABLE_ALL(ushort, UShort)
4119 OPERATOR_TABLE_INTTYPES(float, Float)
4120 OPERATOR_TABLE_INTTYPES(double, Double)
4121 OPERATOR_TABLE_ALL(char, Char)
4122 OPERATOR_TABLE_ALL(uchar, UChar)
4124 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4125 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4126 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4127 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4128 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4129 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4130 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4131 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4133 public void ReadString(char * output, char * string)
4135 int len = strlen(string);
4137 bool quoted = false, escaped = false;
4138 for(c = 0; c<len; c++)
4140 char ch = string[c];
4145 case 'n': output[d] = '\n'; break;
4146 case 't': output[d] = '\t'; break;
4147 case 'a': output[d] = '\a'; break;
4148 case 'b': output[d] = '\b'; break;
4149 case 'f': output[d] = '\f'; break;
4150 case 'r': output[d] = '\r'; break;
4151 case 'v': output[d] = '\v'; break;
4152 case '\\': output[d] = '\\'; break;
4153 case '\"': output[d] = '\"'; break;
4154 default: output[d++] = '\\'; output[d] = ch;
4155 //default: output[d] = ch;
4176 public Operand GetOperand(Expression exp)
4179 Type type = exp.expType;
4182 while(type.kind == classType &&
4183 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4185 if(!type._class.registered.dataType)
4186 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4187 type = type._class.registered.dataType;
4190 op.kind = type.kind;
4191 op.type = exp.expType;
4192 if(exp.isConstant && exp.type == constantExp)
4198 if(exp.constant[0] == '\'')
4199 op.c = exp.constant[1];
4200 else if(type.isSigned)
4202 op.c = (char)strtol(exp.constant, null, 0);
4207 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4215 op.s = (short)strtol(exp.constant, null, 0);
4220 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4228 op.i = (int)strtol(exp.constant, null, 0);
4233 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4241 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4246 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4252 op.f = (float)strtod(exp.constant, null);
4256 op.d = (double)strtod(exp.constant, null);
4259 //case classType: For when we have operator overloading...
4260 // Pointer additions
4261 //case functionType:
4265 op.p = (unsigned char *)strtoul(exp.constant, null, 0);
4266 op.kind = pointerType;
4276 static void UnusedFunction()
4279 a.OnGetString(0,0,0);
4282 extern int __ecereVMethodID_class_OnGetString;
4285 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4287 DataMember dataMember;
4288 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4290 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4291 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4295 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4297 void * ptr = inst.data + dataMember.offset + offset;
4298 char * result = null;
4299 exp.loc = member.loc = inst.loc;
4300 ((Identifier)member.identifiers->first).loc = inst.loc;
4302 if(!dataMember.dataType)
4303 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4304 type = dataMember.dataType;
4305 if(type.kind == classType)
4307 Class _class = type._class.registered;
4308 if(_class.type == enumClass)
4310 Class enumClass = eSystem_FindClass(privateModule, "enum");
4313 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4315 for(item = e.values.first; item; item = item.next)
4317 if((int)item.data == *(int *)ptr)
4325 exp.identifier = MkIdentifier(result);
4326 exp.type = identifierExp;
4327 exp.destType = MkClassType(_class.fullName);
4328 ProcessExpressionType(exp);
4332 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4334 if(!_class.dataType)
4335 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4336 type = _class.dataType;
4345 FreeExpContents(exp);
4347 exp.constant = PrintFloat(*(float*)ptr);
4348 exp.type = constantExp;
4353 FreeExpContents(exp);
4355 exp.constant = PrintDouble(*(double*)ptr);
4356 exp.type = constantExp;
4361 FreeExpContents(exp);
4363 exp.constant = PrintInt(*(int*)ptr);
4364 exp.type = constantExp;
4369 FreeExpContents(exp);
4371 exp.constant = PrintInt64(*(int64*)ptr);
4372 exp.type = constantExp;
4376 printf("error: unhandled type populating instance\n");
4379 ListAdd(memberList, member);
4382 if(parentDataMember.type == unionMember)
4387 void PopulateInstance(Instantiation inst)
4389 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4390 Class _class = classSym.registered;
4391 DataMember dataMember;
4392 OldList * memberList = MkList();
4393 inst.members = MkListOne(MkMembersInitList(memberList));
4394 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4396 if(!dataMember.isProperty)
4398 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4399 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4403 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4405 void * ptr = inst.data + dataMember.offset;
4406 char * result = null;
4408 exp.loc = member.loc = inst.loc;
4409 ((Identifier)member.identifiers->first).loc = inst.loc;
4411 if(!dataMember.dataType)
4412 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4413 type = dataMember.dataType;
4414 if(type.kind == classType)
4416 Class _class = type._class.registered;
4417 if(_class.type == enumClass)
4419 Class enumClass = eSystem_FindClass(privateModule, "enum");
4422 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4424 for(item = e.values.first; item; item = item.next)
4426 if((int)item.data == *(int *)ptr)
4435 exp.identifier = MkIdentifier(result);
4436 exp.type = identifierExp;
4437 exp.destType = MkClassType(_class.fullName);
4438 ProcessExpressionType(exp);
4441 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4443 if(!_class.dataType)
4444 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4445 type = _class.dataType;
4454 exp.constant = PrintFloat(*(float*)ptr);
4455 exp.type = constantExp;
4460 exp.constant = PrintDouble(*(double*)ptr);
4461 exp.type = constantExp;
4466 exp.constant = PrintInt(*(int*)ptr);
4467 exp.type = constantExp;
4472 exp.constant = PrintInt64(*(int64*)ptr);
4473 exp.type = constantExp;
4477 printf("error: unhandled type populating instance\n");
4480 ListAdd(memberList, member);
4486 void ComputeInstantiation(Expression exp)
4488 Instantiation inst = exp.instance;
4489 MembersInit members;
4490 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4491 Class _class = classSym ? classSym.registered : null;
4492 DataMember curMember = null;
4493 Class curClass = null;
4494 DataMember subMemberStack[256];
4495 int subMemberStackPos = 0;
4498 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4500 // Don't recompute the instantiation...
4501 // Non Simple classes will have become constants by now
4505 if(_class.type == normalClass || _class.type == noHeadClass)
4506 inst.data = (byte *)eInstance_New(_class);
4508 inst.data = new0 byte[_class.structSize];
4513 for(members = inst.members->first; members; members = members.next)
4515 switch(members.type)
4517 case dataMembersInit:
4519 if(members.dataMembers)
4522 for(member = members.dataMembers->first; member; member = member.next)
4524 Identifier ident = member.identifiers ? member.identifiers->first : null;
4527 Property prop = null;
4528 DataMember dataMember = null;
4529 Method method = null;
4530 uint dataMemberOffset;
4534 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4537 if(curMember.isProperty)
4538 prop = (Property)curMember;
4541 dataMember = curMember;
4543 // CHANGED THIS HERE
4544 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4545 // dataMemberOffset = dataMember.offset;
4552 prop = eClass_FindProperty(_class, ident.string, privateModule);
4556 if(prop.memberAccess == publicAccess)
4558 curMember = (DataMember)prop;
4559 curClass = prop._class;
4564 DataMember _subMemberStack[256];
4565 int _subMemberStackPos = 0;
4567 // FILL MEMBER STACK
4568 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4573 if(dataMember.memberAccess == publicAccess)
4575 curMember = dataMember;
4576 curClass = dataMember._class;
4577 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
4578 subMemberStackPos = _subMemberStackPos;
4584 if(found && member.initializer && member.initializer.type == expInitializer)
4586 Expression value = member.initializer.exp;
4590 type = prop.dataType;
4594 if(!dataMember.dataType)
4595 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4597 type = dataMember.dataType;
4600 if(ident && ident.next)
4602 // for(; ident && type; ident = ident.next)
4603 for(ident = ident.next; ident && type; ident = ident.next)
4605 if(type.kind == classType)
4607 prop = eClass_FindProperty(type._class.registered,
4608 ident.string, privateModule);
4610 type = prop.dataType;
4613 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4614 ident.string, &dataMemberOffset, privateModule, null, null);
4616 type = dataMember.dataType;
4619 else if(type.kind == structType || type.kind == unionType)
4622 for(memberType = type.members.first; memberType; memberType = memberType.next)
4624 if(!strcmp(memberType.name, ident.string))
4635 FreeType(value.destType);
4636 value.destType = type;
4637 if(type) type.refCount++;
4638 ComputeExpression(value);
4640 if(value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4642 if(type.kind == classType)
4644 Class _class = type._class.registered;
4645 if(_class.type == bitClass || _class.type == unitClass ||
4646 _class.type == enumClass)
4648 if(!_class.dataType)
4649 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4650 type = _class.dataType;
4656 void * ptr = inst.data + dataMemberOffset;
4658 if(value.type == constantExp)
4664 GetInt(value, (int*)ptr);
4669 GetInt64(value, (int64*)ptr);
4674 GetFloat(value, (float*)ptr);
4679 GetDouble(value, (double *)ptr);
4684 else if(value.type == instanceExp)
4686 if(type.kind == classType)
4688 Class _class = type._class.registered;
4689 if(_class.type == structClass)
4691 ComputeTypeSize(type);
4692 if(value.instance.data)
4693 memcpy(ptr, value.instance.data, type.size);
4700 if(value.type == instanceExp && value.instance.data)
4702 void (*Set)(void *, void *) = (void *)prop.Set;
4703 Set(inst.data, value.instance.data);
4704 PopulateInstance(inst);
4706 else if(value.type == constantExp)
4712 void (*Set)(void *, double) = (void *)prop.Set;
4713 Set(inst.data, strtod(value.constant, null) );
4718 void (*Set)(void *, float) = (void *)prop.Set;
4719 Set(inst.data, (float)(strtod(value.constant, null)));
4724 void (*Set)(void *, int) = (void *)prop.Set;
4725 Set(inst.data, strtol(value.constant, null, 0));
4730 void (*Set)(void *, int64) = (void *)prop.Set;
4731 Set(inst.data, _strtoi64(value.constant, null, 0));
4736 else if(value.type == stringExp)
4739 ReadString(temp, value.string);
4740 prop.Set(inst.data, temp);
4744 else if(_class.type == unitClass)
4748 // Only support converting units to units for now...
4749 if(value.type == constantExp)
4751 if(type.kind == classType)
4753 Class _class = type._class.registered;
4754 if(_class.type == unitClass)
4756 if(!_class.dataType)
4757 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4758 type = _class.dataType;
4761 // TODO: Assuming same base type for units...
4767 float (*Set)(float) = (void *)prop.Set;
4768 GetFloat(member.initializer.exp, &fValue);
4769 exp.constant = PrintFloat(Set(fValue));
4770 exp.type = constantExp;
4776 double (*Set)(double) = (void *)prop.Set;
4777 GetDouble(member.initializer.exp, &dValue);
4778 exp.constant = PrintDouble(Set(dValue));
4779 exp.type = constantExp;
4786 else if(_class.type == bitClass)
4790 if(value.type == instanceExp && value.instance.data)
4792 unsigned int (*Set)(void *) = (void *)prop.Set;
4793 bits = Set(value.instance.data);
4795 else if(value.type == constantExp)
4801 BitMember bitMember = (BitMember) dataMember;
4804 GetInt(value, &part);
4805 bits = (bits & ~bitMember.mask);
4806 if(!bitMember.dataType)
4807 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4809 type = bitMember.dataType;
4811 if(type.kind == classType && type._class && type._class.registered)
4813 if(!type._class.registered.dataType)
4814 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4815 type = type._class.registered.dataType;
4822 bits |= ((char)part << bitMember.pos);
4824 bits |= ((unsigned char)part << bitMember.pos);
4828 bits |= ((short)part << bitMember.pos);
4830 bits |= ((unsigned short)part << bitMember.pos);
4835 bits |= ((int)part << bitMember.pos);
4837 bits |= ((unsigned int)part << bitMember.pos);
4841 bits |= ((int64)part << bitMember.pos);
4843 bits |= ((uint64)part << bitMember.pos);
4851 if(_class && _class.type == unitClass)
4853 ComputeExpression(member.initializer.exp);
4854 exp.constant = member.initializer.exp.constant;
4855 exp.type = constantExp;
4857 member.initializer.exp.constant = null;
4867 if(_class && _class.type == bitClass)
4869 exp.constant = PrintHexUInt(bits);
4870 exp.type = constantExp;
4872 if(exp.type != instanceExp)
4878 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4880 if(exp.op.op == SIZEOF)
4882 FreeExpContents(exp);
4883 exp.type = constantExp;
4884 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
4895 // Provide default unary +
4896 Expression exp2 = exp.op.exp2;
4898 FreeExpContents(exp);
4899 FreeType(exp.expType);
4900 FreeType(exp.destType);
4906 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
4908 // unary arithmetic increment and decrement
4909 //OPERATOR_ALL(UNARY, ++, Inc)
4910 //OPERATOR_ALL(UNARY, --, Dec)
4913 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
4915 // unary logical negation
4917 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
4925 // binary arithmetic
4927 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
4930 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
4933 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
4936 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
4939 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
4941 // binary arithmetic assignment
4942 //OPERATOR_ALL(BINARY, =, Asign)
4943 //OPERATOR_ALL(BINARY, +=, AddAsign)
4944 //OPERATOR_ALL(BINARY, -=, SubAsign)
4945 //OPERATOR_ALL(BINARY, *=, MulAsign)
4946 //OPERATOR_ALL(BINARY, /=, DivAsign)
4947 //OPERATOR_ALL(BINARY, %=, ModAsign)
4952 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
4956 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
4959 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
4962 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
4965 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
4967 // binary bitwise assignment
4968 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4969 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4970 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4971 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4972 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4973 // binary logical equality
4975 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
4978 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
4982 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
4985 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
4987 // binary logical relational
4989 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
4992 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
4995 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
4998 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5005 void ComputeExpression(Expression exp)
5007 char expString[10240];
5008 expString[0] = '\0';
5010 PrintExpression(exp, expString);
5017 ComputeInstantiation(exp);
5026 Expression exp1, exp2 = null;
5030 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5032 ComputeExpression(exp.op.exp2);
5035 ComputeExpression(exp.op.exp1);
5038 op1 = GetOperand(exp1);
5039 if(op1.type) op1.type.refCount++;
5042 op2 = GetOperand(exp2);
5043 if(op2.type) op2.type.refCount++;
5049 op1 = GetOperand(exp1);
5050 if(op1.type) op1.type.refCount++;
5053 CallOperator(exp, exp1, exp2, op1, op2);
5060 if(exp.op.exp1 && exp.op.exp2)
5065 FreeExpContents(exp);
5066 op1.ops.BitAnd(exp, op1, op2);
5075 FreeExpContents(exp);
5076 op1.ops.Mul(exp, op1, op2);
5085 FreeExpContents(exp);
5086 op1.ops.Add(exp, op1, op2);
5091 // Provide default unary +
5092 Expression exp2 = exp.op.exp2;
5094 FreeExpContents(exp);
5095 FreeType(exp.expType);
5096 FreeType(exp.destType);
5107 FreeExpContents(exp);
5108 op1.ops.Sub(exp, op1, op2);
5115 FreeExpContents(exp);
5116 op1.ops.Neg(exp, op1);
5123 FreeExpContents(exp);
5124 op1.ops.BitNot(exp, op1);
5130 FreeExpContents(exp);
5131 op1.ops.Not(exp, op1);
5134 // Binary only operators
5138 FreeExpContents(exp);
5139 op1.ops.Div(exp, op1, op2);
5145 FreeExpContents(exp);
5146 op1.ops.Mod(exp, op1, op2);
5158 FreeExpContents(exp);
5159 op1.ops.Sma(exp, op1, op2);
5168 FreeExpContents(exp);
5169 op1.ops.Grt(exp, op1, op2);
5178 FreeExpContents(exp);
5179 op1.ops.SmaEqu(exp, op1, op2);
5188 FreeExpContents(exp);
5189 op1.ops.GrtEqu(exp, op1, op2);
5198 FreeExpContents(exp);
5199 op1.ops.Equ(exp, op1, op2);
5208 FreeExpContents(exp);
5209 op1.ops.Nqu(exp, op1, op2);
5216 FreeExpContents(exp);
5217 op1.ops.BitOr(exp, op1, op2);
5223 FreeExpContents(exp);
5224 op1.ops.BitXor(exp, op1, op2);
5232 FreeExpContents(exp);
5233 exp.type = constantExp;
5234 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5238 if(op1.type) FreeType(op1.type);
5239 if(op2.type) FreeType(op2.type);
5243 case extensionExpressionExp:
5246 for(e = exp.list->first; e; e = n)
5251 OldList * list = exp.list;
5252 ComputeExpression(e);
5253 //FreeExpContents(exp);
5254 FreeType(exp.expType);
5255 FreeType(exp.destType);
5272 exp.isConstant = true;
5274 ComputeExpression(exp.index.exp);
5275 if(!exp.index.exp.isConstant)
5276 exp.isConstant = false;
5278 for(e = exp.index.index->first; e; e = e.next)
5280 ComputeExpression(e);
5283 // Check if this type is int
5286 exp.isConstant = false;
5288 exp.expType = Dereference(exp.index.exp.expType);
5294 Expression memberExp = exp.member.exp;
5295 Identifier memberID = exp.member.member;
5298 ComputeExpression(exp.member.exp);
5299 type = exp.member.exp.expType;
5302 Class _class = (exp.member.member && exp.member.member.classSym) ? exp.member.member.classSym.registered : (((type.kind == classType || type.kind == subClassType) && type._class) ? type._class.registered : null);
5303 Property prop = null;
5304 DataMember member = null;
5305 Class convertTo = null;
5306 if(type.kind == subClassType && exp.member.exp.type == classExp)
5307 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5314 PrintType(type, string, false, true);
5315 classSym = FindClass(string);
5316 _class = classSym ? classSym.registered : null;
5319 if(exp.member.member)
5321 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5323 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5325 if(!prop && !member && _class && exp.member.member)
5327 Symbol classSym = FindClass(exp.member.member.string);
5329 _class = classSym ? classSym.registered : null;
5330 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5337 Type type = prop.dataType;
5338 // TODO: Assuming same base type for units...
5339 if(_class.type == unitClass)
5341 if(type.kind == classType)
5343 Class _class = type._class.registered;
5344 if(_class.type == unitClass)
5346 if(!_class.dataType)
5347 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5348 type = _class.dataType;
5356 float (*Get)(float) = (void *)prop.Get;
5357 GetFloat(exp.member.exp, &value);
5358 exp.constant = PrintFloat(Get ? Get(value) : value);
5359 exp.type = constantExp;
5365 double (*Get)(double);
5366 GetDouble(exp.member.exp, &value);
5369 Get = (void *)prop.Set;
5371 Get = (void *)prop.Get;
5372 exp.constant = PrintDouble(Get ? Get(value) : value);
5373 exp.type = constantExp;
5382 Expression value = exp.member.exp;
5385 ProcessPropertyType(prop);
5387 type = prop.dataType;
5390 // printf("Investigate this\n");
5392 else if(_class.type == structClass)
5398 Class propertyClass = type._class.registered;
5399 if(propertyClass.type == structClass && value.type == instanceExp)
5401 void (*Set)(void *, void *) = (void *)prop.Set;
5402 exp.instance = Instantiation { };
5403 exp.instance.data = new0 byte[_class.structSize];
5404 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5405 exp.instance.loc = exp.loc;
5406 exp.type = instanceExp;
5407 Set(exp.instance.data, value.instance.data);
5408 PopulateInstance(exp.instance);
5415 void (*Set)(void *, int) = (void *)prop.Set;
5417 exp.instance = Instantiation { };
5418 exp.instance.data = new0 byte[_class.structSize];
5419 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5420 exp.instance.loc = exp.loc;
5421 exp.type = instanceExp;
5423 GetInt(value, &intValue);
5425 Set(exp.instance.data, intValue);
5426 PopulateInstance(exp.instance);
5432 void (*Set)(void *, int64) = (void *)prop.Set;
5434 exp.instance = Instantiation { };
5435 exp.instance.data = new0 byte[_class.structSize];
5436 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5437 exp.instance.loc = exp.loc;
5438 exp.type = instanceExp;
5440 GetInt64(value, &intValue);
5442 Set(exp.instance.data, intValue);
5443 PopulateInstance(exp.instance);
5449 void (*Set)(void *, double) = (void *)prop.Set;
5451 exp.instance = Instantiation { };
5452 exp.instance.data = new0 byte[_class.structSize];
5453 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5454 exp.instance.loc = exp.loc;
5455 exp.type = instanceExp;
5457 GetDouble(value, &doubleValue);
5459 Set(exp.instance.data, doubleValue);
5460 PopulateInstance(exp.instance);
5465 else if(_class.type == bitClass)
5471 Class propertyClass = type._class.registered;
5472 if(propertyClass.type == structClass && value.instance.data)
5474 unsigned int (*Set)(void *) = (void *)prop.Set;
5475 unsigned int bits = Set(value.instance.data);
5476 exp.constant = PrintHexUInt(bits);
5477 exp.type = constantExp;
5480 else if(_class.type == bitClass)
5483 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5486 GetUInt(exp.member.exp, &value);
5488 exp.constant = PrintHexUInt(bits);
5489 exp.type = constantExp;
5497 if(_class.type == bitClass)
5500 GetUInt(exp.member.exp, &value);
5506 Class _class = type._class.registered;
5507 if(_class.type == structClass)
5509 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5511 exp.instance = Instantiation { };
5512 exp.instance.data = new0 byte[_class.structSize];
5513 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5514 exp.instance.loc = exp.loc;
5515 //exp.instance.fullSet = true;
5516 exp.type = instanceExp;
5517 Get(value, exp.instance.data);
5518 PopulateInstance(exp.instance);
5520 else if(_class.type == bitClass)
5522 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5523 uint64 bits = Get(value);
5524 exp.constant = PrintHexUInt64(bits);
5525 exp.type = constantExp;
5531 else if(_class.type == structClass)
5533 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5538 Class _class = type._class.registered;
5539 if(_class.type == structClass && value)
5541 void (*Get)(void *, void *) = (void *)prop.Get;
5543 exp.instance = Instantiation { };
5544 exp.instance.data = new0 byte[_class.structSize];
5545 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5546 exp.instance.loc = exp.loc;
5547 //exp.instance.fullSet = true;
5548 exp.type = instanceExp;
5549 Get(value, exp.instance.data);
5550 PopulateInstance(exp.instance);
5558 char * value = exp.member.exp.instance.data;
5563 Class _class = type._class.registered;
5564 if(_class.type == normalClass)
5566 void *(*Get)(void *) = (void *)prop.Get;
5568 exp.instance = Instantiation { };
5569 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5570 exp.type = instanceExp;
5571 exp.instance.data = Get(value, exp.instance.data);
5583 exp.isConstant = false;
5591 if(exp.type != ExpressionType::memberExp)
5593 FreeExpression(memberExp);
5594 FreeIdentifier(memberID);
5600 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5601 FreeExpContents(exp);
5602 exp.constant = PrintUInt(ComputeTypeSize(type));
5603 exp.type = constantExp;
5609 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5610 if(classSym && classSym.registered)
5612 if(classSym.registered.fixed)
5614 FreeSpecifier(exp._class);
5615 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5616 exp.type = constantExp;
5620 char className[1024];
5621 strcpy(className, "__ecereClass_");
5622 FullClassNameCat(className, classSym.string, true);
5623 MangleClassName(className);
5625 FreeExpContents(exp);
5626 exp.type = pointerExp;
5627 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5628 exp.member.member = MkIdentifier("structSize");
5638 if(exp.type == castExp)
5641 ComputeExpression(exp.cast.exp);
5644 if(e && exp.expType)
5647 type = exp.destType;
5650 if(type.kind == classType)
5652 Class _class = type._class.registered;
5653 if(_class && (_class.type == unitClass || _class.type == bitClass))
5655 if(!_class.dataType)
5656 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5657 type = _class.dataType;
5668 FreeExpContents(exp);
5669 exp.constant = PrintChar(value);
5670 exp.type = constantExp;
5674 unsigned char value;
5675 GetUChar(e, &value);
5676 FreeExpContents(exp);
5677 exp.constant = PrintUChar(value);
5678 exp.type = constantExp;
5685 GetShort(e, &value);
5686 FreeExpContents(exp);
5687 exp.constant = PrintShort(value);
5688 exp.type = constantExp;
5692 unsigned short value;
5693 GetUShort(e, &value);
5694 FreeExpContents(exp);
5695 exp.constant = PrintUShort(value);
5696 exp.type = constantExp;
5704 FreeExpContents(exp);
5705 exp.constant = PrintInt(value);
5706 exp.type = constantExp;
5712 FreeExpContents(exp);
5713 exp.constant = PrintUInt(value);
5714 exp.type = constantExp;
5721 GetInt64(e, &value);
5722 FreeExpContents(exp);
5723 exp.constant = PrintInt64(value);
5724 exp.type = constantExp;
5729 GetUInt64(e, &value);
5730 FreeExpContents(exp);
5731 exp.constant = PrintUInt64(value);
5732 exp.type = constantExp;
5738 GetFloat(e, &value);
5739 FreeExpContents(exp);
5740 exp.constant = PrintFloat(value);
5741 exp.type = constantExp;
5747 GetDouble(e, &value);
5748 FreeExpContents(exp);
5749 exp.constant = PrintDouble(value);
5750 exp.type = constantExp;
5764 // Caring only about last expression for now...
5765 ComputeExpression(exp.cond.exp->last);
5766 if(exp.cond.elseExp)
5767 ComputeExpression(exp.cond.elseExp);
5769 ComputeExpression(exp.cond.cond);
5771 op1 = GetOperand(exp.cond.cond);
5772 if(op1.type) op1.type.refCount++;
5773 op2 = GetOperand(exp.cond.exp->last);
5774 if(op2.type) op2.type.refCount++;
5775 op3 = GetOperand(exp.cond.elseExp);
5776 if(op3.type) op3.type.refCount++;
5778 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5779 if(op1.type) FreeType(op1.type);
5780 if(op2.type) FreeType(op2.type);
5781 if(op3.type) FreeType(op3.type);
5787 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5792 OldList converts { };
5795 if(destType.kind == voidType)
5798 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5802 // for(convert = converts.last; convert; convert = convert.prev)
5803 for(convert = converts.first; convert; convert = convert.next)
5805 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
5808 Expression newExp { };
5809 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
5811 // TODO: Check this...
5813 newExp.destType = null;
5818 exp.type = memberExp;
5819 exp.addedThis = true;
5820 exp.member.exp = newExp;
5821 FreeType(exp.member.exp.expType);
5823 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
5824 exp.member.exp.expType.classObjectType = objectType;
5825 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
5826 exp.member.memberType = propertyMember;
5827 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5828 // TESTING THIS... for (int)degrees
5829 exp.needCast = true;
5830 if(exp.expType) exp.expType.refCount++;
5831 ApplyAnyObjectLogic(exp.member.exp);
5836 /*if(exp.isConstant)
5838 // Color { ColorRGB = [exp] };
5839 exp.type = instanceExp;
5840 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
5841 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
5842 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
5846 // If not constant, don't turn it yet into an instantiation
5847 // (Go through the deep members system first)
5848 exp.type = memberExp;
5849 exp.addedThis = true;
5850 exp.member.exp = newExp;
5852 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
5853 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
5854 newExp.expType._class.registered.type == noHeadClass)
5856 newExp.byReference = true;
5859 FreeType(exp.member.exp.expType);
5860 /*exp.member.exp.expType = convert.convert.dataType;
5861 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
5862 exp.member.exp.expType = null;
5863 if(convert.convert.dataType)
5865 exp.member.exp.expType = { };
5866 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
5867 exp.member.exp.expType.refCount = 1;
5868 exp.member.exp.expType.classObjectType = objectType;
5869 ApplyAnyObjectLogic(exp.member.exp);
5872 exp.member.member = MkIdentifier(convert.convert._class.fullName);
5873 exp.member.memberType = reverseConversionMember;
5874 exp.expType = convert.resultType ? convert.resultType :
5875 MkClassType(convert.convert._class.fullName);
5876 exp.needCast = true;
5877 if(convert.resultType) convert.resultType.refCount++;
5883 FreeType(exp.expType);
5886 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5887 exp.needCast = true;
5888 if(exp.expType) exp.expType.refCount++;
5892 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
5893 exp.needCast = true;
5894 if(convert.resultType)
5895 convert.resultType.refCount++;
5899 if(exp.isConstant && inCompiler)
5900 ComputeExpression(exp);
5902 converts.Free(FreeConvert);
5905 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
5907 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
5909 if(!result && exp.expType && exp.destType)
5911 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
5912 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
5913 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
5914 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
5918 // if(result) CheckTemplateTypes(exp);
5922 void CheckTemplateTypes(Expression exp)
5924 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
5926 Expression newExp { };
5930 if(exp.destType) exp.destType.refCount++;
5931 if(exp.expType) exp.expType.refCount++;
5935 switch(exp.expType.kind)
5940 context = PushContext();
5941 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
5942 MkExpExtensionCompound(compound = MkCompoundStmt(
5943 MkListOne(MkDeclaration(MkListOne(MkSpecifier(DOUBLE)),
5944 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal")), MkInitializerAssignment(newExp))))),
5945 MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internal")))))))));
5946 compound.compound.context = context;
5947 PopContext(context);
5952 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
5953 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
5957 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
5959 Expression newExp { };
5963 if(exp.destType) exp.destType.refCount++;
5964 if(exp.expType) exp.expType.refCount++;
5968 switch(exp.expType.kind)
5973 context = PushContext();
5974 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifier(DOUBLE)), MkDeclaratorPointer(MkPointer(null, null), null)),
5975 MkExpExtensionCompound(compound = MkCompoundStmt(
5976 MkListOne(MkDeclaration(MkListOne(MkSpecifierName("uint64")),
5977 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal")), MkInitializerAssignment(newExp))))),
5978 MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internal")))))))));
5979 compound.compound.context = context;
5980 PopContext(context);
5982 ProcessExpressionType(exp.op.exp2);
5986 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
5988 exp.type = bracketsExp;
5989 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
5990 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
5991 ProcessExpressionType(exp.list->first);
5996 exp.type = bracketsExp;
5997 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
5998 newExp.needCast = true;
5999 ProcessExpressionType(exp.list->first);
6005 if(exp.expType.kind == templateType)
6007 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6010 FreeType(exp.destType);
6011 FreeType(exp.expType);
6016 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6021 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6022 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6026 char typeString[1024];
6028 OldList * specs = MkList();
6029 typeString[0] = '\0';
6030 PrintType(exp.expType, typeString, false, false);
6031 decl = SpecDeclFromString(typeString, specs, null);
6034 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6035 exp.cast.typeName = MkTypeName(specs, decl);
6036 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6037 exp.cast.exp.needCast = true;
6045 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6048 int nsLen = strlen(nameSpace);
6049 for(symbol = (Symbol)tree.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6051 if(!strncmp(symbol.string, nameSpace, nsLen))
6055 for(c = strlen(symbol.string)-1; c >= 0; c--)
6056 if(symbol.string[c] == ':')
6059 namePart = symbol.string+c+1;
6060 if(!strcmp(namePart, name))
6062 // TODO: Error on ambiguity
6070 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6073 char nameSpace[1024];
6075 bool gotColon = false;
6077 nameSpace[0] = '\0';
6078 for(c = strlen(name)-1; c >= 0; c--)
6085 namePart = name+c+1;
6086 while(c >= 0 && name[c] == ':') c--;
6089 memcpy(nameSpace, name, c + 1);
6091 return ScanWithNameSpace(tree, nameSpace, namePart);
6095 Symbol symbol = (Symbol)tree.FindString(namePart);
6099 return ScanWithNameSpace(tree, "", namePart);
6103 static void ProcessDeclaration(Declaration decl);
6105 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6108 //Time startTime = GetTime();
6110 // Optimize this later? Do this before/less?
6112 Symbol symbol = null;
6113 // First, check if the identifier is declared inside the function
6114 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6116 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6118 if(ctx == globalContext && !globalNameSpace)
6124 strcpy(curName, thisNameSpace);
6125 strcat(curName, "::");
6126 strcat(curName, name);
6127 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6130 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6133 symbol = (Symbol)ctx.structSymbols.FindString(name);
6135 symbol = (Symbol)ctx.symbols.FindString(name);
6137 if(symbol || ctx == endContext) break;
6139 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6141 if(symbol.pointerExternal.type == functionExternal)
6143 FunctionDefinition function = symbol.pointerExternal.function;
6145 // Modified this recently...
6146 Context tmpContext = curContext;
6148 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6149 curContext = tmpContext;
6151 symbol.pointerExternal.symbol = symbol;
6154 DeclareType(symbol.type, true, true);
6156 ast->Insert(curExternal.prev, symbol.pointerExternal);
6158 symbol.id = curExternal.symbol.idCode;
6161 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6163 ast->Move(symbol.pointerExternal, curExternal.prev);
6164 symbol.id = curExternal.symbol.idCode;
6168 //findSymbolTotalTime += GetTime() - startTime;
6173 static void GetTypeSpecs(Type type, OldList * specs)
6175 if(!type.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
6180 if(type._class.registered)
6182 if(!type._class.registered.dataType)
6183 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6184 GetTypeSpecs(type._class.registered.dataType, specs);
6188 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6189 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6190 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6191 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6192 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6195 ListAdd(specs, MkSpecifier(INT)); break;
6199 // WARNING : This function expects a null terminated string since it recursively concatenate...
6200 static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
6207 if(type._class && type._class.string)
6209 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6210 // look into merging with thisclass ?
6211 if(type.classObjectType == typedObject)
6212 strcat(string, "typed_object");
6214 strcat(string, type._class.string);
6217 if(type._class.registered)
6218 strcat(string, type._class.registered.name);
6220 strcat(string, type._class.string);
6227 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6228 if(funcType && funcType.kind == functionType)
6231 PrintType(funcType.returnType, string, false, fullName);
6232 strcat(string, "(*");
6233 if(printName || funcType.thisClass)
6235 strcat(string, " ");
6236 if(funcType.thisClass)
6238 strcat(string, funcType.thisClass.string);
6239 strcat(string, "::");
6242 strcat(string, type.name);
6244 strcat(string, ")(");
6245 for(param = funcType.params.first; param; param = param.next)
6247 PrintType(param, string, false, fullName);
6248 if(param.next) strcat(string, ", ");
6250 strcat(string, ")");
6254 _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
6255 strcat(string, " *");
6259 case voidType: strcat(string, "void"); break;
6260 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6261 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6262 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6263 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6264 case floatType: strcat(string, "float"); break;
6265 case doubleType: strcat(string, "double"); break;
6269 strcat(string, "struct ");
6270 strcat(string, type.enumName);
6272 else if(type.typeName)
6274 strcat(string, type.typeName);
6279 strcat(string, "struct ");
6280 strcat(string,"(unnamed)");
6283 strcat(string, "struct {");
6284 for(member = type.members.first; member; member = member.next)
6286 PrintType(member, string, true, fullName);
6287 strcat(string,"; ");
6295 strcat(string, "union ");
6296 strcat(string, type.enumName);
6298 else if(type.typeName)
6300 strcat(string, type.typeName);
6304 strcat(string, "union ");
6305 strcat(string,"(unnamed)");
6311 strcat(string, "enum ");
6312 strcat(string, type.enumName);
6314 else if(type.typeName)
6316 strcat(string, type.typeName);
6319 strcat(string, "enum");
6326 strcat(string, "dllexport ");
6327 PrintType(type.returnType, string, false, fullName);
6328 strcat(string, " ");
6331 // DANGER: Testing This
6337 strcat(string, type.name);
6340 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6341 if(name) name += 2; else name = type.name;
6342 strcat(string, name);
6356 strcat(string, "(");
6357 for(param = type.params.first; param; param = param.next)
6359 PrintType(param, string, true, fullName);
6360 if(param.next) strcat(string, ", ");
6362 strcat(string, ")");
6369 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6370 if(funcType && funcType.kind == functionType)
6373 PrintType(funcType.returnType, string, false, fullName);
6374 strcat(string, "(*");
6375 if(printName || funcType.thisClass)
6377 strcat(string, " ");
6378 if(funcType.thisClass)
6380 strcat(string, funcType.thisClass.string);
6381 strcat(string, "::");
6384 strcat(string, type.name);
6386 strcat(string, ")(");
6387 for(param = funcType.params.first; param; param = param.next)
6389 PrintType(param, string, false, fullName);
6390 if(param.next) strcat(string, ", ");
6392 strcat(string, ")");
6396 char baseType[1024], size[256];
6397 Type arrayType = type;
6401 while(arrayType.kind == TypeKind::arrayType)
6404 if(arrayType.enumClass)
6405 strcat(size, arrayType.enumClass.string);
6406 else if(arrayType.arraySizeExp)
6407 PrintExpression(arrayType.arraySizeExp, size);
6408 //sprintf(string, "%s[%s]", baseType, size);
6411 arrayType = arrayType.arrayType;
6413 _PrintType(arrayType, baseType, printName, printFunction, fullName);
6414 strcat(string, baseType);
6415 strcat(string, size);
6419 PrintType(type.arrayType, baseType, printName, fullName);
6421 strcpy(size, type.enumClass.string);
6422 else if(type.arraySizeExp)
6423 PrintExpression(type.arraySizeExp, size);
6424 //sprintf(string, "%s[%s]", baseType, size);
6425 strcat(string, baseType);
6426 strcat(string, "[");
6427 strcat(string, size);
6428 strcat(string, "]");
6435 strcat(string, "...");
6438 _PrintType(type.method.dataType, string, false, printFunction, fullName);
6441 strcat(string, "subclass(");
6442 strcat(string, type._class ? type._class.string : "int");
6443 strcat(string, ")");
6446 strcat(string, type.templateParameter.identifier.string);
6449 strcat(string, "thisclass");
6452 strcat(string, "__builtin_va_list");
6459 if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
6461 strcat(string, " ");
6462 strcat(string, type.name);
6467 void PrintType(Type type, char * string, bool printName, bool fullName)
6470 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6471 if(funcType && funcType.kind == functionType && type != funcType)
6473 char typeString[1024];
6476 PrintType(funcType.returnType, string, false, fullName);
6477 strcat(string, "(");
6478 _PrintType(type, string, printName, false, fullName);
6479 strcat(string, ")");
6482 strcat(string, type.name);
6488 strcat(string, "(");
6489 for(param = funcType.params.first; param; param = param.next)
6491 PrintType(param, string, true, fullName);
6492 if(param.next) strcat(string, ", ");
6494 strcat(string, ")");
6497 _PrintType(type, string, printName, true, fullName);
6498 if(type.bitFieldCount)
6501 sprintf(count, ":%d", type.bitFieldCount);
6502 strcat(string, count);
6506 static Type FindMember(Type type, char * string)
6509 for(memberType = type.members.first; memberType; memberType = memberType.next)
6511 if(!memberType.name)
6513 Type subType = FindMember(memberType, string);
6517 else if(!strcmp(memberType.name, string))
6523 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6526 for(memberType = type.members.first; memberType; memberType = memberType.next)
6528 if(!memberType.name)
6530 Type subType = FindMember(memberType, string);
6533 *offset += memberType.offset;
6537 else if(!strcmp(memberType.name, string))
6539 *offset += memberType.offset;
6546 Expression ParseExpressionString(char * expression)
6548 fileInput = TempFile { };
6549 fileInput.Write(expression, 1, strlen(expression));
6550 fileInput.Seek(0, start);
6553 parsedExpression = null;
6555 expression_yyparse();
6558 return parsedExpression;
6561 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6563 Identifier id = exp.identifier;
6564 Method method = null;
6565 Property prop = null;
6566 DataMember member = null;
6567 ClassProperty classProp = null;
6569 if(_class && _class.type == enumClass)
6571 NamedLink value = null;
6572 Class enumClass = eSystem_FindClass(privateModule, "enum");
6576 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6578 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6579 for(value = e.values.first; value; value = value.next)
6581 if(!strcmp(value.name, id.string))
6588 FreeExpContents(exp);
6590 exp.type = constantExp;
6591 exp.isConstant = true;
6592 if(!strcmp(baseClass.dataTypeString, "int"))
6593 sprintf(constant, "%d",value.data);
6595 sprintf(constant, "0x%X",value.data);
6596 exp.constant = CopyString(constant);
6597 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6598 exp.expType = MkClassType(baseClass.fullName);
6606 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6608 ProcessMethodType(method);
6615 // TOCHECK: Put it back to what it was...
6616 // methodClass = _class;
6617 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6622 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6625 ProcessPropertyType(prop);
6626 exp.expType = prop.dataType;
6627 if(prop.dataType) prop.dataType.refCount++;
6630 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6632 if(!member.dataType)
6633 member.dataType = ProcessTypeString(member.dataTypeString, false);
6634 exp.expType = member.dataType;
6635 if(member.dataType) member.dataType.refCount++;
6638 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6640 if(!classProp.dataType)
6641 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6643 if(classProp.constant)
6645 FreeExpContents(exp);
6647 exp.isConstant = true;
6648 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6650 //char constant[256];
6651 exp.type = stringExp;
6652 exp.constant = QMkString((char *)classProp.Get(_class));
6657 exp.type = constantExp;
6658 sprintf(constant, "%d",classProp.Get(_class));
6659 exp.constant = CopyString(constant);
6667 exp.expType = classProp.dataType;
6668 if(classProp.dataType) classProp.dataType.refCount++;
6674 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6676 BinaryTree * tree = &nameSpace.functions;
6677 GlobalData data = (GlobalData)tree->FindString(name);
6681 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6683 data = ScanGlobalData(child, name);
6691 static GlobalData FindGlobalData(char * name)
6694 NameSpace * nameSpace;
6695 nameSpace = globalData;
6696 for(c = 0; name[c]; c++)
6698 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6700 NameSpace * newSpace;
6701 char * spaceName = new char[c - start + 1];
6702 strncpy(spaceName, name + start, c - start);
6703 spaceName[c-start] = '\0';
6704 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6708 nameSpace = newSpace;
6709 if(name[c] == ':') c++;
6715 return ScanGlobalData(nameSpace, name + start);
6720 static int definedExpStackPos;
6721 static void * definedExpStack[512];
6723 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6724 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6726 Expression prev = checkedExp.prev, next = checkedExp.next;
6728 FreeExpContents(checkedExp);
6729 FreeType(checkedExp.expType);
6730 FreeType(checkedExp.destType);
6732 *checkedExp = *newExp;
6736 checkedExp.prev = prev;
6737 checkedExp.next = next;
6740 void ApplyAnyObjectLogic(Expression e)
6742 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6743 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6745 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6746 //ellipsisDestType = destType;
6749 Type type = e.expType;
6750 Class _class = null;
6751 //Type destType = e.destType;
6753 if(type.kind == classType && type._class && type._class.registered)
6755 _class = type._class.registered;
6757 else if(type.kind == subClassType)
6759 _class = FindClass("ecere::com::Class").registered;
6763 char string[1024] = "";
6766 PrintType(type, string, false, true);
6767 classSym = FindClass(string);
6768 if(classSym) _class = classSym.registered;
6771 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...
6772 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6773 destType.byReference)))
6775 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6777 Expression checkedExp = e, newExp;
6779 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6781 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6783 if(checkedExp.type == extensionCompoundExp)
6785 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6788 checkedExp = checkedExp.list->last;
6790 else if(checkedExp.type == castExp)
6791 checkedExp = checkedExp.cast.exp;
6794 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6796 newExp = checkedExp.op.exp2;
6797 checkedExp.op.exp2 = null;
6798 FreeExpContents(checkedExp);
6800 if(e.expType && e.expType.passAsTemplate)
6803 ComputeTypeSize(e.expType);
6804 sprintf(size, "%d", e.expType.size);
6805 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6806 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6807 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6810 ReplaceExpContents(checkedExp, newExp);
6811 e.byReference = true;
6813 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6815 Expression checkedExp, newExp;
6818 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6820 e.type == identifierExp ||
6821 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6822 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
6823 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
6826 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
6828 Context context = PushContext();
6830 OldList * specs = MkList();
6831 char typeString[1024];
6832 Expression newExp { };
6834 typeString[0] = '\0';
6837 //if(e.destType) e.destType.refCount++;
6838 // if(exp.expType) exp.expType.refCount++;
6841 newExp.expType = null;
6843 PrintType(e.expType, typeString, false, true);
6844 decl = SpecDeclFromString(typeString, specs, null);
6845 newExp.destType = ProcessType(specs, decl);
6847 curContext = context;
6848 e.type = extensionCompoundExp;
6849 e.compound = MkCompoundStmt(
6850 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
6851 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
6853 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
6856 Type type = e.destType;
6858 CopyTypeInto(e.destType, type);
6859 e.destType.refCount = 1;
6860 e.destType.classObjectType = none;
6864 e.compound.compound.context = context;
6865 PopContext(context);
6866 curContext = context.parent;
6870 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
6872 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6874 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6876 if(checkedExp.type == extensionCompoundExp)
6878 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6881 checkedExp = checkedExp.list->last;
6883 else if(checkedExp.type == castExp)
6884 checkedExp = checkedExp.cast.exp;
6887 Expression operand { };
6888 operand = *checkedExp;
6889 checkedExp.destType = null;
6890 checkedExp.expType = null;
6892 checkedExp.type = opExp;
6893 checkedExp.op.op = '&';
6894 checkedExp.op.exp1 = null;
6895 checkedExp.op.exp2 = operand;
6897 //newExp = MkExpOp(null, '&', checkedExp);
6899 //ReplaceExpContents(checkedExp, newExp);
6906 // If expression type is a simple class, make it an address
6907 // FixReference(e, true);
6910 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
6911 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
6912 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
6914 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
6916 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
6920 Expression thisExp { };
6923 thisExp.prev = null;
6924 thisExp.next = null;
6927 e.type = bracketsExp;
6928 e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
6929 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
6930 ((Expression)e.list->first).byReference = true;
6932 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
6934 e.expType = thisExp.expType;
6935 e.expType.refCount++;
6940 CopyTypeInto(e.expType, thisExp.expType);
6941 e.expType.byReference = false;
6942 e.expType.refCount = 1;
6944 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
6945 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
6947 e.expType.classObjectType = none;
6952 // TOFIX: Try this for a nice IDE crash!
6954 // The other way around
6957 if(destType && e.expType &&
6958 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
6959 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
6960 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
6962 if(destType.kind == ellipsisType)
6964 Compiler_Error("Unspecified type\n");
6966 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
6968 bool byReference = e.expType.byReference;
6969 Expression thisExp { };
6971 OldList * specs = MkList();
6972 char typeString[1024]; // Watch buffer overruns
6974 ClassObjectType backupClassObjectType;
6976 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
6981 backupClassObjectType = type.classObjectType;
6983 type.classObjectType = none;
6985 typeString[0] = '\0';
6986 PrintType(type, typeString, false, true);
6987 decl = SpecDeclFromString(typeString, specs, null);
6989 type.classObjectType = backupClassObjectType;
6992 thisExp.prev = null;
6993 thisExp.next = null;
6996 if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
6997 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
6998 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
6999 (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
7000 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7005 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7010 e.cast.typeName = MkTypeName(specs, decl);
7011 e.cast.exp = thisExp;
7012 e.byReference = true;
7015 e.destType = destType;
7017 destType.refCount++;
7022 void ProcessExpressionType(Expression exp)
7024 bool unresolved = false;
7025 Location oldyylloc = yylloc;
7026 bool notByReference = false;
7028 char debugExpString[4096];
7029 debugExpString[0] = '\0';
7030 PrintExpression(exp, debugExpString);
7032 if(!exp || exp.expType)
7035 //eSystem_Logf("%s\n", expString);
7037 // Testing this here
7043 Identifier id = exp.identifier;
7046 // DOING THIS LATER NOW...
7047 if(id._class && id._class.name)
7049 id.classSym = id._class.symbol; // FindClass(id._class.name);
7050 /* TODO: Name Space Fix ups
7052 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7056 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7058 exp.expType = ProcessTypeString("Module", true);
7061 else */if(strstr(id.string, "__ecereClass") == id.string)
7063 exp.expType = ProcessTypeString("ecere::com::Class", true);
7066 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7068 // Added this here as well
7069 ReplaceClassMembers(exp, thisClass);
7070 if(exp.type != identifierExp)
7072 ProcessExpressionType(exp);
7076 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7081 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7082 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7083 if(!symbol/* && exp.destType*/)
7085 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7091 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7092 if(exp.type != identifierExp)
7094 ProcessExpressionType(exp);
7098 // Static methods called from inside the _class
7099 else if(currentClass && !id._class)
7101 if(ResolveIdWithClass(exp, currentClass, true))
7104 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7108 // If we manage to resolve this symbol
7111 Type type = symbol.type;
7112 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7114 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7116 Context context = SetupTemplatesContext(_class);
7117 type = ReplaceThisClassType(_class);
7118 FinishTemplatesContext(context);
7119 if(type) type.refCount = 0; // We'll be incrementing it right below...
7122 FreeSpecifier(id._class);
7125 id.string = CopyString(symbol.string);
7131 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7132 // Add missing cases here... enum Classes...
7133 exp.isConstant = true;
7135 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7136 if(symbol.isParam || !strcmp(id.string, "this"))
7138 if(_class && _class.type == structClass)
7139 exp.byReference = true;
7141 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7142 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7143 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7144 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7146 Identifier id = exp.identifier;
7147 exp.type = bracketsExp;
7148 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7152 if(symbol.isIterator)
7154 if(symbol.isIterator == 3)
7156 exp.type = bracketsExp;
7157 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7158 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7160 ProcessExpressionType(exp);
7162 else if(symbol.isIterator != 4)
7164 exp.type = memberExp;
7165 exp.member.exp = MkExpIdentifier(exp.identifier);
7166 exp.member.exp.expType = exp.expType;
7167 /*if(symbol.isIterator == 6)
7168 exp.member.member = MkIdentifier("key");
7170 exp.member.member = MkIdentifier("data");
7172 ProcessExpressionType(exp);
7179 DefinedExpression definedExp = null;
7180 if(thisNameSpace && !(id._class && !id._class.name))
7183 strcpy(name, thisNameSpace);
7185 strcat(name, id.string);
7186 definedExp = eSystem_FindDefine(privateModule, name);
7189 definedExp = eSystem_FindDefine(privateModule, id.string);
7193 for(c = 0; c<definedExpStackPos; c++)
7194 if(definedExpStack[c] == definedExp)
7196 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7198 Location backupYylloc = yylloc;
7199 definedExpStack[definedExpStackPos++] = definedExp;
7200 fileInput = TempFile { };
7201 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7202 fileInput.Seek(0, start);
7205 parsedExpression = null;
7207 expression_yyparse();
7210 yylloc = backupYylloc;
7212 if(parsedExpression)
7215 exp.type = bracketsExp;
7216 exp.list = MkListOne(parsedExpression);
7217 parsedExpression.loc = yylloc;
7218 ProcessExpressionType(exp);
7219 definedExpStackPos--;
7222 definedExpStackPos--;
7228 Compiler_Error("Recursion in defined expression %s\n", id.string);
7234 GlobalData data = null;
7235 if(thisNameSpace && !(id._class && !id._class.name))
7238 strcpy(name, thisNameSpace);
7240 strcat(name, id.string);
7241 data = FindGlobalData(name);
7244 data = FindGlobalData(id.string);
7247 DeclareGlobalData(data);
7248 exp.expType = data.dataType;
7249 if(data.dataType) data.dataType.refCount++;
7252 id.string = CopyString(data.fullName);
7253 FreeSpecifier(id._class);
7260 GlobalFunction function = null;
7261 if(thisNameSpace && !(id._class && !id._class.name))
7264 strcpy(name, thisNameSpace);
7266 strcat(name, id.string);
7267 function = eSystem_FindFunction(privateModule, name);
7270 function = eSystem_FindFunction(privateModule, id.string);
7275 id.string = CopyString(function.name);
7278 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7279 strcpy(name, "__ecereFunction_");
7280 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7281 if(DeclareFunction(function, name))
7284 id.string = CopyString(name);
7286 exp.expType = function.dataType;
7287 if(function.dataType) function.dataType.refCount++;
7289 FreeSpecifier(id._class);
7306 if(!exp.instance._class)
7308 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7310 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7320 //classSym = FindClass(exp.instance._class.fullName);
7321 //_class = classSym ? classSym.registered : null;
7323 ProcessInstantiationType(exp.instance);
7324 exp.isConstant = exp.instance.isConstant;
7327 if(_class.type == unitClass && _class.base.type != systemClass)
7330 Type destType = exp.destType;
7332 exp.destType = MkClassType(_class.base.fullName);
7333 exp.expType = MkClassType(_class.fullName);
7334 CheckExpressionType(exp, exp.destType, true);
7336 exp.destType = destType;
7338 exp.expType = MkClassType(_class.fullName);
7341 if(exp.instance._class)
7343 exp.expType = MkClassType(exp.instance._class.name);
7344 /*if(exp.expType._class && exp.expType._class.registered &&
7345 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7346 exp.expType.byReference = true;*/
7361 if(exp.constant[0] == '\'')
7363 if((int)((byte *)exp.constant)[1] > 127)
7366 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7367 if(nb < 2) ch = exp.constant[1];
7368 delete exp.constant;
7369 exp.constant = PrintUInt(ch);
7370 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7371 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7372 type._class = FindClass("unichar");
7374 type.isSigned = false;
7378 type.kind = charType;
7379 type.isSigned = true;
7382 else if(strchr(exp.constant, '.'))
7384 char ch = exp.constant[strlen(exp.constant)-1];
7386 type.kind = floatType;
7388 type.kind = doubleType;
7389 type.isSigned = true;
7393 if(exp.constant[0] == '0' && exp.constant[1])
7394 type.isSigned = false;
7395 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7396 type.isSigned = false;
7397 else if(strtoll(exp.constant, null, 0) > MAXINT)
7398 type.isSigned = false;
7400 type.isSigned = true;
7401 type.kind = intType;
7403 exp.isConstant = true;
7409 exp.isConstant = true; // Why wasn't this constant?
7425 ProcessExpressionType(exp._new.size);
7430 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7432 DeclareType(exp.expType.type, false, false);
7436 ProcessExpressionType(exp._renew.size);
7437 ProcessExpressionType(exp._renew.exp);
7442 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7444 DeclareType(exp.expType.type, false, false);
7448 bool assign = false, boolResult = false, boolOps = false;
7449 Type type1 = null, type2 = null;
7450 bool useDestType = false, useSideType = false;
7451 Location oldyylloc = yylloc;
7452 bool useSideUnit = false;
7454 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7463 // Assignment Operators
7477 // boolean Operators
7479 // Expect boolean operators
7481 //boolResult = true;
7485 // Expect boolean operands
7496 // Gives boolean result
7504 // Just added these... testing
7509 // DANGER: Verify units
7514 if(exp.op.op != '*' || exp.op.exp1)
7521 /*// Implement speed etc.
7527 if(exp.op.op == '&')
7529 // Added this here earlier for Iterator address as key
7530 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7532 Identifier id = exp.op.exp2.identifier;
7533 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7534 if(symbol && symbol.isIterator == 2)
7536 exp.type = memberExp;
7537 exp.member.exp = exp.op.exp2;
7538 exp.member.member = MkIdentifier("key");
7540 exp.op.exp2.expType = symbol.type;
7541 symbol.type.refCount++;
7542 ProcessExpressionType(exp);
7546 // exp.op.exp2.usage.usageRef = true;
7550 //dummy.kind = TypeDummy;
7554 if(exp.destType && exp.destType.kind == classType &&
7555 exp.destType._class && exp.destType._class.registered && useDestType &&
7557 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7558 exp.destType._class.registered.type == enumClass ||
7559 exp.destType._class.registered.type == bitClass
7562 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7564 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7565 exp.op.exp1.destType = exp.destType;
7567 exp.destType.refCount++;
7571 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7572 exp.op.exp1.destType = dummy;
7576 // TESTING THIS HERE...
7577 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7578 ProcessExpressionType(exp.op.exp1);
7579 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7581 if(exp.op.exp1.destType == dummy)
7584 exp.op.exp1.destType = null;
7586 type1 = exp.op.exp1.expType;
7591 char expString[10240];
7592 expString[0] = '\0';
7593 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7597 exp.op.exp2.destType = exp.op.exp1.expType;
7598 if(exp.op.exp1.expType)
7599 exp.op.exp1.expType.refCount++;
7603 exp.op.exp2.destType = exp.destType;
7605 exp.destType.refCount++;
7608 if(type1) type1.refCount++;
7609 exp.expType = type1;
7614 PrintExpression(exp.op.exp2, expString);
7616 if(type1 && type1.kind == pointerType)
7618 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 ||
7619 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7620 Compiler_Error("operator %s illegal on pointer\n", exp.op.op);
7621 else if(exp.op.op == '=')
7623 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7624 exp.op.exp2.destType = type1;
7631 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7632 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/* ||
7633 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7636 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7637 exp.op.exp2.destType = type1;
7642 if(type1) type1.refCount++;
7643 exp.expType = type1;
7645 else if(exp.destType && exp.destType.kind == classType &&
7646 exp.destType._class && exp.destType._class.registered &&
7648 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7649 (exp.destType._class.registered.type == enumClass && useDestType))
7652 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7653 exp.op.exp2.destType = exp.destType;
7655 exp.destType.refCount++;
7659 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7660 exp.op.exp2.destType = dummy;
7664 // TESTING THIS HERE... (DANGEROUS)
7665 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7666 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7668 FreeType(exp.op.exp2.destType);
7669 exp.op.exp2.destType = type1;
7672 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7673 ProcessExpressionType(exp.op.exp2);
7674 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7676 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7678 if(exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
7680 if(exp.op.op != '=' && type1.type.kind == voidType)
7681 Compiler_Error("void *: unknown size\n");
7683 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||
7684 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7685 (exp.op.exp2.expType._class.registered.type == normalClass ||
7686 exp.op.exp2.expType._class.registered.type == structClass ||
7687 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7689 if(exp.op.op == ADD_ASSIGN)
7690 Compiler_Error("cannot add two pointers\n");
7692 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7693 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7695 if(exp.op.op == ADD_ASSIGN)
7696 Compiler_Error("cannot add two pointers\n");
7700 char type1String[1024];
7701 char type2String[1024];
7702 type1String[0] = '\0';
7703 type2String[0] = '\0';
7705 PrintType(exp.op.exp2.expType, type1String, false, true);
7706 PrintType(type1, type2String, false, true);
7707 ChangeCh(expString, '\n', ' ');
7708 Compiler_Warning("incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7712 if(exp.op.exp2.destType == dummy)
7715 exp.op.exp2.destType = null;
7718 type2 = exp.op.exp2.expType;
7721 dummy.kind = voidType;
7723 if(exp.op.op == SIZEOF)
7730 exp.isConstant = true;
7732 // Get type of dereferenced pointer
7733 else if(exp.op.op == '*' && !exp.op.exp1)
7735 exp.expType = Dereference(type2);
7736 if(type2 && type2.kind == classType)
7737 notByReference = true;
7739 else if(exp.op.op == '&' && !exp.op.exp1)
7740 exp.expType = Reference(type2);
7747 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7748 exp.op.exp1.destType = MkClassType("bool");
7749 exp.op.exp1.destType.truth = true;
7750 if(!exp.op.exp1.expType)
7751 ProcessExpressionType(exp.op.exp1);
7753 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7754 FreeType(exp.op.exp1.expType);
7755 exp.op.exp1.expType = MkClassType("bool");
7756 exp.op.exp1.expType.truth = true;
7760 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7761 exp.op.exp2.destType = MkClassType("bool");
7762 exp.op.exp2.destType.truth = true;
7763 if(!exp.op.exp2.expType)
7764 ProcessExpressionType(exp.op.exp2);
7766 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7767 FreeType(exp.op.exp2.expType);
7768 exp.op.exp2.expType = MkClassType("bool");
7769 exp.op.exp2.expType.truth = true;
7772 else if(exp.op.exp1 && exp.op.exp2 &&
7775 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7776 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7777 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7778 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7780 if(type1 && type2 &&
7781 // If either both are class or both are not class
7782 ((type1.kind == classType && strcmp(type1._class.string, "String")) == (type2.kind == classType && strcmp(type2._class.string, "String"))))
7784 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7785 exp.op.exp2.destType = type1;
7787 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7788 exp.op.exp1.destType = type2;
7790 // Warning here for adding Radians + Degrees with no destination type
7791 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7792 type1._class.registered && type1._class.registered.type == unitClass &&
7793 type2._class.registered && type2._class.registered.type == unitClass &&
7794 type1._class.registered != type2._class.registered)
7795 Compiler_Warning("operating on %s and %s with an untyped result, assuming %s\n",
7796 type1._class.string, type2._class.string, type1._class.string);
7798 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7800 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7803 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7805 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
7806 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
7809 ProcessExpressionType(exp.op.exp1);
7811 if(type2.kind != pointerType)
7813 ProcessExpressionType(classExp);
7815 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
7816 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7817 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7819 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
7822 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
7823 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7824 MkPointer(null, null), null)))),
7825 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
7827 if(!exp.op.exp2.expType)
7828 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
7830 ProcessExpressionType(exp.op.exp2);
7835 if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
7837 if(type1.kind != classType && type1.type.kind == voidType)
7838 Compiler_Error("void *: unknown size\n");
7839 exp.expType = type1;
7840 if(type1) type1.refCount++;
7842 else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
7844 if(type2.kind != classType && type2.type.kind == voidType)
7845 Compiler_Error("void *: unknown size\n");
7846 exp.expType = type2;
7847 if(type2) type2.refCount++;
7849 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
7850 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
7852 Compiler_Warning("different levels of indirection\n");
7856 bool success = false;
7857 if(type1.kind == pointerType && type2.kind == pointerType)
7859 if(exp.op.op == '+')
7860 Compiler_Error("cannot add two pointers\n");
7861 else if(exp.op.op == '-')
7863 // Pointer Subtraction gives integer
7864 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
7873 if(type1.type.kind == templateType)
7875 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7878 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7880 ProcessExpressionType(classExp);
7882 exp.type = bracketsExp;
7883 exp.list = MkListOne(MkExpOp(
7884 MkExpBrackets(MkListOne(MkExpOp(
7885 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
7887 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
7889 //MkExpMember(classExp, MkIdentifier("typeSize"))
7891 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7892 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7894 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
7897 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
7898 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7899 MkPointer(null, null), null)))),
7900 MkExpMember(classExp, MkIdentifier("typeSize")))))
7905 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
7914 if(!success && exp.op.exp1.type == constantExp)
7916 // If first expression is constant, try to match that first
7917 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
7919 if(exp.expType) FreeType(exp.expType);
7920 exp.expType = exp.op.exp1.destType;
7921 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
7924 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
7926 if(exp.expType) FreeType(exp.expType);
7927 exp.expType = exp.op.exp2.destType;
7928 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
7934 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
7936 if(exp.expType) FreeType(exp.expType);
7937 exp.expType = exp.op.exp2.destType;
7938 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
7941 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
7943 if(exp.expType) FreeType(exp.expType);
7944 exp.expType = exp.op.exp1.destType;
7945 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
7951 char expString1[10240];
7952 char expString2[10240];
7955 expString1[0] = '\0';
7956 expString2[0] = '\0';
7961 PrintExpression(exp.op.exp1, expString1);
7962 ChangeCh(expString1, '\n', ' ');
7963 PrintExpression(exp.op.exp2, expString2);
7964 ChangeCh(expString2, '\n', ' ');
7965 PrintType(exp.op.exp1.expType, type1, false, true);
7966 PrintType(exp.op.exp2.expType, type2, false, true);
7969 Compiler_Warning("incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
7973 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
7974 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
7976 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7977 // Convert e.g. / 4 into / 4.0
7978 exp.op.exp1.destType = type2._class.registered.dataType;
7979 if(type2._class.registered.dataType)
7980 type2._class.registered.dataType.refCount++;
7981 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7982 exp.expType = type2;
7983 if(type2) type2.refCount++;
7985 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
7987 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7988 // Convert e.g. / 4 into / 4.0
7989 exp.op.exp2.destType = type1._class.registered.dataType;
7990 if(type1._class.registered.dataType)
7991 type1._class.registered.dataType.refCount++;
7992 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7993 exp.expType = type1;
7994 if(type1) type1.refCount++;
8000 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8002 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8004 if(!type1._class.registered.dataType)
8005 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8006 exp.op.exp2.destType = type1._class.registered.dataType;
8007 exp.op.exp2.destType.refCount++;
8009 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8010 type2 = exp.op.exp2.destType;
8012 exp.expType = type2;
8016 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8018 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8020 if(!type2._class.registered.dataType)
8021 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8022 exp.op.exp1.destType = type2._class.registered.dataType;
8023 exp.op.exp1.destType.refCount++;
8025 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8026 type1 = exp.op.exp1.destType;
8027 exp.expType = type1;
8031 // TESTING THIS NEW CODE
8032 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8034 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8036 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8038 if(exp.expType) FreeType(exp.expType);
8039 exp.expType = exp.op.exp1.expType;
8040 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8045 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8047 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8049 if(exp.expType) FreeType(exp.expType);
8050 exp.expType = exp.op.exp2.expType;
8051 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8059 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8060 exp.op.exp2.destType = type1;
8064 // Maybe this was meant to be an enum...
8065 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8067 Type oldType = exp.op.exp2.expType;
8068 exp.op.exp2.expType = null;
8069 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8072 exp.op.exp2.expType = oldType;
8077 // TESTING THIS HERE... LATEST ADDITION
8078 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8080 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8081 exp.op.exp2.destType = type2._class.registered.dataType;
8082 if(type2._class.registered.dataType)
8083 type2._class.registered.dataType.refCount++;
8084 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8086 //exp.expType = type2._class.registered.dataType; //type2;
8087 //if(type2) type2.refCount++;
8090 // TESTING THIS HERE... LATEST ADDITION
8091 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8093 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8094 exp.op.exp1.destType = type1._class.registered.dataType;
8095 if(type1._class.registered.dataType)
8096 type1._class.registered.dataType.refCount++;
8097 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8098 exp.expType = type1._class.registered.dataType; //type1;
8099 if(type1) type1.refCount++;
8103 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8105 if(exp.expType) FreeType(exp.expType);
8106 exp.expType = exp.op.exp2.destType;
8107 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8109 else if(type1 && type2)
8111 char expString1[10240];
8112 char expString2[10240];
8113 char type1String[1024];
8114 char type2String[1024];
8115 expString1[0] = '\0';
8116 expString2[0] = '\0';
8117 type1String[0] = '\0';
8118 type2String[0] = '\0';
8121 PrintExpression(exp.op.exp1, expString1);
8122 ChangeCh(expString1, '\n', ' ');
8123 PrintExpression(exp.op.exp2, expString2);
8124 ChangeCh(expString2, '\n', ' ');
8125 PrintType(exp.op.exp1.expType, type1String, false, true);
8126 PrintType(exp.op.exp2.expType, type2String, false, true);
8129 Compiler_Warning("incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8131 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8133 exp.expType = exp.op.exp1.expType;
8134 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8136 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8138 exp.expType = exp.op.exp2.expType;
8139 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8146 // Maybe this was meant to be an enum...
8147 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8149 Type oldType = exp.op.exp1.expType;
8150 exp.op.exp1.expType = null;
8151 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8154 exp.op.exp1.expType = oldType;
8157 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8158 exp.op.exp1.destType = type2;
8161 // TESTING THIS HERE... LATEST ADDITION
8162 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8164 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8165 exp.op.exp1.destType = type1._class.registered.dataType;
8166 if(type1._class.registered.dataType)
8167 type1._class.registered.dataType.refCount++;
8170 // TESTING THIS HERE... LATEST ADDITION
8171 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8173 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8174 exp.op.exp2.destType = type2._class.registered.dataType;
8175 if(type2._class.registered.dataType)
8176 type2._class.registered.dataType.refCount++;
8180 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8182 if(exp.expType) FreeType(exp.expType);
8183 exp.expType = exp.op.exp1.destType;
8184 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8188 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8190 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8192 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8193 // Convert e.g. / 4 into / 4.0
8194 exp.op.exp1.destType = type2._class.registered.dataType;
8195 if(type2._class.registered.dataType)
8196 type2._class.registered.dataType.refCount++;
8197 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8199 if(exp.op.op == '!')
8201 exp.expType = MkClassType("bool");
8202 exp.expType.truth = true;
8206 exp.expType = type2;
8207 if(type2) type2.refCount++;
8210 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8212 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8214 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8215 // Convert e.g. / 4 into / 4.0
8216 exp.op.exp2.destType = type1._class.registered.dataType;
8217 if(type1._class.registered.dataType)
8218 type1._class.registered.dataType.refCount++;
8219 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8221 exp.expType = type1;
8222 if(type1) type1.refCount++;
8227 if(exp.op.exp1 && !exp.op.exp1.expType)
8229 char expString[10000];
8230 expString[0] = '\0';
8233 PrintExpression(exp.op.exp1, expString);
8234 ChangeCh(expString, '\n', ' ');
8237 Compiler_Error("couldn't determine type of %s\n", expString);
8239 if(exp.op.exp2 && !exp.op.exp2.expType)
8241 char expString[10240];
8242 expString[0] = '\0';
8245 PrintExpression(exp.op.exp2, expString);
8246 ChangeCh(expString, '\n', ' ');
8249 Compiler_Error("couldn't determine type of %s\n", expString);
8254 FreeType(exp.expType);
8255 exp.expType = MkClassType("bool");
8256 exp.expType.truth = true;
8259 if(exp.op.op != SIZEOF)
8260 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8261 (!exp.op.exp2 || exp.op.exp2.isConstant);
8263 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8265 DeclareType(exp.op.exp2.expType, false, false);
8274 case extensionExpressionExp:
8277 exp.isConstant = true;
8278 for(e = exp.list->first; e; e = e.next)
8283 FreeType(e.destType);
8284 e.destType = exp.destType;
8285 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8287 ProcessExpressionType(e);
8289 exp.destType.count--;
8290 if(!exp.expType && !e.next)
8292 exp.expType = e.expType;
8293 if(e.expType) e.expType.refCount++;
8296 exp.isConstant = false;
8299 // In case a cast became a member...
8300 e = exp.list->first;
8301 if(!e.next && e.type == memberExp)
8303 // Preserve prev, next
8304 Expression next = exp.next, prev = exp.prev;
8307 FreeType(exp.expType);
8308 FreeType(exp.destType);
8318 ProcessExpressionType(exp);
8325 exp.isConstant = true;
8327 ProcessExpressionType(exp.index.exp);
8328 if(!exp.index.exp.isConstant)
8329 exp.isConstant = false;
8331 if(exp.index.exp.expType)
8333 Type source = exp.index.exp.expType;
8334 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8335 eClass_IsDerived(source._class.registered, containerClass) &&
8336 source._class.registered.templateArgs)
8338 Class _class = source._class.registered;
8339 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8341 if(exp.index.index && exp.index.index->last)
8343 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8348 for(e = exp.index.index->first; e; e = e.next)
8350 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8352 if(e.destType) FreeType(e.destType);
8353 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8355 ProcessExpressionType(e);
8358 // Check if this type is int
8361 exp.isConstant = false;
8365 exp.expType = Dereference(exp.index.exp.expType);
8367 DeclareType(exp.expType, false, false);
8374 Type methodType = null;
8380 PrintExpression(exp.call.exp, name);
8381 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8383 //exp.call.exp.expType = null;
8384 PrintExpression(exp.call.exp, name);
8387 if(exp.call.exp.type == identifierExp)
8389 Expression idExp = exp.call.exp;
8390 Identifier id = idExp.identifier;
8391 if(!strcmp(id.string, "__ENDIAN_PAD"))
8393 exp.expType = ProcessTypeString("int", true);
8394 if(exp.call.arguments && exp.call.arguments->first)
8395 ProcessExpressionType(exp.call.arguments->first);
8398 else if(!strcmp(id.string, "Max") ||
8399 !strcmp(id.string, "Min") ||
8400 !strcmp(id.string, "Sgn") ||
8401 !strcmp(id.string, "Abs"))
8403 Expression a = null;
8404 Expression b = null;
8405 Expression tempExp1 = null, tempExp2 = null;
8406 if((!strcmp(id.string, "Max") ||
8407 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8409 a = exp.call.arguments->first;
8410 b = exp.call.arguments->last;
8414 else if(exp.call.arguments->count == 1)
8416 a = exp.call.arguments->first;
8422 exp.call.arguments->Clear();
8423 idExp.identifier = null;
8425 FreeExpContents(exp);
8427 ProcessExpressionType(a);
8429 ProcessExpressionType(b);
8431 exp.type = bracketsExp;
8432 exp.list = MkList();
8434 if(a.expType && (!b || b.expType))
8436 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8438 // Use the simpleStruct name/ids for now...
8441 OldList * specs = MkList();
8442 OldList * decls = MkList();
8444 char temp1[1024], temp2[1024];
8446 GetTypeSpecs(a.expType, specs);
8448 if(a && !a.isConstant && a.type != identifierExp)
8450 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8451 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8452 tempExp1 = QMkExpId(temp1);
8453 tempExp1.expType = a.expType;
8455 a.expType.refCount++;
8456 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8458 if(b && !b.isConstant && b.type != identifierExp)
8460 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8461 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8462 tempExp2 = QMkExpId(temp2);
8463 tempExp2.expType = b.expType;
8465 b.expType.refCount++;
8466 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8469 decl = MkDeclaration(specs, decls);
8470 if(!curCompound.compound.declarations)
8471 curCompound.compound.declarations = MkList();
8472 curCompound.compound.declarations->Insert(null, decl);
8477 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8479 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8481 MkExpCondition(MkExpBrackets(MkListOne(
8482 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8483 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8484 exp.expType = a.expType;
8486 a.expType.refCount++;
8488 else if(!strcmp(id.string, "Abs"))
8491 MkExpCondition(MkExpBrackets(MkListOne(
8492 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8493 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8494 exp.expType = a.expType;
8496 a.expType.refCount++;
8498 else if(!strcmp(id.string, "Sgn"))
8500 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8502 MkExpCondition(MkExpBrackets(MkListOne(
8503 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8504 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8505 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8506 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8507 exp.expType = ProcessTypeString("int", false);
8510 FreeExpression(tempExp1);
8511 if(tempExp2) FreeExpression(tempExp2);
8525 if(!exp.call.exp.destType)
8527 exp.call.exp.destType = dummy;
8530 ProcessExpressionType(exp.call.exp);
8531 if(exp.call.exp.destType == dummy)
8534 exp.call.exp.destType = null;
8539 // Check argument types against parameter types
8540 functionType = exp.call.exp.expType;
8542 if(functionType && functionType.kind == TypeKind::methodType)
8544 methodType = functionType;
8545 functionType = methodType.method.dataType;
8547 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8548 // TOCHECK: Instead of doing this here could this be done per param?
8549 if(exp.call.exp.expType.usedClass)
8551 char typeString[1024];
8552 typeString[0] = '\0';
8553 PrintType(functionType, typeString, true, true);
8554 if(strstr(typeString, "thisclass"))
8556 OldList * specs = MkList();
8559 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8561 decl = SpecDeclFromString(typeString, specs, null);
8563 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8564 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8565 exp.call.exp.expType.usedClass))
8566 thisClassParams = false;
8568 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8570 Class backupThisClass = thisClass;
8571 thisClass = exp.call.exp.expType.usedClass;
8572 ProcessDeclarator(decl);
8573 thisClass = backupThisClass;
8576 thisClassParams = true;
8578 functionType = ProcessType(specs, decl);
8579 functionType.refCount = 0;
8580 FinishTemplatesContext(context);
8583 FreeList(specs, FreeSpecifier);
8584 FreeDeclarator(decl);
8588 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8590 Type type = functionType.type;
8591 if(!functionType.refCount)
8593 functionType.type = null;
8594 FreeType(functionType);
8596 //methodType = functionType;
8597 functionType = type;
8599 if(functionType && functionType.kind != TypeKind::functionType)
8601 Compiler_Error("called object %s is not a function\n", name);
8603 else if(functionType)
8605 bool emptyParams = false, noParams = false;
8606 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8607 Type type = functionType.params.first;
8608 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8610 Location oldyylloc = yylloc;
8612 if(!type) emptyParams = true;
8615 if(functionType.extraParam && e)
8617 e.destType = MkClassType(functionType.thisClass.string);
8621 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8622 if(!functionType.staticMethod)
8624 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8625 memberExp.member.exp.expType._class)
8627 type = MkClassType(memberExp.member.exp.expType._class.string);
8632 type = functionType.params.first;
8637 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8639 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8644 type = functionType.params.first;
8652 if(type && type.kind == voidType)
8655 if(!type.refCount) FreeType(type);
8659 for( ; e; e = e.next)
8661 if(!type && !emptyParams)
8664 if(methodType && methodType.methodClass)
8665 Compiler_Error("too many arguments for method %s::%s (%d given, expected %d)\n",
8666 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8667 noParams ? 0 : functionType.params.count);
8669 Compiler_Error("too many arguments for function %s (%d given, expected %d)\n",
8670 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8671 noParams ? 0 : functionType.params.count);
8675 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8677 Type templatedType = null;
8678 Class _class = methodType.usedClass;
8679 ClassTemplateParameter curParam = null;
8681 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8684 for(sClass = _class; sClass; sClass = sClass.base)
8686 if(sClass.templateClass) sClass = sClass.templateClass;
8688 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8690 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8693 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8695 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8696 id += nextClass.templateParams.count;
8705 if(curParam && _class.templateArgs[id].dataTypeString)
8707 ClassTemplateArgument arg = _class.templateArgs[id];
8709 Context context = SetupTemplatesContext(_class);
8712 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8713 templatedType = ProcessTypeString(arg.dataTypeString, false);
8714 FinishTemplatesContext(context);
8716 e.destType = templatedType;
8719 templatedType.passAsTemplate = true;
8720 // templatedType.refCount++;
8726 if(type) type.refCount++;
8732 if(type) type.refCount++;
8734 // Don't reach the end for the ellipsis
8735 if(type && type.kind != ellipsisType)
8737 Type next = type.next;
8738 if(!type.refCount) FreeType(type);
8743 if(type && type.kind != ellipsisType)
8745 if(methodType && methodType.methodClass)
8746 Compiler_Warning("not enough arguments for method %s::%s (%d given, expected %d)\n",
8747 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8748 functionType.params.count + extra);
8750 Compiler_Warning("not enough arguments for function %s (%d given, expected %d)\n",
8751 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8752 functionType.params.count + extra);
8755 if(type && !type.refCount) FreeType(type);
8762 kind = TypeKind::functionType;
8765 if(exp.call.exp.type == identifierExp)
8767 char * string = exp.call.exp.identifier.string;
8771 Location oldyylloc = yylloc;
8773 yylloc = exp.call.exp.identifier.loc;
8774 if(strstr(string, "__builtin_") == string);
8776 Compiler_Warning("%s undefined; assuming extern returning int\n", string);
8777 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
8778 globalContext.symbols.Add((BTNode)symbol);
8783 else if(exp.call.exp.type == memberExp)
8785 /*Compiler_Warning("%s undefined; assuming returning int\n",
8786 exp.call.exp.member.member.string);*/
8789 Compiler_Warning("callable object undefined; extern assuming returning int\n");
8791 if(!functionType.returnType)
8793 functionType.returnType = Type
8800 if(functionType && functionType.kind == TypeKind::functionType)
8802 exp.expType = functionType.returnType;
8804 if(functionType.returnType)
8805 functionType.returnType.refCount++;
8807 if(!functionType.refCount)
8808 FreeType(functionType);
8811 if(exp.call.arguments)
8813 for(e = exp.call.arguments->first; e; e = e.next)
8815 Type destType = e.destType;
8816 ProcessExpressionType(e);
8824 Location oldyylloc = yylloc;
8825 bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
8826 exp.thisPtr = thisPtr;
8828 // DOING THIS LATER NOW...
8829 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
8831 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
8832 /* TODO: Name Space Fix ups
8833 if(!exp.member.member.classSym)
8834 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
8838 ProcessExpressionType(exp.member.exp);
8839 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
8840 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
8842 exp.isConstant = false;
8845 exp.isConstant = exp.member.exp.isConstant;
8846 type = exp.member.exp.expType;
8850 if(type && (type.kind == templateType))
8852 Class _class = thisClass ? thisClass : currentClass;
8853 ClassTemplateParameter param = null;
8856 for(param = _class.templateParams.first; param; param = param.next)
8858 if(param.type == identifier && !strcmp(param.name, exp.member.member.string))
8862 if(param && param.defaultArg.member)
8864 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
8867 Expression expMember = exp.member.exp;
8869 OldList * specs = MkList();
8870 char thisClassTypeString[1024];
8872 FreeIdentifier(exp.member.member);
8874 ProcessExpressionType(argExp);
8877 char * colon = strstr(param.defaultArg.memberString, "::");
8880 char className[1024];
8883 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
8884 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
8887 strcpy(thisClassTypeString, _class.fullName);
8890 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
8892 exp.expType = ProcessType(specs, decl);
8893 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
8895 Class expClass = exp.expType._class.registered;
8896 Class cClass = null;
8901 char templateString[1024];
8902 ClassTemplateParameter param;
8903 sprintf(templateString, "%s<", expClass.templateClass.fullName);
8904 for(cClass = expClass; cClass; cClass = cClass.base)
8907 for(param = cClass.templateParams.first; param; param = param.next)
8911 ClassTemplateArgument arg;
8912 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
8913 arg = expClass.templateArgs[id];
8915 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
8917 ClassTemplateParameter cParam;
8918 //int p = numParams - sClass.templateParams.count;
8921 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
8923 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
8925 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
8927 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
8929 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
8930 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
8942 strcat(argument, arg.name.string);
8943 strcat(argument, " = ");
8949 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
8950 char expString[1024];
8951 OldList * specs = MkList();
8952 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
8954 char * string = PrintHexUInt64(arg.expression.ui64);
8955 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
8957 ProcessExpressionType(exp);
8958 ComputeExpression(exp);
8959 expString[0] = '\0';
8960 PrintExpression(exp, expString);
8961 strcat(argument, expString);
8963 FreeExpression(exp);
8968 strcat(argument, arg.member.name);
8971 case TemplateParameterType::type:
8973 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
8975 if(!strcmp(arg.dataTypeString, "thisclass"))
8976 strcat(argument, thisClassTypeString);
8978 strcat(argument, arg.dataTypeString);
8985 if(paramCount) strcat(templateString, ", ");
8986 if(lastParam != p - 1)
8988 strcat(templateString, param.name);
8989 strcat(templateString, " = ");
8991 strcat(templateString, argument);
9000 int len = strlen(templateString);
9001 if(templateString[len-1] == '>') templateString[len++] = ' ';
9002 templateString[len++] = '>';
9003 templateString[len++] = '\0';
9006 Context context = SetupTemplatesContext(_class);
9007 FreeType(exp.expType);
9008 exp.expType = ProcessTypeString(templateString, false);
9009 FinishTemplatesContext(context);
9013 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9014 exp.type = bracketsExp;
9015 exp.list = MkListOne(MkExpOp(null, '*',
9020 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9021 MkExpBrackets(MkListOne(
9022 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9024 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9026 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9031 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9032 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9034 type = ProcessTemplateParameterType(type.templateParameter);
9038 if(type && (type.kind == templateType));
9039 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9041 Identifier id = exp.member.member;
9042 TypeKind typeKind = type.kind;
9043 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9044 if(typeKind == subClassType && exp.member.exp.type == classExp)
9046 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9047 typeKind = classType;
9050 if(id && (typeKind == intType || typeKind == enumType))
9051 _class = eSystem_FindClass(privateModule, "int");
9056 (exp.member.exp.type == identifierExp &&
9057 !strcmp(exp.member.exp.identifier.string, "this"));*/
9058 Property prop = null;
9059 Method method = null;
9060 DataMember member = null;
9061 Property revConvert = null;
9062 ClassProperty classProp = null;
9064 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9065 exp.member.memberType = propertyMember;
9067 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9068 Compiler_Error("invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9070 if(typeKind != subClassType)
9072 // Prioritize data members over properties for "this"
9073 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9075 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9076 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9078 prop = eClass_FindProperty(_class, id.string, privateModule);
9082 if(!member && !prop)
9083 prop = eClass_FindProperty(_class, id.string, privateModule);
9084 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9085 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9086 exp.member.thisPtr = true;
9088 // Prioritize properties over data members otherwise
9091 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9094 prop = eClass_FindProperty(_class, id.string, null);
9095 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9096 member = eClass_FindDataMember(_class, id.string, null, null, null);
9099 if(!prop && !member)
9101 method = eClass_FindMethod(_class, id.string, null);
9104 prop = eClass_FindProperty(_class, id.string, privateModule);
9105 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9106 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9112 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9119 if(!prop && !member)
9120 method = eClass_FindMethod(_class, id.string, privateModule);
9121 if(!prop && !member && !method)
9123 if(typeKind == subClassType)
9125 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9128 exp.member.memberType = classPropertyMember;
9129 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9133 // Assume this is a class_data member
9134 char structName[1024];
9135 Identifier id = exp.member.member;
9136 Expression classExp = exp.member.exp;
9139 FreeType(classExp.expType);
9140 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9142 strcpy(structName, "__ecereClassData_");
9143 FullClassNameCat(structName, type._class.string, false);
9144 exp.type = pointerExp;
9145 exp.member.member = id;
9147 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9148 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9149 MkExpBrackets(MkListOne(MkExpOp(
9150 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9151 MkExpMember(classExp, MkIdentifier("data"))), '+',
9152 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9157 ProcessExpressionType(exp);
9163 // Check for reverse conversion
9164 // (Convert in an instantiation later, so that we can use
9165 // deep properties system)
9166 Symbol classSym = FindClass(id.string);
9169 Class convertClass = classSym.registered;
9171 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9178 exp.member.memberType = propertyMember;
9180 ProcessPropertyType(prop);
9181 exp.expType = prop.dataType;
9182 if(prop.dataType) prop.dataType.refCount++;
9186 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9188 FreeExpContents(exp);
9189 exp.type = identifierExp;
9190 exp.identifier = MkIdentifier("class");
9191 ProcessExpressionType(exp);
9195 exp.member.memberType = dataMember;
9196 DeclareStruct(_class.fullName, false);
9197 if(!member.dataType)
9199 Context context = SetupTemplatesContext(_class);
9200 member.dataType = ProcessTypeString(member.dataTypeString, false);
9201 FinishTemplatesContext(context);
9203 exp.expType = member.dataType;
9204 if(member.dataType) member.dataType.refCount++;
9208 exp.member.memberType = reverseConversionMember;
9209 exp.expType = MkClassType(revConvert._class.fullName);
9217 exp.type = identifierExp;
9218 exp.identifier = exp.member.member;
9221 exp.member.memberType = methodMember;
9223 if(!method.dataType)
9224 ProcessMethodType(method);
9232 // Tricky spot here... To use instance versus class virtual table
9233 // Put it back to what it was... What did we break?
9235 // Had to put it back for overriding Main of Thread global instance
9237 //exp.expType.methodClass = _class;
9238 exp.expType.methodClass = (id && id._class) ? _class : null;
9240 // Need the actual class used for templated classes
9241 exp.expType.usedClass = _class;
9245 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9247 FreeExpContents(exp);
9248 exp.type = identifierExp;
9249 exp.identifier = MkIdentifier("class");
9250 ProcessExpressionType(exp);
9253 yylloc = exp.member.member.loc;
9254 Compiler_Error("couldn't find member %s in class %s\n", id.string, _class.fullName);
9256 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9259 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9264 while(tClass && !tClass.templateClass) tClass = tClass.base;
9266 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9269 ClassTemplateParameter curParam;
9272 for(sClass = tClass; sClass; sClass = sClass.base)
9275 if(sClass.templateClass) sClass = sClass.templateClass;
9276 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9278 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9280 for(sClass = sClass.base; sClass; sClass = sClass.base)
9281 id += sClass.templateParams.count;
9289 if(curParam && tClass.templateArgs[id].dataTypeString)
9291 ClassTemplateArgument arg = tClass.templateArgs[id];
9292 Context context = SetupTemplatesContext(tClass);
9294 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9295 FreeType(exp.expType);
9296 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9299 if(exp.expType.kind == thisClassType)
9301 FreeType(exp.expType);
9302 exp.expType = ReplaceThisClassType(_class);
9305 if(tClass.templateClass)
9306 exp.expType.passAsTemplate = true;
9307 //exp.expType.refCount++;
9310 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9311 //exp.destType.refCount++;
9313 if(exp.destType.kind == thisClassType)
9315 FreeType(exp.destType);
9316 exp.destType = ReplaceThisClassType(_class);
9320 FinishTemplatesContext(context);
9323 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9324 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9327 ClassTemplateParameter curParam;
9330 for(sClass = tClass; sClass; sClass = sClass.base)
9333 if(sClass.templateClass) sClass = sClass.templateClass;
9334 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9336 if(curParam.type == TemplateParameterType::type &&
9337 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9339 for(sClass = sClass.base; sClass; sClass = sClass.base)
9340 id += sClass.templateParams.count;
9350 ClassTemplateArgument arg = tClass.templateArgs[id];
9351 Context context = SetupTemplatesContext(tClass);
9354 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9356 basicType = ProcessTypeString(arg.dataTypeString, false);
9359 if(basicType.kind == thisClassType)
9361 FreeType(basicType);
9362 basicType = ReplaceThisClassType(_class);
9365 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9366 if(tClass.templateClass)
9367 basicType.passAsTemplate = true;
9370 FreeType(exp.expType);
9372 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9373 //exp.expType.refCount++;
9376 exp.destType = exp.expType;
9377 exp.destType.refCount++;
9381 Expression newExp { };
9382 OldList * specs = MkList();
9384 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9386 if(exp.destType) exp.destType.refCount++;
9387 if(exp.expType) exp.expType.refCount++;
9389 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9390 exp.cast.exp = newExp;
9391 //FreeType(exp.expType);
9392 //exp.expType = null;
9393 //ProcessExpressionType(sourceExp);
9396 FinishTemplatesContext(context);
9399 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9401 Class expClass = exp.expType._class.registered;
9404 Class cClass = null;
9409 char templateString[1024];
9410 ClassTemplateParameter param;
9411 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9412 while(cClass != expClass)
9415 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9418 for(param = cClass.templateParams.first; param; param = param.next)
9420 Class cClassCur = null;
9423 ClassTemplateParameter paramCur = null;
9424 ClassTemplateArgument arg;
9425 while(cClassCur != tClass && !paramCur)
9428 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9429 cClassCur = sClassCur;
9431 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9433 if(!strcmp(paramCur.name, param.name))
9441 if(paramCur && paramCur.type == TemplateParameterType::type)
9442 arg = tClass.templateArgs[cp];
9444 arg = expClass.templateArgs[p];
9451 strcat(argument, arg.name.string);
9452 strcat(argument, " = ");
9458 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9459 char expString[1024];
9460 OldList * specs = MkList();
9461 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9463 char * string = PrintHexUInt64(arg.expression.ui64);
9464 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9466 ProcessExpressionType(exp);
9467 ComputeExpression(exp);
9468 expString[0] = '\0';
9469 PrintExpression(exp, expString);
9470 strcat(argument, expString);
9472 FreeExpression(exp);
9477 strcat(argument, arg.member.name);
9480 case TemplateParameterType::type:
9482 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9483 strcat(argument, arg.dataTypeString);
9489 if(paramCount) strcat(templateString, ", ");
9490 if(lastParam != p - 1)
9492 strcat(templateString, param.name);
9493 strcat(templateString, " = ");
9495 strcat(templateString, argument);
9504 int len = strlen(templateString);
9505 if(templateString[len-1] == '>') templateString[len++] = ' ';
9506 templateString[len++] = '>';
9507 templateString[len++] = '\0';
9510 FreeType(exp.expType);
9512 Context context = SetupTemplatesContext(tClass);
9513 exp.expType = ProcessTypeString(templateString, false);
9514 FinishTemplatesContext(context);
9521 Compiler_Error("undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9523 else if(type && (type.kind == structType || type.kind == unionType))
9525 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9528 exp.expType = memberType;
9530 memberType.refCount++;
9535 char expString[10240];
9536 expString[0] = '\0';
9537 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9538 Compiler_Error("member operator on non-structure type expression %s\n", expString);
9541 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9543 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9545 Identifier id = exp.member.member;
9546 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9549 FreeType(exp.expType);
9550 exp.expType = ReplaceThisClassType(_class);
9557 // Convert x->y into (*x).y
9560 Type destType = exp.destType;
9562 // DOING THIS LATER NOW...
9563 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9565 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9566 /* TODO: Name Space Fix ups
9567 if(!exp.member.member.classSym)
9568 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9572 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9573 exp.type = memberExp;
9576 ProcessExpressionType(exp);
9583 //ComputeExpression(exp);
9585 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9586 if(classSym && classSym.registered)
9588 if(classSym.registered.type == noHeadClass)
9592 DeclareStruct(classSym.string, false);
9593 FreeSpecifier(exp._class);
9594 exp.type = typeSizeExp;
9595 FullClassNameCat(name, classSym.string, false);
9596 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9600 if(classSym.registered.fixed)
9602 FreeSpecifier(exp._class);
9603 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9604 exp.type = constantExp;
9608 char className[1024];
9609 strcpy(className, "__ecereClass_");
9610 FullClassNameCat(className, classSym.string, true);
9611 MangleClassName(className);
9613 DeclareClass(classSym, className);
9615 FreeExpContents(exp);
9616 exp.type = pointerExp;
9617 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9618 exp.member.member = MkIdentifier("structSize");
9628 // exp.isConstant = true;
9633 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9640 exp.isConstant = true;
9642 DeclareType(type, false, false);
9648 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9650 FreeType(exp.cast.exp.destType);
9651 exp.cast.exp.destType = type;
9653 ProcessExpressionType(exp.cast.exp);
9658 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9659 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9661 void * prev = exp.prev, * next = exp.next;
9662 Type expType = exp.cast.exp.destType;
9663 Expression castExp = exp.cast.exp;
9664 Type destType = exp.destType;
9666 if(expType) expType.refCount++;
9668 //FreeType(exp.destType);
9669 FreeType(exp.expType);
9670 FreeTypeName(exp.cast.typeName);
9673 FreeType(exp.expType);
9674 FreeType(exp.destType);
9676 exp.expType = expType;
9677 exp.destType = destType;
9687 exp.isConstant = exp.cast.exp.isConstant;
9692 case extensionInitializerExp:
9694 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9696 // ProcessInitializer(exp.initializer.initializer, type);
9702 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9703 ProcessExpressionType(exp.vaArg.exp);
9711 exp.isConstant = true;
9713 FreeType(exp.cond.cond.destType);
9714 exp.cond.cond.destType = MkClassType("bool");
9715 exp.cond.cond.destType.truth = true;
9716 ProcessExpressionType(exp.cond.cond);
9717 if(!exp.cond.cond.isConstant)
9718 exp.isConstant = false;
9719 for(e = exp.cond.exp->first; e; e = e.next)
9723 FreeType(e.destType);
9724 e.destType = exp.destType;
9725 if(e.destType) e.destType.refCount++;
9727 ProcessExpressionType(e);
9730 exp.expType = e.expType;
9731 if(e.expType) e.expType.refCount++;
9734 exp.isConstant = false;
9737 FreeType(exp.cond.elseExp.destType);
9738 // Added this check if we failed to find an expType
9739 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
9742 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
9744 if(exp.cond.elseExp.destType)
9745 exp.cond.elseExp.destType.refCount++;
9746 ProcessExpressionType(exp.cond.elseExp);
9748 // FIXED THIS: Was done before calling process on elseExp
9749 if(!exp.cond.elseExp.isConstant)
9750 exp.isConstant = false;
9753 case extensionCompoundExp:
9755 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
9757 Statement last = exp.compound.compound.statements->last;
9758 if(last.type == expressionStmt && last.expressions && last.expressions->last)
9760 ((Expression)last.expressions->last).destType = exp.destType;
9762 exp.destType.refCount++;
9764 ProcessStatement(exp.compound);
9765 exp.expType = ((Expression)last.expressions->last).expType;
9766 if(((Expression)last.expressions->last).expType)
9767 exp.expType.refCount++;
9773 Specifier spec = exp._classExp.specifiers->first;
9774 if(spec && spec.type == nameSpecifier)
9776 exp.expType = MkClassType(spec.name);
9777 exp.expType.kind = subClassType;
9778 exp.byReference = true;
9782 exp.expType = MkClassType("ecere::com::Class");
9783 exp.byReference = true;
9789 Class _class = thisClass ? thisClass : currentClass;
9792 Identifier id = exp.classData.id;
9793 char structName[1024];
9794 Expression classExp;
9795 strcpy(structName, "__ecereClassData_");
9796 FullClassNameCat(structName, _class.fullName, false);
9797 exp.type = pointerExp;
9798 exp.member.member = id;
9799 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
9800 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
9802 classExp = MkExpIdentifier(MkIdentifier("class"));
9804 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9805 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9806 MkExpBrackets(MkListOne(MkExpOp(
9807 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9808 MkExpMember(classExp, MkIdentifier("data"))), '+',
9809 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
9812 ProcessExpressionType(exp);
9820 char * typeString = null;
9821 char typeStringBuf[1024];
9822 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
9823 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
9825 Class templateClass = exp.destType._class.registered;
9826 typeString = templateClass.templateArgs[2].dataTypeString;
9830 // Guess type from expressions in the array
9832 for(e = exp.list->first; e; e = e.next)
9834 ProcessExpressionType(e);
9837 if(!type) { type = e.expType; type.refCount++; }
9840 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
9841 if(!MatchTypeExpression(e, type, null, false))
9847 e = exp.list->first;
9848 ProcessExpressionType(e);
9851 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
9852 if(!MatchTypeExpression(e, type, null, false))
9854 FreeType(e.expType);
9865 FreeType(e.expType);
9872 typeStringBuf[0] = '\0';
9873 PrintType(type, typeStringBuf, false, true);
9874 typeString = typeStringBuf;
9882 (Container)(__extension__( {
9883 int __arrayMembers[] = { 1, 7, 3, 4, 5 };
9884 BuiltInContainer __baseContainer
9886 data = __arrayMembers,
9889 _vTbl = class(BuiltInContainer)._vTbl,
9890 _class = class(BuiltInContainer) };
9895 char templateString[1024];
9896 OldList * declarations = MkList();
9897 OldList * instMembers = MkList();
9898 OldList * specs = MkList();
9899 OldList * initializers = MkList();
9903 Declarator decl = SpecDeclFromString(typeString, specs, null);
9904 Context context = PushContext();
9906 // sprintf(templateString, "Container<%s >", typeString);
9907 sprintf(templateString, "Container<%s>", typeString);
9909 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("data")), MkInitializerAssignment(MkExpIdentifier(MkIdentifier("__internalList")))));
9911 sprintf(count, "%d", exp.list->count);
9912 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("count")), MkInitializerAssignment(MkExpConstant(count))));
9914 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("type")), MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier),
9915 CopyDeclarator(decl)))));
9917 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("_vTbl")), MkInitializerAssignment(MkExpMember(
9918 MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl")))));
9920 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("_class")), MkInitializerAssignment(
9921 MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null))));
9925 type = ProcessTypeString(typeString, false);
9926 while(e = exp.list->first)
9928 exp.list->Remove(e);
9931 ProcessExpressionType(e);
9932 ListAdd(initializers, MkInitializerAssignment(e));
9938 ListAdd(declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(decl,
9939 MkDeclaratorIdentifier(MkIdentifier("__internalList"))), null),
9940 MkInitializerList(initializers)))));
9941 ListAdd(declarations, MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName("BuiltInContainer")),
9942 MkExpIdentifier(MkIdentifier("__internalContainer")), MkListOne(MkMembersInitList(instMembers)))));
9944 exp.expType = ProcessTypeString(templateString, false);
9945 exp.type = bracketsExp;
9946 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
9947 (expExt = MkExpExtensionCompound(MkCompoundStmt(
9948 declarations, MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internalContainer")))))))))));
9949 expExt.compound.compound.context = context;
9950 PopContext(context);
9951 ProcessExpressionType(expExt);
9955 exp.expType = ProcessTypeString("Container", false);
9956 Compiler_Error("Couldn't determine type of array elements\n");
9962 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
9964 FreeType(exp.expType);
9965 exp.expType = ReplaceThisClassType(thisClass);
9968 // Resolve structures here
9969 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
9971 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
9972 // TODO: Fix members reference...
9975 if(exp.expType.kind != enumType)
9978 exp.expType.members = symbol.type.members;
9979 for(member = symbol.type.members.first; member; member = member.next)
9985 for(member = symbol.type.members.first; member; member = member.next)
9987 NamedLink value { name = CopyString(member.name) };
9988 exp.expType.members.Add(value);
9995 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
9996 else if(exp.destType && !exp.destType.keepCast)
9998 if(!CheckExpressionType(exp, exp.destType, false))
10000 if(!exp.destType.count || unresolved)
10005 if(exp.destType.kind != ellipsisType)
10011 char expString[10240];
10012 expString[0] = '\0';
10014 PrintType(exp.destType, type2, false, true);
10016 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10018 Compiler_Error("unresolved identifier %s; expected %s\n", expString, type2);
10019 else if(exp.type != dummyExp)
10020 Compiler_Error("couldn't determine type of %s; expected %s\n", expString, type2);
10025 char expString[10240] ;
10026 expString[0] = '\0';
10027 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10030 Compiler_Error("unresolved identifier %s\n", expString);
10031 else if(exp.type != dummyExp)
10032 Compiler_Error("couldn't determine type of %s\n", expString);
10043 PrintType(exp.expType, type1, false, true);
10044 PrintType(exp.destType, type2, false, true);
10047 //CheckExpressionType(exp, exp.destType, false);
10049 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10050 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10051 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10054 char expString[10240];
10055 expString[0] = '\0';
10056 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10059 CheckExpressionType(exp, exp.destType, false);
10061 Compiler_Warning("incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10063 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10064 FreeType(exp.expType);
10065 exp.destType.refCount++;
10066 exp.expType = exp.destType;
10071 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10073 Expression newExp { };
10074 char typeString[1024];
10075 OldList * specs = MkList();
10078 typeString[0] = '\0';
10082 if(exp.expType) exp.expType.refCount++;
10083 if(exp.expType) exp.expType.refCount++;
10084 exp.type = castExp;
10085 newExp.destType = exp.expType;
10087 PrintType(exp.expType, typeString, false, false);
10088 decl = SpecDeclFromString(typeString, specs, null);
10090 exp.cast.typeName = MkTypeName(specs, decl);
10091 exp.cast.exp = newExp;
10094 else if(unresolved)
10096 if(exp.identifier._class && exp.identifier._class.name)
10097 Compiler_Error("unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10098 else if(exp.identifier.string && exp.identifier.string[0])
10099 Compiler_Error("unresolved identifier %s\n", exp.identifier.string);
10101 else if(!exp.expType && exp.type != dummyExp)
10103 char expString[10240];
10104 expString[0] = '\0';
10105 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10106 Compiler_Error("couldn't determine type of %s\n", expString);
10109 // Let's try to support any_object & typed_object here:
10110 ApplyAnyObjectLogic(exp);
10112 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10113 exp.expType._class.registered.type == noHeadClass)
10115 exp.byReference = true;
10117 /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10118 exp.destType._class.registered.type == noHeadClass)
10120 exp.byReference = true;
10122 yylloc = oldyylloc;
10125 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10127 // THIS CODE WILL FIND NEXT MEMBER...
10130 *curMember = (*curMember).next;
10132 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10134 *curMember = subMemberStack[--(*subMemberStackPos)];
10135 *curMember = (*curMember).next;
10138 // SKIP ALL PROPERTIES HERE...
10139 while((*curMember) && (*curMember).isProperty)
10140 *curMember = (*curMember).next;
10142 if(subMemberStackPos)
10144 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10146 subMemberStack[(*subMemberStackPos)++] = *curMember;
10148 *curMember = (*curMember).members.first;
10149 while(*curMember && (*curMember).isProperty)
10150 *curMember = (*curMember).next;
10158 if(subMemberStackPos && *subMemberStackPos)
10160 *curMember = subMemberStack[--(*subMemberStackPos)];
10161 *curMember = (*curMember).next;
10165 Class lastCurClass = *curClass;
10167 if(*curClass == _class) break; // REACHED THE END
10169 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10170 *curMember = (*curClass).membersAndProperties.first;
10173 while((*curMember) && (*curMember).isProperty)
10174 *curMember = (*curMember).next;
10175 if(subMemberStackPos)
10177 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10179 subMemberStack[(*subMemberStackPos)++] = *curMember;
10181 *curMember = (*curMember).members.first;
10182 while(*curMember && (*curMember).isProperty)
10183 *curMember = (*curMember).next;
10191 static void ProcessInitializer(Initializer init, Type type)
10195 case expInitializer:
10196 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10198 // TESTING THIS FOR SHUTTING = 0 WARNING
10199 if(init.exp && !init.exp.destType)
10201 FreeType(init.exp.destType);
10202 init.exp.destType = type;
10203 if(type) type.refCount++;
10207 ProcessExpressionType(init.exp);
10208 init.isConstant = init.exp.isConstant;
10214 Expression exp = init.exp;
10215 Instantiation inst = exp.instance;
10216 MembersInit members;
10218 init.type = listInitializer;
10219 init.list = MkList();
10223 for(members = inst.members->first; members; members = members.next)
10225 if(members.type == dataMembersInit)
10228 for(member = members.dataMembers->first; member; member = member.next)
10230 ListAdd(init.list, member.initializer);
10231 member.initializer = null;
10234 // Discard all MembersInitMethod
10237 FreeExpression(exp);
10239 case listInitializer:
10242 Type initializerType = null;
10243 Class curClass = null;
10244 DataMember curMember = null;
10245 DataMember subMemberStack[256];
10246 int subMemberStackPos = 0;
10248 if(type && type.kind == arrayType)
10249 initializerType = Dereference(type);
10250 else if(type && (type.kind == structType || type.kind == unionType))
10251 initializerType = type.members.first;
10253 for(i = init.list->first; i; i = i.next)
10255 if(type && type.kind == classType && type._class && type._class.registered)
10257 // THIS IS FOR A C STYLE INSTANTIATION OF STRUCT CLASSES ONLY... WE ONLY CARE ABOUT DATA MEMBERS, AND ACTUAL MEMORY ORDER (PRIVATE MEMBERS ARE INCLUDED)
10258 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10259 // TODO: Generate error on initializing a private data member this way from another module...
10262 if(!curMember.dataType)
10263 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10264 initializerType = curMember.dataType;
10267 ProcessInitializer(i, initializerType);
10268 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10269 initializerType = initializerType.next;
10271 init.isConstant = false;
10274 if(type && type.kind == arrayType)
10275 FreeType(initializerType);
10277 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10279 Compiler_Error("Assigning list initializer to non list\n");
10286 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10290 case baseSpecifier:
10292 if(spec.specifier == THISCLASS)
10296 spec.type = nameSpecifier;
10297 spec.name = ReplaceThisClass(thisClass);
10298 spec.symbol = FindClass(spec.name);
10299 ProcessSpecifier(spec, declareStruct);
10304 case nameSpecifier:
10306 Symbol symbol = FindType(curContext, spec.name);
10308 DeclareType(symbol.type, true, true);
10309 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10310 DeclareStruct(spec.name, false);
10313 case enumSpecifier:
10318 for(e = spec.list->first; e; e = e.next)
10321 ProcessExpressionType(e.exp);
10326 case structSpecifier:
10327 case unionSpecifier:
10329 if(spec.definitions)
10332 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10334 ProcessClass(spec.definitions, symbol);
10337 for(def = spec.definitions->first; def; def = def.next)
10339 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10340 ProcessDeclaration(def.decl);
10347 case classSpecifier:
10349 Symbol classSym = FindClass(spec.name);
10350 if(classSym && classSym.registered && classSym.registered.type == structClass)
10351 DeclareStruct(spec.name, false);
10359 static void ProcessDeclarator(Declarator decl)
10363 case identifierDeclarator:
10364 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10366 FreeSpecifier(decl.identifier._class);
10367 decl.identifier._class = null;
10370 case arrayDeclarator:
10372 ProcessExpressionType(decl.array.exp);
10373 case structDeclarator:
10374 case bracketsDeclarator:
10375 case functionDeclarator:
10376 case pointerDeclarator:
10377 case extendedDeclarator:
10378 case extendedDeclaratorEnd:
10379 if(decl.declarator)
10380 ProcessDeclarator(decl.declarator);
10381 if(decl.type == functionDeclarator)
10383 Identifier id = GetDeclId(decl);
10384 if(id && id._class)
10388 qualifiers = MkListOne(id._class);
10391 if(!decl.function.parameters)
10392 decl.function.parameters = MkList();
10393 decl.function.parameters->Insert(null, param);
10396 if(decl.function.parameters)
10400 for(param = decl.function.parameters->first; param; param = param.next)
10402 if(param.qualifiers && param.qualifiers->first)
10404 Specifier spec = param.qualifiers->first;
10405 if(spec && spec.specifier == TYPED_OBJECT)
10407 Declarator d = param.declarator;
10410 qualifiers = MkListOne(MkSpecifier(VOID));
10411 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10414 FreeList(param.qualifiers, FreeSpecifier);
10416 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10417 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10419 decl.function.parameters->Insert(param, newParam);
10422 else if(spec && spec.specifier == ANY_OBJECT)
10424 Declarator d = param.declarator;
10426 FreeList(param.qualifiers, FreeSpecifier);
10428 param.qualifiers = MkListOne(MkSpecifier(VOID));
10429 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10431 else if(spec.specifier == THISCLASS)
10435 spec.type = nameSpecifier;
10436 spec.name = ReplaceThisClass(thisClass);
10437 spec.symbol = FindClass(spec.name);
10438 ProcessSpecifier(spec, false);
10443 if(param.declarator)
10444 ProcessDeclarator(param.declarator);
10452 static void ProcessDeclaration(Declaration decl)
10457 case initDeclaration:
10459 bool declareStruct = false;
10461 lineNum = decl.pos.line;
10462 column = decl.pos.col;
10465 if(decl.declarators)
10469 for(d = decl.declarators->first; d; d = d.next)
10471 Type type, subType;
10472 ProcessDeclarator(d.declarator);
10474 type = ProcessType(decl.specifiers, d.declarator);
10478 ProcessInitializer(d.initializer, type);
10480 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10482 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10483 d.initializer.exp.type == instanceExp)
10485 if(type.kind == classType && type._class ==
10486 d.initializer.exp.expType._class)
10488 Instantiation inst = d.initializer.exp.instance;
10489 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10491 d.initializer.exp.instance = null;
10492 if(decl.specifiers)
10493 FreeList(decl.specifiers, FreeSpecifier);
10494 FreeList(decl.declarators, FreeInitDeclarator);
10498 decl.type = instDeclaration;
10503 for(subType = type; subType;)
10505 if(subType.kind == classType)
10507 declareStruct = true;
10510 else if(subType.kind == pointerType)
10512 else if(subType.kind == arrayType)
10513 subType = subType.arrayType;
10523 if(decl.specifiers)
10526 for(s = decl.specifiers->first; s; s = s.next)
10528 ProcessSpecifier(s, declareStruct);
10533 case instDeclaration:
10535 ProcessInstantiationType(decl.inst);
10538 case structDeclaration:
10542 bool declareStruct = false;
10544 if(decl.declarators)
10546 for(d = decl.declarators->first; d; d = d.next)
10548 Type type = ProcessType(decl.specifiers, d.declarator);
10550 ProcessDeclarator(d);
10551 for(subType = type; subType;)
10553 if(subType.kind == classType)
10555 declareStruct = true;
10558 else if(subType.kind == pointerType)
10560 else if(subType.kind == arrayType)
10561 subType = subType.arrayType;
10568 if(decl.specifiers)
10570 for(spec = decl.specifiers->first; spec; spec = spec.next)
10571 ProcessSpecifier(spec, declareStruct);
10578 static FunctionDefinition curFunction;
10580 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10582 char propName[1024], propNameM[1024];
10583 char getName[1024], setName[1024];
10586 DeclareProperty(prop, setName, getName);
10588 // eInstance_FireWatchers(object, prop);
10589 strcpy(propName, "__ecereProp_");
10590 FullClassNameCat(propName, prop._class.fullName, false);
10591 strcat(propName, "_");
10592 // strcat(propName, prop.name);
10593 FullClassNameCat(propName, prop.name, true);
10594 MangleClassName(propName);
10596 strcpy(propNameM, "__ecerePropM_");
10597 FullClassNameCat(propNameM, prop._class.fullName, false);
10598 strcat(propNameM, "_");
10599 // strcat(propNameM, prop.name);
10600 FullClassNameCat(propNameM, prop.name, true);
10601 MangleClassName(propNameM);
10603 if(prop.isWatchable)
10606 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10607 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10608 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10611 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10612 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10613 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10619 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10620 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10621 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10624 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10625 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10626 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10629 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10630 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10631 curFunction.propSet.fireWatchersDone = true;
10634 static void ProcessStatement(Statement stmt)
10638 lineNum = stmt.pos.line;
10639 column = stmt.pos.col;
10644 ProcessStatement(stmt.labeled.stmt);
10647 // This expression should be constant...
10648 if(stmt.caseStmt.exp)
10650 FreeType(stmt.caseStmt.exp.destType);
10651 stmt.caseStmt.exp.destType = curSwitchType;
10652 if(curSwitchType) curSwitchType.refCount++;
10653 ProcessExpressionType(stmt.caseStmt.exp);
10654 ComputeExpression(stmt.caseStmt.exp);
10656 if(stmt.caseStmt.stmt)
10657 ProcessStatement(stmt.caseStmt.stmt);
10661 if(stmt.compound.context)
10666 Statement prevCompound = curCompound;
10667 Context prevContext = curContext;
10669 if(!stmt.compound.isSwitch)
10671 curCompound = stmt;
10672 curContext = stmt.compound.context;
10675 if(stmt.compound.declarations)
10677 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10678 ProcessDeclaration(decl);
10680 if(stmt.compound.statements)
10682 for(s = stmt.compound.statements->first; s; s = s.next)
10683 ProcessStatement(s);
10686 curContext = prevContext;
10687 curCompound = prevCompound;
10691 case expressionStmt:
10694 if(stmt.expressions)
10696 for(exp = stmt.expressions->first; exp; exp = exp.next)
10697 ProcessExpressionType(exp);
10705 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10706 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10707 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10708 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10710 ProcessExpressionType(exp);
10712 if(stmt.ifStmt.stmt)
10713 ProcessStatement(stmt.ifStmt.stmt);
10714 if(stmt.ifStmt.elseStmt)
10715 ProcessStatement(stmt.ifStmt.elseStmt);
10720 Type oldSwitchType = curSwitchType;
10721 if(stmt.switchStmt.exp)
10724 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
10734 e.exp.destType = destType;
10737 ProcessExpressionType(exp);
10740 curSwitchType = exp.expType;
10743 ProcessStatement(stmt.switchStmt.stmt);
10744 curSwitchType = oldSwitchType;
10749 if(stmt.whileStmt.exp)
10753 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
10754 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
10755 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
10756 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
10758 ProcessExpressionType(exp);
10761 if(stmt.whileStmt.stmt)
10762 ProcessStatement(stmt.whileStmt.stmt);
10767 if(stmt.doWhile.exp)
10771 if(stmt.doWhile.exp->last)
10773 FreeType(((Expression)stmt.doWhile.exp->last).destType);
10774 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
10775 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
10777 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
10779 ProcessExpressionType(exp);
10782 if(stmt.doWhile.stmt)
10783 ProcessStatement(stmt.doWhile.stmt);
10789 if(stmt.forStmt.init)
10790 ProcessStatement(stmt.forStmt.init);
10792 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
10794 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
10795 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
10796 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
10799 if(stmt.forStmt.check)
10800 ProcessStatement(stmt.forStmt.check);
10801 if(stmt.forStmt.increment)
10803 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
10804 ProcessExpressionType(exp);
10807 if(stmt.forStmt.stmt)
10808 ProcessStatement(stmt.forStmt.stmt);
10813 Identifier id = stmt.forEachStmt.id;
10814 OldList * exp = stmt.forEachStmt.exp;
10815 OldList * filter = stmt.forEachStmt.filter;
10816 Statement block = stmt.forEachStmt.stmt;
10817 char iteratorType[1024];
10820 bool isBuiltin = exp && exp->last &&
10821 (((Expression)exp->last).type == ExpressionType::arrayExp ||
10822 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
10823 Expression arrayExp;
10824 char * typeString = null;
10825 int builtinCount = 0;
10827 for(e = exp ? exp->first : null; e; e = e.next)
10831 FreeType(e.destType);
10832 e.destType = ProcessTypeString("Container", false);
10834 if(!isBuiltin || e.next)
10835 ProcessExpressionType(e);
10838 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
10839 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
10840 eClass_IsDerived(source._class.registered, containerClass)))
10842 Class _class = source ? source._class.registered : null;
10844 Expression expIt = null;
10845 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
10846 Class arrayClass = eSystem_FindClass(privateModule, "Array");
10847 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
10848 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
10849 stmt.type = compoundStmt;
10851 stmt.compound.context = Context { };
10852 stmt.compound.context.parent = curContext;
10853 curContext = stmt.compound.context;
10855 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
10857 Class mapClass = eSystem_FindClass(privateModule, "Map");
10858 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
10859 isCustomAVLTree = true;
10860 if(eClass_IsDerived(source._class.registered, avlTreeClass))
10862 else if(eClass_IsDerived(source._class.registered, mapClass))
10865 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
10866 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
10868 Class listClass = eSystem_FindClass(privateModule, "List");
10870 isList = eClass_IsDerived(source._class.registered, listClass);
10876 OldList * specs = MkList();
10877 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
10878 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
10879 stmt.compound.declarations = MkListOne(
10880 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
10881 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
10882 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
10883 MkInitializerAssignment(MkExpBrackets(exp))))));
10888 char typeStringBuf[1024];
10890 // TODO: Merge this code?
10891 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
10892 if(((Expression)exp->last).type == castExp)
10894 TypeName typeName = ((Expression)exp->last).cast.typeName;
10896 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
10899 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
10900 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
10901 arrayExp.destType._class.registered.templateArgs)
10903 Class templateClass = arrayExp.destType._class.registered;
10904 typeString = templateClass.templateArgs[2].dataTypeString;
10906 else if(arrayExp.list)
10908 // Guess type from expressions in the array
10910 for(e = arrayExp.list->first; e; e = e.next)
10912 ProcessExpressionType(e);
10915 if(!type) { type = e.expType; type.refCount++; }
10918 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10919 if(!MatchTypeExpression(e, type, null, false))
10925 e = arrayExp.list->first;
10926 ProcessExpressionType(e);
10929 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
10930 if(!MatchTypeExpression(e, type, null, false))
10932 FreeType(e.expType);
10943 FreeType(e.expType);
10950 typeStringBuf[0] = '\0';
10951 PrintType(type, typeStringBuf, false, true);
10952 typeString = typeStringBuf;
10958 OldList * initializers = MkList();
10960 OldList * specs = MkList();
10965 builtinCount = arrayExp.list->count;
10966 type = ProcessTypeString(typeString, false);
10967 while(e = arrayExp.list->first)
10969 arrayExp.list->Remove(e);
10972 ProcessExpressionType(e);
10973 ListAdd(initializers, MkInitializerAssignment(e));
10976 delete arrayExp.list;
10978 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
10979 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
10980 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
10982 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
10983 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
10985 FreeList(exp, FreeExpression);
10989 arrayExp.expType = ProcessTypeString("Container", false);
10990 Compiler_Error("Couldn't determine type of array elements\n");
10995 OldList * specs = MkList();
10997 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
10998 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
10999 stmt.compound.declarations = MkListOne(
11000 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11001 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11002 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11003 MkInitializerAssignment(MkExpBrackets(exp))))));
11006 else if(isLinkList && !isList)
11009 OldList * specs = MkList();
11010 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11011 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11012 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11013 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11014 MkInitializerAssignment(MkExpBrackets(exp))))));
11016 /*else if(isCustomAVLTree)
11019 OldList * specs = MkList();
11020 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11021 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11022 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11023 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11024 MkInitializerAssignment(MkExpBrackets(exp))))));
11026 else if(_class.templateArgs)
11029 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11031 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11033 stmt.compound.declarations = MkListOne(
11034 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11035 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11036 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11038 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11040 if(block && block.type == compoundStmt && block.compound.context)
11042 block.compound.context.parent = stmt.compound.context;
11046 block = MkIfStmt(filter, block, null);
11050 stmt.compound.statements = MkListOne(MkForStmt(
11051 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11052 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11053 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11054 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11056 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11057 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11058 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11063 //OldList * specs = MkList();
11064 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11066 sprintf(count, "%d", builtinCount);
11068 stmt.compound.statements = MkListOne(MkForStmt(
11069 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11070 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11071 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11072 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11076 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11077 stmt.compound.statements = MkListOne(MkForStmt(
11078 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11079 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11080 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11081 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11084 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11085 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11086 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11088 else if(isLinkList && !isList)
11090 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11091 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11092 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11093 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11095 stmt.compound.statements = MkListOne(MkForStmt(
11096 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11097 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11098 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11103 OldList * specs = MkList();
11104 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11105 stmt.compound.statements = MkListOne(MkForStmt(
11106 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11107 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11108 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11109 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11110 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11113 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11114 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11115 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11117 /*else if(isCustomAVLTree)
11119 stmt.compound.statements = MkListOne(MkForStmt(
11120 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11121 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11122 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11123 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11126 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11127 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11128 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11132 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11133 MkIdentifier("Next")), null)), block));
11135 ProcessExpressionType(expIt);
11136 if(stmt.compound.declarations->first)
11137 ProcessDeclaration(stmt.compound.declarations->first);
11140 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11142 ProcessStatement(stmt);
11143 curContext = stmt.compound.context.parent;
11148 Compiler_Error("Expression is not a container\n");
11161 if(stmt.expressions)
11163 for(exp = stmt.expressions->first; exp; exp = exp.next)
11167 if(curFunction && !curFunction.type)
11168 curFunction.type = ProcessType(
11169 curFunction.specifiers, curFunction.declarator);
11170 FreeType(exp.destType);
11171 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11172 if(exp.destType) exp.destType.refCount++;
11174 ProcessExpressionType(exp);
11179 case badDeclarationStmt:
11181 ProcessDeclaration(stmt.decl);
11187 if(stmt.asmStmt.inputFields)
11189 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11190 if(field.expression)
11191 ProcessExpressionType(field.expression);
11193 if(stmt.asmStmt.outputFields)
11195 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11196 if(field.expression)
11197 ProcessExpressionType(field.expression);
11199 if(stmt.asmStmt.clobberedFields)
11201 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11203 if(field.expression)
11204 ProcessExpressionType(field.expression);
11211 PropertyWatch propWatch;
11212 OldList * watches = stmt._watch.watches;
11213 Expression object = stmt._watch.object;
11214 Expression watcher = stmt._watch.watcher;
11216 ProcessExpressionType(watcher);
11218 ProcessExpressionType(object);
11222 if(watcher || thisClass)
11224 External external = curExternal;
11225 Context context = curContext;
11227 stmt.type = expressionStmt;
11228 stmt.expressions = MkList();
11230 curExternal = external.prev;
11232 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11234 ClassFunction func;
11235 char watcherName[1024];
11236 Class watcherClass = watcher ?
11237 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11238 External createdExternal;
11240 // Create a declaration above
11241 External externalDecl = MkExternalDeclaration(null);
11242 ast->Insert(curExternal.prev, externalDecl);
11244 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11245 if(propWatch.deleteWatch)
11246 strcat(watcherName, "_delete");
11250 for(propID = propWatch.properties->first; propID; propID = propID.next)
11252 strcat(watcherName, "_");
11253 strcat(watcherName, propID.string);
11257 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11259 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11260 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11261 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11262 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11263 ProcessClassFunctionBody(func, propWatch.compound);
11264 propWatch.compound = null;
11266 //afterExternal = afterExternal ? afterExternal : curExternal;
11268 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11269 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11271 createdExternal.symbol.idCode = external.symbol.idCode;
11273 curExternal = createdExternal;
11274 ProcessFunction(createdExternal.function);
11277 // Create a declaration above
11279 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11280 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11281 externalDecl.declaration = decl;
11282 if(decl.symbol && !decl.symbol.pointerExternal)
11283 decl.symbol.pointerExternal = externalDecl;
11286 if(propWatch.deleteWatch)
11288 OldList * args = MkList();
11289 ListAdd(args, CopyExpression(object));
11290 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11291 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11292 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11296 Class _class = object.expType._class.registered;
11299 for(propID = propWatch.properties->first; propID; propID = propID.next)
11301 char propName[1024];
11302 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11305 char getName[1024], setName[1024];
11306 OldList * args = MkList();
11308 DeclareProperty(prop, setName, getName);
11310 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11311 strcpy(propName, "__ecereProp_");
11312 FullClassNameCat(propName, prop._class.fullName, false);
11313 strcat(propName, "_");
11314 // strcat(propName, prop.name);
11315 FullClassNameCat(propName, prop.name, true);
11317 ListAdd(args, CopyExpression(object));
11318 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11319 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11320 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11322 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11325 Compiler_Error("Property %s not found in class %s\n", prop.name, _class.fullName);
11330 Compiler_Error("Invalid watched object\n");
11333 curExternal = external;
11334 curContext = context;
11337 FreeExpression(watcher);
11339 FreeExpression(object);
11340 FreeList(watches, FreePropertyWatch);
11343 Compiler_Error("No observer specified and not inside a _class\n");
11347 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11349 ProcessStatement(propWatch.compound);
11355 case fireWatchersStmt:
11357 OldList * watches = stmt._watch.watches;
11358 Expression object = stmt._watch.object;
11360 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11361 // printf("%X\n", watches);
11362 // printf("%X\n", stmt._watch.watches);
11364 ProcessExpressionType(object);
11369 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11375 stmt.type = expressionStmt;
11376 stmt.expressions = MkList();
11378 // Check if we're inside a property set
11379 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11381 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11385 //Compiler_Error("No property specified and not inside a property set\n");
11389 for(propID = watches->first; propID; propID = propID.next)
11391 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11394 CreateFireWatcher(prop, object, stmt);
11397 Compiler_Error("Property %s not found in class %s\n", propID.string, _class.fullName);
11402 // Fire all properties!
11405 for(base = _class; base; base = base.base)
11407 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11409 if(prop.isProperty && prop.isWatchable)
11411 CreateFireWatcher(prop, object, stmt);
11418 FreeExpression(object);
11419 FreeList(watches, FreeIdentifier);
11422 Compiler_Error("Invalid object specified and not inside a class\n");
11426 case stopWatchingStmt:
11428 OldList * watches = stmt._watch.watches;
11429 Expression object = stmt._watch.object;
11430 Expression watcher = stmt._watch.watcher;
11433 ProcessExpressionType(object);
11435 ProcessExpressionType(watcher);
11438 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11440 if(watcher || thisClass)
11446 stmt.type = expressionStmt;
11447 stmt.expressions = MkList();
11452 // eInstance_StopWatching(object, null, watcher);
11454 ListAdd(args, CopyExpression(object));
11455 ListAdd(args, MkExpConstant("0"));
11456 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11457 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11461 for(propID = watches->first; propID; propID = propID.next)
11463 char propName[1024];
11464 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11467 char getName[1024], setName[1024];
11468 OldList * args = MkList();
11470 DeclareProperty(prop, setName, getName);
11472 // eInstance_StopWatching(object, prop, watcher);
11473 strcpy(propName, "__ecereProp_");
11474 FullClassNameCat(propName, prop._class.fullName, false);
11475 strcat(propName, "_");
11476 // strcat(propName, prop.name);
11477 FullClassNameCat(propName, prop.name, true);
11478 MangleClassName(propName);
11480 ListAdd(args, CopyExpression(object));
11481 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11482 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11483 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11486 Compiler_Error("Property %s not found in class %s\n", prop.name, _class.fullName);
11491 FreeExpression(object);
11493 FreeExpression(watcher);
11494 FreeList(watches, FreeIdentifier);
11497 Compiler_Error("Invalid object specified and not inside a class\n");
11500 Compiler_Error("No observer specified and not inside a class\n");
11507 static void ProcessFunction(FunctionDefinition function)
11509 Identifier id = GetDeclId(function.declarator);
11510 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11511 Type type = symbol ? symbol.type : null;
11512 Class oldThisClass = thisClass;
11513 Context oldTopContext = topContext;
11515 yylloc = function.loc;
11516 // Process thisClass
11518 if(type && type.thisClass)
11520 Symbol classSym = type.thisClass;
11521 Class _class = type.thisClass.registered;
11522 char className[1024];
11523 char structName[1024];
11524 Declarator funcDecl;
11527 bool typedObject = false;
11529 if(_class && !_class.base)
11531 _class = currentClass;
11532 if(_class && !_class.symbol)
11533 _class.symbol = FindClass(_class.fullName);
11534 classSym = _class ? _class.symbol : null;
11535 typedObject = true;
11538 thisClass = _class;
11540 if(inCompiler && _class)
11542 if(type.kind == functionType)
11544 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11546 //TypeName param = symbol.type.params.first;
11547 Type param = symbol.type.params.first;
11548 symbol.type.params.Remove(param);
11549 //FreeTypeName(param);
11552 if(type.classObjectType != classPointer)
11554 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11555 symbol.type.staticMethod = true;
11556 symbol.type.thisClass = null;
11558 // HIGH DANGER: VERIFYING THIS...
11559 symbol.type.extraParam = false;
11563 strcpy(className, "__ecereClass_");
11564 FullClassNameCat(className, _class.fullName, true);
11566 MangleClassName(className);
11569 FullClassNameCat(structName, _class.fullName, false);
11574 funcDecl = GetFuncDecl(function.declarator);
11577 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11579 TypeName param = funcDecl.function.parameters->first;
11580 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11582 funcDecl.function.parameters->Remove(param);
11583 FreeTypeName(param);
11587 // DANGER: Watch for this... Check if it's a Conversion?
11588 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11590 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11591 if(!function.propertyNoThis)
11593 TypeName thisParam;
11595 if(type.classObjectType != classPointer)
11597 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11598 if(!funcDecl.function.parameters)
11599 funcDecl.function.parameters = MkList();
11600 funcDecl.function.parameters->Insert(null, thisParam);
11605 if(type.classObjectType != classPointer)
11607 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11608 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11611 thisParam = TypeName
11613 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11614 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11616 funcDecl.function.parameters->Insert(null, thisParam);
11621 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11623 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11624 funcDecl = GetFuncDecl(initDecl.declarator);
11627 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11629 TypeName param = funcDecl.function.parameters->first;
11630 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11632 funcDecl.function.parameters->Remove(param);
11633 FreeTypeName(param);
11637 if(type.classObjectType != classPointer)
11639 // DANGER: Watch for this... Check if it's a Conversion?
11640 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11642 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11644 if(!funcDecl.function.parameters)
11645 funcDecl.function.parameters = MkList();
11646 funcDecl.function.parameters->Insert(null, thisParam);
11653 // Add this to the context
11656 if(type.classObjectType != classPointer)
11658 thisSymbol = Symbol
11660 string = CopyString("this");
11661 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11663 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11665 if(typedObject && thisSymbol.type)
11667 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11668 thisSymbol.type.byReference = type.byReference;
11670 thisSymbol = Symbol { string = CopyString("class") };
11671 function.body.compound.context.symbols.Add(thisSymbol);
11677 // Pointer to class data
11679 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11681 DataMember member = null;
11684 for(base = _class; base && base.type != systemClass; base = base.next)
11686 for(member = base.membersAndProperties.first; member; member = member.next)
11687 if(!member.isProperty)
11693 for(member = _class.membersAndProperties.first; member; member = member.next)
11694 if(!member.isProperty)
11698 char pointerName[1024];
11701 Initializer initializer;
11702 Expression exp, bytePtr;
11704 strcpy(pointerName, "__ecerePointer_");
11705 FullClassNameCat(pointerName, _class.fullName, false);
11707 char className[1024];
11708 strcpy(className, "__ecereClass_");
11709 FullClassNameCat(className, classSym.string, true);
11710 MangleClassName(className);
11713 DeclareClass(classSym, className);
11717 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11722 sprintf(string, "%d", _class.offset);
11723 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11727 // ([bytePtr] + [className]->offset)
11728 exp = QBrackets(MkExpOp(bytePtr, '+',
11729 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
11732 // (this ? [exp] : 0)
11733 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
11737 kind = pointerType;
11738 type = Type { refCount = 1, kind = voidType };
11743 yylloc = function.body.loc;
11744 // ([structName] *) [exp]
11745 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
11746 initializer = MkInitializerAssignment(
11747 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
11749 // [structName] * [pointerName] = [initializer];
11750 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
11753 Context prevContext = curContext;
11754 curContext = function.body.compound.context;
11756 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
11757 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
11759 curContext = prevContext;
11763 decl.symbol = null;
11765 if(!function.body.compound.declarations)
11766 function.body.compound.declarations = MkList();
11767 function.body.compound.declarations->Insert(null, decl);
11773 // Loop through the function and replace undeclared identifiers
11774 // which are a member of the class (methods, properties or data)
11775 // by "this.[member]"
11782 FreeSpecifier(id._class);
11785 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11787 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11788 id = GetDeclId(initDecl.declarator);
11790 FreeSpecifier(id._class);
11795 topContext = function.body.compound.context;
11797 FunctionDefinition oldFunction = curFunction;
11798 curFunction = function;
11800 ProcessStatement(function.body);
11802 // If this is a property set and no firewatchers has been done yet, add one here
11803 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
11805 Statement prevCompound = curCompound;
11806 Context prevContext = curContext;
11808 Statement fireWatchers = MkFireWatchersStmt(null, null);
11809 if(!function.body.compound.statements) function.body.compound.statements = MkList();
11810 ListAdd(function.body.compound.statements, fireWatchers);
11812 curCompound = function.body;
11813 curContext = function.body.compound.context;
11815 ProcessStatement(fireWatchers);
11817 curContext = prevContext;
11818 curCompound = prevCompound;
11822 curFunction = oldFunction;
11825 if(function.declarator)
11827 ProcessDeclarator(function.declarator);
11830 topContext = oldTopContext;
11831 thisClass = oldThisClass;
11834 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
11835 static void ProcessClass(OldList definitions, Symbol symbol)
11838 External external = curExternal;
11839 Class regClass = symbol ? symbol.registered : null;
11841 // Process all functions
11842 for(def = definitions.first; def; def = def.next)
11844 if(def.type == functionClassDef)
11846 if(def.function.declarator)
11847 curExternal = def.function.declarator.symbol.pointerExternal;
11849 curExternal = external;
11851 ProcessFunction((FunctionDefinition)def.function);
11853 else if(def.type == declarationClassDef)
11855 if(def.decl.type == instDeclaration)
11857 thisClass = regClass;
11858 ProcessInstantiationType(def.decl.inst);
11864 Class backThisClass = thisClass;
11865 if(regClass) thisClass = regClass;
11866 ProcessDeclaration(def.decl);
11867 thisClass = backThisClass;
11870 else if(def.type == defaultPropertiesClassDef && def.defProperties)
11872 MemberInit defProperty;
11874 // Add this to the context
11875 Symbol thisSymbol = Symbol
11877 string = CopyString("this");
11878 type = regClass ? MkClassType(regClass.fullName) : null;
11880 globalContext.symbols.Add((BTNode)thisSymbol);
11882 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
11884 thisClass = regClass;
11885 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
11889 globalContext.symbols.Remove((BTNode)thisSymbol);
11890 FreeSymbol(thisSymbol);
11892 else if(def.type == propertyClassDef && def.propertyDef)
11894 PropertyDef prop = def.propertyDef;
11896 // Add this to the context
11898 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
11899 globalContext.symbols.Add(thisSymbol);
11902 thisClass = regClass;
11909 string = CopyString("this");
11910 type = MkClassType(regClass.fullName);
11912 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
11915 curExternal = prop.symbol ? prop.symbol.externalSet : null;
11916 ProcessStatement(prop.setStmt);
11924 string = CopyString("this");
11925 type = MkClassType(regClass.fullName);
11927 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
11930 curExternal = prop.symbol ? prop.symbol.externalGet : null;
11931 ProcessStatement(prop.getStmt);
11939 string = CopyString("this");
11940 type = MkClassType(regClass.fullName);
11942 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
11945 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
11946 ProcessStatement(prop.issetStmt);
11952 globalContext.symbols.Remove(thisSymbol);
11953 FreeSymbol(thisSymbol);
11956 else if(def.type == propertyWatchClassDef && def.propertyWatch)
11958 PropertyWatch propertyWatch = def.propertyWatch;
11960 thisClass = regClass;
11961 if(propertyWatch.compound)
11965 string = CopyString("this");
11966 type = regClass ? MkClassType(regClass.fullName) : null;
11969 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
11971 curExternal = null;
11972 ProcessStatement(propertyWatch.compound);
11979 void ComputeDataTypes()
11983 currentClass = null;
11985 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
11987 temp.symbol = Symbol { id = -1000, idCode = -1000 };
11989 // WHERE SHOULD THIS GO?
11990 // curExternal = ast->first;
11991 ast->Insert(null, temp);
11993 curExternal = temp;
11995 DeclareStruct("ecere::com::Class", false);
11996 DeclareStruct("ecere::com::Instance", false);
11997 DeclareStruct("ecere::com::Property", false);
11998 DeclareStruct("ecere::com::DataMember", false);
11999 DeclareStruct("ecere::com::Method", false);
12000 DeclareStruct("ecere::com::SerialBuffer", false);
12001 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12005 for(external = ast->first; external; external = external.next)
12007 afterExternal = curExternal = external;
12008 if(external.type == functionExternal)
12010 currentClass = external.function._class;
12011 ProcessFunction(external.function);
12013 // There shouldn't be any _class member access here anyways...
12014 else if(external.type == declarationExternal)
12016 currentClass = null;
12017 ProcessDeclaration(external.declaration);
12019 else if(external.type == classExternal)
12021 ClassDefinition _class = external._class;
12022 currentClass = external.symbol.registered;
12023 if(_class.definitions)
12025 ProcessClass(_class.definitions, _class.symbol);
12029 // Free class data...
12030 ast->Remove(external);
12034 else if(external.type == nameSpaceExternal)
12036 thisNameSpace = external.id.string;
12039 currentClass = null;
12040 thisNameSpace = null;
12042 delete temp.symbol;