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;
1836 char templateString[1024];
1837 ClassTemplateParameter param;
1838 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1839 for(cClass = expClass; cClass; cClass = cClass.base)
1842 if(cClass.templateClass) cClass = cClass.templateClass;
1843 for(param = cClass.templateParams.first; param; param = param.next)
1847 ClassTemplateArgument arg;
1848 for(sClass = cClass.base; sClass; sClass = sClass.base)
1850 if(sClass.templateClass) sClass = sClass.templateClass;
1851 id += sClass.templateParams.count;
1853 arg = expClass.templateArgs[id];
1855 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1857 ClassTemplateParameter cParam;
1858 //int p = numParams - sClass.templateParams.count;
1861 if(sClass.templateClass) sClass = sClass.templateClass;
1863 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1865 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1866 p += nextClass.templateParams.count;
1869 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1871 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1873 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1875 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1876 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1888 strcat(argument, arg.name.string);
1889 strcat(argument, " = ");
1895 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1896 char expString[1024];
1897 OldList * specs = MkList();
1898 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1900 char * string = PrintHexUInt64(arg.expression.ui64);
1901 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1904 ProcessExpressionType(exp);
1905 ComputeExpression(exp);
1906 expString[0] = '\0';
1907 PrintExpression(exp, expString);
1908 strcat(argument, expString);
1910 FreeExpression(exp);
1915 strcat(argument, arg.member.name);
1918 case TemplateParameterType::type:
1920 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1921 strcat(argument, arg.dataTypeString);
1927 if(paramCount) strcat(templateString, ", ");
1928 if(lastParam != p - 1)
1930 strcat(templateString, param.name);
1931 strcat(templateString, " = ");
1933 strcat(templateString, argument);
1942 int len = strlen(templateString);
1943 if(templateString[len-1] == '<')
1947 if(templateString[len-1] == '>')
1948 templateString[len++] = ' ';
1949 templateString[len++] = '>';
1951 templateString[len++] = '\0';
1954 Context context = SetupTemplatesContext(_class);
1955 if(freeType) FreeType(type);
1956 type = ProcessTypeString(templateString, false);
1958 FinishTemplatesContext(context);
1962 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1964 ProcessExpressionType(member.initializer.exp);
1965 if(!member.initializer.exp.expType)
1969 char expString[10240];
1970 expString[0] = '\0';
1971 PrintExpression(member.initializer.exp, expString);
1972 ChangeCh(expString, '\n', ' ');
1973 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1976 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1977 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1979 Compiler_Error($"incompatible instance method %s\n", ident.string);
1982 else if(member.initializer)
1985 FreeType(member.exp.destType);
1986 member.exp.destType = type;
1987 if(member.exp.destType)
1988 member.exp.destType.refCount++;
1989 ProcessExpressionType(member.exp);
1992 ProcessInitializer(member.initializer, type);
1994 if(freeType) FreeType(type);
1998 if(_class && _class.type == unitClass)
2000 if(member.initializer)
2003 FreeType(member.exp.destType);
2004 member.exp.destType = MkClassType(_class.fullName);
2005 ProcessExpressionType(member.initializer, type);
2007 Type type = MkClassType(_class.fullName);
2008 ProcessInitializer(member.initializer, type);
2014 if(member.initializer)
2016 //ProcessExpressionType(member.exp);
2017 ProcessInitializer(member.initializer, null);
2023 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2027 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2029 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2033 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2038 void ProcessInstantiationType(Instantiation inst)
2043 MembersInit members;
2044 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
2047 /*if(!inst._class.symbol)
2048 inst._class.symbol = FindClass(inst._class.name);*/
2049 classSym = inst._class.symbol;
2050 _class = classSym ? classSym.registered : null;
2052 // DANGER: Patch for mutex not declaring its struct when not needed
2053 if(!_class || _class.type != noHeadClass)
2054 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
2056 afterExternal = afterExternal ? afterExternal : curExternal;
2059 ProcessExpressionType(inst.exp);
2061 inst.isConstant = true;
2064 DataMember curMember = null;
2065 Class curClass = null;
2066 DataMember subMemberStack[256];
2067 int subMemberStackPos = 0;
2069 for(members = inst.members->first; members; members = members.next)
2071 switch(members.type)
2073 case methodMembersInit:
2076 static uint instMethodID = 0;
2077 External external = curExternal;
2078 Context context = curContext;
2079 Declarator declarator = members.function.declarator;
2080 Identifier nameID = GetDeclId(declarator);
2081 char * unmangled = nameID ? nameID.string : null;
2083 External createdExternal = null;
2088 //members.function.dontMangle = true;
2089 strcpy(name, "__ecereInstMeth_");
2090 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2092 strcat(name, nameID.string);
2094 sprintf(number, "_%08d", instMethodID++);
2095 strcat(name, number);
2096 nameID.string = CopyString(name);
2099 // Do modifications here...
2102 Symbol symbol = declarator.symbol;
2103 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2105 if(method && method.type == virtualMethod)
2107 symbol.method = method;
2108 ProcessMethodType(method);
2110 if(!symbol.type.thisClass)
2112 if(method.dataType.thisClass && currentClass &&
2113 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2115 if(!currentClass.symbol)
2116 currentClass.symbol = FindClass(currentClass.fullName);
2117 symbol.type.thisClass = currentClass.symbol;
2122 _class.symbol = FindClass(_class.fullName);
2123 symbol.type.thisClass = _class.symbol;
2126 // TESTING THIS HERE:
2127 DeclareType(symbol.type, true, true);
2132 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2133 unmangled, classSym.string);
2137 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2138 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2142 FreeSpecifier(nameID._class);
2143 nameID._class = null;
2148 //Type type = declarator.symbol.type;
2149 External oldExternal = curExternal;
2151 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2152 // *** It was commented out for problems such as
2154 class VirtualDesktop : Window
2156 clientSize = Size { };
2167 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2169 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2172 if(strcmp(declarator.symbol.string, name))
2174 printf("TOCHECK: Look out for this\n");
2175 delete declarator.symbol.string;
2176 declarator.symbol.string = CopyString(name);
2179 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2181 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2182 excludedSymbols->Remove(declarator.symbol);
2183 globalContext.symbols.Add((BTNode)declarator.symbol);
2184 if(strstr(declarator.symbol.string), "::")
2185 globalContext.hasNameSpace = true;
2190 //curExternal = curExternal.prev;
2191 //afterExternal = afterExternal->next;
2193 //ProcessFunction(afterExternal->function);
2195 //curExternal = afterExternal;
2197 External externalDecl;
2198 externalDecl = MkExternalDeclaration(null);
2199 ast->Insert(oldExternal.prev, externalDecl);
2201 // Which function does this process?
2202 if(createdExternal.function)
2204 ProcessFunction(createdExternal.function);
2206 //curExternal = oldExternal;
2209 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2211 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2212 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2214 //externalDecl = MkExternalDeclaration(decl);
2216 //***** ast->Insert(external.prev, externalDecl);
2217 //ast->Insert(curExternal.prev, externalDecl);
2218 externalDecl.declaration = decl;
2219 if(decl.symbol && !decl.symbol.pointerExternal)
2220 decl.symbol.pointerExternal = externalDecl;
2222 // Trying this out...
2223 declarator.symbol.pointerExternal = externalDecl;
2230 curExternal = declarator.symbol.pointerExternal;
2231 ProcessFunction((FunctionDefinition)members.function);
2233 curExternal = external;
2234 curContext = context;
2238 FreeClassFunction(members.function);
2240 // In this pass, turn this into a MemberInitData
2241 exp = QMkExpId(name);
2242 members.type = dataMembersInit;
2243 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2249 case dataMembersInit:
2251 if(members.dataMembers && classSym)
2254 Location oldyyloc = yylloc;
2255 for(member = members.dataMembers->first; member; member = member.next)
2257 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2258 if(member.initializer && !member.initializer.isConstant)
2259 inst.isConstant = false;
2271 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2273 // OPTIMIZATIONS: TESTING THIS...
2276 if(type.kind == functionType)
2281 for(param = type.params.first; param; param = param.next)
2282 DeclareType(param, declarePointers, true);
2284 DeclareType(type.returnType, declarePointers, true);
2286 else if(type.kind == pointerType && declarePointers)
2287 DeclareType(type.type, declarePointers, false);
2288 else if(type.kind == classType)
2290 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2291 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2293 else if(type.kind == structType || type.kind == unionType)
2296 for(member = type.members.first; member; member = member.next)
2297 DeclareType(member, false, false);
2299 else if(type.kind == arrayType)
2300 DeclareType(type.arrayType, declarePointers, false);
2304 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2306 ClassTemplateArgument * arg = null;
2308 ClassTemplateParameter curParam = null;
2310 for(sClass = _class; sClass; sClass = sClass.base)
2313 if(sClass.templateClass) sClass = sClass.templateClass;
2314 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2316 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2318 for(sClass = sClass.base; sClass; sClass = sClass.base)
2320 if(sClass.templateClass) sClass = sClass.templateClass;
2321 id += sClass.templateParams.count;
2331 arg = &_class.templateArgs[id];
2332 if(arg && param.type == type)
2333 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2338 public Context SetupTemplatesContext(Class _class)
2340 Context context = PushContext();
2341 context.templateTypesOnly = true;
2342 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2344 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2345 for(; param; param = param.next)
2347 if(param.type == type && param.identifier)
2349 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2350 curContext.templateTypes.Add((BTNode)type);
2357 for(sClass = _class; sClass; sClass = sClass.base)
2359 ClassTemplateParameter p;
2360 for(p = sClass.templateParams.first; p; p = p.next)
2362 //OldList * specs = MkList();
2363 //Declarator decl = null;
2364 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2367 TemplateParameter param = p.param;
2371 // ADD DATA TYPE HERE...
2372 p.param = param = TemplateParameter
2374 identifier = MkIdentifier(p.name), type = p.type,
2375 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2378 type = TemplatedType { key = (uintptr)p.name, param = param };
2379 curContext.templateTypes.Add((BTNode)type);
2387 public void FinishTemplatesContext(Context context)
2389 PopContext(context);
2390 FreeContext(context);
2394 public void ProcessMethodType(Method method)
2396 if(!method.dataType)
2398 Context context = SetupTemplatesContext(method._class);
2400 method.dataType = ProcessTypeString(method.dataTypeString, false);
2402 FinishTemplatesContext(context);
2404 if(method.type != virtualMethod && method.dataType)
2406 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2408 if(!method._class.symbol)
2409 method._class.symbol = FindClass(method._class.fullName);
2410 method.dataType.thisClass = method._class.symbol;
2414 // Why was this commented out? Working fine without now...
2417 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2418 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2425 char * par = strstr(type, "(");
2426 char * classOp = null;
2431 for(c = par-type-1; c >= 0; c++)
2433 if(type[c] == ':' && type[c+1] == ':')
2435 classOp = type + c - 1;
2436 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2443 else if(!isspace(type[c]))
2450 int typeLen = strlen(type);
2451 memcpy(temp, classOp, classOpLen);
2452 temp[classOpLen] = '\0';
2454 _class = eSystem_FindClass(module, temp);
2457 method.dataTypeString = new char[typeLen - classOpLen + 1];
2458 memcpy(method.dataTypeString, type, classOp - type);
2459 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2462 method.dataTypeString = type;
2468 public void ProcessPropertyType(Property prop)
2472 Context context = SetupTemplatesContext(prop._class);
2473 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2474 FinishTemplatesContext(context);
2478 public void DeclareMethod(Method method, const char * name)
2480 Symbol symbol = method.symbol;
2481 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2483 //bool imported = false;
2484 bool dllImport = false;
2486 if(!method.dataType)
2487 method.dataType = ProcessTypeString(method.dataTypeString, false);
2489 if(!symbol || symbol._import || method.type == virtualMethod)
2491 if(!symbol || method.type == virtualMethod)
2494 if(!method._class.symbol)
2495 method._class.symbol = FindClass(method._class.fullName);
2496 classSym = method._class.symbol;
2497 if(!classSym._import)
2499 ModuleImport module;
2501 if(method._class.module && method._class.module.name)
2502 module = FindModule(method._class.module);
2504 module = mainModule;
2505 classSym._import = ClassImport
2507 name = CopyString(method._class.fullName);
2508 isRemote = method._class.isRemote;
2510 module.classes.Add(classSym._import);
2514 symbol = method.symbol = Symbol { };
2518 symbol._import = (ClassImport)MethodImport
2520 name = CopyString(method.name);
2521 isVirtual = method.type == virtualMethod;
2523 classSym._import.methods.Add(symbol._import);
2527 // Set the symbol type
2531 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2533 else if(type.thisClass == (void *)-1)
2535 type.thisClass = null;
2538 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2539 symbol.type = method.dataType;
2540 if(symbol.type) symbol.type.refCount++;
2543 if(!method.thisClass || strcmp(method.thisClass, "void"))
2544 symbol.type.params.Insert(null,
2545 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2548 if(!method.dataType.dllExport)
2551 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2557 if(!method.dataType)
2558 method.dataType = ((Symbol)method.symbol).type;
2559 //ProcessMethodType(method);
2562 if(method.type != virtualMethod && method.dataType)
2563 DeclareType(method.dataType, true, true);
2565 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2567 // We need a declaration here :)
2569 OldList * specifiers, * declarators;
2571 Declarator funcDecl;
2574 specifiers = MkList();
2575 declarators = MkList();
2579 ListAdd(specifiers, MkSpecifier(EXTERN));
2580 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2581 ListAdd(specifiers, MkSpecifier(STATIC));
2583 if(method.type == virtualMethod)
2585 ListAdd(specifiers, MkSpecifier(INT));
2586 d = MkDeclaratorIdentifier(MkIdentifier(name));
2590 d = MkDeclaratorIdentifier(MkIdentifier(name));
2593 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2595 Context context = SetupTemplatesContext(method._class);
2596 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2597 FinishTemplatesContext(context);
2599 funcDecl = GetFuncDecl(d);
2603 Specifier spec, next;
2604 for(spec = specifiers->first; spec; spec = next)
2607 if(spec.type == extendedSpecifier)
2609 specifiers->Remove(spec);
2610 FreeSpecifier(spec);
2615 // Add this parameter if not a static method
2616 if(method.dataType && !method.dataType.staticMethod)
2618 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2620 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2621 TypeName thisParam = MkTypeName(MkListOne(
2622 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2623 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2624 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2625 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2627 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2629 TypeName param = funcDecl.function.parameters->first;
2630 funcDecl.function.parameters->Remove(param);
2631 FreeTypeName(param);
2634 if(!funcDecl.function.parameters)
2635 funcDecl.function.parameters = MkList();
2636 funcDecl.function.parameters->Insert(null, thisParam);
2639 // Make sure we don't have empty parameter declarations for static methods...
2641 else if(!funcDecl.function.parameters)
2643 funcDecl.function.parameters = MkList();
2644 funcDecl.function.parameters->Insert(null,
2645 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2649 ProcessDeclarator(d);
2651 ListAdd(declarators, MkInitDeclarator(d, null));
2653 decl = MkDeclaration(specifiers, declarators);
2655 ReplaceThisClassSpecifiers(specifiers, method._class);
2657 // Keep a different symbol for the function definition than the declaration...
2658 if(symbol.pointerExternal)
2660 Symbol functionSymbol { };
2664 *functionSymbol = *symbol;
2665 functionSymbol.string = CopyString(symbol.string);
2666 if(functionSymbol.type)
2667 functionSymbol.type.refCount++;
2670 excludedSymbols->Add(functionSymbol);
2671 symbol.pointerExternal.symbol = functionSymbol;
2673 external = MkExternalDeclaration(decl);
2675 ast->Insert(curExternal ? curExternal.prev : null, external);
2676 external.symbol = symbol;
2677 symbol.pointerExternal = external;
2681 // Move declaration higher...
2682 ast->Move(symbol.pointerExternal, curExternal.prev);
2685 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2689 char * ReplaceThisClass(Class _class)
2691 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2695 ClassTemplateParameter param;
2698 char className[1024];
2699 strcpy(className, _class.fullName);
2700 for(param = _class.templateParams.first; param; param = param.next)
2702 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2704 if(first) strcat(className, "<");
2705 if(!first) strcat(className, ", ");
2706 if(lastParam + 1 != p)
2708 strcat(className, param.name);
2709 strcat(className, " = ");
2711 strcat(className, param.name);
2719 int len = strlen(className);
2720 if(className[len-1] == '>') className[len++] = ' ';
2721 className[len++] = '>';
2722 className[len++] = '\0';
2724 return CopyString(className);
2727 return CopyString(_class.fullName);
2730 Type ReplaceThisClassType(Class _class)
2732 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2736 ClassTemplateParameter param;
2738 char className[1024];
2739 strcpy(className, _class.fullName);
2741 for(param = _class.templateParams.first; param; param = param.next)
2743 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2745 if(first) strcat(className, "<");
2746 if(!first) strcat(className, ", ");
2747 if(lastParam + 1 != p)
2749 strcat(className, param.name);
2750 strcat(className, " = ");
2752 strcat(className, param.name);
2760 int len = strlen(className);
2761 if(className[len-1] == '>') className[len++] = ' ';
2762 className[len++] = '>';
2763 className[len++] = '\0';
2765 return MkClassType(className);
2766 //return ProcessTypeString(className, false);
2770 return MkClassType(_class.fullName);
2771 //return ProcessTypeString(_class.fullName, false);
2775 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2777 if(specs != null && _class)
2780 for(spec = specs.first; spec; spec = spec.next)
2782 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2784 spec.type = nameSpecifier;
2785 spec.name = ReplaceThisClass(_class);
2786 spec.symbol = FindClass(spec.name); //_class.symbol;
2792 // Returns imported or not
2793 bool DeclareFunction(GlobalFunction function, char * name)
2795 Symbol symbol = function.symbol;
2796 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2798 bool imported = false;
2799 bool dllImport = false;
2801 if(!function.dataType)
2803 function.dataType = ProcessTypeString(function.dataTypeString, false);
2804 if(!function.dataType.thisClass)
2805 function.dataType.staticMethod = true;
2812 ModuleImport module = FindModule(function.module);
2813 // WARNING: This is not added anywhere...
2814 symbol = function.symbol = Symbol { };
2818 if(!function.dataType.dllExport)
2820 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2821 module.functions.Add(symbol._import);
2824 // Set the symbol type
2826 symbol.type = ProcessTypeString(function.dataTypeString, false);
2827 if(!symbol.type.thisClass)
2828 symbol.type.staticMethod = true;
2831 imported = symbol._import ? true : false;
2832 if(imported && function.module != privateModule && function.module.importType != staticImport)
2836 DeclareType(function.dataType, true, true);
2840 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2842 // We need a declaration here :)
2844 OldList * specifiers, * declarators;
2846 Declarator funcDecl;
2849 specifiers = MkList();
2850 declarators = MkList();
2853 ListAdd(specifiers, MkSpecifier(EXTERN));
2856 ListAdd(specifiers, MkSpecifier(STATIC));
2859 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2862 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2864 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2865 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2866 if(function.module.importType == staticImport)
2869 for(spec = specifiers->first; spec; spec = spec.next)
2870 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2872 specifiers->Remove(spec);
2873 FreeSpecifier(spec);
2878 funcDecl = GetFuncDecl(d);
2880 // Make sure we don't have empty parameter declarations for static methods...
2881 if(funcDecl && !funcDecl.function.parameters)
2883 funcDecl.function.parameters = MkList();
2884 funcDecl.function.parameters->Insert(null,
2885 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2888 ListAdd(declarators, MkInitDeclarator(d, null));
2891 Context oldCtx = curContext;
2892 curContext = globalContext;
2893 decl = MkDeclaration(specifiers, declarators);
2894 curContext = oldCtx;
2897 // Keep a different symbol for the function definition than the declaration...
2898 if(symbol.pointerExternal)
2900 Symbol functionSymbol { };
2903 *functionSymbol = *symbol;
2904 functionSymbol.string = CopyString(symbol.string);
2905 if(functionSymbol.type)
2906 functionSymbol.type.refCount++;
2909 excludedSymbols->Add(functionSymbol);
2911 symbol.pointerExternal.symbol = functionSymbol;
2913 external = MkExternalDeclaration(decl);
2915 ast->Insert(curExternal.prev, external);
2916 external.symbol = symbol;
2917 symbol.pointerExternal = external;
2921 // Move declaration higher...
2922 ast->Move(symbol.pointerExternal, curExternal.prev);
2926 symbol.id = curExternal.symbol.idCode;
2929 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2932 void DeclareGlobalData(GlobalData data)
2934 Symbol symbol = data.symbol;
2935 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2940 symbol = data.symbol = Symbol { };
2943 data.dataType = ProcessTypeString(data.dataTypeString, false);
2944 DeclareType(data.dataType, true, true);
2947 if(!symbol.pointerExternal)
2949 // We need a declaration here :)
2951 OldList * specifiers, * declarators;
2955 specifiers = MkList();
2956 declarators = MkList();
2958 ListAdd(specifiers, MkSpecifier(EXTERN));
2959 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2960 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2962 ListAdd(declarators, MkInitDeclarator(d, null));
2964 decl = MkDeclaration(specifiers, declarators);
2965 external = MkExternalDeclaration(decl);
2967 ast->Insert(curExternal.prev, external);
2968 external.symbol = symbol;
2969 symbol.pointerExternal = external;
2973 // Move declaration higher...
2974 ast->Move(symbol.pointerExternal, curExternal.prev);
2978 symbol.id = curExternal.symbol.idCode;
2983 class Conversion : struct
2985 Conversion prev, next;
2991 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2994 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2995 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2997 Class sourceClass = source.kind == classType ? source._class.registered : null;
2998 Class destClass = dest.kind == classType ? dest._class.registered : null;
2999 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
3000 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
3002 Type sourceType = source, destType = dest;
3003 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
3004 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
3005 if(!destType.constant && sourceType.constant)
3009 Compiler_Warning($"discarding const qualifier\n");
3016 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
3017 bool isConversionExploration, bool warnConst)
3022 CheckConstCompatibility(source, dest, true);
3023 // Property convert;
3025 if(source.kind == templateType && dest.kind != templateType)
3027 Type type = ProcessTemplateParameterType(source.templateParameter);
3028 if(type) source = type;
3031 if(dest.kind == templateType && source.kind != templateType)
3033 Type type = ProcessTemplateParameterType(dest.templateParameter);
3034 if(type) dest = type;
3037 if(dest.classObjectType == typedObject && dest.kind != functionType)
3039 if(source.classObjectType != anyObject)
3043 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
3044 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
3052 if(source.kind != functionType && source.classObjectType == anyObject)
3054 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
3058 if((dest.kind == structType && source.kind == structType) ||
3059 (dest.kind == unionType && source.kind == unionType))
3061 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
3062 (source.members.first && source.members.first == dest.members.first))
3066 if(dest.kind == ellipsisType && source.kind != voidType)
3069 if(dest.kind == pointerType && dest.type.kind == voidType &&
3070 ((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))
3071 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
3073 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
3075 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
3077 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
3078 ((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))
3079 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
3080 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
3082 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
3085 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
3087 if(source._class.registered && source._class.registered.type == unitClass)
3089 if(conversions != null)
3091 if(source._class.registered == dest._class.registered)
3096 Class sourceBase, destBase;
3097 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
3098 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
3099 if(sourceBase == destBase)
3103 // Don't match enum inheriting from other enum if resolving enumeration values
3104 // TESTING: !dest.classObjectType
3105 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3107 (!source._class.registered || source._class.registered.type != enumClass) ||
3108 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3112 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3114 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3115 ((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)
3117 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3125 // JUST ADDED THIS...
3126 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3131 // Just added this for Straight conversion of ColorAlpha => Color
3132 if(source.kind == classType)
3135 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3138 for(convert = _class.conversions.first; convert; convert = convert.next)
3140 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3142 Conversion after = (conversions != null) ? conversions.last : null;
3144 if(!convert.dataType)
3145 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3146 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3147 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3148 MatchTypes(convert.dataType, dest, conversions, null, null,
3149 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3150 convert.dataType.kind == classType, false, true, warnConst))
3152 if(!conversions && !convert.Get)
3154 else if(conversions != null)
3156 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3157 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3158 (dest.kind != classType || dest._class.registered != _class.base))
3162 Conversion conv { convert = convert, isGet = true };
3163 // conversions.Add(conv);
3164 conversions.Insert(after, conv);
3177 if(dest.kind == classType)
3180 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3183 for(convert = _class.conversions.first; convert; convert = convert.next)
3185 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3187 Type constType = null;
3188 bool success = false;
3189 // Conversion after = (conversions != null) ? conversions.last : null;
3191 if(!convert.dataType)
3192 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3194 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3197 constType = { kind = pointerType, refCount = 1, type = ptrType };
3198 CopyTypeInto(ptrType, convert.dataType.type);
3199 ptrType.constant = true;
3202 // Just added this equality check to prevent recursion.... Make it safer?
3203 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3204 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3206 if(!conversions && !convert.Set)
3208 else if(conversions != null)
3210 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3211 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3212 (source.kind != classType || source._class.registered != _class.base))
3216 // *** Testing this! ***
3217 Conversion conv { convert = convert };
3218 conversions.Add(conv);
3219 //conversions.Insert(after, conv);
3225 FreeType(constType);
3231 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3233 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3234 (source.kind != classType || source._class.registered.type != structClass))
3238 // TESTING THIS... IS THIS OK??
3239 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3241 if(!dest._class.registered.dataType)
3242 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3243 // Only support this for classes...
3244 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3245 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3247 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3256 if(source.kind == classType)
3259 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3262 for(convert = _class.conversions.first; convert; convert = convert.next)
3264 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3266 Conversion after = (conversions != null) ? conversions.last : null;
3268 if(!convert.dataType)
3269 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3270 if(convert.dataType != source &&
3271 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3272 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3274 if(!conversions && !convert.Get)
3276 else if(conversions != null)
3278 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3279 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3280 (dest.kind != classType || dest._class.registered != _class.base))
3284 Conversion conv { convert = convert, isGet = true };
3286 // conversions.Add(conv);
3287 conversions.Insert(after, conv);
3296 // TESTING THIS... IS THIS OK??
3297 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3299 if(!source._class.registered.dataType)
3300 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3301 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3303 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))
3305 // For bool to be accepted by byte, short, etc.
3306 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3313 if(source.kind == classType || source.kind == subClassType)
3315 else if(dest.kind == source.kind &&
3316 (dest.kind != structType && dest.kind != unionType &&
3317 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3319 // RECENTLY ADDED THESE
3320 else if(dest.kind == doubleType && source.kind == floatType)
3322 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3324 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3326 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3328 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3330 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3332 else if(source.kind == enumType &&
3333 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3335 else if(dest.kind == enumType && !isConversionExploration &&
3336 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3338 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3339 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3341 Type paramSource, paramDest;
3343 if(dest.kind == methodType)
3344 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3345 if(source.kind == methodType)
3346 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3348 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3349 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3350 if(dest.kind == methodType)
3351 dest = dest.method.dataType;
3352 if(source.kind == methodType)
3353 source = source.method.dataType;
3355 paramSource = source.params.first;
3356 if(paramSource && paramSource.kind == voidType) paramSource = null;
3357 paramDest = dest.params.first;
3358 if(paramDest && paramDest.kind == voidType) paramDest = null;
3361 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3362 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3364 // Source thisClass must be derived from destination thisClass
3365 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3366 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3368 if(paramDest && paramDest.kind == classType)
3369 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3371 Compiler_Error($"method class should not take an object\n");
3374 paramDest = paramDest.next;
3376 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3378 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3382 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3384 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3390 // THIS WAS BACKWARDS:
3391 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3392 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3395 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3397 Compiler_Error($"overriding class expected to be derived from method class\n");
3401 paramSource = paramSource.next;
3407 // Source thisClass must be derived from destination thisClass
3408 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3410 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3416 // THIS WAS BACKWARDS TOO??
3417 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3418 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3421 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3423 //Compiler_Error($"overriding class expected to be derived from method class\n");
3431 // Source return type must be derived from destination return type
3432 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3434 Compiler_Warning($"incompatible return type for function\n");
3437 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3439 CheckConstCompatibility(dest.returnType, source.returnType, true);
3443 for(; paramDest; paramDest = paramDest.next)
3447 //Compiler_Warning($"not enough parameters\n");
3448 Compiler_Error($"not enough parameters\n");
3452 Type paramDestType = paramDest;
3453 Type paramSourceType = paramSource;
3454 Type type = paramDestType;
3456 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3457 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3458 paramSource.kind != templateType)
3461 ClassTemplateParameter curParam = null;
3463 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3466 if(sClass.templateClass) sClass = sClass.templateClass;
3467 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3469 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3471 for(sClass = sClass.base; sClass; sClass = sClass.base)
3473 if(sClass.templateClass) sClass = sClass.templateClass;
3474 id += sClass.templateParams.count;
3485 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3486 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3490 // paramDest must be derived from paramSource
3491 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3492 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3496 PrintType(paramDest, type, false, true);
3497 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3499 if(paramDestType != paramDest)
3500 FreeType(paramDestType);
3503 if(paramDestType != paramDest)
3504 FreeType(paramDestType);
3507 paramSource = paramSource.next;
3511 Compiler_Error($"too many parameters\n");
3516 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3520 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3521 (source.kind == arrayType || source.kind == pointerType))
3523 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3530 static void FreeConvert(Conversion convert)
3532 if(convert.resultType)
3533 FreeType(convert.resultType);
3536 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3537 char * string, OldList conversions)
3541 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3543 Class _class = link.data;
3544 if(_class.type == enumClass)
3546 OldList converts { };
3548 type.kind = classType;
3551 _class.symbol = FindClass(_class.fullName);
3552 type._class = _class.symbol;
3554 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false, false))
3557 Class enumClass = eSystem_FindClass(privateModule, "enum");
3561 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3563 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3564 for(value = e.values.first; value; value = value.next)
3566 if(!strcmp(value.name, string))
3571 FreeExpContents(sourceExp);
3572 FreeType(sourceExp.expType);
3574 sourceExp.isConstant = true;
3575 sourceExp.expType = MkClassType(baseClass.fullName);
3579 sourceExp.type = constantExp;
3580 if(!strcmp(baseClass.dataTypeString, "int"))
3581 sprintf(constant, "%d",(int)value.data);
3583 sprintf(constant, "0x%X",(int)value.data);
3584 sourceExp.constant = CopyString(constant);
3585 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3588 while(converts.first)
3590 Conversion convert = converts.first;
3591 converts.Remove(convert);
3592 conversions.Add(convert);
3601 converts.Free(FreeConvert);
3605 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3606 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3611 public bool ModuleVisibility(Module searchIn, Module searchFor)
3613 SubModule subModule;
3615 if(searchFor == searchIn)
3618 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3620 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3622 if(ModuleVisibility(subModule.module, searchFor))
3629 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3633 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3635 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3637 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3640 for(module = mainModule.application.allModules.first; module; module = module.next)
3642 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3648 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3651 Type realDest = dest;
3652 Type backupSourceExpType = null;
3653 Expression computedExp = sourceExp;
3656 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3657 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3659 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3660 ComputeExpression(computedExp /*sourceExp*/);
3663 source = sourceExp.expType;
3665 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3667 if(computedExp != sourceExp)
3669 FreeExpression(computedExp);
3670 computedExp = sourceExp;
3676 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3678 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3680 Class sourceBase, destBase;
3681 for(sourceBase = source._class.registered;
3682 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3683 sourceBase = sourceBase.base);
3684 for(destBase = dest._class.registered;
3685 destBase && destBase.base && destBase.base.type != systemClass;
3686 destBase = destBase.base);
3687 //if(source._class.registered == dest._class.registered)
3688 if(sourceBase == destBase)
3690 if(computedExp != sourceExp)
3692 FreeExpression(computedExp);
3693 computedExp = sourceExp;
3705 int64 value = MAXINT;
3709 if(computedExp.type == constantExp)
3712 value = strtoll(computedExp.constant, null, 0);
3714 value = strtoull(computedExp.constant, null, 0);
3716 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3719 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3721 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3723 if(computedExp != sourceExp)
3725 FreeExpression(computedExp);
3726 computedExp = sourceExp;
3729 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3730 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3733 source = Type { kind = intType, isSigned = false, refCount = 1 };
3736 if(dest.kind == classType)
3738 Class _class = dest._class ? dest._class.registered : null;
3740 if(_class && _class.type == unitClass)
3742 if(source.kind != classType)
3745 Type tempDest, tempSource;
3747 for(; _class.base.type != systemClass; _class = _class.base);
3749 tempDest = tempType;
3751 tempType.kind = classType;
3753 _class.symbol = FindClass(_class.fullName);
3755 tempType._class = _class.symbol;
3756 tempType.truth = dest.truth;
3758 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3760 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3761 backupSourceExpType = sourceExp.expType;
3762 sourceExp.expType = dest; dest.refCount++;
3763 //sourceExp.expType = MkClassType(_class.fullName);
3771 // Why wasn't there something like this?
3772 if(_class && _class.type == bitClass && source.kind != classType)
3774 if(!dest._class.registered.dataType)
3775 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3776 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3779 FreeType(sourceExp.expType);
3780 source = sourceExp.expType = MkClassType(dest._class.string);
3783 //source.kind = classType;
3784 //source._class = dest._class;
3788 // Adding two enumerations
3790 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3792 if(!source._class.registered.dataType)
3793 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3794 if(!dest._class.registered.dataType)
3795 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3797 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3800 source = sourceExp.expType = MkClassType(dest._class.string);
3803 //source.kind = classType;
3804 //source._class = dest._class;
3808 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3810 OldList * specs = MkList();
3814 ReadString(string, sourceExp.string);
3815 decl = SpecDeclFromString(string, specs, null);
3817 FreeExpContents(sourceExp);
3818 FreeType(sourceExp.expType);
3820 sourceExp.type = classExp;
3821 sourceExp._classExp.specifiers = specs;
3822 sourceExp._classExp.decl = decl;
3823 sourceExp.expType = dest;
3828 if(backupSourceExpType) FreeType(backupSourceExpType);
3832 else if(source.kind == classType)
3834 Class _class = source._class ? source._class.registered : null;
3836 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3839 if(dest.kind != classType)
3841 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3842 if(!source._class.registered.dataType)
3843 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3846 dest = MkClassType(source._class.string);
3847 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3848 // dest = MkClassType(source._class.string);
3852 if(dest.kind != classType)
3855 Type tempDest, tempSource;
3857 if(!source._class.registered.dataType)
3858 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3860 for(; _class.base.type != systemClass; _class = _class.base);
3862 tempSource = tempType;
3863 tempType.kind = classType;
3864 tempType._class = FindClass(_class.fullName);
3865 tempType.truth = source.truth;
3866 tempType.classObjectType = source.classObjectType;
3869 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3871 // PUT THIS BACK TESTING UNITS?
3872 if(conversions.last)
3874 ((Conversion)(conversions.last)).resultType = dest;
3878 FreeType(sourceExp.expType);
3879 sourceExp.expType = MkClassType(_class.fullName);
3880 sourceExp.expType.truth = source.truth;
3881 sourceExp.expType.classObjectType = source.classObjectType;
3883 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3885 if(!sourceExp.destType)
3887 FreeType(sourceExp.destType);
3888 sourceExp.destType = sourceExp.expType;
3889 if(sourceExp.expType)
3890 sourceExp.expType.refCount++;
3893 //source = _class.dataType;
3896 // TOCHECK: TESTING THIS NEW CODE
3897 if(!_class.dataType)
3898 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3900 dest = MkClassType(source._class.string);
3901 dest.truth = source.truth;
3902 dest.classObjectType = source.classObjectType;
3905 source = _class.dataType;
3915 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3925 if(source.kind == classType)
3927 Class _class = source._class.registered;
3928 if(_class.type == unitClass)
3930 if(!_class.dataType)
3931 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3932 source = _class.dataType;
3936 if(dest.kind == classType)
3938 Class _class = dest._class ? dest._class.registered : null;
3939 bool fittingValue = false;
3940 if(_class && _class.type == enumClass)
3942 Class enumClass = eSystem_FindClass(privateModule, "enum");
3943 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3944 if(c && value >= 0 && value <= c.largest)
3945 fittingValue = true;
3948 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3949 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3951 if(_class.type == normalClass || _class.type == noHeadClass)
3953 Expression newExp { };
3954 *newExp = *sourceExp;
3955 if(sourceExp.destType) sourceExp.destType.refCount++;
3956 if(sourceExp.expType) sourceExp.expType.refCount++;
3957 sourceExp.type = castExp;
3958 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3959 sourceExp.cast.exp = newExp;
3960 FreeType(sourceExp.expType);
3961 sourceExp.expType = null;
3962 ProcessExpressionType(sourceExp);
3964 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3967 FreeType(sourceExp.expType);
3968 sourceExp.expType = dest;
3972 if(inCompiler) FreeType(dest);
3974 if(backupSourceExpType) FreeType(backupSourceExpType);
3978 if(!_class.dataType)
3979 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3981 dest = _class.dataType;
3985 // Accept lower precision types for units, since we want to keep the unit type
3986 if(dest.kind == doubleType &&
3987 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3988 source.kind == charType || source.kind == _BoolType))
3990 specs = MkListOne(MkSpecifier(DOUBLE));
3992 else if(dest.kind == floatType &&
3993 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3994 source.kind == _BoolType || source.kind == doubleType))
3996 specs = MkListOne(MkSpecifier(FLOAT));
3998 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3999 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4002 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4003 ListAdd(specs, MkSpecifier(INT64));
4005 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
4006 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4009 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4010 ListAdd(specs, MkSpecifier(INT));
4012 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
4013 source.kind == floatType || source.kind == doubleType))
4016 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4017 ListAdd(specs, MkSpecifier(SHORT));
4019 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
4020 source.kind == floatType || source.kind == doubleType))
4023 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4024 ListAdd(specs, MkSpecifier(CHAR));
4030 if(backupSourceExpType)
4032 // Failed to convert: revert previous exp type
4033 if(sourceExp.expType) FreeType(sourceExp.expType);
4034 sourceExp.expType = backupSourceExpType;
4039 else if(dest.kind == doubleType &&
4040 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
4041 source.kind == _BoolType || source.kind == charType))
4043 specs = MkListOne(MkSpecifier(DOUBLE));
4045 else if(dest.kind == floatType &&
4046 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4048 specs = MkListOne(MkSpecifier(FLOAT));
4050 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4051 (value == 1 || value == 0))
4054 ListAdd(specs, MkSpecifier(BOOL));
4056 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4057 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
4060 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4061 ListAdd(specs, MkSpecifier(CHAR));
4063 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
4064 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
4067 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4068 ListAdd(specs, MkSpecifier(SHORT));
4070 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
4073 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4074 ListAdd(specs, MkSpecifier(INT));
4076 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
4079 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4080 ListAdd(specs, MkSpecifier(INT64));
4082 else if(dest.kind == enumType &&
4083 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4085 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4091 if(backupSourceExpType)
4093 // Failed to convert: revert previous exp type
4094 if(sourceExp.expType) FreeType(sourceExp.expType);
4095 sourceExp.expType = backupSourceExpType;
4100 if(!flag && !sourceExp.opDestType)
4102 Expression newExp { };
4103 *newExp = *sourceExp;
4106 if(sourceExp.destType) sourceExp.destType.refCount++;
4107 if(sourceExp.expType) sourceExp.expType.refCount++;
4109 sourceExp.type = castExp;
4110 if(realDest.kind == classType)
4112 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4113 FreeList(specs, FreeSpecifier);
4116 sourceExp.cast.typeName = MkTypeName(specs, null);
4117 if(newExp.type == opExp)
4119 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4122 sourceExp.cast.exp = newExp;
4124 FreeType(sourceExp.expType);
4125 sourceExp.expType = null;
4126 ProcessExpressionType(sourceExp);
4129 FreeList(specs, FreeSpecifier);
4133 if(backupSourceExpType) FreeType(backupSourceExpType);
4139 if(computedExp != sourceExp)
4141 FreeExpression(computedExp);
4142 computedExp = sourceExp;
4145 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4146 if(sourceExp.type == identifierExp)
4148 Identifier id = sourceExp.identifier;
4149 if(dest.kind == classType)
4151 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4153 Class _class = dest._class.registered;
4154 Class enumClass = eSystem_FindClass(privateModule, "enum");
4157 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4160 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4161 for(value = e.values.first; value; value = value.next)
4163 if(!strcmp(value.name, id.string))
4168 FreeExpContents(sourceExp);
4169 FreeType(sourceExp.expType);
4171 sourceExp.isConstant = true;
4172 sourceExp.expType = MkClassType(_class.fullName);
4176 sourceExp.type = constantExp;
4177 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
4178 sprintf(constant, "%d", (int) value.data);
4180 sprintf(constant, "0x%X", (int) value.data);
4181 sourceExp.constant = CopyString(constant);
4182 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4192 // Loop through all enum classes
4193 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4204 #define TERTIARY(o, name, m, t, p) \
4205 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4207 exp.type = constantExp; \
4208 exp.string = p(op1.m ? op2.m : op3.m); \
4210 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4214 #define BINARY(o, name, m, t, p) \
4215 static bool name(Expression exp, Operand op1, Operand op2) \
4218 exp.type = constantExp; \
4219 exp.string = p((t)(op1.m o value2)); \
4221 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4225 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4226 static bool name(Expression exp, Operand op1, Operand op2) \
4229 exp.type = constantExp; \
4230 exp.string = p(value2 ? (op1.m o value2) : 0); \
4232 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4236 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4237 static bool name(Expression exp, Operand op1, Operand op2) \
4240 exp.type = constantExp; \
4241 exp.string = p(op1.m o value2); \
4243 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4247 #define UNARY(o, name, m, t, p) \
4248 static bool name(Expression exp, Operand op1) \
4250 exp.type = constantExp; \
4251 exp.string = p((t)(o op1.m)); \
4253 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4257 #define OPERATOR_ALL(macro, o, name) \
4258 macro(o, Int##name, i, int, PrintInt) \
4259 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4260 macro(o, Int64##name, i64, int64, PrintInt64) \
4261 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4262 macro(o, Short##name, s, short, PrintShort) \
4263 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4264 macro(o, Char##name, c, char, PrintChar) \
4265 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4266 macro(o, Float##name, f, float, PrintFloat) \
4267 macro(o, Double##name, d, double, PrintDouble)
4269 #define OPERATOR_INTTYPES(macro, o, name) \
4270 macro(o, Int##name, i, int, PrintInt) \
4271 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4272 macro(o, Int64##name, i64, int64, PrintInt64) \
4273 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4274 macro(o, Short##name, s, short, PrintShort) \
4275 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4276 macro(o, Char##name, c, char, PrintChar) \
4277 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4279 #define OPERATOR_REALTYPES(macro, o, name) \
4280 macro(o, Float##name, f, float, PrintFloat) \
4281 macro(o, Double##name, d, double, PrintDouble)
4283 // binary arithmetic
4284 OPERATOR_ALL(BINARY, +, Add)
4285 OPERATOR_ALL(BINARY, -, Sub)
4286 OPERATOR_ALL(BINARY, *, Mul)
4287 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4288 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4289 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4292 OPERATOR_ALL(UNARY, -, Neg)
4294 // unary arithmetic increment and decrement
4295 OPERATOR_ALL(UNARY, ++, Inc)
4296 OPERATOR_ALL(UNARY, --, Dec)
4298 // binary arithmetic assignment
4299 OPERATOR_ALL(BINARY, =, Asign)
4300 OPERATOR_ALL(BINARY, +=, AddAsign)
4301 OPERATOR_ALL(BINARY, -=, SubAsign)
4302 OPERATOR_ALL(BINARY, *=, MulAsign)
4303 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4304 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4305 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4308 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4309 OPERATOR_INTTYPES(BINARY, |, BitOr)
4310 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4311 OPERATOR_INTTYPES(BINARY, <<, LShift)
4312 OPERATOR_INTTYPES(BINARY, >>, RShift)
4315 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4317 // binary bitwise assignment
4318 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4319 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4320 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4321 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4322 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4324 // unary logical negation
4325 OPERATOR_INTTYPES(UNARY, !, Not)
4327 // binary logical equality
4328 OPERATOR_ALL(BINARY, ==, Equ)
4329 OPERATOR_ALL(BINARY, !=, Nqu)
4332 OPERATOR_ALL(BINARY, &&, And)
4333 OPERATOR_ALL(BINARY, ||, Or)
4335 // binary logical relational
4336 OPERATOR_ALL(BINARY, >, Grt)
4337 OPERATOR_ALL(BINARY, <, Sma)
4338 OPERATOR_ALL(BINARY, >=, GrtEqu)
4339 OPERATOR_ALL(BINARY, <=, SmaEqu)
4341 // tertiary condition operator
4342 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4344 //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
4345 #define OPERATOR_TABLE_ALL(name, type) \
4346 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4348 type##Inc, type##Dec, \
4349 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4350 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4352 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4354 type##Equ, type##Nqu, \
4355 type##And, type##Or, \
4356 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4359 #define OPERATOR_TABLE_INTTYPES(name, type) \
4360 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4362 type##Inc, type##Dec, \
4363 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4364 null, null, null, null, null, \
4366 null, null, null, null, null, \
4368 type##Equ, type##Nqu, \
4369 type##And, type##Or, \
4370 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4373 OPERATOR_TABLE_ALL(int, Int)
4374 OPERATOR_TABLE_ALL(uint, UInt)
4375 OPERATOR_TABLE_ALL(int64, Int64)
4376 OPERATOR_TABLE_ALL(uint64, UInt64)
4377 OPERATOR_TABLE_ALL(short, Short)
4378 OPERATOR_TABLE_ALL(ushort, UShort)
4379 OPERATOR_TABLE_INTTYPES(float, Float)
4380 OPERATOR_TABLE_INTTYPES(double, Double)
4381 OPERATOR_TABLE_ALL(char, Char)
4382 OPERATOR_TABLE_ALL(uchar, UChar)
4384 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4385 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4386 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4387 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4388 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4389 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4390 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4391 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4393 public void ReadString(char * output, char * string)
4395 int len = strlen(string);
4397 bool quoted = false, escaped = false;
4398 for(c = 0; c<len; c++)
4400 char ch = string[c];
4405 case 'n': output[d] = '\n'; break;
4406 case 't': output[d] = '\t'; break;
4407 case 'a': output[d] = '\a'; break;
4408 case 'b': output[d] = '\b'; break;
4409 case 'f': output[d] = '\f'; break;
4410 case 'r': output[d] = '\r'; break;
4411 case 'v': output[d] = '\v'; break;
4412 case '\\': output[d] = '\\'; break;
4413 case '\"': output[d] = '\"'; break;
4414 case '\'': output[d] = '\''; break;
4415 default: output[d] = ch;
4436 // String Unescape Copy
4438 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4439 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4440 public int UnescapeString(char * d, char * s, int len)
4444 while(j < len && (ch = s[j]))
4449 switch((ch = s[++j]))
4451 case 'n': d[k] = '\n'; break;
4452 case 't': d[k] = '\t'; break;
4453 case 'a': d[k] = '\a'; break;
4454 case 'b': d[k] = '\b'; break;
4455 case 'f': d[k] = '\f'; break;
4456 case 'r': d[k] = '\r'; break;
4457 case 'v': d[k] = '\v'; break;
4458 case '\\': d[k] = '\\'; break;
4459 case '\"': d[k] = '\"'; break;
4460 case '\'': d[k] = '\''; break;
4461 default: d[k] = '\\'; d[k] = ch;
4473 public char * OffsetEscapedString(char * s, int len, int offset)
4477 while(j < len && k < offset && (ch = s[j]))
4482 return (k == offset) ? s + j : null;
4485 public Operand GetOperand(Expression exp)
4488 Type type = exp.expType;
4491 while(type.kind == classType &&
4492 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4494 if(!type._class.registered.dataType)
4495 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4496 type = type._class.registered.dataType;
4499 if(exp.type == stringExp && op.kind == pointerType)
4501 op.ui64 = (uint64)exp.string;
4502 op.kind = pointerType;
4505 else if(exp.isConstant && exp.type == constantExp)
4507 op.kind = type.kind;
4508 op.type = exp.expType;
4515 if(exp.constant[0] == '\'')
4517 op.c = exp.constant[1];
4520 else if(type.isSigned)
4522 op.c = (char)strtol(exp.constant, null, 0);
4527 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4535 op.s = (short)strtol(exp.constant, null, 0);
4540 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4548 op.i = (int)strtol(exp.constant, null, 0);
4553 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4561 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4566 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4569 op.kind = int64Type;
4574 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4579 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4582 op.kind = int64Type;
4587 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4592 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4595 op.kind = int64Type;
4598 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4599 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4600 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4601 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4603 op.f = (float)strtod(exp.constant, null);
4607 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4608 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4609 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4610 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4612 op.d = (double)strtod(exp.constant, null);
4615 //case classType: For when we have operator overloading...
4616 // Pointer additions
4617 //case functionType:
4621 op.ui64 = _strtoui64(exp.constant, null, 0);
4622 op.kind = pointerType;
4632 static __attribute__((unused)) void UnusedFunction()
4635 a.OnGetString(0,0,0);
4638 extern int __ecereVMethodID_class_OnGetString;
4641 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4643 DataMember dataMember;
4644 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4646 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4647 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4651 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4653 void * ptr = inst.data + dataMember.offset + offset;
4654 char * result = null;
4655 exp.loc = member.loc = inst.loc;
4656 ((Identifier)member.identifiers->first).loc = inst.loc;
4658 if(!dataMember.dataType)
4659 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4660 type = dataMember.dataType;
4661 if(type.kind == classType)
4663 Class _class = type._class.registered;
4664 if(_class.type == enumClass)
4666 Class enumClass = eSystem_FindClass(privateModule, "enum");
4669 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4671 for(item = e.values.first; item; item = item.next)
4673 if((int)item.data == *(int *)ptr)
4681 exp.identifier = MkIdentifier(result);
4682 exp.type = identifierExp;
4683 exp.destType = MkClassType(_class.fullName);
4684 ProcessExpressionType(exp);
4688 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4690 if(!_class.dataType)
4691 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4692 type = _class.dataType;
4701 FreeExpContents(exp);
4703 exp.constant = PrintFloat(*(float*)ptr);
4704 exp.type = constantExp;
4709 FreeExpContents(exp);
4711 exp.constant = PrintDouble(*(double*)ptr);
4712 exp.type = constantExp;
4717 FreeExpContents(exp);
4719 exp.constant = PrintInt(*(int*)ptr);
4720 exp.type = constantExp;
4725 FreeExpContents(exp);
4727 exp.constant = PrintInt64(*(int64*)ptr);
4728 exp.type = constantExp;
4733 FreeExpContents(exp);
4734 // TODO: This should probably use proper type
4735 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4736 exp.type = constantExp;
4741 FreeExpContents(exp);
4742 // TODO: This should probably use proper type
4743 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4744 exp.type = constantExp;
4748 Compiler_Error($"Unhandled type populating instance\n");
4751 ListAdd(memberList, member);
4754 if(parentDataMember.type == unionMember)
4759 void PopulateInstance(Instantiation inst)
4761 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4762 Class _class = classSym.registered;
4763 DataMember dataMember;
4764 OldList * memberList = MkList();
4765 // Added this check and ->Add to prevent memory leaks on bad code
4767 inst.members = MkListOne(MkMembersInitList(memberList));
4769 inst.members->Add(MkMembersInitList(memberList));
4770 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4772 if(!dataMember.isProperty)
4774 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4775 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4779 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4781 void * ptr = inst.data + dataMember.offset;
4782 char * result = null;
4784 exp.loc = member.loc = inst.loc;
4785 ((Identifier)member.identifiers->first).loc = inst.loc;
4787 if(!dataMember.dataType)
4788 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4789 type = dataMember.dataType;
4790 if(type.kind == classType)
4792 Class _class = type._class.registered;
4793 if(_class.type == enumClass)
4795 Class enumClass = eSystem_FindClass(privateModule, "enum");
4798 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4800 for(item = e.values.first; item; item = item.next)
4802 if((int)item.data == *(int *)ptr)
4811 exp.identifier = MkIdentifier(result);
4812 exp.type = identifierExp;
4813 exp.destType = MkClassType(_class.fullName);
4814 ProcessExpressionType(exp);
4817 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4819 if(!_class.dataType)
4820 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4821 type = _class.dataType;
4830 exp.constant = PrintFloat(*(float*)ptr);
4831 exp.type = constantExp;
4836 exp.constant = PrintDouble(*(double*)ptr);
4837 exp.type = constantExp;
4842 exp.constant = PrintInt(*(int*)ptr);
4843 exp.type = constantExp;
4848 exp.constant = PrintInt64(*(int64*)ptr);
4849 exp.type = constantExp;
4854 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4855 exp.type = constantExp;
4859 Compiler_Error($"Unhandled type populating instance\n");
4862 ListAdd(memberList, member);
4868 void ComputeInstantiation(Expression exp)
4870 Instantiation inst = exp.instance;
4871 MembersInit members;
4872 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4873 Class _class = classSym ? classSym.registered : null;
4874 DataMember curMember = null;
4875 Class curClass = null;
4876 DataMember subMemberStack[256];
4877 int subMemberStackPos = 0;
4880 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4882 // Don't recompute the instantiation...
4883 // Non Simple classes will have become constants by now
4887 if(_class.type == normalClass || _class.type == noHeadClass)
4889 inst.data = (byte *)eInstance_New(_class);
4890 if(_class.type == normalClass)
4891 ((Instance)inst.data)._refCount++;
4894 inst.data = new0 byte[_class.structSize];
4899 for(members = inst.members->first; members; members = members.next)
4901 switch(members.type)
4903 case dataMembersInit:
4905 if(members.dataMembers)
4908 for(member = members.dataMembers->first; member; member = member.next)
4910 Identifier ident = member.identifiers ? member.identifiers->first : null;
4913 Property prop = null;
4914 DataMember dataMember = null;
4915 uint dataMemberOffset;
4919 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4922 if(curMember.isProperty)
4923 prop = (Property)curMember;
4926 dataMember = curMember;
4928 // CHANGED THIS HERE
4929 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4931 // 2013/17/29 -- It seems that this was missing here!
4932 if(_class.type == normalClass)
4933 dataMemberOffset += _class.base.structSize;
4934 // dataMemberOffset = dataMember.offset;
4941 prop = eClass_FindProperty(_class, ident.string, privateModule);
4945 if(prop.memberAccess == publicAccess)
4947 curMember = (DataMember)prop;
4948 curClass = prop._class;
4953 DataMember _subMemberStack[256];
4954 int _subMemberStackPos = 0;
4956 // FILL MEMBER STACK
4957 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4962 if(dataMember.memberAccess == publicAccess)
4964 curMember = dataMember;
4965 curClass = dataMember._class;
4966 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4967 subMemberStackPos = _subMemberStackPos;
4973 if(found && member.initializer && member.initializer.type == expInitializer)
4975 Expression value = member.initializer.exp;
4977 bool deepMember = false;
4980 type = prop.dataType;
4984 if(!dataMember.dataType)
4985 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4987 type = dataMember.dataType;
4990 if(ident && ident.next)
4994 // for(; ident && type; ident = ident.next)
4995 for(ident = ident.next; ident && type; ident = ident.next)
4997 if(type.kind == classType)
4999 prop = eClass_FindProperty(type._class.registered,
5000 ident.string, privateModule);
5002 type = prop.dataType;
5005 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
5006 ident.string, &dataMemberOffset, privateModule, null, null);
5008 type = dataMember.dataType;
5011 else if(type.kind == structType || type.kind == unionType)
5014 for(memberType = type.members.first; memberType; memberType = memberType.next)
5016 if(!strcmp(memberType.name, ident.string))
5027 FreeType(value.destType);
5028 value.destType = type;
5029 if(type) type.refCount++;
5030 ComputeExpression(value);
5032 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
5034 if(type.kind == classType)
5036 Class _class = type._class.registered;
5037 if(_class.type == bitClass || _class.type == unitClass ||
5038 _class.type == enumClass)
5040 if(!_class.dataType)
5041 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5042 type = _class.dataType;
5048 void * ptr = inst.data + dataMemberOffset;
5050 if(value.type == constantExp)
5056 GetInt(value, (int*)ptr);
5061 GetInt64(value, (int64*)ptr);
5066 GetIntPtr(value, (intptr*)ptr);
5071 GetIntSize(value, (intsize*)ptr);
5076 GetFloat(value, (float*)ptr);
5081 GetDouble(value, (double *)ptr);
5086 else if(value.type == instanceExp)
5088 if(type.kind == classType)
5090 Class _class = type._class.registered;
5091 if(_class.type == structClass)
5093 ComputeTypeSize(type);
5094 if(value.instance.data)
5095 memcpy(ptr, value.instance.data, type.size);
5102 if(value.type == instanceExp && value.instance.data)
5104 if(type.kind == classType)
5106 Class _class = type._class.registered;
5107 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5109 void (*Set)(void *, void *) = (void *)prop.Set;
5110 Set(inst.data, value.instance.data);
5111 PopulateInstance(inst);
5115 else if(value.type == constantExp)
5121 void (*Set)(void *, double) = (void *)prop.Set;
5122 Set(inst.data, strtod(value.constant, null) );
5127 void (*Set)(void *, float) = (void *)prop.Set;
5128 Set(inst.data, (float)(strtod(value.constant, null)));
5133 void (*Set)(void *, int) = (void *)prop.Set;
5134 Set(inst.data, (int)strtol(value.constant, null, 0));
5139 void (*Set)(void *, int64) = (void *)prop.Set;
5140 Set(inst.data, _strtoi64(value.constant, null, 0));
5145 void (*Set)(void *, intptr) = (void *)prop.Set;
5146 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5151 void (*Set)(void *, intsize) = (void *)prop.Set;
5152 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5157 else if(value.type == stringExp)
5160 ReadString(temp, value.string);
5161 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5165 else if(!deepMember && type && _class.type == unitClass)
5169 // Only support converting units to units for now...
5170 if(value.type == constantExp)
5172 if(type.kind == classType)
5174 Class _class = type._class.registered;
5175 if(_class.type == unitClass)
5177 if(!_class.dataType)
5178 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5179 type = _class.dataType;
5182 // TODO: Assuming same base type for units...
5188 float (*Set)(float) = (void *)prop.Set;
5189 GetFloat(member.initializer.exp, &fValue);
5190 exp.constant = PrintFloat(Set(fValue));
5191 exp.type = constantExp;
5197 double (*Set)(double) = (void *)prop.Set;
5198 GetDouble(member.initializer.exp, &dValue);
5199 exp.constant = PrintDouble(Set(dValue));
5200 exp.type = constantExp;
5207 else if(!deepMember && type && _class.type == bitClass)
5211 if(value.type == instanceExp && value.instance.data)
5213 unsigned int (*Set)(void *) = (void *)prop.Set;
5214 bits = Set(value.instance.data);
5216 else if(value.type == constantExp)
5222 BitMember bitMember = (BitMember) dataMember;
5225 bits = (bits & ~bitMember.mask);
5226 if(!bitMember.dataType)
5227 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5228 type = bitMember.dataType;
5229 if(type.kind == classType && type._class && type._class.registered)
5231 if(!type._class.registered.dataType)
5232 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5233 type = type._class.registered.dataType;
5238 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5239 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5241 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5242 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5243 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5244 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5246 bits |= part << bitMember.pos;
5252 if(_class && _class.type == unitClass)
5254 ComputeExpression(member.initializer.exp);
5255 exp.constant = member.initializer.exp.constant;
5256 exp.type = constantExp;
5258 member.initializer.exp.constant = null;
5268 if(_class && _class.type == bitClass)
5270 exp.constant = PrintHexUInt(bits);
5271 exp.type = constantExp;
5273 if(exp.type != instanceExp)
5279 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5281 bool result = false;
5285 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5286 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5290 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5291 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5294 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5295 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5296 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5299 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5300 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5301 result = GetOpFloat(op, &op.f);
5304 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5305 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5306 result = GetOpDouble(op, &op.d);
5309 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5310 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5311 result = GetOpUIntPtr(op, &op.ui64);
5314 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5315 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5316 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5319 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5320 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.ui64);
5323 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5324 result = isSigned ? GetOpIntSize(op, &op.i64) : GetOpUIntSize(op, &op.ui64);
5330 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5332 if(exp.op.op == SIZEOF)
5334 FreeExpContents(exp);
5335 exp.type = constantExp;
5336 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5347 // Provide default unary +
5348 Expression exp2 = exp.op.exp2;
5350 FreeExpContents(exp);
5351 FreeType(exp.expType);
5352 FreeType(exp.destType);
5358 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5360 // unary arithmetic increment and decrement
5361 //OPERATOR_ALL(UNARY, ++, Inc)
5362 //OPERATOR_ALL(UNARY, --, Dec)
5365 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5367 // unary logical negation
5369 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5375 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5377 if(Promote(op2, op1.kind, op1.type.isSigned))
5378 op2.kind = op1.kind, op2.ops = op1.ops;
5379 else if(Promote(op1, op2.kind, op2.type.isSigned))
5380 op1.kind = op2.kind, op1.ops = op2.ops;
5384 // binary arithmetic
5386 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5389 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5392 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5395 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5398 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5400 // binary arithmetic assignment
5401 //OPERATOR_ALL(BINARY, =, Asign)
5402 //OPERATOR_ALL(BINARY, +=, AddAsign)
5403 //OPERATOR_ALL(BINARY, -=, SubAsign)
5404 //OPERATOR_ALL(BINARY, *=, MulAsign)
5405 //OPERATOR_ALL(BINARY, /=, DivAsign)
5406 //OPERATOR_ALL(BINARY, %=, ModAsign)
5411 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5415 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5418 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5421 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5424 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5426 // binary bitwise assignment
5427 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5428 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5429 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5430 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5431 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5432 // binary logical equality
5434 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5437 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5441 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5444 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5446 // binary logical relational
5448 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5451 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5454 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5457 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5464 void ComputeExpression(Expression exp)
5466 char expString[10240];
5467 expString[0] = '\0';
5469 PrintExpression(exp, expString);
5476 ComputeInstantiation(exp);
5485 Expression exp1, exp2 = null;
5489 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5492 Expression e = exp.op.exp2;
5494 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5496 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5498 if(e.type == extensionCompoundExp)
5499 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5504 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5506 if(e.type == stringExp && e.string)
5508 char * string = e.string;
5509 int len = strlen(string);
5510 char * tmp = new char[len-2+1];
5511 len = UnescapeString(tmp, string + 1, len - 2);
5513 FreeExpContents(exp);
5514 exp.type = constantExp;
5515 exp.constant = PrintUInt(len + 1);
5519 Type type = e.expType;
5521 FreeExpContents(exp);
5522 exp.type = constantExp;
5523 exp.constant = PrintUInt(ComputeTypeSize(type));
5529 ComputeExpression(exp.op.exp2);
5533 ComputeExpression(exp.op.exp1);
5536 op1 = GetOperand(exp1);
5537 if(op1.type) op1.type.refCount++;
5540 op2 = GetOperand(exp2);
5541 if(op2.type) op2.type.refCount++;
5547 op1 = GetOperand(exp1);
5548 if(op1.type) op1.type.refCount++;
5551 CallOperator(exp, exp1, exp2, op1, op2);
5558 if(exp.op.exp1 && exp.op.exp2)
5563 FreeExpContents(exp);
5564 op1.ops.BitAnd(exp, op1, op2);
5573 FreeExpContents(exp);
5574 op1.ops.Mul(exp, op1, op2);
5583 FreeExpContents(exp);
5584 op1.ops.Add(exp, op1, op2);
5589 // Provide default unary +
5590 Expression exp2 = exp.op.exp2;
5592 FreeExpContents(exp);
5593 FreeType(exp.expType);
5594 FreeType(exp.destType);
5605 FreeExpContents(exp);
5606 op1.ops.Sub(exp, op1, op2);
5613 FreeExpContents(exp);
5614 op1.ops.Neg(exp, op1);
5621 FreeExpContents(exp);
5622 op1.ops.BitNot(exp, op1);
5628 FreeExpContents(exp);
5629 op1.ops.Not(exp, op1);
5632 // Binary only operators
5636 FreeExpContents(exp);
5637 op1.ops.Div(exp, op1, op2);
5643 FreeExpContents(exp);
5644 op1.ops.Mod(exp, op1, op2);
5656 FreeExpContents(exp);
5657 op1.ops.Sma(exp, op1, op2);
5666 FreeExpContents(exp);
5667 op1.ops.Grt(exp, op1, op2);
5676 FreeExpContents(exp);
5677 op1.ops.SmaEqu(exp, op1, op2);
5686 FreeExpContents(exp);
5687 op1.ops.GrtEqu(exp, op1, op2);
5696 FreeExpContents(exp);
5697 op1.ops.Equ(exp, op1, op2);
5706 FreeExpContents(exp);
5707 op1.ops.Nqu(exp, op1, op2);
5714 FreeExpContents(exp);
5715 op1.ops.BitOr(exp, op1, op2);
5721 FreeExpContents(exp);
5722 op1.ops.BitXor(exp, op1, op2);
5730 FreeExpContents(exp);
5731 exp.type = constantExp;
5732 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5736 if(op1.type) FreeType(op1.type);
5737 if(op2.type) FreeType(op2.type);
5741 case extensionExpressionExp:
5744 for(e = exp.list->first; e; e = n)
5749 OldList * list = exp.list;
5750 Expression prev = exp.prev;
5751 Expression next = exp.next;
5752 ComputeExpression(e);
5753 //FreeExpContents(exp);
5754 FreeType(exp.expType);
5755 FreeType(exp.destType);
5774 exp.isConstant = true;
5776 ComputeExpression(exp.index.exp);
5777 if(!exp.index.exp.isConstant)
5778 exp.isConstant = false;
5780 for(e = exp.index.index->first; e; e = e.next)
5782 ComputeExpression(e);
5785 // Check if this type is int
5788 exp.isConstant = false;
5790 exp.expType = Dereference(exp.index.exp.expType);
5796 Expression memberExp = exp.member.exp;
5797 Identifier memberID = exp.member.member;
5800 ComputeExpression(exp.member.exp);
5801 type = exp.member.exp.expType;
5804 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);
5805 Property prop = null;
5806 DataMember member = null;
5807 Class convertTo = null;
5808 if(type.kind == subClassType && exp.member.exp.type == classExp)
5809 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5816 PrintTypeNoConst(type, string, false, true);
5817 classSym = FindClass(string);
5818 _class = classSym ? classSym.registered : null;
5821 if(exp.member.member)
5823 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5825 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5827 if(!prop && !member && _class && exp.member.member)
5829 Symbol classSym = FindClass(exp.member.member.string);
5831 _class = classSym ? classSym.registered : null;
5832 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5839 Type type = prop.dataType;
5840 // TODO: Assuming same base type for units...
5841 if(_class.type == unitClass)
5843 if(type.kind == classType)
5845 Class _class = type._class.registered;
5846 if(_class.type == unitClass)
5848 if(!_class.dataType)
5849 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5850 type = _class.dataType;
5858 float (*Get)(float) = (void *)prop.Get;
5859 GetFloat(exp.member.exp, &value);
5860 exp.constant = PrintFloat(Get ? Get(value) : value);
5861 exp.type = constantExp;
5867 double (*Get)(double);
5868 GetDouble(exp.member.exp, &value);
5871 Get = (void *)prop.Set;
5873 Get = (void *)prop.Get;
5874 exp.constant = PrintDouble(Get ? Get(value) : value);
5875 exp.type = constantExp;
5884 Expression value = exp.member.exp;
5887 ProcessPropertyType(prop);
5889 type = prop.dataType;
5892 // printf("Investigate this\n");
5894 else if(_class.type == structClass)
5900 Class propertyClass = type._class.registered;
5901 if(propertyClass.type == structClass && value.type == instanceExp)
5903 void (*Set)(void *, void *) = (void *)prop.Set;
5904 exp.instance = Instantiation { };
5905 exp.instance.data = new0 byte[_class.structSize];
5906 exp.instance._class = MkSpecifierName(_class.fullName);
5907 exp.instance.loc = exp.loc;
5908 exp.type = instanceExp;
5909 Set(exp.instance.data, value.instance.data);
5910 PopulateInstance(exp.instance);
5917 void (*Set)(void *, int) = (void *)prop.Set;
5919 exp.instance = Instantiation { };
5920 exp.instance.data = new0 byte[_class.structSize];
5921 exp.instance._class = MkSpecifierName(_class.fullName);
5922 exp.instance.loc = exp.loc;
5923 exp.type = instanceExp;
5925 GetInt(value, &intValue);
5927 Set(exp.instance.data, intValue);
5928 PopulateInstance(exp.instance);
5934 void (*Set)(void *, int64) = (void *)prop.Set;
5936 exp.instance = Instantiation { };
5937 exp.instance.data = new0 byte[_class.structSize];
5938 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5939 exp.instance.loc = exp.loc;
5940 exp.type = instanceExp;
5942 GetInt64(value, &intValue);
5944 Set(exp.instance.data, intValue);
5945 PopulateInstance(exp.instance);
5952 void (*Set)(void *, intptr) = (void *)prop.Set;
5954 exp.instance = Instantiation { };
5955 exp.instance.data = new0 byte[_class.structSize];
5956 exp.instance._class = MkSpecifierName(_class.fullName);
5957 exp.instance.loc = exp.loc;
5958 exp.type = instanceExp;
5960 GetIntPtr(value, &intValue);
5962 Set(exp.instance.data, intValue);
5963 PopulateInstance(exp.instance);
5970 void (*Set)(void *, intsize) = (void *)prop.Set;
5972 exp.instance = Instantiation { };
5973 exp.instance.data = new0 byte[_class.structSize];
5974 exp.instance._class = MkSpecifierName(_class.fullName);
5975 exp.instance.loc = exp.loc;
5976 exp.type = instanceExp;
5978 GetIntSize(value, &intValue);
5980 Set(exp.instance.data, intValue);
5981 PopulateInstance(exp.instance);
5987 void (*Set)(void *, float) = (void *)prop.Set;
5989 exp.instance = Instantiation { };
5990 exp.instance.data = new0 byte[_class.structSize];
5991 exp.instance._class = MkSpecifierName(_class.fullName);
5992 exp.instance.loc = exp.loc;
5993 exp.type = instanceExp;
5995 GetFloat(value, &floatValue);
5997 Set(exp.instance.data, floatValue);
5998 PopulateInstance(exp.instance);
6004 void (*Set)(void *, double) = (void *)prop.Set;
6006 exp.instance = Instantiation { };
6007 exp.instance.data = new0 byte[_class.structSize];
6008 exp.instance._class = MkSpecifierName(_class.fullName);
6009 exp.instance.loc = exp.loc;
6010 exp.type = instanceExp;
6012 GetDouble(value, &doubleValue);
6014 Set(exp.instance.data, doubleValue);
6015 PopulateInstance(exp.instance);
6020 else if(_class.type == bitClass)
6026 Class propertyClass = type._class.registered;
6027 if(propertyClass.type == structClass && value.instance.data)
6029 unsigned int (*Set)(void *) = (void *)prop.Set;
6030 unsigned int bits = Set(value.instance.data);
6031 exp.constant = PrintHexUInt(bits);
6032 exp.type = constantExp;
6035 else if(_class.type == bitClass)
6038 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6041 GetUInt(exp.member.exp, &value);
6043 exp.constant = PrintHexUInt(bits);
6044 exp.type = constantExp;
6052 if(_class.type == bitClass)
6055 GetUInt(exp.member.exp, &value);
6061 Class _class = type._class.registered;
6062 if(_class.type == structClass)
6064 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6066 exp.instance = Instantiation { };
6067 exp.instance.data = new0 byte[_class.structSize];
6068 exp.instance._class = MkSpecifierName(_class.fullName);
6069 exp.instance.loc = exp.loc;
6070 //exp.instance.fullSet = true;
6071 exp.type = instanceExp;
6072 Get(value, exp.instance.data);
6073 PopulateInstance(exp.instance);
6075 else if(_class.type == bitClass)
6077 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6078 uint64 bits = Get(value);
6079 exp.constant = PrintHexUInt64(bits);
6080 exp.type = constantExp;
6086 else if(_class.type == structClass)
6088 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6093 Class _class = type._class.registered;
6094 if(_class.type == structClass && value)
6096 void (*Get)(void *, void *) = (void *)prop.Get;
6098 exp.instance = Instantiation { };
6099 exp.instance.data = new0 byte[_class.structSize];
6100 exp.instance._class = MkSpecifierName(_class.fullName);
6101 exp.instance.loc = exp.loc;
6102 //exp.instance.fullSet = true;
6103 exp.type = instanceExp;
6104 Get(value, exp.instance.data);
6105 PopulateInstance(exp.instance);
6113 char * value = exp.member.exp.instance.data;
6118 Class _class = type._class.registered;
6119 if(_class.type == normalClass)
6121 void *(*Get)(void *) = (void *)prop.Get;
6123 exp.instance = Instantiation { };
6124 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6125 exp.type = instanceExp;
6126 exp.instance.data = Get(value, exp.instance.data);
6138 exp.isConstant = false;
6146 if(exp.type != ExpressionType::memberExp)
6148 FreeExpression(memberExp);
6149 FreeIdentifier(memberID);
6155 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6156 FreeExpContents(exp);
6157 exp.constant = PrintUInt(ComputeTypeSize(type));
6158 exp.type = constantExp;
6164 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6165 if(classSym && classSym.registered)
6167 if(classSym.registered.fixed)
6169 FreeSpecifier(exp._class);
6170 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6171 exp.type = constantExp;
6175 char className[1024];
6176 strcpy(className, "__ecereClass_");
6177 FullClassNameCat(className, classSym.string, true);
6178 //MangleClassName(className);
6180 DeclareClass(classSym, className);
6182 FreeExpContents(exp);
6183 exp.type = pointerExp;
6184 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6185 exp.member.member = MkIdentifier("structSize");
6195 if(exp.type == castExp)
6198 ComputeExpression(exp.cast.exp);
6201 if(e && exp.expType)
6204 type = exp.destType;
6207 if(type.kind == classType)
6209 Class _class = type._class.registered;
6210 if(_class && (_class.type == unitClass || _class.type == bitClass))
6212 if(!_class.dataType)
6213 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6214 type = _class.dataType;
6225 if(GetChar(e, &value))
6227 FreeExpContents(exp);
6228 exp.constant = PrintChar(value);
6229 exp.type = constantExp;
6234 unsigned char value = 0;
6235 if(GetUChar(e, &value))
6237 FreeExpContents(exp);
6238 exp.constant = PrintUChar(value);
6239 exp.type = constantExp;
6247 if(GetShort(e, &value))
6249 FreeExpContents(exp);
6250 exp.constant = PrintShort(value);
6251 exp.type = constantExp;
6256 unsigned short value = 0;
6257 if(GetUShort(e, &value))
6259 FreeExpContents(exp);
6260 exp.constant = PrintUShort(value);
6261 exp.type = constantExp;
6269 if(GetInt(e, &value))
6271 FreeExpContents(exp);
6272 exp.constant = PrintInt(value);
6273 exp.type = constantExp;
6278 unsigned int value = 0;
6279 if(GetUInt(e, &value))
6281 FreeExpContents(exp);
6282 exp.constant = PrintUInt(value);
6283 exp.type = constantExp;
6291 if(GetInt64(e, &value))
6293 FreeExpContents(exp);
6294 exp.constant = PrintInt64(value);
6295 exp.type = constantExp;
6301 if(GetUInt64(e, &value))
6303 FreeExpContents(exp);
6304 exp.constant = PrintUInt64(value);
6305 exp.type = constantExp;
6313 if(GetIntPtr(e, &value))
6315 FreeExpContents(exp);
6316 exp.constant = PrintInt64((int64)value);
6317 exp.type = constantExp;
6323 if(GetUIntPtr(e, &value))
6325 FreeExpContents(exp);
6326 exp.constant = PrintUInt64((uint64)value);
6327 exp.type = constantExp;
6335 if(GetIntSize(e, &value))
6337 FreeExpContents(exp);
6338 exp.constant = PrintInt64((int64)value);
6339 exp.type = constantExp;
6345 if(GetUIntSize(e, &value))
6347 FreeExpContents(exp);
6348 exp.constant = PrintUInt64((uint64)value);
6349 exp.type = constantExp;
6356 if(GetFloat(e, &value))
6358 FreeExpContents(exp);
6359 exp.constant = PrintFloat(value);
6360 exp.type = constantExp;
6367 if(GetDouble(e, &value))
6369 FreeExpContents(exp);
6370 exp.constant = PrintDouble(value);
6371 exp.type = constantExp;
6386 // Caring only about last expression for now...
6387 ComputeExpression(exp.cond.exp->last);
6388 if(exp.cond.elseExp)
6389 ComputeExpression(exp.cond.elseExp);
6391 ComputeExpression(exp.cond.cond);
6393 op1 = GetOperand(exp.cond.cond);
6394 if(op1.type) op1.type.refCount++;
6395 op2 = GetOperand(exp.cond.exp->last);
6396 if(op2.type) op2.type.refCount++;
6397 op3 = GetOperand(exp.cond.elseExp);
6398 if(op3.type) op3.type.refCount++;
6400 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6401 if(op1.type) FreeType(op1.type);
6402 if(op2.type) FreeType(op2.type);
6403 if(op3.type) FreeType(op3.type);
6409 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6414 OldList converts { };
6417 if(destType.kind == voidType)
6420 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6424 // for(convert = converts.last; convert; convert = convert.prev)
6425 for(convert = converts.first; convert; convert = convert.next)
6427 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6430 Expression newExp { };
6431 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6433 // TODO: Check this...
6437 newExp.destType = null;
6442 exp.type = memberExp;
6443 exp.addedThis = true;
6444 exp.member.exp = newExp;
6445 FreeType(exp.member.exp.expType);
6447 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6448 exp.member.exp.expType.classObjectType = objectType;
6449 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6450 exp.member.memberType = propertyMember;
6451 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6452 // TESTING THIS... for (int)degrees
6453 exp.needCast = true;
6454 if(exp.expType) exp.expType.refCount++;
6455 ApplyAnyObjectLogic(exp.member.exp);
6460 /*if(exp.isConstant)
6462 // Color { ColorRGB = [exp] };
6463 exp.type = instanceExp;
6464 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6465 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6466 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6470 // If not constant, don't turn it yet into an instantiation
6471 // (Go through the deep members system first)
6472 exp.type = memberExp;
6473 exp.addedThis = true;
6474 exp.member.exp = newExp;
6476 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6477 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6478 newExp.expType._class.registered.type == noHeadClass)
6480 newExp.byReference = true;
6483 FreeType(exp.member.exp.expType);
6484 /*exp.member.exp.expType = convert.convert.dataType;
6485 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6486 exp.member.exp.expType = null;
6487 if(convert.convert.dataType)
6489 exp.member.exp.expType = { };
6490 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6491 exp.member.exp.expType.refCount = 1;
6492 exp.member.exp.expType.classObjectType = objectType;
6493 ApplyAnyObjectLogic(exp.member.exp);
6496 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6497 exp.member.memberType = reverseConversionMember;
6498 exp.expType = convert.resultType ? convert.resultType :
6499 MkClassType(convert.convert._class.fullName);
6500 exp.needCast = true;
6501 if(convert.resultType) convert.resultType.refCount++;
6507 FreeType(exp.expType);
6510 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6511 if(exp.destType.casted)
6512 exp.needCast = true;
6513 if(exp.expType) exp.expType.refCount++;
6517 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6518 if(exp.destType.casted)
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 Expression nbExp = GetNonBracketsExp(exp);
6551 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6552 (nbExp == exp || nbExp.type != castExp))
6554 Expression newExp { };
6557 if(exp.destType) exp.destType.refCount++;
6558 if(exp.expType) exp.expType.refCount++;
6562 switch(exp.expType.kind)
6565 if(exp.destType.classObjectType)
6567 // We need to pass the address, just pass it along (Undo what was done above)
6568 if(exp.destType) exp.destType.refCount--;
6569 if(exp.expType) exp.expType.refCount--;
6574 // If we're looking for value:
6575 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6577 OldList * unionDefs = MkList();
6578 OldList * statements = MkList();
6579 context = PushContext();
6580 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6581 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6582 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6583 exp.type = extensionCompoundExp;
6584 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6585 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6586 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6587 exp.compound.compound.context = context;
6588 PopContext(context);
6593 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6594 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6595 exp.needCast = true;
6599 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6601 Expression newExp { };
6604 if(exp.destType) exp.destType.refCount++;
6605 if(exp.expType) exp.expType.refCount++;
6609 switch(exp.expType.kind)
6612 if(exp.destType.classObjectType)
6614 // We need to pass the address, just pass it along (Undo what was done above)
6615 if(exp.destType) exp.destType.refCount--;
6616 if(exp.expType) exp.expType.refCount--;
6621 // If we're looking for value:
6622 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6624 OldList * unionDefs = MkList();
6625 OldList * statements = MkList();
6626 context = PushContext();
6627 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6628 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6629 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6630 exp.type = extensionCompoundExp;
6631 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6632 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6633 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6634 exp.compound.compound.context = context;
6635 PopContext(context);
6640 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6642 exp.type = bracketsExp;
6643 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6644 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6645 ProcessExpressionType(exp.list->first);
6650 exp.type = bracketsExp;
6651 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6652 exp.needTemplateCast = 2;
6653 newExp.needCast = true;
6654 newExp.needTemplateCast = 2;
6655 ProcessExpressionType(exp.list->first);
6661 if(exp.expType.kind == templateType)
6663 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6666 FreeType(exp.destType);
6667 FreeType(exp.expType);
6672 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6677 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6678 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6682 char typeString[1024];
6684 OldList * specs = MkList();
6685 typeString[0] = '\0';
6686 PrintType(exp.expType, typeString, false, false);
6687 decl = SpecDeclFromString(typeString, specs, null);
6690 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6691 exp.cast.typeName = MkTypeName(specs, decl);
6692 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6693 exp.cast.exp.needCast = true;
6700 // TODO: The Symbol tree should be reorganized by namespaces
6702 // - Tree of all symbols within (stored without namespace)
6703 // - Tree of sub-namespaces
6705 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6707 int nsLen = strlen(nameSpace);
6709 // Start at the name space prefix
6710 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6712 char * s = symbol.string;
6713 if(!strncmp(s, nameSpace, nsLen))
6715 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6718 for(c = strlen(s)-1; c >= 0; c--)
6723 if(!strcmp(namePart, name))
6725 // TODO: Error on ambiguity
6735 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6738 char nameSpace[1024];
6739 const char * namePart;
6740 bool gotColon = false;
6742 nameSpace[0] = '\0';
6743 for(c = strlen(name)-1; c >= 0; c--)
6750 namePart = name+c+1;
6751 while(c >= 0 && name[c] == ':') c--;
6754 // Try an exact match first
6755 Symbol symbol = (Symbol)tree.FindString(name);
6759 // Namespace specified
6760 memcpy(nameSpace, name, c + 1);
6763 return ScanWithNameSpace(tree, nameSpace, namePart);
6767 // Looking for a global symbol, e.g. ::Sleep()
6768 Symbol symbol = (Symbol)tree.FindString(namePart);
6773 // Name only (no namespace specified)
6774 Symbol symbol = (Symbol)tree.FindString(namePart);
6777 return ScanWithNameSpace(tree, "", namePart);
6782 static void ProcessDeclaration(Declaration decl);
6784 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6787 //Time startTime = GetTime();
6789 // Optimize this later? Do this before/less?
6791 Symbol symbol = null;
6792 // First, check if the identifier is declared inside the function
6793 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6795 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6797 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6803 strcpy(curName, thisNameSpace);
6804 strcat(curName, "::");
6805 strcat(curName, name);
6806 // Try to resolve in current namespace first
6807 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6810 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6813 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6815 if(symbol || ctx == endContext) break;
6817 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6819 if(symbol.pointerExternal.type == functionExternal)
6821 FunctionDefinition function = symbol.pointerExternal.function;
6823 // Modified this recently...
6824 Context tmpContext = curContext;
6826 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6827 curContext = tmpContext;
6829 symbol.pointerExternal.symbol = symbol;
6832 DeclareType(symbol.type, true, true);
6834 ast->Insert(curExternal.prev, symbol.pointerExternal);
6836 symbol.id = curExternal.symbol.idCode;
6839 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6841 ast->Move(symbol.pointerExternal, curExternal.prev);
6842 symbol.id = curExternal.symbol.idCode;
6846 //findSymbolTotalTime += GetTime() - startTime;
6851 static void GetTypeSpecs(Type type, OldList * specs)
6853 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6858 if(type._class.registered)
6860 if(!type._class.registered.dataType)
6861 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6862 GetTypeSpecs(type._class.registered.dataType, specs);
6866 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6867 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6868 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6869 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6870 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6871 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6872 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6873 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6876 ListAdd(specs, MkSpecifier(INT)); break;
6880 static void PrintArraySize(Type arrayType, char * string)
6885 if(arrayType.enumClass)
6886 strcat(size, arrayType.enumClass.string);
6887 else if(arrayType.arraySizeExp)
6888 PrintExpression(arrayType.arraySizeExp, size);
6890 strcat(string, size);
6893 // WARNING : This function expects a null terminated string since it recursively concatenate...
6894 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6898 if(printConst && type.constant)
6899 strcat(string, "const ");
6904 Symbol c = type._class;
6905 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6906 // look into merging with thisclass ?
6907 if(type.classObjectType == typedObject)
6908 strcat(string, "typed_object");
6909 else if(type.classObjectType == anyObject)
6910 strcat(string, "any_object");
6914 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6916 if(type.byReference)
6917 strcat(string, " &");
6920 case voidType: strcat(string, "void"); break;
6921 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6922 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6923 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6924 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6925 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6926 case _BoolType: strcat(string, "_Bool"); break;
6927 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6928 case floatType: strcat(string, "float"); break;
6929 case doubleType: strcat(string, "double"); break;
6933 strcat(string, "struct ");
6934 strcat(string, type.enumName);
6936 else if(type.typeName)
6937 strcat(string, type.typeName);
6941 strcat(string, "struct { ");
6942 for(member = type.members.first; member; member = member.next)
6944 PrintType(member, string, true, fullName);
6945 strcat(string,"; ");
6953 strcat(string, "union ");
6954 strcat(string, type.enumName);
6956 else if(type.typeName)
6957 strcat(string, type.typeName);
6960 strcat(string, "union ");
6961 strcat(string,"(unnamed)");
6967 strcat(string, "enum ");
6968 strcat(string, type.enumName);
6970 else if(type.typeName)
6971 strcat(string, type.typeName);
6973 strcat(string, "int"); // "enum");
6976 strcat(string, "...");
6979 strcat(string, "subclass(");
6980 strcat(string, type._class ? type._class.string : "int");
6981 strcat(string, ")");
6984 strcat(string, type.templateParameter.identifier.string);
6987 strcat(string, "thisclass");
6990 strcat(string, "__builtin_va_list");
6996 static void PrintName(Type type, char * string, bool fullName)
6998 if(type.name && type.name[0])
7001 strcat(string, type.name);
7004 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7005 if(name) name += 2; else name = type.name;
7006 strcat(string, name);
7011 static void PrintAttribs(Type type, char * string)
7015 if(type.dllExport) strcat(string, "dllexport ");
7016 if(type.attrStdcall) strcat(string, "stdcall ");
7020 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7022 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7024 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7025 PrintAttribs(type, string);
7026 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7027 strcat(string, " const");
7028 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7029 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7030 strcat(string, " (");
7031 if(type.kind == pointerType)
7033 if(type.type.kind == functionType || type.type.kind == methodType)
7034 PrintAttribs(type.type, string);
7036 if(type.kind == pointerType)
7038 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7039 strcat(string, "*");
7041 strcat(string, " *");
7043 if(printConst && type.constant && type.kind == pointerType)
7044 strcat(string, " const");
7047 PrintTypeSpecs(type, string, fullName, printConst);
7050 static void PostPrintType(Type type, char * string, bool fullName)
7052 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7053 strcat(string, ")");
7054 if(type.kind == arrayType)
7055 PrintArraySize(type, string);
7056 else if(type.kind == functionType)
7059 strcat(string, "(");
7060 for(param = type.params.first; param; param = param.next)
7062 PrintType(param, string, true, fullName);
7063 if(param.next) strcat(string, ", ");
7065 strcat(string, ")");
7067 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7068 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7072 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7074 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7076 PrePrintType(type, string, fullName, null, printConst);
7078 if(type.thisClass || (printName && type.name && type.name[0]))
7079 strcat(string, " ");
7080 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7082 Symbol _class = type.thisClass;
7083 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7085 if(type.classObjectType == classPointer)
7086 strcat(string, "class");
7088 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7090 else if(_class && _class.string)
7092 String s = _class.string;
7097 char * name = RSearchString(s, "::", strlen(s), true, false);
7098 if(name) name += 2; else name = s;
7099 strcat(string, name);
7102 strcat(string, "::");
7105 if(printName && type.name)
7106 PrintName(type, string, fullName);
7107 PostPrintType(type, string, fullName);
7108 if(type.bitFieldCount)
7111 sprintf(count, ":%d", type.bitFieldCount);
7112 strcat(string, count);
7116 void PrintType(Type type, char * string, bool printName, bool fullName)
7118 _PrintType(type, string, printName, fullName, true);
7121 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7123 _PrintType(type, string, printName, fullName, false);
7126 static Type FindMember(Type type, char * string)
7129 for(memberType = type.members.first; memberType; memberType = memberType.next)
7131 if(!memberType.name)
7133 Type subType = FindMember(memberType, string);
7137 else if(!strcmp(memberType.name, string))
7143 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7146 for(memberType = type.members.first; memberType; memberType = memberType.next)
7148 if(!memberType.name)
7150 Type subType = FindMember(memberType, string);
7153 *offset += memberType.offset;
7157 else if(!strcmp(memberType.name, string))
7159 *offset += memberType.offset;
7166 public bool GetParseError() { return parseError; }
7168 Expression ParseExpressionString(char * expression)
7172 fileInput = TempFile { };
7173 fileInput.Write(expression, 1, strlen(expression));
7174 fileInput.Seek(0, start);
7177 parsedExpression = null;
7179 expression_yyparse();
7182 return parsedExpression;
7185 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7187 Identifier id = exp.identifier;
7188 Method method = null;
7189 Property prop = null;
7190 DataMember member = null;
7191 ClassProperty classProp = null;
7193 if(_class && _class.type == enumClass)
7195 NamedLink value = null;
7196 Class enumClass = eSystem_FindClass(privateModule, "enum");
7200 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7202 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7203 for(value = e.values.first; value; value = value.next)
7205 if(!strcmp(value.name, id.string))
7212 FreeExpContents(exp);
7214 exp.type = constantExp;
7215 exp.isConstant = true;
7216 if(!strcmp(baseClass.dataTypeString, "int"))
7217 sprintf(constant, "%d",(int)value.data);
7219 sprintf(constant, "0x%X",(int)value.data);
7220 exp.constant = CopyString(constant);
7221 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7222 exp.expType = MkClassType(baseClass.fullName);
7230 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7232 ProcessMethodType(method);
7239 // TOCHECK: Put it back to what it was...
7240 // methodClass = _class;
7241 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7246 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7249 ProcessPropertyType(prop);
7250 exp.expType = prop.dataType;
7251 if(prop.dataType) prop.dataType.refCount++;
7254 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7256 if(!member.dataType)
7257 member.dataType = ProcessTypeString(member.dataTypeString, false);
7258 exp.expType = member.dataType;
7259 if(member.dataType) member.dataType.refCount++;
7262 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7264 if(!classProp.dataType)
7265 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7267 if(classProp.constant)
7269 FreeExpContents(exp);
7271 exp.isConstant = true;
7272 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7274 //char constant[256];
7275 exp.type = stringExp;
7276 exp.constant = QMkString((char *)classProp.Get(_class));
7281 exp.type = constantExp;
7282 sprintf(constant, "%d", (int)classProp.Get(_class));
7283 exp.constant = CopyString(constant);
7291 exp.expType = classProp.dataType;
7292 if(classProp.dataType) classProp.dataType.refCount++;
7298 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7300 BinaryTree * tree = &nameSpace.functions;
7301 GlobalData data = (GlobalData)tree->FindString(name);
7305 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7307 data = ScanGlobalData(child, name);
7315 static GlobalData FindGlobalData(char * name)
7318 NameSpace * nameSpace;
7319 nameSpace = globalData;
7320 for(c = 0; name[c]; c++)
7322 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7324 NameSpace * newSpace;
7325 char * spaceName = new char[c - start + 1];
7326 strncpy(spaceName, name + start, c - start);
7327 spaceName[c-start] = '\0';
7328 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7332 nameSpace = newSpace;
7333 if(name[c] == ':') c++;
7339 return ScanGlobalData(nameSpace, name + start);
7344 static int definedExpStackPos;
7345 static void * definedExpStack[512];
7347 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7348 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7350 Expression prev = checkedExp.prev, next = checkedExp.next;
7352 FreeExpContents(checkedExp);
7353 FreeType(checkedExp.expType);
7354 FreeType(checkedExp.destType);
7356 *checkedExp = *newExp;
7360 checkedExp.prev = prev;
7361 checkedExp.next = next;
7364 void ApplyAnyObjectLogic(Expression e)
7366 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7368 char debugExpString[4096];
7369 debugExpString[0] = '\0';
7370 PrintExpression(e, debugExpString);
7373 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7375 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7376 //ellipsisDestType = destType;
7379 Type type = e.expType;
7380 Class _class = null;
7381 //Type destType = e.destType;
7383 if(type.kind == classType && type._class && type._class.registered)
7385 _class = type._class.registered;
7387 else if(type.kind == subClassType)
7389 _class = FindClass("ecere::com::Class").registered;
7393 char string[1024] = "";
7396 PrintTypeNoConst(type, string, false, true);
7397 classSym = FindClass(string);
7398 if(classSym) _class = classSym.registered;
7401 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...
7402 (!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))) ||
7403 destType.byReference)))
7405 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7407 Expression checkedExp = e, newExp;
7409 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7411 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7413 if(checkedExp.type == extensionCompoundExp)
7415 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7418 checkedExp = checkedExp.list->last;
7420 else if(checkedExp.type == castExp)
7421 checkedExp = checkedExp.cast.exp;
7424 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7426 newExp = checkedExp.op.exp2;
7427 checkedExp.op.exp2 = null;
7428 FreeExpContents(checkedExp);
7430 if(e.expType && e.expType.passAsTemplate)
7433 ComputeTypeSize(e.expType);
7434 sprintf(size, "%d", e.expType.size);
7435 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7436 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7437 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7440 ReplaceExpContents(checkedExp, newExp);
7441 e.byReference = true;
7443 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7445 Expression checkedExp; //, newExp;
7448 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7450 e.type == identifierExp ||
7451 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7452 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7453 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7456 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7458 Context context = PushContext();
7460 OldList * specs = MkList();
7461 char typeString[1024];
7462 Expression newExp { };
7464 typeString[0] = '\0';
7467 //if(e.destType) e.destType.refCount++;
7468 // if(exp.expType) exp.expType.refCount++;
7471 newExp.expType = null;
7473 PrintTypeNoConst(e.expType, typeString, false, true);
7474 decl = SpecDeclFromString(typeString, specs, null);
7475 newExp.destType = ProcessType(specs, decl);
7477 curContext = context;
7479 // We need a current compound for this
7483 OldList * stmts = MkList();
7484 e.type = extensionCompoundExp;
7485 sprintf(name, "__internalValue%03X", internalValueCounter++);
7486 if(!curCompound.compound.declarations)
7487 curCompound.compound.declarations = MkList();
7488 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7489 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7490 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7491 e.compound = MkCompoundStmt(null, stmts);
7494 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7497 e.compound = MkCompoundStmt(
7498 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7499 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7501 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7505 Type type = e.destType;
7507 CopyTypeInto(e.destType, type);
7508 e.destType.refCount = 1;
7509 e.destType.classObjectType = none;
7513 e.compound.compound.context = context;
7514 PopContext(context);
7515 curContext = context.parent;
7519 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7521 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7523 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7525 if(checkedExp.type == extensionCompoundExp)
7527 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7530 checkedExp = checkedExp.list->last;
7532 else if(checkedExp.type == castExp)
7533 checkedExp = checkedExp.cast.exp;
7536 Expression operand { };
7537 operand = *checkedExp;
7538 checkedExp.destType = null;
7539 checkedExp.expType = null;
7541 checkedExp.type = opExp;
7542 checkedExp.op.op = '&';
7543 checkedExp.op.exp1 = null;
7544 checkedExp.op.exp2 = operand;
7546 //newExp = MkExpOp(null, '&', checkedExp);
7548 //ReplaceExpContents(checkedExp, newExp);
7555 // If expression type is a simple class, make it an address
7556 // FixReference(e, true);
7559 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7560 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7561 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7563 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"))
7565 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7569 Expression thisExp { };
7572 thisExp.prev = null;
7573 thisExp.next = null;
7576 e.type = bracketsExp;
7577 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7578 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7579 ((Expression)e.list->first).byReference = true;
7581 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7583 e.expType = thisExp.expType;
7584 e.expType.refCount++;
7589 CopyTypeInto(e.expType, thisExp.expType);
7590 e.expType.byReference = false;
7591 e.expType.refCount = 1;
7593 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7594 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7596 e.expType.classObjectType = none;
7601 // TOFIX: Try this for a nice IDE crash!
7603 // The other way around
7606 if(destType && e.expType &&
7607 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7608 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7609 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7611 if(destType.kind == ellipsisType)
7613 Compiler_Error($"Unspecified type\n");
7615 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7617 bool byReference = e.expType.byReference;
7618 Expression thisExp { };
7620 OldList * specs = MkList();
7621 char typeString[1024]; // Watch buffer overruns
7623 ClassObjectType backupClassObjectType;
7624 bool backupByReference;
7626 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7631 backupClassObjectType = type.classObjectType;
7632 backupByReference = type.byReference;
7634 type.classObjectType = none;
7635 type.byReference = false;
7637 typeString[0] = '\0';
7638 PrintType(type, typeString, false, true);
7639 decl = SpecDeclFromString(typeString, specs, null);
7641 type.classObjectType = backupClassObjectType;
7642 type.byReference = backupByReference;
7645 thisExp.prev = null;
7646 thisExp.next = null;
7649 if( ( type.kind == classType && type._class && type._class.registered &&
7650 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7651 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7652 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7653 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7658 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7661 CopyTypeInto(e.expType, type);
7662 e.expType.byReference = false;
7663 e.expType.refCount = 1;
7668 e.cast.typeName = MkTypeName(specs, decl);
7669 e.cast.exp = thisExp;
7670 e.byReference = true;
7674 e.destType = destType;
7675 destType.refCount++;
7680 void ApplyLocation(Expression exp, Location loc)
7686 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7687 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7693 for(e = exp.list->first; e; e = e.next)
7694 ApplyLocation(e, loc);
7701 for(e = exp.index.index->first; e; e = e.next)
7702 ApplyLocation(e, loc);
7705 ApplyLocation(exp.index.exp, loc);
7708 if(exp.call.arguments)
7711 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7712 ApplyLocation(arg, loc);
7715 ApplyLocation(exp.call.exp, loc);
7720 ApplyLocation(exp.member.exp, loc);
7724 ApplyLocation(exp.cast.exp, loc);
7730 for(e = exp.cond.exp->first; e; e = e.next)
7731 ApplyLocation(e, loc);
7734 ApplyLocation(exp.cond.cond, loc);
7735 if(exp.cond.elseExp)
7736 ApplyLocation(exp.cond.elseExp, loc);
7740 ApplyLocation(exp.vaArg.exp, loc);
7747 void ProcessExpressionType(Expression exp)
7749 bool unresolved = false;
7750 Location oldyylloc = yylloc;
7751 bool notByReference = false;
7753 char debugExpString[4096];
7754 debugExpString[0] = '\0';
7755 PrintExpression(exp, debugExpString);
7757 if(!exp || exp.expType)
7760 //eSystem_Logf("%s\n", expString);
7762 // Testing this here
7768 Identifier id = exp.identifier;
7769 if(!id || !topContext) return;
7771 // DOING THIS LATER NOW...
7772 if(id._class && id._class.name)
7774 id.classSym = id._class.symbol; // FindClass(id._class.name);
7775 /* TODO: Name Space Fix ups
7777 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7781 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7783 exp.expType = ProcessTypeString("Module", true);
7786 else */if(strstr(id.string, "__ecereClass") == id.string)
7788 exp.expType = ProcessTypeString("ecere::com::Class", true);
7791 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7793 // Added this here as well
7794 ReplaceClassMembers(exp, thisClass);
7795 if(exp.type != identifierExp)
7797 ProcessExpressionType(exp);
7801 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7806 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7807 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7808 if(!symbol/* && exp.destType*/)
7810 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7816 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7817 if(exp.type != identifierExp)
7819 ProcessExpressionType(exp);
7823 // Static methods called from inside the _class
7824 else if(currentClass && !id._class)
7826 if(ResolveIdWithClass(exp, currentClass, true))
7829 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7833 // If we manage to resolve this symbol
7836 Type type = symbol.type;
7837 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7839 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7841 Context context = SetupTemplatesContext(_class);
7842 type = ReplaceThisClassType(_class);
7843 FinishTemplatesContext(context);
7844 if(type) type.refCount = 0; // We'll be incrementing it right below...
7847 FreeSpecifier(id._class);
7850 id.string = CopyString(symbol.string);
7857 // Commented this out, it was making non-constant enum parameters seen as constant
7858 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7859 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7860 // Add missing cases here... enum Classes...
7861 exp.isConstant = true;
7863 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7864 if(symbol.isParam || !strcmp(id.string, "this"))
7866 if(_class && _class.type == structClass && !type.declaredWithStruct)
7867 exp.byReference = true;
7869 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7870 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7871 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7872 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7874 Identifier id = exp.identifier;
7875 exp.type = bracketsExp;
7876 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7880 if(symbol.isIterator)
7882 if(symbol.isIterator == 3)
7884 exp.type = bracketsExp;
7885 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7886 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7888 ProcessExpressionType(exp);
7890 else if(symbol.isIterator != 4)
7892 exp.type = memberExp;
7893 exp.member.exp = MkExpIdentifier(exp.identifier);
7894 exp.member.exp.expType = exp.expType;
7895 /*if(symbol.isIterator == 6)
7896 exp.member.member = MkIdentifier("key");
7898 exp.member.member = MkIdentifier("data");
7900 ProcessExpressionType(exp);
7907 DefinedExpression definedExp = null;
7908 if(thisNameSpace && !(id._class && !id._class.name))
7911 strcpy(name, thisNameSpace);
7913 strcat(name, id.string);
7914 definedExp = eSystem_FindDefine(privateModule, name);
7917 definedExp = eSystem_FindDefine(privateModule, id.string);
7921 for(c = 0; c<definedExpStackPos; c++)
7922 if(definedExpStack[c] == definedExp)
7924 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7926 Location backupYylloc = yylloc;
7927 File backInput = fileInput;
7928 definedExpStack[definedExpStackPos++] = definedExp;
7930 fileInput = TempFile { };
7931 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7932 fileInput.Seek(0, start);
7935 parsedExpression = null;
7937 expression_yyparse();
7940 fileInput = backInput;
7942 yylloc = backupYylloc;
7944 if(parsedExpression)
7947 exp.type = bracketsExp;
7948 exp.list = MkListOne(parsedExpression);
7949 ApplyLocation(parsedExpression, yylloc);
7950 ProcessExpressionType(exp);
7951 definedExpStackPos--;
7954 definedExpStackPos--;
7960 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7966 GlobalData data = null;
7967 if(thisNameSpace && !(id._class && !id._class.name))
7970 strcpy(name, thisNameSpace);
7972 strcat(name, id.string);
7973 data = FindGlobalData(name);
7976 data = FindGlobalData(id.string);
7979 DeclareGlobalData(data);
7980 exp.expType = data.dataType;
7981 if(data.dataType) data.dataType.refCount++;
7984 id.string = CopyString(data.fullName);
7985 FreeSpecifier(id._class);
7992 GlobalFunction function = null;
7993 if(thisNameSpace && !(id._class && !id._class.name))
7996 strcpy(name, thisNameSpace);
7998 strcat(name, id.string);
7999 function = eSystem_FindFunction(privateModule, name);
8002 function = eSystem_FindFunction(privateModule, id.string);
8007 id.string = CopyString(function.name);
8010 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8011 strcpy(name, "__ecereFunction_");
8012 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8013 if(DeclareFunction(function, name))
8016 id.string = CopyString(name);
8018 exp.expType = function.dataType;
8019 if(function.dataType) function.dataType.refCount++;
8021 FreeSpecifier(id._class);
8038 if(!exp.instance._class)
8040 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8042 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8046 //classSym = FindClass(exp.instance._class.fullName);
8047 //_class = classSym ? classSym.registered : null;
8049 ProcessInstantiationType(exp.instance);
8051 exp.isConstant = exp.instance.isConstant;
8054 if(_class.type == unitClass && _class.base.type != systemClass)
8057 Type destType = exp.destType;
8059 exp.destType = MkClassType(_class.base.fullName);
8060 exp.expType = MkClassType(_class.fullName);
8061 CheckExpressionType(exp, exp.destType, true);
8063 exp.destType = destType;
8065 exp.expType = MkClassType(_class.fullName);
8068 if(exp.instance._class)
8070 exp.expType = MkClassType(exp.instance._class.name);
8071 /*if(exp.expType._class && exp.expType._class.registered &&
8072 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8073 exp.expType.byReference = true;*/
8081 char * constant = exp.constant;
8089 if(constant[0] == '\'')
8091 if((int)((byte *)constant)[1] > 127)
8094 unichar ch = UTF8GetChar(constant + 1, &nb);
8095 if(nb < 2) ch = constant[1];
8097 exp.constant = PrintUInt(ch);
8098 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8099 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8100 type._class = FindClass("unichar");
8102 type.isSigned = false;
8106 type.kind = charType;
8107 type.isSigned = true;
8112 char * dot = strchr(constant, '.');
8113 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8117 exponent = strchr(constant, 'p');
8118 if(!exponent) exponent = strchr(constant, 'P');
8122 exponent = strchr(constant, 'e');
8123 if(!exponent) exponent = strchr(constant, 'E');
8128 if(strchr(constant, 'f') || strchr(constant, 'F'))
8129 type.kind = floatType;
8131 type.kind = doubleType;
8132 type.isSigned = true;
8136 bool isSigned = constant[0] == '-';
8138 int64 i64 = strtoll(constant, &endP, 0);
8139 uint64 ui64 = strtoull(constant, &endP, 0);
8140 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8153 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8157 else if(constant[0] != '0' || !constant[1])
8160 type.kind = is64Bit ? int64Type : intType;
8161 type.isSigned = isSigned;
8164 exp.isConstant = true;
8165 if(exp.destType && exp.destType.kind == doubleType)
8166 type.kind = doubleType;
8167 else if(exp.destType && exp.destType.kind == floatType)
8168 type.kind = floatType;
8169 else if(exp.destType && exp.destType.kind == int64Type)
8170 type.kind = int64Type;
8176 exp.isConstant = true; // Why wasn't this constant?
8193 ProcessExpressionType(exp._new.size);
8198 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8200 DeclareType(exp.expType.type, false, false);
8204 ProcessExpressionType(exp._renew.size);
8205 ProcessExpressionType(exp._renew.exp);
8210 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8212 DeclareType(exp.expType.type, false, false);
8216 bool assign = false, boolResult = false, boolOps = false;
8217 Type type1 = null, type2 = null;
8218 bool useDestType = false, useSideType = false;
8219 Location oldyylloc = yylloc;
8220 bool useSideUnit = false;
8221 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8223 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8232 // Assignment Operators
8246 // boolean Operators
8248 // Expect boolean operators
8250 //boolResult = true;
8254 // Expect boolean operands
8265 // Gives boolean result
8297 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8303 /*// Implement speed etc.
8309 if(exp.op.op == '&')
8311 // Added this here earlier for Iterator address as key
8312 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8314 Identifier id = exp.op.exp2.identifier;
8315 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8316 if(symbol && symbol.isIterator == 2)
8318 exp.type = memberExp;
8319 exp.member.exp = exp.op.exp2;
8320 exp.member.member = MkIdentifier("key");
8322 exp.op.exp2.expType = symbol.type;
8323 symbol.type.refCount++;
8324 ProcessExpressionType(exp);
8328 // exp.op.exp2.usage.usageRef = true;
8332 //dummy.kind = TypeDummy;
8335 // Added this check here to use the dest type only for units derived from the base unit
8336 // So that untyped units will use the side unit as opposed to the untyped destination unit
8337 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8338 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8339 useDestType = false;
8341 if(destClass && useDestType &&
8342 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8344 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8346 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8347 exp.op.exp1.destType = exp.destType;
8348 exp.op.exp1.opDestType = true;
8350 exp.destType.refCount++;
8354 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8355 exp.op.exp1.destType = dummy;
8359 // TESTING THIS HERE...
8360 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8361 ProcessExpressionType(exp.op.exp1);
8362 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8364 exp.op.exp1.opDestType = false;
8366 // Fix for unit and ++ / --
8367 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8368 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8370 exp.op.exp2 = MkExpConstant("1");
8371 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8375 if(exp.op.exp1.destType == dummy)
8378 exp.op.exp1.destType = null;
8380 type1 = exp.op.exp1.expType;
8385 char expString[10240];
8386 expString[0] = '\0';
8387 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8391 exp.op.exp2.destType = exp.op.exp1.expType;
8392 if(exp.op.exp1.expType)
8393 exp.op.exp1.expType.refCount++;
8397 exp.op.exp2.destType = exp.destType;
8398 if(!exp.op.exp1 || exp.op.op != '&')
8399 exp.op.exp2.opDestType = true;
8401 exp.destType.refCount++;
8404 if(type1) type1.refCount++;
8405 exp.expType = type1;
8410 PrintExpression(exp.op.exp2, expString);
8412 if(type1 && type1.kind == pointerType)
8414 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 ||
8415 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8416 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8417 else if(exp.op.op == '=')
8419 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8420 exp.op.exp2.destType = type1;
8427 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8428 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/* ||
8429 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8432 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8433 exp.op.exp2.destType = type1;
8438 if(type1) type1.refCount++;
8439 exp.expType = type1;
8441 else if(destClass &&
8442 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8443 (destClass.type == enumClass && useDestType)))
8445 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8446 exp.op.exp2.destType = exp.destType;
8447 if(exp.op.op != '&')
8448 exp.op.exp2.opDestType = true;
8450 exp.destType.refCount++;
8454 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8455 exp.op.exp2.destType = dummy;
8459 // TESTING THIS HERE... (DANGEROUS)
8460 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8461 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8463 FreeType(exp.op.exp2.destType);
8464 exp.op.exp2.destType = type1;
8467 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8468 // Cannot lose the cast on a sizeof
8469 if(exp.op.op == SIZEOF)
8471 Expression e = exp.op.exp2;
8472 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8474 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8476 if(e.type == extensionCompoundExp)
8477 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8482 if(e.type == castExp && e.cast.exp)
8483 e.cast.exp.needCast = true;
8485 ProcessExpressionType(exp.op.exp2);
8486 exp.op.exp2.opDestType = false;
8487 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8489 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8491 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)
8493 if(exp.op.op != '=' && type1.type.kind == voidType)
8494 Compiler_Error($"void *: unknown size\n");
8496 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||
8497 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8498 (exp.op.exp2.expType._class.registered.type == normalClass ||
8499 exp.op.exp2.expType._class.registered.type == structClass ||
8500 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8502 if(exp.op.op == ADD_ASSIGN)
8503 Compiler_Error($"cannot add two pointers\n");
8505 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8506 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8508 if(exp.op.op == ADD_ASSIGN)
8509 Compiler_Error($"cannot add two pointers\n");
8513 char type1String[1024];
8514 char type2String[1024];
8515 type1String[0] = '\0';
8516 type2String[0] = '\0';
8518 PrintType(exp.op.exp2.expType, type1String, false, true);
8519 PrintType(type1, type2String, false, true);
8520 ChangeCh(expString, '\n', ' ');
8521 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8525 if(exp.op.exp2.destType == dummy)
8528 exp.op.exp2.destType = null;
8531 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8535 CopyTypeInto(type2, exp.op.exp2.expType);
8536 type2.isSigned = true;
8538 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8540 type2 = { kind = intType };
8542 type2.isSigned = true;
8546 type2 = exp.op.exp2.expType;
8547 if(type2) type2.refCount++;
8551 dummy.kind = voidType;
8553 if(exp.op.op == SIZEOF)
8560 exp.isConstant = true;
8562 // Get type of dereferenced pointer
8563 else if(exp.op.op == '*' && !exp.op.exp1)
8565 exp.expType = Dereference(type2);
8566 if(type2 && type2.kind == classType)
8567 notByReference = true;
8569 else if(exp.op.op == '&' && !exp.op.exp1)
8570 exp.expType = Reference(type2);
8577 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8578 exp.op.exp1.destType = MkClassType("bool");
8579 exp.op.exp1.destType.truth = true;
8580 if(!exp.op.exp1.expType)
8581 ProcessExpressionType(exp.op.exp1);
8583 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8584 FreeType(exp.op.exp1.expType);
8585 exp.op.exp1.expType = MkClassType("bool");
8586 exp.op.exp1.expType.truth = true;
8590 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8591 exp.op.exp2.destType = MkClassType("bool");
8592 exp.op.exp2.destType.truth = true;
8593 if(!exp.op.exp2.expType)
8594 ProcessExpressionType(exp.op.exp2);
8596 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8597 FreeType(exp.op.exp2.expType);
8598 exp.op.exp2.expType = MkClassType("bool");
8599 exp.op.exp2.expType.truth = true;
8602 else if(exp.op.exp1 && exp.op.exp2 &&
8605 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8606 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8607 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8608 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8610 if(type1 && type2 &&
8611 // If either both are class or both are not class
8612 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8614 // Added this check for enum subtraction to result in an int type:
8615 if(exp.op.op == '-' &&
8616 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8617 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8620 if(!type1._class.registered.dataType)
8621 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8622 if(!type2._class.registered.dataType)
8623 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8625 intType = ProcessTypeString(
8626 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8628 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8629 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8630 exp.op.exp1.destType = intType;
8631 exp.op.exp2.destType = intType;
8636 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8637 exp.op.exp2.destType = type1;
8639 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8640 exp.op.exp1.destType = type2;
8644 // Warning here for adding Radians + Degrees with no destination type
8645 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8646 type1._class.registered && type1._class.registered.type == unitClass &&
8647 type2._class.registered && type2._class.registered.type == unitClass &&
8648 type1._class.registered != type2._class.registered)
8649 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8650 type1._class.string, type2._class.string, type1._class.string);
8652 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8654 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8657 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8659 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8660 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8663 ProcessExpressionType(exp.op.exp1);
8665 if(type2.kind != pointerType)
8667 ProcessExpressionType(classExp);
8669 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8671 if(!exp.op.exp2.expType)
8675 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8679 ProcessExpressionType(exp.op.exp2);
8684 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)))
8686 if(type1.kind != classType && type1.type.kind == voidType)
8687 Compiler_Error($"void *: unknown size\n");
8688 exp.expType = type1;
8689 if(type1) type1.refCount++;
8691 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)))
8693 if(type2.kind != classType && type2.type.kind == voidType)
8694 Compiler_Error($"void *: unknown size\n");
8695 exp.expType = type2;
8696 if(type2) type2.refCount++;
8698 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8699 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8701 Compiler_Warning($"different levels of indirection\n");
8705 bool success = false;
8706 if(type1.kind == pointerType && type2.kind == pointerType)
8708 if(exp.op.op == '+')
8709 Compiler_Error($"cannot add two pointers\n");
8710 else if(exp.op.op == '-')
8712 // Pointer Subtraction gives integer
8713 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8722 if(type1.type.kind == templateType)
8724 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8727 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8729 ProcessExpressionType(classExp);
8731 exp.type = bracketsExp;
8732 exp.list = MkListOne(MkExpOp(
8733 MkExpBrackets(MkListOne(MkExpOp(
8734 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8736 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8737 MkExpMember(classExp, MkIdentifier("typeSize"))));
8739 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8748 if(!success && exp.op.exp1.type == constantExp)
8750 // If first expression is constant, try to match that first
8751 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8753 if(exp.expType) FreeType(exp.expType);
8754 exp.expType = exp.op.exp1.destType;
8755 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8758 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8760 if(exp.expType) FreeType(exp.expType);
8761 exp.expType = exp.op.exp2.destType;
8762 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8768 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8770 if(exp.expType) FreeType(exp.expType);
8771 exp.expType = exp.op.exp2.destType;
8772 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8775 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8777 if(exp.expType) FreeType(exp.expType);
8778 exp.expType = exp.op.exp1.destType;
8779 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8785 char expString1[10240];
8786 char expString2[10240];
8789 expString1[0] = '\0';
8790 expString2[0] = '\0';
8795 PrintExpression(exp.op.exp1, expString1);
8796 ChangeCh(expString1, '\n', ' ');
8797 PrintExpression(exp.op.exp2, expString2);
8798 ChangeCh(expString2, '\n', ' ');
8799 PrintType(exp.op.exp1.expType, type1, false, true);
8800 PrintType(exp.op.exp2.expType, type2, false, true);
8803 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8807 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8808 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8810 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8811 // Convert e.g. / 4 into / 4.0
8812 exp.op.exp1.destType = type2._class.registered.dataType;
8813 if(type2._class.registered.dataType)
8814 type2._class.registered.dataType.refCount++;
8815 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8816 exp.expType = type2;
8817 if(type2) type2.refCount++;
8819 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8821 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8822 // Convert e.g. / 4 into / 4.0
8823 exp.op.exp2.destType = type1._class.registered.dataType;
8824 if(type1._class.registered.dataType)
8825 type1._class.registered.dataType.refCount++;
8826 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8827 exp.expType = type1;
8828 if(type1) type1.refCount++;
8834 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8836 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8838 if(!type1._class.registered.dataType)
8839 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8840 exp.op.exp2.destType = type1._class.registered.dataType;
8841 exp.op.exp2.destType.refCount++;
8843 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8846 type2 = exp.op.exp2.destType;
8847 if(type2) type2.refCount++;
8849 exp.expType = type2;
8853 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8855 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8857 if(!type2._class.registered.dataType)
8858 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8859 exp.op.exp1.destType = type2._class.registered.dataType;
8860 exp.op.exp1.destType.refCount++;
8862 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8863 type1 = exp.op.exp1.destType;
8864 exp.expType = type1;
8868 // TESTING THIS NEW CODE
8869 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8871 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8872 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8873 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8875 // Convert the enum to an int instead for these operators
8876 if(op1IsEnum && exp.op.exp2.expType)
8878 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8880 if(exp.expType) FreeType(exp.expType);
8881 exp.expType = exp.op.exp2.expType;
8882 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8886 else if(op2IsEnum && exp.op.exp1.expType)
8888 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8890 if(exp.expType) FreeType(exp.expType);
8891 exp.expType = exp.op.exp1.expType;
8892 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8899 if(op1IsEnum && exp.op.exp2.expType)
8901 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8903 if(exp.expType) FreeType(exp.expType);
8904 exp.expType = exp.op.exp1.expType;
8905 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8909 else if(op2IsEnum && exp.op.exp1.expType)
8911 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8913 if(exp.expType) FreeType(exp.expType);
8914 exp.expType = exp.op.exp2.expType;
8915 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8924 // 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
8925 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8926 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8928 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8929 exp.op.exp1.destType = type2;
8932 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8934 if(exp.expType) FreeType(exp.expType);
8935 exp.expType = exp.op.exp1.destType;
8936 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8941 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8942 exp.op.exp2.destType = type1;
8946 // Maybe this was meant to be an enum...
8947 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8949 Type oldType = exp.op.exp2.expType;
8950 exp.op.exp2.expType = null;
8951 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8954 exp.op.exp2.expType = oldType;
8959 // TESTING THIS HERE... LATEST ADDITION
8960 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8962 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8963 exp.op.exp2.destType = type2._class.registered.dataType;
8964 if(type2._class.registered.dataType)
8965 type2._class.registered.dataType.refCount++;
8966 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8968 //exp.expType = type2._class.registered.dataType; //type2;
8969 //if(type2) type2.refCount++;
8972 // TESTING THIS HERE... LATEST ADDITION
8973 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8975 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8976 exp.op.exp1.destType = type1._class.registered.dataType;
8977 if(type1._class.registered.dataType)
8978 type1._class.registered.dataType.refCount++;
8979 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8980 exp.expType = type1._class.registered.dataType; //type1;
8981 if(type1) type1.refCount++;
8985 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8987 if(exp.expType) FreeType(exp.expType);
8988 exp.expType = exp.op.exp2.destType;
8989 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8991 else if(type1 && type2)
8993 char expString1[10240];
8994 char expString2[10240];
8995 char type1String[1024];
8996 char type2String[1024];
8997 expString1[0] = '\0';
8998 expString2[0] = '\0';
8999 type1String[0] = '\0';
9000 type2String[0] = '\0';
9003 PrintExpression(exp.op.exp1, expString1);
9004 ChangeCh(expString1, '\n', ' ');
9005 PrintExpression(exp.op.exp2, expString2);
9006 ChangeCh(expString2, '\n', ' ');
9007 PrintType(exp.op.exp1.expType, type1String, false, true);
9008 PrintType(exp.op.exp2.expType, type2String, false, true);
9011 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9013 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9015 exp.expType = exp.op.exp1.expType;
9016 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9018 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9020 exp.expType = exp.op.exp2.expType;
9021 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9029 // Maybe this was meant to be an enum...
9030 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9032 Type oldType = exp.op.exp1.expType;
9033 exp.op.exp1.expType = null;
9034 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9037 exp.op.exp1.expType = oldType;
9040 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9041 exp.op.exp1.destType = type2;
9044 // TESTING THIS HERE... LATEST ADDITION
9045 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9047 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9048 exp.op.exp1.destType = type1._class.registered.dataType;
9049 if(type1._class.registered.dataType)
9050 type1._class.registered.dataType.refCount++;
9053 // TESTING THIS HERE... LATEST ADDITION
9054 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9056 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9057 exp.op.exp2.destType = type2._class.registered.dataType;
9058 if(type2._class.registered.dataType)
9059 type2._class.registered.dataType.refCount++;
9063 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9065 if(exp.expType) FreeType(exp.expType);
9066 exp.expType = exp.op.exp1.destType;
9067 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9071 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9073 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9075 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9076 // Convert e.g. / 4 into / 4.0
9077 exp.op.exp1.destType = type2._class.registered.dataType;
9078 if(type2._class.registered.dataType)
9079 type2._class.registered.dataType.refCount++;
9080 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9082 if(exp.op.op == '!')
9084 exp.expType = MkClassType("bool");
9085 exp.expType.truth = true;
9089 exp.expType = type2;
9090 if(type2) type2.refCount++;
9093 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9095 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9097 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9098 // Convert e.g. / 4 into / 4.0
9099 exp.op.exp2.destType = type1._class.registered.dataType;
9100 if(type1._class.registered.dataType)
9101 type1._class.registered.dataType.refCount++;
9102 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9104 exp.expType = type1;
9105 if(type1) type1.refCount++;
9110 if(exp.op.exp1 && !exp.op.exp1.expType)
9112 char expString[10000];
9113 expString[0] = '\0';
9116 PrintExpression(exp.op.exp1, expString);
9117 ChangeCh(expString, '\n', ' ');
9120 Compiler_Error($"couldn't determine type of %s\n", expString);
9122 if(exp.op.exp2 && !exp.op.exp2.expType)
9124 char expString[10240];
9125 expString[0] = '\0';
9128 PrintExpression(exp.op.exp2, expString);
9129 ChangeCh(expString, '\n', ' ');
9132 Compiler_Error($"couldn't determine type of %s\n", expString);
9137 FreeType(exp.expType);
9138 exp.expType = MkClassType("bool");
9139 exp.expType.truth = true;
9142 if(exp.op.op != SIZEOF)
9143 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9144 (!exp.op.exp2 || exp.op.exp2.isConstant);
9146 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9148 DeclareType(exp.op.exp2.expType, false, false);
9151 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9152 Compiler_Warning($"deleting const qualified object\n");
9162 case extensionExpressionExp:
9165 exp.isConstant = true;
9166 for(e = exp.list->first; e; e = e.next)
9171 FreeType(e.destType);
9172 e.opDestType = exp.opDestType;
9173 e.destType = exp.destType;
9174 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9176 ProcessExpressionType(e);
9178 exp.destType.count--;
9179 if(!exp.expType && !e.next)
9181 exp.expType = e.expType;
9182 if(e.expType) e.expType.refCount++;
9185 exp.isConstant = false;
9188 // In case a cast became a member...
9189 e = exp.list->first;
9190 if(!e.next && e.type == memberExp)
9192 // Preserve prev, next
9193 Expression next = exp.next, prev = exp.prev;
9196 FreeType(exp.expType);
9197 FreeType(exp.destType);
9207 ProcessExpressionType(exp);
9214 exp.isConstant = true;
9216 ProcessExpressionType(exp.index.exp);
9217 if(!exp.index.exp.isConstant)
9218 exp.isConstant = false;
9220 if(exp.index.exp.expType)
9222 Type source = exp.index.exp.expType;
9223 if(source.kind == classType && source._class && source._class.registered)
9225 Class _class = source._class.registered;
9226 Class c = _class.templateClass ? _class.templateClass : _class;
9227 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9229 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9231 if(exp.index.index && exp.index.index->last)
9233 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9235 if(type.kind == classType) type.constant = true;
9236 else if(type.kind == pointerType)
9239 while(t.kind == pointerType) t = t.type;
9243 ((Expression)exp.index.index->last).destType = type;
9249 for(e = exp.index.index->first; e; e = e.next)
9251 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9253 if(e.destType) FreeType(e.destType);
9254 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9256 ProcessExpressionType(e);
9259 // Check if this type is int
9262 exp.isConstant = false;
9266 exp.expType = Dereference(exp.index.exp.expType);
9268 DeclareType(exp.expType, false, false);
9275 Type methodType = null;
9281 PrintExpression(exp.call.exp, name);
9282 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9284 //exp.call.exp.expType = null;
9285 PrintExpression(exp.call.exp, name);
9288 if(exp.call.exp.type == identifierExp)
9290 Expression idExp = exp.call.exp;
9291 Identifier id = idExp.identifier;
9292 if(!strcmp(id.string, "__builtin_frame_address"))
9294 exp.expType = ProcessTypeString("void *", true);
9295 if(exp.call.arguments && exp.call.arguments->first)
9296 ProcessExpressionType(exp.call.arguments->first);
9299 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9301 exp.expType = ProcessTypeString("int", true);
9302 if(exp.call.arguments && exp.call.arguments->first)
9303 ProcessExpressionType(exp.call.arguments->first);
9306 else if(!strcmp(id.string, "Max") ||
9307 !strcmp(id.string, "Min") ||
9308 !strcmp(id.string, "Sgn") ||
9309 !strcmp(id.string, "Abs"))
9311 Expression a = null;
9312 Expression b = null;
9313 Expression tempExp1 = null, tempExp2 = null;
9314 if((!strcmp(id.string, "Max") ||
9315 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9317 a = exp.call.arguments->first;
9318 b = exp.call.arguments->last;
9322 else if(exp.call.arguments->count == 1)
9324 a = exp.call.arguments->first;
9330 exp.call.arguments->Clear();
9331 idExp.identifier = null;
9333 FreeExpContents(exp);
9335 ProcessExpressionType(a);
9337 ProcessExpressionType(b);
9339 exp.type = bracketsExp;
9340 exp.list = MkList();
9342 if(a.expType && (!b || b.expType))
9344 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9346 // Use the simpleStruct name/ids for now...
9349 OldList * specs = MkList();
9350 OldList * decls = MkList();
9352 char temp1[1024], temp2[1024];
9354 GetTypeSpecs(a.expType, specs);
9356 if(a && !a.isConstant && a.type != identifierExp)
9358 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9359 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9360 tempExp1 = QMkExpId(temp1);
9361 tempExp1.expType = a.expType;
9363 a.expType.refCount++;
9364 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9366 if(b && !b.isConstant && b.type != identifierExp)
9368 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9369 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9370 tempExp2 = QMkExpId(temp2);
9371 tempExp2.expType = b.expType;
9373 b.expType.refCount++;
9374 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9377 decl = MkDeclaration(specs, decls);
9378 if(!curCompound.compound.declarations)
9379 curCompound.compound.declarations = MkList();
9380 curCompound.compound.declarations->Insert(null, decl);
9385 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9387 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9389 MkExpCondition(MkExpBrackets(MkListOne(
9390 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9391 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9392 exp.expType = a.expType;
9394 a.expType.refCount++;
9396 else if(!strcmp(id.string, "Abs"))
9399 MkExpCondition(MkExpBrackets(MkListOne(
9400 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9401 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9402 exp.expType = a.expType;
9404 a.expType.refCount++;
9406 else if(!strcmp(id.string, "Sgn"))
9408 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9410 MkExpCondition(MkExpBrackets(MkListOne(
9411 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9412 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9413 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9414 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9415 exp.expType = ProcessTypeString("int", false);
9418 FreeExpression(tempExp1);
9419 if(tempExp2) FreeExpression(tempExp2);
9433 if(!exp.call.exp.destType)
9435 exp.call.exp.destType = dummy;
9438 ProcessExpressionType(exp.call.exp);
9439 if(exp.call.exp.destType == dummy)
9442 exp.call.exp.destType = null;
9447 // Check argument types against parameter types
9448 functionType = exp.call.exp.expType;
9450 if(functionType && functionType.kind == TypeKind::methodType)
9452 methodType = functionType;
9453 functionType = methodType.method.dataType;
9455 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9456 // TOCHECK: Instead of doing this here could this be done per param?
9457 if(exp.call.exp.expType.usedClass)
9459 char typeString[1024];
9460 typeString[0] = '\0';
9462 Symbol back = functionType.thisClass;
9463 // Do not output class specifier here (thisclass was added to this)
9464 functionType.thisClass = null;
9465 PrintType(functionType, typeString, true, true);
9466 functionType.thisClass = back;
9468 if(strstr(typeString, "thisclass"))
9470 OldList * specs = MkList();
9473 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9475 decl = SpecDeclFromString(typeString, specs, null);
9477 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9478 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9479 exp.call.exp.expType.usedClass))
9480 thisClassParams = false;
9482 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9484 Class backupThisClass = thisClass;
9485 thisClass = exp.call.exp.expType.usedClass;
9486 ProcessDeclarator(decl);
9487 thisClass = backupThisClass;
9490 thisClassParams = true;
9492 functionType = ProcessType(specs, decl);
9493 functionType.refCount = 0;
9494 FinishTemplatesContext(context);
9497 FreeList(specs, FreeSpecifier);
9498 FreeDeclarator(decl);
9502 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9504 Type type = functionType.type;
9505 if(!functionType.refCount)
9507 functionType.type = null;
9508 FreeType(functionType);
9510 //methodType = functionType;
9511 functionType = type;
9513 if(functionType && functionType.kind != TypeKind::functionType)
9515 Compiler_Error($"called object %s is not a function\n", name);
9517 else if(functionType)
9519 bool emptyParams = false, noParams = false;
9520 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9521 Type type = functionType.params.first;
9522 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9524 Location oldyylloc = yylloc;
9526 if(!type) emptyParams = true;
9529 if(functionType.extraParam && e && functionType.thisClass)
9531 e.destType = MkClassType(functionType.thisClass.string);
9535 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9536 // Fixed #141 by adding '&& !functionType.extraParam'
9537 if(!functionType.staticMethod && !functionType.extraParam)
9539 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9540 memberExp.member.exp.expType._class)
9542 type = MkClassType(memberExp.member.exp.expType._class.string);
9547 type = functionType.params.first;
9552 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9554 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9555 type.byReference = functionType.byReference;
9556 type.typedByReference = functionType.typedByReference;
9559 // Allow manually passing a class for typed object
9560 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9564 type = functionType.params.first;
9572 if(type && type.kind == voidType)
9575 if(!type.refCount) FreeType(type);
9579 for( ; e; e = e.next)
9581 if(!type && !emptyParams)
9584 if(methodType && methodType.methodClass)
9585 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9586 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9587 noParams ? 0 : functionType.params.count);
9589 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9590 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9591 noParams ? 0 : functionType.params.count);
9595 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9597 Type templatedType = null;
9598 Class _class = methodType.usedClass;
9599 ClassTemplateParameter curParam = null;
9601 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9604 for(sClass = _class; sClass; sClass = sClass.base)
9606 if(sClass.templateClass) sClass = sClass.templateClass;
9608 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9610 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9613 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9615 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9616 id += nextClass.templateParams.count;
9625 if(curParam && _class.templateArgs[id].dataTypeString)
9627 bool constant = type.constant;
9628 ClassTemplateArgument arg = _class.templateArgs[id];
9630 Context context = SetupTemplatesContext(_class);
9633 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9634 templatedType = ProcessTypeString(arg.dataTypeString, false);
9635 FinishTemplatesContext(context);
9638 if(templatedType.kind == classType && constant) templatedType.constant = true;
9639 else if(templatedType.kind == pointerType)
9641 Type t = templatedType.type;
9642 while(t.kind == pointerType) t = t.type;
9643 if(constant) t.constant = constant;
9646 e.destType = templatedType;
9649 templatedType.passAsTemplate = true;
9650 // templatedType.refCount++;
9656 if(type) type.refCount++;
9661 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9663 e.destType = type.prev;
9664 e.destType.refCount++;
9669 if(type) type.refCount++;
9672 // Don't reach the end for the ellipsis
9673 if(type && type.kind != ellipsisType)
9675 Type next = type.next;
9676 if(!type.refCount) FreeType(type);
9681 if(type && type.kind != ellipsisType)
9683 if(methodType && methodType.methodClass)
9684 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9685 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9686 functionType.params.count + extra);
9688 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9689 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9690 functionType.params.count + extra);
9693 if(type && !type.refCount) FreeType(type);
9700 kind = TypeKind::functionType;
9703 if(exp.call.exp.type == identifierExp)
9705 char * string = exp.call.exp.identifier.string;
9709 Location oldyylloc = yylloc;
9711 yylloc = exp.call.exp.identifier.loc;
9712 if(strstr(string, "__builtin_") == string)
9716 functionType.returnType = exp.destType;
9717 exp.destType.refCount++;
9721 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9722 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9723 globalContext.symbols.Add((BTNode)symbol);
9724 if(strstr(symbol.string, "::"))
9725 globalContext.hasNameSpace = true;
9730 else if(exp.call.exp.type == memberExp)
9732 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9733 exp.call.exp.member.member.string);*/
9736 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9738 if(!functionType.returnType)
9740 functionType.returnType = Type
9747 if(functionType && functionType.kind == TypeKind::functionType)
9749 exp.expType = functionType.returnType;
9751 if(functionType.returnType)
9752 functionType.returnType.refCount++;
9754 if(!functionType.refCount)
9755 FreeType(functionType);
9758 if(exp.call.arguments)
9760 for(e = exp.call.arguments->first; e; e = e.next)
9761 ProcessExpressionType(e);
9768 Location oldyylloc = yylloc;
9770 Expression checkExp = exp.member.exp;
9773 if(checkExp.type == castExp)
9774 checkExp = checkExp.cast.exp;
9775 else if(checkExp.type == bracketsExp)
9776 checkExp = checkExp.list ? checkExp.list->first : null;
9781 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9782 exp.thisPtr = thisPtr;
9784 // DOING THIS LATER NOW...
9785 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9787 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9788 /* TODO: Name Space Fix ups
9789 if(!exp.member.member.classSym)
9790 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9794 ProcessExpressionType(exp.member.exp);
9795 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9796 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9798 exp.isConstant = false;
9801 exp.isConstant = exp.member.exp.isConstant;
9802 type = exp.member.exp.expType;
9806 if(type && (type.kind == templateType))
9808 Class _class = thisClass ? thisClass : currentClass;
9809 ClassTemplateParameter param = null;
9812 for(param = _class.templateParams.first; param; param = param.next)
9814 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9818 if(param && param.defaultArg.member)
9820 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9823 Expression expMember = exp.member.exp;
9825 OldList * specs = MkList();
9826 char thisClassTypeString[1024];
9828 FreeIdentifier(exp.member.member);
9830 ProcessExpressionType(argExp);
9833 char * colon = strstr(param.defaultArg.memberString, "::");
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;
9853 char templateString[1024];
9854 ClassTemplateParameter param;
9855 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9856 for(cClass = expClass; cClass; cClass = cClass.base)
9859 for(param = cClass.templateParams.first; param; param = param.next)
9863 ClassTemplateArgument arg;
9864 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9865 arg = expClass.templateArgs[id];
9867 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9869 ClassTemplateParameter cParam;
9870 //int p = numParams - sClass.templateParams.count;
9873 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9875 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9877 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9879 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9881 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9882 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9894 strcat(argument, arg.name.string);
9895 strcat(argument, " = ");
9901 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9902 char expString[1024];
9903 OldList * specs = MkList();
9904 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9906 char * string = PrintHexUInt64(arg.expression.ui64);
9907 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9910 ProcessExpressionType(exp);
9911 ComputeExpression(exp);
9912 expString[0] = '\0';
9913 PrintExpression(exp, expString);
9914 strcat(argument, expString);
9916 FreeExpression(exp);
9921 strcat(argument, arg.member.name);
9924 case TemplateParameterType::type:
9926 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9928 if(!strcmp(arg.dataTypeString, "thisclass"))
9929 strcat(argument, thisClassTypeString);
9931 strcat(argument, arg.dataTypeString);
9938 if(paramCount) strcat(templateString, ", ");
9939 if(lastParam != p - 1)
9941 strcat(templateString, param.name);
9942 strcat(templateString, " = ");
9944 strcat(templateString, argument);
9953 int len = strlen(templateString);
9954 if(templateString[len-1] == '>') templateString[len++] = ' ';
9955 templateString[len++] = '>';
9956 templateString[len++] = '\0';
9959 Context context = SetupTemplatesContext(_class);
9960 FreeType(exp.expType);
9961 exp.expType = ProcessTypeString(templateString, false);
9962 FinishTemplatesContext(context);
9966 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9967 exp.type = bracketsExp;
9968 exp.list = MkListOne(MkExpOp(null, '*',
9973 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9974 MkExpBrackets(MkListOne(
9975 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9977 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9979 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9984 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9985 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9987 type = ProcessTemplateParameterType(type.templateParameter);
9990 // TODO: *** This seems to be where we should add method support for all basic types ***
9991 if(type && (type.kind == templateType));
9992 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9993 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9994 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9995 (type.kind == pointerType && type.type.kind == charType)))
9997 Identifier id = exp.member.member;
9998 TypeKind typeKind = type.kind;
9999 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10000 if(typeKind == subClassType && exp.member.exp.type == classExp)
10002 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10003 typeKind = classType;
10008 if(typeKind == intType || typeKind == enumType)
10009 _class = eSystem_FindClass(privateModule, "int");
10012 if(type.kind == classType && type._class && type._class.registered)
10014 _class = type._class.registered;
10016 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10018 _class = FindClass("char *").registered;
10020 else if(type.kind == pointerType)
10022 _class = eSystem_FindClass(privateModule, "uintptr");
10023 FreeType(exp.expType);
10024 exp.expType = ProcessTypeString("uintptr", false);
10025 exp.byReference = true;
10029 char string[1024] = "";
10031 PrintTypeNoConst(type, string, false, true);
10032 classSym = FindClass(string);
10033 if(classSym) _class = classSym.registered;
10041 (exp.member.exp.type == identifierExp &&
10042 !strcmp(exp.member.exp.identifier.string, "this"));*/
10043 Property prop = null;
10044 Method method = null;
10045 DataMember member = null;
10046 Property revConvert = null;
10047 ClassProperty classProp = null;
10049 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10050 exp.member.memberType = propertyMember;
10052 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10053 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10055 if(typeKind != subClassType)
10057 // Prioritize data members over properties for "this"
10058 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10060 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10061 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10063 prop = eClass_FindProperty(_class, id.string, privateModule);
10067 if(!member && !prop)
10068 prop = eClass_FindProperty(_class, id.string, privateModule);
10069 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10070 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10071 exp.member.thisPtr = true;
10073 // Prioritize properties over data members otherwise
10076 bool useMemberForNonConst = false;
10077 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10080 prop = eClass_FindProperty(_class, id.string, null);
10082 useMemberForNonConst = prop && exp.destType &&
10083 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10084 !strncmp(prop.dataTypeString, "const ", 6);
10086 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10087 member = eClass_FindDataMember(_class, id.string, null, null, null);
10090 if((!prop || useMemberForNonConst) && !member)
10092 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10095 prop = eClass_FindProperty(_class, id.string, privateModule);
10097 useMemberForNonConst |= prop && exp.destType &&
10098 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10099 !strncmp(prop.dataTypeString, "const ", 6);
10101 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10102 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10108 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10115 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10116 method = eClass_FindMethod(_class, id.string, privateModule);
10117 if(!prop && !member && !method)
10119 if(typeKind == subClassType)
10121 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10124 exp.member.memberType = classPropertyMember;
10125 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10129 // Assume this is a class_data member
10130 char structName[1024];
10131 Identifier id = exp.member.member;
10132 Expression classExp = exp.member.exp;
10135 FreeType(classExp.expType);
10136 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10138 strcpy(structName, "__ecereClassData_");
10139 FullClassNameCat(structName, type._class.string, false);
10140 exp.type = pointerExp;
10141 exp.member.member = id;
10143 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10144 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10145 MkExpBrackets(MkListOne(MkExpOp(
10146 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10147 MkExpMember(classExp, MkIdentifier("data"))), '+',
10148 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10153 ProcessExpressionType(exp);
10159 // Check for reverse conversion
10160 // (Convert in an instantiation later, so that we can use
10161 // deep properties system)
10162 Symbol classSym = FindClass(id.string);
10165 Class convertClass = classSym.registered;
10167 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10174 exp.member.memberType = propertyMember;
10176 ProcessPropertyType(prop);
10177 exp.expType = prop.dataType;
10178 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10181 CopyTypeInto(type, exp.expType);
10183 type.constant = true;
10184 exp.expType = type;
10186 else if(prop.dataType)
10187 prop.dataType.refCount++;
10191 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10193 FreeExpContents(exp);
10194 exp.type = identifierExp;
10195 exp.identifier = MkIdentifier("class");
10196 ProcessExpressionType(exp);
10200 exp.member.memberType = dataMember;
10201 DeclareStruct(_class.fullName, false);
10202 if(!member.dataType)
10204 Context context = SetupTemplatesContext(_class);
10205 member.dataType = ProcessTypeString(member.dataTypeString, false);
10206 FinishTemplatesContext(context);
10208 exp.expType = member.dataType;
10209 if(member.dataType) member.dataType.refCount++;
10211 else if(revConvert)
10213 exp.member.memberType = reverseConversionMember;
10214 exp.expType = MkClassType(revConvert._class.fullName);
10222 exp.type = identifierExp;
10223 exp.identifier = exp.member.member;
10226 exp.member.memberType = methodMember;
10228 if(!method.dataType)
10229 ProcessMethodType(method);
10237 // Tricky spot here... To use instance versus class virtual table
10238 // Put it back to what it was... What did we break?
10240 // Had to put it back for overriding Main of Thread global instance
10242 //exp.expType.methodClass = _class;
10243 exp.expType.methodClass = (id && id._class) ? _class : null;
10245 // Need the actual class used for templated classes
10246 exp.expType.usedClass = _class;
10248 else if(!classProp)
10250 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10252 FreeExpContents(exp);
10253 exp.type = identifierExp;
10254 exp.identifier = MkIdentifier("class");
10255 FreeType(exp.expType);
10256 exp.expType = MkClassType("ecere::com::Class");
10259 yylloc = exp.member.member.loc;
10260 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10262 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10265 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10269 tClass = type._class && type._class.registered ? type._class.registered : _class;
10270 while(tClass && !tClass.templateClass) tClass = tClass.base;
10272 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10275 ClassTemplateParameter curParam = null;
10278 for(sClass = tClass; sClass; sClass = sClass.base)
10281 if(sClass.templateClass) sClass = sClass.templateClass;
10282 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10284 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10286 for(sClass = sClass.base; sClass; sClass = sClass.base)
10287 id += sClass.templateParams.count;
10292 if(curParam) break;
10295 if(curParam && tClass.templateArgs[id].dataTypeString)
10297 ClassTemplateArgument arg = tClass.templateArgs[id];
10298 Context context = SetupTemplatesContext(tClass);
10299 bool constant = exp.expType.constant;
10300 /*if(!arg.dataType)
10301 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10302 FreeType(exp.expType);
10304 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10305 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10306 else if(exp.expType.kind == pointerType)
10308 Type t = exp.expType.type;
10309 while(t.kind == pointerType) t = t.type;
10310 if(constant) t.constant = constant;
10314 if(exp.expType.kind == thisClassType)
10316 FreeType(exp.expType);
10317 exp.expType = ReplaceThisClassType(_class);
10320 if(tClass.templateClass && (exp.expType.kind != templateType || (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType))))
10321 exp.expType.passAsTemplate = true;
10322 //exp.expType.refCount++;
10325 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10326 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10327 else if(exp.destType.kind == pointerType)
10329 Type t = exp.destType.type;
10330 while(t.kind == pointerType) t = t.type;
10331 if(constant) t.constant = constant;
10334 //exp.destType.refCount++;
10336 if(exp.destType.kind == thisClassType)
10338 FreeType(exp.destType);
10339 exp.destType = ReplaceThisClassType(_class);
10343 FinishTemplatesContext(context);
10346 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10347 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10350 ClassTemplateParameter curParam = null;
10353 for(sClass = tClass; sClass; sClass = sClass.base)
10356 if(sClass.templateClass) sClass = sClass.templateClass;
10357 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10359 if(curParam.type == TemplateParameterType::type &&
10360 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10362 for(sClass = sClass.base; sClass; sClass = sClass.base)
10363 id += sClass.templateParams.count;
10368 if(curParam) break;
10373 ClassTemplateArgument arg = tClass.templateArgs[id];
10374 Context context = SetupTemplatesContext(tClass);
10376 /*if(!arg.dataType)
10377 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10379 basicType = ProcessTypeString(arg.dataTypeString, false);
10382 if(basicType.kind == thisClassType)
10384 FreeType(basicType);
10385 basicType = ReplaceThisClassType(_class);
10388 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10389 if(tClass.templateClass)
10390 basicType.passAsTemplate = true;
10393 FreeType(exp.expType);
10395 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10396 //exp.expType.refCount++;
10399 exp.destType = exp.expType;
10400 exp.destType.refCount++;
10404 Expression newExp { };
10405 OldList * specs = MkList();
10407 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10409 if(exp.destType) exp.destType.refCount++;
10410 if(exp.expType) exp.expType.refCount++;
10411 exp.type = castExp;
10412 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10413 exp.cast.exp = newExp;
10414 //FreeType(exp.expType);
10415 //exp.expType = null;
10416 //ProcessExpressionType(sourceExp);
10419 FinishTemplatesContext(context);
10422 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10424 Class expClass = exp.expType._class.registered;
10427 Class cClass = null;
10429 int paramCount = 0;
10430 int lastParam = -1;
10431 char templateString[1024];
10432 ClassTemplateParameter param;
10433 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10434 while(cClass != expClass)
10437 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10440 for(param = cClass.templateParams.first; param; param = param.next)
10442 Class cClassCur = null;
10444 ClassTemplateParameter paramCur = null;
10445 ClassTemplateArgument arg;
10446 while(cClassCur != tClass && !paramCur)
10449 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10450 cClassCur = sClassCur;
10452 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10454 if(!strcmp(paramCur.name, param.name))
10462 if(paramCur && paramCur.type == TemplateParameterType::type)
10463 arg = tClass.templateArgs[cp];
10465 arg = expClass.templateArgs[p];
10468 char argument[256];
10469 argument[0] = '\0';
10472 strcat(argument, arg.name.string);
10473 strcat(argument, " = ");
10479 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10480 char expString[1024];
10481 OldList * specs = MkList();
10482 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10484 char * string = PrintHexUInt64(arg.expression.ui64);
10485 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10488 ProcessExpressionType(exp);
10489 ComputeExpression(exp);
10490 expString[0] = '\0';
10491 PrintExpression(exp, expString);
10492 strcat(argument, expString);
10494 FreeExpression(exp);
10499 strcat(argument, arg.member.name);
10502 case TemplateParameterType::type:
10504 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10505 strcat(argument, arg.dataTypeString);
10511 if(paramCount) strcat(templateString, ", ");
10512 if(lastParam != p - 1)
10514 strcat(templateString, param.name);
10515 strcat(templateString, " = ");
10517 strcat(templateString, argument);
10526 int len = strlen(templateString);
10527 if(templateString[len-1] == '>') templateString[len++] = ' ';
10528 templateString[len++] = '>';
10529 templateString[len++] = '\0';
10532 FreeType(exp.expType);
10534 Context context = SetupTemplatesContext(tClass);
10535 exp.expType = ProcessTypeString(templateString, false);
10536 FinishTemplatesContext(context);
10543 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10545 else if(type && (type.kind == structType || type.kind == unionType))
10547 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10550 exp.expType = memberType;
10552 memberType.refCount++;
10557 char expString[10240];
10558 expString[0] = '\0';
10559 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10560 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10563 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10565 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10567 Identifier id = exp.member.member;
10568 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10571 FreeType(exp.expType);
10572 exp.expType = ReplaceThisClassType(_class);
10576 yylloc = oldyylloc;
10579 // Convert x->y into (*x).y
10582 Type destType = exp.destType;
10584 // DOING THIS LATER NOW...
10585 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10587 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10588 /* TODO: Name Space Fix ups
10589 if(!exp.member.member.classSym)
10590 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10594 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10595 exp.type = memberExp;
10598 ProcessExpressionType(exp);
10605 //ComputeExpression(exp);
10607 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10608 if(classSym && classSym.registered)
10610 if(classSym.registered.type == noHeadClass)
10614 DeclareStruct(classSym.string, false);
10615 FreeSpecifier(exp._class);
10616 exp.type = typeSizeExp;
10617 FullClassNameCat(name, classSym.string, false);
10618 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10622 if(classSym.registered.fixed)
10624 FreeSpecifier(exp._class);
10625 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10626 exp.type = constantExp;
10630 char className[1024];
10631 strcpy(className, "__ecereClass_");
10632 FullClassNameCat(className, classSym.string, true);
10633 //MangleClassName(className);
10635 DeclareClass(classSym, className);
10637 FreeExpContents(exp);
10638 exp.type = pointerExp;
10639 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10640 exp.member.member = MkIdentifier("structSize");
10648 kind = intSizeType;
10650 // exp.isConstant = true;
10655 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10660 kind = intSizeType;
10662 exp.isConstant = true;
10664 DeclareType(type, false, false);
10670 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10672 FreeType(exp.cast.exp.destType);
10673 exp.cast.exp.destType = type;
10675 type.casted = true;
10676 ProcessExpressionType(exp.cast.exp);
10677 type.casted = false;
10679 exp.expType = type;
10682 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10683 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10685 void * prev = exp.prev, * next = exp.next;
10686 Type expType = exp.cast.exp.destType;
10687 Expression castExp = exp.cast.exp;
10688 Type destType = exp.destType;
10690 if(expType) expType.refCount++;
10692 //FreeType(exp.destType);
10693 FreeType(exp.expType);
10694 FreeTypeName(exp.cast.typeName);
10697 FreeType(exp.expType);
10698 FreeType(exp.destType);
10700 exp.expType = expType;
10701 exp.destType = destType;
10711 exp.isConstant = exp.cast.exp.isConstant;
10716 case extensionInitializerExp:
10718 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10719 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10720 // ProcessInitializer(exp.initializer.initializer, type);
10721 exp.expType = type;
10726 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10727 ProcessExpressionType(exp.vaArg.exp);
10728 exp.expType = type;
10734 exp.isConstant = true;
10736 FreeType(exp.cond.cond.destType);
10737 exp.cond.cond.destType = MkClassType("bool");
10738 exp.cond.cond.destType.truth = true;
10739 ProcessExpressionType(exp.cond.cond);
10740 if(!exp.cond.cond.isConstant)
10741 exp.isConstant = false;
10742 for(e = exp.cond.exp->first; e; e = e.next)
10746 FreeType(e.destType);
10747 e.destType = exp.destType;
10748 if(e.destType) e.destType.refCount++;
10750 ProcessExpressionType(e);
10753 exp.expType = e.expType;
10754 if(e.expType) e.expType.refCount++;
10757 exp.isConstant = false;
10760 FreeType(exp.cond.elseExp.destType);
10761 // Added this check if we failed to find an expType
10762 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10765 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10767 if(exp.cond.elseExp.destType)
10768 exp.cond.elseExp.destType.refCount++;
10769 ProcessExpressionType(exp.cond.elseExp);
10771 // FIXED THIS: Was done before calling process on elseExp
10772 if(!exp.cond.elseExp.isConstant)
10773 exp.isConstant = false;
10776 case extensionCompoundExp:
10778 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10780 Statement last = exp.compound.compound.statements->last;
10781 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10783 ((Expression)last.expressions->last).destType = exp.destType;
10785 exp.destType.refCount++;
10787 ProcessStatement(exp.compound);
10788 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10790 exp.expType.refCount++;
10796 Specifier spec = exp._classExp.specifiers->first;
10797 if(spec && spec.type == nameSpecifier)
10799 exp.expType = MkClassType(spec.name);
10800 exp.expType.kind = subClassType;
10801 exp.byReference = true;
10805 exp.expType = MkClassType("ecere::com::Class");
10806 exp.byReference = true;
10812 Class _class = thisClass ? thisClass : currentClass;
10815 Identifier id = exp.classData.id;
10816 char structName[1024];
10817 Expression classExp;
10818 strcpy(structName, "__ecereClassData_");
10819 FullClassNameCat(structName, _class.fullName, false);
10820 exp.type = pointerExp;
10821 exp.member.member = id;
10822 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10823 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10825 classExp = MkExpIdentifier(MkIdentifier("class"));
10827 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10828 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10829 MkExpBrackets(MkListOne(MkExpOp(
10830 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10831 MkExpMember(classExp, MkIdentifier("data"))), '+',
10832 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10835 ProcessExpressionType(exp);
10843 const char * typeString = null;
10844 char typeStringBuf[1024];
10845 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10846 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10848 Class templateClass = exp.destType._class.registered;
10849 typeString = templateClass.templateArgs[2].dataTypeString;
10853 // Guess type from expressions in the array
10855 for(e = exp.list->first; e; e = e.next)
10857 ProcessExpressionType(e);
10860 if(!type) { type = e.expType; type.refCount++; }
10863 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10864 if(!MatchTypeExpression(e, type, null, false, true))
10870 e = exp.list->first;
10871 ProcessExpressionType(e);
10874 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10875 if(!MatchTypeExpression(e, type, null, false, true))
10877 FreeType(e.expType);
10888 FreeType(e.expType);
10895 typeStringBuf[0] = '\0';
10896 PrintTypeNoConst(type, typeStringBuf, false, true);
10897 typeString = typeStringBuf;
10905 (Container)& (struct BuiltInContainer)
10907 ._vTbl = class(BuiltInContainer)._vTbl,
10908 ._class = class(BuiltInContainer),
10910 .data = (int[]){ 1, 7, 3, 4, 5 },
10912 .type = class(int),
10915 char templateString[1024];
10916 OldList * initializers = MkList();
10917 OldList * structInitializers = MkList();
10918 OldList * specs = MkList();
10920 Declarator decl = SpecDeclFromString(typeString, specs, null);
10921 sprintf(templateString, "Container<%s>", typeString);
10926 type = ProcessTypeString(typeString, false);
10927 while((e = exp.list->first))
10929 exp.list->Remove(e);
10932 ProcessExpressionType(e);
10933 ListAdd(initializers, MkInitializerAssignment(e));
10939 DeclareStruct("ecere::com::BuiltInContainer", false);
10941 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10942 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10943 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10944 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10945 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10946 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10947 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10948 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10949 MkInitializerList(initializers))));
10950 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10951 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10952 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10953 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10954 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10955 exp.expType = ProcessTypeString(templateString, false);
10956 exp.type = bracketsExp;
10957 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10959 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10960 MkInitializerList(structInitializers)))));
10961 ProcessExpressionType(expExt);
10965 exp.expType = ProcessTypeString("Container", false);
10966 Compiler_Error($"Couldn't determine type of array elements\n");
10972 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10974 FreeType(exp.expType);
10975 exp.expType = ReplaceThisClassType(thisClass);
10978 // Resolve structures here
10979 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10981 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10982 // TODO: Fix members reference...
10985 if(exp.expType.kind != enumType)
10988 String enumName = CopyString(exp.expType.enumName);
10990 // Fixed a memory leak on self-referencing C structs typedefs
10991 // by instantiating a new type rather than simply copying members
10992 // into exp.expType
10993 FreeType(exp.expType);
10994 exp.expType = Type { };
10995 exp.expType.kind = symbol.type.kind;
10996 exp.expType.refCount++;
10997 exp.expType.enumName = enumName;
10999 exp.expType.members = symbol.type.members;
11000 for(member = symbol.type.members.first; member; member = member.next)
11006 for(member = symbol.type.members.first; member; member = member.next)
11008 NamedLink value { name = CopyString(member.name) };
11009 exp.expType.members.Add(value);
11016 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11017 else if(exp.destType && !exp.destType.keepCast)
11019 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11020 exp.needTemplateCast = 1;
11022 if(exp.destType.kind == voidType);
11023 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11025 if(!exp.destType.count || unresolved)
11030 if(exp.destType.kind != ellipsisType)
11036 char expString[10240];
11037 expString[0] = '\0';
11039 PrintType(exp.destType, type2, false, true);
11041 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11043 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11044 else if(exp.type != dummyExp)
11045 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11050 char expString[10240] ;
11051 expString[0] = '\0';
11052 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11055 Compiler_Error($"unresolved identifier %s\n", expString);
11056 else if(exp.type != dummyExp)
11057 Compiler_Error($"couldn't determine type of %s\n", expString);
11068 PrintType(exp.expType, type1, false, true);
11069 PrintType(exp.destType, type2, false, true);
11072 //CheckExpressionType(exp, exp.destType, false);
11074 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11075 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11076 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11079 char expString[10240];
11080 expString[0] = '\0';
11081 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11084 CheckExpressionType(exp, exp.destType, false, true);
11086 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11087 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
11088 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11090 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11091 FreeType(exp.expType);
11092 exp.destType.refCount++;
11093 exp.expType = exp.destType;
11098 /*else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
11100 Expression newExp { };
11101 char typeString[1024];
11102 OldList * specs = MkList();
11105 typeString[0] = '\0';
11109 if(exp.expType) exp.expType.refCount++;
11110 if(exp.expType) exp.expType.refCount++;
11111 exp.type = castExp;
11112 newExp.destType = exp.expType;
11114 PrintType(exp.expType, typeString, false, false);
11115 decl = SpecDeclFromString(typeString, specs, null);
11117 exp.cast.typeName = MkTypeName(specs, decl);
11118 exp.cast.exp = newExp;
11121 else if(unresolved)
11123 if(exp.identifier._class && exp.identifier._class.name)
11124 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11125 else if(exp.identifier.string && exp.identifier.string[0])
11126 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11128 else if(!exp.expType && exp.type != dummyExp)
11130 char expString[10240];
11131 expString[0] = '\0';
11132 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11133 Compiler_Error($"couldn't determine type of %s\n", expString);
11136 // Let's try to support any_object & typed_object here:
11138 ApplyAnyObjectLogic(exp);
11140 // Mark nohead classes as by reference, unless we're casting them to an integral type
11141 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11142 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11143 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11144 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11146 exp.byReference = true;
11148 yylloc = oldyylloc;
11151 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11153 // THIS CODE WILL FIND NEXT MEMBER...
11156 *curMember = (*curMember).next;
11158 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11160 *curMember = subMemberStack[--(*subMemberStackPos)];
11161 *curMember = (*curMember).next;
11164 // SKIP ALL PROPERTIES HERE...
11165 while((*curMember) && (*curMember).isProperty)
11166 *curMember = (*curMember).next;
11168 if(subMemberStackPos)
11170 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11172 subMemberStack[(*subMemberStackPos)++] = *curMember;
11174 *curMember = (*curMember).members.first;
11175 while(*curMember && (*curMember).isProperty)
11176 *curMember = (*curMember).next;
11184 if(subMemberStackPos && *subMemberStackPos)
11186 *curMember = subMemberStack[--(*subMemberStackPos)];
11187 *curMember = (*curMember).next;
11191 Class lastCurClass = *curClass;
11193 if(*curClass == _class) break; // REACHED THE END
11195 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11196 *curMember = (*curClass).membersAndProperties.first;
11199 while((*curMember) && (*curMember).isProperty)
11200 *curMember = (*curMember).next;
11201 if(subMemberStackPos)
11203 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11205 subMemberStack[(*subMemberStackPos)++] = *curMember;
11207 *curMember = (*curMember).members.first;
11208 while(*curMember && (*curMember).isProperty)
11209 *curMember = (*curMember).next;
11217 static void ProcessInitializer(Initializer init, Type type)
11221 case expInitializer:
11222 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11224 // TESTING THIS FOR SHUTTING = 0 WARNING
11225 if(init.exp && !init.exp.destType)
11227 FreeType(init.exp.destType);
11228 init.exp.destType = type;
11229 if(type) type.refCount++;
11233 ProcessExpressionType(init.exp);
11234 init.isConstant = init.exp.isConstant;
11240 Expression exp = init.exp;
11241 Instantiation inst = exp.instance;
11242 MembersInit members;
11244 init.type = listInitializer;
11245 init.list = MkList();
11249 for(members = inst.members->first; members; members = members.next)
11251 if(members.type == dataMembersInit)
11254 for(member = members.dataMembers->first; member; member = member.next)
11256 ListAdd(init.list, member.initializer);
11257 member.initializer = null;
11260 // Discard all MembersInitMethod
11263 FreeExpression(exp);
11265 case listInitializer:
11268 Type initializerType = null;
11269 Class curClass = null;
11270 DataMember curMember = null;
11271 DataMember subMemberStack[256];
11272 int subMemberStackPos = 0;
11274 if(type && type.kind == arrayType)
11275 initializerType = Dereference(type);
11276 else if(type && (type.kind == structType || type.kind == unionType))
11277 initializerType = type.members.first;
11279 for(i = init.list->first; i; i = i.next)
11281 if(type && type.kind == classType && type._class && type._class.registered)
11283 // 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)
11284 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11285 // TODO: Generate error on initializing a private data member this way from another module...
11288 if(!curMember.dataType)
11289 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11290 initializerType = curMember.dataType;
11293 ProcessInitializer(i, initializerType);
11294 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11295 initializerType = initializerType.next;
11297 init.isConstant = false;
11300 if(type && type.kind == arrayType)
11301 FreeType(initializerType);
11303 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11305 Compiler_Error($"Assigning list initializer to non list\n");
11312 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11316 case baseSpecifier:
11318 if(spec.specifier == THISCLASS)
11322 spec.type = nameSpecifier;
11323 spec.name = ReplaceThisClass(thisClass);
11324 spec.symbol = FindClass(spec.name);
11325 ProcessSpecifier(spec, declareStruct);
11330 case nameSpecifier:
11332 Symbol symbol = FindType(curContext, spec.name);
11334 DeclareType(symbol.type, true, true);
11335 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11336 DeclareStruct(spec.name, false);
11339 case enumSpecifier:
11344 for(e = spec.list->first; e; e = e.next)
11347 ProcessExpressionType(e.exp);
11352 case structSpecifier:
11353 case unionSpecifier:
11355 if(spec.definitions)
11358 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11360 ProcessClass(spec.definitions, symbol);
11363 for(def = spec.definitions->first; def; def = def.next)
11365 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11366 ProcessDeclaration(def.decl);
11373 case classSpecifier:
11375 Symbol classSym = FindClass(spec.name);
11376 if(classSym && classSym.registered && classSym.registered.type == structClass)
11377 DeclareStruct(spec.name, false);
11385 static void ProcessDeclarator(Declarator decl)
11389 case identifierDeclarator:
11390 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11392 FreeSpecifier(decl.identifier._class);
11393 decl.identifier._class = null;
11396 case arrayDeclarator:
11398 ProcessExpressionType(decl.array.exp);
11399 case structDeclarator:
11400 case bracketsDeclarator:
11401 case functionDeclarator:
11402 case pointerDeclarator:
11403 case extendedDeclarator:
11404 case extendedDeclaratorEnd:
11405 if(decl.declarator)
11406 ProcessDeclarator(decl.declarator);
11407 if(decl.type == functionDeclarator)
11409 Identifier id = GetDeclId(decl);
11410 if(id && id._class)
11414 qualifiers = MkListOne(id._class);
11417 if(!decl.function.parameters)
11418 decl.function.parameters = MkList();
11419 decl.function.parameters->Insert(null, param);
11422 if(decl.function.parameters)
11426 for(param = decl.function.parameters->first; param; param = param.next)
11428 if(param.qualifiers && param.qualifiers->first)
11430 Specifier spec = param.qualifiers->first;
11431 if(spec && spec.specifier == TYPED_OBJECT)
11433 Declarator d = param.declarator;
11436 qualifiers = MkListOne(MkSpecifier(VOID));
11437 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11439 if(d.type != pointerDeclarator)
11440 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11442 FreeList(param.qualifiers, FreeSpecifier);
11444 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11445 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11447 decl.function.parameters->Insert(param, newParam);
11450 else if(spec && spec.specifier == ANY_OBJECT)
11452 Declarator d = param.declarator;
11454 FreeList(param.qualifiers, FreeSpecifier);
11456 param.qualifiers = MkListOne(MkSpecifier(VOID));
11457 if(d.type != pointerDeclarator)
11458 param.qualifiers->Insert(null, MkSpecifier(CONST));
11459 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11461 else if(spec.specifier == THISCLASS)
11465 spec.type = nameSpecifier;
11466 spec.name = ReplaceThisClass(thisClass);
11467 spec.symbol = FindClass(spec.name);
11468 ProcessSpecifier(spec, false);
11473 if(param.declarator)
11474 ProcessDeclarator(param.declarator);
11482 static void ProcessDeclaration(Declaration decl)
11487 case initDeclaration:
11489 bool declareStruct = false;
11491 lineNum = decl.pos.line;
11492 column = decl.pos.col;
11495 if(decl.declarators)
11499 for(d = decl.declarators->first; d; d = d.next)
11501 Type type, subType;
11502 ProcessDeclarator(d.declarator);
11504 type = ProcessType(decl.specifiers, d.declarator);
11508 ProcessInitializer(d.initializer, type);
11510 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11512 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11513 d.initializer.exp.type == instanceExp)
11515 if(type.kind == classType && type._class ==
11516 d.initializer.exp.expType._class)
11518 Instantiation inst = d.initializer.exp.instance;
11519 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11521 d.initializer.exp.instance = null;
11522 if(decl.specifiers)
11523 FreeList(decl.specifiers, FreeSpecifier);
11524 FreeList(decl.declarators, FreeInitDeclarator);
11528 decl.type = instDeclaration;
11533 for(subType = type; subType;)
11535 if(subType.kind == classType)
11537 declareStruct = true;
11540 else if(subType.kind == pointerType)
11542 else if(subType.kind == arrayType)
11543 subType = subType.arrayType;
11553 if(decl.specifiers)
11556 for(s = decl.specifiers->first; s; s = s.next)
11558 ProcessSpecifier(s, declareStruct);
11563 case instDeclaration:
11565 ProcessInstantiationType(decl.inst);
11568 case structDeclaration:
11572 bool declareStruct = false;
11574 if(decl.declarators)
11576 for(d = decl.declarators->first; d; d = d.next)
11578 Type type = ProcessType(decl.specifiers, d.declarator);
11580 ProcessDeclarator(d);
11581 for(subType = type; subType;)
11583 if(subType.kind == classType)
11585 declareStruct = true;
11588 else if(subType.kind == pointerType)
11590 else if(subType.kind == arrayType)
11591 subType = subType.arrayType;
11598 if(decl.specifiers)
11600 for(spec = decl.specifiers->first; spec; spec = spec.next)
11601 ProcessSpecifier(spec, declareStruct);
11608 static FunctionDefinition curFunction;
11610 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11612 char propName[1024], propNameM[1024];
11613 char getName[1024], setName[1024];
11616 DeclareProperty(prop, setName, getName);
11618 // eInstance_FireWatchers(object, prop);
11619 strcpy(propName, "__ecereProp_");
11620 FullClassNameCat(propName, prop._class.fullName, false);
11621 strcat(propName, "_");
11622 // strcat(propName, prop.name);
11623 FullClassNameCat(propName, prop.name, true);
11624 //MangleClassName(propName);
11626 strcpy(propNameM, "__ecerePropM_");
11627 FullClassNameCat(propNameM, prop._class.fullName, false);
11628 strcat(propNameM, "_");
11629 // strcat(propNameM, prop.name);
11630 FullClassNameCat(propNameM, prop.name, true);
11631 //MangleClassName(propNameM);
11633 if(prop.isWatchable)
11636 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11637 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11638 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11641 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11642 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11643 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11649 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11650 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11651 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11654 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11655 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11656 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11659 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11660 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11661 curFunction.propSet.fireWatchersDone = true;
11664 static void ProcessStatement(Statement stmt)
11668 lineNum = stmt.pos.line;
11669 column = stmt.pos.col;
11674 ProcessStatement(stmt.labeled.stmt);
11677 // This expression should be constant...
11678 if(stmt.caseStmt.exp)
11680 FreeType(stmt.caseStmt.exp.destType);
11681 stmt.caseStmt.exp.destType = curSwitchType;
11682 if(curSwitchType) curSwitchType.refCount++;
11683 ProcessExpressionType(stmt.caseStmt.exp);
11684 ComputeExpression(stmt.caseStmt.exp);
11686 if(stmt.caseStmt.stmt)
11687 ProcessStatement(stmt.caseStmt.stmt);
11691 if(stmt.compound.context)
11696 Statement prevCompound = curCompound;
11697 Context prevContext = curContext;
11699 if(!stmt.compound.isSwitch)
11700 curCompound = stmt;
11701 curContext = stmt.compound.context;
11703 if(stmt.compound.declarations)
11705 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11706 ProcessDeclaration(decl);
11708 if(stmt.compound.statements)
11710 for(s = stmt.compound.statements->first; s; s = s.next)
11711 ProcessStatement(s);
11714 curContext = prevContext;
11715 curCompound = prevCompound;
11719 case expressionStmt:
11722 if(stmt.expressions)
11724 for(exp = stmt.expressions->first; exp; exp = exp.next)
11725 ProcessExpressionType(exp);
11733 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11734 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11735 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11736 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11738 ProcessExpressionType(exp);
11740 if(stmt.ifStmt.stmt)
11741 ProcessStatement(stmt.ifStmt.stmt);
11742 if(stmt.ifStmt.elseStmt)
11743 ProcessStatement(stmt.ifStmt.elseStmt);
11748 Type oldSwitchType = curSwitchType;
11749 if(stmt.switchStmt.exp)
11752 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11762 e.exp.destType = destType;
11765 ProcessExpressionType(exp);
11768 curSwitchType = exp.expType;
11771 ProcessStatement(stmt.switchStmt.stmt);
11772 curSwitchType = oldSwitchType;
11777 if(stmt.whileStmt.exp)
11781 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11782 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11783 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11784 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11786 ProcessExpressionType(exp);
11789 if(stmt.whileStmt.stmt)
11790 ProcessStatement(stmt.whileStmt.stmt);
11795 if(stmt.doWhile.exp)
11799 if(stmt.doWhile.exp->last)
11801 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11802 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11803 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11805 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11807 ProcessExpressionType(exp);
11810 if(stmt.doWhile.stmt)
11811 ProcessStatement(stmt.doWhile.stmt);
11817 if(stmt.forStmt.init)
11818 ProcessStatement(stmt.forStmt.init);
11820 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11822 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11823 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11824 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11827 if(stmt.forStmt.check)
11828 ProcessStatement(stmt.forStmt.check);
11829 if(stmt.forStmt.increment)
11831 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11832 ProcessExpressionType(exp);
11835 if(stmt.forStmt.stmt)
11836 ProcessStatement(stmt.forStmt.stmt);
11841 Identifier id = stmt.forEachStmt.id;
11842 OldList * exp = stmt.forEachStmt.exp;
11843 OldList * filter = stmt.forEachStmt.filter;
11844 Statement block = stmt.forEachStmt.stmt;
11845 char iteratorType[1024];
11848 bool isBuiltin = exp && exp->last &&
11849 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11850 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11851 Expression arrayExp;
11852 const char * typeString = null;
11853 int builtinCount = 0;
11855 for(e = exp ? exp->first : null; e; e = e.next)
11859 FreeType(e.destType);
11860 e.destType = ProcessTypeString("Container", false);
11862 if(!isBuiltin || e.next)
11863 ProcessExpressionType(e);
11866 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11867 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11868 eClass_IsDerived(source._class.registered, containerClass)))
11870 Class _class = source ? source._class.registered : null;
11872 Expression expIt = null;
11873 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
11874 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11875 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11876 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11877 stmt.type = compoundStmt;
11879 stmt.compound.context = Context { };
11880 stmt.compound.context.parent = curContext;
11881 curContext = stmt.compound.context;
11883 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11885 Class mapClass = eSystem_FindClass(privateModule, "Map");
11886 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11887 isCustomAVLTree = true;
11888 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
11890 else */if(eClass_IsDerived(source._class.registered, mapClass))
11893 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11894 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11896 Class listClass = eSystem_FindClass(privateModule, "List");
11898 isList = eClass_IsDerived(source._class.registered, listClass);
11904 OldList * specs = MkList();
11905 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11906 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11907 stmt.compound.declarations = MkListOne(
11908 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11909 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11910 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11911 MkInitializerAssignment(MkExpBrackets(exp))))));
11916 char typeStringBuf[1024];
11918 // TODO: Merge this code?
11919 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11920 if(((Expression)exp->last).type == castExp)
11922 TypeName typeName = ((Expression)exp->last).cast.typeName;
11924 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11927 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11928 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11929 arrayExp.destType._class.registered.templateArgs)
11931 Class templateClass = arrayExp.destType._class.registered;
11932 typeString = templateClass.templateArgs[2].dataTypeString;
11934 else if(arrayExp.list)
11936 // Guess type from expressions in the array
11938 for(e = arrayExp.list->first; e; e = e.next)
11940 ProcessExpressionType(e);
11943 if(!type) { type = e.expType; type.refCount++; }
11946 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11947 if(!MatchTypeExpression(e, type, null, false, true))
11953 e = arrayExp.list->first;
11954 ProcessExpressionType(e);
11957 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11958 if(!MatchTypeExpression(e, type, null, false, true))
11960 FreeType(e.expType);
11971 FreeType(e.expType);
11978 typeStringBuf[0] = '\0';
11979 PrintType(type, typeStringBuf, false, true);
11980 typeString = typeStringBuf;
11986 OldList * initializers = MkList();
11988 OldList * specs = MkList();
11993 builtinCount = arrayExp.list->count;
11994 type = ProcessTypeString(typeString, false);
11995 while((e = arrayExp.list->first))
11997 arrayExp.list->Remove(e);
12000 ProcessExpressionType(e);
12001 ListAdd(initializers, MkInitializerAssignment(e));
12004 delete arrayExp.list;
12006 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12007 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12008 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12010 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12012 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12013 ), MkInitializerList(initializers)))));
12014 FreeList(exp, FreeExpression);
12018 arrayExp.expType = ProcessTypeString("Container", false);
12019 Compiler_Error($"Couldn't determine type of array elements\n");
12024 OldList * specs = MkList();
12026 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12027 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12028 stmt.compound.declarations = MkListOne(
12029 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12030 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12031 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12032 MkInitializerAssignment(MkExpBrackets(exp))))));
12035 else if(isLinkList && !isList)
12038 OldList * specs = MkList();
12039 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12040 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12041 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12042 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12043 MkInitializerAssignment(MkExpBrackets(exp))))));
12045 /*else if(isCustomAVLTree)
12048 OldList * specs = MkList();
12049 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12050 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12051 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12052 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12053 MkInitializerAssignment(MkExpBrackets(exp))))));
12055 else if(_class.templateArgs)
12058 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12060 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12062 stmt.compound.declarations = MkListOne(
12063 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12064 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12065 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12067 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12071 // Reparent sub-contexts in this statement
12075 if(block.compound.context)
12076 block.compound.context.parent = stmt.compound.context;
12079 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12080 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12081 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12082 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12085 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12086 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12089 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12090 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12093 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12094 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12097 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12098 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12101 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12102 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12104 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12107 case expressionStmt:
12113 case badDeclarationStmt:
12114 case fireWatchersStmt:
12115 case stopWatchingStmt:
12122 block = MkIfStmt(filter, block, null);
12126 stmt.compound.statements = MkListOne(MkForStmt(
12127 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12128 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12129 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12130 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12132 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12133 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12134 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12139 //OldList * specs = MkList();
12140 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12142 sprintf(count, "%d", builtinCount);
12144 stmt.compound.statements = MkListOne(MkForStmt(
12145 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12146 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12147 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12148 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12152 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12153 stmt.compound.statements = MkListOne(MkForStmt(
12154 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12155 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12156 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12157 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12160 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12161 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12162 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12164 else if(isLinkList && !isList)
12166 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12167 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12168 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12169 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12171 stmt.compound.statements = MkListOne(MkForStmt(
12172 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12173 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12174 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12179 OldList * specs = MkList();
12180 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12181 stmt.compound.statements = MkListOne(MkForStmt(
12182 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12183 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12184 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12185 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12186 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12189 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12190 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12191 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12193 /*else if(isCustomAVLTree)
12195 stmt.compound.statements = MkListOne(MkForStmt(
12196 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12197 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12198 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12199 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12202 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12203 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12204 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12208 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12209 MkIdentifier("Next")), null)), block));
12211 ProcessExpressionType(expIt);
12212 if(stmt.compound.declarations->first)
12213 ProcessDeclaration(stmt.compound.declarations->first);
12216 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12218 ProcessStatement(stmt);
12219 curContext = stmt.compound.context.parent;
12224 Compiler_Error($"Expression is not a container\n");
12237 if(stmt.expressions)
12239 for(exp = stmt.expressions->first; exp; exp = exp.next)
12243 if(curFunction && !curFunction.type)
12244 curFunction.type = ProcessType(
12245 curFunction.specifiers, curFunction.declarator);
12246 FreeType(exp.destType);
12247 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12248 if(exp.destType) exp.destType.refCount++;
12250 ProcessExpressionType(exp);
12255 case badDeclarationStmt:
12257 ProcessDeclaration(stmt.decl);
12263 if(stmt.asmStmt.inputFields)
12265 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12266 if(field.expression)
12267 ProcessExpressionType(field.expression);
12269 if(stmt.asmStmt.outputFields)
12271 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12272 if(field.expression)
12273 ProcessExpressionType(field.expression);
12275 if(stmt.asmStmt.clobberedFields)
12277 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12279 if(field.expression)
12280 ProcessExpressionType(field.expression);
12287 PropertyWatch propWatch;
12288 OldList * watches = stmt._watch.watches;
12289 Expression object = stmt._watch.object;
12290 Expression watcher = stmt._watch.watcher;
12292 ProcessExpressionType(watcher);
12294 ProcessExpressionType(object);
12298 if(watcher || thisClass)
12300 External external = curExternal;
12301 Context context = curContext;
12303 stmt.type = expressionStmt;
12304 stmt.expressions = MkList();
12306 curExternal = external.prev;
12308 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12310 ClassFunction func;
12311 char watcherName[1024];
12312 Class watcherClass = watcher ?
12313 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12314 External createdExternal;
12316 // Create a declaration above
12317 External externalDecl = MkExternalDeclaration(null);
12318 ast->Insert(curExternal.prev, externalDecl);
12320 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12321 if(propWatch.deleteWatch)
12322 strcat(watcherName, "_delete");
12326 for(propID = propWatch.properties->first; propID; propID = propID.next)
12328 strcat(watcherName, "_");
12329 strcat(watcherName, propID.string);
12333 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12335 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12336 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12337 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12338 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12339 ProcessClassFunctionBody(func, propWatch.compound);
12340 propWatch.compound = null;
12342 //afterExternal = afterExternal ? afterExternal : curExternal;
12344 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12345 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12347 createdExternal.symbol.idCode = external.symbol.idCode;
12349 curExternal = createdExternal;
12350 ProcessFunction(createdExternal.function);
12353 // Create a declaration above
12355 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12356 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12357 externalDecl.declaration = decl;
12358 if(decl.symbol && !decl.symbol.pointerExternal)
12359 decl.symbol.pointerExternal = externalDecl;
12362 if(propWatch.deleteWatch)
12364 OldList * args = MkList();
12365 ListAdd(args, CopyExpression(object));
12366 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12367 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12368 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12372 Class _class = object.expType._class.registered;
12375 for(propID = propWatch.properties->first; propID; propID = propID.next)
12377 char propName[1024];
12378 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12381 char getName[1024], setName[1024];
12382 OldList * args = MkList();
12384 DeclareProperty(prop, setName, getName);
12386 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12387 strcpy(propName, "__ecereProp_");
12388 FullClassNameCat(propName, prop._class.fullName, false);
12389 strcat(propName, "_");
12390 // strcat(propName, prop.name);
12391 FullClassNameCat(propName, prop.name, true);
12393 ListAdd(args, CopyExpression(object));
12394 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12395 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12396 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12398 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12401 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12406 Compiler_Error($"Invalid watched object\n");
12409 curExternal = external;
12410 curContext = context;
12413 FreeExpression(watcher);
12415 FreeExpression(object);
12416 FreeList(watches, FreePropertyWatch);
12419 Compiler_Error($"No observer specified and not inside a _class\n");
12423 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12425 ProcessStatement(propWatch.compound);
12431 case fireWatchersStmt:
12433 OldList * watches = stmt._watch.watches;
12434 Expression object = stmt._watch.object;
12436 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12437 // printf("%X\n", watches);
12438 // printf("%X\n", stmt._watch.watches);
12440 ProcessExpressionType(object);
12445 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12451 stmt.type = expressionStmt;
12452 stmt.expressions = MkList();
12454 // Check if we're inside a property set
12455 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12457 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12461 //Compiler_Error($"No property specified and not inside a property set\n");
12465 for(propID = watches->first; propID; propID = propID.next)
12467 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12470 CreateFireWatcher(prop, object, stmt);
12473 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12478 // Fire all properties!
12481 for(base = _class; base; base = base.base)
12483 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12485 if(prop.isProperty && prop.isWatchable)
12487 CreateFireWatcher(prop, object, stmt);
12494 FreeExpression(object);
12495 FreeList(watches, FreeIdentifier);
12498 Compiler_Error($"Invalid object specified and not inside a class\n");
12502 case stopWatchingStmt:
12504 OldList * watches = stmt._watch.watches;
12505 Expression object = stmt._watch.object;
12506 Expression watcher = stmt._watch.watcher;
12509 ProcessExpressionType(object);
12511 ProcessExpressionType(watcher);
12514 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12516 if(watcher || thisClass)
12522 stmt.type = expressionStmt;
12523 stmt.expressions = MkList();
12528 // eInstance_StopWatching(object, null, watcher);
12530 ListAdd(args, CopyExpression(object));
12531 ListAdd(args, MkExpConstant("0"));
12532 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12533 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12537 for(propID = watches->first; propID; propID = propID.next)
12539 char propName[1024];
12540 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12543 char getName[1024], setName[1024];
12544 OldList * args = MkList();
12546 DeclareProperty(prop, setName, getName);
12548 // eInstance_StopWatching(object, prop, watcher);
12549 strcpy(propName, "__ecereProp_");
12550 FullClassNameCat(propName, prop._class.fullName, false);
12551 strcat(propName, "_");
12552 // strcat(propName, prop.name);
12553 FullClassNameCat(propName, prop.name, true);
12554 //MangleClassName(propName);
12556 ListAdd(args, CopyExpression(object));
12557 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12558 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12559 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12562 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12567 FreeExpression(object);
12569 FreeExpression(watcher);
12570 FreeList(watches, FreeIdentifier);
12573 Compiler_Error($"Invalid object specified and not inside a class\n");
12576 Compiler_Error($"No observer specified and not inside a class\n");
12583 static void ProcessFunction(FunctionDefinition function)
12585 Identifier id = GetDeclId(function.declarator);
12586 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12587 Type type = symbol ? symbol.type : null;
12588 Class oldThisClass = thisClass;
12589 Context oldTopContext = topContext;
12591 yylloc = function.loc;
12592 // Process thisClass
12594 if(type && type.thisClass)
12596 Symbol classSym = type.thisClass;
12597 Class _class = type.thisClass.registered;
12598 char className[1024];
12599 char structName[1024];
12600 Declarator funcDecl;
12603 bool typedObject = false;
12605 if(_class && !_class.base)
12607 _class = currentClass;
12608 if(_class && !_class.symbol)
12609 _class.symbol = FindClass(_class.fullName);
12610 classSym = _class ? _class.symbol : null;
12611 typedObject = true;
12614 thisClass = _class;
12616 if(inCompiler && _class)
12618 if(type.kind == functionType)
12620 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12622 //TypeName param = symbol.type.params.first;
12623 Type param = symbol.type.params.first;
12624 symbol.type.params.Remove(param);
12625 //FreeTypeName(param);
12628 if(type.classObjectType != classPointer)
12630 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12631 symbol.type.staticMethod = true;
12632 symbol.type.thisClass = null;
12634 // HIGH DANGER: VERIFYING THIS...
12635 symbol.type.extraParam = false;
12639 strcpy(className, "__ecereClass_");
12640 FullClassNameCat(className, _class.fullName, true);
12642 //MangleClassName(className);
12645 FullClassNameCat(structName, _class.fullName, false);
12650 funcDecl = GetFuncDecl(function.declarator);
12653 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12655 TypeName param = funcDecl.function.parameters->first;
12656 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12658 funcDecl.function.parameters->Remove(param);
12659 FreeTypeName(param);
12663 // DANGER: Watch for this... Check if it's a Conversion?
12664 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12666 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12667 if(!function.propertyNoThis)
12669 TypeName thisParam;
12671 if(type.classObjectType != classPointer)
12673 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12674 if(!funcDecl.function.parameters)
12675 funcDecl.function.parameters = MkList();
12676 funcDecl.function.parameters->Insert(null, thisParam);
12681 if(type.classObjectType != classPointer)
12683 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12684 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12687 thisParam = TypeName
12689 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12690 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12692 funcDecl.function.parameters->Insert(null, thisParam);
12697 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12699 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12700 funcDecl = GetFuncDecl(initDecl.declarator);
12703 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12705 TypeName param = funcDecl.function.parameters->first;
12706 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12708 funcDecl.function.parameters->Remove(param);
12709 FreeTypeName(param);
12713 if(type.classObjectType != classPointer)
12715 // DANGER: Watch for this... Check if it's a Conversion?
12716 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12718 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12720 if(!funcDecl.function.parameters)
12721 funcDecl.function.parameters = MkList();
12722 funcDecl.function.parameters->Insert(null, thisParam);
12729 // Add this to the context
12732 if(type.classObjectType != classPointer)
12734 thisSymbol = Symbol
12736 string = CopyString("this");
12737 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12739 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12741 if(typedObject && thisSymbol.type)
12743 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12744 thisSymbol.type.byReference = type.byReference;
12745 thisSymbol.type.typedByReference = type.byReference;
12747 thisSymbol = Symbol { string = CopyString("class") };
12748 function.body.compound.context.symbols.Add(thisSymbol);
12754 // Pointer to class data
12756 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12758 DataMember member = null;
12761 for(base = _class; base && base.type != systemClass; base = base.next)
12763 for(member = base.membersAndProperties.first; member; member = member.next)
12764 if(!member.isProperty)
12770 for(member = _class.membersAndProperties.first; member; member = member.next)
12771 if(!member.isProperty)
12775 char pointerName[1024];
12778 Initializer initializer;
12779 Expression exp, bytePtr;
12781 strcpy(pointerName, "__ecerePointer_");
12782 FullClassNameCat(pointerName, _class.fullName, false);
12784 char className[1024];
12785 strcpy(className, "__ecereClass_");
12786 FullClassNameCat(className, classSym.string, true);
12787 //MangleClassName(className);
12790 DeclareClass(classSym, className);
12794 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12799 sprintf(string, "%d", _class.offset);
12800 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12804 // ([bytePtr] + [className]->offset)
12805 exp = QBrackets(MkExpOp(bytePtr, '+',
12806 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12809 // (this ? [exp] : 0)
12810 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12814 kind = pointerType;
12815 type = Type { refCount = 1, kind = voidType };
12820 yylloc = function.body.loc;
12821 // ([structName] *) [exp]
12822 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12823 initializer = MkInitializerAssignment(
12824 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12826 // [structName] * [pointerName] = [initializer];
12827 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12830 Context prevContext = curContext;
12831 curContext = function.body.compound.context;
12833 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12834 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12836 curContext = prevContext;
12840 decl.symbol = null;
12842 if(!function.body.compound.declarations)
12843 function.body.compound.declarations = MkList();
12844 function.body.compound.declarations->Insert(null, decl);
12850 // Loop through the function and replace undeclared identifiers
12851 // which are a member of the class (methods, properties or data)
12852 // by "this.[member]"
12859 FreeSpecifier(id._class);
12862 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12864 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12865 id = GetDeclId(initDecl.declarator);
12867 FreeSpecifier(id._class);
12872 topContext = function.body.compound.context;
12874 FunctionDefinition oldFunction = curFunction;
12875 curFunction = function;
12877 ProcessStatement(function.body);
12879 // If this is a property set and no firewatchers has been done yet, add one here
12880 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12882 Statement prevCompound = curCompound;
12883 Context prevContext = curContext;
12885 Statement fireWatchers = MkFireWatchersStmt(null, null);
12886 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12887 ListAdd(function.body.compound.statements, fireWatchers);
12889 curCompound = function.body;
12890 curContext = function.body.compound.context;
12892 ProcessStatement(fireWatchers);
12894 curContext = prevContext;
12895 curCompound = prevCompound;
12899 curFunction = oldFunction;
12902 if(function.declarator)
12904 ProcessDeclarator(function.declarator);
12907 topContext = oldTopContext;
12908 thisClass = oldThisClass;
12911 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12912 static void ProcessClass(OldList definitions, Symbol symbol)
12915 External external = curExternal;
12916 Class regClass = symbol ? symbol.registered : null;
12918 // Process all functions
12919 for(def = definitions.first; def; def = def.next)
12921 if(def.type == functionClassDef)
12923 if(def.function.declarator)
12924 curExternal = def.function.declarator.symbol.pointerExternal;
12926 curExternal = external;
12928 ProcessFunction((FunctionDefinition)def.function);
12930 else if(def.type == declarationClassDef)
12932 if(def.decl.type == instDeclaration)
12934 thisClass = regClass;
12935 ProcessInstantiationType(def.decl.inst);
12941 Class backThisClass = thisClass;
12942 if(regClass) thisClass = regClass;
12943 ProcessDeclaration(def.decl);
12944 thisClass = backThisClass;
12947 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12949 MemberInit defProperty;
12951 // Add this to the context
12952 Symbol thisSymbol = Symbol
12954 string = CopyString("this");
12955 type = regClass ? MkClassType(regClass.fullName) : null;
12957 globalContext.symbols.Add((BTNode)thisSymbol);
12959 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12961 thisClass = regClass;
12962 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12966 globalContext.symbols.Remove((BTNode)thisSymbol);
12967 FreeSymbol(thisSymbol);
12969 else if(def.type == propertyClassDef && def.propertyDef)
12971 PropertyDef prop = def.propertyDef;
12973 // Add this to the context
12975 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12976 globalContext.symbols.Add(thisSymbol);
12979 thisClass = regClass;
12986 string = CopyString("this");
12987 type = MkClassType(regClass.fullName);
12989 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12992 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12993 ProcessStatement(prop.setStmt);
13001 string = CopyString("this");
13002 type = MkClassType(regClass.fullName);
13004 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13007 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13008 ProcessStatement(prop.getStmt);
13016 string = CopyString("this");
13017 type = MkClassType(regClass.fullName);
13019 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13022 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13023 ProcessStatement(prop.issetStmt);
13029 globalContext.symbols.Remove(thisSymbol);
13030 FreeSymbol(thisSymbol);
13033 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13035 PropertyWatch propertyWatch = def.propertyWatch;
13037 thisClass = regClass;
13038 if(propertyWatch.compound)
13042 string = CopyString("this");
13043 type = regClass ? MkClassType(regClass.fullName) : null;
13046 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13048 curExternal = null;
13049 ProcessStatement(propertyWatch.compound);
13056 void DeclareFunctionUtil(const String s)
13058 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13063 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13064 strcpy(name, "__ecereFunction_");
13065 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13066 DeclareFunction(function, name);
13070 void ComputeDataTypes()
13074 External after = null;
13076 currentClass = null;
13078 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13080 for(external = ast->first; external; external = external.next)
13082 if(external.type == declarationExternal)
13084 Declaration decl = external.declaration;
13087 OldList * decls = decl.declarators;
13090 InitDeclarator initDecl = decls->first;
13093 Declarator declarator = initDecl.declarator;
13094 if(declarator && declarator.type == identifierDeclarator)
13096 Identifier id = declarator.identifier;
13097 if(id && id.string)
13099 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
13101 external.symbol.id = -1001, external.symbol.idCode = -1001;
13113 // Workaround until we have proper toposort for declarations reordering
13114 External e = MkExternalDeclaration(MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Instance"), null)), null));
13115 ast->Insert(after, e);
13119 temp.symbol = Symbol { id = -1000, idCode = -1000 };
13120 ast->Insert(after, temp);
13121 curExternal = temp;
13123 DeclareFunctionUtil("eSystem_New");
13124 DeclareFunctionUtil("eSystem_New0");
13125 DeclareFunctionUtil("eSystem_Renew");
13126 DeclareFunctionUtil("eSystem_Renew0");
13127 DeclareFunctionUtil("eSystem_Delete");
13128 DeclareFunctionUtil("eClass_GetProperty");
13129 DeclareFunctionUtil("eClass_SetProperty");
13130 DeclareFunctionUtil("eInstance_FireSelfWatchers");
13131 DeclareFunctionUtil("eInstance_SetMethod");
13132 DeclareFunctionUtil("eInstance_IncRef");
13133 DeclareFunctionUtil("eInstance_StopWatching");
13134 DeclareFunctionUtil("eInstance_Watch");
13135 DeclareFunctionUtil("eInstance_FireWatchers");
13137 DeclareStruct("ecere::com::Class", false);
13138 DeclareStruct("ecere::com::Instance", false);
13139 DeclareStruct("ecere::com::Property", false);
13140 DeclareStruct("ecere::com::DataMember", false);
13141 DeclareStruct("ecere::com::Method", false);
13142 DeclareStruct("ecere::com::SerialBuffer", false);
13143 DeclareStruct("ecere::com::ClassTemplateArgument", false);
13147 for(external = ast->first; external; external = external.next)
13149 afterExternal = curExternal = external;
13150 if(external.type == functionExternal)
13152 currentClass = external.function._class;
13153 ProcessFunction(external.function);
13155 // There shouldn't be any _class member access here anyways...
13156 else if(external.type == declarationExternal)
13158 currentClass = null;
13159 if(external.declaration)
13160 ProcessDeclaration(external.declaration);
13162 else if(external.type == classExternal)
13164 ClassDefinition _class = external._class;
13165 currentClass = external.symbol.registered;
13166 if(_class.definitions)
13168 ProcessClass(_class.definitions, _class.symbol);
13172 // Free class data...
13173 ast->Remove(external);
13177 else if(external.type == nameSpaceExternal)
13179 thisNameSpace = external.id.string;
13182 currentClass = null;
13183 thisNameSpace = null;
13184 curExternal = null;
13186 delete temp.symbol;