4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
37 uint internalValueCounter;
40 Time findSymbolTotalTime;
43 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
44 /*static */public void PrintExpression(Expression exp, char * string)
50 bool backOutputLineNumbers = outputLineNumbers;
51 outputLineNumbers = false;
54 OutputExpression(exp, f);
56 count = strlen(string);
57 count += f.Read(string + count, 1, 1023);
61 outputLineNumbers = backOutputLineNumbers;
65 Type ProcessTemplateParameterType(TemplateParameter param)
67 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
69 // TOFIX: Will need to free this Type
72 if(param.dataTypeString)
73 param.baseType = ProcessTypeString(param.dataTypeString, false);
75 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
77 return param.baseType;
82 bool NeedCast(Type type1, Type type2)
84 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
86 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
91 if(type1.kind == type2.kind)
102 if(type1.passAsTemplate && !type2.passAsTemplate)
104 return type1.isSigned != type2.isSigned;
106 return type1._class != type2._class;
108 return (type1.type && type2.type && type1.type.constant != type2.type.constant) || NeedCast(type1.type, type2.type);
110 return true; //false; ????
116 static void ReplaceClassMembers(Expression exp, Class _class)
118 if(exp.type == identifierExp && exp.identifier)
120 Identifier id = exp.identifier;
122 Symbol symbol = null;
123 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
125 // First, check if the identifier is declared inside the function
126 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
128 symbol = (Symbol)ctx.symbols.FindString(id.string);
133 // If it is not, check if it is a member of the _class
134 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
136 Property prop = eClass_FindProperty(_class, id.string, privateModule);
137 Method method = null;
138 DataMember member = null;
139 ClassProperty classProp = null;
142 method = eClass_FindMethod(_class, id.string, privateModule);
145 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
146 if(!prop && !method && !member)
148 classProp = eClass_FindClassProperty(_class, id.string);
150 if(prop || method || member || classProp)
152 // Replace by this.[member]
153 exp.type = memberExp;
154 exp.member.member = id;
155 exp.member.memberType = unresolvedMember;
156 exp.member.exp = QMkExpId("this");
157 //exp.member.exp.loc = exp.loc;
158 exp.addedThis = true;
160 else if(_class && _class.templateParams.first)
163 for(sClass = _class; sClass; sClass = sClass.base)
165 if(sClass.templateParams.first)
167 ClassTemplateParameter param;
168 for(param = sClass.templateParams.first; param; param = param.next)
170 if(param.type == expression && !strcmp(param.name, id.string))
172 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
177 OldList * specs = MkList();
179 FreeIdentifier(exp.member.member);
181 ProcessExpressionType(argExp);
183 decl = SpecDeclFromString(param.dataTypeString, specs, null);
185 exp.expType = ProcessType(specs, decl);
187 // *[expType] *[argExp]
188 exp.type = bracketsExp;
189 exp.list = MkListOne(MkExpOp(null, '*',
190 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
201 ////////////////////////////////////////////////////////////////////////
202 // PRINTING ////////////////////////////////////////////////////////////
203 ////////////////////////////////////////////////////////////////////////
205 public char * PrintInt(int64 result)
209 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
211 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
212 if(result > MAXINT || result < MININT)
214 return CopyString(temp);
217 public char * PrintUInt(uint64 result)
220 if(result > MAXDWORD)
221 sprintf(temp, FORMAT64HEXLL /*"0x%I64X"*/, result);
222 else if(result > MAXINT)
223 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
225 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
226 return CopyString(temp);
229 public char * PrintInt64(int64 result)
232 if(result > MAXINT || result < MININT)
233 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
235 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
236 return CopyString(temp);
239 public char * PrintUInt64(uint64 result)
242 if(result > MAXDWORD)
243 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
244 else if(result > MAXINT)
245 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
247 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
248 return CopyString(temp);
251 public char * PrintHexUInt(uint64 result)
254 if(result > MAXDWORD)
255 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
257 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
258 if(result > MAXDWORD)
260 return CopyString(temp);
263 public char * PrintHexUInt64(uint64 result)
266 if(result > MAXDWORD)
267 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
269 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
270 return CopyString(temp);
273 public char * PrintShort(short result)
276 sprintf(temp, "%d", (unsigned short)result);
277 return CopyString(temp);
280 public char * PrintUShort(unsigned short result)
284 sprintf(temp, "0x%X", (int)result);
286 sprintf(temp, "%d", (int)result);
287 return CopyString(temp);
290 public char * PrintChar(char result)
293 if(result > 0 && isprint(result))
294 sprintf(temp, "'%c'", result);
296 sprintf(temp, "%d", (int)result);
298 //sprintf(temp, "%#X", result);
299 sprintf(temp, "0x%X", (unsigned char)result);
300 return CopyString(temp);
303 public char * PrintUChar(unsigned char result)
306 sprintf(temp, "0x%X", result);
307 return CopyString(temp);
310 public char * PrintFloat(float result)
316 strcpy(temp, "-inf");
320 else if(result.isNan)
323 strcpy(temp, "-nan");
328 sprintf(temp, "%.16ff", result);
329 return CopyString(temp);
332 public char * PrintDouble(double result)
338 strcpy(temp, "-inf");
342 else if(result.isNan)
345 strcpy(temp, "-nan");
350 sprintf(temp, "%.16f", result);
351 return CopyString(temp);
354 ////////////////////////////////////////////////////////////////////////
355 ////////////////////////////////////////////////////////////////////////
357 //public Operand GetOperand(Expression exp);
359 #define GETVALUE(name, t) \
360 public bool GetOp##name(Operand op2, t * value2) \
362 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
363 else if(op2.kind == intType) *value2 = (t) op2.ui; \
364 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
365 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
366 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
367 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
368 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
369 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
370 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
371 else if(op2.kind == shortType) *value2 = (t) op2.us; \
372 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
373 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
374 else if(op2.kind == floatType) *value2 = (t) op2.f; \
375 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
376 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
381 public bool Get##name(Expression exp, t * value2) \
383 Operand op2 = GetOperand(exp); \
384 return GetOp##name(op2, value2); \
387 // To help the debugger currently not preprocessing...
390 GETVALUE(Int, HELP(int));
391 GETVALUE(UInt, HELP(unsigned int));
392 GETVALUE(Int64, HELP(int64));
393 GETVALUE(UInt64, HELP(uint64));
394 GETVALUE(IntPtr, HELP(intptr));
395 GETVALUE(UIntPtr, HELP(uintptr));
396 GETVALUE(IntSize, HELP(intsize));
397 GETVALUE(UIntSize, HELP(uintsize));
398 GETVALUE(Short, HELP(short));
399 GETVALUE(UShort, HELP(unsigned short));
400 GETVALUE(Char, HELP(char));
401 GETVALUE(UChar, HELP(unsigned char));
402 GETVALUE(Float, HELP(float));
403 GETVALUE(Double, HELP(double));
405 void ComputeExpression(Expression exp);
407 void ComputeClassMembers(Class _class, bool isMember)
409 DataMember member = isMember ? (DataMember) _class : null;
410 Context context = isMember ? null : SetupTemplatesContext(_class);
411 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
412 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
414 int unionMemberOffset = 0;
418 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
419 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
424 member.memberOffset = 0;
425 if(targetBits < sizeof(void *) * 8)
426 member.structAlignment = 0;
428 else if(targetBits < sizeof(void *) * 8)
429 _class.structAlignment = 0;
431 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
432 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
433 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
435 if(!member && _class.destructionWatchOffset)
436 _class.memberOffset += sizeof(OldList);
438 // To avoid reentrancy...
439 //_class.structSize = -1;
442 DataMember dataMember;
443 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
445 if(!dataMember.isProperty)
447 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
449 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
450 /*if(!dataMember.dataType)
451 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
459 DataMember dataMember;
460 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
462 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
464 if(!isMember && _class.type == bitClass && dataMember.dataType)
466 BitMember bitMember = (BitMember) dataMember;
470 ComputeTypeSize(dataMember.dataType);
472 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
473 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
475 _class.memberOffset = bitMember.pos + bitMember.size;
476 for(d = 0; d<bitMember.size; d++)
482 bitMember.mask = mask << bitMember.pos;
484 else if(dataMember.type == normalMember && dataMember.dataType)
489 // Prevent infinite recursion
490 if(dataMember.dataType.kind != classType ||
491 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
492 _class.type != structClass)))
493 ComputeTypeSize(dataMember.dataType);
495 if(dataMember.dataType.bitFieldCount)
497 bitFields += dataMember.dataType.bitFieldCount;
504 int size = (bitFields + 7) / 8;
508 // TESTING THIS PADDING CODE
511 member.structAlignment = Max(member.structAlignment, alignment);
513 if(member.memberOffset % alignment)
514 member.memberOffset += alignment - (member.memberOffset % alignment);
517 dataMember.offset = member.memberOffset;
518 if(member.type == unionMember)
519 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
522 member.memberOffset += size;
527 // TESTING THIS PADDING CODE
530 _class.structAlignment = Max(_class.structAlignment, alignment);
532 if(_class.memberOffset % alignment)
533 _class.memberOffset += alignment - (_class.memberOffset % alignment);
536 dataMember.offset = _class.memberOffset;
537 _class.memberOffset += size;
541 size = dataMember.dataType.size;
542 alignment = dataMember.dataType.alignment;
547 // TESTING THIS PADDING CODE
550 member.structAlignment = Max(member.structAlignment, alignment);
552 if(member.memberOffset % alignment)
553 member.memberOffset += alignment - (member.memberOffset % alignment);
556 dataMember.offset = member.memberOffset;
557 if(member.type == unionMember)
558 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
561 member.memberOffset += size;
566 // TESTING THIS PADDING CODE
569 _class.structAlignment = Max(_class.structAlignment, alignment);
571 if(_class.memberOffset % alignment)
572 _class.memberOffset += alignment - (_class.memberOffset % alignment);
575 dataMember.offset = _class.memberOffset;
576 _class.memberOffset += size;
583 ComputeClassMembers((Class)dataMember, true);
584 alignment = dataMember.structAlignment;
590 if(member.memberOffset % alignment)
591 member.memberOffset += alignment - (member.memberOffset % alignment);
593 member.structAlignment = Max(member.structAlignment, alignment);
595 dataMember.offset = member.memberOffset;
596 if(member.type == unionMember)
597 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
599 member.memberOffset += dataMember.memberOffset;
605 if(_class.memberOffset % alignment)
606 _class.memberOffset += alignment - (_class.memberOffset % alignment);
607 _class.structAlignment = Max(_class.structAlignment, alignment);
609 dataMember.offset = _class.memberOffset;
610 _class.memberOffset += dataMember.memberOffset;
618 int size = (bitFields + 7) / 8;
622 // TESTING THIS PADDING CODE
625 member.structAlignment = Max(member.structAlignment, alignment);
627 if(member.memberOffset % alignment)
628 member.memberOffset += alignment - (member.memberOffset % alignment);
631 if(member.type == unionMember)
632 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
635 member.memberOffset += size;
640 // TESTING THIS PADDING CODE
643 _class.structAlignment = Max(_class.structAlignment, alignment);
645 if(_class.memberOffset % alignment)
646 _class.memberOffset += alignment - (_class.memberOffset % alignment);
648 _class.memberOffset += size;
653 if(member && member.type == unionMember)
655 member.memberOffset = unionMemberOffset;
660 /*if(_class.type == structClass)
661 _class.size = _class.memberOffset;
665 if(_class.type != bitClass)
668 if(_class.structAlignment)
670 if(_class.memberOffset % _class.structAlignment)
671 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
673 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
677 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
679 if(prop.isProperty && prop.isWatchable)
681 prop.watcherOffset = _class.structSize;
682 _class.structSize += sizeof(OldList);
690 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
692 Class deriv = derivative.data;
694 if(deriv.computeSize)
696 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
697 deriv.offset = /*_class.offset + */_class.structSize;
698 deriv.memberOffset = 0;
699 // ----------------------
701 deriv.structSize = deriv.offset;
703 ComputeClassMembers(deriv, false);
711 FinishTemplatesContext(context);
714 public void ComputeModuleClasses(Module module)
719 for(subModule = module.modules.first; subModule; subModule = subModule.next)
720 ComputeModuleClasses(subModule.data);
721 for(_class = module.classes.first; _class; _class = _class.next)
722 ComputeClassMembers(_class, false);
726 public int ComputeTypeSize(Type type)
728 uint size = type ? type.size : 0;
729 if(!size && type && !type.computing)
731 type.computing = true;
734 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
735 case charType: type.alignment = size = sizeof(char); break;
736 case intType: type.alignment = size = sizeof(int); break;
737 case int64Type: type.alignment = size = sizeof(int64); break;
738 case intPtrType: type.alignment = size = targetBits / 8; break;
739 case intSizeType: type.alignment = size = targetBits / 8; break;
740 case longType: type.alignment = size = sizeof(long); break;
741 case shortType: type.alignment = size = sizeof(short); break;
742 case floatType: type.alignment = size = sizeof(float); break;
743 case doubleType: type.alignment = size = sizeof(double); break;
746 Class _class = type._class ? type._class.registered : null;
748 if(_class && _class.type == structClass)
750 // Ensure all members are properly registered
751 ComputeClassMembers(_class, false);
752 type.alignment = _class.structAlignment;
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);
767 size = type.alignment = targetBits / 8; // sizeof(Instance *);
770 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
772 if(type.arraySizeExp)
774 ProcessExpressionType(type.arraySizeExp);
775 ComputeExpression(type.arraySizeExp);
776 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
777 type.arraySizeExp.expType.kind != shortType &&
778 type.arraySizeExp.expType.kind != charType &&
779 type.arraySizeExp.expType.kind != longType &&
780 type.arraySizeExp.expType.kind != int64Type &&
781 type.arraySizeExp.expType.kind != intSizeType &&
782 type.arraySizeExp.expType.kind != intPtrType &&
783 type.arraySizeExp.expType.kind != enumType &&
784 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
786 Location oldLoc = yylloc;
787 // bool isConstant = type.arraySizeExp.isConstant;
788 char expression[10240];
789 expression[0] = '\0';
790 type.arraySizeExp.expType = null;
791 yylloc = type.arraySizeExp.loc;
793 PrintExpression(type.arraySizeExp, expression);
794 Compiler_Error($"Array size not constant int (%s)\n", expression);
797 GetInt(type.arraySizeExp, &type.arraySize);
799 else if(type.enumClass)
801 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
803 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
810 // Unimplemented auto size
814 size = ComputeTypeSize(type.type) * type.arraySize;
816 type.alignment = type.type.alignment;
822 for(member = type.members.first; member; member = member.next)
824 uint addSize = ComputeTypeSize(member);
826 member.offset = size;
827 if(member.alignment && size % member.alignment)
828 member.offset += member.alignment - (size % member.alignment);
829 size = member.offset;
831 type.alignment = Max(type.alignment, member.alignment);
834 if(type.alignment && size % type.alignment)
835 size += type.alignment - (size % type.alignment);
841 for(member = type.members.first; member; member = member.next)
843 uint addSize = ComputeTypeSize(member);
845 member.offset = size;
846 if(member.alignment && size % member.alignment)
847 member.offset += member.alignment - (size % member.alignment);
848 size = member.offset;
850 type.alignment = Max(type.alignment, member.alignment);
851 size = Max(size, addSize);
853 if(type.alignment && size % type.alignment)
854 size += type.alignment - (size % type.alignment);
859 TemplateParameter param = type.templateParameter;
860 Type baseType = ProcessTemplateParameterType(param);
863 size = ComputeTypeSize(baseType);
864 type.alignment = baseType.alignment;
867 type.alignment = size = sizeof(uint64);
872 type.alignment = size = sizeof(enum { test });
877 type.alignment = size = targetBits / 8; //sizeof(void *);
882 type.computing = false;
888 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
890 // This function is in need of a major review when implementing private members etc.
891 DataMember topMember = isMember ? (DataMember) _class : null;
898 Context context = isMember ? null : SetupTemplatesContext(_class);
900 *addedPadding = false;
902 if(!isMember && _class.base)
904 maxSize = _class.structSize;
905 //if(_class.base.type != systemClass) // Commented out with new Instance _class
907 // DANGER: Testing this noHeadClass here...
908 if(_class.type == structClass || _class.type == noHeadClass)
909 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
912 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
913 if(maxSize > baseSize)
921 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
923 if(!member.isProperty)
929 if(member.dataTypeString)
931 OldList * specs = MkList(), * decls = MkList();
934 decl = SpecDeclFromString(member.dataTypeString, specs,
935 MkDeclaratorIdentifier(MkIdentifier(member.name)));
936 ListAdd(decls, MkStructDeclarator(decl, null));
937 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
940 member.dataType = ProcessType(specs, decl);
942 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
945 Type type = ProcessType(specs, decl);
946 DeclareType(member.dataType, false, false);
950 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
951 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
952 DeclareStruct(member.dataType._class.string, false);
955 ComputeTypeSize(member.dataType);
956 size = member.dataType.size;
957 alignment = member.dataType.alignment;
961 if(totalSize % alignment)
962 totalSize += alignment - (totalSize % alignment);
971 OldList * specs = MkList(), * list = MkList();
973 sprintf(id, "__anon%d", anonID++);
976 AddMembers(list, (Class)member, true, &size, topClass, null);
978 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
979 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
980 alignment = member.structAlignment;
984 if(totalSize % alignment)
985 totalSize += alignment - (totalSize % alignment);
995 if(topMember && topMember.type == unionMember)
996 *retSize = Max(*retSize, totalSize);
998 *retSize += totalSize;
1000 else if(totalSize < maxSize && _class.type != systemClass)
1002 int autoPadding = 0;
1003 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1004 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1005 if(totalSize + autoPadding < maxSize)
1007 char sizeString[50];
1008 sprintf(sizeString, "%d", maxSize - totalSize);
1009 ListAdd(declarations,
1010 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1011 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1013 *addedPadding = true;
1017 FinishTemplatesContext(context);
1018 return topMember ? topMember.memberID : _class.memberID;
1021 static int DeclareMembers(Class _class, bool isMember)
1023 DataMember topMember = isMember ? (DataMember) _class : null;
1025 Context context = isMember ? null : SetupTemplatesContext(_class);
1027 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1028 DeclareMembers(_class.base, false);
1030 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1032 if(!member.isProperty)
1039 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1040 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1041 DeclareStruct(member.dataType._class.string, false);
1043 if(!member.dataType && member.dataTypeString)
1044 member.dataType = ProcessTypeString(member.dataTypeString, false);
1046 DeclareType(member.dataType, false, false);
1052 DeclareMembers((Class)member, true);
1059 FinishTemplatesContext(context);
1061 return topMember ? topMember.memberID : _class.memberID;
1064 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1068 for(def = definitions->first; def; def = def.next)
1070 if(def.type == declarationClassDef)
1072 Declaration decl = def.decl;
1073 if(decl && decl.specifiers)
1076 bool isStruct = false;
1077 for(spec = decl.specifiers->first; spec; spec = spec.next)
1079 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1081 if(spec.definitions)
1082 IdentifyAnonStructs(spec.definitions);
1088 Declarator d = null;
1089 if(decl.declarators)
1091 for(d = decl.declarators->first; d; d = d.next)
1093 Identifier idDecl = GetDeclId(d);
1101 sprintf(id, "__anon%d", anonID++);
1102 if(!decl.declarators)
1103 decl.declarators = MkList();
1104 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1112 void DeclareStruct(const char * name, bool skipNoHead)
1114 External external = null;
1115 Symbol classSym = FindClass(name);
1117 if(!inCompiler || !classSym) return;
1119 // We don't need any declaration for bit classes...
1120 if(classSym.registered &&
1121 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1124 /*if(classSym.registered.templateClass)
1125 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1128 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1130 // Add typedef struct
1132 OldList * specifiers, * declarators;
1133 OldList * declarations = null;
1134 char structName[1024];
1135 Specifier spec = null;
1136 external = (classSym.registered && classSym.registered.type == structClass) ?
1137 classSym.pointerExternal : classSym.structExternal;
1139 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1140 // Moved this one up because DeclareClass done later will need it
1142 classSym.declaring++;
1144 if(strchr(classSym.string, '<'))
1146 if(classSym.registered.templateClass)
1148 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1149 classSym.declaring--;
1155 DeclareMembers(classSym.registered, false);
1158 FullClassNameCat(structName, name, false);
1160 if(external && external.declaration && external.declaration.specifiers)
1162 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1164 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1170 external = MkExternalDeclaration(null);*/
1172 if(!skipNoHead && (!spec || !spec.definitions))
1174 bool addedPadding = false;
1175 classSym.declaredStructSym = true;
1177 declarations = MkList();
1179 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1181 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1182 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1184 if(!declarations->count || (declarations->count == 1 && addedPadding))
1186 FreeList(declarations, FreeClassDef);
1187 declarations = null;
1190 if(skipNoHead || declarations)
1195 spec.definitions = declarations;
1197 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1200 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1203 if(classSym.structExternal)
1204 ast->Move(classSym.structExternal, curExternal.prev);
1205 ast->Move(classSym.pointerExternal, curExternal.prev);
1207 classSym.id = curExternal.symbol.idCode;
1208 classSym.idCode = curExternal.symbol.idCode;
1209 // external = classSym.pointerExternal;
1210 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1216 external = MkExternalDeclaration(null);
1218 specifiers = MkList();
1219 declarators = MkList();
1220 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1223 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1224 ListAdd(declarators, MkInitDeclarator(d, null));
1226 external.declaration = decl = MkDeclaration(specifiers, declarators);
1227 if(decl.symbol && !decl.symbol.pointerExternal)
1228 decl.symbol.pointerExternal = external;
1230 // For simple classes, keep the declaration as the external to move around
1231 if(classSym.registered && classSym.registered.type == structClass)
1233 char className[1024];
1234 strcpy(className, "__ecereClass_");
1235 FullClassNameCat(className, classSym.string, true);
1236 //MangleClassName(className);
1239 DeclareClass(classSym, className);
1241 external.symbol = classSym;
1242 classSym.pointerExternal = external;
1243 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1244 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1248 char className[1024];
1249 strcpy(className, "__ecereClass_");
1250 FullClassNameCat(className, classSym.string, true);
1251 //MangleClassName(className);
1253 // TOFIX: TESTING THIS...
1254 classSym.structExternal = external;
1255 DeclareClass(classSym, className);
1256 external.symbol = classSym;
1260 ast->Insert(curExternal ? curExternal.prev : null, external);
1264 classSym.declaring--;
1268 if(classSym.structExternal && classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1271 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1273 IdentifyAnonStructs(spec.definitions);
1277 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1279 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1280 // Moved this one up because DeclareClass done later will need it
1283 classSym.declaring++;
1287 if(classSym.registered)
1288 DeclareMembers(classSym.registered, false);
1291 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1294 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1297 if(classSym.structExternal)
1298 ast->Move(classSym.structExternal, curExternal.prev);
1299 ast->Move(classSym.pointerExternal, curExternal.prev);
1301 classSym.id = curExternal.symbol.idCode;
1302 classSym.idCode = curExternal.symbol.idCode;
1303 // external = classSym.pointerExternal;
1304 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1307 classSym.declaring--;
1313 void DeclareProperty(Property prop, char * setName, char * getName)
1315 Symbol symbol = prop.symbol;
1317 strcpy(setName, "__ecereProp_");
1318 FullClassNameCat(setName, prop._class.fullName, false);
1319 strcat(setName, "_Set_");
1320 // strcat(setName, prop.name);
1321 FullClassNameCat(setName, prop.name, true);
1322 //MangleClassName(setName);
1324 strcpy(getName, "__ecereProp_");
1325 FullClassNameCat(getName, prop._class.fullName, false);
1326 strcat(getName, "_Get_");
1327 FullClassNameCat(getName, prop.name, true);
1328 // strcat(getName, prop.name);
1330 // To support "char *" property
1331 //MangleClassName(getName);
1333 if(prop._class.type == structClass)
1334 DeclareStruct(prop._class.fullName, false);
1336 if(!symbol || curExternal.symbol.idCode < symbol.id)
1338 bool imported = false;
1339 bool dllImport = false;
1341 if(!symbol || symbol._import)
1346 if(!prop._class.symbol)
1347 prop._class.symbol = FindClass(prop._class.fullName);
1348 classSym = prop._class.symbol;
1349 if(classSym && !classSym._import)
1351 ModuleImport module;
1353 if(prop._class.module)
1354 module = FindModule(prop._class.module);
1356 module = mainModule;
1358 classSym._import = ClassImport
1360 name = CopyString(prop._class.fullName);
1361 isRemote = prop._class.isRemote;
1363 module.classes.Add(classSym._import);
1365 symbol = prop.symbol = Symbol { };
1366 symbol._import = (ClassImport)PropertyImport
1368 name = CopyString(prop.name);
1369 isVirtual = false; //prop.isVirtual;
1370 hasSet = prop.Set ? true : false;
1371 hasGet = prop.Get ? true : false;
1374 classSym._import.properties.Add(symbol._import);
1377 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1378 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1379 prop._class.module.importType != staticImport)
1385 Context context = SetupTemplatesContext(prop._class);
1386 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1387 FinishTemplatesContext(context);
1393 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1396 OldList * specifiers, * declarators;
1401 Declarator typeDecl;
1402 bool simple = false;
1404 specifiers = MkList();
1405 declarators = MkList();
1408 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1409 MkDeclaratorIdentifier(MkIdentifier("this"))));
1411 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1414 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1417 Context context = SetupTemplatesContext(prop._class);
1418 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1419 FinishTemplatesContext(context);
1422 // Make sure the simple _class's type is declared
1423 for(spec = specifiers->first; spec; spec = spec.next)
1425 if(spec.type == nameSpecifier /*SpecifierClass*/)
1427 if((!typeDecl || typeDecl.type == identifierDeclarator))
1429 Symbol classSym = spec.symbol; // FindClass(spec.name);
1430 symbol._class = classSym.registered;
1431 if(classSym.registered && classSym.registered.type == structClass)
1433 DeclareStruct(spec.name, false);
1441 d = PlugDeclarator(typeDecl, d);
1444 ListAdd(params, MkTypeName(specifiers,
1445 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1446 specifiers = MkList();
1449 d = MkDeclaratorFunction(d, params);
1453 specifiers->Insert(null, MkSpecifier(EXTERN));
1454 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1455 specifiers->Insert(null, MkSpecifier(STATIC));
1457 ListAdd(specifiers, MkSpecifier(VOID));
1459 ListAdd(declarators, MkInitDeclarator(d, null));
1461 decl = MkDeclaration(specifiers, declarators);
1463 external = MkExternalDeclaration(decl);
1464 ast->Insert(curExternal.prev, external);
1465 external.symbol = symbol;
1466 symbol.externalGet = external;
1468 ReplaceThisClassSpecifiers(specifiers, prop._class);
1471 FreeDeclarator(typeDecl);
1475 // Move declaration higher...
1476 ast->Move(symbol.externalGet, curExternal.prev);
1483 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1486 OldList * specifiers, * declarators;
1491 Declarator typeDecl;
1493 declarators = MkList();
1496 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1497 if(!prop.conversion || prop._class.type == structClass)
1499 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1500 MkDeclaratorIdentifier(MkIdentifier("this"))));
1503 specifiers = MkList();
1506 Context context = SetupTemplatesContext(prop._class);
1507 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1508 MkDeclaratorIdentifier(MkIdentifier("value")));
1509 FinishTemplatesContext(context);
1511 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1512 specifiers->Insert(null, MkSpecifier(CONST));
1514 ListAdd(params, MkTypeName(specifiers, d));
1516 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1519 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1520 d = MkDeclaratorFunction(d, params);
1522 // Make sure the simple _class's type is declared
1523 for(spec = specifiers->first; spec; spec = spec.next)
1525 if(spec.type == nameSpecifier /*SpecifierClass*/)
1527 if((!typeDecl || typeDecl.type == identifierDeclarator))
1529 Symbol classSym = spec.symbol; // FindClass(spec.name);
1530 symbol._class = classSym.registered;
1531 if(classSym.registered && classSym.registered.type == structClass)
1532 DeclareStruct(spec.name, false);
1537 ListAdd(declarators, MkInitDeclarator(d, null));
1539 specifiers = MkList();
1542 specifiers->Insert(null, MkSpecifier(EXTERN));
1543 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1544 specifiers->Insert(null, MkSpecifier(STATIC));
1546 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1547 if(!prop.conversion || prop._class.type == structClass)
1548 ListAdd(specifiers, MkSpecifier(VOID));
1550 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1552 decl = MkDeclaration(specifiers, declarators);
1554 external = MkExternalDeclaration(decl);
1555 ast->Insert(curExternal.prev, external);
1556 external.symbol = symbol;
1557 symbol.externalSet = external;
1559 ReplaceThisClassSpecifiers(specifiers, prop._class);
1563 // Move declaration higher...
1564 ast->Move(symbol.externalSet, curExternal.prev);
1568 // Property (for Watchers)
1569 if(!symbol.externalPtr)
1573 OldList * specifiers = MkList();
1574 char propName[1024];
1577 specifiers->Insert(null, MkSpecifier(EXTERN));
1579 specifiers->Insert(null, MkSpecifier(STATIC));
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);
1587 // strcat(propName, prop.name);
1588 //MangleClassName(propName);
1591 OldList * list = MkList();
1592 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1593 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1597 strcpy(propName, "__ecerePropM_");
1598 FullClassNameCat(propName, prop._class.fullName, false);
1599 strcat(propName, "_");
1600 // strcat(propName, prop.name);
1601 FullClassNameCat(propName, prop.name, true);
1603 //MangleClassName(propName);
1605 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1606 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1608 decl = MkDeclaration(specifiers, list);
1611 external = MkExternalDeclaration(decl);
1612 ast->Insert(curExternal.prev, external);
1613 external.symbol = symbol;
1614 symbol.externalPtr = external;
1618 // Move declaration higher...
1619 ast->Move(symbol.externalPtr, curExternal.prev);
1622 symbol.id = curExternal.symbol.idCode;
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;
2049 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
2052 /*if(!inst._class.symbol)
2053 inst._class.symbol = FindClass(inst._class.name);*/
2054 classSym = inst._class.symbol;
2055 _class = classSym ? classSym.registered : null;
2057 // DANGER: Patch for mutex not declaring its struct when not needed
2058 if(!_class || _class.type != noHeadClass)
2059 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
2061 afterExternal = afterExternal ? afterExternal : curExternal;
2064 ProcessExpressionType(inst.exp);
2066 inst.isConstant = true;
2069 DataMember curMember = null;
2070 Class curClass = null;
2071 DataMember subMemberStack[256];
2072 int subMemberStackPos = 0;
2074 for(members = inst.members->first; members; members = members.next)
2076 switch(members.type)
2078 case methodMembersInit:
2081 static uint instMethodID = 0;
2082 External external = curExternal;
2083 Context context = curContext;
2084 Declarator declarator = members.function.declarator;
2085 Identifier nameID = GetDeclId(declarator);
2086 char * unmangled = nameID ? nameID.string : null;
2088 External createdExternal = null;
2093 //members.function.dontMangle = true;
2094 strcpy(name, "__ecereInstMeth_");
2095 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2097 strcat(name, nameID.string);
2099 sprintf(number, "_%08d", instMethodID++);
2100 strcat(name, number);
2101 nameID.string = CopyString(name);
2104 // Do modifications here...
2107 Symbol symbol = declarator.symbol;
2108 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2110 if(method && method.type == virtualMethod)
2112 symbol.method = method;
2113 ProcessMethodType(method);
2115 if(!symbol.type.thisClass)
2117 if(method.dataType.thisClass && currentClass &&
2118 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2120 if(!currentClass.symbol)
2121 currentClass.symbol = FindClass(currentClass.fullName);
2122 symbol.type.thisClass = currentClass.symbol;
2127 _class.symbol = FindClass(_class.fullName);
2128 symbol.type.thisClass = _class.symbol;
2131 // TESTING THIS HERE:
2132 DeclareType(symbol.type, true, true);
2137 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2138 unmangled, classSym.string);
2142 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2143 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2147 FreeSpecifier(nameID._class);
2148 nameID._class = null;
2153 //Type type = declarator.symbol.type;
2154 External oldExternal = curExternal;
2156 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2157 // *** It was commented out for problems such as
2159 class VirtualDesktop : Window
2161 clientSize = Size { };
2172 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2174 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2177 if(strcmp(declarator.symbol.string, name))
2179 printf("TOCHECK: Look out for this\n");
2180 delete declarator.symbol.string;
2181 declarator.symbol.string = CopyString(name);
2184 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2186 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2187 excludedSymbols->Remove(declarator.symbol);
2188 globalContext.symbols.Add((BTNode)declarator.symbol);
2189 if(strstr(declarator.symbol.string), "::")
2190 globalContext.hasNameSpace = true;
2195 //curExternal = curExternal.prev;
2196 //afterExternal = afterExternal->next;
2198 //ProcessFunction(afterExternal->function);
2200 //curExternal = afterExternal;
2202 External externalDecl;
2203 externalDecl = MkExternalDeclaration(null);
2204 ast->Insert(oldExternal.prev, externalDecl);
2206 // Which function does this process?
2207 if(createdExternal.function)
2209 ProcessFunction(createdExternal.function);
2211 //curExternal = oldExternal;
2214 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2216 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2217 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2219 //externalDecl = MkExternalDeclaration(decl);
2221 //***** ast->Insert(external.prev, externalDecl);
2222 //ast->Insert(curExternal.prev, externalDecl);
2223 externalDecl.declaration = decl;
2224 if(decl.symbol && !decl.symbol.pointerExternal)
2225 decl.symbol.pointerExternal = externalDecl;
2227 // Trying this out...
2228 declarator.symbol.pointerExternal = externalDecl;
2235 curExternal = declarator.symbol.pointerExternal;
2236 ProcessFunction((FunctionDefinition)members.function);
2238 curExternal = external;
2239 curContext = context;
2243 FreeClassFunction(members.function);
2245 // In this pass, turn this into a MemberInitData
2246 exp = QMkExpId(name);
2247 members.type = dataMembersInit;
2248 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2254 case dataMembersInit:
2256 if(members.dataMembers && classSym)
2259 Location oldyyloc = yylloc;
2260 for(member = members.dataMembers->first; member; member = member.next)
2262 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2263 if(member.initializer && !member.initializer.isConstant)
2264 inst.isConstant = false;
2276 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2278 // OPTIMIZATIONS: TESTING THIS...
2281 if(type.kind == functionType)
2286 for(param = type.params.first; param; param = param.next)
2287 DeclareType(param, declarePointers, true);
2289 DeclareType(type.returnType, declarePointers, true);
2291 else if(type.kind == pointerType && declarePointers)
2292 DeclareType(type.type, declarePointers, false);
2293 else if(type.kind == classType)
2295 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2296 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2298 else if(type.kind == structType || type.kind == unionType)
2301 for(member = type.members.first; member; member = member.next)
2302 DeclareType(member, false, false);
2304 else if(type.kind == arrayType)
2305 DeclareType(type.arrayType, declarePointers, false);
2309 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2311 ClassTemplateArgument * arg = null;
2313 ClassTemplateParameter curParam = null;
2315 for(sClass = _class; sClass; sClass = sClass.base)
2318 if(sClass.templateClass) sClass = sClass.templateClass;
2319 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2321 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2323 for(sClass = sClass.base; sClass; sClass = sClass.base)
2325 if(sClass.templateClass) sClass = sClass.templateClass;
2326 id += sClass.templateParams.count;
2336 arg = &_class.templateArgs[id];
2337 if(arg && param.type == type)
2338 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2343 public Context SetupTemplatesContext(Class _class)
2345 Context context = PushContext();
2346 context.templateTypesOnly = true;
2347 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2349 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2350 for(; param; param = param.next)
2352 if(param.type == type && param.identifier)
2354 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2355 curContext.templateTypes.Add((BTNode)type);
2362 for(sClass = _class; sClass; sClass = sClass.base)
2364 ClassTemplateParameter p;
2365 for(p = sClass.templateParams.first; p; p = p.next)
2367 //OldList * specs = MkList();
2368 //Declarator decl = null;
2369 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2372 TemplateParameter param = p.param;
2376 // ADD DATA TYPE HERE...
2377 p.param = param = TemplateParameter
2379 identifier = MkIdentifier(p.name), type = p.type,
2380 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2383 type = TemplatedType { key = (uintptr)p.name, param = param };
2384 curContext.templateTypes.Add((BTNode)type);
2392 public void FinishTemplatesContext(Context context)
2394 PopContext(context);
2395 FreeContext(context);
2399 public void ProcessMethodType(Method method)
2401 if(!method.dataType)
2403 Context context = SetupTemplatesContext(method._class);
2405 method.dataType = ProcessTypeString(method.dataTypeString, false);
2407 FinishTemplatesContext(context);
2409 if(method.type != virtualMethod && method.dataType)
2411 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2413 if(!method._class.symbol)
2414 method._class.symbol = FindClass(method._class.fullName);
2415 method.dataType.thisClass = method._class.symbol;
2419 // Why was this commented out? Working fine without now...
2422 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2423 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2430 char * par = strstr(type, "(");
2431 char * classOp = null;
2436 for(c = par-type-1; c >= 0; c++)
2438 if(type[c] == ':' && type[c+1] == ':')
2440 classOp = type + c - 1;
2441 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2448 else if(!isspace(type[c]))
2455 int typeLen = strlen(type);
2456 memcpy(temp, classOp, classOpLen);
2457 temp[classOpLen] = '\0';
2459 _class = eSystem_FindClass(module, temp);
2462 method.dataTypeString = new char[typeLen - classOpLen + 1];
2463 memcpy(method.dataTypeString, type, classOp - type);
2464 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2467 method.dataTypeString = type;
2473 public void ProcessPropertyType(Property prop)
2477 Context context = SetupTemplatesContext(prop._class);
2478 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2479 FinishTemplatesContext(context);
2483 public void DeclareMethod(Method method, const char * name)
2485 Symbol symbol = method.symbol;
2486 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2488 //bool imported = false;
2489 bool dllImport = false;
2491 if(!method.dataType)
2492 method.dataType = ProcessTypeString(method.dataTypeString, false);
2494 if(!symbol || symbol._import || method.type == virtualMethod)
2496 if(!symbol || method.type == virtualMethod)
2499 if(!method._class.symbol)
2500 method._class.symbol = FindClass(method._class.fullName);
2501 classSym = method._class.symbol;
2502 if(!classSym._import)
2504 ModuleImport module;
2506 if(method._class.module && method._class.module.name)
2507 module = FindModule(method._class.module);
2509 module = mainModule;
2510 classSym._import = ClassImport
2512 name = CopyString(method._class.fullName);
2513 isRemote = method._class.isRemote;
2515 module.classes.Add(classSym._import);
2519 symbol = method.symbol = Symbol { };
2523 symbol._import = (ClassImport)MethodImport
2525 name = CopyString(method.name);
2526 isVirtual = method.type == virtualMethod;
2528 classSym._import.methods.Add(symbol._import);
2532 // Set the symbol type
2536 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2538 else if(type.thisClass == (void *)-1)
2540 type.thisClass = null;
2543 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2544 symbol.type = method.dataType;
2545 if(symbol.type) symbol.type.refCount++;
2548 if(!method.thisClass || strcmp(method.thisClass, "void"))
2549 symbol.type.params.Insert(null,
2550 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2553 if(!method.dataType.dllExport)
2556 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2562 if(!method.dataType)
2563 method.dataType = ((Symbol)method.symbol).type;
2564 //ProcessMethodType(method);
2567 if(method.type != virtualMethod && method.dataType)
2568 DeclareType(method.dataType, true, true);
2570 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2572 // We need a declaration here :)
2574 OldList * specifiers, * declarators;
2576 Declarator funcDecl;
2579 specifiers = MkList();
2580 declarators = MkList();
2584 ListAdd(specifiers, MkSpecifier(EXTERN));
2585 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2586 ListAdd(specifiers, MkSpecifier(STATIC));
2588 if(method.type == virtualMethod)
2590 ListAdd(specifiers, MkSpecifier(INT));
2591 d = MkDeclaratorIdentifier(MkIdentifier(name));
2595 d = MkDeclaratorIdentifier(MkIdentifier(name));
2598 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2600 Context context = SetupTemplatesContext(method._class);
2601 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2602 FinishTemplatesContext(context);
2604 funcDecl = GetFuncDecl(d);
2608 Specifier spec, next;
2609 for(spec = specifiers->first; spec; spec = next)
2612 if(spec.type == extendedSpecifier)
2614 specifiers->Remove(spec);
2615 FreeSpecifier(spec);
2620 // Add this parameter if not a static method
2621 if(method.dataType && !method.dataType.staticMethod)
2623 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2625 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2626 TypeName thisParam = MkTypeName(MkListOne(
2627 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2628 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2629 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2630 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2632 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2634 TypeName param = funcDecl.function.parameters->first;
2635 funcDecl.function.parameters->Remove(param);
2636 FreeTypeName(param);
2639 if(!funcDecl.function.parameters)
2640 funcDecl.function.parameters = MkList();
2641 funcDecl.function.parameters->Insert(null, thisParam);
2644 // Make sure we don't have empty parameter declarations for static methods...
2646 else if(!funcDecl.function.parameters)
2648 funcDecl.function.parameters = MkList();
2649 funcDecl.function.parameters->Insert(null,
2650 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2654 ProcessDeclarator(d);
2656 ListAdd(declarators, MkInitDeclarator(d, null));
2658 decl = MkDeclaration(specifiers, declarators);
2660 ReplaceThisClassSpecifiers(specifiers, method._class);
2662 // Keep a different symbol for the function definition than the declaration...
2663 if(symbol.pointerExternal)
2665 Symbol functionSymbol { };
2669 *functionSymbol = *symbol;
2670 functionSymbol.string = CopyString(symbol.string);
2671 if(functionSymbol.type)
2672 functionSymbol.type.refCount++;
2675 excludedSymbols->Add(functionSymbol);
2676 symbol.pointerExternal.symbol = functionSymbol;
2678 external = MkExternalDeclaration(decl);
2680 ast->Insert(curExternal ? curExternal.prev : null, external);
2681 external.symbol = symbol;
2682 symbol.pointerExternal = external;
2686 // Move declaration higher...
2687 ast->Move(symbol.pointerExternal, curExternal.prev);
2690 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2694 char * ReplaceThisClass(Class _class)
2696 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2700 ClassTemplateParameter param;
2703 char className[1024];
2704 strcpy(className, _class.fullName);
2705 for(param = _class.templateParams.first; param; param = param.next)
2707 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2709 if(first) strcat(className, "<");
2710 if(!first) strcat(className, ", ");
2711 if(lastParam + 1 != p)
2713 strcat(className, param.name);
2714 strcat(className, " = ");
2716 strcat(className, param.name);
2724 int len = strlen(className);
2725 if(className[len-1] == '>') className[len++] = ' ';
2726 className[len++] = '>';
2727 className[len++] = '\0';
2729 return CopyString(className);
2732 return CopyString(_class.fullName);
2735 Type ReplaceThisClassType(Class _class)
2738 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2742 ClassTemplateParameter param;
2744 char className[1024];
2745 strcpy(className, _class.fullName);
2747 for(param = _class.templateParams.first; param; param = param.next)
2749 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2751 if(first) strcat(className, "<");
2752 if(!first) strcat(className, ", ");
2753 if(lastParam + 1 != p)
2755 strcat(className, param.name);
2756 strcat(className, " = ");
2758 strcat(className, param.name);
2766 int len = strlen(className);
2767 if(className[len-1] == '>') className[len++] = ' ';
2768 className[len++] = '>';
2769 className[len++] = '\0';
2771 type = MkClassType(className);
2772 //type = ProcessTypeString(className, false);
2776 type = MkClassType(_class.fullName);
2777 //type = ProcessTypeString(_class.fullName, false);
2779 //type.wasThisClass = true;
2783 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2785 if(specs != null && _class)
2788 for(spec = specs.first; spec; spec = spec.next)
2790 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2792 spec.type = nameSpecifier;
2793 spec.name = ReplaceThisClass(_class);
2794 spec.symbol = FindClass(spec.name); //_class.symbol;
2800 // Returns imported or not
2801 bool DeclareFunction(GlobalFunction function, char * name)
2803 Symbol symbol = function.symbol;
2804 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2806 bool imported = false;
2807 bool dllImport = false;
2809 if(!function.dataType)
2811 function.dataType = ProcessTypeString(function.dataTypeString, false);
2812 if(!function.dataType.thisClass)
2813 function.dataType.staticMethod = true;
2820 ModuleImport module = FindModule(function.module);
2821 // WARNING: This is not added anywhere...
2822 symbol = function.symbol = Symbol { };
2826 if(!function.dataType.dllExport)
2828 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2829 module.functions.Add(symbol._import);
2832 // Set the symbol type
2834 symbol.type = ProcessTypeString(function.dataTypeString, false);
2835 if(!symbol.type.thisClass)
2836 symbol.type.staticMethod = true;
2839 imported = symbol._import ? true : false;
2840 if(imported && function.module != privateModule && function.module.importType != staticImport)
2844 DeclareType(function.dataType, true, true);
2848 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2850 // We need a declaration here :)
2852 OldList * specifiers, * declarators;
2854 Declarator funcDecl;
2857 specifiers = MkList();
2858 declarators = MkList();
2861 ListAdd(specifiers, MkSpecifier(EXTERN));
2864 ListAdd(specifiers, MkSpecifier(STATIC));
2867 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2870 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2872 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2873 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2874 if(function.module.importType == staticImport)
2877 for(spec = specifiers->first; spec; spec = spec.next)
2878 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2880 specifiers->Remove(spec);
2881 FreeSpecifier(spec);
2886 funcDecl = GetFuncDecl(d);
2888 // Make sure we don't have empty parameter declarations for static methods...
2889 if(funcDecl && !funcDecl.function.parameters)
2891 funcDecl.function.parameters = MkList();
2892 funcDecl.function.parameters->Insert(null,
2893 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2896 ListAdd(declarators, MkInitDeclarator(d, null));
2899 Context oldCtx = curContext;
2900 curContext = globalContext;
2901 decl = MkDeclaration(specifiers, declarators);
2902 curContext = oldCtx;
2905 // Keep a different symbol for the function definition than the declaration...
2906 if(symbol.pointerExternal)
2908 Symbol functionSymbol { };
2911 *functionSymbol = *symbol;
2912 functionSymbol.string = CopyString(symbol.string);
2913 if(functionSymbol.type)
2914 functionSymbol.type.refCount++;
2917 excludedSymbols->Add(functionSymbol);
2919 symbol.pointerExternal.symbol = functionSymbol;
2921 external = MkExternalDeclaration(decl);
2923 ast->Insert(curExternal.prev, external);
2924 external.symbol = symbol;
2925 symbol.pointerExternal = external;
2929 // Move declaration higher...
2930 ast->Move(symbol.pointerExternal, curExternal.prev);
2934 symbol.id = curExternal.symbol.idCode;
2937 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2940 void DeclareGlobalData(GlobalData data)
2942 Symbol symbol = data.symbol;
2943 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2948 symbol = data.symbol = Symbol { };
2951 data.dataType = ProcessTypeString(data.dataTypeString, false);
2952 DeclareType(data.dataType, true, true);
2955 if(!symbol.pointerExternal)
2957 // We need a declaration here :)
2959 OldList * specifiers, * declarators;
2963 specifiers = MkList();
2964 declarators = MkList();
2966 ListAdd(specifiers, MkSpecifier(EXTERN));
2967 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2968 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2970 ListAdd(declarators, MkInitDeclarator(d, null));
2972 decl = MkDeclaration(specifiers, declarators);
2973 external = MkExternalDeclaration(decl);
2975 ast->Insert(curExternal.prev, external);
2976 external.symbol = symbol;
2977 symbol.pointerExternal = external;
2981 // Move declaration higher...
2982 ast->Move(symbol.pointerExternal, curExternal.prev);
2986 symbol.id = curExternal.symbol.idCode;
2991 class Conversion : struct
2993 Conversion prev, next;
2999 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
3002 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
3003 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
3005 Class sourceClass = source.kind == classType ? source._class.registered : null;
3006 Class destClass = dest.kind == classType ? dest._class.registered : null;
3007 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
3008 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
3010 Type sourceType = source, destType = dest;
3011 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
3012 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
3013 if(!destType.constant && sourceType.constant)
3017 Compiler_Warning($"discarding const qualifier\n");
3024 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
3025 bool isConversionExploration, bool warnConst)
3030 CheckConstCompatibility(source, dest, true);
3031 // Property convert;
3033 if(source.kind == templateType && dest.kind != templateType)
3035 Type type = ProcessTemplateParameterType(source.templateParameter);
3036 if(type) source = type;
3039 if(dest.kind == templateType && source.kind != templateType)
3041 Type type = ProcessTemplateParameterType(dest.templateParameter);
3042 if(type) dest = type;
3045 if(dest.classObjectType == typedObject && dest.kind != functionType)
3047 if(source.classObjectType != anyObject)
3051 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
3052 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
3060 if(source.kind != functionType && source.classObjectType == anyObject)
3062 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
3066 if((dest.kind == structType && source.kind == structType) ||
3067 (dest.kind == unionType && source.kind == unionType))
3069 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
3070 (source.members.first && source.members.first == dest.members.first))
3074 if(dest.kind == ellipsisType && source.kind != voidType)
3077 if(dest.kind == pointerType && dest.type.kind == voidType &&
3078 ((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))
3079 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
3081 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
3083 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
3085 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
3086 ((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))
3087 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
3088 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
3090 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
3093 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
3095 if(source._class.registered && source._class.registered.type == unitClass)
3097 if(conversions != null)
3099 if(source._class.registered == dest._class.registered)
3104 Class sourceBase, destBase;
3105 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
3106 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
3107 if(sourceBase == destBase)
3111 // Don't match enum inheriting from other enum if resolving enumeration values
3112 // TESTING: !dest.classObjectType
3113 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3115 (!source._class.registered || source._class.registered.type != enumClass) ||
3116 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3120 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3122 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3123 ((source._class && source._class.registered && source._class.registered.type != enumClass) || source.kind == classType)) // Added this here for a base enum to be acceptable for a derived enum (#139)
3125 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3133 // JUST ADDED THIS...
3134 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3139 // Just added this for Straight conversion of ColorAlpha => Color
3140 if(source.kind == classType)
3143 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3146 for(convert = _class.conversions.first; convert; convert = convert.next)
3148 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3150 Conversion after = (conversions != null) ? conversions.last : null;
3152 if(!convert.dataType)
3153 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3154 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3155 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3156 MatchTypes(convert.dataType, dest, conversions, null, null,
3157 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3158 convert.dataType.kind == classType, false, true, warnConst))
3160 if(!conversions && !convert.Get)
3162 else if(conversions != null)
3164 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3165 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3166 (dest.kind != classType || dest._class.registered != _class.base))
3170 Conversion conv { convert = convert, isGet = true };
3171 // conversions.Add(conv);
3172 conversions.Insert(after, conv);
3185 if(dest.kind == classType)
3188 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3191 for(convert = _class.conversions.first; convert; convert = convert.next)
3193 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3195 Type constType = null;
3196 bool success = false;
3197 // Conversion after = (conversions != null) ? conversions.last : null;
3199 if(!convert.dataType)
3200 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3202 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3205 constType = { kind = pointerType, refCount = 1, type = ptrType };
3206 CopyTypeInto(ptrType, convert.dataType.type);
3207 ptrType.constant = true;
3210 // Just added this equality check to prevent recursion.... Make it safer?
3211 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3212 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3214 if(!conversions && !convert.Set)
3216 else if(conversions != null)
3218 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3219 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3220 (source.kind != classType || source._class.registered != _class.base))
3224 // *** Testing this! ***
3225 Conversion conv { convert = convert };
3226 conversions.Add(conv);
3227 //conversions.Insert(after, conv);
3233 FreeType(constType);
3239 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3241 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3242 (source.kind != classType || source._class.registered.type != structClass))
3246 // TESTING THIS... IS THIS OK??
3247 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3249 if(!dest._class.registered.dataType)
3250 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3251 // Only support this for classes...
3252 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3253 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3255 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3264 if(source.kind == classType)
3267 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3270 for(convert = _class.conversions.first; convert; convert = convert.next)
3272 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3274 Conversion after = (conversions != null) ? conversions.last : null;
3276 if(!convert.dataType)
3277 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3278 if(convert.dataType != source &&
3279 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3280 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3282 if(!conversions && !convert.Get)
3284 else if(conversions != null)
3286 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3287 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3288 (dest.kind != classType || dest._class.registered != _class.base))
3292 Conversion conv { convert = convert, isGet = true };
3294 // conversions.Add(conv);
3295 conversions.Insert(after, conv);
3304 // TESTING THIS... IS THIS OK??
3305 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3307 if(!source._class.registered.dataType)
3308 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3309 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3311 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))
3313 // For bool to be accepted by byte, short, etc.
3314 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3321 if(source.kind == classType || source.kind == subClassType)
3323 else if(dest.kind == source.kind &&
3324 (dest.kind != structType && dest.kind != unionType &&
3325 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3327 // RECENTLY ADDED THESE
3328 else if(dest.kind == doubleType && source.kind == floatType)
3330 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3332 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3334 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3336 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3338 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3340 else if(source.kind == enumType &&
3341 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3343 else if(dest.kind == enumType && !isConversionExploration &&
3344 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3346 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3347 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3349 Type paramSource, paramDest;
3351 if(dest.kind == methodType)
3352 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3353 if(source.kind == methodType)
3354 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3356 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3357 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3358 if(dest.kind == methodType)
3359 dest = dest.method.dataType;
3360 if(source.kind == methodType)
3361 source = source.method.dataType;
3363 paramSource = source.params.first;
3364 if(paramSource && paramSource.kind == voidType) paramSource = null;
3365 paramDest = dest.params.first;
3366 if(paramDest && paramDest.kind == voidType) paramDest = null;
3369 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3370 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3372 // Source thisClass must be derived from destination thisClass
3373 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3374 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3376 if(paramDest && paramDest.kind == classType)
3377 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3379 Compiler_Error($"method class should not take an object\n");
3382 paramDest = paramDest.next;
3384 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3386 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3390 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3392 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3398 // THIS WAS BACKWARDS:
3399 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3400 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3403 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3405 Compiler_Error($"overriding class expected to be derived from method class\n");
3409 paramSource = paramSource.next;
3415 // Source thisClass must be derived from destination thisClass
3416 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3418 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3424 // THIS WAS BACKWARDS TOO??
3425 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3426 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3429 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3431 //Compiler_Error($"overriding class expected to be derived from method class\n");
3439 // Source return type must be derived from destination return type
3440 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3442 Compiler_Warning($"incompatible return type for function\n");
3445 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3447 CheckConstCompatibility(dest.returnType, source.returnType, true);
3451 for(; paramDest; paramDest = paramDest.next)
3455 //Compiler_Warning($"not enough parameters\n");
3456 Compiler_Error($"not enough parameters\n");
3460 Type paramDestType = paramDest;
3461 Type paramSourceType = paramSource;
3462 Type type = paramDestType;
3464 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3465 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3466 paramSource.kind != templateType)
3469 ClassTemplateParameter curParam = null;
3471 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3474 if(sClass.templateClass) sClass = sClass.templateClass;
3475 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3477 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3479 for(sClass = sClass.base; sClass; sClass = sClass.base)
3481 if(sClass.templateClass) sClass = sClass.templateClass;
3482 id += sClass.templateParams.count;
3493 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3494 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3498 // paramDest must be derived from paramSource
3499 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3500 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3504 PrintType(paramDest, type, false, true);
3505 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3507 if(paramDestType != paramDest)
3508 FreeType(paramDestType);
3511 if(paramDestType != paramDest)
3512 FreeType(paramDestType);
3515 paramSource = paramSource.next;
3519 Compiler_Error($"too many parameters\n");
3524 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3528 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3529 (source.kind == arrayType || source.kind == pointerType))
3531 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3538 static void FreeConvert(Conversion convert)
3540 if(convert.resultType)
3541 FreeType(convert.resultType);
3544 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3545 char * string, OldList conversions)
3549 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3551 Class _class = link.data;
3552 if(_class.type == enumClass)
3554 OldList converts { };
3556 type.kind = classType;
3559 _class.symbol = FindClass(_class.fullName);
3560 type._class = _class.symbol;
3562 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false, false))
3565 Class enumClass = eSystem_FindClass(privateModule, "enum");
3569 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3571 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3572 for(value = e.values.first; value; value = value.next)
3574 if(!strcmp(value.name, string))
3579 FreeExpContents(sourceExp);
3580 FreeType(sourceExp.expType);
3582 sourceExp.isConstant = true;
3583 sourceExp.expType = MkClassType(baseClass.fullName);
3587 sourceExp.type = constantExp;
3588 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3589 sprintf(constant, FORMAT64D, value.data);
3591 sprintf(constant, FORMAT64HEXLL, value.data);
3592 sourceExp.constant = CopyString(constant);
3593 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3596 while(converts.first)
3598 Conversion convert = converts.first;
3599 converts.Remove(convert);
3600 conversions.Add(convert);
3609 converts.Free(FreeConvert);
3613 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3614 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3619 public bool ModuleVisibility(Module searchIn, Module searchFor)
3621 SubModule subModule;
3623 if(searchFor == searchIn)
3626 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3628 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3630 if(ModuleVisibility(subModule.module, searchFor))
3637 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3641 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3643 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3645 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3648 for(module = mainModule.application.allModules.first; module; module = module.next)
3650 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3656 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3659 Type realDest = dest;
3660 Type backupSourceExpType = null;
3661 Expression computedExp = sourceExp;
3664 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3665 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3667 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3668 ComputeExpression(computedExp /*sourceExp*/);
3671 source = sourceExp.expType;
3673 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3675 if(computedExp != sourceExp)
3677 FreeExpression(computedExp);
3678 computedExp = sourceExp;
3684 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3686 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3688 Class sourceBase, destBase;
3689 for(sourceBase = source._class.registered;
3690 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3691 sourceBase = sourceBase.base);
3692 for(destBase = dest._class.registered;
3693 destBase && destBase.base && destBase.base.type != systemClass;
3694 destBase = destBase.base);
3695 //if(source._class.registered == dest._class.registered)
3696 if(sourceBase == destBase)
3698 if(computedExp != sourceExp)
3700 FreeExpression(computedExp);
3701 computedExp = sourceExp;
3713 int64 value = MAXINT;
3717 if(computedExp.type == constantExp)
3720 value = strtoll(computedExp.constant, null, 0);
3722 value = strtoull(computedExp.constant, null, 0);
3724 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3727 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3729 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3731 if(computedExp != sourceExp)
3733 FreeExpression(computedExp);
3734 computedExp = sourceExp;
3737 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3738 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3741 source = Type { kind = intType, isSigned = false, refCount = 1 };
3744 if(dest.kind == classType)
3746 Class _class = dest._class ? dest._class.registered : null;
3748 if(_class && _class.type == unitClass)
3750 if(source.kind != classType)
3753 Type tempDest, tempSource;
3755 for(; _class.base.type != systemClass; _class = _class.base);
3757 tempDest = tempType;
3759 tempType.kind = classType;
3761 _class.symbol = FindClass(_class.fullName);
3763 tempType._class = _class.symbol;
3764 tempType.truth = dest.truth;
3766 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3768 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3769 backupSourceExpType = sourceExp.expType;
3770 sourceExp.expType = dest; dest.refCount++;
3771 //sourceExp.expType = MkClassType(_class.fullName);
3779 // Why wasn't there something like this?
3780 if(_class && _class.type == bitClass && source.kind != classType)
3782 if(!dest._class.registered.dataType)
3783 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3784 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3787 FreeType(sourceExp.expType);
3788 source = sourceExp.expType = MkClassType(dest._class.string);
3791 //source.kind = classType;
3792 //source._class = dest._class;
3796 // Adding two enumerations
3798 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3800 if(!source._class.registered.dataType)
3801 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3802 if(!dest._class.registered.dataType)
3803 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3805 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3808 source = sourceExp.expType = MkClassType(dest._class.string);
3811 //source.kind = classType;
3812 //source._class = dest._class;
3816 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3818 OldList * specs = MkList();
3822 ReadString(string, sourceExp.string);
3823 decl = SpecDeclFromString(string, specs, null);
3825 FreeExpContents(sourceExp);
3826 FreeType(sourceExp.expType);
3828 sourceExp.type = classExp;
3829 sourceExp._classExp.specifiers = specs;
3830 sourceExp._classExp.decl = decl;
3831 sourceExp.expType = dest;
3836 if(backupSourceExpType) FreeType(backupSourceExpType);
3840 else if(source.kind == classType)
3842 Class _class = source._class ? source._class.registered : null;
3844 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3847 if(dest.kind != classType)
3849 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3850 if(!source._class.registered.dataType)
3851 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3854 dest = MkClassType(source._class.string);
3855 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3856 // dest = MkClassType(source._class.string);
3860 if(dest.kind != classType)
3863 Type tempDest, tempSource;
3865 if(!source._class.registered.dataType)
3866 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3868 for(; _class.base.type != systemClass; _class = _class.base);
3870 tempSource = tempType;
3871 tempType.kind = classType;
3872 tempType._class = FindClass(_class.fullName);
3873 tempType.truth = source.truth;
3874 tempType.classObjectType = source.classObjectType;
3877 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3879 // PUT THIS BACK TESTING UNITS?
3880 if(conversions.last)
3882 ((Conversion)(conversions.last)).resultType = dest;
3886 FreeType(sourceExp.expType);
3887 sourceExp.expType = MkClassType(_class.fullName);
3888 sourceExp.expType.truth = source.truth;
3889 sourceExp.expType.classObjectType = source.classObjectType;
3891 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3893 if(!sourceExp.destType)
3895 FreeType(sourceExp.destType);
3896 sourceExp.destType = sourceExp.expType;
3897 if(sourceExp.expType)
3898 sourceExp.expType.refCount++;
3901 //source = _class.dataType;
3904 // TOCHECK: TESTING THIS NEW CODE
3905 if(!_class.dataType)
3906 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3908 dest = MkClassType(source._class.string);
3909 dest.truth = source.truth;
3910 dest.classObjectType = source.classObjectType;
3913 source = _class.dataType;
3923 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3933 if(source.kind == classType)
3935 Class _class = source._class.registered;
3936 if(_class.type == unitClass)
3938 if(!_class.dataType)
3939 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3940 source = _class.dataType;
3944 if(dest.kind == classType)
3946 Class _class = dest._class ? dest._class.registered : null;
3947 bool fittingValue = false;
3948 if(_class && _class.type == enumClass)
3950 Class enumClass = eSystem_FindClass(privateModule, "enum");
3951 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3952 if(c && value >= 0 && value <= c.largest)
3953 fittingValue = true;
3956 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3957 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3959 if(_class.type == normalClass || _class.type == noHeadClass)
3961 Expression newExp { };
3962 *newExp = *sourceExp;
3963 if(sourceExp.destType) sourceExp.destType.refCount++;
3964 if(sourceExp.expType) sourceExp.expType.refCount++;
3965 sourceExp.type = castExp;
3966 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3967 sourceExp.cast.exp = newExp;
3968 FreeType(sourceExp.expType);
3969 sourceExp.expType = null;
3970 ProcessExpressionType(sourceExp);
3972 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3975 FreeType(sourceExp.expType);
3976 sourceExp.expType = dest;
3980 if(inCompiler) FreeType(dest);
3982 if(backupSourceExpType) FreeType(backupSourceExpType);
3986 if(!_class.dataType)
3987 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3989 dest = _class.dataType;
3993 // Accept lower precision types for units, since we want to keep the unit type
3994 if(dest.kind == doubleType &&
3995 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3996 source.kind == charType || source.kind == _BoolType))
3998 specs = MkListOne(MkSpecifier(DOUBLE));
4000 else if(dest.kind == floatType &&
4001 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4002 source.kind == _BoolType || source.kind == doubleType))
4004 specs = MkListOne(MkSpecifier(FLOAT));
4006 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4007 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4010 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4011 ListAdd(specs, MkSpecifier(INT64));
4013 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
4014 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4017 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4018 ListAdd(specs, MkSpecifier(INT));
4020 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
4021 source.kind == floatType || source.kind == doubleType))
4024 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4025 ListAdd(specs, MkSpecifier(SHORT));
4027 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
4028 source.kind == floatType || source.kind == doubleType))
4031 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4032 ListAdd(specs, MkSpecifier(CHAR));
4038 if(backupSourceExpType)
4040 // Failed to convert: revert previous exp type
4041 if(sourceExp.expType) FreeType(sourceExp.expType);
4042 sourceExp.expType = backupSourceExpType;
4047 else if(dest.kind == doubleType &&
4048 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
4049 source.kind == _BoolType || source.kind == charType))
4051 specs = MkListOne(MkSpecifier(DOUBLE));
4053 else if(dest.kind == floatType &&
4054 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4056 specs = MkListOne(MkSpecifier(FLOAT));
4058 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4059 (value == 1 || value == 0))
4062 ListAdd(specs, MkSpecifier(BOOL));
4064 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4065 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
4068 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4069 ListAdd(specs, MkSpecifier(CHAR));
4071 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
4072 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
4075 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4076 ListAdd(specs, MkSpecifier(SHORT));
4078 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
4081 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4082 ListAdd(specs, MkSpecifier(INT));
4084 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
4087 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4088 ListAdd(specs, MkSpecifier(INT64));
4090 else if(dest.kind == enumType &&
4091 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4093 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4099 if(backupSourceExpType)
4101 // Failed to convert: revert previous exp type
4102 if(sourceExp.expType) FreeType(sourceExp.expType);
4103 sourceExp.expType = backupSourceExpType;
4108 if(!flag && !sourceExp.opDestType)
4110 Expression newExp { };
4111 *newExp = *sourceExp;
4114 if(sourceExp.destType) sourceExp.destType.refCount++;
4115 if(sourceExp.expType) sourceExp.expType.refCount++;
4117 sourceExp.type = castExp;
4118 if(realDest.kind == classType)
4120 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4121 FreeList(specs, FreeSpecifier);
4124 sourceExp.cast.typeName = MkTypeName(specs, null);
4125 if(newExp.type == opExp)
4127 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4130 sourceExp.cast.exp = newExp;
4132 FreeType(sourceExp.expType);
4133 sourceExp.expType = null;
4134 ProcessExpressionType(sourceExp);
4137 FreeList(specs, FreeSpecifier);
4141 if(backupSourceExpType) FreeType(backupSourceExpType);
4147 if(computedExp != sourceExp)
4149 FreeExpression(computedExp);
4150 computedExp = sourceExp;
4153 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4154 if(sourceExp.type == identifierExp)
4156 Identifier id = sourceExp.identifier;
4157 if(dest.kind == classType)
4159 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4161 Class _class = dest._class.registered;
4162 Class enumClass = eSystem_FindClass(privateModule, "enum");
4165 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4168 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4169 for(value = e.values.first; value; value = value.next)
4171 if(!strcmp(value.name, id.string))
4176 FreeExpContents(sourceExp);
4177 FreeType(sourceExp.expType);
4179 sourceExp.isConstant = true;
4180 sourceExp.expType = MkClassType(_class.fullName);
4183 sourceExp.type = constantExp;
4184 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4185 sourceExp.constant = PrintInt64(value.data);
4187 sourceExp.constant = PrintUInt64(value.data);
4188 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4198 // Loop through all enum classes
4199 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4210 #define TERTIARY(o, name, m, t, p) \
4211 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4213 exp.type = constantExp; \
4214 exp.string = p(op1.m ? op2.m : op3.m); \
4216 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4220 #define BINARY(o, name, m, t, p) \
4221 static bool name(Expression exp, Operand op1, Operand op2) \
4224 exp.type = constantExp; \
4225 exp.string = p((t)(op1.m o value2)); \
4227 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4231 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4232 static bool name(Expression exp, Operand op1, Operand op2) \
4235 exp.type = constantExp; \
4236 exp.string = p(value2 ? (op1.m o value2) : 0); \
4238 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4242 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4243 static bool name(Expression exp, Operand op1, Operand op2) \
4246 exp.type = constantExp; \
4247 exp.string = p(op1.m o value2); \
4249 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4253 #define UNARY(o, name, m, t, p) \
4254 static bool name(Expression exp, Operand op1) \
4256 exp.type = constantExp; \
4257 exp.string = p((t)(o op1.m)); \
4259 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4263 #define OPERATOR_ALL(macro, o, name) \
4264 macro(o, Int##name, i, int, PrintInt) \
4265 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4266 macro(o, Int64##name, i64, int64, PrintInt64) \
4267 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4268 macro(o, Short##name, s, short, PrintShort) \
4269 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4270 macro(o, Char##name, c, char, PrintChar) \
4271 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4272 macro(o, Float##name, f, float, PrintFloat) \
4273 macro(o, Double##name, d, double, PrintDouble)
4275 #define OPERATOR_INTTYPES(macro, o, name) \
4276 macro(o, Int##name, i, int, PrintInt) \
4277 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4278 macro(o, Int64##name, i64, int64, PrintInt64) \
4279 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4280 macro(o, Short##name, s, short, PrintShort) \
4281 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4282 macro(o, Char##name, c, char, PrintChar) \
4283 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4285 #define OPERATOR_REALTYPES(macro, o, name) \
4286 macro(o, Float##name, f, float, PrintFloat) \
4287 macro(o, Double##name, d, double, PrintDouble)
4289 // binary arithmetic
4290 OPERATOR_ALL(BINARY, +, Add)
4291 OPERATOR_ALL(BINARY, -, Sub)
4292 OPERATOR_ALL(BINARY, *, Mul)
4293 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4294 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4295 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4298 OPERATOR_ALL(UNARY, -, Neg)
4300 // unary arithmetic increment and decrement
4301 OPERATOR_ALL(UNARY, ++, Inc)
4302 OPERATOR_ALL(UNARY, --, Dec)
4304 // binary arithmetic assignment
4305 OPERATOR_ALL(BINARY, =, Asign)
4306 OPERATOR_ALL(BINARY, +=, AddAsign)
4307 OPERATOR_ALL(BINARY, -=, SubAsign)
4308 OPERATOR_ALL(BINARY, *=, MulAsign)
4309 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4310 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4311 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4314 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4315 OPERATOR_INTTYPES(BINARY, |, BitOr)
4316 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4317 OPERATOR_INTTYPES(BINARY, <<, LShift)
4318 OPERATOR_INTTYPES(BINARY, >>, RShift)
4321 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4323 // binary bitwise assignment
4324 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4325 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4326 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4327 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4328 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4330 // unary logical negation
4331 OPERATOR_INTTYPES(UNARY, !, Not)
4333 // binary logical equality
4334 OPERATOR_ALL(BINARY, ==, Equ)
4335 OPERATOR_ALL(BINARY, !=, Nqu)
4338 OPERATOR_ALL(BINARY, &&, And)
4339 OPERATOR_ALL(BINARY, ||, Or)
4341 // binary logical relational
4342 OPERATOR_ALL(BINARY, >, Grt)
4343 OPERATOR_ALL(BINARY, <, Sma)
4344 OPERATOR_ALL(BINARY, >=, GrtEqu)
4345 OPERATOR_ALL(BINARY, <=, SmaEqu)
4347 // tertiary condition operator
4348 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4350 //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
4351 #define OPERATOR_TABLE_ALL(name, type) \
4352 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4354 type##Inc, type##Dec, \
4355 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4356 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4358 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4360 type##Equ, type##Nqu, \
4361 type##And, type##Or, \
4362 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4365 #define OPERATOR_TABLE_INTTYPES(name, type) \
4366 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4368 type##Inc, type##Dec, \
4369 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4370 null, null, null, null, null, \
4372 null, null, null, null, null, \
4374 type##Equ, type##Nqu, \
4375 type##And, type##Or, \
4376 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4379 OPERATOR_TABLE_ALL(int, Int)
4380 OPERATOR_TABLE_ALL(uint, UInt)
4381 OPERATOR_TABLE_ALL(int64, Int64)
4382 OPERATOR_TABLE_ALL(uint64, UInt64)
4383 OPERATOR_TABLE_ALL(short, Short)
4384 OPERATOR_TABLE_ALL(ushort, UShort)
4385 OPERATOR_TABLE_INTTYPES(float, Float)
4386 OPERATOR_TABLE_INTTYPES(double, Double)
4387 OPERATOR_TABLE_ALL(char, Char)
4388 OPERATOR_TABLE_ALL(uchar, UChar)
4390 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4391 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4392 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4393 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4394 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4395 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4396 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4397 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4399 public void ReadString(char * output, char * string)
4401 int len = strlen(string);
4403 bool quoted = false, escaped = false;
4404 for(c = 0; c<len; c++)
4406 char ch = string[c];
4411 case 'n': output[d] = '\n'; break;
4412 case 't': output[d] = '\t'; break;
4413 case 'a': output[d] = '\a'; break;
4414 case 'b': output[d] = '\b'; break;
4415 case 'f': output[d] = '\f'; break;
4416 case 'r': output[d] = '\r'; break;
4417 case 'v': output[d] = '\v'; break;
4418 case '\\': output[d] = '\\'; break;
4419 case '\"': output[d] = '\"'; break;
4420 case '\'': output[d] = '\''; break;
4421 default: output[d] = ch;
4442 // String Unescape Copy
4444 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4445 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4446 public int UnescapeString(char * d, char * s, int len)
4450 while(j < len && (ch = s[j]))
4455 switch((ch = s[++j]))
4457 case 'n': d[k] = '\n'; break;
4458 case 't': d[k] = '\t'; break;
4459 case 'a': d[k] = '\a'; break;
4460 case 'b': d[k] = '\b'; break;
4461 case 'f': d[k] = '\f'; break;
4462 case 'r': d[k] = '\r'; break;
4463 case 'v': d[k] = '\v'; break;
4464 case '\\': d[k] = '\\'; break;
4465 case '\"': d[k] = '\"'; break;
4466 case '\'': d[k] = '\''; break;
4467 default: d[k] = '\\'; d[k] = ch;
4479 public char * OffsetEscapedString(char * s, int len, int offset)
4483 while(j < len && k < offset && (ch = s[j]))
4488 return (k == offset) ? s + j : null;
4491 public Operand GetOperand(Expression exp)
4494 Type type = exp.expType;
4497 while(type.kind == classType &&
4498 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4500 if(!type._class.registered.dataType)
4501 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4502 type = type._class.registered.dataType;
4505 if(exp.type == stringExp && op.kind == pointerType)
4507 op.ui64 = (uint64)exp.string;
4508 op.kind = pointerType;
4511 else if(exp.isConstant && exp.type == constantExp)
4513 op.kind = type.kind;
4521 if(exp.constant[0] == '\'')
4523 op.c = exp.constant[1];
4526 else if(type.isSigned)
4528 op.c = (char)strtol(exp.constant, null, 0);
4533 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4541 op.s = (short)strtol(exp.constant, null, 0);
4546 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4554 op.i = (int)strtol(exp.constant, null, 0);
4559 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4567 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4572 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4575 op.kind = int64Type;
4580 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4585 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4588 op.kind = int64Type;
4593 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4598 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4601 op.kind = int64Type;
4604 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4605 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4606 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4607 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4609 op.f = (float)strtod(exp.constant, null);
4613 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4614 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4615 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4616 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4618 op.d = (double)strtod(exp.constant, null);
4621 //case classType: For when we have operator overloading...
4622 // Pointer additions
4623 //case functionType:
4627 op.ui64 = _strtoui64(exp.constant, null, 0);
4628 op.kind = pointerType;
4638 static int64 GetEnumValue(Class _class, void * ptr)
4641 switch(_class.typeSize)
4644 if(!strcmp(_class.dataTypeString, "uint64"))
4645 v = (int64)*(uint64 *)ptr;
4647 v = (int64)*(int64 *)ptr;
4650 if(!strcmp(_class.dataTypeString, "uint"))
4651 v = (int64)*(uint *)ptr;
4653 v = (int64)*(int *)ptr;
4656 if(!strcmp(_class.dataTypeString, "uint16"))
4657 v = (int64)*(uint16 *)ptr;
4659 v = (int64)*(short *)ptr;
4662 if(!strcmp(_class.dataTypeString, "byte"))
4663 v = (int64)*(byte *)ptr;
4665 v = (int64)*(char *)ptr;
4671 static __attribute__((unused)) void UnusedFunction()
4674 a.OnGetString(0,0,0);
4677 extern int __ecereVMethodID_class_OnGetString;
4680 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4682 DataMember dataMember;
4683 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4685 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4686 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4690 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4692 void * ptr = inst.data + dataMember.offset + offset;
4693 char * result = null;
4694 exp.loc = member.loc = inst.loc;
4695 ((Identifier)member.identifiers->first).loc = inst.loc;
4697 if(!dataMember.dataType)
4698 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4699 type = dataMember.dataType;
4700 if(type.kind == classType)
4702 Class _class = type._class.registered;
4703 if(_class.type == enumClass)
4705 Class enumClass = eSystem_FindClass(privateModule, "enum");
4708 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4710 for(item = e.values.first; item; item = item.next)
4712 if(item.data == GetEnumValue(_class, ptr))
4720 exp.identifier = MkIdentifier(result);
4721 exp.type = identifierExp;
4722 exp.destType = MkClassType(_class.fullName);
4723 ProcessExpressionType(exp);
4727 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4729 if(!_class.dataType)
4730 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4731 type = _class.dataType;
4740 FreeExpContents(exp);
4742 exp.constant = PrintFloat(*(float*)ptr);
4743 exp.type = constantExp;
4748 FreeExpContents(exp);
4750 exp.constant = PrintDouble(*(double*)ptr);
4751 exp.type = constantExp;
4756 FreeExpContents(exp);
4758 exp.constant = PrintInt(*(int*)ptr);
4759 exp.type = constantExp;
4764 FreeExpContents(exp);
4766 exp.constant = PrintInt64(*(int64*)ptr);
4767 exp.type = constantExp;
4772 FreeExpContents(exp);
4773 // TODO: This should probably use proper type
4774 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4775 exp.type = constantExp;
4780 FreeExpContents(exp);
4781 // TODO: This should probably use proper type
4782 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4783 exp.type = constantExp;
4787 Compiler_Error($"Unhandled type populating instance\n");
4790 ListAdd(memberList, member);
4793 if(parentDataMember.type == unionMember)
4798 void PopulateInstance(Instantiation inst)
4800 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4801 Class _class = classSym.registered;
4802 DataMember dataMember;
4803 OldList * memberList = MkList();
4804 // Added this check and ->Add to prevent memory leaks on bad code
4806 inst.members = MkListOne(MkMembersInitList(memberList));
4808 inst.members->Add(MkMembersInitList(memberList));
4809 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4811 if(!dataMember.isProperty)
4813 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4814 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4818 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4820 void * ptr = inst.data + dataMember.offset;
4821 char * result = null;
4823 exp.loc = member.loc = inst.loc;
4824 ((Identifier)member.identifiers->first).loc = inst.loc;
4826 if(!dataMember.dataType)
4827 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4828 type = dataMember.dataType;
4829 if(type.kind == classType)
4831 Class _class = type._class.registered;
4832 if(_class.type == enumClass)
4834 Class enumClass = eSystem_FindClass(privateModule, "enum");
4837 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4839 for(item = e.values.first; item; item = item.next)
4841 if(item.data == GetEnumValue(_class, ptr))
4850 exp.identifier = MkIdentifier(result);
4851 exp.type = identifierExp;
4852 exp.destType = MkClassType(_class.fullName);
4853 ProcessExpressionType(exp);
4856 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4858 if(!_class.dataType)
4859 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4860 type = _class.dataType;
4869 exp.constant = PrintFloat(*(float*)ptr);
4870 exp.type = constantExp;
4875 exp.constant = PrintDouble(*(double*)ptr);
4876 exp.type = constantExp;
4881 exp.constant = PrintInt(*(int*)ptr);
4882 exp.type = constantExp;
4887 exp.constant = PrintInt64(*(int64*)ptr);
4888 exp.type = constantExp;
4893 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4894 exp.type = constantExp;
4898 Compiler_Error($"Unhandled type populating instance\n");
4901 ListAdd(memberList, member);
4907 void ComputeInstantiation(Expression exp)
4909 Instantiation inst = exp.instance;
4910 MembersInit members;
4911 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4912 Class _class = classSym ? classSym.registered : null;
4913 DataMember curMember = null;
4914 Class curClass = null;
4915 DataMember subMemberStack[256];
4916 int subMemberStackPos = 0;
4919 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4921 // Don't recompute the instantiation...
4922 // Non Simple classes will have become constants by now
4926 if(_class.type == normalClass || _class.type == noHeadClass)
4928 inst.data = (byte *)eInstance_New(_class);
4929 if(_class.type == normalClass)
4930 ((Instance)inst.data)._refCount++;
4933 inst.data = new0 byte[_class.structSize];
4938 for(members = inst.members->first; members; members = members.next)
4940 switch(members.type)
4942 case dataMembersInit:
4944 if(members.dataMembers)
4947 for(member = members.dataMembers->first; member; member = member.next)
4949 Identifier ident = member.identifiers ? member.identifiers->first : null;
4952 Property prop = null;
4953 DataMember dataMember = null;
4954 uint dataMemberOffset;
4958 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4961 if(curMember.isProperty)
4962 prop = (Property)curMember;
4965 dataMember = curMember;
4967 // CHANGED THIS HERE
4968 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4970 // 2013/17/29 -- It seems that this was missing here!
4971 if(_class.type == normalClass)
4972 dataMemberOffset += _class.base.structSize;
4973 // dataMemberOffset = dataMember.offset;
4980 prop = eClass_FindProperty(_class, ident.string, privateModule);
4984 if(prop.memberAccess == publicAccess)
4986 curMember = (DataMember)prop;
4987 curClass = prop._class;
4992 DataMember _subMemberStack[256];
4993 int _subMemberStackPos = 0;
4995 // FILL MEMBER STACK
4996 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
5001 if(dataMember.memberAccess == publicAccess)
5003 curMember = dataMember;
5004 curClass = dataMember._class;
5005 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
5006 subMemberStackPos = _subMemberStackPos;
5012 if(found && member.initializer && member.initializer.type == expInitializer)
5014 Expression value = member.initializer.exp;
5016 bool deepMember = false;
5019 type = prop.dataType;
5023 if(!dataMember.dataType)
5024 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
5026 type = dataMember.dataType;
5029 if(ident && ident.next)
5033 // for(; ident && type; ident = ident.next)
5034 for(ident = ident.next; ident && type; ident = ident.next)
5036 if(type.kind == classType)
5038 prop = eClass_FindProperty(type._class.registered,
5039 ident.string, privateModule);
5041 type = prop.dataType;
5044 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
5045 ident.string, &dataMemberOffset, privateModule, null, null);
5047 type = dataMember.dataType;
5050 else if(type.kind == structType || type.kind == unionType)
5053 for(memberType = type.members.first; memberType; memberType = memberType.next)
5055 if(!strcmp(memberType.name, ident.string))
5066 FreeType(value.destType);
5067 value.destType = type;
5068 if(type) type.refCount++;
5069 ComputeExpression(value);
5071 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
5073 if(type.kind == classType)
5075 Class _class = type._class.registered;
5076 if(_class.type == bitClass || _class.type == unitClass ||
5077 _class.type == enumClass)
5079 if(!_class.dataType)
5080 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5081 type = _class.dataType;
5087 void * ptr = inst.data + dataMemberOffset;
5089 if(value.type == constantExp)
5095 GetInt(value, (int*)ptr);
5100 GetInt64(value, (int64*)ptr);
5105 GetIntPtr(value, (intptr*)ptr);
5110 GetIntSize(value, (intsize*)ptr);
5115 GetFloat(value, (float*)ptr);
5120 GetDouble(value, (double *)ptr);
5125 else if(value.type == instanceExp)
5127 if(type.kind == classType)
5129 Class _class = type._class.registered;
5130 if(_class.type == structClass)
5132 ComputeTypeSize(type);
5133 if(value.instance.data)
5134 memcpy(ptr, value.instance.data, type.size);
5141 if(value.type == instanceExp && value.instance.data)
5143 if(type.kind == classType)
5145 Class _class = type._class.registered;
5146 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5148 void (*Set)(void *, void *) = (void *)prop.Set;
5149 Set(inst.data, value.instance.data);
5150 PopulateInstance(inst);
5154 else if(value.type == constantExp)
5160 void (*Set)(void *, double) = (void *)prop.Set;
5161 Set(inst.data, strtod(value.constant, null) );
5166 void (*Set)(void *, float) = (void *)prop.Set;
5167 Set(inst.data, (float)(strtod(value.constant, null)));
5172 void (*Set)(void *, int) = (void *)prop.Set;
5173 Set(inst.data, (int)strtol(value.constant, null, 0));
5178 void (*Set)(void *, int64) = (void *)prop.Set;
5179 Set(inst.data, _strtoi64(value.constant, null, 0));
5184 void (*Set)(void *, intptr) = (void *)prop.Set;
5185 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5190 void (*Set)(void *, intsize) = (void *)prop.Set;
5191 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5196 else if(value.type == stringExp)
5199 ReadString(temp, value.string);
5200 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5204 else if(!deepMember && type && _class.type == unitClass)
5208 // Only support converting units to units for now...
5209 if(value.type == constantExp)
5211 if(type.kind == classType)
5213 Class _class = type._class.registered;
5214 if(_class.type == unitClass)
5216 if(!_class.dataType)
5217 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5218 type = _class.dataType;
5221 // TODO: Assuming same base type for units...
5227 float (*Set)(float) = (void *)prop.Set;
5228 GetFloat(member.initializer.exp, &fValue);
5229 exp.constant = PrintFloat(Set(fValue));
5230 exp.type = constantExp;
5236 double (*Set)(double) = (void *)prop.Set;
5237 GetDouble(member.initializer.exp, &dValue);
5238 exp.constant = PrintDouble(Set(dValue));
5239 exp.type = constantExp;
5246 else if(!deepMember && type && _class.type == bitClass)
5250 if(value.type == instanceExp && value.instance.data)
5252 unsigned int (*Set)(void *) = (void *)prop.Set;
5253 bits = Set(value.instance.data);
5255 else if(value.type == constantExp)
5261 BitMember bitMember = (BitMember) dataMember;
5264 bits = (bits & ~bitMember.mask);
5265 if(!bitMember.dataType)
5266 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5267 type = bitMember.dataType;
5268 if(type.kind == classType && type._class && type._class.registered)
5270 if(!type._class.registered.dataType)
5271 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5272 type = type._class.registered.dataType;
5277 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5278 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5280 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5281 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5282 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5283 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5285 bits |= part << bitMember.pos;
5291 if(_class && _class.type == unitClass)
5293 ComputeExpression(member.initializer.exp);
5294 exp.constant = member.initializer.exp.constant;
5295 exp.type = constantExp;
5297 member.initializer.exp.constant = null;
5307 if(_class && _class.type == bitClass)
5309 exp.constant = PrintHexUInt(bits);
5310 exp.type = constantExp;
5312 if(exp.type != instanceExp)
5318 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5320 bool result = false;
5324 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5325 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5329 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5330 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5333 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5334 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5335 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5338 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5339 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5340 result = GetOpFloat(op, &op.f);
5343 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5344 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5345 result = GetOpDouble(op, &op.d);
5348 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5349 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5350 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5353 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5354 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5355 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5358 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5359 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5362 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5363 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5369 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5371 if(exp.op.op == SIZEOF)
5373 FreeExpContents(exp);
5374 exp.type = constantExp;
5375 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5386 // Provide default unary +
5387 Expression exp2 = exp.op.exp2;
5389 FreeExpContents(exp);
5390 FreeType(exp.expType);
5391 FreeType(exp.destType);
5397 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5399 // unary arithmetic increment and decrement
5400 //OPERATOR_ALL(UNARY, ++, Inc)
5401 //OPERATOR_ALL(UNARY, --, Dec)
5404 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5406 // unary logical negation
5408 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5414 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5416 if(Promote(op2, op1.kind, op1.type.isSigned))
5417 op2.kind = op1.kind, op2.ops = op1.ops;
5418 else if(Promote(op1, op2.kind, op2.type.isSigned))
5419 op1.kind = op2.kind, op1.ops = op2.ops;
5423 // binary arithmetic
5425 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5428 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5431 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5434 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5437 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5439 // binary arithmetic assignment
5440 //OPERATOR_ALL(BINARY, =, Asign)
5441 //OPERATOR_ALL(BINARY, +=, AddAsign)
5442 //OPERATOR_ALL(BINARY, -=, SubAsign)
5443 //OPERATOR_ALL(BINARY, *=, MulAsign)
5444 //OPERATOR_ALL(BINARY, /=, DivAsign)
5445 //OPERATOR_ALL(BINARY, %=, ModAsign)
5450 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5454 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5457 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5460 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5463 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5465 // binary bitwise assignment
5466 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5467 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5468 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5469 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5470 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5471 // binary logical equality
5473 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5476 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5480 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5483 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5485 // binary logical relational
5487 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5490 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5493 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5496 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5503 void ComputeExpression(Expression exp)
5506 char expString[10240];
5507 expString[0] = '\0';
5508 PrintExpression(exp, expString);
5515 ComputeInstantiation(exp);
5524 Expression exp1, exp2 = null;
5528 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5531 Expression e = exp.op.exp2;
5533 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5535 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5537 if(e.type == extensionCompoundExp)
5538 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5543 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5545 if(e.type == stringExp && e.string)
5547 char * string = e.string;
5548 int len = strlen(string);
5549 char * tmp = new char[len-2+1];
5550 len = UnescapeString(tmp, string + 1, len - 2);
5552 FreeExpContents(exp);
5553 exp.type = constantExp;
5554 exp.constant = PrintUInt(len + 1);
5558 Type type = e.expType;
5560 FreeExpContents(exp);
5561 exp.type = constantExp;
5562 exp.constant = PrintUInt(ComputeTypeSize(type));
5568 ComputeExpression(exp.op.exp2);
5572 ComputeExpression(exp.op.exp1);
5575 op1 = GetOperand(exp1);
5576 if(op1.type) op1.type.refCount++;
5579 op2 = GetOperand(exp2);
5580 if(op2.type) op2.type.refCount++;
5586 op1 = GetOperand(exp1);
5587 if(op1.type) op1.type.refCount++;
5590 CallOperator(exp, exp1, exp2, op1, op2);
5597 if(exp.op.exp1 && exp.op.exp2)
5602 FreeExpContents(exp);
5603 op1.ops.BitAnd(exp, op1, op2);
5612 FreeExpContents(exp);
5613 op1.ops.Mul(exp, op1, op2);
5622 FreeExpContents(exp);
5623 op1.ops.Add(exp, op1, op2);
5628 // Provide default unary +
5629 Expression exp2 = exp.op.exp2;
5631 FreeExpContents(exp);
5632 FreeType(exp.expType);
5633 FreeType(exp.destType);
5644 FreeExpContents(exp);
5645 op1.ops.Sub(exp, op1, op2);
5652 FreeExpContents(exp);
5653 op1.ops.Neg(exp, op1);
5660 FreeExpContents(exp);
5661 op1.ops.BitNot(exp, op1);
5667 FreeExpContents(exp);
5668 op1.ops.Not(exp, op1);
5671 // Binary only operators
5675 FreeExpContents(exp);
5676 op1.ops.Div(exp, op1, op2);
5682 FreeExpContents(exp);
5683 op1.ops.Mod(exp, op1, op2);
5695 FreeExpContents(exp);
5696 op1.ops.Sma(exp, op1, op2);
5705 FreeExpContents(exp);
5706 op1.ops.Grt(exp, op1, op2);
5715 FreeExpContents(exp);
5716 op1.ops.SmaEqu(exp, op1, op2);
5725 FreeExpContents(exp);
5726 op1.ops.GrtEqu(exp, op1, op2);
5735 FreeExpContents(exp);
5736 op1.ops.Equ(exp, op1, op2);
5745 FreeExpContents(exp);
5746 op1.ops.Nqu(exp, op1, op2);
5753 FreeExpContents(exp);
5754 op1.ops.BitOr(exp, op1, op2);
5760 FreeExpContents(exp);
5761 op1.ops.BitXor(exp, op1, op2);
5769 FreeExpContents(exp);
5770 exp.type = constantExp;
5771 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5775 if(op1.type) FreeType(op1.type);
5776 if(op2.type) FreeType(op2.type);
5780 case extensionExpressionExp:
5783 for(e = exp.list->first; e; e = n)
5788 OldList * list = exp.list;
5789 Expression prev = exp.prev;
5790 Expression next = exp.next;
5791 ComputeExpression(e);
5792 //FreeExpContents(exp);
5793 FreeType(exp.expType);
5794 FreeType(exp.destType);
5813 exp.isConstant = true;
5815 ComputeExpression(exp.index.exp);
5816 if(!exp.index.exp.isConstant)
5817 exp.isConstant = false;
5819 for(e = exp.index.index->first; e; e = e.next)
5821 ComputeExpression(e);
5824 // Check if this type is int
5827 exp.isConstant = false;
5829 exp.expType = Dereference(exp.index.exp.expType);
5835 Expression memberExp = exp.member.exp;
5836 Identifier memberID = exp.member.member;
5839 ComputeExpression(exp.member.exp);
5840 type = exp.member.exp.expType;
5843 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);
5844 Property prop = null;
5845 DataMember member = null;
5846 Class convertTo = null;
5847 if(type.kind == subClassType && exp.member.exp.type == classExp)
5848 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5855 PrintTypeNoConst(type, string, false, true);
5856 classSym = FindClass(string);
5857 _class = classSym ? classSym.registered : null;
5860 if(exp.member.member)
5862 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5864 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5866 if(!prop && !member && _class && exp.member.member)
5868 Symbol classSym = FindClass(exp.member.member.string);
5870 _class = classSym ? classSym.registered : null;
5871 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5878 Type type = prop.dataType;
5879 // TODO: Assuming same base type for units...
5880 if(_class.type == unitClass)
5882 if(type.kind == classType)
5884 Class _class = type._class.registered;
5885 if(_class.type == unitClass)
5887 if(!_class.dataType)
5888 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5889 type = _class.dataType;
5897 float (*Get)(float) = (void *)prop.Get;
5898 GetFloat(exp.member.exp, &value);
5899 exp.constant = PrintFloat(Get ? Get(value) : value);
5900 exp.type = constantExp;
5906 double (*Get)(double);
5907 GetDouble(exp.member.exp, &value);
5910 Get = (void *)prop.Set;
5912 Get = (void *)prop.Get;
5913 exp.constant = PrintDouble(Get ? Get(value) : value);
5914 exp.type = constantExp;
5923 Expression value = exp.member.exp;
5926 ProcessPropertyType(prop);
5928 type = prop.dataType;
5931 // printf("Investigate this\n");
5933 else if(_class.type == structClass)
5939 Class propertyClass = type._class.registered;
5940 if(propertyClass.type == structClass && value.type == instanceExp)
5942 void (*Set)(void *, void *) = (void *)prop.Set;
5943 exp.instance = Instantiation { };
5944 exp.instance.data = new0 byte[_class.structSize];
5945 exp.instance._class = MkSpecifierName(_class.fullName);
5946 exp.instance.loc = exp.loc;
5947 exp.type = instanceExp;
5948 Set(exp.instance.data, value.instance.data);
5949 PopulateInstance(exp.instance);
5956 void (*Set)(void *, int) = (void *)prop.Set;
5958 exp.instance = Instantiation { };
5959 exp.instance.data = new0 byte[_class.structSize];
5960 exp.instance._class = MkSpecifierName(_class.fullName);
5961 exp.instance.loc = exp.loc;
5962 exp.type = instanceExp;
5964 GetInt(value, &intValue);
5966 Set(exp.instance.data, intValue);
5967 PopulateInstance(exp.instance);
5973 void (*Set)(void *, int64) = (void *)prop.Set;
5975 exp.instance = Instantiation { };
5976 exp.instance.data = new0 byte[_class.structSize];
5977 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5978 exp.instance.loc = exp.loc;
5979 exp.type = instanceExp;
5981 GetInt64(value, &intValue);
5983 Set(exp.instance.data, intValue);
5984 PopulateInstance(exp.instance);
5991 void (*Set)(void *, intptr) = (void *)prop.Set;
5993 exp.instance = Instantiation { };
5994 exp.instance.data = new0 byte[_class.structSize];
5995 exp.instance._class = MkSpecifierName(_class.fullName);
5996 exp.instance.loc = exp.loc;
5997 exp.type = instanceExp;
5999 GetIntPtr(value, &intValue);
6001 Set(exp.instance.data, intValue);
6002 PopulateInstance(exp.instance);
6009 void (*Set)(void *, intsize) = (void *)prop.Set;
6011 exp.instance = Instantiation { };
6012 exp.instance.data = new0 byte[_class.structSize];
6013 exp.instance._class = MkSpecifierName(_class.fullName);
6014 exp.instance.loc = exp.loc;
6015 exp.type = instanceExp;
6017 GetIntSize(value, &intValue);
6019 Set(exp.instance.data, intValue);
6020 PopulateInstance(exp.instance);
6026 void (*Set)(void *, float) = (void *)prop.Set;
6028 exp.instance = Instantiation { };
6029 exp.instance.data = new0 byte[_class.structSize];
6030 exp.instance._class = MkSpecifierName(_class.fullName);
6031 exp.instance.loc = exp.loc;
6032 exp.type = instanceExp;
6034 GetFloat(value, &floatValue);
6036 Set(exp.instance.data, floatValue);
6037 PopulateInstance(exp.instance);
6043 void (*Set)(void *, double) = (void *)prop.Set;
6045 exp.instance = Instantiation { };
6046 exp.instance.data = new0 byte[_class.structSize];
6047 exp.instance._class = MkSpecifierName(_class.fullName);
6048 exp.instance.loc = exp.loc;
6049 exp.type = instanceExp;
6051 GetDouble(value, &doubleValue);
6053 Set(exp.instance.data, doubleValue);
6054 PopulateInstance(exp.instance);
6059 else if(_class.type == bitClass)
6065 Class propertyClass = type._class.registered;
6066 if(propertyClass.type == structClass && value.instance.data)
6068 unsigned int (*Set)(void *) = (void *)prop.Set;
6069 unsigned int bits = Set(value.instance.data);
6070 exp.constant = PrintHexUInt(bits);
6071 exp.type = constantExp;
6074 else if(_class.type == bitClass)
6077 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6080 GetUInt(exp.member.exp, &value);
6082 exp.constant = PrintHexUInt(bits);
6083 exp.type = constantExp;
6091 if(_class.type == bitClass)
6094 GetUInt(exp.member.exp, &value);
6100 Class _class = type._class.registered;
6101 if(_class.type == structClass)
6103 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6105 exp.instance = Instantiation { };
6106 exp.instance.data = new0 byte[_class.structSize];
6107 exp.instance._class = MkSpecifierName(_class.fullName);
6108 exp.instance.loc = exp.loc;
6109 //exp.instance.fullSet = true;
6110 exp.type = instanceExp;
6111 Get(value, exp.instance.data);
6112 PopulateInstance(exp.instance);
6114 else if(_class.type == bitClass)
6116 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6117 uint64 bits = Get(value);
6118 exp.constant = PrintHexUInt64(bits);
6119 exp.type = constantExp;
6125 else if(_class.type == structClass)
6127 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6132 Class _class = type._class.registered;
6133 if(_class.type == structClass && value)
6135 void (*Get)(void *, void *) = (void *)prop.Get;
6137 exp.instance = Instantiation { };
6138 exp.instance.data = new0 byte[_class.structSize];
6139 exp.instance._class = MkSpecifierName(_class.fullName);
6140 exp.instance.loc = exp.loc;
6141 //exp.instance.fullSet = true;
6142 exp.type = instanceExp;
6143 Get(value, exp.instance.data);
6144 PopulateInstance(exp.instance);
6152 char * value = exp.member.exp.instance.data;
6157 Class _class = type._class.registered;
6158 if(_class.type == normalClass)
6160 void *(*Get)(void *) = (void *)prop.Get;
6162 exp.instance = Instantiation { };
6163 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6164 exp.type = instanceExp;
6165 exp.instance.data = Get(value, exp.instance.data);
6177 exp.isConstant = false;
6185 if(exp.type != ExpressionType::memberExp)
6187 FreeExpression(memberExp);
6188 FreeIdentifier(memberID);
6194 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6195 FreeExpContents(exp);
6196 exp.constant = PrintUInt(ComputeTypeSize(type));
6197 exp.type = constantExp;
6203 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6204 if(classSym && classSym.registered)
6206 if(classSym.registered.fixed)
6208 FreeSpecifier(exp._class);
6209 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6210 exp.type = constantExp;
6214 char className[1024];
6215 strcpy(className, "__ecereClass_");
6216 FullClassNameCat(className, classSym.string, true);
6217 //MangleClassName(className);
6219 DeclareClass(classSym, className);
6221 FreeExpContents(exp);
6222 exp.type = pointerExp;
6223 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6224 exp.member.member = MkIdentifier("structSize");
6234 if(exp.type == castExp)
6237 ComputeExpression(exp.cast.exp);
6240 if(e && exp.expType)
6243 type = exp.destType;
6246 if(type.kind == classType)
6248 Class _class = type._class.registered;
6249 if(_class && (_class.type == unitClass || _class.type == bitClass))
6251 if(!_class.dataType)
6252 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6253 type = _class.dataType;
6264 if(GetChar(e, &value))
6266 FreeExpContents(exp);
6267 exp.constant = PrintChar(value);
6268 exp.type = constantExp;
6273 unsigned char value = 0;
6274 if(GetUChar(e, &value))
6276 FreeExpContents(exp);
6277 exp.constant = PrintUChar(value);
6278 exp.type = constantExp;
6286 if(GetShort(e, &value))
6288 FreeExpContents(exp);
6289 exp.constant = PrintShort(value);
6290 exp.type = constantExp;
6295 unsigned short value = 0;
6296 if(GetUShort(e, &value))
6298 FreeExpContents(exp);
6299 exp.constant = PrintUShort(value);
6300 exp.type = constantExp;
6308 if(GetInt(e, &value))
6310 FreeExpContents(exp);
6311 exp.constant = PrintInt(value);
6312 exp.type = constantExp;
6317 unsigned int value = 0;
6318 if(GetUInt(e, &value))
6320 FreeExpContents(exp);
6321 exp.constant = PrintUInt(value);
6322 exp.type = constantExp;
6330 if(GetInt64(e, &value))
6332 FreeExpContents(exp);
6333 exp.constant = PrintInt64(value);
6334 exp.type = constantExp;
6340 if(GetUInt64(e, &value))
6342 FreeExpContents(exp);
6343 exp.constant = PrintUInt64(value);
6344 exp.type = constantExp;
6352 if(GetIntPtr(e, &value))
6354 FreeExpContents(exp);
6355 exp.constant = PrintInt64((int64)value);
6356 exp.type = constantExp;
6362 if(GetUIntPtr(e, &value))
6364 FreeExpContents(exp);
6365 exp.constant = PrintUInt64((uint64)value);
6366 exp.type = constantExp;
6374 if(GetIntSize(e, &value))
6376 FreeExpContents(exp);
6377 exp.constant = PrintInt64((int64)value);
6378 exp.type = constantExp;
6384 if(GetUIntSize(e, &value))
6386 FreeExpContents(exp);
6387 exp.constant = PrintUInt64((uint64)value);
6388 exp.type = constantExp;
6395 if(GetFloat(e, &value))
6397 FreeExpContents(exp);
6398 exp.constant = PrintFloat(value);
6399 exp.type = constantExp;
6406 if(GetDouble(e, &value))
6408 FreeExpContents(exp);
6409 exp.constant = PrintDouble(value);
6410 exp.type = constantExp;
6425 // Caring only about last expression for now...
6426 ComputeExpression(exp.cond.exp->last);
6427 if(exp.cond.elseExp)
6428 ComputeExpression(exp.cond.elseExp);
6430 ComputeExpression(exp.cond.cond);
6432 op1 = GetOperand(exp.cond.cond);
6433 if(op1.type) op1.type.refCount++;
6434 op2 = GetOperand(exp.cond.exp->last);
6435 if(op2.type) op2.type.refCount++;
6436 op3 = GetOperand(exp.cond.elseExp);
6437 if(op3.type) op3.type.refCount++;
6439 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6440 if(op1.type) FreeType(op1.type);
6441 if(op2.type) FreeType(op2.type);
6442 if(op3.type) FreeType(op3.type);
6448 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6453 OldList converts { };
6456 if(destType.kind == voidType)
6459 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6463 // for(convert = converts.last; convert; convert = convert.prev)
6464 for(convert = converts.first; convert; convert = convert.next)
6466 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6469 Expression newExp { };
6470 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6472 // TODO: Check this...
6476 newExp.destType = null;
6481 exp.type = memberExp;
6482 exp.addedThis = true;
6483 exp.member.exp = newExp;
6484 FreeType(exp.member.exp.expType);
6486 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6487 exp.member.exp.expType.classObjectType = objectType;
6488 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6489 exp.member.memberType = propertyMember;
6490 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6491 // TESTING THIS... for (int)degrees
6492 exp.needCast = true;
6493 if(exp.expType) exp.expType.refCount++;
6494 ApplyAnyObjectLogic(exp.member.exp);
6499 /*if(exp.isConstant)
6501 // Color { ColorRGB = [exp] };
6502 exp.type = instanceExp;
6503 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6504 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6505 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6509 // If not constant, don't turn it yet into an instantiation
6510 // (Go through the deep members system first)
6511 exp.type = memberExp;
6512 exp.addedThis = true;
6513 exp.member.exp = newExp;
6515 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6516 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6517 newExp.expType._class.registered.type == noHeadClass)
6519 newExp.byReference = true;
6522 FreeType(exp.member.exp.expType);
6523 /*exp.member.exp.expType = convert.convert.dataType;
6524 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6525 exp.member.exp.expType = null;
6526 if(convert.convert.dataType)
6528 exp.member.exp.expType = { };
6529 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6530 exp.member.exp.expType.refCount = 1;
6531 exp.member.exp.expType.classObjectType = objectType;
6532 ApplyAnyObjectLogic(exp.member.exp);
6535 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6536 exp.member.memberType = reverseConversionMember;
6537 exp.expType = convert.resultType ? convert.resultType :
6538 MkClassType(convert.convert._class.fullName);
6539 exp.needCast = true;
6540 if(convert.resultType) convert.resultType.refCount++;
6546 FreeType(exp.expType);
6549 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6550 if(exp.destType.casted)
6551 exp.needCast = true;
6552 if(exp.expType) exp.expType.refCount++;
6556 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6557 if(exp.destType.casted)
6558 exp.needCast = true;
6559 if(convert.resultType)
6560 convert.resultType.refCount++;
6564 if(exp.isConstant && inCompiler)
6565 ComputeExpression(exp);
6567 converts.Free(FreeConvert);
6570 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6572 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6574 if(!result && exp.expType && exp.destType)
6576 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6577 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6578 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6579 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6583 // if(result) CheckTemplateTypes(exp);
6587 void CheckTemplateTypes(Expression exp)
6589 Expression nbExp = GetNonBracketsExp(exp);
6590 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6591 (nbExp == exp || nbExp.type != castExp))
6593 Expression newExp { };
6596 if(exp.destType) exp.destType.refCount++;
6597 if(exp.expType) exp.expType.refCount++;
6601 switch(exp.expType.kind)
6604 if(exp.destType.classObjectType)
6606 // We need to pass the address, just pass it along (Undo what was done above)
6607 if(exp.destType) exp.destType.refCount--;
6608 if(exp.expType) exp.expType.refCount--;
6613 // If we're looking for value:
6614 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6616 OldList * unionDefs = MkList();
6617 OldList * statements = MkList();
6618 context = PushContext();
6619 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6620 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6621 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6622 exp.type = extensionCompoundExp;
6623 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6624 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6625 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6626 exp.compound.compound.context = context;
6627 PopContext(context);
6632 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6633 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6634 exp.needCast = true;
6638 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6640 Expression newExp { };
6643 if(exp.destType) exp.destType.refCount++;
6644 if(exp.expType) exp.expType.refCount++;
6648 switch(exp.expType.kind)
6651 if(exp.destType.classObjectType)
6653 // We need to pass the address, just pass it along (Undo what was done above)
6654 if(exp.destType) exp.destType.refCount--;
6655 if(exp.expType) exp.expType.refCount--;
6660 // If we're looking for value:
6661 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6663 OldList * unionDefs = MkList();
6664 OldList * statements = MkList();
6665 context = PushContext();
6666 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6667 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6668 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6669 exp.type = extensionCompoundExp;
6670 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6671 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6672 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6673 exp.compound.compound.context = context;
6674 PopContext(context);
6679 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6681 exp.type = bracketsExp;
6682 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6683 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6684 ProcessExpressionType(exp.list->first);
6689 exp.type = bracketsExp;
6690 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6691 exp.needTemplateCast = 2;
6692 newExp.needCast = true;
6693 newExp.needTemplateCast = 2;
6694 ProcessExpressionType(exp.list->first);
6700 if(exp.expType.kind == templateType)
6702 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6705 FreeType(exp.destType);
6706 FreeType(exp.expType);
6711 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6716 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6717 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6721 char typeString[1024];
6723 OldList * specs = MkList();
6724 typeString[0] = '\0';
6725 PrintType(exp.expType, typeString, false, false);
6726 decl = SpecDeclFromString(typeString, specs, null);
6729 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6730 exp.cast.typeName = MkTypeName(specs, decl);
6731 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6732 exp.cast.exp.needCast = true;
6739 // TODO: The Symbol tree should be reorganized by namespaces
6741 // - Tree of all symbols within (stored without namespace)
6742 // - Tree of sub-namespaces
6744 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6746 int nsLen = strlen(nameSpace);
6748 // Start at the name space prefix
6749 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6751 char * s = symbol.string;
6752 if(!strncmp(s, nameSpace, nsLen))
6754 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6757 for(c = strlen(s)-1; c >= 0; c--)
6762 if(!strcmp(namePart, name))
6764 // TODO: Error on ambiguity
6774 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6777 char nameSpace[1024];
6778 const char * namePart;
6779 bool gotColon = false;
6781 nameSpace[0] = '\0';
6782 for(c = strlen(name)-1; c >= 0; c--)
6789 namePart = name+c+1;
6790 while(c >= 0 && name[c] == ':') c--;
6793 // Try an exact match first
6794 Symbol symbol = (Symbol)tree.FindString(name);
6798 // Namespace specified
6799 memcpy(nameSpace, name, c + 1);
6802 return ScanWithNameSpace(tree, nameSpace, namePart);
6806 // Looking for a global symbol, e.g. ::Sleep()
6807 Symbol symbol = (Symbol)tree.FindString(namePart);
6812 // Name only (no namespace specified)
6813 Symbol symbol = (Symbol)tree.FindString(namePart);
6816 return ScanWithNameSpace(tree, "", namePart);
6821 static void ProcessDeclaration(Declaration decl);
6823 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6826 //Time startTime = GetTime();
6828 // Optimize this later? Do this before/less?
6830 Symbol symbol = null;
6831 // First, check if the identifier is declared inside the function
6832 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6834 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6836 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6842 strcpy(curName, thisNameSpace);
6843 strcat(curName, "::");
6844 strcat(curName, name);
6845 // Try to resolve in current namespace first
6846 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6849 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6852 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6854 if(symbol || ctx == endContext) break;
6856 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6858 if(symbol.pointerExternal.type == functionExternal)
6860 FunctionDefinition function = symbol.pointerExternal.function;
6862 // Modified this recently...
6863 Context tmpContext = curContext;
6865 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6866 curContext = tmpContext;
6868 symbol.pointerExternal.symbol = symbol;
6871 DeclareType(symbol.type, true, true);
6873 ast->Insert(curExternal.prev, symbol.pointerExternal);
6875 symbol.id = curExternal.symbol.idCode;
6878 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6880 ast->Move(symbol.pointerExternal, curExternal.prev);
6881 symbol.id = curExternal.symbol.idCode;
6885 //findSymbolTotalTime += GetTime() - startTime;
6890 static void GetTypeSpecs(Type type, OldList * specs)
6892 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6897 if(type._class.registered)
6899 if(!type._class.registered.dataType)
6900 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6901 GetTypeSpecs(type._class.registered.dataType, specs);
6905 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6906 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6907 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6908 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6909 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6910 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6911 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6912 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6915 ListAdd(specs, MkSpecifier(INT)); break;
6919 static void PrintArraySize(Type arrayType, char * string)
6924 if(arrayType.enumClass)
6925 strcat(size, arrayType.enumClass.string);
6926 else if(arrayType.arraySizeExp)
6927 PrintExpression(arrayType.arraySizeExp, size);
6929 strcat(string, size);
6932 // WARNING : This function expects a null terminated string since it recursively concatenate...
6933 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6937 if(printConst && type.constant)
6938 strcat(string, "const ");
6943 Symbol c = type._class;
6944 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6945 // look into merging with thisclass ?
6946 if(type.classObjectType == typedObject)
6947 strcat(string, "typed_object");
6948 else if(type.classObjectType == anyObject)
6949 strcat(string, "any_object");
6953 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6955 if(type.byReference)
6956 strcat(string, " &");
6959 case voidType: strcat(string, "void"); break;
6960 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6961 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6962 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6963 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6964 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6965 case _BoolType: strcat(string, "_Bool"); break;
6966 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6967 case floatType: strcat(string, "float"); break;
6968 case doubleType: strcat(string, "double"); break;
6972 strcat(string, "struct ");
6973 strcat(string, type.enumName);
6975 else if(type.typeName)
6976 strcat(string, type.typeName);
6980 strcat(string, "struct { ");
6981 for(member = type.members.first; member; member = member.next)
6983 PrintType(member, string, true, fullName);
6984 strcat(string,"; ");
6992 strcat(string, "union ");
6993 strcat(string, type.enumName);
6995 else if(type.typeName)
6996 strcat(string, type.typeName);
6999 strcat(string, "union ");
7000 strcat(string,"(unnamed)");
7006 strcat(string, "enum ");
7007 strcat(string, type.enumName);
7009 else if(type.typeName)
7010 strcat(string, type.typeName);
7012 strcat(string, "int"); // "enum");
7015 strcat(string, "...");
7018 strcat(string, "subclass(");
7019 strcat(string, type._class ? type._class.string : "int");
7020 strcat(string, ")");
7023 strcat(string, type.templateParameter.identifier.string);
7026 strcat(string, "thisclass");
7029 strcat(string, "__builtin_va_list");
7035 static void PrintName(Type type, char * string, bool fullName)
7037 if(type.name && type.name[0])
7040 strcat(string, type.name);
7043 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7044 if(name) name += 2; else name = type.name;
7045 strcat(string, name);
7050 static void PrintAttribs(Type type, char * string)
7054 if(type.dllExport) strcat(string, "dllexport ");
7055 if(type.attrStdcall) strcat(string, "stdcall ");
7059 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7061 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7063 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7064 PrintAttribs(type, string);
7065 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7066 strcat(string, " const");
7067 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7068 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7069 strcat(string, " (");
7070 if(type.kind == pointerType)
7072 if(type.type.kind == functionType || type.type.kind == methodType)
7073 PrintAttribs(type.type, string);
7075 if(type.kind == pointerType)
7077 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7078 strcat(string, "*");
7080 strcat(string, " *");
7082 if(printConst && type.constant && type.kind == pointerType)
7083 strcat(string, " const");
7086 PrintTypeSpecs(type, string, fullName, printConst);
7089 static void PostPrintType(Type type, char * string, bool fullName)
7091 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7092 strcat(string, ")");
7093 if(type.kind == arrayType)
7094 PrintArraySize(type, string);
7095 else if(type.kind == functionType)
7098 strcat(string, "(");
7099 for(param = type.params.first; param; param = param.next)
7101 PrintType(param, string, true, fullName);
7102 if(param.next) strcat(string, ", ");
7104 strcat(string, ")");
7106 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7107 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7111 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7113 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7115 PrePrintType(type, string, fullName, null, printConst);
7117 if(type.thisClass || (printName && type.name && type.name[0]))
7118 strcat(string, " ");
7119 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7121 Symbol _class = type.thisClass;
7122 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7124 if(type.classObjectType == classPointer)
7125 strcat(string, "class");
7127 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7129 else if(_class && _class.string)
7131 String s = _class.string;
7136 char * name = RSearchString(s, "::", strlen(s), true, false);
7137 if(name) name += 2; else name = s;
7138 strcat(string, name);
7141 strcat(string, "::");
7144 if(printName && type.name)
7145 PrintName(type, string, fullName);
7146 PostPrintType(type, string, fullName);
7147 if(type.bitFieldCount)
7150 sprintf(count, ":%d", type.bitFieldCount);
7151 strcat(string, count);
7155 void PrintType(Type type, char * string, bool printName, bool fullName)
7157 _PrintType(type, string, printName, fullName, true);
7160 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7162 _PrintType(type, string, printName, fullName, false);
7165 static Type FindMember(Type type, char * string)
7168 for(memberType = type.members.first; memberType; memberType = memberType.next)
7170 if(!memberType.name)
7172 Type subType = FindMember(memberType, string);
7176 else if(!strcmp(memberType.name, string))
7182 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7185 for(memberType = type.members.first; memberType; memberType = memberType.next)
7187 if(!memberType.name)
7189 Type subType = FindMember(memberType, string);
7192 *offset += memberType.offset;
7196 else if(!strcmp(memberType.name, string))
7198 *offset += memberType.offset;
7205 public bool GetParseError() { return parseError; }
7207 Expression ParseExpressionString(char * expression)
7211 fileInput = TempFile { };
7212 fileInput.Write(expression, 1, strlen(expression));
7213 fileInput.Seek(0, start);
7216 parsedExpression = null;
7218 expression_yyparse();
7221 return parsedExpression;
7224 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7226 Identifier id = exp.identifier;
7227 Method method = null;
7228 Property prop = null;
7229 DataMember member = null;
7230 ClassProperty classProp = null;
7232 if(_class && _class.type == enumClass)
7234 NamedLink64 value = null;
7235 Class enumClass = eSystem_FindClass(privateModule, "enum");
7239 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7241 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7242 for(value = e.values.first; value; value = value.next)
7244 if(!strcmp(value.name, id.string))
7251 FreeExpContents(exp);
7253 exp.type = constantExp;
7254 exp.isConstant = true;
7255 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7256 sprintf(constant, FORMAT64D, value.data);
7258 sprintf(constant, FORMAT64HEX, value.data);
7259 exp.constant = CopyString(constant);
7260 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7261 exp.expType = MkClassType(baseClass.fullName);
7269 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7271 ProcessMethodType(method);
7278 // TOCHECK: Put it back to what it was...
7279 // methodClass = _class;
7280 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7285 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7288 ProcessPropertyType(prop);
7289 exp.expType = prop.dataType;
7290 if(prop.dataType) prop.dataType.refCount++;
7293 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7295 if(!member.dataType)
7296 member.dataType = ProcessTypeString(member.dataTypeString, false);
7297 exp.expType = member.dataType;
7298 if(member.dataType) member.dataType.refCount++;
7301 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7303 if(!classProp.dataType)
7304 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7306 if(classProp.constant)
7308 FreeExpContents(exp);
7310 exp.isConstant = true;
7311 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7313 //char constant[256];
7314 exp.type = stringExp;
7315 exp.constant = QMkString((char *)classProp.Get(_class));
7320 exp.type = constantExp;
7321 sprintf(constant, "%d", (int)classProp.Get(_class));
7322 exp.constant = CopyString(constant);
7330 exp.expType = classProp.dataType;
7331 if(classProp.dataType) classProp.dataType.refCount++;
7337 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7339 BinaryTree * tree = &nameSpace.functions;
7340 GlobalData data = (GlobalData)tree->FindString(name);
7344 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7346 data = ScanGlobalData(child, name);
7354 static GlobalData FindGlobalData(char * name)
7357 NameSpace * nameSpace;
7358 nameSpace = globalData;
7359 for(c = 0; name[c]; c++)
7361 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7363 NameSpace * newSpace;
7364 char * spaceName = new char[c - start + 1];
7365 strncpy(spaceName, name + start, c - start);
7366 spaceName[c-start] = '\0';
7367 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7371 nameSpace = newSpace;
7372 if(name[c] == ':') c++;
7378 return ScanGlobalData(nameSpace, name + start);
7383 static int definedExpStackPos;
7384 static void * definedExpStack[512];
7386 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7387 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7389 Expression prev = checkedExp.prev, next = checkedExp.next;
7391 FreeExpContents(checkedExp);
7392 FreeType(checkedExp.expType);
7393 FreeType(checkedExp.destType);
7395 *checkedExp = *newExp;
7399 checkedExp.prev = prev;
7400 checkedExp.next = next;
7403 void ApplyAnyObjectLogic(Expression e)
7405 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7407 char debugExpString[4096];
7408 debugExpString[0] = '\0';
7409 PrintExpression(e, debugExpString);
7412 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7414 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7415 //ellipsisDestType = destType;
7418 Type type = e.expType;
7419 Class _class = null;
7420 //Type destType = e.destType;
7422 if(type.kind == classType && type._class && type._class.registered)
7424 _class = type._class.registered;
7426 else if(type.kind == subClassType)
7428 _class = FindClass("ecere::com::Class").registered;
7432 char string[1024] = "";
7435 PrintTypeNoConst(type, string, false, true);
7436 classSym = FindClass(string);
7437 if(classSym) _class = classSym.registered;
7440 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...
7441 (!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))) ||
7442 destType.byReference)))
7444 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7446 Expression checkedExp = e, newExp;
7448 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7450 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7452 if(checkedExp.type == extensionCompoundExp)
7454 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7457 checkedExp = checkedExp.list->last;
7459 else if(checkedExp.type == castExp)
7460 checkedExp = checkedExp.cast.exp;
7463 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7465 newExp = checkedExp.op.exp2;
7466 checkedExp.op.exp2 = null;
7467 FreeExpContents(checkedExp);
7469 if(e.expType && e.expType.passAsTemplate)
7472 ComputeTypeSize(e.expType);
7473 sprintf(size, "%d", e.expType.size);
7474 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7475 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7476 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7479 ReplaceExpContents(checkedExp, newExp);
7480 e.byReference = true;
7482 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7484 Expression checkedExp; //, newExp;
7487 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7489 e.type == identifierExp ||
7490 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7491 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7492 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7495 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7497 Context context = PushContext();
7499 OldList * specs = MkList();
7500 char typeString[1024];
7501 Expression newExp { };
7503 typeString[0] = '\0';
7506 //if(e.destType) e.destType.refCount++;
7507 // if(exp.expType) exp.expType.refCount++;
7510 newExp.expType = null;
7512 PrintTypeNoConst(e.expType, typeString, false, true);
7513 decl = SpecDeclFromString(typeString, specs, null);
7514 newExp.destType = ProcessType(specs, decl);
7516 curContext = context;
7518 // We need a current compound for this
7522 OldList * stmts = MkList();
7523 e.type = extensionCompoundExp;
7524 sprintf(name, "__internalValue%03X", internalValueCounter++);
7525 if(!curCompound.compound.declarations)
7526 curCompound.compound.declarations = MkList();
7527 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7528 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7529 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7530 e.compound = MkCompoundStmt(null, stmts);
7533 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7536 e.compound = MkCompoundStmt(
7537 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7538 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7540 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7544 Type type = e.destType;
7546 CopyTypeInto(e.destType, type);
7547 e.destType.refCount = 1;
7548 e.destType.classObjectType = none;
7552 e.compound.compound.context = context;
7553 PopContext(context);
7554 curContext = context.parent;
7558 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7560 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7562 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7564 if(checkedExp.type == extensionCompoundExp)
7566 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7569 checkedExp = checkedExp.list->last;
7571 else if(checkedExp.type == castExp)
7572 checkedExp = checkedExp.cast.exp;
7575 Expression operand { };
7576 operand = *checkedExp;
7578 checkedExp.destType = ProcessTypeString("void *", false);
7579 checkedExp.expType = checkedExp.destType;
7580 checkedExp.destType.refCount++;
7582 checkedExp.type = opExp;
7583 checkedExp.op.op = '&';
7584 checkedExp.op.exp1 = null;
7585 checkedExp.op.exp2 = operand;
7587 //newExp = MkExpOp(null, '&', checkedExp);
7589 //ReplaceExpContents(checkedExp, newExp);
7596 // If expression type is a simple class, make it an address
7597 // FixReference(e, true);
7600 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7601 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7602 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7604 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"))
7606 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7610 Expression thisExp { };
7613 thisExp.prev = null;
7614 thisExp.next = null;
7617 e.type = bracketsExp;
7618 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7619 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7620 ((Expression)e.list->first).byReference = true;
7622 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7624 e.expType = thisExp.expType;
7625 e.expType.refCount++;
7630 CopyTypeInto(e.expType, thisExp.expType);
7631 e.expType.byReference = false;
7632 e.expType.refCount = 1;
7634 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7635 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7637 e.expType.classObjectType = none;
7642 // TOFIX: Try this for a nice IDE crash!
7644 // The other way around
7647 if(destType && e.expType &&
7648 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7649 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7650 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7652 if(destType.kind == ellipsisType)
7654 Compiler_Error($"Unspecified type\n");
7656 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7658 bool byReference = e.expType.byReference;
7659 Expression thisExp { };
7661 OldList * specs = MkList();
7662 char typeString[1024]; // Watch buffer overruns
7664 ClassObjectType backupClassObjectType;
7665 bool backupByReference;
7667 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7672 backupClassObjectType = type.classObjectType;
7673 backupByReference = type.byReference;
7675 type.classObjectType = none;
7676 type.byReference = false;
7678 typeString[0] = '\0';
7679 PrintType(type, typeString, false, true);
7680 decl = SpecDeclFromString(typeString, specs, null);
7682 type.classObjectType = backupClassObjectType;
7683 type.byReference = backupByReference;
7686 thisExp.prev = null;
7687 thisExp.next = null;
7690 if( ( type.kind == classType && type._class && type._class.registered &&
7691 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7692 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7693 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7694 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7699 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7702 CopyTypeInto(e.expType, type);
7703 e.expType.byReference = false;
7704 e.expType.refCount = 1;
7709 e.cast.typeName = MkTypeName(specs, decl);
7710 e.cast.exp = thisExp;
7711 e.byReference = true;
7715 e.destType = destType;
7716 destType.refCount++;
7721 void ApplyLocation(Expression exp, Location loc)
7727 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7728 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7734 for(e = exp.list->first; e; e = e.next)
7735 ApplyLocation(e, loc);
7742 for(e = exp.index.index->first; e; e = e.next)
7743 ApplyLocation(e, loc);
7746 ApplyLocation(exp.index.exp, loc);
7749 if(exp.call.arguments)
7752 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7753 ApplyLocation(arg, loc);
7756 ApplyLocation(exp.call.exp, loc);
7761 ApplyLocation(exp.member.exp, loc);
7765 ApplyLocation(exp.cast.exp, loc);
7771 for(e = exp.cond.exp->first; e; e = e.next)
7772 ApplyLocation(e, loc);
7775 ApplyLocation(exp.cond.cond, loc);
7776 if(exp.cond.elseExp)
7777 ApplyLocation(exp.cond.elseExp, loc);
7781 ApplyLocation(exp.vaArg.exp, loc);
7788 void ProcessExpressionType(Expression exp)
7790 bool unresolved = false;
7791 Location oldyylloc = yylloc;
7792 bool notByReference = false;
7794 char debugExpString[4096];
7795 debugExpString[0] = '\0';
7796 PrintExpression(exp, debugExpString);
7798 if(!exp || exp.expType)
7801 //eSystem_Logf("%s\n", expString);
7803 // Testing this here
7809 Identifier id = exp.identifier;
7810 if(!id || !topContext) return;
7812 // DOING THIS LATER NOW...
7813 if(id._class && id._class.name)
7815 id.classSym = id._class.symbol; // FindClass(id._class.name);
7816 /* TODO: Name Space Fix ups
7818 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7822 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7824 exp.expType = ProcessTypeString("Module", true);
7827 else */if(strstr(id.string, "__ecereClass") == id.string)
7829 exp.expType = ProcessTypeString("ecere::com::Class", true);
7832 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7834 // Added this here as well
7835 ReplaceClassMembers(exp, thisClass);
7836 if(exp.type != identifierExp)
7838 ProcessExpressionType(exp);
7842 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7847 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7848 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7849 if(!symbol/* && exp.destType*/)
7851 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7857 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7858 if(exp.type != identifierExp)
7860 ProcessExpressionType(exp);
7864 // Static methods called from inside the _class
7865 else if(currentClass && !id._class)
7867 if(ResolveIdWithClass(exp, currentClass, true))
7870 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7874 // If we manage to resolve this symbol
7877 Type type = symbol.type;
7878 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7880 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7882 Context context = SetupTemplatesContext(_class);
7883 type = ReplaceThisClassType(_class);
7884 FinishTemplatesContext(context);
7885 if(type) type.refCount = 0; // We'll be incrementing it right below...
7888 FreeSpecifier(id._class);
7891 id.string = CopyString(symbol.string);
7898 // Commented this out, it was making non-constant enum parameters seen as constant
7899 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7900 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7901 // Add missing cases here... enum Classes...
7902 exp.isConstant = true;
7904 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7905 if(symbol.isParam || !strcmp(id.string, "this"))
7907 if(_class && _class.type == structClass && !type.declaredWithStruct)
7908 exp.byReference = true;
7910 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7911 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7912 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7913 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7915 Identifier id = exp.identifier;
7916 exp.type = bracketsExp;
7917 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7921 if(symbol.isIterator)
7923 if(symbol.isIterator == 3)
7925 exp.type = bracketsExp;
7926 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7927 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7929 ProcessExpressionType(exp);
7931 else if(symbol.isIterator != 4)
7933 exp.type = memberExp;
7934 exp.member.exp = MkExpIdentifier(exp.identifier);
7935 exp.member.exp.expType = exp.expType;
7936 /*if(symbol.isIterator == 6)
7937 exp.member.member = MkIdentifier("key");
7939 exp.member.member = MkIdentifier("data");
7941 ProcessExpressionType(exp);
7948 DefinedExpression definedExp = null;
7949 if(thisNameSpace && !(id._class && !id._class.name))
7952 strcpy(name, thisNameSpace);
7954 strcat(name, id.string);
7955 definedExp = eSystem_FindDefine(privateModule, name);
7958 definedExp = eSystem_FindDefine(privateModule, id.string);
7962 for(c = 0; c<definedExpStackPos; c++)
7963 if(definedExpStack[c] == definedExp)
7965 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7967 Location backupYylloc = yylloc;
7968 File backInput = fileInput;
7969 definedExpStack[definedExpStackPos++] = definedExp;
7971 fileInput = TempFile { };
7972 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7973 fileInput.Seek(0, start);
7976 parsedExpression = null;
7978 expression_yyparse();
7981 fileInput = backInput;
7983 yylloc = backupYylloc;
7985 if(parsedExpression)
7988 exp.type = bracketsExp;
7989 exp.list = MkListOne(parsedExpression);
7990 ApplyLocation(parsedExpression, yylloc);
7991 ProcessExpressionType(exp);
7992 definedExpStackPos--;
7995 definedExpStackPos--;
8001 Compiler_Error($"Recursion in defined expression %s\n", id.string);
8007 GlobalData data = null;
8008 if(thisNameSpace && !(id._class && !id._class.name))
8011 strcpy(name, thisNameSpace);
8013 strcat(name, id.string);
8014 data = FindGlobalData(name);
8017 data = FindGlobalData(id.string);
8020 DeclareGlobalData(data);
8021 exp.expType = data.dataType;
8022 if(data.dataType) data.dataType.refCount++;
8025 id.string = CopyString(data.fullName);
8026 FreeSpecifier(id._class);
8033 GlobalFunction function = null;
8034 if(thisNameSpace && !(id._class && !id._class.name))
8037 strcpy(name, thisNameSpace);
8039 strcat(name, id.string);
8040 function = eSystem_FindFunction(privateModule, name);
8043 function = eSystem_FindFunction(privateModule, id.string);
8048 id.string = CopyString(function.name);
8051 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8052 strcpy(name, "__ecereFunction_");
8053 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8054 if(DeclareFunction(function, name))
8057 id.string = CopyString(name);
8059 exp.expType = function.dataType;
8060 if(function.dataType) function.dataType.refCount++;
8062 FreeSpecifier(id._class);
8079 if(!exp.instance._class)
8081 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8083 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8087 //classSym = FindClass(exp.instance._class.fullName);
8088 //_class = classSym ? classSym.registered : null;
8090 ProcessInstantiationType(exp.instance);
8092 exp.isConstant = exp.instance.isConstant;
8095 if(_class.type == unitClass && _class.base.type != systemClass)
8098 Type destType = exp.destType;
8100 exp.destType = MkClassType(_class.base.fullName);
8101 exp.expType = MkClassType(_class.fullName);
8102 CheckExpressionType(exp, exp.destType, true);
8104 exp.destType = destType;
8106 exp.expType = MkClassType(_class.fullName);
8109 if(exp.instance._class)
8111 exp.expType = MkClassType(exp.instance._class.name);
8112 /*if(exp.expType._class && exp.expType._class.registered &&
8113 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8114 exp.expType.byReference = true;*/
8122 char * constant = exp.constant;
8130 if(constant[0] == '\'')
8132 if((int)((byte *)constant)[1] > 127)
8135 unichar ch = UTF8GetChar(constant + 1, &nb);
8136 if(nb < 2) ch = constant[1];
8138 exp.constant = PrintUInt(ch);
8139 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8140 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8141 type._class = FindClass("unichar");
8143 type.isSigned = false;
8147 type.kind = charType;
8148 type.isSigned = true;
8153 char * dot = strchr(constant, '.');
8154 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8158 exponent = strchr(constant, 'p');
8159 if(!exponent) exponent = strchr(constant, 'P');
8163 exponent = strchr(constant, 'e');
8164 if(!exponent) exponent = strchr(constant, 'E');
8169 if(strchr(constant, 'f') || strchr(constant, 'F'))
8170 type.kind = floatType;
8172 type.kind = doubleType;
8173 type.isSigned = true;
8177 bool isSigned = constant[0] == '-';
8179 int64 i64 = strtoll(constant, &endP, 0);
8180 uint64 ui64 = strtoull(constant, &endP, 0);
8181 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8194 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8198 else if(constant[0] != '0' || !constant[1])
8201 type.kind = is64Bit ? int64Type : intType;
8202 type.isSigned = isSigned;
8205 exp.isConstant = true;
8206 if(exp.destType && exp.destType.kind == doubleType)
8207 type.kind = doubleType;
8208 else if(exp.destType && exp.destType.kind == floatType)
8209 type.kind = floatType;
8210 else if(exp.destType && exp.destType.kind == int64Type)
8211 type.kind = int64Type;
8217 exp.isConstant = true; // Why wasn't this constant?
8234 ProcessExpressionType(exp._new.size);
8239 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8241 DeclareType(exp.expType.type, false, false);
8245 ProcessExpressionType(exp._renew.size);
8246 ProcessExpressionType(exp._renew.exp);
8251 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8253 DeclareType(exp.expType.type, false, false);
8257 bool assign = false, boolResult = false, boolOps = false;
8258 Type type1 = null, type2 = null;
8259 bool useDestType = false, useSideType = false;
8260 Location oldyylloc = yylloc;
8261 bool useSideUnit = false;
8262 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8264 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8273 // Assignment Operators
8287 // boolean Operators
8289 // Expect boolean operators
8291 //boolResult = true;
8295 // Expect boolean operands
8306 // Gives boolean result
8338 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8344 /*// Implement speed etc.
8350 if(exp.op.op == '&')
8352 // Added this here earlier for Iterator address as key
8353 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8355 Identifier id = exp.op.exp2.identifier;
8356 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8357 if(symbol && symbol.isIterator == 2)
8359 exp.type = memberExp;
8360 exp.member.exp = exp.op.exp2;
8361 exp.member.member = MkIdentifier("key");
8363 exp.op.exp2.expType = symbol.type;
8364 symbol.type.refCount++;
8365 ProcessExpressionType(exp);
8369 // exp.op.exp2.usage.usageRef = true;
8373 //dummy.kind = TypeDummy;
8376 // Added this check here to use the dest type only for units derived from the base unit
8377 // So that untyped units will use the side unit as opposed to the untyped destination unit
8378 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8379 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8380 useDestType = false;
8382 if(destClass && useDestType &&
8383 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8385 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8387 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8388 exp.op.exp1.destType = exp.destType;
8389 exp.op.exp1.opDestType = true;
8391 exp.destType.refCount++;
8395 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8396 exp.op.exp1.destType = dummy;
8400 // TESTING THIS HERE...
8401 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8402 ProcessExpressionType(exp.op.exp1);
8403 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8405 exp.op.exp1.opDestType = false;
8407 // Fix for unit and ++ / --
8408 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8409 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8411 exp.op.exp2 = MkExpConstant("1");
8412 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8416 if(exp.op.exp1.destType == dummy)
8419 exp.op.exp1.destType = null;
8421 type1 = exp.op.exp1.expType;
8426 char expString[10240];
8427 expString[0] = '\0';
8428 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8432 exp.op.exp2.destType = exp.op.exp1.expType;
8433 if(exp.op.exp1.expType)
8434 exp.op.exp1.expType.refCount++;
8438 exp.op.exp2.destType = exp.destType;
8439 if(!exp.op.exp1 || exp.op.op != '&')
8440 exp.op.exp2.opDestType = true;
8442 exp.destType.refCount++;
8445 if(type1) type1.refCount++;
8446 exp.expType = type1;
8451 PrintExpression(exp.op.exp2, expString);
8453 if(type1 && type1.kind == pointerType)
8455 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 ||
8456 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8457 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8458 else if(exp.op.op == '=')
8460 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8461 exp.op.exp2.destType = type1;
8468 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8469 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/* ||
8470 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8473 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8474 exp.op.exp2.destType = type1;
8479 if(type1) type1.refCount++;
8480 exp.expType = type1;
8482 else if(destClass &&
8483 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8484 (destClass.type == enumClass && useDestType)))
8486 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8487 exp.op.exp2.destType = exp.destType;
8488 if(exp.op.op != '&')
8489 exp.op.exp2.opDestType = true;
8491 exp.destType.refCount++;
8495 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8496 exp.op.exp2.destType = dummy;
8500 // TESTING THIS HERE... (DANGEROUS)
8501 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8502 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8504 FreeType(exp.op.exp2.destType);
8505 exp.op.exp2.destType = type1;
8508 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8509 // Cannot lose the cast on a sizeof
8510 if(exp.op.op == SIZEOF)
8512 Expression e = exp.op.exp2;
8513 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8515 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8517 if(e.type == extensionCompoundExp)
8518 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8523 if(e.type == castExp && e.cast.exp)
8524 e.cast.exp.needCast = true;
8526 ProcessExpressionType(exp.op.exp2);
8527 exp.op.exp2.opDestType = false;
8528 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8530 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8532 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)
8534 if(exp.op.op != '=' && type1.type.kind == voidType)
8535 Compiler_Error($"void *: unknown size\n");
8537 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||
8538 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8539 (exp.op.exp2.expType._class.registered.type == normalClass ||
8540 exp.op.exp2.expType._class.registered.type == structClass ||
8541 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8543 if(exp.op.op == ADD_ASSIGN)
8544 Compiler_Error($"cannot add two pointers\n");
8546 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8547 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8549 if(exp.op.op == ADD_ASSIGN)
8550 Compiler_Error($"cannot add two pointers\n");
8554 char type1String[1024];
8555 char type2String[1024];
8556 type1String[0] = '\0';
8557 type2String[0] = '\0';
8559 PrintType(exp.op.exp2.expType, type1String, false, true);
8560 PrintType(type1, type2String, false, true);
8561 ChangeCh(expString, '\n', ' ');
8562 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8566 if(exp.op.exp2.destType == dummy)
8569 exp.op.exp2.destType = null;
8572 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8576 CopyTypeInto(type2, exp.op.exp2.expType);
8577 type2.isSigned = true;
8579 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8581 type2 = { kind = intType };
8583 type2.isSigned = true;
8587 type2 = exp.op.exp2.expType;
8588 if(type2) type2.refCount++;
8592 dummy.kind = voidType;
8594 if(exp.op.op == SIZEOF)
8601 exp.isConstant = true;
8603 // Get type of dereferenced pointer
8604 else if(exp.op.op == '*' && !exp.op.exp1)
8606 exp.expType = Dereference(type2);
8607 if(type2 && type2.kind == classType)
8608 notByReference = true;
8610 else if(exp.op.op == '&' && !exp.op.exp1)
8611 exp.expType = Reference(type2);
8618 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8619 exp.op.exp1.destType = MkClassType("bool");
8620 exp.op.exp1.destType.truth = true;
8621 if(!exp.op.exp1.expType)
8622 ProcessExpressionType(exp.op.exp1);
8624 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8625 FreeType(exp.op.exp1.expType);
8626 exp.op.exp1.expType = MkClassType("bool");
8627 exp.op.exp1.expType.truth = true;
8631 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8632 exp.op.exp2.destType = MkClassType("bool");
8633 exp.op.exp2.destType.truth = true;
8634 if(!exp.op.exp2.expType)
8635 ProcessExpressionType(exp.op.exp2);
8637 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8638 FreeType(exp.op.exp2.expType);
8639 exp.op.exp2.expType = MkClassType("bool");
8640 exp.op.exp2.expType.truth = true;
8643 else if(exp.op.exp1 && exp.op.exp2 &&
8646 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8647 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8648 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8649 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8651 if(type1 && type2 &&
8652 // If either both are class or both are not class
8653 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8655 // Added this check for enum subtraction to result in an int type:
8656 if(exp.op.op == '-' &&
8657 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8658 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8661 if(!type1._class.registered.dataType)
8662 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8663 if(!type2._class.registered.dataType)
8664 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8666 intType = ProcessTypeString(
8667 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8669 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8670 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8671 exp.op.exp1.destType = intType;
8672 exp.op.exp2.destType = intType;
8677 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8678 exp.op.exp2.destType = type1;
8680 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8681 exp.op.exp1.destType = type2;
8685 // Warning here for adding Radians + Degrees with no destination type
8686 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8687 type1._class.registered && type1._class.registered.type == unitClass &&
8688 type2._class.registered && type2._class.registered.type == unitClass &&
8689 type1._class.registered != type2._class.registered)
8690 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8691 type1._class.string, type2._class.string, type1._class.string);
8693 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8695 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8698 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8700 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8701 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8704 ProcessExpressionType(exp.op.exp1);
8706 if(type2.kind != pointerType)
8708 ProcessExpressionType(classExp);
8710 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8712 if(!exp.op.exp2.expType)
8716 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8720 ProcessExpressionType(exp.op.exp2);
8725 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)))
8727 if(type1.kind != classType && type1.type.kind == voidType)
8728 Compiler_Error($"void *: unknown size\n");
8729 exp.expType = type1;
8730 if(type1) type1.refCount++;
8732 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)))
8734 if(type2.kind != classType && type2.type.kind == voidType)
8735 Compiler_Error($"void *: unknown size\n");
8736 exp.expType = type2;
8737 if(type2) type2.refCount++;
8739 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8740 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8742 Compiler_Warning($"different levels of indirection\n");
8746 bool success = false;
8747 if(type1.kind == pointerType && type2.kind == pointerType)
8749 if(exp.op.op == '+')
8750 Compiler_Error($"cannot add two pointers\n");
8751 else if(exp.op.op == '-')
8753 // Pointer Subtraction gives integer
8754 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8763 if(type1.type.kind == templateType)
8765 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8768 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8770 ProcessExpressionType(classExp);
8772 exp.type = bracketsExp;
8773 exp.list = MkListOne(MkExpOp(
8774 MkExpBrackets(MkListOne(MkExpOp(
8775 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8777 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8778 MkExpMember(classExp, MkIdentifier("typeSize"))));
8780 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8789 if(!success && exp.op.exp1.type == constantExp)
8791 // If first expression is constant, try to match that first
8792 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8794 if(exp.expType) FreeType(exp.expType);
8795 exp.expType = exp.op.exp1.destType;
8796 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8799 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8801 if(exp.expType) FreeType(exp.expType);
8802 exp.expType = exp.op.exp2.destType;
8803 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8809 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8811 if(exp.expType) FreeType(exp.expType);
8812 exp.expType = exp.op.exp2.destType;
8813 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8816 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8818 if(exp.expType) FreeType(exp.expType);
8819 exp.expType = exp.op.exp1.destType;
8820 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8826 char expString1[10240];
8827 char expString2[10240];
8830 expString1[0] = '\0';
8831 expString2[0] = '\0';
8836 PrintExpression(exp.op.exp1, expString1);
8837 ChangeCh(expString1, '\n', ' ');
8838 PrintExpression(exp.op.exp2, expString2);
8839 ChangeCh(expString2, '\n', ' ');
8840 PrintType(exp.op.exp1.expType, type1, false, true);
8841 PrintType(exp.op.exp2.expType, type2, false, true);
8844 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8848 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8849 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8851 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8852 // Convert e.g. / 4 into / 4.0
8853 exp.op.exp1.destType = type2._class.registered.dataType;
8854 if(type2._class.registered.dataType)
8855 type2._class.registered.dataType.refCount++;
8856 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8857 exp.expType = type2;
8858 if(type2) type2.refCount++;
8860 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8862 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8863 // Convert e.g. / 4 into / 4.0
8864 exp.op.exp2.destType = type1._class.registered.dataType;
8865 if(type1._class.registered.dataType)
8866 type1._class.registered.dataType.refCount++;
8867 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8868 exp.expType = type1;
8869 if(type1) type1.refCount++;
8875 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8877 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8879 if(!type1._class.registered.dataType)
8880 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8881 exp.op.exp2.destType = type1._class.registered.dataType;
8882 exp.op.exp2.destType.refCount++;
8884 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8887 type2 = exp.op.exp2.destType;
8888 if(type2) type2.refCount++;
8890 exp.expType = type2;
8894 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8896 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8898 if(!type2._class.registered.dataType)
8899 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8900 exp.op.exp1.destType = type2._class.registered.dataType;
8901 exp.op.exp1.destType.refCount++;
8903 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8904 type1 = exp.op.exp1.destType;
8905 exp.expType = type1;
8909 // TESTING THIS NEW CODE
8910 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8912 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8913 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8914 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8916 // Convert the enum to an int instead for these operators
8917 if(op1IsEnum && exp.op.exp2.expType)
8919 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8921 if(exp.expType) FreeType(exp.expType);
8922 exp.expType = exp.op.exp2.expType;
8923 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8927 else if(op2IsEnum && exp.op.exp1.expType)
8929 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8931 if(exp.expType) FreeType(exp.expType);
8932 exp.expType = exp.op.exp1.expType;
8933 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8940 if(op1IsEnum && exp.op.exp2.expType)
8942 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8944 if(exp.expType) FreeType(exp.expType);
8945 exp.expType = exp.op.exp1.expType;
8946 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8950 else if(op2IsEnum && exp.op.exp1.expType)
8952 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8954 if(exp.expType) FreeType(exp.expType);
8955 exp.expType = exp.op.exp2.expType;
8956 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8965 // 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
8966 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8967 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8969 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8970 exp.op.exp1.destType = type2;
8973 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8975 if(exp.expType) FreeType(exp.expType);
8976 exp.expType = exp.op.exp1.destType;
8977 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8982 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8983 exp.op.exp2.destType = type1;
8987 // Maybe this was meant to be an enum...
8988 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8990 Type oldType = exp.op.exp2.expType;
8991 exp.op.exp2.expType = null;
8992 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8995 exp.op.exp2.expType = oldType;
9000 // TESTING THIS HERE... LATEST ADDITION
9001 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9003 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9004 exp.op.exp2.destType = type2._class.registered.dataType;
9005 if(type2._class.registered.dataType)
9006 type2._class.registered.dataType.refCount++;
9007 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9009 //exp.expType = type2._class.registered.dataType; //type2;
9010 //if(type2) type2.refCount++;
9013 // TESTING THIS HERE... LATEST ADDITION
9014 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9016 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9017 exp.op.exp1.destType = type1._class.registered.dataType;
9018 if(type1._class.registered.dataType)
9019 type1._class.registered.dataType.refCount++;
9020 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9021 exp.expType = type1._class.registered.dataType; //type1;
9022 if(type1) type1.refCount++;
9026 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9028 if(exp.expType) FreeType(exp.expType);
9029 exp.expType = exp.op.exp2.destType;
9030 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9032 else if(type1 && type2)
9034 char expString1[10240];
9035 char expString2[10240];
9036 char type1String[1024];
9037 char type2String[1024];
9038 expString1[0] = '\0';
9039 expString2[0] = '\0';
9040 type1String[0] = '\0';
9041 type2String[0] = '\0';
9044 PrintExpression(exp.op.exp1, expString1);
9045 ChangeCh(expString1, '\n', ' ');
9046 PrintExpression(exp.op.exp2, expString2);
9047 ChangeCh(expString2, '\n', ' ');
9048 PrintType(exp.op.exp1.expType, type1String, false, true);
9049 PrintType(exp.op.exp2.expType, type2String, false, true);
9052 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9054 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9056 exp.expType = exp.op.exp1.expType;
9057 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9059 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9061 exp.expType = exp.op.exp2.expType;
9062 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9070 // Maybe this was meant to be an enum...
9071 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9073 Type oldType = exp.op.exp1.expType;
9074 exp.op.exp1.expType = null;
9075 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9078 exp.op.exp1.expType = oldType;
9081 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9082 exp.op.exp1.destType = type2;
9085 // TESTING THIS HERE... LATEST ADDITION
9086 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9088 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9089 exp.op.exp1.destType = type1._class.registered.dataType;
9090 if(type1._class.registered.dataType)
9091 type1._class.registered.dataType.refCount++;
9094 // TESTING THIS HERE... LATEST ADDITION
9095 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9097 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9098 exp.op.exp2.destType = type2._class.registered.dataType;
9099 if(type2._class.registered.dataType)
9100 type2._class.registered.dataType.refCount++;
9104 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9106 if(exp.expType) FreeType(exp.expType);
9107 exp.expType = exp.op.exp1.destType;
9108 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9112 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9114 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9116 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9117 // Convert e.g. / 4 into / 4.0
9118 exp.op.exp1.destType = type2._class.registered.dataType;
9119 if(type2._class.registered.dataType)
9120 type2._class.registered.dataType.refCount++;
9121 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9123 if(exp.op.op == '!')
9125 exp.expType = MkClassType("bool");
9126 exp.expType.truth = true;
9130 exp.expType = type2;
9131 if(type2) type2.refCount++;
9134 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9136 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9138 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9139 // Convert e.g. / 4 into / 4.0
9140 exp.op.exp2.destType = type1._class.registered.dataType;
9141 if(type1._class.registered.dataType)
9142 type1._class.registered.dataType.refCount++;
9143 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9145 exp.expType = type1;
9146 if(type1) type1.refCount++;
9151 if(exp.op.exp1 && !exp.op.exp1.expType)
9153 char expString[10000];
9154 expString[0] = '\0';
9157 PrintExpression(exp.op.exp1, expString);
9158 ChangeCh(expString, '\n', ' ');
9161 Compiler_Error($"couldn't determine type of %s\n", expString);
9163 if(exp.op.exp2 && !exp.op.exp2.expType)
9165 char expString[10240];
9166 expString[0] = '\0';
9169 PrintExpression(exp.op.exp2, expString);
9170 ChangeCh(expString, '\n', ' ');
9173 Compiler_Error($"couldn't determine type of %s\n", expString);
9178 FreeType(exp.expType);
9179 exp.expType = MkClassType("bool");
9180 exp.expType.truth = true;
9183 if(exp.op.op != SIZEOF)
9184 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9185 (!exp.op.exp2 || exp.op.exp2.isConstant);
9187 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9189 DeclareType(exp.op.exp2.expType, false, false);
9192 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9193 Compiler_Warning($"deleting const qualified object\n");
9203 case extensionExpressionExp:
9206 exp.isConstant = true;
9207 for(e = exp.list->first; e; e = e.next)
9212 FreeType(e.destType);
9213 e.opDestType = exp.opDestType;
9214 e.destType = exp.destType;
9215 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9217 ProcessExpressionType(e);
9219 exp.destType.count--;
9220 if(!exp.expType && !e.next)
9222 exp.expType = e.expType;
9223 if(e.expType) e.expType.refCount++;
9226 exp.isConstant = false;
9229 // In case a cast became a member...
9230 e = exp.list->first;
9231 if(!e.next && e.type == memberExp)
9233 // Preserve prev, next
9234 Expression next = exp.next, prev = exp.prev;
9237 FreeType(exp.expType);
9238 FreeType(exp.destType);
9248 ProcessExpressionType(exp);
9255 exp.isConstant = true;
9257 ProcessExpressionType(exp.index.exp);
9258 if(!exp.index.exp.isConstant)
9259 exp.isConstant = false;
9261 if(exp.index.exp.expType)
9263 Type source = exp.index.exp.expType;
9264 if(source.kind == classType && source._class && source._class.registered)
9266 Class _class = source._class.registered;
9267 Class c = _class.templateClass ? _class.templateClass : _class;
9268 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9270 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9272 if(exp.index.index && exp.index.index->last)
9274 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9276 if(type.kind == classType) type.constant = true;
9277 else if(type.kind == pointerType)
9280 while(t.kind == pointerType) t = t.type;
9284 ((Expression)exp.index.index->last).destType = type;
9290 for(e = exp.index.index->first; e; e = e.next)
9292 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9294 if(e.destType) FreeType(e.destType);
9295 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9297 ProcessExpressionType(e);
9300 // Check if this type is int
9303 exp.isConstant = false;
9307 exp.expType = Dereference(exp.index.exp.expType);
9309 DeclareType(exp.expType, false, false);
9316 Type methodType = null;
9322 PrintExpression(exp.call.exp, name);
9323 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9325 //exp.call.exp.expType = null;
9326 PrintExpression(exp.call.exp, name);
9329 if(exp.call.exp.type == identifierExp)
9331 Expression idExp = exp.call.exp;
9332 Identifier id = idExp.identifier;
9333 if(!strcmp(id.string, "__builtin_frame_address"))
9335 exp.expType = ProcessTypeString("void *", true);
9336 if(exp.call.arguments && exp.call.arguments->first)
9337 ProcessExpressionType(exp.call.arguments->first);
9340 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9342 exp.expType = ProcessTypeString("int", true);
9343 if(exp.call.arguments && exp.call.arguments->first)
9344 ProcessExpressionType(exp.call.arguments->first);
9347 else if(!strcmp(id.string, "Max") ||
9348 !strcmp(id.string, "Min") ||
9349 !strcmp(id.string, "Sgn") ||
9350 !strcmp(id.string, "Abs"))
9352 Expression a = null;
9353 Expression b = null;
9354 Expression tempExp1 = null, tempExp2 = null;
9355 if((!strcmp(id.string, "Max") ||
9356 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9358 a = exp.call.arguments->first;
9359 b = exp.call.arguments->last;
9363 else if(exp.call.arguments->count == 1)
9365 a = exp.call.arguments->first;
9371 exp.call.arguments->Clear();
9372 idExp.identifier = null;
9374 FreeExpContents(exp);
9376 ProcessExpressionType(a);
9378 ProcessExpressionType(b);
9380 exp.type = bracketsExp;
9381 exp.list = MkList();
9383 if(a.expType && (!b || b.expType))
9385 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9387 // Use the simpleStruct name/ids for now...
9390 OldList * specs = MkList();
9391 OldList * decls = MkList();
9393 char temp1[1024], temp2[1024];
9395 GetTypeSpecs(a.expType, specs);
9397 if(a && !a.isConstant && a.type != identifierExp)
9399 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9400 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9401 tempExp1 = QMkExpId(temp1);
9402 tempExp1.expType = a.expType;
9404 a.expType.refCount++;
9405 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9407 if(b && !b.isConstant && b.type != identifierExp)
9409 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9410 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9411 tempExp2 = QMkExpId(temp2);
9412 tempExp2.expType = b.expType;
9414 b.expType.refCount++;
9415 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9418 decl = MkDeclaration(specs, decls);
9419 if(!curCompound.compound.declarations)
9420 curCompound.compound.declarations = MkList();
9421 curCompound.compound.declarations->Insert(null, decl);
9426 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9428 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9430 MkExpCondition(MkExpBrackets(MkListOne(
9431 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9432 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9433 exp.expType = a.expType;
9435 a.expType.refCount++;
9437 else if(!strcmp(id.string, "Abs"))
9440 MkExpCondition(MkExpBrackets(MkListOne(
9441 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9442 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9443 exp.expType = a.expType;
9445 a.expType.refCount++;
9447 else if(!strcmp(id.string, "Sgn"))
9449 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9451 MkExpCondition(MkExpBrackets(MkListOne(
9452 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9453 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9454 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9455 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9456 exp.expType = ProcessTypeString("int", false);
9459 FreeExpression(tempExp1);
9460 if(tempExp2) FreeExpression(tempExp2);
9474 if(!exp.call.exp.destType)
9476 exp.call.exp.destType = dummy;
9479 ProcessExpressionType(exp.call.exp);
9480 if(exp.call.exp.destType == dummy)
9483 exp.call.exp.destType = null;
9488 // Check argument types against parameter types
9489 functionType = exp.call.exp.expType;
9491 if(functionType && functionType.kind == TypeKind::methodType)
9493 methodType = functionType;
9494 functionType = methodType.method.dataType;
9496 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9497 // TOCHECK: Instead of doing this here could this be done per param?
9498 if(exp.call.exp.expType.usedClass)
9500 char typeString[1024];
9501 typeString[0] = '\0';
9503 Symbol back = functionType.thisClass;
9504 // Do not output class specifier here (thisclass was added to this)
9505 functionType.thisClass = null;
9506 PrintType(functionType, typeString, true, true);
9507 functionType.thisClass = back;
9509 if(strstr(typeString, "thisclass"))
9511 OldList * specs = MkList();
9514 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9516 decl = SpecDeclFromString(typeString, specs, null);
9518 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9519 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9520 exp.call.exp.expType.usedClass))
9521 thisClassParams = false;
9523 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9525 Class backupThisClass = thisClass;
9526 thisClass = exp.call.exp.expType.usedClass;
9527 ProcessDeclarator(decl);
9528 thisClass = backupThisClass;
9531 thisClassParams = true;
9533 functionType = ProcessType(specs, decl);
9534 functionType.refCount = 0;
9535 FinishTemplatesContext(context);
9537 // Mark parameters that were 'thisclass'
9540 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9541 p.wasThisClass = op.kind == thisClassType;
9545 FreeList(specs, FreeSpecifier);
9546 FreeDeclarator(decl);
9550 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9552 Type type = functionType.type;
9553 if(!functionType.refCount)
9555 functionType.type = null;
9556 FreeType(functionType);
9558 //methodType = functionType;
9559 functionType = type;
9561 if(functionType && functionType.kind != TypeKind::functionType)
9563 Compiler_Error($"called object %s is not a function\n", name);
9565 else if(functionType)
9567 bool emptyParams = false, noParams = false;
9568 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9569 Type type = functionType.params.first;
9570 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9572 Location oldyylloc = yylloc;
9574 if(!type) emptyParams = true;
9577 if(functionType.extraParam && e && functionType.thisClass)
9579 e.destType = MkClassType(functionType.thisClass.string);
9583 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9584 // Fixed #141 by adding '&& !functionType.extraParam'
9585 if(!functionType.staticMethod && !functionType.extraParam)
9587 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9588 memberExp.member.exp.expType._class)
9590 type = MkClassType(memberExp.member.exp.expType._class.string);
9595 type = functionType.params.first;
9600 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9602 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9603 type.byReference = functionType.byReference;
9604 type.typedByReference = functionType.typedByReference;
9607 // Allow manually passing a class for typed object
9608 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9612 type = functionType.params.first;
9620 if(type && type.kind == voidType)
9623 if(!type.refCount) FreeType(type);
9627 for( ; e; e = e.next)
9629 if(!type && !emptyParams)
9632 if(methodType && methodType.methodClass)
9633 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9634 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9635 noParams ? 0 : functionType.params.count);
9637 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9638 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9639 noParams ? 0 : functionType.params.count);
9643 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9645 Type templatedType = null;
9646 Class _class = methodType.usedClass;
9647 ClassTemplateParameter curParam = null;
9649 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9652 for(sClass = _class; sClass; sClass = sClass.base)
9654 if(sClass.templateClass) sClass = sClass.templateClass;
9656 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9658 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9661 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9663 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9664 id += nextClass.templateParams.count;
9673 if(curParam && _class.templateArgs[id].dataTypeString)
9675 bool constant = type.constant;
9676 ClassTemplateArgument arg = _class.templateArgs[id];
9678 Context context = SetupTemplatesContext(_class);
9681 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9682 templatedType = ProcessTypeString(arg.dataTypeString, false);
9683 FinishTemplatesContext(context);
9686 if(templatedType.kind == classType && constant) templatedType.constant = true;
9687 else if(templatedType.kind == pointerType)
9689 Type t = templatedType.type;
9690 while(t.kind == pointerType) t = t.type;
9691 if(constant) t.constant = constant;
9694 e.destType = templatedType;
9697 templatedType.passAsTemplate = true;
9698 // templatedType.refCount++;
9704 if(type) type.refCount++;
9709 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9711 e.destType = type.prev;
9712 e.destType.refCount++;
9717 if(type) type.refCount++;
9720 // Don't reach the end for the ellipsis
9721 if(type && type.kind != ellipsisType)
9723 Type next = type.next;
9724 if(!type.refCount) FreeType(type);
9729 if(type && type.kind != ellipsisType)
9731 if(methodType && methodType.methodClass)
9732 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9733 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9734 functionType.params.count + extra);
9736 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9737 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9738 functionType.params.count + extra);
9741 if(type && !type.refCount) FreeType(type);
9748 kind = TypeKind::functionType;
9751 if(exp.call.exp.type == identifierExp)
9753 char * string = exp.call.exp.identifier.string;
9757 Location oldyylloc = yylloc;
9759 yylloc = exp.call.exp.identifier.loc;
9760 if(strstr(string, "__builtin_") == string)
9764 functionType.returnType = exp.destType;
9765 exp.destType.refCount++;
9769 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9770 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9771 globalContext.symbols.Add((BTNode)symbol);
9772 if(strstr(symbol.string, "::"))
9773 globalContext.hasNameSpace = true;
9778 else if(exp.call.exp.type == memberExp)
9780 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9781 exp.call.exp.member.member.string);*/
9784 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9786 if(!functionType.returnType)
9788 functionType.returnType = Type
9795 if(functionType && functionType.kind == TypeKind::functionType)
9797 exp.expType = functionType.returnType;
9799 if(functionType.returnType)
9800 functionType.returnType.refCount++;
9802 if(!functionType.refCount)
9803 FreeType(functionType);
9806 if(exp.call.arguments)
9808 for(e = exp.call.arguments->first; e; e = e.next)
9809 ProcessExpressionType(e);
9816 Location oldyylloc = yylloc;
9818 Expression checkExp = exp.member.exp;
9821 if(checkExp.type == castExp)
9822 checkExp = checkExp.cast.exp;
9823 else if(checkExp.type == bracketsExp)
9824 checkExp = checkExp.list ? checkExp.list->first : null;
9829 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9830 exp.thisPtr = thisPtr;
9832 // DOING THIS LATER NOW...
9833 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9835 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9836 /* TODO: Name Space Fix ups
9837 if(!exp.member.member.classSym)
9838 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9842 ProcessExpressionType(exp.member.exp);
9843 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9844 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9846 exp.isConstant = false;
9849 exp.isConstant = exp.member.exp.isConstant;
9850 type = exp.member.exp.expType;
9854 if(type && (type.kind == templateType))
9856 Class _class = thisClass ? thisClass : currentClass;
9857 ClassTemplateParameter param = null;
9860 for(param = _class.templateParams.first; param; param = param.next)
9862 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9866 if(param && param.defaultArg.member)
9868 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9871 Expression expMember = exp.member.exp;
9873 OldList * specs = MkList();
9874 char thisClassTypeString[1024];
9876 FreeIdentifier(exp.member.member);
9878 ProcessExpressionType(argExp);
9881 char * colon = strstr(param.defaultArg.memberString, "::");
9884 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9885 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9888 strcpy(thisClassTypeString, _class.fullName);
9891 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9893 exp.expType = ProcessType(specs, decl);
9894 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9896 Class expClass = exp.expType._class.registered;
9897 Class cClass = null;
9901 char templateString[1024];
9902 ClassTemplateParameter param;
9903 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9904 for(cClass = expClass; cClass; cClass = cClass.base)
9907 for(param = cClass.templateParams.first; param; param = param.next)
9911 ClassTemplateArgument arg;
9912 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9913 arg = expClass.templateArgs[id];
9915 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9917 ClassTemplateParameter cParam;
9918 //int p = numParams - sClass.templateParams.count;
9921 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9923 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9925 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9927 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9929 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9930 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9942 strcat(argument, arg.name.string);
9943 strcat(argument, " = ");
9949 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9950 char expString[1024];
9951 OldList * specs = MkList();
9952 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9954 char * string = PrintHexUInt64(arg.expression.ui64);
9955 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9958 ProcessExpressionType(exp);
9959 ComputeExpression(exp);
9960 expString[0] = '\0';
9961 PrintExpression(exp, expString);
9962 strcat(argument, expString);
9964 FreeExpression(exp);
9969 strcat(argument, arg.member.name);
9972 case TemplateParameterType::type:
9974 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9976 if(!strcmp(arg.dataTypeString, "thisclass"))
9977 strcat(argument, thisClassTypeString);
9979 strcat(argument, arg.dataTypeString);
9986 if(paramCount) strcat(templateString, ", ");
9987 if(lastParam != p - 1)
9989 strcat(templateString, param.name);
9990 strcat(templateString, " = ");
9992 strcat(templateString, argument);
10001 int len = strlen(templateString);
10002 if(templateString[len-1] == '>') templateString[len++] = ' ';
10003 templateString[len++] = '>';
10004 templateString[len++] = '\0';
10007 Context context = SetupTemplatesContext(_class);
10008 FreeType(exp.expType);
10009 exp.expType = ProcessTypeString(templateString, false);
10010 FinishTemplatesContext(context);
10014 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
10015 exp.type = bracketsExp;
10016 exp.list = MkListOne(MkExpOp(null, '*',
10019 exp.op.exp1 = null;
10021 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10022 MkExpBrackets(MkListOne(
10023 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
10025 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10027 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10032 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10033 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10035 type = ProcessTemplateParameterType(type.templateParameter);
10038 // TODO: *** This seems to be where we should add method support for all basic types ***
10039 if(type && (type.kind == templateType));
10040 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10041 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10042 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10043 (type.kind == pointerType && type.type.kind == charType)))
10045 Identifier id = exp.member.member;
10046 TypeKind typeKind = type.kind;
10047 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10048 if(typeKind == subClassType && exp.member.exp.type == classExp)
10050 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10051 typeKind = classType;
10056 if(typeKind == intType || typeKind == enumType)
10057 _class = eSystem_FindClass(privateModule, "int");
10060 if(type.kind == classType && type._class && type._class.registered)
10062 _class = type._class.registered;
10064 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10066 _class = FindClass("char *").registered;
10068 else if(type.kind == pointerType)
10070 _class = eSystem_FindClass(privateModule, "uintptr");
10071 FreeType(exp.expType);
10072 exp.expType = ProcessTypeString("uintptr", false);
10073 exp.byReference = true;
10077 char string[1024] = "";
10079 PrintTypeNoConst(type, string, false, true);
10080 classSym = FindClass(string);
10081 if(classSym) _class = classSym.registered;
10089 (exp.member.exp.type == identifierExp &&
10090 !strcmp(exp.member.exp.identifier.string, "this"));*/
10091 Property prop = null;
10092 Method method = null;
10093 DataMember member = null;
10094 Property revConvert = null;
10095 ClassProperty classProp = null;
10097 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10098 exp.member.memberType = propertyMember;
10100 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10101 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10103 if(typeKind != subClassType)
10105 // Prioritize data members over properties for "this"
10106 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10108 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10109 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10111 prop = eClass_FindProperty(_class, id.string, privateModule);
10115 if(!member && !prop)
10116 prop = eClass_FindProperty(_class, id.string, privateModule);
10117 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10118 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10119 exp.member.thisPtr = true;
10121 // Prioritize properties over data members otherwise
10124 bool useMemberForNonConst = false;
10125 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10128 prop = eClass_FindProperty(_class, id.string, null);
10130 useMemberForNonConst = prop && exp.destType &&
10131 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10132 !strncmp(prop.dataTypeString, "const ", 6);
10134 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10135 member = eClass_FindDataMember(_class, id.string, null, null, null);
10138 if((!prop || useMemberForNonConst) && !member)
10140 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10143 prop = eClass_FindProperty(_class, id.string, privateModule);
10145 useMemberForNonConst |= prop && exp.destType &&
10146 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10147 !strncmp(prop.dataTypeString, "const ", 6);
10149 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10150 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10156 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10163 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10164 method = eClass_FindMethod(_class, id.string, privateModule);
10165 if(!prop && !member && !method)
10167 if(typeKind == subClassType)
10169 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10172 exp.member.memberType = classPropertyMember;
10173 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10177 // Assume this is a class_data member
10178 char structName[1024];
10179 Identifier id = exp.member.member;
10180 Expression classExp = exp.member.exp;
10183 FreeType(classExp.expType);
10184 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10186 strcpy(structName, "__ecereClassData_");
10187 FullClassNameCat(structName, type._class.string, false);
10188 exp.type = pointerExp;
10189 exp.member.member = id;
10191 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10192 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10193 MkExpBrackets(MkListOne(MkExpOp(
10194 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10195 MkExpMember(classExp, MkIdentifier("data"))), '+',
10196 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10201 ProcessExpressionType(exp);
10207 // Check for reverse conversion
10208 // (Convert in an instantiation later, so that we can use
10209 // deep properties system)
10210 Symbol classSym = FindClass(id.string);
10213 Class convertClass = classSym.registered;
10215 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10220 if(!exp.member.exp.destType)
10222 if(method && !method._class.symbol)
10223 method._class.symbol = FindClass(method._class.fullName);
10224 if(prop && !prop._class.symbol)
10225 prop._class.symbol = FindClass(prop._class.fullName);
10227 exp.member.exp.destType = Type
10231 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10232 // wasThisClass = type ? type.wasThisClass : false;
10238 exp.member.memberType = propertyMember;
10240 ProcessPropertyType(prop);
10241 exp.expType = prop.dataType;
10242 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10245 CopyTypeInto(type, exp.expType);
10247 type.constant = true;
10248 exp.expType = type;
10250 else if(prop.dataType)
10251 prop.dataType.refCount++;
10255 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10257 FreeExpContents(exp);
10258 exp.type = identifierExp;
10259 exp.identifier = MkIdentifier("class");
10260 ProcessExpressionType(exp);
10264 exp.member.memberType = dataMember;
10265 DeclareStruct(_class.fullName, false);
10266 if(!member.dataType)
10268 Context context = SetupTemplatesContext(_class);
10269 member.dataType = ProcessTypeString(member.dataTypeString, false);
10270 FinishTemplatesContext(context);
10272 exp.expType = member.dataType;
10273 if(member.dataType) member.dataType.refCount++;
10275 else if(revConvert)
10277 exp.member.memberType = reverseConversionMember;
10278 exp.expType = MkClassType(revConvert._class.fullName);
10286 exp.type = identifierExp;
10287 exp.identifier = exp.member.member;
10290 exp.member.memberType = methodMember;
10292 if(!method.dataType)
10293 ProcessMethodType(method);
10301 // Tricky spot here... To use instance versus class virtual table
10302 // Put it back to what it was... What did we break?
10304 // Had to put it back for overriding Main of Thread global instance
10306 //exp.expType.methodClass = _class;
10307 exp.expType.methodClass = (id && id._class) ? _class : null;
10309 // Need the actual class used for templated classes
10310 exp.expType.usedClass = _class;
10312 else if(!classProp)
10314 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10316 FreeExpContents(exp);
10317 exp.type = identifierExp;
10318 exp.identifier = MkIdentifier("class");
10319 FreeType(exp.expType);
10320 exp.expType = MkClassType("ecere::com::Class");
10323 yylloc = exp.member.member.loc;
10324 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10326 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10329 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10333 tClass = type._class && type._class.registered ? type._class.registered : _class;
10334 while(tClass && !tClass.templateClass) tClass = tClass.base;
10336 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10339 ClassTemplateParameter curParam = null;
10342 for(sClass = tClass; sClass; sClass = sClass.base)
10345 if(sClass.templateClass) sClass = sClass.templateClass;
10346 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10348 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10350 for(sClass = sClass.base; sClass; sClass = sClass.base)
10351 id += sClass.templateParams.count;
10356 if(curParam) break;
10359 if(curParam && tClass.templateArgs[id].dataTypeString)
10361 ClassTemplateArgument arg = tClass.templateArgs[id];
10362 Context context = SetupTemplatesContext(tClass);
10363 bool constant = exp.expType.constant;
10364 /*if(!arg.dataType)
10365 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10366 FreeType(exp.expType);
10368 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10369 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10370 else if(exp.expType.kind == pointerType)
10372 Type t = exp.expType.type;
10373 while(t.kind == pointerType) t = t.type;
10374 if(constant) t.constant = constant;
10378 if(exp.expType.kind == thisClassType)
10380 FreeType(exp.expType);
10381 exp.expType = ReplaceThisClassType(_class);
10384 if(tClass.templateClass && (exp.expType.kind != templateType || (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType))))
10385 exp.expType.passAsTemplate = true;
10386 //exp.expType.refCount++;
10389 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10390 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10391 else if(exp.destType.kind == pointerType)
10393 Type t = exp.destType.type;
10394 while(t.kind == pointerType) t = t.type;
10395 if(constant) t.constant = constant;
10398 //exp.destType.refCount++;
10400 if(exp.destType.kind == thisClassType)
10402 FreeType(exp.destType);
10403 exp.destType = ReplaceThisClassType(_class);
10407 FinishTemplatesContext(context);
10410 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10411 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10414 ClassTemplateParameter curParam = null;
10417 for(sClass = tClass; sClass; sClass = sClass.base)
10420 if(sClass.templateClass) sClass = sClass.templateClass;
10421 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10423 if(curParam.type == TemplateParameterType::type &&
10424 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10426 for(sClass = sClass.base; sClass; sClass = sClass.base)
10427 id += sClass.templateParams.count;
10432 if(curParam) break;
10437 ClassTemplateArgument arg = tClass.templateArgs[id];
10438 Context context = SetupTemplatesContext(tClass);
10440 /*if(!arg.dataType)
10441 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10443 basicType = ProcessTypeString(arg.dataTypeString, false);
10446 if(basicType.kind == thisClassType)
10448 FreeType(basicType);
10449 basicType = ReplaceThisClassType(_class);
10452 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10453 if(tClass.templateClass)
10454 basicType.passAsTemplate = true;
10457 FreeType(exp.expType);
10459 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10460 //exp.expType.refCount++;
10463 exp.destType = exp.expType;
10464 exp.destType.refCount++;
10468 Expression newExp { };
10469 OldList * specs = MkList();
10471 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10473 if(exp.destType) exp.destType.refCount++;
10474 if(exp.expType) exp.expType.refCount++;
10475 exp.type = castExp;
10476 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10477 exp.cast.exp = newExp;
10478 //FreeType(exp.expType);
10479 //exp.expType = null;
10480 //ProcessExpressionType(sourceExp);
10483 FinishTemplatesContext(context);
10486 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10488 Class expClass = exp.expType._class.registered;
10491 Class cClass = null;
10493 int paramCount = 0;
10494 int lastParam = -1;
10495 char templateString[1024];
10496 ClassTemplateParameter param;
10497 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10498 while(cClass != expClass)
10501 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10504 for(param = cClass.templateParams.first; param; param = param.next)
10506 Class cClassCur = null;
10508 ClassTemplateParameter paramCur = null;
10509 ClassTemplateArgument arg;
10510 while(cClassCur != tClass && !paramCur)
10513 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10514 cClassCur = sClassCur;
10516 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10518 if(!strcmp(paramCur.name, param.name))
10526 if(paramCur && paramCur.type == TemplateParameterType::type)
10527 arg = tClass.templateArgs[cp];
10529 arg = expClass.templateArgs[p];
10532 char argument[256];
10533 argument[0] = '\0';
10536 strcat(argument, arg.name.string);
10537 strcat(argument, " = ");
10543 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10544 char expString[1024];
10545 OldList * specs = MkList();
10546 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10548 char * string = PrintHexUInt64(arg.expression.ui64);
10549 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10552 ProcessExpressionType(exp);
10553 ComputeExpression(exp);
10554 expString[0] = '\0';
10555 PrintExpression(exp, expString);
10556 strcat(argument, expString);
10558 FreeExpression(exp);
10563 strcat(argument, arg.member.name);
10566 case TemplateParameterType::type:
10568 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10569 strcat(argument, arg.dataTypeString);
10575 if(paramCount) strcat(templateString, ", ");
10576 if(lastParam != p - 1)
10578 strcat(templateString, param.name);
10579 strcat(templateString, " = ");
10581 strcat(templateString, argument);
10590 int len = strlen(templateString);
10591 if(templateString[len-1] == '>') templateString[len++] = ' ';
10592 templateString[len++] = '>';
10593 templateString[len++] = '\0';
10596 FreeType(exp.expType);
10598 Context context = SetupTemplatesContext(tClass);
10599 exp.expType = ProcessTypeString(templateString, false);
10600 FinishTemplatesContext(context);
10607 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10609 else if(type && (type.kind == structType || type.kind == unionType))
10611 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10614 exp.expType = memberType;
10616 memberType.refCount++;
10621 char expString[10240];
10622 expString[0] = '\0';
10623 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10624 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10627 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10629 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10631 Identifier id = exp.member.member;
10632 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10635 FreeType(exp.expType);
10636 exp.expType = ReplaceThisClassType(_class);
10640 yylloc = oldyylloc;
10643 // Convert x->y into (*x).y
10646 Type destType = exp.destType;
10648 // DOING THIS LATER NOW...
10649 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10651 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10652 /* TODO: Name Space Fix ups
10653 if(!exp.member.member.classSym)
10654 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10658 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10659 exp.type = memberExp;
10662 ProcessExpressionType(exp);
10669 //ComputeExpression(exp);
10671 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10672 if(classSym && classSym.registered)
10674 if(classSym.registered.type == noHeadClass)
10678 DeclareStruct(classSym.string, false);
10679 FreeSpecifier(exp._class);
10680 exp.type = typeSizeExp;
10681 FullClassNameCat(name, classSym.string, false);
10682 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10686 if(classSym.registered.fixed)
10688 FreeSpecifier(exp._class);
10689 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10690 exp.type = constantExp;
10694 char className[1024];
10695 strcpy(className, "__ecereClass_");
10696 FullClassNameCat(className, classSym.string, true);
10697 //MangleClassName(className);
10699 DeclareClass(classSym, className);
10701 FreeExpContents(exp);
10702 exp.type = pointerExp;
10703 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10704 exp.member.member = MkIdentifier("structSize");
10712 kind = intSizeType;
10714 // exp.isConstant = true;
10719 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10724 kind = intSizeType;
10726 exp.isConstant = true;
10728 DeclareType(type, false, false);
10734 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10736 FreeType(exp.cast.exp.destType);
10737 exp.cast.exp.destType = type;
10739 type.casted = true;
10740 ProcessExpressionType(exp.cast.exp);
10741 type.casted = false;
10743 exp.expType = type;
10746 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10747 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10749 void * prev = exp.prev, * next = exp.next;
10750 Type expType = exp.cast.exp.destType;
10751 Expression castExp = exp.cast.exp;
10752 Type destType = exp.destType;
10754 if(expType) expType.refCount++;
10756 //FreeType(exp.destType);
10757 FreeType(exp.expType);
10758 FreeTypeName(exp.cast.typeName);
10761 FreeType(exp.expType);
10762 FreeType(exp.destType);
10764 exp.expType = expType;
10765 exp.destType = destType;
10775 exp.isConstant = exp.cast.exp.isConstant;
10780 case extensionInitializerExp:
10782 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10783 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10784 // ProcessInitializer(exp.initializer.initializer, type);
10785 exp.expType = type;
10790 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10791 ProcessExpressionType(exp.vaArg.exp);
10792 exp.expType = type;
10798 exp.isConstant = true;
10800 FreeType(exp.cond.cond.destType);
10801 exp.cond.cond.destType = MkClassType("bool");
10802 exp.cond.cond.destType.truth = true;
10803 ProcessExpressionType(exp.cond.cond);
10804 if(!exp.cond.cond.isConstant)
10805 exp.isConstant = false;
10806 for(e = exp.cond.exp->first; e; e = e.next)
10810 FreeType(e.destType);
10811 e.destType = exp.destType;
10812 if(e.destType) e.destType.refCount++;
10814 ProcessExpressionType(e);
10817 exp.expType = e.expType;
10818 if(e.expType) e.expType.refCount++;
10821 exp.isConstant = false;
10824 FreeType(exp.cond.elseExp.destType);
10825 // Added this check if we failed to find an expType
10826 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10829 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10831 if(exp.cond.elseExp.destType)
10832 exp.cond.elseExp.destType.refCount++;
10833 ProcessExpressionType(exp.cond.elseExp);
10835 // FIXED THIS: Was done before calling process on elseExp
10836 if(!exp.cond.elseExp.isConstant)
10837 exp.isConstant = false;
10840 case extensionCompoundExp:
10842 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10844 Statement last = exp.compound.compound.statements->last;
10845 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10847 ((Expression)last.expressions->last).destType = exp.destType;
10849 exp.destType.refCount++;
10851 ProcessStatement(exp.compound);
10852 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10854 exp.expType.refCount++;
10860 Specifier spec = exp._classExp.specifiers->first;
10861 if(spec && spec.type == nameSpecifier)
10863 exp.expType = MkClassType(spec.name);
10864 exp.expType.kind = subClassType;
10865 exp.byReference = true;
10869 exp.expType = MkClassType("ecere::com::Class");
10870 exp.byReference = true;
10876 Class _class = thisClass ? thisClass : currentClass;
10879 Identifier id = exp.classData.id;
10880 char structName[1024];
10881 Expression classExp;
10882 strcpy(structName, "__ecereClassData_");
10883 FullClassNameCat(structName, _class.fullName, false);
10884 exp.type = pointerExp;
10885 exp.member.member = id;
10886 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10887 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10889 classExp = MkExpIdentifier(MkIdentifier("class"));
10891 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10892 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10893 MkExpBrackets(MkListOne(MkExpOp(
10894 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10895 MkExpMember(classExp, MkIdentifier("data"))), '+',
10896 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10899 ProcessExpressionType(exp);
10907 const char * typeString = null;
10908 char typeStringBuf[1024];
10909 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10910 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10912 Class templateClass = exp.destType._class.registered;
10913 typeString = templateClass.templateArgs[2].dataTypeString;
10917 // Guess type from expressions in the array
10919 for(e = exp.list->first; e; e = e.next)
10921 ProcessExpressionType(e);
10924 if(!type) { type = e.expType; type.refCount++; }
10927 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10928 if(!MatchTypeExpression(e, type, null, false, true))
10934 e = exp.list->first;
10935 ProcessExpressionType(e);
10938 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10939 if(!MatchTypeExpression(e, type, null, false, true))
10941 FreeType(e.expType);
10952 FreeType(e.expType);
10959 typeStringBuf[0] = '\0';
10960 PrintTypeNoConst(type, typeStringBuf, false, true);
10961 typeString = typeStringBuf;
10969 (Container)& (struct BuiltInContainer)
10971 ._vTbl = class(BuiltInContainer)._vTbl,
10972 ._class = class(BuiltInContainer),
10974 .data = (int[]){ 1, 7, 3, 4, 5 },
10976 .type = class(int),
10979 char templateString[1024];
10980 OldList * initializers = MkList();
10981 OldList * structInitializers = MkList();
10982 OldList * specs = MkList();
10984 Declarator decl = SpecDeclFromString(typeString, specs, null);
10985 sprintf(templateString, "Container<%s>", typeString);
10990 type = ProcessTypeString(typeString, false);
10991 while((e = exp.list->first))
10993 exp.list->Remove(e);
10996 ProcessExpressionType(e);
10997 ListAdd(initializers, MkInitializerAssignment(e));
11003 DeclareStruct("ecere::com::BuiltInContainer", false);
11005 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11006 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11007 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11008 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11009 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11010 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11011 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11012 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11013 MkInitializerList(initializers))));
11014 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11015 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11016 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11017 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11018 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11019 exp.expType = ProcessTypeString(templateString, false);
11020 exp.type = bracketsExp;
11021 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11023 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11024 MkInitializerList(structInitializers)))));
11025 ProcessExpressionType(expExt);
11029 exp.expType = ProcessTypeString("Container", false);
11030 Compiler_Error($"Couldn't determine type of array elements\n");
11036 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11038 FreeType(exp.expType);
11039 exp.expType = ReplaceThisClassType(thisClass);
11042 // Resolve structures here
11043 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11045 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11046 // TODO: Fix members reference...
11049 if(exp.expType.kind != enumType)
11052 String enumName = CopyString(exp.expType.enumName);
11054 // Fixed a memory leak on self-referencing C structs typedefs
11055 // by instantiating a new type rather than simply copying members
11056 // into exp.expType
11057 FreeType(exp.expType);
11058 exp.expType = Type { };
11059 exp.expType.kind = symbol.type.kind;
11060 exp.expType.refCount++;
11061 exp.expType.enumName = enumName;
11063 exp.expType.members = symbol.type.members;
11064 for(member = symbol.type.members.first; member; member = member.next)
11069 NamedLink64 member;
11070 for(member = symbol.type.members.first; member; member = member.next)
11072 NamedLink64 value { name = CopyString(member.name) };
11073 exp.expType.members.Add(value);
11080 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11081 else if(exp.destType && !exp.destType.keepCast)
11083 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11084 exp.needTemplateCast = 1;
11086 if(exp.destType.kind == voidType);
11087 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11089 if(!exp.destType.count || unresolved)
11094 if(exp.destType.kind != ellipsisType)
11100 char expString[10240];
11101 expString[0] = '\0';
11103 PrintType(exp.destType, type2, false, true);
11105 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11107 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11108 else if(exp.type != dummyExp)
11109 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11114 char expString[10240] ;
11115 expString[0] = '\0';
11116 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11119 Compiler_Error($"unresolved identifier %s\n", expString);
11120 else if(exp.type != dummyExp)
11121 Compiler_Error($"couldn't determine type of %s\n", expString);
11132 PrintType(exp.expType, type1, false, true);
11133 PrintType(exp.destType, type2, false, true);
11136 //CheckExpressionType(exp, exp.destType, false);
11138 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11139 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11140 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11143 char expString[10240];
11144 expString[0] = '\0';
11145 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11148 CheckExpressionType(exp, exp.destType, false, true);
11150 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11151 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
11152 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11154 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11155 FreeType(exp.expType);
11156 exp.destType.refCount++;
11157 exp.expType = exp.destType;
11162 /*else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
11164 Expression newExp { };
11165 char typeString[1024];
11166 OldList * specs = MkList();
11169 typeString[0] = '\0';
11173 if(exp.expType) exp.expType.refCount++;
11174 if(exp.expType) exp.expType.refCount++;
11175 exp.type = castExp;
11176 newExp.destType = exp.expType;
11178 PrintType(exp.expType, typeString, false, false);
11179 decl = SpecDeclFromString(typeString, specs, null);
11181 exp.cast.typeName = MkTypeName(specs, decl);
11182 exp.cast.exp = newExp;
11185 else if(unresolved)
11187 if(exp.identifier._class && exp.identifier._class.name)
11188 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11189 else if(exp.identifier.string && exp.identifier.string[0])
11190 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11192 else if(!exp.expType && exp.type != dummyExp)
11194 char expString[10240];
11195 expString[0] = '\0';
11196 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11197 Compiler_Error($"couldn't determine type of %s\n", expString);
11200 // Let's try to support any_object & typed_object here:
11202 ApplyAnyObjectLogic(exp);
11204 // Mark nohead classes as by reference, unless we're casting them to an integral type
11205 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11206 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11207 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11208 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11210 exp.byReference = true;
11212 yylloc = oldyylloc;
11215 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11217 // THIS CODE WILL FIND NEXT MEMBER...
11220 *curMember = (*curMember).next;
11222 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11224 *curMember = subMemberStack[--(*subMemberStackPos)];
11225 *curMember = (*curMember).next;
11228 // SKIP ALL PROPERTIES HERE...
11229 while((*curMember) && (*curMember).isProperty)
11230 *curMember = (*curMember).next;
11232 if(subMemberStackPos)
11234 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11236 subMemberStack[(*subMemberStackPos)++] = *curMember;
11238 *curMember = (*curMember).members.first;
11239 while(*curMember && (*curMember).isProperty)
11240 *curMember = (*curMember).next;
11248 if(subMemberStackPos && *subMemberStackPos)
11250 *curMember = subMemberStack[--(*subMemberStackPos)];
11251 *curMember = (*curMember).next;
11255 Class lastCurClass = *curClass;
11257 if(*curClass == _class) break; // REACHED THE END
11259 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11260 *curMember = (*curClass).membersAndProperties.first;
11263 while((*curMember) && (*curMember).isProperty)
11264 *curMember = (*curMember).next;
11265 if(subMemberStackPos)
11267 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11269 subMemberStack[(*subMemberStackPos)++] = *curMember;
11271 *curMember = (*curMember).members.first;
11272 while(*curMember && (*curMember).isProperty)
11273 *curMember = (*curMember).next;
11281 static void ProcessInitializer(Initializer init, Type type)
11285 case expInitializer:
11286 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11288 // TESTING THIS FOR SHUTTING = 0 WARNING
11289 if(init.exp && !init.exp.destType)
11291 FreeType(init.exp.destType);
11292 init.exp.destType = type;
11293 if(type) type.refCount++;
11297 ProcessExpressionType(init.exp);
11298 init.isConstant = init.exp.isConstant;
11304 Expression exp = init.exp;
11305 Instantiation inst = exp.instance;
11306 MembersInit members;
11308 init.type = listInitializer;
11309 init.list = MkList();
11313 for(members = inst.members->first; members; members = members.next)
11315 if(members.type == dataMembersInit)
11318 for(member = members.dataMembers->first; member; member = member.next)
11320 ListAdd(init.list, member.initializer);
11321 member.initializer = null;
11324 // Discard all MembersInitMethod
11327 FreeExpression(exp);
11329 case listInitializer:
11332 Type initializerType = null;
11333 Class curClass = null;
11334 DataMember curMember = null;
11335 DataMember subMemberStack[256];
11336 int subMemberStackPos = 0;
11338 if(type && type.kind == arrayType)
11339 initializerType = Dereference(type);
11340 else if(type && (type.kind == structType || type.kind == unionType))
11341 initializerType = type.members.first;
11343 for(i = init.list->first; i; i = i.next)
11345 if(type && type.kind == classType && type._class && type._class.registered)
11347 // 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)
11348 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11349 // TODO: Generate error on initializing a private data member this way from another module...
11352 if(!curMember.dataType)
11353 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11354 initializerType = curMember.dataType;
11357 ProcessInitializer(i, initializerType);
11358 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11359 initializerType = initializerType.next;
11361 init.isConstant = false;
11364 if(type && type.kind == arrayType)
11365 FreeType(initializerType);
11367 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11369 Compiler_Error($"Assigning list initializer to non list\n");
11376 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11380 case baseSpecifier:
11382 if(spec.specifier == THISCLASS)
11386 spec.type = nameSpecifier;
11387 spec.name = ReplaceThisClass(thisClass);
11388 spec.symbol = FindClass(spec.name);
11389 ProcessSpecifier(spec, declareStruct);
11394 case nameSpecifier:
11396 Symbol symbol = FindType(curContext, spec.name);
11398 DeclareType(symbol.type, true, true);
11399 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11400 DeclareStruct(spec.name, false);
11403 case enumSpecifier:
11408 for(e = spec.list->first; e; e = e.next)
11411 ProcessExpressionType(e.exp);
11416 case structSpecifier:
11417 case unionSpecifier:
11419 if(spec.definitions)
11422 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11424 ProcessClass(spec.definitions, symbol);
11427 for(def = spec.definitions->first; def; def = def.next)
11429 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11430 ProcessDeclaration(def.decl);
11437 case classSpecifier:
11439 Symbol classSym = FindClass(spec.name);
11440 if(classSym && classSym.registered && classSym.registered.type == structClass)
11441 DeclareStruct(spec.name, false);
11449 static void ProcessDeclarator(Declarator decl)
11453 case identifierDeclarator:
11454 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11456 FreeSpecifier(decl.identifier._class);
11457 decl.identifier._class = null;
11460 case arrayDeclarator:
11462 ProcessExpressionType(decl.array.exp);
11463 case structDeclarator:
11464 case bracketsDeclarator:
11465 case functionDeclarator:
11466 case pointerDeclarator:
11467 case extendedDeclarator:
11468 case extendedDeclaratorEnd:
11469 if(decl.declarator)
11470 ProcessDeclarator(decl.declarator);
11471 if(decl.type == functionDeclarator)
11473 Identifier id = GetDeclId(decl);
11474 if(id && id._class)
11478 qualifiers = MkListOne(id._class);
11481 if(!decl.function.parameters)
11482 decl.function.parameters = MkList();
11483 decl.function.parameters->Insert(null, param);
11486 if(decl.function.parameters)
11490 for(param = decl.function.parameters->first; param; param = param.next)
11492 if(param.qualifiers && param.qualifiers->first)
11494 Specifier spec = param.qualifiers->first;
11495 if(spec && spec.specifier == TYPED_OBJECT)
11497 Declarator d = param.declarator;
11500 qualifiers = MkListOne(MkSpecifier(VOID));
11501 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11503 if(d.type != pointerDeclarator)
11504 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11506 FreeList(param.qualifiers, FreeSpecifier);
11508 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11509 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11511 decl.function.parameters->Insert(param, newParam);
11514 else if(spec && spec.specifier == ANY_OBJECT)
11516 Declarator d = param.declarator;
11518 FreeList(param.qualifiers, FreeSpecifier);
11520 param.qualifiers = MkListOne(MkSpecifier(VOID));
11521 if(d.type != pointerDeclarator)
11522 param.qualifiers->Insert(null, MkSpecifier(CONST));
11523 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11525 else if(spec.specifier == THISCLASS)
11529 spec.type = nameSpecifier;
11530 spec.name = ReplaceThisClass(thisClass);
11531 spec.symbol = FindClass(spec.name);
11532 ProcessSpecifier(spec, false);
11537 if(param.declarator)
11538 ProcessDeclarator(param.declarator);
11546 static void ProcessDeclaration(Declaration decl)
11551 case initDeclaration:
11553 bool declareStruct = false;
11555 lineNum = decl.pos.line;
11556 column = decl.pos.col;
11559 if(decl.declarators)
11563 for(d = decl.declarators->first; d; d = d.next)
11565 Type type, subType;
11566 ProcessDeclarator(d.declarator);
11568 type = ProcessType(decl.specifiers, d.declarator);
11572 ProcessInitializer(d.initializer, type);
11574 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11576 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11577 d.initializer.exp.type == instanceExp)
11579 if(type.kind == classType && type._class ==
11580 d.initializer.exp.expType._class)
11582 Instantiation inst = d.initializer.exp.instance;
11583 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11585 d.initializer.exp.instance = null;
11586 if(decl.specifiers)
11587 FreeList(decl.specifiers, FreeSpecifier);
11588 FreeList(decl.declarators, FreeInitDeclarator);
11592 decl.type = instDeclaration;
11597 for(subType = type; subType;)
11599 if(subType.kind == classType)
11601 declareStruct = true;
11604 else if(subType.kind == pointerType)
11606 else if(subType.kind == arrayType)
11607 subType = subType.arrayType;
11617 if(decl.specifiers)
11620 for(s = decl.specifiers->first; s; s = s.next)
11622 ProcessSpecifier(s, declareStruct);
11627 case instDeclaration:
11629 ProcessInstantiationType(decl.inst);
11632 case structDeclaration:
11636 bool declareStruct = false;
11638 if(decl.declarators)
11640 for(d = decl.declarators->first; d; d = d.next)
11642 Type type = ProcessType(decl.specifiers, d.declarator);
11644 ProcessDeclarator(d);
11645 for(subType = type; subType;)
11647 if(subType.kind == classType)
11649 declareStruct = true;
11652 else if(subType.kind == pointerType)
11654 else if(subType.kind == arrayType)
11655 subType = subType.arrayType;
11662 if(decl.specifiers)
11664 for(spec = decl.specifiers->first; spec; spec = spec.next)
11665 ProcessSpecifier(spec, declareStruct);
11672 static FunctionDefinition curFunction;
11674 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11676 char propName[1024], propNameM[1024];
11677 char getName[1024], setName[1024];
11680 DeclareProperty(prop, setName, getName);
11682 // eInstance_FireWatchers(object, prop);
11683 strcpy(propName, "__ecereProp_");
11684 FullClassNameCat(propName, prop._class.fullName, false);
11685 strcat(propName, "_");
11686 // strcat(propName, prop.name);
11687 FullClassNameCat(propName, prop.name, true);
11688 //MangleClassName(propName);
11690 strcpy(propNameM, "__ecerePropM_");
11691 FullClassNameCat(propNameM, prop._class.fullName, false);
11692 strcat(propNameM, "_");
11693 // strcat(propNameM, prop.name);
11694 FullClassNameCat(propNameM, prop.name, true);
11695 //MangleClassName(propNameM);
11697 if(prop.isWatchable)
11700 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11701 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11702 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11705 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11706 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11707 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11713 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11714 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11715 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11718 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11719 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11720 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11723 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11724 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11725 curFunction.propSet.fireWatchersDone = true;
11728 static void ProcessStatement(Statement stmt)
11732 lineNum = stmt.pos.line;
11733 column = stmt.pos.col;
11738 ProcessStatement(stmt.labeled.stmt);
11741 // This expression should be constant...
11742 if(stmt.caseStmt.exp)
11744 FreeType(stmt.caseStmt.exp.destType);
11745 stmt.caseStmt.exp.destType = curSwitchType;
11746 if(curSwitchType) curSwitchType.refCount++;
11747 ProcessExpressionType(stmt.caseStmt.exp);
11748 ComputeExpression(stmt.caseStmt.exp);
11750 if(stmt.caseStmt.stmt)
11751 ProcessStatement(stmt.caseStmt.stmt);
11755 if(stmt.compound.context)
11760 Statement prevCompound = curCompound;
11761 Context prevContext = curContext;
11763 if(!stmt.compound.isSwitch)
11764 curCompound = stmt;
11765 curContext = stmt.compound.context;
11767 if(stmt.compound.declarations)
11769 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11770 ProcessDeclaration(decl);
11772 if(stmt.compound.statements)
11774 for(s = stmt.compound.statements->first; s; s = s.next)
11775 ProcessStatement(s);
11778 curContext = prevContext;
11779 curCompound = prevCompound;
11783 case expressionStmt:
11786 if(stmt.expressions)
11788 for(exp = stmt.expressions->first; exp; exp = exp.next)
11789 ProcessExpressionType(exp);
11797 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11798 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11799 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11800 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11802 ProcessExpressionType(exp);
11804 if(stmt.ifStmt.stmt)
11805 ProcessStatement(stmt.ifStmt.stmt);
11806 if(stmt.ifStmt.elseStmt)
11807 ProcessStatement(stmt.ifStmt.elseStmt);
11812 Type oldSwitchType = curSwitchType;
11813 if(stmt.switchStmt.exp)
11816 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11826 e.exp.destType = destType;
11829 ProcessExpressionType(exp);
11832 curSwitchType = exp.expType;
11835 ProcessStatement(stmt.switchStmt.stmt);
11836 curSwitchType = oldSwitchType;
11841 if(stmt.whileStmt.exp)
11845 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11846 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11847 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11848 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11850 ProcessExpressionType(exp);
11853 if(stmt.whileStmt.stmt)
11854 ProcessStatement(stmt.whileStmt.stmt);
11859 if(stmt.doWhile.exp)
11863 if(stmt.doWhile.exp->last)
11865 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11866 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11867 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11869 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11871 ProcessExpressionType(exp);
11874 if(stmt.doWhile.stmt)
11875 ProcessStatement(stmt.doWhile.stmt);
11881 if(stmt.forStmt.init)
11882 ProcessStatement(stmt.forStmt.init);
11884 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11886 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11887 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11888 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11891 if(stmt.forStmt.check)
11892 ProcessStatement(stmt.forStmt.check);
11893 if(stmt.forStmt.increment)
11895 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11896 ProcessExpressionType(exp);
11899 if(stmt.forStmt.stmt)
11900 ProcessStatement(stmt.forStmt.stmt);
11905 Identifier id = stmt.forEachStmt.id;
11906 OldList * exp = stmt.forEachStmt.exp;
11907 OldList * filter = stmt.forEachStmt.filter;
11908 Statement block = stmt.forEachStmt.stmt;
11909 char iteratorType[1024];
11912 bool isBuiltin = exp && exp->last &&
11913 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11914 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11915 Expression arrayExp;
11916 const char * typeString = null;
11917 int builtinCount = 0;
11919 for(e = exp ? exp->first : null; e; e = e.next)
11923 FreeType(e.destType);
11924 e.destType = ProcessTypeString("Container", false);
11926 if(!isBuiltin || e.next)
11927 ProcessExpressionType(e);
11930 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11931 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11932 eClass_IsDerived(source._class.registered, containerClass)))
11934 Class _class = source ? source._class.registered : null;
11936 Expression expIt = null;
11937 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
11938 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11939 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11940 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11941 stmt.type = compoundStmt;
11943 stmt.compound.context = Context { };
11944 stmt.compound.context.parent = curContext;
11945 curContext = stmt.compound.context;
11947 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11949 Class mapClass = eSystem_FindClass(privateModule, "Map");
11950 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11951 isCustomAVLTree = true;
11952 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
11954 else */if(eClass_IsDerived(source._class.registered, mapClass))
11957 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11958 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11960 Class listClass = eSystem_FindClass(privateModule, "List");
11962 isList = eClass_IsDerived(source._class.registered, listClass);
11968 OldList * specs = MkList();
11969 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11970 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11971 stmt.compound.declarations = MkListOne(
11972 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11973 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11974 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11975 MkInitializerAssignment(MkExpBrackets(exp))))));
11980 char typeStringBuf[1024];
11982 // TODO: Merge this code?
11983 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11984 if(((Expression)exp->last).type == castExp)
11986 TypeName typeName = ((Expression)exp->last).cast.typeName;
11988 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11991 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11992 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11993 arrayExp.destType._class.registered.templateArgs)
11995 Class templateClass = arrayExp.destType._class.registered;
11996 typeString = templateClass.templateArgs[2].dataTypeString;
11998 else if(arrayExp.list)
12000 // Guess type from expressions in the array
12002 for(e = arrayExp.list->first; e; e = e.next)
12004 ProcessExpressionType(e);
12007 if(!type) { type = e.expType; type.refCount++; }
12010 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12011 if(!MatchTypeExpression(e, type, null, false, true))
12017 e = arrayExp.list->first;
12018 ProcessExpressionType(e);
12021 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12022 if(!MatchTypeExpression(e, type, null, false, true))
12024 FreeType(e.expType);
12035 FreeType(e.expType);
12042 typeStringBuf[0] = '\0';
12043 PrintType(type, typeStringBuf, false, true);
12044 typeString = typeStringBuf;
12050 OldList * initializers = MkList();
12052 OldList * specs = MkList();
12057 builtinCount = arrayExp.list->count;
12058 type = ProcessTypeString(typeString, false);
12059 while((e = arrayExp.list->first))
12061 arrayExp.list->Remove(e);
12064 ProcessExpressionType(e);
12065 ListAdd(initializers, MkInitializerAssignment(e));
12068 delete arrayExp.list;
12070 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12071 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12072 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12074 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12076 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12077 ), MkInitializerList(initializers)))));
12078 FreeList(exp, FreeExpression);
12082 arrayExp.expType = ProcessTypeString("Container", false);
12083 Compiler_Error($"Couldn't determine type of array elements\n");
12088 OldList * specs = MkList();
12090 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12091 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12092 stmt.compound.declarations = MkListOne(
12093 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12094 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12095 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12096 MkInitializerAssignment(MkExpBrackets(exp))))));
12099 else if(isLinkList && !isList)
12102 OldList * specs = MkList();
12103 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12104 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12105 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12106 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12107 MkInitializerAssignment(MkExpBrackets(exp))))));
12109 /*else if(isCustomAVLTree)
12112 OldList * specs = MkList();
12113 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12114 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12115 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12116 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12117 MkInitializerAssignment(MkExpBrackets(exp))))));
12119 else if(_class.templateArgs)
12122 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12124 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12126 stmt.compound.declarations = MkListOne(
12127 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12128 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12129 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12131 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12135 // Reparent sub-contexts in this statement
12139 if(block.compound.context)
12140 block.compound.context.parent = stmt.compound.context;
12143 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12144 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12145 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12146 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12149 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12150 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12153 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12154 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12157 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12158 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12161 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12162 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12165 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12166 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12168 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12171 case expressionStmt:
12177 case badDeclarationStmt:
12178 case fireWatchersStmt:
12179 case stopWatchingStmt:
12186 block = MkIfStmt(filter, block, null);
12190 stmt.compound.statements = MkListOne(MkForStmt(
12191 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12192 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12193 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12194 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12196 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12197 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12198 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12203 //OldList * specs = MkList();
12204 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12206 sprintf(count, "%d", builtinCount);
12208 stmt.compound.statements = MkListOne(MkForStmt(
12209 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12210 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12211 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12212 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12216 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12217 stmt.compound.statements = MkListOne(MkForStmt(
12218 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12219 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12220 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12221 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12224 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12225 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12226 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12228 else if(isLinkList && !isList)
12230 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12231 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12232 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12233 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12235 stmt.compound.statements = MkListOne(MkForStmt(
12236 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12237 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12238 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12243 OldList * specs = MkList();
12244 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12245 stmt.compound.statements = MkListOne(MkForStmt(
12246 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12247 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12248 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12249 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12250 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12253 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12254 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12255 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12257 /*else if(isCustomAVLTree)
12259 stmt.compound.statements = MkListOne(MkForStmt(
12260 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12261 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12262 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12263 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12266 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12267 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12268 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12272 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12273 MkIdentifier("Next")), null)), block));
12275 ProcessExpressionType(expIt);
12276 if(stmt.compound.declarations->first)
12277 ProcessDeclaration(stmt.compound.declarations->first);
12280 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12282 ProcessStatement(stmt);
12283 curContext = stmt.compound.context.parent;
12288 Compiler_Error($"Expression is not a container\n");
12301 if(stmt.expressions)
12303 for(exp = stmt.expressions->first; exp; exp = exp.next)
12307 if(curFunction && !curFunction.type)
12308 curFunction.type = ProcessType(
12309 curFunction.specifiers, curFunction.declarator);
12310 FreeType(exp.destType);
12311 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12312 if(exp.destType) exp.destType.refCount++;
12314 ProcessExpressionType(exp);
12319 case badDeclarationStmt:
12321 ProcessDeclaration(stmt.decl);
12327 if(stmt.asmStmt.inputFields)
12329 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12330 if(field.expression)
12331 ProcessExpressionType(field.expression);
12333 if(stmt.asmStmt.outputFields)
12335 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12336 if(field.expression)
12337 ProcessExpressionType(field.expression);
12339 if(stmt.asmStmt.clobberedFields)
12341 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12343 if(field.expression)
12344 ProcessExpressionType(field.expression);
12351 PropertyWatch propWatch;
12352 OldList * watches = stmt._watch.watches;
12353 Expression object = stmt._watch.object;
12354 Expression watcher = stmt._watch.watcher;
12356 ProcessExpressionType(watcher);
12358 ProcessExpressionType(object);
12362 if(watcher || thisClass)
12364 External external = curExternal;
12365 Context context = curContext;
12367 stmt.type = expressionStmt;
12368 stmt.expressions = MkList();
12370 curExternal = external.prev;
12372 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12374 ClassFunction func;
12375 char watcherName[1024];
12376 Class watcherClass = watcher ?
12377 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12378 External createdExternal;
12380 // Create a declaration above
12381 External externalDecl = MkExternalDeclaration(null);
12382 ast->Insert(curExternal.prev, externalDecl);
12384 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12385 if(propWatch.deleteWatch)
12386 strcat(watcherName, "_delete");
12390 for(propID = propWatch.properties->first; propID; propID = propID.next)
12392 strcat(watcherName, "_");
12393 strcat(watcherName, propID.string);
12397 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12399 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12400 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12401 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12402 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12403 ProcessClassFunctionBody(func, propWatch.compound);
12404 propWatch.compound = null;
12406 //afterExternal = afterExternal ? afterExternal : curExternal;
12408 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12409 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12411 createdExternal.symbol.idCode = external.symbol.idCode;
12413 curExternal = createdExternal;
12414 ProcessFunction(createdExternal.function);
12417 // Create a declaration above
12419 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12420 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12421 externalDecl.declaration = decl;
12422 if(decl.symbol && !decl.symbol.pointerExternal)
12423 decl.symbol.pointerExternal = externalDecl;
12426 if(propWatch.deleteWatch)
12428 OldList * args = MkList();
12429 ListAdd(args, CopyExpression(object));
12430 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12431 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12432 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12436 Class _class = object.expType._class.registered;
12439 for(propID = propWatch.properties->first; propID; propID = propID.next)
12441 char propName[1024];
12442 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12445 char getName[1024], setName[1024];
12446 OldList * args = MkList();
12448 DeclareProperty(prop, setName, getName);
12450 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12451 strcpy(propName, "__ecereProp_");
12452 FullClassNameCat(propName, prop._class.fullName, false);
12453 strcat(propName, "_");
12454 // strcat(propName, prop.name);
12455 FullClassNameCat(propName, prop.name, true);
12457 ListAdd(args, CopyExpression(object));
12458 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12459 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12460 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12462 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12465 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12470 Compiler_Error($"Invalid watched object\n");
12473 curExternal = external;
12474 curContext = context;
12477 FreeExpression(watcher);
12479 FreeExpression(object);
12480 FreeList(watches, FreePropertyWatch);
12483 Compiler_Error($"No observer specified and not inside a _class\n");
12487 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12489 ProcessStatement(propWatch.compound);
12495 case fireWatchersStmt:
12497 OldList * watches = stmt._watch.watches;
12498 Expression object = stmt._watch.object;
12500 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12501 // printf("%X\n", watches);
12502 // printf("%X\n", stmt._watch.watches);
12504 ProcessExpressionType(object);
12509 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12515 stmt.type = expressionStmt;
12516 stmt.expressions = MkList();
12518 // Check if we're inside a property set
12519 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12521 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12525 //Compiler_Error($"No property specified and not inside a property set\n");
12529 for(propID = watches->first; propID; propID = propID.next)
12531 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12534 CreateFireWatcher(prop, object, stmt);
12537 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12542 // Fire all properties!
12545 for(base = _class; base; base = base.base)
12547 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12549 if(prop.isProperty && prop.isWatchable)
12551 CreateFireWatcher(prop, object, stmt);
12558 FreeExpression(object);
12559 FreeList(watches, FreeIdentifier);
12562 Compiler_Error($"Invalid object specified and not inside a class\n");
12566 case stopWatchingStmt:
12568 OldList * watches = stmt._watch.watches;
12569 Expression object = stmt._watch.object;
12570 Expression watcher = stmt._watch.watcher;
12573 ProcessExpressionType(object);
12575 ProcessExpressionType(watcher);
12578 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12580 if(watcher || thisClass)
12586 stmt.type = expressionStmt;
12587 stmt.expressions = MkList();
12592 // eInstance_StopWatching(object, null, watcher);
12594 ListAdd(args, CopyExpression(object));
12595 ListAdd(args, MkExpConstant("0"));
12596 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12597 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12601 for(propID = watches->first; propID; propID = propID.next)
12603 char propName[1024];
12604 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12607 char getName[1024], setName[1024];
12608 OldList * args = MkList();
12610 DeclareProperty(prop, setName, getName);
12612 // eInstance_StopWatching(object, prop, watcher);
12613 strcpy(propName, "__ecereProp_");
12614 FullClassNameCat(propName, prop._class.fullName, false);
12615 strcat(propName, "_");
12616 // strcat(propName, prop.name);
12617 FullClassNameCat(propName, prop.name, true);
12618 //MangleClassName(propName);
12620 ListAdd(args, CopyExpression(object));
12621 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12622 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12623 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12626 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12631 FreeExpression(object);
12633 FreeExpression(watcher);
12634 FreeList(watches, FreeIdentifier);
12637 Compiler_Error($"Invalid object specified and not inside a class\n");
12640 Compiler_Error($"No observer specified and not inside a class\n");
12647 static void ProcessFunction(FunctionDefinition function)
12649 Identifier id = GetDeclId(function.declarator);
12650 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12651 Type type = symbol ? symbol.type : null;
12652 Class oldThisClass = thisClass;
12653 Context oldTopContext = topContext;
12655 yylloc = function.loc;
12656 // Process thisClass
12658 if(type && type.thisClass)
12660 Symbol classSym = type.thisClass;
12661 Class _class = type.thisClass.registered;
12662 char className[1024];
12663 char structName[1024];
12664 Declarator funcDecl;
12667 bool typedObject = false;
12669 if(_class && !_class.base)
12671 _class = currentClass;
12672 if(_class && !_class.symbol)
12673 _class.symbol = FindClass(_class.fullName);
12674 classSym = _class ? _class.symbol : null;
12675 typedObject = true;
12678 thisClass = _class;
12680 if(inCompiler && _class)
12682 if(type.kind == functionType)
12684 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12686 //TypeName param = symbol.type.params.first;
12687 Type param = symbol.type.params.first;
12688 symbol.type.params.Remove(param);
12689 //FreeTypeName(param);
12692 if(type.classObjectType != classPointer)
12694 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12695 symbol.type.staticMethod = true;
12696 symbol.type.thisClass = null;
12698 // HIGH DANGER: VERIFYING THIS...
12699 symbol.type.extraParam = false;
12703 strcpy(className, "__ecereClass_");
12704 FullClassNameCat(className, _class.fullName, true);
12706 //MangleClassName(className);
12709 FullClassNameCat(structName, _class.fullName, false);
12714 funcDecl = GetFuncDecl(function.declarator);
12717 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12719 TypeName param = funcDecl.function.parameters->first;
12720 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12722 funcDecl.function.parameters->Remove(param);
12723 FreeTypeName(param);
12727 // DANGER: Watch for this... Check if it's a Conversion?
12728 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12730 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12731 if(!function.propertyNoThis)
12733 TypeName thisParam = null;
12735 if(type.classObjectType != classPointer)
12737 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12738 if(!funcDecl.function.parameters)
12739 funcDecl.function.parameters = MkList();
12740 funcDecl.function.parameters->Insert(null, thisParam);
12745 if(type.classObjectType != classPointer)
12747 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12748 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12751 thisParam = TypeName
12753 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12754 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12756 funcDecl.function.parameters->Insert(null, thisParam);
12761 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12763 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12764 funcDecl = GetFuncDecl(initDecl.declarator);
12767 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12769 TypeName param = funcDecl.function.parameters->first;
12770 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12772 funcDecl.function.parameters->Remove(param);
12773 FreeTypeName(param);
12777 if(type.classObjectType != classPointer)
12779 // DANGER: Watch for this... Check if it's a Conversion?
12780 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12782 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12784 if(!funcDecl.function.parameters)
12785 funcDecl.function.parameters = MkList();
12786 funcDecl.function.parameters->Insert(null, thisParam);
12793 // Add this to the context
12796 if(type.classObjectType != classPointer)
12798 thisSymbol = Symbol
12800 string = CopyString("this");
12801 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12803 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12805 if(typedObject && thisSymbol.type)
12807 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12808 thisSymbol.type.byReference = type.byReference;
12809 thisSymbol.type.typedByReference = type.byReference;
12811 thisSymbol = Symbol { string = CopyString("class") };
12812 function.body.compound.context.symbols.Add(thisSymbol);
12818 // Pointer to class data
12820 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12822 DataMember member = null;
12825 for(base = _class; base && base.type != systemClass; base = base.next)
12827 for(member = base.membersAndProperties.first; member; member = member.next)
12828 if(!member.isProperty)
12834 for(member = _class.membersAndProperties.first; member; member = member.next)
12835 if(!member.isProperty)
12839 char pointerName[1024];
12842 Initializer initializer;
12843 Expression exp, bytePtr;
12845 strcpy(pointerName, "__ecerePointer_");
12846 FullClassNameCat(pointerName, _class.fullName, false);
12848 char className[1024];
12849 strcpy(className, "__ecereClass_");
12850 FullClassNameCat(className, classSym.string, true);
12851 //MangleClassName(className);
12854 DeclareClass(classSym, className);
12858 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12863 sprintf(string, "%d", _class.offset);
12864 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12868 // ([bytePtr] + [className]->offset)
12869 exp = QBrackets(MkExpOp(bytePtr, '+',
12870 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12873 // (this ? [exp] : 0)
12874 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12878 kind = pointerType;
12879 type = Type { refCount = 1, kind = voidType };
12884 yylloc = function.body.loc;
12885 // ([structName] *) [exp]
12886 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12887 initializer = MkInitializerAssignment(
12888 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12890 // [structName] * [pointerName] = [initializer];
12891 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12894 Context prevContext = curContext;
12895 curContext = function.body.compound.context;
12897 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12898 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12900 curContext = prevContext;
12904 decl.symbol = null;
12906 if(!function.body.compound.declarations)
12907 function.body.compound.declarations = MkList();
12908 function.body.compound.declarations->Insert(null, decl);
12914 // Loop through the function and replace undeclared identifiers
12915 // which are a member of the class (methods, properties or data)
12916 // by "this.[member]"
12923 FreeSpecifier(id._class);
12926 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12928 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12929 id = GetDeclId(initDecl.declarator);
12931 FreeSpecifier(id._class);
12936 topContext = function.body.compound.context;
12938 FunctionDefinition oldFunction = curFunction;
12939 curFunction = function;
12941 ProcessStatement(function.body);
12943 // If this is a property set and no firewatchers has been done yet, add one here
12944 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12946 Statement prevCompound = curCompound;
12947 Context prevContext = curContext;
12949 Statement fireWatchers = MkFireWatchersStmt(null, null);
12950 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12951 ListAdd(function.body.compound.statements, fireWatchers);
12953 curCompound = function.body;
12954 curContext = function.body.compound.context;
12956 ProcessStatement(fireWatchers);
12958 curContext = prevContext;
12959 curCompound = prevCompound;
12963 curFunction = oldFunction;
12966 if(function.declarator)
12968 ProcessDeclarator(function.declarator);
12971 topContext = oldTopContext;
12972 thisClass = oldThisClass;
12975 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12976 static void ProcessClass(OldList definitions, Symbol symbol)
12979 External external = curExternal;
12980 Class regClass = symbol ? symbol.registered : null;
12982 // Process all functions
12983 for(def = definitions.first; def; def = def.next)
12985 if(def.type == functionClassDef)
12987 if(def.function.declarator)
12988 curExternal = def.function.declarator.symbol.pointerExternal;
12990 curExternal = external;
12992 ProcessFunction((FunctionDefinition)def.function);
12994 else if(def.type == declarationClassDef)
12996 if(def.decl.type == instDeclaration)
12998 thisClass = regClass;
12999 ProcessInstantiationType(def.decl.inst);
13005 Class backThisClass = thisClass;
13006 if(regClass) thisClass = regClass;
13007 ProcessDeclaration(def.decl);
13008 thisClass = backThisClass;
13011 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13013 MemberInit defProperty;
13015 // Add this to the context
13016 Symbol thisSymbol = Symbol
13018 string = CopyString("this");
13019 type = regClass ? MkClassType(regClass.fullName) : null;
13021 globalContext.symbols.Add((BTNode)thisSymbol);
13023 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13025 thisClass = regClass;
13026 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13030 globalContext.symbols.Remove((BTNode)thisSymbol);
13031 FreeSymbol(thisSymbol);
13033 else if(def.type == propertyClassDef && def.propertyDef)
13035 PropertyDef prop = def.propertyDef;
13037 // Add this to the context
13039 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
13040 globalContext.symbols.Add(thisSymbol);
13043 thisClass = regClass;
13050 string = CopyString("this");
13051 type = MkClassType(regClass.fullName);
13053 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13056 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13057 ProcessStatement(prop.setStmt);
13065 string = CopyString("this");
13066 type = MkClassType(regClass.fullName);
13068 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13071 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13072 ProcessStatement(prop.getStmt);
13080 string = CopyString("this");
13081 type = MkClassType(regClass.fullName);
13083 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13086 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13087 ProcessStatement(prop.issetStmt);
13093 globalContext.symbols.Remove(thisSymbol);
13094 FreeSymbol(thisSymbol);
13097 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13099 PropertyWatch propertyWatch = def.propertyWatch;
13101 thisClass = regClass;
13102 if(propertyWatch.compound)
13106 string = CopyString("this");
13107 type = regClass ? MkClassType(regClass.fullName) : null;
13110 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13112 curExternal = null;
13113 ProcessStatement(propertyWatch.compound);
13120 void DeclareFunctionUtil(const String s)
13122 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13127 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13128 strcpy(name, "__ecereFunction_");
13129 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13130 DeclareFunction(function, name);
13134 void ComputeDataTypes()
13138 External after = null;
13140 currentClass = null;
13142 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13144 for(external = ast->first; external; external = external.next)
13146 if(external.type == declarationExternal)
13148 Declaration decl = external.declaration;
13151 OldList * decls = decl.declarators;
13154 InitDeclarator initDecl = decls->first;
13157 Declarator declarator = initDecl.declarator;
13158 if(declarator && declarator.type == identifierDeclarator)
13160 Identifier id = declarator.identifier;
13161 if(id && id.string)
13163 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
13165 external.symbol.id = -1001, external.symbol.idCode = -1001;
13177 // Workaround until we have proper toposort for declarations reordering
13178 External e = MkExternalDeclaration(MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Instance"), null)), null));
13179 ast->Insert(after, e);
13183 temp.symbol = Symbol { id = -1000, idCode = -1000 };
13184 ast->Insert(after, temp);
13185 curExternal = temp;
13187 DeclareFunctionUtil("eSystem_New");
13188 DeclareFunctionUtil("eSystem_New0");
13189 DeclareFunctionUtil("eSystem_Renew");
13190 DeclareFunctionUtil("eSystem_Renew0");
13191 DeclareFunctionUtil("eSystem_Delete");
13192 DeclareFunctionUtil("eClass_GetProperty");
13193 DeclareFunctionUtil("eClass_SetProperty");
13194 DeclareFunctionUtil("eInstance_FireSelfWatchers");
13195 DeclareFunctionUtil("eInstance_SetMethod");
13196 DeclareFunctionUtil("eInstance_IncRef");
13197 DeclareFunctionUtil("eInstance_StopWatching");
13198 DeclareFunctionUtil("eInstance_Watch");
13199 DeclareFunctionUtil("eInstance_FireWatchers");
13201 DeclareStruct("ecere::com::Class", false);
13202 DeclareStruct("ecere::com::Instance", false);
13203 DeclareStruct("ecere::com::Property", false);
13204 DeclareStruct("ecere::com::DataMember", false);
13205 DeclareStruct("ecere::com::Method", false);
13206 DeclareStruct("ecere::com::SerialBuffer", false);
13207 DeclareStruct("ecere::com::ClassTemplateArgument", false);
13211 for(external = ast->first; external; external = external.next)
13213 afterExternal = curExternal = external;
13214 if(external.type == functionExternal)
13216 currentClass = external.function._class;
13217 ProcessFunction(external.function);
13219 // There shouldn't be any _class member access here anyways...
13220 else if(external.type == declarationExternal)
13222 currentClass = null;
13223 if(external.declaration)
13224 ProcessDeclaration(external.declaration);
13226 else if(external.type == classExternal)
13228 ClassDefinition _class = external._class;
13229 currentClass = external.symbol.registered;
13230 if(_class.definitions)
13232 ProcessClass(_class.definitions, _class.symbol);
13236 // Free class data...
13237 ast->Remove(external);
13241 else if(external.type == nameSpaceExternal)
13243 thisNameSpace = external.id.string;
13246 currentClass = null;
13247 thisNameSpace = null;
13248 curExternal = null;
13250 delete temp.symbol;