3 // UNTIL IMPLEMENTED IN GRAMMAR
4 #define ACCESS_CLASSDATA(_class, baseClass) \
5 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
7 #define YYLTYPE Location
11 extern int returnCode;
12 extern Expression parsedExpression;
14 public void SetYydebug(bool b) { yydebug = b; }
19 // TODO: Reset this to 0 on reinitialization
22 int expression_yyparse();
23 static Statement curCompound;
24 External curExternal, afterExternal;
25 static Type curSwitchType;
26 static Class currentClass;
28 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
29 static char * thisNameSpace;
30 /*static */Class containerClass;
31 bool thisClassParams = true;
33 uint internalValueCounter;
36 Time findSymbolTotalTime;
39 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
40 /*static */public void PrintExpression(Expression exp, char * string)
46 bool backOutputLineNumbers = outputLineNumbers;
47 outputLineNumbers = false;
50 OutputExpression(exp, f);
52 count = strlen(string);
53 count += f.Read(string + count, 1, 1023);
57 outputLineNumbers = backOutputLineNumbers;
61 Type ProcessTemplateParameterType(TemplateParameter param)
63 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
65 // TOFIX: Will need to free this Type
68 if(param.dataTypeString)
69 param.baseType = ProcessTypeString(param.dataTypeString, false);
71 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
73 return param.baseType;
78 bool NeedCast(Type type1, Type type2)
80 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
82 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
87 if(type1.kind == type2.kind && type1.isLong == type2.isLong)
98 if(type1.passAsTemplate && !type2.passAsTemplate)
100 return type1.isSigned != type2.isSigned;
102 return type1._class != type2._class;
104 return (type1.type && type2.type && type1.type.constant != type2.type.constant) || NeedCast(type1.type, type2.type);
106 return true; //false; ????
112 static void ReplaceClassMembers(Expression exp, Class _class)
114 if(exp.type == identifierExp && exp.identifier)
116 Identifier id = exp.identifier;
118 Symbol symbol = null;
119 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
121 // First, check if the identifier is declared inside the function
122 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
124 if(!ctx) break; // This happened opening old mapTileCache.ec from archives?
125 symbol = (Symbol)ctx.symbols.FindString(id.string);
130 // If it is not, check if it is a member of the _class
131 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
133 Property prop = eClass_FindProperty(_class, id.string, privateModule);
134 Method method = null;
135 DataMember member = null;
136 ClassProperty classProp = null;
139 method = eClass_FindMethod(_class, id.string, privateModule);
142 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
143 if(!prop && !method && !member)
145 classProp = eClass_FindClassProperty(_class, id.string);
147 if(prop || method || member || classProp)
149 // Replace by this.[member]
150 exp.type = memberExp;
151 exp.member.member = id;
152 exp.member.memberType = unresolvedMember;
153 exp.member.exp = QMkExpId("this");
154 //exp.member.exp.loc = exp.loc;
155 exp.addedThis = true;
157 else if(_class && _class.templateParams.first)
160 for(sClass = _class; sClass; sClass = sClass.base)
162 if(sClass.templateParams.first)
164 ClassTemplateParameter param;
165 for(param = sClass.templateParams.first; param; param = param.next)
167 if(param.type == expression && !strcmp(param.name, id.string))
169 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
174 OldList * specs = MkList();
176 FreeIdentifier(exp.member.member);
178 ProcessExpressionType(argExp);
180 decl = SpecDeclFromString(param.dataTypeString, specs, null);
182 exp.expType = ProcessType(specs, decl);
184 // *[expType] *[argExp]
185 exp.type = bracketsExp;
186 exp.list = MkListOne(MkExpOp(null, '*',
187 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
198 ////////////////////////////////////////////////////////////////////////
199 // PRINTING ////////////////////////////////////////////////////////////
200 ////////////////////////////////////////////////////////////////////////
202 public char * PrintInt(int64 result)
206 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
208 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
209 if(result > MAXINT || result < MININT)
211 return CopyString(temp);
214 public char * PrintUInt(uint64 result)
217 if(result > MAXDWORD)
218 sprintf(temp, FORMAT64HEXLL /*"0x%I64X"*/, result);
219 else if(result > MAXINT)
220 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
222 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
223 return CopyString(temp);
226 public char * PrintInt64(int64 result)
229 if(result > MAXINT || result < MININT)
230 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
232 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
233 return CopyString(temp);
236 public char * PrintUInt64(uint64 result)
239 if(result > MAXDWORD)
240 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
241 else if(result > MAXINT)
242 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
244 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
245 return CopyString(temp);
248 public char * PrintHexUInt(uint64 result)
251 if(result > MAXDWORD)
252 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
254 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
255 if(result > MAXDWORD)
257 return CopyString(temp);
260 public char * PrintHexUInt64(uint64 result)
263 if(result > MAXDWORD)
264 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
266 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
267 return CopyString(temp);
270 public char * PrintShort(short result)
273 sprintf(temp, "%d", (unsigned short)result);
274 return CopyString(temp);
277 public char * PrintUShort(unsigned short result)
281 sprintf(temp, "0x%X", (int)result);
283 sprintf(temp, "%d", (int)result);
284 return CopyString(temp);
287 public char * PrintChar(char result)
290 if(result > 0 && isprint(result))
291 sprintf(temp, "'%c'", result);
293 sprintf(temp, "%d", (int)result);
295 //sprintf(temp, "%#X", result);
296 sprintf(temp, "0x%X", (unsigned char)result);
297 return CopyString(temp);
300 public char * PrintUChar(unsigned char result)
303 sprintf(temp, "0x%X", result);
304 return CopyString(temp);
307 public char * PrintFloat(float result)
313 strcpy(temp, "-inf");
317 else if(result.isNan)
320 strcpy(temp, "-nan");
325 sprintf(temp, "%.16ff", result);
326 return CopyString(temp);
329 public char * PrintDouble(double result)
335 strcpy(temp, "-inf");
339 else if(result.isNan)
342 strcpy(temp, "-nan");
347 sprintf(temp, "%.16f", result);
348 return CopyString(temp);
351 ////////////////////////////////////////////////////////////////////////
352 ////////////////////////////////////////////////////////////////////////
354 //public Operand GetOperand(Expression exp);
356 #define GETVALUE(name, t) \
357 public bool GetOp##name(Operand op2, t * value2) \
359 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
360 else if(op2.kind == intType) *value2 = (t) op2.ui; \
361 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
362 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
363 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
364 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
365 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
366 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
367 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
368 else if(op2.kind == shortType) *value2 = (t) op2.us; \
369 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
370 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
371 else if(op2.kind == floatType) *value2 = (t) op2.f; \
372 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
373 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
378 public bool Get##name(Expression exp, t * value2) \
380 Operand op2 = GetOperand(exp); \
381 return GetOp##name(op2, value2); \
384 // To help the debugger currently not preprocessing...
387 GETVALUE(Int, HELP(int));
388 GETVALUE(UInt, HELP(unsigned int));
389 GETVALUE(Int64, HELP(int64));
390 GETVALUE(UInt64, HELP(uint64));
391 GETVALUE(IntPtr, HELP(intptr));
392 GETVALUE(UIntPtr, HELP(uintptr));
393 GETVALUE(IntSize, HELP(intsize));
394 GETVALUE(UIntSize, HELP(uintsize));
395 GETVALUE(Short, HELP(short));
396 GETVALUE(UShort, HELP(unsigned short));
397 GETVALUE(Char, HELP(char));
398 GETVALUE(UChar, HELP(unsigned char));
399 GETVALUE(Float, HELP(float));
400 GETVALUE(Double, HELP(double));
402 void ComputeExpression(Expression exp);
404 void ComputeClassMembers(Class _class, bool isMember)
406 DataMember member = isMember ? (DataMember) _class : null;
407 Context context = isMember ? null : SetupTemplatesContext(_class);
408 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
409 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
411 int unionMemberOffset = 0;
415 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
416 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
421 member.memberOffset = 0;
422 if(targetBits < sizeof(void *) * 8)
423 member.structAlignment = 0;
425 else if(targetBits < sizeof(void *) * 8)
426 _class.structAlignment = 0;
428 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
429 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
430 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
432 if(!member && _class.destructionWatchOffset)
433 _class.memberOffset += sizeof(OldList);
435 // To avoid reentrancy...
436 //_class.structSize = -1;
439 DataMember dataMember;
440 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
442 if(!dataMember.isProperty)
444 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
446 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
447 /*if(!dataMember.dataType)
448 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
456 DataMember dataMember;
457 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
459 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
461 if(!isMember && _class.type == bitClass && dataMember.dataType)
463 BitMember bitMember = (BitMember) dataMember;
467 ComputeTypeSize(dataMember.dataType);
469 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
470 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
472 _class.memberOffset = bitMember.pos + bitMember.size;
473 for(d = 0; d<bitMember.size; d++)
479 bitMember.mask = mask << bitMember.pos;
481 else if(dataMember.type == normalMember && dataMember.dataType)
486 // Prevent infinite recursion
487 if(dataMember.dataType.kind != classType ||
488 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
489 _class.type != structClass)))
490 ComputeTypeSize(dataMember.dataType);
492 if(dataMember.dataType.bitFieldCount)
494 bitFields += dataMember.dataType.bitFieldCount;
501 int size = (bitFields + 7) / 8;
505 // TESTING THIS PADDING CODE
508 member.structAlignment = Max(member.structAlignment, alignment);
510 if(member.memberOffset % alignment)
511 member.memberOffset += alignment - (member.memberOffset % alignment);
514 dataMember.offset = member.memberOffset;
515 if(member.type == unionMember)
516 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
519 member.memberOffset += size;
524 // TESTING THIS PADDING CODE
527 _class.structAlignment = Max(_class.structAlignment, alignment);
529 if(_class.memberOffset % alignment)
530 _class.memberOffset += alignment - (_class.memberOffset % alignment);
533 dataMember.offset = _class.memberOffset;
534 _class.memberOffset += size;
538 size = dataMember.dataType.size;
539 alignment = dataMember.dataType.alignment;
544 // TESTING THIS PADDING CODE
547 member.structAlignment = Max(member.structAlignment, alignment);
549 if(member.memberOffset % alignment)
550 member.memberOffset += alignment - (member.memberOffset % alignment);
553 dataMember.offset = member.memberOffset;
554 if(member.type == unionMember)
555 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
558 member.memberOffset += size;
563 // TESTING THIS PADDING CODE
566 _class.structAlignment = Max(_class.structAlignment, alignment);
568 if(_class.memberOffset % alignment)
569 _class.memberOffset += alignment - (_class.memberOffset % alignment);
572 dataMember.offset = _class.memberOffset;
573 _class.memberOffset += size;
580 ComputeClassMembers((Class)dataMember, true);
581 alignment = dataMember.structAlignment;
587 if(member.memberOffset % alignment)
588 member.memberOffset += alignment - (member.memberOffset % alignment);
590 member.structAlignment = Max(member.structAlignment, alignment);
592 dataMember.offset = member.memberOffset;
593 if(member.type == unionMember)
594 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
596 member.memberOffset += dataMember.memberOffset;
602 if(_class.memberOffset % alignment)
603 _class.memberOffset += alignment - (_class.memberOffset % alignment);
604 _class.structAlignment = Max(_class.structAlignment, alignment);
606 dataMember.offset = _class.memberOffset;
607 _class.memberOffset += dataMember.memberOffset;
615 int size = (bitFields + 7) / 8;
619 // TESTING THIS PADDING CODE
622 member.structAlignment = Max(member.structAlignment, alignment);
624 if(member.memberOffset % alignment)
625 member.memberOffset += alignment - (member.memberOffset % alignment);
628 if(member.type == unionMember)
629 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
632 member.memberOffset += size;
637 // TESTING THIS PADDING CODE
640 _class.structAlignment = Max(_class.structAlignment, alignment);
642 if(_class.memberOffset % alignment)
643 _class.memberOffset += alignment - (_class.memberOffset % alignment);
645 _class.memberOffset += size;
650 if(member && member.type == unionMember)
652 member.memberOffset = unionMemberOffset;
657 /*if(_class.type == structClass)
658 _class.size = _class.memberOffset;
662 if(_class.type != bitClass)
665 if(_class.structAlignment)
667 if(_class.memberOffset % _class.structAlignment)
668 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
670 _class.structSize = (_class.base ? (_class.base.templateClass ?
671 (_class.base.type == noHeadClass ? _class.base.templateClass.memberOffset : _class.base.templateClass.structSize) :
672 (_class.base.type == noHeadClass ? _class.base.memberOffset : _class.base.structSize) ) : 0) + _class.memberOffset + extra;
676 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
678 if(prop.isProperty && prop.isWatchable)
680 prop.watcherOffset = _class.structSize;
681 _class.structSize += sizeof(OldList);
689 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
691 Class deriv = derivative.data;
693 if(deriv.computeSize)
695 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
696 deriv.offset = /*_class.offset + */(_class.type == noHeadClass ? _class.memberOffset : _class.structSize);
697 deriv.memberOffset = 0;
698 // ----------------------
700 deriv.structSize = deriv.offset;
702 ComputeClassMembers(deriv, false);
710 FinishTemplatesContext(context);
713 public void ComputeModuleClasses(Module module)
718 for(subModule = module.modules.first; subModule; subModule = subModule.next)
719 ComputeModuleClasses(subModule.data);
720 for(_class = module.classes.first; _class; _class = _class.next)
721 ComputeClassMembers(_class, false);
725 public int ComputeTypeSize(Type type)
727 uint size = type ? type.size : 0;
728 if(!size && type && !type.computing)
730 type.computing = true;
733 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
734 case charType: type.alignment = size = sizeof(char); break;
735 case intType: type.alignment = size = sizeof(int); break;
736 case int64Type: type.alignment = size = sizeof(int64); break;
737 case intPtrType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; break;
738 case intSizeType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; break;
739 case longType: type.alignment = size = sizeof(long); break;
740 case shortType: type.alignment = size = sizeof(short); break;
741 case floatType: type.alignment = size = sizeof(float); break;
742 case doubleType: type.alignment = size = sizeof(double); break;
745 Class _class = type._class ? type._class.registered : null;
747 if(_class && _class.type == structClass)
749 // Ensure all members are properly registered
750 ComputeClassMembers(_class, false);
751 type.alignment = _class.structAlignment;
752 type.pointerAlignment = (bool)_class.pointerAlignment;
753 size = _class.structSize;
754 if(type.alignment && size % type.alignment)
755 size += type.alignment - (size % type.alignment);
758 else if(_class && (_class.type == unitClass ||
759 _class.type == enumClass ||
760 _class.type == bitClass))
763 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
764 size = type.alignment = ComputeTypeSize(_class.dataType);
768 size = type.alignment = targetBits / 8; // sizeof(Instance *);
769 type.pointerAlignment = true;
773 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */ type.pointerAlignment = true; break;
775 if(type.arraySizeExp)
777 ProcessExpressionType(type.arraySizeExp);
778 ComputeExpression(type.arraySizeExp);
779 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
780 type.arraySizeExp.expType.kind != shortType &&
781 type.arraySizeExp.expType.kind != charType &&
782 type.arraySizeExp.expType.kind != longType &&
783 type.arraySizeExp.expType.kind != int64Type &&
784 type.arraySizeExp.expType.kind != intSizeType &&
785 type.arraySizeExp.expType.kind != intPtrType &&
786 type.arraySizeExp.expType.kind != enumType &&
787 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
789 Location oldLoc = yylloc;
790 // bool isConstant = type.arraySizeExp.isConstant;
791 char expression[10240];
792 expression[0] = '\0';
793 type.arraySizeExp.expType = null;
794 yylloc = type.arraySizeExp.loc;
796 PrintExpression(type.arraySizeExp, expression);
797 Compiler_Error($"Array size not constant int (%s)\n", expression);
800 GetInt(type.arraySizeExp, &type.arraySize);
802 else if(type.enumClass)
804 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
806 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
813 // Unimplemented auto size
817 size = ComputeTypeSize(type.type) * type.arraySize;
820 type.alignment = type.type.alignment;
821 type.pointerAlignment = type.type.pointerAlignment;
827 if(!type.members.first && type.enumName)
829 Symbol symbol = FindStruct(curContext, type.enumName);
830 if(symbol && symbol.type)
832 ComputeTypeSize(symbol.type);
833 size = symbol.type.size;
839 for(member = type.members.first; member; member = member.next)
841 uint addSize = ComputeTypeSize(member);
843 member.offset = size;
844 if(member.alignment && size % member.alignment)
845 member.offset += member.alignment - (size % member.alignment);
846 size = member.offset;
848 if(member.pointerAlignment && type.size <= 4)
849 type.pointerAlignment = true;
850 else if(!member.pointerAlignment && member.alignment >= 8)
851 type.pointerAlignment = false;
853 type.alignment = Max(type.alignment, member.alignment);
856 if(type.alignment && size % type.alignment)
857 size += type.alignment - (size % type.alignment);
863 if(!type.members.first && type.enumName)
865 Symbol symbol = FindStruct(curContext, type.enumName);
866 if(symbol && symbol.type)
868 ComputeTypeSize(symbol.type);
869 size = symbol.type.size;
870 type.alignment = symbol.type.alignment;
876 for(member = type.members.first; member; member = member.next)
878 uint addSize = ComputeTypeSize(member);
880 member.offset = size;
881 if(member.alignment && size % member.alignment)
882 member.offset += member.alignment - (size % member.alignment);
883 size = member.offset;
885 if(member.pointerAlignment && type.size <= 4)
886 type.pointerAlignment = true;
887 else if(!member.pointerAlignment && member.alignment >= 8)
888 type.pointerAlignment = false;
890 type.alignment = Max(type.alignment, member.alignment);
892 size = Max(size, addSize);
894 if(type.alignment && size % type.alignment)
895 size += type.alignment - (size % type.alignment);
901 TemplateParameter param = type.templateParameter;
902 Type baseType = ProcessTemplateParameterType(param);
905 size = ComputeTypeSize(baseType);
906 type.alignment = baseType.alignment;
907 type.pointerAlignment = baseType.pointerAlignment;
910 type.alignment = size = sizeof(uint64);
915 type.alignment = size = sizeof(enum { test });
920 type.alignment = size = targetBits / 8; //sizeof(void *);
921 type.pointerAlignment = true;
926 type.computing = false;
932 /*static */int AddMembers(External neededBy, OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
934 // This function is in need of a major review when implementing private members etc.
935 DataMember topMember = isMember ? (DataMember) _class : null;
942 Context context = isMember ? null : SetupTemplatesContext(_class);
944 *addedPadding = false;
946 if(!isMember && _class.base)
948 maxSize = _class.structSize;
949 //if(_class.base.type != systemClass) // Commented out with new Instance _class
951 // DANGER: Testing this noHeadClass here...
952 if(_class.type == structClass || _class.type == noHeadClass)
953 /*totalSize = */AddMembers(neededBy, declarations, _class.base, false, &totalSize, topClass, null);
956 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
957 if(maxSize > baseSize)
965 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
967 if(!member.isProperty)
973 if(member.dataTypeString)
975 OldList * specs = MkList(), * decls = MkList();
978 decl = SpecDeclFromString(member.dataTypeString, specs,
979 MkDeclaratorIdentifier(MkIdentifier(member.name)));
980 ListAdd(decls, MkStructDeclarator(decl, null));
981 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
984 member.dataType = ProcessType(specs, decl);
986 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
989 Type type = ProcessType(specs, decl);
990 DeclareType(neededBy, member.dataType, true, false);
994 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
995 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
996 DeclareStruct(member.dataType._class.string, false);
999 ComputeTypeSize(member.dataType);
1000 size = member.dataType.size;
1001 alignment = member.dataType.alignment;
1005 if(totalSize % alignment)
1006 totalSize += alignment - (totalSize % alignment);
1015 OldList * specs = MkList(), * list = MkList();
1017 sprintf(id, "__anon%d", anonID++);
1020 AddMembers(neededBy, list, (Class)member, true, &size, topClass, null);
1022 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
1023 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
1024 alignment = member.structAlignment;
1028 if(totalSize % alignment)
1029 totalSize += alignment - (totalSize % alignment);
1039 if(topMember && topMember.type == unionMember)
1040 *retSize = Max(*retSize, totalSize);
1042 *retSize += totalSize;
1044 else if(totalSize < maxSize && _class.type != systemClass)
1046 int autoPadding = 0;
1047 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1048 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1049 if(totalSize + autoPadding < maxSize)
1051 char sizeString[50];
1052 sprintf(sizeString, "%d", maxSize - totalSize);
1053 ListAdd(declarations,
1054 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1055 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1057 *addedPadding = true;
1061 FinishTemplatesContext(context);
1062 return topMember ? topMember.memberID : _class.memberID;
1065 static int DeclareMembers(External neededBy, Class _class, bool isMember)
1067 DataMember topMember = isMember ? (DataMember) _class : null;
1069 Context context = isMember ? null : SetupTemplatesContext(_class);
1071 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1072 DeclareMembers(neededBy, _class.base, false);
1074 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1076 if(!member.isProperty)
1082 if(!member.dataType && member.dataTypeString)
1083 member.dataType = ProcessTypeString(member.dataTypeString, false);
1085 DeclareType(neededBy, member.dataType, true, false);
1091 DeclareMembers(neededBy, (Class)member, true);
1098 FinishTemplatesContext(context);
1100 return topMember ? topMember.memberID : _class.memberID;
1103 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1107 for(def = definitions->first; def; def = def.next)
1109 if(def.type == declarationClassDef)
1111 Declaration decl = def.decl;
1112 if(decl && decl.specifiers)
1115 bool isStruct = false;
1116 for(spec = decl.specifiers->first; spec; spec = spec.next)
1118 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1120 if(spec.definitions)
1121 IdentifyAnonStructs(spec.definitions);
1127 Declarator d = null;
1128 if(decl.declarators)
1130 for(d = decl.declarators->first; d; d = d.next)
1132 Identifier idDecl = GetDeclId(d);
1140 sprintf(id, "__anon%d", anonID++);
1141 if(!decl.declarators)
1142 decl.declarators = MkList();
1143 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1151 External DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference)
1153 return _DeclareStruct(neededBy, name, skipNoHead, needDereference, false);
1156 External _DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference, bool fwdDecl)
1158 External external = null;
1159 Symbol classSym = FindClass(name);
1160 OldList * curDeclarations = null;
1162 if(!inCompiler || !classSym) return null;
1164 // We don't need any declaration for bit classes...
1165 if(classSym.registered &&
1166 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1169 if(!classSym.registered || (classSym.registered.type == normalClass && classSym.registered.structSize && classSym.registered.base && classSym.registered.base.base))
1170 _DeclareStruct(neededBy, "ecere::com::Instance", false, true, fwdDecl);
1172 external = classSym.structExternal;
1174 if(external && external.declaration)
1177 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1178 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1180 curDeclarations = spec.definitions;
1185 if(classSym.registered && !classSym.declaring && classSym.imported && (!classSym.declaredStructSym || (classSym.registered.type == noHeadClass && !skipNoHead && external && !curDeclarations)))
1187 OldList * specifiers, * declarators;
1188 OldList * declarations = null;
1189 char structName[1024];
1190 bool addedPadding = false;
1191 Specifier curSpec = null;
1193 classSym.declaring++;
1195 if(strchr(classSym.string, '<'))
1197 if(classSym.registered.templateClass)
1198 external = _DeclareStruct(neededBy, classSym.registered.templateClass.fullName, skipNoHead, needDereference, fwdDecl);
1199 classSym.declaring--;
1204 FullClassNameCat(structName, name, false);
1206 classSym.declaredStructSym = true;
1207 if(!external || (classSym.registered.type == noHeadClass && !skipNoHead && !curDeclarations))
1212 external = MkExternalDeclaration(null);
1213 classSym.structExternal = external;
1214 external.symbol = classSym;
1221 declarations = MkList();
1222 AddMembers(external, declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1225 if(external.declaration)
1228 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1229 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1232 curDeclarations = spec.definitions;
1237 if(declarations && (!declarations->count || (declarations->count == 1 && addedPadding)))
1239 FreeList(declarations, FreeClassDef);
1240 declarations = null;
1243 if(classSym.registered.type != noHeadClass && !declarations)
1245 FreeExternal(external);
1247 classSym.structExternal = null;
1252 curSpec.definitions = declarations;
1255 specifiers = MkList();
1256 declarators = MkList();
1257 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1258 external.declaration = MkDeclaration(specifiers, declarators);
1264 classSym.declaring--;
1266 else if(!classSym.declaredStructSym && classSym.structExternal)
1268 classSym.declaredStructSym = true;
1270 if(classSym.registered)
1271 DeclareMembers(classSym.structExternal, classSym.registered, false);
1273 if(classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1276 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1278 if(spec.definitions)
1279 IdentifyAnonStructs(spec.definitions);
1283 if(inCompiler && neededBy && (external || !classSym.imported))
1287 classSym.structExternal = external = MkExternalDeclaration(null);
1288 external.symbol = classSym;
1291 if(reachedPass15 && !external.declaration && classSym.registered && classSym.registered.type == noHeadClass)
1293 // Declare nohead classes without definitions here (e.g. IteratorPointer)
1294 char structName[1024];
1295 OldList * specifiers, * declarators;
1297 FullClassNameCat(structName, name, false);
1298 specifiers = MkList();
1299 declarators = MkList();
1300 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), null));
1301 external.declaration = MkDeclaration(specifiers, declarators);
1305 External e = external.fwdDecl ? external.fwdDecl : external;
1306 if(e.incoming.count)
1307 neededBy.CreateUniqueEdge(e, !needDereference && !external.fwdDecl);
1310 neededBy.CreateUniqueEdge(external, !needDereference);
1315 void DeclareProperty(External neededBy, Property prop, char * setName, char * getName)
1317 Symbol symbol = prop.symbol;
1318 bool imported = false;
1319 bool dllImport = false;
1320 External structExternal = null;
1321 External instExternal = null;
1323 strcpy(setName, "__ecereProp_");
1324 FullClassNameCat(setName, prop._class.fullName, false);
1325 strcat(setName, "_Set_");
1326 FullClassNameCat(setName, prop.name, true);
1328 strcpy(getName, "__ecereProp_");
1329 FullClassNameCat(getName, prop._class.fullName, false);
1330 strcat(getName, "_Get_");
1331 FullClassNameCat(getName, prop.name, true);
1333 if(!symbol || symbol._import)
1339 if(!prop._class.symbol)
1340 prop._class.symbol = FindClass(prop._class.fullName);
1341 classSym = prop._class.symbol;
1342 if(classSym && !classSym._import)
1344 ModuleImport module;
1346 if(prop._class.module)
1347 module = FindModule(prop._class.module);
1349 module = mainModule;
1351 classSym._import = ClassImport
1353 name = CopyString(prop._class.fullName);
1354 isRemote = prop._class.isRemote;
1356 module.classes.Add(classSym._import);
1358 symbol = prop.symbol = Symbol { };
1359 symbol._import = (ClassImport)PropertyImport
1361 name = CopyString(prop.name);
1362 isVirtual = false; //prop.isVirtual;
1363 hasSet = prop.Set ? true : false;
1364 hasGet = prop.Get ? true : false;
1367 classSym._import.properties.Add(symbol._import);
1370 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1371 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1372 prop._class.module.importType != staticImport)
1378 Context context = SetupTemplatesContext(prop._class);
1379 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1380 FinishTemplatesContext(context);
1383 if((prop.Get && !symbol.externalGet) || (prop.Set && !symbol.externalSet))
1385 if(prop._class.type == normalClass && prop._class.structSize)
1386 instExternal = DeclareStruct(null, "ecere::com::Instance", false, true);
1387 structExternal = DeclareStruct(null, prop._class.fullName, prop._class.type != structClass /*true*/, false);
1391 if(prop.Get && !symbol.externalGet)
1394 OldList * specifiers, * declarators;
1397 Specifier spec = null;
1399 Declarator typeDecl;
1400 bool simple = false;
1403 specifiers = MkList();
1404 declarators = MkList();
1407 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1408 MkDeclaratorIdentifier(MkIdentifier("this"))));
1410 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1413 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1416 Context context = SetupTemplatesContext(prop._class);
1417 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1418 FinishTemplatesContext(context);
1421 // Make sure the simple _class's type is declared
1422 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1423 for(spec = specifiers->first; spec; spec = spec.next)
1425 if(spec.type == nameSpecifier)
1427 Symbol classSym = spec.symbol;
1430 symbol._class = classSym.registered;
1431 if(classSym.registered && classSym.registered.type == structClass)
1439 d = PlugDeclarator(typeDecl, d);
1442 ListAdd(params, MkTypeName(specifiers,
1443 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1444 specifiers = MkList();
1447 d = MkDeclaratorFunction(d, params);
1451 specifiers->Insert(null, MkSpecifier(EXTERN));
1452 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1453 specifiers->Insert(null, MkSpecifier(STATIC));
1455 ListAdd(specifiers, MkSpecifier(VOID));
1457 ListAdd(declarators, MkInitDeclarator(d, null));
1459 decl = MkDeclaration(specifiers, declarators);
1461 external = MkExternalDeclaration(decl);
1464 external.CreateEdge(structExternal, false);
1466 external.CreateEdge(instExternal, false);
1469 DeclareStruct(external, spec.name, false, needReference);
1472 external.symbol = symbol;
1473 symbol.externalGet = external;
1475 ReplaceThisClassSpecifiers(specifiers, prop._class);
1478 FreeDeclarator(typeDecl);
1482 if(prop.Set && !symbol.externalSet)
1485 OldList * specifiers, * declarators;
1488 Specifier spec = null;
1490 Declarator typeDecl;
1493 declarators = MkList();
1496 if(!prop.conversion || prop._class.type == structClass)
1498 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1499 MkDeclaratorIdentifier(MkIdentifier("this"))));
1502 specifiers = MkList();
1505 Context context = SetupTemplatesContext(prop._class);
1506 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1507 MkDeclaratorIdentifier(MkIdentifier("value")));
1508 FinishTemplatesContext(context);
1510 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1511 specifiers->Insert(null, MkSpecifier(CONST));
1513 ListAdd(params, MkTypeName(specifiers, d));
1515 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1517 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1518 d = MkDeclaratorFunction(d, params);
1520 // Make sure the simple _class's type is declared
1521 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1522 for(spec = specifiers->first; spec; spec = spec.next)
1524 if(spec.type == nameSpecifier)
1526 Symbol classSym = spec.symbol;
1528 symbol._class = classSym.registered;
1533 ListAdd(declarators, MkInitDeclarator(d, null));
1535 specifiers = MkList();
1537 specifiers->Insert(null, MkSpecifier(EXTERN));
1538 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1539 specifiers->Insert(null, MkSpecifier(STATIC));
1541 if(!prop.conversion || prop._class.type == structClass)
1542 ListAdd(specifiers, MkSpecifier(VOID));
1544 ListAdd(specifiers, MkSpecifierName(prop._class.fullName));
1546 decl = MkDeclaration(specifiers, declarators);
1548 external = MkExternalDeclaration(decl);
1551 external.CreateEdge(structExternal, false);
1553 external.CreateEdge(instExternal, false);
1556 DeclareStruct(external, spec.name, false, needReference);
1559 external.symbol = symbol;
1560 symbol.externalSet = external;
1562 ReplaceThisClassSpecifiers(specifiers, prop._class);
1565 // Property (for Watchers)
1566 if(!symbol.externalPtr)
1570 OldList * specifiers = MkList();
1571 char propName[1024];
1574 specifiers->Insert(null, MkSpecifier(EXTERN));
1577 specifiers->Insert(null, MkSpecifier(STATIC));
1578 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
1581 ListAdd(specifiers, MkSpecifierName("Property"));
1583 strcpy(propName, "__ecereProp_");
1584 FullClassNameCat(propName, prop._class.fullName, false);
1585 strcat(propName, "_");
1586 FullClassNameCat(propName, prop.name, true);
1589 OldList * list = MkList();
1590 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1594 strcpy(propName, "__ecerePropM_");
1595 FullClassNameCat(propName, prop._class.fullName, false);
1596 strcat(propName, "_");
1597 FullClassNameCat(propName, prop.name, true);
1599 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1601 decl = MkDeclaration(specifiers, list);
1604 external = MkExternalDeclaration(decl);
1605 ast->Insert(curExternal.prev, external);
1606 external.symbol = symbol;
1607 symbol.externalPtr = external;
1610 if(inCompiler && neededBy)
1612 // Could improve this to create edge on only what is needed...
1613 if(symbol.externalPtr)
1614 neededBy.CreateUniqueEdge(symbol.externalPtr, false);
1616 if(symbol.externalGet)
1617 neededBy.CreateUniqueEdge(symbol.externalGet, symbol.externalGet.type == functionExternal);
1619 if(symbol.externalSet)
1620 neededBy.CreateUniqueEdge(symbol.externalSet, symbol.externalSet.type == functionExternal);
1626 // ***************** EXPRESSION PROCESSING ***************************
1627 public Type Dereference(Type source)
1632 if(source.kind == pointerType || source.kind == arrayType)
1635 source.type.refCount++;
1637 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1645 // Support dereferencing of no head classes for now...
1646 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1652 Compiler_Error($"cannot dereference type\n");
1657 static Type Reference(Type source)
1673 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1675 Identifier ident = member.identifiers ? member.identifiers->first : null;
1677 DataMember dataMember = null;
1678 Method method = null;
1679 bool freeType = false;
1681 yylloc = member.loc;
1687 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1691 dataMember = *curMember;
1697 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1698 DataMember _subMemberStack[256];
1699 int _subMemberStackPos = 0;
1701 // FILL MEMBER STACK
1703 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1706 dataMember = thisMember;
1707 if(curMember && thisMember.memberAccess == publicAccess)
1709 *curMember = thisMember;
1710 *curClass = thisMember._class;
1711 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1712 *subMemberStackPos = _subMemberStackPos;
1719 method = eClass_FindMethod(_class, ident.string, privateModule);
1720 if(method && method.type == virtualMethod)
1732 if(!dataMember.dataType && dataMember.dataTypeString)
1734 //Context context = SetupTemplatesContext(dataMember._class);
1735 Context context = SetupTemplatesContext(_class);
1736 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1737 FinishTemplatesContext(context);
1739 type = dataMember.dataType;
1743 // This is for destination type...
1744 if(!method.dataType)
1745 ProcessMethodType(method);
1746 //DeclareMethod(method);
1747 // method.dataType = ((Symbol)method.symbol)->type;
1748 type = method.dataType;
1751 if(ident && ident.next)
1753 for(ident = ident.next; ident && type; ident = ident.next)
1755 if(type.kind == classType)
1757 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1759 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1761 type = dataMember.dataType;
1763 else if(type.kind == structType || type.kind == unionType)
1766 for(memberType = type.members.first; memberType; memberType = memberType.next)
1768 if(!strcmp(memberType.name, ident.string))
1778 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1779 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1782 ClassTemplateParameter curParam = null;
1784 for(sClass = _class; sClass; sClass = sClass.base)
1787 if(sClass.templateClass) sClass = sClass.templateClass;
1788 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1790 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1792 for(sClass = sClass.base; sClass; sClass = sClass.base)
1794 if(sClass.templateClass) sClass = sClass.templateClass;
1795 id += sClass.templateParams.count;
1806 ClassTemplateArgument arg = _class.templateArgs[id];
1807 if(arg.dataTypeString)
1809 bool constant = type.constant;
1811 type = ProcessTypeString(arg.dataTypeString, false);
1812 if(type.kind == classType && constant) type.constant = true;
1813 else if(type.kind == pointerType)
1816 while(t.kind == pointerType) t = t.type;
1817 if(constant) t.constant = constant;
1820 if(type && _class.templateClass)
1821 type.passAsTemplate = true;
1827 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1828 exp.destType.refCount++;
1834 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1836 Class expClass = type._class.registered;
1837 Class cClass = null;
1841 char templateString[1024];
1842 ClassTemplateParameter param;
1843 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1844 for(cClass = expClass; cClass; cClass = cClass.base)
1847 if(cClass.templateClass) cClass = cClass.templateClass;
1848 for(param = cClass.templateParams.first; param; param = param.next)
1852 ClassTemplateArgument arg;
1853 for(sClass = cClass.base; sClass; sClass = sClass.base)
1855 if(sClass.templateClass) sClass = sClass.templateClass;
1856 id += sClass.templateParams.count;
1858 arg = expClass.templateArgs[id];
1860 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1862 ClassTemplateParameter cParam;
1863 //int p = numParams - sClass.templateParams.count;
1866 if(sClass.templateClass) sClass = sClass.templateClass;
1868 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1870 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1871 p += nextClass.templateParams.count;
1874 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1876 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1878 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1880 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1881 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1893 strcat(argument, arg.name.string);
1894 strcat(argument, " = ");
1900 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1901 char expString[1024];
1902 OldList * specs = MkList();
1903 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1905 char * string = PrintHexUInt64(arg.expression.ui64);
1906 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1909 ProcessExpressionType(exp);
1910 ComputeExpression(exp);
1911 expString[0] = '\0';
1912 PrintExpression(exp, expString);
1913 strcat(argument, expString);
1915 FreeExpression(exp);
1920 strcat(argument, arg.member.name);
1923 case TemplateParameterType::type:
1925 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1926 strcat(argument, arg.dataTypeString);
1932 if(paramCount) strcat(templateString, ", ");
1933 if(lastParam != p - 1)
1935 strcat(templateString, param.name);
1936 strcat(templateString, " = ");
1938 strcat(templateString, argument);
1947 int len = strlen(templateString);
1948 if(templateString[len-1] == '<')
1952 if(templateString[len-1] == '>')
1953 templateString[len++] = ' ';
1954 templateString[len++] = '>';
1956 templateString[len++] = '\0';
1959 Context context = SetupTemplatesContext(_class);
1960 if(freeType) FreeType(type);
1961 type = ProcessTypeString(templateString, false);
1963 FinishTemplatesContext(context);
1967 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1969 ProcessExpressionType(member.initializer.exp);
1970 if(!member.initializer.exp.expType)
1974 char expString[10240];
1975 expString[0] = '\0';
1976 PrintExpression(member.initializer.exp, expString);
1977 ChangeCh(expString, '\n', ' ');
1978 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1981 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1982 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1984 Compiler_Error($"incompatible instance method %s\n", ident.string);
1987 else if(member.initializer)
1990 FreeType(member.exp.destType);
1991 member.exp.destType = type;
1992 if(member.exp.destType)
1993 member.exp.destType.refCount++;
1994 ProcessExpressionType(member.exp);
1997 ProcessInitializer(member.initializer, type);
1999 if(freeType) FreeType(type);
2003 if(_class && _class.type == unitClass)
2005 if(member.initializer)
2008 FreeType(member.exp.destType);
2009 member.exp.destType = MkClassType(_class.fullName);
2010 ProcessExpressionType(member.initializer, type);
2012 Type type = MkClassType(_class.fullName);
2013 ProcessInitializer(member.initializer, type);
2019 if(member.initializer)
2021 //ProcessExpressionType(member.exp);
2022 ProcessInitializer(member.initializer, null);
2028 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2032 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2034 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2038 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2043 void ProcessInstantiationType(Instantiation inst)
2048 MembersInit members;
2052 classSym = inst._class.symbol;
2053 _class = classSym ? classSym.registered : null;
2055 if(!_class || _class.type != noHeadClass)
2056 DeclareStruct(curExternal, inst._class.name, false, true);
2058 afterExternal = afterExternal ? afterExternal : curExternal;
2061 ProcessExpressionType(inst.exp);
2063 inst.isConstant = true;
2066 DataMember curMember = null;
2067 Class curClass = null;
2068 DataMember subMemberStack[256];
2069 int subMemberStackPos = 0;
2071 for(members = inst.members->first; members; members = members.next)
2073 switch(members.type)
2075 case methodMembersInit:
2078 static uint instMethodID = 0;
2079 External external = curExternal;
2080 Context context = curContext;
2081 Declarator declarator = members.function.declarator;
2082 Identifier nameID = GetDeclId(declarator);
2083 char * unmangled = nameID ? nameID.string : null;
2085 External createdExternal = null;
2090 strcpy(name, "__ecereInstMeth_");
2091 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2093 strcat(name, nameID.string);
2095 sprintf(number, "_%08d", instMethodID++);
2096 strcat(name, number);
2097 nameID.string = CopyString(name);
2100 // Do modifications here...
2103 Symbol symbol = declarator.symbol;
2104 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2106 if(method && method.type == virtualMethod)
2108 symbol.method = method;
2109 ProcessMethodType(method);
2111 if(!symbol.type.thisClass)
2113 if(method.dataType.thisClass && currentClass &&
2114 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2116 if(!currentClass.symbol)
2117 currentClass.symbol = FindClass(currentClass.fullName);
2118 symbol.type.thisClass = currentClass.symbol;
2123 _class.symbol = FindClass(_class.fullName);
2124 symbol.type.thisClass = _class.symbol;
2127 DeclareType(curExternal, symbol.type, true, true);
2132 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2133 unmangled, classSym.string);
2137 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2141 FreeSpecifier(nameID._class);
2142 nameID._class = null;
2145 curExternal = createdExternal;
2148 if(createdExternal.function)
2149 ProcessFunction(createdExternal.function);
2153 curExternal = declarator.symbol.pointerExternal;
2154 ProcessFunction((FunctionDefinition)members.function);
2156 curExternal = external;
2157 curContext = context;
2161 FreeClassFunction(members.function);
2163 // In this pass, turn this into a MemberInitData
2164 exp = QMkExpId(name);
2165 members.type = dataMembersInit;
2166 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2172 case dataMembersInit:
2174 if(members.dataMembers && classSym)
2177 Location oldyyloc = yylloc;
2178 for(member = members.dataMembers->first; member; member = member.next)
2180 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2181 if(member.initializer && !member.initializer.isConstant)
2182 inst.isConstant = false;
2194 void DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2196 _DeclareType(neededFor, type, needDereference, forFunctionDef, false);
2199 void DeclareTypeForwardDeclare(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2201 _DeclareType(neededFor, type, needDereference, forFunctionDef, true);
2204 static void _DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef, bool fwdDecl)
2208 if(type.kind == functionType)
2211 for(param = type.params.first; param; param = param.next)
2212 _DeclareType(neededFor, param, forFunctionDef, false, fwdDecl);
2213 _DeclareType(neededFor, type.returnType, forFunctionDef, false, fwdDecl);
2215 else if(type.kind == pointerType)
2216 _DeclareType(neededFor, type.type, false, false, fwdDecl);
2217 else if(type.kind == classType)
2219 Class c = type._class.registered;
2220 _DeclareStruct(neededFor, c ? c.fullName : "ecere::com::Instance", c ? c.type == noHeadClass : false, needDereference && c && c.type == structClass, fwdDecl);
2222 else if(type.kind == structType || type.kind == unionType)
2225 for(member = type.members.first; member; member = member.next)
2226 _DeclareType(neededFor, member, needDereference, forFunctionDef, fwdDecl);
2228 else if(type.kind == arrayType)
2229 _DeclareType(neededFor, type.arrayType, true, false, fwdDecl);
2233 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2235 ClassTemplateArgument * arg = null;
2237 ClassTemplateParameter curParam = null;
2239 for(sClass = _class; sClass; sClass = sClass.base)
2242 if(sClass.templateClass) sClass = sClass.templateClass;
2243 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2245 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2247 for(sClass = sClass.base; sClass; sClass = sClass.base)
2249 if(sClass.templateClass) sClass = sClass.templateClass;
2250 id += sClass.templateParams.count;
2260 arg = &_class.templateArgs[id];
2261 if(arg && param.type == type)
2262 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2267 public Context SetupTemplatesContext(Class _class)
2269 Context context = PushContext();
2270 context.templateTypesOnly = true;
2271 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2273 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2274 for(; param; param = param.next)
2276 if(param.type == type && param.identifier)
2278 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2279 curContext.templateTypes.Add((BTNode)type);
2286 for(sClass = _class; sClass; sClass = sClass.base)
2288 ClassTemplateParameter p;
2289 for(p = sClass.templateParams.first; p; p = p.next)
2291 //OldList * specs = MkList();
2292 //Declarator decl = null;
2293 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2296 TemplateParameter param = p.param;
2300 // ADD DATA TYPE HERE...
2301 p.param = param = TemplateParameter
2303 identifier = MkIdentifier(p.name), type = p.type,
2304 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2307 type = TemplatedType { key = (uintptr)p.name, param = param };
2308 curContext.templateTypes.Add((BTNode)type);
2316 public void FinishTemplatesContext(Context context)
2318 PopContext(context);
2319 FreeContext(context);
2323 public void ProcessMethodType(Method method)
2325 if(!method.dataType)
2327 Context context = SetupTemplatesContext(method._class);
2329 method.dataType = ProcessTypeString(method.dataTypeString, false);
2331 FinishTemplatesContext(context);
2333 if(method.type != virtualMethod && method.dataType)
2335 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2337 if(!method._class.symbol)
2338 method._class.symbol = FindClass(method._class.fullName);
2339 method.dataType.thisClass = method._class.symbol;
2343 // Why was this commented out? Working fine without now...
2346 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2347 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2354 char * par = strstr(type, "(");
2355 char * classOp = null;
2360 for(c = par-type-1; c >= 0; c++)
2362 if(type[c] == ':' && type[c+1] == ':')
2364 classOp = type + c - 1;
2365 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2372 else if(!isspace(type[c]))
2379 int typeLen = strlen(type);
2380 memcpy(temp, classOp, classOpLen);
2381 temp[classOpLen] = '\0';
2383 _class = eSystem_FindClass(module, temp);
2386 method.dataTypeString = new char[typeLen - classOpLen + 1];
2387 memcpy(method.dataTypeString, type, classOp - type);
2388 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2391 method.dataTypeString = type;
2397 public void ProcessPropertyType(Property prop)
2401 Context context = SetupTemplatesContext(prop._class);
2402 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2403 FinishTemplatesContext(context);
2407 public void DeclareMethod(External neededFor, Method method, const char * name)
2409 Symbol symbol = method.symbol;
2410 if(!symbol || (!symbol.pointerExternal && (!symbol.methodCodeExternal || method.type == virtualMethod)))
2412 bool dllImport = false;
2414 if(!method.dataType)
2415 method.dataType = ProcessTypeString(method.dataTypeString, false);
2417 //if(!symbol || symbol._import || method.type == virtualMethod)
2419 if(!symbol || method.type == virtualMethod)
2422 if(!method._class.symbol)
2423 method._class.symbol = FindClass(method._class.fullName);
2424 classSym = method._class.symbol;
2425 if(!classSym._import)
2427 ModuleImport module;
2429 if(method._class.module && method._class.module.name)
2430 module = FindModule(method._class.module);
2432 module = mainModule;
2433 classSym._import = ClassImport
2435 name = CopyString(method._class.fullName);
2436 isRemote = method._class.isRemote;
2438 module.classes.Add(classSym._import);
2442 symbol = method.symbol = Symbol { };
2446 symbol._import = (ClassImport)MethodImport
2448 name = CopyString(method.name);
2449 isVirtual = method.type == virtualMethod;
2451 classSym._import.methods.Add(symbol._import);
2455 symbol.type = method.dataType;
2456 if(symbol.type) symbol.type.refCount++;
2459 if(!method.dataType.dllExport)
2461 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2468 // We need a declaration here :)
2470 OldList * specifiers, * declarators;
2472 Declarator funcDecl;
2475 specifiers = MkList();
2476 declarators = MkList();
2479 ListAdd(specifiers, MkSpecifier(EXTERN));
2480 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2481 ListAdd(specifiers, MkSpecifier(STATIC));
2483 if(method.type == virtualMethod)
2485 ListAdd(specifiers, MkSpecifier(INT));
2486 d = MkDeclaratorIdentifier(MkIdentifier(name));
2490 d = MkDeclaratorIdentifier(MkIdentifier(name));
2492 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2494 Context context = SetupTemplatesContext(method._class);
2495 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2496 FinishTemplatesContext(context);
2498 funcDecl = GetFuncDecl(d);
2502 Specifier spec, next;
2503 for(spec = specifiers->first; spec; spec = next)
2506 if(spec.type == extendedSpecifier)
2508 specifiers->Remove(spec);
2509 FreeSpecifier(spec);
2514 // Add this parameter if not a static method
2515 if(method.dataType && !method.dataType.staticMethod)
2517 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2519 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2520 TypeName thisParam = MkTypeName(MkListOne(
2521 MkSpecifierName(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2522 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2523 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2524 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2526 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2528 TypeName param = funcDecl.function.parameters->first;
2529 funcDecl.function.parameters->Remove(param);
2530 FreeTypeName(param);
2533 if(!funcDecl.function.parameters)
2534 funcDecl.function.parameters = MkList();
2535 funcDecl.function.parameters->Insert(null, thisParam);
2539 ProcessDeclarator(d, true);
2541 ListAdd(declarators, MkInitDeclarator(d, null));
2543 decl = MkDeclaration(specifiers, declarators);
2545 ReplaceThisClassSpecifiers(specifiers, method._class);
2547 external = MkExternalDeclaration(decl);
2548 external.symbol = symbol;
2549 symbol.pointerExternal = external;
2551 DeclareStruct(external, method._class.fullName, true, true);
2553 DeclareType(external, method.dataType, true, true);
2556 if(inCompiler && neededFor)
2558 External external = symbol.pointerExternal ? symbol.pointerExternal : symbol.methodCodeExternal;
2559 neededFor.CreateUniqueEdge(external, external.type == functionExternal);
2563 char * ReplaceThisClass(Class _class)
2565 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2569 ClassTemplateParameter param;
2572 char className[1024];
2573 strcpy(className, _class.fullName);
2574 for(param = _class.templateParams.first; param; param = param.next)
2576 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2578 if(first) strcat(className, "<");
2579 if(!first) strcat(className, ", ");
2580 if(lastParam + 1 != p)
2582 strcat(className, param.name);
2583 strcat(className, " = ");
2585 strcat(className, param.name);
2593 int len = strlen(className);
2594 if(className[len-1] == '>') className[len++] = ' ';
2595 className[len++] = '>';
2596 className[len++] = '\0';
2598 return CopyString(className);
2601 return CopyString(_class.fullName);
2604 Type ReplaceThisClassType(Class _class)
2607 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2611 ClassTemplateParameter param;
2613 char className[1024];
2614 strcpy(className, _class.fullName);
2616 for(param = _class.templateParams.first; param; param = param.next)
2618 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2620 if(first) strcat(className, "<");
2621 if(!first) strcat(className, ", ");
2622 if(lastParam + 1 != p)
2624 strcat(className, param.name);
2625 strcat(className, " = ");
2627 strcat(className, param.name);
2635 int len = strlen(className);
2636 if(className[len-1] == '>') className[len++] = ' ';
2637 className[len++] = '>';
2638 className[len++] = '\0';
2640 type = MkClassType(className);
2641 //type = ProcessTypeString(className, false);
2645 type = MkClassType(_class.fullName);
2646 //type = ProcessTypeString(_class.fullName, false);
2648 //type.wasThisClass = true;
2652 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2654 if(specs != null && _class)
2657 for(spec = specs.first; spec; spec = spec.next)
2659 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2661 spec.type = nameSpecifier;
2662 spec.name = ReplaceThisClass(_class);
2663 spec.symbol = FindClass(spec.name); //_class.symbol;
2669 // Returns imported or not
2670 bool DeclareFunction(External neededFor, GlobalFunction function, char * name)
2672 Symbol symbol = function.symbol;
2673 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2674 if(!symbol || !symbol.pointerExternal)
2676 bool imported = false;
2677 bool dllImport = false;
2679 if(!function.dataType)
2681 function.dataType = ProcessTypeString(function.dataTypeString, false);
2682 if(!function.dataType.thisClass)
2683 function.dataType.staticMethod = true;
2690 ModuleImport module = FindModule(function.module);
2691 // WARNING: This is not added anywhere...
2692 symbol = function.symbol = Symbol { };
2696 if(!function.dataType.dllExport)
2698 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2699 module.functions.Add(symbol._import);
2702 // Set the symbol type
2704 symbol.type = ProcessTypeString(function.dataTypeString, false);
2705 if(!symbol.type.thisClass)
2706 symbol.type.staticMethod = true;
2709 imported = symbol._import ? true : false;
2710 if(imported && function.module != privateModule && function.module.importType != staticImport)
2716 // TOCHECK: What's with the functionExternal check here? Is it Edge breaking / forward declaration?
2717 //if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2719 // We need a declaration here :)
2721 OldList * specifiers, * declarators;
2723 Declarator funcDecl;
2726 specifiers = MkList();
2727 declarators = MkList();
2729 ListAdd(specifiers, MkSpecifier(EXTERN));
2731 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2733 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2735 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2736 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2737 if(function.module.importType == staticImport)
2740 for(spec = specifiers->first; spec; spec = spec.next)
2741 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2743 specifiers->Remove(spec);
2744 FreeSpecifier(spec);
2749 funcDecl = GetFuncDecl(d);
2751 // Make sure we don't have empty parameter declarations for static methods...
2752 if(funcDecl && !funcDecl.function.parameters)
2754 funcDecl.function.parameters = MkList();
2755 funcDecl.function.parameters->Insert(null,
2756 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2759 ListAdd(declarators, MkInitDeclarator(d, null));
2762 Context oldCtx = curContext;
2763 curContext = globalContext;
2764 decl = MkDeclaration(specifiers, declarators);
2765 curContext = oldCtx;
2768 // Keep a different symbol for the function definition than the declaration...
2769 /* Note: This should be handled by the edge breaking...
2770 if(symbol.pointerExternal && symbol.pointerExternal.type == functionExternal)
2772 Symbol functionSymbol { };
2775 *functionSymbol = *symbol;
2776 functionSymbol.string = CopyString(symbol.string);
2777 if(functionSymbol.type)
2778 functionSymbol.type.refCount++;
2781 excludedSymbols->Add(functionSymbol);
2783 symbol.pointerExternal.symbol = functionSymbol;
2786 external = MkExternalDeclaration(decl);
2788 external.symbol = symbol;
2789 symbol.pointerExternal = external;
2791 DeclareType(external, function.dataType, true, true);
2795 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2796 neededFor.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
2797 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2800 void DeclareGlobalData(External neededFor, GlobalData data)
2802 Symbol symbol = data.symbol;
2803 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2804 if(!symbol || !symbol.pointerExternal)
2809 symbol = data.symbol = Symbol { };
2812 data.dataType = ProcessTypeString(data.dataTypeString, false);
2816 // We need a declaration here :)
2818 OldList * specifiers, * declarators;
2822 specifiers = MkList();
2823 declarators = MkList();
2825 ListAdd(specifiers, MkSpecifier(EXTERN));
2826 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2827 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2829 ListAdd(declarators, MkInitDeclarator(d, null));
2831 decl = MkDeclaration(specifiers, declarators);
2832 external = MkExternalDeclaration(decl);
2834 ast->Insert(curExternal.prev, external);
2835 external.symbol = symbol;
2836 symbol.pointerExternal = external;
2838 DeclareType(external, data.dataType, true, true);
2841 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2842 neededFor.CreateUniqueEdge(symbol.pointerExternal, false);
2845 class Conversion : struct
2847 Conversion prev, next;
2853 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2856 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2857 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2859 Class sourceClass = source.kind == classType ? source._class.registered : null;
2860 Class destClass = dest.kind == classType ? dest._class.registered : null;
2861 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
2862 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
2864 Type sourceType = source, destType = dest;
2865 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
2866 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
2867 if(!destType.constant && sourceType.constant)
2871 Compiler_Warning($"discarding const qualifier\n");
2878 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
2879 bool isConversionExploration, bool warnConst)
2884 CheckConstCompatibility(source, dest, true);
2885 // Property convert;
2887 if(source.kind == templateType && dest.kind != templateType)
2889 Type type = ProcessTemplateParameterType(source.templateParameter);
2890 if(type) source = type;
2893 if(dest.kind == templateType && source.kind != templateType)
2895 Type type = ProcessTemplateParameterType(dest.templateParameter);
2896 if(type) dest = type;
2899 if(dest.classObjectType == typedObject && dest.kind != functionType)
2901 if(source.classObjectType != anyObject)
2905 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2906 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2914 if(source.kind != functionType && source.classObjectType == anyObject)
2916 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
2920 if((dest.kind == structType && source.kind == structType) ||
2921 (dest.kind == unionType && source.kind == unionType))
2923 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2924 (source.members.first && source.members.first == dest.members.first))
2928 if(dest.kind == ellipsisType && source.kind != voidType)
2931 if(dest.kind == pointerType && dest.type.kind == voidType &&
2932 ((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))
2933 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2935 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2937 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2939 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2940 ((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))
2941 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2942 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2944 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2947 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2949 if(source._class.registered && source._class.registered.type == unitClass)
2951 if(conversions != null)
2953 if(source._class.registered == dest._class.registered)
2958 Class sourceBase, destBase;
2959 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2960 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2961 if(sourceBase == destBase)
2965 // Don't match enum inheriting from other enum if resolving enumeration values
2966 // TESTING: !dest.classObjectType
2967 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2969 (!source._class.registered || source._class.registered.type != enumClass) ||
2970 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2974 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2975 if(dest._class && dest._class.registered && source._class && source._class.registered &&
2976 (dest.casted || (enumBaseType && dest._class.registered.type == enumClass &&
2977 (source.kind == classType || // Added this here for a base enum to be acceptable for a derived enum (#139)
2978 source._class.registered.type != enumClass)
2981 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2989 // JUST ADDED THIS...
2990 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2995 // Just added this for Straight conversion of ColorAlpha => Color
2996 if(source.kind == classType)
2999 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3002 for(convert = _class.conversions.first; convert; convert = convert.next)
3004 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3006 Conversion after = (conversions != null) ? conversions.last : null;
3008 if(!convert.dataType)
3009 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3010 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3011 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3012 MatchTypes(convert.dataType, dest, conversions, null, null,
3013 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3014 convert.dataType.kind == classType, false, true, warnConst))
3016 if(!conversions && !convert.Get)
3018 else if(conversions != null)
3020 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3021 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3022 (dest.kind != classType || dest._class.registered != _class.base))
3026 Conversion conv { convert = convert, isGet = true };
3027 // conversions.Add(conv);
3028 conversions.Insert(after, conv);
3041 if(dest.kind == classType)
3044 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3047 for(convert = _class.conversions.first; convert; convert = convert.next)
3049 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3051 Type constType = null;
3052 bool success = false;
3053 // Conversion after = (conversions != null) ? conversions.last : null;
3055 if(!convert.dataType)
3056 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3058 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3061 constType = { kind = pointerType, refCount = 1, type = ptrType };
3062 CopyTypeInto(ptrType, convert.dataType.type);
3063 ptrType.constant = true;
3066 // Just added this equality check to prevent recursion.... Make it safer?
3067 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3068 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3070 if(!conversions && !convert.Set)
3072 else if(conversions != null)
3074 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3075 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3076 (source.kind != classType || source._class.registered != _class.base))
3080 // *** Testing this! ***
3081 Conversion conv { convert = convert };
3082 conversions.Add(conv);
3083 //conversions.Insert(after, conv);
3089 FreeType(constType);
3095 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3097 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3098 (source.kind != classType || source._class.registered.type != structClass))
3102 // TESTING THIS... IS THIS OK??
3103 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3105 if(!dest._class.registered.dataType)
3106 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3107 // Only support this for classes...
3108 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3109 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3111 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3120 if(source.kind == classType)
3123 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3126 for(convert = _class.conversions.first; convert; convert = convert.next)
3128 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3130 Conversion after = (conversions != null) ? conversions.last : null;
3132 if(!convert.dataType)
3133 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3134 if(convert.dataType != source &&
3135 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3136 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3138 if(!conversions && !convert.Get)
3140 else if(conversions != null)
3142 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3143 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3144 (dest.kind != classType || dest._class.registered != _class.base))
3148 Conversion conv { convert = convert, isGet = true };
3150 // conversions.Add(conv);
3151 conversions.Insert(after, conv);
3160 // TESTING THIS... IS THIS OK??
3161 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3163 if(!source._class.registered.dataType)
3164 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3165 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3167 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false, warnConst))
3169 // For bool to be accepted by byte, short, etc.
3170 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3177 if(source.kind == classType || source.kind == subClassType)
3179 else if(dest.kind == source.kind &&
3180 (dest.kind != structType && dest.kind != unionType &&
3181 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3183 // RECENTLY ADDED THESE
3184 else if(dest.kind == doubleType && source.kind == floatType)
3186 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3188 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3190 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3192 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3194 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3196 else if(source.kind == enumType &&
3197 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3199 else if(dest.kind == enumType && !isConversionExploration &&
3200 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3202 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3203 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3205 Type paramSource, paramDest;
3207 if(dest.kind == methodType)
3208 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3209 if(source.kind == methodType)
3210 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3212 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3213 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3214 if(dest.kind == methodType)
3215 dest = dest.method.dataType;
3216 if(source.kind == methodType)
3217 source = source.method.dataType;
3219 paramSource = source.params.first;
3220 if(paramSource && paramSource.kind == voidType) paramSource = null;
3221 paramDest = dest.params.first;
3222 if(paramDest && paramDest.kind == voidType) paramDest = null;
3225 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3226 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3228 // Source thisClass must be derived from destination thisClass
3229 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3230 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3232 if(paramDest && paramDest.kind == classType)
3233 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3235 Compiler_Error($"method class should not take an object\n");
3238 paramDest = paramDest.next;
3240 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3242 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3246 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3248 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3254 // THIS WAS BACKWARDS:
3255 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3256 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3259 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3261 Compiler_Error($"overriding class expected to be derived from method class\n");
3265 paramSource = paramSource.next;
3271 // Source thisClass must be derived from destination thisClass
3272 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3274 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3280 // THIS WAS BACKWARDS TOO??
3281 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3282 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3285 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3287 //Compiler_Error($"overriding class expected to be derived from method class\n");
3295 // Source return type must be derived from destination return type
3296 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3298 Compiler_Warning($"incompatible return type for function\n");
3301 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3303 CheckConstCompatibility(dest.returnType, source.returnType, true);
3307 for(; paramDest; paramDest = paramDest.next)
3311 //Compiler_Warning($"not enough parameters\n");
3312 Compiler_Error($"not enough parameters\n");
3316 Type paramDestType = paramDest;
3317 Type paramSourceType = paramSource;
3318 Type type = paramDestType;
3320 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3321 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3322 paramSource.kind != templateType)
3325 ClassTemplateParameter curParam = null;
3327 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3330 if(sClass.templateClass) sClass = sClass.templateClass;
3331 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3333 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3335 for(sClass = sClass.base; sClass; sClass = sClass.base)
3337 if(sClass.templateClass) sClass = sClass.templateClass;
3338 id += sClass.templateParams.count;
3349 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3350 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3354 // paramDest must be derived from paramSource
3355 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3356 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3360 PrintType(paramDest, type, false, true);
3361 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3363 if(paramDestType != paramDest)
3364 FreeType(paramDestType);
3367 if(paramDestType != paramDest)
3368 FreeType(paramDestType);
3371 paramSource = paramSource.next;
3375 Compiler_Error($"too many parameters\n");
3380 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3384 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3385 (source.kind == arrayType || source.kind == pointerType))
3387 // Pointers to pointer is incompatible with non normal/nohead classes
3388 if(!(dest.type && dest.type.kind == pointerType && source.type.kind == classType && source.type._class &&
3389 source.type._class.registered && (source.type._class.registered.type != normalClass && source.type._class.registered.type != noHeadClass) && !source.type.byReference))
3391 ComputeTypeSize(source.type);
3392 ComputeTypeSize(dest.type);
3393 if(source.type.size == dest.type.size && MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3401 static void FreeConvert(Conversion convert)
3403 if(convert.resultType)
3404 FreeType(convert.resultType);
3407 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3408 char * string, OldList conversions)
3412 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3414 Class _class = link.data;
3415 if(_class.type == enumClass)
3417 OldList converts { };
3419 type.kind = classType;
3422 _class.symbol = FindClass(_class.fullName);
3423 type._class = _class.symbol;
3425 if(MatchTypes(type, dest, &converts, null, null, dest.kind != classType || !dest._class || strcmp(dest._class.string, "bool"),
3426 false, false, false, false))
3429 Class enumClass = eSystem_FindClass(privateModule, "enum");
3433 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3435 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3436 for(value = e.values.first; value; value = value.next)
3438 if(!strcmp(value.name, string))
3443 FreeType(sourceExp.expType);
3445 sourceExp.isConstant = true;
3446 sourceExp.expType = MkClassType(baseClass.fullName);
3447 if(inCompiler || inPreCompiler || inDebugger)
3450 FreeExpContents(sourceExp);
3452 sourceExp.type = constantExp;
3453 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3454 sprintf(constant, FORMAT64D, value.data);
3456 sprintf(constant, FORMAT64HEXLL, value.data);
3457 sourceExp.constant = CopyString(constant);
3458 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3461 while(converts.first)
3463 Conversion convert = converts.first;
3464 converts.Remove(convert);
3465 conversions.Add(convert);
3474 converts.Free(FreeConvert);
3478 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3479 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3484 public bool ModuleVisibility(Module searchIn, Module searchFor)
3486 SubModule subModule;
3488 if(searchFor == searchIn)
3491 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3493 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3495 if(ModuleVisibility(subModule.module, searchFor))
3502 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3506 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3508 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3510 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3513 for(module = mainModule.application.allModules.first; module; module = module.next)
3515 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3521 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3524 Type realDest = dest;
3525 Type backupSourceExpType = null;
3526 Expression nbExp = GetNonBracketsExp(sourceExp);
3527 Expression computedExp = nbExp;
3530 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3531 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3533 computedExp = CopyExpression(nbExp); // Keep the original expression, but compute for checking enum ranges
3534 ComputeExpression(computedExp /*sourceExp*/);
3537 source = sourceExp.expType;
3539 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3541 if(computedExp != nbExp)
3543 FreeExpression(computedExp);
3544 computedExp = nbExp;
3550 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3552 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3554 Class sourceBase, destBase;
3555 for(sourceBase = source._class.registered;
3556 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3557 sourceBase = sourceBase.base);
3558 for(destBase = dest._class.registered;
3559 destBase && destBase.base && destBase.base.type != systemClass;
3560 destBase = destBase.base);
3561 //if(source._class.registered == dest._class.registered)
3562 if(sourceBase == destBase)
3564 if(computedExp != nbExp)
3566 FreeExpression(computedExp);
3567 computedExp = nbExp;
3579 int64 value = MAXINT;
3583 if(computedExp.type == constantExp)
3586 value = strtoll(computedExp.constant, null, 0);
3588 value = strtoull(computedExp.constant, null, 0);
3590 else if(computedExp.type == opExp && computedExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3593 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3595 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3597 if(computedExp != nbExp)
3599 FreeExpression(computedExp);
3600 computedExp = nbExp;
3603 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3604 !strcmp(source._class.registered.fullName, "unichar" /*"ecere::com::unichar"*/))
3607 source = Type { kind = intType, isSigned = false, refCount = 1 };
3610 if(dest.kind == classType)
3612 Class _class = dest._class ? dest._class.registered : null;
3614 if(_class && _class.type == unitClass)
3616 if(source.kind != classType)
3619 Type tempDest, tempSource;
3621 for(; _class.base.type != systemClass; _class = _class.base);
3623 tempDest = tempType;
3625 tempType.kind = classType;
3627 _class.symbol = FindClass(_class.fullName);
3629 tempType._class = _class.symbol;
3630 tempType.truth = dest.truth;
3632 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3634 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3635 backupSourceExpType = sourceExp.expType;
3636 if(dest.passAsTemplate)
3638 // Don't carry passAsTemplate
3639 sourceExp.expType = { };
3640 CopyTypeInto(sourceExp.expType, dest);
3641 sourceExp.expType.passAsTemplate = false;
3645 sourceExp.expType = dest;
3648 //sourceExp.expType = MkClassType(_class.fullName);
3656 // Why wasn't there something like this?
3657 if(_class && _class.type == bitClass && source.kind != classType)
3659 if(!dest._class.registered.dataType)
3660 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3661 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3664 FreeType(sourceExp.expType);
3665 source = sourceExp.expType = MkClassType(dest._class.string);
3668 //source.kind = classType;
3669 //source._class = dest._class;
3673 // Adding two enumerations
3675 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3677 if(!source._class.registered.dataType)
3678 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3679 if(!dest._class.registered.dataType)
3680 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3682 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3685 source = sourceExp.expType = MkClassType(dest._class.string);
3688 //source.kind = classType;
3689 //source._class = dest._class;
3693 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3695 OldList * specs = MkList();
3699 ReadString(string, sourceExp.string);
3700 decl = SpecDeclFromString(string, specs, null);
3702 FreeExpContents(sourceExp);
3703 FreeType(sourceExp.expType);
3705 sourceExp.type = classExp;
3706 sourceExp._classExp.specifiers = specs;
3707 sourceExp._classExp.decl = decl;
3708 sourceExp.expType = dest;
3713 if(backupSourceExpType) FreeType(backupSourceExpType);
3717 else if(source.kind == classType)
3719 Class _class = source._class ? source._class.registered : null;
3721 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || _class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3724 if(dest.kind != classType)
3726 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3727 if(!source._class.registered.dataType)
3728 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3731 dest = MkClassType(source._class.string);
3732 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3733 // dest = MkClassType(source._class.string);
3737 if(dest.kind != classType)
3740 Type tempDest, tempSource;
3742 if(!source._class.registered.dataType)
3743 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3745 for(; _class.base.type != systemClass; _class = _class.base);
3747 tempSource = tempType;
3748 tempType.kind = classType;
3749 tempType._class = FindClass(_class.fullName);
3750 tempType.truth = source.truth;
3751 tempType.classObjectType = source.classObjectType;
3754 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3756 // PUT THIS BACK TESTING UNITS?
3757 if(conversions && conversions.last)
3759 ((Conversion)(conversions.last)).resultType = dest;
3763 FreeType(sourceExp.expType);
3764 sourceExp.expType = MkClassType(_class.fullName);
3765 sourceExp.expType.truth = source.truth;
3766 sourceExp.expType.classObjectType = source.classObjectType;
3768 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3770 if(!sourceExp.destType)
3772 FreeType(sourceExp.destType);
3773 sourceExp.destType = sourceExp.expType;
3774 if(sourceExp.expType)
3775 sourceExp.expType.refCount++;
3778 //source = _class.dataType;
3781 // TOCHECK: TESTING THIS NEW CODE
3782 if(!_class.dataType)
3783 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3785 dest = MkClassType(source._class.string);
3786 dest.truth = source.truth;
3787 dest.classObjectType = source.classObjectType;
3790 source = _class.dataType;
3800 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3810 if(source.kind == classType)
3812 Class _class = source._class.registered;
3813 if(_class.type == unitClass)
3815 if(!_class.dataType)
3816 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3817 source = _class.dataType;
3821 if(dest.kind == classType)
3823 Class _class = dest._class ? dest._class.registered : null;
3824 bool fittingValue = false;
3825 if(_class && _class.type == enumClass)
3827 Class enumClass = eSystem_FindClass(privateModule, "enum");
3828 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3829 if(c && value >= 0 && value <= c.largest)
3830 fittingValue = true;
3833 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3834 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3836 if(_class.type == normalClass || _class.type == noHeadClass)
3838 Expression newExp { };
3839 *newExp = *sourceExp;
3840 if(sourceExp.destType) sourceExp.destType.refCount++;
3841 if(sourceExp.expType) sourceExp.expType.refCount++;
3842 sourceExp.type = castExp;
3843 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3844 sourceExp.cast.exp = newExp;
3845 FreeType(sourceExp.expType);
3846 sourceExp.expType = null;
3847 ProcessExpressionType(sourceExp);
3849 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3852 FreeType(sourceExp.expType);
3853 sourceExp.expType = dest;
3857 if(inCompiler) FreeType(dest);
3859 if(backupSourceExpType) FreeType(backupSourceExpType);
3863 if(!_class.dataType)
3864 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3866 dest = _class.dataType;
3870 // Accept lower precision types for units, since we want to keep the unit type
3871 if(dest.kind == doubleType &&
3872 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3873 source.kind == charType || source.kind == _BoolType))
3875 specs = MkListOne(MkSpecifier(DOUBLE));
3877 else if(dest.kind == floatType &&
3878 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3879 source.kind == _BoolType || source.kind == doubleType))
3881 specs = MkListOne(MkSpecifier(FLOAT));
3883 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3884 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3887 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3888 ListAdd(specs, MkSpecifier(INT64));
3890 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3891 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3894 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3895 ListAdd(specs, MkSpecifier(INT));
3897 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3898 source.kind == floatType || source.kind == doubleType))
3901 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3902 ListAdd(specs, MkSpecifier(SHORT));
3904 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3905 source.kind == floatType || source.kind == doubleType))
3908 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3909 ListAdd(specs, MkSpecifier(CHAR));
3915 if(backupSourceExpType)
3917 // Failed to convert: revert previous exp type
3918 if(sourceExp.expType) FreeType(sourceExp.expType);
3919 sourceExp.expType = backupSourceExpType;
3924 else if(dest.kind == doubleType &&
3925 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3926 source.kind == _BoolType || source.kind == charType))
3928 specs = MkListOne(MkSpecifier(DOUBLE));
3930 else if(dest.kind == floatType &&
3931 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3933 specs = MkListOne(MkSpecifier(FLOAT));
3935 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3936 (value == 1 || value == 0))
3939 ListAdd(specs, MkSpecifier(BOOL));
3941 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3942 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3944 if(source.kind == intType)
3948 if(backupSourceExpType) FreeType(backupSourceExpType);
3954 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3955 ListAdd(specs, MkSpecifier(CHAR));
3958 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3959 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3961 if(source.kind == intType)
3965 if(backupSourceExpType) FreeType(backupSourceExpType);
3971 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3972 ListAdd(specs, MkSpecifier(SHORT));
3975 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3978 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3979 ListAdd(specs, MkSpecifier(INT));
3981 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3984 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3985 ListAdd(specs, MkSpecifier(INT64));
3987 else if(dest.kind == enumType &&
3988 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3990 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3996 if(backupSourceExpType)
3998 // Failed to convert: revert previous exp type
3999 if(sourceExp.expType) FreeType(sourceExp.expType);
4000 sourceExp.expType = backupSourceExpType;
4005 if(!flag && !sourceExp.opDestType)
4007 Expression newExp { };
4008 *newExp = *sourceExp;
4011 if(sourceExp.destType) sourceExp.destType.refCount++;
4012 if(sourceExp.expType) sourceExp.expType.refCount++;
4014 sourceExp.type = castExp;
4015 if(realDest.kind == classType)
4017 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4018 FreeList(specs, FreeSpecifier);
4021 sourceExp.cast.typeName = MkTypeName(specs, null);
4022 if(newExp.type == opExp)
4024 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4027 sourceExp.cast.exp = newExp;
4029 FreeType(sourceExp.expType);
4030 sourceExp.expType = null;
4031 ProcessExpressionType(sourceExp);
4034 FreeList(specs, FreeSpecifier);
4038 if(backupSourceExpType) FreeType(backupSourceExpType);
4044 if(computedExp != nbExp)
4046 FreeExpression(computedExp);
4047 computedExp = nbExp;
4050 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4051 if(sourceExp.type == identifierExp)
4053 Identifier id = sourceExp.identifier;
4054 if(dest.kind == classType)
4056 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4058 Class _class = dest._class.registered;
4059 Class enumClass = eSystem_FindClass(privateModule, "enum");
4062 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4065 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4066 for(value = e.values.first; value; value = value.next)
4068 if(!strcmp(value.name, id.string))
4073 FreeType(sourceExp.expType);
4075 sourceExp.isConstant = true;
4076 sourceExp.expType = MkClassType(_class.fullName);
4077 if(inCompiler || inPreCompiler || inDebugger)
4079 FreeExpContents(sourceExp);
4081 sourceExp.type = constantExp;
4082 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4083 sourceExp.constant = PrintInt64(value.data);
4085 sourceExp.constant = PrintUInt64(value.data);
4086 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4096 // Loop through all enum classes
4097 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4108 #define TERTIARY(o, name, m, t, p) \
4109 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4111 exp.type = constantExp; \
4112 exp.string = p(op1.m ? op2.m : op3.m); \
4114 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4118 #define BINARY(o, name, m, t, p) \
4119 static bool name(Expression exp, Operand op1, Operand op2) \
4122 exp.type = constantExp; \
4123 exp.string = p((t)(op1.m o value2)); \
4125 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4129 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4130 static bool name(Expression exp, Operand op1, Operand op2) \
4133 exp.type = constantExp; \
4134 exp.string = p(value2 ? ((t)(op1.m o value2)) : 0); \
4136 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4140 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4141 static bool name(Expression exp, Operand op1, Operand op2) \
4144 exp.type = constantExp; \
4145 exp.string = p((t)(op1.m o value2)); \
4147 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4151 #define UNARY(o, name, m, t, p) \
4152 static bool name(Expression exp, Operand op1) \
4154 exp.type = constantExp; \
4155 exp.string = p((t)(o op1.m)); \
4157 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4161 #define OPERATOR_ALL(macro, o, name) \
4162 macro(o, Int##name, i, int, PrintInt) \
4163 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4164 macro(o, Int64##name, i64, int64, PrintInt64) \
4165 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4166 macro(o, Short##name, s, short, PrintShort) \
4167 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4168 macro(o, Char##name, c, char, PrintChar) \
4169 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4170 macro(o, Float##name, f, float, PrintFloat) \
4171 macro(o, Double##name, d, double, PrintDouble)
4173 #define OPERATOR_INTTYPES(macro, o, name) \
4174 macro(o, Int##name, i, int, PrintInt) \
4175 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4176 macro(o, Int64##name, i64, int64, PrintInt64) \
4177 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4178 macro(o, Short##name, s, short, PrintShort) \
4179 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4180 macro(o, Char##name, c, char, PrintChar) \
4181 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4183 #define OPERATOR_REALTYPES(macro, o, name) \
4184 macro(o, Float##name, f, float, PrintFloat) \
4185 macro(o, Double##name, d, double, PrintDouble)
4187 // binary arithmetic
4188 OPERATOR_ALL(BINARY, +, Add)
4189 OPERATOR_ALL(BINARY, -, Sub)
4190 OPERATOR_ALL(BINARY, *, Mul)
4191 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4192 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4193 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4196 OPERATOR_ALL(UNARY, -, Neg)
4198 // unary arithmetic increment and decrement
4199 OPERATOR_ALL(UNARY, ++, Inc)
4200 OPERATOR_ALL(UNARY, --, Dec)
4202 // binary arithmetic assignment
4203 OPERATOR_ALL(BINARY, =, Asign)
4204 OPERATOR_ALL(BINARY, +=, AddAsign)
4205 OPERATOR_ALL(BINARY, -=, SubAsign)
4206 OPERATOR_ALL(BINARY, *=, MulAsign)
4207 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4208 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4209 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4212 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4213 OPERATOR_INTTYPES(BINARY, |, BitOr)
4214 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4215 OPERATOR_INTTYPES(BINARY, <<, LShift)
4216 OPERATOR_INTTYPES(BINARY, >>, RShift)
4219 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4221 // binary bitwise assignment
4222 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4223 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4224 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4225 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4226 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4228 // unary logical negation
4229 OPERATOR_INTTYPES(UNARY, !, Not)
4231 // binary logical equality
4232 OPERATOR_ALL(BINARY, ==, Equ)
4233 OPERATOR_ALL(BINARY, !=, Nqu)
4236 OPERATOR_ALL(BINARY, &&, And)
4237 OPERATOR_ALL(BINARY, ||, Or)
4239 // binary logical relational
4240 OPERATOR_ALL(BINARY, >, Grt)
4241 OPERATOR_ALL(BINARY, <, Sma)
4242 OPERATOR_ALL(BINARY, >=, GrtEqu)
4243 OPERATOR_ALL(BINARY, <=, SmaEqu)
4245 // tertiary condition operator
4246 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4248 //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
4249 #define OPERATOR_TABLE_ALL(name, type) \
4250 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4252 type##Inc, type##Dec, \
4253 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4254 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4256 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4258 type##Equ, type##Nqu, \
4259 type##And, type##Or, \
4260 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4263 #define OPERATOR_TABLE_INTTYPES(name, type) \
4264 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4266 type##Inc, type##Dec, \
4267 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4268 null, null, null, null, null, \
4270 null, null, null, null, null, \
4272 type##Equ, type##Nqu, \
4273 type##And, type##Or, \
4274 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4277 OPERATOR_TABLE_ALL(int, Int)
4278 OPERATOR_TABLE_ALL(uint, UInt)
4279 OPERATOR_TABLE_ALL(int64, Int64)
4280 OPERATOR_TABLE_ALL(uint64, UInt64)
4281 OPERATOR_TABLE_ALL(short, Short)
4282 OPERATOR_TABLE_ALL(ushort, UShort)
4283 OPERATOR_TABLE_INTTYPES(float, Float)
4284 OPERATOR_TABLE_INTTYPES(double, Double)
4285 OPERATOR_TABLE_ALL(char, Char)
4286 OPERATOR_TABLE_ALL(uchar, UChar)
4288 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4289 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4290 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4291 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4292 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4293 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4294 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4295 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4297 public void ReadString(char * output, char * string)
4299 int len = strlen(string);
4301 bool quoted = false, escaped = false;
4302 for(c = 0; c<len; c++)
4304 char ch = string[c];
4309 case 'n': output[d] = '\n'; break;
4310 case 't': output[d] = '\t'; break;
4311 case 'a': output[d] = '\a'; break;
4312 case 'b': output[d] = '\b'; break;
4313 case 'f': output[d] = '\f'; break;
4314 case 'r': output[d] = '\r'; break;
4315 case 'v': output[d] = '\v'; break;
4316 case '\\': output[d] = '\\'; break;
4317 case '\"': output[d] = '\"'; break;
4318 case '\'': output[d] = '\''; break;
4319 default: output[d] = ch;
4340 // String Unescape Copy
4342 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4343 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4344 public int UnescapeString(char * d, char * s, int len)
4348 while(j < len && (ch = s[j]))
4353 switch((ch = s[++j]))
4355 case 'n': d[k] = '\n'; break;
4356 case 't': d[k] = '\t'; break;
4357 case 'a': d[k] = '\a'; break;
4358 case 'b': d[k] = '\b'; break;
4359 case 'f': d[k] = '\f'; break;
4360 case 'r': d[k] = '\r'; break;
4361 case 'v': d[k] = '\v'; break;
4362 case '\\': d[k] = '\\'; break;
4363 case '\"': d[k] = '\"'; break;
4364 case '\'': d[k] = '\''; break;
4365 default: d[k] = '\\'; d[k] = ch;
4377 public char * OffsetEscapedString(char * s, int len, int offset)
4381 while(j < len && k < offset && (ch = s[j]))
4386 return (k == offset) ? s + j : null;
4389 public Operand GetOperand(Expression exp)
4392 Type type = exp.expType;
4395 while(type.kind == classType && type._class &&
4396 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4398 if(!type._class.registered.dataType)
4399 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4400 type = type._class.registered.dataType;
4403 if(exp.type == stringExp && op.kind == pointerType)
4405 op.ui64 = (uint64)(uintptr)exp.string;
4406 op.kind = pointerType;
4409 else if(exp.isConstant && exp.type == constantExp)
4411 op.kind = type.kind;
4419 if(exp.constant[0] == '\'')
4421 op.c = exp.constant[1];
4424 else if(type.isSigned)
4426 op.c = (char)strtol(exp.constant, null, 0);
4431 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4437 if(exp.constant[0] == '\'')
4439 op.s = exp.constant[1];
4442 else if(type.isSigned)
4444 op.s = (short)strtol(exp.constant, null, 0);
4449 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4455 if(exp.constant[0] == '\'')
4457 op.i = exp.constant[1];
4460 else if(type.isSigned)
4462 op.i = (int)strtol(exp.constant, null, 0);
4467 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4475 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4480 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4483 op.kind = int64Type;
4488 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4493 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4496 op.kind = int64Type;
4501 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4506 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4509 op.kind = int64Type;
4512 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4513 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4514 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4515 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4517 op.f = (float)strtod(exp.constant, null);
4521 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4522 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4523 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4524 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4526 op.d = (double)strtod(exp.constant, null);
4529 //case classType: For when we have operator overloading...
4530 // Pointer additions
4531 //case functionType:
4535 op.ui64 = _strtoui64(exp.constant, null, 0);
4536 op.kind = pointerType;
4546 static int64 GetEnumValue(Class _class, void * ptr)
4549 switch(_class.typeSize)
4552 if(!strcmp(_class.dataTypeString, "uint64"))
4553 v = (int64)*(uint64 *)ptr;
4555 v = (int64)*(int64 *)ptr;
4558 if(!strcmp(_class.dataTypeString, "uint"))
4559 v = (int64)*(uint *)ptr;
4561 v = (int64)*(int *)ptr;
4564 if(!strcmp(_class.dataTypeString, "uint16"))
4565 v = (int64)*(uint16 *)ptr;
4567 v = (int64)*(short *)ptr;
4570 if(!strcmp(_class.dataTypeString, "byte"))
4571 v = (int64)*(byte *)ptr;
4573 v = (int64)*(char *)ptr;
4579 static __attribute__((unused)) void UnusedFunction()
4582 a.OnGetString(0,0,0);
4585 extern int __ecereVMethodID_class_OnGetString;
4588 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4590 DataMember dataMember;
4591 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4593 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4594 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4598 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4600 void * ptr = inst.data + dataMember.offset + offset;
4601 char * result = null;
4602 exp.loc = member.loc = inst.loc;
4603 ((Identifier)member.identifiers->first).loc = inst.loc;
4605 if(!dataMember.dataType)
4606 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4607 type = dataMember.dataType;
4608 if(type.kind == classType)
4610 Class _class = type._class.registered;
4611 if(_class.type == enumClass)
4613 Class enumClass = eSystem_FindClass(privateModule, "enum");
4616 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4618 for(item = e.values.first; item; item = item.next)
4620 if(item.data == GetEnumValue(_class, ptr))
4628 exp.identifier = MkIdentifier(result);
4629 exp.type = identifierExp;
4630 exp.destType = MkClassType(_class.fullName);
4631 ProcessExpressionType(exp);
4635 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4637 if(!_class.dataType)
4638 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4639 type = _class.dataType;
4648 FreeExpContents(exp);
4650 exp.constant = PrintFloat(*(float*)ptr);
4651 exp.type = constantExp;
4656 FreeExpContents(exp);
4658 exp.constant = PrintDouble(*(double*)ptr);
4659 exp.type = constantExp;
4664 FreeExpContents(exp);
4666 exp.constant = PrintInt(*(int*)ptr);
4667 exp.type = constantExp;
4672 FreeExpContents(exp);
4674 exp.constant = PrintInt64(*(int64*)ptr);
4675 exp.type = constantExp;
4680 FreeExpContents(exp);
4681 // TODO: This should probably use proper type
4682 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4683 exp.type = constantExp;
4688 FreeExpContents(exp);
4689 // TODO: This should probably use proper type
4690 exp.constant = PrintInt64((int64)*(intsize*)ptr);
4691 exp.type = constantExp;
4695 Compiler_Error($"Unhandled type populating instance\n");
4698 ListAdd(memberList, member);
4701 if(parentDataMember.type == unionMember)
4706 void PopulateInstance(Instantiation inst)
4708 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4709 Class _class = classSym.registered;
4710 DataMember dataMember;
4711 OldList * memberList = MkList();
4712 // Added this check and ->Add to prevent memory leaks on bad code
4714 inst.members = MkListOne(MkMembersInitList(memberList));
4716 inst.members->Add(MkMembersInitList(memberList));
4717 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4719 if(!dataMember.isProperty)
4721 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4722 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4726 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4728 void * ptr = inst.data + dataMember.offset;
4729 char * result = null;
4731 exp.loc = member.loc = inst.loc;
4732 ((Identifier)member.identifiers->first).loc = inst.loc;
4734 if(!dataMember.dataType)
4735 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4736 type = dataMember.dataType;
4737 if(type.kind == classType)
4739 Class _class = type._class.registered;
4740 if(_class.type == enumClass)
4742 Class enumClass = eSystem_FindClass(privateModule, "enum");
4745 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4747 for(item = e.values.first; item; item = item.next)
4749 if(item.data == GetEnumValue(_class, ptr))
4758 exp.identifier = MkIdentifier(result);
4759 exp.type = identifierExp;
4760 exp.destType = MkClassType(_class.fullName);
4761 ProcessExpressionType(exp);
4764 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4766 if(!_class.dataType)
4767 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4768 type = _class.dataType;
4777 exp.constant = PrintFloat(*(float*)ptr);
4778 exp.type = constantExp;
4783 exp.constant = PrintDouble(*(double*)ptr);
4784 exp.type = constantExp;
4789 exp.constant = PrintInt(*(int*)ptr);
4790 exp.type = constantExp;
4795 exp.constant = PrintInt64(*(int64*)ptr);
4796 exp.type = constantExp;
4801 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4802 exp.type = constantExp;
4806 Compiler_Error($"Unhandled type populating instance\n");
4809 ListAdd(memberList, member);
4815 void ComputeInstantiation(Expression exp)
4817 Instantiation inst = exp.instance;
4818 MembersInit members;
4819 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4820 Class _class = classSym ? classSym.registered : null;
4821 DataMember curMember = null;
4822 Class curClass = null;
4823 DataMember subMemberStack[256];
4824 int subMemberStackPos = 0;
4827 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4829 // Don't recompute the instantiation...
4830 // Non Simple classes will have become constants by now
4834 if(_class.type == normalClass || _class.type == noHeadClass)
4836 inst.data = (byte *)eInstance_New(_class);
4837 if(_class.type == normalClass)
4838 ((Instance)inst.data)._refCount++;
4841 inst.data = new0 byte[_class.structSize];
4846 for(members = inst.members->first; members; members = members.next)
4848 switch(members.type)
4850 case dataMembersInit:
4852 if(members.dataMembers)
4855 for(member = members.dataMembers->first; member; member = member.next)
4857 Identifier ident = member.identifiers ? member.identifiers->first : null;
4860 Property prop = null;
4861 DataMember dataMember = null;
4862 uint dataMemberOffset;
4866 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4869 if(curMember.isProperty)
4870 prop = (Property)curMember;
4873 dataMember = curMember;
4875 // CHANGED THIS HERE
4876 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4878 // 2013/17/29 -- It seems that this was missing here!
4879 if(_class.type == normalClass)
4880 dataMemberOffset += _class.base.structSize;
4881 // dataMemberOffset = dataMember.offset;
4888 prop = eClass_FindProperty(_class, ident.string, privateModule);
4892 if(prop.memberAccess == publicAccess)
4894 curMember = (DataMember)prop;
4895 curClass = prop._class;
4900 DataMember _subMemberStack[256];
4901 int _subMemberStackPos = 0;
4903 // FILL MEMBER STACK
4904 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4909 if(dataMember.memberAccess == publicAccess)
4911 curMember = dataMember;
4912 curClass = dataMember._class;
4913 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4914 subMemberStackPos = _subMemberStackPos;
4920 if(found && member.initializer && member.initializer.type == expInitializer)
4922 Expression value = member.initializer.exp;
4924 bool deepMember = false;
4927 type = prop.dataType;
4931 if(!dataMember.dataType)
4932 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4934 type = dataMember.dataType;
4937 if(ident && ident.next)
4941 // for(; ident && type; ident = ident.next)
4942 for(ident = ident.next; ident && type; ident = ident.next)
4944 if(type.kind == classType)
4946 prop = eClass_FindProperty(type._class.registered,
4947 ident.string, privateModule);
4949 type = prop.dataType;
4952 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4953 ident.string, &dataMemberOffset, privateModule, null, null);
4955 type = dataMember.dataType;
4958 else if(type.kind == structType || type.kind == unionType)
4961 for(memberType = type.members.first; memberType; memberType = memberType.next)
4963 if(!strcmp(memberType.name, ident.string))
4974 FreeType(value.destType);
4975 value.destType = type;
4976 if(type) type.refCount++;
4977 ComputeExpression(value);
4979 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4981 if(type.kind == classType)
4983 Class _class = type._class.registered;
4984 if(_class && (_class.type == bitClass || _class.type == unitClass || _class.type == enumClass))
4986 if(!_class.dataType)
4987 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4988 type = _class.dataType;
4994 void * ptr = inst.data + dataMemberOffset;
4996 if(value.type == constantExp)
5002 GetInt(value, (int*)ptr);
5007 GetInt64(value, (int64*)ptr);
5012 GetIntPtr(value, (intptr*)ptr);
5017 GetIntSize(value, (intsize*)ptr);
5022 GetFloat(value, (float*)ptr);
5027 GetDouble(value, (double *)ptr);
5032 else if(value.type == instanceExp)
5034 if(type.kind == classType)
5036 Class _class = type._class.registered;
5037 if(_class.type == structClass)
5039 ComputeTypeSize(type);
5040 if(value.instance.data)
5041 memcpy(ptr, value.instance.data, type.size);
5046 else if(prop && prop.Set != (void *)(intptr)1)
5048 if(value.type == instanceExp && value.instance.data)
5050 if(type.kind == classType)
5052 Class _class = type._class.registered;
5053 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5055 void (*Set)(void *, void *) = (void *)prop.Set;
5056 Set(inst.data, value.instance.data);
5057 PopulateInstance(inst);
5061 else if(value.type == constantExp)
5067 void (*Set)(void *, double) = (void *)prop.Set;
5068 Set(inst.data, strtod(value.constant, null) );
5073 void (*Set)(void *, float) = (void *)prop.Set;
5074 Set(inst.data, (float)(strtod(value.constant, null)));
5079 void (*Set)(void *, int) = (void *)prop.Set;
5080 Set(inst.data, (int)strtol(value.constant, null, 0));
5085 void (*Set)(void *, int64) = (void *)prop.Set;
5086 Set(inst.data, _strtoi64(value.constant, null, 0));
5091 void (*Set)(void *, intptr) = (void *)prop.Set;
5092 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5097 void (*Set)(void *, intsize) = (void *)prop.Set;
5098 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5103 else if(value.type == stringExp)
5106 ReadString(temp, value.string);
5107 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5111 else if(!deepMember && type && _class.type == unitClass)
5115 // Only support converting units to units for now...
5116 if(value.type == constantExp)
5118 if(type.kind == classType)
5120 Class _class = type._class.registered;
5121 if(_class.type == unitClass)
5123 if(!_class.dataType)
5124 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5125 type = _class.dataType;
5128 // TODO: Assuming same base type for units...
5134 float (*Set)(float) = (void *)prop.Set;
5135 GetFloat(member.initializer.exp, &fValue);
5136 exp.constant = PrintFloat(Set(fValue));
5137 exp.type = constantExp;
5143 double (*Set)(double) = (void *)prop.Set;
5144 GetDouble(member.initializer.exp, &dValue);
5145 exp.constant = PrintDouble(Set(dValue));
5146 exp.type = constantExp;
5153 else if(!deepMember && type && _class.type == bitClass)
5157 if(value.type == instanceExp && value.instance.data)
5159 unsigned int (*Set)(void *) = (void *)prop.Set;
5160 bits = Set(value.instance.data);
5162 else if(value.type == constantExp)
5168 BitMember bitMember = (BitMember) dataMember;
5171 bits = (bits & ~bitMember.mask);
5172 if(!bitMember.dataType)
5173 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5174 type = bitMember.dataType;
5175 if(type.kind == classType && type._class && type._class.registered)
5177 if(!type._class.registered.dataType)
5178 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5179 type = type._class.registered.dataType;
5184 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5185 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5187 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5188 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5189 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5190 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5192 bits |= part << bitMember.pos;
5198 if(_class && _class.type == unitClass)
5200 ComputeExpression(member.initializer.exp);
5201 exp.constant = member.initializer.exp.constant;
5202 exp.type = constantExp;
5204 member.initializer.exp.constant = null;
5214 if(_class && _class.type == bitClass)
5216 exp.constant = PrintHexUInt(bits);
5217 exp.type = constantExp;
5219 if(exp.type != instanceExp)
5225 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5227 bool result = false;
5231 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5232 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5236 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5237 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5240 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5241 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5242 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5245 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5246 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5247 result = GetOpFloat(op, &op.f);
5250 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5251 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5252 result = GetOpDouble(op, &op.d);
5255 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5256 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5257 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5260 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5261 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5262 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5265 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5266 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5269 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5270 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5276 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5278 if(exp.op.op == SIZEOF)
5280 FreeExpContents(exp);
5281 exp.type = constantExp;
5282 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5293 // Provide default unary +
5294 Expression exp2 = exp.op.exp2;
5296 FreeExpContents(exp);
5297 FreeType(exp.expType);
5298 FreeType(exp.destType);
5304 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5306 // unary arithmetic increment and decrement
5307 //OPERATOR_ALL(UNARY, ++, Inc)
5308 //OPERATOR_ALL(UNARY, --, Dec)
5311 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5313 // unary logical negation
5315 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5321 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5323 if(Promote(op2, op1.kind, op1.type.isSigned))
5324 op2.kind = op1.kind, op2.ops = op1.ops;
5325 else if(Promote(op1, op2.kind, op2.type.isSigned))
5326 op1.kind = op2.kind, op1.ops = op2.ops;
5330 // binary arithmetic
5332 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5335 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5338 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5341 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5344 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5346 // binary arithmetic assignment
5347 //OPERATOR_ALL(BINARY, =, Asign)
5348 //OPERATOR_ALL(BINARY, +=, AddAsign)
5349 //OPERATOR_ALL(BINARY, -=, SubAsign)
5350 //OPERATOR_ALL(BINARY, *=, MulAsign)
5351 //OPERATOR_ALL(BINARY, /=, DivAsign)
5352 //OPERATOR_ALL(BINARY, %=, ModAsign)
5357 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5361 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5364 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5367 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5370 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5372 // binary bitwise assignment
5373 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5374 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5375 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5376 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5377 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5378 // binary logical equality
5380 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5383 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5387 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5390 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5392 // binary logical relational
5394 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5397 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5400 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5403 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5410 void ComputeExpression(Expression exp)
5413 char expString[10240];
5414 expString[0] = '\0';
5415 PrintExpression(exp, expString);
5422 Identifier id = exp.identifier;
5423 if(id && exp.isConstant && !inCompiler && !inPreCompiler && !inDebugger)
5425 Class c = (exp.expType && exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
5426 if(c && c.type == enumClass)
5428 Class enumClass = eSystem_FindClass(privateModule, "enum");
5432 EnumClassData e = ACCESS_CLASSDATA(c, enumClass);
5433 for(value = e.values.first; value; value = value.next)
5435 if(!strcmp(value.name, id.string))
5440 const String dts = c.dataTypeString;
5441 FreeExpContents(exp);
5442 exp.type = constantExp;
5443 exp.constant = (dts && (!strcmp(dts, "int") || !strcmp(dts, "int64") || !strcmp(dts, "short") || !strcmp(dts, "char"))) ? PrintInt64(value.data) : PrintUInt64(value.data);
5452 ComputeInstantiation(exp);
5461 Expression exp1, exp2 = null;
5465 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5468 Expression e = exp.op.exp2;
5470 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5472 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5474 if(e.type == extensionCompoundExp)
5475 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5480 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5482 if(e.type == stringExp && e.string)
5484 char * string = e.string;
5485 int len = strlen(string);
5486 char * tmp = new char[len-2+1];
5487 len = UnescapeString(tmp, string + 1, len - 2);
5489 FreeExpContents(exp);
5490 exp.type = constantExp;
5491 exp.constant = PrintUInt(len + 1);
5495 Type type = e.expType;
5497 FreeExpContents(exp);
5498 exp.type = constantExp;
5499 exp.constant = PrintUInt(ComputeTypeSize(type));
5505 ComputeExpression(exp.op.exp2);
5509 ComputeExpression(exp.op.exp1);
5512 op1 = GetOperand(exp1);
5513 if(op1.type) op1.type.refCount++;
5516 op2 = GetOperand(exp2);
5517 if(op2.type) op2.type.refCount++;
5523 op1 = GetOperand(exp1);
5524 if(op1.type) op1.type.refCount++;
5527 CallOperator(exp, exp1, exp2, op1, op2);
5534 if(exp.op.exp1 && exp.op.exp2)
5539 FreeExpContents(exp);
5540 op1.ops.BitAnd(exp, op1, op2);
5549 FreeExpContents(exp);
5550 op1.ops.Mul(exp, op1, op2);
5559 FreeExpContents(exp);
5560 op1.ops.Add(exp, op1, op2);
5565 // Provide default unary +
5566 Expression exp2 = exp.op.exp2;
5568 FreeExpContents(exp);
5569 FreeType(exp.expType);
5570 FreeType(exp.destType);
5581 FreeExpContents(exp);
5582 op1.ops.Sub(exp, op1, op2);
5589 FreeExpContents(exp);
5590 op1.ops.Neg(exp, op1);
5597 FreeExpContents(exp);
5598 op1.ops.BitNot(exp, op1);
5604 FreeExpContents(exp);
5605 op1.ops.Not(exp, op1);
5608 // Binary only operators
5612 FreeExpContents(exp);
5613 op1.ops.Div(exp, op1, op2);
5619 FreeExpContents(exp);
5620 op1.ops.Mod(exp, op1, op2);
5632 FreeExpContents(exp);
5633 op1.ops.Sma(exp, op1, op2);
5642 FreeExpContents(exp);
5643 op1.ops.Grt(exp, op1, op2);
5652 FreeExpContents(exp);
5653 op1.ops.SmaEqu(exp, op1, op2);
5662 FreeExpContents(exp);
5663 op1.ops.GrtEqu(exp, op1, op2);
5672 FreeExpContents(exp);
5673 op1.ops.Equ(exp, op1, op2);
5682 FreeExpContents(exp);
5683 op1.ops.Nqu(exp, op1, op2);
5690 FreeExpContents(exp);
5691 op1.ops.BitOr(exp, op1, op2);
5697 FreeExpContents(exp);
5698 op1.ops.BitXor(exp, op1, op2);
5706 FreeExpContents(exp);
5707 exp.type = constantExp;
5708 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5712 if(op1.type) FreeType(op1.type);
5713 if(op2.type) FreeType(op2.type);
5717 case extensionExpressionExp:
5720 for(e = exp.list->first; e; e = n)
5725 OldList * list = exp.list;
5726 Expression prev = exp.prev;
5727 Expression next = exp.next;
5729 // For operations which set the exp type on brackets exp after the inner exp was processed...
5730 if(exp.expType && exp.expType.kind == classType && (!e.expType || e.expType.kind != classType))
5732 FreeType(e.expType);
5733 e.expType = exp.expType;
5734 e.expType.refCount++;
5736 ComputeExpression(e);
5737 //FreeExpContents(exp);
5738 FreeType(exp.expType);
5739 FreeType(exp.destType);
5758 exp.isConstant = true;
5760 ComputeExpression(exp.index.exp);
5761 if(!exp.index.exp.isConstant)
5762 exp.isConstant = false;
5764 for(e = exp.index.index->first; e; e = e.next)
5766 ComputeExpression(e);
5769 // Check if this type is int
5772 exp.isConstant = false;
5774 exp.expType = Dereference(exp.index.exp.expType);
5780 Expression memberExp = exp.member.exp;
5781 Identifier memberID = exp.member.member;
5784 ComputeExpression(exp.member.exp);
5785 type = exp.member.exp.expType;
5788 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);
5789 Property prop = null;
5790 DataMember member = null;
5791 Class convertTo = null;
5792 if(type.kind == subClassType && exp.member.exp.type == classExp)
5793 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5800 PrintTypeNoConst(type, string, false, true);
5801 classSym = FindClass(string);
5802 _class = classSym ? classSym.registered : null;
5805 if(exp.member.member)
5807 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5809 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5811 if(!prop && !member && _class && exp.member.member)
5813 Symbol classSym = FindClass(exp.member.member.string);
5815 _class = classSym ? classSym.registered : null;
5816 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5823 Type type = prop.dataType;
5824 // TODO: Assuming same base type for units...
5825 if(_class.type == unitClass)
5827 if(type.kind == classType)
5829 Class _class = type._class.registered;
5830 if(_class.type == unitClass)
5832 if(!_class.dataType)
5833 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5834 type = _class.dataType;
5842 float (*Get)(float) = (void *)prop.Get;
5843 GetFloat(exp.member.exp, &value);
5844 exp.constant = PrintFloat(Get ? Get(value) : value);
5845 exp.type = constantExp;
5851 double (*Get)(double);
5852 GetDouble(exp.member.exp, &value);
5855 Get = (void *)prop.Set;
5857 Get = (void *)prop.Get;
5858 exp.constant = PrintDouble(Get ? Get(value) : value);
5859 exp.type = constantExp;
5868 Expression value = exp.member.exp;
5871 ProcessPropertyType(prop);
5873 type = prop.dataType;
5876 // printf("Investigate this\n");
5878 else if(_class.type == structClass)
5884 Class propertyClass = type._class.registered;
5885 if(propertyClass.type == structClass && value.type == instanceExp)
5887 void (*Set)(void *, void *) = (void *)prop.Set;
5888 exp.instance = Instantiation { };
5889 exp.instance.data = new0 byte[_class.structSize];
5890 exp.instance._class = MkSpecifierName(_class.fullName);
5891 exp.instance.loc = exp.loc;
5892 exp.type = instanceExp;
5893 Set(exp.instance.data, value.instance.data);
5894 PopulateInstance(exp.instance);
5901 void (*Set)(void *, int) = (void *)prop.Set;
5903 exp.instance = Instantiation { };
5904 exp.instance.data = new0 byte[_class.structSize];
5905 exp.instance._class = MkSpecifierName(_class.fullName);
5906 exp.instance.loc = exp.loc;
5907 exp.type = instanceExp;
5909 GetInt(value, &intValue);
5911 Set(exp.instance.data, intValue);
5912 PopulateInstance(exp.instance);
5918 void (*Set)(void *, int64) = (void *)prop.Set;
5920 exp.instance = Instantiation { };
5921 exp.instance.data = new0 byte[_class.structSize];
5922 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5923 exp.instance.loc = exp.loc;
5924 exp.type = instanceExp;
5926 GetInt64(value, &intValue);
5928 Set(exp.instance.data, intValue);
5929 PopulateInstance(exp.instance);
5936 void (*Set)(void *, intptr) = (void *)prop.Set;
5938 exp.instance = Instantiation { };
5939 exp.instance.data = new0 byte[_class.structSize];
5940 exp.instance._class = MkSpecifierName(_class.fullName);
5941 exp.instance.loc = exp.loc;
5942 exp.type = instanceExp;
5944 GetIntPtr(value, &intValue);
5946 Set(exp.instance.data, intValue);
5947 PopulateInstance(exp.instance);
5954 void (*Set)(void *, intsize) = (void *)prop.Set;
5956 exp.instance = Instantiation { };
5957 exp.instance.data = new0 byte[_class.structSize];
5958 exp.instance._class = MkSpecifierName(_class.fullName);
5959 exp.instance.loc = exp.loc;
5960 exp.type = instanceExp;
5962 GetIntSize(value, &intValue);
5964 Set(exp.instance.data, intValue);
5965 PopulateInstance(exp.instance);
5971 void (*Set)(void *, float) = (void *)prop.Set;
5973 exp.instance = Instantiation { };
5974 exp.instance.data = new0 byte[_class.structSize];
5975 exp.instance._class = MkSpecifierName(_class.fullName);
5976 exp.instance.loc = exp.loc;
5977 exp.type = instanceExp;
5979 GetFloat(value, &floatValue);
5981 Set(exp.instance.data, floatValue);
5982 PopulateInstance(exp.instance);
5988 void (*Set)(void *, double) = (void *)prop.Set;
5990 exp.instance = Instantiation { };
5991 exp.instance.data = new0 byte[_class.structSize];
5992 exp.instance._class = MkSpecifierName(_class.fullName);
5993 exp.instance.loc = exp.loc;
5994 exp.type = instanceExp;
5996 GetDouble(value, &doubleValue);
5998 Set(exp.instance.data, doubleValue);
5999 PopulateInstance(exp.instance);
6004 else if(_class.type == bitClass)
6010 Class propertyClass = type._class.registered;
6011 if(propertyClass.type == structClass && value.instance.data)
6013 unsigned int (*Set)(void *) = (void *)prop.Set;
6014 unsigned int bits = Set(value.instance.data);
6015 exp.constant = PrintHexUInt(bits);
6016 exp.type = constantExp;
6019 else if(_class.type == bitClass)
6022 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6025 GetUInt(exp.member.exp, &value);
6027 exp.constant = PrintHexUInt(bits);
6028 exp.type = constantExp;
6036 if(_class.type == bitClass)
6039 GetUInt(exp.member.exp, &value);
6045 Class _class = type._class.registered;
6046 if(_class.type == structClass)
6048 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6050 exp.instance = Instantiation { };
6051 exp.instance.data = new0 byte[_class.structSize];
6052 exp.instance._class = MkSpecifierName(_class.fullName);
6053 exp.instance.loc = exp.loc;
6054 //exp.instance.fullSet = true;
6055 exp.type = instanceExp;
6056 Get(value, exp.instance.data);
6057 PopulateInstance(exp.instance);
6059 else if(_class.type == bitClass)
6061 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6062 uint64 bits = Get(value);
6063 exp.constant = PrintHexUInt64(bits);
6064 exp.type = constantExp;
6070 else if(_class.type == structClass)
6072 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6077 Class _class = type._class.registered;
6078 if(_class.type == structClass && value)
6080 void (*Get)(void *, void *) = (void *)prop.Get;
6082 exp.instance = Instantiation { };
6083 exp.instance.data = new0 byte[_class.structSize];
6084 exp.instance._class = MkSpecifierName(_class.fullName);
6085 exp.instance.loc = exp.loc;
6086 //exp.instance.fullSet = true;
6087 exp.type = instanceExp;
6088 Get(value, exp.instance.data);
6089 PopulateInstance(exp.instance);
6097 char * value = exp.member.exp.instance.data;
6102 Class _class = type._class.registered;
6103 if(_class.type == normalClass)
6105 void *(*Get)(void *) = (void *)prop.Get;
6107 exp.instance = Instantiation { };
6108 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6109 exp.type = instanceExp;
6110 exp.instance.data = Get(value, exp.instance.data);
6122 exp.isConstant = false;
6130 if(exp.type != ExpressionType::memberExp)
6132 FreeExpression(memberExp);
6133 FreeIdentifier(memberID);
6139 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6140 FreeExpContents(exp);
6141 exp.constant = PrintUInt(ComputeTypeSize(type));
6142 exp.type = constantExp;
6148 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6149 if(classSym && classSym.registered)
6151 if(classSym.registered.fixed)
6153 FreeSpecifier(exp._class);
6154 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6155 exp.type = constantExp;
6159 char className[1024];
6160 strcpy(className, "__ecereClass_");
6161 FullClassNameCat(className, classSym.string, true);
6163 DeclareClass(curExternal, classSym, className);
6165 FreeExpContents(exp);
6166 exp.type = pointerExp;
6167 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6168 exp.member.member = MkIdentifier("structSize");
6178 if(exp.type == castExp)
6181 ComputeExpression(exp.cast.exp);
6184 if(e && exp.expType)
6187 type = exp.destType;
6190 if(type.kind == classType)
6192 Class _class = type._class.registered;
6193 if(_class && (_class.type == unitClass || _class.type == bitClass))
6195 if(!_class.dataType)
6196 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6197 type = _class.dataType;
6208 if(GetChar(e, &value))
6210 FreeExpContents(exp);
6211 exp.constant = PrintChar(value);
6212 exp.type = constantExp;
6217 unsigned char value = 0;
6218 if(GetUChar(e, &value))
6220 FreeExpContents(exp);
6221 exp.constant = PrintUChar(value);
6222 exp.type = constantExp;
6230 if(GetShort(e, &value))
6232 FreeExpContents(exp);
6233 exp.constant = PrintShort(value);
6234 exp.type = constantExp;
6239 unsigned short value = 0;
6240 if(GetUShort(e, &value))
6242 FreeExpContents(exp);
6243 exp.constant = PrintUShort(value);
6244 exp.type = constantExp;
6252 if(GetInt(e, &value))
6254 FreeExpContents(exp);
6255 exp.constant = PrintInt(value);
6256 exp.type = constantExp;
6261 unsigned int value = 0;
6262 if(GetUInt(e, &value))
6264 FreeExpContents(exp);
6265 exp.constant = PrintUInt(value);
6266 exp.type = constantExp;
6274 if(GetInt64(e, &value))
6276 FreeExpContents(exp);
6277 exp.constant = PrintInt64(value);
6278 exp.type = constantExp;
6284 if(GetUInt64(e, &value))
6286 FreeExpContents(exp);
6287 exp.constant = PrintUInt64(value);
6288 exp.type = constantExp;
6296 if(GetIntPtr(e, &value))
6298 FreeExpContents(exp);
6299 exp.constant = PrintInt64((int64)value);
6300 exp.type = constantExp;
6306 if(GetUIntPtr(e, &value))
6308 FreeExpContents(exp);
6309 exp.constant = PrintUInt64((uint64)value);
6310 exp.type = constantExp;
6318 if(GetIntSize(e, &value))
6320 FreeExpContents(exp);
6321 exp.constant = PrintInt64((int64)value);
6322 exp.type = constantExp;
6328 if(GetUIntSize(e, &value))
6330 FreeExpContents(exp);
6331 exp.constant = PrintUInt64((uint64)value);
6332 exp.type = constantExp;
6339 if(GetFloat(e, &value))
6341 FreeExpContents(exp);
6342 exp.constant = PrintFloat(value);
6343 exp.type = constantExp;
6350 if(GetDouble(e, &value))
6352 FreeExpContents(exp);
6353 exp.constant = PrintDouble(value);
6354 exp.type = constantExp;
6369 // Caring only about last expression for now...
6370 ComputeExpression(exp.cond.exp->last);
6371 if(exp.cond.elseExp)
6372 ComputeExpression(exp.cond.elseExp);
6374 ComputeExpression(exp.cond.cond);
6376 op1 = GetOperand(exp.cond.cond);
6377 if(op1.type) op1.type.refCount++;
6378 op2 = GetOperand(exp.cond.exp->last);
6379 if(op2.type) op2.type.refCount++;
6380 op3 = GetOperand(exp.cond.elseExp);
6381 if(op3.type) op3.type.refCount++;
6383 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6384 if(op1.type) FreeType(op1.type);
6385 if(op2.type) FreeType(op2.type);
6386 if(op3.type) FreeType(op3.type);
6392 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6397 OldList converts { };
6400 if(destType.kind == voidType)
6403 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6407 // for(convert = converts.last; convert; convert = convert.prev)
6408 for(convert = converts.first; convert; convert = convert.next)
6410 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6413 Expression newExp { };
6414 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6416 // TODO: Check this...
6420 newExp.destType = null;
6425 exp.type = memberExp;
6426 exp.addedThis = true;
6427 exp.member.exp = newExp;
6428 FreeType(exp.member.exp.expType);
6430 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6431 exp.member.exp.expType.classObjectType = objectType;
6432 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6433 exp.member.memberType = propertyMember;
6434 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6435 // TESTING THIS... for (int)degrees
6436 exp.needCast = true;
6437 if(exp.expType) exp.expType.refCount++;
6438 ApplyAnyObjectLogic(exp.member.exp);
6443 /*if(exp.isConstant)
6445 // Color { ColorRGB = [exp] };
6446 exp.type = instanceExp;
6447 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6448 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6449 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6453 // If not constant, don't turn it yet into an instantiation
6454 // (Go through the deep members system first)
6455 exp.type = memberExp;
6456 exp.addedThis = true;
6457 exp.member.exp = newExp;
6459 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6460 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6461 newExp.expType._class.registered.type == noHeadClass)
6463 newExp.byReference = true;
6466 FreeType(exp.member.exp.expType);
6467 /*exp.member.exp.expType = convert.convert.dataType;
6468 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6469 exp.member.exp.expType = null;
6470 if(convert.convert.dataType)
6472 exp.member.exp.expType = { };
6473 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6474 exp.member.exp.expType.refCount = 1;
6475 exp.member.exp.expType.classObjectType = objectType;
6476 ApplyAnyObjectLogic(exp.member.exp);
6479 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6480 exp.member.memberType = reverseConversionMember;
6481 exp.expType = convert.resultType ? convert.resultType :
6482 MkClassType(convert.convert._class.fullName);
6483 exp.needCast = true;
6484 if(convert.resultType) convert.resultType.refCount++;
6490 FreeType(exp.expType);
6493 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6494 if(exp.destType.casted)
6495 exp.needCast = true;
6496 if(exp.expType) exp.expType.refCount++;
6500 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6501 if(exp.destType.casted)
6502 exp.needCast = true;
6503 if(convert.resultType)
6504 convert.resultType.refCount++;
6508 if(exp.isConstant && inCompiler)
6509 ComputeExpression(exp);
6511 converts.Free(FreeConvert);
6514 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6516 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6518 if(!result && exp.expType && exp.destType)
6520 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6521 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6522 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6523 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6527 // if(result) CheckTemplateTypes(exp);
6531 void CheckTemplateTypes(Expression exp)
6534 bool et = exp.expType ? exp.expType.passAsTemplate : false;
6535 bool dt = exp.destType ? exp.destType.passAsTemplate : false;
6537 Expression nbExp = GetNonBracketsExp(exp);
6538 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6539 (nbExp == exp || nbExp.type != castExp))
6541 Expression newExp { };
6543 TypeKind kind = exp.expType.kind;
6545 if(exp.destType) exp.destType.refCount++;
6546 if(exp.expType) exp.expType.refCount++;
6550 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6552 Class c = exp.expType._class.registered;
6553 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6556 c.dataType = ProcessTypeString(c.dataTypeString, false);
6557 kind = c.dataType.kind;
6564 if(exp.destType.classObjectType)
6566 // We need to pass the address, just pass it along (Undo what was done above)
6567 if(exp.destType) exp.destType.refCount--;
6568 if(exp.expType) exp.expType.refCount--;
6573 // If we're looking for value:
6574 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6576 OldList * unionDefs = MkList();
6577 OldList * statements = MkList();
6578 context = PushContext();
6579 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6580 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6581 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6582 exp.type = extensionCompoundExp;
6583 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6584 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6585 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6586 exp.compound.compound.context = context;
6587 PopContext(context);
6592 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6593 if((exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass) || exp.expType.isPointerType)
6594 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
6596 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6597 exp.needCast = true;
6601 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6603 Expression newExp { };
6605 TypeKind kind = exp.expType.kind;
6607 if(exp.destType) exp.destType.refCount++;
6608 if(exp.expType) exp.expType.refCount++;
6612 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6614 Class c = exp.expType._class.registered;
6615 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6618 c.dataType = ProcessTypeString(c.dataTypeString, false);
6619 kind = c.dataType.kind;
6626 if(exp.destType.classObjectType)
6628 // We need to pass the address, just pass it along (Undo what was done above)
6629 if(exp.destType) exp.destType.refCount--;
6630 if(exp.expType) exp.expType.refCount--;
6635 // If we're looking for value:
6636 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6638 OldList * unionDefs = MkList();
6639 OldList * statements = MkList();
6640 context = PushContext();
6641 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6642 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6643 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6644 exp.type = extensionCompoundExp;
6645 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6646 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6647 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6648 exp.compound.compound.context = context;
6649 PopContext(context);
6654 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6656 exp.type = bracketsExp;
6658 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6659 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6660 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6661 ProcessExpressionType(exp.list->first);
6666 exp.type = bracketsExp;
6667 if(exp.expType.isPointerType)
6669 exp.needTemplateCast = 2;
6670 newExp.needCast = true;
6671 newExp.needTemplateCast = 2;
6672 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6675 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6676 exp.needTemplateCast = 2;
6677 newExp.needCast = true;
6678 newExp.needTemplateCast = 2;
6679 ProcessExpressionType(exp.list->first);
6685 if(exp.expType.kind == templateType)
6687 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6690 FreeType(exp.destType);
6691 FreeType(exp.expType);
6696 /*if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6698 // When was this required? Removed to address using templated values to pass to printf()
6702 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6703 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6707 char typeString[1024];
6709 OldList * specs = MkList();
6710 typeString[0] = '\0';
6711 PrintType(exp.expType, typeString, false, false);
6712 decl = SpecDeclFromString(typeString, specs, null);
6715 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6716 exp.cast.typeName = MkTypeName(specs, decl);
6717 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6718 exp.cast.exp.needCast = true;
6719 exp.needTemplateCast = 2;
6720 newExp.needTemplateCast = 2;
6727 // TODO: The Symbol tree should be reorganized by namespaces
6729 // - Tree of all symbols within (stored without namespace)
6730 // - Tree of sub-namespaces
6732 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6734 int nsLen = strlen(nameSpace);
6736 // Start at the name space prefix
6737 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6739 char * s = symbol.string;
6740 if(!strncmp(s, nameSpace, nsLen))
6742 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6745 for(c = strlen(s)-1; c >= 0; c--)
6750 if(!strcmp(namePart, name))
6752 // TODO: Error on ambiguity
6762 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6765 char nameSpace[1024];
6766 const char * namePart;
6767 bool gotColon = false;
6769 nameSpace[0] = '\0';
6770 for(c = strlen(name)-1; c >= 0; c--)
6777 namePart = name+c+1;
6778 while(c >= 0 && name[c] == ':') c--;
6781 // Try an exact match first
6782 Symbol symbol = (Symbol)tree.FindString(name);
6786 // Namespace specified
6787 memcpy(nameSpace, name, c + 1);
6790 return ScanWithNameSpace(tree, nameSpace, namePart);
6794 // Looking for a global symbol, e.g. ::Sleep()
6795 Symbol symbol = (Symbol)tree.FindString(namePart);
6800 // Name only (no namespace specified)
6801 Symbol symbol = (Symbol)tree.FindString(namePart);
6804 return ScanWithNameSpace(tree, "", namePart);
6809 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6812 //Time startTime = GetTime();
6814 // Optimize this later? Do this before/less?
6816 Symbol symbol = null;
6818 // First, check if the identifier is declared inside the function
6819 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6821 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6823 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6829 strcpy(curName, thisNameSpace);
6830 strcat(curName, "::");
6831 strcat(curName, name);
6832 // Try to resolve in current namespace first
6833 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6836 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6839 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6841 if(symbol || ctx == endContext) break;
6843 if(inCompiler && symbol && ctx == globalContext && symbol.pointerExternal && curExternal && symbol.pointerExternal != curExternal)
6844 curExternal.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
6846 //findSymbolTotalTime += GetTime() - startTime;
6851 static void GetTypeSpecs(Type type, OldList * specs)
6853 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6858 if(type._class.registered)
6860 if(!type._class.registered.dataType)
6861 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6862 GetTypeSpecs(type._class.registered.dataType, specs);
6866 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6867 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6868 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6869 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6870 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6871 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6872 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6873 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6876 ListAdd(specs, MkSpecifier(INT)); break;
6880 static void PrintArraySize(Type arrayType, char * string)
6885 if(arrayType.enumClass)
6886 strcat(size, arrayType.enumClass.string);
6887 else if(arrayType.arraySizeExp)
6888 PrintExpression(arrayType.arraySizeExp, size);
6890 strcat(string, size);
6893 // WARNING : This function expects a null terminated string since it recursively concatenate...
6894 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6898 if(printConst && type.constant)
6899 strcat(string, "const ");
6904 Symbol c = type._class;
6905 bool isObjectBaseClass = !c || !c.string || !strcmp(c.string, "class");
6906 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6907 // look into merging with thisclass ?
6908 if(type.classObjectType == typedObject && isObjectBaseClass)
6909 strcat(string, "typed_object");
6910 else if(type.classObjectType == anyObject && isObjectBaseClass)
6911 strcat(string, "any_object");
6915 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6917 if(type.byReference)
6918 strcat(string, " &");
6921 case voidType: strcat(string, "void"); break;
6922 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6923 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6924 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6925 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6926 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6927 case _BoolType: strcat(string, "_Bool"); break;
6928 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6929 case floatType: strcat(string, "float"); break;
6930 case doubleType: strcat(string, "double"); break;
6934 strcat(string, "struct ");
6935 strcat(string, type.enumName);
6937 else if(type.typeName)
6938 strcat(string, type.typeName);
6942 strcat(string, "struct { ");
6943 for(member = type.members.first; member; member = member.next)
6945 PrintType(member, string, true, fullName);
6946 strcat(string,"; ");
6954 strcat(string, "union ");
6955 strcat(string, type.enumName);
6957 else if(type.typeName)
6958 strcat(string, type.typeName);
6961 strcat(string, "union ");
6962 strcat(string,"(unnamed)");
6968 strcat(string, "enum ");
6969 strcat(string, type.enumName);
6971 else if(type.typeName)
6972 strcat(string, type.typeName);
6974 strcat(string, "int"); // "enum");
6977 strcat(string, "...");
6980 strcat(string, "subclass(");
6981 strcat(string, type._class ? type._class.string : "int");
6982 strcat(string, ")");
6985 strcat(string, type.templateParameter.identifier.string);
6988 strcat(string, "thisclass");
6991 strcat(string, "__builtin_va_list");
6997 static void PrintName(Type type, char * string, bool fullName)
6999 if(type.name && type.name[0])
7002 strcat(string, type.name);
7005 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7006 if(name) name += 2; else name = type.name;
7007 strcat(string, name);
7012 static void PrintAttribs(Type type, char * string)
7016 if(type.dllExport) strcat(string, "dllexport ");
7017 if(type.attrStdcall) strcat(string, "stdcall ");
7021 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7023 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7025 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7026 PrintAttribs(type, string);
7027 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7028 strcat(string, " const");
7029 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7030 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7031 strcat(string, " (");
7032 if(type.kind == pointerType)
7034 if(type.type.kind == functionType || type.type.kind == methodType)
7035 PrintAttribs(type.type, string);
7037 if(type.kind == pointerType)
7039 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7040 strcat(string, "*");
7042 strcat(string, " *");
7044 if(printConst && type.constant && type.kind == pointerType)
7045 strcat(string, " const");
7048 PrintTypeSpecs(type, string, fullName, printConst);
7051 static void PostPrintType(Type type, char * string, bool fullName)
7053 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7054 strcat(string, ")");
7055 if(type.kind == arrayType)
7056 PrintArraySize(type, string);
7057 else if(type.kind == functionType)
7060 strcat(string, "(");
7061 for(param = type.params.first; param; param = param.next)
7063 PrintType(param, string, true, fullName);
7064 if(param.next) strcat(string, ", ");
7066 strcat(string, ")");
7068 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7069 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7073 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7075 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7077 PrePrintType(type, string, fullName, null, printConst);
7079 if(type.thisClass || (printName && type.name && type.name[0]))
7080 strcat(string, " ");
7081 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7083 Symbol _class = type.thisClass;
7084 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7086 if(type.classObjectType == classPointer)
7087 strcat(string, "class");
7089 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7091 else if(_class && _class.string)
7093 String s = _class.string;
7098 char * name = RSearchString(s, "::", strlen(s), true, false);
7099 if(name) name += 2; else name = s;
7100 strcat(string, name);
7103 strcat(string, "::");
7106 if(printName && type.name)
7107 PrintName(type, string, fullName);
7108 PostPrintType(type, string, fullName);
7109 if(type.bitFieldCount)
7112 sprintf(count, ":%d", type.bitFieldCount);
7113 strcat(string, count);
7117 void PrintType(Type type, char * string, bool printName, bool fullName)
7119 _PrintType(type, string, printName, fullName, true);
7122 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7124 _PrintType(type, string, printName, fullName, false);
7127 static Type FindMember(Type type, char * string)
7130 for(memberType = type.members.first; memberType; memberType = memberType.next)
7132 if(!memberType.name)
7134 Type subType = FindMember(memberType, string);
7138 else if(!strcmp(memberType.name, string))
7144 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7147 for(memberType = type.members.first; memberType; memberType = memberType.next)
7149 if(!memberType.name)
7151 Type subType = FindMember(memberType, string);
7154 *offset += memberType.offset;
7158 else if(!strcmp(memberType.name, string))
7160 *offset += memberType.offset;
7167 public bool GetParseError() { return parseError; }
7169 Expression ParseExpressionString(char * expression)
7173 fileInput = TempFile { };
7174 fileInput.Write(expression, 1, strlen(expression));
7175 fileInput.Seek(0, start);
7178 parsedExpression = null;
7180 expression_yyparse();
7183 return parsedExpression;
7186 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7188 Identifier id = exp.identifier;
7189 Method method = null;
7190 Property prop = null;
7191 DataMember member = null;
7192 ClassProperty classProp = null;
7194 if(_class && _class.type == enumClass)
7196 NamedLink64 value = null;
7197 Class enumClass = eSystem_FindClass(privateModule, "enum");
7201 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7203 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7204 for(value = e.values.first; value; value = value.next)
7206 if(!strcmp(value.name, id.string))
7211 exp.isConstant = true;
7212 if(inCompiler || inPreCompiler || inDebugger)
7215 FreeExpContents(exp);
7217 exp.type = constantExp;
7218 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7219 sprintf(constant, FORMAT64D, value.data);
7221 sprintf(constant, FORMAT64HEX, value.data);
7222 exp.constant = CopyString(constant);
7224 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7225 exp.expType = MkClassType(baseClass.fullName);
7233 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7235 ProcessMethodType(method);
7242 // TOCHECK: Put it back to what it was...
7243 // methodClass = _class;
7244 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7249 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7252 ProcessPropertyType(prop);
7253 exp.expType = prop.dataType;
7254 if(prop.dataType) prop.dataType.refCount++;
7257 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7259 if(!member.dataType)
7260 member.dataType = ProcessTypeString(member.dataTypeString, false);
7261 exp.expType = member.dataType;
7262 if(member.dataType) member.dataType.refCount++;
7265 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7267 if(!classProp.dataType)
7268 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7270 if(classProp.constant)
7272 FreeExpContents(exp);
7274 exp.isConstant = true;
7275 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7277 //char constant[256];
7278 exp.type = stringExp;
7279 exp.constant = QMkString((char *)(uintptr)classProp.Get(_class));
7284 exp.type = constantExp;
7285 sprintf(constant, "%d", (int)classProp.Get(_class));
7286 exp.constant = CopyString(constant);
7294 exp.expType = classProp.dataType;
7295 if(classProp.dataType) classProp.dataType.refCount++;
7301 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7303 BinaryTree * tree = &nameSpace.functions;
7304 GlobalData data = (GlobalData)tree->FindString(name);
7308 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7310 data = ScanGlobalData(child, name);
7318 static GlobalData FindGlobalData(char * name)
7321 NameSpace * nameSpace;
7322 nameSpace = globalData;
7323 for(c = 0; name[c]; c++)
7325 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7327 NameSpace * newSpace;
7328 char * spaceName = new char[c - start + 1];
7329 strncpy(spaceName, name + start, c - start);
7330 spaceName[c-start] = '\0';
7331 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7335 nameSpace = newSpace;
7336 if(name[c] == ':') c++;
7342 return ScanGlobalData(nameSpace, name + start);
7347 static int definedExpStackPos;
7348 static void * definedExpStack[512];
7350 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7351 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7353 Expression prev = checkedExp.prev, next = checkedExp.next;
7355 FreeExpContents(checkedExp);
7356 FreeType(checkedExp.expType);
7357 FreeType(checkedExp.destType);
7359 *checkedExp = *newExp;
7363 checkedExp.prev = prev;
7364 checkedExp.next = next;
7367 void ApplyAnyObjectLogic(Expression e)
7369 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7371 char debugExpString[4096];
7372 debugExpString[0] = '\0';
7373 PrintExpression(e, debugExpString);
7376 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7378 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7379 //ellipsisDestType = destType;
7382 Type type = e.expType;
7383 Class _class = null;
7384 //Type destType = e.destType;
7386 if(type.kind == classType && type._class && type._class.registered)
7388 _class = type._class.registered;
7390 else if(type.kind == subClassType)
7392 _class = FindClass("ecere::com::Class").registered;
7396 char string[1024] = "";
7399 PrintTypeNoConst(type, string, false, true);
7400 classSym = FindClass(string);
7401 if(classSym) _class = classSym.registered;
7404 if((_class && (_class.type == enumClass || _class.type == unitClass || _class.type == bitClass || _class.type == systemClass) && strcmp(_class.fullName, "class") && strcmp(_class.fullName, "uintptr") && strcmp(_class.fullName, "intptr")) || // Patched so that class isn't considered SYSTEM...
7405 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != intPtrType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
7406 destType.byReference)))
7408 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7410 Expression checkedExp = e, newExp;
7412 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7414 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7416 if(checkedExp.type == extensionCompoundExp)
7418 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7421 checkedExp = checkedExp.list->last;
7423 else if(checkedExp.type == castExp)
7424 checkedExp = checkedExp.cast.exp;
7427 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7429 newExp = checkedExp.op.exp2;
7430 checkedExp.op.exp2 = null;
7431 FreeExpContents(checkedExp);
7433 if(e.expType && e.expType.passAsTemplate)
7436 ComputeTypeSize(e.expType);
7437 sprintf(size, "%d", e.expType.size); // Potential 32/64 Bootstrap issue
7438 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7439 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7440 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7443 ReplaceExpContents(checkedExp, newExp);
7444 e.byReference = true;
7446 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7448 Expression checkedExp; //, newExp;
7451 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7453 e.type == identifierExp ||
7454 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7455 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7456 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7459 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7461 Context context = PushContext();
7463 OldList * specs = MkList();
7464 char typeString[1024];
7465 Expression newExp { };
7467 typeString[0] = '\0';
7470 //if(e.destType) e.destType.refCount++;
7471 // if(exp.expType) exp.expType.refCount++;
7474 newExp.expType = null;
7476 PrintTypeNoConst(e.expType, typeString, false, true);
7477 decl = SpecDeclFromString(typeString, specs, null);
7478 newExp.destType = ProcessType(specs, decl);
7480 curContext = context;
7482 // We need a current compound for this
7486 OldList * stmts = MkList();
7487 e.type = extensionCompoundExp;
7488 sprintf(name, "__internalValue%03X", internalValueCounter++);
7489 if(!curCompound.compound.declarations)
7490 curCompound.compound.declarations = MkList();
7491 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7492 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7493 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7494 e.compound = MkCompoundStmt(null, stmts);
7497 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7500 e.compound = MkCompoundStmt(
7501 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7502 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7504 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7508 Type type = e.destType;
7510 CopyTypeInto(e.destType, type);
7511 e.destType.refCount = 1;
7512 e.destType.classObjectType = none;
7516 e.compound.compound.context = context;
7517 PopContext(context);
7518 curContext = context.parent;
7522 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7524 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7526 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7528 if(checkedExp.type == extensionCompoundExp)
7530 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7533 checkedExp = checkedExp.list->last;
7535 else if(checkedExp.type == castExp)
7536 checkedExp = checkedExp.cast.exp;
7539 Expression operand { };
7540 operand = *checkedExp;
7542 checkedExp.destType = ProcessTypeString("void *", false);
7543 checkedExp.expType = checkedExp.destType;
7544 checkedExp.destType.refCount++;
7546 checkedExp.type = opExp;
7547 checkedExp.op.op = '&';
7548 checkedExp.op.exp1 = null;
7549 checkedExp.op.exp2 = operand;
7551 //newExp = MkExpOp(null, '&', checkedExp);
7553 //ReplaceExpContents(checkedExp, newExp);
7560 // If expression type is a simple class, make it an address
7561 // FixReference(e, true);
7564 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7565 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7566 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7568 if(e.expType.classObjectType && destType && destType.classObjectType) //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
7570 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7574 Expression thisExp { };
7577 thisExp.prev = null;
7578 thisExp.next = null;
7581 e.type = bracketsExp;
7582 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7583 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7584 ((Expression)e.list->first).byReference = true;
7586 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7588 e.expType = thisExp.expType;
7589 e.expType.refCount++;
7594 CopyTypeInto(e.expType, thisExp.expType);
7595 e.expType.byReference = false;
7596 e.expType.refCount = 1;
7598 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7599 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7601 e.expType.classObjectType = none;
7606 // TOFIX: Try this for a nice IDE crash!
7608 // The other way around
7611 if(destType && e.expType &&
7612 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7613 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7614 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7616 if(destType.kind == ellipsisType)
7618 Compiler_Error($"Unspecified type\n");
7620 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7622 bool byReference = e.expType.byReference;
7623 Expression thisExp { };
7625 OldList * specs = MkList();
7626 char typeString[1024]; // Watch buffer overruns
7628 ClassObjectType backupClassObjectType;
7629 bool backupByReference;
7631 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7636 backupClassObjectType = type.classObjectType;
7637 backupByReference = type.byReference;
7639 type.classObjectType = none;
7640 type.byReference = false;
7642 typeString[0] = '\0';
7643 PrintType(type, typeString, false, true);
7644 decl = SpecDeclFromString(typeString, specs, null);
7646 type.classObjectType = backupClassObjectType;
7647 type.byReference = backupByReference;
7650 thisExp.prev = null;
7651 thisExp.next = null;
7654 if( ( type.kind == classType && type._class && type._class.registered &&
7655 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7656 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7657 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7658 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7660 bool passAsTemplate = thisExp.destType.passAsTemplate;
7663 destType.refCount++;
7668 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7671 CopyTypeInto(t, thisExp.destType);
7672 t.passAsTemplate = false;
7673 FreeType(thisExp.destType);
7674 thisExp.destType = t;
7677 CopyTypeInto(t, destType);
7678 t.passAsTemplate = passAsTemplate;
7681 destType.refCount = 0;
7684 CopyTypeInto(e.expType, type);
7685 if(type.passAsTemplate)
7687 e.expType.classObjectType = none;
7688 e.expType.passAsTemplate = false;
7690 e.expType.byReference = false;
7691 e.expType.refCount = 1;
7696 e.cast.typeName = MkTypeName(specs, decl);
7697 e.cast.exp = thisExp;
7698 e.byReference = true;
7704 FreeType(e.destType);
7706 e.destType = destType;
7707 destType.refCount++;
7712 void ApplyLocation(Expression exp, Location loc)
7718 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7719 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7725 for(e = exp.list->first; e; e = e.next)
7726 ApplyLocation(e, loc);
7733 for(e = exp.index.index->first; e; e = e.next)
7734 ApplyLocation(e, loc);
7737 ApplyLocation(exp.index.exp, loc);
7740 if(exp.call.arguments)
7743 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7744 ApplyLocation(arg, loc);
7747 ApplyLocation(exp.call.exp, loc);
7752 ApplyLocation(exp.member.exp, loc);
7756 ApplyLocation(exp.cast.exp, loc);
7762 for(e = exp.cond.exp->first; e; e = e.next)
7763 ApplyLocation(e, loc);
7766 ApplyLocation(exp.cond.cond, loc);
7767 if(exp.cond.elseExp)
7768 ApplyLocation(exp.cond.elseExp, loc);
7772 ApplyLocation(exp.vaArg.exp, loc);
7779 bool RelatedUnits(Class c1, Class c2)
7781 if(c1.base.type == unitClass) c1 = c1.base;
7782 if(c2.base.type == unitClass) c2 = c2.base;
7786 void ProcessExpressionType(Expression exp)
7788 bool unresolved = false;
7789 Location oldyylloc = yylloc;
7790 bool notByReference = false;
7792 char debugExpString[4096];
7793 debugExpString[0] = '\0';
7794 PrintExpression(exp, debugExpString);
7796 if(!exp || exp.expType)
7799 //eSystem_Logf("%s\n", expString);
7801 // Testing this here
7807 Identifier id = exp.identifier;
7808 if(!id || !topContext) return;
7810 // DOING THIS LATER NOW...
7811 if(id._class && id._class.name)
7813 id.classSym = id._class.symbol; // FindClass(id._class.name);
7814 /* TODO: Name Space Fix ups
7816 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7820 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7822 exp.expType = ProcessTypeString("Module", true);
7826 if(!strcmp(id.string, "__runtimePlatform"))
7828 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7831 else if(strstr(id.string, "__ecereClass") == id.string)
7833 exp.expType = ProcessTypeString("ecere::com::Class", true);
7836 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7838 // Added this here as well
7839 ReplaceClassMembers(exp, thisClass);
7840 if(exp.type != identifierExp)
7842 ProcessExpressionType(exp);
7846 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7851 Symbol symbol = null;
7852 bool findInGlobal = false;
7853 if(!topContext.parent && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == enumClass)
7854 findInGlobal = true; // In global context, look at enum values first
7856 symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7858 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7859 if(!symbol/* && exp.destType*/)
7861 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7867 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7868 if(exp.type != identifierExp)
7870 ProcessExpressionType(exp);
7874 // Static methods called from inside the _class
7875 else if(currentClass && !id._class)
7877 if(ResolveIdWithClass(exp, currentClass, true))
7880 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7884 symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7886 // If we manage to resolve this symbol
7889 Type type = symbol.type;
7890 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7892 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7894 Context context = SetupTemplatesContext(_class);
7895 type = ReplaceThisClassType(_class);
7896 FinishTemplatesContext(context);
7897 if(type) type.refCount = 0; // We'll be incrementing it right below...
7900 FreeSpecifier(id._class);
7903 id.string = CopyString(symbol.string);
7910 // Commented this out, it was making non-constant enum parameters seen as constant
7911 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7912 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7913 // Add missing cases here... enum Classes...
7914 exp.isConstant = true;
7916 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7917 if(symbol.isParam || !strcmp(id.string, "this"))
7919 if(_class && _class.type == structClass && !type.declaredWithStruct)
7920 exp.byReference = true;
7922 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7923 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7924 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7925 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7927 Identifier id = exp.identifier;
7928 exp.type = bracketsExp;
7929 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7933 if(symbol.isIterator)
7935 if(symbol.isIterator == 3)
7937 exp.type = bracketsExp;
7938 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7939 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7941 ProcessExpressionType(exp);
7943 else if(symbol.isIterator != 4)
7945 exp.type = memberExp;
7946 exp.member.exp = MkExpIdentifier(exp.identifier);
7947 exp.member.exp.expType = exp.expType;
7948 /*if(symbol.isIterator == 6)
7949 exp.member.member = MkIdentifier("key");
7951 exp.member.member = MkIdentifier("data");
7953 ProcessExpressionType(exp);
7960 DefinedExpression definedExp = null;
7961 if(thisNameSpace && !(id._class && !id._class.name))
7964 strcpy(name, thisNameSpace);
7966 strcat(name, id.string);
7967 definedExp = eSystem_FindDefine(privateModule, name);
7970 definedExp = eSystem_FindDefine(privateModule, id.string);
7974 for(c = 0; c<definedExpStackPos; c++)
7975 if(definedExpStack[c] == definedExp)
7977 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7979 Location backupYylloc = yylloc;
7980 File backInput = fileInput;
7981 definedExpStack[definedExpStackPos++] = definedExp;
7983 fileInput = TempFile { };
7984 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7985 fileInput.Seek(0, start);
7988 parsedExpression = null;
7990 expression_yyparse();
7993 fileInput = backInput;
7995 yylloc = backupYylloc;
7997 if(parsedExpression)
8000 exp.type = bracketsExp;
8001 exp.list = MkListOne(parsedExpression);
8002 ApplyLocation(parsedExpression, yylloc);
8003 ProcessExpressionType(exp);
8004 definedExpStackPos--;
8007 definedExpStackPos--;
8013 Compiler_Error($"Recursion in defined expression %s\n", id.string);
8019 GlobalData data = null;
8020 if(thisNameSpace && !(id._class && !id._class.name))
8023 strcpy(name, thisNameSpace);
8025 strcat(name, id.string);
8026 data = FindGlobalData(name);
8029 data = FindGlobalData(id.string);
8032 DeclareGlobalData(curExternal, data);
8033 exp.expType = data.dataType;
8034 if(data.dataType) data.dataType.refCount++;
8037 id.string = CopyString(data.fullName);
8038 FreeSpecifier(id._class);
8045 GlobalFunction function = null;
8046 if(thisNameSpace && !(id._class && !id._class.name))
8049 strcpy(name, thisNameSpace);
8051 strcat(name, id.string);
8052 function = eSystem_FindFunction(privateModule, name);
8055 function = eSystem_FindFunction(privateModule, id.string);
8060 id.string = CopyString(function.name);
8063 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8064 strcpy(name, "__ecereFunction_");
8065 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8066 if(DeclareFunction(curExternal, function, name))
8069 id.string = CopyString(name);
8071 exp.expType = function.dataType;
8072 if(function.dataType) function.dataType.refCount++;
8074 FreeSpecifier(id._class);
8091 if(!exp.instance._class)
8093 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8095 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8099 //classSym = FindClass(exp.instance._class.fullName);
8100 //_class = classSym ? classSym.registered : null;
8102 ProcessInstantiationType(exp.instance);
8104 exp.isConstant = exp.instance.isConstant;
8107 if(_class.type == unitClass && _class.base.type != systemClass)
8110 Type destType = exp.destType;
8112 exp.destType = MkClassType(_class.base.fullName);
8113 exp.expType = MkClassType(_class.fullName);
8114 CheckExpressionType(exp, exp.destType, true);
8116 exp.destType = destType;
8118 exp.expType = MkClassType(_class.fullName);
8121 if(exp.instance._class)
8123 exp.expType = MkClassType(exp.instance._class.name);
8124 /*if(exp.expType._class && exp.expType._class.registered &&
8125 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8126 exp.expType.byReference = true;*/
8134 char * constant = exp.constant;
8142 if(constant[0] == '\'')
8144 if((int)((byte *)constant)[1] > 127)
8147 unichar ch = UTF8GetChar(constant + 1, &nb);
8148 if(nb < 2) ch = constant[1];
8150 exp.constant = PrintUInt(ch);
8151 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8152 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8153 type._class = FindClass("unichar");
8155 type.isSigned = false;
8159 type.kind = charType;
8160 type.isSigned = true;
8165 char * dot = strchr(constant, '.');
8166 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8170 exponent = strchr(constant, 'p');
8171 if(!exponent) exponent = strchr(constant, 'P');
8175 exponent = strchr(constant, 'e');
8176 if(!exponent) exponent = strchr(constant, 'E');
8181 if(strchr(constant, 'f') || strchr(constant, 'F'))
8182 type.kind = floatType;
8184 type.kind = doubleType;
8185 type.isSigned = true;
8189 bool isSigned = constant[0] == '-';
8191 int64 i64 = strtoll(constant, &endP, 0);
8192 uint64 ui64 = strtoull(constant, &endP, 0);
8193 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8194 bool forceUnsigned = endP && (!strcmp(endP, "U") || !strcmp(endP, "u") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8207 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8211 else if(constant[0] != '0' || !constant[1])
8216 type.kind = is64Bit ? int64Type : intType;
8217 type.isSigned = isSigned;
8220 exp.isConstant = true;
8221 if(exp.destType && exp.destType.kind == doubleType)
8222 type.kind = doubleType;
8223 else if(exp.destType && exp.destType.kind == floatType)
8224 type.kind = floatType;
8225 else if(exp.destType && exp.destType.kind == int64Type)
8226 type.kind = int64Type;
8232 exp.isConstant = true; // Why wasn't this constant?
8240 kind = exp.wideString ? shortType : charType;
8242 isSigned = exp.wideString ? false : true;
8249 ProcessExpressionType(exp._new.size);
8254 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8256 DeclareType(curExternal, exp.expType.type, true, false);
8260 ProcessExpressionType(exp._renew.size);
8261 ProcessExpressionType(exp._renew.exp);
8266 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8268 DeclareType(curExternal, exp.expType.type, true, false);
8272 bool assign = false, boolResult = false, boolOps = false;
8273 Type type1 = null, type2 = null;
8274 bool useDestType = false, useSideType = false;
8275 Location oldyylloc = yylloc;
8276 bool useSideUnit = false;
8277 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8278 bool powerOp = false, relationOp = false;
8279 Class c1 = null, c2 = null;
8281 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8290 // Assignment Operators
8304 // boolean Operators
8306 // Expect boolean operators
8308 //boolResult = true;
8312 // Expect boolean operands
8323 // Gives boolean result
8337 // useSideType = true;
8338 // useDestType = true;
8351 if(exp.op.op == '/') powerOp = true;
8357 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8360 if(exp.op.op == '*') powerOp = true;
8364 /*// Implement speed etc.
8370 if(exp.op.op == '&')
8372 // Added this here earlier for Iterator address as key
8373 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8375 Identifier id = exp.op.exp2.identifier;
8376 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8377 if(symbol && symbol.isIterator == 2)
8379 exp.type = memberExp;
8380 exp.member.exp = exp.op.exp2;
8381 exp.member.member = MkIdentifier("key");
8383 exp.op.exp2.expType = symbol.type;
8384 symbol.type.refCount++;
8385 ProcessExpressionType(exp);
8389 // exp.op.exp2.usage.usageRef = true;
8393 //dummy.kind = TypeDummy;
8396 // Added this check here to use the dest type only for units derived from the base unit
8397 // So that untyped units will use the side unit as opposed to the untyped destination unit
8398 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8399 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8400 useDestType = false;
8402 if(destClass && useDestType &&
8403 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8405 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8407 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8408 exp.op.exp1.destType = exp.destType;
8409 exp.op.exp1.opDestType = true;
8411 exp.destType.refCount++;
8415 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8416 exp.op.exp1.destType = dummy;
8419 exp.op.exp1.opDestType = true;
8421 exp.op.exp1.usedInComparison = true;
8423 if(exp.op.op == '+' || exp.op.op == '-')
8426 exp.op.exp1.parentOpDestType = true;
8427 if(exp.usedInComparison)
8428 exp.op.exp1.usedInComparison = true;
8431 // TESTING THIS HERE...
8432 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8433 ProcessExpressionType(exp.op.exp1);
8434 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8436 exp.op.exp1.opDestType = false;
8437 exp.op.exp1.usedInComparison = false;
8439 // Fix for unit and ++ / --
8440 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8441 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8443 exp.op.exp2 = MkExpConstant("1");
8444 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8448 if(exp.op.exp1.destType == dummy)
8451 exp.op.exp1.destType = null;
8456 if(!assign && exp.op.exp1.expType && (exp.op.exp1.expType.kind == charType || exp.op.exp1.expType.kind == shortType))
8458 Type type { kind = intType, isSigned = true, refCount = 1, signedBeforePromotion = exp.op.exp1.expType.isSigned, bitMemberSize = exp.op.exp1.expType.bitMemberSize, promotedFrom = exp.op.exp1.expType.kind };
8459 FreeType(exp.op.exp1.expType);
8460 exp.op.exp1.expType = type;
8464 type1 = exp.op.exp1.expType;
8469 char expString[10240];
8470 expString[0] = '\0';
8471 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8475 exp.op.exp2.destType = exp.op.exp1.expType;
8476 if(exp.op.exp1.expType)
8477 exp.op.exp1.expType.refCount++;
8481 exp.op.exp2.destType = exp.destType;
8482 if(!exp.op.exp1 || (exp.op.op != '&' && exp.op.op != '^'))
8483 exp.op.exp2.opDestType = true;
8485 exp.destType.refCount++;
8488 if(type1) type1.refCount++;
8489 exp.expType = type1;
8494 PrintExpression(exp.op.exp2, expString);
8496 if(type1 && type1.kind == pointerType)
8498 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 ||
8499 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8500 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8501 else if(exp.op.op == '=')
8503 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8504 exp.op.exp2.destType = type1;
8511 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8512 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/* ||
8513 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8516 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8517 exp.op.exp2.destType = type1;
8522 if(type1) type1.refCount++;
8523 exp.expType = type1;
8525 else if(destClass &&
8526 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8527 (destClass.type == enumClass && useDestType)))
8529 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8530 exp.op.exp2.destType = exp.destType;
8531 if(exp.op.op != '&' && exp.op.op != '^')
8532 exp.op.exp2.opDestType = true;
8534 exp.destType.refCount++;
8538 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8539 exp.op.exp2.destType = dummy;
8542 exp.op.exp2.opDestType = true;
8544 exp.op.exp2.usedInComparison = true;
8547 // TESTING THIS HERE... (DANGEROUS)
8548 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8549 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8551 FreeType(exp.op.exp2.destType);
8552 exp.op.exp2.destType = type1;
8555 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8556 // Cannot lose the cast on a sizeof
8557 if(exp.op.op == SIZEOF)
8559 Expression e = exp.op.exp2;
8560 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8562 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8564 if(e.type == extensionCompoundExp)
8565 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8570 if(e.type == castExp && e.cast.exp)
8571 e.cast.exp.needCast = true;
8573 if(exp.op.op == '+' || exp.op.op == '-')
8576 exp.op.exp2.parentOpDestType = true;
8577 if(exp.usedInComparison)
8578 exp.op.exp2.usedInComparison = true;
8580 ProcessExpressionType(exp.op.exp2);
8581 exp.op.exp2.opDestType = false;
8582 exp.op.exp2.usedInComparison = false;
8583 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8585 if(!assign && (exp.op.exp1 || exp.op.op == '~'))
8587 if(exp.op.exp2.expType && (exp.op.exp2.expType.kind == charType || exp.op.exp2.expType.kind == shortType))
8589 Type type { kind = intType, isSigned = true, refCount = 1, signedBeforePromotion = exp.op.exp2.expType.isSigned, bitMemberSize = exp.op.exp2.expType.bitMemberSize, promotedFrom = exp.op.exp2.expType.kind };
8590 FreeType(exp.op.exp2.expType);
8591 exp.op.exp2.expType = type;
8595 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8597 if(exp.op.exp2.expType.kind == intSizeType || exp.op.exp2.expType.kind == intPtrType || exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
8599 if(exp.op.op != '=' && type1.type.kind == voidType)
8600 Compiler_Error($"void *: unknown size\n");
8602 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||
8603 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8604 (exp.op.exp2.expType._class.registered.type == normalClass ||
8605 exp.op.exp2.expType._class.registered.type == structClass ||
8606 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8608 if(exp.op.op == ADD_ASSIGN)
8609 Compiler_Error($"cannot add two pointers\n");
8611 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8612 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8614 if(exp.op.op == ADD_ASSIGN)
8615 Compiler_Error($"cannot add two pointers\n");
8619 char type1String[1024];
8620 char type2String[1024];
8621 type1String[0] = '\0';
8622 type2String[0] = '\0';
8624 PrintType(exp.op.exp2.expType, type1String, false, true);
8625 PrintType(type1, type2String, false, true);
8626 ChangeCh(expString, '\n', ' ');
8627 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8631 if(exp.op.exp2.destType == dummy)
8634 exp.op.exp2.destType = null;
8637 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8641 CopyTypeInto(type2, exp.op.exp2.expType);
8642 type2.isSigned = true;
8644 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8646 type2 = { kind = intType };
8648 type2.isSigned = true;
8652 type2 = exp.op.exp2.expType;
8653 if(type2) type2.refCount++;
8656 c1 = type1 && type1.kind == classType && type1._class ? type1._class.registered : null;
8657 c2 = type2 && type2.kind == classType && type2._class ? type2._class.registered : null;
8660 ( (exp.op.exp1 && exp.op.exp1.ambiguousUnits && (!c2 || c2.type != unitClass)) ||
8661 (exp.op.exp2 && exp.op.exp2.ambiguousUnits && (!c1 || c1.type != unitClass))) )
8662 Compiler_Warning($"ambiguous units in relation operation\n");
8665 ((exp.op.exp1 && exp.op.exp1.ambiguousUnits) ||
8666 (exp.op.exp2 && exp.op.exp2.ambiguousUnits)) &&
8667 (!powerOp || !c1 || c1.type != unitClass || !c2 || c2.type != unitClass || !RelatedUnits(c1, c2)))
8669 if(exp.opDestType || exp.usedInComparison)
8670 exp.ambiguousUnits = true;
8672 Compiler_Warning($"ambiguous units\n");
8675 dummy.kind = voidType;
8677 if(exp.op.op == SIZEOF)
8684 exp.isConstant = true;
8686 // Get type of dereferenced pointer
8687 else if(exp.op.op == '*' && !exp.op.exp1)
8689 exp.expType = Dereference(type2);
8690 if(type2 && type2.kind == classType)
8691 notByReference = true;
8693 else if(exp.op.op == '&' && !exp.op.exp1)
8694 exp.expType = Reference(type2);
8695 else if(exp.op.op == LEFT_OP || exp.op.op == RIGHT_OP)
8697 if(exp.op.exp1.expType)
8699 exp.expType = exp.op.exp1.expType;
8700 exp.expType.refCount++;
8705 if(c1 && !c1.dataType)
8706 c1.dataType = ProcessTypeString(c1.dataTypeString, false);
8707 if(c2 && !c2.dataType)
8708 c2.dataType = ProcessTypeString(c2.dataTypeString, false);
8714 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8715 exp.op.exp1.destType = MkClassType("bool");
8716 exp.op.exp1.destType.truth = true;
8717 if(!exp.op.exp1.expType)
8718 ProcessExpressionType(exp.op.exp1);
8720 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8721 FreeType(exp.op.exp1.expType);
8722 exp.op.exp1.expType = MkClassType("bool");
8723 exp.op.exp1.expType.truth = true;
8727 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8728 exp.op.exp2.destType = MkClassType("bool");
8729 exp.op.exp2.destType.truth = true;
8730 if(!exp.op.exp2.expType)
8731 ProcessExpressionType(exp.op.exp2);
8733 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8734 FreeType(exp.op.exp2.expType);
8735 exp.op.exp2.expType = MkClassType("bool");
8736 exp.op.exp2.expType.truth = true;
8739 else if(powerOp && exp.op.exp1 && exp.op.exp2 && ((c1 && c1.type == unitClass) || (c2 && c2.type == unitClass)))
8741 // * or / with at least one unit operand
8742 if(c1 && c1.type == unitClass && c2 && c2.type == unitClass)
8744 // This is where we'd handle unit powers e.g. square meters or meters/seconds
8745 // For now using base types
8746 if(c1.dataType.kind == doubleType) exp.expType = c1.dataType;
8747 else if(c2.dataType.kind == doubleType) exp.expType = c2.dataType;
8748 else if(c1.dataType.kind == floatType) exp.expType = c1.dataType;
8749 else if(c2.dataType.kind == floatType) exp.expType = c2.dataType;
8751 exp.expType = c1.dataType;
8753 else if((c1 && c1.type == unitClass) || exp.op.op == '/') // 1/units should not be typed with unit
8754 exp.expType = type1;
8756 exp.expType = type2;
8759 exp.expType.refCount++;
8761 else if(exp.op.exp1 && exp.op.exp2 &&
8764 ((!c1 || c1.type != unitClass) &&
8765 (!c2 || c2.type != unitClass)))*/) ||
8766 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8767 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8769 if(type1 && type2 &&
8770 // If either both are class or both are not class
8771 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8773 // Added this check for enum subtraction to result in an int type:
8774 if(exp.op.op == '-' && ((c1 && c1.type == enumClass) || (c2 && c2.type == enumClass)) )
8776 Type intType = ProcessTypeString((c1 && c1.dataType.kind == int64Type) || (c2 && c2.dataType.kind == int64Type) ? "int64" : "int", false);
8778 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8779 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8780 exp.op.exp1.destType = intType;
8781 exp.op.exp2.destType = intType;
8786 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8787 exp.op.exp2.destType = type1;
8789 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8790 exp.op.exp1.destType = type2;
8794 // Warning here for adding Radians + Degrees with no destination type
8795 if(!boolResult && !exp.opDestType && (!exp.destType || exp.destType.kind != classType) &&
8796 c1 && c1.type == unitClass &&
8797 c2 && c2.type == unitClass &&
8800 if(exp.usedInComparison || exp.parentOpDestType)
8801 exp.ambiguousUnits = true;
8803 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8804 type1._class.string, type2._class.string, type1._class.string);
8807 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8809 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8812 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8814 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8815 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8818 ProcessExpressionType(exp.op.exp1);
8820 if(type2.kind != pointerType)
8822 ProcessExpressionType(classExp);
8824 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8826 if(!exp.op.exp2.expType)
8830 type2 = exp.op.exp2.expType = ProcessTypeString("int", false); c2 = null;
8834 ProcessExpressionType(exp.op.exp2);
8839 if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == intSizeType || type2.kind == intPtrType || type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
8841 if(type1.kind != classType && type1.type.kind == voidType)
8842 Compiler_Error($"void *: unknown size\n");
8843 exp.expType = type1;
8844 if(type1) type1.refCount++;
8846 else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == intSizeType || type1.kind == intPtrType || type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
8848 if(type2.kind != classType && type2.type.kind == voidType)
8849 Compiler_Error($"void *: unknown size\n");
8850 exp.expType = type2;
8851 if(type2) type2.refCount++;
8853 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8854 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8856 Compiler_Warning($"different levels of indirection\n");
8860 bool success = false;
8861 if(type1.kind == pointerType && type2.kind == pointerType)
8863 if(exp.op.op == '+')
8864 Compiler_Error($"cannot add two pointers\n");
8865 else if(exp.op.op == '-')
8867 // Pointer Subtraction gives integer
8868 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8877 if(type1.type.kind == templateType)
8879 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8882 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8884 ProcessExpressionType(classExp);
8886 exp.type = bracketsExp;
8887 exp.list = MkListOne(MkExpOp(
8888 MkExpBrackets(MkListOne(MkExpOp(
8889 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8891 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8892 MkExpMember(classExp, MkIdentifier("typeSize"))));
8894 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8903 if(!success && exp.op.exp1.type == constantExp)
8905 // If first expression is constant, try to match that first
8906 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8908 if(exp.expType) FreeType(exp.expType);
8909 exp.expType = exp.op.exp1.destType;
8910 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8913 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8915 if(exp.expType) FreeType(exp.expType);
8916 exp.expType = exp.op.exp2.destType;
8917 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8923 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8925 if(exp.expType) FreeType(exp.expType);
8926 exp.expType = exp.op.exp2.destType;
8927 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8930 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8932 if(exp.expType) FreeType(exp.expType);
8933 exp.expType = exp.op.exp1.destType;
8934 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8940 char expString1[10240];
8941 char expString2[10240];
8944 expString1[0] = '\0';
8945 expString2[0] = '\0';
8950 PrintExpression(exp.op.exp1, expString1);
8951 ChangeCh(expString1, '\n', ' ');
8952 PrintExpression(exp.op.exp2, expString2);
8953 ChangeCh(expString2, '\n', ' ');
8954 PrintType(exp.op.exp1.expType, type1, false, true);
8955 PrintType(exp.op.exp2.expType, type2, false, true);
8958 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8962 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8963 else if(!boolResult && !useSideUnit && c2 && c2.type == unitClass && type1 && type1.kind != classType)
8965 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8966 // Convert e.g. / 4 into / 4.0
8967 exp.op.exp1.destType = type2._class.registered.dataType;
8968 if(type2._class.registered.dataType)
8969 type2._class.registered.dataType.refCount++;
8970 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8971 exp.expType = type2;
8972 if(type2) type2.refCount++;
8974 else if(!boolResult && !useSideUnit && c1 && c1.type == unitClass && type2 && type2.kind != classType)
8976 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8977 // Convert e.g. / 4 into / 4.0
8978 exp.op.exp2.destType = type1._class.registered.dataType;
8979 if(type1._class.registered.dataType)
8980 type1._class.registered.dataType.refCount++;
8981 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8982 exp.expType = type1;
8983 if(type1) type1.refCount++;
8989 if(!boolResult && useSideUnit && c1 && c1.type == unitClass && type2 && type2.kind != classType)
8991 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8993 exp.op.exp2.destType = c1.dataType;
8994 exp.op.exp2.destType.refCount++;
8996 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8999 type2 = exp.op.exp2.destType;
9000 c2 = type2 && type2.kind == classType && type2._class ? type2._class.registered : null;
9001 if(type2) type2.refCount++;
9003 exp.expType = type2;
9007 if(!boolResult && useSideUnit && c2 && c2.type == unitClass && type1 && type1.kind != classType)
9009 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9011 exp.op.exp1.destType = c2.dataType;
9012 exp.op.exp1.destType.refCount++;
9014 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9015 type1 = exp.op.exp1.destType;
9016 c1 = type1 && type1.kind == classType && type1._class ? type1._class.registered : null;
9017 exp.expType = type1;
9021 // TESTING THIS NEW CODE
9022 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
9024 bool op1IsEnum = c1 && c1.type == enumClass;
9025 bool op2IsEnum = c2 && c2.type == enumClass;
9026 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
9028 // Convert the enum to an int instead for these operators
9029 if(op1IsEnum && exp.op.exp2.expType)
9031 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
9033 if(exp.expType) FreeType(exp.expType);
9034 exp.expType = exp.op.exp2.expType;
9035 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9039 else if(op2IsEnum && exp.op.exp1.expType)
9041 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
9043 if(exp.expType) FreeType(exp.expType);
9044 exp.expType = exp.op.exp1.expType;
9045 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9052 if(op1IsEnum && exp.op.exp2.expType)
9054 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
9056 if(exp.expType) FreeType(exp.expType);
9057 exp.expType = exp.op.exp1.expType;
9058 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9062 else if(op2IsEnum && exp.op.exp1.expType)
9064 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
9066 if(exp.expType) FreeType(exp.expType);
9067 exp.expType = exp.op.exp2.expType;
9068 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9077 // Added this first part of the if here to handle 5 + Degrees { 5 } with either a base unit dest or not a unit dest type
9078 if(c2 && c2.type == unitClass && (!c1 || c1.type != unitClass))
9080 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9081 exp.op.exp1.destType = type2;
9084 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9086 if(exp.expType) FreeType(exp.expType);
9087 exp.expType = exp.op.exp1.destType;
9088 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9093 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9094 exp.op.exp2.destType = type1;
9098 // Maybe this was meant to be an enum...
9099 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9101 Type oldType = exp.op.exp2.expType;
9102 exp.op.exp2.expType = null;
9103 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9106 exp.op.exp2.expType = oldType;
9111 // TESTING THIS HERE... LATEST ADDITION
9112 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9114 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9115 exp.op.exp2.destType = type2._class.registered.dataType;
9116 if(type2._class.registered.dataType)
9117 type2._class.registered.dataType.refCount++;
9118 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9120 //exp.expType = type2._class.registered.dataType; //type2;
9121 //if(type2) type2.refCount++;
9124 // TESTING THIS HERE... LATEST ADDITION
9125 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9127 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9128 exp.op.exp1.destType = type1._class.registered.dataType;
9129 if(type1._class.registered.dataType)
9130 type1._class.registered.dataType.refCount++;
9131 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9132 exp.expType = type1._class.registered.dataType; //type1;
9133 if(type1) type1.refCount++;
9137 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9139 if(exp.expType) FreeType(exp.expType);
9140 exp.expType = exp.op.exp2.destType;
9141 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9143 else if(type1 && type2)
9145 char expString1[10240];
9146 char expString2[10240];
9147 char type1String[1024];
9148 char type2String[1024];
9149 expString1[0] = '\0';
9150 expString2[0] = '\0';
9151 type1String[0] = '\0';
9152 type2String[0] = '\0';
9155 PrintExpression(exp.op.exp1, expString1);
9156 ChangeCh(expString1, '\n', ' ');
9157 PrintExpression(exp.op.exp2, expString2);
9158 ChangeCh(expString2, '\n', ' ');
9159 PrintType(exp.op.exp1.expType, type1String, false, true);
9160 PrintType(exp.op.exp2.expType, type2String, false, true);
9163 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9165 if(c1 && c1.type == enumClass)
9167 exp.expType = exp.op.exp1.expType;
9168 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9170 else if(c2 && c2.type == enumClass)
9172 exp.expType = exp.op.exp2.expType;
9173 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9181 // Maybe this was meant to be an enum...
9182 if(c2 && c2.type == enumClass)
9184 Type oldType = exp.op.exp1.expType;
9185 exp.op.exp1.expType = null;
9186 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9189 exp.op.exp1.expType = oldType;
9192 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9193 exp.op.exp1.destType = type2;
9196 // TESTING THIS HERE... LATEST ADDITION
9197 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9199 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9200 exp.op.exp1.destType = type1._class.registered.dataType;
9201 if(type1._class.registered.dataType)
9202 type1._class.registered.dataType.refCount++;
9205 // TESTING THIS HERE... LATEST ADDITION
9206 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9208 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9209 exp.op.exp2.destType = type2._class.registered.dataType;
9210 if(type2._class.registered.dataType)
9211 type2._class.registered.dataType.refCount++;
9215 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9217 if(exp.expType) FreeType(exp.expType);
9218 exp.expType = exp.op.exp1.destType;
9219 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9223 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9225 if(type1 && c2 && c2.type == unitClass)
9227 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9228 // Convert e.g. / 4 into / 4.0
9229 exp.op.exp1.destType = type2._class.registered.dataType;
9230 if(type2._class.registered.dataType)
9231 type2._class.registered.dataType.refCount++;
9232 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9234 if(exp.op.op == '!')
9236 exp.expType = MkClassType("bool");
9237 exp.expType.truth = true;
9241 exp.expType = type2;
9242 if(type2) type2.refCount++;
9245 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9247 if(c2 && c2.type == unitClass)
9249 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9250 // Convert e.g. / 4 into / 4.0
9251 exp.op.exp2.destType = type1._class.registered.dataType;
9252 if(type1._class.registered.dataType)
9253 type1._class.registered.dataType.refCount++;
9254 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9256 exp.expType = type1;
9257 if(type1) type1.refCount++;
9262 if(exp.op.exp1 && !exp.op.exp1.expType)
9264 char expString[10000];
9265 expString[0] = '\0';
9268 PrintExpression(exp.op.exp1, expString);
9269 ChangeCh(expString, '\n', ' ');
9272 Compiler_Error($"couldn't determine type of %s\n", expString);
9274 if(exp.op.exp2 && !exp.op.exp2.expType)
9276 char expString[10240];
9277 expString[0] = '\0';
9280 PrintExpression(exp.op.exp2, expString);
9281 ChangeCh(expString, '\n', ' ');
9284 Compiler_Error($"couldn't determine type of %s\n", expString);
9289 FreeType(exp.expType);
9290 exp.expType = MkClassType("bool");
9291 exp.expType.truth = true;
9294 if(exp.op.op != SIZEOF)
9295 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9296 (!exp.op.exp2 || exp.op.exp2.isConstant);
9298 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9300 DeclareType(curExternal, exp.op.exp2.expType, true, false);
9303 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9304 Compiler_Warning($"deleting const qualified object\n");
9314 case extensionExpressionExp:
9317 exp.isConstant = true;
9318 for(e = exp.list->first; e; e = e.next)
9320 //bool inced = false;
9323 FreeType(e.destType);
9324 e.opDestType = exp.opDestType;
9325 e.usedInComparison = exp.usedInComparison;
9326 e.parentOpDestType = exp.parentOpDestType;
9327 e.destType = exp.destType;
9328 if(e.destType) { exp.destType.refCount++; /*e.destType.count++; inced = true;*/ }
9330 ProcessExpressionType(e);
9331 if(e.ambiguousUnits)
9332 exp.ambiguousUnits = true;
9334 exp.destType.count--;*/
9335 if(!exp.expType && !e.next)
9337 exp.expType = e.expType;
9338 if(e.expType) e.expType.refCount++;
9339 exp.needCast = e.needCast;
9342 exp.isConstant = false;
9345 // In case a cast became a member...
9346 e = exp.list->first;
9347 if(!e.next && e.type == memberExp)
9349 // Preserve prev, next
9350 Expression next = exp.next, prev = exp.prev;
9353 FreeType(exp.expType);
9354 FreeType(exp.destType);
9364 ProcessExpressionType(exp);
9371 exp.isConstant = true;
9373 ProcessExpressionType(exp.index.exp);
9374 if(!exp.index.exp.isConstant)
9375 exp.isConstant = false;
9377 if(exp.index.exp.expType)
9379 Type source = exp.index.exp.expType;
9380 if(source.kind == classType && source._class && source._class.registered)
9382 Class _class = source._class.registered;
9383 Class c = _class.templateClass ? _class.templateClass : _class;
9384 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9386 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9388 if(exp.index.index && exp.index.index->last)
9390 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9392 if(type.kind == classType) type.constant = true;
9393 else if(type.kind == pointerType)
9396 while(t.kind == pointerType) t = t.type;
9400 ((Expression)exp.index.index->last).destType = type;
9406 for(e = exp.index.index->first; e; e = e.next)
9408 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9410 if(e.destType) FreeType(e.destType);
9411 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9413 ProcessExpressionType(e);
9416 // Check if this type is int
9419 exp.isConstant = false;
9423 exp.expType = Dereference(exp.index.exp.expType);
9425 DeclareType(curExternal, exp.expType, true, false);
9432 Type methodType = null;
9438 PrintExpression(exp.call.exp, name);
9439 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9441 //exp.call.exp.expType = null;
9442 PrintExpression(exp.call.exp, name);
9445 if(exp.call.exp.type == identifierExp)
9447 Expression idExp = exp.call.exp;
9448 Identifier id = idExp.identifier;
9449 if(!strcmp(id.string, "__builtin_frame_address"))
9451 exp.expType = ProcessTypeString("void *", true);
9452 if(exp.call.arguments && exp.call.arguments->first)
9453 ProcessExpressionType(exp.call.arguments->first);
9456 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9458 exp.expType = ProcessTypeString("int", true);
9459 if(exp.call.arguments && exp.call.arguments->first)
9460 ProcessExpressionType(exp.call.arguments->first);
9463 else if(!strcmp(id.string, "Max") ||
9464 !strcmp(id.string, "Min") ||
9465 !strcmp(id.string, "Sgn") ||
9466 !strcmp(id.string, "Abs"))
9468 Expression a = null;
9469 Expression b = null;
9470 Expression tempExp1 = null, tempExp2 = null;
9471 if((!strcmp(id.string, "Max") ||
9472 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9474 a = exp.call.arguments->first;
9475 b = exp.call.arguments->last;
9479 else if(exp.call.arguments->count == 1)
9481 a = exp.call.arguments->first;
9487 exp.call.arguments->Clear();
9488 idExp.identifier = null;
9490 FreeExpContents(exp);
9492 ProcessExpressionType(a);
9494 ProcessExpressionType(b);
9496 exp.type = bracketsExp;
9497 exp.list = MkList();
9499 if(a.expType && (!b || b.expType))
9501 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9503 // Use the simpleStruct name/ids for now...
9506 OldList * specs = MkList();
9507 OldList * decls = MkList();
9509 char temp1[1024], temp2[1024];
9511 GetTypeSpecs(a.expType, specs);
9513 if(a && !a.isConstant && a.type != identifierExp)
9515 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9516 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9517 tempExp1 = QMkExpId(temp1);
9518 tempExp1.expType = a.expType;
9520 a.expType.refCount++;
9521 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9523 if(b && !b.isConstant && b.type != identifierExp)
9525 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9526 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9527 tempExp2 = QMkExpId(temp2);
9528 tempExp2.expType = b.expType;
9530 b.expType.refCount++;
9531 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9534 decl = MkDeclaration(specs, decls);
9535 if(!curCompound.compound.declarations)
9536 curCompound.compound.declarations = MkList();
9537 curCompound.compound.declarations->Insert(null, decl);
9542 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9544 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9546 MkExpCondition(MkExpBrackets(MkListOne(
9547 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9548 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9549 exp.expType = a.expType;
9551 a.expType.refCount++;
9553 else if(!strcmp(id.string, "Abs"))
9556 MkExpCondition(MkExpBrackets(MkListOne(
9557 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9558 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9559 exp.expType = a.expType;
9561 a.expType.refCount++;
9563 else if(!strcmp(id.string, "Sgn"))
9565 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9567 MkExpCondition(MkExpBrackets(MkListOne(
9568 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9569 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9570 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9571 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9572 exp.expType = ProcessTypeString("int", false);
9575 FreeExpression(tempExp1);
9576 if(tempExp2) FreeExpression(tempExp2);
9590 if(!exp.call.exp.destType)
9592 exp.call.exp.destType = dummy;
9595 ProcessExpressionType(exp.call.exp);
9596 if(exp.call.exp.destType == dummy)
9599 exp.call.exp.destType = null;
9604 // Check argument types against parameter types
9605 functionType = exp.call.exp.expType;
9607 if(functionType && functionType.kind == TypeKind::methodType)
9609 methodType = functionType;
9610 functionType = methodType.method.dataType;
9612 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9613 // TOCHECK: Instead of doing this here could this be done per param?
9614 if(exp.call.exp.expType.usedClass)
9616 char typeString[1024];
9617 typeString[0] = '\0';
9619 Symbol back = functionType.thisClass;
9620 // Do not output class specifier here (thisclass was added to this)
9621 functionType.thisClass = null;
9622 PrintType(functionType, typeString, true, true);
9623 functionType.thisClass = back;
9625 if(strstr(typeString, "thisclass"))
9627 OldList * specs = MkList();
9630 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9632 decl = SpecDeclFromString(typeString, specs, null);
9634 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9635 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9636 exp.call.exp.expType.usedClass))
9637 thisClassParams = false;
9639 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9641 Class backupThisClass = thisClass;
9642 thisClass = exp.call.exp.expType.usedClass;
9643 ProcessDeclarator(decl, true);
9644 thisClass = backupThisClass;
9647 thisClassParams = true;
9649 functionType = ProcessType(specs, decl);
9650 functionType.refCount = 0;
9651 FinishTemplatesContext(context);
9653 // Mark parameters that were 'thisclass'
9656 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9658 //p.wasThisClass = op.kind == thisClassType;
9659 if(op.kind == thisClassType)
9660 p.thisClassFrom = methodType.method._class;
9663 if(methodType.method.dataType.returnType.kind == thisClassType)
9665 // functionType.returnType.wasThisClass = true;
9666 functionType.returnType.thisClassFrom = methodType.method._class;
9670 FreeList(specs, FreeSpecifier);
9671 FreeDeclarator(decl);
9675 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9677 Type type = functionType.type;
9678 if(!functionType.refCount)
9680 functionType.type = null;
9681 FreeType(functionType);
9683 //methodType = functionType;
9684 functionType = type;
9686 if(functionType && functionType.kind != TypeKind::functionType)
9688 Compiler_Error($"called object %s is not a function\n", name);
9690 else if(functionType)
9692 bool emptyParams = false, noParams = false;
9693 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9694 Type type = functionType.params.first;
9695 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9697 Location oldyylloc = yylloc;
9699 if(!type) emptyParams = true;
9702 if(functionType.extraParam && e && functionType.thisClass)
9704 e.destType = MkClassType(functionType.thisClass.string);
9708 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9709 // Fixed #141 by adding '&& !functionType.extraParam'
9710 if(!functionType.staticMethod && !functionType.extraParam)
9712 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9713 memberExp.member.exp.expType._class)
9715 type = MkClassType(memberExp.member.exp.expType._class.string);
9720 type = functionType.params.first;
9725 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9727 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9728 type.byReference = functionType.byReference;
9729 type.typedByReference = functionType.typedByReference;
9732 // Allow manually passing a class for typed object
9733 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9737 type = functionType.params.first;
9745 if(type && type.kind == voidType)
9748 if(!type.refCount) FreeType(type);
9752 for( ; e; e = e.next)
9754 if(!type && !emptyParams)
9757 if(methodType && methodType.methodClass)
9758 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9759 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9760 noParams ? 0 : functionType.params.count);
9762 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9763 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9764 noParams ? 0 : functionType.params.count);
9768 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9770 Type templatedType = null;
9771 Class _class = methodType.usedClass;
9772 ClassTemplateParameter curParam = null;
9774 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9777 for(sClass = _class; sClass; sClass = sClass.base)
9779 if(sClass.templateClass) sClass = sClass.templateClass;
9781 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9783 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9786 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9788 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9789 id += nextClass.templateParams.count;
9798 if(curParam && _class.templateArgs[id].dataTypeString)
9800 bool constant = type.constant;
9801 ClassTemplateArgument arg = _class.templateArgs[id];
9803 Context context = SetupTemplatesContext(_class);
9806 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9807 templatedType = ProcessTypeString(arg.dataTypeString, false);
9808 FinishTemplatesContext(context);
9811 if(templatedType.kind == classType && constant) templatedType.constant = true;
9812 else if(templatedType.kind == pointerType)
9814 Type t = templatedType.type;
9815 while(t.kind == pointerType) t = t.type;
9816 if(constant) t.constant = constant;
9819 e.destType = templatedType;
9822 templatedType.passAsTemplate = true;
9823 // templatedType.refCount++;
9829 if(type) type.refCount++;
9834 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9836 e.destType = type.prev;
9837 e.destType.refCount++;
9842 if(type) type.refCount++;
9845 // Don't reach the end for the ellipsis
9846 if(type && type.kind != ellipsisType)
9848 Type next = type.next;
9849 if(!type.refCount) FreeType(type);
9854 if(type && type.kind != ellipsisType)
9856 if(methodType && methodType.methodClass)
9857 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9858 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9859 functionType.params.count + extra);
9861 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9862 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9863 functionType.params.count + extra);
9866 if(type && !type.refCount) FreeType(type);
9873 kind = TypeKind::functionType;
9876 if(exp.call.exp.type == identifierExp)
9878 char * string = exp.call.exp.identifier.string;
9882 Location oldyylloc = yylloc;
9884 yylloc = exp.call.exp.identifier.loc;
9885 if(strstr(string, "__builtin_") == string)
9889 functionType.returnType = exp.destType;
9890 exp.destType.refCount++;
9894 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9895 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9896 globalContext.symbols.Add((BTNode)symbol);
9897 if(strstr(symbol.string, "::"))
9898 globalContext.hasNameSpace = true;
9903 else if(exp.call.exp.type == memberExp)
9905 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9906 exp.call.exp.member.member.string);*/
9909 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9911 if(!functionType.returnType)
9913 functionType.returnType = Type
9920 if(functionType && functionType.kind == TypeKind::functionType)
9922 exp.expType = functionType.returnType;
9924 if(functionType.returnType)
9925 functionType.returnType.refCount++;
9927 if(!functionType.refCount)
9928 FreeType(functionType);
9931 if(exp.call.arguments)
9933 for(e = exp.call.arguments->first; e; e = e.next)
9934 ProcessExpressionType(e);
9941 Location oldyylloc = yylloc;
9943 Expression checkExp = exp.member.exp;
9946 if(checkExp.type == castExp)
9947 checkExp = checkExp.cast.exp;
9948 else if(checkExp.type == bracketsExp)
9949 checkExp = checkExp.list ? checkExp.list->first : null;
9954 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9955 exp.thisPtr = thisPtr;
9957 // DOING THIS LATER NOW...
9958 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9960 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9961 /* TODO: Name Space Fix ups
9962 if(!exp.member.member.classSym)
9963 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9967 ProcessExpressionType(exp.member.exp);
9968 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9969 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9971 exp.isConstant = false;
9974 exp.isConstant = exp.member.exp.isConstant;
9975 type = exp.member.exp.expType;
9979 if(type && (type.kind == templateType))
9981 Class _class = thisClass ? thisClass : currentClass;
9982 ClassTemplateParameter param = null;
9985 for(param = _class.templateParams.first; param; param = param.next)
9987 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9991 if(param && param.defaultArg.member)
9993 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9996 Expression expMember = exp.member.exp;
9998 OldList * specs = MkList();
9999 char thisClassTypeString[1024];
10001 FreeIdentifier(exp.member.member);
10003 ProcessExpressionType(argExp);
10006 char * colon = strstr(param.defaultArg.memberString, "::");
10009 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
10010 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
10013 strcpy(thisClassTypeString, _class.fullName);
10016 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
10018 exp.expType = ProcessType(specs, decl);
10019 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
10021 Class expClass = exp.expType._class.registered;
10022 Class cClass = null;
10023 int paramCount = 0;
10024 int lastParam = -1;
10026 char templateString[1024];
10027 ClassTemplateParameter param;
10028 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10029 for(cClass = expClass; cClass; cClass = cClass.base)
10032 for(param = cClass.templateParams.first; param; param = param.next)
10036 ClassTemplateArgument arg;
10037 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
10038 arg = expClass.templateArgs[id];
10040 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
10042 ClassTemplateParameter cParam;
10043 //int p = numParams - sClass.templateParams.count;
10046 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
10048 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
10050 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
10052 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10054 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
10055 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
10063 char argument[256];
10064 argument[0] = '\0';
10067 strcat(argument, arg.name.string);
10068 strcat(argument, " = ");
10074 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10075 char expString[1024];
10076 OldList * specs = MkList();
10077 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10079 char * string = PrintHexUInt64(arg.expression.ui64);
10080 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10083 ProcessExpressionType(exp);
10084 ComputeExpression(exp);
10085 expString[0] = '\0';
10086 PrintExpression(exp, expString);
10087 strcat(argument, expString);
10089 FreeExpression(exp);
10094 strcat(argument, arg.member.name);
10097 case TemplateParameterType::type:
10099 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10101 if(!strcmp(arg.dataTypeString, "thisclass"))
10102 strcat(argument, thisClassTypeString);
10104 strcat(argument, arg.dataTypeString);
10111 if(paramCount) strcat(templateString, ", ");
10112 if(lastParam != p - 1)
10114 strcat(templateString, param.name);
10115 strcat(templateString, " = ");
10117 strcat(templateString, argument);
10126 int len = strlen(templateString);
10127 if(templateString[len-1] == '>') templateString[len++] = ' ';
10128 templateString[len++] = '>';
10129 templateString[len++] = '\0';
10132 Context context = SetupTemplatesContext(_class);
10133 FreeType(exp.expType);
10134 exp.expType = ProcessTypeString(templateString, false);
10135 FinishTemplatesContext(context);
10139 if(!expMember.expType.isPointerType)
10140 expMember = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), expMember);
10141 // *([expType] *)(((byte *)(uintptr)[exp.member.exp]) + [argExp].member.offset)
10142 exp.type = bracketsExp;
10143 exp.list = MkListOne(MkExpOp(null, '*',
10146 exp.op.exp1 = null;
10148 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10149 MkExpBrackets(MkListOne(
10150 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
10153 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10155 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10160 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10161 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10163 type = ProcessTemplateParameterType(type.templateParameter);
10166 // TODO: *** This seems to be where we should add method support for all basic types ***
10167 if(type && (type.kind == templateType));
10168 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10169 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10170 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10171 (type.kind == pointerType && type.type.kind == charType)))
10173 Identifier id = exp.member.member;
10174 TypeKind typeKind = type.kind;
10175 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10176 if(typeKind == subClassType && exp.member.exp.type == classExp)
10178 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10179 typeKind = classType;
10184 if(typeKind == intType || typeKind == enumType)
10185 _class = eSystem_FindClass(privateModule, "int");
10188 if(type.kind == classType && type._class && type._class.registered)
10190 _class = type._class.registered;
10192 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10194 _class = FindClass("char *").registered;
10196 else if(type.kind == pointerType)
10198 _class = eSystem_FindClass(privateModule, "uintptr");
10199 FreeType(exp.expType);
10200 exp.expType = ProcessTypeString("uintptr", false);
10201 exp.byReference = true;
10205 char string[1024] = "";
10207 PrintTypeNoConst(type, string, false, true);
10208 classSym = FindClass(string);
10209 if(classSym) _class = classSym.registered;
10217 (exp.member.exp.type == identifierExp &&
10218 !strcmp(exp.member.exp.identifier.string, "this"));*/
10219 Property prop = null;
10220 Method method = null;
10221 DataMember member = null;
10222 Property revConvert = null;
10223 ClassProperty classProp = null;
10225 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10226 exp.member.memberType = propertyMember;
10228 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10229 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10231 if(typeKind != subClassType)
10233 // Prioritize data members over properties for "this"
10234 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10236 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10237 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10239 prop = eClass_FindProperty(_class, id.string, privateModule);
10243 if(!member && !prop)
10244 prop = eClass_FindProperty(_class, id.string, privateModule);
10245 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10246 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10247 exp.member.thisPtr = true;
10249 // Prioritize properties over data members otherwise
10252 bool useMemberForNonConst = false;
10253 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10256 prop = eClass_FindProperty(_class, id.string, null);
10258 useMemberForNonConst = prop && exp.destType &&
10259 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10260 !strncmp(prop.dataTypeString, "const ", 6);
10262 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10263 member = eClass_FindDataMember(_class, id.string, null, null, null);
10266 if((!prop || useMemberForNonConst) && !member)
10268 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10271 prop = eClass_FindProperty(_class, id.string, privateModule);
10273 useMemberForNonConst |= prop && exp.destType &&
10274 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10275 !strncmp(prop.dataTypeString, "const ", 6);
10277 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10278 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10284 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10291 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10292 method = eClass_FindMethod(_class, id.string, privateModule);
10293 if(!prop && !member && !method)
10295 if(typeKind == subClassType)
10297 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10300 exp.member.memberType = classPropertyMember;
10301 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10305 // Assume this is a class_data member
10306 char structName[1024];
10307 Identifier id = exp.member.member;
10308 Expression classExp = exp.member.exp;
10311 FreeType(classExp.expType);
10312 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10314 strcpy(structName, "__ecereClassData_");
10315 FullClassNameCat(structName, type._class.string, false);
10316 exp.type = pointerExp;
10317 exp.member.member = id;
10319 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10320 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10321 MkExpBrackets(MkListOne(MkExpOp(
10322 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10323 MkExpMember(classExp, MkIdentifier("data"))), '+',
10324 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10329 ProcessExpressionType(exp);
10335 // Check for reverse conversion
10336 // (Convert in an instantiation later, so that we can use
10337 // deep properties system)
10338 Symbol classSym = FindClass(id.string);
10341 Class convertClass = classSym.registered;
10343 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10348 //if(!exp.member.exp.destType)
10349 if(exp.member.exp.destType)
10350 FreeType(exp.member.exp.destType);
10352 if(method && !method._class.symbol)
10353 method._class.symbol = FindClass(method._class.fullName);
10354 if(prop && !prop._class.symbol)
10355 prop._class.symbol = FindClass(prop._class.fullName);
10357 exp.member.exp.destType = Type
10361 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10362 // wasThisClass = type ? type.wasThisClass : false;
10363 thisClassFrom = type ? type.thisClassFrom : null;
10369 exp.member.memberType = propertyMember;
10371 ProcessPropertyType(prop);
10372 exp.expType = prop.dataType;
10373 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10376 CopyTypeInto(type, exp.expType);
10378 type.constant = true;
10379 exp.expType = type;
10381 else if(prop.dataType)
10382 prop.dataType.refCount++;
10386 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10388 FreeExpContents(exp);
10389 exp.type = identifierExp;
10390 exp.identifier = MkIdentifier("class");
10391 ProcessExpressionType(exp);
10395 exp.member.memberType = dataMember;
10396 DeclareStruct(curExternal, _class.fullName, false, true);
10397 if(member._class != _class)
10398 DeclareStruct(curExternal, member._class.fullName, false, true);
10400 if(!member.dataType)
10402 Context context = SetupTemplatesContext(_class);
10403 member.dataType = ProcessTypeString(member.dataTypeString, false);
10404 FinishTemplatesContext(context);
10406 if(exp.member.exp.expType.kind == classType && exp.member.exp.expType._class && exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == bitClass)
10407 member.dataType.bitMemberSize = ((BitMember)member).size;
10408 exp.expType = member.dataType;
10409 if(member.dataType) member.dataType.refCount++;
10411 else if(revConvert)
10413 exp.member.memberType = reverseConversionMember;
10414 exp.expType = MkClassType(revConvert._class.fullName);
10422 exp.type = identifierExp;
10423 exp.identifier = exp.member.member;
10426 exp.member.memberType = methodMember;
10428 if(!method.dataType)
10429 ProcessMethodType(method);
10437 // Tricky spot here... To use instance versus class virtual table
10438 // Put it back to what it was... What did we break?
10440 // Had to put it back for overriding Main of Thread global instance
10442 //exp.expType.methodClass = _class;
10443 exp.expType.methodClass = (id && id._class) ? _class : null;
10445 // Need the actual class used for templated classes
10446 exp.expType.usedClass = _class;
10448 else if(!classProp)
10450 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10452 FreeExpContents(exp);
10453 exp.type = identifierExp;
10454 exp.identifier = MkIdentifier("class");
10455 FreeType(exp.expType);
10456 exp.expType = MkClassType("ecere::com::Class");
10459 yylloc = exp.member.member.loc;
10460 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10462 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10465 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10469 tClass = type._class && type._class.registered ? type._class.registered : _class;
10470 while(tClass && !tClass.templateClass) tClass = tClass.base;
10472 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10475 ClassTemplateParameter curParam = null;
10478 for(sClass = tClass; sClass; sClass = sClass.base)
10481 if(sClass.templateClass) sClass = sClass.templateClass;
10482 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10484 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10486 for(sClass = sClass.base; sClass; sClass = sClass.base)
10487 id += sClass.templateParams.count;
10492 if(curParam) break;
10495 if(curParam && tClass.templateArgs[id].dataTypeString)
10497 ClassTemplateArgument arg = tClass.templateArgs[id];
10498 Context context = SetupTemplatesContext(tClass);
10499 bool constant = exp.expType.constant;
10500 bool passAsTemplate = false;
10501 Class thisClassFrom = null;
10502 Type t = ProcessTypeString(exp.expType.templateParameter.dataTypeString, false);
10503 if(t && t.kind == classType && t._class)
10504 thisClassFrom = t._class.registered;
10506 // Mark that 'thisClassFrom' was set to something
10507 thisClassFrom = eSystem_FindClass(GetPrivateModule(), "class");
10511 passAsTemplate = tClass.templateClass && (exp.expType.kind != templateType ||
10512 (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType)));
10514 /*if(!arg.dataType)
10515 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10516 FreeType(exp.expType);
10518 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10519 exp.expType.thisClassFrom = thisClassFrom;
10520 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10521 else if(exp.expType.kind == pointerType)
10523 Type t = exp.expType.type;
10524 while(t.kind == pointerType) t = t.type;
10525 if(constant) t.constant = constant;
10529 if(exp.expType.kind == thisClassType)
10531 FreeType(exp.expType);
10532 exp.expType = ReplaceThisClassType(_class);
10536 exp.expType.passAsTemplate = true;
10537 //exp.expType.refCount++;
10540 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10541 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10542 else if(exp.destType.kind == pointerType)
10544 Type t = exp.destType.type;
10545 while(t.kind == pointerType) t = t.type;
10546 if(constant) t.constant = constant;
10549 //exp.destType.refCount++;
10551 if(exp.destType.kind == thisClassType)
10553 FreeType(exp.destType);
10554 exp.destType = ReplaceThisClassType(_class);
10558 FinishTemplatesContext(context);
10561 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10562 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10565 ClassTemplateParameter curParam = null;
10568 for(sClass = tClass; sClass; sClass = sClass.base)
10571 if(sClass.templateClass) sClass = sClass.templateClass;
10572 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10574 if(curParam.type == TemplateParameterType::type &&
10575 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10577 for(sClass = sClass.base; sClass; sClass = sClass.base)
10578 id += sClass.templateParams.count;
10583 if(curParam) break;
10588 ClassTemplateArgument arg = tClass.templateArgs[id];
10589 Context context = SetupTemplatesContext(tClass);
10591 /*if(!arg.dataType)
10592 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10594 basicType = ProcessTypeString(arg.dataTypeString, false);
10597 if(basicType.kind == thisClassType)
10599 FreeType(basicType);
10600 basicType = ReplaceThisClassType(_class);
10603 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10604 if(tClass.templateClass)
10605 basicType.passAsTemplate = true;
10608 FreeType(exp.expType);
10610 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10611 //exp.expType.refCount++;
10614 exp.destType = exp.expType;
10615 exp.destType.refCount++;
10619 Expression newExp { };
10620 OldList * specs = MkList();
10622 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10624 if(exp.destType) exp.destType.refCount++;
10625 if(exp.expType) exp.expType.refCount++;
10626 exp.type = castExp;
10627 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10628 exp.cast.exp = newExp;
10629 //FreeType(exp.expType);
10630 //exp.expType = null;
10631 //ProcessExpressionType(sourceExp);
10634 FinishTemplatesContext(context);
10637 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10639 Class expClass = exp.expType._class.registered;
10642 Class cClass = null;
10644 int paramCount = 0;
10645 int lastParam = -1;
10646 char templateString[1024];
10647 ClassTemplateParameter param;
10648 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10649 while(cClass != expClass)
10652 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10655 for(param = cClass.templateParams.first; param; param = param.next)
10657 Class cClassCur = null;
10659 ClassTemplateParameter paramCur = null;
10660 ClassTemplateArgument arg;
10661 while(cClassCur != tClass && !paramCur)
10664 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10665 cClassCur = sClassCur;
10667 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10669 if(!strcmp(paramCur.name, param.name))
10677 if(paramCur && paramCur.type == TemplateParameterType::type)
10678 arg = tClass.templateArgs[cp];
10680 arg = expClass.templateArgs[p];
10683 char argument[256];
10684 argument[0] = '\0';
10687 strcat(argument, arg.name.string);
10688 strcat(argument, " = ");
10694 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10695 char expString[1024];
10696 OldList * specs = MkList();
10697 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10699 char * string = PrintHexUInt64(arg.expression.ui64);
10700 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10703 ProcessExpressionType(exp);
10704 ComputeExpression(exp);
10705 expString[0] = '\0';
10706 PrintExpression(exp, expString);
10707 strcat(argument, expString);
10709 FreeExpression(exp);
10714 strcat(argument, arg.member.name);
10717 case TemplateParameterType::type:
10719 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10720 strcat(argument, arg.dataTypeString);
10726 if(paramCount) strcat(templateString, ", ");
10727 if(lastParam != p - 1)
10729 strcat(templateString, param.name);
10730 strcat(templateString, " = ");
10732 strcat(templateString, argument);
10741 int len = strlen(templateString);
10742 if(templateString[len-1] == '>') templateString[len++] = ' ';
10743 templateString[len++] = '>';
10744 templateString[len++] = '\0';
10747 FreeType(exp.expType);
10749 Context context = SetupTemplatesContext(tClass);
10750 exp.expType = ProcessTypeString(templateString, false);
10751 FinishTemplatesContext(context);
10758 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10760 else if(type && (type.kind == structType || type.kind == unionType))
10762 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10765 exp.expType = memberType;
10767 memberType.refCount++;
10772 char expString[10240];
10773 expString[0] = '\0';
10774 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10775 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10778 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10780 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10782 Identifier id = exp.member.member;
10783 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10786 FreeType(exp.expType);
10787 exp.expType = ReplaceThisClassType(_class);
10791 yylloc = oldyylloc;
10794 // Convert x->y into (*x).y
10797 Type destType = exp.destType;
10799 // DOING THIS LATER NOW...
10800 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10802 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10803 /* TODO: Name Space Fix ups
10804 if(!exp.member.member.classSym)
10805 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10809 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10810 exp.type = memberExp;
10813 ProcessExpressionType(exp);
10820 //ComputeExpression(exp);
10822 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10823 if(classSym && classSym.registered)
10825 if(classSym.registered.type == noHeadClass || (classSym.registered.fixed && classSym.registered.structSize))
10828 Class b = classSym.registered;
10830 DeclareStruct(curExternal, classSym.string, false, true);
10831 FreeSpecifier(exp._class);
10832 FullClassNameCat(name, classSym.string, false);
10836 exp.type = typeSizeExp;
10837 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10843 if(b.structSize == b.offset)
10844 exp.op.exp1 = MkExpConstant("0");
10846 exp.op.exp1 = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10849 while(b.offset != 0)
10852 Expression typeSize;
10855 sym = FindClass(b.fullName);
10858 DeclareStruct(curExternal, sym.string, false, true);
10859 FullClassNameCat(name, sym.string, false);
10861 if(b.structSize == b.offset)
10862 typeSize = MkExpConstant("0");
10864 typeSize = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10865 e.op.exp2 = b.offset ? MkExpOp(typeSize, '+', null) : typeSize;
10872 if(classSym.registered.fixed && !classSym.registered.structSize)
10874 FreeSpecifier(exp._class);
10875 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10876 exp.type = constantExp;
10880 char className[1024];
10881 strcpy(className, "__ecereClass_");
10882 FullClassNameCat(className, classSym.string, true);
10884 DeclareClass(curExternal, classSym, className);
10886 FreeExpContents(exp);
10887 exp.type = pointerExp;
10888 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10889 exp.member.member = MkIdentifier("structSize");
10897 kind = intSizeType;
10899 // exp.isConstant = true;
10904 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10909 kind = intSizeType;
10911 exp.isConstant = true;
10913 DeclareType(curExternal, type, true, false);
10919 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10921 FreeType(exp.cast.exp.destType);
10922 exp.cast.exp.destType = type;
10924 type.casted = true;
10925 ProcessExpressionType(exp.cast.exp);
10926 type.casted = false;
10928 exp.expType = type;
10931 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10932 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10934 void * prev = exp.prev, * next = exp.next;
10935 Type expType = exp.cast.exp.destType;
10936 Expression castExp = exp.cast.exp;
10937 Type destType = exp.destType;
10939 if(expType) expType.refCount++;
10941 //FreeType(exp.destType);
10942 FreeType(exp.expType);
10943 FreeTypeName(exp.cast.typeName);
10946 FreeType(exp.expType);
10947 FreeType(exp.destType);
10949 exp.expType = expType;
10950 exp.destType = destType;
10960 exp.isConstant = exp.cast.exp.isConstant;
10965 case extensionInitializerExp:
10967 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10968 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10969 // ProcessInitializer(exp.initializer.initializer, type);
10970 exp.expType = type;
10975 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10976 ProcessExpressionType(exp.vaArg.exp);
10977 exp.expType = type;
10983 Type t = exp.destType;
10984 if(t && !exp.destType.casted)
10987 CopyTypeInto(t, exp.destType);
10993 exp.isConstant = true;
10995 FreeType(exp.cond.cond.destType);
10996 exp.cond.cond.destType = MkClassType("bool");
10997 exp.cond.cond.destType.truth = true;
10998 ProcessExpressionType(exp.cond.cond);
10999 if(!exp.cond.cond.isConstant)
11000 exp.isConstant = false;
11001 for(e = exp.cond.exp->first; e; e = e.next)
11005 FreeType(e.destType);
11007 if(e.destType) e.destType.refCount++;
11009 ProcessExpressionType(e);
11012 exp.expType = e.expType;
11013 if(e.expType) e.expType.refCount++;
11016 exp.isConstant = false;
11019 FreeType(exp.cond.elseExp.destType);
11020 // Added this check if we failed to find an expType
11021 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
11024 exp.cond.elseExp.destType = t ? t : exp.expType;
11026 if(exp.cond.elseExp.destType)
11027 exp.cond.elseExp.destType.refCount++;
11028 ProcessExpressionType(exp.cond.elseExp);
11030 // FIXED THIS: Was done before calling process on elseExp
11031 if(!exp.cond.elseExp.isConstant)
11032 exp.isConstant = false;
11037 case extensionCompoundExp:
11039 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
11041 Statement last = exp.compound.compound.statements->last;
11042 if(last.type == expressionStmt && last.expressions && last.expressions->last)
11044 ((Expression)last.expressions->last).destType = exp.destType;
11046 exp.destType.refCount++;
11048 ProcessStatement(exp.compound);
11049 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
11051 exp.expType.refCount++;
11057 Specifier spec = exp._classExp.specifiers->first;
11058 if(spec && spec.type == nameSpecifier)
11060 exp.expType = MkClassType(spec.name);
11061 exp.expType.kind = subClassType;
11062 exp.byReference = true;
11066 exp.expType = MkClassType("ecere::com::Class");
11067 exp.byReference = true;
11073 Class _class = thisClass ? thisClass : currentClass;
11076 Identifier id = exp.classData.id;
11077 char structName[1024];
11078 Expression classExp;
11079 strcpy(structName, "__ecereClassData_");
11080 FullClassNameCat(structName, _class.fullName, false);
11081 exp.type = pointerExp;
11082 exp.member.member = id;
11083 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
11084 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
11086 classExp = MkExpIdentifier(MkIdentifier("class"));
11088 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
11089 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
11090 MkExpBrackets(MkListOne(MkExpOp(
11091 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
11092 MkExpMember(classExp, MkIdentifier("data"))), '+',
11093 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
11096 ProcessExpressionType(exp);
11104 const char * typeString = null;
11105 char typeStringBuf[1024];
11106 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
11107 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
11109 Class templateClass = exp.destType._class.registered;
11110 typeString = templateClass.templateArgs[2].dataTypeString;
11114 // Guess type from expressions in the array
11116 for(e = exp.list->first; e; e = e.next)
11118 ProcessExpressionType(e);
11121 if(!type) { type = e.expType; type.refCount++; }
11124 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11125 if(!MatchTypeExpression(e, type, null, false, true))
11131 e = exp.list->first;
11132 ProcessExpressionType(e);
11135 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
11136 if(!MatchTypeExpression(e, type, null, false, true))
11138 FreeType(e.expType);
11149 FreeType(e.expType);
11156 typeStringBuf[0] = '\0';
11157 PrintTypeNoConst(type, typeStringBuf, false, true);
11158 typeString = typeStringBuf;
11166 (Container)& (struct BuiltInContainer)
11168 ._vTbl = class(BuiltInContainer)._vTbl,
11169 ._class = class(BuiltInContainer),
11171 .data = (int[]){ 1, 7, 3, 4, 5 },
11173 .type = class(int),
11176 char templateString[1024];
11177 OldList * initializers = MkList();
11178 OldList * structInitializers = MkList();
11179 OldList * specs = MkList();
11181 Declarator decl = SpecDeclFromString(typeString, specs, null);
11182 sprintf(templateString, "Container<%s>", typeString);
11187 type = ProcessTypeString(typeString, false);
11188 while((e = exp.list->first))
11190 exp.list->Remove(e);
11193 ProcessExpressionType(e);
11194 ListAdd(initializers, MkInitializerAssignment(e));
11200 DeclareStruct(curExternal, "ecere::com::BuiltInContainer", false, true);
11202 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11203 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11204 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11205 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11206 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11207 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11208 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11209 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11210 MkInitializerList(initializers))));
11211 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11212 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11213 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11214 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11215 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11216 exp.expType = ProcessTypeString(templateString, false);
11217 exp.type = bracketsExp;
11218 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11220 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11221 MkInitializerList(structInitializers)))));
11222 ProcessExpressionType(expExt);
11226 exp.expType = ProcessTypeString("Container", false);
11227 Compiler_Error($"Couldn't determine type of array elements\n");
11233 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11235 FreeType(exp.expType);
11236 exp.expType = ReplaceThisClassType(thisClass);
11239 // Resolve structures here
11240 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11242 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11243 // TODO: Fix members reference...
11246 if(exp.expType.kind != enumType)
11249 String enumName = CopyString(exp.expType.enumName);
11251 // Fixed a memory leak on self-referencing C structs typedefs
11252 // by instantiating a new type rather than simply copying members
11253 // into exp.expType
11254 FreeType(exp.expType);
11255 exp.expType = Type { };
11256 exp.expType.kind = symbol.type.kind;
11257 exp.expType.refCount++;
11258 exp.expType.enumName = enumName;
11260 exp.expType.members = symbol.type.members;
11261 for(member = symbol.type.members.first; member; member = member.next)
11266 NamedLink64 member;
11267 for(member = symbol.type.members.first; member; member = member.next)
11269 NamedLink64 value { name = CopyString(member.name) };
11270 exp.expType.members.Add(value);
11276 // Trying to do this here before conversion properties kick in and this becomes a new expression... (Fixing Class c; const char * a = c;)
11277 // Mark nohead classes as by reference, unless we're casting them to an integral type
11278 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11279 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11280 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11281 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11283 exp.byReference = true;
11287 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11288 else if(exp.destType && !exp.destType.keepCast)
11290 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11291 exp.needTemplateCast = 1;
11293 if(exp.destType.kind == voidType);
11294 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11296 // Warn for casting unrelated types to/from struct classes
11297 bool invalidCast = false;
11298 if(inCompiler && exp.destType.count && exp.expType)
11300 Class c1 = (exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
11301 Class c2 = (exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
11302 if(c1 && c1.type != structClass) c1 = null;
11303 if(c2 && c2.type != structClass) c2 = null;
11304 if((c1 && !exp.expType.byReference && !c2 && !exp.destType.isPointerType) || (c2 && !exp.destType.byReference && !c1 && !exp.expType.isPointerType))
11305 invalidCast = true;
11307 if(!exp.destType.count || unresolved || invalidCast)
11312 if(exp.destType.kind != ellipsisType)
11318 char expString[10240];
11319 expString[0] = '\0';
11321 PrintType(exp.destType, type2, false, true);
11323 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11325 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11326 else if(exp.type != dummyExp)
11327 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11332 char expString[10240] ;
11333 expString[0] = '\0';
11334 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11337 Compiler_Error($"unresolved identifier %s\n", expString);
11338 else if(exp.type != dummyExp)
11339 Compiler_Error($"couldn't determine type of %s\n", expString);
11350 PrintType(exp.expType, type1, false, true);
11351 PrintType(exp.destType, type2, false, true);
11354 //CheckExpressionType(exp, exp.destType, false);
11356 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11357 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11358 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11361 Expression nbExp = GetNonBracketsExp(exp);
11362 bool skipWarning = false;
11363 TypeKind kind = exp.destType.kind;
11364 if(nbExp.type == conditionExp && nbExp.destType && !nbExp.destType.casted && nbExp.destType.kind == exp.destType.kind)
11365 // The if/else operands have already been checked / warned about
11366 skipWarning = true;
11367 if((kind == charType || kind == shortType) && exp.destType.isSigned == exp.expType.signedBeforePromotion && nbExp.type == opExp && nbExp.op.exp1 && nbExp.op.exp2)
11369 int op = nbExp.op.op;
11370 Expression nbExp1, nbExp2;
11375 case '%': case '/':
11376 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11377 from = nbExp1.expType.promotedFrom;
11378 // Division and Modulo will not take more room than type before promotion
11379 if(from == charType || (kind == shortType && from == shortType))
11380 skipWarning = true;
11383 case LEFT_OP: case RIGHT_OP:
11384 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11385 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11386 from = nbExp1.expType.promotedFrom;
11387 // Right shift will not take more room than type before promotion
11388 if(op == RIGHT_OP && (from == charType || (kind == shortType && from == shortType)))
11389 skipWarning = true;
11390 else if(nbExp2.isConstant && nbExp2.type == constantExp && (nbExp.op.op == RIGHT_OP || nbExp1.expType.bitMemberSize))
11392 int n = (int)strtol(nbExp2.constant, null, 0);
11393 int s = from == charType ? 8 : 16;
11394 // Left shifting a bit member constrained in size may still fit in type before promotion
11395 if(nbExp1.expType.bitMemberSize && nbExp1.expType.bitMemberSize < s)
11396 s = nbExp1.expType.bitMemberSize;
11398 // If right shifted enough things will fit in smaller type
11399 if(nbExp.op.op == RIGHT_OP)
11403 if(s <= (kind == charType ? 8 : 16))
11404 skipWarning = true;
11408 if(!exp.destType.isSigned)
11410 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11411 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11412 from = nbExp2.expType.promotedFrom;
11413 // Max value of unsigned type before promotion minus the same will always fit
11414 if((from == charType || from == shortType) && nbExp1.isConstant && nbExp1.type == constantExp)
11416 int n = (int)strtol(nbExp1.constant, null, 0);
11417 if(n == (from == charType ? 255 : 65535))
11418 skipWarning = true;
11424 TypeKind kind1, kind2;
11425 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11426 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11427 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11428 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11429 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) &&
11430 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11431 skipWarning = true;
11436 TypeKind kind1, kind2;
11437 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11438 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11439 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11440 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11441 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) ||
11442 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11443 skipWarning = true;
11451 char expString[10240];
11452 expString[0] = '\0';
11453 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11456 CheckExpressionType(exp, exp.destType, false, true);
11459 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11460 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11461 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11462 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11463 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11466 Compiler_Error($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11468 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11472 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11475 FreeType(exp.expType);
11476 exp.destType.refCount++;
11477 exp.expType = exp.destType;
11483 // Cast function pointers to void * as eC already checked compatibility
11484 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11485 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11487 Expression nbExp = GetNonBracketsExp(exp);
11488 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11490 Expression e = MoveExpContents(exp);
11491 exp.cast.exp = MkExpBrackets(MkListOne(e));
11492 exp.type = castExp;
11493 exp.cast.exp.destType = exp.destType;
11494 if(exp.destType) exp.destType.refCount++;
11495 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11499 else if(unresolved)
11501 if(exp.identifier._class && exp.identifier._class.name)
11502 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11503 else if(exp.identifier.string && exp.identifier.string[0])
11504 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11506 else if(!exp.expType && exp.type != dummyExp)
11508 char expString[10240];
11509 expString[0] = '\0';
11510 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11511 Compiler_Error($"couldn't determine type of %s\n", expString);
11514 // Let's try to support any_object & typed_object here:
11516 ApplyAnyObjectLogic(exp);
11518 // Mark nohead classes as by reference, unless we're casting them to an integral type
11519 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11520 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11521 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11522 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11524 exp.byReference = true;
11526 yylloc = oldyylloc;
11529 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11531 // THIS CODE WILL FIND NEXT MEMBER...
11534 *curMember = (*curMember).next;
11536 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11538 *curMember = subMemberStack[--(*subMemberStackPos)];
11539 *curMember = (*curMember).next;
11542 // SKIP ALL PROPERTIES HERE...
11543 while((*curMember) && (*curMember).isProperty)
11544 *curMember = (*curMember).next;
11546 if(subMemberStackPos)
11548 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11550 subMemberStack[(*subMemberStackPos)++] = *curMember;
11552 *curMember = (*curMember).members.first;
11553 while(*curMember && (*curMember).isProperty)
11554 *curMember = (*curMember).next;
11562 if(subMemberStackPos && *subMemberStackPos)
11564 *curMember = subMemberStack[--(*subMemberStackPos)];
11565 *curMember = (*curMember).next;
11569 Class lastCurClass = *curClass;
11571 if(*curClass == _class) break; // REACHED THE END
11573 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11574 *curMember = (*curClass).membersAndProperties.first;
11577 while((*curMember) && (*curMember).isProperty)
11578 *curMember = (*curMember).next;
11579 if(subMemberStackPos)
11581 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11583 subMemberStack[(*subMemberStackPos)++] = *curMember;
11585 *curMember = (*curMember).members.first;
11586 while(*curMember && (*curMember).isProperty)
11587 *curMember = (*curMember).next;
11595 static void ProcessInitializer(Initializer init, Type type)
11599 case expInitializer:
11600 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11602 // TESTING THIS FOR SHUTTING = 0 WARNING
11603 if(init.exp && !init.exp.destType)
11605 FreeType(init.exp.destType);
11606 init.exp.destType = type;
11607 if(type) type.refCount++;
11611 ProcessExpressionType(init.exp);
11612 init.isConstant = init.exp.isConstant;
11618 Expression exp = init.exp;
11619 Instantiation inst = exp.instance;
11620 MembersInit members;
11622 init.type = listInitializer;
11623 init.list = MkList();
11627 for(members = inst.members->first; members; members = members.next)
11629 if(members.type == dataMembersInit)
11632 for(member = members.dataMembers->first; member; member = member.next)
11634 ListAdd(init.list, member.initializer);
11635 member.initializer = null;
11638 // Discard all MembersInitMethod
11641 FreeExpression(exp);
11643 case listInitializer:
11646 Type initializerType = null;
11647 Class curClass = null;
11648 DataMember curMember = null;
11649 DataMember subMemberStack[256];
11650 int subMemberStackPos = 0;
11652 if(type && type.kind == arrayType)
11653 initializerType = Dereference(type);
11654 else if(type && (type.kind == structType || type.kind == unionType))
11655 initializerType = type.members.first;
11657 for(i = init.list->first; i; i = i.next)
11659 if(type && type.kind == classType && type._class && type._class.registered)
11661 // 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)
11662 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11663 // TODO: Generate error on initializing a private data member this way from another module...
11666 if(!curMember.dataType)
11667 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11668 initializerType = curMember.dataType;
11671 ProcessInitializer(i, initializerType);
11672 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11673 initializerType = initializerType.next;
11675 init.isConstant = false;
11678 if(type && type.kind == arrayType)
11679 FreeType(initializerType);
11681 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11683 Compiler_Error($"Assigning list initializer to non list\n");
11690 static void ProcessSpecifier(Specifier spec, bool declareStruct, bool warnClasses)
11694 case baseSpecifier:
11696 if(spec.specifier == THISCLASS)
11700 spec.type = nameSpecifier;
11701 spec.name = ReplaceThisClass(thisClass);
11702 spec.symbol = FindClass(spec.name);
11703 ProcessSpecifier(spec, declareStruct, false);
11708 case nameSpecifier:
11710 Symbol symbol = FindType(curContext, spec.name);
11712 DeclareType(curExternal, symbol.type, true, true);
11713 else if(spec.symbol /*&& declareStruct*/)
11715 Class c = spec.symbol.registered;
11716 if(warnClasses && !c)
11717 Compiler_Warning("Undeclared class %s\n", spec.name);
11718 DeclareStruct(curExternal, spec.name, c && c.type == noHeadClass, declareStruct && c && c.type == structClass);
11722 case enumSpecifier:
11727 for(e = spec.list->first; e; e = e.next)
11730 ProcessExpressionType(e.exp);
11733 // Fall through for IDE type processing
11737 case structSpecifier:
11738 case unionSpecifier:
11740 if(spec.definitions)
11743 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11745 ProcessClass(spec.definitions, symbol);
11748 for(def = spec.definitions->first; def; def = def.next)
11750 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11751 ProcessDeclaration(def.decl);
11758 case classSpecifier:
11760 Symbol classSym = FindClass(spec.name);
11761 if(classSym && classSym.registered && classSym.registered.type == structClass)
11762 DeclareStruct(spec.name, false, true);
11770 static void ProcessDeclarator(Declarator decl, bool isFunction)
11774 case identifierDeclarator:
11775 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11777 FreeSpecifier(decl.identifier._class);
11778 decl.identifier._class = null;
11781 case arrayDeclarator:
11783 ProcessExpressionType(decl.array.exp);
11784 case structDeclarator:
11785 case bracketsDeclarator:
11786 case functionDeclarator:
11787 case pointerDeclarator:
11788 case extendedDeclarator:
11789 case extendedDeclaratorEnd:
11791 Identifier id = null;
11792 Specifier classSpec = null;
11793 if(decl.type == functionDeclarator)
11795 id = GetDeclId(decl);
11796 if(id && id._class)
11798 classSpec = id._class;
11802 if(decl.declarator)
11803 ProcessDeclarator(decl.declarator, isFunction);
11804 if(decl.type == functionDeclarator)
11810 qualifiers = MkListOne(classSpec);
11813 if(!decl.function.parameters)
11814 decl.function.parameters = MkList();
11815 decl.function.parameters->Insert(null, param);
11817 if(decl.function.parameters)
11821 for(param = decl.function.parameters->first; param; param = param.next)
11823 if(param.qualifiers)
11826 for(spec = param.qualifiers->first; spec; spec = spec.next)
11828 if(spec.type == baseSpecifier)
11830 if(spec.specifier == TYPED_OBJECT)
11832 Declarator d = param.declarator;
11835 qualifiers = MkListOne(MkSpecifier(VOID));
11836 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11838 if(!d || d.type != pointerDeclarator)
11839 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11841 FreeList(param.qualifiers, FreeSpecifier);
11843 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11844 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11846 DeclareStruct(curExternal, "ecere::com::Class", false, true);
11848 decl.function.parameters->Insert(param, newParam);
11852 else if(spec.specifier == ANY_OBJECT)
11854 Declarator d = param.declarator;
11856 FreeList(param.qualifiers, FreeSpecifier);
11858 param.qualifiers = MkListOne(MkSpecifier(VOID));
11859 if(!d || d.type != pointerDeclarator)
11860 param.qualifiers->Insert(null, MkSpecifier(CONST));
11861 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11864 else if(spec.specifier == THISCLASS)
11868 spec.type = nameSpecifier;
11869 spec.name = ReplaceThisClass(thisClass);
11870 spec.symbol = FindClass(spec.name);
11871 ProcessSpecifier(spec, false, false);
11876 else if(spec.type == nameSpecifier)
11878 ProcessSpecifier(spec, isFunction, true);
11880 else if((spec.type == structSpecifier || spec.type == unionSpecifier) && !spec.definitions && spec.id && spec.id.string)
11882 Declarator d = param.declarator;
11883 if(!d || d.type != pointerDeclarator)
11884 DeclareStruct(curExternal, spec.id.string, false, true);
11889 if(param.declarator)
11890 ProcessDeclarator(param.declarator, false);
11899 static void ProcessDeclaration(Declaration decl, bool warnClasses)
11904 case initDeclaration:
11906 bool declareStruct = false;
11908 lineNum = decl.pos.line;
11909 column = decl.pos.col;
11912 if(decl.declarators)
11916 for(d = decl.declarators->first; d; d = d.next)
11918 Type type, subType;
11919 ProcessDeclarator(d.declarator, false);
11921 type = ProcessType(decl.specifiers, d.declarator);
11925 ProcessInitializer(d.initializer, type);
11927 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11929 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11930 d.initializer.exp.type == instanceExp)
11932 if(type.kind == classType && type._class ==
11933 d.initializer.exp.expType._class)
11935 Instantiation inst = d.initializer.exp.instance;
11936 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11938 d.initializer.exp.instance = null;
11939 if(decl.specifiers)
11940 FreeList(decl.specifiers, FreeSpecifier);
11941 FreeList(decl.declarators, FreeInitDeclarator);
11945 decl.type = instDeclaration;
11950 for(subType = type; subType;)
11952 if(subType.kind == classType)
11954 declareStruct = true;
11957 else if(subType.kind == pointerType)
11959 else if(subType.kind == arrayType)
11960 subType = subType.arrayType;
11970 if(decl.specifiers)
11973 for(s = decl.specifiers->first; s; s = s.next)
11975 ProcessSpecifier(s, declareStruct, true);
11980 case instDeclaration:
11982 ProcessInstantiationType(decl.inst);
11985 case structDeclaration:
11989 bool declareStruct = false;
11991 if(decl.declarators)
11993 for(d = decl.declarators->first; d; d = d.next)
11995 Type type = ProcessType(decl.specifiers, d.declarator);
11997 ProcessDeclarator(d, false);
11998 for(subType = type; subType;)
12000 if(subType.kind == classType)
12002 declareStruct = true;
12005 else if(subType.kind == pointerType)
12007 else if(subType.kind == arrayType)
12008 subType = subType.arrayType;
12015 if(decl.specifiers)
12017 for(spec = decl.specifiers->first; spec; spec = spec.next)
12018 ProcessSpecifier(spec, declareStruct, warnClasses);
12025 static FunctionDefinition curFunction;
12027 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
12029 char propName[1024], propNameM[1024];
12030 char getName[1024], setName[1024];
12033 DeclareProperty(curExternal, prop, setName, getName);
12035 // eInstance_FireWatchers(object, prop);
12036 strcpy(propName, "__ecereProp_");
12037 FullClassNameCat(propName, prop._class.fullName, false);
12038 strcat(propName, "_");
12039 FullClassNameCat(propName, prop.name, true);
12041 strcpy(propNameM, "__ecerePropM_");
12042 FullClassNameCat(propNameM, prop._class.fullName, false);
12043 strcat(propNameM, "_");
12044 FullClassNameCat(propNameM, prop.name, true);
12046 if(prop.isWatchable)
12049 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
12050 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12051 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
12054 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
12055 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
12056 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
12058 DeclareFunctionUtil(curExternal, "eInstance_FireWatchers");
12063 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
12064 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12065 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
12068 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
12069 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
12070 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
12072 DeclareFunctionUtil(curExternal, "eInstance_FireSelfWatchers");
12075 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
12076 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12077 curFunction.propSet.fireWatchersDone = true;
12080 static void ProcessStatement(Statement stmt)
12084 lineNum = stmt.pos.line;
12085 column = stmt.pos.col;
12090 ProcessStatement(stmt.labeled.stmt);
12093 // This expression should be constant...
12094 if(stmt.caseStmt.exp)
12096 FreeType(stmt.caseStmt.exp.destType);
12097 stmt.caseStmt.exp.destType = curSwitchType;
12098 if(curSwitchType) curSwitchType.refCount++;
12099 ProcessExpressionType(stmt.caseStmt.exp);
12100 ComputeExpression(stmt.caseStmt.exp);
12102 if(stmt.caseStmt.stmt)
12103 ProcessStatement(stmt.caseStmt.stmt);
12107 if(stmt.compound.context)
12112 Statement prevCompound = curCompound;
12113 Context prevContext = curContext;
12115 if(!stmt.compound.isSwitch)
12116 curCompound = stmt;
12117 curContext = stmt.compound.context;
12119 if(stmt.compound.declarations)
12121 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
12122 ProcessDeclaration(decl, true);
12124 if(stmt.compound.statements)
12126 for(s = stmt.compound.statements->first; s; s = s.next)
12127 ProcessStatement(s);
12130 curContext = prevContext;
12131 curCompound = prevCompound;
12135 case expressionStmt:
12138 if(stmt.expressions)
12140 for(exp = stmt.expressions->first; exp; exp = exp.next)
12141 ProcessExpressionType(exp);
12149 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
12150 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
12151 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
12152 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
12154 ProcessExpressionType(exp);
12156 if(stmt.ifStmt.stmt)
12157 ProcessStatement(stmt.ifStmt.stmt);
12158 if(stmt.ifStmt.elseStmt)
12159 ProcessStatement(stmt.ifStmt.elseStmt);
12164 Type oldSwitchType = curSwitchType;
12165 if(stmt.switchStmt.exp)
12168 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
12178 e.exp.destType = destType;
12181 ProcessExpressionType(exp);
12184 curSwitchType = exp.expType;
12187 ProcessStatement(stmt.switchStmt.stmt);
12188 curSwitchType = oldSwitchType;
12193 if(stmt.whileStmt.exp)
12197 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
12198 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
12199 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
12200 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
12202 ProcessExpressionType(exp);
12205 if(stmt.whileStmt.stmt)
12206 ProcessStatement(stmt.whileStmt.stmt);
12211 if(stmt.doWhile.exp)
12215 if(stmt.doWhile.exp->last)
12217 FreeType(((Expression)stmt.doWhile.exp->last).destType);
12218 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
12219 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
12221 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
12223 ProcessExpressionType(exp);
12226 if(stmt.doWhile.stmt)
12227 ProcessStatement(stmt.doWhile.stmt);
12233 if(stmt.forStmt.init)
12234 ProcessStatement(stmt.forStmt.init);
12236 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
12238 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
12239 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
12240 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
12243 if(stmt.forStmt.check)
12244 ProcessStatement(stmt.forStmt.check);
12245 if(stmt.forStmt.increment)
12247 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
12248 ProcessExpressionType(exp);
12251 if(stmt.forStmt.stmt)
12252 ProcessStatement(stmt.forStmt.stmt);
12257 Identifier id = stmt.forEachStmt.id;
12258 OldList * exp = stmt.forEachStmt.exp;
12259 OldList * filter = stmt.forEachStmt.filter;
12260 Statement block = stmt.forEachStmt.stmt;
12261 char iteratorType[1024];
12264 bool isBuiltin = exp && exp->last &&
12265 (((Expression)exp->last).type == ExpressionType::arrayExp ||
12266 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
12267 Expression arrayExp;
12268 const char * typeString = null;
12269 int builtinCount = 0;
12271 for(e = exp ? exp->first : null; e; e = e.next)
12275 FreeType(e.destType);
12276 e.destType = ProcessTypeString("Container", false);
12278 if(!isBuiltin || e.next)
12279 ProcessExpressionType(e);
12282 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
12283 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
12284 eClass_IsDerived(source._class.registered, containerClass)))
12286 Class _class = source ? source._class.registered : null;
12288 Expression expIt = null;
12289 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
12290 Class arrayClass = eSystem_FindClass(privateModule, "Array");
12291 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
12292 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
12296 stmt.type = compoundStmt;
12298 stmt.compound.context = Context { };
12299 stmt.compound.context.parent = curContext;
12300 curContext = stmt.compound.context;
12303 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
12305 Class mapClass = eSystem_FindClass(privateModule, "Map");
12306 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
12307 isCustomAVLTree = true;
12308 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
12310 else */if(eClass_IsDerived(source._class.registered, mapClass))
12313 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
12314 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
12316 Class listClass = eSystem_FindClass(privateModule, "List");
12318 isList = eClass_IsDerived(source._class.registered, listClass);
12321 if(inCompiler && isArray)
12324 OldList * specs = MkList();
12325 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12326 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12327 stmt.compound.declarations = MkListOne(
12328 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12329 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12330 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12331 MkInitializerAssignment(MkExpBrackets(exp))))));
12336 char typeStringBuf[1024];
12338 // TODO: Merge this code?
12339 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12340 if(((Expression)exp->last).type == castExp)
12342 TypeName typeName = ((Expression)exp->last).cast.typeName;
12344 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12347 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12348 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12349 arrayExp.destType._class.registered.templateArgs)
12351 Class templateClass = arrayExp.destType._class.registered;
12352 typeString = templateClass.templateArgs[2].dataTypeString;
12354 else if(arrayExp.list)
12356 // Guess type from expressions in the array
12358 for(e = arrayExp.list->first; e; e = e.next)
12360 ProcessExpressionType(e);
12363 if(!type) { type = e.expType; type.refCount++; }
12366 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12367 if(!MatchTypeExpression(e, type, null, false, true))
12373 e = arrayExp.list->first;
12374 ProcessExpressionType(e);
12377 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12378 if(!MatchTypeExpression(e, type, null, false, true))
12380 FreeType(e.expType);
12391 FreeType(e.expType);
12398 typeStringBuf[0] = '\0';
12399 PrintType(type, typeStringBuf, false, true);
12400 typeString = typeStringBuf;
12408 OldList * initializers = MkList();
12410 OldList * specs = MkList();
12415 builtinCount = arrayExp.list->count;
12416 type = ProcessTypeString(typeString, false);
12417 while((e = arrayExp.list->first))
12419 arrayExp.list->Remove(e);
12422 ProcessExpressionType(e);
12424 ListAdd(initializers, MkInitializerAssignment(e));
12427 delete arrayExp.list;
12429 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12431 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12432 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12434 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12436 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12437 ), MkInitializerList(initializers)))));
12438 FreeList(exp, FreeExpression);
12440 else if(arrayExp.list)
12443 type = ProcessTypeString(typeString, false);
12444 for(e = arrayExp.list->first; e; e = e.next)
12448 ProcessExpressionType(e);
12455 arrayExp.expType = ProcessTypeString("Container", false);
12456 Compiler_Error($"Couldn't determine type of array elements\n");
12461 OldList * specs = MkList();
12463 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12464 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12465 stmt.compound.declarations = MkListOne(
12466 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12467 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12468 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12469 MkInitializerAssignment(MkExpBrackets(exp))))));
12472 else if(inCompiler && isLinkList && !isList)
12475 OldList * specs = MkList();
12476 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12477 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12478 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12479 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12480 MkInitializerAssignment(MkExpBrackets(exp))))));
12482 /*else if(isCustomAVLTree)
12485 OldList * specs = MkList();
12486 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12487 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12488 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12489 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12490 MkInitializerAssignment(MkExpBrackets(exp))))));
12492 else if(inCompiler && _class.templateArgs)
12495 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12497 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12499 stmt.compound.declarations = MkListOne(
12500 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12501 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12502 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12506 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12510 // Reparent sub-contexts in this statement
12514 if(block.compound.context)
12515 block.compound.context.parent = stmt.compound.context;
12518 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12519 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12520 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12521 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12524 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12525 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12528 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12529 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12532 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12533 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12536 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12537 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12540 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12541 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12543 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12546 case expressionStmt:
12552 case badDeclarationStmt:
12553 case fireWatchersStmt:
12554 case stopWatchingStmt:
12562 block = MkIfStmt(filter, block, null);
12566 stmt.compound.statements = MkListOne(MkForStmt(
12567 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12568 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12569 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12570 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12572 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12573 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12574 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12579 //OldList * specs = MkList();
12580 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12582 sprintf(count, "%d", builtinCount);
12584 stmt.compound.statements = MkListOne(MkForStmt(
12585 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12586 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12587 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12588 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12592 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12593 stmt.compound.statements = MkListOne(MkForStmt(
12594 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12595 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12596 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12597 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12600 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12601 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12602 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12604 else if(isLinkList && !isList)
12606 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12607 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12608 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12609 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12611 stmt.compound.statements = MkListOne(MkForStmt(
12612 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12613 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12614 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12619 OldList * specs = MkList();
12620 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12621 stmt.compound.statements = MkListOne(MkForStmt(
12622 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12623 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12624 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12625 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12626 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12629 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12630 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12631 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12633 /*else if(isCustomAVLTree)
12635 stmt.compound.statements = MkListOne(MkForStmt(
12636 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12637 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12638 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12639 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12642 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12643 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12644 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12648 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12649 MkIdentifier("Next")), null)), block));
12651 ProcessExpressionType(expIt);
12652 if(stmt.compound.declarations->first)
12653 ProcessDeclaration(stmt.compound.declarations->first, true);
12656 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12658 ProcessStatement(stmt);
12661 ProcessStatement(stmt.forEachStmt.stmt);
12663 curContext = stmt.compound.context.parent;
12668 Compiler_Error($"Expression is not a container\n");
12681 if(stmt.expressions)
12683 for(exp = stmt.expressions->first; exp; exp = exp.next)
12687 if(curFunction && !curFunction.type)
12688 curFunction.type = ProcessType(
12689 curFunction.specifiers, curFunction.declarator);
12690 FreeType(exp.destType);
12691 // TODO: current property if not compiling
12692 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12693 if(exp.destType) exp.destType.refCount++;
12695 ProcessExpressionType(exp);
12700 case badDeclarationStmt:
12702 ProcessDeclaration(stmt.decl, true);
12708 if(stmt.asmStmt.inputFields)
12710 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12711 if(field.expression)
12712 ProcessExpressionType(field.expression);
12714 if(stmt.asmStmt.outputFields)
12716 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12717 if(field.expression)
12718 ProcessExpressionType(field.expression);
12720 if(stmt.asmStmt.clobberedFields)
12722 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12724 if(field.expression)
12725 ProcessExpressionType(field.expression);
12732 PropertyWatch propWatch;
12733 OldList * watches = stmt._watch.watches;
12734 Expression object = stmt._watch.object;
12735 Expression watcher = stmt._watch.watcher;
12737 ProcessExpressionType(watcher);
12739 ProcessExpressionType(object);
12743 if(watcher || thisClass)
12745 External external = curExternal;
12746 Context context = curContext;
12748 stmt.type = expressionStmt;
12749 stmt.expressions = MkList();
12751 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12753 ClassFunction func;
12754 char watcherName[1024];
12755 Class watcherClass = watcher ?
12756 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12757 External createdExternal;
12759 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12760 if(propWatch.deleteWatch)
12761 strcat(watcherName, "_delete");
12765 for(propID = propWatch.properties->first; propID; propID = propID.next)
12767 strcat(watcherName, "_");
12768 strcat(watcherName, propID.string);
12772 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12774 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12775 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12776 ProcessClassFunctionBody(func, propWatch.compound);
12777 propWatch.compound = null;
12779 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12781 FreeClassFunction(func);
12783 curExternal = createdExternal;
12784 ProcessFunction(createdExternal.function);
12786 if(propWatch.deleteWatch)
12788 OldList * args = MkList();
12789 ListAdd(args, CopyExpression(object));
12790 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12791 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12792 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12796 Class _class = object.expType._class.registered;
12799 for(propID = propWatch.properties->first; propID; propID = propID.next)
12801 char propName[1024];
12802 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12805 char getName[1024], setName[1024];
12806 OldList * args = MkList();
12808 DeclareProperty(createdExternal, prop, setName, getName);
12810 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12811 strcpy(propName, "__ecereProp_");
12812 FullClassNameCat(propName, prop._class.fullName, false);
12813 strcat(propName, "_");
12814 FullClassNameCat(propName, prop.name, true);
12816 ListAdd(args, CopyExpression(object));
12817 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12818 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12819 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12821 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12823 external.CreateUniqueEdge(createdExternal, true);
12826 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12831 Compiler_Error($"Invalid watched object\n");
12834 curExternal = external;
12835 curContext = context;
12838 FreeExpression(watcher);
12840 FreeExpression(object);
12841 FreeList(watches, FreePropertyWatch);
12844 Compiler_Error($"No observer specified and not inside a class\n");
12848 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12850 ProcessStatement(propWatch.compound);
12856 case fireWatchersStmt:
12858 OldList * watches = stmt._watch.watches;
12859 Expression object = stmt._watch.object;
12861 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12862 // printf("%X\n", watches);
12863 // printf("%X\n", stmt._watch.watches);
12865 ProcessExpressionType(object);
12870 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12876 stmt.type = expressionStmt;
12877 stmt.expressions = MkList();
12879 // Check if we're inside a property set
12880 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12882 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12886 //Compiler_Error($"No property specified and not inside a property set\n");
12890 for(propID = watches->first; propID; propID = propID.next)
12892 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12895 CreateFireWatcher(prop, object, stmt);
12898 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12903 // Fire all properties!
12906 for(base = _class; base; base = base.base)
12908 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12910 if(prop.isProperty && prop.isWatchable)
12912 CreateFireWatcher(prop, object, stmt);
12919 FreeExpression(object);
12920 FreeList(watches, FreeIdentifier);
12923 Compiler_Error($"Invalid object specified and not inside a class\n");
12927 case stopWatchingStmt:
12929 OldList * watches = stmt._watch.watches;
12930 Expression object = stmt._watch.object;
12931 Expression watcher = stmt._watch.watcher;
12934 ProcessExpressionType(object);
12936 ProcessExpressionType(watcher);
12939 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12941 if(watcher || thisClass)
12947 stmt.type = expressionStmt;
12948 stmt.expressions = MkList();
12953 // eInstance_StopWatching(object, null, watcher);
12955 ListAdd(args, CopyExpression(object));
12956 ListAdd(args, MkExpConstant("0"));
12957 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12958 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12962 for(propID = watches->first; propID; propID = propID.next)
12964 char propName[1024];
12965 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12968 char getName[1024], setName[1024];
12969 OldList * args = MkList();
12971 DeclareProperty(curExternal, prop, setName, getName);
12973 // eInstance_StopWatching(object, prop, watcher);
12974 strcpy(propName, "__ecereProp_");
12975 FullClassNameCat(propName, prop._class.fullName, false);
12976 strcat(propName, "_");
12977 FullClassNameCat(propName, prop.name, true);
12979 ListAdd(args, CopyExpression(object));
12980 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12981 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12982 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12985 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12990 FreeExpression(object);
12992 FreeExpression(watcher);
12993 FreeList(watches, FreeIdentifier);
12996 Compiler_Error($"Invalid object specified and not inside a class\n");
12999 Compiler_Error($"No observer specified and not inside a class\n");
13006 static void ProcessFunction(FunctionDefinition function)
13008 Identifier id = GetDeclId(function.declarator);
13009 Symbol symbol = function.declarator ? function.declarator.symbol : null;
13010 Type type = symbol ? symbol.type : null;
13011 Class oldThisClass = thisClass;
13012 Context oldTopContext = topContext;
13014 yylloc = function.loc;
13015 // Process thisClass
13017 if(type && type.thisClass)
13019 Symbol classSym = type.thisClass;
13020 Class _class = type.thisClass.registered;
13021 char className[1024];
13022 char structName[1024];
13023 Declarator funcDecl;
13026 bool typedObject = false;
13028 if(_class && !_class.base)
13030 _class = currentClass;
13031 if(_class && !_class.symbol)
13032 _class.symbol = FindClass(_class.fullName);
13033 classSym = _class ? _class.symbol : null;
13034 typedObject = true;
13037 thisClass = _class;
13039 if(inCompiler && _class)
13041 if(type.kind == functionType)
13043 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
13045 //TypeName param = symbol.type.params.first;
13046 Type param = symbol.type.params.first;
13047 symbol.type.params.Remove(param);
13048 //FreeTypeName(param);
13051 if(type.classObjectType != classPointer)
13053 symbol.type.params.Insert(null, MkClassType(_class.fullName));
13054 symbol.type.staticMethod = true;
13055 symbol.type.thisClass = null;
13057 // HIGH DANGER: VERIFYING THIS...
13058 symbol.type.extraParam = false;
13062 strcpy(className, "__ecereClass_");
13063 FullClassNameCat(className, _class.fullName, true);
13066 FullClassNameCat(structName, _class.fullName, false);
13069 funcDecl = GetFuncDecl(function.declarator);
13072 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
13074 TypeName param = funcDecl.function.parameters->first;
13075 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
13077 funcDecl.function.parameters->Remove(param);
13078 FreeTypeName(param);
13082 if(!function.propertyNoThis)
13084 TypeName thisParam = null;
13086 if(type.classObjectType != classPointer)
13088 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13089 if(!funcDecl.function.parameters)
13090 funcDecl.function.parameters = MkList();
13091 funcDecl.function.parameters->Insert(null, thisParam);
13096 if(type.classObjectType != classPointer)
13098 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
13099 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
13102 thisParam = TypeName
13104 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
13105 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
13107 DeclareStruct(curExternal, "ecere::com::Class", false, true);
13108 funcDecl.function.parameters->Insert(null, thisParam);
13113 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13115 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13116 funcDecl = GetFuncDecl(initDecl.declarator);
13119 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
13121 TypeName param = funcDecl.function.parameters->first;
13122 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
13124 funcDecl.function.parameters->Remove(param);
13125 FreeTypeName(param);
13129 if(type.classObjectType != classPointer)
13131 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
13133 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13135 if(!funcDecl.function.parameters)
13136 funcDecl.function.parameters = MkList();
13137 funcDecl.function.parameters->Insert(null, thisParam);
13144 // Add this to the context
13147 if(type.classObjectType != classPointer)
13149 thisSymbol = Symbol
13151 string = CopyString("this");
13152 type = classSym ? MkClassType(classSym.string) : null;
13154 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
13156 if(typedObject && thisSymbol.type)
13158 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
13159 thisSymbol.type.byReference = type.byReference;
13160 thisSymbol.type.typedByReference = type.byReference;
13165 // Pointer to class data
13166 if(inCompiler && _class && _class.type == normalClass && type.classObjectType != classPointer)
13168 DataMember member = null;
13171 for(base = _class; base && base.type != systemClass; base = base.next)
13173 for(member = base.membersAndProperties.first; member; member = member.next)
13174 if(!member.isProperty)
13180 for(member = _class.membersAndProperties.first; member; member = member.next)
13181 if(!member.isProperty)
13185 char pointerName[1024];
13188 Initializer initializer;
13189 Expression exp, bytePtr;
13191 strcpy(pointerName, "__ecerePointer_");
13192 FullClassNameCat(pointerName, _class.fullName, false);
13194 char className[1024];
13195 strcpy(className, "__ecereClass_");
13196 FullClassNameCat(className, classSym.string, true);
13198 DeclareClass(curExternal, classSym, className);
13202 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
13207 if(_class.offset && _class.offset == (_class.base.type == noHeadClass ? _class.base.memberOffset : _class.base.structSize))
13209 e = MkExpClassSize(MkSpecifierName(_class.base.fullName));
13210 ProcessExpressionType(e);
13215 sprintf(string, "%d", _class.offset); // Need Bootstrap Fix
13216 e = MkExpConstant(string);
13218 exp = QBrackets(MkExpOp(bytePtr, '+', e));
13222 // ([bytePtr] + [className]->offset)
13223 exp = QBrackets(MkExpOp(bytePtr, '+',
13224 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
13227 // (this ? [exp] : 0)
13228 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
13232 kind = pointerType;
13233 type = Type { refCount = 1, kind = voidType };
13238 yylloc = function.body.loc;
13239 // ([structName] *) [exp]
13240 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
13241 initializer = MkInitializerAssignment(
13242 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
13244 // [structName] * [pointerName] = [initializer];
13245 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
13248 Context prevContext = curContext;
13250 curContext = function.body.compound.context;
13252 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
13253 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
13254 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
13256 curContext = prevContext;
13260 decl.symbol = null;
13262 if(!function.body.compound.declarations)
13263 function.body.compound.declarations = MkList();
13264 function.body.compound.declarations->Insert(null, decl);
13270 // Loop through the function and replace undeclared identifiers
13271 // which are a member of the class (methods, properties or data)
13272 // by "this.[member]"
13279 FreeSpecifier(id._class);
13282 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13284 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13285 id = GetDeclId(initDecl.declarator);
13287 FreeSpecifier(id._class);
13292 topContext = function.body.compound.context;
13294 FunctionDefinition oldFunction = curFunction;
13295 curFunction = function;
13297 ProcessStatement(function.body);
13299 // If this is a property set and no firewatchers has been done yet, add one here
13300 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
13302 Statement prevCompound = curCompound;
13303 Context prevContext = curContext;
13305 Statement fireWatchers = MkFireWatchersStmt(null, null);
13306 if(!function.body.compound.statements) function.body.compound.statements = MkList();
13307 ListAdd(function.body.compound.statements, fireWatchers);
13309 curCompound = function.body;
13310 curContext = function.body.compound.context;
13312 ProcessStatement(fireWatchers);
13314 curContext = prevContext;
13315 curCompound = prevCompound;
13319 curFunction = oldFunction;
13322 if(function.declarator)
13324 ProcessDeclarator(function.declarator, true);
13327 topContext = oldTopContext;
13328 thisClass = oldThisClass;
13331 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13332 static void ProcessClass(OldList definitions, Symbol symbol)
13335 External external = curExternal;
13336 Class regClass = symbol ? symbol.registered : null;
13338 // Process all functions
13339 for(def = definitions.first; def; def = def.next)
13341 if(def.type == functionClassDef)
13343 if(def.function.declarator)
13344 curExternal = def.function.declarator.symbol.pointerExternal;
13346 curExternal = external;
13348 ProcessFunction((FunctionDefinition)def.function);
13350 else if(def.type == declarationClassDef)
13352 if(def.decl.type == instDeclaration)
13354 thisClass = regClass;
13355 ProcessInstantiationType(def.decl.inst);
13361 Class backThisClass = thisClass;
13362 if(regClass) thisClass = regClass;
13363 ProcessDeclaration(def.decl, symbol ? true : false);
13364 thisClass = backThisClass;
13367 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13369 MemberInit defProperty;
13371 // Add this to the context
13372 Symbol thisSymbol = Symbol
13374 string = CopyString("this");
13375 type = regClass ? MkClassType(regClass.fullName) : null;
13377 globalContext.symbols.Add((BTNode)thisSymbol);
13379 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13381 thisClass = regClass;
13382 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13386 globalContext.symbols.Remove((BTNode)thisSymbol);
13387 FreeSymbol(thisSymbol);
13389 else if(def.type == propertyClassDef && def.propertyDef)
13391 PropertyDef prop = def.propertyDef;
13393 // Add this to the context
13394 thisClass = regClass;
13401 string = CopyString("this");
13402 type = MkClassType(regClass.fullName);
13404 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13407 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13408 ProcessStatement(prop.setStmt);
13416 string = CopyString("this");
13417 type = MkClassType(regClass.fullName);
13419 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13422 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13423 ProcessStatement(prop.getStmt);
13431 string = CopyString("this");
13432 type = MkClassType(regClass.fullName);
13434 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13437 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13438 ProcessStatement(prop.issetStmt);
13443 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13445 PropertyWatch propertyWatch = def.propertyWatch;
13447 thisClass = regClass;
13448 if(propertyWatch.compound)
13452 string = CopyString("this");
13453 type = regClass ? MkClassType(regClass.fullName) : null;
13456 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13458 curExternal = null;
13459 ProcessStatement(propertyWatch.compound);
13466 void DeclareFunctionUtil(External neededBy, const String s)
13468 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13473 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13474 strcpy(name, "__ecereFunction_");
13475 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13476 DeclareFunction(neededBy, function, name);
13479 FindSymbol(s, globalContext, globalContext, false, false);
13482 bool reachedPass15;
13484 void ComputeDataTypes()
13488 currentClass = null;
13490 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13492 DeclareStruct(null, "ecere::com::Class", false, true);
13493 DeclareStruct(null, "ecere::com::Instance", false, true);
13494 DeclareStruct(null, "ecere::com::Property", false, true);
13495 DeclareStruct(null, "ecere::com::DataMember", false, true);
13496 DeclareStruct(null, "ecere::com::Method", false, true);
13497 DeclareStruct(null, "ecere::com::SerialBuffer", false, true);
13498 DeclareStruct(null, "ecere::com::ClassTemplateArgument", false, true);
13500 DeclareFunctionUtil(null, "eSystem_New");
13501 DeclareFunctionUtil(null, "eSystem_New0");
13502 DeclareFunctionUtil(null, "eSystem_Renew");
13503 DeclareFunctionUtil(null, "eSystem_Renew0");
13504 DeclareFunctionUtil(null, "eSystem_Delete");
13505 DeclareFunctionUtil(null, "eClass_GetProperty");
13506 DeclareFunctionUtil(null, "eClass_SetProperty");
13507 DeclareFunctionUtil(null, "eInstance_FireSelfWatchers");
13508 DeclareFunctionUtil(null, "eInstance_SetMethod");
13509 DeclareFunctionUtil(null, "eInstance_IncRef");
13510 DeclareFunctionUtil(null, "eInstance_StopWatching");
13511 DeclareFunctionUtil(null, "eInstance_Watch");
13512 DeclareFunctionUtil(null, "eInstance_FireWatchers");
13513 reachedPass15 = true;
13515 for(external = ast->first; external; external = external.next)
13517 afterExternal = curExternal = external;
13518 if(external.type == functionExternal)
13522 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13523 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13526 currentClass = external.function._class;
13527 ProcessFunction(external.function);
13529 // There shouldn't be any _class member access here anyways...
13530 else if(external.type == declarationExternal)
13532 if(memoryGuard && external.declaration && external.declaration.type == instDeclaration)
13534 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13535 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13538 currentClass = null;
13539 if(external.declaration)
13540 ProcessDeclaration(external.declaration, true);
13542 else if(external.type == classExternal)
13544 ClassDefinition _class = external._class;
13545 currentClass = external.symbol.registered;
13548 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13549 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13551 if(_class.definitions)
13553 ProcessClass(_class.definitions, _class.symbol);
13557 // Free class data...
13558 ast->Remove(external);
13562 else if(external.type == nameSpaceExternal)
13564 thisNameSpace = external.id.string;
13567 currentClass = null;
13568 thisNameSpace = null;
13569 curExternal = null;