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;
3638 else if(source.kind == classType)
3640 Class _class = source._class ? source._class.registered : null;
3642 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3645 if(dest.kind != classType)
3647 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3648 if(!source._class.registered.dataType)
3649 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3652 dest = MkClassType(source._class.string);
3653 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3654 // dest = MkClassType(source._class.string);
3658 if(dest.kind != classType)
3661 Type tempDest, tempSource;
3663 if(!source._class.registered.dataType)
3664 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3666 for(; _class.base.type != systemClass; _class = _class.base);
3668 tempSource = tempType;
3669 tempType.kind = classType;
3670 tempType._class = FindClass(_class.fullName);
3671 tempType.truth = source.truth;
3672 tempType.classObjectType = source.classObjectType;
3675 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3677 // PUT THIS BACK TESTING UNITS?
3678 if(conversions.last)
3680 ((Conversion)(conversions.last)).resultType = dest;
3684 FreeType(sourceExp.expType);
3685 sourceExp.expType = MkClassType(_class.fullName);
3686 sourceExp.expType.truth = source.truth;
3687 sourceExp.expType.classObjectType = source.classObjectType;
3689 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3691 if(!sourceExp.destType)
3693 FreeType(sourceExp.destType);
3694 sourceExp.destType = sourceExp.expType;
3695 if(sourceExp.expType)
3696 sourceExp.expType.refCount++;
3699 //source = _class.dataType;
3702 // TOCHECK: TESTING THIS NEW CODE
3703 if(!_class.dataType)
3704 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3706 dest = MkClassType(source._class.string);
3707 dest.truth = source.truth;
3708 dest.classObjectType = source.classObjectType;
3711 source = _class.dataType;
3721 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3731 if(source.kind == classType)
3733 Class _class = source._class.registered;
3734 if(_class.type == unitClass)
3736 if(!_class.dataType)
3737 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3738 source = _class.dataType;
3742 if(dest.kind == classType)
3744 Class _class = dest._class ? dest._class.registered : null;
3745 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3746 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3748 if(_class.type == normalClass || _class.type == noHeadClass)
3750 Expression newExp { };
3751 *newExp = *sourceExp;
3752 if(sourceExp.destType) sourceExp.destType.refCount++;
3753 if(sourceExp.expType) sourceExp.expType.refCount++;
3754 sourceExp.type = castExp;
3755 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3756 sourceExp.cast.exp = newExp;
3757 FreeType(sourceExp.expType);
3758 sourceExp.expType = null;
3759 ProcessExpressionType(sourceExp);
3761 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3764 FreeType(sourceExp.expType);
3765 sourceExp.expType = dest;
3769 if(inCompiler) FreeType(dest);
3774 if(!_class.dataType)
3775 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3777 dest = _class.dataType;
3781 // Accept lower precision types for units, since we want to keep the unit type
3782 if(dest.kind == doubleType &&
3783 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3784 source.kind == charType))
3786 specs = MkListOne(MkSpecifier(DOUBLE));
3788 else if(dest.kind == floatType &&
3789 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3790 source.kind == doubleType))
3792 specs = MkListOne(MkSpecifier(FLOAT));
3794 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3795 source.kind == floatType || source.kind == doubleType))
3798 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3799 ListAdd(specs, MkSpecifier(INT64));
3801 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3802 source.kind == floatType || source.kind == doubleType))
3805 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3806 ListAdd(specs, MkSpecifier(INT));
3808 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
3809 source.kind == floatType || source.kind == doubleType))
3812 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3813 ListAdd(specs, MkSpecifier(SHORT));
3815 else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
3816 source.kind == floatType || source.kind == doubleType))
3819 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3820 ListAdd(specs, MkSpecifier(CHAR));
3829 else if(dest.kind == doubleType &&
3830 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3831 source.kind == charType))
3833 specs = MkListOne(MkSpecifier(DOUBLE));
3835 else if(dest.kind == floatType &&
3836 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3838 specs = MkListOne(MkSpecifier(FLOAT));
3840 else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3841 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3844 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3845 ListAdd(specs, MkSpecifier(CHAR));
3847 else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
3848 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3851 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3852 ListAdd(specs, MkSpecifier(SHORT));
3854 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
3857 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3858 ListAdd(specs, MkSpecifier(INT));
3860 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3863 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3864 ListAdd(specs, MkSpecifier(INT64));
3866 else if(dest.kind == enumType &&
3867 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3869 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3880 Expression newExp { };
3881 *newExp = *sourceExp;
3884 if(sourceExp.destType) sourceExp.destType.refCount++;
3885 if(sourceExp.expType) sourceExp.expType.refCount++;
3887 sourceExp.type = castExp;
3888 if(realDest.kind == classType)
3890 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3891 FreeList(specs, FreeSpecifier);
3894 sourceExp.cast.typeName = MkTypeName(specs, null);
3895 if(newExp.type == opExp)
3897 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3900 sourceExp.cast.exp = newExp;
3902 FreeType(sourceExp.expType);
3903 sourceExp.expType = null;
3904 ProcessExpressionType(sourceExp);
3907 FreeList(specs, FreeSpecifier);
3915 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3916 if(sourceExp.type == identifierExp)
3918 Identifier id = sourceExp.identifier;
3919 if(dest.kind == classType)
3921 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3923 Class _class = dest._class.registered;
3924 Class enumClass = eSystem_FindClass(privateModule, "enum");
3927 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3930 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3931 for(value = e.values.first; value; value = value.next)
3933 if(!strcmp(value.name, id.string))
3938 FreeExpContents(sourceExp);
3939 FreeType(sourceExp.expType);
3941 sourceExp.isConstant = true;
3942 sourceExp.expType = MkClassType(_class.fullName);
3946 sourceExp.type = constantExp;
3947 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3948 sprintf(constant, "%d",value.data);
3950 sprintf(constant, "0x%X",value.data);
3951 sourceExp.constant = CopyString(constant);
3952 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3961 // Loop through all enum classes
3962 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3969 #define TERTIARY(o, name, m, t, p) \
3970 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3972 exp.type = constantExp; \
3973 exp.string = p(op1.m ? op2.m : op3.m); \
3975 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3979 #define BINARY(o, name, m, t, p) \
3980 static bool name(Expression exp, Operand op1, Operand op2) \
3983 exp.type = constantExp; \
3984 exp.string = p(op1.m o value2); \
3986 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3990 #define BINARY_DIVIDE(o, name, m, t, p) \
3991 static bool name(Expression exp, Operand op1, Operand op2) \
3994 exp.type = constantExp; \
3995 exp.string = p(value2 ? (op1.m o value2) : 0); \
3997 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4001 #define UNARY(o, name, m, t, p) \
4002 static bool name(Expression exp, Operand op1) \
4004 exp.type = constantExp; \
4005 exp.string = p(o op1.m); \
4007 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4011 #define OPERATOR_ALL(macro, o, name) \
4012 macro(o, Int##name, i, int, PrintInt) \
4013 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4014 macro(o, Short##name, s, short, PrintShort) \
4015 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4016 macro(o, Char##name, c, char, PrintChar) \
4017 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4018 macro(o, Float##name, f, float, PrintFloat) \
4019 macro(o, Double##name, d, double, PrintDouble)
4021 #define OPERATOR_INTTYPES(macro, o, name) \
4022 macro(o, Int##name, i, int, PrintInt) \
4023 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4024 macro(o, Short##name, s, short, PrintShort) \
4025 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4026 macro(o, Char##name, c, char, PrintChar) \
4027 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4030 // binary arithmetic
4031 OPERATOR_ALL(BINARY, +, Add)
4032 OPERATOR_ALL(BINARY, -, Sub)
4033 OPERATOR_ALL(BINARY, *, Mul)
4034 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4035 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4038 OPERATOR_ALL(UNARY, -, Neg)
4040 // unary arithmetic increment and decrement
4041 OPERATOR_ALL(UNARY, ++, Inc)
4042 OPERATOR_ALL(UNARY, --, Dec)
4044 // binary arithmetic assignment
4045 OPERATOR_ALL(BINARY, =, Asign)
4046 OPERATOR_ALL(BINARY, +=, AddAsign)
4047 OPERATOR_ALL(BINARY, -=, SubAsign)
4048 OPERATOR_ALL(BINARY, *=, MulAsign)
4049 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4050 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4053 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4054 OPERATOR_INTTYPES(BINARY, |, BitOr)
4055 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4056 OPERATOR_INTTYPES(BINARY, <<, LShift)
4057 OPERATOR_INTTYPES(BINARY, >>, RShift)
4060 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4062 // binary bitwise assignment
4063 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4064 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4065 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4066 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4067 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4069 // unary logical negation
4070 OPERATOR_INTTYPES(UNARY, !, Not)
4072 // binary logical equality
4073 OPERATOR_ALL(BINARY, ==, Equ)
4074 OPERATOR_ALL(BINARY, !=, Nqu)
4077 OPERATOR_ALL(BINARY, &&, And)
4078 OPERATOR_ALL(BINARY, ||, Or)
4080 // binary logical relational
4081 OPERATOR_ALL(BINARY, >, Grt)
4082 OPERATOR_ALL(BINARY, <, Sma)
4083 OPERATOR_ALL(BINARY, >=, GrtEqu)
4084 OPERATOR_ALL(BINARY, <=, SmaEqu)
4086 // tertiary condition operator
4087 OPERATOR_ALL(TERTIARY, ?, Cond)
4089 //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
4090 #define OPERATOR_TABLE_ALL(name, type) \
4091 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4093 type##Inc, type##Dec, \
4094 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4095 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4097 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4099 type##Equ, type##Nqu, \
4100 type##And, type##Or, \
4101 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4104 #define OPERATOR_TABLE_INTTYPES(name, type) \
4105 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4107 type##Inc, type##Dec, \
4108 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4109 null, null, null, null, null, \
4111 null, null, null, null, null, \
4113 type##Equ, type##Nqu, \
4114 type##And, type##Or, \
4115 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4118 OPERATOR_TABLE_ALL(int, Int)
4119 OPERATOR_TABLE_ALL(uint, UInt)
4120 OPERATOR_TABLE_ALL(short, Short)
4121 OPERATOR_TABLE_ALL(ushort, UShort)
4122 OPERATOR_TABLE_INTTYPES(float, Float)
4123 OPERATOR_TABLE_INTTYPES(double, Double)
4124 OPERATOR_TABLE_ALL(char, Char)
4125 OPERATOR_TABLE_ALL(uchar, UChar)
4127 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4128 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4129 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4130 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4131 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4132 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4133 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4134 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4136 public void ReadString(char * output, char * string)
4138 int len = strlen(string);
4140 bool quoted = false, escaped = false;
4141 for(c = 0; c<len; c++)
4143 char ch = string[c];
4148 case 'n': output[d] = '\n'; break;
4149 case 't': output[d] = '\t'; break;
4150 case 'a': output[d] = '\a'; break;
4151 case 'b': output[d] = '\b'; break;
4152 case 'f': output[d] = '\f'; break;
4153 case 'r': output[d] = '\r'; break;
4154 case 'v': output[d] = '\v'; break;
4155 case '\\': output[d] = '\\'; break;
4156 case '\"': output[d] = '\"'; break;
4157 default: output[d++] = '\\'; output[d] = ch;
4158 //default: output[d] = ch;
4179 public Operand GetOperand(Expression exp)
4182 Type type = exp.expType;
4185 while(type.kind == classType &&
4186 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4188 if(!type._class.registered.dataType)
4189 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4190 type = type._class.registered.dataType;
4193 op.kind = type.kind;
4194 op.type = exp.expType;
4195 if(exp.isConstant && exp.type == constantExp)
4201 if(exp.constant[0] == '\'')
4202 op.c = exp.constant[1];
4203 else if(type.isSigned)
4205 op.c = (char)strtol(exp.constant, null, 0);
4210 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4218 op.s = (short)strtol(exp.constant, null, 0);
4223 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4231 op.i = (int)strtol(exp.constant, null, 0);
4236 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4244 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4249 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4255 op.f = (float)strtod(exp.constant, null);
4259 op.d = (double)strtod(exp.constant, null);
4262 //case classType: For when we have operator overloading...
4263 // Pointer additions
4264 //case functionType:
4268 op.p = (unsigned char *)strtoul(exp.constant, null, 0);
4269 op.kind = pointerType;
4279 static void UnusedFunction()
4282 a.OnGetString(0,0,0);
4285 extern int __ecereVMethodID_class_OnGetString;
4288 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4290 DataMember dataMember;
4291 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4293 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4294 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4298 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4300 void * ptr = inst.data + dataMember.offset + offset;
4301 char * result = null;
4302 exp.loc = member.loc = inst.loc;
4303 ((Identifier)member.identifiers->first).loc = inst.loc;
4305 if(!dataMember.dataType)
4306 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4307 type = dataMember.dataType;
4308 if(type.kind == classType)
4310 Class _class = type._class.registered;
4311 if(_class.type == enumClass)
4313 Class enumClass = eSystem_FindClass(privateModule, "enum");
4316 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4318 for(item = e.values.first; item; item = item.next)
4320 if((int)item.data == *(int *)ptr)
4328 exp.identifier = MkIdentifier(result);
4329 exp.type = identifierExp;
4330 exp.destType = MkClassType(_class.fullName);
4331 ProcessExpressionType(exp);
4335 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4337 if(!_class.dataType)
4338 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4339 type = _class.dataType;
4348 FreeExpContents(exp);
4350 exp.constant = PrintFloat(*(float*)ptr);
4351 exp.type = constantExp;
4356 FreeExpContents(exp);
4358 exp.constant = PrintDouble(*(double*)ptr);
4359 exp.type = constantExp;
4364 FreeExpContents(exp);
4366 exp.constant = PrintInt(*(int*)ptr);
4367 exp.type = constantExp;
4372 FreeExpContents(exp);
4374 exp.constant = PrintInt64(*(int64*)ptr);
4375 exp.type = constantExp;
4379 printf("error: unhandled type populating instance\n");
4382 ListAdd(memberList, member);
4385 if(parentDataMember.type == unionMember)
4390 void PopulateInstance(Instantiation inst)
4392 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4393 Class _class = classSym.registered;
4394 DataMember dataMember;
4395 OldList * memberList = MkList();
4396 inst.members = MkListOne(MkMembersInitList(memberList));
4397 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4399 if(!dataMember.isProperty)
4401 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4402 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4406 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4408 void * ptr = inst.data + dataMember.offset;
4409 char * result = null;
4411 exp.loc = member.loc = inst.loc;
4412 ((Identifier)member.identifiers->first).loc = inst.loc;
4414 if(!dataMember.dataType)
4415 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4416 type = dataMember.dataType;
4417 if(type.kind == classType)
4419 Class _class = type._class.registered;
4420 if(_class.type == enumClass)
4422 Class enumClass = eSystem_FindClass(privateModule, "enum");
4425 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4427 for(item = e.values.first; item; item = item.next)
4429 if((int)item.data == *(int *)ptr)
4438 exp.identifier = MkIdentifier(result);
4439 exp.type = identifierExp;
4440 exp.destType = MkClassType(_class.fullName);
4441 ProcessExpressionType(exp);
4444 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4446 if(!_class.dataType)
4447 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4448 type = _class.dataType;
4457 exp.constant = PrintFloat(*(float*)ptr);
4458 exp.type = constantExp;
4463 exp.constant = PrintDouble(*(double*)ptr);
4464 exp.type = constantExp;
4469 exp.constant = PrintInt(*(int*)ptr);
4470 exp.type = constantExp;
4475 exp.constant = PrintInt64(*(int64*)ptr);
4476 exp.type = constantExp;
4480 printf("error: unhandled type populating instance\n");
4483 ListAdd(memberList, member);
4489 void ComputeInstantiation(Expression exp)
4491 Instantiation inst = exp.instance;
4492 MembersInit members;
4493 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4494 Class _class = classSym ? classSym.registered : null;
4495 DataMember curMember = null;
4496 Class curClass = null;
4497 DataMember subMemberStack[256];
4498 int subMemberStackPos = 0;
4501 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4503 // Don't recompute the instantiation...
4504 // Non Simple classes will have become constants by now
4508 if(_class.type == normalClass || _class.type == noHeadClass)
4509 inst.data = (byte *)eInstance_New(_class);
4511 inst.data = new0 byte[_class.structSize];
4516 for(members = inst.members->first; members; members = members.next)
4518 switch(members.type)
4520 case dataMembersInit:
4522 if(members.dataMembers)
4525 for(member = members.dataMembers->first; member; member = member.next)
4527 Identifier ident = member.identifiers ? member.identifiers->first : null;
4530 Property prop = null;
4531 DataMember dataMember = null;
4532 Method method = null;
4533 uint dataMemberOffset;
4537 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4540 if(curMember.isProperty)
4541 prop = (Property)curMember;
4544 dataMember = curMember;
4546 // CHANGED THIS HERE
4547 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4548 // dataMemberOffset = dataMember.offset;
4555 prop = eClass_FindProperty(_class, ident.string, privateModule);
4559 if(prop.memberAccess == publicAccess)
4561 curMember = (DataMember)prop;
4562 curClass = prop._class;
4567 DataMember _subMemberStack[256];
4568 int _subMemberStackPos = 0;
4570 // FILL MEMBER STACK
4571 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4576 if(dataMember.memberAccess == publicAccess)
4578 curMember = dataMember;
4579 curClass = dataMember._class;
4580 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
4581 subMemberStackPos = _subMemberStackPos;
4587 if(found && member.initializer && member.initializer.type == expInitializer)
4589 Expression value = member.initializer.exp;
4593 type = prop.dataType;
4597 if(!dataMember.dataType)
4598 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4600 type = dataMember.dataType;
4603 if(ident && ident.next)
4605 // for(; ident && type; ident = ident.next)
4606 for(ident = ident.next; ident && type; ident = ident.next)
4608 if(type.kind == classType)
4610 prop = eClass_FindProperty(type._class.registered,
4611 ident.string, privateModule);
4613 type = prop.dataType;
4616 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4617 ident.string, &dataMemberOffset, privateModule, null, null);
4619 type = dataMember.dataType;
4622 else if(type.kind == structType || type.kind == unionType)
4625 for(memberType = type.members.first; memberType; memberType = memberType.next)
4627 if(!strcmp(memberType.name, ident.string))
4638 FreeType(value.destType);
4639 value.destType = type;
4640 if(type) type.refCount++;
4641 ComputeExpression(value);
4643 if(value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4645 if(type.kind == classType)
4647 Class _class = type._class.registered;
4648 if(_class.type == bitClass || _class.type == unitClass ||
4649 _class.type == enumClass)
4651 if(!_class.dataType)
4652 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4653 type = _class.dataType;
4659 void * ptr = inst.data + dataMemberOffset;
4661 if(value.type == constantExp)
4667 GetInt(value, (int*)ptr);
4672 GetInt64(value, (int64*)ptr);
4677 GetFloat(value, (float*)ptr);
4682 GetDouble(value, (double *)ptr);
4687 else if(value.type == instanceExp)
4689 if(type.kind == classType)
4691 Class _class = type._class.registered;
4692 if(_class.type == structClass)
4694 ComputeTypeSize(type);
4695 if(value.instance.data)
4696 memcpy(ptr, value.instance.data, type.size);
4703 if(value.type == instanceExp && value.instance.data)
4705 void (*Set)(void *, void *) = (void *)prop.Set;
4706 Set(inst.data, value.instance.data);
4707 PopulateInstance(inst);
4709 else if(value.type == constantExp)
4715 void (*Set)(void *, double) = (void *)prop.Set;
4716 Set(inst.data, strtod(value.constant, null) );
4721 void (*Set)(void *, float) = (void *)prop.Set;
4722 Set(inst.data, (float)(strtod(value.constant, null)));
4727 void (*Set)(void *, int) = (void *)prop.Set;
4728 Set(inst.data, strtol(value.constant, null, 0));
4733 void (*Set)(void *, int64) = (void *)prop.Set;
4734 Set(inst.data, _strtoi64(value.constant, null, 0));
4739 else if(value.type == stringExp)
4742 ReadString(temp, value.string);
4743 prop.Set(inst.data, temp);
4747 else if(_class.type == unitClass)
4751 // Only support converting units to units for now...
4752 if(value.type == constantExp)
4754 if(type.kind == classType)
4756 Class _class = type._class.registered;
4757 if(_class.type == unitClass)
4759 if(!_class.dataType)
4760 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4761 type = _class.dataType;
4764 // TODO: Assuming same base type for units...
4770 float (*Set)(float) = (void *)prop.Set;
4771 GetFloat(member.initializer.exp, &fValue);
4772 exp.constant = PrintFloat(Set(fValue));
4773 exp.type = constantExp;
4779 double (*Set)(double) = (void *)prop.Set;
4780 GetDouble(member.initializer.exp, &dValue);
4781 exp.constant = PrintDouble(Set(dValue));
4782 exp.type = constantExp;
4789 else if(_class.type == bitClass)
4793 if(value.type == instanceExp && value.instance.data)
4795 unsigned int (*Set)(void *) = (void *)prop.Set;
4796 bits = Set(value.instance.data);
4798 else if(value.type == constantExp)
4804 BitMember bitMember = (BitMember) dataMember;
4807 GetInt(value, &part);
4808 bits = (bits & ~bitMember.mask);
4809 if(!bitMember.dataType)
4810 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4812 type = bitMember.dataType;
4814 if(type.kind == classType && type._class && type._class.registered)
4816 if(!type._class.registered.dataType)
4817 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4818 type = type._class.registered.dataType;
4825 bits |= ((char)part << bitMember.pos);
4827 bits |= ((unsigned char)part << bitMember.pos);
4831 bits |= ((short)part << bitMember.pos);
4833 bits |= ((unsigned short)part << bitMember.pos);
4838 bits |= ((int)part << bitMember.pos);
4840 bits |= ((unsigned int)part << bitMember.pos);
4844 bits |= ((int64)part << bitMember.pos);
4846 bits |= ((uint64)part << bitMember.pos);
4854 if(_class && _class.type == unitClass)
4856 ComputeExpression(member.initializer.exp);
4857 exp.constant = member.initializer.exp.constant;
4858 exp.type = constantExp;
4860 member.initializer.exp.constant = null;
4870 if(_class && _class.type == bitClass)
4872 exp.constant = PrintHexUInt(bits);
4873 exp.type = constantExp;
4875 if(exp.type != instanceExp)
4881 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4883 if(exp.op.op == SIZEOF)
4885 FreeExpContents(exp);
4886 exp.type = constantExp;
4887 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
4898 // Provide default unary +
4899 Expression exp2 = exp.op.exp2;
4901 FreeExpContents(exp);
4902 FreeType(exp.expType);
4903 FreeType(exp.destType);
4909 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
4911 // unary arithmetic increment and decrement
4912 //OPERATOR_ALL(UNARY, ++, Inc)
4913 //OPERATOR_ALL(UNARY, --, Dec)
4916 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
4918 // unary logical negation
4920 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
4928 // binary arithmetic
4930 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
4933 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
4936 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
4939 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
4942 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
4944 // binary arithmetic assignment
4945 //OPERATOR_ALL(BINARY, =, Asign)
4946 //OPERATOR_ALL(BINARY, +=, AddAsign)
4947 //OPERATOR_ALL(BINARY, -=, SubAsign)
4948 //OPERATOR_ALL(BINARY, *=, MulAsign)
4949 //OPERATOR_ALL(BINARY, /=, DivAsign)
4950 //OPERATOR_ALL(BINARY, %=, ModAsign)
4955 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
4959 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
4962 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
4965 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
4968 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
4970 // binary bitwise assignment
4971 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4972 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4973 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4974 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4975 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4976 // binary logical equality
4978 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
4981 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
4985 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
4988 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
4990 // binary logical relational
4992 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
4995 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
4998 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5001 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5008 void ComputeExpression(Expression exp)
5010 char expString[10240];
5011 expString[0] = '\0';
5013 PrintExpression(exp, expString);
5020 ComputeInstantiation(exp);
5029 Expression exp1, exp2 = null;
5033 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5035 ComputeExpression(exp.op.exp2);
5038 ComputeExpression(exp.op.exp1);
5041 op1 = GetOperand(exp1);
5042 if(op1.type) op1.type.refCount++;
5045 op2 = GetOperand(exp2);
5046 if(op2.type) op2.type.refCount++;
5052 op1 = GetOperand(exp1);
5053 if(op1.type) op1.type.refCount++;
5056 CallOperator(exp, exp1, exp2, op1, op2);
5063 if(exp.op.exp1 && exp.op.exp2)
5068 FreeExpContents(exp);
5069 op1.ops.BitAnd(exp, op1, op2);
5078 FreeExpContents(exp);
5079 op1.ops.Mul(exp, op1, op2);
5088 FreeExpContents(exp);
5089 op1.ops.Add(exp, op1, op2);
5094 // Provide default unary +
5095 Expression exp2 = exp.op.exp2;
5097 FreeExpContents(exp);
5098 FreeType(exp.expType);
5099 FreeType(exp.destType);
5110 FreeExpContents(exp);
5111 op1.ops.Sub(exp, op1, op2);
5118 FreeExpContents(exp);
5119 op1.ops.Neg(exp, op1);
5126 FreeExpContents(exp);
5127 op1.ops.BitNot(exp, op1);
5133 FreeExpContents(exp);
5134 op1.ops.Not(exp, op1);
5137 // Binary only operators
5141 FreeExpContents(exp);
5142 op1.ops.Div(exp, op1, op2);
5148 FreeExpContents(exp);
5149 op1.ops.Mod(exp, op1, op2);
5161 FreeExpContents(exp);
5162 op1.ops.Sma(exp, op1, op2);
5171 FreeExpContents(exp);
5172 op1.ops.Grt(exp, op1, op2);
5181 FreeExpContents(exp);
5182 op1.ops.SmaEqu(exp, op1, op2);
5191 FreeExpContents(exp);
5192 op1.ops.GrtEqu(exp, op1, op2);
5201 FreeExpContents(exp);
5202 op1.ops.Equ(exp, op1, op2);
5211 FreeExpContents(exp);
5212 op1.ops.Nqu(exp, op1, op2);
5219 FreeExpContents(exp);
5220 op1.ops.BitOr(exp, op1, op2);
5226 FreeExpContents(exp);
5227 op1.ops.BitXor(exp, op1, op2);
5235 FreeExpContents(exp);
5236 exp.type = constantExp;
5237 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5241 if(op1.type) FreeType(op1.type);
5242 if(op2.type) FreeType(op2.type);
5246 case extensionExpressionExp:
5249 for(e = exp.list->first; e; e = n)
5254 OldList * list = exp.list;
5255 ComputeExpression(e);
5256 //FreeExpContents(exp);
5257 FreeType(exp.expType);
5258 FreeType(exp.destType);
5275 exp.isConstant = true;
5277 ComputeExpression(exp.index.exp);
5278 if(!exp.index.exp.isConstant)
5279 exp.isConstant = false;
5281 for(e = exp.index.index->first; e; e = e.next)
5283 ComputeExpression(e);
5286 // Check if this type is int
5289 exp.isConstant = false;
5291 exp.expType = Dereference(exp.index.exp.expType);
5297 Expression memberExp = exp.member.exp;
5298 Identifier memberID = exp.member.member;
5301 ComputeExpression(exp.member.exp);
5302 type = exp.member.exp.expType;
5305 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);
5306 Property prop = null;
5307 DataMember member = null;
5308 Class convertTo = null;
5309 if(type.kind == subClassType && exp.member.exp.type == classExp)
5310 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5317 PrintType(type, string, false, true);
5318 classSym = FindClass(string);
5319 _class = classSym ? classSym.registered : null;
5322 if(exp.member.member)
5324 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5326 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5328 if(!prop && !member && _class && exp.member.member)
5330 Symbol classSym = FindClass(exp.member.member.string);
5332 _class = classSym ? classSym.registered : null;
5333 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5340 Type type = prop.dataType;
5341 // TODO: Assuming same base type for units...
5342 if(_class.type == unitClass)
5344 if(type.kind == classType)
5346 Class _class = type._class.registered;
5347 if(_class.type == unitClass)
5349 if(!_class.dataType)
5350 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5351 type = _class.dataType;
5359 float (*Get)(float) = (void *)prop.Get;
5360 GetFloat(exp.member.exp, &value);
5361 exp.constant = PrintFloat(Get ? Get(value) : value);
5362 exp.type = constantExp;
5368 double (*Get)(double);
5369 GetDouble(exp.member.exp, &value);
5372 Get = (void *)prop.Set;
5374 Get = (void *)prop.Get;
5375 exp.constant = PrintDouble(Get ? Get(value) : value);
5376 exp.type = constantExp;
5385 Expression value = exp.member.exp;
5388 ProcessPropertyType(prop);
5390 type = prop.dataType;
5393 // printf("Investigate this\n");
5395 else if(_class.type == structClass)
5401 Class propertyClass = type._class.registered;
5402 if(propertyClass.type == structClass && value.type == instanceExp)
5404 void (*Set)(void *, void *) = (void *)prop.Set;
5405 exp.instance = Instantiation { };
5406 exp.instance.data = new0 byte[_class.structSize];
5407 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5408 exp.instance.loc = exp.loc;
5409 exp.type = instanceExp;
5410 Set(exp.instance.data, value.instance.data);
5411 PopulateInstance(exp.instance);
5418 void (*Set)(void *, int) = (void *)prop.Set;
5420 exp.instance = Instantiation { };
5421 exp.instance.data = new0 byte[_class.structSize];
5422 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5423 exp.instance.loc = exp.loc;
5424 exp.type = instanceExp;
5426 GetInt(value, &intValue);
5428 Set(exp.instance.data, intValue);
5429 PopulateInstance(exp.instance);
5435 void (*Set)(void *, int64) = (void *)prop.Set;
5437 exp.instance = Instantiation { };
5438 exp.instance.data = new0 byte[_class.structSize];
5439 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5440 exp.instance.loc = exp.loc;
5441 exp.type = instanceExp;
5443 GetInt64(value, &intValue);
5445 Set(exp.instance.data, intValue);
5446 PopulateInstance(exp.instance);
5452 void (*Set)(void *, double) = (void *)prop.Set;
5454 exp.instance = Instantiation { };
5455 exp.instance.data = new0 byte[_class.structSize];
5456 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5457 exp.instance.loc = exp.loc;
5458 exp.type = instanceExp;
5460 GetDouble(value, &doubleValue);
5462 Set(exp.instance.data, doubleValue);
5463 PopulateInstance(exp.instance);
5468 else if(_class.type == bitClass)
5474 Class propertyClass = type._class.registered;
5475 if(propertyClass.type == structClass && value.instance.data)
5477 unsigned int (*Set)(void *) = (void *)prop.Set;
5478 unsigned int bits = Set(value.instance.data);
5479 exp.constant = PrintHexUInt(bits);
5480 exp.type = constantExp;
5483 else if(_class.type == bitClass)
5486 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5489 GetUInt(exp.member.exp, &value);
5491 exp.constant = PrintHexUInt(bits);
5492 exp.type = constantExp;
5500 if(_class.type == bitClass)
5503 GetUInt(exp.member.exp, &value);
5509 Class _class = type._class.registered;
5510 if(_class.type == structClass)
5512 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5514 exp.instance = Instantiation { };
5515 exp.instance.data = new0 byte[_class.structSize];
5516 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5517 exp.instance.loc = exp.loc;
5518 //exp.instance.fullSet = true;
5519 exp.type = instanceExp;
5520 Get(value, exp.instance.data);
5521 PopulateInstance(exp.instance);
5523 else if(_class.type == bitClass)
5525 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5526 uint64 bits = Get(value);
5527 exp.constant = PrintHexUInt64(bits);
5528 exp.type = constantExp;
5534 else if(_class.type == structClass)
5536 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5541 Class _class = type._class.registered;
5542 if(_class.type == structClass && value)
5544 void (*Get)(void *, void *) = (void *)prop.Get;
5546 exp.instance = Instantiation { };
5547 exp.instance.data = new0 byte[_class.structSize];
5548 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5549 exp.instance.loc = exp.loc;
5550 //exp.instance.fullSet = true;
5551 exp.type = instanceExp;
5552 Get(value, exp.instance.data);
5553 PopulateInstance(exp.instance);
5561 char * value = exp.member.exp.instance.data;
5566 Class _class = type._class.registered;
5567 if(_class.type == normalClass)
5569 void *(*Get)(void *) = (void *)prop.Get;
5571 exp.instance = Instantiation { };
5572 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5573 exp.type = instanceExp;
5574 exp.instance.data = Get(value, exp.instance.data);
5586 exp.isConstant = false;
5594 if(exp.type != ExpressionType::memberExp)
5596 FreeExpression(memberExp);
5597 FreeIdentifier(memberID);
5603 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5604 FreeExpContents(exp);
5605 exp.constant = PrintUInt(ComputeTypeSize(type));
5606 exp.type = constantExp;
5612 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5613 if(classSym && classSym.registered)
5615 if(classSym.registered.fixed)
5617 FreeSpecifier(exp._class);
5618 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5619 exp.type = constantExp;
5623 char className[1024];
5624 strcpy(className, "__ecereClass_");
5625 FullClassNameCat(className, classSym.string, true);
5626 MangleClassName(className);
5628 FreeExpContents(exp);
5629 exp.type = pointerExp;
5630 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5631 exp.member.member = MkIdentifier("structSize");
5641 if(exp.type == castExp)
5644 ComputeExpression(exp.cast.exp);
5647 if(e && exp.expType)
5650 type = exp.destType;
5653 if(type.kind == classType)
5655 Class _class = type._class.registered;
5656 if(_class && (_class.type == unitClass || _class.type == bitClass))
5658 if(!_class.dataType)
5659 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5660 type = _class.dataType;
5671 FreeExpContents(exp);
5672 exp.constant = PrintChar(value);
5673 exp.type = constantExp;
5677 unsigned char value;
5678 GetUChar(e, &value);
5679 FreeExpContents(exp);
5680 exp.constant = PrintUChar(value);
5681 exp.type = constantExp;
5688 GetShort(e, &value);
5689 FreeExpContents(exp);
5690 exp.constant = PrintShort(value);
5691 exp.type = constantExp;
5695 unsigned short value;
5696 GetUShort(e, &value);
5697 FreeExpContents(exp);
5698 exp.constant = PrintUShort(value);
5699 exp.type = constantExp;
5707 FreeExpContents(exp);
5708 exp.constant = PrintInt(value);
5709 exp.type = constantExp;
5715 FreeExpContents(exp);
5716 exp.constant = PrintUInt(value);
5717 exp.type = constantExp;
5724 GetInt64(e, &value);
5725 FreeExpContents(exp);
5726 exp.constant = PrintInt64(value);
5727 exp.type = constantExp;
5732 GetUInt64(e, &value);
5733 FreeExpContents(exp);
5734 exp.constant = PrintUInt64(value);
5735 exp.type = constantExp;
5741 GetFloat(e, &value);
5742 FreeExpContents(exp);
5743 exp.constant = PrintFloat(value);
5744 exp.type = constantExp;
5750 GetDouble(e, &value);
5751 FreeExpContents(exp);
5752 exp.constant = PrintDouble(value);
5753 exp.type = constantExp;
5767 // Caring only about last expression for now...
5768 ComputeExpression(exp.cond.exp->last);
5769 if(exp.cond.elseExp)
5770 ComputeExpression(exp.cond.elseExp);
5772 ComputeExpression(exp.cond.cond);
5774 op1 = GetOperand(exp.cond.cond);
5775 if(op1.type) op1.type.refCount++;
5776 op2 = GetOperand(exp.cond.exp->last);
5777 if(op2.type) op2.type.refCount++;
5778 op3 = GetOperand(exp.cond.elseExp);
5779 if(op3.type) op3.type.refCount++;
5781 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5782 if(op1.type) FreeType(op1.type);
5783 if(op2.type) FreeType(op2.type);
5784 if(op3.type) FreeType(op3.type);
5790 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5795 OldList converts { };
5798 if(destType.kind == voidType)
5801 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5805 // for(convert = converts.last; convert; convert = convert.prev)
5806 for(convert = converts.first; convert; convert = convert.next)
5808 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
5811 Expression newExp { };
5812 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
5814 // TODO: Check this...
5816 newExp.destType = null;
5821 exp.type = memberExp;
5822 exp.addedThis = true;
5823 exp.member.exp = newExp;
5824 FreeType(exp.member.exp.expType);
5826 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
5827 exp.member.exp.expType.classObjectType = objectType;
5828 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
5829 exp.member.memberType = propertyMember;
5830 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5831 // TESTING THIS... for (int)degrees
5832 exp.needCast = true;
5833 if(exp.expType) exp.expType.refCount++;
5834 ApplyAnyObjectLogic(exp.member.exp);
5839 /*if(exp.isConstant)
5841 // Color { ColorRGB = [exp] };
5842 exp.type = instanceExp;
5843 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
5844 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
5845 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
5849 // If not constant, don't turn it yet into an instantiation
5850 // (Go through the deep members system first)
5851 exp.type = memberExp;
5852 exp.addedThis = true;
5853 exp.member.exp = newExp;
5855 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
5856 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
5857 newExp.expType._class.registered.type == noHeadClass)
5859 newExp.byReference = true;
5862 FreeType(exp.member.exp.expType);
5863 /*exp.member.exp.expType = convert.convert.dataType;
5864 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
5865 exp.member.exp.expType = null;
5866 if(convert.convert.dataType)
5868 exp.member.exp.expType = { };
5869 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
5870 exp.member.exp.expType.refCount = 1;
5871 exp.member.exp.expType.classObjectType = objectType;
5872 ApplyAnyObjectLogic(exp.member.exp);
5875 exp.member.member = MkIdentifier(convert.convert._class.fullName);
5876 exp.member.memberType = reverseConversionMember;
5877 exp.expType = convert.resultType ? convert.resultType :
5878 MkClassType(convert.convert._class.fullName);
5879 exp.needCast = true;
5880 if(convert.resultType) convert.resultType.refCount++;
5886 FreeType(exp.expType);
5889 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5890 exp.needCast = true;
5891 if(exp.expType) exp.expType.refCount++;
5895 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
5896 exp.needCast = true;
5897 if(convert.resultType)
5898 convert.resultType.refCount++;
5902 if(exp.isConstant && inCompiler)
5903 ComputeExpression(exp);
5905 converts.Free(FreeConvert);
5908 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
5910 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
5912 if(!result && exp.expType && exp.destType)
5914 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
5915 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
5916 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
5917 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
5921 // if(result) CheckTemplateTypes(exp);
5925 void CheckTemplateTypes(Expression exp)
5927 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
5929 Expression newExp { };
5933 if(exp.destType) exp.destType.refCount++;
5934 if(exp.expType) exp.expType.refCount++;
5938 switch(exp.expType.kind)
5943 context = PushContext();
5944 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
5945 MkExpExtensionCompound(compound = MkCompoundStmt(
5946 MkListOne(MkDeclaration(MkListOne(MkSpecifier(DOUBLE)),
5947 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal")), MkInitializerAssignment(newExp))))),
5948 MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internal")))))))));
5949 compound.compound.context = context;
5950 PopContext(context);
5955 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
5956 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
5960 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
5962 Expression newExp { };
5966 if(exp.destType) exp.destType.refCount++;
5967 if(exp.expType) exp.expType.refCount++;
5971 switch(exp.expType.kind)
5976 context = PushContext();
5977 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifier(DOUBLE)), MkDeclaratorPointer(MkPointer(null, null), null)),
5978 MkExpExtensionCompound(compound = MkCompoundStmt(
5979 MkListOne(MkDeclaration(MkListOne(MkSpecifierName("uint64")),
5980 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal")), MkInitializerAssignment(newExp))))),
5981 MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internal")))))))));
5982 compound.compound.context = context;
5983 PopContext(context);
5985 ProcessExpressionType(exp.op.exp2);
5989 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
5991 exp.type = bracketsExp;
5992 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
5993 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
5994 ProcessExpressionType(exp.list->first);
5999 exp.type = bracketsExp;
6000 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6001 newExp.needCast = true;
6002 ProcessExpressionType(exp.list->first);
6008 if(exp.expType.kind == templateType)
6010 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6013 FreeType(exp.destType);
6014 FreeType(exp.expType);
6019 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6024 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6025 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6029 char typeString[1024];
6031 OldList * specs = MkList();
6032 typeString[0] = '\0';
6033 PrintType(exp.expType, typeString, false, false);
6034 decl = SpecDeclFromString(typeString, specs, null);
6037 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6038 exp.cast.typeName = MkTypeName(specs, decl);
6039 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6040 exp.cast.exp.needCast = true;
6048 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6051 int nsLen = strlen(nameSpace);
6052 for(symbol = (Symbol)tree.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6054 if(!strncmp(symbol.string, nameSpace, nsLen))
6058 for(c = strlen(symbol.string)-1; c >= 0; c--)
6059 if(symbol.string[c] == ':')
6062 namePart = symbol.string+c+1;
6063 if(!strcmp(namePart, name))
6065 // TODO: Error on ambiguity
6073 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6076 char nameSpace[1024];
6078 bool gotColon = false;
6080 nameSpace[0] = '\0';
6081 for(c = strlen(name)-1; c >= 0; c--)
6088 namePart = name+c+1;
6089 while(c >= 0 && name[c] == ':') c--;
6092 memcpy(nameSpace, name, c + 1);
6094 return ScanWithNameSpace(tree, nameSpace, namePart);
6098 Symbol symbol = (Symbol)tree.FindString(namePart);
6102 return ScanWithNameSpace(tree, "", namePart);
6106 static void ProcessDeclaration(Declaration decl);
6108 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6111 //Time startTime = GetTime();
6113 // Optimize this later? Do this before/less?
6115 Symbol symbol = null;
6116 // First, check if the identifier is declared inside the function
6117 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6119 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6121 if(ctx == globalContext && !globalNameSpace)
6127 strcpy(curName, thisNameSpace);
6128 strcat(curName, "::");
6129 strcat(curName, name);
6130 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6133 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6136 symbol = (Symbol)ctx.structSymbols.FindString(name);
6138 symbol = (Symbol)ctx.symbols.FindString(name);
6140 if(symbol || ctx == endContext) break;
6142 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6144 if(symbol.pointerExternal.type == functionExternal)
6146 FunctionDefinition function = symbol.pointerExternal.function;
6148 // Modified this recently...
6149 Context tmpContext = curContext;
6151 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6152 curContext = tmpContext;
6154 symbol.pointerExternal.symbol = symbol;
6157 DeclareType(symbol.type, true, true);
6159 ast->Insert(curExternal.prev, symbol.pointerExternal);
6161 symbol.id = curExternal.symbol.idCode;
6164 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6166 ast->Move(symbol.pointerExternal, curExternal.prev);
6167 symbol.id = curExternal.symbol.idCode;
6171 //findSymbolTotalTime += GetTime() - startTime;
6176 static void GetTypeSpecs(Type type, OldList * specs)
6178 if(!type.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
6183 if(type._class.registered)
6185 if(!type._class.registered.dataType)
6186 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6187 GetTypeSpecs(type._class.registered.dataType, specs);
6191 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6192 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6193 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6194 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6195 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6198 ListAdd(specs, MkSpecifier(INT)); break;
6202 // WARNING : This function expects a null terminated string since it recursively concatenate...
6203 static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
6210 if(type._class && type._class.string)
6212 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6213 // look into merging with thisclass ?
6214 if(type.classObjectType == typedObject)
6215 strcat(string, "typed_object");
6217 strcat(string, type._class.string);
6220 if(type._class.registered)
6221 strcat(string, type._class.registered.name);
6223 strcat(string, type._class.string);
6230 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6231 if(funcType && funcType.kind == functionType)
6234 PrintType(funcType.returnType, string, false, fullName);
6235 strcat(string, "(*");
6236 if(printName || funcType.thisClass)
6238 strcat(string, " ");
6239 if(funcType.thisClass)
6241 strcat(string, funcType.thisClass.string);
6242 strcat(string, "::");
6245 strcat(string, type.name);
6247 strcat(string, ")(");
6248 for(param = funcType.params.first; param; param = param.next)
6250 PrintType(param, string, false, fullName);
6251 if(param.next) strcat(string, ", ");
6253 strcat(string, ")");
6257 _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
6258 strcat(string, " *");
6262 case voidType: strcat(string, "void"); break;
6263 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6264 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6265 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6266 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6267 case floatType: strcat(string, "float"); break;
6268 case doubleType: strcat(string, "double"); break;
6272 strcat(string, "struct ");
6273 strcat(string, type.enumName);
6275 else if(type.typeName)
6277 strcat(string, type.typeName);
6282 strcat(string, "struct ");
6283 strcat(string,"(unnamed)");
6286 strcat(string, "struct {");
6287 for(member = type.members.first; member; member = member.next)
6289 PrintType(member, string, true, fullName);
6290 strcat(string,"; ");
6298 strcat(string, "union ");
6299 strcat(string, type.enumName);
6301 else if(type.typeName)
6303 strcat(string, type.typeName);
6307 strcat(string, "union ");
6308 strcat(string,"(unnamed)");
6314 strcat(string, "enum ");
6315 strcat(string, type.enumName);
6317 else if(type.typeName)
6319 strcat(string, type.typeName);
6322 strcat(string, "enum");
6329 strcat(string, "dllexport ");
6330 PrintType(type.returnType, string, false, fullName);
6331 strcat(string, " ");
6334 // DANGER: Testing This
6340 strcat(string, type.name);
6343 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6344 if(name) name += 2; else name = type.name;
6345 strcat(string, name);
6359 strcat(string, "(");
6360 for(param = type.params.first; param; param = param.next)
6362 PrintType(param, string, true, fullName);
6363 if(param.next) strcat(string, ", ");
6365 strcat(string, ")");
6372 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6373 if(funcType && funcType.kind == functionType)
6376 PrintType(funcType.returnType, string, false, fullName);
6377 strcat(string, "(*");
6378 if(printName || funcType.thisClass)
6380 strcat(string, " ");
6381 if(funcType.thisClass)
6383 strcat(string, funcType.thisClass.string);
6384 strcat(string, "::");
6387 strcat(string, type.name);
6389 strcat(string, ")(");
6390 for(param = funcType.params.first; param; param = param.next)
6392 PrintType(param, string, false, fullName);
6393 if(param.next) strcat(string, ", ");
6395 strcat(string, ")");
6399 char baseType[1024], size[256];
6400 Type arrayType = type;
6404 while(arrayType.kind == TypeKind::arrayType)
6407 if(arrayType.enumClass)
6408 strcat(size, arrayType.enumClass.string);
6409 else if(arrayType.arraySizeExp)
6410 PrintExpression(arrayType.arraySizeExp, size);
6411 //sprintf(string, "%s[%s]", baseType, size);
6414 arrayType = arrayType.arrayType;
6416 _PrintType(arrayType, baseType, printName, printFunction, fullName);
6417 strcat(string, baseType);
6418 strcat(string, size);
6422 PrintType(type.arrayType, baseType, printName, fullName);
6424 strcpy(size, type.enumClass.string);
6425 else if(type.arraySizeExp)
6426 PrintExpression(type.arraySizeExp, size);
6427 //sprintf(string, "%s[%s]", baseType, size);
6428 strcat(string, baseType);
6429 strcat(string, "[");
6430 strcat(string, size);
6431 strcat(string, "]");
6438 strcat(string, "...");
6441 _PrintType(type.method.dataType, string, false, printFunction, fullName);
6444 strcat(string, "subclass(");
6445 strcat(string, type._class ? type._class.string : "int");
6446 strcat(string, ")");
6449 strcat(string, type.templateParameter.identifier.string);
6452 strcat(string, "thisclass");
6455 strcat(string, "__builtin_va_list");
6462 if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
6464 strcat(string, " ");
6465 strcat(string, type.name);
6470 void PrintType(Type type, char * string, bool printName, bool fullName)
6473 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6474 if(funcType && funcType.kind == functionType && type != funcType)
6476 char typeString[1024];
6479 PrintType(funcType.returnType, string, false, fullName);
6480 strcat(string, "(");
6481 _PrintType(type, string, printName, false, fullName);
6482 strcat(string, ")");
6485 strcat(string, type.name);
6491 strcat(string, "(");
6492 for(param = funcType.params.first; param; param = param.next)
6494 PrintType(param, string, true, fullName);
6495 if(param.next) strcat(string, ", ");
6497 strcat(string, ")");
6500 _PrintType(type, string, printName, true, fullName);
6501 if(type.bitFieldCount)
6504 sprintf(count, ":%d", type.bitFieldCount);
6505 strcat(string, count);
6509 static Type FindMember(Type type, char * string)
6512 for(memberType = type.members.first; memberType; memberType = memberType.next)
6514 if(!memberType.name)
6516 Type subType = FindMember(memberType, string);
6520 else if(!strcmp(memberType.name, string))
6526 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6529 for(memberType = type.members.first; memberType; memberType = memberType.next)
6531 if(!memberType.name)
6533 Type subType = FindMember(memberType, string);
6536 *offset += memberType.offset;
6540 else if(!strcmp(memberType.name, string))
6542 *offset += memberType.offset;
6549 Expression ParseExpressionString(char * expression)
6551 fileInput = TempFile { };
6552 fileInput.Write(expression, 1, strlen(expression));
6553 fileInput.Seek(0, start);
6556 parsedExpression = null;
6558 expression_yyparse();
6561 return parsedExpression;
6564 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6566 Identifier id = exp.identifier;
6567 Method method = null;
6568 Property prop = null;
6569 DataMember member = null;
6570 ClassProperty classProp = null;
6572 if(_class && _class.type == enumClass)
6574 NamedLink value = null;
6575 Class enumClass = eSystem_FindClass(privateModule, "enum");
6579 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6581 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6582 for(value = e.values.first; value; value = value.next)
6584 if(!strcmp(value.name, id.string))
6591 FreeExpContents(exp);
6593 exp.type = constantExp;
6594 exp.isConstant = true;
6595 if(!strcmp(baseClass.dataTypeString, "int"))
6596 sprintf(constant, "%d",value.data);
6598 sprintf(constant, "0x%X",value.data);
6599 exp.constant = CopyString(constant);
6600 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6601 exp.expType = MkClassType(baseClass.fullName);
6609 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6611 ProcessMethodType(method);
6618 // TOCHECK: Put it back to what it was...
6619 // methodClass = _class;
6620 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6625 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6628 ProcessPropertyType(prop);
6629 exp.expType = prop.dataType;
6630 if(prop.dataType) prop.dataType.refCount++;
6633 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6635 if(!member.dataType)
6636 member.dataType = ProcessTypeString(member.dataTypeString, false);
6637 exp.expType = member.dataType;
6638 if(member.dataType) member.dataType.refCount++;
6641 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6643 if(!classProp.dataType)
6644 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6646 if(classProp.constant)
6648 FreeExpContents(exp);
6650 exp.isConstant = true;
6651 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6653 //char constant[256];
6654 exp.type = stringExp;
6655 exp.constant = QMkString((char *)classProp.Get(_class));
6660 exp.type = constantExp;
6661 sprintf(constant, "%d",classProp.Get(_class));
6662 exp.constant = CopyString(constant);
6670 exp.expType = classProp.dataType;
6671 if(classProp.dataType) classProp.dataType.refCount++;
6677 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6679 BinaryTree * tree = &nameSpace.functions;
6680 GlobalData data = (GlobalData)tree->FindString(name);
6684 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6686 data = ScanGlobalData(child, name);
6694 static GlobalData FindGlobalData(char * name)
6697 NameSpace * nameSpace;
6698 nameSpace = globalData;
6699 for(c = 0; name[c]; c++)
6701 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6703 NameSpace * newSpace;
6704 char * spaceName = new char[c - start + 1];
6705 strncpy(spaceName, name + start, c - start);
6706 spaceName[c-start] = '\0';
6707 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6711 nameSpace = newSpace;
6712 if(name[c] == ':') c++;
6718 return ScanGlobalData(nameSpace, name + start);
6723 static int definedExpStackPos;
6724 static void * definedExpStack[512];
6726 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6727 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6729 Expression prev = checkedExp.prev, next = checkedExp.next;
6731 FreeExpContents(checkedExp);
6732 FreeType(checkedExp.expType);
6733 FreeType(checkedExp.destType);
6735 *checkedExp = *newExp;
6739 checkedExp.prev = prev;
6740 checkedExp.next = next;
6743 void ApplyAnyObjectLogic(Expression e)
6745 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6746 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6748 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6749 //ellipsisDestType = destType;
6752 Type type = e.expType;
6753 Class _class = null;
6754 //Type destType = e.destType;
6756 if(type.kind == classType && type._class && type._class.registered)
6758 _class = type._class.registered;
6760 else if(type.kind == subClassType)
6762 _class = FindClass("ecere::com::Class").registered;
6766 char string[1024] = "";
6769 PrintType(type, string, false, true);
6770 classSym = FindClass(string);
6771 if(classSym) _class = classSym.registered;
6774 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...
6775 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6776 destType.byReference)))
6778 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6780 Expression checkedExp = e, newExp;
6782 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6784 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6786 if(checkedExp.type == extensionCompoundExp)
6788 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6791 checkedExp = checkedExp.list->last;
6793 else if(checkedExp.type == castExp)
6794 checkedExp = checkedExp.cast.exp;
6797 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6799 newExp = checkedExp.op.exp2;
6800 checkedExp.op.exp2 = null;
6801 FreeExpContents(checkedExp);
6803 if(e.expType && e.expType.passAsTemplate)
6806 ComputeTypeSize(e.expType);
6807 sprintf(size, "%d", e.expType.size);
6808 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6809 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6810 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6813 ReplaceExpContents(checkedExp, newExp);
6814 e.byReference = true;
6816 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6818 Expression checkedExp, newExp;
6821 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6823 e.type == identifierExp ||
6824 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6825 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
6826 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
6829 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
6831 Context context = PushContext();
6833 OldList * specs = MkList();
6834 char typeString[1024];
6835 Expression newExp { };
6837 typeString[0] = '\0';
6840 //if(e.destType) e.destType.refCount++;
6841 // if(exp.expType) exp.expType.refCount++;
6844 newExp.expType = null;
6846 PrintType(e.expType, typeString, false, true);
6847 decl = SpecDeclFromString(typeString, specs, null);
6848 newExp.destType = ProcessType(specs, decl);
6850 curContext = context;
6851 e.type = extensionCompoundExp;
6852 e.compound = MkCompoundStmt(
6853 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
6854 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
6856 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
6859 Type type = e.destType;
6861 CopyTypeInto(e.destType, type);
6862 e.destType.refCount = 1;
6863 e.destType.classObjectType = none;
6867 e.compound.compound.context = context;
6868 PopContext(context);
6869 curContext = context.parent;
6873 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
6875 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6877 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6879 if(checkedExp.type == extensionCompoundExp)
6881 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6884 checkedExp = checkedExp.list->last;
6886 else if(checkedExp.type == castExp)
6887 checkedExp = checkedExp.cast.exp;
6890 Expression operand { };
6891 operand = *checkedExp;
6892 checkedExp.destType = null;
6893 checkedExp.expType = null;
6895 checkedExp.type = opExp;
6896 checkedExp.op.op = '&';
6897 checkedExp.op.exp1 = null;
6898 checkedExp.op.exp2 = operand;
6900 //newExp = MkExpOp(null, '&', checkedExp);
6902 //ReplaceExpContents(checkedExp, newExp);
6909 // If expression type is a simple class, make it an address
6910 // FixReference(e, true);
6913 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
6914 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
6915 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
6917 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
6919 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
6923 Expression thisExp { };
6926 thisExp.prev = null;
6927 thisExp.next = null;
6930 e.type = bracketsExp;
6931 e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
6932 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
6933 ((Expression)e.list->first).byReference = true;
6935 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
6937 e.expType = thisExp.expType;
6938 e.expType.refCount++;
6943 CopyTypeInto(e.expType, thisExp.expType);
6944 e.expType.byReference = false;
6945 e.expType.refCount = 1;
6947 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
6948 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
6950 e.expType.classObjectType = none;
6955 // TOFIX: Try this for a nice IDE crash!
6957 // The other way around
6960 if(destType && e.expType &&
6961 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
6962 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
6963 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
6965 if(destType.kind == ellipsisType)
6967 Compiler_Error("Unspecified type\n");
6969 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
6971 bool byReference = e.expType.byReference;
6972 Expression thisExp { };
6974 OldList * specs = MkList();
6975 char typeString[1024]; // Watch buffer overruns
6977 ClassObjectType backupClassObjectType;
6979 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
6984 backupClassObjectType = type.classObjectType;
6986 type.classObjectType = none;
6988 typeString[0] = '\0';
6989 PrintType(type, typeString, false, true);
6990 decl = SpecDeclFromString(typeString, specs, null);
6992 type.classObjectType = backupClassObjectType;
6995 thisExp.prev = null;
6996 thisExp.next = null;
6999 if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
7000 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7001 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7002 (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
7003 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7008 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7013 e.cast.typeName = MkTypeName(specs, decl);
7014 e.cast.exp = thisExp;
7015 e.byReference = true;
7018 e.destType = destType;
7020 destType.refCount++;
7025 void ProcessExpressionType(Expression exp)
7027 bool unresolved = false;
7028 Location oldyylloc = yylloc;
7029 bool notByReference = false;
7031 char debugExpString[4096];
7032 debugExpString[0] = '\0';
7033 PrintExpression(exp, debugExpString);
7035 if(!exp || exp.expType)
7038 //eSystem_Logf("%s\n", expString);
7040 // Testing this here
7046 Identifier id = exp.identifier;
7049 // DOING THIS LATER NOW...
7050 if(id._class && id._class.name)
7052 id.classSym = id._class.symbol; // FindClass(id._class.name);
7053 /* TODO: Name Space Fix ups
7055 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7059 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7061 exp.expType = ProcessTypeString("Module", true);
7064 else */if(strstr(id.string, "__ecereClass") == id.string)
7066 exp.expType = ProcessTypeString("ecere::com::Class", true);
7069 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7071 // Added this here as well
7072 ReplaceClassMembers(exp, thisClass);
7073 if(exp.type != identifierExp)
7075 ProcessExpressionType(exp);
7079 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7084 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7085 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7086 if(!symbol/* && exp.destType*/)
7088 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7094 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7095 if(exp.type != identifierExp)
7097 ProcessExpressionType(exp);
7101 // Static methods called from inside the _class
7102 else if(currentClass && !id._class)
7104 if(ResolveIdWithClass(exp, currentClass, true))
7107 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7111 // If we manage to resolve this symbol
7114 Type type = symbol.type;
7115 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7117 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7119 Context context = SetupTemplatesContext(_class);
7120 type = ReplaceThisClassType(_class);
7121 FinishTemplatesContext(context);
7122 if(type) type.refCount = 0; // We'll be incrementing it right below...
7125 FreeSpecifier(id._class);
7128 id.string = CopyString(symbol.string);
7134 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7135 // Add missing cases here... enum Classes...
7136 exp.isConstant = true;
7138 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7139 if(symbol.isParam || !strcmp(id.string, "this"))
7141 if(_class && _class.type == structClass)
7142 exp.byReference = true;
7144 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7145 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7146 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7147 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7149 Identifier id = exp.identifier;
7150 exp.type = bracketsExp;
7151 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7155 if(symbol.isIterator)
7157 if(symbol.isIterator == 3)
7159 exp.type = bracketsExp;
7160 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7161 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7163 ProcessExpressionType(exp);
7165 else if(symbol.isIterator != 4)
7167 exp.type = memberExp;
7168 exp.member.exp = MkExpIdentifier(exp.identifier);
7169 exp.member.exp.expType = exp.expType;
7170 /*if(symbol.isIterator == 6)
7171 exp.member.member = MkIdentifier("key");
7173 exp.member.member = MkIdentifier("data");
7175 ProcessExpressionType(exp);
7182 DefinedExpression definedExp = null;
7183 if(thisNameSpace && !(id._class && !id._class.name))
7186 strcpy(name, thisNameSpace);
7188 strcat(name, id.string);
7189 definedExp = eSystem_FindDefine(privateModule, name);
7192 definedExp = eSystem_FindDefine(privateModule, id.string);
7196 for(c = 0; c<definedExpStackPos; c++)
7197 if(definedExpStack[c] == definedExp)
7199 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7201 Location backupYylloc = yylloc;
7202 definedExpStack[definedExpStackPos++] = definedExp;
7203 fileInput = TempFile { };
7204 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7205 fileInput.Seek(0, start);
7208 parsedExpression = null;
7210 expression_yyparse();
7213 yylloc = backupYylloc;
7215 if(parsedExpression)
7218 exp.type = bracketsExp;
7219 exp.list = MkListOne(parsedExpression);
7220 parsedExpression.loc = yylloc;
7221 ProcessExpressionType(exp);
7222 definedExpStackPos--;
7225 definedExpStackPos--;
7231 Compiler_Error("Recursion in defined expression %s\n", id.string);
7237 GlobalData data = null;
7238 if(thisNameSpace && !(id._class && !id._class.name))
7241 strcpy(name, thisNameSpace);
7243 strcat(name, id.string);
7244 data = FindGlobalData(name);
7247 data = FindGlobalData(id.string);
7250 DeclareGlobalData(data);
7251 exp.expType = data.dataType;
7252 if(data.dataType) data.dataType.refCount++;
7255 id.string = CopyString(data.fullName);
7256 FreeSpecifier(id._class);
7263 GlobalFunction function = null;
7264 if(thisNameSpace && !(id._class && !id._class.name))
7267 strcpy(name, thisNameSpace);
7269 strcat(name, id.string);
7270 function = eSystem_FindFunction(privateModule, name);
7273 function = eSystem_FindFunction(privateModule, id.string);
7278 id.string = CopyString(function.name);
7281 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7282 strcpy(name, "__ecereFunction_");
7283 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7284 if(DeclareFunction(function, name))
7287 id.string = CopyString(name);
7289 exp.expType = function.dataType;
7290 if(function.dataType) function.dataType.refCount++;
7292 FreeSpecifier(id._class);
7309 if(!exp.instance._class)
7311 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7313 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7323 //classSym = FindClass(exp.instance._class.fullName);
7324 //_class = classSym ? classSym.registered : null;
7326 ProcessInstantiationType(exp.instance);
7327 exp.isConstant = exp.instance.isConstant;
7330 if(_class.type == unitClass && _class.base.type != systemClass)
7333 Type destType = exp.destType;
7335 exp.destType = MkClassType(_class.base.fullName);
7336 exp.expType = MkClassType(_class.fullName);
7337 CheckExpressionType(exp, exp.destType, true);
7339 exp.destType = destType;
7341 exp.expType = MkClassType(_class.fullName);
7344 if(exp.instance._class)
7346 exp.expType = MkClassType(exp.instance._class.name);
7347 /*if(exp.expType._class && exp.expType._class.registered &&
7348 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7349 exp.expType.byReference = true;*/
7364 if(exp.constant[0] == '\'')
7366 if((int)((byte *)exp.constant)[1] > 127)
7369 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7370 if(nb < 2) ch = exp.constant[1];
7371 delete exp.constant;
7372 exp.constant = PrintUInt(ch);
7373 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7374 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7375 type._class = FindClass("unichar");
7377 type.isSigned = false;
7381 type.kind = charType;
7382 type.isSigned = true;
7385 else if(strchr(exp.constant, '.'))
7387 char ch = exp.constant[strlen(exp.constant)-1];
7389 type.kind = floatType;
7391 type.kind = doubleType;
7392 type.isSigned = true;
7396 if(exp.constant[0] == '0' && exp.constant[1])
7397 type.isSigned = false;
7398 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7399 type.isSigned = false;
7400 else if(strtoll(exp.constant, null, 0) > MAXINT)
7401 type.isSigned = false;
7403 type.isSigned = true;
7404 type.kind = intType;
7406 exp.isConstant = true;
7412 exp.isConstant = true; // Why wasn't this constant?
7428 ProcessExpressionType(exp._new.size);
7433 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7435 DeclareType(exp.expType.type, false, false);
7439 ProcessExpressionType(exp._renew.size);
7440 ProcessExpressionType(exp._renew.exp);
7445 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7447 DeclareType(exp.expType.type, false, false);
7451 bool assign = false, boolResult = false, boolOps = false;
7452 Type type1 = null, type2 = null;
7453 bool useDestType = false, useSideType = false;
7454 Location oldyylloc = yylloc;
7455 bool useSideUnit = false;
7457 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7466 // Assignment Operators
7480 // boolean Operators
7482 // Expect boolean operators
7484 //boolResult = true;
7488 // Expect boolean operands
7499 // Gives boolean result
7507 // Just added these... testing
7512 // DANGER: Verify units
7517 if(exp.op.op != '*' || exp.op.exp1)
7524 /*// Implement speed etc.
7530 if(exp.op.op == '&')
7532 // Added this here earlier for Iterator address as key
7533 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7535 Identifier id = exp.op.exp2.identifier;
7536 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7537 if(symbol && symbol.isIterator == 2)
7539 exp.type = memberExp;
7540 exp.member.exp = exp.op.exp2;
7541 exp.member.member = MkIdentifier("key");
7543 exp.op.exp2.expType = symbol.type;
7544 symbol.type.refCount++;
7545 ProcessExpressionType(exp);
7549 // exp.op.exp2.usage.usageRef = true;
7553 //dummy.kind = TypeDummy;
7557 if(exp.destType && exp.destType.kind == classType &&
7558 exp.destType._class && exp.destType._class.registered && useDestType &&
7560 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7561 exp.destType._class.registered.type == enumClass ||
7562 exp.destType._class.registered.type == bitClass
7565 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7567 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7568 exp.op.exp1.destType = exp.destType;
7570 exp.destType.refCount++;
7574 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7575 exp.op.exp1.destType = dummy;
7579 // TESTING THIS HERE...
7580 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7581 ProcessExpressionType(exp.op.exp1);
7582 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7584 if(exp.op.exp1.destType == dummy)
7587 exp.op.exp1.destType = null;
7589 type1 = exp.op.exp1.expType;
7594 char expString[10240];
7595 expString[0] = '\0';
7596 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7600 exp.op.exp2.destType = exp.op.exp1.expType;
7601 if(exp.op.exp1.expType)
7602 exp.op.exp1.expType.refCount++;
7606 exp.op.exp2.destType = exp.destType;
7608 exp.destType.refCount++;
7611 if(type1) type1.refCount++;
7612 exp.expType = type1;
7617 PrintExpression(exp.op.exp2, expString);
7619 if(type1 && type1.kind == pointerType)
7621 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 ||
7622 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7623 Compiler_Error("operator %s illegal on pointer\n", exp.op.op);
7624 else if(exp.op.op == '=')
7626 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7627 exp.op.exp2.destType = type1;
7634 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7635 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/* ||
7636 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7639 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7640 exp.op.exp2.destType = type1;
7645 if(type1) type1.refCount++;
7646 exp.expType = type1;
7648 else if(exp.destType && exp.destType.kind == classType &&
7649 exp.destType._class && exp.destType._class.registered &&
7651 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7652 (exp.destType._class.registered.type == enumClass && useDestType))
7655 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7656 exp.op.exp2.destType = exp.destType;
7658 exp.destType.refCount++;
7662 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7663 exp.op.exp2.destType = dummy;
7667 // TESTING THIS HERE... (DANGEROUS)
7668 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7669 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7671 FreeType(exp.op.exp2.destType);
7672 exp.op.exp2.destType = type1;
7675 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7676 ProcessExpressionType(exp.op.exp2);
7677 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7679 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7681 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)
7683 if(exp.op.op != '=' && type1.type.kind == voidType)
7684 Compiler_Error("void *: unknown size\n");
7686 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||
7687 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7688 (exp.op.exp2.expType._class.registered.type == normalClass ||
7689 exp.op.exp2.expType._class.registered.type == structClass ||
7690 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7692 if(exp.op.op == ADD_ASSIGN)
7693 Compiler_Error("cannot add two pointers\n");
7695 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7696 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7698 if(exp.op.op == ADD_ASSIGN)
7699 Compiler_Error("cannot add two pointers\n");
7703 char type1String[1024];
7704 char type2String[1024];
7705 type1String[0] = '\0';
7706 type2String[0] = '\0';
7708 PrintType(exp.op.exp2.expType, type1String, false, true);
7709 PrintType(type1, type2String, false, true);
7710 ChangeCh(expString, '\n', ' ');
7711 Compiler_Warning("incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7715 if(exp.op.exp2.destType == dummy)
7718 exp.op.exp2.destType = null;
7721 type2 = exp.op.exp2.expType;
7724 dummy.kind = voidType;
7726 if(exp.op.op == SIZEOF)
7733 exp.isConstant = true;
7735 // Get type of dereferenced pointer
7736 else if(exp.op.op == '*' && !exp.op.exp1)
7738 exp.expType = Dereference(type2);
7739 if(type2 && type2.kind == classType)
7740 notByReference = true;
7742 else if(exp.op.op == '&' && !exp.op.exp1)
7743 exp.expType = Reference(type2);
7750 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7751 exp.op.exp1.destType = MkClassType("bool");
7752 exp.op.exp1.destType.truth = true;
7753 if(!exp.op.exp1.expType)
7754 ProcessExpressionType(exp.op.exp1);
7756 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7757 FreeType(exp.op.exp1.expType);
7758 exp.op.exp1.expType = MkClassType("bool");
7759 exp.op.exp1.expType.truth = true;
7763 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7764 exp.op.exp2.destType = MkClassType("bool");
7765 exp.op.exp2.destType.truth = true;
7766 if(!exp.op.exp2.expType)
7767 ProcessExpressionType(exp.op.exp2);
7769 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7770 FreeType(exp.op.exp2.expType);
7771 exp.op.exp2.expType = MkClassType("bool");
7772 exp.op.exp2.expType.truth = true;
7775 else if(exp.op.exp1 && exp.op.exp2 &&
7778 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7779 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7780 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7781 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7783 if(type1 && type2 &&
7784 // If either both are class or both are not class
7785 ((type1.kind == classType && strcmp(type1._class.string, "String")) == (type2.kind == classType && strcmp(type2._class.string, "String"))))
7787 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7788 exp.op.exp2.destType = type1;
7790 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7791 exp.op.exp1.destType = type2;
7793 // Warning here for adding Radians + Degrees with no destination type
7794 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7795 type1._class.registered && type1._class.registered.type == unitClass &&
7796 type2._class.registered && type2._class.registered.type == unitClass &&
7797 type1._class.registered != type2._class.registered)
7798 Compiler_Warning("operating on %s and %s with an untyped result, assuming %s\n",
7799 type1._class.string, type2._class.string, type1._class.string);
7801 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7803 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7806 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7808 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
7809 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
7812 ProcessExpressionType(exp.op.exp1);
7814 if(type2.kind != pointerType)
7816 ProcessExpressionType(classExp);
7818 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
7819 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7820 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7822 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
7825 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
7826 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7827 MkPointer(null, null), null)))),
7828 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
7830 if(!exp.op.exp2.expType)
7831 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
7833 ProcessExpressionType(exp.op.exp2);
7838 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)))
7840 if(type1.kind != classType && type1.type.kind == voidType)
7841 Compiler_Error("void *: unknown size\n");
7842 exp.expType = type1;
7843 if(type1) type1.refCount++;
7845 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)))
7847 if(type2.kind != classType && type2.type.kind == voidType)
7848 Compiler_Error("void *: unknown size\n");
7849 exp.expType = type2;
7850 if(type2) type2.refCount++;
7852 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
7853 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
7855 Compiler_Warning("different levels of indirection\n");
7859 bool success = false;
7860 if(type1.kind == pointerType && type2.kind == pointerType)
7862 if(exp.op.op == '+')
7863 Compiler_Error("cannot add two pointers\n");
7864 else if(exp.op.op == '-')
7866 // Pointer Subtraction gives integer
7867 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
7876 if(type1.type.kind == templateType)
7878 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7881 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7883 ProcessExpressionType(classExp);
7885 exp.type = bracketsExp;
7886 exp.list = MkListOne(MkExpOp(
7887 MkExpBrackets(MkListOne(MkExpOp(
7888 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
7890 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
7892 //MkExpMember(classExp, MkIdentifier("typeSize"))
7894 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7895 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7897 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
7900 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
7901 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7902 MkPointer(null, null), null)))),
7903 MkExpMember(classExp, MkIdentifier("typeSize")))))
7908 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
7917 if(!success && exp.op.exp1.type == constantExp)
7919 // If first expression is constant, try to match that first
7920 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
7922 if(exp.expType) FreeType(exp.expType);
7923 exp.expType = exp.op.exp1.destType;
7924 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
7927 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
7929 if(exp.expType) FreeType(exp.expType);
7930 exp.expType = exp.op.exp2.destType;
7931 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
7937 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
7939 if(exp.expType) FreeType(exp.expType);
7940 exp.expType = exp.op.exp2.destType;
7941 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
7944 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
7946 if(exp.expType) FreeType(exp.expType);
7947 exp.expType = exp.op.exp1.destType;
7948 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
7954 char expString1[10240];
7955 char expString2[10240];
7958 expString1[0] = '\0';
7959 expString2[0] = '\0';
7964 PrintExpression(exp.op.exp1, expString1);
7965 ChangeCh(expString1, '\n', ' ');
7966 PrintExpression(exp.op.exp2, expString2);
7967 ChangeCh(expString2, '\n', ' ');
7968 PrintType(exp.op.exp1.expType, type1, false, true);
7969 PrintType(exp.op.exp2.expType, type2, false, true);
7972 Compiler_Warning("incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
7976 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
7977 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
7979 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7980 // Convert e.g. / 4 into / 4.0
7981 exp.op.exp1.destType = type2._class.registered.dataType;
7982 if(type2._class.registered.dataType)
7983 type2._class.registered.dataType.refCount++;
7984 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7985 exp.expType = type2;
7986 if(type2) type2.refCount++;
7988 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
7990 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7991 // Convert e.g. / 4 into / 4.0
7992 exp.op.exp2.destType = type1._class.registered.dataType;
7993 if(type1._class.registered.dataType)
7994 type1._class.registered.dataType.refCount++;
7995 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7996 exp.expType = type1;
7997 if(type1) type1.refCount++;
8003 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8005 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8007 if(!type1._class.registered.dataType)
8008 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8009 exp.op.exp2.destType = type1._class.registered.dataType;
8010 exp.op.exp2.destType.refCount++;
8012 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8013 type2 = exp.op.exp2.destType;
8015 exp.expType = type2;
8019 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8021 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8023 if(!type2._class.registered.dataType)
8024 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8025 exp.op.exp1.destType = type2._class.registered.dataType;
8026 exp.op.exp1.destType.refCount++;
8028 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8029 type1 = exp.op.exp1.destType;
8030 exp.expType = type1;
8034 // TESTING THIS NEW CODE
8035 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8037 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8039 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8041 if(exp.expType) FreeType(exp.expType);
8042 exp.expType = exp.op.exp1.expType;
8043 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8048 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8050 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8052 if(exp.expType) FreeType(exp.expType);
8053 exp.expType = exp.op.exp2.expType;
8054 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8062 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8063 exp.op.exp2.destType = type1;
8067 // Maybe this was meant to be an enum...
8068 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8070 Type oldType = exp.op.exp2.expType;
8071 exp.op.exp2.expType = null;
8072 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8075 exp.op.exp2.expType = oldType;
8080 // TESTING THIS HERE... LATEST ADDITION
8081 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8083 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8084 exp.op.exp2.destType = type2._class.registered.dataType;
8085 if(type2._class.registered.dataType)
8086 type2._class.registered.dataType.refCount++;
8087 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8089 //exp.expType = type2._class.registered.dataType; //type2;
8090 //if(type2) type2.refCount++;
8093 // TESTING THIS HERE... LATEST ADDITION
8094 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8096 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8097 exp.op.exp1.destType = type1._class.registered.dataType;
8098 if(type1._class.registered.dataType)
8099 type1._class.registered.dataType.refCount++;
8100 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8101 exp.expType = type1._class.registered.dataType; //type1;
8102 if(type1) type1.refCount++;
8106 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8108 if(exp.expType) FreeType(exp.expType);
8109 exp.expType = exp.op.exp2.destType;
8110 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8112 else if(type1 && type2)
8114 char expString1[10240];
8115 char expString2[10240];
8116 char type1String[1024];
8117 char type2String[1024];
8118 expString1[0] = '\0';
8119 expString2[0] = '\0';
8120 type1String[0] = '\0';
8121 type2String[0] = '\0';
8124 PrintExpression(exp.op.exp1, expString1);
8125 ChangeCh(expString1, '\n', ' ');
8126 PrintExpression(exp.op.exp2, expString2);
8127 ChangeCh(expString2, '\n', ' ');
8128 PrintType(exp.op.exp1.expType, type1String, false, true);
8129 PrintType(exp.op.exp2.expType, type2String, false, true);
8132 Compiler_Warning("incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8134 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8136 exp.expType = exp.op.exp1.expType;
8137 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8139 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8141 exp.expType = exp.op.exp2.expType;
8142 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8149 // Maybe this was meant to be an enum...
8150 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8152 Type oldType = exp.op.exp1.expType;
8153 exp.op.exp1.expType = null;
8154 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8157 exp.op.exp1.expType = oldType;
8160 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8161 exp.op.exp1.destType = type2;
8164 // TESTING THIS HERE... LATEST ADDITION
8165 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8167 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8168 exp.op.exp1.destType = type1._class.registered.dataType;
8169 if(type1._class.registered.dataType)
8170 type1._class.registered.dataType.refCount++;
8173 // TESTING THIS HERE... LATEST ADDITION
8174 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8176 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8177 exp.op.exp2.destType = type2._class.registered.dataType;
8178 if(type2._class.registered.dataType)
8179 type2._class.registered.dataType.refCount++;
8183 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8185 if(exp.expType) FreeType(exp.expType);
8186 exp.expType = exp.op.exp1.destType;
8187 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8191 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8193 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8195 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8196 // Convert e.g. / 4 into / 4.0
8197 exp.op.exp1.destType = type2._class.registered.dataType;
8198 if(type2._class.registered.dataType)
8199 type2._class.registered.dataType.refCount++;
8200 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8202 if(exp.op.op == '!')
8204 exp.expType = MkClassType("bool");
8205 exp.expType.truth = true;
8209 exp.expType = type2;
8210 if(type2) type2.refCount++;
8213 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8215 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8217 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8218 // Convert e.g. / 4 into / 4.0
8219 exp.op.exp2.destType = type1._class.registered.dataType;
8220 if(type1._class.registered.dataType)
8221 type1._class.registered.dataType.refCount++;
8222 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8224 exp.expType = type1;
8225 if(type1) type1.refCount++;
8230 if(exp.op.exp1 && !exp.op.exp1.expType)
8232 char expString[10000];
8233 expString[0] = '\0';
8236 PrintExpression(exp.op.exp1, expString);
8237 ChangeCh(expString, '\n', ' ');
8240 Compiler_Error("couldn't determine type of %s\n", expString);
8242 if(exp.op.exp2 && !exp.op.exp2.expType)
8244 char expString[10240];
8245 expString[0] = '\0';
8248 PrintExpression(exp.op.exp2, expString);
8249 ChangeCh(expString, '\n', ' ');
8252 Compiler_Error("couldn't determine type of %s\n", expString);
8257 FreeType(exp.expType);
8258 exp.expType = MkClassType("bool");
8259 exp.expType.truth = true;
8262 if(exp.op.op != SIZEOF)
8263 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8264 (!exp.op.exp2 || exp.op.exp2.isConstant);
8266 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8268 DeclareType(exp.op.exp2.expType, false, false);
8277 case extensionExpressionExp:
8280 exp.isConstant = true;
8281 for(e = exp.list->first; e; e = e.next)
8286 FreeType(e.destType);
8287 e.destType = exp.destType;
8288 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8290 ProcessExpressionType(e);
8292 exp.destType.count--;
8293 if(!exp.expType && !e.next)
8295 exp.expType = e.expType;
8296 if(e.expType) e.expType.refCount++;
8299 exp.isConstant = false;
8302 // In case a cast became a member...
8303 e = exp.list->first;
8304 if(!e.next && e.type == memberExp)
8306 // Preserve prev, next
8307 Expression next = exp.next, prev = exp.prev;
8310 FreeType(exp.expType);
8311 FreeType(exp.destType);
8321 ProcessExpressionType(exp);
8328 exp.isConstant = true;
8330 ProcessExpressionType(exp.index.exp);
8331 if(!exp.index.exp.isConstant)
8332 exp.isConstant = false;
8334 if(exp.index.exp.expType)
8336 Type source = exp.index.exp.expType;
8337 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8338 eClass_IsDerived(source._class.registered, containerClass) &&
8339 source._class.registered.templateArgs)
8341 Class _class = source._class.registered;
8342 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8344 if(exp.index.index && exp.index.index->last)
8346 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8351 for(e = exp.index.index->first; e; e = e.next)
8353 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8355 if(e.destType) FreeType(e.destType);
8356 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8358 ProcessExpressionType(e);
8361 // Check if this type is int
8364 exp.isConstant = false;
8368 exp.expType = Dereference(exp.index.exp.expType);
8370 DeclareType(exp.expType, false, false);
8377 Type methodType = null;
8383 PrintExpression(exp.call.exp, name);
8384 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8386 //exp.call.exp.expType = null;
8387 PrintExpression(exp.call.exp, name);
8390 if(exp.call.exp.type == identifierExp)
8392 Expression idExp = exp.call.exp;
8393 Identifier id = idExp.identifier;
8394 if(!strcmp(id.string, "__ENDIAN_PAD"))
8396 exp.expType = ProcessTypeString("int", true);
8397 if(exp.call.arguments && exp.call.arguments->first)
8398 ProcessExpressionType(exp.call.arguments->first);
8401 else if(!strcmp(id.string, "Max") ||
8402 !strcmp(id.string, "Min") ||
8403 !strcmp(id.string, "Sgn") ||
8404 !strcmp(id.string, "Abs"))
8406 Expression a = null;
8407 Expression b = null;
8408 Expression tempExp1 = null, tempExp2 = null;
8409 if((!strcmp(id.string, "Max") ||
8410 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8412 a = exp.call.arguments->first;
8413 b = exp.call.arguments->last;
8417 else if(exp.call.arguments->count == 1)
8419 a = exp.call.arguments->first;
8425 exp.call.arguments->Clear();
8426 idExp.identifier = null;
8428 FreeExpContents(exp);
8430 ProcessExpressionType(a);
8432 ProcessExpressionType(b);
8434 exp.type = bracketsExp;
8435 exp.list = MkList();
8437 if(a.expType && (!b || b.expType))
8439 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8441 // Use the simpleStruct name/ids for now...
8444 OldList * specs = MkList();
8445 OldList * decls = MkList();
8447 char temp1[1024], temp2[1024];
8449 GetTypeSpecs(a.expType, specs);
8451 if(a && !a.isConstant && a.type != identifierExp)
8453 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8454 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8455 tempExp1 = QMkExpId(temp1);
8456 tempExp1.expType = a.expType;
8458 a.expType.refCount++;
8459 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8461 if(b && !b.isConstant && b.type != identifierExp)
8463 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8464 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8465 tempExp2 = QMkExpId(temp2);
8466 tempExp2.expType = b.expType;
8468 b.expType.refCount++;
8469 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8472 decl = MkDeclaration(specs, decls);
8473 if(!curCompound.compound.declarations)
8474 curCompound.compound.declarations = MkList();
8475 curCompound.compound.declarations->Insert(null, decl);
8480 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8482 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8484 MkExpCondition(MkExpBrackets(MkListOne(
8485 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8486 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8487 exp.expType = a.expType;
8489 a.expType.refCount++;
8491 else if(!strcmp(id.string, "Abs"))
8494 MkExpCondition(MkExpBrackets(MkListOne(
8495 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8496 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8497 exp.expType = a.expType;
8499 a.expType.refCount++;
8501 else if(!strcmp(id.string, "Sgn"))
8503 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8505 MkExpCondition(MkExpBrackets(MkListOne(
8506 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8507 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8508 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8509 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8510 exp.expType = ProcessTypeString("int", false);
8513 FreeExpression(tempExp1);
8514 if(tempExp2) FreeExpression(tempExp2);
8528 if(!exp.call.exp.destType)
8530 exp.call.exp.destType = dummy;
8533 ProcessExpressionType(exp.call.exp);
8534 if(exp.call.exp.destType == dummy)
8537 exp.call.exp.destType = null;
8542 // Check argument types against parameter types
8543 functionType = exp.call.exp.expType;
8545 if(functionType && functionType.kind == TypeKind::methodType)
8547 methodType = functionType;
8548 functionType = methodType.method.dataType;
8550 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8551 // TOCHECK: Instead of doing this here could this be done per param?
8552 if(exp.call.exp.expType.usedClass)
8554 char typeString[1024];
8555 typeString[0] = '\0';
8556 PrintType(functionType, typeString, true, true);
8557 if(strstr(typeString, "thisclass"))
8559 OldList * specs = MkList();
8562 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8564 decl = SpecDeclFromString(typeString, specs, null);
8566 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8567 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8568 exp.call.exp.expType.usedClass))
8569 thisClassParams = false;
8571 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8573 Class backupThisClass = thisClass;
8574 thisClass = exp.call.exp.expType.usedClass;
8575 ProcessDeclarator(decl);
8576 thisClass = backupThisClass;
8579 thisClassParams = true;
8581 functionType = ProcessType(specs, decl);
8582 functionType.refCount = 0;
8583 FinishTemplatesContext(context);
8586 FreeList(specs, FreeSpecifier);
8587 FreeDeclarator(decl);
8591 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8593 Type type = functionType.type;
8594 if(!functionType.refCount)
8596 functionType.type = null;
8597 FreeType(functionType);
8599 //methodType = functionType;
8600 functionType = type;
8602 if(functionType && functionType.kind != TypeKind::functionType)
8604 Compiler_Error("called object %s is not a function\n", name);
8606 else if(functionType)
8608 bool emptyParams = false, noParams = false;
8609 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8610 Type type = functionType.params.first;
8611 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8613 Location oldyylloc = yylloc;
8615 if(!type) emptyParams = true;
8618 if(functionType.extraParam && e)
8620 e.destType = MkClassType(functionType.thisClass.string);
8624 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8625 if(!functionType.staticMethod)
8627 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8628 memberExp.member.exp.expType._class)
8630 type = MkClassType(memberExp.member.exp.expType._class.string);
8635 type = functionType.params.first;
8640 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8642 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8647 type = functionType.params.first;
8655 if(type && type.kind == voidType)
8658 if(!type.refCount) FreeType(type);
8662 for( ; e; e = e.next)
8664 if(!type && !emptyParams)
8667 if(methodType && methodType.methodClass)
8668 Compiler_Error("too many arguments for method %s::%s (%d given, expected %d)\n",
8669 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8670 noParams ? 0 : functionType.params.count);
8672 Compiler_Error("too many arguments for function %s (%d given, expected %d)\n",
8673 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8674 noParams ? 0 : functionType.params.count);
8678 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8680 Type templatedType = null;
8681 Class _class = methodType.usedClass;
8682 ClassTemplateParameter curParam = null;
8684 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8687 for(sClass = _class; sClass; sClass = sClass.base)
8689 if(sClass.templateClass) sClass = sClass.templateClass;
8691 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8693 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8696 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8698 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8699 id += nextClass.templateParams.count;
8708 if(curParam && _class.templateArgs[id].dataTypeString)
8710 ClassTemplateArgument arg = _class.templateArgs[id];
8712 Context context = SetupTemplatesContext(_class);
8715 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8716 templatedType = ProcessTypeString(arg.dataTypeString, false);
8717 FinishTemplatesContext(context);
8719 e.destType = templatedType;
8722 templatedType.passAsTemplate = true;
8723 // templatedType.refCount++;
8729 if(type) type.refCount++;
8735 if(type) type.refCount++;
8737 // Don't reach the end for the ellipsis
8738 if(type && type.kind != ellipsisType)
8740 Type next = type.next;
8741 if(!type.refCount) FreeType(type);
8746 if(type && type.kind != ellipsisType)
8748 if(methodType && methodType.methodClass)
8749 Compiler_Warning("not enough arguments for method %s::%s (%d given, expected %d)\n",
8750 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8751 functionType.params.count + extra);
8753 Compiler_Warning("not enough arguments for function %s (%d given, expected %d)\n",
8754 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8755 functionType.params.count + extra);
8758 if(type && !type.refCount) FreeType(type);
8765 kind = TypeKind::functionType;
8768 if(exp.call.exp.type == identifierExp)
8770 char * string = exp.call.exp.identifier.string;
8774 Location oldyylloc = yylloc;
8776 yylloc = exp.call.exp.identifier.loc;
8777 if(strstr(string, "__builtin_") == string);
8779 Compiler_Warning("%s undefined; assuming extern returning int\n", string);
8780 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
8781 globalContext.symbols.Add((BTNode)symbol);
8786 else if(exp.call.exp.type == memberExp)
8788 /*Compiler_Warning("%s undefined; assuming returning int\n",
8789 exp.call.exp.member.member.string);*/
8792 Compiler_Warning("callable object undefined; extern assuming returning int\n");
8794 if(!functionType.returnType)
8796 functionType.returnType = Type
8803 if(functionType && functionType.kind == TypeKind::functionType)
8805 exp.expType = functionType.returnType;
8807 if(functionType.returnType)
8808 functionType.returnType.refCount++;
8810 if(!functionType.refCount)
8811 FreeType(functionType);
8814 if(exp.call.arguments)
8816 for(e = exp.call.arguments->first; e; e = e.next)
8818 Type destType = e.destType;
8819 ProcessExpressionType(e);
8827 Location oldyylloc = yylloc;
8828 bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
8829 exp.thisPtr = thisPtr;
8831 // DOING THIS LATER NOW...
8832 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
8834 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
8835 /* TODO: Name Space Fix ups
8836 if(!exp.member.member.classSym)
8837 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
8841 ProcessExpressionType(exp.member.exp);
8842 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
8843 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
8845 exp.isConstant = false;
8848 exp.isConstant = exp.member.exp.isConstant;
8849 type = exp.member.exp.expType;
8853 if(type && (type.kind == templateType))
8855 Class _class = thisClass ? thisClass : currentClass;
8856 ClassTemplateParameter param = null;
8859 for(param = _class.templateParams.first; param; param = param.next)
8861 if(param.type == identifier && !strcmp(param.name, exp.member.member.string))
8865 if(param && param.defaultArg.member)
8867 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
8870 Expression expMember = exp.member.exp;
8872 OldList * specs = MkList();
8873 char thisClassTypeString[1024];
8875 FreeIdentifier(exp.member.member);
8877 ProcessExpressionType(argExp);
8880 char * colon = strstr(param.defaultArg.memberString, "::");
8883 char className[1024];
8886 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
8887 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
8890 strcpy(thisClassTypeString, _class.fullName);
8893 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
8895 exp.expType = ProcessType(specs, decl);
8896 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
8898 Class expClass = exp.expType._class.registered;
8899 Class cClass = null;
8904 char templateString[1024];
8905 ClassTemplateParameter param;
8906 sprintf(templateString, "%s<", expClass.templateClass.fullName);
8907 for(cClass = expClass; cClass; cClass = cClass.base)
8910 for(param = cClass.templateParams.first; param; param = param.next)
8914 ClassTemplateArgument arg;
8915 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
8916 arg = expClass.templateArgs[id];
8918 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
8920 ClassTemplateParameter cParam;
8921 //int p = numParams - sClass.templateParams.count;
8924 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
8926 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
8928 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
8930 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
8932 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
8933 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
8945 strcat(argument, arg.name.string);
8946 strcat(argument, " = ");
8952 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
8953 char expString[1024];
8954 OldList * specs = MkList();
8955 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
8957 char * string = PrintHexUInt64(arg.expression.ui64);
8958 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
8960 ProcessExpressionType(exp);
8961 ComputeExpression(exp);
8962 expString[0] = '\0';
8963 PrintExpression(exp, expString);
8964 strcat(argument, expString);
8966 FreeExpression(exp);
8971 strcat(argument, arg.member.name);
8974 case TemplateParameterType::type:
8976 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
8978 if(!strcmp(arg.dataTypeString, "thisclass"))
8979 strcat(argument, thisClassTypeString);
8981 strcat(argument, arg.dataTypeString);
8988 if(paramCount) strcat(templateString, ", ");
8989 if(lastParam != p - 1)
8991 strcat(templateString, param.name);
8992 strcat(templateString, " = ");
8994 strcat(templateString, argument);
9003 int len = strlen(templateString);
9004 if(templateString[len-1] == '>') templateString[len++] = ' ';
9005 templateString[len++] = '>';
9006 templateString[len++] = '\0';
9009 Context context = SetupTemplatesContext(_class);
9010 FreeType(exp.expType);
9011 exp.expType = ProcessTypeString(templateString, false);
9012 FinishTemplatesContext(context);
9016 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9017 exp.type = bracketsExp;
9018 exp.list = MkListOne(MkExpOp(null, '*',
9023 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9024 MkExpBrackets(MkListOne(
9025 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9027 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9029 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9034 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9035 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9037 type = ProcessTemplateParameterType(type.templateParameter);
9041 if(type && (type.kind == templateType));
9042 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9044 Identifier id = exp.member.member;
9045 TypeKind typeKind = type.kind;
9046 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9047 if(typeKind == subClassType && exp.member.exp.type == classExp)
9049 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9050 typeKind = classType;
9053 if(id && (typeKind == intType || typeKind == enumType))
9054 _class = eSystem_FindClass(privateModule, "int");
9059 (exp.member.exp.type == identifierExp &&
9060 !strcmp(exp.member.exp.identifier.string, "this"));*/
9061 Property prop = null;
9062 Method method = null;
9063 DataMember member = null;
9064 Property revConvert = null;
9065 ClassProperty classProp = null;
9067 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9068 exp.member.memberType = propertyMember;
9070 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9071 Compiler_Error("invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9073 if(typeKind != subClassType)
9075 // Prioritize data members over properties for "this"
9076 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9078 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9079 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9081 prop = eClass_FindProperty(_class, id.string, privateModule);
9085 if(!member && !prop)
9086 prop = eClass_FindProperty(_class, id.string, privateModule);
9087 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9088 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9089 exp.member.thisPtr = true;
9091 // Prioritize properties over data members otherwise
9094 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9097 prop = eClass_FindProperty(_class, id.string, null);
9098 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9099 member = eClass_FindDataMember(_class, id.string, null, null, null);
9102 if(!prop && !member)
9104 method = eClass_FindMethod(_class, id.string, null);
9107 prop = eClass_FindProperty(_class, id.string, privateModule);
9108 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9109 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9115 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9122 if(!prop && !member)
9123 method = eClass_FindMethod(_class, id.string, privateModule);
9124 if(!prop && !member && !method)
9126 if(typeKind == subClassType)
9128 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9131 exp.member.memberType = classPropertyMember;
9132 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9136 // Assume this is a class_data member
9137 char structName[1024];
9138 Identifier id = exp.member.member;
9139 Expression classExp = exp.member.exp;
9142 FreeType(classExp.expType);
9143 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9145 strcpy(structName, "__ecereClassData_");
9146 FullClassNameCat(structName, type._class.string, false);
9147 exp.type = pointerExp;
9148 exp.member.member = id;
9150 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9151 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9152 MkExpBrackets(MkListOne(MkExpOp(
9153 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9154 MkExpMember(classExp, MkIdentifier("data"))), '+',
9155 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9160 ProcessExpressionType(exp);
9166 // Check for reverse conversion
9167 // (Convert in an instantiation later, so that we can use
9168 // deep properties system)
9169 Symbol classSym = FindClass(id.string);
9172 Class convertClass = classSym.registered;
9174 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9181 exp.member.memberType = propertyMember;
9183 ProcessPropertyType(prop);
9184 exp.expType = prop.dataType;
9185 if(prop.dataType) prop.dataType.refCount++;
9189 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9191 FreeExpContents(exp);
9192 exp.type = identifierExp;
9193 exp.identifier = MkIdentifier("class");
9194 ProcessExpressionType(exp);
9198 exp.member.memberType = dataMember;
9199 DeclareStruct(_class.fullName, false);
9200 if(!member.dataType)
9202 Context context = SetupTemplatesContext(_class);
9203 member.dataType = ProcessTypeString(member.dataTypeString, false);
9204 FinishTemplatesContext(context);
9206 exp.expType = member.dataType;
9207 if(member.dataType) member.dataType.refCount++;
9211 exp.member.memberType = reverseConversionMember;
9212 exp.expType = MkClassType(revConvert._class.fullName);
9220 exp.type = identifierExp;
9221 exp.identifier = exp.member.member;
9224 exp.member.memberType = methodMember;
9226 if(!method.dataType)
9227 ProcessMethodType(method);
9235 // Tricky spot here... To use instance versus class virtual table
9236 // Put it back to what it was... What did we break?
9238 // Had to put it back for overriding Main of Thread global instance
9240 //exp.expType.methodClass = _class;
9241 exp.expType.methodClass = (id && id._class) ? _class : null;
9243 // Need the actual class used for templated classes
9244 exp.expType.usedClass = _class;
9248 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9250 FreeExpContents(exp);
9251 exp.type = identifierExp;
9252 exp.identifier = MkIdentifier("class");
9253 ProcessExpressionType(exp);
9256 yylloc = exp.member.member.loc;
9257 Compiler_Error("couldn't find member %s in class %s\n", id.string, _class.fullName);
9259 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9262 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9267 while(tClass && !tClass.templateClass) tClass = tClass.base;
9269 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9272 ClassTemplateParameter curParam;
9275 for(sClass = tClass; sClass; sClass = sClass.base)
9278 if(sClass.templateClass) sClass = sClass.templateClass;
9279 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9281 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9283 for(sClass = sClass.base; sClass; sClass = sClass.base)
9284 id += sClass.templateParams.count;
9292 if(curParam && tClass.templateArgs[id].dataTypeString)
9294 ClassTemplateArgument arg = tClass.templateArgs[id];
9295 Context context = SetupTemplatesContext(tClass);
9297 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9298 FreeType(exp.expType);
9299 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9302 if(exp.expType.kind == thisClassType)
9304 FreeType(exp.expType);
9305 exp.expType = ReplaceThisClassType(_class);
9308 if(tClass.templateClass)
9309 exp.expType.passAsTemplate = true;
9310 //exp.expType.refCount++;
9313 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9314 //exp.destType.refCount++;
9316 if(exp.destType.kind == thisClassType)
9318 FreeType(exp.destType);
9319 exp.destType = ReplaceThisClassType(_class);
9323 FinishTemplatesContext(context);
9326 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9327 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9330 ClassTemplateParameter curParam;
9333 for(sClass = tClass; sClass; sClass = sClass.base)
9336 if(sClass.templateClass) sClass = sClass.templateClass;
9337 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9339 if(curParam.type == TemplateParameterType::type &&
9340 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9342 for(sClass = sClass.base; sClass; sClass = sClass.base)
9343 id += sClass.templateParams.count;
9353 ClassTemplateArgument arg = tClass.templateArgs[id];
9354 Context context = SetupTemplatesContext(tClass);
9357 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9359 basicType = ProcessTypeString(arg.dataTypeString, false);
9362 if(basicType.kind == thisClassType)
9364 FreeType(basicType);
9365 basicType = ReplaceThisClassType(_class);
9368 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9369 if(tClass.templateClass)
9370 basicType.passAsTemplate = true;
9373 FreeType(exp.expType);
9375 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9376 //exp.expType.refCount++;
9379 exp.destType = exp.expType;
9380 exp.destType.refCount++;
9384 Expression newExp { };
9385 OldList * specs = MkList();
9387 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9389 if(exp.destType) exp.destType.refCount++;
9390 if(exp.expType) exp.expType.refCount++;
9392 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9393 exp.cast.exp = newExp;
9394 //FreeType(exp.expType);
9395 //exp.expType = null;
9396 //ProcessExpressionType(sourceExp);
9399 FinishTemplatesContext(context);
9402 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9404 Class expClass = exp.expType._class.registered;
9407 Class cClass = null;
9412 char templateString[1024];
9413 ClassTemplateParameter param;
9414 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9415 while(cClass != expClass)
9418 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9421 for(param = cClass.templateParams.first; param; param = param.next)
9423 Class cClassCur = null;
9426 ClassTemplateParameter paramCur = null;
9427 ClassTemplateArgument arg;
9428 while(cClassCur != tClass && !paramCur)
9431 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9432 cClassCur = sClassCur;
9434 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9436 if(!strcmp(paramCur.name, param.name))
9444 if(paramCur && paramCur.type == TemplateParameterType::type)
9445 arg = tClass.templateArgs[cp];
9447 arg = expClass.templateArgs[p];
9454 strcat(argument, arg.name.string);
9455 strcat(argument, " = ");
9461 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9462 char expString[1024];
9463 OldList * specs = MkList();
9464 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9466 char * string = PrintHexUInt64(arg.expression.ui64);
9467 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9469 ProcessExpressionType(exp);
9470 ComputeExpression(exp);
9471 expString[0] = '\0';
9472 PrintExpression(exp, expString);
9473 strcat(argument, expString);
9475 FreeExpression(exp);
9480 strcat(argument, arg.member.name);
9483 case TemplateParameterType::type:
9485 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9486 strcat(argument, arg.dataTypeString);
9492 if(paramCount) strcat(templateString, ", ");
9493 if(lastParam != p - 1)
9495 strcat(templateString, param.name);
9496 strcat(templateString, " = ");
9498 strcat(templateString, argument);
9507 int len = strlen(templateString);
9508 if(templateString[len-1] == '>') templateString[len++] = ' ';
9509 templateString[len++] = '>';
9510 templateString[len++] = '\0';
9513 FreeType(exp.expType);
9515 Context context = SetupTemplatesContext(tClass);
9516 exp.expType = ProcessTypeString(templateString, false);
9517 FinishTemplatesContext(context);
9524 Compiler_Error("undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9526 else if(type && (type.kind == structType || type.kind == unionType))
9528 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9531 exp.expType = memberType;
9533 memberType.refCount++;
9538 char expString[10240];
9539 expString[0] = '\0';
9540 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9541 Compiler_Error("member operator on non-structure type expression %s\n", expString);
9544 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9546 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9548 Identifier id = exp.member.member;
9549 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9552 FreeType(exp.expType);
9553 exp.expType = ReplaceThisClassType(_class);
9560 // Convert x->y into (*x).y
9563 Type destType = exp.destType;
9565 // DOING THIS LATER NOW...
9566 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9568 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9569 /* TODO: Name Space Fix ups
9570 if(!exp.member.member.classSym)
9571 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9575 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9576 exp.type = memberExp;
9579 ProcessExpressionType(exp);
9586 //ComputeExpression(exp);
9588 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9589 if(classSym && classSym.registered)
9591 if(classSym.registered.type == noHeadClass)
9595 DeclareStruct(classSym.string, false);
9596 FreeSpecifier(exp._class);
9597 exp.type = typeSizeExp;
9598 FullClassNameCat(name, classSym.string, false);
9599 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9603 if(classSym.registered.fixed)
9605 FreeSpecifier(exp._class);
9606 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9607 exp.type = constantExp;
9611 char className[1024];
9612 strcpy(className, "__ecereClass_");
9613 FullClassNameCat(className, classSym.string, true);
9614 MangleClassName(className);
9616 DeclareClass(classSym, className);
9618 FreeExpContents(exp);
9619 exp.type = pointerExp;
9620 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9621 exp.member.member = MkIdentifier("structSize");
9631 // exp.isConstant = true;
9636 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9643 exp.isConstant = true;
9645 DeclareType(type, false, false);
9651 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9653 FreeType(exp.cast.exp.destType);
9654 exp.cast.exp.destType = type;
9656 ProcessExpressionType(exp.cast.exp);
9661 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9662 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9664 void * prev = exp.prev, * next = exp.next;
9665 Type expType = exp.cast.exp.destType;
9666 Expression castExp = exp.cast.exp;
9667 Type destType = exp.destType;
9669 if(expType) expType.refCount++;
9671 //FreeType(exp.destType);
9672 FreeType(exp.expType);
9673 FreeTypeName(exp.cast.typeName);
9676 FreeType(exp.expType);
9677 FreeType(exp.destType);
9679 exp.expType = expType;
9680 exp.destType = destType;
9690 exp.isConstant = exp.cast.exp.isConstant;
9695 case extensionInitializerExp:
9697 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9699 // ProcessInitializer(exp.initializer.initializer, type);
9705 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9706 ProcessExpressionType(exp.vaArg.exp);
9714 exp.isConstant = true;
9716 FreeType(exp.cond.cond.destType);
9717 exp.cond.cond.destType = MkClassType("bool");
9718 exp.cond.cond.destType.truth = true;
9719 ProcessExpressionType(exp.cond.cond);
9720 if(!exp.cond.cond.isConstant)
9721 exp.isConstant = false;
9722 for(e = exp.cond.exp->first; e; e = e.next)
9726 FreeType(e.destType);
9727 e.destType = exp.destType;
9728 if(e.destType) e.destType.refCount++;
9730 ProcessExpressionType(e);
9733 exp.expType = e.expType;
9734 if(e.expType) e.expType.refCount++;
9737 exp.isConstant = false;
9740 FreeType(exp.cond.elseExp.destType);
9741 // Added this check if we failed to find an expType
9742 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
9745 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
9747 if(exp.cond.elseExp.destType)
9748 exp.cond.elseExp.destType.refCount++;
9749 ProcessExpressionType(exp.cond.elseExp);
9751 // FIXED THIS: Was done before calling process on elseExp
9752 if(!exp.cond.elseExp.isConstant)
9753 exp.isConstant = false;
9756 case extensionCompoundExp:
9758 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
9760 Statement last = exp.compound.compound.statements->last;
9761 if(last.type == expressionStmt && last.expressions && last.expressions->last)
9763 ((Expression)last.expressions->last).destType = exp.destType;
9765 exp.destType.refCount++;
9767 ProcessStatement(exp.compound);
9768 exp.expType = ((Expression)last.expressions->last).expType;
9769 if(((Expression)last.expressions->last).expType)
9770 exp.expType.refCount++;
9776 Specifier spec = exp._classExp.specifiers->first;
9777 if(spec && spec.type == nameSpecifier)
9779 exp.expType = MkClassType(spec.name);
9780 exp.expType.kind = subClassType;
9781 exp.byReference = true;
9785 exp.expType = MkClassType("ecere::com::Class");
9786 exp.byReference = true;
9792 Class _class = thisClass ? thisClass : currentClass;
9795 Identifier id = exp.classData.id;
9796 char structName[1024];
9797 Expression classExp;
9798 strcpy(structName, "__ecereClassData_");
9799 FullClassNameCat(structName, _class.fullName, false);
9800 exp.type = pointerExp;
9801 exp.member.member = id;
9802 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
9803 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
9805 classExp = MkExpIdentifier(MkIdentifier("class"));
9807 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9808 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9809 MkExpBrackets(MkListOne(MkExpOp(
9810 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9811 MkExpMember(classExp, MkIdentifier("data"))), '+',
9812 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
9815 ProcessExpressionType(exp);
9823 char * typeString = null;
9824 char typeStringBuf[1024];
9825 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
9826 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
9828 Class templateClass = exp.destType._class.registered;
9829 typeString = templateClass.templateArgs[2].dataTypeString;
9833 // Guess type from expressions in the array
9835 for(e = exp.list->first; e; e = e.next)
9837 ProcessExpressionType(e);
9840 if(!type) { type = e.expType; type.refCount++; }
9843 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
9844 if(!MatchTypeExpression(e, type, null, false))
9850 e = exp.list->first;
9851 ProcessExpressionType(e);
9854 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
9855 if(!MatchTypeExpression(e, type, null, false))
9857 FreeType(e.expType);
9868 FreeType(e.expType);
9875 typeStringBuf[0] = '\0';
9876 PrintType(type, typeStringBuf, false, true);
9877 typeString = typeStringBuf;
9885 (Container)(__extension__( {
9886 int __arrayMembers[] = { 1, 7, 3, 4, 5 };
9887 BuiltInContainer __baseContainer
9889 data = __arrayMembers,
9892 _vTbl = class(BuiltInContainer)._vTbl,
9893 _class = class(BuiltInContainer) };
9898 char templateString[1024];
9899 OldList * declarations = MkList();
9900 OldList * instMembers = MkList();
9901 OldList * specs = MkList();
9902 OldList * initializers = MkList();
9906 Declarator decl = SpecDeclFromString(typeString, specs, null);
9907 Context context = PushContext();
9909 // sprintf(templateString, "Container<%s >", typeString);
9910 sprintf(templateString, "Container<%s>", typeString);
9912 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("data")), MkInitializerAssignment(MkExpIdentifier(MkIdentifier("__internalList")))));
9914 sprintf(count, "%d", exp.list->count);
9915 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("count")), MkInitializerAssignment(MkExpConstant(count))));
9917 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("type")), MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier),
9918 CopyDeclarator(decl)))));
9920 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("_vTbl")), MkInitializerAssignment(MkExpMember(
9921 MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl")))));
9923 ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("_class")), MkInitializerAssignment(
9924 MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null))));
9928 type = ProcessTypeString(typeString, false);
9929 while(e = exp.list->first)
9931 exp.list->Remove(e);
9934 ProcessExpressionType(e);
9935 ListAdd(initializers, MkInitializerAssignment(e));
9941 ListAdd(declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(decl,
9942 MkDeclaratorIdentifier(MkIdentifier("__internalList"))), null),
9943 MkInitializerList(initializers)))));
9944 ListAdd(declarations, MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName("BuiltInContainer")),
9945 MkExpIdentifier(MkIdentifier("__internalContainer")), MkListOne(MkMembersInitList(instMembers)))));
9947 exp.expType = ProcessTypeString(templateString, false);
9948 exp.type = bracketsExp;
9949 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
9950 (expExt = MkExpExtensionCompound(MkCompoundStmt(
9951 declarations, MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internalContainer")))))))))));
9952 expExt.compound.compound.context = context;
9953 PopContext(context);
9954 ProcessExpressionType(expExt);
9958 exp.expType = ProcessTypeString("Container", false);
9959 Compiler_Error("Couldn't determine type of array elements\n");
9965 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
9967 FreeType(exp.expType);
9968 exp.expType = ReplaceThisClassType(thisClass);
9971 // Resolve structures here
9972 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
9974 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
9975 // TODO: Fix members reference...
9978 if(exp.expType.kind != enumType)
9981 exp.expType.members = symbol.type.members;
9982 for(member = symbol.type.members.first; member; member = member.next)
9988 for(member = symbol.type.members.first; member; member = member.next)
9990 NamedLink value { name = CopyString(member.name) };
9991 exp.expType.members.Add(value);
9998 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
9999 else if(exp.destType && !exp.destType.keepCast)
10001 if(!CheckExpressionType(exp, exp.destType, false))
10003 if(!exp.destType.count || unresolved)
10008 if(exp.destType.kind != ellipsisType)
10014 char expString[10240];
10015 expString[0] = '\0';
10017 PrintType(exp.destType, type2, false, true);
10019 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10021 Compiler_Error("unresolved identifier %s; expected %s\n", expString, type2);
10022 else if(exp.type != dummyExp)
10023 Compiler_Error("couldn't determine type of %s; expected %s\n", expString, type2);
10028 char expString[10240] ;
10029 expString[0] = '\0';
10030 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10033 Compiler_Error("unresolved identifier %s\n", expString);
10034 else if(exp.type != dummyExp)
10035 Compiler_Error("couldn't determine type of %s\n", expString);
10046 PrintType(exp.expType, type1, false, true);
10047 PrintType(exp.destType, type2, false, true);
10050 //CheckExpressionType(exp, exp.destType, false);
10052 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10053 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10054 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10057 char expString[10240];
10058 expString[0] = '\0';
10059 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10062 CheckExpressionType(exp, exp.destType, false);
10064 Compiler_Warning("incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10066 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10067 FreeType(exp.expType);
10068 exp.destType.refCount++;
10069 exp.expType = exp.destType;
10074 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10076 Expression newExp { };
10077 char typeString[1024];
10078 OldList * specs = MkList();
10081 typeString[0] = '\0';
10085 if(exp.expType) exp.expType.refCount++;
10086 if(exp.expType) exp.expType.refCount++;
10087 exp.type = castExp;
10088 newExp.destType = exp.expType;
10090 PrintType(exp.expType, typeString, false, false);
10091 decl = SpecDeclFromString(typeString, specs, null);
10093 exp.cast.typeName = MkTypeName(specs, decl);
10094 exp.cast.exp = newExp;
10097 else if(unresolved)
10099 if(exp.identifier._class && exp.identifier._class.name)
10100 Compiler_Error("unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10101 else if(exp.identifier.string && exp.identifier.string[0])
10102 Compiler_Error("unresolved identifier %s\n", exp.identifier.string);
10104 else if(!exp.expType && exp.type != dummyExp)
10106 char expString[10240];
10107 expString[0] = '\0';
10108 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10109 Compiler_Error("couldn't determine type of %s\n", expString);
10112 // Let's try to support any_object & typed_object here:
10113 ApplyAnyObjectLogic(exp);
10115 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10116 exp.expType._class.registered.type == noHeadClass)
10118 exp.byReference = true;
10120 /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10121 exp.destType._class.registered.type == noHeadClass)
10123 exp.byReference = true;
10125 yylloc = oldyylloc;
10128 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10130 // THIS CODE WILL FIND NEXT MEMBER...
10133 *curMember = (*curMember).next;
10135 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10137 *curMember = subMemberStack[--(*subMemberStackPos)];
10138 *curMember = (*curMember).next;
10141 // SKIP ALL PROPERTIES HERE...
10142 while((*curMember) && (*curMember).isProperty)
10143 *curMember = (*curMember).next;
10145 if(subMemberStackPos)
10147 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10149 subMemberStack[(*subMemberStackPos)++] = *curMember;
10151 *curMember = (*curMember).members.first;
10152 while(*curMember && (*curMember).isProperty)
10153 *curMember = (*curMember).next;
10161 if(subMemberStackPos && *subMemberStackPos)
10163 *curMember = subMemberStack[--(*subMemberStackPos)];
10164 *curMember = (*curMember).next;
10168 Class lastCurClass = *curClass;
10170 if(*curClass == _class) break; // REACHED THE END
10172 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10173 *curMember = (*curClass).membersAndProperties.first;
10176 while((*curMember) && (*curMember).isProperty)
10177 *curMember = (*curMember).next;
10178 if(subMemberStackPos)
10180 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10182 subMemberStack[(*subMemberStackPos)++] = *curMember;
10184 *curMember = (*curMember).members.first;
10185 while(*curMember && (*curMember).isProperty)
10186 *curMember = (*curMember).next;
10194 static void ProcessInitializer(Initializer init, Type type)
10198 case expInitializer:
10199 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10201 // TESTING THIS FOR SHUTTING = 0 WARNING
10202 if(init.exp && !init.exp.destType)
10204 FreeType(init.exp.destType);
10205 init.exp.destType = type;
10206 if(type) type.refCount++;
10210 ProcessExpressionType(init.exp);
10211 init.isConstant = init.exp.isConstant;
10217 Expression exp = init.exp;
10218 Instantiation inst = exp.instance;
10219 MembersInit members;
10221 init.type = listInitializer;
10222 init.list = MkList();
10226 for(members = inst.members->first; members; members = members.next)
10228 if(members.type == dataMembersInit)
10231 for(member = members.dataMembers->first; member; member = member.next)
10233 ListAdd(init.list, member.initializer);
10234 member.initializer = null;
10237 // Discard all MembersInitMethod
10240 FreeExpression(exp);
10242 case listInitializer:
10245 Type initializerType = null;
10246 Class curClass = null;
10247 DataMember curMember = null;
10248 DataMember subMemberStack[256];
10249 int subMemberStackPos = 0;
10251 if(type && type.kind == arrayType)
10252 initializerType = Dereference(type);
10253 else if(type && (type.kind == structType || type.kind == unionType))
10254 initializerType = type.members.first;
10256 for(i = init.list->first; i; i = i.next)
10258 if(type && type.kind == classType && type._class && type._class.registered)
10260 // 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)
10261 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10262 // TODO: Generate error on initializing a private data member this way from another module...
10265 if(!curMember.dataType)
10266 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10267 initializerType = curMember.dataType;
10270 ProcessInitializer(i, initializerType);
10271 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10272 initializerType = initializerType.next;
10274 init.isConstant = false;
10277 if(type && type.kind == arrayType)
10278 FreeType(initializerType);
10280 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10282 Compiler_Error("Assigning list initializer to non list\n");
10289 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10293 case baseSpecifier:
10295 if(spec.specifier == THISCLASS)
10299 spec.type = nameSpecifier;
10300 spec.name = ReplaceThisClass(thisClass);
10301 spec.symbol = FindClass(spec.name);
10302 ProcessSpecifier(spec, declareStruct);
10307 case nameSpecifier:
10309 Symbol symbol = FindType(curContext, spec.name);
10311 DeclareType(symbol.type, true, true);
10312 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10313 DeclareStruct(spec.name, false);
10316 case enumSpecifier:
10321 for(e = spec.list->first; e; e = e.next)
10324 ProcessExpressionType(e.exp);
10329 case structSpecifier:
10330 case unionSpecifier:
10332 if(spec.definitions)
10335 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10337 ProcessClass(spec.definitions, symbol);
10340 for(def = spec.definitions->first; def; def = def.next)
10342 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10343 ProcessDeclaration(def.decl);
10350 case classSpecifier:
10352 Symbol classSym = FindClass(spec.name);
10353 if(classSym && classSym.registered && classSym.registered.type == structClass)
10354 DeclareStruct(spec.name, false);
10362 static void ProcessDeclarator(Declarator decl)
10366 case identifierDeclarator:
10367 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10369 FreeSpecifier(decl.identifier._class);
10370 decl.identifier._class = null;
10373 case arrayDeclarator:
10375 ProcessExpressionType(decl.array.exp);
10376 case structDeclarator:
10377 case bracketsDeclarator:
10378 case functionDeclarator:
10379 case pointerDeclarator:
10380 case extendedDeclarator:
10381 case extendedDeclaratorEnd:
10382 if(decl.declarator)
10383 ProcessDeclarator(decl.declarator);
10384 if(decl.type == functionDeclarator)
10386 Identifier id = GetDeclId(decl);
10387 if(id && id._class)
10391 qualifiers = MkListOne(id._class);
10394 if(!decl.function.parameters)
10395 decl.function.parameters = MkList();
10396 decl.function.parameters->Insert(null, param);
10399 if(decl.function.parameters)
10403 for(param = decl.function.parameters->first; param; param = param.next)
10405 if(param.qualifiers && param.qualifiers->first)
10407 Specifier spec = param.qualifiers->first;
10408 if(spec && spec.specifier == TYPED_OBJECT)
10410 Declarator d = param.declarator;
10413 qualifiers = MkListOne(MkSpecifier(VOID));
10414 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10417 FreeList(param.qualifiers, FreeSpecifier);
10419 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10420 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10422 decl.function.parameters->Insert(param, newParam);
10425 else if(spec && spec.specifier == ANY_OBJECT)
10427 Declarator d = param.declarator;
10429 FreeList(param.qualifiers, FreeSpecifier);
10431 param.qualifiers = MkListOne(MkSpecifier(VOID));
10432 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10434 else if(spec.specifier == THISCLASS)
10438 spec.type = nameSpecifier;
10439 spec.name = ReplaceThisClass(thisClass);
10440 spec.symbol = FindClass(spec.name);
10441 ProcessSpecifier(spec, false);
10446 if(param.declarator)
10447 ProcessDeclarator(param.declarator);
10455 static void ProcessDeclaration(Declaration decl)
10460 case initDeclaration:
10462 bool declareStruct = false;
10464 lineNum = decl.pos.line;
10465 column = decl.pos.col;
10468 if(decl.declarators)
10472 for(d = decl.declarators->first; d; d = d.next)
10474 Type type, subType;
10475 ProcessDeclarator(d.declarator);
10477 type = ProcessType(decl.specifiers, d.declarator);
10481 ProcessInitializer(d.initializer, type);
10483 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10485 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10486 d.initializer.exp.type == instanceExp)
10488 if(type.kind == classType && type._class ==
10489 d.initializer.exp.expType._class)
10491 Instantiation inst = d.initializer.exp.instance;
10492 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10494 d.initializer.exp.instance = null;
10495 if(decl.specifiers)
10496 FreeList(decl.specifiers, FreeSpecifier);
10497 FreeList(decl.declarators, FreeInitDeclarator);
10501 decl.type = instDeclaration;
10506 for(subType = type; subType;)
10508 if(subType.kind == classType)
10510 declareStruct = true;
10513 else if(subType.kind == pointerType)
10515 else if(subType.kind == arrayType)
10516 subType = subType.arrayType;
10526 if(decl.specifiers)
10529 for(s = decl.specifiers->first; s; s = s.next)
10531 ProcessSpecifier(s, declareStruct);
10536 case instDeclaration:
10538 ProcessInstantiationType(decl.inst);
10541 case structDeclaration:
10545 bool declareStruct = false;
10547 if(decl.declarators)
10549 for(d = decl.declarators->first; d; d = d.next)
10551 Type type = ProcessType(decl.specifiers, d.declarator);
10553 ProcessDeclarator(d);
10554 for(subType = type; subType;)
10556 if(subType.kind == classType)
10558 declareStruct = true;
10561 else if(subType.kind == pointerType)
10563 else if(subType.kind == arrayType)
10564 subType = subType.arrayType;
10571 if(decl.specifiers)
10573 for(spec = decl.specifiers->first; spec; spec = spec.next)
10574 ProcessSpecifier(spec, declareStruct);
10581 static FunctionDefinition curFunction;
10583 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10585 char propName[1024], propNameM[1024];
10586 char getName[1024], setName[1024];
10589 DeclareProperty(prop, setName, getName);
10591 // eInstance_FireWatchers(object, prop);
10592 strcpy(propName, "__ecereProp_");
10593 FullClassNameCat(propName, prop._class.fullName, false);
10594 strcat(propName, "_");
10595 // strcat(propName, prop.name);
10596 FullClassNameCat(propName, prop.name, true);
10597 MangleClassName(propName);
10599 strcpy(propNameM, "__ecerePropM_");
10600 FullClassNameCat(propNameM, prop._class.fullName, false);
10601 strcat(propNameM, "_");
10602 // strcat(propNameM, prop.name);
10603 FullClassNameCat(propNameM, prop.name, true);
10604 MangleClassName(propNameM);
10606 if(prop.isWatchable)
10609 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10610 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10611 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10614 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10615 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10616 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10622 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10623 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10624 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10627 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10628 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10629 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10632 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10633 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10634 curFunction.propSet.fireWatchersDone = true;
10637 static void ProcessStatement(Statement stmt)
10641 lineNum = stmt.pos.line;
10642 column = stmt.pos.col;
10647 ProcessStatement(stmt.labeled.stmt);
10650 // This expression should be constant...
10651 if(stmt.caseStmt.exp)
10653 FreeType(stmt.caseStmt.exp.destType);
10654 stmt.caseStmt.exp.destType = curSwitchType;
10655 if(curSwitchType) curSwitchType.refCount++;
10656 ProcessExpressionType(stmt.caseStmt.exp);
10657 ComputeExpression(stmt.caseStmt.exp);
10659 if(stmt.caseStmt.stmt)
10660 ProcessStatement(stmt.caseStmt.stmt);
10664 if(stmt.compound.context)
10669 Statement prevCompound = curCompound;
10670 Context prevContext = curContext;
10672 if(!stmt.compound.isSwitch)
10674 curCompound = stmt;
10675 curContext = stmt.compound.context;
10678 if(stmt.compound.declarations)
10680 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10681 ProcessDeclaration(decl);
10683 if(stmt.compound.statements)
10685 for(s = stmt.compound.statements->first; s; s = s.next)
10686 ProcessStatement(s);
10689 curContext = prevContext;
10690 curCompound = prevCompound;
10694 case expressionStmt:
10697 if(stmt.expressions)
10699 for(exp = stmt.expressions->first; exp; exp = exp.next)
10700 ProcessExpressionType(exp);
10708 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10709 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10710 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10711 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10713 ProcessExpressionType(exp);
10715 if(stmt.ifStmt.stmt)
10716 ProcessStatement(stmt.ifStmt.stmt);
10717 if(stmt.ifStmt.elseStmt)
10718 ProcessStatement(stmt.ifStmt.elseStmt);
10723 Type oldSwitchType = curSwitchType;
10724 if(stmt.switchStmt.exp)
10727 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
10737 e.exp.destType = destType;
10740 ProcessExpressionType(exp);
10743 curSwitchType = exp.expType;
10746 ProcessStatement(stmt.switchStmt.stmt);
10747 curSwitchType = oldSwitchType;
10752 if(stmt.whileStmt.exp)
10756 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
10757 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
10758 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
10759 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
10761 ProcessExpressionType(exp);
10764 if(stmt.whileStmt.stmt)
10765 ProcessStatement(stmt.whileStmt.stmt);
10770 if(stmt.doWhile.exp)
10774 if(stmt.doWhile.exp->last)
10776 FreeType(((Expression)stmt.doWhile.exp->last).destType);
10777 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
10778 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
10780 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
10782 ProcessExpressionType(exp);
10785 if(stmt.doWhile.stmt)
10786 ProcessStatement(stmt.doWhile.stmt);
10792 if(stmt.forStmt.init)
10793 ProcessStatement(stmt.forStmt.init);
10795 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
10797 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
10798 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
10799 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
10802 if(stmt.forStmt.check)
10803 ProcessStatement(stmt.forStmt.check);
10804 if(stmt.forStmt.increment)
10806 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
10807 ProcessExpressionType(exp);
10810 if(stmt.forStmt.stmt)
10811 ProcessStatement(stmt.forStmt.stmt);
10816 Identifier id = stmt.forEachStmt.id;
10817 OldList * exp = stmt.forEachStmt.exp;
10818 OldList * filter = stmt.forEachStmt.filter;
10819 Statement block = stmt.forEachStmt.stmt;
10820 char iteratorType[1024];
10823 bool isBuiltin = exp && exp->last &&
10824 (((Expression)exp->last).type == ExpressionType::arrayExp ||
10825 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
10826 Expression arrayExp;
10827 char * typeString = null;
10828 int builtinCount = 0;
10830 for(e = exp ? exp->first : null; e; e = e.next)
10834 FreeType(e.destType);
10835 e.destType = ProcessTypeString("Container", false);
10837 if(!isBuiltin || e.next)
10838 ProcessExpressionType(e);
10841 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
10842 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
10843 eClass_IsDerived(source._class.registered, containerClass)))
10845 Class _class = source ? source._class.registered : null;
10847 Expression expIt = null;
10848 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
10849 Class arrayClass = eSystem_FindClass(privateModule, "Array");
10850 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
10851 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
10852 stmt.type = compoundStmt;
10854 stmt.compound.context = Context { };
10855 stmt.compound.context.parent = curContext;
10856 curContext = stmt.compound.context;
10858 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
10860 Class mapClass = eSystem_FindClass(privateModule, "Map");
10861 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
10862 isCustomAVLTree = true;
10863 if(eClass_IsDerived(source._class.registered, avlTreeClass))
10865 else if(eClass_IsDerived(source._class.registered, mapClass))
10868 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
10869 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
10871 Class listClass = eSystem_FindClass(privateModule, "List");
10873 isList = eClass_IsDerived(source._class.registered, listClass);
10879 OldList * specs = MkList();
10880 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
10881 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
10882 stmt.compound.declarations = MkListOne(
10883 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
10884 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
10885 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
10886 MkInitializerAssignment(MkExpBrackets(exp))))));
10891 char typeStringBuf[1024];
10893 // TODO: Merge this code?
10894 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
10895 if(((Expression)exp->last).type == castExp)
10897 TypeName typeName = ((Expression)exp->last).cast.typeName;
10899 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
10902 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
10903 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
10904 arrayExp.destType._class.registered.templateArgs)
10906 Class templateClass = arrayExp.destType._class.registered;
10907 typeString = templateClass.templateArgs[2].dataTypeString;
10909 else if(arrayExp.list)
10911 // Guess type from expressions in the array
10913 for(e = arrayExp.list->first; e; e = e.next)
10915 ProcessExpressionType(e);
10918 if(!type) { type = e.expType; type.refCount++; }
10921 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10922 if(!MatchTypeExpression(e, type, null, false))
10928 e = arrayExp.list->first;
10929 ProcessExpressionType(e);
10932 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
10933 if(!MatchTypeExpression(e, type, null, false))
10935 FreeType(e.expType);
10946 FreeType(e.expType);
10953 typeStringBuf[0] = '\0';
10954 PrintType(type, typeStringBuf, false, true);
10955 typeString = typeStringBuf;
10961 OldList * initializers = MkList();
10963 OldList * specs = MkList();
10968 builtinCount = arrayExp.list->count;
10969 type = ProcessTypeString(typeString, false);
10970 while(e = arrayExp.list->first)
10972 arrayExp.list->Remove(e);
10975 ProcessExpressionType(e);
10976 ListAdd(initializers, MkInitializerAssignment(e));
10979 delete arrayExp.list;
10981 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
10982 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
10983 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
10985 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
10986 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
10988 FreeList(exp, FreeExpression);
10992 arrayExp.expType = ProcessTypeString("Container", false);
10993 Compiler_Error("Couldn't determine type of array elements\n");
10998 OldList * specs = MkList();
11000 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11001 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11002 stmt.compound.declarations = MkListOne(
11003 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11004 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11005 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11006 MkInitializerAssignment(MkExpBrackets(exp))))));
11009 else if(isLinkList && !isList)
11012 OldList * specs = MkList();
11013 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11014 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11015 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11016 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11017 MkInitializerAssignment(MkExpBrackets(exp))))));
11019 /*else if(isCustomAVLTree)
11022 OldList * specs = MkList();
11023 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11024 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11025 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11026 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11027 MkInitializerAssignment(MkExpBrackets(exp))))));
11029 else if(_class.templateArgs)
11032 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11034 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11036 stmt.compound.declarations = MkListOne(
11037 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11038 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11039 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11041 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11043 if(block && block.type == compoundStmt && block.compound.context)
11045 block.compound.context.parent = stmt.compound.context;
11049 block = MkIfStmt(filter, block, null);
11053 stmt.compound.statements = MkListOne(MkForStmt(
11054 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11055 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11056 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11057 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11059 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11060 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11061 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11066 //OldList * specs = MkList();
11067 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11069 sprintf(count, "%d", builtinCount);
11071 stmt.compound.statements = MkListOne(MkForStmt(
11072 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11073 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11074 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11075 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11079 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11080 stmt.compound.statements = MkListOne(MkForStmt(
11081 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11082 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11083 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11084 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11087 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11088 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11089 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11091 else if(isLinkList && !isList)
11093 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11094 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11095 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11096 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11098 stmt.compound.statements = MkListOne(MkForStmt(
11099 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11100 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11101 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11106 OldList * specs = MkList();
11107 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11108 stmt.compound.statements = MkListOne(MkForStmt(
11109 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11110 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11111 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11112 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11113 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11116 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11117 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11118 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11120 /*else if(isCustomAVLTree)
11122 stmt.compound.statements = MkListOne(MkForStmt(
11123 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11124 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11125 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11126 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11129 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11130 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11131 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11135 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11136 MkIdentifier("Next")), null)), block));
11138 ProcessExpressionType(expIt);
11139 if(stmt.compound.declarations->first)
11140 ProcessDeclaration(stmt.compound.declarations->first);
11143 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11145 ProcessStatement(stmt);
11146 curContext = stmt.compound.context.parent;
11151 Compiler_Error("Expression is not a container\n");
11164 if(stmt.expressions)
11166 for(exp = stmt.expressions->first; exp; exp = exp.next)
11170 if(curFunction && !curFunction.type)
11171 curFunction.type = ProcessType(
11172 curFunction.specifiers, curFunction.declarator);
11173 FreeType(exp.destType);
11174 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11175 if(exp.destType) exp.destType.refCount++;
11177 ProcessExpressionType(exp);
11182 case badDeclarationStmt:
11184 ProcessDeclaration(stmt.decl);
11190 if(stmt.asmStmt.inputFields)
11192 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11193 if(field.expression)
11194 ProcessExpressionType(field.expression);
11196 if(stmt.asmStmt.outputFields)
11198 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11199 if(field.expression)
11200 ProcessExpressionType(field.expression);
11202 if(stmt.asmStmt.clobberedFields)
11204 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11206 if(field.expression)
11207 ProcessExpressionType(field.expression);
11214 PropertyWatch propWatch;
11215 OldList * watches = stmt._watch.watches;
11216 Expression object = stmt._watch.object;
11217 Expression watcher = stmt._watch.watcher;
11219 ProcessExpressionType(watcher);
11221 ProcessExpressionType(object);
11225 if(watcher || thisClass)
11227 External external = curExternal;
11228 Context context = curContext;
11230 stmt.type = expressionStmt;
11231 stmt.expressions = MkList();
11233 curExternal = external.prev;
11235 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11237 ClassFunction func;
11238 char watcherName[1024];
11239 Class watcherClass = watcher ?
11240 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11241 External createdExternal;
11243 // Create a declaration above
11244 External externalDecl = MkExternalDeclaration(null);
11245 ast->Insert(curExternal.prev, externalDecl);
11247 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11248 if(propWatch.deleteWatch)
11249 strcat(watcherName, "_delete");
11253 for(propID = propWatch.properties->first; propID; propID = propID.next)
11255 strcat(watcherName, "_");
11256 strcat(watcherName, propID.string);
11260 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11262 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11263 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11264 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11265 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11266 ProcessClassFunctionBody(func, propWatch.compound);
11267 propWatch.compound = null;
11269 //afterExternal = afterExternal ? afterExternal : curExternal;
11271 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11272 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11274 createdExternal.symbol.idCode = external.symbol.idCode;
11276 curExternal = createdExternal;
11277 ProcessFunction(createdExternal.function);
11280 // Create a declaration above
11282 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11283 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11284 externalDecl.declaration = decl;
11285 if(decl.symbol && !decl.symbol.pointerExternal)
11286 decl.symbol.pointerExternal = externalDecl;
11289 if(propWatch.deleteWatch)
11291 OldList * args = MkList();
11292 ListAdd(args, CopyExpression(object));
11293 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11294 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11295 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11299 Class _class = object.expType._class.registered;
11302 for(propID = propWatch.properties->first; propID; propID = propID.next)
11304 char propName[1024];
11305 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11308 char getName[1024], setName[1024];
11309 OldList * args = MkList();
11311 DeclareProperty(prop, setName, getName);
11313 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11314 strcpy(propName, "__ecereProp_");
11315 FullClassNameCat(propName, prop._class.fullName, false);
11316 strcat(propName, "_");
11317 // strcat(propName, prop.name);
11318 FullClassNameCat(propName, prop.name, true);
11320 ListAdd(args, CopyExpression(object));
11321 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11322 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11323 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11325 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11328 Compiler_Error("Property %s not found in class %s\n", prop.name, _class.fullName);
11333 Compiler_Error("Invalid watched object\n");
11336 curExternal = external;
11337 curContext = context;
11340 FreeExpression(watcher);
11342 FreeExpression(object);
11343 FreeList(watches, FreePropertyWatch);
11346 Compiler_Error("No observer specified and not inside a _class\n");
11350 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11352 ProcessStatement(propWatch.compound);
11358 case fireWatchersStmt:
11360 OldList * watches = stmt._watch.watches;
11361 Expression object = stmt._watch.object;
11363 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11364 // printf("%X\n", watches);
11365 // printf("%X\n", stmt._watch.watches);
11367 ProcessExpressionType(object);
11372 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11378 stmt.type = expressionStmt;
11379 stmt.expressions = MkList();
11381 // Check if we're inside a property set
11382 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11384 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11388 //Compiler_Error("No property specified and not inside a property set\n");
11392 for(propID = watches->first; propID; propID = propID.next)
11394 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11397 CreateFireWatcher(prop, object, stmt);
11400 Compiler_Error("Property %s not found in class %s\n", propID.string, _class.fullName);
11405 // Fire all properties!
11408 for(base = _class; base; base = base.base)
11410 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11412 if(prop.isProperty && prop.isWatchable)
11414 CreateFireWatcher(prop, object, stmt);
11421 FreeExpression(object);
11422 FreeList(watches, FreeIdentifier);
11425 Compiler_Error("Invalid object specified and not inside a class\n");
11429 case stopWatchingStmt:
11431 OldList * watches = stmt._watch.watches;
11432 Expression object = stmt._watch.object;
11433 Expression watcher = stmt._watch.watcher;
11436 ProcessExpressionType(object);
11438 ProcessExpressionType(watcher);
11441 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11443 if(watcher || thisClass)
11449 stmt.type = expressionStmt;
11450 stmt.expressions = MkList();
11455 // eInstance_StopWatching(object, null, watcher);
11457 ListAdd(args, CopyExpression(object));
11458 ListAdd(args, MkExpConstant("0"));
11459 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11460 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11464 for(propID = watches->first; propID; propID = propID.next)
11466 char propName[1024];
11467 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11470 char getName[1024], setName[1024];
11471 OldList * args = MkList();
11473 DeclareProperty(prop, setName, getName);
11475 // eInstance_StopWatching(object, prop, watcher);
11476 strcpy(propName, "__ecereProp_");
11477 FullClassNameCat(propName, prop._class.fullName, false);
11478 strcat(propName, "_");
11479 // strcat(propName, prop.name);
11480 FullClassNameCat(propName, prop.name, true);
11481 MangleClassName(propName);
11483 ListAdd(args, CopyExpression(object));
11484 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11485 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11486 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11489 Compiler_Error("Property %s not found in class %s\n", prop.name, _class.fullName);
11494 FreeExpression(object);
11496 FreeExpression(watcher);
11497 FreeList(watches, FreeIdentifier);
11500 Compiler_Error("Invalid object specified and not inside a class\n");
11503 Compiler_Error("No observer specified and not inside a class\n");
11510 static void ProcessFunction(FunctionDefinition function)
11512 Identifier id = GetDeclId(function.declarator);
11513 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11514 Type type = symbol ? symbol.type : null;
11515 Class oldThisClass = thisClass;
11516 Context oldTopContext = topContext;
11518 yylloc = function.loc;
11519 // Process thisClass
11521 if(type && type.thisClass)
11523 Symbol classSym = type.thisClass;
11524 Class _class = type.thisClass.registered;
11525 char className[1024];
11526 char structName[1024];
11527 Declarator funcDecl;
11530 bool typedObject = false;
11532 if(_class && !_class.base)
11534 _class = currentClass;
11535 if(_class && !_class.symbol)
11536 _class.symbol = FindClass(_class.fullName);
11537 classSym = _class ? _class.symbol : null;
11538 typedObject = true;
11541 thisClass = _class;
11543 if(inCompiler && _class)
11545 if(type.kind == functionType)
11547 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11549 //TypeName param = symbol.type.params.first;
11550 Type param = symbol.type.params.first;
11551 symbol.type.params.Remove(param);
11552 //FreeTypeName(param);
11555 if(type.classObjectType != classPointer)
11557 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11558 symbol.type.staticMethod = true;
11559 symbol.type.thisClass = null;
11561 // HIGH DANGER: VERIFYING THIS...
11562 symbol.type.extraParam = false;
11566 strcpy(className, "__ecereClass_");
11567 FullClassNameCat(className, _class.fullName, true);
11569 MangleClassName(className);
11572 FullClassNameCat(structName, _class.fullName, false);
11577 funcDecl = GetFuncDecl(function.declarator);
11580 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11582 TypeName param = funcDecl.function.parameters->first;
11583 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11585 funcDecl.function.parameters->Remove(param);
11586 FreeTypeName(param);
11590 // DANGER: Watch for this... Check if it's a Conversion?
11591 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11593 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11594 if(!function.propertyNoThis)
11596 TypeName thisParam;
11598 if(type.classObjectType != classPointer)
11600 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11601 if(!funcDecl.function.parameters)
11602 funcDecl.function.parameters = MkList();
11603 funcDecl.function.parameters->Insert(null, thisParam);
11608 if(type.classObjectType != classPointer)
11610 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11611 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11614 thisParam = TypeName
11616 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11617 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11619 funcDecl.function.parameters->Insert(null, thisParam);
11624 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11626 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11627 funcDecl = GetFuncDecl(initDecl.declarator);
11630 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11632 TypeName param = funcDecl.function.parameters->first;
11633 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11635 funcDecl.function.parameters->Remove(param);
11636 FreeTypeName(param);
11640 if(type.classObjectType != classPointer)
11642 // DANGER: Watch for this... Check if it's a Conversion?
11643 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11645 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11647 if(!funcDecl.function.parameters)
11648 funcDecl.function.parameters = MkList();
11649 funcDecl.function.parameters->Insert(null, thisParam);
11656 // Add this to the context
11659 if(type.classObjectType != classPointer)
11661 thisSymbol = Symbol
11663 string = CopyString("this");
11664 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11666 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11668 if(typedObject && thisSymbol.type)
11670 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11671 thisSymbol.type.byReference = type.byReference;
11673 thisSymbol = Symbol { string = CopyString("class") };
11674 function.body.compound.context.symbols.Add(thisSymbol);
11680 // Pointer to class data
11682 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11684 DataMember member = null;
11687 for(base = _class; base && base.type != systemClass; base = base.next)
11689 for(member = base.membersAndProperties.first; member; member = member.next)
11690 if(!member.isProperty)
11696 for(member = _class.membersAndProperties.first; member; member = member.next)
11697 if(!member.isProperty)
11701 char pointerName[1024];
11704 Initializer initializer;
11705 Expression exp, bytePtr;
11707 strcpy(pointerName, "__ecerePointer_");
11708 FullClassNameCat(pointerName, _class.fullName, false);
11710 char className[1024];
11711 strcpy(className, "__ecereClass_");
11712 FullClassNameCat(className, classSym.string, true);
11713 MangleClassName(className);
11716 DeclareClass(classSym, className);
11720 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11725 sprintf(string, "%d", _class.offset);
11726 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11730 // ([bytePtr] + [className]->offset)
11731 exp = QBrackets(MkExpOp(bytePtr, '+',
11732 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
11735 // (this ? [exp] : 0)
11736 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
11740 kind = pointerType;
11741 type = Type { refCount = 1, kind = voidType };
11746 yylloc = function.body.loc;
11747 // ([structName] *) [exp]
11748 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
11749 initializer = MkInitializerAssignment(
11750 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
11752 // [structName] * [pointerName] = [initializer];
11753 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
11756 Context prevContext = curContext;
11757 curContext = function.body.compound.context;
11759 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
11760 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
11762 curContext = prevContext;
11766 decl.symbol = null;
11768 if(!function.body.compound.declarations)
11769 function.body.compound.declarations = MkList();
11770 function.body.compound.declarations->Insert(null, decl);
11776 // Loop through the function and replace undeclared identifiers
11777 // which are a member of the class (methods, properties or data)
11778 // by "this.[member]"
11785 FreeSpecifier(id._class);
11788 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11790 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11791 id = GetDeclId(initDecl.declarator);
11793 FreeSpecifier(id._class);
11798 topContext = function.body.compound.context;
11800 FunctionDefinition oldFunction = curFunction;
11801 curFunction = function;
11803 ProcessStatement(function.body);
11805 // If this is a property set and no firewatchers has been done yet, add one here
11806 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
11808 Statement prevCompound = curCompound;
11809 Context prevContext = curContext;
11811 Statement fireWatchers = MkFireWatchersStmt(null, null);
11812 if(!function.body.compound.statements) function.body.compound.statements = MkList();
11813 ListAdd(function.body.compound.statements, fireWatchers);
11815 curCompound = function.body;
11816 curContext = function.body.compound.context;
11818 ProcessStatement(fireWatchers);
11820 curContext = prevContext;
11821 curCompound = prevCompound;
11825 curFunction = oldFunction;
11828 if(function.declarator)
11830 ProcessDeclarator(function.declarator);
11833 topContext = oldTopContext;
11834 thisClass = oldThisClass;
11837 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
11838 static void ProcessClass(OldList definitions, Symbol symbol)
11841 External external = curExternal;
11842 Class regClass = symbol ? symbol.registered : null;
11844 // Process all functions
11845 for(def = definitions.first; def; def = def.next)
11847 if(def.type == functionClassDef)
11849 if(def.function.declarator)
11850 curExternal = def.function.declarator.symbol.pointerExternal;
11852 curExternal = external;
11854 ProcessFunction((FunctionDefinition)def.function);
11856 else if(def.type == declarationClassDef)
11858 if(def.decl.type == instDeclaration)
11860 thisClass = regClass;
11861 ProcessInstantiationType(def.decl.inst);
11867 Class backThisClass = thisClass;
11868 if(regClass) thisClass = regClass;
11869 ProcessDeclaration(def.decl);
11870 thisClass = backThisClass;
11873 else if(def.type == defaultPropertiesClassDef && def.defProperties)
11875 MemberInit defProperty;
11877 // Add this to the context
11878 Symbol thisSymbol = Symbol
11880 string = CopyString("this");
11881 type = regClass ? MkClassType(regClass.fullName) : null;
11883 globalContext.symbols.Add((BTNode)thisSymbol);
11885 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
11887 thisClass = regClass;
11888 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
11892 globalContext.symbols.Remove((BTNode)thisSymbol);
11893 FreeSymbol(thisSymbol);
11895 else if(def.type == propertyClassDef && def.propertyDef)
11897 PropertyDef prop = def.propertyDef;
11899 // Add this to the context
11901 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
11902 globalContext.symbols.Add(thisSymbol);
11905 thisClass = regClass;
11912 string = CopyString("this");
11913 type = MkClassType(regClass.fullName);
11915 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
11918 curExternal = prop.symbol ? prop.symbol.externalSet : null;
11919 ProcessStatement(prop.setStmt);
11927 string = CopyString("this");
11928 type = MkClassType(regClass.fullName);
11930 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
11933 curExternal = prop.symbol ? prop.symbol.externalGet : null;
11934 ProcessStatement(prop.getStmt);
11942 string = CopyString("this");
11943 type = MkClassType(regClass.fullName);
11945 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
11948 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
11949 ProcessStatement(prop.issetStmt);
11955 globalContext.symbols.Remove(thisSymbol);
11956 FreeSymbol(thisSymbol);
11959 else if(def.type == propertyWatchClassDef && def.propertyWatch)
11961 PropertyWatch propertyWatch = def.propertyWatch;
11963 thisClass = regClass;
11964 if(propertyWatch.compound)
11968 string = CopyString("this");
11969 type = regClass ? MkClassType(regClass.fullName) : null;
11972 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
11974 curExternal = null;
11975 ProcessStatement(propertyWatch.compound);
11982 void ComputeDataTypes()
11986 currentClass = null;
11988 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
11990 temp.symbol = Symbol { id = -1000, idCode = -1000 };
11992 // WHERE SHOULD THIS GO?
11993 // curExternal = ast->first;
11994 ast->Insert(null, temp);
11996 curExternal = temp;
11998 DeclareStruct("ecere::com::Class", false);
11999 DeclareStruct("ecere::com::Instance", false);
12000 DeclareStruct("ecere::com::Property", false);
12001 DeclareStruct("ecere::com::DataMember", false);
12002 DeclareStruct("ecere::com::Method", false);
12003 DeclareStruct("ecere::com::SerialBuffer", false);
12004 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12008 for(external = ast->first; external; external = external.next)
12010 afterExternal = curExternal = external;
12011 if(external.type == functionExternal)
12013 currentClass = external.function._class;
12014 ProcessFunction(external.function);
12016 // There shouldn't be any _class member access here anyways...
12017 else if(external.type == declarationExternal)
12019 currentClass = null;
12020 ProcessDeclaration(external.declaration);
12022 else if(external.type == classExternal)
12024 ClassDefinition _class = external._class;
12025 currentClass = external.symbol.registered;
12026 if(_class.definitions)
12028 ProcessClass(_class.definitions, _class.symbol);
12032 // Free class data...
12033 ast->Remove(external);
12037 else if(external.type == nameSpaceExternal)
12039 thisNameSpace = external.id.string;
12042 currentClass = null;
12043 thisNameSpace = null;
12045 delete temp.symbol;