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)
52 OutputExpression(exp, f);
54 count = strlen(string);
55 count += f.Read(string + count, 1, 1023);
61 Type ProcessTemplateParameterType(TemplateParameter param)
63 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
65 // TOFIX: Will need to free this Type
68 if(param.dataTypeString)
69 param.baseType = ProcessTypeString(param.dataTypeString, false);
71 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
73 return param.baseType;
78 bool NeedCast(Type type1, Type type2)
80 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
82 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
87 if(type1.kind == type2.kind)
98 if(type1.passAsTemplate && !type2.passAsTemplate)
100 return type1.isSigned != type2.isSigned;
102 return type1._class != type2._class;
104 return NeedCast(type1.type, type2.type);
106 return true; //false; ????
112 static void ReplaceClassMembers(Expression exp, Class _class)
114 if(exp.type == identifierExp && exp.identifier)
116 Identifier id = exp.identifier;
118 Symbol symbol = null;
119 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
121 // First, check if the identifier is declared inside the function
122 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
124 symbol = (Symbol)ctx.symbols.FindString(id.string);
129 // If it is not, check if it is a member of the _class
130 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
132 Property prop = eClass_FindProperty(_class, id.string, privateModule);
133 Method method = null;
134 DataMember member = null;
135 ClassProperty classProp = null;
138 method = eClass_FindMethod(_class, id.string, privateModule);
141 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
142 if(!prop && !method && !member)
144 classProp = eClass_FindClassProperty(_class, id.string);
146 if(prop || method || member || classProp)
148 // Replace by this.[member]
149 exp.type = memberExp;
150 exp.member.member = id;
151 exp.member.memberType = unresolvedMember;
152 exp.member.exp = QMkExpId("this");
153 //exp.member.exp.loc = exp.loc;
154 exp.addedThis = true;
156 else if(_class && _class.templateParams.first)
159 for(sClass = _class; sClass; sClass = sClass.base)
161 if(sClass.templateParams.first)
163 ClassTemplateParameter param;
164 for(param = sClass.templateParams.first; param; param = param.next)
166 if(param.type == expression && !strcmp(param.name, id.string))
168 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
173 OldList * specs = MkList();
175 FreeIdentifier(exp.member.member);
177 ProcessExpressionType(argExp);
179 decl = SpecDeclFromString(param.dataTypeString, specs, null);
181 exp.expType = ProcessType(specs, decl);
183 // *[expType] *[argExp]
184 exp.type = bracketsExp;
185 exp.list = MkListOne(MkExpOp(null, '*',
186 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
197 ////////////////////////////////////////////////////////////////////////
198 // PRINTING ////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////////////////
201 public char * PrintInt(int64 result)
205 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
207 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
208 if(result > MAXINT || result < MININT)
210 return CopyString(temp);
213 public char * PrintUInt(uint64 result)
216 if(result > MAXDWORD)
217 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
218 else if(result > MAXINT)
219 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
221 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
222 return CopyString(temp);
225 public char * PrintInt64(int64 result)
228 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
229 return CopyString(temp);
232 public char * PrintUInt64(uint64 result)
235 if(result > MAXINT64)
236 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
238 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
239 return CopyString(temp);
242 public char * PrintHexUInt(uint64 result)
245 if(result > MAXDWORD)
246 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
248 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
249 if(result > MAXDWORD)
251 return CopyString(temp);
254 public char * PrintHexUInt64(uint64 result)
257 if(result > MAXDWORD)
258 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
260 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
261 return CopyString(temp);
264 public char * PrintShort(short result)
267 sprintf(temp, "%d", (unsigned short)result);
268 return CopyString(temp);
271 public char * PrintUShort(unsigned short result)
275 sprintf(temp, "0x%X", (int)result);
277 sprintf(temp, "%d", (int)result);
278 return CopyString(temp);
281 public char * PrintChar(char result)
284 if(result > 0 && isprint(result))
285 sprintf(temp, "'%c'", result);
287 sprintf(temp, "%d", (int)result);
289 //sprintf(temp, "%#X", result);
290 sprintf(temp, "0x%X", (unsigned char)result);
291 return CopyString(temp);
294 public char * PrintUChar(unsigned char result)
297 sprintf(temp, "0x%X", result);
298 return CopyString(temp);
301 public char * PrintFloat(float result)
307 strcpy(temp, "-inf");
311 else if(result.isNan)
314 strcpy(temp, "-nan");
319 sprintf(temp, "%.16ff", result);
320 return CopyString(temp);
323 public char * PrintDouble(double result)
329 strcpy(temp, "-inf");
333 else if(result.isNan)
336 strcpy(temp, "-nan");
341 sprintf(temp, "%.16f", result);
342 return CopyString(temp);
345 ////////////////////////////////////////////////////////////////////////
346 ////////////////////////////////////////////////////////////////////////
348 //public Operand GetOperand(Expression exp);
350 #define GETVALUE(name, t) \
351 public bool GetOp##name(Operand op2, t * value2) \
353 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
354 else if(op2.kind == intType) *value2 = (t) op2.ui; \
355 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
356 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
357 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
358 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
359 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
360 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
361 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
362 else if(op2.kind == shortType) *value2 = (t) op2.us; \
363 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
364 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
365 else if(op2.kind == floatType) *value2 = (t) op2.f; \
366 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
367 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
372 public bool Get##name(Expression exp, t * value2) \
374 Operand op2 = GetOperand(exp); \
375 return GetOp##name(op2, value2); \
378 // To help the deubugger currently not preprocessing...
381 GETVALUE(Int, HELP(int));
382 GETVALUE(UInt, HELP(unsigned int));
383 GETVALUE(Int64, HELP(int64));
384 GETVALUE(UInt64, HELP(uint64));
385 GETVALUE(IntPtr, HELP(intptr));
386 GETVALUE(UIntPtr, HELP(uintptr));
387 GETVALUE(IntSize, HELP(intsize));
388 GETVALUE(UIntSize, HELP(uintsize));
389 GETVALUE(Short, HELP(short));
390 GETVALUE(UShort, HELP(unsigned short));
391 GETVALUE(Char, HELP(char));
392 GETVALUE(UChar, HELP(unsigned char));
393 GETVALUE(Float, HELP(float));
394 GETVALUE(Double, HELP(double));
396 void ComputeExpression(Expression exp);
398 void ComputeClassMembers(Class _class, bool isMember)
400 DataMember member = isMember ? (DataMember) _class : null;
401 Context context = isMember ? null : SetupTemplatesContext(_class);
402 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
403 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
406 int unionMemberOffset = 0;
410 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
411 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
416 member.memberOffset = 0;
417 if(targetBits < sizeof(void *) * 8)
418 member.structAlignment = 0;
420 else if(targetBits < sizeof(void *) * 8)
421 _class.structAlignment = 0;
423 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
424 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
425 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
427 if(!member && _class.destructionWatchOffset)
428 _class.memberOffset += sizeof(OldList);
430 // To avoid reentrancy...
431 //_class.structSize = -1;
434 DataMember dataMember;
435 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
437 if(!dataMember.isProperty)
439 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
441 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
442 /*if(!dataMember.dataType)
443 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
451 DataMember dataMember;
452 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
454 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
456 if(!isMember && _class.type == bitClass && dataMember.dataType)
458 BitMember bitMember = (BitMember) dataMember;
462 ComputeTypeSize(dataMember.dataType);
464 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
465 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
467 _class.memberOffset = bitMember.pos + bitMember.size;
468 for(d = 0; d<bitMember.size; d++)
474 bitMember.mask = mask << bitMember.pos;
476 else if(dataMember.type == normalMember && dataMember.dataType)
481 // Prevent infinite recursion
482 if(dataMember.dataType.kind != classType ||
483 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
484 _class.type != structClass)))
485 ComputeTypeSize(dataMember.dataType);
487 if(dataMember.dataType.bitFieldCount)
489 bitFields += dataMember.dataType.bitFieldCount;
496 int size = (bitFields + 7) / 8;
500 // TESTING THIS PADDING CODE
503 member.structAlignment = Max(member.structAlignment, alignment);
505 if(member.memberOffset % alignment)
506 member.memberOffset += alignment - (member.memberOffset % alignment);
509 dataMember.offset = member.memberOffset;
510 if(member.type == unionMember)
511 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
514 member.memberOffset += size;
519 // TESTING THIS PADDING CODE
522 _class.structAlignment = Max(_class.structAlignment, alignment);
524 if(_class.memberOffset % alignment)
525 _class.memberOffset += alignment - (_class.memberOffset % alignment);
528 dataMember.offset = _class.memberOffset;
529 _class.memberOffset += size;
533 size = dataMember.dataType.size;
534 alignment = dataMember.dataType.alignment;
539 // TESTING THIS PADDING CODE
542 member.structAlignment = Max(member.structAlignment, alignment);
544 if(member.memberOffset % alignment)
545 member.memberOffset += alignment - (member.memberOffset % alignment);
548 dataMember.offset = member.memberOffset;
549 if(member.type == unionMember)
550 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
553 member.memberOffset += size;
558 // TESTING THIS PADDING CODE
561 _class.structAlignment = Max(_class.structAlignment, alignment);
563 if(_class.memberOffset % alignment)
564 _class.memberOffset += alignment - (_class.memberOffset % alignment);
567 dataMember.offset = _class.memberOffset;
568 _class.memberOffset += size;
575 ComputeClassMembers((Class)dataMember, true);
576 alignment = dataMember.structAlignment;
582 if(member.memberOffset % alignment)
583 member.memberOffset += alignment - (member.memberOffset % alignment);
585 member.structAlignment = Max(member.structAlignment, alignment);
587 dataMember.offset = member.memberOffset;
588 if(member.type == unionMember)
589 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
591 member.memberOffset += dataMember.memberOffset;
597 if(_class.memberOffset % alignment)
598 _class.memberOffset += alignment - (_class.memberOffset % alignment);
599 _class.structAlignment = Max(_class.structAlignment, alignment);
601 dataMember.offset = _class.memberOffset;
602 _class.memberOffset += dataMember.memberOffset;
610 int size = (bitFields + 7) / 8;
614 // TESTING THIS PADDING CODE
617 member.structAlignment = Max(member.structAlignment, alignment);
619 if(member.memberOffset % alignment)
620 member.memberOffset += alignment - (member.memberOffset % alignment);
623 if(member.type == unionMember)
624 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
627 member.memberOffset += size;
632 // TESTING THIS PADDING CODE
635 _class.structAlignment = Max(_class.structAlignment, alignment);
637 if(_class.memberOffset % alignment)
638 _class.memberOffset += alignment - (_class.memberOffset % alignment);
640 _class.memberOffset += size;
645 if(member && member.type == unionMember)
647 member.memberOffset = unionMemberOffset;
652 /*if(_class.type == structClass)
653 _class.size = _class.memberOffset;
657 if(_class.type != bitClass)
660 if(_class.structAlignment)
662 if(_class.memberOffset % _class.structAlignment)
663 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
665 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
669 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
671 if(prop.isProperty && prop.isWatchable)
673 prop.watcherOffset = _class.structSize;
674 _class.structSize += sizeof(OldList);
682 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
684 Class deriv = derivative.data;
686 if(deriv.computeSize)
688 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
689 deriv.offset = /*_class.offset + */_class.structSize;
690 deriv.memberOffset = 0;
691 // ----------------------
693 deriv.structSize = deriv.offset;
695 ComputeClassMembers(deriv, false);
703 FinishTemplatesContext(context);
706 public void ComputeModuleClasses(Module module)
711 for(subModule = module.modules.first; subModule; subModule = subModule.next)
712 ComputeModuleClasses(subModule.data);
713 for(_class = module.classes.first; _class; _class = _class.next)
714 ComputeClassMembers(_class, false);
718 public int ComputeTypeSize(Type type)
720 uint size = type ? type.size : 0;
721 if(!size && type && !type.computing)
723 type.computing = true;
726 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
727 case charType: type.alignment = size = sizeof(char); break;
728 case intType: type.alignment = size = sizeof(int); break;
729 case int64Type: type.alignment = size = sizeof(int64); break;
730 case intPtrType: type.alignment = size = targetBits / 8; break;
731 case intSizeType: type.alignment = size = targetBits / 8; break;
732 case longType: type.alignment = size = sizeof(long); break;
733 case shortType: type.alignment = size = sizeof(short); break;
734 case floatType: type.alignment = size = sizeof(float); break;
735 case doubleType: type.alignment = size = sizeof(double); break;
738 Class _class = type._class ? type._class.registered : null;
740 if(_class && _class.type == structClass)
742 // Ensure all members are properly registered
743 ComputeClassMembers(_class, false);
744 type.alignment = _class.structAlignment;
745 size = _class.structSize;
746 if(type.alignment && size % type.alignment)
747 size += type.alignment - (size % type.alignment);
750 else if(_class && (_class.type == unitClass ||
751 _class.type == enumClass ||
752 _class.type == bitClass))
755 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
756 size = type.alignment = ComputeTypeSize(_class.dataType);
759 size = type.alignment = targetBits / 8; // sizeof(Instance *);
762 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
764 if(type.arraySizeExp)
766 ProcessExpressionType(type.arraySizeExp);
767 ComputeExpression(type.arraySizeExp);
768 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
769 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
771 Location oldLoc = yylloc;
772 // bool isConstant = type.arraySizeExp.isConstant;
773 char expression[10240];
774 expression[0] = '\0';
775 type.arraySizeExp.expType = null;
776 yylloc = type.arraySizeExp.loc;
778 PrintExpression(type.arraySizeExp, expression);
779 Compiler_Error($"Array size not constant int (%s)\n", expression);
782 GetInt(type.arraySizeExp, &type.arraySize);
784 else if(type.enumClass)
786 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
788 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
795 // Unimplemented auto size
799 size = ComputeTypeSize(type.type) * type.arraySize;
801 type.alignment = type.type.alignment;
807 for(member = type.members.first; member; member = member.next)
809 uint addSize = ComputeTypeSize(member);
811 member.offset = size;
812 if(member.alignment && size % member.alignment)
813 member.offset += member.alignment - (size % member.alignment);
814 size = member.offset;
816 type.alignment = Max(type.alignment, member.alignment);
819 if(type.alignment && size % type.alignment)
820 size += type.alignment - (size % type.alignment);
826 for(member = type.members.first; member; member = member.next)
828 uint addSize = ComputeTypeSize(member);
830 member.offset = size;
831 if(member.alignment && size % member.alignment)
832 member.offset += member.alignment - (size % member.alignment);
833 size = member.offset;
835 type.alignment = Max(type.alignment, member.alignment);
836 size = Max(size, addSize);
838 if(type.alignment && size % type.alignment)
839 size += type.alignment - (size % type.alignment);
844 TemplateParameter param = type.templateParameter;
845 Type baseType = ProcessTemplateParameterType(param);
848 size = ComputeTypeSize(baseType);
849 type.alignment = baseType.alignment;
852 type.alignment = size = sizeof(uint64);
857 type.alignment = size = sizeof(enum { test });
862 type.alignment = size = targetBits / 8; //sizeof(void *);
867 type.computing = false;
873 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
875 // This function is in need of a major review when implementing private members etc.
876 DataMember topMember = isMember ? (DataMember) _class : null;
881 Context context = isMember ? null : SetupTemplatesContext(_class);
883 *addedPadding = false;
885 if(!isMember && _class.base)
887 maxSize = _class.structSize;
888 //if(_class.base.type != systemClass) // Commented out with new Instance _class
890 // DANGER: Testing this noHeadClass here...
891 if(_class.type == structClass || _class.type == noHeadClass)
892 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
895 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
896 if(maxSize > baseSize)
904 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
906 if(!member.isProperty)
912 if(member.dataTypeString)
914 OldList * specs = MkList(), * decls = MkList();
917 decl = SpecDeclFromString(member.dataTypeString, specs,
918 MkDeclaratorIdentifier(MkIdentifier(member.name)));
919 ListAdd(decls, MkStructDeclarator(decl, null));
920 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
923 member.dataType = ProcessType(specs, decl);
925 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
928 Type type = ProcessType(specs, decl);
929 DeclareType(member.dataType, false, false);
933 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
934 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
935 DeclareStruct(member.dataType._class.string, false);
938 ComputeTypeSize(member.dataType);
939 size = member.dataType.size;
940 alignment = member.dataType.alignment;
944 if(totalSize % alignment)
945 totalSize += alignment - (totalSize % alignment);
954 OldList * specs = MkList(), * list = MkList();
957 AddMembers(list, (Class)member, true, &size, topClass, null);
959 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
960 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
961 alignment = member.structAlignment;
965 if(totalSize % alignment)
966 totalSize += alignment - (totalSize % alignment);
976 if(topMember && topMember.type == unionMember)
977 *retSize = Max(*retSize, totalSize);
979 *retSize += totalSize;
981 else if(totalSize < maxSize && _class.type != systemClass)
984 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
985 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
986 if(totalSize + autoPadding < maxSize)
989 sprintf(sizeString, "%d", maxSize - totalSize);
990 ListAdd(declarations,
991 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
992 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
994 *addedPadding = true;
998 FinishTemplatesContext(context);
999 return topMember ? topMember.memberID : _class.memberID;
1002 static int DeclareMembers(Class _class, bool isMember)
1004 DataMember topMember = isMember ? (DataMember) _class : null;
1007 Context context = isMember ? null : SetupTemplatesContext(_class);
1009 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1010 DeclareMembers(_class.base, false);
1012 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1014 if(!member.isProperty)
1021 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1022 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1023 DeclareStruct(member.dataType._class.string, false);
1025 if(!member.dataType && member.dataTypeString)
1026 member.dataType = ProcessTypeString(member.dataTypeString, false);
1028 DeclareType(member.dataType, false, false);
1034 DeclareMembers((Class)member, true);
1041 FinishTemplatesContext(context);
1043 return topMember ? topMember.memberID : _class.memberID;
1046 void DeclareStruct(char * name, bool skipNoHead)
1048 External external = null;
1049 Symbol classSym = FindClass(name);
1051 if(!inCompiler || !classSym) return;
1053 // We don't need any declaration for bit classes...
1054 if(classSym.registered &&
1055 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1058 /*if(classSym.registered.templateClass)
1059 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1062 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1064 // Add typedef struct
1066 OldList * specifiers, * declarators;
1067 OldList * declarations = null;
1068 char structName[1024];
1069 external = (classSym.registered && classSym.registered.type == structClass) ?
1070 classSym.pointerExternal : classSym.structExternal;
1072 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1073 // Moved this one up because DeclareClass done later will need it
1075 classSym.declaring++;
1077 if(strchr(classSym.string, '<'))
1079 if(classSym.registered.templateClass)
1081 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1082 classSym.declaring--;
1088 DeclareMembers(classSym.registered, false);
1091 FullClassNameCat(structName, name, false);
1094 external = MkExternalDeclaration(null);*/
1098 bool addedPadding = false;
1099 classSym.declaredStructSym = true;
1101 declarations = MkList();
1103 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1105 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1106 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1108 if(!declarations->count || (declarations->count == 1 && addedPadding))
1110 FreeList(declarations, FreeClassDef);
1111 declarations = null;
1114 if(skipNoHead || declarations)
1116 if(external && external.declaration)
1118 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1120 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1123 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1126 if(classSym.structExternal)
1127 ast->Move(classSym.structExternal, curExternal.prev);
1128 ast->Move(classSym.pointerExternal, curExternal.prev);
1130 classSym.id = curExternal.symbol.idCode;
1131 classSym.idCode = curExternal.symbol.idCode;
1132 // external = classSym.pointerExternal;
1133 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1139 external = MkExternalDeclaration(null);
1141 specifiers = MkList();
1142 declarators = MkList();
1143 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1146 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1147 ListAdd(declarators, MkInitDeclarator(d, null));
1149 external.declaration = decl = MkDeclaration(specifiers, declarators);
1150 if(decl.symbol && !decl.symbol.pointerExternal)
1151 decl.symbol.pointerExternal = external;
1153 // For simple classes, keep the declaration as the external to move around
1154 if(classSym.registered && classSym.registered.type == structClass)
1156 char className[1024];
1157 strcpy(className, "__ecereClass_");
1158 FullClassNameCat(className, classSym.string, true);
1159 MangleClassName(className);
1162 DeclareClass(classSym, className);
1164 external.symbol = classSym;
1165 classSym.pointerExternal = external;
1166 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1167 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1171 char className[1024];
1172 strcpy(className, "__ecereClass_");
1173 FullClassNameCat(className, classSym.string, true);
1174 MangleClassName(className);
1176 // TOFIX: TESTING THIS...
1177 classSym.structExternal = external;
1178 DeclareClass(classSym, className);
1179 external.symbol = classSym;
1183 ast->Insert(curExternal ? curExternal.prev : null, external);
1187 classSym.declaring--;
1189 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1191 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1192 // Moved this one up because DeclareClass done later will need it
1195 classSym.declaring++;
1199 if(classSym.registered)
1200 DeclareMembers(classSym.registered, false);
1203 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1206 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1209 if(classSym.structExternal)
1210 ast->Move(classSym.structExternal, curExternal.prev);
1211 ast->Move(classSym.pointerExternal, curExternal.prev);
1213 classSym.id = curExternal.symbol.idCode;
1214 classSym.idCode = curExternal.symbol.idCode;
1215 // external = classSym.pointerExternal;
1216 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1219 classSym.declaring--;
1224 void DeclareProperty(Property prop, char * setName, char * getName)
1226 Symbol symbol = prop.symbol;
1227 char propName[1024];
1229 strcpy(setName, "__ecereProp_");
1230 FullClassNameCat(setName, prop._class.fullName, false);
1231 strcat(setName, "_Set_");
1232 // strcat(setName, prop.name);
1233 FullClassNameCat(setName, prop.name, true);
1235 strcpy(getName, "__ecereProp_");
1236 FullClassNameCat(getName, prop._class.fullName, false);
1237 strcat(getName, "_Get_");
1238 FullClassNameCat(getName, prop.name, true);
1239 // strcat(getName, prop.name);
1241 strcpy(propName, "__ecereProp_");
1242 FullClassNameCat(propName, prop._class.fullName, false);
1243 strcat(propName, "_");
1244 FullClassNameCat(propName, prop.name, true);
1245 // strcat(propName, prop.name);
1247 // To support "char *" property
1248 MangleClassName(getName);
1249 MangleClassName(setName);
1250 MangleClassName(propName);
1252 if(prop._class.type == structClass)
1253 DeclareStruct(prop._class.fullName, false);
1255 if(!symbol || curExternal.symbol.idCode < symbol.id)
1257 bool imported = false;
1258 bool dllImport = false;
1259 if(!symbol || symbol._import)
1264 if(!prop._class.symbol)
1265 prop._class.symbol = FindClass(prop._class.fullName);
1266 classSym = prop._class.symbol;
1267 if(classSym && !classSym._import)
1269 ModuleImport module;
1271 if(prop._class.module)
1272 module = FindModule(prop._class.module);
1274 module = mainModule;
1276 classSym._import = ClassImport
1278 name = CopyString(prop._class.fullName);
1279 isRemote = prop._class.isRemote;
1281 module.classes.Add(classSym._import);
1283 symbol = prop.symbol = Symbol { };
1284 symbol._import = (ClassImport)PropertyImport
1286 name = CopyString(prop.name);
1287 isVirtual = false; //prop.isVirtual;
1288 hasSet = prop.Set ? true : false;
1289 hasGet = prop.Get ? true : false;
1292 classSym._import.properties.Add(symbol._import);
1295 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1296 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1297 prop._class.module.importType != staticImport)
1303 Context context = SetupTemplatesContext(prop._class);
1304 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1305 FinishTemplatesContext(context);
1311 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1314 OldList * specifiers, * declarators;
1319 Declarator typeDecl;
1320 bool simple = false;
1322 specifiers = MkList();
1323 declarators = MkList();
1326 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1327 MkDeclaratorIdentifier(MkIdentifier("this"))));
1329 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1332 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1335 Context context = SetupTemplatesContext(prop._class);
1336 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1337 FinishTemplatesContext(context);
1340 // Make sure the simple _class's type is declared
1341 for(spec = specifiers->first; spec; spec = spec.next)
1343 if(spec.type == nameSpecifier /*SpecifierClass*/)
1345 if((!typeDecl || typeDecl.type == identifierDeclarator))
1347 Symbol classSym = spec.symbol; // FindClass(spec.name);
1348 symbol._class = classSym.registered;
1349 if(classSym.registered && classSym.registered.type == structClass)
1351 DeclareStruct(spec.name, false);
1359 d = PlugDeclarator(typeDecl, d);
1362 ListAdd(params, MkTypeName(specifiers,
1363 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1364 specifiers = MkList();
1367 d = MkDeclaratorFunction(d, params);
1371 specifiers->Insert(null, MkSpecifier(EXTERN));
1372 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1373 specifiers->Insert(null, MkSpecifier(STATIC));
1375 ListAdd(specifiers, MkSpecifier(VOID));
1377 ListAdd(declarators, MkInitDeclarator(d, null));
1379 decl = MkDeclaration(specifiers, declarators);
1381 external = MkExternalDeclaration(decl);
1382 ast->Insert(curExternal.prev, external);
1383 external.symbol = symbol;
1384 symbol.externalGet = external;
1386 ReplaceThisClassSpecifiers(specifiers, prop._class);
1389 FreeDeclarator(typeDecl);
1393 // Move declaration higher...
1394 ast->Move(symbol.externalGet, curExternal.prev);
1401 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1404 OldList * specifiers, * declarators;
1409 Declarator typeDecl;
1411 declarators = MkList();
1414 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1415 if(!prop.conversion || prop._class.type == structClass)
1417 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1418 MkDeclaratorIdentifier(MkIdentifier("this"))));
1421 specifiers = MkList();
1424 Context context = SetupTemplatesContext(prop._class);
1425 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1426 MkDeclaratorIdentifier(MkIdentifier("value")));
1427 FinishTemplatesContext(context);
1429 ListAdd(params, MkTypeName(specifiers, d));
1431 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1434 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1435 d = MkDeclaratorFunction(d, params);
1437 // Make sure the simple _class's type is declared
1438 for(spec = specifiers->first; spec; spec = spec.next)
1440 if(spec.type == nameSpecifier /*SpecifierClass*/)
1442 if((!typeDecl || typeDecl.type == identifierDeclarator))
1444 Symbol classSym = spec.symbol; // FindClass(spec.name);
1445 symbol._class = classSym.registered;
1446 if(classSym.registered && classSym.registered.type == structClass)
1447 DeclareStruct(spec.name, false);
1452 ListAdd(declarators, MkInitDeclarator(d, null));
1454 specifiers = MkList();
1457 specifiers->Insert(null, MkSpecifier(EXTERN));
1458 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1459 specifiers->Insert(null, MkSpecifier(STATIC));
1461 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1462 if(!prop.conversion || prop._class.type == structClass)
1463 ListAdd(specifiers, MkSpecifier(VOID));
1465 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1467 decl = MkDeclaration(specifiers, declarators);
1469 external = MkExternalDeclaration(decl);
1470 ast->Insert(curExternal.prev, external);
1471 external.symbol = symbol;
1472 symbol.externalSet = external;
1474 ReplaceThisClassSpecifiers(specifiers, prop._class);
1478 // Move declaration higher...
1479 ast->Move(symbol.externalSet, curExternal.prev);
1483 // Property (for Watchers)
1484 if(!symbol.externalPtr)
1488 OldList * specifiers = MkList();
1491 specifiers->Insert(null, MkSpecifier(EXTERN));
1493 specifiers->Insert(null, MkSpecifier(STATIC));
1495 ListAdd(specifiers, MkSpecifierName("Property"));
1498 OldList * list = MkList();
1499 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1500 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1504 strcpy(propName, "__ecerePropM_");
1505 FullClassNameCat(propName, prop._class.fullName, false);
1506 strcat(propName, "_");
1507 // strcat(propName, prop.name);
1508 FullClassNameCat(propName, prop.name, true);
1510 MangleClassName(propName);
1512 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1513 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1515 decl = MkDeclaration(specifiers, list);
1518 external = MkExternalDeclaration(decl);
1519 ast->Insert(curExternal.prev, external);
1520 external.symbol = symbol;
1521 symbol.externalPtr = external;
1525 // Move declaration higher...
1526 ast->Move(symbol.externalPtr, curExternal.prev);
1529 symbol.id = curExternal.symbol.idCode;
1533 // ***************** EXPRESSION PROCESSING ***************************
1534 public Type Dereference(Type source)
1539 if(source.kind == pointerType || source.kind == arrayType)
1542 source.type.refCount++;
1544 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1552 // Support dereferencing of no head classes for now...
1553 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1559 Compiler_Error($"cannot dereference type\n");
1564 static Type Reference(Type source)
1580 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1582 Identifier ident = member.identifiers ? member.identifiers->first : null;
1584 DataMember dataMember = null;
1585 Method method = null;
1586 bool freeType = false;
1588 yylloc = member.loc;
1594 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1598 dataMember = *curMember;
1604 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1605 DataMember _subMemberStack[256];
1606 int _subMemberStackPos = 0;
1608 // FILL MEMBER STACK
1610 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1613 dataMember = thisMember;
1614 if(curMember && thisMember.memberAccess == publicAccess)
1616 *curMember = thisMember;
1617 *curClass = thisMember._class;
1618 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1619 *subMemberStackPos = _subMemberStackPos;
1626 method = eClass_FindMethod(_class, ident.string, privateModule);
1627 if(method && method.type == virtualMethod)
1639 if(!dataMember.dataType && dataMember.dataTypeString)
1641 //Context context = SetupTemplatesContext(dataMember._class);
1642 Context context = SetupTemplatesContext(_class);
1643 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1644 FinishTemplatesContext(context);
1646 type = dataMember.dataType;
1650 // This is for destination type...
1651 if(!method.dataType)
1652 ProcessMethodType(method);
1653 //DeclareMethod(method);
1654 // method.dataType = ((Symbol)method.symbol)->type;
1655 type = method.dataType;
1658 if(ident && ident.next)
1660 for(ident = ident.next; ident && type; ident = ident.next)
1662 if(type.kind == classType)
1664 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1666 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1668 type = dataMember.dataType;
1670 else if(type.kind == structType || type.kind == unionType)
1673 for(memberType = type.members.first; memberType; memberType = memberType.next)
1675 if(!strcmp(memberType.name, ident.string))
1685 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1686 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1689 ClassTemplateParameter curParam = null;
1691 for(sClass = _class; sClass; sClass = sClass.base)
1694 if(sClass.templateClass) sClass = sClass.templateClass;
1695 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1697 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1699 for(sClass = sClass.base; sClass; sClass = sClass.base)
1701 if(sClass.templateClass) sClass = sClass.templateClass;
1702 id += sClass.templateParams.count;
1713 ClassTemplateArgument arg = _class.templateArgs[id];
1714 if(arg.dataTypeString)
1717 type = ProcessTypeString(arg.dataTypeString, false);
1719 if(type && _class.templateClass)
1720 type.passAsTemplate = true;
1726 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1727 exp.destType.refCount++;
1733 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1735 Class expClass = type._class.registered;
1736 Class cClass = null;
1741 char templateString[1024];
1742 ClassTemplateParameter param;
1743 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1744 for(cClass = expClass; cClass; cClass = cClass.base)
1747 if(cClass.templateClass) cClass = cClass.templateClass;
1748 for(param = cClass.templateParams.first; param; param = param.next)
1752 ClassTemplateArgument arg;
1753 for(sClass = cClass.base; sClass; sClass = sClass.base)
1755 if(sClass.templateClass) sClass = sClass.templateClass;
1756 id += sClass.templateParams.count;
1758 arg = expClass.templateArgs[id];
1760 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1762 ClassTemplateParameter cParam;
1763 //int p = numParams - sClass.templateParams.count;
1766 if(sClass.templateClass) sClass = sClass.templateClass;
1768 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1770 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1771 p += nextClass.templateParams.count;
1774 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1776 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1778 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1780 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1781 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1793 strcat(argument, arg.name.string);
1794 strcat(argument, " = ");
1800 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1801 char expString[1024];
1802 OldList * specs = MkList();
1803 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1805 char * string = PrintHexUInt64(arg.expression.ui64);
1806 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1809 ProcessExpressionType(exp);
1810 ComputeExpression(exp);
1811 expString[0] = '\0';
1812 PrintExpression(exp, expString);
1813 strcat(argument, expString);
1815 FreeExpression(exp);
1820 strcat(argument, arg.member.name);
1823 case TemplateParameterType::type:
1825 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1826 strcat(argument, arg.dataTypeString);
1832 if(paramCount) strcat(templateString, ", ");
1833 if(lastParam != p - 1)
1835 strcat(templateString, param.name);
1836 strcat(templateString, " = ");
1838 strcat(templateString, argument);
1847 int len = strlen(templateString);
1848 if(templateString[len-1] == '<')
1852 if(templateString[len-1] == '>')
1853 templateString[len++] = ' ';
1854 templateString[len++] = '>';
1856 templateString[len++] = '\0';
1859 Context context = SetupTemplatesContext(_class);
1860 if(freeType) FreeType(type);
1861 type = ProcessTypeString(templateString, false);
1863 FinishTemplatesContext(context);
1867 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1869 ProcessExpressionType(member.initializer.exp);
1870 if(!member.initializer.exp.expType)
1874 char expString[10240];
1875 expString[0] = '\0';
1876 PrintExpression(member.initializer.exp, expString);
1877 ChangeCh(expString, '\n', ' ');
1878 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1881 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1882 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1884 Compiler_Error($"incompatible instance method %s\n", ident.string);
1887 else if(member.initializer)
1890 FreeType(member.exp.destType);
1891 member.exp.destType = type;
1892 if(member.exp.destType)
1893 member.exp.destType.refCount++;
1894 ProcessExpressionType(member.exp);
1897 ProcessInitializer(member.initializer, type);
1899 if(freeType) FreeType(type);
1903 if(_class && _class.type == unitClass)
1905 if(member.initializer)
1908 FreeType(member.exp.destType);
1909 member.exp.destType = MkClassType(_class.fullName);
1910 ProcessExpressionType(member.initializer, type);
1912 Type type = MkClassType(_class.fullName);
1913 ProcessInitializer(member.initializer, type);
1919 if(member.initializer)
1921 //ProcessExpressionType(member.exp);
1922 ProcessInitializer(member.initializer, null);
1928 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1932 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1934 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1938 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1943 void ProcessInstantiationType(Instantiation inst)
1948 MembersInit members;
1949 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1952 /*if(!inst._class.symbol)
1953 inst._class.symbol = FindClass(inst._class.name);*/
1954 classSym = inst._class.symbol;
1955 _class = classSym ? classSym.registered : null;
1957 // DANGER: Patch for mutex not declaring its struct when not needed
1958 if(!_class || _class.type != noHeadClass)
1959 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1961 afterExternal = afterExternal ? afterExternal : curExternal;
1964 ProcessExpressionType(inst.exp);
1966 inst.isConstant = true;
1969 DataMember curMember = null;
1970 Class curClass = null;
1971 DataMember subMemberStack[256];
1972 int subMemberStackPos = 0;
1974 for(members = inst.members->first; members; members = members.next)
1976 switch(members.type)
1978 case methodMembersInit:
1981 static uint instMethodID = 0;
1982 External external = curExternal;
1983 Context context = curContext;
1984 Declarator declarator = members.function.declarator;
1985 Identifier nameID = GetDeclId(declarator);
1986 char * unmangled = nameID ? nameID.string : null;
1988 External createdExternal = null;
1993 //members.function.dontMangle = true;
1994 strcpy(name, "__ecereInstMeth_");
1995 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
1997 strcat(name, nameID.string);
1999 sprintf(number, "_%08d", instMethodID++);
2000 strcat(name, number);
2001 nameID.string = CopyString(name);
2004 // Do modifications here...
2007 Symbol symbol = declarator.symbol;
2008 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2010 if(method && method.type == virtualMethod)
2012 symbol.method = method;
2013 ProcessMethodType(method);
2015 if(!symbol.type.thisClass)
2017 if(method.dataType.thisClass && currentClass &&
2018 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2020 if(!currentClass.symbol)
2021 currentClass.symbol = FindClass(currentClass.fullName);
2022 symbol.type.thisClass = currentClass.symbol;
2027 _class.symbol = FindClass(_class.fullName);
2028 symbol.type.thisClass = _class.symbol;
2031 // TESTING THIS HERE:
2032 DeclareType(symbol.type, true, true);
2037 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2038 unmangled, classSym.string);
2042 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2043 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2047 FreeSpecifier(nameID._class);
2048 nameID._class = null;
2054 Type type = declarator.symbol.type;
2055 External oldExternal = curExternal;
2057 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2058 // *** It was commented out for problems such as
2060 class VirtualDesktop : Window
2062 clientSize = Size { };
2073 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2075 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2078 if(strcmp(declarator.symbol.string, name))
2080 printf("TOCHECK: Look out for this\n");
2081 delete declarator.symbol.string;
2082 declarator.symbol.string = CopyString(name);
2085 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2087 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2088 excludedSymbols->Remove(declarator.symbol);
2089 globalContext.symbols.Add((BTNode)declarator.symbol);
2090 if(strstr(declarator.symbol.string), "::")
2091 globalContext.hasNameSpace = true;
2096 //curExternal = curExternal.prev;
2097 //afterExternal = afterExternal->next;
2099 //ProcessFunction(afterExternal->function);
2101 //curExternal = afterExternal;
2103 External externalDecl;
2104 externalDecl = MkExternalDeclaration(null);
2105 ast->Insert(oldExternal.prev, externalDecl);
2107 // Which function does this process?
2108 if(createdExternal.function)
2110 ProcessFunction(createdExternal.function);
2112 //curExternal = oldExternal;
2115 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2117 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2118 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2120 //externalDecl = MkExternalDeclaration(decl);
2122 //***** ast->Insert(external.prev, externalDecl);
2123 //ast->Insert(curExternal.prev, externalDecl);
2124 externalDecl.declaration = decl;
2125 if(decl.symbol && !decl.symbol.pointerExternal)
2126 decl.symbol.pointerExternal = externalDecl;
2128 // Trying this out...
2129 declarator.symbol.pointerExternal = externalDecl;
2136 curExternal = declarator.symbol.pointerExternal;
2137 ProcessFunction((FunctionDefinition)members.function);
2139 curExternal = external;
2140 curContext = context;
2144 FreeClassFunction(members.function);
2146 // In this pass, turn this into a MemberInitData
2147 exp = QMkExpId(name);
2148 members.type = dataMembersInit;
2149 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2155 case dataMembersInit:
2157 if(members.dataMembers && classSym)
2160 Location oldyyloc = yylloc;
2161 for(member = members.dataMembers->first; member; member = member.next)
2163 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2164 if(member.initializer && !member.initializer.isConstant)
2165 inst.isConstant = false;
2177 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2179 // OPTIMIZATIONS: TESTING THIS...
2182 if(type.kind == functionType)
2187 for(param = type.params.first; param; param = param.next)
2188 DeclareType(param, declarePointers, true);
2190 DeclareType(type.returnType, declarePointers, true);
2192 else if(type.kind == pointerType && declarePointers)
2193 DeclareType(type.type, declarePointers, false);
2194 else if(type.kind == classType)
2196 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2197 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2199 else if(type.kind == structType || type.kind == unionType)
2202 for(member = type.members.first; member; member = member.next)
2203 DeclareType(member, false, false);
2205 else if(type.kind == arrayType)
2206 DeclareType(type.arrayType, declarePointers, false);
2210 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2212 ClassTemplateArgument * arg = null;
2214 ClassTemplateParameter curParam = null;
2216 for(sClass = _class; sClass; sClass = sClass.base)
2219 if(sClass.templateClass) sClass = sClass.templateClass;
2220 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2222 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2224 for(sClass = sClass.base; sClass; sClass = sClass.base)
2226 if(sClass.templateClass) sClass = sClass.templateClass;
2227 id += sClass.templateParams.count;
2237 arg = &_class.templateArgs[id];
2238 if(arg && param.type == type)
2239 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2244 public Context SetupTemplatesContext(Class _class)
2246 Context context = PushContext();
2247 context.templateTypesOnly = true;
2248 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2250 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2251 for(; param; param = param.next)
2253 if(param.type == type && param.identifier)
2255 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2256 curContext.templateTypes.Add((BTNode)type);
2263 for(sClass = _class; sClass; sClass = sClass.base)
2265 ClassTemplateParameter p;
2266 for(p = sClass.templateParams.first; p; p = p.next)
2268 //OldList * specs = MkList();
2269 //Declarator decl = null;
2270 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2273 TemplateParameter param = p.param;
2277 // ADD DATA TYPE HERE...
2278 p.param = param = TemplateParameter
2280 identifier = MkIdentifier(p.name), type = p.type,
2281 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2284 type = TemplatedType { key = (uintptr)p.name, param = param };
2285 curContext.templateTypes.Add((BTNode)type);
2293 public void FinishTemplatesContext(Context context)
2295 PopContext(context);
2296 FreeContext(context);
2300 public void ProcessMethodType(Method method)
2302 if(!method.dataType)
2304 Context context = SetupTemplatesContext(method._class);
2306 method.dataType = ProcessTypeString(method.dataTypeString, false);
2308 FinishTemplatesContext(context);
2310 if(method.type != virtualMethod && method.dataType)
2312 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2314 if(!method._class.symbol)
2315 method._class.symbol = FindClass(method._class.fullName);
2316 method.dataType.thisClass = method._class.symbol;
2320 // Why was this commented out? Working fine without now...
2323 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2324 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2331 char * par = strstr(type, "(");
2332 char * classOp = null;
2337 for(c = par-type-1; c >= 0; c++)
2339 if(type[c] == ':' && type[c+1] == ':')
2341 classOp = type + c - 1;
2342 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2349 else if(!isspace(type[c]))
2356 int typeLen = strlen(type);
2357 memcpy(temp, classOp, classOpLen);
2358 temp[classOpLen] = '\0';
2360 _class = eSystem_FindClass(module, temp);
2363 method.dataTypeString = new char[typeLen - classOpLen + 1];
2364 memcpy(method.dataTypeString, type, classOp - type);
2365 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2368 method.dataTypeString = type;
2374 public void ProcessPropertyType(Property prop)
2378 Context context = SetupTemplatesContext(prop._class);
2379 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2380 FinishTemplatesContext(context);
2384 public void DeclareMethod(Method method, char * name)
2386 Symbol symbol = method.symbol;
2387 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2389 bool imported = false;
2390 bool dllImport = false;
2392 if(!method.dataType)
2393 method.dataType = ProcessTypeString(method.dataTypeString, false);
2395 if(!symbol || symbol._import || method.type == virtualMethod)
2397 if(!symbol || method.type == virtualMethod)
2400 if(!method._class.symbol)
2401 method._class.symbol = FindClass(method._class.fullName);
2402 classSym = method._class.symbol;
2403 if(!classSym._import)
2405 ModuleImport module;
2407 if(method._class.module && method._class.module.name)
2408 module = FindModule(method._class.module);
2410 module = mainModule;
2411 classSym._import = ClassImport
2413 name = CopyString(method._class.fullName);
2414 isRemote = method._class.isRemote;
2416 module.classes.Add(classSym._import);
2420 symbol = method.symbol = Symbol { };
2424 symbol._import = (ClassImport)MethodImport
2426 name = CopyString(method.name);
2427 isVirtual = method.type == virtualMethod;
2429 classSym._import.methods.Add(symbol._import);
2433 // Set the symbol type
2437 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2439 else if(type.thisClass == (void *)-1)
2441 type.thisClass = null;
2444 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2445 symbol.type = method.dataType;
2446 if(symbol.type) symbol.type.refCount++;
2449 if(!method.thisClass || strcmp(method.thisClass, "void"))
2450 symbol.type.params.Insert(null,
2451 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2454 if(!method.dataType.dllExport)
2457 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2463 if(!method.dataType)
2464 method.dataType = ((Symbol)method.symbol).type;
2465 //ProcessMethodType(method);
2468 if(method.type != virtualMethod && method.dataType)
2469 DeclareType(method.dataType, true, true);
2471 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2473 // We need a declaration here :)
2475 OldList * specifiers, * declarators;
2477 Declarator funcDecl;
2480 specifiers = MkList();
2481 declarators = MkList();
2485 ListAdd(specifiers, MkSpecifier(EXTERN));
2486 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2487 ListAdd(specifiers, MkSpecifier(STATIC));
2489 if(method.type == virtualMethod)
2491 ListAdd(specifiers, MkSpecifier(INT));
2492 d = MkDeclaratorIdentifier(MkIdentifier(name));
2496 d = MkDeclaratorIdentifier(MkIdentifier(name));
2499 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2501 Context context = SetupTemplatesContext(method._class);
2502 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2503 FinishTemplatesContext(context);
2505 funcDecl = GetFuncDecl(d);
2509 Specifier spec, next;
2510 for(spec = specifiers->first; spec; spec = next)
2513 if(spec.type == extendedSpecifier)
2515 specifiers->Remove(spec);
2516 FreeSpecifier(spec);
2521 // Add this parameter if not a static method
2522 if(method.dataType && !method.dataType.staticMethod)
2524 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2526 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2527 TypeName thisParam = MkTypeName(MkListOne(
2528 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2529 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2530 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2531 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2533 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2535 TypeName param = funcDecl.function.parameters->first;
2536 funcDecl.function.parameters->Remove(param);
2537 FreeTypeName(param);
2540 if(!funcDecl.function.parameters)
2541 funcDecl.function.parameters = MkList();
2542 funcDecl.function.parameters->Insert(null, thisParam);
2545 // Make sure we don't have empty parameter declarations for static methods...
2547 else if(!funcDecl.function.parameters)
2549 funcDecl.function.parameters = MkList();
2550 funcDecl.function.parameters->Insert(null,
2551 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2555 ProcessDeclarator(d);
2557 ListAdd(declarators, MkInitDeclarator(d, null));
2559 decl = MkDeclaration(specifiers, declarators);
2561 ReplaceThisClassSpecifiers(specifiers, method._class);
2563 // Keep a different symbol for the function definition than the declaration...
2564 if(symbol.pointerExternal)
2566 Symbol functionSymbol { };
2570 *functionSymbol = *symbol;
2571 functionSymbol.string = CopyString(symbol.string);
2572 if(functionSymbol.type)
2573 functionSymbol.type.refCount++;
2576 excludedSymbols->Add(functionSymbol);
2577 symbol.pointerExternal.symbol = functionSymbol;
2579 external = MkExternalDeclaration(decl);
2581 ast->Insert(curExternal ? curExternal.prev : null, external);
2582 external.symbol = symbol;
2583 symbol.pointerExternal = external;
2587 // Move declaration higher...
2588 ast->Move(symbol.pointerExternal, curExternal.prev);
2591 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2595 char * ReplaceThisClass(Class _class)
2597 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2601 ClassTemplateParameter param;
2604 char className[1024];
2605 strcpy(className, _class.fullName);
2606 for(param = _class.templateParams.first; param; param = param.next)
2608 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2610 if(first) strcat(className, "<");
2611 if(!first) strcat(className, ", ");
2612 if(lastParam + 1 != p)
2614 strcat(className, param.name);
2615 strcat(className, " = ");
2617 strcat(className, param.name);
2625 int len = strlen(className);
2626 if(className[len-1] == '>') className[len++] = ' ';
2627 className[len++] = '>';
2628 className[len++] = '\0';
2630 return CopyString(className);
2633 return CopyString(_class.fullName);
2636 Type ReplaceThisClassType(Class _class)
2638 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2642 ClassTemplateParameter param;
2644 char className[1024];
2645 strcpy(className, _class.fullName);
2647 for(param = _class.templateParams.first; param; param = param.next)
2649 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2651 if(first) strcat(className, "<");
2652 if(!first) strcat(className, ", ");
2653 if(lastParam + 1 != p)
2655 strcat(className, param.name);
2656 strcat(className, " = ");
2658 strcat(className, param.name);
2666 int len = strlen(className);
2667 if(className[len-1] == '>') className[len++] = ' ';
2668 className[len++] = '>';
2669 className[len++] = '\0';
2671 return MkClassType(className);
2672 //return ProcessTypeString(className, false);
2676 return MkClassType(_class.fullName);
2677 //return ProcessTypeString(_class.fullName, false);
2681 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2683 if(specs != null && _class)
2686 for(spec = specs.first; spec; spec = spec.next)
2688 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2690 spec.type = nameSpecifier;
2691 spec.name = ReplaceThisClass(_class);
2692 spec.symbol = FindClass(spec.name); //_class.symbol;
2698 // Returns imported or not
2699 bool DeclareFunction(GlobalFunction function, char * name)
2701 Symbol symbol = function.symbol;
2702 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2704 bool imported = false;
2705 bool dllImport = false;
2707 if(!function.dataType)
2709 function.dataType = ProcessTypeString(function.dataTypeString, false);
2710 if(!function.dataType.thisClass)
2711 function.dataType.staticMethod = true;
2718 ModuleImport module = FindModule(function.module);
2719 // WARNING: This is not added anywhere...
2720 symbol = function.symbol = Symbol { };
2724 if(!function.dataType.dllExport)
2726 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2727 module.functions.Add(symbol._import);
2730 // Set the symbol type
2732 symbol.type = ProcessTypeString(function.dataTypeString, false);
2733 if(!symbol.type.thisClass)
2734 symbol.type.staticMethod = true;
2737 imported = symbol._import ? true : false;
2738 if(imported && function.module != privateModule && function.module.importType != staticImport)
2742 DeclareType(function.dataType, true, true);
2746 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2748 // We need a declaration here :)
2750 OldList * specifiers, * declarators;
2752 Declarator funcDecl;
2755 specifiers = MkList();
2756 declarators = MkList();
2759 ListAdd(specifiers, MkSpecifier(EXTERN));
2762 ListAdd(specifiers, MkSpecifier(STATIC));
2765 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2768 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2770 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2771 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2772 if(function.module.importType == staticImport)
2775 for(spec = specifiers->first; spec; spec = spec.next)
2776 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2778 specifiers->Remove(spec);
2779 FreeSpecifier(spec);
2784 funcDecl = GetFuncDecl(d);
2786 // Make sure we don't have empty parameter declarations for static methods...
2787 if(funcDecl && !funcDecl.function.parameters)
2789 funcDecl.function.parameters = MkList();
2790 funcDecl.function.parameters->Insert(null,
2791 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2794 ListAdd(declarators, MkInitDeclarator(d, null));
2797 Context oldCtx = curContext;
2798 curContext = globalContext;
2799 decl = MkDeclaration(specifiers, declarators);
2800 curContext = oldCtx;
2803 // Keep a different symbol for the function definition than the declaration...
2804 if(symbol.pointerExternal)
2806 Symbol functionSymbol { };
2809 *functionSymbol = *symbol;
2810 functionSymbol.string = CopyString(symbol.string);
2811 if(functionSymbol.type)
2812 functionSymbol.type.refCount++;
2815 excludedSymbols->Add(functionSymbol);
2817 symbol.pointerExternal.symbol = functionSymbol;
2819 external = MkExternalDeclaration(decl);
2821 ast->Insert(curExternal.prev, external);
2822 external.symbol = symbol;
2823 symbol.pointerExternal = external;
2827 // Move declaration higher...
2828 ast->Move(symbol.pointerExternal, curExternal.prev);
2832 symbol.id = curExternal.symbol.idCode;
2835 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2838 void DeclareGlobalData(GlobalData data)
2840 Symbol symbol = data.symbol;
2841 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2846 symbol = data.symbol = Symbol { };
2849 data.dataType = ProcessTypeString(data.dataTypeString, false);
2850 DeclareType(data.dataType, true, true);
2853 if(!symbol.pointerExternal)
2855 // We need a declaration here :)
2857 OldList * specifiers, * declarators;
2861 specifiers = MkList();
2862 declarators = MkList();
2864 ListAdd(specifiers, MkSpecifier(EXTERN));
2865 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2866 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2868 ListAdd(declarators, MkInitDeclarator(d, null));
2870 decl = MkDeclaration(specifiers, declarators);
2871 external = MkExternalDeclaration(decl);
2873 ast->Insert(curExternal.prev, external);
2874 external.symbol = symbol;
2875 symbol.pointerExternal = external;
2879 // Move declaration higher...
2880 ast->Move(symbol.pointerExternal, curExternal.prev);
2884 symbol.id = curExternal.symbol.idCode;
2889 class Conversion : struct
2891 Conversion prev, next;
2897 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2901 // Property convert;
2903 if(source.kind == templateType && dest.kind != templateType)
2905 Type type = ProcessTemplateParameterType(source.templateParameter);
2906 if(type) source = type;
2909 if(dest.kind == templateType && source.kind != templateType)
2911 Type type = ProcessTemplateParameterType(dest.templateParameter);
2912 if(type) dest = type;
2915 if(dest.classObjectType == typedObject)
2917 if(source.classObjectType != anyObject)
2921 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2922 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2930 if(source.classObjectType == anyObject)
2932 if(dest.classObjectType == anyObject && source.classObjectType != typedObject)
2936 if((dest.kind == structType && source.kind == structType) ||
2937 (dest.kind == unionType && source.kind == unionType))
2939 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2940 (source.members.first && source.members.first == dest.members.first))
2944 if(dest.kind == ellipsisType && source.kind != voidType)
2947 if(dest.kind == pointerType && dest.type.kind == voidType &&
2948 ((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))
2949 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2951 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2953 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2955 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2956 ((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))
2957 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2959 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2961 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2964 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2966 if(source._class.registered && source._class.registered.type == unitClass)
2968 if(conversions != null)
2970 if(source._class.registered == dest._class.registered)
2975 Class sourceBase, destBase;
2976 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2977 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2978 if(sourceBase == destBase)
2982 // Don't match enum inheriting from other enum if resolving enumeration values
2983 // TESTING: !dest.classObjectType
2984 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2986 (!source._class.registered || source._class.registered.type != enumClass) ||
2987 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2991 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2993 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2994 ((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)
2996 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3004 // JUST ADDED THIS...
3005 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3010 // Just added this for Straight conversion of ColorAlpha => Color
3011 if(source.kind == classType)
3014 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3017 for(convert = _class.conversions.first; convert; convert = convert.next)
3019 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3021 Conversion after = (conversions != null) ? conversions.last : null;
3023 if(!convert.dataType)
3024 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3025 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
3027 if(!conversions && !convert.Get)
3029 else if(conversions != null)
3031 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3032 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3033 (dest.kind != classType || dest._class.registered != _class.base))
3037 Conversion conv { convert = convert, isGet = true };
3038 // conversions.Add(conv);
3039 conversions.Insert(after, conv);
3051 if(dest.kind == classType)
3054 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3057 for(convert = _class.conversions.first; convert; convert = convert.next)
3059 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3061 // Conversion after = (conversions != null) ? conversions.last : null;
3063 if(!convert.dataType)
3064 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3065 // Just added this equality check to prevent recursion.... Make it safer?
3066 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3067 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3069 if(!conversions && !convert.Set)
3071 else if(conversions != null)
3073 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3074 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3075 (source.kind != classType || source._class.registered != _class.base))
3079 // *** Testing this! ***
3080 Conversion conv { convert = convert };
3081 conversions.Add(conv);
3082 //conversions.Insert(after, conv);
3090 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3092 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3093 (source.kind != classType || source._class.registered.type != structClass))
3097 // TESTING THIS... IS THIS OK??
3098 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3100 if(!dest._class.registered.dataType)
3101 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3102 // Only support this for classes...
3103 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3104 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3106 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3115 if(source.kind == classType)
3118 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3121 for(convert = _class.conversions.first; convert; convert = convert.next)
3123 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3125 Conversion after = (conversions != null) ? conversions.last : null;
3127 if(!convert.dataType)
3128 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3129 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3131 if(!conversions && !convert.Get)
3133 else if(conversions != null)
3135 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3136 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3137 (dest.kind != classType || dest._class.registered != _class.base))
3141 Conversion conv { convert = convert, isGet = true };
3143 // conversions.Add(conv);
3144 conversions.Insert(after, conv);
3153 // TESTING THIS... IS THIS OK??
3154 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3156 if(!source._class.registered.dataType)
3157 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3158 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3166 if(source.kind == classType || source.kind == subClassType)
3168 else if(dest.kind == source.kind &&
3169 (dest.kind != structType && dest.kind != unionType &&
3170 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3172 // RECENTLY ADDED THESE
3173 else if(dest.kind == doubleType && source.kind == floatType)
3175 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3177 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3179 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3181 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3183 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3185 else if(source.kind == enumType &&
3186 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3188 else if(dest.kind == enumType &&
3189 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3191 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3192 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3194 Type paramSource, paramDest;
3196 if(dest.kind == methodType)
3197 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3198 if(source.kind == methodType)
3199 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3201 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3202 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3203 if(dest.kind == methodType)
3204 dest = dest.method.dataType;
3205 if(source.kind == methodType)
3206 source = source.method.dataType;
3208 paramSource = source.params.first;
3209 if(paramSource && paramSource.kind == voidType) paramSource = null;
3210 paramDest = dest.params.first;
3211 if(paramDest && paramDest.kind == voidType) paramDest = null;
3214 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3215 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3217 // Source thisClass must be derived from destination thisClass
3218 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3219 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3221 if(paramDest && paramDest.kind == classType)
3222 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3224 Compiler_Error($"method class should not take an object\n");
3227 paramDest = paramDest.next;
3229 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3231 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3235 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3237 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3243 // THIS WAS BACKWARDS:
3244 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3245 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3248 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3250 Compiler_Error($"overriding class expected to be derived from method class\n");
3254 paramSource = paramSource.next;
3260 // Source thisClass must be derived from destination thisClass
3261 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3263 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3269 // THIS WAS BACKWARDS TOO??
3270 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3271 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3274 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3276 //Compiler_Error($"overriding class expected to be derived from method class\n");
3284 // Source return type must be derived from destination return type
3285 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3287 Compiler_Warning($"incompatible return type for function\n");
3293 for(; paramDest; paramDest = paramDest.next)
3297 //Compiler_Warning($"not enough parameters\n");
3298 Compiler_Error($"not enough parameters\n");
3302 Type paramDestType = paramDest;
3303 Type paramSourceType = paramSource;
3304 Type type = paramDestType;
3306 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3307 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3308 paramSource.kind != templateType)
3311 ClassTemplateParameter curParam = null;
3313 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3316 if(sClass.templateClass) sClass = sClass.templateClass;
3317 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3319 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3321 for(sClass = sClass.base; sClass; sClass = sClass.base)
3323 if(sClass.templateClass) sClass = sClass.templateClass;
3324 id += sClass.templateParams.count;
3335 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3336 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3340 // paramDest must be derived from paramSource
3341 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3342 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3346 PrintType(paramDest, type, false, true);
3347 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3349 if(paramDestType != paramDest)
3350 FreeType(paramDestType);
3353 if(paramDestType != paramDest)
3354 FreeType(paramDestType);
3357 paramSource = paramSource.next;
3361 Compiler_Error($"too many parameters\n");
3366 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3370 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3371 (source.kind == arrayType || source.kind == pointerType))
3373 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3380 static void FreeConvert(Conversion convert)
3382 if(convert.resultType)
3383 FreeType(convert.resultType);
3386 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3387 char * string, OldList conversions)
3391 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3393 Class _class = link.data;
3394 if(_class.type == enumClass)
3396 OldList converts { };
3398 type.kind = classType;
3401 _class.symbol = FindClass(_class.fullName);
3402 type._class = _class.symbol;
3404 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3407 Class enumClass = eSystem_FindClass(privateModule, "enum");
3411 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3413 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3414 for(value = e.values.first; value; value = value.next)
3416 if(!strcmp(value.name, string))
3421 FreeExpContents(sourceExp);
3422 FreeType(sourceExp.expType);
3424 sourceExp.isConstant = true;
3425 sourceExp.expType = MkClassType(baseClass.fullName);
3429 sourceExp.type = constantExp;
3430 if(!strcmp(baseClass.dataTypeString, "int"))
3431 sprintf(constant, "%d",(int)value.data);
3433 sprintf(constant, "0x%X",(int)value.data);
3434 sourceExp.constant = CopyString(constant);
3435 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3438 while(converts.first)
3440 Conversion convert = converts.first;
3441 converts.Remove(convert);
3442 conversions.Add(convert);
3451 converts.Free(FreeConvert);
3455 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3456 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3461 public bool ModuleVisibility(Module searchIn, Module searchFor)
3463 SubModule subModule;
3465 if(searchFor == searchIn)
3468 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3470 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3472 if(ModuleVisibility(subModule.module, searchFor))
3479 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3483 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3485 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3487 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3490 for(module = mainModule.application.allModules.first; module; module = module.next)
3492 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3498 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3500 Type source = sourceExp.expType;
3501 Type realDest = dest;
3502 Type backupSourceExpType = null;
3504 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3507 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3509 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3511 Class sourceBase, destBase;
3512 for(sourceBase = source._class.registered;
3513 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3514 sourceBase = sourceBase.base);
3515 for(destBase = dest._class.registered;
3516 destBase && destBase.base && destBase.base.type != systemClass;
3517 destBase = destBase.base);
3518 //if(source._class.registered == dest._class.registered)
3519 if(sourceBase == destBase)
3528 int64 value = MAXINT;
3533 if(sourceExp.type == constantExp)
3536 value = strtoll(sourceExp.constant, null, 0);
3538 value = strtoull(sourceExp.constant, null, 0);
3540 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3543 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3545 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3548 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3549 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3552 source = Type { kind = intType, isSigned = false, refCount = 1 };
3555 if(dest.kind == classType)
3557 Class _class = dest._class ? dest._class.registered : null;
3559 if(_class && _class.type == unitClass)
3561 if(source.kind != classType)
3564 Type tempDest, tempSource;
3566 for(; _class.base.type != systemClass; _class = _class.base);
3568 tempDest = tempType;
3570 tempType.kind = classType;
3572 _class.symbol = FindClass(_class.fullName);
3574 tempType._class = _class.symbol;
3575 tempType.truth = dest.truth;
3577 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3579 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3580 backupSourceExpType = sourceExp.expType;
3581 sourceExp.expType = dest; dest.refCount++;
3582 //sourceExp.expType = MkClassType(_class.fullName);
3590 // Why wasn't there something like this?
3591 if(_class && _class.type == bitClass && source.kind != classType)
3593 if(!dest._class.registered.dataType)
3594 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3595 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3598 FreeType(sourceExp.expType);
3599 source = sourceExp.expType = MkClassType(dest._class.string);
3602 //source.kind = classType;
3603 //source._class = dest._class;
3607 // Adding two enumerations
3609 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3611 if(!source._class.registered.dataType)
3612 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3613 if(!dest._class.registered.dataType)
3614 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3616 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3619 source = sourceExp.expType = MkClassType(dest._class.string);
3622 //source.kind = classType;
3623 //source._class = dest._class;
3627 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3629 OldList * specs = MkList();
3633 ReadString(string, sourceExp.string);
3634 decl = SpecDeclFromString(string, specs, null);
3636 FreeExpContents(sourceExp);
3637 FreeType(sourceExp.expType);
3639 sourceExp.type = classExp;
3640 sourceExp._classExp.specifiers = specs;
3641 sourceExp._classExp.decl = decl;
3642 sourceExp.expType = dest;
3647 if(backupSourceExpType) FreeType(backupSourceExpType);
3651 else if(source.kind == classType)
3653 Class _class = source._class ? source._class.registered : null;
3655 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3658 if(dest.kind != classType)
3660 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3661 if(!source._class.registered.dataType)
3662 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3665 dest = MkClassType(source._class.string);
3666 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3667 // dest = MkClassType(source._class.string);
3671 if(dest.kind != classType)
3674 Type tempDest, tempSource;
3676 if(!source._class.registered.dataType)
3677 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3679 for(; _class.base.type != systemClass; _class = _class.base);
3681 tempSource = tempType;
3682 tempType.kind = classType;
3683 tempType._class = FindClass(_class.fullName);
3684 tempType.truth = source.truth;
3685 tempType.classObjectType = source.classObjectType;
3688 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3690 // PUT THIS BACK TESTING UNITS?
3691 if(conversions.last)
3693 ((Conversion)(conversions.last)).resultType = dest;
3697 FreeType(sourceExp.expType);
3698 sourceExp.expType = MkClassType(_class.fullName);
3699 sourceExp.expType.truth = source.truth;
3700 sourceExp.expType.classObjectType = source.classObjectType;
3702 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3704 if(!sourceExp.destType)
3706 FreeType(sourceExp.destType);
3707 sourceExp.destType = sourceExp.expType;
3708 if(sourceExp.expType)
3709 sourceExp.expType.refCount++;
3712 //source = _class.dataType;
3715 // TOCHECK: TESTING THIS NEW CODE
3716 if(!_class.dataType)
3717 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3719 dest = MkClassType(source._class.string);
3720 dest.truth = source.truth;
3721 dest.classObjectType = source.classObjectType;
3724 source = _class.dataType;
3734 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3744 if(source.kind == classType)
3746 Class _class = source._class.registered;
3747 if(_class.type == unitClass)
3749 if(!_class.dataType)
3750 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3751 source = _class.dataType;
3755 if(dest.kind == classType)
3757 Class _class = dest._class ? dest._class.registered : null;
3758 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3759 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3761 if(_class.type == normalClass || _class.type == noHeadClass)
3763 Expression newExp { };
3764 *newExp = *sourceExp;
3765 if(sourceExp.destType) sourceExp.destType.refCount++;
3766 if(sourceExp.expType) sourceExp.expType.refCount++;
3767 sourceExp.type = castExp;
3768 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3769 sourceExp.cast.exp = newExp;
3770 FreeType(sourceExp.expType);
3771 sourceExp.expType = null;
3772 ProcessExpressionType(sourceExp);
3774 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3777 FreeType(sourceExp.expType);
3778 sourceExp.expType = dest;
3782 if(inCompiler) FreeType(dest);
3784 if(backupSourceExpType) FreeType(backupSourceExpType);
3788 if(!_class.dataType)
3789 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3791 dest = _class.dataType;
3795 // Accept lower precision types for units, since we want to keep the unit type
3796 if(dest.kind == doubleType &&
3797 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3798 source.kind == charType || source.kind == _BoolType))
3800 specs = MkListOne(MkSpecifier(DOUBLE));
3802 else if(dest.kind == floatType &&
3803 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3804 source.kind == _BoolType || source.kind == doubleType))
3806 specs = MkListOne(MkSpecifier(FLOAT));
3808 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3809 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3812 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3813 ListAdd(specs, MkSpecifier(INT64));
3815 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3816 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3819 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3820 ListAdd(specs, MkSpecifier(INT));
3822 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3823 source.kind == floatType || source.kind == doubleType))
3826 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3827 ListAdd(specs, MkSpecifier(SHORT));
3829 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3830 source.kind == floatType || source.kind == doubleType))
3833 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3834 ListAdd(specs, MkSpecifier(CHAR));
3840 if(backupSourceExpType)
3842 // Failed to convert: revert previous exp type
3843 if(sourceExp.expType) FreeType(sourceExp.expType);
3844 sourceExp.expType = backupSourceExpType;
3849 else if(dest.kind == doubleType &&
3850 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3851 source.kind == _BoolType || source.kind == charType))
3853 specs = MkListOne(MkSpecifier(DOUBLE));
3855 else if(dest.kind == floatType &&
3856 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3858 specs = MkListOne(MkSpecifier(FLOAT));
3860 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3861 (value == 1 || value == 0))
3864 ListAdd(specs, MkSpecifier(BOOL));
3866 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3867 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3870 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3871 ListAdd(specs, MkSpecifier(CHAR));
3873 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3874 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3877 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3878 ListAdd(specs, MkSpecifier(SHORT));
3880 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3883 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3884 ListAdd(specs, MkSpecifier(INT));
3886 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3889 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3890 ListAdd(specs, MkSpecifier(INT64));
3892 else if(dest.kind == enumType &&
3893 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3895 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3901 if(backupSourceExpType)
3903 // Failed to convert: revert previous exp type
3904 if(sourceExp.expType) FreeType(sourceExp.expType);
3905 sourceExp.expType = backupSourceExpType;
3912 Expression newExp { };
3913 *newExp = *sourceExp;
3916 if(sourceExp.destType) sourceExp.destType.refCount++;
3917 if(sourceExp.expType) sourceExp.expType.refCount++;
3919 sourceExp.type = castExp;
3920 if(realDest.kind == classType)
3922 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3923 FreeList(specs, FreeSpecifier);
3926 sourceExp.cast.typeName = MkTypeName(specs, null);
3927 if(newExp.type == opExp)
3929 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3932 sourceExp.cast.exp = newExp;
3934 FreeType(sourceExp.expType);
3935 sourceExp.expType = null;
3936 ProcessExpressionType(sourceExp);
3939 FreeList(specs, FreeSpecifier);
3943 if(backupSourceExpType) FreeType(backupSourceExpType);
3949 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3950 if(sourceExp.type == identifierExp)
3952 Identifier id = sourceExp.identifier;
3953 if(dest.kind == classType)
3955 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3957 Class _class = dest._class.registered;
3958 Class enumClass = eSystem_FindClass(privateModule, "enum");
3961 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3964 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3965 for(value = e.values.first; value; value = value.next)
3967 if(!strcmp(value.name, id.string))
3972 FreeExpContents(sourceExp);
3973 FreeType(sourceExp.expType);
3975 sourceExp.isConstant = true;
3976 sourceExp.expType = MkClassType(_class.fullName);
3980 sourceExp.type = constantExp;
3981 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3982 sprintf(constant, "%d", (int) value.data);
3984 sprintf(constant, "0x%X", (int) value.data);
3985 sourceExp.constant = CopyString(constant);
3986 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3995 // Loop through all enum classes
3996 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4003 #define TERTIARY(o, name, m, t, p) \
4004 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4006 exp.type = constantExp; \
4007 exp.string = p(op1.m ? op2.m : op3.m); \
4009 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4013 #define BINARY(o, name, m, t, p) \
4014 static bool name(Expression exp, Operand op1, Operand op2) \
4017 exp.type = constantExp; \
4018 exp.string = p(op1.m o value2); \
4020 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4024 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4025 static bool name(Expression exp, Operand op1, Operand op2) \
4028 exp.type = constantExp; \
4029 exp.string = p(value2 ? (op1.m o value2) : 0); \
4031 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4035 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4036 static bool name(Expression exp, Operand op1, Operand op2) \
4039 exp.type = constantExp; \
4040 exp.string = p(op1.m o value2); \
4042 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4046 #define UNARY(o, name, m, t, p) \
4047 static bool name(Expression exp, Operand op1) \
4049 exp.type = constantExp; \
4050 exp.string = p((t)(o op1.m)); \
4052 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4056 #define OPERATOR_ALL(macro, o, name) \
4057 macro(o, Int##name, i, int, PrintInt) \
4058 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4059 macro(o, Int64##name, i64, int64, PrintInt64) \
4060 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4061 macro(o, Short##name, s, short, PrintShort) \
4062 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4063 macro(o, Char##name, c, char, PrintChar) \
4064 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4065 macro(o, Float##name, f, float, PrintFloat) \
4066 macro(o, Double##name, d, double, PrintDouble)
4068 #define OPERATOR_INTTYPES(macro, o, name) \
4069 macro(o, Int##name, i, int, PrintInt) \
4070 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4071 macro(o, Int64##name, i64, int64, PrintInt64) \
4072 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4073 macro(o, Short##name, s, short, PrintShort) \
4074 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4075 macro(o, Char##name, c, char, PrintChar) \
4076 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4078 #define OPERATOR_REALTYPES(macro, o, name) \
4079 macro(o, Float##name, f, float, PrintFloat) \
4080 macro(o, Double##name, d, double, PrintDouble)
4082 // binary arithmetic
4083 OPERATOR_ALL(BINARY, +, Add)
4084 OPERATOR_ALL(BINARY, -, Sub)
4085 OPERATOR_ALL(BINARY, *, Mul)
4086 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4087 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4088 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4091 OPERATOR_ALL(UNARY, -, Neg)
4093 // unary arithmetic increment and decrement
4094 OPERATOR_ALL(UNARY, ++, Inc)
4095 OPERATOR_ALL(UNARY, --, Dec)
4097 // binary arithmetic assignment
4098 OPERATOR_ALL(BINARY, =, Asign)
4099 OPERATOR_ALL(BINARY, +=, AddAsign)
4100 OPERATOR_ALL(BINARY, -=, SubAsign)
4101 OPERATOR_ALL(BINARY, *=, MulAsign)
4102 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4103 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4104 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4107 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4108 OPERATOR_INTTYPES(BINARY, |, BitOr)
4109 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4110 OPERATOR_INTTYPES(BINARY, <<, LShift)
4111 OPERATOR_INTTYPES(BINARY, >>, RShift)
4114 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4116 // binary bitwise assignment
4117 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4118 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4119 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4120 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4121 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4123 // unary logical negation
4124 OPERATOR_INTTYPES(UNARY, !, Not)
4126 // binary logical equality
4127 OPERATOR_ALL(BINARY, ==, Equ)
4128 OPERATOR_ALL(BINARY, !=, Nqu)
4131 OPERATOR_ALL(BINARY, &&, And)
4132 OPERATOR_ALL(BINARY, ||, Or)
4134 // binary logical relational
4135 OPERATOR_ALL(BINARY, >, Grt)
4136 OPERATOR_ALL(BINARY, <, Sma)
4137 OPERATOR_ALL(BINARY, >=, GrtEqu)
4138 OPERATOR_ALL(BINARY, <=, SmaEqu)
4140 // tertiary condition operator
4141 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4143 //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
4144 #define OPERATOR_TABLE_ALL(name, type) \
4145 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4147 type##Inc, type##Dec, \
4148 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4149 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4151 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4153 type##Equ, type##Nqu, \
4154 type##And, type##Or, \
4155 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4158 #define OPERATOR_TABLE_INTTYPES(name, type) \
4159 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4161 type##Inc, type##Dec, \
4162 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4163 null, null, null, null, null, \
4165 null, null, null, null, null, \
4167 type##Equ, type##Nqu, \
4168 type##And, type##Or, \
4169 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4172 OPERATOR_TABLE_ALL(int, Int)
4173 OPERATOR_TABLE_ALL(uint, UInt)
4174 OPERATOR_TABLE_ALL(int64, Int64)
4175 OPERATOR_TABLE_ALL(uint64, UInt64)
4176 OPERATOR_TABLE_ALL(short, Short)
4177 OPERATOR_TABLE_ALL(ushort, UShort)
4178 OPERATOR_TABLE_INTTYPES(float, Float)
4179 OPERATOR_TABLE_INTTYPES(double, Double)
4180 OPERATOR_TABLE_ALL(char, Char)
4181 OPERATOR_TABLE_ALL(uchar, UChar)
4183 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4184 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4185 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4186 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4187 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4188 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4189 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4190 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4192 public void ReadString(char * output, char * string)
4194 int len = strlen(string);
4196 bool quoted = false, escaped = false;
4197 for(c = 0; c<len; c++)
4199 char ch = string[c];
4204 case 'n': output[d] = '\n'; break;
4205 case 't': output[d] = '\t'; break;
4206 case 'a': output[d] = '\a'; break;
4207 case 'b': output[d] = '\b'; break;
4208 case 'f': output[d] = '\f'; break;
4209 case 'r': output[d] = '\r'; break;
4210 case 'v': output[d] = '\v'; break;
4211 case '\\': output[d] = '\\'; break;
4212 case '\"': output[d] = '\"'; break;
4213 case '\'': output[d] = '\''; break;
4214 default: output[d] = ch;
4235 // String Unescape Copy
4237 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4238 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4239 public int UnescapeString(char * d, char * s, int len)
4243 while(j < len && (ch = s[j]))
4248 switch((ch = s[++j]))
4250 case 'n': d[k] = '\n'; break;
4251 case 't': d[k] = '\t'; break;
4252 case 'a': d[k] = '\a'; break;
4253 case 'b': d[k] = '\b'; break;
4254 case 'f': d[k] = '\f'; break;
4255 case 'r': d[k] = '\r'; break;
4256 case 'v': d[k] = '\v'; break;
4257 case '\\': d[k] = '\\'; break;
4258 case '\"': d[k] = '\"'; break;
4259 case '\'': d[k] = '\''; break;
4260 default: d[k] = '\\'; d[k] = ch;
4272 public char * OffsetEscapedString(char * s, int len, int offset)
4276 while(j < len && k < offset && (ch = s[j]))
4281 return (k == offset) ? s + j : null;
4284 public Operand GetOperand(Expression exp)
4287 Type type = exp.expType;
4290 while(type.kind == classType &&
4291 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4293 if(!type._class.registered.dataType)
4294 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4295 type = type._class.registered.dataType;
4298 if(exp.type == stringExp && op.kind == pointerType)
4300 op.ui64 = (uint64)exp.string;
4301 op.kind = pointerType;
4304 else if(exp.isConstant && exp.type == constantExp)
4306 op.kind = type.kind;
4307 op.type = exp.expType;
4314 if(exp.constant[0] == '\'')
4316 op.c = exp.constant[1];
4319 else if(type.isSigned)
4321 op.c = (char)strtol(exp.constant, null, 0);
4326 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4334 op.s = (short)strtol(exp.constant, null, 0);
4339 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4347 op.i = (int)strtol(exp.constant, null, 0);
4352 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4360 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4365 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4368 op.kind = int64Type;
4373 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4378 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4381 op.kind = int64Type;
4386 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4391 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4394 op.kind = int64Type;
4397 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4398 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4399 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4400 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4402 op.f = (float)strtod(exp.constant, null);
4406 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4407 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4408 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4409 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4411 op.d = (double)strtod(exp.constant, null);
4414 //case classType: For when we have operator overloading...
4415 // Pointer additions
4416 //case functionType:
4420 op.ui64 = _strtoui64(exp.constant, null, 0);
4421 op.kind = pointerType;
4431 static void UnusedFunction()
4434 a.OnGetString(0,0,0);
4437 extern int __ecereVMethodID_class_OnGetString;
4440 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4442 DataMember dataMember;
4443 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4445 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4446 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4450 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4452 void * ptr = inst.data + dataMember.offset + offset;
4453 char * result = null;
4454 exp.loc = member.loc = inst.loc;
4455 ((Identifier)member.identifiers->first).loc = inst.loc;
4457 if(!dataMember.dataType)
4458 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4459 type = dataMember.dataType;
4460 if(type.kind == classType)
4462 Class _class = type._class.registered;
4463 if(_class.type == enumClass)
4465 Class enumClass = eSystem_FindClass(privateModule, "enum");
4468 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4470 for(item = e.values.first; item; item = item.next)
4472 if((int)item.data == *(int *)ptr)
4480 exp.identifier = MkIdentifier(result);
4481 exp.type = identifierExp;
4482 exp.destType = MkClassType(_class.fullName);
4483 ProcessExpressionType(exp);
4487 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4489 if(!_class.dataType)
4490 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4491 type = _class.dataType;
4500 FreeExpContents(exp);
4502 exp.constant = PrintFloat(*(float*)ptr);
4503 exp.type = constantExp;
4508 FreeExpContents(exp);
4510 exp.constant = PrintDouble(*(double*)ptr);
4511 exp.type = constantExp;
4516 FreeExpContents(exp);
4518 exp.constant = PrintInt(*(int*)ptr);
4519 exp.type = constantExp;
4524 FreeExpContents(exp);
4526 exp.constant = PrintInt64(*(int64*)ptr);
4527 exp.type = constantExp;
4532 FreeExpContents(exp);
4533 // TODO: This should probably use proper type
4534 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4535 exp.type = constantExp;
4540 FreeExpContents(exp);
4541 // TODO: This should probably use proper type
4542 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4543 exp.type = constantExp;
4547 Compiler_Error($"Unhandled type populating instance\n");
4550 ListAdd(memberList, member);
4553 if(parentDataMember.type == unionMember)
4558 void PopulateInstance(Instantiation inst)
4560 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4561 Class _class = classSym.registered;
4562 DataMember dataMember;
4563 OldList * memberList = MkList();
4564 // Added this check and ->Add to prevent memory leaks on bad code
4566 inst.members = MkListOne(MkMembersInitList(memberList));
4568 inst.members->Add(MkMembersInitList(memberList));
4569 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4571 if(!dataMember.isProperty)
4573 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4574 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4578 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4580 void * ptr = inst.data + dataMember.offset;
4581 char * result = null;
4583 exp.loc = member.loc = inst.loc;
4584 ((Identifier)member.identifiers->first).loc = inst.loc;
4586 if(!dataMember.dataType)
4587 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4588 type = dataMember.dataType;
4589 if(type.kind == classType)
4591 Class _class = type._class.registered;
4592 if(_class.type == enumClass)
4594 Class enumClass = eSystem_FindClass(privateModule, "enum");
4597 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4599 for(item = e.values.first; item; item = item.next)
4601 if((int)item.data == *(int *)ptr)
4610 exp.identifier = MkIdentifier(result);
4611 exp.type = identifierExp;
4612 exp.destType = MkClassType(_class.fullName);
4613 ProcessExpressionType(exp);
4616 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4618 if(!_class.dataType)
4619 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4620 type = _class.dataType;
4629 exp.constant = PrintFloat(*(float*)ptr);
4630 exp.type = constantExp;
4635 exp.constant = PrintDouble(*(double*)ptr);
4636 exp.type = constantExp;
4641 exp.constant = PrintInt(*(int*)ptr);
4642 exp.type = constantExp;
4647 exp.constant = PrintInt64(*(int64*)ptr);
4648 exp.type = constantExp;
4653 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4654 exp.type = constantExp;
4658 Compiler_Error($"Unhandled type populating instance\n");
4661 ListAdd(memberList, member);
4667 void ComputeInstantiation(Expression exp)
4669 Instantiation inst = exp.instance;
4670 MembersInit members;
4671 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4672 Class _class = classSym ? classSym.registered : null;
4673 DataMember curMember = null;
4674 Class curClass = null;
4675 DataMember subMemberStack[256];
4676 int subMemberStackPos = 0;
4679 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4681 // Don't recompute the instantiation...
4682 // Non Simple classes will have become constants by now
4686 if(_class.type == normalClass || _class.type == noHeadClass)
4688 inst.data = (byte *)eInstance_New(_class);
4689 if(_class.type == normalClass)
4690 ((Instance)inst.data)._refCount++;
4693 inst.data = new0 byte[_class.structSize];
4698 for(members = inst.members->first; members; members = members.next)
4700 switch(members.type)
4702 case dataMembersInit:
4704 if(members.dataMembers)
4707 for(member = members.dataMembers->first; member; member = member.next)
4709 Identifier ident = member.identifiers ? member.identifiers->first : null;
4712 Property prop = null;
4713 DataMember dataMember = null;
4714 Method method = null;
4715 uint dataMemberOffset;
4719 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4722 if(curMember.isProperty)
4723 prop = (Property)curMember;
4726 dataMember = curMember;
4728 // CHANGED THIS HERE
4729 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4731 // 2013/17/29 -- It seems that this was missing here!
4732 if(_class.type == normalClass)
4733 dataMemberOffset += _class.base.structSize;
4734 // dataMemberOffset = dataMember.offset;
4741 prop = eClass_FindProperty(_class, ident.string, privateModule);
4745 if(prop.memberAccess == publicAccess)
4747 curMember = (DataMember)prop;
4748 curClass = prop._class;
4753 DataMember _subMemberStack[256];
4754 int _subMemberStackPos = 0;
4756 // FILL MEMBER STACK
4757 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4762 if(dataMember.memberAccess == publicAccess)
4764 curMember = dataMember;
4765 curClass = dataMember._class;
4766 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4767 subMemberStackPos = _subMemberStackPos;
4773 if(found && member.initializer && member.initializer.type == expInitializer)
4775 Expression value = member.initializer.exp;
4777 bool deepMember = false;
4780 type = prop.dataType;
4784 if(!dataMember.dataType)
4785 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4787 type = dataMember.dataType;
4790 if(ident && ident.next)
4794 // for(; ident && type; ident = ident.next)
4795 for(ident = ident.next; ident && type; ident = ident.next)
4797 if(type.kind == classType)
4799 prop = eClass_FindProperty(type._class.registered,
4800 ident.string, privateModule);
4802 type = prop.dataType;
4805 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4806 ident.string, &dataMemberOffset, privateModule, null, null);
4808 type = dataMember.dataType;
4811 else if(type.kind == structType || type.kind == unionType)
4814 for(memberType = type.members.first; memberType; memberType = memberType.next)
4816 if(!strcmp(memberType.name, ident.string))
4827 FreeType(value.destType);
4828 value.destType = type;
4829 if(type) type.refCount++;
4830 ComputeExpression(value);
4832 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4834 if(type.kind == classType)
4836 Class _class = type._class.registered;
4837 if(_class.type == bitClass || _class.type == unitClass ||
4838 _class.type == enumClass)
4840 if(!_class.dataType)
4841 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4842 type = _class.dataType;
4848 void * ptr = inst.data + dataMemberOffset;
4850 if(value.type == constantExp)
4856 GetInt(value, (int*)ptr);
4861 GetInt64(value, (int64*)ptr);
4866 GetIntPtr(value, (intptr*)ptr);
4871 GetIntSize(value, (intsize*)ptr);
4876 GetFloat(value, (float*)ptr);
4881 GetDouble(value, (double *)ptr);
4886 else if(value.type == instanceExp)
4888 if(type.kind == classType)
4890 Class _class = type._class.registered;
4891 if(_class.type == structClass)
4893 ComputeTypeSize(type);
4894 if(value.instance.data)
4895 memcpy(ptr, value.instance.data, type.size);
4902 if(value.type == instanceExp && value.instance.data)
4904 if(type.kind == classType)
4906 Class _class = type._class.registered;
4907 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4909 void (*Set)(void *, void *) = (void *)prop.Set;
4910 Set(inst.data, value.instance.data);
4911 PopulateInstance(inst);
4915 else if(value.type == constantExp)
4921 void (*Set)(void *, double) = (void *)prop.Set;
4922 Set(inst.data, strtod(value.constant, null) );
4927 void (*Set)(void *, float) = (void *)prop.Set;
4928 Set(inst.data, (float)(strtod(value.constant, null)));
4933 void (*Set)(void *, int) = (void *)prop.Set;
4934 Set(inst.data, (int)strtol(value.constant, null, 0));
4939 void (*Set)(void *, int64) = (void *)prop.Set;
4940 Set(inst.data, _strtoi64(value.constant, null, 0));
4945 void (*Set)(void *, intptr) = (void *)prop.Set;
4946 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4951 void (*Set)(void *, intsize) = (void *)prop.Set;
4952 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4957 else if(value.type == stringExp)
4960 ReadString(temp, value.string);
4961 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4965 else if(!deepMember && type && _class.type == unitClass)
4969 // Only support converting units to units for now...
4970 if(value.type == constantExp)
4972 if(type.kind == classType)
4974 Class _class = type._class.registered;
4975 if(_class.type == unitClass)
4977 if(!_class.dataType)
4978 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4979 type = _class.dataType;
4982 // TODO: Assuming same base type for units...
4988 float (*Set)(float) = (void *)prop.Set;
4989 GetFloat(member.initializer.exp, &fValue);
4990 exp.constant = PrintFloat(Set(fValue));
4991 exp.type = constantExp;
4997 double (*Set)(double) = (void *)prop.Set;
4998 GetDouble(member.initializer.exp, &dValue);
4999 exp.constant = PrintDouble(Set(dValue));
5000 exp.type = constantExp;
5007 else if(!deepMember && type && _class.type == bitClass)
5011 if(value.type == instanceExp && value.instance.data)
5013 unsigned int (*Set)(void *) = (void *)prop.Set;
5014 bits = Set(value.instance.data);
5016 else if(value.type == constantExp)
5022 BitMember bitMember = (BitMember) dataMember;
5025 bits = (bits & ~bitMember.mask);
5026 if(!bitMember.dataType)
5027 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5028 type = bitMember.dataType;
5029 if(type.kind == classType && type._class && type._class.registered)
5031 if(!type._class.registered.dataType)
5032 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5033 type = type._class.registered.dataType;
5038 case charType: { byte v; type.isSigned ? GetChar(value, &v) : GetUChar(value, &v); part = (uint64)v; break; }
5039 case shortType: { uint16 v; type.isSigned ? GetShort(value, &v) : GetUShort(value, &v); part = (uint64)v; break; }
5041 case longType: { uint v; type.isSigned ? GetInt(value, &v) : GetUInt(value, &v); part = (uint64)v; break; }
5042 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, &v) : GetUInt64(value, &v); part = (uint64)v; break; }
5043 case intPtrType: { intptr v; type.isSigned ? GetIntPtr(value, &v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5044 case intSizeType: { intsize v; type.isSigned ? GetIntSize(value, &v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5046 bits += part << bitMember.pos;
5052 if(_class && _class.type == unitClass)
5054 ComputeExpression(member.initializer.exp);
5055 exp.constant = member.initializer.exp.constant;
5056 exp.type = constantExp;
5058 member.initializer.exp.constant = null;
5068 if(_class && _class.type == bitClass)
5070 exp.constant = PrintHexUInt(bits);
5071 exp.type = constantExp;
5073 if(exp.type != instanceExp)
5079 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5081 bool result = false;
5085 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5086 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5090 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5091 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5094 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5095 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5096 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5099 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5100 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5101 result = GetOpFloat(op, &op.f);
5104 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5105 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5106 result = GetOpDouble(op, &op.d);
5109 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5110 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5111 result = GetOpUIntPtr(op, &op.ui64);
5114 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5115 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5116 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5119 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5120 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5123 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5124 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5130 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5132 if(exp.op.op == SIZEOF)
5134 FreeExpContents(exp);
5135 exp.type = constantExp;
5136 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5147 // Provide default unary +
5148 Expression exp2 = exp.op.exp2;
5150 FreeExpContents(exp);
5151 FreeType(exp.expType);
5152 FreeType(exp.destType);
5158 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5160 // unary arithmetic increment and decrement
5161 //OPERATOR_ALL(UNARY, ++, Inc)
5162 //OPERATOR_ALL(UNARY, --, Dec)
5165 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5167 // unary logical negation
5169 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5175 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5177 if(Promote(op2, op1.kind, op1.type.isSigned))
5178 op2.kind = op1.kind, op2.ops = op1.ops;
5179 else if(Promote(op1, op2.kind, op2.type.isSigned))
5180 op1.kind = op2.kind, op1.ops = op2.ops;
5184 // binary arithmetic
5186 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5189 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5192 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5195 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5198 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5200 // binary arithmetic assignment
5201 //OPERATOR_ALL(BINARY, =, Asign)
5202 //OPERATOR_ALL(BINARY, +=, AddAsign)
5203 //OPERATOR_ALL(BINARY, -=, SubAsign)
5204 //OPERATOR_ALL(BINARY, *=, MulAsign)
5205 //OPERATOR_ALL(BINARY, /=, DivAsign)
5206 //OPERATOR_ALL(BINARY, %=, ModAsign)
5211 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5215 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5218 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5221 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5224 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5226 // binary bitwise assignment
5227 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5228 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5229 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5230 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5231 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5232 // binary logical equality
5234 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5237 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5241 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5244 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5246 // binary logical relational
5248 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5251 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5254 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5257 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5264 void ComputeExpression(Expression exp)
5266 char expString[10240];
5267 expString[0] = '\0';
5269 PrintExpression(exp, expString);
5276 ComputeInstantiation(exp);
5285 Expression exp1, exp2 = null;
5289 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5292 Expression e = exp.op.exp2;
5294 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5296 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5298 if(e.type == extensionCompoundExp)
5299 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5304 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5306 if(e.type == stringExp && e.string)
5308 char * string = e.string;
5309 int len = strlen(string);
5310 char * tmp = new char[len-2+1];
5311 len = UnescapeString(tmp, string + 1, len - 2);
5313 FreeExpContents(exp);
5314 exp.type = constantExp;
5315 exp.constant = PrintUInt(len + 1);
5319 Type type = e.expType;
5321 FreeExpContents(exp);
5322 exp.type = constantExp;
5323 exp.constant = PrintUInt(ComputeTypeSize(type));
5329 ComputeExpression(exp.op.exp2);
5333 ComputeExpression(exp.op.exp1);
5336 op1 = GetOperand(exp1);
5337 if(op1.type) op1.type.refCount++;
5340 op2 = GetOperand(exp2);
5341 if(op2.type) op2.type.refCount++;
5347 op1 = GetOperand(exp1);
5348 if(op1.type) op1.type.refCount++;
5351 CallOperator(exp, exp1, exp2, op1, op2);
5358 if(exp.op.exp1 && exp.op.exp2)
5363 FreeExpContents(exp);
5364 op1.ops.BitAnd(exp, op1, op2);
5373 FreeExpContents(exp);
5374 op1.ops.Mul(exp, op1, op2);
5383 FreeExpContents(exp);
5384 op1.ops.Add(exp, op1, op2);
5389 // Provide default unary +
5390 Expression exp2 = exp.op.exp2;
5392 FreeExpContents(exp);
5393 FreeType(exp.expType);
5394 FreeType(exp.destType);
5405 FreeExpContents(exp);
5406 op1.ops.Sub(exp, op1, op2);
5413 FreeExpContents(exp);
5414 op1.ops.Neg(exp, op1);
5421 FreeExpContents(exp);
5422 op1.ops.BitNot(exp, op1);
5428 FreeExpContents(exp);
5429 op1.ops.Not(exp, op1);
5432 // Binary only operators
5436 FreeExpContents(exp);
5437 op1.ops.Div(exp, op1, op2);
5443 FreeExpContents(exp);
5444 op1.ops.Mod(exp, op1, op2);
5456 FreeExpContents(exp);
5457 op1.ops.Sma(exp, op1, op2);
5466 FreeExpContents(exp);
5467 op1.ops.Grt(exp, op1, op2);
5476 FreeExpContents(exp);
5477 op1.ops.SmaEqu(exp, op1, op2);
5486 FreeExpContents(exp);
5487 op1.ops.GrtEqu(exp, op1, op2);
5496 FreeExpContents(exp);
5497 op1.ops.Equ(exp, op1, op2);
5506 FreeExpContents(exp);
5507 op1.ops.Nqu(exp, op1, op2);
5514 FreeExpContents(exp);
5515 op1.ops.BitOr(exp, op1, op2);
5521 FreeExpContents(exp);
5522 op1.ops.BitXor(exp, op1, op2);
5530 FreeExpContents(exp);
5531 exp.type = constantExp;
5532 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5536 if(op1.type) FreeType(op1.type);
5537 if(op2.type) FreeType(op2.type);
5541 case extensionExpressionExp:
5544 for(e = exp.list->first; e; e = n)
5549 OldList * list = exp.list;
5550 ComputeExpression(e);
5551 //FreeExpContents(exp);
5552 FreeType(exp.expType);
5553 FreeType(exp.destType);
5570 exp.isConstant = true;
5572 ComputeExpression(exp.index.exp);
5573 if(!exp.index.exp.isConstant)
5574 exp.isConstant = false;
5576 for(e = exp.index.index->first; e; e = e.next)
5578 ComputeExpression(e);
5581 // Check if this type is int
5584 exp.isConstant = false;
5586 exp.expType = Dereference(exp.index.exp.expType);
5592 Expression memberExp = exp.member.exp;
5593 Identifier memberID = exp.member.member;
5596 ComputeExpression(exp.member.exp);
5597 type = exp.member.exp.expType;
5600 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);
5601 Property prop = null;
5602 DataMember member = null;
5603 Class convertTo = null;
5604 if(type.kind == subClassType && exp.member.exp.type == classExp)
5605 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5612 PrintTypeNoConst(type, string, false, true);
5613 classSym = FindClass(string);
5614 _class = classSym ? classSym.registered : null;
5617 if(exp.member.member)
5619 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5621 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5623 if(!prop && !member && _class && exp.member.member)
5625 Symbol classSym = FindClass(exp.member.member.string);
5627 _class = classSym ? classSym.registered : null;
5628 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5635 Type type = prop.dataType;
5636 // TODO: Assuming same base type for units...
5637 if(_class.type == unitClass)
5639 if(type.kind == classType)
5641 Class _class = type._class.registered;
5642 if(_class.type == unitClass)
5644 if(!_class.dataType)
5645 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5646 type = _class.dataType;
5654 float (*Get)(float) = (void *)prop.Get;
5655 GetFloat(exp.member.exp, &value);
5656 exp.constant = PrintFloat(Get ? Get(value) : value);
5657 exp.type = constantExp;
5663 double (*Get)(double);
5664 GetDouble(exp.member.exp, &value);
5667 Get = (void *)prop.Set;
5669 Get = (void *)prop.Get;
5670 exp.constant = PrintDouble(Get ? Get(value) : value);
5671 exp.type = constantExp;
5680 Expression value = exp.member.exp;
5683 ProcessPropertyType(prop);
5685 type = prop.dataType;
5688 // printf("Investigate this\n");
5690 else if(_class.type == structClass)
5696 Class propertyClass = type._class.registered;
5697 if(propertyClass.type == structClass && value.type == instanceExp)
5699 void (*Set)(void *, void *) = (void *)prop.Set;
5700 exp.instance = Instantiation { };
5701 exp.instance.data = new0 byte[_class.structSize];
5702 exp.instance._class = MkSpecifierName(_class.fullName);
5703 exp.instance.loc = exp.loc;
5704 exp.type = instanceExp;
5705 Set(exp.instance.data, value.instance.data);
5706 PopulateInstance(exp.instance);
5713 void (*Set)(void *, int) = (void *)prop.Set;
5715 exp.instance = Instantiation { };
5716 exp.instance.data = new0 byte[_class.structSize];
5717 exp.instance._class = MkSpecifierName(_class.fullName);
5718 exp.instance.loc = exp.loc;
5719 exp.type = instanceExp;
5721 GetInt(value, &intValue);
5723 Set(exp.instance.data, intValue);
5724 PopulateInstance(exp.instance);
5730 void (*Set)(void *, int64) = (void *)prop.Set;
5732 exp.instance = Instantiation { };
5733 exp.instance.data = new0 byte[_class.structSize];
5734 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5735 exp.instance.loc = exp.loc;
5736 exp.type = instanceExp;
5738 GetInt64(value, &intValue);
5740 Set(exp.instance.data, intValue);
5741 PopulateInstance(exp.instance);
5748 void (*Set)(void *, intptr) = (void *)prop.Set;
5750 exp.instance = Instantiation { };
5751 exp.instance.data = new0 byte[_class.structSize];
5752 exp.instance._class = MkSpecifierName(_class.fullName);
5753 exp.instance.loc = exp.loc;
5754 exp.type = instanceExp;
5756 GetIntPtr(value, &intValue);
5758 Set(exp.instance.data, intValue);
5759 PopulateInstance(exp.instance);
5766 void (*Set)(void *, intsize) = (void *)prop.Set;
5768 exp.instance = Instantiation { };
5769 exp.instance.data = new0 byte[_class.structSize];
5770 exp.instance._class = MkSpecifierName(_class.fullName);
5771 exp.instance.loc = exp.loc;
5772 exp.type = instanceExp;
5774 GetIntSize(value, &intValue);
5776 Set(exp.instance.data, intValue);
5777 PopulateInstance(exp.instance);
5783 void (*Set)(void *, float) = (void *)prop.Set;
5785 exp.instance = Instantiation { };
5786 exp.instance.data = new0 byte[_class.structSize];
5787 exp.instance._class = MkSpecifierName(_class.fullName);
5788 exp.instance.loc = exp.loc;
5789 exp.type = instanceExp;
5791 GetFloat(value, &floatValue);
5793 Set(exp.instance.data, floatValue);
5794 PopulateInstance(exp.instance);
5800 void (*Set)(void *, double) = (void *)prop.Set;
5802 exp.instance = Instantiation { };
5803 exp.instance.data = new0 byte[_class.structSize];
5804 exp.instance._class = MkSpecifierName(_class.fullName);
5805 exp.instance.loc = exp.loc;
5806 exp.type = instanceExp;
5808 GetDouble(value, &doubleValue);
5810 Set(exp.instance.data, doubleValue);
5811 PopulateInstance(exp.instance);
5816 else if(_class.type == bitClass)
5822 Class propertyClass = type._class.registered;
5823 if(propertyClass.type == structClass && value.instance.data)
5825 unsigned int (*Set)(void *) = (void *)prop.Set;
5826 unsigned int bits = Set(value.instance.data);
5827 exp.constant = PrintHexUInt(bits);
5828 exp.type = constantExp;
5831 else if(_class.type == bitClass)
5834 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5837 GetUInt(exp.member.exp, &value);
5839 exp.constant = PrintHexUInt(bits);
5840 exp.type = constantExp;
5848 if(_class.type == bitClass)
5851 GetUInt(exp.member.exp, &value);
5857 Class _class = type._class.registered;
5858 if(_class.type == structClass)
5860 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5862 exp.instance = Instantiation { };
5863 exp.instance.data = new0 byte[_class.structSize];
5864 exp.instance._class = MkSpecifierName(_class.fullName);
5865 exp.instance.loc = exp.loc;
5866 //exp.instance.fullSet = true;
5867 exp.type = instanceExp;
5868 Get(value, exp.instance.data);
5869 PopulateInstance(exp.instance);
5871 else if(_class.type == bitClass)
5873 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5874 uint64 bits = Get(value);
5875 exp.constant = PrintHexUInt64(bits);
5876 exp.type = constantExp;
5882 else if(_class.type == structClass)
5884 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5889 Class _class = type._class.registered;
5890 if(_class.type == structClass && value)
5892 void (*Get)(void *, void *) = (void *)prop.Get;
5894 exp.instance = Instantiation { };
5895 exp.instance.data = new0 byte[_class.structSize];
5896 exp.instance._class = MkSpecifierName(_class.fullName);
5897 exp.instance.loc = exp.loc;
5898 //exp.instance.fullSet = true;
5899 exp.type = instanceExp;
5900 Get(value, exp.instance.data);
5901 PopulateInstance(exp.instance);
5909 char * value = exp.member.exp.instance.data;
5914 Class _class = type._class.registered;
5915 if(_class.type == normalClass)
5917 void *(*Get)(void *) = (void *)prop.Get;
5919 exp.instance = Instantiation { };
5920 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5921 exp.type = instanceExp;
5922 exp.instance.data = Get(value, exp.instance.data);
5934 exp.isConstant = false;
5942 if(exp.type != ExpressionType::memberExp)
5944 FreeExpression(memberExp);
5945 FreeIdentifier(memberID);
5951 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5952 FreeExpContents(exp);
5953 exp.constant = PrintUInt(ComputeTypeSize(type));
5954 exp.type = constantExp;
5960 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5961 if(classSym && classSym.registered)
5963 if(classSym.registered.fixed)
5965 FreeSpecifier(exp._class);
5966 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5967 exp.type = constantExp;
5971 char className[1024];
5972 strcpy(className, "__ecereClass_");
5973 FullClassNameCat(className, classSym.string, true);
5974 MangleClassName(className);
5976 DeclareClass(classSym, className);
5978 FreeExpContents(exp);
5979 exp.type = pointerExp;
5980 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5981 exp.member.member = MkIdentifier("structSize");
5991 if(exp.type == castExp)
5994 ComputeExpression(exp.cast.exp);
5997 if(e && exp.expType)
6000 type = exp.destType;
6003 if(type.kind == classType)
6005 Class _class = type._class.registered;
6006 if(_class && (_class.type == unitClass || _class.type == bitClass))
6008 if(!_class.dataType)
6009 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6010 type = _class.dataType;
6021 if(GetChar(e, &value))
6023 FreeExpContents(exp);
6024 exp.constant = PrintChar(value);
6025 exp.type = constantExp;
6030 unsigned char value = 0;
6031 if(GetUChar(e, &value))
6033 FreeExpContents(exp);
6034 exp.constant = PrintUChar(value);
6035 exp.type = constantExp;
6043 if(GetShort(e, &value))
6045 FreeExpContents(exp);
6046 exp.constant = PrintShort(value);
6047 exp.type = constantExp;
6052 unsigned short value = 0;
6053 if(GetUShort(e, &value))
6055 FreeExpContents(exp);
6056 exp.constant = PrintUShort(value);
6057 exp.type = constantExp;
6065 if(GetInt(e, &value))
6067 FreeExpContents(exp);
6068 exp.constant = PrintInt(value);
6069 exp.type = constantExp;
6074 unsigned int value = 0;
6075 if(GetUInt(e, &value))
6077 FreeExpContents(exp);
6078 exp.constant = PrintUInt(value);
6079 exp.type = constantExp;
6087 if(GetInt64(e, &value))
6089 FreeExpContents(exp);
6090 exp.constant = PrintInt64(value);
6091 exp.type = constantExp;
6097 if(GetUInt64(e, &value))
6099 FreeExpContents(exp);
6100 exp.constant = PrintUInt64(value);
6101 exp.type = constantExp;
6109 if(GetIntPtr(e, &value))
6111 FreeExpContents(exp);
6112 exp.constant = PrintInt64((int64)value);
6113 exp.type = constantExp;
6119 if(GetUIntPtr(e, &value))
6121 FreeExpContents(exp);
6122 exp.constant = PrintUInt64((uint64)value);
6123 exp.type = constantExp;
6131 if(GetIntSize(e, &value))
6133 FreeExpContents(exp);
6134 exp.constant = PrintInt64((int64)value);
6135 exp.type = constantExp;
6141 if(GetUIntSize(e, &value))
6143 FreeExpContents(exp);
6144 exp.constant = PrintUInt64((uint64)value);
6145 exp.type = constantExp;
6152 if(GetFloat(e, &value))
6154 FreeExpContents(exp);
6155 exp.constant = PrintFloat(value);
6156 exp.type = constantExp;
6163 if(GetDouble(e, &value))
6165 FreeExpContents(exp);
6166 exp.constant = PrintDouble(value);
6167 exp.type = constantExp;
6182 // Caring only about last expression for now...
6183 ComputeExpression(exp.cond.exp->last);
6184 if(exp.cond.elseExp)
6185 ComputeExpression(exp.cond.elseExp);
6187 ComputeExpression(exp.cond.cond);
6189 op1 = GetOperand(exp.cond.cond);
6190 if(op1.type) op1.type.refCount++;
6191 op2 = GetOperand(exp.cond.exp->last);
6192 if(op2.type) op2.type.refCount++;
6193 op3 = GetOperand(exp.cond.elseExp);
6194 if(op3.type) op3.type.refCount++;
6196 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6197 if(op1.type) FreeType(op1.type);
6198 if(op2.type) FreeType(op2.type);
6199 if(op3.type) FreeType(op3.type);
6205 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
6210 OldList converts { };
6213 if(destType.kind == voidType)
6216 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
6220 // for(convert = converts.last; convert; convert = convert.prev)
6221 for(convert = converts.first; convert; convert = convert.next)
6223 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6226 Expression newExp { };
6227 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6229 // TODO: Check this...
6231 newExp.destType = null;
6236 exp.type = memberExp;
6237 exp.addedThis = true;
6238 exp.member.exp = newExp;
6239 FreeType(exp.member.exp.expType);
6241 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6242 exp.member.exp.expType.classObjectType = objectType;
6243 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6244 exp.member.memberType = propertyMember;
6245 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6246 // TESTING THIS... for (int)degrees
6247 exp.needCast = true;
6248 if(exp.expType) exp.expType.refCount++;
6249 ApplyAnyObjectLogic(exp.member.exp);
6254 /*if(exp.isConstant)
6256 // Color { ColorRGB = [exp] };
6257 exp.type = instanceExp;
6258 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6259 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6260 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6264 // If not constant, don't turn it yet into an instantiation
6265 // (Go through the deep members system first)
6266 exp.type = memberExp;
6267 exp.addedThis = true;
6268 exp.member.exp = newExp;
6270 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6271 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6272 newExp.expType._class.registered.type == noHeadClass)
6274 newExp.byReference = true;
6277 FreeType(exp.member.exp.expType);
6278 /*exp.member.exp.expType = convert.convert.dataType;
6279 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6280 exp.member.exp.expType = null;
6281 if(convert.convert.dataType)
6283 exp.member.exp.expType = { };
6284 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6285 exp.member.exp.expType.refCount = 1;
6286 exp.member.exp.expType.classObjectType = objectType;
6287 ApplyAnyObjectLogic(exp.member.exp);
6290 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6291 exp.member.memberType = reverseConversionMember;
6292 exp.expType = convert.resultType ? convert.resultType :
6293 MkClassType(convert.convert._class.fullName);
6294 exp.needCast = true;
6295 if(convert.resultType) convert.resultType.refCount++;
6301 FreeType(exp.expType);
6304 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6305 exp.needCast = true;
6306 if(exp.expType) exp.expType.refCount++;
6310 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6311 exp.needCast = true;
6312 if(convert.resultType)
6313 convert.resultType.refCount++;
6317 if(exp.isConstant && inCompiler)
6318 ComputeExpression(exp);
6320 converts.Free(FreeConvert);
6323 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6325 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6327 if(!result && exp.expType && exp.destType)
6329 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6330 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6331 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6332 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6336 // if(result) CheckTemplateTypes(exp);
6340 void CheckTemplateTypes(Expression exp)
6342 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6344 Expression newExp { };
6348 if(exp.destType) exp.destType.refCount++;
6349 if(exp.expType) exp.expType.refCount++;
6353 switch(exp.expType.kind)
6356 if(exp.destType.classObjectType)
6358 // We need to pass the address, just pass it along (Undo what was done above)
6359 if(exp.destType) exp.destType.refCount--;
6360 if(exp.expType) exp.expType.refCount--;
6365 // If we're looking for value:
6366 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6368 OldList * unionDefs = MkList();
6369 OldList * statements = MkList();
6370 context = PushContext();
6371 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6372 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6373 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6374 exp.type = extensionCompoundExp;
6375 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6376 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6377 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6378 exp.compound.compound.context = context;
6379 PopContext(context);
6384 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6385 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6389 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6391 Expression newExp { };
6395 if(exp.destType) exp.destType.refCount++;
6396 if(exp.expType) exp.expType.refCount++;
6400 switch(exp.expType.kind)
6403 if(exp.destType.classObjectType)
6405 // We need to pass the address, just pass it along (Undo what was done above)
6406 if(exp.destType) exp.destType.refCount--;
6407 if(exp.expType) exp.expType.refCount--;
6412 // If we're looking for value:
6413 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6415 OldList * unionDefs = MkList();
6416 OldList * statements = MkList();
6417 context = PushContext();
6418 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6419 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6420 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6421 exp.type = extensionCompoundExp;
6422 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6423 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6424 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6425 exp.compound.compound.context = context;
6426 PopContext(context);
6431 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6433 exp.type = bracketsExp;
6434 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6435 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6436 ProcessExpressionType(exp.list->first);
6441 exp.type = bracketsExp;
6442 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6443 newExp.needCast = true;
6444 ProcessExpressionType(exp.list->first);
6450 if(exp.expType.kind == templateType)
6452 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6455 FreeType(exp.destType);
6456 FreeType(exp.expType);
6461 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6466 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6467 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6471 char typeString[1024];
6473 OldList * specs = MkList();
6474 typeString[0] = '\0';
6475 PrintType(exp.expType, typeString, false, false);
6476 decl = SpecDeclFromString(typeString, specs, null);
6479 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6480 exp.cast.typeName = MkTypeName(specs, decl);
6481 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6482 exp.cast.exp.needCast = true;
6489 // TODO: The Symbol tree should be reorganized by namespaces
6491 // - Tree of all symbols within (stored without namespace)
6492 // - Tree of sub-namespaces
6494 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6496 int nsLen = strlen(nameSpace);
6498 // Start at the name space prefix
6499 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6501 char * s = symbol.string;
6502 if(!strncmp(s, nameSpace, nsLen))
6504 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6507 for(c = strlen(s)-1; c >= 0; c--)
6512 if(!strcmp(namePart, name))
6514 // TODO: Error on ambiguity
6524 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6527 char nameSpace[1024];
6529 bool gotColon = false;
6531 nameSpace[0] = '\0';
6532 for(c = strlen(name)-1; c >= 0; c--)
6539 namePart = name+c+1;
6540 while(c >= 0 && name[c] == ':') c--;
6543 // Try an exact match first
6544 Symbol symbol = (Symbol)tree.FindString(name);
6548 // Namespace specified
6549 memcpy(nameSpace, name, c + 1);
6552 return ScanWithNameSpace(tree, nameSpace, namePart);
6556 // Looking for a global symbol, e.g. ::Sleep()
6557 Symbol symbol = (Symbol)tree.FindString(namePart);
6562 // Name only (no namespace specified)
6563 Symbol symbol = (Symbol)tree.FindString(namePart);
6566 return ScanWithNameSpace(tree, "", namePart);
6571 static void ProcessDeclaration(Declaration decl);
6573 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6576 //Time startTime = GetTime();
6578 // Optimize this later? Do this before/less?
6580 Symbol symbol = null;
6581 // First, check if the identifier is declared inside the function
6582 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6584 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6586 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6592 strcpy(curName, thisNameSpace);
6593 strcat(curName, "::");
6594 strcat(curName, name);
6595 // Try to resolve in current namespace first
6596 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6599 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6602 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6604 if(symbol || ctx == endContext) break;
6606 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6608 if(symbol.pointerExternal.type == functionExternal)
6610 FunctionDefinition function = symbol.pointerExternal.function;
6612 // Modified this recently...
6613 Context tmpContext = curContext;
6615 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6616 curContext = tmpContext;
6618 symbol.pointerExternal.symbol = symbol;
6621 DeclareType(symbol.type, true, true);
6623 ast->Insert(curExternal.prev, symbol.pointerExternal);
6625 symbol.id = curExternal.symbol.idCode;
6628 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6630 ast->Move(symbol.pointerExternal, curExternal.prev);
6631 symbol.id = curExternal.symbol.idCode;
6635 //findSymbolTotalTime += GetTime() - startTime;
6640 static void GetTypeSpecs(Type type, OldList * specs)
6642 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6647 if(type._class.registered)
6649 if(!type._class.registered.dataType)
6650 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6651 GetTypeSpecs(type._class.registered.dataType, specs);
6655 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6656 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6657 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6658 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6659 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6660 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6661 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6662 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6665 ListAdd(specs, MkSpecifier(INT)); break;
6669 static void PrintArraySize(Type arrayType, char * string)
6674 if(arrayType.enumClass)
6675 strcat(size, arrayType.enumClass.string);
6676 else if(arrayType.arraySizeExp)
6677 PrintExpression(arrayType.arraySizeExp, size);
6679 strcat(string, size);
6682 // WARNING : This function expects a null terminated string since it recursively concatenate...
6683 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6687 if(printConst && type.constant)
6688 strcat(string, "const ");
6693 Symbol c = type._class;
6694 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6695 // look into merging with thisclass ?
6696 if(type.classObjectType == typedObject)
6697 strcat(string, "typed_object");
6698 else if(type.classObjectType == anyObject)
6699 strcat(string, "any_object");
6703 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6705 if(type.byReference)
6706 strcat(string, " &");
6709 case voidType: strcat(string, "void"); break;
6710 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6711 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6712 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6713 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6714 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6715 case _BoolType: strcat(string, "_Bool"); break;
6716 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6717 case floatType: strcat(string, "float"); break;
6718 case doubleType: strcat(string, "double"); break;
6722 strcat(string, "struct ");
6723 strcat(string, type.enumName);
6725 else if(type.typeName)
6726 strcat(string, type.typeName);
6730 strcat(string, "struct { ");
6731 for(member = type.members.first; member; member = member.next)
6733 PrintType(member, string, true, fullName);
6734 strcat(string,"; ");
6742 strcat(string, "union ");
6743 strcat(string, type.enumName);
6745 else if(type.typeName)
6746 strcat(string, type.typeName);
6749 strcat(string, "union ");
6750 strcat(string,"(unnamed)");
6756 strcat(string, "enum ");
6757 strcat(string, type.enumName);
6759 else if(type.typeName)
6760 strcat(string, type.typeName);
6762 strcat(string, "int"); // "enum");
6765 strcat(string, "...");
6768 strcat(string, "subclass(");
6769 strcat(string, type._class ? type._class.string : "int");
6770 strcat(string, ")");
6773 strcat(string, type.templateParameter.identifier.string);
6776 strcat(string, "thisclass");
6779 strcat(string, "__builtin_va_list");
6785 static void PrintName(Type type, char * string, bool fullName)
6787 if(type.name && type.name[0])
6790 strcat(string, type.name);
6793 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6794 if(name) name += 2; else name = type.name;
6795 strcat(string, name);
6800 static void PrintAttribs(Type type, char * string)
6804 if(type.dllExport) strcat(string, "dllexport ");
6805 if(type.attrStdcall) strcat(string, "stdcall ");
6809 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6811 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6813 Type attrType = null;
6814 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6815 PrintAttribs(type, string);
6816 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6817 strcat(string, " const");
6818 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6819 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6820 strcat(string, " (");
6821 if(type.kind == pointerType)
6823 if(type.type.kind == functionType || type.type.kind == methodType)
6824 PrintAttribs(type.type, string);
6826 if(type.kind == pointerType)
6828 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6829 strcat(string, "*");
6831 strcat(string, " *");
6833 if(printConst && type.constant && type.kind == pointerType)
6834 strcat(string, " const");
6837 PrintTypeSpecs(type, string, fullName, printConst);
6840 static void PostPrintType(Type type, char * string, bool fullName)
6842 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6843 strcat(string, ")");
6844 if(type.kind == arrayType)
6845 PrintArraySize(type, string);
6846 else if(type.kind == functionType)
6849 strcat(string, "(");
6850 for(param = type.params.first; param; param = param.next)
6852 PrintType(param, string, true, fullName);
6853 if(param.next) strcat(string, ", ");
6855 strcat(string, ")");
6857 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6858 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6862 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6864 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6866 PrePrintType(type, string, fullName, null, printConst);
6868 if(type.thisClass || (printName && type.name && type.name[0]))
6869 strcat(string, " ");
6870 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6872 Symbol _class = type.thisClass;
6873 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6875 if(type.classObjectType == classPointer)
6876 strcat(string, "class");
6878 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6880 else if(_class && _class.string)
6882 String s = _class.string;
6887 char * name = RSearchString(s, "::", strlen(s), true, false);
6888 if(name) name += 2; else name = s;
6889 strcat(string, name);
6892 strcat(string, "::");
6895 if(printName && type.name)
6896 PrintName(type, string, fullName);
6897 PostPrintType(type, string, fullName);
6898 if(type.bitFieldCount)
6901 sprintf(count, ":%d", type.bitFieldCount);
6902 strcat(string, count);
6906 void PrintType(Type type, char * string, bool printName, bool fullName)
6908 _PrintType(type, string, printName, fullName, true);
6911 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6913 _PrintType(type, string, printName, fullName, false);
6916 static Type FindMember(Type type, char * string)
6919 for(memberType = type.members.first; memberType; memberType = memberType.next)
6921 if(!memberType.name)
6923 Type subType = FindMember(memberType, string);
6927 else if(!strcmp(memberType.name, string))
6933 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6936 for(memberType = type.members.first; memberType; memberType = memberType.next)
6938 if(!memberType.name)
6940 Type subType = FindMember(memberType, string);
6943 *offset += memberType.offset;
6947 else if(!strcmp(memberType.name, string))
6949 *offset += memberType.offset;
6956 public bool GetParseError() { return parseError; }
6958 Expression ParseExpressionString(char * expression)
6962 fileInput = TempFile { };
6963 fileInput.Write(expression, 1, strlen(expression));
6964 fileInput.Seek(0, start);
6967 parsedExpression = null;
6969 expression_yyparse();
6972 return parsedExpression;
6975 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6977 Identifier id = exp.identifier;
6978 Method method = null;
6979 Property prop = null;
6980 DataMember member = null;
6981 ClassProperty classProp = null;
6983 if(_class && _class.type == enumClass)
6985 NamedLink value = null;
6986 Class enumClass = eSystem_FindClass(privateModule, "enum");
6990 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6992 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6993 for(value = e.values.first; value; value = value.next)
6995 if(!strcmp(value.name, id.string))
7002 FreeExpContents(exp);
7004 exp.type = constantExp;
7005 exp.isConstant = true;
7006 if(!strcmp(baseClass.dataTypeString, "int"))
7007 sprintf(constant, "%d",(int)value.data);
7009 sprintf(constant, "0x%X",(int)value.data);
7010 exp.constant = CopyString(constant);
7011 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7012 exp.expType = MkClassType(baseClass.fullName);
7020 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7022 ProcessMethodType(method);
7029 // TOCHECK: Put it back to what it was...
7030 // methodClass = _class;
7031 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7036 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7039 ProcessPropertyType(prop);
7040 exp.expType = prop.dataType;
7041 if(prop.dataType) prop.dataType.refCount++;
7044 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7046 if(!member.dataType)
7047 member.dataType = ProcessTypeString(member.dataTypeString, false);
7048 exp.expType = member.dataType;
7049 if(member.dataType) member.dataType.refCount++;
7052 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7054 if(!classProp.dataType)
7055 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7057 if(classProp.constant)
7059 FreeExpContents(exp);
7061 exp.isConstant = true;
7062 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7064 //char constant[256];
7065 exp.type = stringExp;
7066 exp.constant = QMkString((char *)classProp.Get(_class));
7071 exp.type = constantExp;
7072 sprintf(constant, "%d", (int)classProp.Get(_class));
7073 exp.constant = CopyString(constant);
7081 exp.expType = classProp.dataType;
7082 if(classProp.dataType) classProp.dataType.refCount++;
7088 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7090 BinaryTree * tree = &nameSpace.functions;
7091 GlobalData data = (GlobalData)tree->FindString(name);
7095 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7097 data = ScanGlobalData(child, name);
7105 static GlobalData FindGlobalData(char * name)
7108 NameSpace * nameSpace;
7109 nameSpace = globalData;
7110 for(c = 0; name[c]; c++)
7112 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7114 NameSpace * newSpace;
7115 char * spaceName = new char[c - start + 1];
7116 strncpy(spaceName, name + start, c - start);
7117 spaceName[c-start] = '\0';
7118 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7122 nameSpace = newSpace;
7123 if(name[c] == ':') c++;
7129 return ScanGlobalData(nameSpace, name + start);
7134 static int definedExpStackPos;
7135 static void * definedExpStack[512];
7137 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7138 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7140 Expression prev = checkedExp.prev, next = checkedExp.next;
7142 FreeExpContents(checkedExp);
7143 FreeType(checkedExp.expType);
7144 FreeType(checkedExp.destType);
7146 *checkedExp = *newExp;
7150 checkedExp.prev = prev;
7151 checkedExp.next = next;
7154 void ApplyAnyObjectLogic(Expression e)
7156 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7158 char debugExpString[4096];
7159 debugExpString[0] = '\0';
7160 PrintExpression(e, debugExpString);
7163 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7165 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7166 //ellipsisDestType = destType;
7169 Type type = e.expType;
7170 Class _class = null;
7171 //Type destType = e.destType;
7173 if(type.kind == classType && type._class && type._class.registered)
7175 _class = type._class.registered;
7177 else if(type.kind == subClassType)
7179 _class = FindClass("ecere::com::Class").registered;
7183 char string[1024] = "";
7186 PrintTypeNoConst(type, string, false, true);
7187 classSym = FindClass(string);
7188 if(classSym) _class = classSym.registered;
7191 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...
7192 (!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))) ||
7193 destType.byReference)))
7195 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7197 Expression checkedExp = e, newExp;
7199 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7201 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7203 if(checkedExp.type == extensionCompoundExp)
7205 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7208 checkedExp = checkedExp.list->last;
7210 else if(checkedExp.type == castExp)
7211 checkedExp = checkedExp.cast.exp;
7214 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7216 newExp = checkedExp.op.exp2;
7217 checkedExp.op.exp2 = null;
7218 FreeExpContents(checkedExp);
7220 if(e.expType && e.expType.passAsTemplate)
7223 ComputeTypeSize(e.expType);
7224 sprintf(size, "%d", e.expType.size);
7225 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7226 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7227 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7230 ReplaceExpContents(checkedExp, newExp);
7231 e.byReference = true;
7233 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7235 Expression checkedExp, newExp;
7238 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7240 e.type == identifierExp ||
7241 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7242 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7243 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7246 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7248 Context context = PushContext();
7250 OldList * specs = MkList();
7251 char typeString[1024];
7252 Expression newExp { };
7254 typeString[0] = '\0';
7257 //if(e.destType) e.destType.refCount++;
7258 // if(exp.expType) exp.expType.refCount++;
7261 newExp.expType = null;
7263 PrintTypeNoConst(e.expType, typeString, false, true);
7264 decl = SpecDeclFromString(typeString, specs, null);
7265 newExp.destType = ProcessType(specs, decl);
7267 curContext = context;
7269 // We need a current compound for this
7273 OldList * stmts = MkList();
7274 e.type = extensionCompoundExp;
7275 sprintf(name, "__internalValue%03X", internalValueCounter++);
7276 if(!curCompound.compound.declarations)
7277 curCompound.compound.declarations = MkList();
7278 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7279 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7280 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7281 e.compound = MkCompoundStmt(null, stmts);
7284 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7287 e.compound = MkCompoundStmt(
7288 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7289 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7291 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7295 Type type = e.destType;
7297 CopyTypeInto(e.destType, type);
7298 e.destType.refCount = 1;
7299 e.destType.classObjectType = none;
7303 e.compound.compound.context = context;
7304 PopContext(context);
7305 curContext = context.parent;
7309 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7311 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7313 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7315 if(checkedExp.type == extensionCompoundExp)
7317 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7320 checkedExp = checkedExp.list->last;
7322 else if(checkedExp.type == castExp)
7323 checkedExp = checkedExp.cast.exp;
7326 Expression operand { };
7327 operand = *checkedExp;
7328 checkedExp.destType = null;
7329 checkedExp.expType = null;
7331 checkedExp.type = opExp;
7332 checkedExp.op.op = '&';
7333 checkedExp.op.exp1 = null;
7334 checkedExp.op.exp2 = operand;
7336 //newExp = MkExpOp(null, '&', checkedExp);
7338 //ReplaceExpContents(checkedExp, newExp);
7345 // If expression type is a simple class, make it an address
7346 // FixReference(e, true);
7349 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7350 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7351 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7353 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"))
7355 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7359 Expression thisExp { };
7362 thisExp.prev = null;
7363 thisExp.next = null;
7366 e.type = bracketsExp;
7367 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7368 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7369 ((Expression)e.list->first).byReference = true;
7371 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7373 e.expType = thisExp.expType;
7374 e.expType.refCount++;
7379 CopyTypeInto(e.expType, thisExp.expType);
7380 e.expType.byReference = false;
7381 e.expType.refCount = 1;
7383 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7384 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7386 e.expType.classObjectType = none;
7391 // TOFIX: Try this for a nice IDE crash!
7393 // The other way around
7396 if(destType && e.expType &&
7397 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7398 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7399 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7401 if(destType.kind == ellipsisType)
7403 Compiler_Error($"Unspecified type\n");
7405 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7407 bool byReference = e.expType.byReference;
7408 Expression thisExp { };
7410 OldList * specs = MkList();
7411 char typeString[1024]; // Watch buffer overruns
7413 ClassObjectType backupClassObjectType;
7414 bool backupByReference;
7416 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7421 backupClassObjectType = type.classObjectType;
7422 backupByReference = type.byReference;
7424 type.classObjectType = none;
7425 type.byReference = false;
7427 typeString[0] = '\0';
7428 PrintType(type, typeString, false, true);
7429 decl = SpecDeclFromString(typeString, specs, null);
7431 type.classObjectType = backupClassObjectType;
7432 type.byReference = backupByReference;
7435 thisExp.prev = null;
7436 thisExp.next = null;
7439 if( ( type.kind == classType && type._class && type._class.registered &&
7440 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7441 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7442 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7443 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7448 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7451 CopyTypeInto(e.expType, type);
7452 e.expType.byReference = false;
7453 e.expType.refCount = 1;
7458 e.cast.typeName = MkTypeName(specs, decl);
7459 e.cast.exp = thisExp;
7460 e.byReference = true;
7464 e.destType = destType;
7465 destType.refCount++;
7470 void ProcessExpressionType(Expression exp)
7472 bool unresolved = false;
7473 Location oldyylloc = yylloc;
7474 bool notByReference = false;
7476 char debugExpString[4096];
7477 debugExpString[0] = '\0';
7478 PrintExpression(exp, debugExpString);
7480 if(!exp || exp.expType)
7483 //eSystem_Logf("%s\n", expString);
7485 // Testing this here
7491 Identifier id = exp.identifier;
7492 if(!id || !topContext) return;
7494 // DOING THIS LATER NOW...
7495 if(id._class && id._class.name)
7497 id.classSym = id._class.symbol; // FindClass(id._class.name);
7498 /* TODO: Name Space Fix ups
7500 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7504 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7506 exp.expType = ProcessTypeString("Module", true);
7509 else */if(strstr(id.string, "__ecereClass") == id.string)
7511 exp.expType = ProcessTypeString("ecere::com::Class", true);
7514 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7516 // Added this here as well
7517 ReplaceClassMembers(exp, thisClass);
7518 if(exp.type != identifierExp)
7520 ProcessExpressionType(exp);
7524 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7529 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7530 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7531 if(!symbol/* && exp.destType*/)
7533 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7539 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7540 if(exp.type != identifierExp)
7542 ProcessExpressionType(exp);
7546 // Static methods called from inside the _class
7547 else if(currentClass && !id._class)
7549 if(ResolveIdWithClass(exp, currentClass, true))
7552 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7556 // If we manage to resolve this symbol
7559 Type type = symbol.type;
7560 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7562 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7564 Context context = SetupTemplatesContext(_class);
7565 type = ReplaceThisClassType(_class);
7566 FinishTemplatesContext(context);
7567 if(type) type.refCount = 0; // We'll be incrementing it right below...
7570 FreeSpecifier(id._class);
7573 id.string = CopyString(symbol.string);
7579 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7580 // Add missing cases here... enum Classes...
7581 exp.isConstant = true;
7583 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7584 if(symbol.isParam || !strcmp(id.string, "this"))
7586 if(_class && _class.type == structClass && !type.declaredWithStruct)
7587 exp.byReference = true;
7589 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7590 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7591 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7592 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7594 Identifier id = exp.identifier;
7595 exp.type = bracketsExp;
7596 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7600 if(symbol.isIterator)
7602 if(symbol.isIterator == 3)
7604 exp.type = bracketsExp;
7605 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7606 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7608 ProcessExpressionType(exp);
7610 else if(symbol.isIterator != 4)
7612 exp.type = memberExp;
7613 exp.member.exp = MkExpIdentifier(exp.identifier);
7614 exp.member.exp.expType = exp.expType;
7615 /*if(symbol.isIterator == 6)
7616 exp.member.member = MkIdentifier("key");
7618 exp.member.member = MkIdentifier("data");
7620 ProcessExpressionType(exp);
7627 DefinedExpression definedExp = null;
7628 if(thisNameSpace && !(id._class && !id._class.name))
7631 strcpy(name, thisNameSpace);
7633 strcat(name, id.string);
7634 definedExp = eSystem_FindDefine(privateModule, name);
7637 definedExp = eSystem_FindDefine(privateModule, id.string);
7641 for(c = 0; c<definedExpStackPos; c++)
7642 if(definedExpStack[c] == definedExp)
7644 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7646 Location backupYylloc = yylloc;
7647 File backInput = fileInput;
7648 definedExpStack[definedExpStackPos++] = definedExp;
7650 fileInput = TempFile { };
7651 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7652 fileInput.Seek(0, start);
7655 parsedExpression = null;
7657 expression_yyparse();
7660 fileInput = backInput;
7662 yylloc = backupYylloc;
7664 if(parsedExpression)
7667 exp.type = bracketsExp;
7668 exp.list = MkListOne(parsedExpression);
7669 parsedExpression.loc = yylloc;
7670 ProcessExpressionType(exp);
7671 definedExpStackPos--;
7674 definedExpStackPos--;
7680 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7686 GlobalData data = null;
7687 if(thisNameSpace && !(id._class && !id._class.name))
7690 strcpy(name, thisNameSpace);
7692 strcat(name, id.string);
7693 data = FindGlobalData(name);
7696 data = FindGlobalData(id.string);
7699 DeclareGlobalData(data);
7700 exp.expType = data.dataType;
7701 if(data.dataType) data.dataType.refCount++;
7704 id.string = CopyString(data.fullName);
7705 FreeSpecifier(id._class);
7712 GlobalFunction function = null;
7713 if(thisNameSpace && !(id._class && !id._class.name))
7716 strcpy(name, thisNameSpace);
7718 strcat(name, id.string);
7719 function = eSystem_FindFunction(privateModule, name);
7722 function = eSystem_FindFunction(privateModule, id.string);
7727 id.string = CopyString(function.name);
7730 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7731 strcpy(name, "__ecereFunction_");
7732 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7733 if(DeclareFunction(function, name))
7736 id.string = CopyString(name);
7738 exp.expType = function.dataType;
7739 if(function.dataType) function.dataType.refCount++;
7741 FreeSpecifier(id._class);
7758 if(!exp.instance._class)
7760 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7762 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7766 //classSym = FindClass(exp.instance._class.fullName);
7767 //_class = classSym ? classSym.registered : null;
7769 ProcessInstantiationType(exp.instance);
7770 exp.isConstant = exp.instance.isConstant;
7773 if(_class.type == unitClass && _class.base.type != systemClass)
7776 Type destType = exp.destType;
7778 exp.destType = MkClassType(_class.base.fullName);
7779 exp.expType = MkClassType(_class.fullName);
7780 CheckExpressionType(exp, exp.destType, true);
7782 exp.destType = destType;
7784 exp.expType = MkClassType(_class.fullName);
7787 if(exp.instance._class)
7789 exp.expType = MkClassType(exp.instance._class.name);
7790 /*if(exp.expType._class && exp.expType._class.registered &&
7791 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7792 exp.expType.byReference = true;*/
7800 char * constant = exp.constant;
7808 if(constant[0] == '\'')
7810 if((int)((byte *)constant)[1] > 127)
7813 unichar ch = UTF8GetChar(constant + 1, &nb);
7814 if(nb < 2) ch = constant[1];
7816 exp.constant = PrintUInt(ch);
7817 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7818 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7819 type._class = FindClass("unichar");
7821 type.isSigned = false;
7825 type.kind = charType;
7826 type.isSigned = true;
7831 char * dot = strchr(constant, '.');
7832 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7836 exponent = strchr(constant, 'p');
7837 if(!exponent) exponent = strchr(constant, 'P');
7841 exponent = strchr(constant, 'e');
7842 if(!exponent) exponent = strchr(constant, 'E');
7847 if(strchr(constant, 'f') || strchr(constant, 'F'))
7848 type.kind = floatType;
7850 type.kind = doubleType;
7851 type.isSigned = true;
7855 bool isSigned = constant[0] == '-';
7857 int64 i64 = strtoll(constant, &endP, 0);
7858 uint64 ui64 = strtoull(constant, &endP, 0);
7859 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
7872 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7876 else if(constant[0] != '0' || !constant[1])
7879 type.kind = is64Bit ? int64Type : intType;
7880 type.isSigned = isSigned;
7883 exp.isConstant = true;
7884 if(exp.destType && exp.destType.kind == doubleType)
7885 type.kind = doubleType;
7886 else if(exp.destType && exp.destType.kind == floatType)
7887 type.kind = floatType;
7888 else if(exp.destType && exp.destType.kind == int64Type)
7889 type.kind = int64Type;
7895 exp.isConstant = true; // Why wasn't this constant?
7912 ProcessExpressionType(exp._new.size);
7917 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7919 DeclareType(exp.expType.type, false, false);
7923 ProcessExpressionType(exp._renew.size);
7924 ProcessExpressionType(exp._renew.exp);
7929 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7931 DeclareType(exp.expType.type, false, false);
7935 bool assign = false, boolResult = false, boolOps = false;
7936 Type type1 = null, type2 = null;
7937 bool useDestType = false, useSideType = false;
7938 Location oldyylloc = yylloc;
7939 bool useSideUnit = false;
7941 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7950 // Assignment Operators
7964 // boolean Operators
7966 // Expect boolean operators
7968 //boolResult = true;
7972 // Expect boolean operands
7983 // Gives boolean result
7991 // Just added these... testing
7996 // DANGER: Verify units
8001 if(exp.op.op != '*' || exp.op.exp1)
8008 /*// Implement speed etc.
8014 if(exp.op.op == '&')
8016 // Added this here earlier for Iterator address as key
8017 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8019 Identifier id = exp.op.exp2.identifier;
8020 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8021 if(symbol && symbol.isIterator == 2)
8023 exp.type = memberExp;
8024 exp.member.exp = exp.op.exp2;
8025 exp.member.member = MkIdentifier("key");
8027 exp.op.exp2.expType = symbol.type;
8028 symbol.type.refCount++;
8029 ProcessExpressionType(exp);
8033 // exp.op.exp2.usage.usageRef = true;
8037 //dummy.kind = TypeDummy;
8041 if(exp.destType && exp.destType.kind == classType &&
8042 exp.destType._class && exp.destType._class.registered && useDestType &&
8044 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
8045 exp.destType._class.registered.type == enumClass ||
8046 exp.destType._class.registered.type == bitClass
8049 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8051 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8052 exp.op.exp1.destType = exp.destType;
8054 exp.destType.refCount++;
8058 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8059 exp.op.exp1.destType = dummy;
8063 // TESTING THIS HERE...
8064 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8065 ProcessExpressionType(exp.op.exp1);
8066 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8068 if(exp.op.exp1.destType == dummy)
8071 exp.op.exp1.destType = null;
8073 type1 = exp.op.exp1.expType;
8078 char expString[10240];
8079 expString[0] = '\0';
8080 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8084 exp.op.exp2.destType = exp.op.exp1.expType;
8085 if(exp.op.exp1.expType)
8086 exp.op.exp1.expType.refCount++;
8090 exp.op.exp2.destType = exp.destType;
8092 exp.destType.refCount++;
8095 if(type1) type1.refCount++;
8096 exp.expType = type1;
8101 PrintExpression(exp.op.exp2, expString);
8103 if(type1 && type1.kind == pointerType)
8105 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 ||
8106 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8107 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8108 else if(exp.op.op == '=')
8110 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8111 exp.op.exp2.destType = type1;
8118 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8119 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/* ||
8120 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8123 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8124 exp.op.exp2.destType = type1;
8129 if(type1) type1.refCount++;
8130 exp.expType = type1;
8132 else if(exp.destType && exp.destType.kind == classType &&
8133 exp.destType._class && exp.destType._class.registered &&
8135 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
8136 (exp.destType._class.registered.type == enumClass && useDestType))
8139 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8140 exp.op.exp2.destType = exp.destType;
8142 exp.destType.refCount++;
8146 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8147 exp.op.exp2.destType = dummy;
8151 // TESTING THIS HERE... (DANGEROUS)
8152 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8153 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8155 FreeType(exp.op.exp2.destType);
8156 exp.op.exp2.destType = type1;
8159 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8160 // Cannot lose the cast on a sizeof
8161 if(exp.op.op == SIZEOF)
8163 Expression e = exp.op.exp2;
8164 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8166 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8168 if(e.type == extensionCompoundExp)
8169 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8174 if(e.type == castExp && e.cast.exp)
8175 e.cast.exp.needCast = true;
8177 ProcessExpressionType(exp.op.exp2);
8178 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8180 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8182 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)
8184 if(exp.op.op != '=' && type1.type.kind == voidType)
8185 Compiler_Error($"void *: unknown size\n");
8187 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||
8188 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8189 (exp.op.exp2.expType._class.registered.type == normalClass ||
8190 exp.op.exp2.expType._class.registered.type == structClass ||
8191 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8193 if(exp.op.op == ADD_ASSIGN)
8194 Compiler_Error($"cannot add two pointers\n");
8196 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8197 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8199 if(exp.op.op == ADD_ASSIGN)
8200 Compiler_Error($"cannot add two pointers\n");
8204 char type1String[1024];
8205 char type2String[1024];
8206 type1String[0] = '\0';
8207 type2String[0] = '\0';
8209 PrintType(exp.op.exp2.expType, type1String, false, true);
8210 PrintType(type1, type2String, false, true);
8211 ChangeCh(expString, '\n', ' ');
8212 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8216 if(exp.op.exp2.destType == dummy)
8219 exp.op.exp2.destType = null;
8222 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8226 CopyTypeInto(type2, exp.op.exp2.expType);
8227 type2.isSigned = true;
8229 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8231 type2 = { kind = intType };
8233 type2.isSigned = true;
8237 type2 = exp.op.exp2.expType;
8238 if(type2) type2.refCount++;
8242 dummy.kind = voidType;
8244 if(exp.op.op == SIZEOF)
8251 exp.isConstant = true;
8253 // Get type of dereferenced pointer
8254 else if(exp.op.op == '*' && !exp.op.exp1)
8256 exp.expType = Dereference(type2);
8257 if(type2 && type2.kind == classType)
8258 notByReference = true;
8260 else if(exp.op.op == '&' && !exp.op.exp1)
8261 exp.expType = Reference(type2);
8268 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8269 exp.op.exp1.destType = MkClassType("bool");
8270 exp.op.exp1.destType.truth = true;
8271 if(!exp.op.exp1.expType)
8272 ProcessExpressionType(exp.op.exp1);
8274 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8275 FreeType(exp.op.exp1.expType);
8276 exp.op.exp1.expType = MkClassType("bool");
8277 exp.op.exp1.expType.truth = true;
8281 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8282 exp.op.exp2.destType = MkClassType("bool");
8283 exp.op.exp2.destType.truth = true;
8284 if(!exp.op.exp2.expType)
8285 ProcessExpressionType(exp.op.exp2);
8287 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8288 FreeType(exp.op.exp2.expType);
8289 exp.op.exp2.expType = MkClassType("bool");
8290 exp.op.exp2.expType.truth = true;
8293 else if(exp.op.exp1 && exp.op.exp2 &&
8296 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8297 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8298 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8299 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8301 if(type1 && type2 &&
8302 // If either both are class or both are not class
8303 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8305 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8306 exp.op.exp2.destType = type1;
8308 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8309 exp.op.exp1.destType = type2;
8311 // Warning here for adding Radians + Degrees with no destination type
8312 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8313 type1._class.registered && type1._class.registered.type == unitClass &&
8314 type2._class.registered && type2._class.registered.type == unitClass &&
8315 type1._class.registered != type2._class.registered)
8316 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8317 type1._class.string, type2._class.string, type1._class.string);
8319 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8321 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8324 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8326 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8327 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8330 ProcessExpressionType(exp.op.exp1);
8332 if(type2.kind != pointerType)
8334 ProcessExpressionType(classExp);
8336 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8337 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8338 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8340 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8343 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8344 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8345 MkPointer(null, null), null)))),
8346 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8348 if(!exp.op.exp2.expType)
8352 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8356 ProcessExpressionType(exp.op.exp2);
8361 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)))
8363 if(type1.kind != classType && type1.type.kind == voidType)
8364 Compiler_Error($"void *: unknown size\n");
8365 exp.expType = type1;
8366 if(type1) type1.refCount++;
8368 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)))
8370 if(type2.kind != classType && type2.type.kind == voidType)
8371 Compiler_Error($"void *: unknown size\n");
8372 exp.expType = type2;
8373 if(type2) type2.refCount++;
8375 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8376 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8378 Compiler_Warning($"different levels of indirection\n");
8382 bool success = false;
8383 if(type1.kind == pointerType && type2.kind == pointerType)
8385 if(exp.op.op == '+')
8386 Compiler_Error($"cannot add two pointers\n");
8387 else if(exp.op.op == '-')
8389 // Pointer Subtraction gives integer
8390 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8399 if(type1.type.kind == templateType)
8401 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8404 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8406 ProcessExpressionType(classExp);
8408 exp.type = bracketsExp;
8409 exp.list = MkListOne(MkExpOp(
8410 MkExpBrackets(MkListOne(MkExpOp(
8411 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8413 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8415 //MkExpMember(classExp, MkIdentifier("typeSize"))
8417 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8418 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8420 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8423 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8424 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8425 MkPointer(null, null), null)))),
8426 MkExpMember(classExp, MkIdentifier("typeSize")))))
8431 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8440 if(!success && exp.op.exp1.type == constantExp)
8442 // If first expression is constant, try to match that first
8443 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8445 if(exp.expType) FreeType(exp.expType);
8446 exp.expType = exp.op.exp1.destType;
8447 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8450 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8452 if(exp.expType) FreeType(exp.expType);
8453 exp.expType = exp.op.exp2.destType;
8454 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8460 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8462 if(exp.expType) FreeType(exp.expType);
8463 exp.expType = exp.op.exp2.destType;
8464 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8467 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8469 if(exp.expType) FreeType(exp.expType);
8470 exp.expType = exp.op.exp1.destType;
8471 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8477 char expString1[10240];
8478 char expString2[10240];
8481 expString1[0] = '\0';
8482 expString2[0] = '\0';
8487 PrintExpression(exp.op.exp1, expString1);
8488 ChangeCh(expString1, '\n', ' ');
8489 PrintExpression(exp.op.exp2, expString2);
8490 ChangeCh(expString2, '\n', ' ');
8491 PrintType(exp.op.exp1.expType, type1, false, true);
8492 PrintType(exp.op.exp2.expType, type2, false, true);
8495 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8499 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8500 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8502 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8503 // Convert e.g. / 4 into / 4.0
8504 exp.op.exp1.destType = type2._class.registered.dataType;
8505 if(type2._class.registered.dataType)
8506 type2._class.registered.dataType.refCount++;
8507 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8508 exp.expType = type2;
8509 if(type2) type2.refCount++;
8511 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8513 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8514 // Convert e.g. / 4 into / 4.0
8515 exp.op.exp2.destType = type1._class.registered.dataType;
8516 if(type1._class.registered.dataType)
8517 type1._class.registered.dataType.refCount++;
8518 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8519 exp.expType = type1;
8520 if(type1) type1.refCount++;
8526 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8528 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8530 if(!type1._class.registered.dataType)
8531 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8532 exp.op.exp2.destType = type1._class.registered.dataType;
8533 exp.op.exp2.destType.refCount++;
8535 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8538 type2 = exp.op.exp2.destType;
8539 if(type2) type2.refCount++;
8541 exp.expType = type2;
8545 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8547 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8549 if(!type2._class.registered.dataType)
8550 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8551 exp.op.exp1.destType = type2._class.registered.dataType;
8552 exp.op.exp1.destType.refCount++;
8554 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8555 type1 = exp.op.exp1.destType;
8556 exp.expType = type1;
8560 // TESTING THIS NEW CODE
8561 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8563 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8565 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8567 if(exp.expType) FreeType(exp.expType);
8568 exp.expType = exp.op.exp1.expType;
8569 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8574 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8576 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8578 if(exp.expType) FreeType(exp.expType);
8579 exp.expType = exp.op.exp2.expType;
8580 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8588 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8589 exp.op.exp2.destType = type1;
8593 // Maybe this was meant to be an enum...
8594 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8596 Type oldType = exp.op.exp2.expType;
8597 exp.op.exp2.expType = null;
8598 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8601 exp.op.exp2.expType = oldType;
8606 // TESTING THIS HERE... LATEST ADDITION
8607 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8609 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8610 exp.op.exp2.destType = type2._class.registered.dataType;
8611 if(type2._class.registered.dataType)
8612 type2._class.registered.dataType.refCount++;
8613 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8615 //exp.expType = type2._class.registered.dataType; //type2;
8616 //if(type2) type2.refCount++;
8619 // TESTING THIS HERE... LATEST ADDITION
8620 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8622 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8623 exp.op.exp1.destType = type1._class.registered.dataType;
8624 if(type1._class.registered.dataType)
8625 type1._class.registered.dataType.refCount++;
8626 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8627 exp.expType = type1._class.registered.dataType; //type1;
8628 if(type1) type1.refCount++;
8632 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8634 if(exp.expType) FreeType(exp.expType);
8635 exp.expType = exp.op.exp2.destType;
8636 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8638 else if(type1 && type2)
8640 char expString1[10240];
8641 char expString2[10240];
8642 char type1String[1024];
8643 char type2String[1024];
8644 expString1[0] = '\0';
8645 expString2[0] = '\0';
8646 type1String[0] = '\0';
8647 type2String[0] = '\0';
8650 PrintExpression(exp.op.exp1, expString1);
8651 ChangeCh(expString1, '\n', ' ');
8652 PrintExpression(exp.op.exp2, expString2);
8653 ChangeCh(expString2, '\n', ' ');
8654 PrintType(exp.op.exp1.expType, type1String, false, true);
8655 PrintType(exp.op.exp2.expType, type2String, false, true);
8658 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8660 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8662 exp.expType = exp.op.exp1.expType;
8663 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8665 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8667 exp.expType = exp.op.exp2.expType;
8668 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8675 // Maybe this was meant to be an enum...
8676 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8678 Type oldType = exp.op.exp1.expType;
8679 exp.op.exp1.expType = null;
8680 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8683 exp.op.exp1.expType = oldType;
8686 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8687 exp.op.exp1.destType = type2;
8690 // TESTING THIS HERE... LATEST ADDITION
8691 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8693 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8694 exp.op.exp1.destType = type1._class.registered.dataType;
8695 if(type1._class.registered.dataType)
8696 type1._class.registered.dataType.refCount++;
8699 // TESTING THIS HERE... LATEST ADDITION
8700 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8702 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8703 exp.op.exp2.destType = type2._class.registered.dataType;
8704 if(type2._class.registered.dataType)
8705 type2._class.registered.dataType.refCount++;
8709 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8711 if(exp.expType) FreeType(exp.expType);
8712 exp.expType = exp.op.exp1.destType;
8713 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8717 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8719 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8721 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8722 // Convert e.g. / 4 into / 4.0
8723 exp.op.exp1.destType = type2._class.registered.dataType;
8724 if(type2._class.registered.dataType)
8725 type2._class.registered.dataType.refCount++;
8726 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8728 if(exp.op.op == '!')
8730 exp.expType = MkClassType("bool");
8731 exp.expType.truth = true;
8735 exp.expType = type2;
8736 if(type2) type2.refCount++;
8739 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8741 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8743 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8744 // Convert e.g. / 4 into / 4.0
8745 exp.op.exp2.destType = type1._class.registered.dataType;
8746 if(type1._class.registered.dataType)
8747 type1._class.registered.dataType.refCount++;
8748 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8750 exp.expType = type1;
8751 if(type1) type1.refCount++;
8756 if(exp.op.exp1 && !exp.op.exp1.expType)
8758 char expString[10000];
8759 expString[0] = '\0';
8762 PrintExpression(exp.op.exp1, expString);
8763 ChangeCh(expString, '\n', ' ');
8766 Compiler_Error($"couldn't determine type of %s\n", expString);
8768 if(exp.op.exp2 && !exp.op.exp2.expType)
8770 char expString[10240];
8771 expString[0] = '\0';
8774 PrintExpression(exp.op.exp2, expString);
8775 ChangeCh(expString, '\n', ' ');
8778 Compiler_Error($"couldn't determine type of %s\n", expString);
8783 FreeType(exp.expType);
8784 exp.expType = MkClassType("bool");
8785 exp.expType.truth = true;
8788 if(exp.op.op != SIZEOF)
8789 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8790 (!exp.op.exp2 || exp.op.exp2.isConstant);
8792 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8794 DeclareType(exp.op.exp2.expType, false, false);
8805 case extensionExpressionExp:
8808 exp.isConstant = true;
8809 for(e = exp.list->first; e; e = e.next)
8814 FreeType(e.destType);
8815 e.destType = exp.destType;
8816 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8818 ProcessExpressionType(e);
8820 exp.destType.count--;
8821 if(!exp.expType && !e.next)
8823 exp.expType = e.expType;
8824 if(e.expType) e.expType.refCount++;
8827 exp.isConstant = false;
8830 // In case a cast became a member...
8831 e = exp.list->first;
8832 if(!e.next && e.type == memberExp)
8834 // Preserve prev, next
8835 Expression next = exp.next, prev = exp.prev;
8838 FreeType(exp.expType);
8839 FreeType(exp.destType);
8849 ProcessExpressionType(exp);
8856 exp.isConstant = true;
8858 ProcessExpressionType(exp.index.exp);
8859 if(!exp.index.exp.isConstant)
8860 exp.isConstant = false;
8862 if(exp.index.exp.expType)
8864 Type source = exp.index.exp.expType;
8865 if(source.kind == classType && source._class && source._class.registered)
8867 Class _class = source._class.registered;
8868 Class c = _class.templateClass ? _class.templateClass : _class;
8869 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
8871 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8873 if(exp.index.index && exp.index.index->last)
8875 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8881 for(e = exp.index.index->first; e; e = e.next)
8883 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8885 if(e.destType) FreeType(e.destType);
8886 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8888 ProcessExpressionType(e);
8891 // Check if this type is int
8894 exp.isConstant = false;
8898 exp.expType = Dereference(exp.index.exp.expType);
8900 DeclareType(exp.expType, false, false);
8907 Type methodType = null;
8913 PrintExpression(exp.call.exp, name);
8914 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8916 //exp.call.exp.expType = null;
8917 PrintExpression(exp.call.exp, name);
8920 if(exp.call.exp.type == identifierExp)
8922 Expression idExp = exp.call.exp;
8923 Identifier id = idExp.identifier;
8924 if(!strcmp(id.string, "__builtin_frame_address"))
8926 exp.expType = ProcessTypeString("void *", true);
8927 if(exp.call.arguments && exp.call.arguments->first)
8928 ProcessExpressionType(exp.call.arguments->first);
8931 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8933 exp.expType = ProcessTypeString("int", true);
8934 if(exp.call.arguments && exp.call.arguments->first)
8935 ProcessExpressionType(exp.call.arguments->first);
8938 else if(!strcmp(id.string, "Max") ||
8939 !strcmp(id.string, "Min") ||
8940 !strcmp(id.string, "Sgn") ||
8941 !strcmp(id.string, "Abs"))
8943 Expression a = null;
8944 Expression b = null;
8945 Expression tempExp1 = null, tempExp2 = null;
8946 if((!strcmp(id.string, "Max") ||
8947 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8949 a = exp.call.arguments->first;
8950 b = exp.call.arguments->last;
8954 else if(exp.call.arguments->count == 1)
8956 a = exp.call.arguments->first;
8962 exp.call.arguments->Clear();
8963 idExp.identifier = null;
8965 FreeExpContents(exp);
8967 ProcessExpressionType(a);
8969 ProcessExpressionType(b);
8971 exp.type = bracketsExp;
8972 exp.list = MkList();
8974 if(a.expType && (!b || b.expType))
8976 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8978 // Use the simpleStruct name/ids for now...
8981 OldList * specs = MkList();
8982 OldList * decls = MkList();
8984 char temp1[1024], temp2[1024];
8986 GetTypeSpecs(a.expType, specs);
8988 if(a && !a.isConstant && a.type != identifierExp)
8990 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8991 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8992 tempExp1 = QMkExpId(temp1);
8993 tempExp1.expType = a.expType;
8995 a.expType.refCount++;
8996 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8998 if(b && !b.isConstant && b.type != identifierExp)
9000 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9001 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9002 tempExp2 = QMkExpId(temp2);
9003 tempExp2.expType = b.expType;
9005 b.expType.refCount++;
9006 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9009 decl = MkDeclaration(specs, decls);
9010 if(!curCompound.compound.declarations)
9011 curCompound.compound.declarations = MkList();
9012 curCompound.compound.declarations->Insert(null, decl);
9017 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9019 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9021 MkExpCondition(MkExpBrackets(MkListOne(
9022 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9023 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9024 exp.expType = a.expType;
9026 a.expType.refCount++;
9028 else if(!strcmp(id.string, "Abs"))
9031 MkExpCondition(MkExpBrackets(MkListOne(
9032 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9033 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9034 exp.expType = a.expType;
9036 a.expType.refCount++;
9038 else if(!strcmp(id.string, "Sgn"))
9040 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9042 MkExpCondition(MkExpBrackets(MkListOne(
9043 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9044 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9045 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9046 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9047 exp.expType = ProcessTypeString("int", false);
9050 FreeExpression(tempExp1);
9051 if(tempExp2) FreeExpression(tempExp2);
9065 if(!exp.call.exp.destType)
9067 exp.call.exp.destType = dummy;
9070 ProcessExpressionType(exp.call.exp);
9071 if(exp.call.exp.destType == dummy)
9074 exp.call.exp.destType = null;
9079 // Check argument types against parameter types
9080 functionType = exp.call.exp.expType;
9082 if(functionType && functionType.kind == TypeKind::methodType)
9084 methodType = functionType;
9085 functionType = methodType.method.dataType;
9087 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9088 // TOCHECK: Instead of doing this here could this be done per param?
9089 if(exp.call.exp.expType.usedClass)
9091 char typeString[1024];
9092 typeString[0] = '\0';
9094 Symbol back = functionType.thisClass;
9095 // Do not output class specifier here (thisclass was added to this)
9096 functionType.thisClass = null;
9097 PrintType(functionType, typeString, true, true);
9098 functionType.thisClass = back;
9100 if(strstr(typeString, "thisclass"))
9102 OldList * specs = MkList();
9105 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9107 decl = SpecDeclFromString(typeString, specs, null);
9109 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9110 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9111 exp.call.exp.expType.usedClass))
9112 thisClassParams = false;
9114 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9116 Class backupThisClass = thisClass;
9117 thisClass = exp.call.exp.expType.usedClass;
9118 ProcessDeclarator(decl);
9119 thisClass = backupThisClass;
9122 thisClassParams = true;
9124 functionType = ProcessType(specs, decl);
9125 functionType.refCount = 0;
9126 FinishTemplatesContext(context);
9129 FreeList(specs, FreeSpecifier);
9130 FreeDeclarator(decl);
9134 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9136 Type type = functionType.type;
9137 if(!functionType.refCount)
9139 functionType.type = null;
9140 FreeType(functionType);
9142 //methodType = functionType;
9143 functionType = type;
9145 if(functionType && functionType.kind != TypeKind::functionType)
9147 Compiler_Error($"called object %s is not a function\n", name);
9149 else if(functionType)
9151 bool emptyParams = false, noParams = false;
9152 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9153 Type type = functionType.params.first;
9154 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9156 Location oldyylloc = yylloc;
9158 if(!type) emptyParams = true;
9161 if(functionType.extraParam && e && functionType.thisClass)
9163 e.destType = MkClassType(functionType.thisClass.string);
9167 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9168 // Fixed #141 by adding '&& !functionType.extraParam'
9169 if(!functionType.staticMethod && !functionType.extraParam)
9171 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9172 memberExp.member.exp.expType._class)
9174 type = MkClassType(memberExp.member.exp.expType._class.string);
9179 type = functionType.params.first;
9184 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9186 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9187 type.byReference = functionType.byReference;
9188 type.typedByReference = functionType.typedByReference;
9191 // Allow manually passing a class for typed object
9192 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9196 type = functionType.params.first;
9204 if(type && type.kind == voidType)
9207 if(!type.refCount) FreeType(type);
9211 for( ; e; e = e.next)
9213 if(!type && !emptyParams)
9216 if(methodType && methodType.methodClass)
9217 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9218 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9219 noParams ? 0 : functionType.params.count);
9221 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9222 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9223 noParams ? 0 : functionType.params.count);
9227 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9229 Type templatedType = null;
9230 Class _class = methodType.usedClass;
9231 ClassTemplateParameter curParam = null;
9233 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9236 for(sClass = _class; sClass; sClass = sClass.base)
9238 if(sClass.templateClass) sClass = sClass.templateClass;
9240 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9242 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9245 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9247 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9248 id += nextClass.templateParams.count;
9257 if(curParam && _class.templateArgs[id].dataTypeString)
9259 ClassTemplateArgument arg = _class.templateArgs[id];
9261 Context context = SetupTemplatesContext(_class);
9264 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9265 templatedType = ProcessTypeString(arg.dataTypeString, false);
9266 FinishTemplatesContext(context);
9268 e.destType = templatedType;
9271 templatedType.passAsTemplate = true;
9272 // templatedType.refCount++;
9278 if(type) type.refCount++;
9283 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9285 e.destType = type.prev;
9286 e.destType.refCount++;
9291 if(type) type.refCount++;
9294 // Don't reach the end for the ellipsis
9295 if(type && type.kind != ellipsisType)
9297 Type next = type.next;
9298 if(!type.refCount) FreeType(type);
9303 if(type && type.kind != ellipsisType)
9305 if(methodType && methodType.methodClass)
9306 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9307 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9308 functionType.params.count + extra);
9310 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9311 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9312 functionType.params.count + extra);
9315 if(type && !type.refCount) FreeType(type);
9322 kind = TypeKind::functionType;
9325 if(exp.call.exp.type == identifierExp)
9327 char * string = exp.call.exp.identifier.string;
9331 Location oldyylloc = yylloc;
9333 yylloc = exp.call.exp.identifier.loc;
9334 if(strstr(string, "__builtin_") == string)
9338 functionType.returnType = exp.destType;
9339 exp.destType.refCount++;
9343 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9344 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9345 globalContext.symbols.Add((BTNode)symbol);
9346 if(strstr(symbol.string, "::"))
9347 globalContext.hasNameSpace = true;
9352 else if(exp.call.exp.type == memberExp)
9354 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9355 exp.call.exp.member.member.string);*/
9358 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9360 if(!functionType.returnType)
9362 functionType.returnType = Type
9369 if(functionType && functionType.kind == TypeKind::functionType)
9371 exp.expType = functionType.returnType;
9373 if(functionType.returnType)
9374 functionType.returnType.refCount++;
9376 if(!functionType.refCount)
9377 FreeType(functionType);
9380 if(exp.call.arguments)
9382 for(e = exp.call.arguments->first; e; e = e.next)
9384 Type destType = e.destType;
9385 ProcessExpressionType(e);
9393 Location oldyylloc = yylloc;
9395 Expression checkExp = exp.member.exp;
9398 if(checkExp.type == castExp)
9399 checkExp = checkExp.cast.exp;
9400 else if(checkExp.type == bracketsExp)
9401 checkExp = checkExp.list ? checkExp.list->first : null;
9406 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9407 exp.thisPtr = thisPtr;
9409 // DOING THIS LATER NOW...
9410 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9412 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9413 /* TODO: Name Space Fix ups
9414 if(!exp.member.member.classSym)
9415 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9419 ProcessExpressionType(exp.member.exp);
9420 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9421 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9423 exp.isConstant = false;
9426 exp.isConstant = exp.member.exp.isConstant;
9427 type = exp.member.exp.expType;
9431 if(type && (type.kind == templateType))
9433 Class _class = thisClass ? thisClass : currentClass;
9434 ClassTemplateParameter param = null;
9437 for(param = _class.templateParams.first; param; param = param.next)
9439 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9443 if(param && param.defaultArg.member)
9445 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9448 Expression expMember = exp.member.exp;
9450 OldList * specs = MkList();
9451 char thisClassTypeString[1024];
9453 FreeIdentifier(exp.member.member);
9455 ProcessExpressionType(argExp);
9458 char * colon = strstr(param.defaultArg.memberString, "::");
9461 char className[1024];
9464 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9465 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9468 strcpy(thisClassTypeString, _class.fullName);
9471 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9473 exp.expType = ProcessType(specs, decl);
9474 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9476 Class expClass = exp.expType._class.registered;
9477 Class cClass = null;
9482 char templateString[1024];
9483 ClassTemplateParameter param;
9484 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9485 for(cClass = expClass; cClass; cClass = cClass.base)
9488 for(param = cClass.templateParams.first; param; param = param.next)
9492 ClassTemplateArgument arg;
9493 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9494 arg = expClass.templateArgs[id];
9496 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9498 ClassTemplateParameter cParam;
9499 //int p = numParams - sClass.templateParams.count;
9502 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9504 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9506 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9508 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9510 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9511 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9523 strcat(argument, arg.name.string);
9524 strcat(argument, " = ");
9530 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9531 char expString[1024];
9532 OldList * specs = MkList();
9533 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9535 char * string = PrintHexUInt64(arg.expression.ui64);
9536 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9539 ProcessExpressionType(exp);
9540 ComputeExpression(exp);
9541 expString[0] = '\0';
9542 PrintExpression(exp, expString);
9543 strcat(argument, expString);
9545 FreeExpression(exp);
9550 strcat(argument, arg.member.name);
9553 case TemplateParameterType::type:
9555 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9557 if(!strcmp(arg.dataTypeString, "thisclass"))
9558 strcat(argument, thisClassTypeString);
9560 strcat(argument, arg.dataTypeString);
9567 if(paramCount) strcat(templateString, ", ");
9568 if(lastParam != p - 1)
9570 strcat(templateString, param.name);
9571 strcat(templateString, " = ");
9573 strcat(templateString, argument);
9582 int len = strlen(templateString);
9583 if(templateString[len-1] == '>') templateString[len++] = ' ';
9584 templateString[len++] = '>';
9585 templateString[len++] = '\0';
9588 Context context = SetupTemplatesContext(_class);
9589 FreeType(exp.expType);
9590 exp.expType = ProcessTypeString(templateString, false);
9591 FinishTemplatesContext(context);
9595 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9596 exp.type = bracketsExp;
9597 exp.list = MkListOne(MkExpOp(null, '*',
9602 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9603 MkExpBrackets(MkListOne(
9604 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9606 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9608 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9613 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9614 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9616 type = ProcessTemplateParameterType(type.templateParameter);
9619 // TODO: *** This seems to be where we should add method support for all basic types ***
9620 if(type && (type.kind == templateType));
9621 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9622 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9623 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9624 (type.kind == pointerType && type.type.kind == charType)))
9626 Identifier id = exp.member.member;
9627 TypeKind typeKind = type.kind;
9628 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9629 if(typeKind == subClassType && exp.member.exp.type == classExp)
9631 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9632 typeKind = classType;
9637 if(typeKind == intType || typeKind == enumType)
9638 _class = eSystem_FindClass(privateModule, "int");
9641 if(type.kind == classType && type._class && type._class.registered)
9643 _class = type._class.registered;
9645 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9647 _class = FindClass("char *").registered;
9649 else if(type.kind == pointerType)
9651 _class = eSystem_FindClass(privateModule, "uintptr");
9652 FreeType(exp.expType);
9653 exp.expType = ProcessTypeString("uintptr", false);
9654 exp.byReference = true;
9658 char string[1024] = "";
9660 PrintTypeNoConst(type, string, false, true);
9661 classSym = FindClass(string);
9662 if(classSym) _class = classSym.registered;
9670 (exp.member.exp.type == identifierExp &&
9671 !strcmp(exp.member.exp.identifier.string, "this"));*/
9672 Property prop = null;
9673 Method method = null;
9674 DataMember member = null;
9675 Property revConvert = null;
9676 ClassProperty classProp = null;
9678 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9679 exp.member.memberType = propertyMember;
9681 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9682 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9684 if(typeKind != subClassType)
9686 // Prioritize data members over properties for "this"
9687 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9689 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9690 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9692 prop = eClass_FindProperty(_class, id.string, privateModule);
9696 if(!member && !prop)
9697 prop = eClass_FindProperty(_class, id.string, privateModule);
9698 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9699 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9700 exp.member.thisPtr = true;
9702 // Prioritize properties over data members otherwise
9705 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9708 prop = eClass_FindProperty(_class, id.string, null);
9709 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9710 member = eClass_FindDataMember(_class, id.string, null, null, null);
9713 if(!prop && !member)
9715 method = eClass_FindMethod(_class, id.string, null);
9718 prop = eClass_FindProperty(_class, id.string, privateModule);
9719 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9720 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9726 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9733 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9734 method = eClass_FindMethod(_class, id.string, privateModule);
9735 if(!prop && !member && !method)
9737 if(typeKind == subClassType)
9739 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9742 exp.member.memberType = classPropertyMember;
9743 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9747 // Assume this is a class_data member
9748 char structName[1024];
9749 Identifier id = exp.member.member;
9750 Expression classExp = exp.member.exp;
9753 FreeType(classExp.expType);
9754 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9756 strcpy(structName, "__ecereClassData_");
9757 FullClassNameCat(structName, type._class.string, false);
9758 exp.type = pointerExp;
9759 exp.member.member = id;
9761 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9762 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9763 MkExpBrackets(MkListOne(MkExpOp(
9764 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9765 MkExpMember(classExp, MkIdentifier("data"))), '+',
9766 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9771 ProcessExpressionType(exp);
9777 // Check for reverse conversion
9778 // (Convert in an instantiation later, so that we can use
9779 // deep properties system)
9780 Symbol classSym = FindClass(id.string);
9783 Class convertClass = classSym.registered;
9785 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9792 exp.member.memberType = propertyMember;
9794 ProcessPropertyType(prop);
9795 exp.expType = prop.dataType;
9796 if(prop.dataType) prop.dataType.refCount++;
9800 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9802 FreeExpContents(exp);
9803 exp.type = identifierExp;
9804 exp.identifier = MkIdentifier("class");
9805 ProcessExpressionType(exp);
9809 exp.member.memberType = dataMember;
9810 DeclareStruct(_class.fullName, false);
9811 if(!member.dataType)
9813 Context context = SetupTemplatesContext(_class);
9814 member.dataType = ProcessTypeString(member.dataTypeString, false);
9815 FinishTemplatesContext(context);
9817 exp.expType = member.dataType;
9818 if(member.dataType) member.dataType.refCount++;
9822 exp.member.memberType = reverseConversionMember;
9823 exp.expType = MkClassType(revConvert._class.fullName);
9831 exp.type = identifierExp;
9832 exp.identifier = exp.member.member;
9835 exp.member.memberType = methodMember;
9837 if(!method.dataType)
9838 ProcessMethodType(method);
9846 // Tricky spot here... To use instance versus class virtual table
9847 // Put it back to what it was... What did we break?
9849 // Had to put it back for overriding Main of Thread global instance
9851 //exp.expType.methodClass = _class;
9852 exp.expType.methodClass = (id && id._class) ? _class : null;
9854 // Need the actual class used for templated classes
9855 exp.expType.usedClass = _class;
9859 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9861 FreeExpContents(exp);
9862 exp.type = identifierExp;
9863 exp.identifier = MkIdentifier("class");
9864 FreeType(exp.expType);
9865 exp.expType = MkClassType("ecere::com::Class");
9868 yylloc = exp.member.member.loc;
9869 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9871 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9874 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9879 while(tClass && !tClass.templateClass) tClass = tClass.base;
9881 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9884 ClassTemplateParameter curParam = null;
9887 for(sClass = tClass; sClass; sClass = sClass.base)
9890 if(sClass.templateClass) sClass = sClass.templateClass;
9891 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9893 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9895 for(sClass = sClass.base; sClass; sClass = sClass.base)
9896 id += sClass.templateParams.count;
9904 if(curParam && tClass.templateArgs[id].dataTypeString)
9906 ClassTemplateArgument arg = tClass.templateArgs[id];
9907 Context context = SetupTemplatesContext(tClass);
9909 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9910 FreeType(exp.expType);
9911 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9914 if(exp.expType.kind == thisClassType)
9916 FreeType(exp.expType);
9917 exp.expType = ReplaceThisClassType(_class);
9920 if(tClass.templateClass)
9921 exp.expType.passAsTemplate = true;
9922 //exp.expType.refCount++;
9925 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9926 //exp.destType.refCount++;
9928 if(exp.destType.kind == thisClassType)
9930 FreeType(exp.destType);
9931 exp.destType = ReplaceThisClassType(_class);
9935 FinishTemplatesContext(context);
9938 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9939 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9942 ClassTemplateParameter curParam = null;
9945 for(sClass = tClass; sClass; sClass = sClass.base)
9948 if(sClass.templateClass) sClass = sClass.templateClass;
9949 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9951 if(curParam.type == TemplateParameterType::type &&
9952 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9954 for(sClass = sClass.base; sClass; sClass = sClass.base)
9955 id += sClass.templateParams.count;
9965 ClassTemplateArgument arg = tClass.templateArgs[id];
9966 Context context = SetupTemplatesContext(tClass);
9969 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9971 basicType = ProcessTypeString(arg.dataTypeString, false);
9974 if(basicType.kind == thisClassType)
9976 FreeType(basicType);
9977 basicType = ReplaceThisClassType(_class);
9980 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9981 if(tClass.templateClass)
9982 basicType.passAsTemplate = true;
9985 FreeType(exp.expType);
9987 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9988 //exp.expType.refCount++;
9991 exp.destType = exp.expType;
9992 exp.destType.refCount++;
9996 Expression newExp { };
9997 OldList * specs = MkList();
9999 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10001 if(exp.destType) exp.destType.refCount++;
10002 if(exp.expType) exp.expType.refCount++;
10003 exp.type = castExp;
10004 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10005 exp.cast.exp = newExp;
10006 //FreeType(exp.expType);
10007 //exp.expType = null;
10008 //ProcessExpressionType(sourceExp);
10011 FinishTemplatesContext(context);
10014 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10016 Class expClass = exp.expType._class.registered;
10019 Class cClass = null;
10022 int paramCount = 0;
10023 int lastParam = -1;
10024 char templateString[1024];
10025 ClassTemplateParameter param;
10026 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10027 while(cClass != expClass)
10030 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10033 for(param = cClass.templateParams.first; param; param = param.next)
10035 Class cClassCur = null;
10038 ClassTemplateParameter paramCur = null;
10039 ClassTemplateArgument arg;
10040 while(cClassCur != tClass && !paramCur)
10043 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10044 cClassCur = sClassCur;
10046 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10048 if(!strcmp(paramCur.name, param.name))
10056 if(paramCur && paramCur.type == TemplateParameterType::type)
10057 arg = tClass.templateArgs[cp];
10059 arg = expClass.templateArgs[p];
10062 char argument[256];
10063 argument[0] = '\0';
10066 strcat(argument, arg.name.string);
10067 strcat(argument, " = ");
10073 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10074 char expString[1024];
10075 OldList * specs = MkList();
10076 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10078 char * string = PrintHexUInt64(arg.expression.ui64);
10079 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10082 ProcessExpressionType(exp);
10083 ComputeExpression(exp);
10084 expString[0] = '\0';
10085 PrintExpression(exp, expString);
10086 strcat(argument, expString);
10088 FreeExpression(exp);
10093 strcat(argument, arg.member.name);
10096 case TemplateParameterType::type:
10098 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10099 strcat(argument, arg.dataTypeString);
10105 if(paramCount) strcat(templateString, ", ");
10106 if(lastParam != p - 1)
10108 strcat(templateString, param.name);
10109 strcat(templateString, " = ");
10111 strcat(templateString, argument);
10120 int len = strlen(templateString);
10121 if(templateString[len-1] == '>') templateString[len++] = ' ';
10122 templateString[len++] = '>';
10123 templateString[len++] = '\0';
10126 FreeType(exp.expType);
10128 Context context = SetupTemplatesContext(tClass);
10129 exp.expType = ProcessTypeString(templateString, false);
10130 FinishTemplatesContext(context);
10137 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10139 else if(type && (type.kind == structType || type.kind == unionType))
10141 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10144 exp.expType = memberType;
10146 memberType.refCount++;
10151 char expString[10240];
10152 expString[0] = '\0';
10153 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10154 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10157 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10159 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10161 Identifier id = exp.member.member;
10162 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10165 FreeType(exp.expType);
10166 exp.expType = ReplaceThisClassType(_class);
10170 yylloc = oldyylloc;
10173 // Convert x->y into (*x).y
10176 Type destType = exp.destType;
10178 // DOING THIS LATER NOW...
10179 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10181 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10182 /* TODO: Name Space Fix ups
10183 if(!exp.member.member.classSym)
10184 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10188 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10189 exp.type = memberExp;
10192 ProcessExpressionType(exp);
10199 //ComputeExpression(exp);
10201 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10202 if(classSym && classSym.registered)
10204 if(classSym.registered.type == noHeadClass)
10208 DeclareStruct(classSym.string, false);
10209 FreeSpecifier(exp._class);
10210 exp.type = typeSizeExp;
10211 FullClassNameCat(name, classSym.string, false);
10212 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10216 if(classSym.registered.fixed)
10218 FreeSpecifier(exp._class);
10219 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10220 exp.type = constantExp;
10224 char className[1024];
10225 strcpy(className, "__ecereClass_");
10226 FullClassNameCat(className, classSym.string, true);
10227 MangleClassName(className);
10229 DeclareClass(classSym, className);
10231 FreeExpContents(exp);
10232 exp.type = pointerExp;
10233 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10234 exp.member.member = MkIdentifier("structSize");
10244 // exp.isConstant = true;
10249 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10256 exp.isConstant = true;
10258 DeclareType(type, false, false);
10264 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10266 FreeType(exp.cast.exp.destType);
10267 exp.cast.exp.destType = type;
10269 ProcessExpressionType(exp.cast.exp);
10271 exp.expType = type;
10274 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10275 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10277 void * prev = exp.prev, * next = exp.next;
10278 Type expType = exp.cast.exp.destType;
10279 Expression castExp = exp.cast.exp;
10280 Type destType = exp.destType;
10282 if(expType) expType.refCount++;
10284 //FreeType(exp.destType);
10285 FreeType(exp.expType);
10286 FreeTypeName(exp.cast.typeName);
10289 FreeType(exp.expType);
10290 FreeType(exp.destType);
10292 exp.expType = expType;
10293 exp.destType = destType;
10303 exp.isConstant = exp.cast.exp.isConstant;
10308 case extensionInitializerExp:
10310 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10311 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10312 // ProcessInitializer(exp.initializer.initializer, type);
10313 exp.expType = type;
10318 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10319 ProcessExpressionType(exp.vaArg.exp);
10320 exp.expType = type;
10326 exp.isConstant = true;
10328 FreeType(exp.cond.cond.destType);
10329 exp.cond.cond.destType = MkClassType("bool");
10330 exp.cond.cond.destType.truth = true;
10331 ProcessExpressionType(exp.cond.cond);
10332 if(!exp.cond.cond.isConstant)
10333 exp.isConstant = false;
10334 for(e = exp.cond.exp->first; e; e = e.next)
10338 FreeType(e.destType);
10339 e.destType = exp.destType;
10340 if(e.destType) e.destType.refCount++;
10342 ProcessExpressionType(e);
10345 exp.expType = e.expType;
10346 if(e.expType) e.expType.refCount++;
10349 exp.isConstant = false;
10352 FreeType(exp.cond.elseExp.destType);
10353 // Added this check if we failed to find an expType
10354 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10357 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10359 if(exp.cond.elseExp.destType)
10360 exp.cond.elseExp.destType.refCount++;
10361 ProcessExpressionType(exp.cond.elseExp);
10363 // FIXED THIS: Was done before calling process on elseExp
10364 if(!exp.cond.elseExp.isConstant)
10365 exp.isConstant = false;
10368 case extensionCompoundExp:
10370 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10372 Statement last = exp.compound.compound.statements->last;
10373 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10375 ((Expression)last.expressions->last).destType = exp.destType;
10377 exp.destType.refCount++;
10379 ProcessStatement(exp.compound);
10380 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10382 exp.expType.refCount++;
10388 Specifier spec = exp._classExp.specifiers->first;
10389 if(spec && spec.type == nameSpecifier)
10391 exp.expType = MkClassType(spec.name);
10392 exp.expType.kind = subClassType;
10393 exp.byReference = true;
10397 exp.expType = MkClassType("ecere::com::Class");
10398 exp.byReference = true;
10404 Class _class = thisClass ? thisClass : currentClass;
10407 Identifier id = exp.classData.id;
10408 char structName[1024];
10409 Expression classExp;
10410 strcpy(structName, "__ecereClassData_");
10411 FullClassNameCat(structName, _class.fullName, false);
10412 exp.type = pointerExp;
10413 exp.member.member = id;
10414 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10415 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10417 classExp = MkExpIdentifier(MkIdentifier("class"));
10419 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10420 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10421 MkExpBrackets(MkListOne(MkExpOp(
10422 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10423 MkExpMember(classExp, MkIdentifier("data"))), '+',
10424 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10427 ProcessExpressionType(exp);
10435 char * typeString = null;
10436 char typeStringBuf[1024];
10437 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10438 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10440 Class templateClass = exp.destType._class.registered;
10441 typeString = templateClass.templateArgs[2].dataTypeString;
10445 // Guess type from expressions in the array
10447 for(e = exp.list->first; e; e = e.next)
10449 ProcessExpressionType(e);
10452 if(!type) { type = e.expType; type.refCount++; }
10455 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10456 if(!MatchTypeExpression(e, type, null, false))
10462 e = exp.list->first;
10463 ProcessExpressionType(e);
10466 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10467 if(!MatchTypeExpression(e, type, null, false))
10469 FreeType(e.expType);
10480 FreeType(e.expType);
10487 typeStringBuf[0] = '\0';
10488 PrintTypeNoConst(type, typeStringBuf, false, true);
10489 typeString = typeStringBuf;
10497 (Container)& (struct BuiltInContainer)
10499 ._vTbl = class(BuiltInContainer)._vTbl,
10500 ._class = class(BuiltInContainer),
10502 .data = (int[]){ 1, 7, 3, 4, 5 },
10504 .type = class(int),
10507 char templateString[1024];
10508 OldList * initializers = MkList();
10509 OldList * structInitializers = MkList();
10510 OldList * specs = MkList();
10512 Declarator decl = SpecDeclFromString(typeString, specs, null);
10513 sprintf(templateString, "Container<%s>", typeString);
10518 type = ProcessTypeString(typeString, false);
10519 while(e = exp.list->first)
10521 exp.list->Remove(e);
10524 ProcessExpressionType(e);
10525 ListAdd(initializers, MkInitializerAssignment(e));
10531 DeclareStruct("ecere::com::BuiltInContainer", false);
10533 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10534 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10535 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10536 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10537 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10538 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10539 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10540 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10541 MkInitializerList(initializers))));
10542 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10543 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10544 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10545 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10546 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10547 exp.expType = ProcessTypeString(templateString, false);
10548 exp.type = bracketsExp;
10549 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10551 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10552 MkInitializerList(structInitializers)))));
10553 ProcessExpressionType(expExt);
10557 exp.expType = ProcessTypeString("Container", false);
10558 Compiler_Error($"Couldn't determine type of array elements\n");
10564 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10566 FreeType(exp.expType);
10567 exp.expType = ReplaceThisClassType(thisClass);
10570 // Resolve structures here
10571 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10573 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10574 // TODO: Fix members reference...
10577 if(exp.expType.kind != enumType)
10580 String enumName = CopyString(exp.expType.enumName);
10582 // Fixed a memory leak on self-referencing C structs typedefs
10583 // by instantiating a new type rather than simply copying members
10584 // into exp.expType
10585 FreeType(exp.expType);
10586 exp.expType = Type { };
10587 exp.expType.kind = symbol.type.kind;
10588 exp.expType.refCount++;
10589 exp.expType.enumName = enumName;
10591 exp.expType.members = symbol.type.members;
10592 for(member = symbol.type.members.first; member; member = member.next)
10598 for(member = symbol.type.members.first; member; member = member.next)
10600 NamedLink value { name = CopyString(member.name) };
10601 exp.expType.members.Add(value);
10608 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10609 else if(exp.destType && !exp.destType.keepCast)
10611 if(!CheckExpressionType(exp, exp.destType, false))
10613 if(!exp.destType.count || unresolved)
10618 if(exp.destType.kind != ellipsisType)
10624 char expString[10240];
10625 expString[0] = '\0';
10627 PrintType(exp.destType, type2, false, true);
10629 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10631 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10632 else if(exp.type != dummyExp)
10633 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10638 char expString[10240] ;
10639 expString[0] = '\0';
10640 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10643 Compiler_Error($"unresolved identifier %s\n", expString);
10644 else if(exp.type != dummyExp)
10645 Compiler_Error($"couldn't determine type of %s\n", expString);
10656 PrintType(exp.expType, type1, false, true);
10657 PrintType(exp.destType, type2, false, true);
10660 //CheckExpressionType(exp, exp.destType, false);
10662 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10663 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10664 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10667 char expString[10240];
10668 expString[0] = '\0';
10669 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10672 CheckExpressionType(exp, exp.destType, false);
10674 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10675 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10676 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10678 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10679 FreeType(exp.expType);
10680 exp.destType.refCount++;
10681 exp.expType = exp.destType;
10686 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10688 Expression newExp { };
10689 char typeString[1024];
10690 OldList * specs = MkList();
10693 typeString[0] = '\0';
10697 if(exp.expType) exp.expType.refCount++;
10698 if(exp.expType) exp.expType.refCount++;
10699 exp.type = castExp;
10700 newExp.destType = exp.expType;
10702 PrintType(exp.expType, typeString, false, false);
10703 decl = SpecDeclFromString(typeString, specs, null);
10705 exp.cast.typeName = MkTypeName(specs, decl);
10706 exp.cast.exp = newExp;
10709 else if(unresolved)
10711 if(exp.identifier._class && exp.identifier._class.name)
10712 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10713 else if(exp.identifier.string && exp.identifier.string[0])
10714 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10716 else if(!exp.expType && exp.type != dummyExp)
10718 char expString[10240];
10719 expString[0] = '\0';
10720 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10721 Compiler_Error($"couldn't determine type of %s\n", expString);
10724 // Let's try to support any_object & typed_object here:
10726 ApplyAnyObjectLogic(exp);
10728 // Mark nohead classes as by reference, unless we're casting them to an integral type
10729 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10730 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10731 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10732 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10734 exp.byReference = true;
10736 yylloc = oldyylloc;
10739 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10741 // THIS CODE WILL FIND NEXT MEMBER...
10744 *curMember = (*curMember).next;
10746 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10748 *curMember = subMemberStack[--(*subMemberStackPos)];
10749 *curMember = (*curMember).next;
10752 // SKIP ALL PROPERTIES HERE...
10753 while((*curMember) && (*curMember).isProperty)
10754 *curMember = (*curMember).next;
10756 if(subMemberStackPos)
10758 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10760 subMemberStack[(*subMemberStackPos)++] = *curMember;
10762 *curMember = (*curMember).members.first;
10763 while(*curMember && (*curMember).isProperty)
10764 *curMember = (*curMember).next;
10772 if(subMemberStackPos && *subMemberStackPos)
10774 *curMember = subMemberStack[--(*subMemberStackPos)];
10775 *curMember = (*curMember).next;
10779 Class lastCurClass = *curClass;
10781 if(*curClass == _class) break; // REACHED THE END
10783 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10784 *curMember = (*curClass).membersAndProperties.first;
10787 while((*curMember) && (*curMember).isProperty)
10788 *curMember = (*curMember).next;
10789 if(subMemberStackPos)
10791 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10793 subMemberStack[(*subMemberStackPos)++] = *curMember;
10795 *curMember = (*curMember).members.first;
10796 while(*curMember && (*curMember).isProperty)
10797 *curMember = (*curMember).next;
10805 static void ProcessInitializer(Initializer init, Type type)
10809 case expInitializer:
10810 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10812 // TESTING THIS FOR SHUTTING = 0 WARNING
10813 if(init.exp && !init.exp.destType)
10815 FreeType(init.exp.destType);
10816 init.exp.destType = type;
10817 if(type) type.refCount++;
10821 ProcessExpressionType(init.exp);
10822 init.isConstant = init.exp.isConstant;
10828 Expression exp = init.exp;
10829 Instantiation inst = exp.instance;
10830 MembersInit members;
10832 init.type = listInitializer;
10833 init.list = MkList();
10837 for(members = inst.members->first; members; members = members.next)
10839 if(members.type == dataMembersInit)
10842 for(member = members.dataMembers->first; member; member = member.next)
10844 ListAdd(init.list, member.initializer);
10845 member.initializer = null;
10848 // Discard all MembersInitMethod
10851 FreeExpression(exp);
10853 case listInitializer:
10856 Type initializerType = null;
10857 Class curClass = null;
10858 DataMember curMember = null;
10859 DataMember subMemberStack[256];
10860 int subMemberStackPos = 0;
10862 if(type && type.kind == arrayType)
10863 initializerType = Dereference(type);
10864 else if(type && (type.kind == structType || type.kind == unionType))
10865 initializerType = type.members.first;
10867 for(i = init.list->first; i; i = i.next)
10869 if(type && type.kind == classType && type._class && type._class.registered)
10871 // 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)
10872 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10873 // TODO: Generate error on initializing a private data member this way from another module...
10876 if(!curMember.dataType)
10877 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10878 initializerType = curMember.dataType;
10881 ProcessInitializer(i, initializerType);
10882 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10883 initializerType = initializerType.next;
10885 init.isConstant = false;
10888 if(type && type.kind == arrayType)
10889 FreeType(initializerType);
10891 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10893 Compiler_Error($"Assigning list initializer to non list\n");
10900 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10904 case baseSpecifier:
10906 if(spec.specifier == THISCLASS)
10910 spec.type = nameSpecifier;
10911 spec.name = ReplaceThisClass(thisClass);
10912 spec.symbol = FindClass(spec.name);
10913 ProcessSpecifier(spec, declareStruct);
10918 case nameSpecifier:
10920 Symbol symbol = FindType(curContext, spec.name);
10922 DeclareType(symbol.type, true, true);
10923 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10924 DeclareStruct(spec.name, false);
10927 case enumSpecifier:
10932 for(e = spec.list->first; e; e = e.next)
10935 ProcessExpressionType(e.exp);
10940 case structSpecifier:
10941 case unionSpecifier:
10943 if(spec.definitions)
10946 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10948 ProcessClass(spec.definitions, symbol);
10951 for(def = spec.definitions->first; def; def = def.next)
10953 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10954 ProcessDeclaration(def.decl);
10961 case classSpecifier:
10963 Symbol classSym = FindClass(spec.name);
10964 if(classSym && classSym.registered && classSym.registered.type == structClass)
10965 DeclareStruct(spec.name, false);
10973 static void ProcessDeclarator(Declarator decl)
10977 case identifierDeclarator:
10978 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10980 FreeSpecifier(decl.identifier._class);
10981 decl.identifier._class = null;
10984 case arrayDeclarator:
10986 ProcessExpressionType(decl.array.exp);
10987 case structDeclarator:
10988 case bracketsDeclarator:
10989 case functionDeclarator:
10990 case pointerDeclarator:
10991 case extendedDeclarator:
10992 case extendedDeclaratorEnd:
10993 if(decl.declarator)
10994 ProcessDeclarator(decl.declarator);
10995 if(decl.type == functionDeclarator)
10997 Identifier id = GetDeclId(decl);
10998 if(id && id._class)
11002 qualifiers = MkListOne(id._class);
11005 if(!decl.function.parameters)
11006 decl.function.parameters = MkList();
11007 decl.function.parameters->Insert(null, param);
11010 if(decl.function.parameters)
11014 for(param = decl.function.parameters->first; param; param = param.next)
11016 if(param.qualifiers && param.qualifiers->first)
11018 Specifier spec = param.qualifiers->first;
11019 if(spec && spec.specifier == TYPED_OBJECT)
11021 Declarator d = param.declarator;
11024 qualifiers = MkListOne(MkSpecifier(VOID));
11025 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11028 FreeList(param.qualifiers, FreeSpecifier);
11030 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11031 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11033 decl.function.parameters->Insert(param, newParam);
11036 else if(spec && spec.specifier == ANY_OBJECT)
11038 Declarator d = param.declarator;
11040 FreeList(param.qualifiers, FreeSpecifier);
11042 param.qualifiers = MkListOne(MkSpecifier(VOID));
11043 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11045 else if(spec.specifier == THISCLASS)
11049 spec.type = nameSpecifier;
11050 spec.name = ReplaceThisClass(thisClass);
11051 spec.symbol = FindClass(spec.name);
11052 ProcessSpecifier(spec, false);
11057 if(param.declarator)
11058 ProcessDeclarator(param.declarator);
11066 static void ProcessDeclaration(Declaration decl)
11071 case initDeclaration:
11073 bool declareStruct = false;
11075 lineNum = decl.pos.line;
11076 column = decl.pos.col;
11079 if(decl.declarators)
11083 for(d = decl.declarators->first; d; d = d.next)
11085 Type type, subType;
11086 ProcessDeclarator(d.declarator);
11088 type = ProcessType(decl.specifiers, d.declarator);
11092 ProcessInitializer(d.initializer, type);
11094 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11096 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11097 d.initializer.exp.type == instanceExp)
11099 if(type.kind == classType && type._class ==
11100 d.initializer.exp.expType._class)
11102 Instantiation inst = d.initializer.exp.instance;
11103 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11105 d.initializer.exp.instance = null;
11106 if(decl.specifiers)
11107 FreeList(decl.specifiers, FreeSpecifier);
11108 FreeList(decl.declarators, FreeInitDeclarator);
11112 decl.type = instDeclaration;
11117 for(subType = type; subType;)
11119 if(subType.kind == classType)
11121 declareStruct = true;
11124 else if(subType.kind == pointerType)
11126 else if(subType.kind == arrayType)
11127 subType = subType.arrayType;
11137 if(decl.specifiers)
11140 for(s = decl.specifiers->first; s; s = s.next)
11142 ProcessSpecifier(s, declareStruct);
11147 case instDeclaration:
11149 ProcessInstantiationType(decl.inst);
11152 case structDeclaration:
11156 bool declareStruct = false;
11158 if(decl.declarators)
11160 for(d = decl.declarators->first; d; d = d.next)
11162 Type type = ProcessType(decl.specifiers, d.declarator);
11164 ProcessDeclarator(d);
11165 for(subType = type; subType;)
11167 if(subType.kind == classType)
11169 declareStruct = true;
11172 else if(subType.kind == pointerType)
11174 else if(subType.kind == arrayType)
11175 subType = subType.arrayType;
11182 if(decl.specifiers)
11184 for(spec = decl.specifiers->first; spec; spec = spec.next)
11185 ProcessSpecifier(spec, declareStruct);
11192 static FunctionDefinition curFunction;
11194 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11196 char propName[1024], propNameM[1024];
11197 char getName[1024], setName[1024];
11200 DeclareProperty(prop, setName, getName);
11202 // eInstance_FireWatchers(object, prop);
11203 strcpy(propName, "__ecereProp_");
11204 FullClassNameCat(propName, prop._class.fullName, false);
11205 strcat(propName, "_");
11206 // strcat(propName, prop.name);
11207 FullClassNameCat(propName, prop.name, true);
11208 MangleClassName(propName);
11210 strcpy(propNameM, "__ecerePropM_");
11211 FullClassNameCat(propNameM, prop._class.fullName, false);
11212 strcat(propNameM, "_");
11213 // strcat(propNameM, prop.name);
11214 FullClassNameCat(propNameM, prop.name, true);
11215 MangleClassName(propNameM);
11217 if(prop.isWatchable)
11220 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11221 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11222 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11225 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11226 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11227 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11233 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11234 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11235 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11238 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11239 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11240 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11243 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11244 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11245 curFunction.propSet.fireWatchersDone = true;
11248 static void ProcessStatement(Statement stmt)
11252 lineNum = stmt.pos.line;
11253 column = stmt.pos.col;
11258 ProcessStatement(stmt.labeled.stmt);
11261 // This expression should be constant...
11262 if(stmt.caseStmt.exp)
11264 FreeType(stmt.caseStmt.exp.destType);
11265 stmt.caseStmt.exp.destType = curSwitchType;
11266 if(curSwitchType) curSwitchType.refCount++;
11267 ProcessExpressionType(stmt.caseStmt.exp);
11268 ComputeExpression(stmt.caseStmt.exp);
11270 if(stmt.caseStmt.stmt)
11271 ProcessStatement(stmt.caseStmt.stmt);
11275 if(stmt.compound.context)
11280 Statement prevCompound = curCompound;
11281 Context prevContext = curContext;
11283 if(!stmt.compound.isSwitch)
11284 curCompound = stmt;
11285 curContext = stmt.compound.context;
11287 if(stmt.compound.declarations)
11289 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11290 ProcessDeclaration(decl);
11292 if(stmt.compound.statements)
11294 for(s = stmt.compound.statements->first; s; s = s.next)
11295 ProcessStatement(s);
11298 curContext = prevContext;
11299 curCompound = prevCompound;
11303 case expressionStmt:
11306 if(stmt.expressions)
11308 for(exp = stmt.expressions->first; exp; exp = exp.next)
11309 ProcessExpressionType(exp);
11317 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11318 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11319 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11320 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11322 ProcessExpressionType(exp);
11324 if(stmt.ifStmt.stmt)
11325 ProcessStatement(stmt.ifStmt.stmt);
11326 if(stmt.ifStmt.elseStmt)
11327 ProcessStatement(stmt.ifStmt.elseStmt);
11332 Type oldSwitchType = curSwitchType;
11333 if(stmt.switchStmt.exp)
11336 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11346 e.exp.destType = destType;
11349 ProcessExpressionType(exp);
11352 curSwitchType = exp.expType;
11355 ProcessStatement(stmt.switchStmt.stmt);
11356 curSwitchType = oldSwitchType;
11361 if(stmt.whileStmt.exp)
11365 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11366 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11367 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11368 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11370 ProcessExpressionType(exp);
11373 if(stmt.whileStmt.stmt)
11374 ProcessStatement(stmt.whileStmt.stmt);
11379 if(stmt.doWhile.exp)
11383 if(stmt.doWhile.exp->last)
11385 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11386 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11387 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11389 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11391 ProcessExpressionType(exp);
11394 if(stmt.doWhile.stmt)
11395 ProcessStatement(stmt.doWhile.stmt);
11401 if(stmt.forStmt.init)
11402 ProcessStatement(stmt.forStmt.init);
11404 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11406 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11407 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11408 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11411 if(stmt.forStmt.check)
11412 ProcessStatement(stmt.forStmt.check);
11413 if(stmt.forStmt.increment)
11415 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11416 ProcessExpressionType(exp);
11419 if(stmt.forStmt.stmt)
11420 ProcessStatement(stmt.forStmt.stmt);
11425 Identifier id = stmt.forEachStmt.id;
11426 OldList * exp = stmt.forEachStmt.exp;
11427 OldList * filter = stmt.forEachStmt.filter;
11428 Statement block = stmt.forEachStmt.stmt;
11429 char iteratorType[1024];
11432 bool isBuiltin = exp && exp->last &&
11433 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11434 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11435 Expression arrayExp;
11436 char * typeString = null;
11437 int builtinCount = 0;
11439 for(e = exp ? exp->first : null; e; e = e.next)
11443 FreeType(e.destType);
11444 e.destType = ProcessTypeString("Container", false);
11446 if(!isBuiltin || e.next)
11447 ProcessExpressionType(e);
11450 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11451 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11452 eClass_IsDerived(source._class.registered, containerClass)))
11454 Class _class = source ? source._class.registered : null;
11456 Expression expIt = null;
11457 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11458 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11459 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11460 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11461 stmt.type = compoundStmt;
11463 stmt.compound.context = Context { };
11464 stmt.compound.context.parent = curContext;
11465 curContext = stmt.compound.context;
11467 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11469 Class mapClass = eSystem_FindClass(privateModule, "Map");
11470 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11471 isCustomAVLTree = true;
11472 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11474 else if(eClass_IsDerived(source._class.registered, mapClass))
11477 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11478 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11480 Class listClass = eSystem_FindClass(privateModule, "List");
11482 isList = eClass_IsDerived(source._class.registered, listClass);
11488 OldList * specs = MkList();
11489 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11490 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11491 stmt.compound.declarations = MkListOne(
11492 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11493 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11494 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11495 MkInitializerAssignment(MkExpBrackets(exp))))));
11500 char typeStringBuf[1024];
11502 // TODO: Merge this code?
11503 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11504 if(((Expression)exp->last).type == castExp)
11506 TypeName typeName = ((Expression)exp->last).cast.typeName;
11508 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11511 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11512 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11513 arrayExp.destType._class.registered.templateArgs)
11515 Class templateClass = arrayExp.destType._class.registered;
11516 typeString = templateClass.templateArgs[2].dataTypeString;
11518 else if(arrayExp.list)
11520 // Guess type from expressions in the array
11522 for(e = arrayExp.list->first; e; e = e.next)
11524 ProcessExpressionType(e);
11527 if(!type) { type = e.expType; type.refCount++; }
11530 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11531 if(!MatchTypeExpression(e, type, null, false))
11537 e = arrayExp.list->first;
11538 ProcessExpressionType(e);
11541 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11542 if(!MatchTypeExpression(e, type, null, false))
11544 FreeType(e.expType);
11555 FreeType(e.expType);
11562 typeStringBuf[0] = '\0';
11563 PrintType(type, typeStringBuf, false, true);
11564 typeString = typeStringBuf;
11570 OldList * initializers = MkList();
11572 OldList * specs = MkList();
11577 builtinCount = arrayExp.list->count;
11578 type = ProcessTypeString(typeString, false);
11579 while(e = arrayExp.list->first)
11581 arrayExp.list->Remove(e);
11584 ProcessExpressionType(e);
11585 ListAdd(initializers, MkInitializerAssignment(e));
11588 delete arrayExp.list;
11590 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11591 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11592 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11594 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11596 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11597 ), MkInitializerList(initializers)))));
11598 FreeList(exp, FreeExpression);
11602 arrayExp.expType = ProcessTypeString("Container", false);
11603 Compiler_Error($"Couldn't determine type of array elements\n");
11608 OldList * specs = MkList();
11610 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11611 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11612 stmt.compound.declarations = MkListOne(
11613 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11614 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11615 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11616 MkInitializerAssignment(MkExpBrackets(exp))))));
11619 else if(isLinkList && !isList)
11622 OldList * specs = MkList();
11623 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11624 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11625 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11626 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11627 MkInitializerAssignment(MkExpBrackets(exp))))));
11629 /*else if(isCustomAVLTree)
11632 OldList * specs = MkList();
11633 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11634 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11635 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11636 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11637 MkInitializerAssignment(MkExpBrackets(exp))))));
11639 else if(_class.templateArgs)
11642 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11644 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11646 stmt.compound.declarations = MkListOne(
11647 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11648 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11649 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11651 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11655 // Reparent sub-contexts in this statement
11659 if(block.compound.context)
11660 block.compound.context.parent = stmt.compound.context;
11663 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11664 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11665 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11666 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11669 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11670 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11673 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11674 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11677 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11678 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11681 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11682 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11685 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11686 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11688 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11691 case expressionStmt:
11697 case badDeclarationStmt:
11698 case fireWatchersStmt:
11699 case stopWatchingStmt:
11706 block = MkIfStmt(filter, block, null);
11710 stmt.compound.statements = MkListOne(MkForStmt(
11711 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11712 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11713 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11714 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11716 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11717 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11718 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11723 //OldList * specs = MkList();
11724 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11726 sprintf(count, "%d", builtinCount);
11728 stmt.compound.statements = MkListOne(MkForStmt(
11729 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11730 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11731 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11732 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11736 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11737 stmt.compound.statements = MkListOne(MkForStmt(
11738 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11739 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11740 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11741 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11744 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11745 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11746 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11748 else if(isLinkList && !isList)
11750 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11751 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11752 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11753 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11755 stmt.compound.statements = MkListOne(MkForStmt(
11756 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11757 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11758 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11763 OldList * specs = MkList();
11764 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11765 stmt.compound.statements = MkListOne(MkForStmt(
11766 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11767 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11768 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11769 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11770 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11773 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11774 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11775 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11777 /*else if(isCustomAVLTree)
11779 stmt.compound.statements = MkListOne(MkForStmt(
11780 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11781 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11782 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11783 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11786 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11787 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11788 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11792 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11793 MkIdentifier("Next")), null)), block));
11795 ProcessExpressionType(expIt);
11796 if(stmt.compound.declarations->first)
11797 ProcessDeclaration(stmt.compound.declarations->first);
11800 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11802 ProcessStatement(stmt);
11803 curContext = stmt.compound.context.parent;
11808 Compiler_Error($"Expression is not a container\n");
11821 if(stmt.expressions)
11823 for(exp = stmt.expressions->first; exp; exp = exp.next)
11827 if(curFunction && !curFunction.type)
11828 curFunction.type = ProcessType(
11829 curFunction.specifiers, curFunction.declarator);
11830 FreeType(exp.destType);
11831 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11832 if(exp.destType) exp.destType.refCount++;
11834 ProcessExpressionType(exp);
11839 case badDeclarationStmt:
11841 ProcessDeclaration(stmt.decl);
11847 if(stmt.asmStmt.inputFields)
11849 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11850 if(field.expression)
11851 ProcessExpressionType(field.expression);
11853 if(stmt.asmStmt.outputFields)
11855 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11856 if(field.expression)
11857 ProcessExpressionType(field.expression);
11859 if(stmt.asmStmt.clobberedFields)
11861 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11863 if(field.expression)
11864 ProcessExpressionType(field.expression);
11871 PropertyWatch propWatch;
11872 OldList * watches = stmt._watch.watches;
11873 Expression object = stmt._watch.object;
11874 Expression watcher = stmt._watch.watcher;
11876 ProcessExpressionType(watcher);
11878 ProcessExpressionType(object);
11882 if(watcher || thisClass)
11884 External external = curExternal;
11885 Context context = curContext;
11887 stmt.type = expressionStmt;
11888 stmt.expressions = MkList();
11890 curExternal = external.prev;
11892 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11894 ClassFunction func;
11895 char watcherName[1024];
11896 Class watcherClass = watcher ?
11897 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11898 External createdExternal;
11900 // Create a declaration above
11901 External externalDecl = MkExternalDeclaration(null);
11902 ast->Insert(curExternal.prev, externalDecl);
11904 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11905 if(propWatch.deleteWatch)
11906 strcat(watcherName, "_delete");
11910 for(propID = propWatch.properties->first; propID; propID = propID.next)
11912 strcat(watcherName, "_");
11913 strcat(watcherName, propID.string);
11917 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11919 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11920 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11921 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11922 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11923 ProcessClassFunctionBody(func, propWatch.compound);
11924 propWatch.compound = null;
11926 //afterExternal = afterExternal ? afterExternal : curExternal;
11928 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11929 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11931 createdExternal.symbol.idCode = external.symbol.idCode;
11933 curExternal = createdExternal;
11934 ProcessFunction(createdExternal.function);
11937 // Create a declaration above
11939 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11940 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11941 externalDecl.declaration = decl;
11942 if(decl.symbol && !decl.symbol.pointerExternal)
11943 decl.symbol.pointerExternal = externalDecl;
11946 if(propWatch.deleteWatch)
11948 OldList * args = MkList();
11949 ListAdd(args, CopyExpression(object));
11950 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11951 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11952 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11956 Class _class = object.expType._class.registered;
11959 for(propID = propWatch.properties->first; propID; propID = propID.next)
11961 char propName[1024];
11962 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11965 char getName[1024], setName[1024];
11966 OldList * args = MkList();
11968 DeclareProperty(prop, setName, getName);
11970 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11971 strcpy(propName, "__ecereProp_");
11972 FullClassNameCat(propName, prop._class.fullName, false);
11973 strcat(propName, "_");
11974 // strcat(propName, prop.name);
11975 FullClassNameCat(propName, prop.name, true);
11977 ListAdd(args, CopyExpression(object));
11978 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11979 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11980 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11982 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11985 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11990 Compiler_Error($"Invalid watched object\n");
11993 curExternal = external;
11994 curContext = context;
11997 FreeExpression(watcher);
11999 FreeExpression(object);
12000 FreeList(watches, FreePropertyWatch);
12003 Compiler_Error($"No observer specified and not inside a _class\n");
12007 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12009 ProcessStatement(propWatch.compound);
12015 case fireWatchersStmt:
12017 OldList * watches = stmt._watch.watches;
12018 Expression object = stmt._watch.object;
12020 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12021 // printf("%X\n", watches);
12022 // printf("%X\n", stmt._watch.watches);
12024 ProcessExpressionType(object);
12029 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12035 stmt.type = expressionStmt;
12036 stmt.expressions = MkList();
12038 // Check if we're inside a property set
12039 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12041 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12045 //Compiler_Error($"No property specified and not inside a property set\n");
12049 for(propID = watches->first; propID; propID = propID.next)
12051 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12054 CreateFireWatcher(prop, object, stmt);
12057 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12062 // Fire all properties!
12065 for(base = _class; base; base = base.base)
12067 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12069 if(prop.isProperty && prop.isWatchable)
12071 CreateFireWatcher(prop, object, stmt);
12078 FreeExpression(object);
12079 FreeList(watches, FreeIdentifier);
12082 Compiler_Error($"Invalid object specified and not inside a class\n");
12086 case stopWatchingStmt:
12088 OldList * watches = stmt._watch.watches;
12089 Expression object = stmt._watch.object;
12090 Expression watcher = stmt._watch.watcher;
12093 ProcessExpressionType(object);
12095 ProcessExpressionType(watcher);
12098 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12100 if(watcher || thisClass)
12106 stmt.type = expressionStmt;
12107 stmt.expressions = MkList();
12112 // eInstance_StopWatching(object, null, watcher);
12114 ListAdd(args, CopyExpression(object));
12115 ListAdd(args, MkExpConstant("0"));
12116 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12117 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12121 for(propID = watches->first; propID; propID = propID.next)
12123 char propName[1024];
12124 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12127 char getName[1024], setName[1024];
12128 OldList * args = MkList();
12130 DeclareProperty(prop, setName, getName);
12132 // eInstance_StopWatching(object, prop, watcher);
12133 strcpy(propName, "__ecereProp_");
12134 FullClassNameCat(propName, prop._class.fullName, false);
12135 strcat(propName, "_");
12136 // strcat(propName, prop.name);
12137 FullClassNameCat(propName, prop.name, true);
12138 MangleClassName(propName);
12140 ListAdd(args, CopyExpression(object));
12141 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12142 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12143 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12146 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12151 FreeExpression(object);
12153 FreeExpression(watcher);
12154 FreeList(watches, FreeIdentifier);
12157 Compiler_Error($"Invalid object specified and not inside a class\n");
12160 Compiler_Error($"No observer specified and not inside a class\n");
12167 static void ProcessFunction(FunctionDefinition function)
12169 Identifier id = GetDeclId(function.declarator);
12170 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12171 Type type = symbol ? symbol.type : null;
12172 Class oldThisClass = thisClass;
12173 Context oldTopContext = topContext;
12175 yylloc = function.loc;
12176 // Process thisClass
12178 if(type && type.thisClass)
12180 Symbol classSym = type.thisClass;
12181 Class _class = type.thisClass.registered;
12182 char className[1024];
12183 char structName[1024];
12184 Declarator funcDecl;
12187 bool typedObject = false;
12189 if(_class && !_class.base)
12191 _class = currentClass;
12192 if(_class && !_class.symbol)
12193 _class.symbol = FindClass(_class.fullName);
12194 classSym = _class ? _class.symbol : null;
12195 typedObject = true;
12198 thisClass = _class;
12200 if(inCompiler && _class)
12202 if(type.kind == functionType)
12204 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12206 //TypeName param = symbol.type.params.first;
12207 Type param = symbol.type.params.first;
12208 symbol.type.params.Remove(param);
12209 //FreeTypeName(param);
12212 if(type.classObjectType != classPointer)
12214 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12215 symbol.type.staticMethod = true;
12216 symbol.type.thisClass = null;
12218 // HIGH DANGER: VERIFYING THIS...
12219 symbol.type.extraParam = false;
12223 strcpy(className, "__ecereClass_");
12224 FullClassNameCat(className, _class.fullName, true);
12226 MangleClassName(className);
12229 FullClassNameCat(structName, _class.fullName, false);
12234 funcDecl = GetFuncDecl(function.declarator);
12237 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12239 TypeName param = funcDecl.function.parameters->first;
12240 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12242 funcDecl.function.parameters->Remove(param);
12243 FreeTypeName(param);
12247 // DANGER: Watch for this... Check if it's a Conversion?
12248 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12250 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12251 if(!function.propertyNoThis)
12253 TypeName thisParam;
12255 if(type.classObjectType != classPointer)
12257 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12258 if(!funcDecl.function.parameters)
12259 funcDecl.function.parameters = MkList();
12260 funcDecl.function.parameters->Insert(null, thisParam);
12265 if(type.classObjectType != classPointer)
12267 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12268 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12271 thisParam = TypeName
12273 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12274 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12276 funcDecl.function.parameters->Insert(null, thisParam);
12281 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12283 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12284 funcDecl = GetFuncDecl(initDecl.declarator);
12287 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12289 TypeName param = funcDecl.function.parameters->first;
12290 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12292 funcDecl.function.parameters->Remove(param);
12293 FreeTypeName(param);
12297 if(type.classObjectType != classPointer)
12299 // DANGER: Watch for this... Check if it's a Conversion?
12300 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12302 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12304 if(!funcDecl.function.parameters)
12305 funcDecl.function.parameters = MkList();
12306 funcDecl.function.parameters->Insert(null, thisParam);
12313 // Add this to the context
12316 if(type.classObjectType != classPointer)
12318 thisSymbol = Symbol
12320 string = CopyString("this");
12321 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12323 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12325 if(typedObject && thisSymbol.type)
12327 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12328 thisSymbol.type.byReference = type.byReference;
12329 thisSymbol.type.typedByReference = type.byReference;
12331 thisSymbol = Symbol { string = CopyString("class") };
12332 function.body.compound.context.symbols.Add(thisSymbol);
12338 // Pointer to class data
12340 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12342 DataMember member = null;
12345 for(base = _class; base && base.type != systemClass; base = base.next)
12347 for(member = base.membersAndProperties.first; member; member = member.next)
12348 if(!member.isProperty)
12354 for(member = _class.membersAndProperties.first; member; member = member.next)
12355 if(!member.isProperty)
12359 char pointerName[1024];
12362 Initializer initializer;
12363 Expression exp, bytePtr;
12365 strcpy(pointerName, "__ecerePointer_");
12366 FullClassNameCat(pointerName, _class.fullName, false);
12368 char className[1024];
12369 strcpy(className, "__ecereClass_");
12370 FullClassNameCat(className, classSym.string, true);
12371 MangleClassName(className);
12374 DeclareClass(classSym, className);
12378 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12383 sprintf(string, "%d", _class.offset);
12384 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12388 // ([bytePtr] + [className]->offset)
12389 exp = QBrackets(MkExpOp(bytePtr, '+',
12390 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12393 // (this ? [exp] : 0)
12394 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12398 kind = pointerType;
12399 type = Type { refCount = 1, kind = voidType };
12404 yylloc = function.body.loc;
12405 // ([structName] *) [exp]
12406 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12407 initializer = MkInitializerAssignment(
12408 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12410 // [structName] * [pointerName] = [initializer];
12411 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12414 Context prevContext = curContext;
12415 curContext = function.body.compound.context;
12417 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12418 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12420 curContext = prevContext;
12424 decl.symbol = null;
12426 if(!function.body.compound.declarations)
12427 function.body.compound.declarations = MkList();
12428 function.body.compound.declarations->Insert(null, decl);
12434 // Loop through the function and replace undeclared identifiers
12435 // which are a member of the class (methods, properties or data)
12436 // by "this.[member]"
12443 FreeSpecifier(id._class);
12446 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12448 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12449 id = GetDeclId(initDecl.declarator);
12451 FreeSpecifier(id._class);
12456 topContext = function.body.compound.context;
12458 FunctionDefinition oldFunction = curFunction;
12459 curFunction = function;
12461 ProcessStatement(function.body);
12463 // If this is a property set and no firewatchers has been done yet, add one here
12464 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12466 Statement prevCompound = curCompound;
12467 Context prevContext = curContext;
12469 Statement fireWatchers = MkFireWatchersStmt(null, null);
12470 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12471 ListAdd(function.body.compound.statements, fireWatchers);
12473 curCompound = function.body;
12474 curContext = function.body.compound.context;
12476 ProcessStatement(fireWatchers);
12478 curContext = prevContext;
12479 curCompound = prevCompound;
12483 curFunction = oldFunction;
12486 if(function.declarator)
12488 ProcessDeclarator(function.declarator);
12491 topContext = oldTopContext;
12492 thisClass = oldThisClass;
12495 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12496 static void ProcessClass(OldList definitions, Symbol symbol)
12499 External external = curExternal;
12500 Class regClass = symbol ? symbol.registered : null;
12502 // Process all functions
12503 for(def = definitions.first; def; def = def.next)
12505 if(def.type == functionClassDef)
12507 if(def.function.declarator)
12508 curExternal = def.function.declarator.symbol.pointerExternal;
12510 curExternal = external;
12512 ProcessFunction((FunctionDefinition)def.function);
12514 else if(def.type == declarationClassDef)
12516 if(def.decl.type == instDeclaration)
12518 thisClass = regClass;
12519 ProcessInstantiationType(def.decl.inst);
12525 Class backThisClass = thisClass;
12526 if(regClass) thisClass = regClass;
12527 ProcessDeclaration(def.decl);
12528 thisClass = backThisClass;
12531 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12533 MemberInit defProperty;
12535 // Add this to the context
12536 Symbol thisSymbol = Symbol
12538 string = CopyString("this");
12539 type = regClass ? MkClassType(regClass.fullName) : null;
12541 globalContext.symbols.Add((BTNode)thisSymbol);
12543 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12545 thisClass = regClass;
12546 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12550 globalContext.symbols.Remove((BTNode)thisSymbol);
12551 FreeSymbol(thisSymbol);
12553 else if(def.type == propertyClassDef && def.propertyDef)
12555 PropertyDef prop = def.propertyDef;
12557 // Add this to the context
12559 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12560 globalContext.symbols.Add(thisSymbol);
12563 thisClass = regClass;
12570 string = CopyString("this");
12571 type = MkClassType(regClass.fullName);
12573 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12576 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12577 ProcessStatement(prop.setStmt);
12585 string = CopyString("this");
12586 type = MkClassType(regClass.fullName);
12588 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12591 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12592 ProcessStatement(prop.getStmt);
12600 string = CopyString("this");
12601 type = MkClassType(regClass.fullName);
12603 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12606 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12607 ProcessStatement(prop.issetStmt);
12613 globalContext.symbols.Remove(thisSymbol);
12614 FreeSymbol(thisSymbol);
12617 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12619 PropertyWatch propertyWatch = def.propertyWatch;
12621 thisClass = regClass;
12622 if(propertyWatch.compound)
12626 string = CopyString("this");
12627 type = regClass ? MkClassType(regClass.fullName) : null;
12630 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12632 curExternal = null;
12633 ProcessStatement(propertyWatch.compound);
12640 void DeclareFunctionUtil(String s)
12642 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12647 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12648 strcpy(name, "__ecereFunction_");
12649 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12650 DeclareFunction(function, name);
12654 void ComputeDataTypes()
12658 External after = null;
12660 currentClass = null;
12662 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12664 for(external = ast->first; external; external = external.next)
12666 if(external.type == declarationExternal)
12668 Declaration decl = external.declaration;
12671 OldList * decls = decl.declarators;
12674 InitDeclarator initDecl = decls->first;
12677 Declarator declarator = initDecl.declarator;
12678 if(declarator && declarator.type == identifierDeclarator)
12680 Identifier id = declarator.identifier;
12681 if(id && id.string)
12683 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12685 external.symbol.id = -1001, external.symbol.idCode = -1001;
12696 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12697 ast->Insert(after, temp);
12698 curExternal = temp;
12700 DeclareFunctionUtil("eSystem_New");
12701 DeclareFunctionUtil("eSystem_New0");
12702 DeclareFunctionUtil("eSystem_Renew");
12703 DeclareFunctionUtil("eSystem_Renew0");
12704 DeclareFunctionUtil("eSystem_Delete");
12705 DeclareFunctionUtil("eClass_GetProperty");
12706 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12708 DeclareStruct("ecere::com::Class", false);
12709 DeclareStruct("ecere::com::Instance", false);
12710 DeclareStruct("ecere::com::Property", false);
12711 DeclareStruct("ecere::com::DataMember", false);
12712 DeclareStruct("ecere::com::Method", false);
12713 DeclareStruct("ecere::com::SerialBuffer", false);
12714 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12718 for(external = ast->first; external; external = external.next)
12720 afterExternal = curExternal = external;
12721 if(external.type == functionExternal)
12723 currentClass = external.function._class;
12724 ProcessFunction(external.function);
12726 // There shouldn't be any _class member access here anyways...
12727 else if(external.type == declarationExternal)
12729 currentClass = null;
12730 ProcessDeclaration(external.declaration);
12732 else if(external.type == classExternal)
12734 ClassDefinition _class = external._class;
12735 currentClass = external.symbol.registered;
12736 if(_class.definitions)
12738 ProcessClass(_class.definitions, _class.symbol);
12742 // Free class data...
12743 ast->Remove(external);
12747 else if(external.type == nameSpaceExternal)
12749 thisNameSpace = external.id.string;
12752 currentClass = null;
12753 thisNameSpace = null;
12755 delete temp.symbol;