4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
37 uint internalValueCounter;
40 Time findSymbolTotalTime;
43 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
44 /*static */public void PrintExpression(Expression exp, char * string)
50 bool backOutputLineNumbers = outputLineNumbers;
51 outputLineNumbers = false;
54 OutputExpression(exp, f);
56 count = strlen(string);
57 count += f.Read(string + count, 1, 1023);
61 outputLineNumbers = backOutputLineNumbers;
65 Type ProcessTemplateParameterType(TemplateParameter param)
67 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
69 // TOFIX: Will need to free this Type
72 if(param.dataTypeString)
73 param.baseType = ProcessTypeString(param.dataTypeString, false);
75 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
77 return param.baseType;
82 bool NeedCast(Type type1, Type type2)
84 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
86 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
91 if(type1.kind == type2.kind)
102 if(type1.passAsTemplate && !type2.passAsTemplate)
104 return type1.isSigned != type2.isSigned;
106 return type1._class != type2._class;
108 return (type1.type && type2.type && type1.type.constant != type2.type.constant) || NeedCast(type1.type, type2.type);
110 return true; //false; ????
116 static void ReplaceClassMembers(Expression exp, Class _class)
118 if(exp.type == identifierExp && exp.identifier)
120 Identifier id = exp.identifier;
122 Symbol symbol = null;
123 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
125 // First, check if the identifier is declared inside the function
126 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
128 symbol = (Symbol)ctx.symbols.FindString(id.string);
133 // If it is not, check if it is a member of the _class
134 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
136 Property prop = eClass_FindProperty(_class, id.string, privateModule);
137 Method method = null;
138 DataMember member = null;
139 ClassProperty classProp = null;
142 method = eClass_FindMethod(_class, id.string, privateModule);
145 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
146 if(!prop && !method && !member)
148 classProp = eClass_FindClassProperty(_class, id.string);
150 if(prop || method || member || classProp)
152 // Replace by this.[member]
153 exp.type = memberExp;
154 exp.member.member = id;
155 exp.member.memberType = unresolvedMember;
156 exp.member.exp = QMkExpId("this");
157 //exp.member.exp.loc = exp.loc;
158 exp.addedThis = true;
160 else if(_class && _class.templateParams.first)
163 for(sClass = _class; sClass; sClass = sClass.base)
165 if(sClass.templateParams.first)
167 ClassTemplateParameter param;
168 for(param = sClass.templateParams.first; param; param = param.next)
170 if(param.type == expression && !strcmp(param.name, id.string))
172 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
177 OldList * specs = MkList();
179 FreeIdentifier(exp.member.member);
181 ProcessExpressionType(argExp);
183 decl = SpecDeclFromString(param.dataTypeString, specs, null);
185 exp.expType = ProcessType(specs, decl);
187 // *[expType] *[argExp]
188 exp.type = bracketsExp;
189 exp.list = MkListOne(MkExpOp(null, '*',
190 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
201 ////////////////////////////////////////////////////////////////////////
202 // PRINTING ////////////////////////////////////////////////////////////
203 ////////////////////////////////////////////////////////////////////////
205 public char * PrintInt(int64 result)
209 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
211 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
212 if(result > MAXINT || result < MININT)
214 return CopyString(temp);
217 public char * PrintUInt(uint64 result)
220 if(result > MAXDWORD)
221 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
222 else if(result > MAXINT)
223 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
225 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
226 return CopyString(temp);
229 public char * PrintInt64(int64 result)
232 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
233 return CopyString(temp);
236 public char * PrintUInt64(uint64 result)
239 if(result > MAXINT64)
240 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
242 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
243 return CopyString(temp);
246 public char * PrintHexUInt(uint64 result)
249 if(result > MAXDWORD)
250 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
252 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
253 if(result > MAXDWORD)
255 return CopyString(temp);
258 public char * PrintHexUInt64(uint64 result)
261 if(result > MAXDWORD)
262 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
264 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
265 return CopyString(temp);
268 public char * PrintShort(short result)
271 sprintf(temp, "%d", (unsigned short)result);
272 return CopyString(temp);
275 public char * PrintUShort(unsigned short result)
279 sprintf(temp, "0x%X", (int)result);
281 sprintf(temp, "%d", (int)result);
282 return CopyString(temp);
285 public char * PrintChar(char result)
288 if(result > 0 && isprint(result))
289 sprintf(temp, "'%c'", result);
291 sprintf(temp, "%d", (int)result);
293 //sprintf(temp, "%#X", result);
294 sprintf(temp, "0x%X", (unsigned char)result);
295 return CopyString(temp);
298 public char * PrintUChar(unsigned char result)
301 sprintf(temp, "0x%X", result);
302 return CopyString(temp);
305 public char * PrintFloat(float result)
311 strcpy(temp, "-inf");
315 else if(result.isNan)
318 strcpy(temp, "-nan");
323 sprintf(temp, "%.16ff", result);
324 return CopyString(temp);
327 public char * PrintDouble(double result)
333 strcpy(temp, "-inf");
337 else if(result.isNan)
340 strcpy(temp, "-nan");
345 sprintf(temp, "%.16f", result);
346 return CopyString(temp);
349 ////////////////////////////////////////////////////////////////////////
350 ////////////////////////////////////////////////////////////////////////
352 //public Operand GetOperand(Expression exp);
354 #define GETVALUE(name, t) \
355 public bool GetOp##name(Operand op2, t * value2) \
357 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
358 else if(op2.kind == intType) *value2 = (t) op2.ui; \
359 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
360 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
361 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
362 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
363 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
364 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
365 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
366 else if(op2.kind == shortType) *value2 = (t) op2.us; \
367 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
368 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
369 else if(op2.kind == floatType) *value2 = (t) op2.f; \
370 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
371 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
376 public bool Get##name(Expression exp, t * value2) \
378 Operand op2 = GetOperand(exp); \
379 return GetOp##name(op2, value2); \
382 // To help the deubugger currently not preprocessing...
385 GETVALUE(Int, HELP(int));
386 GETVALUE(UInt, HELP(unsigned int));
387 GETVALUE(Int64, HELP(int64));
388 GETVALUE(UInt64, HELP(uint64));
389 GETVALUE(IntPtr, HELP(intptr));
390 GETVALUE(UIntPtr, HELP(uintptr));
391 GETVALUE(IntSize, HELP(intsize));
392 GETVALUE(UIntSize, HELP(uintsize));
393 GETVALUE(Short, HELP(short));
394 GETVALUE(UShort, HELP(unsigned short));
395 GETVALUE(Char, HELP(char));
396 GETVALUE(UChar, HELP(unsigned char));
397 GETVALUE(Float, HELP(float));
398 GETVALUE(Double, HELP(double));
400 void ComputeExpression(Expression exp);
402 void ComputeClassMembers(Class _class, bool isMember)
404 DataMember member = isMember ? (DataMember) _class : null;
405 Context context = isMember ? null : SetupTemplatesContext(_class);
406 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
407 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
409 int unionMemberOffset = 0;
413 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
414 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
419 member.memberOffset = 0;
420 if(targetBits < sizeof(void *) * 8)
421 member.structAlignment = 0;
423 else if(targetBits < sizeof(void *) * 8)
424 _class.structAlignment = 0;
426 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
427 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
428 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
430 if(!member && _class.destructionWatchOffset)
431 _class.memberOffset += sizeof(OldList);
433 // To avoid reentrancy...
434 //_class.structSize = -1;
437 DataMember dataMember;
438 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
440 if(!dataMember.isProperty)
442 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
444 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
445 /*if(!dataMember.dataType)
446 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
454 DataMember dataMember;
455 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
457 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
459 if(!isMember && _class.type == bitClass && dataMember.dataType)
461 BitMember bitMember = (BitMember) dataMember;
465 ComputeTypeSize(dataMember.dataType);
467 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
468 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
470 _class.memberOffset = bitMember.pos + bitMember.size;
471 for(d = 0; d<bitMember.size; d++)
477 bitMember.mask = mask << bitMember.pos;
479 else if(dataMember.type == normalMember && dataMember.dataType)
484 // Prevent infinite recursion
485 if(dataMember.dataType.kind != classType ||
486 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
487 _class.type != structClass)))
488 ComputeTypeSize(dataMember.dataType);
490 if(dataMember.dataType.bitFieldCount)
492 bitFields += dataMember.dataType.bitFieldCount;
499 int size = (bitFields + 7) / 8;
503 // TESTING THIS PADDING CODE
506 member.structAlignment = Max(member.structAlignment, alignment);
508 if(member.memberOffset % alignment)
509 member.memberOffset += alignment - (member.memberOffset % alignment);
512 dataMember.offset = member.memberOffset;
513 if(member.type == unionMember)
514 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
517 member.memberOffset += size;
522 // TESTING THIS PADDING CODE
525 _class.structAlignment = Max(_class.structAlignment, alignment);
527 if(_class.memberOffset % alignment)
528 _class.memberOffset += alignment - (_class.memberOffset % alignment);
531 dataMember.offset = _class.memberOffset;
532 _class.memberOffset += size;
536 size = dataMember.dataType.size;
537 alignment = dataMember.dataType.alignment;
542 // TESTING THIS PADDING CODE
545 member.structAlignment = Max(member.structAlignment, alignment);
547 if(member.memberOffset % alignment)
548 member.memberOffset += alignment - (member.memberOffset % alignment);
551 dataMember.offset = member.memberOffset;
552 if(member.type == unionMember)
553 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
556 member.memberOffset += size;
561 // TESTING THIS PADDING CODE
564 _class.structAlignment = Max(_class.structAlignment, alignment);
566 if(_class.memberOffset % alignment)
567 _class.memberOffset += alignment - (_class.memberOffset % alignment);
570 dataMember.offset = _class.memberOffset;
571 _class.memberOffset += size;
578 ComputeClassMembers((Class)dataMember, true);
579 alignment = dataMember.structAlignment;
585 if(member.memberOffset % alignment)
586 member.memberOffset += alignment - (member.memberOffset % alignment);
588 member.structAlignment = Max(member.structAlignment, alignment);
590 dataMember.offset = member.memberOffset;
591 if(member.type == unionMember)
592 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
594 member.memberOffset += dataMember.memberOffset;
600 if(_class.memberOffset % alignment)
601 _class.memberOffset += alignment - (_class.memberOffset % alignment);
602 _class.structAlignment = Max(_class.structAlignment, alignment);
604 dataMember.offset = _class.memberOffset;
605 _class.memberOffset += dataMember.memberOffset;
613 int size = (bitFields + 7) / 8;
617 // TESTING THIS PADDING CODE
620 member.structAlignment = Max(member.structAlignment, alignment);
622 if(member.memberOffset % alignment)
623 member.memberOffset += alignment - (member.memberOffset % alignment);
626 if(member.type == unionMember)
627 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
630 member.memberOffset += size;
635 // TESTING THIS PADDING CODE
638 _class.structAlignment = Max(_class.structAlignment, alignment);
640 if(_class.memberOffset % alignment)
641 _class.memberOffset += alignment - (_class.memberOffset % alignment);
643 _class.memberOffset += size;
648 if(member && member.type == unionMember)
650 member.memberOffset = unionMemberOffset;
655 /*if(_class.type == structClass)
656 _class.size = _class.memberOffset;
660 if(_class.type != bitClass)
663 if(_class.structAlignment)
665 if(_class.memberOffset % _class.structAlignment)
666 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
668 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
672 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
674 if(prop.isProperty && prop.isWatchable)
676 prop.watcherOffset = _class.structSize;
677 _class.structSize += sizeof(OldList);
685 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
687 Class deriv = derivative.data;
689 if(deriv.computeSize)
691 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
692 deriv.offset = /*_class.offset + */_class.structSize;
693 deriv.memberOffset = 0;
694 // ----------------------
696 deriv.structSize = deriv.offset;
698 ComputeClassMembers(deriv, false);
706 FinishTemplatesContext(context);
709 public void ComputeModuleClasses(Module module)
714 for(subModule = module.modules.first; subModule; subModule = subModule.next)
715 ComputeModuleClasses(subModule.data);
716 for(_class = module.classes.first; _class; _class = _class.next)
717 ComputeClassMembers(_class, false);
721 public int ComputeTypeSize(Type type)
723 uint size = type ? type.size : 0;
724 if(!size && type && !type.computing)
726 type.computing = true;
729 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
730 case charType: type.alignment = size = sizeof(char); break;
731 case intType: type.alignment = size = sizeof(int); break;
732 case int64Type: type.alignment = size = sizeof(int64); break;
733 case intPtrType: type.alignment = size = targetBits / 8; break;
734 case intSizeType: type.alignment = size = targetBits / 8; break;
735 case longType: type.alignment = size = sizeof(long); break;
736 case shortType: type.alignment = size = sizeof(short); break;
737 case floatType: type.alignment = size = sizeof(float); break;
738 case doubleType: type.alignment = size = sizeof(double); break;
741 Class _class = type._class ? type._class.registered : null;
743 if(_class && _class.type == structClass)
745 // Ensure all members are properly registered
746 ComputeClassMembers(_class, false);
747 type.alignment = _class.structAlignment;
748 size = _class.structSize;
749 if(type.alignment && size % type.alignment)
750 size += type.alignment - (size % type.alignment);
753 else if(_class && (_class.type == unitClass ||
754 _class.type == enumClass ||
755 _class.type == bitClass))
758 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
759 size = type.alignment = ComputeTypeSize(_class.dataType);
762 size = type.alignment = targetBits / 8; // sizeof(Instance *);
765 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
767 if(type.arraySizeExp)
769 ProcessExpressionType(type.arraySizeExp);
770 ComputeExpression(type.arraySizeExp);
771 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
772 type.arraySizeExp.expType.kind != shortType &&
773 type.arraySizeExp.expType.kind != charType &&
774 type.arraySizeExp.expType.kind != longType &&
775 type.arraySizeExp.expType.kind != int64Type &&
776 type.arraySizeExp.expType.kind != intSizeType &&
777 type.arraySizeExp.expType.kind != intPtrType &&
778 type.arraySizeExp.expType.kind != enumType &&
779 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
781 Location oldLoc = yylloc;
782 // bool isConstant = type.arraySizeExp.isConstant;
783 char expression[10240];
784 expression[0] = '\0';
785 type.arraySizeExp.expType = null;
786 yylloc = type.arraySizeExp.loc;
788 PrintExpression(type.arraySizeExp, expression);
789 Compiler_Error($"Array size not constant int (%s)\n", expression);
792 GetInt(type.arraySizeExp, &type.arraySize);
794 else if(type.enumClass)
796 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
798 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
805 // Unimplemented auto size
809 size = ComputeTypeSize(type.type) * type.arraySize;
811 type.alignment = type.type.alignment;
817 for(member = type.members.first; member; member = member.next)
819 uint addSize = ComputeTypeSize(member);
821 member.offset = size;
822 if(member.alignment && size % member.alignment)
823 member.offset += member.alignment - (size % member.alignment);
824 size = member.offset;
826 type.alignment = Max(type.alignment, member.alignment);
829 if(type.alignment && size % type.alignment)
830 size += type.alignment - (size % type.alignment);
836 for(member = type.members.first; member; member = member.next)
838 uint addSize = ComputeTypeSize(member);
840 member.offset = size;
841 if(member.alignment && size % member.alignment)
842 member.offset += member.alignment - (size % member.alignment);
843 size = member.offset;
845 type.alignment = Max(type.alignment, member.alignment);
846 size = Max(size, addSize);
848 if(type.alignment && size % type.alignment)
849 size += type.alignment - (size % type.alignment);
854 TemplateParameter param = type.templateParameter;
855 Type baseType = ProcessTemplateParameterType(param);
858 size = ComputeTypeSize(baseType);
859 type.alignment = baseType.alignment;
862 type.alignment = size = sizeof(uint64);
867 type.alignment = size = sizeof(enum { test });
872 type.alignment = size = targetBits / 8; //sizeof(void *);
877 type.computing = false;
883 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
885 // This function is in need of a major review when implementing private members etc.
886 DataMember topMember = isMember ? (DataMember) _class : null;
893 Context context = isMember ? null : SetupTemplatesContext(_class);
895 *addedPadding = false;
897 if(!isMember && _class.base)
899 maxSize = _class.structSize;
900 //if(_class.base.type != systemClass) // Commented out with new Instance _class
902 // DANGER: Testing this noHeadClass here...
903 if(_class.type == structClass || _class.type == noHeadClass)
904 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
907 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
908 if(maxSize > baseSize)
916 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
918 if(!member.isProperty)
924 if(member.dataTypeString)
926 OldList * specs = MkList(), * decls = MkList();
929 decl = SpecDeclFromString(member.dataTypeString, specs,
930 MkDeclaratorIdentifier(MkIdentifier(member.name)));
931 ListAdd(decls, MkStructDeclarator(decl, null));
932 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
935 member.dataType = ProcessType(specs, decl);
937 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
940 Type type = ProcessType(specs, decl);
941 DeclareType(member.dataType, false, false);
945 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
946 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
947 DeclareStruct(member.dataType._class.string, false);
950 ComputeTypeSize(member.dataType);
951 size = member.dataType.size;
952 alignment = member.dataType.alignment;
956 if(totalSize % alignment)
957 totalSize += alignment - (totalSize % alignment);
966 OldList * specs = MkList(), * list = MkList();
968 sprintf(id, "__anon%d", anonID++);
971 AddMembers(list, (Class)member, true, &size, topClass, null);
973 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
974 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
975 alignment = member.structAlignment;
979 if(totalSize % alignment)
980 totalSize += alignment - (totalSize % alignment);
990 if(topMember && topMember.type == unionMember)
991 *retSize = Max(*retSize, totalSize);
993 *retSize += totalSize;
995 else if(totalSize < maxSize && _class.type != systemClass)
998 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
999 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1000 if(totalSize + autoPadding < maxSize)
1002 char sizeString[50];
1003 sprintf(sizeString, "%d", maxSize - totalSize);
1004 ListAdd(declarations,
1005 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1006 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1008 *addedPadding = true;
1012 FinishTemplatesContext(context);
1013 return topMember ? topMember.memberID : _class.memberID;
1016 static int DeclareMembers(Class _class, bool isMember)
1018 DataMember topMember = isMember ? (DataMember) _class : null;
1020 Context context = isMember ? null : SetupTemplatesContext(_class);
1022 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1023 DeclareMembers(_class.base, false);
1025 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1027 if(!member.isProperty)
1034 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1035 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1036 DeclareStruct(member.dataType._class.string, false);
1038 if(!member.dataType && member.dataTypeString)
1039 member.dataType = ProcessTypeString(member.dataTypeString, false);
1041 DeclareType(member.dataType, false, false);
1047 DeclareMembers((Class)member, true);
1054 FinishTemplatesContext(context);
1056 return topMember ? topMember.memberID : _class.memberID;
1059 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1063 for(def = definitions->first; def; def = def.next)
1065 if(def.type == declarationClassDef)
1067 Declaration decl = def.decl;
1068 if(decl && decl.specifiers)
1071 bool isStruct = false;
1072 for(spec = decl.specifiers->first; spec; spec = spec.next)
1074 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1076 if(spec.definitions)
1077 IdentifyAnonStructs(spec.definitions);
1083 Declarator d = null;
1084 if(decl.declarators)
1086 for(d = decl.declarators->first; d; d = d.next)
1088 Identifier idDecl = GetDeclId(d);
1096 sprintf(id, "__anon%d", anonID++);
1097 if(!decl.declarators)
1098 decl.declarators = MkList();
1099 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1107 void DeclareStruct(const char * name, bool skipNoHead)
1109 External external = null;
1110 Symbol classSym = FindClass(name);
1112 if(!inCompiler || !classSym) return;
1114 // We don't need any declaration for bit classes...
1115 if(classSym.registered &&
1116 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1119 /*if(classSym.registered.templateClass)
1120 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1123 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1125 // Add typedef struct
1127 OldList * specifiers, * declarators;
1128 OldList * declarations = null;
1129 char structName[1024];
1130 Specifier spec = null;
1131 external = (classSym.registered && classSym.registered.type == structClass) ?
1132 classSym.pointerExternal : classSym.structExternal;
1134 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1135 // Moved this one up because DeclareClass done later will need it
1137 classSym.declaring++;
1139 if(strchr(classSym.string, '<'))
1141 if(classSym.registered.templateClass)
1143 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1144 classSym.declaring--;
1150 DeclareMembers(classSym.registered, false);
1153 FullClassNameCat(structName, name, false);
1155 if(external && external.declaration && external.declaration.specifiers)
1157 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1159 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1165 external = MkExternalDeclaration(null);*/
1167 if(!skipNoHead && (!spec || !spec.definitions))
1169 bool addedPadding = false;
1170 classSym.declaredStructSym = true;
1172 declarations = MkList();
1174 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1176 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1177 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1179 if(!declarations->count || (declarations->count == 1 && addedPadding))
1181 FreeList(declarations, FreeClassDef);
1182 declarations = null;
1185 if(skipNoHead || declarations)
1190 spec.definitions = declarations;
1192 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1195 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1198 if(classSym.structExternal)
1199 ast->Move(classSym.structExternal, curExternal.prev);
1200 ast->Move(classSym.pointerExternal, curExternal.prev);
1202 classSym.id = curExternal.symbol.idCode;
1203 classSym.idCode = curExternal.symbol.idCode;
1204 // external = classSym.pointerExternal;
1205 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1211 external = MkExternalDeclaration(null);
1213 specifiers = MkList();
1214 declarators = MkList();
1215 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1218 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1219 ListAdd(declarators, MkInitDeclarator(d, null));
1221 external.declaration = decl = MkDeclaration(specifiers, declarators);
1222 if(decl.symbol && !decl.symbol.pointerExternal)
1223 decl.symbol.pointerExternal = external;
1225 // For simple classes, keep the declaration as the external to move around
1226 if(classSym.registered && classSym.registered.type == structClass)
1228 char className[1024];
1229 strcpy(className, "__ecereClass_");
1230 FullClassNameCat(className, classSym.string, true);
1231 MangleClassName(className);
1234 DeclareClass(classSym, className);
1236 external.symbol = classSym;
1237 classSym.pointerExternal = external;
1238 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1239 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1243 char className[1024];
1244 strcpy(className, "__ecereClass_");
1245 FullClassNameCat(className, classSym.string, true);
1246 MangleClassName(className);
1248 // TOFIX: TESTING THIS...
1249 classSym.structExternal = external;
1250 DeclareClass(classSym, className);
1251 external.symbol = classSym;
1255 ast->Insert(curExternal ? curExternal.prev : null, external);
1259 classSym.declaring--;
1263 if(classSym.structExternal && classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1266 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1268 IdentifyAnonStructs(spec.definitions);
1272 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1274 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1275 // Moved this one up because DeclareClass done later will need it
1278 classSym.declaring++;
1282 if(classSym.registered)
1283 DeclareMembers(classSym.registered, false);
1286 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1289 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1292 if(classSym.structExternal)
1293 ast->Move(classSym.structExternal, curExternal.prev);
1294 ast->Move(classSym.pointerExternal, curExternal.prev);
1296 classSym.id = curExternal.symbol.idCode;
1297 classSym.idCode = curExternal.symbol.idCode;
1298 // external = classSym.pointerExternal;
1299 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1302 classSym.declaring--;
1308 void DeclareProperty(Property prop, char * setName, char * getName)
1310 Symbol symbol = prop.symbol;
1312 strcpy(setName, "__ecereProp_");
1313 FullClassNameCat(setName, prop._class.fullName, false);
1314 strcat(setName, "_Set_");
1315 // strcat(setName, prop.name);
1316 FullClassNameCat(setName, prop.name, true);
1317 MangleClassName(setName);
1319 strcpy(getName, "__ecereProp_");
1320 FullClassNameCat(getName, prop._class.fullName, false);
1321 strcat(getName, "_Get_");
1322 FullClassNameCat(getName, prop.name, true);
1323 // strcat(getName, prop.name);
1325 // To support "char *" property
1326 MangleClassName(getName);
1328 if(prop._class.type == structClass)
1329 DeclareStruct(prop._class.fullName, false);
1331 if(!symbol || curExternal.symbol.idCode < symbol.id)
1333 bool imported = false;
1334 bool dllImport = false;
1336 if(!symbol || symbol._import)
1341 if(!prop._class.symbol)
1342 prop._class.symbol = FindClass(prop._class.fullName);
1343 classSym = prop._class.symbol;
1344 if(classSym && !classSym._import)
1346 ModuleImport module;
1348 if(prop._class.module)
1349 module = FindModule(prop._class.module);
1351 module = mainModule;
1353 classSym._import = ClassImport
1355 name = CopyString(prop._class.fullName);
1356 isRemote = prop._class.isRemote;
1358 module.classes.Add(classSym._import);
1360 symbol = prop.symbol = Symbol { };
1361 symbol._import = (ClassImport)PropertyImport
1363 name = CopyString(prop.name);
1364 isVirtual = false; //prop.isVirtual;
1365 hasSet = prop.Set ? true : false;
1366 hasGet = prop.Get ? true : false;
1369 classSym._import.properties.Add(symbol._import);
1372 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1373 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1374 prop._class.module.importType != staticImport)
1380 Context context = SetupTemplatesContext(prop._class);
1381 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1382 FinishTemplatesContext(context);
1388 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1391 OldList * specifiers, * declarators;
1396 Declarator typeDecl;
1397 bool simple = false;
1399 specifiers = MkList();
1400 declarators = MkList();
1403 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1404 MkDeclaratorIdentifier(MkIdentifier("this"))));
1406 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1409 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1412 Context context = SetupTemplatesContext(prop._class);
1413 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1414 FinishTemplatesContext(context);
1417 // Make sure the simple _class's type is declared
1418 for(spec = specifiers->first; spec; spec = spec.next)
1420 if(spec.type == nameSpecifier /*SpecifierClass*/)
1422 if((!typeDecl || typeDecl.type == identifierDeclarator))
1424 Symbol classSym = spec.symbol; // FindClass(spec.name);
1425 symbol._class = classSym.registered;
1426 if(classSym.registered && classSym.registered.type == structClass)
1428 DeclareStruct(spec.name, false);
1436 d = PlugDeclarator(typeDecl, d);
1439 ListAdd(params, MkTypeName(specifiers,
1440 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1441 specifiers = MkList();
1444 d = MkDeclaratorFunction(d, params);
1448 specifiers->Insert(null, MkSpecifier(EXTERN));
1449 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1450 specifiers->Insert(null, MkSpecifier(STATIC));
1452 ListAdd(specifiers, MkSpecifier(VOID));
1454 ListAdd(declarators, MkInitDeclarator(d, null));
1456 decl = MkDeclaration(specifiers, declarators);
1458 external = MkExternalDeclaration(decl);
1459 ast->Insert(curExternal.prev, external);
1460 external.symbol = symbol;
1461 symbol.externalGet = external;
1463 ReplaceThisClassSpecifiers(specifiers, prop._class);
1466 FreeDeclarator(typeDecl);
1470 // Move declaration higher...
1471 ast->Move(symbol.externalGet, curExternal.prev);
1478 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1481 OldList * specifiers, * declarators;
1486 Declarator typeDecl;
1488 declarators = MkList();
1491 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1492 if(!prop.conversion || prop._class.type == structClass)
1494 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1495 MkDeclaratorIdentifier(MkIdentifier("this"))));
1498 specifiers = MkList();
1501 Context context = SetupTemplatesContext(prop._class);
1502 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1503 MkDeclaratorIdentifier(MkIdentifier("value")));
1504 FinishTemplatesContext(context);
1506 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1507 specifiers->Insert(null, MkSpecifier(CONST));
1509 ListAdd(params, MkTypeName(specifiers, d));
1511 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1514 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1515 d = MkDeclaratorFunction(d, params);
1517 // Make sure the simple _class's type is declared
1518 for(spec = specifiers->first; spec; spec = spec.next)
1520 if(spec.type == nameSpecifier /*SpecifierClass*/)
1522 if((!typeDecl || typeDecl.type == identifierDeclarator))
1524 Symbol classSym = spec.symbol; // FindClass(spec.name);
1525 symbol._class = classSym.registered;
1526 if(classSym.registered && classSym.registered.type == structClass)
1527 DeclareStruct(spec.name, false);
1532 ListAdd(declarators, MkInitDeclarator(d, null));
1534 specifiers = MkList();
1537 specifiers->Insert(null, MkSpecifier(EXTERN));
1538 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1539 specifiers->Insert(null, MkSpecifier(STATIC));
1541 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1542 if(!prop.conversion || prop._class.type == structClass)
1543 ListAdd(specifiers, MkSpecifier(VOID));
1545 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1547 decl = MkDeclaration(specifiers, declarators);
1549 external = MkExternalDeclaration(decl);
1550 ast->Insert(curExternal.prev, external);
1551 external.symbol = symbol;
1552 symbol.externalSet = external;
1554 ReplaceThisClassSpecifiers(specifiers, prop._class);
1558 // Move declaration higher...
1559 ast->Move(symbol.externalSet, curExternal.prev);
1563 // Property (for Watchers)
1564 if(!symbol.externalPtr)
1568 OldList * specifiers = MkList();
1569 char propName[1024];
1572 specifiers->Insert(null, MkSpecifier(EXTERN));
1574 specifiers->Insert(null, MkSpecifier(STATIC));
1576 ListAdd(specifiers, MkSpecifierName("Property"));
1578 strcpy(propName, "__ecereProp_");
1579 FullClassNameCat(propName, prop._class.fullName, false);
1580 strcat(propName, "_");
1581 FullClassNameCat(propName, prop.name, true);
1582 // strcat(propName, prop.name);
1583 MangleClassName(propName);
1586 OldList * list = MkList();
1587 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1588 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1592 strcpy(propName, "__ecerePropM_");
1593 FullClassNameCat(propName, prop._class.fullName, false);
1594 strcat(propName, "_");
1595 // strcat(propName, prop.name);
1596 FullClassNameCat(propName, prop.name, true);
1598 MangleClassName(propName);
1600 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1601 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1603 decl = MkDeclaration(specifiers, list);
1606 external = MkExternalDeclaration(decl);
1607 ast->Insert(curExternal.prev, external);
1608 external.symbol = symbol;
1609 symbol.externalPtr = external;
1613 // Move declaration higher...
1614 ast->Move(symbol.externalPtr, curExternal.prev);
1617 symbol.id = curExternal.symbol.idCode;
1621 // ***************** EXPRESSION PROCESSING ***************************
1622 public Type Dereference(Type source)
1627 if(source.kind == pointerType || source.kind == arrayType)
1630 source.type.refCount++;
1632 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1640 // Support dereferencing of no head classes for now...
1641 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1647 Compiler_Error($"cannot dereference type\n");
1652 static Type Reference(Type source)
1668 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1670 Identifier ident = member.identifiers ? member.identifiers->first : null;
1672 DataMember dataMember = null;
1673 Method method = null;
1674 bool freeType = false;
1676 yylloc = member.loc;
1682 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1686 dataMember = *curMember;
1692 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1693 DataMember _subMemberStack[256];
1694 int _subMemberStackPos = 0;
1696 // FILL MEMBER STACK
1698 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1701 dataMember = thisMember;
1702 if(curMember && thisMember.memberAccess == publicAccess)
1704 *curMember = thisMember;
1705 *curClass = thisMember._class;
1706 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1707 *subMemberStackPos = _subMemberStackPos;
1714 method = eClass_FindMethod(_class, ident.string, privateModule);
1715 if(method && method.type == virtualMethod)
1727 if(!dataMember.dataType && dataMember.dataTypeString)
1729 //Context context = SetupTemplatesContext(dataMember._class);
1730 Context context = SetupTemplatesContext(_class);
1731 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1732 FinishTemplatesContext(context);
1734 type = dataMember.dataType;
1738 // This is for destination type...
1739 if(!method.dataType)
1740 ProcessMethodType(method);
1741 //DeclareMethod(method);
1742 // method.dataType = ((Symbol)method.symbol)->type;
1743 type = method.dataType;
1746 if(ident && ident.next)
1748 for(ident = ident.next; ident && type; ident = ident.next)
1750 if(type.kind == classType)
1752 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1754 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1756 type = dataMember.dataType;
1758 else if(type.kind == structType || type.kind == unionType)
1761 for(memberType = type.members.first; memberType; memberType = memberType.next)
1763 if(!strcmp(memberType.name, ident.string))
1773 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1774 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1777 ClassTemplateParameter curParam = null;
1779 for(sClass = _class; sClass; sClass = sClass.base)
1782 if(sClass.templateClass) sClass = sClass.templateClass;
1783 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1785 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1787 for(sClass = sClass.base; sClass; sClass = sClass.base)
1789 if(sClass.templateClass) sClass = sClass.templateClass;
1790 id += sClass.templateParams.count;
1801 ClassTemplateArgument arg = _class.templateArgs[id];
1802 if(arg.dataTypeString)
1804 bool constant = type.constant;
1806 type = ProcessTypeString(arg.dataTypeString, false);
1807 if(type.kind == classType && constant) type.constant = true;
1808 else if(type.kind == pointerType)
1811 while(t.kind == pointerType) t = t.type;
1812 if(constant) t.constant = constant;
1815 if(type && _class.templateClass)
1816 type.passAsTemplate = true;
1822 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1823 exp.destType.refCount++;
1829 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1831 Class expClass = type._class.registered;
1832 Class cClass = null;
1837 char templateString[1024];
1838 ClassTemplateParameter param;
1839 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1840 for(cClass = expClass; cClass; cClass = cClass.base)
1843 if(cClass.templateClass) cClass = cClass.templateClass;
1844 for(param = cClass.templateParams.first; param; param = param.next)
1848 ClassTemplateArgument arg;
1849 for(sClass = cClass.base; sClass; sClass = sClass.base)
1851 if(sClass.templateClass) sClass = sClass.templateClass;
1852 id += sClass.templateParams.count;
1854 arg = expClass.templateArgs[id];
1856 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1858 ClassTemplateParameter cParam;
1859 //int p = numParams - sClass.templateParams.count;
1862 if(sClass.templateClass) sClass = sClass.templateClass;
1864 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1866 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1867 p += nextClass.templateParams.count;
1870 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1872 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1874 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1876 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1877 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1889 strcat(argument, arg.name.string);
1890 strcat(argument, " = ");
1896 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1897 char expString[1024];
1898 OldList * specs = MkList();
1899 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1901 char * string = PrintHexUInt64(arg.expression.ui64);
1902 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1905 ProcessExpressionType(exp);
1906 ComputeExpression(exp);
1907 expString[0] = '\0';
1908 PrintExpression(exp, expString);
1909 strcat(argument, expString);
1911 FreeExpression(exp);
1916 strcat(argument, arg.member.name);
1919 case TemplateParameterType::type:
1921 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1922 strcat(argument, arg.dataTypeString);
1928 if(paramCount) strcat(templateString, ", ");
1929 if(lastParam != p - 1)
1931 strcat(templateString, param.name);
1932 strcat(templateString, " = ");
1934 strcat(templateString, argument);
1943 int len = strlen(templateString);
1944 if(templateString[len-1] == '<')
1948 if(templateString[len-1] == '>')
1949 templateString[len++] = ' ';
1950 templateString[len++] = '>';
1952 templateString[len++] = '\0';
1955 Context context = SetupTemplatesContext(_class);
1956 if(freeType) FreeType(type);
1957 type = ProcessTypeString(templateString, false);
1959 FinishTemplatesContext(context);
1963 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1965 ProcessExpressionType(member.initializer.exp);
1966 if(!member.initializer.exp.expType)
1970 char expString[10240];
1971 expString[0] = '\0';
1972 PrintExpression(member.initializer.exp, expString);
1973 ChangeCh(expString, '\n', ' ');
1974 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1977 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1978 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1980 Compiler_Error($"incompatible instance method %s\n", ident.string);
1983 else if(member.initializer)
1986 FreeType(member.exp.destType);
1987 member.exp.destType = type;
1988 if(member.exp.destType)
1989 member.exp.destType.refCount++;
1990 ProcessExpressionType(member.exp);
1993 ProcessInitializer(member.initializer, type);
1995 if(freeType) FreeType(type);
1999 if(_class && _class.type == unitClass)
2001 if(member.initializer)
2004 FreeType(member.exp.destType);
2005 member.exp.destType = MkClassType(_class.fullName);
2006 ProcessExpressionType(member.initializer, type);
2008 Type type = MkClassType(_class.fullName);
2009 ProcessInitializer(member.initializer, type);
2015 if(member.initializer)
2017 //ProcessExpressionType(member.exp);
2018 ProcessInitializer(member.initializer, null);
2024 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2028 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2030 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2034 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2039 void ProcessInstantiationType(Instantiation inst)
2044 MembersInit members;
2045 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
2048 /*if(!inst._class.symbol)
2049 inst._class.symbol = FindClass(inst._class.name);*/
2050 classSym = inst._class.symbol;
2051 _class = classSym ? classSym.registered : null;
2053 // DANGER: Patch for mutex not declaring its struct when not needed
2054 if(!_class || _class.type != noHeadClass)
2055 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
2057 afterExternal = afterExternal ? afterExternal : curExternal;
2060 ProcessExpressionType(inst.exp);
2062 inst.isConstant = true;
2065 DataMember curMember = null;
2066 Class curClass = null;
2067 DataMember subMemberStack[256];
2068 int subMemberStackPos = 0;
2070 for(members = inst.members->first; members; members = members.next)
2072 switch(members.type)
2074 case methodMembersInit:
2077 static uint instMethodID = 0;
2078 External external = curExternal;
2079 Context context = curContext;
2080 Declarator declarator = members.function.declarator;
2081 Identifier nameID = GetDeclId(declarator);
2082 char * unmangled = nameID ? nameID.string : null;
2084 External createdExternal = null;
2089 //members.function.dontMangle = true;
2090 strcpy(name, "__ecereInstMeth_");
2091 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2093 strcat(name, nameID.string);
2095 sprintf(number, "_%08d", instMethodID++);
2096 strcat(name, number);
2097 nameID.string = CopyString(name);
2100 // Do modifications here...
2103 Symbol symbol = declarator.symbol;
2104 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2106 if(method && method.type == virtualMethod)
2108 symbol.method = method;
2109 ProcessMethodType(method);
2111 if(!symbol.type.thisClass)
2113 if(method.dataType.thisClass && currentClass &&
2114 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2116 if(!currentClass.symbol)
2117 currentClass.symbol = FindClass(currentClass.fullName);
2118 symbol.type.thisClass = currentClass.symbol;
2123 _class.symbol = FindClass(_class.fullName);
2124 symbol.type.thisClass = _class.symbol;
2127 // TESTING THIS HERE:
2128 DeclareType(symbol.type, true, true);
2133 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2134 unmangled, classSym.string);
2138 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2139 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2143 FreeSpecifier(nameID._class);
2144 nameID._class = null;
2149 //Type type = declarator.symbol.type;
2150 External oldExternal = curExternal;
2152 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2153 // *** It was commented out for problems such as
2155 class VirtualDesktop : Window
2157 clientSize = Size { };
2168 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2170 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2173 if(strcmp(declarator.symbol.string, name))
2175 printf("TOCHECK: Look out for this\n");
2176 delete declarator.symbol.string;
2177 declarator.symbol.string = CopyString(name);
2180 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2182 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2183 excludedSymbols->Remove(declarator.symbol);
2184 globalContext.symbols.Add((BTNode)declarator.symbol);
2185 if(strstr(declarator.symbol.string), "::")
2186 globalContext.hasNameSpace = true;
2191 //curExternal = curExternal.prev;
2192 //afterExternal = afterExternal->next;
2194 //ProcessFunction(afterExternal->function);
2196 //curExternal = afterExternal;
2198 External externalDecl;
2199 externalDecl = MkExternalDeclaration(null);
2200 ast->Insert(oldExternal.prev, externalDecl);
2202 // Which function does this process?
2203 if(createdExternal.function)
2205 ProcessFunction(createdExternal.function);
2207 //curExternal = oldExternal;
2210 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2212 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2213 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2215 //externalDecl = MkExternalDeclaration(decl);
2217 //***** ast->Insert(external.prev, externalDecl);
2218 //ast->Insert(curExternal.prev, externalDecl);
2219 externalDecl.declaration = decl;
2220 if(decl.symbol && !decl.symbol.pointerExternal)
2221 decl.symbol.pointerExternal = externalDecl;
2223 // Trying this out...
2224 declarator.symbol.pointerExternal = externalDecl;
2231 curExternal = declarator.symbol.pointerExternal;
2232 ProcessFunction((FunctionDefinition)members.function);
2234 curExternal = external;
2235 curContext = context;
2239 FreeClassFunction(members.function);
2241 // In this pass, turn this into a MemberInitData
2242 exp = QMkExpId(name);
2243 members.type = dataMembersInit;
2244 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2250 case dataMembersInit:
2252 if(members.dataMembers && classSym)
2255 Location oldyyloc = yylloc;
2256 for(member = members.dataMembers->first; member; member = member.next)
2258 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2259 if(member.initializer && !member.initializer.isConstant)
2260 inst.isConstant = false;
2272 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2274 // OPTIMIZATIONS: TESTING THIS...
2277 if(type.kind == functionType)
2282 for(param = type.params.first; param; param = param.next)
2283 DeclareType(param, declarePointers, true);
2285 DeclareType(type.returnType, declarePointers, true);
2287 else if(type.kind == pointerType && declarePointers)
2288 DeclareType(type.type, declarePointers, false);
2289 else if(type.kind == classType)
2291 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2292 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2294 else if(type.kind == structType || type.kind == unionType)
2297 for(member = type.members.first; member; member = member.next)
2298 DeclareType(member, false, false);
2300 else if(type.kind == arrayType)
2301 DeclareType(type.arrayType, declarePointers, false);
2305 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2307 ClassTemplateArgument * arg = null;
2309 ClassTemplateParameter curParam = null;
2311 for(sClass = _class; sClass; sClass = sClass.base)
2314 if(sClass.templateClass) sClass = sClass.templateClass;
2315 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2317 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2319 for(sClass = sClass.base; sClass; sClass = sClass.base)
2321 if(sClass.templateClass) sClass = sClass.templateClass;
2322 id += sClass.templateParams.count;
2332 arg = &_class.templateArgs[id];
2333 if(arg && param.type == type)
2334 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2339 public Context SetupTemplatesContext(Class _class)
2341 Context context = PushContext();
2342 context.templateTypesOnly = true;
2343 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2345 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2346 for(; param; param = param.next)
2348 if(param.type == type && param.identifier)
2350 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2351 curContext.templateTypes.Add((BTNode)type);
2358 for(sClass = _class; sClass; sClass = sClass.base)
2360 ClassTemplateParameter p;
2361 for(p = sClass.templateParams.first; p; p = p.next)
2363 //OldList * specs = MkList();
2364 //Declarator decl = null;
2365 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2368 TemplateParameter param = p.param;
2372 // ADD DATA TYPE HERE...
2373 p.param = param = TemplateParameter
2375 identifier = MkIdentifier(p.name), type = p.type,
2376 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2379 type = TemplatedType { key = (uintptr)p.name, param = param };
2380 curContext.templateTypes.Add((BTNode)type);
2388 public void FinishTemplatesContext(Context context)
2390 PopContext(context);
2391 FreeContext(context);
2395 public void ProcessMethodType(Method method)
2397 if(!method.dataType)
2399 Context context = SetupTemplatesContext(method._class);
2401 method.dataType = ProcessTypeString(method.dataTypeString, false);
2403 FinishTemplatesContext(context);
2405 if(method.type != virtualMethod && method.dataType)
2407 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2409 if(!method._class.symbol)
2410 method._class.symbol = FindClass(method._class.fullName);
2411 method.dataType.thisClass = method._class.symbol;
2415 // Why was this commented out? Working fine without now...
2418 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2419 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2426 char * par = strstr(type, "(");
2427 char * classOp = null;
2432 for(c = par-type-1; c >= 0; c++)
2434 if(type[c] == ':' && type[c+1] == ':')
2436 classOp = type + c - 1;
2437 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2444 else if(!isspace(type[c]))
2451 int typeLen = strlen(type);
2452 memcpy(temp, classOp, classOpLen);
2453 temp[classOpLen] = '\0';
2455 _class = eSystem_FindClass(module, temp);
2458 method.dataTypeString = new char[typeLen - classOpLen + 1];
2459 memcpy(method.dataTypeString, type, classOp - type);
2460 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2463 method.dataTypeString = type;
2469 public void ProcessPropertyType(Property prop)
2473 Context context = SetupTemplatesContext(prop._class);
2474 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2475 FinishTemplatesContext(context);
2479 public void DeclareMethod(Method method, const char * name)
2481 Symbol symbol = method.symbol;
2482 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2484 bool imported = false;
2485 bool dllImport = false;
2487 if(!method.dataType)
2488 method.dataType = ProcessTypeString(method.dataTypeString, false);
2490 if(!symbol || symbol._import || method.type == virtualMethod)
2492 if(!symbol || method.type == virtualMethod)
2495 if(!method._class.symbol)
2496 method._class.symbol = FindClass(method._class.fullName);
2497 classSym = method._class.symbol;
2498 if(!classSym._import)
2500 ModuleImport module;
2502 if(method._class.module && method._class.module.name)
2503 module = FindModule(method._class.module);
2505 module = mainModule;
2506 classSym._import = ClassImport
2508 name = CopyString(method._class.fullName);
2509 isRemote = method._class.isRemote;
2511 module.classes.Add(classSym._import);
2515 symbol = method.symbol = Symbol { };
2519 symbol._import = (ClassImport)MethodImport
2521 name = CopyString(method.name);
2522 isVirtual = method.type == virtualMethod;
2524 classSym._import.methods.Add(symbol._import);
2528 // Set the symbol type
2532 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2534 else if(type.thisClass == (void *)-1)
2536 type.thisClass = null;
2539 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2540 symbol.type = method.dataType;
2541 if(symbol.type) symbol.type.refCount++;
2544 if(!method.thisClass || strcmp(method.thisClass, "void"))
2545 symbol.type.params.Insert(null,
2546 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2549 if(!method.dataType.dllExport)
2552 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2558 if(!method.dataType)
2559 method.dataType = ((Symbol)method.symbol).type;
2560 //ProcessMethodType(method);
2563 if(method.type != virtualMethod && method.dataType)
2564 DeclareType(method.dataType, true, true);
2566 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2568 // We need a declaration here :)
2570 OldList * specifiers, * declarators;
2572 Declarator funcDecl;
2575 specifiers = MkList();
2576 declarators = MkList();
2580 ListAdd(specifiers, MkSpecifier(EXTERN));
2581 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2582 ListAdd(specifiers, MkSpecifier(STATIC));
2584 if(method.type == virtualMethod)
2586 ListAdd(specifiers, MkSpecifier(INT));
2587 d = MkDeclaratorIdentifier(MkIdentifier(name));
2591 d = MkDeclaratorIdentifier(MkIdentifier(name));
2594 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2596 Context context = SetupTemplatesContext(method._class);
2597 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2598 FinishTemplatesContext(context);
2600 funcDecl = GetFuncDecl(d);
2604 Specifier spec, next;
2605 for(spec = specifiers->first; spec; spec = next)
2608 if(spec.type == extendedSpecifier)
2610 specifiers->Remove(spec);
2611 FreeSpecifier(spec);
2616 // Add this parameter if not a static method
2617 if(method.dataType && !method.dataType.staticMethod)
2619 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2621 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2622 TypeName thisParam = MkTypeName(MkListOne(
2623 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2624 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2625 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2626 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2628 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2630 TypeName param = funcDecl.function.parameters->first;
2631 funcDecl.function.parameters->Remove(param);
2632 FreeTypeName(param);
2635 if(!funcDecl.function.parameters)
2636 funcDecl.function.parameters = MkList();
2637 funcDecl.function.parameters->Insert(null, thisParam);
2640 // Make sure we don't have empty parameter declarations for static methods...
2642 else if(!funcDecl.function.parameters)
2644 funcDecl.function.parameters = MkList();
2645 funcDecl.function.parameters->Insert(null,
2646 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2650 ProcessDeclarator(d);
2652 ListAdd(declarators, MkInitDeclarator(d, null));
2654 decl = MkDeclaration(specifiers, declarators);
2656 ReplaceThisClassSpecifiers(specifiers, method._class);
2658 // Keep a different symbol for the function definition than the declaration...
2659 if(symbol.pointerExternal)
2661 Symbol functionSymbol { };
2665 *functionSymbol = *symbol;
2666 functionSymbol.string = CopyString(symbol.string);
2667 if(functionSymbol.type)
2668 functionSymbol.type.refCount++;
2671 excludedSymbols->Add(functionSymbol);
2672 symbol.pointerExternal.symbol = functionSymbol;
2674 external = MkExternalDeclaration(decl);
2676 ast->Insert(curExternal ? curExternal.prev : null, external);
2677 external.symbol = symbol;
2678 symbol.pointerExternal = external;
2682 // Move declaration higher...
2683 ast->Move(symbol.pointerExternal, curExternal.prev);
2686 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2690 char * ReplaceThisClass(Class _class)
2692 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2696 ClassTemplateParameter param;
2699 char className[1024];
2700 strcpy(className, _class.fullName);
2701 for(param = _class.templateParams.first; param; param = param.next)
2703 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2705 if(first) strcat(className, "<");
2706 if(!first) strcat(className, ", ");
2707 if(lastParam + 1 != p)
2709 strcat(className, param.name);
2710 strcat(className, " = ");
2712 strcat(className, param.name);
2720 int len = strlen(className);
2721 if(className[len-1] == '>') className[len++] = ' ';
2722 className[len++] = '>';
2723 className[len++] = '\0';
2725 return CopyString(className);
2728 return CopyString(_class.fullName);
2731 Type ReplaceThisClassType(Class _class)
2733 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2737 ClassTemplateParameter param;
2739 char className[1024];
2740 strcpy(className, _class.fullName);
2742 for(param = _class.templateParams.first; param; param = param.next)
2744 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2746 if(first) strcat(className, "<");
2747 if(!first) strcat(className, ", ");
2748 if(lastParam + 1 != p)
2750 strcat(className, param.name);
2751 strcat(className, " = ");
2753 strcat(className, param.name);
2761 int len = strlen(className);
2762 if(className[len-1] == '>') className[len++] = ' ';
2763 className[len++] = '>';
2764 className[len++] = '\0';
2766 return MkClassType(className);
2767 //return ProcessTypeString(className, false);
2771 return MkClassType(_class.fullName);
2772 //return ProcessTypeString(_class.fullName, false);
2776 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2778 if(specs != null && _class)
2781 for(spec = specs.first; spec; spec = spec.next)
2783 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2785 spec.type = nameSpecifier;
2786 spec.name = ReplaceThisClass(_class);
2787 spec.symbol = FindClass(spec.name); //_class.symbol;
2793 // Returns imported or not
2794 bool DeclareFunction(GlobalFunction function, char * name)
2796 Symbol symbol = function.symbol;
2797 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2799 bool imported = false;
2800 bool dllImport = false;
2802 if(!function.dataType)
2804 function.dataType = ProcessTypeString(function.dataTypeString, false);
2805 if(!function.dataType.thisClass)
2806 function.dataType.staticMethod = true;
2813 ModuleImport module = FindModule(function.module);
2814 // WARNING: This is not added anywhere...
2815 symbol = function.symbol = Symbol { };
2819 if(!function.dataType.dllExport)
2821 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2822 module.functions.Add(symbol._import);
2825 // Set the symbol type
2827 symbol.type = ProcessTypeString(function.dataTypeString, false);
2828 if(!symbol.type.thisClass)
2829 symbol.type.staticMethod = true;
2832 imported = symbol._import ? true : false;
2833 if(imported && function.module != privateModule && function.module.importType != staticImport)
2837 DeclareType(function.dataType, true, true);
2841 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2843 // We need a declaration here :)
2845 OldList * specifiers, * declarators;
2847 Declarator funcDecl;
2850 specifiers = MkList();
2851 declarators = MkList();
2854 ListAdd(specifiers, MkSpecifier(EXTERN));
2857 ListAdd(specifiers, MkSpecifier(STATIC));
2860 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2863 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2865 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2866 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2867 if(function.module.importType == staticImport)
2870 for(spec = specifiers->first; spec; spec = spec.next)
2871 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2873 specifiers->Remove(spec);
2874 FreeSpecifier(spec);
2879 funcDecl = GetFuncDecl(d);
2881 // Make sure we don't have empty parameter declarations for static methods...
2882 if(funcDecl && !funcDecl.function.parameters)
2884 funcDecl.function.parameters = MkList();
2885 funcDecl.function.parameters->Insert(null,
2886 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2889 ListAdd(declarators, MkInitDeclarator(d, null));
2892 Context oldCtx = curContext;
2893 curContext = globalContext;
2894 decl = MkDeclaration(specifiers, declarators);
2895 curContext = oldCtx;
2898 // Keep a different symbol for the function definition than the declaration...
2899 if(symbol.pointerExternal)
2901 Symbol functionSymbol { };
2904 *functionSymbol = *symbol;
2905 functionSymbol.string = CopyString(symbol.string);
2906 if(functionSymbol.type)
2907 functionSymbol.type.refCount++;
2910 excludedSymbols->Add(functionSymbol);
2912 symbol.pointerExternal.symbol = functionSymbol;
2914 external = MkExternalDeclaration(decl);
2916 ast->Insert(curExternal.prev, external);
2917 external.symbol = symbol;
2918 symbol.pointerExternal = external;
2922 // Move declaration higher...
2923 ast->Move(symbol.pointerExternal, curExternal.prev);
2927 symbol.id = curExternal.symbol.idCode;
2930 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2933 void DeclareGlobalData(GlobalData data)
2935 Symbol symbol = data.symbol;
2936 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2941 symbol = data.symbol = Symbol { };
2944 data.dataType = ProcessTypeString(data.dataTypeString, false);
2945 DeclareType(data.dataType, true, true);
2948 if(!symbol.pointerExternal)
2950 // We need a declaration here :)
2952 OldList * specifiers, * declarators;
2956 specifiers = MkList();
2957 declarators = MkList();
2959 ListAdd(specifiers, MkSpecifier(EXTERN));
2960 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2961 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2963 ListAdd(declarators, MkInitDeclarator(d, null));
2965 decl = MkDeclaration(specifiers, declarators);
2966 external = MkExternalDeclaration(decl);
2968 ast->Insert(curExternal.prev, external);
2969 external.symbol = symbol;
2970 symbol.pointerExternal = external;
2974 // Move declaration higher...
2975 ast->Move(symbol.pointerExternal, curExternal.prev);
2979 symbol.id = curExternal.symbol.idCode;
2984 class Conversion : struct
2986 Conversion prev, next;
2992 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2995 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2996 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2998 Class sourceClass = source.kind == classType ? source._class.registered : null;
2999 Class destClass = dest.kind == classType ? dest._class.registered : null;
3000 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
3001 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
3003 Type sourceType = source, destType = dest;
3004 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
3005 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
3006 if(!destType.constant && sourceType.constant)
3010 Compiler_Warning($"discarding const qualifier\n");
3017 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
3018 bool isConversionExploration, bool warnConst)
3023 CheckConstCompatibility(source, dest, true);
3024 // Property convert;
3026 if(source.kind == templateType && dest.kind != templateType)
3028 Type type = ProcessTemplateParameterType(source.templateParameter);
3029 if(type) source = type;
3032 if(dest.kind == templateType && source.kind != templateType)
3034 Type type = ProcessTemplateParameterType(dest.templateParameter);
3035 if(type) dest = type;
3038 if(dest.classObjectType == typedObject && dest.kind != functionType)
3040 if(source.classObjectType != anyObject)
3044 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
3045 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
3053 if(source.kind != functionType && source.classObjectType == anyObject)
3055 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
3059 if((dest.kind == structType && source.kind == structType) ||
3060 (dest.kind == unionType && source.kind == unionType))
3062 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
3063 (source.members.first && source.members.first == dest.members.first))
3067 if(dest.kind == ellipsisType && source.kind != voidType)
3070 if(dest.kind == pointerType && dest.type.kind == voidType &&
3071 ((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))
3072 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
3074 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
3076 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
3078 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
3079 ((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))
3080 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
3081 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
3083 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
3086 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
3088 if(source._class.registered && source._class.registered.type == unitClass)
3090 if(conversions != null)
3092 if(source._class.registered == dest._class.registered)
3097 Class sourceBase, destBase;
3098 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
3099 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
3100 if(sourceBase == destBase)
3104 // Don't match enum inheriting from other enum if resolving enumeration values
3105 // TESTING: !dest.classObjectType
3106 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3108 (!source._class.registered || source._class.registered.type != enumClass) ||
3109 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3113 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3115 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3116 ((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)
3118 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3126 // JUST ADDED THIS...
3127 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3132 // Just added this for Straight conversion of ColorAlpha => Color
3133 if(source.kind == classType)
3136 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3139 for(convert = _class.conversions.first; convert; convert = convert.next)
3141 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3143 Conversion after = (conversions != null) ? conversions.last : null;
3145 if(!convert.dataType)
3146 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3147 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3148 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3149 MatchTypes(convert.dataType, dest, conversions, null, null,
3150 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3151 convert.dataType.kind == classType, false, true, warnConst))
3153 if(!conversions && !convert.Get)
3155 else if(conversions != null)
3157 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3158 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3159 (dest.kind != classType || dest._class.registered != _class.base))
3163 Conversion conv { convert = convert, isGet = true };
3164 // conversions.Add(conv);
3165 conversions.Insert(after, conv);
3178 if(dest.kind == classType)
3181 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3184 for(convert = _class.conversions.first; convert; convert = convert.next)
3186 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3188 Type constType = null;
3189 bool success = false;
3190 // Conversion after = (conversions != null) ? conversions.last : null;
3192 if(!convert.dataType)
3193 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3195 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3198 constType = { kind = pointerType, refCount = 1, type = ptrType };
3199 CopyTypeInto(ptrType, convert.dataType.type);
3200 ptrType.constant = true;
3203 // Just added this equality check to prevent recursion.... Make it safer?
3204 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3205 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3207 if(!conversions && !convert.Set)
3209 else if(conversions != null)
3211 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3212 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3213 (source.kind != classType || source._class.registered != _class.base))
3217 // *** Testing this! ***
3218 Conversion conv { convert = convert };
3219 conversions.Add(conv);
3220 //conversions.Insert(after, conv);
3226 FreeType(constType);
3232 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3234 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3235 (source.kind != classType || source._class.registered.type != structClass))
3239 // TESTING THIS... IS THIS OK??
3240 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3242 if(!dest._class.registered.dataType)
3243 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3244 // Only support this for classes...
3245 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3246 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3248 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3257 if(source.kind == classType)
3260 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3263 for(convert = _class.conversions.first; convert; convert = convert.next)
3265 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3267 Conversion after = (conversions != null) ? conversions.last : null;
3269 if(!convert.dataType)
3270 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3271 if(convert.dataType != source &&
3272 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3273 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3275 if(!conversions && !convert.Get)
3277 else if(conversions != null)
3279 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3280 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3281 (dest.kind != classType || dest._class.registered != _class.base))
3285 Conversion conv { convert = convert, isGet = true };
3287 // conversions.Add(conv);
3288 conversions.Insert(after, conv);
3297 // TESTING THIS... IS THIS OK??
3298 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3300 if(!source._class.registered.dataType)
3301 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3302 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3304 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false, warnConst))
3306 // For bool to be accepted by byte, short, etc.
3307 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3314 if(source.kind == classType || source.kind == subClassType)
3316 else if(dest.kind == source.kind &&
3317 (dest.kind != structType && dest.kind != unionType &&
3318 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3320 // RECENTLY ADDED THESE
3321 else if(dest.kind == doubleType && source.kind == floatType)
3323 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3325 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3327 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3329 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3331 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3333 else if(source.kind == enumType &&
3334 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3336 else if(dest.kind == enumType && !isConversionExploration &&
3337 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3339 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3340 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3342 Type paramSource, paramDest;
3344 if(dest.kind == methodType)
3345 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3346 if(source.kind == methodType)
3347 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3349 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3350 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3351 if(dest.kind == methodType)
3352 dest = dest.method.dataType;
3353 if(source.kind == methodType)
3354 source = source.method.dataType;
3356 paramSource = source.params.first;
3357 if(paramSource && paramSource.kind == voidType) paramSource = null;
3358 paramDest = dest.params.first;
3359 if(paramDest && paramDest.kind == voidType) paramDest = null;
3362 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3363 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3365 // Source thisClass must be derived from destination thisClass
3366 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3367 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3369 if(paramDest && paramDest.kind == classType)
3370 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3372 Compiler_Error($"method class should not take an object\n");
3375 paramDest = paramDest.next;
3377 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3379 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3383 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3385 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3391 // THIS WAS BACKWARDS:
3392 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3393 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3396 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3398 Compiler_Error($"overriding class expected to be derived from method class\n");
3402 paramSource = paramSource.next;
3408 // Source thisClass must be derived from destination thisClass
3409 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3411 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3417 // THIS WAS BACKWARDS TOO??
3418 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3419 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3422 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3424 //Compiler_Error($"overriding class expected to be derived from method class\n");
3432 // Source return type must be derived from destination return type
3433 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3435 Compiler_Warning($"incompatible return type for function\n");
3438 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3440 CheckConstCompatibility(dest.returnType, source.returnType, true);
3444 for(; paramDest; paramDest = paramDest.next)
3448 //Compiler_Warning($"not enough parameters\n");
3449 Compiler_Error($"not enough parameters\n");
3453 Type paramDestType = paramDest;
3454 Type paramSourceType = paramSource;
3455 Type type = paramDestType;
3457 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3458 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3459 paramSource.kind != templateType)
3462 ClassTemplateParameter curParam = null;
3464 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3467 if(sClass.templateClass) sClass = sClass.templateClass;
3468 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3470 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3472 for(sClass = sClass.base; sClass; sClass = sClass.base)
3474 if(sClass.templateClass) sClass = sClass.templateClass;
3475 id += sClass.templateParams.count;
3486 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3487 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3491 // paramDest must be derived from paramSource
3492 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3493 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3497 PrintType(paramDest, type, false, true);
3498 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3500 if(paramDestType != paramDest)
3501 FreeType(paramDestType);
3504 if(paramDestType != paramDest)
3505 FreeType(paramDestType);
3508 paramSource = paramSource.next;
3512 Compiler_Error($"too many parameters\n");
3517 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3521 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3522 (source.kind == arrayType || source.kind == pointerType))
3524 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3531 static void FreeConvert(Conversion convert)
3533 if(convert.resultType)
3534 FreeType(convert.resultType);
3537 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3538 char * string, OldList conversions)
3542 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3544 Class _class = link.data;
3545 if(_class.type == enumClass)
3547 OldList converts { };
3549 type.kind = classType;
3552 _class.symbol = FindClass(_class.fullName);
3553 type._class = _class.symbol;
3555 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false, false))
3558 Class enumClass = eSystem_FindClass(privateModule, "enum");
3562 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3564 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3565 for(value = e.values.first; value; value = value.next)
3567 if(!strcmp(value.name, string))
3572 FreeExpContents(sourceExp);
3573 FreeType(sourceExp.expType);
3575 sourceExp.isConstant = true;
3576 sourceExp.expType = MkClassType(baseClass.fullName);
3580 sourceExp.type = constantExp;
3581 if(!strcmp(baseClass.dataTypeString, "int"))
3582 sprintf(constant, "%d",(int)value.data);
3584 sprintf(constant, "0x%X",(int)value.data);
3585 sourceExp.constant = CopyString(constant);
3586 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3589 while(converts.first)
3591 Conversion convert = converts.first;
3592 converts.Remove(convert);
3593 conversions.Add(convert);
3602 converts.Free(FreeConvert);
3606 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3607 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3612 public bool ModuleVisibility(Module searchIn, Module searchFor)
3614 SubModule subModule;
3616 if(searchFor == searchIn)
3619 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3621 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3623 if(ModuleVisibility(subModule.module, searchFor))
3630 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3634 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3636 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3638 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3641 for(module = mainModule.application.allModules.first; module; module = module.next)
3643 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3649 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3652 Type realDest = dest;
3653 Type backupSourceExpType = null;
3654 Expression computedExp = sourceExp;
3657 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3658 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3660 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3661 ComputeExpression(computedExp /*sourceExp*/);
3664 source = sourceExp.expType;
3666 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3668 if(computedExp != sourceExp)
3670 FreeExpression(computedExp);
3671 computedExp = sourceExp;
3677 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3679 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3681 Class sourceBase, destBase;
3682 for(sourceBase = source._class.registered;
3683 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3684 sourceBase = sourceBase.base);
3685 for(destBase = dest._class.registered;
3686 destBase && destBase.base && destBase.base.type != systemClass;
3687 destBase = destBase.base);
3688 //if(source._class.registered == dest._class.registered)
3689 if(sourceBase == destBase)
3691 if(computedExp != sourceExp)
3693 FreeExpression(computedExp);
3694 computedExp = sourceExp;
3706 int64 value = MAXINT;
3710 if(computedExp.type == constantExp)
3713 value = strtoll(computedExp.constant, null, 0);
3715 value = strtoull(computedExp.constant, null, 0);
3717 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3720 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3722 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3724 if(computedExp != sourceExp)
3726 FreeExpression(computedExp);
3727 computedExp = sourceExp;
3730 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3731 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3734 source = Type { kind = intType, isSigned = false, refCount = 1 };
3737 if(dest.kind == classType)
3739 Class _class = dest._class ? dest._class.registered : null;
3741 if(_class && _class.type == unitClass)
3743 if(source.kind != classType)
3746 Type tempDest, tempSource;
3748 for(; _class.base.type != systemClass; _class = _class.base);
3750 tempDest = tempType;
3752 tempType.kind = classType;
3754 _class.symbol = FindClass(_class.fullName);
3756 tempType._class = _class.symbol;
3757 tempType.truth = dest.truth;
3759 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3761 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3762 backupSourceExpType = sourceExp.expType;
3763 sourceExp.expType = dest; dest.refCount++;
3764 //sourceExp.expType = MkClassType(_class.fullName);
3772 // Why wasn't there something like this?
3773 if(_class && _class.type == bitClass && source.kind != classType)
3775 if(!dest._class.registered.dataType)
3776 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3777 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3780 FreeType(sourceExp.expType);
3781 source = sourceExp.expType = MkClassType(dest._class.string);
3784 //source.kind = classType;
3785 //source._class = dest._class;
3789 // Adding two enumerations
3791 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3793 if(!source._class.registered.dataType)
3794 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3795 if(!dest._class.registered.dataType)
3796 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3798 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3801 source = sourceExp.expType = MkClassType(dest._class.string);
3804 //source.kind = classType;
3805 //source._class = dest._class;
3809 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3811 OldList * specs = MkList();
3815 ReadString(string, sourceExp.string);
3816 decl = SpecDeclFromString(string, specs, null);
3818 FreeExpContents(sourceExp);
3819 FreeType(sourceExp.expType);
3821 sourceExp.type = classExp;
3822 sourceExp._classExp.specifiers = specs;
3823 sourceExp._classExp.decl = decl;
3824 sourceExp.expType = dest;
3829 if(backupSourceExpType) FreeType(backupSourceExpType);
3833 else if(source.kind == classType)
3835 Class _class = source._class ? source._class.registered : null;
3837 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3840 if(dest.kind != classType)
3842 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3843 if(!source._class.registered.dataType)
3844 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3847 dest = MkClassType(source._class.string);
3848 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3849 // dest = MkClassType(source._class.string);
3853 if(dest.kind != classType)
3856 Type tempDest, tempSource;
3858 if(!source._class.registered.dataType)
3859 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3861 for(; _class.base.type != systemClass; _class = _class.base);
3863 tempSource = tempType;
3864 tempType.kind = classType;
3865 tempType._class = FindClass(_class.fullName);
3866 tempType.truth = source.truth;
3867 tempType.classObjectType = source.classObjectType;
3870 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3872 // PUT THIS BACK TESTING UNITS?
3873 if(conversions.last)
3875 ((Conversion)(conversions.last)).resultType = dest;
3879 FreeType(sourceExp.expType);
3880 sourceExp.expType = MkClassType(_class.fullName);
3881 sourceExp.expType.truth = source.truth;
3882 sourceExp.expType.classObjectType = source.classObjectType;
3884 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3886 if(!sourceExp.destType)
3888 FreeType(sourceExp.destType);
3889 sourceExp.destType = sourceExp.expType;
3890 if(sourceExp.expType)
3891 sourceExp.expType.refCount++;
3894 //source = _class.dataType;
3897 // TOCHECK: TESTING THIS NEW CODE
3898 if(!_class.dataType)
3899 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3901 dest = MkClassType(source._class.string);
3902 dest.truth = source.truth;
3903 dest.classObjectType = source.classObjectType;
3906 source = _class.dataType;
3916 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3926 if(source.kind == classType)
3928 Class _class = source._class.registered;
3929 if(_class.type == unitClass)
3931 if(!_class.dataType)
3932 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3933 source = _class.dataType;
3937 if(dest.kind == classType)
3939 Class _class = dest._class ? dest._class.registered : null;
3940 bool fittingValue = false;
3941 if(_class && _class.type == enumClass)
3943 Class enumClass = eSystem_FindClass(privateModule, "enum");
3944 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3945 if(c && value >= 0 && value <= c.largest)
3946 fittingValue = true;
3949 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3950 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3952 if(_class.type == normalClass || _class.type == noHeadClass)
3954 Expression newExp { };
3955 *newExp = *sourceExp;
3956 if(sourceExp.destType) sourceExp.destType.refCount++;
3957 if(sourceExp.expType) sourceExp.expType.refCount++;
3958 sourceExp.type = castExp;
3959 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3960 sourceExp.cast.exp = newExp;
3961 FreeType(sourceExp.expType);
3962 sourceExp.expType = null;
3963 ProcessExpressionType(sourceExp);
3965 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3968 FreeType(sourceExp.expType);
3969 sourceExp.expType = dest;
3973 if(inCompiler) FreeType(dest);
3975 if(backupSourceExpType) FreeType(backupSourceExpType);
3979 if(!_class.dataType)
3980 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3982 dest = _class.dataType;
3986 // Accept lower precision types for units, since we want to keep the unit type
3987 if(dest.kind == doubleType &&
3988 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3989 source.kind == charType || source.kind == _BoolType))
3991 specs = MkListOne(MkSpecifier(DOUBLE));
3993 else if(dest.kind == floatType &&
3994 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3995 source.kind == _BoolType || source.kind == doubleType))
3997 specs = MkListOne(MkSpecifier(FLOAT));
3999 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4000 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4003 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4004 ListAdd(specs, MkSpecifier(INT64));
4006 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
4007 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4010 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4011 ListAdd(specs, MkSpecifier(INT));
4013 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
4014 source.kind == floatType || source.kind == doubleType))
4017 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4018 ListAdd(specs, MkSpecifier(SHORT));
4020 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
4021 source.kind == floatType || source.kind == doubleType))
4024 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4025 ListAdd(specs, MkSpecifier(CHAR));
4031 if(backupSourceExpType)
4033 // Failed to convert: revert previous exp type
4034 if(sourceExp.expType) FreeType(sourceExp.expType);
4035 sourceExp.expType = backupSourceExpType;
4040 else if(dest.kind == doubleType &&
4041 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
4042 source.kind == _BoolType || source.kind == charType))
4044 specs = MkListOne(MkSpecifier(DOUBLE));
4046 else if(dest.kind == floatType &&
4047 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4049 specs = MkListOne(MkSpecifier(FLOAT));
4051 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4052 (value == 1 || value == 0))
4055 ListAdd(specs, MkSpecifier(BOOL));
4057 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4058 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
4061 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4062 ListAdd(specs, MkSpecifier(CHAR));
4064 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
4065 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
4068 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4069 ListAdd(specs, MkSpecifier(SHORT));
4071 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
4074 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4075 ListAdd(specs, MkSpecifier(INT));
4077 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
4080 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4081 ListAdd(specs, MkSpecifier(INT64));
4083 else if(dest.kind == enumType &&
4084 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4086 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4092 if(backupSourceExpType)
4094 // Failed to convert: revert previous exp type
4095 if(sourceExp.expType) FreeType(sourceExp.expType);
4096 sourceExp.expType = backupSourceExpType;
4101 if(!flag && !sourceExp.opDestType)
4103 Expression newExp { };
4104 *newExp = *sourceExp;
4107 if(sourceExp.destType) sourceExp.destType.refCount++;
4108 if(sourceExp.expType) sourceExp.expType.refCount++;
4110 sourceExp.type = castExp;
4111 if(realDest.kind == classType)
4113 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4114 FreeList(specs, FreeSpecifier);
4117 sourceExp.cast.typeName = MkTypeName(specs, null);
4118 if(newExp.type == opExp)
4120 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4123 sourceExp.cast.exp = newExp;
4125 FreeType(sourceExp.expType);
4126 sourceExp.expType = null;
4127 ProcessExpressionType(sourceExp);
4130 FreeList(specs, FreeSpecifier);
4134 if(backupSourceExpType) FreeType(backupSourceExpType);
4140 if(computedExp != sourceExp)
4142 FreeExpression(computedExp);
4143 computedExp = sourceExp;
4146 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4147 if(sourceExp.type == identifierExp)
4149 Identifier id = sourceExp.identifier;
4150 if(dest.kind == classType)
4152 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4154 Class _class = dest._class.registered;
4155 Class enumClass = eSystem_FindClass(privateModule, "enum");
4158 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4161 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4162 for(value = e.values.first; value; value = value.next)
4164 if(!strcmp(value.name, id.string))
4169 FreeExpContents(sourceExp);
4170 FreeType(sourceExp.expType);
4172 sourceExp.isConstant = true;
4173 sourceExp.expType = MkClassType(_class.fullName);
4177 sourceExp.type = constantExp;
4178 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
4179 sprintf(constant, "%d", (int) value.data);
4181 sprintf(constant, "0x%X", (int) value.data);
4182 sourceExp.constant = CopyString(constant);
4183 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4193 // Loop through all enum classes
4194 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4205 #define TERTIARY(o, name, m, t, p) \
4206 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4208 exp.type = constantExp; \
4209 exp.string = p(op1.m ? op2.m : op3.m); \
4211 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4215 #define BINARY(o, name, m, t, p) \
4216 static bool name(Expression exp, Operand op1, Operand op2) \
4219 exp.type = constantExp; \
4220 exp.string = p((t)(op1.m o value2)); \
4222 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4226 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4227 static bool name(Expression exp, Operand op1, Operand op2) \
4230 exp.type = constantExp; \
4231 exp.string = p(value2 ? (op1.m o value2) : 0); \
4233 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4237 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4238 static bool name(Expression exp, Operand op1, Operand op2) \
4241 exp.type = constantExp; \
4242 exp.string = p(op1.m o value2); \
4244 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4248 #define UNARY(o, name, m, t, p) \
4249 static bool name(Expression exp, Operand op1) \
4251 exp.type = constantExp; \
4252 exp.string = p((t)(o op1.m)); \
4254 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4258 #define OPERATOR_ALL(macro, o, name) \
4259 macro(o, Int##name, i, int, PrintInt) \
4260 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4261 macro(o, Int64##name, i64, int64, PrintInt64) \
4262 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4263 macro(o, Short##name, s, short, PrintShort) \
4264 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4265 macro(o, Char##name, c, char, PrintChar) \
4266 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4267 macro(o, Float##name, f, float, PrintFloat) \
4268 macro(o, Double##name, d, double, PrintDouble)
4270 #define OPERATOR_INTTYPES(macro, o, name) \
4271 macro(o, Int##name, i, int, PrintInt) \
4272 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4273 macro(o, Int64##name, i64, int64, PrintInt64) \
4274 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4275 macro(o, Short##name, s, short, PrintShort) \
4276 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4277 macro(o, Char##name, c, char, PrintChar) \
4278 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4280 #define OPERATOR_REALTYPES(macro, o, name) \
4281 macro(o, Float##name, f, float, PrintFloat) \
4282 macro(o, Double##name, d, double, PrintDouble)
4284 // binary arithmetic
4285 OPERATOR_ALL(BINARY, +, Add)
4286 OPERATOR_ALL(BINARY, -, Sub)
4287 OPERATOR_ALL(BINARY, *, Mul)
4288 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4289 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4290 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4293 OPERATOR_ALL(UNARY, -, Neg)
4295 // unary arithmetic increment and decrement
4296 OPERATOR_ALL(UNARY, ++, Inc)
4297 OPERATOR_ALL(UNARY, --, Dec)
4299 // binary arithmetic assignment
4300 OPERATOR_ALL(BINARY, =, Asign)
4301 OPERATOR_ALL(BINARY, +=, AddAsign)
4302 OPERATOR_ALL(BINARY, -=, SubAsign)
4303 OPERATOR_ALL(BINARY, *=, MulAsign)
4304 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4305 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4306 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4309 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4310 OPERATOR_INTTYPES(BINARY, |, BitOr)
4311 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4312 OPERATOR_INTTYPES(BINARY, <<, LShift)
4313 OPERATOR_INTTYPES(BINARY, >>, RShift)
4316 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4318 // binary bitwise assignment
4319 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4320 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4321 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4322 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4323 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4325 // unary logical negation
4326 OPERATOR_INTTYPES(UNARY, !, Not)
4328 // binary logical equality
4329 OPERATOR_ALL(BINARY, ==, Equ)
4330 OPERATOR_ALL(BINARY, !=, Nqu)
4333 OPERATOR_ALL(BINARY, &&, And)
4334 OPERATOR_ALL(BINARY, ||, Or)
4336 // binary logical relational
4337 OPERATOR_ALL(BINARY, >, Grt)
4338 OPERATOR_ALL(BINARY, <, Sma)
4339 OPERATOR_ALL(BINARY, >=, GrtEqu)
4340 OPERATOR_ALL(BINARY, <=, SmaEqu)
4342 // tertiary condition operator
4343 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4345 //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
4346 #define OPERATOR_TABLE_ALL(name, type) \
4347 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4349 type##Inc, type##Dec, \
4350 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4351 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4353 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4355 type##Equ, type##Nqu, \
4356 type##And, type##Or, \
4357 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4360 #define OPERATOR_TABLE_INTTYPES(name, type) \
4361 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4363 type##Inc, type##Dec, \
4364 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4365 null, null, null, null, null, \
4367 null, null, null, null, null, \
4369 type##Equ, type##Nqu, \
4370 type##And, type##Or, \
4371 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4374 OPERATOR_TABLE_ALL(int, Int)
4375 OPERATOR_TABLE_ALL(uint, UInt)
4376 OPERATOR_TABLE_ALL(int64, Int64)
4377 OPERATOR_TABLE_ALL(uint64, UInt64)
4378 OPERATOR_TABLE_ALL(short, Short)
4379 OPERATOR_TABLE_ALL(ushort, UShort)
4380 OPERATOR_TABLE_INTTYPES(float, Float)
4381 OPERATOR_TABLE_INTTYPES(double, Double)
4382 OPERATOR_TABLE_ALL(char, Char)
4383 OPERATOR_TABLE_ALL(uchar, UChar)
4385 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4386 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4387 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4388 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4389 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4390 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4391 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4392 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4394 public void ReadString(char * output, char * string)
4396 int len = strlen(string);
4398 bool quoted = false, escaped = false;
4399 for(c = 0; c<len; c++)
4401 char ch = string[c];
4406 case 'n': output[d] = '\n'; break;
4407 case 't': output[d] = '\t'; break;
4408 case 'a': output[d] = '\a'; break;
4409 case 'b': output[d] = '\b'; break;
4410 case 'f': output[d] = '\f'; break;
4411 case 'r': output[d] = '\r'; break;
4412 case 'v': output[d] = '\v'; break;
4413 case '\\': output[d] = '\\'; break;
4414 case '\"': output[d] = '\"'; break;
4415 case '\'': output[d] = '\''; break;
4416 default: output[d] = ch;
4437 // String Unescape Copy
4439 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4440 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4441 public int UnescapeString(char * d, char * s, int len)
4445 while(j < len && (ch = s[j]))
4450 switch((ch = s[++j]))
4452 case 'n': d[k] = '\n'; break;
4453 case 't': d[k] = '\t'; break;
4454 case 'a': d[k] = '\a'; break;
4455 case 'b': d[k] = '\b'; break;
4456 case 'f': d[k] = '\f'; break;
4457 case 'r': d[k] = '\r'; break;
4458 case 'v': d[k] = '\v'; break;
4459 case '\\': d[k] = '\\'; break;
4460 case '\"': d[k] = '\"'; break;
4461 case '\'': d[k] = '\''; break;
4462 default: d[k] = '\\'; d[k] = ch;
4474 public char * OffsetEscapedString(char * s, int len, int offset)
4478 while(j < len && k < offset && (ch = s[j]))
4483 return (k == offset) ? s + j : null;
4486 public Operand GetOperand(Expression exp)
4489 Type type = exp.expType;
4492 while(type.kind == classType &&
4493 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4495 if(!type._class.registered.dataType)
4496 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4497 type = type._class.registered.dataType;
4500 if(exp.type == stringExp && op.kind == pointerType)
4502 op.ui64 = (uint64)exp.string;
4503 op.kind = pointerType;
4506 else if(exp.isConstant && exp.type == constantExp)
4508 op.kind = type.kind;
4509 op.type = exp.expType;
4516 if(exp.constant[0] == '\'')
4518 op.c = exp.constant[1];
4521 else if(type.isSigned)
4523 op.c = (char)strtol(exp.constant, null, 0);
4528 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4536 op.s = (short)strtol(exp.constant, null, 0);
4541 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4549 op.i = (int)strtol(exp.constant, null, 0);
4554 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4562 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4567 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4570 op.kind = int64Type;
4575 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4580 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4583 op.kind = int64Type;
4588 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4593 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4596 op.kind = int64Type;
4599 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4600 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4601 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4602 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4604 op.f = (float)strtod(exp.constant, null);
4608 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4609 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4610 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4611 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4613 op.d = (double)strtod(exp.constant, null);
4616 //case classType: For when we have operator overloading...
4617 // Pointer additions
4618 //case functionType:
4622 op.ui64 = _strtoui64(exp.constant, null, 0);
4623 op.kind = pointerType;
4633 static __attribute__((unused)) void UnusedFunction()
4636 a.OnGetString(0,0,0);
4639 extern int __ecereVMethodID_class_OnGetString;
4642 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4644 DataMember dataMember;
4645 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4647 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4648 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4652 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4654 void * ptr = inst.data + dataMember.offset + offset;
4655 char * result = null;
4656 exp.loc = member.loc = inst.loc;
4657 ((Identifier)member.identifiers->first).loc = inst.loc;
4659 if(!dataMember.dataType)
4660 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4661 type = dataMember.dataType;
4662 if(type.kind == classType)
4664 Class _class = type._class.registered;
4665 if(_class.type == enumClass)
4667 Class enumClass = eSystem_FindClass(privateModule, "enum");
4670 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4672 for(item = e.values.first; item; item = item.next)
4674 if((int)item.data == *(int *)ptr)
4682 exp.identifier = MkIdentifier(result);
4683 exp.type = identifierExp;
4684 exp.destType = MkClassType(_class.fullName);
4685 ProcessExpressionType(exp);
4689 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4691 if(!_class.dataType)
4692 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4693 type = _class.dataType;
4702 FreeExpContents(exp);
4704 exp.constant = PrintFloat(*(float*)ptr);
4705 exp.type = constantExp;
4710 FreeExpContents(exp);
4712 exp.constant = PrintDouble(*(double*)ptr);
4713 exp.type = constantExp;
4718 FreeExpContents(exp);
4720 exp.constant = PrintInt(*(int*)ptr);
4721 exp.type = constantExp;
4726 FreeExpContents(exp);
4728 exp.constant = PrintInt64(*(int64*)ptr);
4729 exp.type = constantExp;
4734 FreeExpContents(exp);
4735 // TODO: This should probably use proper type
4736 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4737 exp.type = constantExp;
4742 FreeExpContents(exp);
4743 // TODO: This should probably use proper type
4744 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4745 exp.type = constantExp;
4749 Compiler_Error($"Unhandled type populating instance\n");
4752 ListAdd(memberList, member);
4755 if(parentDataMember.type == unionMember)
4760 void PopulateInstance(Instantiation inst)
4762 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4763 Class _class = classSym.registered;
4764 DataMember dataMember;
4765 OldList * memberList = MkList();
4766 // Added this check and ->Add to prevent memory leaks on bad code
4768 inst.members = MkListOne(MkMembersInitList(memberList));
4770 inst.members->Add(MkMembersInitList(memberList));
4771 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4773 if(!dataMember.isProperty)
4775 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4776 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4780 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4782 void * ptr = inst.data + dataMember.offset;
4783 char * result = null;
4785 exp.loc = member.loc = inst.loc;
4786 ((Identifier)member.identifiers->first).loc = inst.loc;
4788 if(!dataMember.dataType)
4789 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4790 type = dataMember.dataType;
4791 if(type.kind == classType)
4793 Class _class = type._class.registered;
4794 if(_class.type == enumClass)
4796 Class enumClass = eSystem_FindClass(privateModule, "enum");
4799 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4801 for(item = e.values.first; item; item = item.next)
4803 if((int)item.data == *(int *)ptr)
4812 exp.identifier = MkIdentifier(result);
4813 exp.type = identifierExp;
4814 exp.destType = MkClassType(_class.fullName);
4815 ProcessExpressionType(exp);
4818 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4820 if(!_class.dataType)
4821 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4822 type = _class.dataType;
4831 exp.constant = PrintFloat(*(float*)ptr);
4832 exp.type = constantExp;
4837 exp.constant = PrintDouble(*(double*)ptr);
4838 exp.type = constantExp;
4843 exp.constant = PrintInt(*(int*)ptr);
4844 exp.type = constantExp;
4849 exp.constant = PrintInt64(*(int64*)ptr);
4850 exp.type = constantExp;
4855 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4856 exp.type = constantExp;
4860 Compiler_Error($"Unhandled type populating instance\n");
4863 ListAdd(memberList, member);
4869 void ComputeInstantiation(Expression exp)
4871 Instantiation inst = exp.instance;
4872 MembersInit members;
4873 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4874 Class _class = classSym ? classSym.registered : null;
4875 DataMember curMember = null;
4876 Class curClass = null;
4877 DataMember subMemberStack[256];
4878 int subMemberStackPos = 0;
4881 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4883 // Don't recompute the instantiation...
4884 // Non Simple classes will have become constants by now
4888 if(_class.type == normalClass || _class.type == noHeadClass)
4890 inst.data = (byte *)eInstance_New(_class);
4891 if(_class.type == normalClass)
4892 ((Instance)inst.data)._refCount++;
4895 inst.data = new0 byte[_class.structSize];
4900 for(members = inst.members->first; members; members = members.next)
4902 switch(members.type)
4904 case dataMembersInit:
4906 if(members.dataMembers)
4909 for(member = members.dataMembers->first; member; member = member.next)
4911 Identifier ident = member.identifiers ? member.identifiers->first : null;
4914 Property prop = null;
4915 DataMember dataMember = null;
4916 Method method = null;
4917 uint dataMemberOffset;
4921 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4924 if(curMember.isProperty)
4925 prop = (Property)curMember;
4928 dataMember = curMember;
4930 // CHANGED THIS HERE
4931 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4933 // 2013/17/29 -- It seems that this was missing here!
4934 if(_class.type == normalClass)
4935 dataMemberOffset += _class.base.structSize;
4936 // dataMemberOffset = dataMember.offset;
4943 prop = eClass_FindProperty(_class, ident.string, privateModule);
4947 if(prop.memberAccess == publicAccess)
4949 curMember = (DataMember)prop;
4950 curClass = prop._class;
4955 DataMember _subMemberStack[256];
4956 int _subMemberStackPos = 0;
4958 // FILL MEMBER STACK
4959 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4964 if(dataMember.memberAccess == publicAccess)
4966 curMember = dataMember;
4967 curClass = dataMember._class;
4968 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4969 subMemberStackPos = _subMemberStackPos;
4975 if(found && member.initializer && member.initializer.type == expInitializer)
4977 Expression value = member.initializer.exp;
4979 bool deepMember = false;
4982 type = prop.dataType;
4986 if(!dataMember.dataType)
4987 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4989 type = dataMember.dataType;
4992 if(ident && ident.next)
4996 // for(; ident && type; ident = ident.next)
4997 for(ident = ident.next; ident && type; ident = ident.next)
4999 if(type.kind == classType)
5001 prop = eClass_FindProperty(type._class.registered,
5002 ident.string, privateModule);
5004 type = prop.dataType;
5007 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
5008 ident.string, &dataMemberOffset, privateModule, null, null);
5010 type = dataMember.dataType;
5013 else if(type.kind == structType || type.kind == unionType)
5016 for(memberType = type.members.first; memberType; memberType = memberType.next)
5018 if(!strcmp(memberType.name, ident.string))
5029 FreeType(value.destType);
5030 value.destType = type;
5031 if(type) type.refCount++;
5032 ComputeExpression(value);
5034 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
5036 if(type.kind == classType)
5038 Class _class = type._class.registered;
5039 if(_class.type == bitClass || _class.type == unitClass ||
5040 _class.type == enumClass)
5042 if(!_class.dataType)
5043 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5044 type = _class.dataType;
5050 void * ptr = inst.data + dataMemberOffset;
5052 if(value.type == constantExp)
5058 GetInt(value, (int*)ptr);
5063 GetInt64(value, (int64*)ptr);
5068 GetIntPtr(value, (intptr*)ptr);
5073 GetIntSize(value, (intsize*)ptr);
5078 GetFloat(value, (float*)ptr);
5083 GetDouble(value, (double *)ptr);
5088 else if(value.type == instanceExp)
5090 if(type.kind == classType)
5092 Class _class = type._class.registered;
5093 if(_class.type == structClass)
5095 ComputeTypeSize(type);
5096 if(value.instance.data)
5097 memcpy(ptr, value.instance.data, type.size);
5104 if(value.type == instanceExp && value.instance.data)
5106 if(type.kind == classType)
5108 Class _class = type._class.registered;
5109 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5111 void (*Set)(void *, void *) = (void *)prop.Set;
5112 Set(inst.data, value.instance.data);
5113 PopulateInstance(inst);
5117 else if(value.type == constantExp)
5123 void (*Set)(void *, double) = (void *)prop.Set;
5124 Set(inst.data, strtod(value.constant, null) );
5129 void (*Set)(void *, float) = (void *)prop.Set;
5130 Set(inst.data, (float)(strtod(value.constant, null)));
5135 void (*Set)(void *, int) = (void *)prop.Set;
5136 Set(inst.data, (int)strtol(value.constant, null, 0));
5141 void (*Set)(void *, int64) = (void *)prop.Set;
5142 Set(inst.data, _strtoi64(value.constant, null, 0));
5147 void (*Set)(void *, intptr) = (void *)prop.Set;
5148 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5153 void (*Set)(void *, intsize) = (void *)prop.Set;
5154 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5159 else if(value.type == stringExp)
5162 ReadString(temp, value.string);
5163 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5167 else if(!deepMember && type && _class.type == unitClass)
5171 // Only support converting units to units for now...
5172 if(value.type == constantExp)
5174 if(type.kind == classType)
5176 Class _class = type._class.registered;
5177 if(_class.type == unitClass)
5179 if(!_class.dataType)
5180 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5181 type = _class.dataType;
5184 // TODO: Assuming same base type for units...
5190 float (*Set)(float) = (void *)prop.Set;
5191 GetFloat(member.initializer.exp, &fValue);
5192 exp.constant = PrintFloat(Set(fValue));
5193 exp.type = constantExp;
5199 double (*Set)(double) = (void *)prop.Set;
5200 GetDouble(member.initializer.exp, &dValue);
5201 exp.constant = PrintDouble(Set(dValue));
5202 exp.type = constantExp;
5209 else if(!deepMember && type && _class.type == bitClass)
5213 if(value.type == instanceExp && value.instance.data)
5215 unsigned int (*Set)(void *) = (void *)prop.Set;
5216 bits = Set(value.instance.data);
5218 else if(value.type == constantExp)
5224 BitMember bitMember = (BitMember) dataMember;
5227 bits = (bits & ~bitMember.mask);
5228 if(!bitMember.dataType)
5229 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5230 type = bitMember.dataType;
5231 if(type.kind == classType && type._class && type._class.registered)
5233 if(!type._class.registered.dataType)
5234 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5235 type = type._class.registered.dataType;
5240 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5241 case shortType: { uint16 v; type.isSigned ? GetShort(value, (uint16 *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5243 case longType: { uint v; type.isSigned ? GetInt(value, (uint *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5244 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (uint64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5245 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (uintptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5246 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (uintsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5248 bits |= part << bitMember.pos;
5254 if(_class && _class.type == unitClass)
5256 ComputeExpression(member.initializer.exp);
5257 exp.constant = member.initializer.exp.constant;
5258 exp.type = constantExp;
5260 member.initializer.exp.constant = null;
5270 if(_class && _class.type == bitClass)
5272 exp.constant = PrintHexUInt(bits);
5273 exp.type = constantExp;
5275 if(exp.type != instanceExp)
5281 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5283 bool result = false;
5287 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5288 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5292 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5293 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5296 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5297 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5298 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5301 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5302 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5303 result = GetOpFloat(op, &op.f);
5306 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5307 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5308 result = GetOpDouble(op, &op.d);
5311 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5312 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5313 result = GetOpUIntPtr(op, &op.ui64);
5316 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5317 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5318 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5321 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5322 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5325 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5326 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5332 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5334 if(exp.op.op == SIZEOF)
5336 FreeExpContents(exp);
5337 exp.type = constantExp;
5338 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5349 // Provide default unary +
5350 Expression exp2 = exp.op.exp2;
5352 FreeExpContents(exp);
5353 FreeType(exp.expType);
5354 FreeType(exp.destType);
5360 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5362 // unary arithmetic increment and decrement
5363 //OPERATOR_ALL(UNARY, ++, Inc)
5364 //OPERATOR_ALL(UNARY, --, Dec)
5367 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5369 // unary logical negation
5371 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5377 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5379 if(Promote(op2, op1.kind, op1.type.isSigned))
5380 op2.kind = op1.kind, op2.ops = op1.ops;
5381 else if(Promote(op1, op2.kind, op2.type.isSigned))
5382 op1.kind = op2.kind, op1.ops = op2.ops;
5386 // binary arithmetic
5388 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5391 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5394 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5397 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5400 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5402 // binary arithmetic assignment
5403 //OPERATOR_ALL(BINARY, =, Asign)
5404 //OPERATOR_ALL(BINARY, +=, AddAsign)
5405 //OPERATOR_ALL(BINARY, -=, SubAsign)
5406 //OPERATOR_ALL(BINARY, *=, MulAsign)
5407 //OPERATOR_ALL(BINARY, /=, DivAsign)
5408 //OPERATOR_ALL(BINARY, %=, ModAsign)
5413 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5417 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5420 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5423 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5426 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5428 // binary bitwise assignment
5429 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5430 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5431 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5432 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5433 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5434 // binary logical equality
5436 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5439 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5443 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5446 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5448 // binary logical relational
5450 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5453 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5456 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5459 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5466 void ComputeExpression(Expression exp)
5468 char expString[10240];
5469 expString[0] = '\0';
5471 PrintExpression(exp, expString);
5478 ComputeInstantiation(exp);
5487 Expression exp1, exp2 = null;
5491 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5494 Expression e = exp.op.exp2;
5496 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5498 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5500 if(e.type == extensionCompoundExp)
5501 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5506 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5508 if(e.type == stringExp && e.string)
5510 char * string = e.string;
5511 int len = strlen(string);
5512 char * tmp = new char[len-2+1];
5513 len = UnescapeString(tmp, string + 1, len - 2);
5515 FreeExpContents(exp);
5516 exp.type = constantExp;
5517 exp.constant = PrintUInt(len + 1);
5521 Type type = e.expType;
5523 FreeExpContents(exp);
5524 exp.type = constantExp;
5525 exp.constant = PrintUInt(ComputeTypeSize(type));
5531 ComputeExpression(exp.op.exp2);
5535 ComputeExpression(exp.op.exp1);
5538 op1 = GetOperand(exp1);
5539 if(op1.type) op1.type.refCount++;
5542 op2 = GetOperand(exp2);
5543 if(op2.type) op2.type.refCount++;
5549 op1 = GetOperand(exp1);
5550 if(op1.type) op1.type.refCount++;
5553 CallOperator(exp, exp1, exp2, op1, op2);
5560 if(exp.op.exp1 && exp.op.exp2)
5565 FreeExpContents(exp);
5566 op1.ops.BitAnd(exp, op1, op2);
5575 FreeExpContents(exp);
5576 op1.ops.Mul(exp, op1, op2);
5585 FreeExpContents(exp);
5586 op1.ops.Add(exp, op1, op2);
5591 // Provide default unary +
5592 Expression exp2 = exp.op.exp2;
5594 FreeExpContents(exp);
5595 FreeType(exp.expType);
5596 FreeType(exp.destType);
5607 FreeExpContents(exp);
5608 op1.ops.Sub(exp, op1, op2);
5615 FreeExpContents(exp);
5616 op1.ops.Neg(exp, op1);
5623 FreeExpContents(exp);
5624 op1.ops.BitNot(exp, op1);
5630 FreeExpContents(exp);
5631 op1.ops.Not(exp, op1);
5634 // Binary only operators
5638 FreeExpContents(exp);
5639 op1.ops.Div(exp, op1, op2);
5645 FreeExpContents(exp);
5646 op1.ops.Mod(exp, op1, op2);
5658 FreeExpContents(exp);
5659 op1.ops.Sma(exp, op1, op2);
5668 FreeExpContents(exp);
5669 op1.ops.Grt(exp, op1, op2);
5678 FreeExpContents(exp);
5679 op1.ops.SmaEqu(exp, op1, op2);
5688 FreeExpContents(exp);
5689 op1.ops.GrtEqu(exp, op1, op2);
5698 FreeExpContents(exp);
5699 op1.ops.Equ(exp, op1, op2);
5708 FreeExpContents(exp);
5709 op1.ops.Nqu(exp, op1, op2);
5716 FreeExpContents(exp);
5717 op1.ops.BitOr(exp, op1, op2);
5723 FreeExpContents(exp);
5724 op1.ops.BitXor(exp, op1, op2);
5732 FreeExpContents(exp);
5733 exp.type = constantExp;
5734 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5738 if(op1.type) FreeType(op1.type);
5739 if(op2.type) FreeType(op2.type);
5743 case extensionExpressionExp:
5746 for(e = exp.list->first; e; e = n)
5751 OldList * list = exp.list;
5752 Expression prev = exp.prev;
5753 Expression next = exp.next;
5754 ComputeExpression(e);
5755 //FreeExpContents(exp);
5756 FreeType(exp.expType);
5757 FreeType(exp.destType);
5776 exp.isConstant = true;
5778 ComputeExpression(exp.index.exp);
5779 if(!exp.index.exp.isConstant)
5780 exp.isConstant = false;
5782 for(e = exp.index.index->first; e; e = e.next)
5784 ComputeExpression(e);
5787 // Check if this type is int
5790 exp.isConstant = false;
5792 exp.expType = Dereference(exp.index.exp.expType);
5798 Expression memberExp = exp.member.exp;
5799 Identifier memberID = exp.member.member;
5802 ComputeExpression(exp.member.exp);
5803 type = exp.member.exp.expType;
5806 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);
5807 Property prop = null;
5808 DataMember member = null;
5809 Class convertTo = null;
5810 if(type.kind == subClassType && exp.member.exp.type == classExp)
5811 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5818 PrintTypeNoConst(type, string, false, true);
5819 classSym = FindClass(string);
5820 _class = classSym ? classSym.registered : null;
5823 if(exp.member.member)
5825 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5827 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5829 if(!prop && !member && _class && exp.member.member)
5831 Symbol classSym = FindClass(exp.member.member.string);
5833 _class = classSym ? classSym.registered : null;
5834 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5841 Type type = prop.dataType;
5842 // TODO: Assuming same base type for units...
5843 if(_class.type == unitClass)
5845 if(type.kind == classType)
5847 Class _class = type._class.registered;
5848 if(_class.type == unitClass)
5850 if(!_class.dataType)
5851 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5852 type = _class.dataType;
5860 float (*Get)(float) = (void *)prop.Get;
5861 GetFloat(exp.member.exp, &value);
5862 exp.constant = PrintFloat(Get ? Get(value) : value);
5863 exp.type = constantExp;
5869 double (*Get)(double);
5870 GetDouble(exp.member.exp, &value);
5873 Get = (void *)prop.Set;
5875 Get = (void *)prop.Get;
5876 exp.constant = PrintDouble(Get ? Get(value) : value);
5877 exp.type = constantExp;
5886 Expression value = exp.member.exp;
5889 ProcessPropertyType(prop);
5891 type = prop.dataType;
5894 // printf("Investigate this\n");
5896 else if(_class.type == structClass)
5902 Class propertyClass = type._class.registered;
5903 if(propertyClass.type == structClass && value.type == instanceExp)
5905 void (*Set)(void *, void *) = (void *)prop.Set;
5906 exp.instance = Instantiation { };
5907 exp.instance.data = new0 byte[_class.structSize];
5908 exp.instance._class = MkSpecifierName(_class.fullName);
5909 exp.instance.loc = exp.loc;
5910 exp.type = instanceExp;
5911 Set(exp.instance.data, value.instance.data);
5912 PopulateInstance(exp.instance);
5919 void (*Set)(void *, int) = (void *)prop.Set;
5921 exp.instance = Instantiation { };
5922 exp.instance.data = new0 byte[_class.structSize];
5923 exp.instance._class = MkSpecifierName(_class.fullName);
5924 exp.instance.loc = exp.loc;
5925 exp.type = instanceExp;
5927 GetInt(value, &intValue);
5929 Set(exp.instance.data, intValue);
5930 PopulateInstance(exp.instance);
5936 void (*Set)(void *, int64) = (void *)prop.Set;
5938 exp.instance = Instantiation { };
5939 exp.instance.data = new0 byte[_class.structSize];
5940 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5941 exp.instance.loc = exp.loc;
5942 exp.type = instanceExp;
5944 GetInt64(value, &intValue);
5946 Set(exp.instance.data, intValue);
5947 PopulateInstance(exp.instance);
5954 void (*Set)(void *, intptr) = (void *)prop.Set;
5956 exp.instance = Instantiation { };
5957 exp.instance.data = new0 byte[_class.structSize];
5958 exp.instance._class = MkSpecifierName(_class.fullName);
5959 exp.instance.loc = exp.loc;
5960 exp.type = instanceExp;
5962 GetIntPtr(value, &intValue);
5964 Set(exp.instance.data, intValue);
5965 PopulateInstance(exp.instance);
5972 void (*Set)(void *, intsize) = (void *)prop.Set;
5974 exp.instance = Instantiation { };
5975 exp.instance.data = new0 byte[_class.structSize];
5976 exp.instance._class = MkSpecifierName(_class.fullName);
5977 exp.instance.loc = exp.loc;
5978 exp.type = instanceExp;
5980 GetIntSize(value, &intValue);
5982 Set(exp.instance.data, intValue);
5983 PopulateInstance(exp.instance);
5989 void (*Set)(void *, float) = (void *)prop.Set;
5991 exp.instance = Instantiation { };
5992 exp.instance.data = new0 byte[_class.structSize];
5993 exp.instance._class = MkSpecifierName(_class.fullName);
5994 exp.instance.loc = exp.loc;
5995 exp.type = instanceExp;
5997 GetFloat(value, &floatValue);
5999 Set(exp.instance.data, floatValue);
6000 PopulateInstance(exp.instance);
6006 void (*Set)(void *, double) = (void *)prop.Set;
6008 exp.instance = Instantiation { };
6009 exp.instance.data = new0 byte[_class.structSize];
6010 exp.instance._class = MkSpecifierName(_class.fullName);
6011 exp.instance.loc = exp.loc;
6012 exp.type = instanceExp;
6014 GetDouble(value, &doubleValue);
6016 Set(exp.instance.data, doubleValue);
6017 PopulateInstance(exp.instance);
6022 else if(_class.type == bitClass)
6028 Class propertyClass = type._class.registered;
6029 if(propertyClass.type == structClass && value.instance.data)
6031 unsigned int (*Set)(void *) = (void *)prop.Set;
6032 unsigned int bits = Set(value.instance.data);
6033 exp.constant = PrintHexUInt(bits);
6034 exp.type = constantExp;
6037 else if(_class.type == bitClass)
6040 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6043 GetUInt(exp.member.exp, &value);
6045 exp.constant = PrintHexUInt(bits);
6046 exp.type = constantExp;
6054 if(_class.type == bitClass)
6057 GetUInt(exp.member.exp, &value);
6063 Class _class = type._class.registered;
6064 if(_class.type == structClass)
6066 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6068 exp.instance = Instantiation { };
6069 exp.instance.data = new0 byte[_class.structSize];
6070 exp.instance._class = MkSpecifierName(_class.fullName);
6071 exp.instance.loc = exp.loc;
6072 //exp.instance.fullSet = true;
6073 exp.type = instanceExp;
6074 Get(value, exp.instance.data);
6075 PopulateInstance(exp.instance);
6077 else if(_class.type == bitClass)
6079 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6080 uint64 bits = Get(value);
6081 exp.constant = PrintHexUInt64(bits);
6082 exp.type = constantExp;
6088 else if(_class.type == structClass)
6090 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6095 Class _class = type._class.registered;
6096 if(_class.type == structClass && value)
6098 void (*Get)(void *, void *) = (void *)prop.Get;
6100 exp.instance = Instantiation { };
6101 exp.instance.data = new0 byte[_class.structSize];
6102 exp.instance._class = MkSpecifierName(_class.fullName);
6103 exp.instance.loc = exp.loc;
6104 //exp.instance.fullSet = true;
6105 exp.type = instanceExp;
6106 Get(value, exp.instance.data);
6107 PopulateInstance(exp.instance);
6115 char * value = exp.member.exp.instance.data;
6120 Class _class = type._class.registered;
6121 if(_class.type == normalClass)
6123 void *(*Get)(void *) = (void *)prop.Get;
6125 exp.instance = Instantiation { };
6126 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6127 exp.type = instanceExp;
6128 exp.instance.data = Get(value, exp.instance.data);
6140 exp.isConstant = false;
6148 if(exp.type != ExpressionType::memberExp)
6150 FreeExpression(memberExp);
6151 FreeIdentifier(memberID);
6157 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6158 FreeExpContents(exp);
6159 exp.constant = PrintUInt(ComputeTypeSize(type));
6160 exp.type = constantExp;
6166 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6167 if(classSym && classSym.registered)
6169 if(classSym.registered.fixed)
6171 FreeSpecifier(exp._class);
6172 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6173 exp.type = constantExp;
6177 char className[1024];
6178 strcpy(className, "__ecereClass_");
6179 FullClassNameCat(className, classSym.string, true);
6180 MangleClassName(className);
6182 DeclareClass(classSym, className);
6184 FreeExpContents(exp);
6185 exp.type = pointerExp;
6186 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6187 exp.member.member = MkIdentifier("structSize");
6197 if(exp.type == castExp)
6200 ComputeExpression(exp.cast.exp);
6203 if(e && exp.expType)
6206 type = exp.destType;
6209 if(type.kind == classType)
6211 Class _class = type._class.registered;
6212 if(_class && (_class.type == unitClass || _class.type == bitClass))
6214 if(!_class.dataType)
6215 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6216 type = _class.dataType;
6227 if(GetChar(e, &value))
6229 FreeExpContents(exp);
6230 exp.constant = PrintChar(value);
6231 exp.type = constantExp;
6236 unsigned char value = 0;
6237 if(GetUChar(e, &value))
6239 FreeExpContents(exp);
6240 exp.constant = PrintUChar(value);
6241 exp.type = constantExp;
6249 if(GetShort(e, &value))
6251 FreeExpContents(exp);
6252 exp.constant = PrintShort(value);
6253 exp.type = constantExp;
6258 unsigned short value = 0;
6259 if(GetUShort(e, &value))
6261 FreeExpContents(exp);
6262 exp.constant = PrintUShort(value);
6263 exp.type = constantExp;
6271 if(GetInt(e, &value))
6273 FreeExpContents(exp);
6274 exp.constant = PrintInt(value);
6275 exp.type = constantExp;
6280 unsigned int value = 0;
6281 if(GetUInt(e, &value))
6283 FreeExpContents(exp);
6284 exp.constant = PrintUInt(value);
6285 exp.type = constantExp;
6293 if(GetInt64(e, &value))
6295 FreeExpContents(exp);
6296 exp.constant = PrintInt64(value);
6297 exp.type = constantExp;
6303 if(GetUInt64(e, &value))
6305 FreeExpContents(exp);
6306 exp.constant = PrintUInt64(value);
6307 exp.type = constantExp;
6315 if(GetIntPtr(e, &value))
6317 FreeExpContents(exp);
6318 exp.constant = PrintInt64((int64)value);
6319 exp.type = constantExp;
6325 if(GetUIntPtr(e, &value))
6327 FreeExpContents(exp);
6328 exp.constant = PrintUInt64((uint64)value);
6329 exp.type = constantExp;
6337 if(GetIntSize(e, &value))
6339 FreeExpContents(exp);
6340 exp.constant = PrintInt64((int64)value);
6341 exp.type = constantExp;
6347 if(GetUIntSize(e, &value))
6349 FreeExpContents(exp);
6350 exp.constant = PrintUInt64((uint64)value);
6351 exp.type = constantExp;
6358 if(GetFloat(e, &value))
6360 FreeExpContents(exp);
6361 exp.constant = PrintFloat(value);
6362 exp.type = constantExp;
6369 if(GetDouble(e, &value))
6371 FreeExpContents(exp);
6372 exp.constant = PrintDouble(value);
6373 exp.type = constantExp;
6388 // Caring only about last expression for now...
6389 ComputeExpression(exp.cond.exp->last);
6390 if(exp.cond.elseExp)
6391 ComputeExpression(exp.cond.elseExp);
6393 ComputeExpression(exp.cond.cond);
6395 op1 = GetOperand(exp.cond.cond);
6396 if(op1.type) op1.type.refCount++;
6397 op2 = GetOperand(exp.cond.exp->last);
6398 if(op2.type) op2.type.refCount++;
6399 op3 = GetOperand(exp.cond.elseExp);
6400 if(op3.type) op3.type.refCount++;
6402 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6403 if(op1.type) FreeType(op1.type);
6404 if(op2.type) FreeType(op2.type);
6405 if(op3.type) FreeType(op3.type);
6411 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6416 OldList converts { };
6419 if(destType.kind == voidType)
6422 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6426 // for(convert = converts.last; convert; convert = convert.prev)
6427 for(convert = converts.first; convert; convert = convert.next)
6429 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6432 Expression newExp { };
6433 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6435 // TODO: Check this...
6439 newExp.destType = null;
6444 exp.type = memberExp;
6445 exp.addedThis = true;
6446 exp.member.exp = newExp;
6447 FreeType(exp.member.exp.expType);
6449 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6450 exp.member.exp.expType.classObjectType = objectType;
6451 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6452 exp.member.memberType = propertyMember;
6453 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6454 // TESTING THIS... for (int)degrees
6455 exp.needCast = true;
6456 if(exp.expType) exp.expType.refCount++;
6457 ApplyAnyObjectLogic(exp.member.exp);
6462 /*if(exp.isConstant)
6464 // Color { ColorRGB = [exp] };
6465 exp.type = instanceExp;
6466 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6467 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6468 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6472 // If not constant, don't turn it yet into an instantiation
6473 // (Go through the deep members system first)
6474 exp.type = memberExp;
6475 exp.addedThis = true;
6476 exp.member.exp = newExp;
6478 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6479 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6480 newExp.expType._class.registered.type == noHeadClass)
6482 newExp.byReference = true;
6485 FreeType(exp.member.exp.expType);
6486 /*exp.member.exp.expType = convert.convert.dataType;
6487 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6488 exp.member.exp.expType = null;
6489 if(convert.convert.dataType)
6491 exp.member.exp.expType = { };
6492 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6493 exp.member.exp.expType.refCount = 1;
6494 exp.member.exp.expType.classObjectType = objectType;
6495 ApplyAnyObjectLogic(exp.member.exp);
6498 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6499 exp.member.memberType = reverseConversionMember;
6500 exp.expType = convert.resultType ? convert.resultType :
6501 MkClassType(convert.convert._class.fullName);
6502 exp.needCast = true;
6503 if(convert.resultType) convert.resultType.refCount++;
6509 FreeType(exp.expType);
6512 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6513 exp.needCast = true;
6514 if(exp.expType) exp.expType.refCount++;
6518 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6519 exp.needCast = true;
6520 if(convert.resultType)
6521 convert.resultType.refCount++;
6525 if(exp.isConstant && inCompiler)
6526 ComputeExpression(exp);
6528 converts.Free(FreeConvert);
6531 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6533 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6535 if(!result && exp.expType && exp.destType)
6537 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6538 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6539 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6540 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6544 // if(result) CheckTemplateTypes(exp);
6548 void CheckTemplateTypes(Expression exp)
6550 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6552 Expression newExp { };
6555 if(exp.destType) exp.destType.refCount++;
6556 if(exp.expType) exp.expType.refCount++;
6560 switch(exp.expType.kind)
6563 if(exp.destType.classObjectType)
6565 // We need to pass the address, just pass it along (Undo what was done above)
6566 if(exp.destType) exp.destType.refCount--;
6567 if(exp.expType) exp.expType.refCount--;
6572 // If we're looking for value:
6573 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6575 OldList * unionDefs = MkList();
6576 OldList * statements = MkList();
6577 context = PushContext();
6578 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6579 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6580 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6581 exp.type = extensionCompoundExp;
6582 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6583 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6584 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6585 exp.compound.compound.context = context;
6586 PopContext(context);
6591 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6592 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6596 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6598 Expression newExp { };
6602 if(exp.destType) exp.destType.refCount++;
6603 if(exp.expType) exp.expType.refCount++;
6607 switch(exp.expType.kind)
6610 if(exp.destType.classObjectType)
6612 // We need to pass the address, just pass it along (Undo what was done above)
6613 if(exp.destType) exp.destType.refCount--;
6614 if(exp.expType) exp.expType.refCount--;
6619 // If we're looking for value:
6620 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6622 OldList * unionDefs = MkList();
6623 OldList * statements = MkList();
6624 context = PushContext();
6625 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6626 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6627 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6628 exp.type = extensionCompoundExp;
6629 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6630 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6631 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6632 exp.compound.compound.context = context;
6633 PopContext(context);
6638 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6640 exp.type = bracketsExp;
6641 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6642 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6643 ProcessExpressionType(exp.list->first);
6648 exp.type = bracketsExp;
6649 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6650 newExp.needCast = true;
6651 ProcessExpressionType(exp.list->first);
6657 if(exp.expType.kind == templateType)
6659 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6662 FreeType(exp.destType);
6663 FreeType(exp.expType);
6668 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6673 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6674 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6678 char typeString[1024];
6680 OldList * specs = MkList();
6681 typeString[0] = '\0';
6682 PrintType(exp.expType, typeString, false, false);
6683 decl = SpecDeclFromString(typeString, specs, null);
6686 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6687 exp.cast.typeName = MkTypeName(specs, decl);
6688 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6689 exp.cast.exp.needCast = true;
6696 // TODO: The Symbol tree should be reorganized by namespaces
6698 // - Tree of all symbols within (stored without namespace)
6699 // - Tree of sub-namespaces
6701 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6703 int nsLen = strlen(nameSpace);
6705 // Start at the name space prefix
6706 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6708 char * s = symbol.string;
6709 if(!strncmp(s, nameSpace, nsLen))
6711 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6714 for(c = strlen(s)-1; c >= 0; c--)
6719 if(!strcmp(namePart, name))
6721 // TODO: Error on ambiguity
6731 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6734 char nameSpace[1024];
6735 const char * namePart;
6736 bool gotColon = false;
6738 nameSpace[0] = '\0';
6739 for(c = strlen(name)-1; c >= 0; c--)
6746 namePart = name+c+1;
6747 while(c >= 0 && name[c] == ':') c--;
6750 // Try an exact match first
6751 Symbol symbol = (Symbol)tree.FindString(name);
6755 // Namespace specified
6756 memcpy(nameSpace, name, c + 1);
6759 return ScanWithNameSpace(tree, nameSpace, namePart);
6763 // Looking for a global symbol, e.g. ::Sleep()
6764 Symbol symbol = (Symbol)tree.FindString(namePart);
6769 // Name only (no namespace specified)
6770 Symbol symbol = (Symbol)tree.FindString(namePart);
6773 return ScanWithNameSpace(tree, "", namePart);
6778 static void ProcessDeclaration(Declaration decl);
6780 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6783 //Time startTime = GetTime();
6785 // Optimize this later? Do this before/less?
6787 Symbol symbol = null;
6788 // First, check if the identifier is declared inside the function
6789 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6791 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6793 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6799 strcpy(curName, thisNameSpace);
6800 strcat(curName, "::");
6801 strcat(curName, name);
6802 // Try to resolve in current namespace first
6803 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6806 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6809 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6811 if(symbol || ctx == endContext) break;
6813 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6815 if(symbol.pointerExternal.type == functionExternal)
6817 FunctionDefinition function = symbol.pointerExternal.function;
6819 // Modified this recently...
6820 Context tmpContext = curContext;
6822 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6823 curContext = tmpContext;
6825 symbol.pointerExternal.symbol = symbol;
6828 DeclareType(symbol.type, true, true);
6830 ast->Insert(curExternal.prev, symbol.pointerExternal);
6832 symbol.id = curExternal.symbol.idCode;
6835 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6837 ast->Move(symbol.pointerExternal, curExternal.prev);
6838 symbol.id = curExternal.symbol.idCode;
6842 //findSymbolTotalTime += GetTime() - startTime;
6847 static void GetTypeSpecs(Type type, OldList * specs)
6849 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6854 if(type._class.registered)
6856 if(!type._class.registered.dataType)
6857 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6858 GetTypeSpecs(type._class.registered.dataType, specs);
6862 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6863 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6864 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6865 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6866 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6867 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6868 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6869 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6872 ListAdd(specs, MkSpecifier(INT)); break;
6876 static void PrintArraySize(Type arrayType, char * string)
6881 if(arrayType.enumClass)
6882 strcat(size, arrayType.enumClass.string);
6883 else if(arrayType.arraySizeExp)
6884 PrintExpression(arrayType.arraySizeExp, size);
6886 strcat(string, size);
6889 // WARNING : This function expects a null terminated string since it recursively concatenate...
6890 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6894 if(printConst && type.constant)
6895 strcat(string, "const ");
6900 Symbol c = type._class;
6901 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6902 // look into merging with thisclass ?
6903 if(type.classObjectType == typedObject)
6904 strcat(string, "typed_object");
6905 else if(type.classObjectType == anyObject)
6906 strcat(string, "any_object");
6910 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6912 if(type.byReference)
6913 strcat(string, " &");
6916 case voidType: strcat(string, "void"); break;
6917 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6918 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6919 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6920 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6921 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6922 case _BoolType: strcat(string, "_Bool"); break;
6923 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6924 case floatType: strcat(string, "float"); break;
6925 case doubleType: strcat(string, "double"); break;
6929 strcat(string, "struct ");
6930 strcat(string, type.enumName);
6932 else if(type.typeName)
6933 strcat(string, type.typeName);
6937 strcat(string, "struct { ");
6938 for(member = type.members.first; member; member = member.next)
6940 PrintType(member, string, true, fullName);
6941 strcat(string,"; ");
6949 strcat(string, "union ");
6950 strcat(string, type.enumName);
6952 else if(type.typeName)
6953 strcat(string, type.typeName);
6956 strcat(string, "union ");
6957 strcat(string,"(unnamed)");
6963 strcat(string, "enum ");
6964 strcat(string, type.enumName);
6966 else if(type.typeName)
6967 strcat(string, type.typeName);
6969 strcat(string, "int"); // "enum");
6972 strcat(string, "...");
6975 strcat(string, "subclass(");
6976 strcat(string, type._class ? type._class.string : "int");
6977 strcat(string, ")");
6980 strcat(string, type.templateParameter.identifier.string);
6983 strcat(string, "thisclass");
6986 strcat(string, "__builtin_va_list");
6992 static void PrintName(Type type, char * string, bool fullName)
6994 if(type.name && type.name[0])
6997 strcat(string, type.name);
7000 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7001 if(name) name += 2; else name = type.name;
7002 strcat(string, name);
7007 static void PrintAttribs(Type type, char * string)
7011 if(type.dllExport) strcat(string, "dllexport ");
7012 if(type.attrStdcall) strcat(string, "stdcall ");
7016 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7018 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7020 Type attrType = null;
7021 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7022 PrintAttribs(type, string);
7023 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7024 strcat(string, " const");
7025 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7026 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7027 strcat(string, " (");
7028 if(type.kind == pointerType)
7030 if(type.type.kind == functionType || type.type.kind == methodType)
7031 PrintAttribs(type.type, string);
7033 if(type.kind == pointerType)
7035 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7036 strcat(string, "*");
7038 strcat(string, " *");
7040 if(printConst && type.constant && type.kind == pointerType)
7041 strcat(string, " const");
7044 PrintTypeSpecs(type, string, fullName, printConst);
7047 static void PostPrintType(Type type, char * string, bool fullName)
7049 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7050 strcat(string, ")");
7051 if(type.kind == arrayType)
7052 PrintArraySize(type, string);
7053 else if(type.kind == functionType)
7056 strcat(string, "(");
7057 for(param = type.params.first; param; param = param.next)
7059 PrintType(param, string, true, fullName);
7060 if(param.next) strcat(string, ", ");
7062 strcat(string, ")");
7064 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7065 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7069 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7071 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7073 PrePrintType(type, string, fullName, null, printConst);
7075 if(type.thisClass || (printName && type.name && type.name[0]))
7076 strcat(string, " ");
7077 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7079 Symbol _class = type.thisClass;
7080 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7082 if(type.classObjectType == classPointer)
7083 strcat(string, "class");
7085 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7087 else if(_class && _class.string)
7089 String s = _class.string;
7094 char * name = RSearchString(s, "::", strlen(s), true, false);
7095 if(name) name += 2; else name = s;
7096 strcat(string, name);
7099 strcat(string, "::");
7102 if(printName && type.name)
7103 PrintName(type, string, fullName);
7104 PostPrintType(type, string, fullName);
7105 if(type.bitFieldCount)
7108 sprintf(count, ":%d", type.bitFieldCount);
7109 strcat(string, count);
7113 void PrintType(Type type, char * string, bool printName, bool fullName)
7115 _PrintType(type, string, printName, fullName, true);
7118 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7120 _PrintType(type, string, printName, fullName, false);
7123 static Type FindMember(Type type, char * string)
7126 for(memberType = type.members.first; memberType; memberType = memberType.next)
7128 if(!memberType.name)
7130 Type subType = FindMember(memberType, string);
7134 else if(!strcmp(memberType.name, string))
7140 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7143 for(memberType = type.members.first; memberType; memberType = memberType.next)
7145 if(!memberType.name)
7147 Type subType = FindMember(memberType, string);
7150 *offset += memberType.offset;
7154 else if(!strcmp(memberType.name, string))
7156 *offset += memberType.offset;
7163 public bool GetParseError() { return parseError; }
7165 Expression ParseExpressionString(char * expression)
7169 fileInput = TempFile { };
7170 fileInput.Write(expression, 1, strlen(expression));
7171 fileInput.Seek(0, start);
7174 parsedExpression = null;
7176 expression_yyparse();
7179 return parsedExpression;
7182 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7184 Identifier id = exp.identifier;
7185 Method method = null;
7186 Property prop = null;
7187 DataMember member = null;
7188 ClassProperty classProp = null;
7190 if(_class && _class.type == enumClass)
7192 NamedLink value = null;
7193 Class enumClass = eSystem_FindClass(privateModule, "enum");
7197 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7199 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7200 for(value = e.values.first; value; value = value.next)
7202 if(!strcmp(value.name, id.string))
7209 FreeExpContents(exp);
7211 exp.type = constantExp;
7212 exp.isConstant = true;
7213 if(!strcmp(baseClass.dataTypeString, "int"))
7214 sprintf(constant, "%d",(int)value.data);
7216 sprintf(constant, "0x%X",(int)value.data);
7217 exp.constant = CopyString(constant);
7218 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7219 exp.expType = MkClassType(baseClass.fullName);
7227 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7229 ProcessMethodType(method);
7236 // TOCHECK: Put it back to what it was...
7237 // methodClass = _class;
7238 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7243 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7246 ProcessPropertyType(prop);
7247 exp.expType = prop.dataType;
7248 if(prop.dataType) prop.dataType.refCount++;
7251 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7253 if(!member.dataType)
7254 member.dataType = ProcessTypeString(member.dataTypeString, false);
7255 exp.expType = member.dataType;
7256 if(member.dataType) member.dataType.refCount++;
7259 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7261 if(!classProp.dataType)
7262 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7264 if(classProp.constant)
7266 FreeExpContents(exp);
7268 exp.isConstant = true;
7269 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7271 //char constant[256];
7272 exp.type = stringExp;
7273 exp.constant = QMkString((char *)classProp.Get(_class));
7278 exp.type = constantExp;
7279 sprintf(constant, "%d", (int)classProp.Get(_class));
7280 exp.constant = CopyString(constant);
7288 exp.expType = classProp.dataType;
7289 if(classProp.dataType) classProp.dataType.refCount++;
7295 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7297 BinaryTree * tree = &nameSpace.functions;
7298 GlobalData data = (GlobalData)tree->FindString(name);
7302 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7304 data = ScanGlobalData(child, name);
7312 static GlobalData FindGlobalData(char * name)
7315 NameSpace * nameSpace;
7316 nameSpace = globalData;
7317 for(c = 0; name[c]; c++)
7319 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7321 NameSpace * newSpace;
7322 char * spaceName = new char[c - start + 1];
7323 strncpy(spaceName, name + start, c - start);
7324 spaceName[c-start] = '\0';
7325 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7329 nameSpace = newSpace;
7330 if(name[c] == ':') c++;
7336 return ScanGlobalData(nameSpace, name + start);
7341 static int definedExpStackPos;
7342 static void * definedExpStack[512];
7344 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7345 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7347 Expression prev = checkedExp.prev, next = checkedExp.next;
7349 FreeExpContents(checkedExp);
7350 FreeType(checkedExp.expType);
7351 FreeType(checkedExp.destType);
7353 *checkedExp = *newExp;
7357 checkedExp.prev = prev;
7358 checkedExp.next = next;
7361 void ApplyAnyObjectLogic(Expression e)
7363 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7365 char debugExpString[4096];
7366 debugExpString[0] = '\0';
7367 PrintExpression(e, debugExpString);
7370 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7372 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7373 //ellipsisDestType = destType;
7376 Type type = e.expType;
7377 Class _class = null;
7378 //Type destType = e.destType;
7380 if(type.kind == classType && type._class && type._class.registered)
7382 _class = type._class.registered;
7384 else if(type.kind == subClassType)
7386 _class = FindClass("ecere::com::Class").registered;
7390 char string[1024] = "";
7393 PrintTypeNoConst(type, string, false, true);
7394 classSym = FindClass(string);
7395 if(classSym) _class = classSym.registered;
7398 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...
7399 (!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))) ||
7400 destType.byReference)))
7402 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7404 Expression checkedExp = e, newExp;
7406 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7408 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7410 if(checkedExp.type == extensionCompoundExp)
7412 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7415 checkedExp = checkedExp.list->last;
7417 else if(checkedExp.type == castExp)
7418 checkedExp = checkedExp.cast.exp;
7421 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7423 newExp = checkedExp.op.exp2;
7424 checkedExp.op.exp2 = null;
7425 FreeExpContents(checkedExp);
7427 if(e.expType && e.expType.passAsTemplate)
7430 ComputeTypeSize(e.expType);
7431 sprintf(size, "%d", e.expType.size);
7432 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7433 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7434 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7437 ReplaceExpContents(checkedExp, newExp);
7438 e.byReference = true;
7440 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7442 Expression checkedExp; //, newExp;
7445 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7447 e.type == identifierExp ||
7448 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7449 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7450 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7453 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7455 Context context = PushContext();
7457 OldList * specs = MkList();
7458 char typeString[1024];
7459 Expression newExp { };
7461 typeString[0] = '\0';
7464 //if(e.destType) e.destType.refCount++;
7465 // if(exp.expType) exp.expType.refCount++;
7468 newExp.expType = null;
7470 PrintTypeNoConst(e.expType, typeString, false, true);
7471 decl = SpecDeclFromString(typeString, specs, null);
7472 newExp.destType = ProcessType(specs, decl);
7474 curContext = context;
7476 // We need a current compound for this
7480 OldList * stmts = MkList();
7481 e.type = extensionCompoundExp;
7482 sprintf(name, "__internalValue%03X", internalValueCounter++);
7483 if(!curCompound.compound.declarations)
7484 curCompound.compound.declarations = MkList();
7485 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7486 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7487 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7488 e.compound = MkCompoundStmt(null, stmts);
7491 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7494 e.compound = MkCompoundStmt(
7495 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7496 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7498 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7502 Type type = e.destType;
7504 CopyTypeInto(e.destType, type);
7505 e.destType.refCount = 1;
7506 e.destType.classObjectType = none;
7510 e.compound.compound.context = context;
7511 PopContext(context);
7512 curContext = context.parent;
7516 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7518 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7520 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7522 if(checkedExp.type == extensionCompoundExp)
7524 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7527 checkedExp = checkedExp.list->last;
7529 else if(checkedExp.type == castExp)
7530 checkedExp = checkedExp.cast.exp;
7533 Expression operand { };
7534 operand = *checkedExp;
7535 checkedExp.destType = null;
7536 checkedExp.expType = null;
7538 checkedExp.type = opExp;
7539 checkedExp.op.op = '&';
7540 checkedExp.op.exp1 = null;
7541 checkedExp.op.exp2 = operand;
7543 //newExp = MkExpOp(null, '&', checkedExp);
7545 //ReplaceExpContents(checkedExp, newExp);
7552 // If expression type is a simple class, make it an address
7553 // FixReference(e, true);
7556 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7557 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7558 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7560 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"))
7562 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7566 Expression thisExp { };
7569 thisExp.prev = null;
7570 thisExp.next = null;
7573 e.type = bracketsExp;
7574 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7575 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7576 ((Expression)e.list->first).byReference = true;
7578 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7580 e.expType = thisExp.expType;
7581 e.expType.refCount++;
7586 CopyTypeInto(e.expType, thisExp.expType);
7587 e.expType.byReference = false;
7588 e.expType.refCount = 1;
7590 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7591 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7593 e.expType.classObjectType = none;
7598 // TOFIX: Try this for a nice IDE crash!
7600 // The other way around
7603 if(destType && e.expType &&
7604 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7605 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7606 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7608 if(destType.kind == ellipsisType)
7610 Compiler_Error($"Unspecified type\n");
7612 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7614 bool byReference = e.expType.byReference;
7615 Expression thisExp { };
7617 OldList * specs = MkList();
7618 char typeString[1024]; // Watch buffer overruns
7620 ClassObjectType backupClassObjectType;
7621 bool backupByReference;
7623 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7628 backupClassObjectType = type.classObjectType;
7629 backupByReference = type.byReference;
7631 type.classObjectType = none;
7632 type.byReference = false;
7634 typeString[0] = '\0';
7635 PrintType(type, typeString, false, true);
7636 decl = SpecDeclFromString(typeString, specs, null);
7638 type.classObjectType = backupClassObjectType;
7639 type.byReference = backupByReference;
7642 thisExp.prev = null;
7643 thisExp.next = null;
7646 if( ( type.kind == classType && type._class && type._class.registered &&
7647 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7648 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7649 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7650 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7655 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7658 CopyTypeInto(e.expType, type);
7659 e.expType.byReference = false;
7660 e.expType.refCount = 1;
7665 e.cast.typeName = MkTypeName(specs, decl);
7666 e.cast.exp = thisExp;
7667 e.byReference = true;
7671 e.destType = destType;
7672 destType.refCount++;
7677 void ApplyLocation(Expression exp, Location loc)
7683 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7684 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7690 for(e = exp.list->first; e; e = e.next)
7691 ApplyLocation(e, loc);
7698 for(e = exp.index.index->first; e; e = e.next)
7699 ApplyLocation(e, loc);
7702 ApplyLocation(exp.index.exp, loc);
7705 if(exp.call.arguments)
7708 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7709 ApplyLocation(arg, loc);
7712 ApplyLocation(exp.call.exp, loc);
7717 ApplyLocation(exp.member.exp, loc);
7721 ApplyLocation(exp.cast.exp, loc);
7727 for(e = exp.cond.exp->first; e; e = e.next)
7728 ApplyLocation(e, loc);
7731 ApplyLocation(exp.cond.cond, loc);
7732 if(exp.cond.elseExp)
7733 ApplyLocation(exp.cond.elseExp, loc);
7737 ApplyLocation(exp.vaArg.exp, loc);
7744 void ProcessExpressionType(Expression exp)
7746 bool unresolved = false;
7747 Location oldyylloc = yylloc;
7748 bool notByReference = false;
7750 char debugExpString[4096];
7751 debugExpString[0] = '\0';
7752 PrintExpression(exp, debugExpString);
7754 if(!exp || exp.expType)
7757 //eSystem_Logf("%s\n", expString);
7759 // Testing this here
7765 Identifier id = exp.identifier;
7766 if(!id || !topContext) return;
7768 // DOING THIS LATER NOW...
7769 if(id._class && id._class.name)
7771 id.classSym = id._class.symbol; // FindClass(id._class.name);
7772 /* TODO: Name Space Fix ups
7774 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7778 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7780 exp.expType = ProcessTypeString("Module", true);
7783 else */if(strstr(id.string, "__ecereClass") == id.string)
7785 exp.expType = ProcessTypeString("ecere::com::Class", true);
7788 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7790 // Added this here as well
7791 ReplaceClassMembers(exp, thisClass);
7792 if(exp.type != identifierExp)
7794 ProcessExpressionType(exp);
7798 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7803 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7804 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7805 if(!symbol/* && exp.destType*/)
7807 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7813 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7814 if(exp.type != identifierExp)
7816 ProcessExpressionType(exp);
7820 // Static methods called from inside the _class
7821 else if(currentClass && !id._class)
7823 if(ResolveIdWithClass(exp, currentClass, true))
7826 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7830 // If we manage to resolve this symbol
7833 Type type = symbol.type;
7834 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7836 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7838 Context context = SetupTemplatesContext(_class);
7839 type = ReplaceThisClassType(_class);
7840 FinishTemplatesContext(context);
7841 if(type) type.refCount = 0; // We'll be incrementing it right below...
7844 FreeSpecifier(id._class);
7847 id.string = CopyString(symbol.string);
7854 // Commented this out, it was making non-constant enum parameters seen as constant
7855 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7856 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7857 // Add missing cases here... enum Classes...
7858 exp.isConstant = true;
7860 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7861 if(symbol.isParam || !strcmp(id.string, "this"))
7863 if(_class && _class.type == structClass && !type.declaredWithStruct)
7864 exp.byReference = true;
7866 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7867 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7868 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7869 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7871 Identifier id = exp.identifier;
7872 exp.type = bracketsExp;
7873 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7877 if(symbol.isIterator)
7879 if(symbol.isIterator == 3)
7881 exp.type = bracketsExp;
7882 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7883 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7885 ProcessExpressionType(exp);
7887 else if(symbol.isIterator != 4)
7889 exp.type = memberExp;
7890 exp.member.exp = MkExpIdentifier(exp.identifier);
7891 exp.member.exp.expType = exp.expType;
7892 /*if(symbol.isIterator == 6)
7893 exp.member.member = MkIdentifier("key");
7895 exp.member.member = MkIdentifier("data");
7897 ProcessExpressionType(exp);
7904 DefinedExpression definedExp = null;
7905 if(thisNameSpace && !(id._class && !id._class.name))
7908 strcpy(name, thisNameSpace);
7910 strcat(name, id.string);
7911 definedExp = eSystem_FindDefine(privateModule, name);
7914 definedExp = eSystem_FindDefine(privateModule, id.string);
7918 for(c = 0; c<definedExpStackPos; c++)
7919 if(definedExpStack[c] == definedExp)
7921 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7923 Location backupYylloc = yylloc;
7924 File backInput = fileInput;
7925 definedExpStack[definedExpStackPos++] = definedExp;
7927 fileInput = TempFile { };
7928 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7929 fileInput.Seek(0, start);
7932 parsedExpression = null;
7934 expression_yyparse();
7937 fileInput = backInput;
7939 yylloc = backupYylloc;
7941 if(parsedExpression)
7944 exp.type = bracketsExp;
7945 exp.list = MkListOne(parsedExpression);
7946 ApplyLocation(parsedExpression, yylloc);
7947 ProcessExpressionType(exp);
7948 definedExpStackPos--;
7951 definedExpStackPos--;
7957 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7963 GlobalData data = null;
7964 if(thisNameSpace && !(id._class && !id._class.name))
7967 strcpy(name, thisNameSpace);
7969 strcat(name, id.string);
7970 data = FindGlobalData(name);
7973 data = FindGlobalData(id.string);
7976 DeclareGlobalData(data);
7977 exp.expType = data.dataType;
7978 if(data.dataType) data.dataType.refCount++;
7981 id.string = CopyString(data.fullName);
7982 FreeSpecifier(id._class);
7989 GlobalFunction function = null;
7990 if(thisNameSpace && !(id._class && !id._class.name))
7993 strcpy(name, thisNameSpace);
7995 strcat(name, id.string);
7996 function = eSystem_FindFunction(privateModule, name);
7999 function = eSystem_FindFunction(privateModule, id.string);
8004 id.string = CopyString(function.name);
8007 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8008 strcpy(name, "__ecereFunction_");
8009 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8010 if(DeclareFunction(function, name))
8013 id.string = CopyString(name);
8015 exp.expType = function.dataType;
8016 if(function.dataType) function.dataType.refCount++;
8018 FreeSpecifier(id._class);
8035 if(!exp.instance._class)
8037 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8039 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8043 //classSym = FindClass(exp.instance._class.fullName);
8044 //_class = classSym ? classSym.registered : null;
8046 ProcessInstantiationType(exp.instance);
8048 exp.isConstant = exp.instance.isConstant;
8051 if(_class.type == unitClass && _class.base.type != systemClass)
8054 Type destType = exp.destType;
8056 exp.destType = MkClassType(_class.base.fullName);
8057 exp.expType = MkClassType(_class.fullName);
8058 CheckExpressionType(exp, exp.destType, true);
8060 exp.destType = destType;
8062 exp.expType = MkClassType(_class.fullName);
8065 if(exp.instance._class)
8067 exp.expType = MkClassType(exp.instance._class.name);
8068 /*if(exp.expType._class && exp.expType._class.registered &&
8069 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8070 exp.expType.byReference = true;*/
8078 char * constant = exp.constant;
8086 if(constant[0] == '\'')
8088 if((int)((byte *)constant)[1] > 127)
8091 unichar ch = UTF8GetChar(constant + 1, &nb);
8092 if(nb < 2) ch = constant[1];
8094 exp.constant = PrintUInt(ch);
8095 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8096 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8097 type._class = FindClass("unichar");
8099 type.isSigned = false;
8103 type.kind = charType;
8104 type.isSigned = true;
8109 char * dot = strchr(constant, '.');
8110 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8114 exponent = strchr(constant, 'p');
8115 if(!exponent) exponent = strchr(constant, 'P');
8119 exponent = strchr(constant, 'e');
8120 if(!exponent) exponent = strchr(constant, 'E');
8125 if(strchr(constant, 'f') || strchr(constant, 'F'))
8126 type.kind = floatType;
8128 type.kind = doubleType;
8129 type.isSigned = true;
8133 bool isSigned = constant[0] == '-';
8135 int64 i64 = strtoll(constant, &endP, 0);
8136 uint64 ui64 = strtoull(constant, &endP, 0);
8137 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8150 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8154 else if(constant[0] != '0' || !constant[1])
8157 type.kind = is64Bit ? int64Type : intType;
8158 type.isSigned = isSigned;
8161 exp.isConstant = true;
8162 if(exp.destType && exp.destType.kind == doubleType)
8163 type.kind = doubleType;
8164 else if(exp.destType && exp.destType.kind == floatType)
8165 type.kind = floatType;
8166 else if(exp.destType && exp.destType.kind == int64Type)
8167 type.kind = int64Type;
8173 exp.isConstant = true; // Why wasn't this constant?
8190 ProcessExpressionType(exp._new.size);
8195 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8197 DeclareType(exp.expType.type, false, false);
8201 ProcessExpressionType(exp._renew.size);
8202 ProcessExpressionType(exp._renew.exp);
8207 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8209 DeclareType(exp.expType.type, false, false);
8213 bool assign = false, boolResult = false, boolOps = false;
8214 Type type1 = null, type2 = null;
8215 bool useDestType = false, useSideType = false;
8216 Location oldyylloc = yylloc;
8217 bool useSideUnit = false;
8218 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8220 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8229 // Assignment Operators
8243 // boolean Operators
8245 // Expect boolean operators
8247 //boolResult = true;
8251 // Expect boolean operands
8262 // Gives boolean result
8294 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8300 /*// Implement speed etc.
8306 if(exp.op.op == '&')
8308 // Added this here earlier for Iterator address as key
8309 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8311 Identifier id = exp.op.exp2.identifier;
8312 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8313 if(symbol && symbol.isIterator == 2)
8315 exp.type = memberExp;
8316 exp.member.exp = exp.op.exp2;
8317 exp.member.member = MkIdentifier("key");
8319 exp.op.exp2.expType = symbol.type;
8320 symbol.type.refCount++;
8321 ProcessExpressionType(exp);
8325 // exp.op.exp2.usage.usageRef = true;
8329 //dummy.kind = TypeDummy;
8332 // Added this check here to use the dest type only for units derived from the base unit
8333 // So that untyped units will use the side unit as opposed to the untyped destination unit
8334 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8335 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8336 useDestType = false;
8338 if(destClass && useDestType &&
8339 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8341 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8343 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8344 exp.op.exp1.destType = exp.destType;
8345 exp.op.exp1.opDestType = true;
8347 exp.destType.refCount++;
8351 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8352 exp.op.exp1.destType = dummy;
8356 // TESTING THIS HERE...
8357 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8358 ProcessExpressionType(exp.op.exp1);
8359 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8361 exp.op.exp1.opDestType = false;
8363 // Fix for unit and ++ / --
8364 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8365 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8367 exp.op.exp2 = MkExpConstant("1");
8368 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8372 if(exp.op.exp1.destType == dummy)
8375 exp.op.exp1.destType = null;
8377 type1 = exp.op.exp1.expType;
8382 char expString[10240];
8383 expString[0] = '\0';
8384 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8388 exp.op.exp2.destType = exp.op.exp1.expType;
8389 if(exp.op.exp1.expType)
8390 exp.op.exp1.expType.refCount++;
8394 exp.op.exp2.destType = exp.destType;
8395 if(!exp.op.exp1 || exp.op.op != '&')
8396 exp.op.exp2.opDestType = true;
8398 exp.destType.refCount++;
8401 if(type1) type1.refCount++;
8402 exp.expType = type1;
8407 PrintExpression(exp.op.exp2, expString);
8409 if(type1 && type1.kind == pointerType)
8411 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 ||
8412 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8413 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8414 else if(exp.op.op == '=')
8416 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8417 exp.op.exp2.destType = type1;
8424 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8425 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/* ||
8426 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8429 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8430 exp.op.exp2.destType = type1;
8435 if(type1) type1.refCount++;
8436 exp.expType = type1;
8438 else if(destClass &&
8439 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8440 (destClass.type == enumClass && useDestType)))
8442 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8443 exp.op.exp2.destType = exp.destType;
8444 if(exp.op.op != '&')
8445 exp.op.exp2.opDestType = true;
8447 exp.destType.refCount++;
8451 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8452 exp.op.exp2.destType = dummy;
8456 // TESTING THIS HERE... (DANGEROUS)
8457 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8458 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8460 FreeType(exp.op.exp2.destType);
8461 exp.op.exp2.destType = type1;
8464 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8465 // Cannot lose the cast on a sizeof
8466 if(exp.op.op == SIZEOF)
8468 Expression e = exp.op.exp2;
8469 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8471 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8473 if(e.type == extensionCompoundExp)
8474 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8479 if(e.type == castExp && e.cast.exp)
8480 e.cast.exp.needCast = true;
8482 ProcessExpressionType(exp.op.exp2);
8483 exp.op.exp2.opDestType = false;
8484 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8486 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8488 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)
8490 if(exp.op.op != '=' && type1.type.kind == voidType)
8491 Compiler_Error($"void *: unknown size\n");
8493 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||
8494 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8495 (exp.op.exp2.expType._class.registered.type == normalClass ||
8496 exp.op.exp2.expType._class.registered.type == structClass ||
8497 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8499 if(exp.op.op == ADD_ASSIGN)
8500 Compiler_Error($"cannot add two pointers\n");
8502 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8503 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8505 if(exp.op.op == ADD_ASSIGN)
8506 Compiler_Error($"cannot add two pointers\n");
8510 char type1String[1024];
8511 char type2String[1024];
8512 type1String[0] = '\0';
8513 type2String[0] = '\0';
8515 PrintType(exp.op.exp2.expType, type1String, false, true);
8516 PrintType(type1, type2String, false, true);
8517 ChangeCh(expString, '\n', ' ');
8518 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8522 if(exp.op.exp2.destType == dummy)
8525 exp.op.exp2.destType = null;
8528 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8532 CopyTypeInto(type2, exp.op.exp2.expType);
8533 type2.isSigned = true;
8535 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8537 type2 = { kind = intType };
8539 type2.isSigned = true;
8543 type2 = exp.op.exp2.expType;
8544 if(type2) type2.refCount++;
8548 dummy.kind = voidType;
8550 if(exp.op.op == SIZEOF)
8557 exp.isConstant = true;
8559 // Get type of dereferenced pointer
8560 else if(exp.op.op == '*' && !exp.op.exp1)
8562 exp.expType = Dereference(type2);
8563 if(type2 && type2.kind == classType)
8564 notByReference = true;
8566 else if(exp.op.op == '&' && !exp.op.exp1)
8567 exp.expType = Reference(type2);
8574 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8575 exp.op.exp1.destType = MkClassType("bool");
8576 exp.op.exp1.destType.truth = true;
8577 if(!exp.op.exp1.expType)
8578 ProcessExpressionType(exp.op.exp1);
8580 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8581 FreeType(exp.op.exp1.expType);
8582 exp.op.exp1.expType = MkClassType("bool");
8583 exp.op.exp1.expType.truth = true;
8587 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8588 exp.op.exp2.destType = MkClassType("bool");
8589 exp.op.exp2.destType.truth = true;
8590 if(!exp.op.exp2.expType)
8591 ProcessExpressionType(exp.op.exp2);
8593 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8594 FreeType(exp.op.exp2.expType);
8595 exp.op.exp2.expType = MkClassType("bool");
8596 exp.op.exp2.expType.truth = true;
8599 else if(exp.op.exp1 && exp.op.exp2 &&
8602 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8603 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8604 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8605 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8607 if(type1 && type2 &&
8608 // If either both are class or both are not class
8609 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8611 // Added this check for enum subtraction to result in an int type:
8612 if(exp.op.op == '-' &&
8613 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8614 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8617 if(!type1._class.registered.dataType)
8618 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8619 if(!type2._class.registered.dataType)
8620 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8622 intType = ProcessTypeString(
8623 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8625 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8626 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8627 exp.op.exp1.destType = intType;
8628 exp.op.exp2.destType = intType;
8633 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8634 exp.op.exp2.destType = type1;
8636 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8637 exp.op.exp1.destType = type2;
8641 // Warning here for adding Radians + Degrees with no destination type
8642 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8643 type1._class.registered && type1._class.registered.type == unitClass &&
8644 type2._class.registered && type2._class.registered.type == unitClass &&
8645 type1._class.registered != type2._class.registered)
8646 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8647 type1._class.string, type2._class.string, type1._class.string);
8649 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8651 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8654 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8656 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8657 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8660 ProcessExpressionType(exp.op.exp1);
8662 if(type2.kind != pointerType)
8664 ProcessExpressionType(classExp);
8666 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8668 if(!exp.op.exp2.expType)
8672 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8676 ProcessExpressionType(exp.op.exp2);
8681 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)))
8683 if(type1.kind != classType && type1.type.kind == voidType)
8684 Compiler_Error($"void *: unknown size\n");
8685 exp.expType = type1;
8686 if(type1) type1.refCount++;
8688 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)))
8690 if(type2.kind != classType && type2.type.kind == voidType)
8691 Compiler_Error($"void *: unknown size\n");
8692 exp.expType = type2;
8693 if(type2) type2.refCount++;
8695 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8696 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8698 Compiler_Warning($"different levels of indirection\n");
8702 bool success = false;
8703 if(type1.kind == pointerType && type2.kind == pointerType)
8705 if(exp.op.op == '+')
8706 Compiler_Error($"cannot add two pointers\n");
8707 else if(exp.op.op == '-')
8709 // Pointer Subtraction gives integer
8710 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8719 if(type1.type.kind == templateType)
8721 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8724 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8726 ProcessExpressionType(classExp);
8728 exp.type = bracketsExp;
8729 exp.list = MkListOne(MkExpOp(
8730 MkExpBrackets(MkListOne(MkExpOp(
8731 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8733 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8734 MkExpMember(classExp, MkIdentifier("typeSize"))));
8736 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8745 if(!success && exp.op.exp1.type == constantExp)
8747 // If first expression is constant, try to match that first
8748 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8750 if(exp.expType) FreeType(exp.expType);
8751 exp.expType = exp.op.exp1.destType;
8752 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8755 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8757 if(exp.expType) FreeType(exp.expType);
8758 exp.expType = exp.op.exp2.destType;
8759 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8765 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8767 if(exp.expType) FreeType(exp.expType);
8768 exp.expType = exp.op.exp2.destType;
8769 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8772 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8774 if(exp.expType) FreeType(exp.expType);
8775 exp.expType = exp.op.exp1.destType;
8776 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8782 char expString1[10240];
8783 char expString2[10240];
8786 expString1[0] = '\0';
8787 expString2[0] = '\0';
8792 PrintExpression(exp.op.exp1, expString1);
8793 ChangeCh(expString1, '\n', ' ');
8794 PrintExpression(exp.op.exp2, expString2);
8795 ChangeCh(expString2, '\n', ' ');
8796 PrintType(exp.op.exp1.expType, type1, false, true);
8797 PrintType(exp.op.exp2.expType, type2, false, true);
8800 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8804 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8805 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8807 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8808 // Convert e.g. / 4 into / 4.0
8809 exp.op.exp1.destType = type2._class.registered.dataType;
8810 if(type2._class.registered.dataType)
8811 type2._class.registered.dataType.refCount++;
8812 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8813 exp.expType = type2;
8814 if(type2) type2.refCount++;
8816 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8818 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8819 // Convert e.g. / 4 into / 4.0
8820 exp.op.exp2.destType = type1._class.registered.dataType;
8821 if(type1._class.registered.dataType)
8822 type1._class.registered.dataType.refCount++;
8823 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8824 exp.expType = type1;
8825 if(type1) type1.refCount++;
8831 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8833 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8835 if(!type1._class.registered.dataType)
8836 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8837 exp.op.exp2.destType = type1._class.registered.dataType;
8838 exp.op.exp2.destType.refCount++;
8840 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8843 type2 = exp.op.exp2.destType;
8844 if(type2) type2.refCount++;
8846 exp.expType = type2;
8850 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8852 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8854 if(!type2._class.registered.dataType)
8855 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8856 exp.op.exp1.destType = type2._class.registered.dataType;
8857 exp.op.exp1.destType.refCount++;
8859 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8860 type1 = exp.op.exp1.destType;
8861 exp.expType = type1;
8865 // TESTING THIS NEW CODE
8866 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8868 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8869 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8870 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8872 // Convert the enum to an int instead for these operators
8873 if(op1IsEnum && exp.op.exp2.expType)
8875 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8877 if(exp.expType) FreeType(exp.expType);
8878 exp.expType = exp.op.exp2.expType;
8879 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8883 else if(op2IsEnum && exp.op.exp1.expType)
8885 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8887 if(exp.expType) FreeType(exp.expType);
8888 exp.expType = exp.op.exp1.expType;
8889 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8896 if(op1IsEnum && exp.op.exp2.expType)
8898 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8900 if(exp.expType) FreeType(exp.expType);
8901 exp.expType = exp.op.exp1.expType;
8902 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8906 else if(op2IsEnum && exp.op.exp1.expType)
8908 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8910 if(exp.expType) FreeType(exp.expType);
8911 exp.expType = exp.op.exp2.expType;
8912 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8921 // Added this first part of the if here to handle 5 + Degrees { 5 } with either a base unit dest or not a unit dest type
8922 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8923 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8925 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8926 exp.op.exp1.destType = type2;
8929 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8931 if(exp.expType) FreeType(exp.expType);
8932 exp.expType = exp.op.exp1.destType;
8933 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8938 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8939 exp.op.exp2.destType = type1;
8943 // Maybe this was meant to be an enum...
8944 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8946 Type oldType = exp.op.exp2.expType;
8947 exp.op.exp2.expType = null;
8948 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8951 exp.op.exp2.expType = oldType;
8956 // TESTING THIS HERE... LATEST ADDITION
8957 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8959 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8960 exp.op.exp2.destType = type2._class.registered.dataType;
8961 if(type2._class.registered.dataType)
8962 type2._class.registered.dataType.refCount++;
8963 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8965 //exp.expType = type2._class.registered.dataType; //type2;
8966 //if(type2) type2.refCount++;
8969 // TESTING THIS HERE... LATEST ADDITION
8970 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8972 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8973 exp.op.exp1.destType = type1._class.registered.dataType;
8974 if(type1._class.registered.dataType)
8975 type1._class.registered.dataType.refCount++;
8976 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8977 exp.expType = type1._class.registered.dataType; //type1;
8978 if(type1) type1.refCount++;
8982 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8984 if(exp.expType) FreeType(exp.expType);
8985 exp.expType = exp.op.exp2.destType;
8986 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8988 else if(type1 && type2)
8990 char expString1[10240];
8991 char expString2[10240];
8992 char type1String[1024];
8993 char type2String[1024];
8994 expString1[0] = '\0';
8995 expString2[0] = '\0';
8996 type1String[0] = '\0';
8997 type2String[0] = '\0';
9000 PrintExpression(exp.op.exp1, expString1);
9001 ChangeCh(expString1, '\n', ' ');
9002 PrintExpression(exp.op.exp2, expString2);
9003 ChangeCh(expString2, '\n', ' ');
9004 PrintType(exp.op.exp1.expType, type1String, false, true);
9005 PrintType(exp.op.exp2.expType, type2String, false, true);
9008 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9010 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9012 exp.expType = exp.op.exp1.expType;
9013 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9015 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9017 exp.expType = exp.op.exp2.expType;
9018 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9026 // Maybe this was meant to be an enum...
9027 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9029 Type oldType = exp.op.exp1.expType;
9030 exp.op.exp1.expType = null;
9031 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9034 exp.op.exp1.expType = oldType;
9037 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9038 exp.op.exp1.destType = type2;
9041 // TESTING THIS HERE... LATEST ADDITION
9042 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9044 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9045 exp.op.exp1.destType = type1._class.registered.dataType;
9046 if(type1._class.registered.dataType)
9047 type1._class.registered.dataType.refCount++;
9050 // TESTING THIS HERE... LATEST ADDITION
9051 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9053 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9054 exp.op.exp2.destType = type2._class.registered.dataType;
9055 if(type2._class.registered.dataType)
9056 type2._class.registered.dataType.refCount++;
9060 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9062 if(exp.expType) FreeType(exp.expType);
9063 exp.expType = exp.op.exp1.destType;
9064 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9068 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9070 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9072 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9073 // Convert e.g. / 4 into / 4.0
9074 exp.op.exp1.destType = type2._class.registered.dataType;
9075 if(type2._class.registered.dataType)
9076 type2._class.registered.dataType.refCount++;
9077 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9079 if(exp.op.op == '!')
9081 exp.expType = MkClassType("bool");
9082 exp.expType.truth = true;
9086 exp.expType = type2;
9087 if(type2) type2.refCount++;
9090 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9092 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9094 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9095 // Convert e.g. / 4 into / 4.0
9096 exp.op.exp2.destType = type1._class.registered.dataType;
9097 if(type1._class.registered.dataType)
9098 type1._class.registered.dataType.refCount++;
9099 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9101 exp.expType = type1;
9102 if(type1) type1.refCount++;
9107 if(exp.op.exp1 && !exp.op.exp1.expType)
9109 char expString[10000];
9110 expString[0] = '\0';
9113 PrintExpression(exp.op.exp1, expString);
9114 ChangeCh(expString, '\n', ' ');
9117 Compiler_Error($"couldn't determine type of %s\n", expString);
9119 if(exp.op.exp2 && !exp.op.exp2.expType)
9121 char expString[10240];
9122 expString[0] = '\0';
9125 PrintExpression(exp.op.exp2, expString);
9126 ChangeCh(expString, '\n', ' ');
9129 Compiler_Error($"couldn't determine type of %s\n", expString);
9134 FreeType(exp.expType);
9135 exp.expType = MkClassType("bool");
9136 exp.expType.truth = true;
9139 if(exp.op.op != SIZEOF)
9140 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9141 (!exp.op.exp2 || exp.op.exp2.isConstant);
9143 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9145 DeclareType(exp.op.exp2.expType, false, false);
9156 case extensionExpressionExp:
9159 exp.isConstant = true;
9160 for(e = exp.list->first; e; e = e.next)
9165 FreeType(e.destType);
9166 e.opDestType = exp.opDestType;
9167 e.destType = exp.destType;
9168 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9170 ProcessExpressionType(e);
9172 exp.destType.count--;
9173 if(!exp.expType && !e.next)
9175 exp.expType = e.expType;
9176 if(e.expType) e.expType.refCount++;
9179 exp.isConstant = false;
9182 // In case a cast became a member...
9183 e = exp.list->first;
9184 if(!e.next && e.type == memberExp)
9186 // Preserve prev, next
9187 Expression next = exp.next, prev = exp.prev;
9190 FreeType(exp.expType);
9191 FreeType(exp.destType);
9201 ProcessExpressionType(exp);
9208 exp.isConstant = true;
9210 ProcessExpressionType(exp.index.exp);
9211 if(!exp.index.exp.isConstant)
9212 exp.isConstant = false;
9214 if(exp.index.exp.expType)
9216 Type source = exp.index.exp.expType;
9217 if(source.kind == classType && source._class && source._class.registered)
9219 Class _class = source._class.registered;
9220 Class c = _class.templateClass ? _class.templateClass : _class;
9221 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9223 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9225 if(exp.index.index && exp.index.index->last)
9227 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9229 if(type.kind == classType) type.constant = true;
9230 else if(type.kind == pointerType)
9233 while(t.kind == pointerType) t = t.type;
9237 ((Expression)exp.index.index->last).destType = type;
9243 for(e = exp.index.index->first; e; e = e.next)
9245 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9247 if(e.destType) FreeType(e.destType);
9248 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9250 ProcessExpressionType(e);
9253 // Check if this type is int
9256 exp.isConstant = false;
9260 exp.expType = Dereference(exp.index.exp.expType);
9262 DeclareType(exp.expType, false, false);
9269 Type methodType = null;
9275 PrintExpression(exp.call.exp, name);
9276 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9278 //exp.call.exp.expType = null;
9279 PrintExpression(exp.call.exp, name);
9282 if(exp.call.exp.type == identifierExp)
9284 Expression idExp = exp.call.exp;
9285 Identifier id = idExp.identifier;
9286 if(!strcmp(id.string, "__builtin_frame_address"))
9288 exp.expType = ProcessTypeString("void *", true);
9289 if(exp.call.arguments && exp.call.arguments->first)
9290 ProcessExpressionType(exp.call.arguments->first);
9293 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9295 exp.expType = ProcessTypeString("int", true);
9296 if(exp.call.arguments && exp.call.arguments->first)
9297 ProcessExpressionType(exp.call.arguments->first);
9300 else if(!strcmp(id.string, "Max") ||
9301 !strcmp(id.string, "Min") ||
9302 !strcmp(id.string, "Sgn") ||
9303 !strcmp(id.string, "Abs"))
9305 Expression a = null;
9306 Expression b = null;
9307 Expression tempExp1 = null, tempExp2 = null;
9308 if((!strcmp(id.string, "Max") ||
9309 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9311 a = exp.call.arguments->first;
9312 b = exp.call.arguments->last;
9316 else if(exp.call.arguments->count == 1)
9318 a = exp.call.arguments->first;
9324 exp.call.arguments->Clear();
9325 idExp.identifier = null;
9327 FreeExpContents(exp);
9329 ProcessExpressionType(a);
9331 ProcessExpressionType(b);
9333 exp.type = bracketsExp;
9334 exp.list = MkList();
9336 if(a.expType && (!b || b.expType))
9338 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9340 // Use the simpleStruct name/ids for now...
9343 OldList * specs = MkList();
9344 OldList * decls = MkList();
9346 char temp1[1024], temp2[1024];
9348 GetTypeSpecs(a.expType, specs);
9350 if(a && !a.isConstant && a.type != identifierExp)
9352 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9353 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9354 tempExp1 = QMkExpId(temp1);
9355 tempExp1.expType = a.expType;
9357 a.expType.refCount++;
9358 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9360 if(b && !b.isConstant && b.type != identifierExp)
9362 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9363 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9364 tempExp2 = QMkExpId(temp2);
9365 tempExp2.expType = b.expType;
9367 b.expType.refCount++;
9368 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9371 decl = MkDeclaration(specs, decls);
9372 if(!curCompound.compound.declarations)
9373 curCompound.compound.declarations = MkList();
9374 curCompound.compound.declarations->Insert(null, decl);
9379 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9381 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9383 MkExpCondition(MkExpBrackets(MkListOne(
9384 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9385 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9386 exp.expType = a.expType;
9388 a.expType.refCount++;
9390 else if(!strcmp(id.string, "Abs"))
9393 MkExpCondition(MkExpBrackets(MkListOne(
9394 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9395 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9396 exp.expType = a.expType;
9398 a.expType.refCount++;
9400 else if(!strcmp(id.string, "Sgn"))
9402 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9404 MkExpCondition(MkExpBrackets(MkListOne(
9405 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9406 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9407 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9408 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9409 exp.expType = ProcessTypeString("int", false);
9412 FreeExpression(tempExp1);
9413 if(tempExp2) FreeExpression(tempExp2);
9427 if(!exp.call.exp.destType)
9429 exp.call.exp.destType = dummy;
9432 ProcessExpressionType(exp.call.exp);
9433 if(exp.call.exp.destType == dummy)
9436 exp.call.exp.destType = null;
9441 // Check argument types against parameter types
9442 functionType = exp.call.exp.expType;
9444 if(functionType && functionType.kind == TypeKind::methodType)
9446 methodType = functionType;
9447 functionType = methodType.method.dataType;
9449 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9450 // TOCHECK: Instead of doing this here could this be done per param?
9451 if(exp.call.exp.expType.usedClass)
9453 char typeString[1024];
9454 typeString[0] = '\0';
9456 Symbol back = functionType.thisClass;
9457 // Do not output class specifier here (thisclass was added to this)
9458 functionType.thisClass = null;
9459 PrintType(functionType, typeString, true, true);
9460 functionType.thisClass = back;
9462 if(strstr(typeString, "thisclass"))
9464 OldList * specs = MkList();
9467 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9469 decl = SpecDeclFromString(typeString, specs, null);
9471 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9472 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9473 exp.call.exp.expType.usedClass))
9474 thisClassParams = false;
9476 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9478 Class backupThisClass = thisClass;
9479 thisClass = exp.call.exp.expType.usedClass;
9480 ProcessDeclarator(decl);
9481 thisClass = backupThisClass;
9484 thisClassParams = true;
9486 functionType = ProcessType(specs, decl);
9487 functionType.refCount = 0;
9488 FinishTemplatesContext(context);
9491 FreeList(specs, FreeSpecifier);
9492 FreeDeclarator(decl);
9496 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9498 Type type = functionType.type;
9499 if(!functionType.refCount)
9501 functionType.type = null;
9502 FreeType(functionType);
9504 //methodType = functionType;
9505 functionType = type;
9507 if(functionType && functionType.kind != TypeKind::functionType)
9509 Compiler_Error($"called object %s is not a function\n", name);
9511 else if(functionType)
9513 bool emptyParams = false, noParams = false;
9514 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9515 Type type = functionType.params.first;
9516 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9518 Location oldyylloc = yylloc;
9520 if(!type) emptyParams = true;
9523 if(functionType.extraParam && e && functionType.thisClass)
9525 e.destType = MkClassType(functionType.thisClass.string);
9529 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9530 // Fixed #141 by adding '&& !functionType.extraParam'
9531 if(!functionType.staticMethod && !functionType.extraParam)
9533 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9534 memberExp.member.exp.expType._class)
9536 type = MkClassType(memberExp.member.exp.expType._class.string);
9541 type = functionType.params.first;
9546 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9548 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9549 type.byReference = functionType.byReference;
9550 type.typedByReference = functionType.typedByReference;
9553 // Allow manually passing a class for typed object
9554 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9558 type = functionType.params.first;
9566 if(type && type.kind == voidType)
9569 if(!type.refCount) FreeType(type);
9573 for( ; e; e = e.next)
9575 if(!type && !emptyParams)
9578 if(methodType && methodType.methodClass)
9579 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9580 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9581 noParams ? 0 : functionType.params.count);
9583 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9584 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9585 noParams ? 0 : functionType.params.count);
9589 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9591 Type templatedType = null;
9592 Class _class = methodType.usedClass;
9593 ClassTemplateParameter curParam = null;
9595 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9598 for(sClass = _class; sClass; sClass = sClass.base)
9600 if(sClass.templateClass) sClass = sClass.templateClass;
9602 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9604 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9607 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9609 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9610 id += nextClass.templateParams.count;
9619 if(curParam && _class.templateArgs[id].dataTypeString)
9621 bool constant = type.constant;
9622 ClassTemplateArgument arg = _class.templateArgs[id];
9624 Context context = SetupTemplatesContext(_class);
9627 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9628 templatedType = ProcessTypeString(arg.dataTypeString, false);
9629 FinishTemplatesContext(context);
9632 if(templatedType.kind == classType && constant) templatedType.constant = true;
9633 else if(templatedType.kind == pointerType)
9635 Type t = templatedType.type;
9636 while(t.kind == pointerType) t = t.type;
9637 if(constant) t.constant = constant;
9640 e.destType = templatedType;
9643 templatedType.passAsTemplate = true;
9644 // templatedType.refCount++;
9650 if(type) type.refCount++;
9655 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9657 e.destType = type.prev;
9658 e.destType.refCount++;
9663 if(type) type.refCount++;
9666 // Don't reach the end for the ellipsis
9667 if(type && type.kind != ellipsisType)
9669 Type next = type.next;
9670 if(!type.refCount) FreeType(type);
9675 if(type && type.kind != ellipsisType)
9677 if(methodType && methodType.methodClass)
9678 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9679 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9680 functionType.params.count + extra);
9682 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9683 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9684 functionType.params.count + extra);
9687 if(type && !type.refCount) FreeType(type);
9694 kind = TypeKind::functionType;
9697 if(exp.call.exp.type == identifierExp)
9699 char * string = exp.call.exp.identifier.string;
9703 Location oldyylloc = yylloc;
9705 yylloc = exp.call.exp.identifier.loc;
9706 if(strstr(string, "__builtin_") == string)
9710 functionType.returnType = exp.destType;
9711 exp.destType.refCount++;
9715 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9716 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9717 globalContext.symbols.Add((BTNode)symbol);
9718 if(strstr(symbol.string, "::"))
9719 globalContext.hasNameSpace = true;
9724 else if(exp.call.exp.type == memberExp)
9726 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9727 exp.call.exp.member.member.string);*/
9730 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9732 if(!functionType.returnType)
9734 functionType.returnType = Type
9741 if(functionType && functionType.kind == TypeKind::functionType)
9743 exp.expType = functionType.returnType;
9745 if(functionType.returnType)
9746 functionType.returnType.refCount++;
9748 if(!functionType.refCount)
9749 FreeType(functionType);
9752 if(exp.call.arguments)
9754 for(e = exp.call.arguments->first; e; e = e.next)
9756 Type destType = e.destType;
9757 ProcessExpressionType(e);
9765 Location oldyylloc = yylloc;
9767 Expression checkExp = exp.member.exp;
9770 if(checkExp.type == castExp)
9771 checkExp = checkExp.cast.exp;
9772 else if(checkExp.type == bracketsExp)
9773 checkExp = checkExp.list ? checkExp.list->first : null;
9778 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9779 exp.thisPtr = thisPtr;
9781 // DOING THIS LATER NOW...
9782 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9784 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9785 /* TODO: Name Space Fix ups
9786 if(!exp.member.member.classSym)
9787 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9791 ProcessExpressionType(exp.member.exp);
9792 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9793 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9795 exp.isConstant = false;
9798 exp.isConstant = exp.member.exp.isConstant;
9799 type = exp.member.exp.expType;
9803 if(type && (type.kind == templateType))
9805 Class _class = thisClass ? thisClass : currentClass;
9806 ClassTemplateParameter param = null;
9809 for(param = _class.templateParams.first; param; param = param.next)
9811 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9815 if(param && param.defaultArg.member)
9817 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9820 Expression expMember = exp.member.exp;
9822 OldList * specs = MkList();
9823 char thisClassTypeString[1024];
9825 FreeIdentifier(exp.member.member);
9827 ProcessExpressionType(argExp);
9830 char * colon = strstr(param.defaultArg.memberString, "::");
9833 char className[1024];
9836 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9837 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9840 strcpy(thisClassTypeString, _class.fullName);
9843 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9845 exp.expType = ProcessType(specs, decl);
9846 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9848 Class expClass = exp.expType._class.registered;
9849 Class cClass = null;
9854 char templateString[1024];
9855 ClassTemplateParameter param;
9856 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9857 for(cClass = expClass; cClass; cClass = cClass.base)
9860 for(param = cClass.templateParams.first; param; param = param.next)
9864 ClassTemplateArgument arg;
9865 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9866 arg = expClass.templateArgs[id];
9868 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9870 ClassTemplateParameter cParam;
9871 //int p = numParams - sClass.templateParams.count;
9874 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9876 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9878 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9880 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9882 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9883 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9895 strcat(argument, arg.name.string);
9896 strcat(argument, " = ");
9902 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9903 char expString[1024];
9904 OldList * specs = MkList();
9905 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9907 char * string = PrintHexUInt64(arg.expression.ui64);
9908 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9911 ProcessExpressionType(exp);
9912 ComputeExpression(exp);
9913 expString[0] = '\0';
9914 PrintExpression(exp, expString);
9915 strcat(argument, expString);
9917 FreeExpression(exp);
9922 strcat(argument, arg.member.name);
9925 case TemplateParameterType::type:
9927 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9929 if(!strcmp(arg.dataTypeString, "thisclass"))
9930 strcat(argument, thisClassTypeString);
9932 strcat(argument, arg.dataTypeString);
9939 if(paramCount) strcat(templateString, ", ");
9940 if(lastParam != p - 1)
9942 strcat(templateString, param.name);
9943 strcat(templateString, " = ");
9945 strcat(templateString, argument);
9954 int len = strlen(templateString);
9955 if(templateString[len-1] == '>') templateString[len++] = ' ';
9956 templateString[len++] = '>';
9957 templateString[len++] = '\0';
9960 Context context = SetupTemplatesContext(_class);
9961 FreeType(exp.expType);
9962 exp.expType = ProcessTypeString(templateString, false);
9963 FinishTemplatesContext(context);
9967 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9968 exp.type = bracketsExp;
9969 exp.list = MkListOne(MkExpOp(null, '*',
9974 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9975 MkExpBrackets(MkListOne(
9976 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9978 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9980 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9985 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9986 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9988 type = ProcessTemplateParameterType(type.templateParameter);
9991 // TODO: *** This seems to be where we should add method support for all basic types ***
9992 if(type && (type.kind == templateType));
9993 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9994 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9995 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9996 (type.kind == pointerType && type.type.kind == charType)))
9998 Identifier id = exp.member.member;
9999 TypeKind typeKind = type.kind;
10000 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10001 if(typeKind == subClassType && exp.member.exp.type == classExp)
10003 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10004 typeKind = classType;
10009 if(typeKind == intType || typeKind == enumType)
10010 _class = eSystem_FindClass(privateModule, "int");
10013 if(type.kind == classType && type._class && type._class.registered)
10015 _class = type._class.registered;
10017 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10019 _class = FindClass("char *").registered;
10021 else if(type.kind == pointerType)
10023 _class = eSystem_FindClass(privateModule, "uintptr");
10024 FreeType(exp.expType);
10025 exp.expType = ProcessTypeString("uintptr", false);
10026 exp.byReference = true;
10030 char string[1024] = "";
10032 PrintTypeNoConst(type, string, false, true);
10033 classSym = FindClass(string);
10034 if(classSym) _class = classSym.registered;
10042 (exp.member.exp.type == identifierExp &&
10043 !strcmp(exp.member.exp.identifier.string, "this"));*/
10044 Property prop = null;
10045 Method method = null;
10046 DataMember member = null;
10047 Property revConvert = null;
10048 ClassProperty classProp = null;
10050 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10051 exp.member.memberType = propertyMember;
10053 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10054 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10056 if(typeKind != subClassType)
10058 // Prioritize data members over properties for "this"
10059 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10061 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10062 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10064 prop = eClass_FindProperty(_class, id.string, privateModule);
10068 if(!member && !prop)
10069 prop = eClass_FindProperty(_class, id.string, privateModule);
10070 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10071 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10072 exp.member.thisPtr = true;
10074 // Prioritize properties over data members otherwise
10077 bool useMemberForNonConst = false;
10078 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10081 prop = eClass_FindProperty(_class, id.string, null);
10083 useMemberForNonConst = prop && exp.destType &&
10084 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10085 !strncmp(prop.dataTypeString, "const ", 6);
10087 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10088 member = eClass_FindDataMember(_class, id.string, null, null, null);
10091 if((!prop || useMemberForNonConst) && !member)
10093 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10096 prop = eClass_FindProperty(_class, id.string, privateModule);
10098 useMemberForNonConst |= prop && exp.destType &&
10099 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10100 !strncmp(prop.dataTypeString, "const ", 6);
10102 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10103 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10109 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10116 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10117 method = eClass_FindMethod(_class, id.string, privateModule);
10118 if(!prop && !member && !method)
10120 if(typeKind == subClassType)
10122 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10125 exp.member.memberType = classPropertyMember;
10126 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10130 // Assume this is a class_data member
10131 char structName[1024];
10132 Identifier id = exp.member.member;
10133 Expression classExp = exp.member.exp;
10136 FreeType(classExp.expType);
10137 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10139 strcpy(structName, "__ecereClassData_");
10140 FullClassNameCat(structName, type._class.string, false);
10141 exp.type = pointerExp;
10142 exp.member.member = id;
10144 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10145 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10146 MkExpBrackets(MkListOne(MkExpOp(
10147 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10148 MkExpMember(classExp, MkIdentifier("data"))), '+',
10149 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10154 ProcessExpressionType(exp);
10160 // Check for reverse conversion
10161 // (Convert in an instantiation later, so that we can use
10162 // deep properties system)
10163 Symbol classSym = FindClass(id.string);
10166 Class convertClass = classSym.registered;
10168 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10175 exp.member.memberType = propertyMember;
10177 ProcessPropertyType(prop);
10178 exp.expType = prop.dataType;
10179 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10182 CopyTypeInto(type, exp.expType);
10184 type.constant = true;
10185 exp.expType = type;
10187 else if(prop.dataType)
10188 prop.dataType.refCount++;
10192 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10194 FreeExpContents(exp);
10195 exp.type = identifierExp;
10196 exp.identifier = MkIdentifier("class");
10197 ProcessExpressionType(exp);
10201 exp.member.memberType = dataMember;
10202 DeclareStruct(_class.fullName, false);
10203 if(!member.dataType)
10205 Context context = SetupTemplatesContext(_class);
10206 member.dataType = ProcessTypeString(member.dataTypeString, false);
10207 FinishTemplatesContext(context);
10209 exp.expType = member.dataType;
10210 if(member.dataType) member.dataType.refCount++;
10212 else if(revConvert)
10214 exp.member.memberType = reverseConversionMember;
10215 exp.expType = MkClassType(revConvert._class.fullName);
10223 exp.type = identifierExp;
10224 exp.identifier = exp.member.member;
10227 exp.member.memberType = methodMember;
10229 if(!method.dataType)
10230 ProcessMethodType(method);
10238 // Tricky spot here... To use instance versus class virtual table
10239 // Put it back to what it was... What did we break?
10241 // Had to put it back for overriding Main of Thread global instance
10243 //exp.expType.methodClass = _class;
10244 exp.expType.methodClass = (id && id._class) ? _class : null;
10246 // Need the actual class used for templated classes
10247 exp.expType.usedClass = _class;
10249 else if(!classProp)
10251 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10253 FreeExpContents(exp);
10254 exp.type = identifierExp;
10255 exp.identifier = MkIdentifier("class");
10256 FreeType(exp.expType);
10257 exp.expType = MkClassType("ecere::com::Class");
10260 yylloc = exp.member.member.loc;
10261 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10263 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10266 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10271 while(tClass && !tClass.templateClass) tClass = tClass.base;
10273 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10276 ClassTemplateParameter curParam = null;
10279 for(sClass = tClass; sClass; sClass = sClass.base)
10282 if(sClass.templateClass) sClass = sClass.templateClass;
10283 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10285 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10287 for(sClass = sClass.base; sClass; sClass = sClass.base)
10288 id += sClass.templateParams.count;
10293 if(curParam) break;
10296 if(curParam && tClass.templateArgs[id].dataTypeString)
10298 ClassTemplateArgument arg = tClass.templateArgs[id];
10299 Context context = SetupTemplatesContext(tClass);
10300 bool constant = exp.expType.constant;
10301 /*if(!arg.dataType)
10302 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10303 FreeType(exp.expType);
10305 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10306 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10307 else if(exp.expType.kind == pointerType)
10309 Type t = exp.expType.type;
10310 while(t.kind == pointerType) t = t.type;
10311 if(constant) t.constant = constant;
10315 if(exp.expType.kind == thisClassType)
10317 FreeType(exp.expType);
10318 exp.expType = ReplaceThisClassType(_class);
10321 if(tClass.templateClass)
10322 exp.expType.passAsTemplate = true;
10323 //exp.expType.refCount++;
10326 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10327 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10328 else if(exp.destType.kind == pointerType)
10330 Type t = exp.destType.type;
10331 while(t.kind == pointerType) t = t.type;
10332 if(constant) t.constant = constant;
10335 //exp.destType.refCount++;
10337 if(exp.destType.kind == thisClassType)
10339 FreeType(exp.destType);
10340 exp.destType = ReplaceThisClassType(_class);
10344 FinishTemplatesContext(context);
10347 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10348 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10351 ClassTemplateParameter curParam = null;
10354 for(sClass = tClass; sClass; sClass = sClass.base)
10357 if(sClass.templateClass) sClass = sClass.templateClass;
10358 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10360 if(curParam.type == TemplateParameterType::type &&
10361 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10363 for(sClass = sClass.base; sClass; sClass = sClass.base)
10364 id += sClass.templateParams.count;
10369 if(curParam) break;
10374 ClassTemplateArgument arg = tClass.templateArgs[id];
10375 Context context = SetupTemplatesContext(tClass);
10377 /*if(!arg.dataType)
10378 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10380 basicType = ProcessTypeString(arg.dataTypeString, false);
10383 if(basicType.kind == thisClassType)
10385 FreeType(basicType);
10386 basicType = ReplaceThisClassType(_class);
10389 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10390 if(tClass.templateClass)
10391 basicType.passAsTemplate = true;
10394 FreeType(exp.expType);
10396 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10397 //exp.expType.refCount++;
10400 exp.destType = exp.expType;
10401 exp.destType.refCount++;
10405 Expression newExp { };
10406 OldList * specs = MkList();
10408 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10410 if(exp.destType) exp.destType.refCount++;
10411 if(exp.expType) exp.expType.refCount++;
10412 exp.type = castExp;
10413 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10414 exp.cast.exp = newExp;
10415 //FreeType(exp.expType);
10416 //exp.expType = null;
10417 //ProcessExpressionType(sourceExp);
10420 FinishTemplatesContext(context);
10423 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10425 Class expClass = exp.expType._class.registered;
10428 Class cClass = null;
10431 int paramCount = 0;
10432 int lastParam = -1;
10433 char templateString[1024];
10434 ClassTemplateParameter param;
10435 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10436 while(cClass != expClass)
10439 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10442 for(param = cClass.templateParams.first; param; param = param.next)
10444 Class cClassCur = null;
10447 ClassTemplateParameter paramCur = null;
10448 ClassTemplateArgument arg;
10449 while(cClassCur != tClass && !paramCur)
10452 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10453 cClassCur = sClassCur;
10455 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10457 if(!strcmp(paramCur.name, param.name))
10465 if(paramCur && paramCur.type == TemplateParameterType::type)
10466 arg = tClass.templateArgs[cp];
10468 arg = expClass.templateArgs[p];
10471 char argument[256];
10472 argument[0] = '\0';
10475 strcat(argument, arg.name.string);
10476 strcat(argument, " = ");
10482 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10483 char expString[1024];
10484 OldList * specs = MkList();
10485 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10487 char * string = PrintHexUInt64(arg.expression.ui64);
10488 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10491 ProcessExpressionType(exp);
10492 ComputeExpression(exp);
10493 expString[0] = '\0';
10494 PrintExpression(exp, expString);
10495 strcat(argument, expString);
10497 FreeExpression(exp);
10502 strcat(argument, arg.member.name);
10505 case TemplateParameterType::type:
10507 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10508 strcat(argument, arg.dataTypeString);
10514 if(paramCount) strcat(templateString, ", ");
10515 if(lastParam != p - 1)
10517 strcat(templateString, param.name);
10518 strcat(templateString, " = ");
10520 strcat(templateString, argument);
10529 int len = strlen(templateString);
10530 if(templateString[len-1] == '>') templateString[len++] = ' ';
10531 templateString[len++] = '>';
10532 templateString[len++] = '\0';
10535 FreeType(exp.expType);
10537 Context context = SetupTemplatesContext(tClass);
10538 exp.expType = ProcessTypeString(templateString, false);
10539 FinishTemplatesContext(context);
10546 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10548 else if(type && (type.kind == structType || type.kind == unionType))
10550 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10553 exp.expType = memberType;
10555 memberType.refCount++;
10560 char expString[10240];
10561 expString[0] = '\0';
10562 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10563 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10566 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10568 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10570 Identifier id = exp.member.member;
10571 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10574 FreeType(exp.expType);
10575 exp.expType = ReplaceThisClassType(_class);
10579 yylloc = oldyylloc;
10582 // Convert x->y into (*x).y
10585 Type destType = exp.destType;
10587 // DOING THIS LATER NOW...
10588 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10590 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10591 /* TODO: Name Space Fix ups
10592 if(!exp.member.member.classSym)
10593 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10597 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10598 exp.type = memberExp;
10601 ProcessExpressionType(exp);
10608 //ComputeExpression(exp);
10610 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10611 if(classSym && classSym.registered)
10613 if(classSym.registered.type == noHeadClass)
10617 DeclareStruct(classSym.string, false);
10618 FreeSpecifier(exp._class);
10619 exp.type = typeSizeExp;
10620 FullClassNameCat(name, classSym.string, false);
10621 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10625 if(classSym.registered.fixed)
10627 FreeSpecifier(exp._class);
10628 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10629 exp.type = constantExp;
10633 char className[1024];
10634 strcpy(className, "__ecereClass_");
10635 FullClassNameCat(className, classSym.string, true);
10636 MangleClassName(className);
10638 DeclareClass(classSym, className);
10640 FreeExpContents(exp);
10641 exp.type = pointerExp;
10642 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10643 exp.member.member = MkIdentifier("structSize");
10651 kind = intSizeType;
10653 // exp.isConstant = true;
10658 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10663 kind = intSizeType;
10665 exp.isConstant = true;
10667 DeclareType(type, false, false);
10673 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10675 FreeType(exp.cast.exp.destType);
10676 exp.cast.exp.destType = type;
10678 type.casted = true;
10679 ProcessExpressionType(exp.cast.exp);
10680 type.casted = false;
10682 exp.expType = type;
10685 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10686 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10688 void * prev = exp.prev, * next = exp.next;
10689 Type expType = exp.cast.exp.destType;
10690 Expression castExp = exp.cast.exp;
10691 Type destType = exp.destType;
10693 if(expType) expType.refCount++;
10695 //FreeType(exp.destType);
10696 FreeType(exp.expType);
10697 FreeTypeName(exp.cast.typeName);
10700 FreeType(exp.expType);
10701 FreeType(exp.destType);
10703 exp.expType = expType;
10704 exp.destType = destType;
10714 exp.isConstant = exp.cast.exp.isConstant;
10719 case extensionInitializerExp:
10721 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10722 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10723 // ProcessInitializer(exp.initializer.initializer, type);
10724 exp.expType = type;
10729 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10730 ProcessExpressionType(exp.vaArg.exp);
10731 exp.expType = type;
10737 exp.isConstant = true;
10739 FreeType(exp.cond.cond.destType);
10740 exp.cond.cond.destType = MkClassType("bool");
10741 exp.cond.cond.destType.truth = true;
10742 ProcessExpressionType(exp.cond.cond);
10743 if(!exp.cond.cond.isConstant)
10744 exp.isConstant = false;
10745 for(e = exp.cond.exp->first; e; e = e.next)
10749 FreeType(e.destType);
10750 e.destType = exp.destType;
10751 if(e.destType) e.destType.refCount++;
10753 ProcessExpressionType(e);
10756 exp.expType = e.expType;
10757 if(e.expType) e.expType.refCount++;
10760 exp.isConstant = false;
10763 FreeType(exp.cond.elseExp.destType);
10764 // Added this check if we failed to find an expType
10765 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10768 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10770 if(exp.cond.elseExp.destType)
10771 exp.cond.elseExp.destType.refCount++;
10772 ProcessExpressionType(exp.cond.elseExp);
10774 // FIXED THIS: Was done before calling process on elseExp
10775 if(!exp.cond.elseExp.isConstant)
10776 exp.isConstant = false;
10779 case extensionCompoundExp:
10781 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10783 Statement last = exp.compound.compound.statements->last;
10784 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10786 ((Expression)last.expressions->last).destType = exp.destType;
10788 exp.destType.refCount++;
10790 ProcessStatement(exp.compound);
10791 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10793 exp.expType.refCount++;
10799 Specifier spec = exp._classExp.specifiers->first;
10800 if(spec && spec.type == nameSpecifier)
10802 exp.expType = MkClassType(spec.name);
10803 exp.expType.kind = subClassType;
10804 exp.byReference = true;
10808 exp.expType = MkClassType("ecere::com::Class");
10809 exp.byReference = true;
10815 Class _class = thisClass ? thisClass : currentClass;
10818 Identifier id = exp.classData.id;
10819 char structName[1024];
10820 Expression classExp;
10821 strcpy(structName, "__ecereClassData_");
10822 FullClassNameCat(structName, _class.fullName, false);
10823 exp.type = pointerExp;
10824 exp.member.member = id;
10825 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10826 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10828 classExp = MkExpIdentifier(MkIdentifier("class"));
10830 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10831 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10832 MkExpBrackets(MkListOne(MkExpOp(
10833 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10834 MkExpMember(classExp, MkIdentifier("data"))), '+',
10835 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10838 ProcessExpressionType(exp);
10846 const char * typeString = null;
10847 char typeStringBuf[1024];
10848 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10849 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10851 Class templateClass = exp.destType._class.registered;
10852 typeString = templateClass.templateArgs[2].dataTypeString;
10856 // Guess type from expressions in the array
10858 for(e = exp.list->first; e; e = e.next)
10860 ProcessExpressionType(e);
10863 if(!type) { type = e.expType; type.refCount++; }
10866 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10867 if(!MatchTypeExpression(e, type, null, false, true))
10873 e = exp.list->first;
10874 ProcessExpressionType(e);
10877 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10878 if(!MatchTypeExpression(e, type, null, false, true))
10880 FreeType(e.expType);
10891 FreeType(e.expType);
10898 typeStringBuf[0] = '\0';
10899 PrintTypeNoConst(type, typeStringBuf, false, true);
10900 typeString = typeStringBuf;
10908 (Container)& (struct BuiltInContainer)
10910 ._vTbl = class(BuiltInContainer)._vTbl,
10911 ._class = class(BuiltInContainer),
10913 .data = (int[]){ 1, 7, 3, 4, 5 },
10915 .type = class(int),
10918 char templateString[1024];
10919 OldList * initializers = MkList();
10920 OldList * structInitializers = MkList();
10921 OldList * specs = MkList();
10923 Declarator decl = SpecDeclFromString(typeString, specs, null);
10924 sprintf(templateString, "Container<%s>", typeString);
10929 type = ProcessTypeString(typeString, false);
10930 while(e = exp.list->first)
10932 exp.list->Remove(e);
10935 ProcessExpressionType(e);
10936 ListAdd(initializers, MkInitializerAssignment(e));
10942 DeclareStruct("ecere::com::BuiltInContainer", false);
10944 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10945 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10946 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10947 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10948 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10949 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10950 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10951 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10952 MkInitializerList(initializers))));
10953 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10954 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10955 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10956 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10957 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10958 exp.expType = ProcessTypeString(templateString, false);
10959 exp.type = bracketsExp;
10960 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10962 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10963 MkInitializerList(structInitializers)))));
10964 ProcessExpressionType(expExt);
10968 exp.expType = ProcessTypeString("Container", false);
10969 Compiler_Error($"Couldn't determine type of array elements\n");
10975 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10977 FreeType(exp.expType);
10978 exp.expType = ReplaceThisClassType(thisClass);
10981 // Resolve structures here
10982 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10984 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10985 // TODO: Fix members reference...
10988 if(exp.expType.kind != enumType)
10991 String enumName = CopyString(exp.expType.enumName);
10993 // Fixed a memory leak on self-referencing C structs typedefs
10994 // by instantiating a new type rather than simply copying members
10995 // into exp.expType
10996 FreeType(exp.expType);
10997 exp.expType = Type { };
10998 exp.expType.kind = symbol.type.kind;
10999 exp.expType.refCount++;
11000 exp.expType.enumName = enumName;
11002 exp.expType.members = symbol.type.members;
11003 for(member = symbol.type.members.first; member; member = member.next)
11009 for(member = symbol.type.members.first; member; member = member.next)
11011 NamedLink value { name = CopyString(member.name) };
11012 exp.expType.members.Add(value);
11019 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
11020 else if(exp.destType && !exp.destType.keepCast)
11022 if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11024 if(!exp.destType.count || unresolved)
11029 if(exp.destType.kind != ellipsisType)
11035 char expString[10240];
11036 expString[0] = '\0';
11038 PrintType(exp.destType, type2, false, true);
11040 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11042 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11043 else if(exp.type != dummyExp)
11044 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11049 char expString[10240] ;
11050 expString[0] = '\0';
11051 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11054 Compiler_Error($"unresolved identifier %s\n", expString);
11055 else if(exp.type != dummyExp)
11056 Compiler_Error($"couldn't determine type of %s\n", expString);
11067 PrintType(exp.expType, type1, false, true);
11068 PrintType(exp.destType, type2, false, true);
11071 //CheckExpressionType(exp, exp.destType, false);
11073 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11074 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11075 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11078 char expString[10240];
11079 expString[0] = '\0';
11080 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11083 CheckExpressionType(exp, exp.destType, false, true);
11085 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11086 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
11087 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11089 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11090 FreeType(exp.expType);
11091 exp.destType.refCount++;
11092 exp.expType = exp.destType;
11097 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
11099 Expression newExp { };
11100 char typeString[1024];
11101 OldList * specs = MkList();
11104 typeString[0] = '\0';
11108 if(exp.expType) exp.expType.refCount++;
11109 if(exp.expType) exp.expType.refCount++;
11110 exp.type = castExp;
11111 newExp.destType = exp.expType;
11113 PrintType(exp.expType, typeString, false, false);
11114 decl = SpecDeclFromString(typeString, specs, null);
11116 exp.cast.typeName = MkTypeName(specs, decl);
11117 exp.cast.exp = newExp;
11120 else if(unresolved)
11122 if(exp.identifier._class && exp.identifier._class.name)
11123 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11124 else if(exp.identifier.string && exp.identifier.string[0])
11125 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11127 else if(!exp.expType && exp.type != dummyExp)
11129 char expString[10240];
11130 expString[0] = '\0';
11131 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11132 Compiler_Error($"couldn't determine type of %s\n", expString);
11135 // Let's try to support any_object & typed_object here:
11137 ApplyAnyObjectLogic(exp);
11139 // Mark nohead classes as by reference, unless we're casting them to an integral type
11140 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11141 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11142 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11143 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11145 exp.byReference = true;
11147 yylloc = oldyylloc;
11150 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11152 // THIS CODE WILL FIND NEXT MEMBER...
11155 *curMember = (*curMember).next;
11157 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11159 *curMember = subMemberStack[--(*subMemberStackPos)];
11160 *curMember = (*curMember).next;
11163 // SKIP ALL PROPERTIES HERE...
11164 while((*curMember) && (*curMember).isProperty)
11165 *curMember = (*curMember).next;
11167 if(subMemberStackPos)
11169 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11171 subMemberStack[(*subMemberStackPos)++] = *curMember;
11173 *curMember = (*curMember).members.first;
11174 while(*curMember && (*curMember).isProperty)
11175 *curMember = (*curMember).next;
11183 if(subMemberStackPos && *subMemberStackPos)
11185 *curMember = subMemberStack[--(*subMemberStackPos)];
11186 *curMember = (*curMember).next;
11190 Class lastCurClass = *curClass;
11192 if(*curClass == _class) break; // REACHED THE END
11194 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11195 *curMember = (*curClass).membersAndProperties.first;
11198 while((*curMember) && (*curMember).isProperty)
11199 *curMember = (*curMember).next;
11200 if(subMemberStackPos)
11202 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11204 subMemberStack[(*subMemberStackPos)++] = *curMember;
11206 *curMember = (*curMember).members.first;
11207 while(*curMember && (*curMember).isProperty)
11208 *curMember = (*curMember).next;
11216 static void ProcessInitializer(Initializer init, Type type)
11220 case expInitializer:
11221 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11223 // TESTING THIS FOR SHUTTING = 0 WARNING
11224 if(init.exp && !init.exp.destType)
11226 FreeType(init.exp.destType);
11227 init.exp.destType = type;
11228 if(type) type.refCount++;
11232 ProcessExpressionType(init.exp);
11233 init.isConstant = init.exp.isConstant;
11239 Expression exp = init.exp;
11240 Instantiation inst = exp.instance;
11241 MembersInit members;
11243 init.type = listInitializer;
11244 init.list = MkList();
11248 for(members = inst.members->first; members; members = members.next)
11250 if(members.type == dataMembersInit)
11253 for(member = members.dataMembers->first; member; member = member.next)
11255 ListAdd(init.list, member.initializer);
11256 member.initializer = null;
11259 // Discard all MembersInitMethod
11262 FreeExpression(exp);
11264 case listInitializer:
11267 Type initializerType = null;
11268 Class curClass = null;
11269 DataMember curMember = null;
11270 DataMember subMemberStack[256];
11271 int subMemberStackPos = 0;
11273 if(type && type.kind == arrayType)
11274 initializerType = Dereference(type);
11275 else if(type && (type.kind == structType || type.kind == unionType))
11276 initializerType = type.members.first;
11278 for(i = init.list->first; i; i = i.next)
11280 if(type && type.kind == classType && type._class && type._class.registered)
11282 // 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)
11283 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11284 // TODO: Generate error on initializing a private data member this way from another module...
11287 if(!curMember.dataType)
11288 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11289 initializerType = curMember.dataType;
11292 ProcessInitializer(i, initializerType);
11293 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11294 initializerType = initializerType.next;
11296 init.isConstant = false;
11299 if(type && type.kind == arrayType)
11300 FreeType(initializerType);
11302 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11304 Compiler_Error($"Assigning list initializer to non list\n");
11311 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11315 case baseSpecifier:
11317 if(spec.specifier == THISCLASS)
11321 spec.type = nameSpecifier;
11322 spec.name = ReplaceThisClass(thisClass);
11323 spec.symbol = FindClass(spec.name);
11324 ProcessSpecifier(spec, declareStruct);
11329 case nameSpecifier:
11331 Symbol symbol = FindType(curContext, spec.name);
11333 DeclareType(symbol.type, true, true);
11334 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11335 DeclareStruct(spec.name, false);
11338 case enumSpecifier:
11343 for(e = spec.list->first; e; e = e.next)
11346 ProcessExpressionType(e.exp);
11351 case structSpecifier:
11352 case unionSpecifier:
11354 if(spec.definitions)
11357 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11359 ProcessClass(spec.definitions, symbol);
11362 for(def = spec.definitions->first; def; def = def.next)
11364 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11365 ProcessDeclaration(def.decl);
11372 case classSpecifier:
11374 Symbol classSym = FindClass(spec.name);
11375 if(classSym && classSym.registered && classSym.registered.type == structClass)
11376 DeclareStruct(spec.name, false);
11384 static void ProcessDeclarator(Declarator decl)
11388 case identifierDeclarator:
11389 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11391 FreeSpecifier(decl.identifier._class);
11392 decl.identifier._class = null;
11395 case arrayDeclarator:
11397 ProcessExpressionType(decl.array.exp);
11398 case structDeclarator:
11399 case bracketsDeclarator:
11400 case functionDeclarator:
11401 case pointerDeclarator:
11402 case extendedDeclarator:
11403 case extendedDeclaratorEnd:
11404 if(decl.declarator)
11405 ProcessDeclarator(decl.declarator);
11406 if(decl.type == functionDeclarator)
11408 Identifier id = GetDeclId(decl);
11409 if(id && id._class)
11413 qualifiers = MkListOne(id._class);
11416 if(!decl.function.parameters)
11417 decl.function.parameters = MkList();
11418 decl.function.parameters->Insert(null, param);
11421 if(decl.function.parameters)
11425 for(param = decl.function.parameters->first; param; param = param.next)
11427 if(param.qualifiers && param.qualifiers->first)
11429 Specifier spec = param.qualifiers->first;
11430 if(spec && spec.specifier == TYPED_OBJECT)
11432 Declarator d = param.declarator;
11435 qualifiers = MkListOne(MkSpecifier(VOID));
11436 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11438 if(d.type != pointerDeclarator)
11439 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11441 FreeList(param.qualifiers, FreeSpecifier);
11443 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11444 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11446 decl.function.parameters->Insert(param, newParam);
11449 else if(spec && spec.specifier == ANY_OBJECT)
11451 Declarator d = param.declarator;
11453 FreeList(param.qualifiers, FreeSpecifier);
11455 param.qualifiers = MkListOne(MkSpecifier(VOID));
11456 if(d.type != pointerDeclarator)
11457 param.qualifiers->Insert(null, MkSpecifier(CONST));
11458 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11460 else if(spec.specifier == THISCLASS)
11464 spec.type = nameSpecifier;
11465 spec.name = ReplaceThisClass(thisClass);
11466 spec.symbol = FindClass(spec.name);
11467 ProcessSpecifier(spec, false);
11472 if(param.declarator)
11473 ProcessDeclarator(param.declarator);
11481 static void ProcessDeclaration(Declaration decl)
11486 case initDeclaration:
11488 bool declareStruct = false;
11490 lineNum = decl.pos.line;
11491 column = decl.pos.col;
11494 if(decl.declarators)
11498 for(d = decl.declarators->first; d; d = d.next)
11500 Type type, subType;
11501 ProcessDeclarator(d.declarator);
11503 type = ProcessType(decl.specifiers, d.declarator);
11507 ProcessInitializer(d.initializer, type);
11509 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11511 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11512 d.initializer.exp.type == instanceExp)
11514 if(type.kind == classType && type._class ==
11515 d.initializer.exp.expType._class)
11517 Instantiation inst = d.initializer.exp.instance;
11518 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11520 d.initializer.exp.instance = null;
11521 if(decl.specifiers)
11522 FreeList(decl.specifiers, FreeSpecifier);
11523 FreeList(decl.declarators, FreeInitDeclarator);
11527 decl.type = instDeclaration;
11532 for(subType = type; subType;)
11534 if(subType.kind == classType)
11536 declareStruct = true;
11539 else if(subType.kind == pointerType)
11541 else if(subType.kind == arrayType)
11542 subType = subType.arrayType;
11552 if(decl.specifiers)
11555 for(s = decl.specifiers->first; s; s = s.next)
11557 ProcessSpecifier(s, declareStruct);
11562 case instDeclaration:
11564 ProcessInstantiationType(decl.inst);
11567 case structDeclaration:
11571 bool declareStruct = false;
11573 if(decl.declarators)
11575 for(d = decl.declarators->first; d; d = d.next)
11577 Type type = ProcessType(decl.specifiers, d.declarator);
11579 ProcessDeclarator(d);
11580 for(subType = type; subType;)
11582 if(subType.kind == classType)
11584 declareStruct = true;
11587 else if(subType.kind == pointerType)
11589 else if(subType.kind == arrayType)
11590 subType = subType.arrayType;
11597 if(decl.specifiers)
11599 for(spec = decl.specifiers->first; spec; spec = spec.next)
11600 ProcessSpecifier(spec, declareStruct);
11607 static FunctionDefinition curFunction;
11609 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11611 char propName[1024], propNameM[1024];
11612 char getName[1024], setName[1024];
11615 DeclareProperty(prop, setName, getName);
11617 // eInstance_FireWatchers(object, prop);
11618 strcpy(propName, "__ecereProp_");
11619 FullClassNameCat(propName, prop._class.fullName, false);
11620 strcat(propName, "_");
11621 // strcat(propName, prop.name);
11622 FullClassNameCat(propName, prop.name, true);
11623 MangleClassName(propName);
11625 strcpy(propNameM, "__ecerePropM_");
11626 FullClassNameCat(propNameM, prop._class.fullName, false);
11627 strcat(propNameM, "_");
11628 // strcat(propNameM, prop.name);
11629 FullClassNameCat(propNameM, prop.name, true);
11630 MangleClassName(propNameM);
11632 if(prop.isWatchable)
11635 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11636 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11637 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11640 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11641 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11642 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11648 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11649 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11650 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11653 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11654 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11655 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11658 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11659 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11660 curFunction.propSet.fireWatchersDone = true;
11663 static void ProcessStatement(Statement stmt)
11667 lineNum = stmt.pos.line;
11668 column = stmt.pos.col;
11673 ProcessStatement(stmt.labeled.stmt);
11676 // This expression should be constant...
11677 if(stmt.caseStmt.exp)
11679 FreeType(stmt.caseStmt.exp.destType);
11680 stmt.caseStmt.exp.destType = curSwitchType;
11681 if(curSwitchType) curSwitchType.refCount++;
11682 ProcessExpressionType(stmt.caseStmt.exp);
11683 ComputeExpression(stmt.caseStmt.exp);
11685 if(stmt.caseStmt.stmt)
11686 ProcessStatement(stmt.caseStmt.stmt);
11690 if(stmt.compound.context)
11695 Statement prevCompound = curCompound;
11696 Context prevContext = curContext;
11698 if(!stmt.compound.isSwitch)
11699 curCompound = stmt;
11700 curContext = stmt.compound.context;
11702 if(stmt.compound.declarations)
11704 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11705 ProcessDeclaration(decl);
11707 if(stmt.compound.statements)
11709 for(s = stmt.compound.statements->first; s; s = s.next)
11710 ProcessStatement(s);
11713 curContext = prevContext;
11714 curCompound = prevCompound;
11718 case expressionStmt:
11721 if(stmt.expressions)
11723 for(exp = stmt.expressions->first; exp; exp = exp.next)
11724 ProcessExpressionType(exp);
11732 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11733 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11734 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11735 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11737 ProcessExpressionType(exp);
11739 if(stmt.ifStmt.stmt)
11740 ProcessStatement(stmt.ifStmt.stmt);
11741 if(stmt.ifStmt.elseStmt)
11742 ProcessStatement(stmt.ifStmt.elseStmt);
11747 Type oldSwitchType = curSwitchType;
11748 if(stmt.switchStmt.exp)
11751 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11761 e.exp.destType = destType;
11764 ProcessExpressionType(exp);
11767 curSwitchType = exp.expType;
11770 ProcessStatement(stmt.switchStmt.stmt);
11771 curSwitchType = oldSwitchType;
11776 if(stmt.whileStmt.exp)
11780 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11781 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11782 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11783 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11785 ProcessExpressionType(exp);
11788 if(stmt.whileStmt.stmt)
11789 ProcessStatement(stmt.whileStmt.stmt);
11794 if(stmt.doWhile.exp)
11798 if(stmt.doWhile.exp->last)
11800 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11801 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11802 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11804 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11806 ProcessExpressionType(exp);
11809 if(stmt.doWhile.stmt)
11810 ProcessStatement(stmt.doWhile.stmt);
11816 if(stmt.forStmt.init)
11817 ProcessStatement(stmt.forStmt.init);
11819 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11821 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11822 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11823 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11826 if(stmt.forStmt.check)
11827 ProcessStatement(stmt.forStmt.check);
11828 if(stmt.forStmt.increment)
11830 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11831 ProcessExpressionType(exp);
11834 if(stmt.forStmt.stmt)
11835 ProcessStatement(stmt.forStmt.stmt);
11840 Identifier id = stmt.forEachStmt.id;
11841 OldList * exp = stmt.forEachStmt.exp;
11842 OldList * filter = stmt.forEachStmt.filter;
11843 Statement block = stmt.forEachStmt.stmt;
11844 char iteratorType[1024];
11847 bool isBuiltin = exp && exp->last &&
11848 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11849 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11850 Expression arrayExp;
11851 const char * typeString = null;
11852 int builtinCount = 0;
11854 for(e = exp ? exp->first : null; e; e = e.next)
11858 FreeType(e.destType);
11859 e.destType = ProcessTypeString("Container", false);
11861 if(!isBuiltin || e.next)
11862 ProcessExpressionType(e);
11865 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11866 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11867 eClass_IsDerived(source._class.registered, containerClass)))
11869 Class _class = source ? source._class.registered : null;
11871 Expression expIt = null;
11872 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
11873 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11874 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11875 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11876 stmt.type = compoundStmt;
11878 stmt.compound.context = Context { };
11879 stmt.compound.context.parent = curContext;
11880 curContext = stmt.compound.context;
11882 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11884 Class mapClass = eSystem_FindClass(privateModule, "Map");
11885 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11886 isCustomAVLTree = true;
11887 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
11889 else */if(eClass_IsDerived(source._class.registered, mapClass))
11892 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11893 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11895 Class listClass = eSystem_FindClass(privateModule, "List");
11897 isList = eClass_IsDerived(source._class.registered, listClass);
11903 OldList * specs = MkList();
11904 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11905 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11906 stmt.compound.declarations = MkListOne(
11907 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11908 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11909 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11910 MkInitializerAssignment(MkExpBrackets(exp))))));
11915 char typeStringBuf[1024];
11917 // TODO: Merge this code?
11918 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11919 if(((Expression)exp->last).type == castExp)
11921 TypeName typeName = ((Expression)exp->last).cast.typeName;
11923 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11926 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11927 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11928 arrayExp.destType._class.registered.templateArgs)
11930 Class templateClass = arrayExp.destType._class.registered;
11931 typeString = templateClass.templateArgs[2].dataTypeString;
11933 else if(arrayExp.list)
11935 // Guess type from expressions in the array
11937 for(e = arrayExp.list->first; e; e = e.next)
11939 ProcessExpressionType(e);
11942 if(!type) { type = e.expType; type.refCount++; }
11945 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11946 if(!MatchTypeExpression(e, type, null, false, true))
11952 e = arrayExp.list->first;
11953 ProcessExpressionType(e);
11956 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11957 if(!MatchTypeExpression(e, type, null, false, true))
11959 FreeType(e.expType);
11970 FreeType(e.expType);
11977 typeStringBuf[0] = '\0';
11978 PrintType(type, typeStringBuf, false, true);
11979 typeString = typeStringBuf;
11985 OldList * initializers = MkList();
11987 OldList * specs = MkList();
11992 builtinCount = arrayExp.list->count;
11993 type = ProcessTypeString(typeString, false);
11994 while(e = arrayExp.list->first)
11996 arrayExp.list->Remove(e);
11999 ProcessExpressionType(e);
12000 ListAdd(initializers, MkInitializerAssignment(e));
12003 delete arrayExp.list;
12005 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12006 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12007 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12009 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12011 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12012 ), MkInitializerList(initializers)))));
12013 FreeList(exp, FreeExpression);
12017 arrayExp.expType = ProcessTypeString("Container", false);
12018 Compiler_Error($"Couldn't determine type of array elements\n");
12023 OldList * specs = MkList();
12025 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12026 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12027 stmt.compound.declarations = MkListOne(
12028 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12029 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12030 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12031 MkInitializerAssignment(MkExpBrackets(exp))))));
12034 else if(isLinkList && !isList)
12037 OldList * specs = MkList();
12038 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12039 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12040 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12041 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12042 MkInitializerAssignment(MkExpBrackets(exp))))));
12044 /*else if(isCustomAVLTree)
12047 OldList * specs = MkList();
12048 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12049 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12050 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12051 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12052 MkInitializerAssignment(MkExpBrackets(exp))))));
12054 else if(_class.templateArgs)
12057 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12059 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12061 stmt.compound.declarations = MkListOne(
12062 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12063 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12064 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12066 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12070 // Reparent sub-contexts in this statement
12074 if(block.compound.context)
12075 block.compound.context.parent = stmt.compound.context;
12078 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12079 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12080 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12081 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12084 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12085 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12088 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12089 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12092 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12093 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12096 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12097 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12100 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12101 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12103 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12106 case expressionStmt:
12112 case badDeclarationStmt:
12113 case fireWatchersStmt:
12114 case stopWatchingStmt:
12121 block = MkIfStmt(filter, block, null);
12125 stmt.compound.statements = MkListOne(MkForStmt(
12126 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12127 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12128 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12129 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12131 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12132 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12133 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12138 //OldList * specs = MkList();
12139 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12141 sprintf(count, "%d", builtinCount);
12143 stmt.compound.statements = MkListOne(MkForStmt(
12144 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12145 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12146 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12147 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12151 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12152 stmt.compound.statements = MkListOne(MkForStmt(
12153 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12154 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12155 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12156 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12159 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12160 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12161 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12163 else if(isLinkList && !isList)
12165 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12166 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12167 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12168 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12170 stmt.compound.statements = MkListOne(MkForStmt(
12171 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12172 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12173 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12178 OldList * specs = MkList();
12179 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12180 stmt.compound.statements = MkListOne(MkForStmt(
12181 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12182 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12183 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12184 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12185 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12188 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12189 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12190 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12192 /*else if(isCustomAVLTree)
12194 stmt.compound.statements = MkListOne(MkForStmt(
12195 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12196 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12197 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12198 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12201 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12202 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12203 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12207 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12208 MkIdentifier("Next")), null)), block));
12210 ProcessExpressionType(expIt);
12211 if(stmt.compound.declarations->first)
12212 ProcessDeclaration(stmt.compound.declarations->first);
12215 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12217 ProcessStatement(stmt);
12218 curContext = stmt.compound.context.parent;
12223 Compiler_Error($"Expression is not a container\n");
12236 if(stmt.expressions)
12238 for(exp = stmt.expressions->first; exp; exp = exp.next)
12242 if(curFunction && !curFunction.type)
12243 curFunction.type = ProcessType(
12244 curFunction.specifiers, curFunction.declarator);
12245 FreeType(exp.destType);
12246 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12247 if(exp.destType) exp.destType.refCount++;
12249 ProcessExpressionType(exp);
12254 case badDeclarationStmt:
12256 ProcessDeclaration(stmt.decl);
12262 if(stmt.asmStmt.inputFields)
12264 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12265 if(field.expression)
12266 ProcessExpressionType(field.expression);
12268 if(stmt.asmStmt.outputFields)
12270 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12271 if(field.expression)
12272 ProcessExpressionType(field.expression);
12274 if(stmt.asmStmt.clobberedFields)
12276 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12278 if(field.expression)
12279 ProcessExpressionType(field.expression);
12286 PropertyWatch propWatch;
12287 OldList * watches = stmt._watch.watches;
12288 Expression object = stmt._watch.object;
12289 Expression watcher = stmt._watch.watcher;
12291 ProcessExpressionType(watcher);
12293 ProcessExpressionType(object);
12297 if(watcher || thisClass)
12299 External external = curExternal;
12300 Context context = curContext;
12302 stmt.type = expressionStmt;
12303 stmt.expressions = MkList();
12305 curExternal = external.prev;
12307 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12309 ClassFunction func;
12310 char watcherName[1024];
12311 Class watcherClass = watcher ?
12312 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12313 External createdExternal;
12315 // Create a declaration above
12316 External externalDecl = MkExternalDeclaration(null);
12317 ast->Insert(curExternal.prev, externalDecl);
12319 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12320 if(propWatch.deleteWatch)
12321 strcat(watcherName, "_delete");
12325 for(propID = propWatch.properties->first; propID; propID = propID.next)
12327 strcat(watcherName, "_");
12328 strcat(watcherName, propID.string);
12332 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12334 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12335 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12336 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12337 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12338 ProcessClassFunctionBody(func, propWatch.compound);
12339 propWatch.compound = null;
12341 //afterExternal = afterExternal ? afterExternal : curExternal;
12343 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12344 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12346 createdExternal.symbol.idCode = external.symbol.idCode;
12348 curExternal = createdExternal;
12349 ProcessFunction(createdExternal.function);
12352 // Create a declaration above
12354 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12355 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12356 externalDecl.declaration = decl;
12357 if(decl.symbol && !decl.symbol.pointerExternal)
12358 decl.symbol.pointerExternal = externalDecl;
12361 if(propWatch.deleteWatch)
12363 OldList * args = MkList();
12364 ListAdd(args, CopyExpression(object));
12365 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12366 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12367 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12371 Class _class = object.expType._class.registered;
12374 for(propID = propWatch.properties->first; propID; propID = propID.next)
12376 char propName[1024];
12377 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12380 char getName[1024], setName[1024];
12381 OldList * args = MkList();
12383 DeclareProperty(prop, setName, getName);
12385 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12386 strcpy(propName, "__ecereProp_");
12387 FullClassNameCat(propName, prop._class.fullName, false);
12388 strcat(propName, "_");
12389 // strcat(propName, prop.name);
12390 FullClassNameCat(propName, prop.name, true);
12392 ListAdd(args, CopyExpression(object));
12393 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12394 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12395 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12397 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12400 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12405 Compiler_Error($"Invalid watched object\n");
12408 curExternal = external;
12409 curContext = context;
12412 FreeExpression(watcher);
12414 FreeExpression(object);
12415 FreeList(watches, FreePropertyWatch);
12418 Compiler_Error($"No observer specified and not inside a _class\n");
12422 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12424 ProcessStatement(propWatch.compound);
12430 case fireWatchersStmt:
12432 OldList * watches = stmt._watch.watches;
12433 Expression object = stmt._watch.object;
12435 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12436 // printf("%X\n", watches);
12437 // printf("%X\n", stmt._watch.watches);
12439 ProcessExpressionType(object);
12444 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12450 stmt.type = expressionStmt;
12451 stmt.expressions = MkList();
12453 // Check if we're inside a property set
12454 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12456 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12460 //Compiler_Error($"No property specified and not inside a property set\n");
12464 for(propID = watches->first; propID; propID = propID.next)
12466 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12469 CreateFireWatcher(prop, object, stmt);
12472 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12477 // Fire all properties!
12480 for(base = _class; base; base = base.base)
12482 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12484 if(prop.isProperty && prop.isWatchable)
12486 CreateFireWatcher(prop, object, stmt);
12493 FreeExpression(object);
12494 FreeList(watches, FreeIdentifier);
12497 Compiler_Error($"Invalid object specified and not inside a class\n");
12501 case stopWatchingStmt:
12503 OldList * watches = stmt._watch.watches;
12504 Expression object = stmt._watch.object;
12505 Expression watcher = stmt._watch.watcher;
12508 ProcessExpressionType(object);
12510 ProcessExpressionType(watcher);
12513 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12515 if(watcher || thisClass)
12521 stmt.type = expressionStmt;
12522 stmt.expressions = MkList();
12527 // eInstance_StopWatching(object, null, watcher);
12529 ListAdd(args, CopyExpression(object));
12530 ListAdd(args, MkExpConstant("0"));
12531 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12532 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12536 for(propID = watches->first; propID; propID = propID.next)
12538 char propName[1024];
12539 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12542 char getName[1024], setName[1024];
12543 OldList * args = MkList();
12545 DeclareProperty(prop, setName, getName);
12547 // eInstance_StopWatching(object, prop, watcher);
12548 strcpy(propName, "__ecereProp_");
12549 FullClassNameCat(propName, prop._class.fullName, false);
12550 strcat(propName, "_");
12551 // strcat(propName, prop.name);
12552 FullClassNameCat(propName, prop.name, true);
12553 MangleClassName(propName);
12555 ListAdd(args, CopyExpression(object));
12556 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12557 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12558 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12561 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12566 FreeExpression(object);
12568 FreeExpression(watcher);
12569 FreeList(watches, FreeIdentifier);
12572 Compiler_Error($"Invalid object specified and not inside a class\n");
12575 Compiler_Error($"No observer specified and not inside a class\n");
12582 static void ProcessFunction(FunctionDefinition function)
12584 Identifier id = GetDeclId(function.declarator);
12585 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12586 Type type = symbol ? symbol.type : null;
12587 Class oldThisClass = thisClass;
12588 Context oldTopContext = topContext;
12590 yylloc = function.loc;
12591 // Process thisClass
12593 if(type && type.thisClass)
12595 Symbol classSym = type.thisClass;
12596 Class _class = type.thisClass.registered;
12597 char className[1024];
12598 char structName[1024];
12599 Declarator funcDecl;
12602 bool typedObject = false;
12604 if(_class && !_class.base)
12606 _class = currentClass;
12607 if(_class && !_class.symbol)
12608 _class.symbol = FindClass(_class.fullName);
12609 classSym = _class ? _class.symbol : null;
12610 typedObject = true;
12613 thisClass = _class;
12615 if(inCompiler && _class)
12617 if(type.kind == functionType)
12619 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12621 //TypeName param = symbol.type.params.first;
12622 Type param = symbol.type.params.first;
12623 symbol.type.params.Remove(param);
12624 //FreeTypeName(param);
12627 if(type.classObjectType != classPointer)
12629 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12630 symbol.type.staticMethod = true;
12631 symbol.type.thisClass = null;
12633 // HIGH DANGER: VERIFYING THIS...
12634 symbol.type.extraParam = false;
12638 strcpy(className, "__ecereClass_");
12639 FullClassNameCat(className, _class.fullName, true);
12641 MangleClassName(className);
12644 FullClassNameCat(structName, _class.fullName, false);
12649 funcDecl = GetFuncDecl(function.declarator);
12652 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12654 TypeName param = funcDecl.function.parameters->first;
12655 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12657 funcDecl.function.parameters->Remove(param);
12658 FreeTypeName(param);
12662 // DANGER: Watch for this... Check if it's a Conversion?
12663 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12665 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12666 if(!function.propertyNoThis)
12668 TypeName thisParam;
12670 if(type.classObjectType != classPointer)
12672 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12673 if(!funcDecl.function.parameters)
12674 funcDecl.function.parameters = MkList();
12675 funcDecl.function.parameters->Insert(null, thisParam);
12680 if(type.classObjectType != classPointer)
12682 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12683 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12686 thisParam = TypeName
12688 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12689 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12691 funcDecl.function.parameters->Insert(null, thisParam);
12696 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12698 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12699 funcDecl = GetFuncDecl(initDecl.declarator);
12702 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12704 TypeName param = funcDecl.function.parameters->first;
12705 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12707 funcDecl.function.parameters->Remove(param);
12708 FreeTypeName(param);
12712 if(type.classObjectType != classPointer)
12714 // DANGER: Watch for this... Check if it's a Conversion?
12715 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12717 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12719 if(!funcDecl.function.parameters)
12720 funcDecl.function.parameters = MkList();
12721 funcDecl.function.parameters->Insert(null, thisParam);
12728 // Add this to the context
12731 if(type.classObjectType != classPointer)
12733 thisSymbol = Symbol
12735 string = CopyString("this");
12736 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12738 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12740 if(typedObject && thisSymbol.type)
12742 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12743 thisSymbol.type.byReference = type.byReference;
12744 thisSymbol.type.typedByReference = type.byReference;
12746 thisSymbol = Symbol { string = CopyString("class") };
12747 function.body.compound.context.symbols.Add(thisSymbol);
12753 // Pointer to class data
12755 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12757 DataMember member = null;
12760 for(base = _class; base && base.type != systemClass; base = base.next)
12762 for(member = base.membersAndProperties.first; member; member = member.next)
12763 if(!member.isProperty)
12769 for(member = _class.membersAndProperties.first; member; member = member.next)
12770 if(!member.isProperty)
12774 char pointerName[1024];
12777 Initializer initializer;
12778 Expression exp, bytePtr;
12780 strcpy(pointerName, "__ecerePointer_");
12781 FullClassNameCat(pointerName, _class.fullName, false);
12783 char className[1024];
12784 strcpy(className, "__ecereClass_");
12785 FullClassNameCat(className, classSym.string, true);
12786 MangleClassName(className);
12789 DeclareClass(classSym, className);
12793 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12798 sprintf(string, "%d", _class.offset);
12799 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12803 // ([bytePtr] + [className]->offset)
12804 exp = QBrackets(MkExpOp(bytePtr, '+',
12805 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12808 // (this ? [exp] : 0)
12809 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12813 kind = pointerType;
12814 type = Type { refCount = 1, kind = voidType };
12819 yylloc = function.body.loc;
12820 // ([structName] *) [exp]
12821 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12822 initializer = MkInitializerAssignment(
12823 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12825 // [structName] * [pointerName] = [initializer];
12826 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12829 Context prevContext = curContext;
12830 curContext = function.body.compound.context;
12832 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12833 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12835 curContext = prevContext;
12839 decl.symbol = null;
12841 if(!function.body.compound.declarations)
12842 function.body.compound.declarations = MkList();
12843 function.body.compound.declarations->Insert(null, decl);
12849 // Loop through the function and replace undeclared identifiers
12850 // which are a member of the class (methods, properties or data)
12851 // by "this.[member]"
12858 FreeSpecifier(id._class);
12861 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12863 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12864 id = GetDeclId(initDecl.declarator);
12866 FreeSpecifier(id._class);
12871 topContext = function.body.compound.context;
12873 FunctionDefinition oldFunction = curFunction;
12874 curFunction = function;
12876 ProcessStatement(function.body);
12878 // If this is a property set and no firewatchers has been done yet, add one here
12879 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12881 Statement prevCompound = curCompound;
12882 Context prevContext = curContext;
12884 Statement fireWatchers = MkFireWatchersStmt(null, null);
12885 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12886 ListAdd(function.body.compound.statements, fireWatchers);
12888 curCompound = function.body;
12889 curContext = function.body.compound.context;
12891 ProcessStatement(fireWatchers);
12893 curContext = prevContext;
12894 curCompound = prevCompound;
12898 curFunction = oldFunction;
12901 if(function.declarator)
12903 ProcessDeclarator(function.declarator);
12906 topContext = oldTopContext;
12907 thisClass = oldThisClass;
12910 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12911 static void ProcessClass(OldList definitions, Symbol symbol)
12914 External external = curExternal;
12915 Class regClass = symbol ? symbol.registered : null;
12917 // Process all functions
12918 for(def = definitions.first; def; def = def.next)
12920 if(def.type == functionClassDef)
12922 if(def.function.declarator)
12923 curExternal = def.function.declarator.symbol.pointerExternal;
12925 curExternal = external;
12927 ProcessFunction((FunctionDefinition)def.function);
12929 else if(def.type == declarationClassDef)
12931 if(def.decl.type == instDeclaration)
12933 thisClass = regClass;
12934 ProcessInstantiationType(def.decl.inst);
12940 Class backThisClass = thisClass;
12941 if(regClass) thisClass = regClass;
12942 ProcessDeclaration(def.decl);
12943 thisClass = backThisClass;
12946 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12948 MemberInit defProperty;
12950 // Add this to the context
12951 Symbol thisSymbol = Symbol
12953 string = CopyString("this");
12954 type = regClass ? MkClassType(regClass.fullName) : null;
12956 globalContext.symbols.Add((BTNode)thisSymbol);
12958 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12960 thisClass = regClass;
12961 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12965 globalContext.symbols.Remove((BTNode)thisSymbol);
12966 FreeSymbol(thisSymbol);
12968 else if(def.type == propertyClassDef && def.propertyDef)
12970 PropertyDef prop = def.propertyDef;
12972 // Add this to the context
12974 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12975 globalContext.symbols.Add(thisSymbol);
12978 thisClass = regClass;
12985 string = CopyString("this");
12986 type = MkClassType(regClass.fullName);
12988 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12991 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12992 ProcessStatement(prop.setStmt);
13000 string = CopyString("this");
13001 type = MkClassType(regClass.fullName);
13003 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13006 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13007 ProcessStatement(prop.getStmt);
13015 string = CopyString("this");
13016 type = MkClassType(regClass.fullName);
13018 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13021 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13022 ProcessStatement(prop.issetStmt);
13028 globalContext.symbols.Remove(thisSymbol);
13029 FreeSymbol(thisSymbol);
13032 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13034 PropertyWatch propertyWatch = def.propertyWatch;
13036 thisClass = regClass;
13037 if(propertyWatch.compound)
13041 string = CopyString("this");
13042 type = regClass ? MkClassType(regClass.fullName) : null;
13045 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13047 curExternal = null;
13048 ProcessStatement(propertyWatch.compound);
13055 void DeclareFunctionUtil(const String s)
13057 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13062 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13063 strcpy(name, "__ecereFunction_");
13064 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13065 DeclareFunction(function, name);
13069 void ComputeDataTypes()
13073 External after = null;
13075 currentClass = null;
13077 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13079 for(external = ast->first; external; external = external.next)
13081 if(external.type == declarationExternal)
13083 Declaration decl = external.declaration;
13086 OldList * decls = decl.declarators;
13089 InitDeclarator initDecl = decls->first;
13092 Declarator declarator = initDecl.declarator;
13093 if(declarator && declarator.type == identifierDeclarator)
13095 Identifier id = declarator.identifier;
13096 if(id && id.string)
13098 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
13100 external.symbol.id = -1001, external.symbol.idCode = -1001;
13111 temp.symbol = Symbol { id = -1000, idCode = -1000 };
13112 ast->Insert(after, temp);
13113 curExternal = temp;
13115 DeclareFunctionUtil("eSystem_New");
13116 DeclareFunctionUtil("eSystem_New0");
13117 DeclareFunctionUtil("eSystem_Renew");
13118 DeclareFunctionUtil("eSystem_Renew0");
13119 DeclareFunctionUtil("eSystem_Delete");
13120 DeclareFunctionUtil("eClass_GetProperty");
13121 DeclareFunctionUtil("eClass_SetProperty");
13122 DeclareFunctionUtil("eInstance_FireSelfWatchers");
13123 DeclareFunctionUtil("eInstance_SetMethod");
13124 DeclareFunctionUtil("eInstance_IncRef");
13125 DeclareFunctionUtil("eInstance_StopWatching");
13126 DeclareFunctionUtil("eInstance_Watch");
13127 DeclareFunctionUtil("eInstance_FireWatchers");
13129 DeclareStruct("ecere::com::Class", false);
13130 DeclareStruct("ecere::com::Instance", false);
13131 DeclareStruct("ecere::com::Property", false);
13132 DeclareStruct("ecere::com::DataMember", false);
13133 DeclareStruct("ecere::com::Method", false);
13134 DeclareStruct("ecere::com::SerialBuffer", false);
13135 DeclareStruct("ecere::com::ClassTemplateArgument", false);
13139 for(external = ast->first; external; external = external.next)
13141 afterExternal = curExternal = external;
13142 if(external.type == functionExternal)
13144 currentClass = external.function._class;
13145 ProcessFunction(external.function);
13147 // There shouldn't be any _class member access here anyways...
13148 else if(external.type == declarationExternal)
13150 currentClass = null;
13151 if(external.declaration)
13152 ProcessDeclaration(external.declaration);
13154 else if(external.type == classExternal)
13156 ClassDefinition _class = external._class;
13157 currentClass = external.symbol.registered;
13158 if(_class.definitions)
13160 ProcessClass(_class.definitions, _class.symbol);
13164 // Free class data...
13165 ast->Remove(external);
13169 else if(external.type == nameSpaceExternal)
13171 thisNameSpace = external.id.string;
13174 currentClass = null;
13175 thisNameSpace = null;
13176 curExternal = null;
13178 delete temp.symbol;