4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
37 uint internalValueCounter;
40 Time findSymbolTotalTime;
43 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
44 /*static */public void PrintExpression(Expression exp, char * string)
50 bool backOutputLineNumbers = outputLineNumbers;
51 outputLineNumbers = false;
54 OutputExpression(exp, f);
56 count = strlen(string);
57 count += f.Read(string + count, 1, 1023);
61 outputLineNumbers = backOutputLineNumbers;
65 Type ProcessTemplateParameterType(TemplateParameter param)
67 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
69 // TOFIX: Will need to free this Type
72 if(param.dataTypeString)
73 param.baseType = ProcessTypeString(param.dataTypeString, false);
75 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
77 return param.baseType;
82 bool NeedCast(Type type1, Type type2)
84 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
86 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
91 if(type1.kind == type2.kind)
102 if(type1.passAsTemplate && !type2.passAsTemplate)
104 return type1.isSigned != type2.isSigned;
106 return type1._class != type2._class;
108 return (type1.type && type2.type && type1.type.constant != type2.type.constant) || NeedCast(type1.type, type2.type);
110 return true; //false; ????
116 static void ReplaceClassMembers(Expression exp, Class _class)
118 if(exp.type == identifierExp && exp.identifier)
120 Identifier id = exp.identifier;
122 Symbol symbol = null;
123 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
125 // First, check if the identifier is declared inside the function
126 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
128 symbol = (Symbol)ctx.symbols.FindString(id.string);
133 // If it is not, check if it is a member of the _class
134 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
136 Property prop = eClass_FindProperty(_class, id.string, privateModule);
137 Method method = null;
138 DataMember member = null;
139 ClassProperty classProp = null;
142 method = eClass_FindMethod(_class, id.string, privateModule);
145 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
146 if(!prop && !method && !member)
148 classProp = eClass_FindClassProperty(_class, id.string);
150 if(prop || method || member || classProp)
152 // Replace by this.[member]
153 exp.type = memberExp;
154 exp.member.member = id;
155 exp.member.memberType = unresolvedMember;
156 exp.member.exp = QMkExpId("this");
157 //exp.member.exp.loc = exp.loc;
158 exp.addedThis = true;
160 else if(_class && _class.templateParams.first)
163 for(sClass = _class; sClass; sClass = sClass.base)
165 if(sClass.templateParams.first)
167 ClassTemplateParameter param;
168 for(param = sClass.templateParams.first; param; param = param.next)
170 if(param.type == expression && !strcmp(param.name, id.string))
172 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
177 OldList * specs = MkList();
179 FreeIdentifier(exp.member.member);
181 ProcessExpressionType(argExp);
183 decl = SpecDeclFromString(param.dataTypeString, specs, null);
185 exp.expType = ProcessType(specs, decl);
187 // *[expType] *[argExp]
188 exp.type = bracketsExp;
189 exp.list = MkListOne(MkExpOp(null, '*',
190 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
201 ////////////////////////////////////////////////////////////////////////
202 // PRINTING ////////////////////////////////////////////////////////////
203 ////////////////////////////////////////////////////////////////////////
205 public char * PrintInt(int64 result)
209 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
211 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
212 if(result > MAXINT || result < MININT)
214 return CopyString(temp);
217 public char * PrintUInt(uint64 result)
220 if(result > MAXDWORD)
221 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
222 else if(result > MAXINT)
223 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
225 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
226 return CopyString(temp);
229 public char * PrintInt64(int64 result)
232 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
233 return CopyString(temp);
236 public char * PrintUInt64(uint64 result)
239 if(result > MAXINT64)
240 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
242 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
243 return CopyString(temp);
246 public char * PrintHexUInt(uint64 result)
249 if(result > MAXDWORD)
250 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
252 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
253 if(result > MAXDWORD)
255 return CopyString(temp);
258 public char * PrintHexUInt64(uint64 result)
261 if(result > MAXDWORD)
262 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
264 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
265 return CopyString(temp);
268 public char * PrintShort(short result)
271 sprintf(temp, "%d", (unsigned short)result);
272 return CopyString(temp);
275 public char * PrintUShort(unsigned short result)
279 sprintf(temp, "0x%X", (int)result);
281 sprintf(temp, "%d", (int)result);
282 return CopyString(temp);
285 public char * PrintChar(char result)
288 if(result > 0 && isprint(result))
289 sprintf(temp, "'%c'", result);
291 sprintf(temp, "%d", (int)result);
293 //sprintf(temp, "%#X", result);
294 sprintf(temp, "0x%X", (unsigned char)result);
295 return CopyString(temp);
298 public char * PrintUChar(unsigned char result)
301 sprintf(temp, "0x%X", result);
302 return CopyString(temp);
305 public char * PrintFloat(float result)
311 strcpy(temp, "-inf");
315 else if(result.isNan)
318 strcpy(temp, "-nan");
323 sprintf(temp, "%.16ff", result);
324 return CopyString(temp);
327 public char * PrintDouble(double result)
333 strcpy(temp, "-inf");
337 else if(result.isNan)
340 strcpy(temp, "-nan");
345 sprintf(temp, "%.16f", result);
346 return CopyString(temp);
349 ////////////////////////////////////////////////////////////////////////
350 ////////////////////////////////////////////////////////////////////////
352 //public Operand GetOperand(Expression exp);
354 #define GETVALUE(name, t) \
355 public bool GetOp##name(Operand op2, t * value2) \
357 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
358 else if(op2.kind == intType) *value2 = (t) op2.ui; \
359 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
360 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
361 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
362 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
363 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
364 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
365 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
366 else if(op2.kind == shortType) *value2 = (t) op2.us; \
367 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
368 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
369 else if(op2.kind == floatType) *value2 = (t) op2.f; \
370 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
371 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
376 public bool Get##name(Expression exp, t * value2) \
378 Operand op2 = GetOperand(exp); \
379 return GetOp##name(op2, value2); \
382 // To help the deubugger currently not preprocessing...
385 GETVALUE(Int, HELP(int));
386 GETVALUE(UInt, HELP(unsigned int));
387 GETVALUE(Int64, HELP(int64));
388 GETVALUE(UInt64, HELP(uint64));
389 GETVALUE(IntPtr, HELP(intptr));
390 GETVALUE(UIntPtr, HELP(uintptr));
391 GETVALUE(IntSize, HELP(intsize));
392 GETVALUE(UIntSize, HELP(uintsize));
393 GETVALUE(Short, HELP(short));
394 GETVALUE(UShort, HELP(unsigned short));
395 GETVALUE(Char, HELP(char));
396 GETVALUE(UChar, HELP(unsigned char));
397 GETVALUE(Float, HELP(float));
398 GETVALUE(Double, HELP(double));
400 void ComputeExpression(Expression exp);
402 void ComputeClassMembers(Class _class, bool isMember)
404 DataMember member = isMember ? (DataMember) _class : null;
405 Context context = isMember ? null : SetupTemplatesContext(_class);
406 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
407 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
409 int unionMemberOffset = 0;
413 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
414 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
419 member.memberOffset = 0;
420 if(targetBits < sizeof(void *) * 8)
421 member.structAlignment = 0;
423 else if(targetBits < sizeof(void *) * 8)
424 _class.structAlignment = 0;
426 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
427 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
428 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
430 if(!member && _class.destructionWatchOffset)
431 _class.memberOffset += sizeof(OldList);
433 // To avoid reentrancy...
434 //_class.structSize = -1;
437 DataMember dataMember;
438 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
440 if(!dataMember.isProperty)
442 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
444 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
445 /*if(!dataMember.dataType)
446 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
454 DataMember dataMember;
455 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
457 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
459 if(!isMember && _class.type == bitClass && dataMember.dataType)
461 BitMember bitMember = (BitMember) dataMember;
465 ComputeTypeSize(dataMember.dataType);
467 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
468 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
470 _class.memberOffset = bitMember.pos + bitMember.size;
471 for(d = 0; d<bitMember.size; d++)
477 bitMember.mask = mask << bitMember.pos;
479 else if(dataMember.type == normalMember && dataMember.dataType)
484 // Prevent infinite recursion
485 if(dataMember.dataType.kind != classType ||
486 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
487 _class.type != structClass)))
488 ComputeTypeSize(dataMember.dataType);
490 if(dataMember.dataType.bitFieldCount)
492 bitFields += dataMember.dataType.bitFieldCount;
499 int size = (bitFields + 7) / 8;
503 // TESTING THIS PADDING CODE
506 member.structAlignment = Max(member.structAlignment, alignment);
508 if(member.memberOffset % alignment)
509 member.memberOffset += alignment - (member.memberOffset % alignment);
512 dataMember.offset = member.memberOffset;
513 if(member.type == unionMember)
514 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
517 member.memberOffset += size;
522 // TESTING THIS PADDING CODE
525 _class.structAlignment = Max(_class.structAlignment, alignment);
527 if(_class.memberOffset % alignment)
528 _class.memberOffset += alignment - (_class.memberOffset % alignment);
531 dataMember.offset = _class.memberOffset;
532 _class.memberOffset += size;
536 size = dataMember.dataType.size;
537 alignment = dataMember.dataType.alignment;
542 // TESTING THIS PADDING CODE
545 member.structAlignment = Max(member.structAlignment, alignment);
547 if(member.memberOffset % alignment)
548 member.memberOffset += alignment - (member.memberOffset % alignment);
551 dataMember.offset = member.memberOffset;
552 if(member.type == unionMember)
553 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
556 member.memberOffset += size;
561 // TESTING THIS PADDING CODE
564 _class.structAlignment = Max(_class.structAlignment, alignment);
566 if(_class.memberOffset % alignment)
567 _class.memberOffset += alignment - (_class.memberOffset % alignment);
570 dataMember.offset = _class.memberOffset;
571 _class.memberOffset += size;
578 ComputeClassMembers((Class)dataMember, true);
579 alignment = dataMember.structAlignment;
585 if(member.memberOffset % alignment)
586 member.memberOffset += alignment - (member.memberOffset % alignment);
588 member.structAlignment = Max(member.structAlignment, alignment);
590 dataMember.offset = member.memberOffset;
591 if(member.type == unionMember)
592 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
594 member.memberOffset += dataMember.memberOffset;
600 if(_class.memberOffset % alignment)
601 _class.memberOffset += alignment - (_class.memberOffset % alignment);
602 _class.structAlignment = Max(_class.structAlignment, alignment);
604 dataMember.offset = _class.memberOffset;
605 _class.memberOffset += dataMember.memberOffset;
613 int size = (bitFields + 7) / 8;
617 // TESTING THIS PADDING CODE
620 member.structAlignment = Max(member.structAlignment, alignment);
622 if(member.memberOffset % alignment)
623 member.memberOffset += alignment - (member.memberOffset % alignment);
626 if(member.type == unionMember)
627 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
630 member.memberOffset += size;
635 // TESTING THIS PADDING CODE
638 _class.structAlignment = Max(_class.structAlignment, alignment);
640 if(_class.memberOffset % alignment)
641 _class.memberOffset += alignment - (_class.memberOffset % alignment);
643 _class.memberOffset += size;
648 if(member && member.type == unionMember)
650 member.memberOffset = unionMemberOffset;
655 /*if(_class.type == structClass)
656 _class.size = _class.memberOffset;
660 if(_class.type != bitClass)
663 if(_class.structAlignment)
665 if(_class.memberOffset % _class.structAlignment)
666 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
668 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
672 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
674 if(prop.isProperty && prop.isWatchable)
676 prop.watcherOffset = _class.structSize;
677 _class.structSize += sizeof(OldList);
685 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
687 Class deriv = derivative.data;
689 if(deriv.computeSize)
691 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
692 deriv.offset = /*_class.offset + */_class.structSize;
693 deriv.memberOffset = 0;
694 // ----------------------
696 deriv.structSize = deriv.offset;
698 ComputeClassMembers(deriv, false);
706 FinishTemplatesContext(context);
709 public void ComputeModuleClasses(Module module)
714 for(subModule = module.modules.first; subModule; subModule = subModule.next)
715 ComputeModuleClasses(subModule.data);
716 for(_class = module.classes.first; _class; _class = _class.next)
717 ComputeClassMembers(_class, false);
721 public int ComputeTypeSize(Type type)
723 uint size = type ? type.size : 0;
724 if(!size && type && !type.computing)
726 type.computing = true;
729 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
730 case charType: type.alignment = size = sizeof(char); break;
731 case intType: type.alignment = size = sizeof(int); break;
732 case int64Type: type.alignment = size = sizeof(int64); break;
733 case intPtrType: type.alignment = size = targetBits / 8; break;
734 case intSizeType: type.alignment = size = targetBits / 8; break;
735 case longType: type.alignment = size = sizeof(long); break;
736 case shortType: type.alignment = size = sizeof(short); break;
737 case floatType: type.alignment = size = sizeof(float); break;
738 case doubleType: type.alignment = size = sizeof(double); break;
741 Class _class = type._class ? type._class.registered : null;
743 if(_class && _class.type == structClass)
745 // Ensure all members are properly registered
746 ComputeClassMembers(_class, false);
747 type.alignment = _class.structAlignment;
748 size = _class.structSize;
749 if(type.alignment && size % type.alignment)
750 size += type.alignment - (size % type.alignment);
753 else if(_class && (_class.type == unitClass ||
754 _class.type == enumClass ||
755 _class.type == bitClass))
758 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
759 size = type.alignment = ComputeTypeSize(_class.dataType);
762 size = type.alignment = targetBits / 8; // sizeof(Instance *);
765 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
767 if(type.arraySizeExp)
769 ProcessExpressionType(type.arraySizeExp);
770 ComputeExpression(type.arraySizeExp);
771 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
772 type.arraySizeExp.expType.kind != shortType &&
773 type.arraySizeExp.expType.kind != charType &&
774 type.arraySizeExp.expType.kind != longType &&
775 type.arraySizeExp.expType.kind != int64Type &&
776 type.arraySizeExp.expType.kind != intSizeType &&
777 type.arraySizeExp.expType.kind != intPtrType &&
778 type.arraySizeExp.expType.kind != enumType &&
779 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
781 Location oldLoc = yylloc;
782 // bool isConstant = type.arraySizeExp.isConstant;
783 char expression[10240];
784 expression[0] = '\0';
785 type.arraySizeExp.expType = null;
786 yylloc = type.arraySizeExp.loc;
788 PrintExpression(type.arraySizeExp, expression);
789 Compiler_Error($"Array size not constant int (%s)\n", expression);
792 GetInt(type.arraySizeExp, &type.arraySize);
794 else if(type.enumClass)
796 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
798 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
805 // Unimplemented auto size
809 size = ComputeTypeSize(type.type) * type.arraySize;
811 type.alignment = type.type.alignment;
817 for(member = type.members.first; member; member = member.next)
819 uint addSize = ComputeTypeSize(member);
821 member.offset = size;
822 if(member.alignment && size % member.alignment)
823 member.offset += member.alignment - (size % member.alignment);
824 size = member.offset;
826 type.alignment = Max(type.alignment, member.alignment);
829 if(type.alignment && size % type.alignment)
830 size += type.alignment - (size % type.alignment);
836 for(member = type.members.first; member; member = member.next)
838 uint addSize = ComputeTypeSize(member);
840 member.offset = size;
841 if(member.alignment && size % member.alignment)
842 member.offset += member.alignment - (size % member.alignment);
843 size = member.offset;
845 type.alignment = Max(type.alignment, member.alignment);
846 size = Max(size, addSize);
848 if(type.alignment && size % type.alignment)
849 size += type.alignment - (size % type.alignment);
854 TemplateParameter param = type.templateParameter;
855 Type baseType = ProcessTemplateParameterType(param);
858 size = ComputeTypeSize(baseType);
859 type.alignment = baseType.alignment;
862 type.alignment = size = sizeof(uint64);
867 type.alignment = size = sizeof(enum { test });
872 type.alignment = size = targetBits / 8; //sizeof(void *);
877 type.computing = false;
883 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
885 // This function is in need of a major review when implementing private members etc.
886 DataMember topMember = isMember ? (DataMember) _class : null;
893 Context context = isMember ? null : SetupTemplatesContext(_class);
895 *addedPadding = false;
897 if(!isMember && _class.base)
899 maxSize = _class.structSize;
900 //if(_class.base.type != systemClass) // Commented out with new Instance _class
902 // DANGER: Testing this noHeadClass here...
903 if(_class.type == structClass || _class.type == noHeadClass)
904 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
907 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
908 if(maxSize > baseSize)
916 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
918 if(!member.isProperty)
924 if(member.dataTypeString)
926 OldList * specs = MkList(), * decls = MkList();
929 decl = SpecDeclFromString(member.dataTypeString, specs,
930 MkDeclaratorIdentifier(MkIdentifier(member.name)));
931 ListAdd(decls, MkStructDeclarator(decl, null));
932 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
935 member.dataType = ProcessType(specs, decl);
937 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
940 Type type = ProcessType(specs, decl);
941 DeclareType(member.dataType, false, false);
945 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
946 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
947 DeclareStruct(member.dataType._class.string, false);
950 ComputeTypeSize(member.dataType);
951 size = member.dataType.size;
952 alignment = member.dataType.alignment;
956 if(totalSize % alignment)
957 totalSize += alignment - (totalSize % alignment);
966 OldList * specs = MkList(), * list = MkList();
968 sprintf(id, "__anon%d", anonID++);
971 AddMembers(list, (Class)member, true, &size, topClass, null);
973 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
974 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
975 alignment = member.structAlignment;
979 if(totalSize % alignment)
980 totalSize += alignment - (totalSize % alignment);
990 if(topMember && topMember.type == unionMember)
991 *retSize = Max(*retSize, totalSize);
993 *retSize += totalSize;
995 else if(totalSize < maxSize && _class.type != systemClass)
998 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
999 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1000 if(totalSize + autoPadding < maxSize)
1002 char sizeString[50];
1003 sprintf(sizeString, "%d", maxSize - totalSize);
1004 ListAdd(declarations,
1005 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1006 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1008 *addedPadding = true;
1012 FinishTemplatesContext(context);
1013 return topMember ? topMember.memberID : _class.memberID;
1016 static int DeclareMembers(Class _class, bool isMember)
1018 DataMember topMember = isMember ? (DataMember) _class : null;
1020 Context context = isMember ? null : SetupTemplatesContext(_class);
1022 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1023 DeclareMembers(_class.base, false);
1025 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1027 if(!member.isProperty)
1034 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1035 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1036 DeclareStruct(member.dataType._class.string, false);
1038 if(!member.dataType && member.dataTypeString)
1039 member.dataType = ProcessTypeString(member.dataTypeString, false);
1041 DeclareType(member.dataType, false, false);
1047 DeclareMembers((Class)member, true);
1054 FinishTemplatesContext(context);
1056 return topMember ? topMember.memberID : _class.memberID;
1059 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1063 for(def = definitions->first; def; def = def.next)
1065 if(def.type == declarationClassDef)
1067 Declaration decl = def.decl;
1068 if(decl && decl.specifiers)
1071 bool isStruct = false;
1072 for(spec = decl.specifiers->first; spec; spec = spec.next)
1074 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1076 if(spec.definitions)
1077 IdentifyAnonStructs(spec.definitions);
1083 Declarator d = null;
1084 if(decl.declarators)
1086 for(d = decl.declarators->first; d; d = d.next)
1088 Identifier idDecl = GetDeclId(d);
1096 sprintf(id, "__anon%d", anonID++);
1097 if(!decl.declarators)
1098 decl.declarators = MkList();
1099 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1107 void DeclareStruct(const char * name, bool skipNoHead)
1109 External external = null;
1110 Symbol classSym = FindClass(name);
1112 if(!inCompiler || !classSym) return;
1114 // We don't need any declaration for bit classes...
1115 if(classSym.registered &&
1116 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1119 /*if(classSym.registered.templateClass)
1120 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1123 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1125 // Add typedef struct
1127 OldList * specifiers, * declarators;
1128 OldList * declarations = null;
1129 char structName[1024];
1130 Specifier spec = null;
1131 external = (classSym.registered && classSym.registered.type == structClass) ?
1132 classSym.pointerExternal : classSym.structExternal;
1134 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1135 // Moved this one up because DeclareClass done later will need it
1137 classSym.declaring++;
1139 if(strchr(classSym.string, '<'))
1141 if(classSym.registered.templateClass)
1143 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1144 classSym.declaring--;
1150 DeclareMembers(classSym.registered, false);
1153 FullClassNameCat(structName, name, false);
1155 if(external && external.declaration && external.declaration.specifiers)
1157 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1159 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1165 external = MkExternalDeclaration(null);*/
1167 if(!skipNoHead && (!spec || !spec.definitions))
1169 bool addedPadding = false;
1170 classSym.declaredStructSym = true;
1172 declarations = MkList();
1174 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1176 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1177 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1179 if(!declarations->count || (declarations->count == 1 && addedPadding))
1181 FreeList(declarations, FreeClassDef);
1182 declarations = null;
1185 if(skipNoHead || declarations)
1190 spec.definitions = declarations;
1192 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1195 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1198 if(classSym.structExternal)
1199 ast->Move(classSym.structExternal, curExternal.prev);
1200 ast->Move(classSym.pointerExternal, curExternal.prev);
1202 classSym.id = curExternal.symbol.idCode;
1203 classSym.idCode = curExternal.symbol.idCode;
1204 // external = classSym.pointerExternal;
1205 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1211 external = MkExternalDeclaration(null);
1213 specifiers = MkList();
1214 declarators = MkList();
1215 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1218 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1219 ListAdd(declarators, MkInitDeclarator(d, null));
1221 external.declaration = decl = MkDeclaration(specifiers, declarators);
1222 if(decl.symbol && !decl.symbol.pointerExternal)
1223 decl.symbol.pointerExternal = external;
1225 // For simple classes, keep the declaration as the external to move around
1226 if(classSym.registered && classSym.registered.type == structClass)
1228 char className[1024];
1229 strcpy(className, "__ecereClass_");
1230 FullClassNameCat(className, classSym.string, true);
1231 MangleClassName(className);
1234 DeclareClass(classSym, className);
1236 external.symbol = classSym;
1237 classSym.pointerExternal = external;
1238 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1239 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1243 char className[1024];
1244 strcpy(className, "__ecereClass_");
1245 FullClassNameCat(className, classSym.string, true);
1246 MangleClassName(className);
1248 // TOFIX: TESTING THIS...
1249 classSym.structExternal = external;
1250 DeclareClass(classSym, className);
1251 external.symbol = classSym;
1255 ast->Insert(curExternal ? curExternal.prev : null, external);
1259 classSym.declaring--;
1263 if(classSym.structExternal && classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1266 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1268 IdentifyAnonStructs(spec.definitions);
1272 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1274 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1275 // Moved this one up because DeclareClass done later will need it
1278 classSym.declaring++;
1282 if(classSym.registered)
1283 DeclareMembers(classSym.registered, false);
1286 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1289 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1292 if(classSym.structExternal)
1293 ast->Move(classSym.structExternal, curExternal.prev);
1294 ast->Move(classSym.pointerExternal, curExternal.prev);
1296 classSym.id = curExternal.symbol.idCode;
1297 classSym.idCode = curExternal.symbol.idCode;
1298 // external = classSym.pointerExternal;
1299 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1302 classSym.declaring--;
1308 void DeclareProperty(Property prop, char * setName, char * getName)
1310 Symbol symbol = prop.symbol;
1312 strcpy(setName, "__ecereProp_");
1313 FullClassNameCat(setName, prop._class.fullName, false);
1314 strcat(setName, "_Set_");
1315 // strcat(setName, prop.name);
1316 FullClassNameCat(setName, prop.name, true);
1317 MangleClassName(setName);
1319 strcpy(getName, "__ecereProp_");
1320 FullClassNameCat(getName, prop._class.fullName, false);
1321 strcat(getName, "_Get_");
1322 FullClassNameCat(getName, prop.name, true);
1323 // strcat(getName, prop.name);
1325 // To support "char *" property
1326 MangleClassName(getName);
1328 if(prop._class.type == structClass)
1329 DeclareStruct(prop._class.fullName, false);
1331 if(!symbol || curExternal.symbol.idCode < symbol.id)
1333 bool imported = false;
1334 bool dllImport = false;
1336 if(!symbol || symbol._import)
1341 if(!prop._class.symbol)
1342 prop._class.symbol = FindClass(prop._class.fullName);
1343 classSym = prop._class.symbol;
1344 if(classSym && !classSym._import)
1346 ModuleImport module;
1348 if(prop._class.module)
1349 module = FindModule(prop._class.module);
1351 module = mainModule;
1353 classSym._import = ClassImport
1355 name = CopyString(prop._class.fullName);
1356 isRemote = prop._class.isRemote;
1358 module.classes.Add(classSym._import);
1360 symbol = prop.symbol = Symbol { };
1361 symbol._import = (ClassImport)PropertyImport
1363 name = CopyString(prop.name);
1364 isVirtual = false; //prop.isVirtual;
1365 hasSet = prop.Set ? true : false;
1366 hasGet = prop.Get ? true : false;
1369 classSym._import.properties.Add(symbol._import);
1372 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1373 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1374 prop._class.module.importType != staticImport)
1380 Context context = SetupTemplatesContext(prop._class);
1381 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1382 FinishTemplatesContext(context);
1388 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1391 OldList * specifiers, * declarators;
1396 Declarator typeDecl;
1397 bool simple = false;
1399 specifiers = MkList();
1400 declarators = MkList();
1403 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1404 MkDeclaratorIdentifier(MkIdentifier("this"))));
1406 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1409 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1412 Context context = SetupTemplatesContext(prop._class);
1413 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1414 FinishTemplatesContext(context);
1417 // Make sure the simple _class's type is declared
1418 for(spec = specifiers->first; spec; spec = spec.next)
1420 if(spec.type == nameSpecifier /*SpecifierClass*/)
1422 if((!typeDecl || typeDecl.type == identifierDeclarator))
1424 Symbol classSym = spec.symbol; // FindClass(spec.name);
1425 symbol._class = classSym.registered;
1426 if(classSym.registered && classSym.registered.type == structClass)
1428 DeclareStruct(spec.name, false);
1436 d = PlugDeclarator(typeDecl, d);
1439 ListAdd(params, MkTypeName(specifiers,
1440 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1441 specifiers = MkList();
1444 d = MkDeclaratorFunction(d, params);
1448 specifiers->Insert(null, MkSpecifier(EXTERN));
1449 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1450 specifiers->Insert(null, MkSpecifier(STATIC));
1452 ListAdd(specifiers, MkSpecifier(VOID));
1454 ListAdd(declarators, MkInitDeclarator(d, null));
1456 decl = MkDeclaration(specifiers, declarators);
1458 external = MkExternalDeclaration(decl);
1459 ast->Insert(curExternal.prev, external);
1460 external.symbol = symbol;
1461 symbol.externalGet = external;
1463 ReplaceThisClassSpecifiers(specifiers, prop._class);
1466 FreeDeclarator(typeDecl);
1470 // Move declaration higher...
1471 ast->Move(symbol.externalGet, curExternal.prev);
1478 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1481 OldList * specifiers, * declarators;
1486 Declarator typeDecl;
1488 declarators = MkList();
1491 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1492 if(!prop.conversion || prop._class.type == structClass)
1494 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1495 MkDeclaratorIdentifier(MkIdentifier("this"))));
1498 specifiers = MkList();
1501 Context context = SetupTemplatesContext(prop._class);
1502 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1503 MkDeclaratorIdentifier(MkIdentifier("value")));
1504 FinishTemplatesContext(context);
1506 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1507 specifiers->Insert(null, MkSpecifier(CONST));
1509 ListAdd(params, MkTypeName(specifiers, d));
1511 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1514 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1515 d = MkDeclaratorFunction(d, params);
1517 // Make sure the simple _class's type is declared
1518 for(spec = specifiers->first; spec; spec = spec.next)
1520 if(spec.type == nameSpecifier /*SpecifierClass*/)
1522 if((!typeDecl || typeDecl.type == identifierDeclarator))
1524 Symbol classSym = spec.symbol; // FindClass(spec.name);
1525 symbol._class = classSym.registered;
1526 if(classSym.registered && classSym.registered.type == structClass)
1527 DeclareStruct(spec.name, false);
1532 ListAdd(declarators, MkInitDeclarator(d, null));
1534 specifiers = MkList();
1537 specifiers->Insert(null, MkSpecifier(EXTERN));
1538 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1539 specifiers->Insert(null, MkSpecifier(STATIC));
1541 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1542 if(!prop.conversion || prop._class.type == structClass)
1543 ListAdd(specifiers, MkSpecifier(VOID));
1545 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1547 decl = MkDeclaration(specifiers, declarators);
1549 external = MkExternalDeclaration(decl);
1550 ast->Insert(curExternal.prev, external);
1551 external.symbol = symbol;
1552 symbol.externalSet = external;
1554 ReplaceThisClassSpecifiers(specifiers, prop._class);
1558 // Move declaration higher...
1559 ast->Move(symbol.externalSet, curExternal.prev);
1563 // Property (for Watchers)
1564 if(!symbol.externalPtr)
1568 OldList * specifiers = MkList();
1569 char propName[1024];
1572 specifiers->Insert(null, MkSpecifier(EXTERN));
1574 specifiers->Insert(null, MkSpecifier(STATIC));
1576 ListAdd(specifiers, MkSpecifierName("Property"));
1578 strcpy(propName, "__ecereProp_");
1579 FullClassNameCat(propName, prop._class.fullName, false);
1580 strcat(propName, "_");
1581 FullClassNameCat(propName, prop.name, true);
1582 // strcat(propName, prop.name);
1583 MangleClassName(propName);
1586 OldList * list = MkList();
1587 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1588 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1592 strcpy(propName, "__ecerePropM_");
1593 FullClassNameCat(propName, prop._class.fullName, false);
1594 strcat(propName, "_");
1595 // strcat(propName, prop.name);
1596 FullClassNameCat(propName, prop.name, true);
1598 MangleClassName(propName);
1600 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1601 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1603 decl = MkDeclaration(specifiers, list);
1606 external = MkExternalDeclaration(decl);
1607 ast->Insert(curExternal.prev, external);
1608 external.symbol = symbol;
1609 symbol.externalPtr = external;
1613 // Move declaration higher...
1614 ast->Move(symbol.externalPtr, curExternal.prev);
1617 symbol.id = curExternal.symbol.idCode;
1621 // ***************** EXPRESSION PROCESSING ***************************
1622 public Type Dereference(Type source)
1627 if(source.kind == pointerType || source.kind == arrayType)
1630 source.type.refCount++;
1632 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1640 // Support dereferencing of no head classes for now...
1641 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1647 Compiler_Error($"cannot dereference type\n");
1652 static Type Reference(Type source)
1668 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1670 Identifier ident = member.identifiers ? member.identifiers->first : null;
1672 DataMember dataMember = null;
1673 Method method = null;
1674 bool freeType = false;
1676 yylloc = member.loc;
1682 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1686 dataMember = *curMember;
1692 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1693 DataMember _subMemberStack[256];
1694 int _subMemberStackPos = 0;
1696 // FILL MEMBER STACK
1698 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1701 dataMember = thisMember;
1702 if(curMember && thisMember.memberAccess == publicAccess)
1704 *curMember = thisMember;
1705 *curClass = thisMember._class;
1706 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1707 *subMemberStackPos = _subMemberStackPos;
1714 method = eClass_FindMethod(_class, ident.string, privateModule);
1715 if(method && method.type == virtualMethod)
1727 if(!dataMember.dataType && dataMember.dataTypeString)
1729 //Context context = SetupTemplatesContext(dataMember._class);
1730 Context context = SetupTemplatesContext(_class);
1731 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1732 FinishTemplatesContext(context);
1734 type = dataMember.dataType;
1738 // This is for destination type...
1739 if(!method.dataType)
1740 ProcessMethodType(method);
1741 //DeclareMethod(method);
1742 // method.dataType = ((Symbol)method.symbol)->type;
1743 type = method.dataType;
1746 if(ident && ident.next)
1748 for(ident = ident.next; ident && type; ident = ident.next)
1750 if(type.kind == classType)
1752 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1754 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1756 type = dataMember.dataType;
1758 else if(type.kind == structType || type.kind == unionType)
1761 for(memberType = type.members.first; memberType; memberType = memberType.next)
1763 if(!strcmp(memberType.name, ident.string))
1773 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1774 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1777 ClassTemplateParameter curParam = null;
1779 for(sClass = _class; sClass; sClass = sClass.base)
1782 if(sClass.templateClass) sClass = sClass.templateClass;
1783 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1785 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1787 for(sClass = sClass.base; sClass; sClass = sClass.base)
1789 if(sClass.templateClass) sClass = sClass.templateClass;
1790 id += sClass.templateParams.count;
1801 ClassTemplateArgument arg = _class.templateArgs[id];
1802 if(arg.dataTypeString)
1804 bool constant = type.constant;
1806 type = ProcessTypeString(arg.dataTypeString, false);
1807 if(type.kind == classType && constant) type.constant = true;
1808 else if(type.kind == pointerType)
1811 while(t.kind == pointerType) t = t.type;
1812 if(constant) t.constant = constant;
1815 if(type && _class.templateClass)
1816 type.passAsTemplate = true;
1822 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1823 exp.destType.refCount++;
1829 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1831 Class expClass = type._class.registered;
1832 Class cClass = null;
1837 char templateString[1024];
1838 ClassTemplateParameter param;
1839 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1840 for(cClass = expClass; cClass; cClass = cClass.base)
1843 if(cClass.templateClass) cClass = cClass.templateClass;
1844 for(param = cClass.templateParams.first; param; param = param.next)
1848 ClassTemplateArgument arg;
1849 for(sClass = cClass.base; sClass; sClass = sClass.base)
1851 if(sClass.templateClass) sClass = sClass.templateClass;
1852 id += sClass.templateParams.count;
1854 arg = expClass.templateArgs[id];
1856 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1858 ClassTemplateParameter cParam;
1859 //int p = numParams - sClass.templateParams.count;
1862 if(sClass.templateClass) sClass = sClass.templateClass;
1864 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1866 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1867 p += nextClass.templateParams.count;
1870 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1872 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1874 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1876 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1877 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1889 strcat(argument, arg.name.string);
1890 strcat(argument, " = ");
1896 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1897 char expString[1024];
1898 OldList * specs = MkList();
1899 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1901 char * string = PrintHexUInt64(arg.expression.ui64);
1902 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1905 ProcessExpressionType(exp);
1906 ComputeExpression(exp);
1907 expString[0] = '\0';
1908 PrintExpression(exp, expString);
1909 strcat(argument, expString);
1911 FreeExpression(exp);
1916 strcat(argument, arg.member.name);
1919 case TemplateParameterType::type:
1921 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1922 strcat(argument, arg.dataTypeString);
1928 if(paramCount) strcat(templateString, ", ");
1929 if(lastParam != p - 1)
1931 strcat(templateString, param.name);
1932 strcat(templateString, " = ");
1934 strcat(templateString, argument);
1943 int len = strlen(templateString);
1944 if(templateString[len-1] == '<')
1948 if(templateString[len-1] == '>')
1949 templateString[len++] = ' ';
1950 templateString[len++] = '>';
1952 templateString[len++] = '\0';
1955 Context context = SetupTemplatesContext(_class);
1956 if(freeType) FreeType(type);
1957 type = ProcessTypeString(templateString, false);
1959 FinishTemplatesContext(context);
1963 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1965 ProcessExpressionType(member.initializer.exp);
1966 if(!member.initializer.exp.expType)
1970 char expString[10240];
1971 expString[0] = '\0';
1972 PrintExpression(member.initializer.exp, expString);
1973 ChangeCh(expString, '\n', ' ');
1974 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1977 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1978 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1980 Compiler_Error($"incompatible instance method %s\n", ident.string);
1983 else if(member.initializer)
1986 FreeType(member.exp.destType);
1987 member.exp.destType = type;
1988 if(member.exp.destType)
1989 member.exp.destType.refCount++;
1990 ProcessExpressionType(member.exp);
1993 ProcessInitializer(member.initializer, type);
1995 if(freeType) FreeType(type);
1999 if(_class && _class.type == unitClass)
2001 if(member.initializer)
2004 FreeType(member.exp.destType);
2005 member.exp.destType = MkClassType(_class.fullName);
2006 ProcessExpressionType(member.initializer, type);
2008 Type type = MkClassType(_class.fullName);
2009 ProcessInitializer(member.initializer, type);
2015 if(member.initializer)
2017 //ProcessExpressionType(member.exp);
2018 ProcessInitializer(member.initializer, null);
2024 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2028 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2030 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2034 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2039 void ProcessInstantiationType(Instantiation inst)
2044 MembersInit members;
2045 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
2048 /*if(!inst._class.symbol)
2049 inst._class.symbol = FindClass(inst._class.name);*/
2050 classSym = inst._class.symbol;
2051 _class = classSym ? classSym.registered : null;
2053 // DANGER: Patch for mutex not declaring its struct when not needed
2054 if(!_class || _class.type != noHeadClass)
2055 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
2057 afterExternal = afterExternal ? afterExternal : curExternal;
2060 ProcessExpressionType(inst.exp);
2062 inst.isConstant = true;
2065 DataMember curMember = null;
2066 Class curClass = null;
2067 DataMember subMemberStack[256];
2068 int subMemberStackPos = 0;
2070 for(members = inst.members->first; members; members = members.next)
2072 switch(members.type)
2074 case methodMembersInit:
2077 static uint instMethodID = 0;
2078 External external = curExternal;
2079 Context context = curContext;
2080 Declarator declarator = members.function.declarator;
2081 Identifier nameID = GetDeclId(declarator);
2082 char * unmangled = nameID ? nameID.string : null;
2084 External createdExternal = null;
2089 //members.function.dontMangle = true;
2090 strcpy(name, "__ecereInstMeth_");
2091 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2093 strcat(name, nameID.string);
2095 sprintf(number, "_%08d", instMethodID++);
2096 strcat(name, number);
2097 nameID.string = CopyString(name);
2100 // Do modifications here...
2103 Symbol symbol = declarator.symbol;
2104 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2106 if(method && method.type == virtualMethod)
2108 symbol.method = method;
2109 ProcessMethodType(method);
2111 if(!symbol.type.thisClass)
2113 if(method.dataType.thisClass && currentClass &&
2114 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2116 if(!currentClass.symbol)
2117 currentClass.symbol = FindClass(currentClass.fullName);
2118 symbol.type.thisClass = currentClass.symbol;
2123 _class.symbol = FindClass(_class.fullName);
2124 symbol.type.thisClass = _class.symbol;
2127 // TESTING THIS HERE:
2128 DeclareType(symbol.type, true, true);
2133 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2134 unmangled, classSym.string);
2138 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2139 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2143 FreeSpecifier(nameID._class);
2144 nameID._class = null;
2149 //Type type = declarator.symbol.type;
2150 External oldExternal = curExternal;
2152 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2153 // *** It was commented out for problems such as
2155 class VirtualDesktop : Window
2157 clientSize = Size { };
2168 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2170 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2173 if(strcmp(declarator.symbol.string, name))
2175 printf("TOCHECK: Look out for this\n");
2176 delete declarator.symbol.string;
2177 declarator.symbol.string = CopyString(name);
2180 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2182 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2183 excludedSymbols->Remove(declarator.symbol);
2184 globalContext.symbols.Add((BTNode)declarator.symbol);
2185 if(strstr(declarator.symbol.string), "::")
2186 globalContext.hasNameSpace = true;
2191 //curExternal = curExternal.prev;
2192 //afterExternal = afterExternal->next;
2194 //ProcessFunction(afterExternal->function);
2196 //curExternal = afterExternal;
2198 External externalDecl;
2199 externalDecl = MkExternalDeclaration(null);
2200 ast->Insert(oldExternal.prev, externalDecl);
2202 // Which function does this process?
2203 if(createdExternal.function)
2205 ProcessFunction(createdExternal.function);
2207 //curExternal = oldExternal;
2210 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2212 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2213 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2215 //externalDecl = MkExternalDeclaration(decl);
2217 //***** ast->Insert(external.prev, externalDecl);
2218 //ast->Insert(curExternal.prev, externalDecl);
2219 externalDecl.declaration = decl;
2220 if(decl.symbol && !decl.symbol.pointerExternal)
2221 decl.symbol.pointerExternal = externalDecl;
2223 // Trying this out...
2224 declarator.symbol.pointerExternal = externalDecl;
2231 curExternal = declarator.symbol.pointerExternal;
2232 ProcessFunction((FunctionDefinition)members.function);
2234 curExternal = external;
2235 curContext = context;
2239 FreeClassFunction(members.function);
2241 // In this pass, turn this into a MemberInitData
2242 exp = QMkExpId(name);
2243 members.type = dataMembersInit;
2244 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2250 case dataMembersInit:
2252 if(members.dataMembers && classSym)
2255 Location oldyyloc = yylloc;
2256 for(member = members.dataMembers->first; member; member = member.next)
2258 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2259 if(member.initializer && !member.initializer.isConstant)
2260 inst.isConstant = false;
2272 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2274 // OPTIMIZATIONS: TESTING THIS...
2277 if(type.kind == functionType)
2282 for(param = type.params.first; param; param = param.next)
2283 DeclareType(param, declarePointers, true);
2285 DeclareType(type.returnType, declarePointers, true);
2287 else if(type.kind == pointerType && declarePointers)
2288 DeclareType(type.type, declarePointers, false);
2289 else if(type.kind == classType)
2291 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2292 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2294 else if(type.kind == structType || type.kind == unionType)
2297 for(member = type.members.first; member; member = member.next)
2298 DeclareType(member, false, false);
2300 else if(type.kind == arrayType)
2301 DeclareType(type.arrayType, declarePointers, false);
2305 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2307 ClassTemplateArgument * arg = null;
2309 ClassTemplateParameter curParam = null;
2311 for(sClass = _class; sClass; sClass = sClass.base)
2314 if(sClass.templateClass) sClass = sClass.templateClass;
2315 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2317 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2319 for(sClass = sClass.base; sClass; sClass = sClass.base)
2321 if(sClass.templateClass) sClass = sClass.templateClass;
2322 id += sClass.templateParams.count;
2332 arg = &_class.templateArgs[id];
2333 if(arg && param.type == type)
2334 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2339 public Context SetupTemplatesContext(Class _class)
2341 Context context = PushContext();
2342 context.templateTypesOnly = true;
2343 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2345 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2346 for(; param; param = param.next)
2348 if(param.type == type && param.identifier)
2350 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2351 curContext.templateTypes.Add((BTNode)type);
2358 for(sClass = _class; sClass; sClass = sClass.base)
2360 ClassTemplateParameter p;
2361 for(p = sClass.templateParams.first; p; p = p.next)
2363 //OldList * specs = MkList();
2364 //Declarator decl = null;
2365 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2368 TemplateParameter param = p.param;
2372 // ADD DATA TYPE HERE...
2373 p.param = param = TemplateParameter
2375 identifier = MkIdentifier(p.name), type = p.type,
2376 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2379 type = TemplatedType { key = (uintptr)p.name, param = param };
2380 curContext.templateTypes.Add((BTNode)type);
2388 public void FinishTemplatesContext(Context context)
2390 PopContext(context);
2391 FreeContext(context);
2395 public void ProcessMethodType(Method method)
2397 if(!method.dataType)
2399 Context context = SetupTemplatesContext(method._class);
2401 method.dataType = ProcessTypeString(method.dataTypeString, false);
2403 FinishTemplatesContext(context);
2405 if(method.type != virtualMethod && method.dataType)
2407 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2409 if(!method._class.symbol)
2410 method._class.symbol = FindClass(method._class.fullName);
2411 method.dataType.thisClass = method._class.symbol;
2415 // Why was this commented out? Working fine without now...
2418 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2419 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2426 char * par = strstr(type, "(");
2427 char * classOp = null;
2432 for(c = par-type-1; c >= 0; c++)
2434 if(type[c] == ':' && type[c+1] == ':')
2436 classOp = type + c - 1;
2437 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2444 else if(!isspace(type[c]))
2451 int typeLen = strlen(type);
2452 memcpy(temp, classOp, classOpLen);
2453 temp[classOpLen] = '\0';
2455 _class = eSystem_FindClass(module, temp);
2458 method.dataTypeString = new char[typeLen - classOpLen + 1];
2459 memcpy(method.dataTypeString, type, classOp - type);
2460 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2463 method.dataTypeString = type;
2469 public void ProcessPropertyType(Property prop)
2473 Context context = SetupTemplatesContext(prop._class);
2474 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2475 FinishTemplatesContext(context);
2479 public void DeclareMethod(Method method, const char * name)
2481 Symbol symbol = method.symbol;
2482 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2484 bool imported = false;
2485 bool dllImport = false;
2487 if(!method.dataType)
2488 method.dataType = ProcessTypeString(method.dataTypeString, false);
2490 if(!symbol || symbol._import || method.type == virtualMethod)
2492 if(!symbol || method.type == virtualMethod)
2495 if(!method._class.symbol)
2496 method._class.symbol = FindClass(method._class.fullName);
2497 classSym = method._class.symbol;
2498 if(!classSym._import)
2500 ModuleImport module;
2502 if(method._class.module && method._class.module.name)
2503 module = FindModule(method._class.module);
2505 module = mainModule;
2506 classSym._import = ClassImport
2508 name = CopyString(method._class.fullName);
2509 isRemote = method._class.isRemote;
2511 module.classes.Add(classSym._import);
2515 symbol = method.symbol = Symbol { };
2519 symbol._import = (ClassImport)MethodImport
2521 name = CopyString(method.name);
2522 isVirtual = method.type == virtualMethod;
2524 classSym._import.methods.Add(symbol._import);
2528 // Set the symbol type
2532 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2534 else if(type.thisClass == (void *)-1)
2536 type.thisClass = null;
2539 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2540 symbol.type = method.dataType;
2541 if(symbol.type) symbol.type.refCount++;
2544 if(!method.thisClass || strcmp(method.thisClass, "void"))
2545 symbol.type.params.Insert(null,
2546 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2549 if(!method.dataType.dllExport)
2552 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2558 if(!method.dataType)
2559 method.dataType = ((Symbol)method.symbol).type;
2560 //ProcessMethodType(method);
2563 if(method.type != virtualMethod && method.dataType)
2564 DeclareType(method.dataType, true, true);
2566 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2568 // We need a declaration here :)
2570 OldList * specifiers, * declarators;
2572 Declarator funcDecl;
2575 specifiers = MkList();
2576 declarators = MkList();
2580 ListAdd(specifiers, MkSpecifier(EXTERN));
2581 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2582 ListAdd(specifiers, MkSpecifier(STATIC));
2584 if(method.type == virtualMethod)
2586 ListAdd(specifiers, MkSpecifier(INT));
2587 d = MkDeclaratorIdentifier(MkIdentifier(name));
2591 d = MkDeclaratorIdentifier(MkIdentifier(name));
2594 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2596 Context context = SetupTemplatesContext(method._class);
2597 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2598 FinishTemplatesContext(context);
2600 funcDecl = GetFuncDecl(d);
2604 Specifier spec, next;
2605 for(spec = specifiers->first; spec; spec = next)
2608 if(spec.type == extendedSpecifier)
2610 specifiers->Remove(spec);
2611 FreeSpecifier(spec);
2616 // Add this parameter if not a static method
2617 if(method.dataType && !method.dataType.staticMethod)
2619 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2621 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2622 TypeName thisParam = MkTypeName(MkListOne(
2623 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2624 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2625 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2626 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2628 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2630 TypeName param = funcDecl.function.parameters->first;
2631 funcDecl.function.parameters->Remove(param);
2632 FreeTypeName(param);
2635 if(!funcDecl.function.parameters)
2636 funcDecl.function.parameters = MkList();
2637 funcDecl.function.parameters->Insert(null, thisParam);
2640 // Make sure we don't have empty parameter declarations for static methods...
2642 else if(!funcDecl.function.parameters)
2644 funcDecl.function.parameters = MkList();
2645 funcDecl.function.parameters->Insert(null,
2646 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2650 ProcessDeclarator(d);
2652 ListAdd(declarators, MkInitDeclarator(d, null));
2654 decl = MkDeclaration(specifiers, declarators);
2656 ReplaceThisClassSpecifiers(specifiers, method._class);
2658 // Keep a different symbol for the function definition than the declaration...
2659 if(symbol.pointerExternal)
2661 Symbol functionSymbol { };
2665 *functionSymbol = *symbol;
2666 functionSymbol.string = CopyString(symbol.string);
2667 if(functionSymbol.type)
2668 functionSymbol.type.refCount++;
2671 excludedSymbols->Add(functionSymbol);
2672 symbol.pointerExternal.symbol = functionSymbol;
2674 external = MkExternalDeclaration(decl);
2676 ast->Insert(curExternal ? curExternal.prev : null, external);
2677 external.symbol = symbol;
2678 symbol.pointerExternal = external;
2682 // Move declaration higher...
2683 ast->Move(symbol.pointerExternal, curExternal.prev);
2686 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2690 char * ReplaceThisClass(Class _class)
2692 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2696 ClassTemplateParameter param;
2699 char className[1024];
2700 strcpy(className, _class.fullName);
2701 for(param = _class.templateParams.first; param; param = param.next)
2703 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2705 if(first) strcat(className, "<");
2706 if(!first) strcat(className, ", ");
2707 if(lastParam + 1 != p)
2709 strcat(className, param.name);
2710 strcat(className, " = ");
2712 strcat(className, param.name);
2720 int len = strlen(className);
2721 if(className[len-1] == '>') className[len++] = ' ';
2722 className[len++] = '>';
2723 className[len++] = '\0';
2725 return CopyString(className);
2728 return CopyString(_class.fullName);
2731 Type ReplaceThisClassType(Class _class)
2733 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2737 ClassTemplateParameter param;
2739 char className[1024];
2740 strcpy(className, _class.fullName);
2742 for(param = _class.templateParams.first; param; param = param.next)
2744 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2746 if(first) strcat(className, "<");
2747 if(!first) strcat(className, ", ");
2748 if(lastParam + 1 != p)
2750 strcat(className, param.name);
2751 strcat(className, " = ");
2753 strcat(className, param.name);
2761 int len = strlen(className);
2762 if(className[len-1] == '>') className[len++] = ' ';
2763 className[len++] = '>';
2764 className[len++] = '\0';
2766 return MkClassType(className);
2767 //return ProcessTypeString(className, false);
2771 return MkClassType(_class.fullName);
2772 //return ProcessTypeString(_class.fullName, false);
2776 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2778 if(specs != null && _class)
2781 for(spec = specs.first; spec; spec = spec.next)
2783 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2785 spec.type = nameSpecifier;
2786 spec.name = ReplaceThisClass(_class);
2787 spec.symbol = FindClass(spec.name); //_class.symbol;
2793 // Returns imported or not
2794 bool DeclareFunction(GlobalFunction function, char * name)
2796 Symbol symbol = function.symbol;
2797 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2799 bool imported = false;
2800 bool dllImport = false;
2802 if(!function.dataType)
2804 function.dataType = ProcessTypeString(function.dataTypeString, false);
2805 if(!function.dataType.thisClass)
2806 function.dataType.staticMethod = true;
2813 ModuleImport module = FindModule(function.module);
2814 // WARNING: This is not added anywhere...
2815 symbol = function.symbol = Symbol { };
2819 if(!function.dataType.dllExport)
2821 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2822 module.functions.Add(symbol._import);
2825 // Set the symbol type
2827 symbol.type = ProcessTypeString(function.dataTypeString, false);
2828 if(!symbol.type.thisClass)
2829 symbol.type.staticMethod = true;
2832 imported = symbol._import ? true : false;
2833 if(imported && function.module != privateModule && function.module.importType != staticImport)
2837 DeclareType(function.dataType, true, true);
2841 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2843 // We need a declaration here :)
2845 OldList * specifiers, * declarators;
2847 Declarator funcDecl;
2850 specifiers = MkList();
2851 declarators = MkList();
2854 ListAdd(specifiers, MkSpecifier(EXTERN));
2857 ListAdd(specifiers, MkSpecifier(STATIC));
2860 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2863 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2865 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2866 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2867 if(function.module.importType == staticImport)
2870 for(spec = specifiers->first; spec; spec = spec.next)
2871 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2873 specifiers->Remove(spec);
2874 FreeSpecifier(spec);
2879 funcDecl = GetFuncDecl(d);
2881 // Make sure we don't have empty parameter declarations for static methods...
2882 if(funcDecl && !funcDecl.function.parameters)
2884 funcDecl.function.parameters = MkList();
2885 funcDecl.function.parameters->Insert(null,
2886 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2889 ListAdd(declarators, MkInitDeclarator(d, null));
2892 Context oldCtx = curContext;
2893 curContext = globalContext;
2894 decl = MkDeclaration(specifiers, declarators);
2895 curContext = oldCtx;
2898 // Keep a different symbol for the function definition than the declaration...
2899 if(symbol.pointerExternal)
2901 Symbol functionSymbol { };
2904 *functionSymbol = *symbol;
2905 functionSymbol.string = CopyString(symbol.string);
2906 if(functionSymbol.type)
2907 functionSymbol.type.refCount++;
2910 excludedSymbols->Add(functionSymbol);
2912 symbol.pointerExternal.symbol = functionSymbol;
2914 external = MkExternalDeclaration(decl);
2916 ast->Insert(curExternal.prev, external);
2917 external.symbol = symbol;
2918 symbol.pointerExternal = external;
2922 // Move declaration higher...
2923 ast->Move(symbol.pointerExternal, curExternal.prev);
2927 symbol.id = curExternal.symbol.idCode;
2930 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2933 void DeclareGlobalData(GlobalData data)
2935 Symbol symbol = data.symbol;
2936 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2941 symbol = data.symbol = Symbol { };
2944 data.dataType = ProcessTypeString(data.dataTypeString, false);
2945 DeclareType(data.dataType, true, true);
2948 if(!symbol.pointerExternal)
2950 // We need a declaration here :)
2952 OldList * specifiers, * declarators;
2956 specifiers = MkList();
2957 declarators = MkList();
2959 ListAdd(specifiers, MkSpecifier(EXTERN));
2960 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2961 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2963 ListAdd(declarators, MkInitDeclarator(d, null));
2965 decl = MkDeclaration(specifiers, declarators);
2966 external = MkExternalDeclaration(decl);
2968 ast->Insert(curExternal.prev, external);
2969 external.symbol = symbol;
2970 symbol.pointerExternal = external;
2974 // Move declaration higher...
2975 ast->Move(symbol.pointerExternal, curExternal.prev);
2979 symbol.id = curExternal.symbol.idCode;
2984 class Conversion : struct
2986 Conversion prev, next;
2992 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2995 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2996 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2998 Class sourceClass = source.kind == classType ? source._class.registered : null;
2999 Class destClass = dest.kind == classType ? dest._class.registered : null;
3000 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
3001 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
3003 Type sourceType = source, destType = dest;
3004 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
3005 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
3006 if(!destType.constant && sourceType.constant)
3010 Compiler_Warning($"discarding const qualifier\n");
3017 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
3018 bool isConversionExploration, bool warnConst)
3023 CheckConstCompatibility(source, dest, true);
3024 // Property convert;
3026 if(source.kind == templateType && dest.kind != templateType)
3028 Type type = ProcessTemplateParameterType(source.templateParameter);
3029 if(type) source = type;
3032 if(dest.kind == templateType && source.kind != templateType)
3034 Type type = ProcessTemplateParameterType(dest.templateParameter);
3035 if(type) dest = type;
3038 if(dest.classObjectType == typedObject && dest.kind != functionType)
3040 if(source.classObjectType != anyObject)
3044 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
3045 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
3053 if(source.kind != functionType && source.classObjectType == anyObject)
3055 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
3059 if((dest.kind == structType && source.kind == structType) ||
3060 (dest.kind == unionType && source.kind == unionType))
3062 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
3063 (source.members.first && source.members.first == dest.members.first))
3067 if(dest.kind == ellipsisType && source.kind != voidType)
3070 if(dest.kind == pointerType && dest.type.kind == voidType &&
3071 ((source.kind == classType && (!source._class || !source._class.registered || source._class.registered.type == structClass || source._class.registered.type == normalClass || source._class.registered.type == noHeadClass || source._class.registered.type == systemClass))
3072 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
3074 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
3076 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
3078 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
3079 ((dest.kind == classType && (!dest._class || !dest._class.registered || dest._class.registered.type == structClass || dest._class.registered.type == normalClass || dest._class.registered.type == noHeadClass || dest._class.registered.type == systemClass))
3080 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
3081 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
3083 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
3086 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
3088 if(source._class.registered && source._class.registered.type == unitClass)
3090 if(conversions != null)
3092 if(source._class.registered == dest._class.registered)
3097 Class sourceBase, destBase;
3098 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
3099 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
3100 if(sourceBase == destBase)
3104 // Don't match enum inheriting from other enum if resolving enumeration values
3105 // TESTING: !dest.classObjectType
3106 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3108 (!source._class.registered || source._class.registered.type != enumClass) ||
3109 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3113 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3115 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3116 ((source._class && source._class.registered && source._class.registered.type != enumClass) || source.kind == classType)) // Added this here for a base enum to be acceptable for a derived enum (#139)
3118 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3126 // JUST ADDED THIS...
3127 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3132 // Just added this for Straight conversion of ColorAlpha => Color
3133 if(source.kind == classType)
3136 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3139 for(convert = _class.conversions.first; convert; convert = convert.next)
3141 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3143 Conversion after = (conversions != null) ? conversions.last : null;
3145 if(!convert.dataType)
3146 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3147 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3148 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3149 MatchTypes(convert.dataType, dest, conversions, null, null,
3150 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3151 convert.dataType.kind == classType, false, true, warnConst))
3153 if(!conversions && !convert.Get)
3155 else if(conversions != null)
3157 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3158 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3159 (dest.kind != classType || dest._class.registered != _class.base))
3163 Conversion conv { convert = convert, isGet = true };
3164 // conversions.Add(conv);
3165 conversions.Insert(after, conv);
3178 if(dest.kind == classType)
3181 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3184 for(convert = _class.conversions.first; convert; convert = convert.next)
3186 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3188 Type constType = null;
3189 bool success = false;
3190 // Conversion after = (conversions != null) ? conversions.last : null;
3192 if(!convert.dataType)
3193 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3195 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3198 constType = { kind = pointerType, refCount = 1, type = ptrType };
3199 CopyTypeInto(ptrType, convert.dataType.type);
3200 ptrType.constant = true;
3203 // Just added this equality check to prevent recursion.... Make it safer?
3204 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3205 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3207 if(!conversions && !convert.Set)
3209 else if(conversions != null)
3211 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3212 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3213 (source.kind != classType || source._class.registered != _class.base))
3217 // *** Testing this! ***
3218 Conversion conv { convert = convert };
3219 conversions.Add(conv);
3220 //conversions.Insert(after, conv);
3226 FreeType(constType);
3232 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3234 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3235 (source.kind != classType || source._class.registered.type != structClass))
3239 // TESTING THIS... IS THIS OK??
3240 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3242 if(!dest._class.registered.dataType)
3243 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3244 // Only support this for classes...
3245 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3246 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3248 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3257 if(source.kind == classType)
3260 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3263 for(convert = _class.conversions.first; convert; convert = convert.next)
3265 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3267 Conversion after = (conversions != null) ? conversions.last : null;
3269 if(!convert.dataType)
3270 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3271 if(convert.dataType != source &&
3272 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3273 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3275 if(!conversions && !convert.Get)
3277 else if(conversions != null)
3279 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3280 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3281 (dest.kind != classType || dest._class.registered != _class.base))
3285 Conversion conv { convert = convert, isGet = true };
3287 // conversions.Add(conv);
3288 conversions.Insert(after, conv);
3297 // TESTING THIS... IS THIS OK??
3298 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3300 if(!source._class.registered.dataType)
3301 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3302 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3304 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false, warnConst))
3306 // For bool to be accepted by byte, short, etc.
3307 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3314 if(source.kind == classType || source.kind == subClassType)
3316 else if(dest.kind == source.kind &&
3317 (dest.kind != structType && dest.kind != unionType &&
3318 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3320 // RECENTLY ADDED THESE
3321 else if(dest.kind == doubleType && source.kind == floatType)
3323 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3325 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3327 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3329 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3331 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3333 else if(source.kind == enumType &&
3334 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3336 else if(dest.kind == enumType && !isConversionExploration &&
3337 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3339 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3340 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3342 Type paramSource, paramDest;
3344 if(dest.kind == methodType)
3345 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3346 if(source.kind == methodType)
3347 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3349 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3350 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3351 if(dest.kind == methodType)
3352 dest = dest.method.dataType;
3353 if(source.kind == methodType)
3354 source = source.method.dataType;
3356 paramSource = source.params.first;
3357 if(paramSource && paramSource.kind == voidType) paramSource = null;
3358 paramDest = dest.params.first;
3359 if(paramDest && paramDest.kind == voidType) paramDest = null;
3362 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3363 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3365 // Source thisClass must be derived from destination thisClass
3366 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3367 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3369 if(paramDest && paramDest.kind == classType)
3370 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3372 Compiler_Error($"method class should not take an object\n");
3375 paramDest = paramDest.next;
3377 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3379 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3383 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3385 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3391 // THIS WAS BACKWARDS:
3392 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3393 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3396 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3398 Compiler_Error($"overriding class expected to be derived from method class\n");
3402 paramSource = paramSource.next;
3408 // Source thisClass must be derived from destination thisClass
3409 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3411 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3417 // THIS WAS BACKWARDS TOO??
3418 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3419 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3422 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3424 //Compiler_Error($"overriding class expected to be derived from method class\n");
3432 // Source return type must be derived from destination return type
3433 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3435 Compiler_Warning($"incompatible return type for function\n");
3438 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3440 CheckConstCompatibility(dest.returnType, source.returnType, true);
3444 for(; paramDest; paramDest = paramDest.next)
3448 //Compiler_Warning($"not enough parameters\n");
3449 Compiler_Error($"not enough parameters\n");
3453 Type paramDestType = paramDest;
3454 Type paramSourceType = paramSource;
3455 Type type = paramDestType;
3457 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3458 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3459 paramSource.kind != templateType)
3462 ClassTemplateParameter curParam = null;
3464 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3467 if(sClass.templateClass) sClass = sClass.templateClass;
3468 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3470 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3472 for(sClass = sClass.base; sClass; sClass = sClass.base)
3474 if(sClass.templateClass) sClass = sClass.templateClass;
3475 id += sClass.templateParams.count;
3486 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3487 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3491 // paramDest must be derived from paramSource
3492 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3493 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3497 PrintType(paramDest, type, false, true);
3498 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3500 if(paramDestType != paramDest)
3501 FreeType(paramDestType);
3504 if(paramDestType != paramDest)
3505 FreeType(paramDestType);
3508 paramSource = paramSource.next;
3512 Compiler_Error($"too many parameters\n");
3517 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3521 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3522 (source.kind == arrayType || source.kind == pointerType))
3524 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3531 static void FreeConvert(Conversion convert)
3533 if(convert.resultType)
3534 FreeType(convert.resultType);
3537 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3538 char * string, OldList conversions)
3542 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3544 Class _class = link.data;
3545 if(_class.type == enumClass)
3547 OldList converts { };
3549 type.kind = classType;
3552 _class.symbol = FindClass(_class.fullName);
3553 type._class = _class.symbol;
3555 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false, false))
3558 Class enumClass = eSystem_FindClass(privateModule, "enum");
3562 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3564 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3565 for(value = e.values.first; value; value = value.next)
3567 if(!strcmp(value.name, string))
3572 FreeExpContents(sourceExp);
3573 FreeType(sourceExp.expType);
3575 sourceExp.isConstant = true;
3576 sourceExp.expType = MkClassType(baseClass.fullName);
3580 sourceExp.type = constantExp;
3581 if(!strcmp(baseClass.dataTypeString, "int"))
3582 sprintf(constant, "%d",(int)value.data);
3584 sprintf(constant, "0x%X",(int)value.data);
3585 sourceExp.constant = CopyString(constant);
3586 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3589 while(converts.first)
3591 Conversion convert = converts.first;
3592 converts.Remove(convert);
3593 conversions.Add(convert);
3602 converts.Free(FreeConvert);
3606 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3607 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3612 public bool ModuleVisibility(Module searchIn, Module searchFor)
3614 SubModule subModule;
3616 if(searchFor == searchIn)
3619 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3621 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3623 if(ModuleVisibility(subModule.module, searchFor))
3630 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3634 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3636 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3638 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3641 for(module = mainModule.application.allModules.first; module; module = module.next)
3643 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3649 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3652 Type realDest = dest;
3653 Type backupSourceExpType = null;
3654 Expression computedExp = sourceExp;
3657 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3658 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3660 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3661 ComputeExpression(computedExp /*sourceExp*/);
3664 source = sourceExp.expType;
3666 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3668 if(computedExp != sourceExp)
3670 FreeExpression(computedExp);
3671 computedExp = sourceExp;
3677 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3679 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3681 Class sourceBase, destBase;
3682 for(sourceBase = source._class.registered;
3683 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3684 sourceBase = sourceBase.base);
3685 for(destBase = dest._class.registered;
3686 destBase && destBase.base && destBase.base.type != systemClass;
3687 destBase = destBase.base);
3688 //if(source._class.registered == dest._class.registered)
3689 if(sourceBase == destBase)
3691 if(computedExp != sourceExp)
3693 FreeExpression(computedExp);
3694 computedExp = sourceExp;
3706 int64 value = MAXINT;
3710 if(computedExp.type == constantExp)
3713 value = strtoll(computedExp.constant, null, 0);
3715 value = strtoull(computedExp.constant, null, 0);
3717 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3720 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3722 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3724 if(computedExp != sourceExp)
3726 FreeExpression(computedExp);
3727 computedExp = sourceExp;
3730 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3731 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3734 source = Type { kind = intType, isSigned = false, refCount = 1 };
3737 if(dest.kind == classType)
3739 Class _class = dest._class ? dest._class.registered : null;
3741 if(_class && _class.type == unitClass)
3743 if(source.kind != classType)
3746 Type tempDest, tempSource;
3748 for(; _class.base.type != systemClass; _class = _class.base);
3750 tempDest = tempType;
3752 tempType.kind = classType;
3754 _class.symbol = FindClass(_class.fullName);
3756 tempType._class = _class.symbol;
3757 tempType.truth = dest.truth;
3759 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3761 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3762 backupSourceExpType = sourceExp.expType;
3763 sourceExp.expType = dest; dest.refCount++;
3764 //sourceExp.expType = MkClassType(_class.fullName);
3772 // Why wasn't there something like this?
3773 if(_class && _class.type == bitClass && source.kind != classType)
3775 if(!dest._class.registered.dataType)
3776 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3777 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3780 FreeType(sourceExp.expType);
3781 source = sourceExp.expType = MkClassType(dest._class.string);
3784 //source.kind = classType;
3785 //source._class = dest._class;
3789 // Adding two enumerations
3791 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3793 if(!source._class.registered.dataType)
3794 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3795 if(!dest._class.registered.dataType)
3796 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3798 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3801 source = sourceExp.expType = MkClassType(dest._class.string);
3804 //source.kind = classType;
3805 //source._class = dest._class;
3809 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3811 OldList * specs = MkList();
3815 ReadString(string, sourceExp.string);
3816 decl = SpecDeclFromString(string, specs, null);
3818 FreeExpContents(sourceExp);
3819 FreeType(sourceExp.expType);
3821 sourceExp.type = classExp;
3822 sourceExp._classExp.specifiers = specs;
3823 sourceExp._classExp.decl = decl;
3824 sourceExp.expType = dest;
3829 if(backupSourceExpType) FreeType(backupSourceExpType);
3833 else if(source.kind == classType)
3835 Class _class = source._class ? source._class.registered : null;
3837 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3840 if(dest.kind != classType)
3842 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3843 if(!source._class.registered.dataType)
3844 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3847 dest = MkClassType(source._class.string);
3848 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3849 // dest = MkClassType(source._class.string);
3853 if(dest.kind != classType)
3856 Type tempDest, tempSource;
3858 if(!source._class.registered.dataType)
3859 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3861 for(; _class.base.type != systemClass; _class = _class.base);
3863 tempSource = tempType;
3864 tempType.kind = classType;
3865 tempType._class = FindClass(_class.fullName);
3866 tempType.truth = source.truth;
3867 tempType.classObjectType = source.classObjectType;
3870 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3872 // PUT THIS BACK TESTING UNITS?
3873 if(conversions.last)
3875 ((Conversion)(conversions.last)).resultType = dest;
3879 FreeType(sourceExp.expType);
3880 sourceExp.expType = MkClassType(_class.fullName);
3881 sourceExp.expType.truth = source.truth;
3882 sourceExp.expType.classObjectType = source.classObjectType;
3884 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3886 if(!sourceExp.destType)
3888 FreeType(sourceExp.destType);
3889 sourceExp.destType = sourceExp.expType;
3890 if(sourceExp.expType)
3891 sourceExp.expType.refCount++;
3894 //source = _class.dataType;
3897 // TOCHECK: TESTING THIS NEW CODE
3898 if(!_class.dataType)
3899 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3901 dest = MkClassType(source._class.string);
3902 dest.truth = source.truth;
3903 dest.classObjectType = source.classObjectType;
3906 source = _class.dataType;
3916 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3926 if(source.kind == classType)
3928 Class _class = source._class.registered;
3929 if(_class.type == unitClass)
3931 if(!_class.dataType)
3932 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3933 source = _class.dataType;
3937 if(dest.kind == classType)
3939 Class _class = dest._class ? dest._class.registered : null;
3940 bool fittingValue = false;
3941 if(_class && _class.type == enumClass)
3943 Class enumClass = eSystem_FindClass(privateModule, "enum");
3944 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3945 if(c && value >= 0 && value <= c.largest)
3946 fittingValue = true;
3949 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3950 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3952 if(_class.type == normalClass || _class.type == noHeadClass)
3954 Expression newExp { };
3955 *newExp = *sourceExp;
3956 if(sourceExp.destType) sourceExp.destType.refCount++;
3957 if(sourceExp.expType) sourceExp.expType.refCount++;
3958 sourceExp.type = castExp;
3959 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3960 sourceExp.cast.exp = newExp;
3961 FreeType(sourceExp.expType);
3962 sourceExp.expType = null;
3963 ProcessExpressionType(sourceExp);
3965 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3968 FreeType(sourceExp.expType);
3969 sourceExp.expType = dest;
3973 if(inCompiler) FreeType(dest);
3975 if(backupSourceExpType) FreeType(backupSourceExpType);
3979 if(!_class.dataType)
3980 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3982 dest = _class.dataType;
3986 // Accept lower precision types for units, since we want to keep the unit type
3987 if(dest.kind == doubleType &&
3988 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3989 source.kind == charType || source.kind == _BoolType))
3991 specs = MkListOne(MkSpecifier(DOUBLE));
3993 else if(dest.kind == floatType &&
3994 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3995 source.kind == _BoolType || source.kind == doubleType))
3997 specs = MkListOne(MkSpecifier(FLOAT));
3999 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4000 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4003 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4004 ListAdd(specs, MkSpecifier(INT64));
4006 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
4007 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4010 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4011 ListAdd(specs, MkSpecifier(INT));
4013 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
4014 source.kind == floatType || source.kind == doubleType))
4017 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4018 ListAdd(specs, MkSpecifier(SHORT));
4020 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
4021 source.kind == floatType || source.kind == doubleType))
4024 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4025 ListAdd(specs, MkSpecifier(CHAR));
4031 if(backupSourceExpType)
4033 // Failed to convert: revert previous exp type
4034 if(sourceExp.expType) FreeType(sourceExp.expType);
4035 sourceExp.expType = backupSourceExpType;
4040 else if(dest.kind == doubleType &&
4041 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
4042 source.kind == _BoolType || source.kind == charType))
4044 specs = MkListOne(MkSpecifier(DOUBLE));
4046 else if(dest.kind == floatType &&
4047 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4049 specs = MkListOne(MkSpecifier(FLOAT));
4051 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4052 (value == 1 || value == 0))
4055 ListAdd(specs, MkSpecifier(BOOL));
4057 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4058 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
4061 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4062 ListAdd(specs, MkSpecifier(CHAR));
4064 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
4065 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
4068 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4069 ListAdd(specs, MkSpecifier(SHORT));
4071 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
4074 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4075 ListAdd(specs, MkSpecifier(INT));
4077 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
4080 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4081 ListAdd(specs, MkSpecifier(INT64));
4083 else if(dest.kind == enumType &&
4084 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4086 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4092 if(backupSourceExpType)
4094 // Failed to convert: revert previous exp type
4095 if(sourceExp.expType) FreeType(sourceExp.expType);
4096 sourceExp.expType = backupSourceExpType;
4101 if(!flag && !sourceExp.opDestType)
4103 Expression newExp { };
4104 *newExp = *sourceExp;
4107 if(sourceExp.destType) sourceExp.destType.refCount++;
4108 if(sourceExp.expType) sourceExp.expType.refCount++;
4110 sourceExp.type = castExp;
4111 if(realDest.kind == classType)
4113 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4114 FreeList(specs, FreeSpecifier);
4117 sourceExp.cast.typeName = MkTypeName(specs, null);
4118 if(newExp.type == opExp)
4120 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4123 sourceExp.cast.exp = newExp;
4125 FreeType(sourceExp.expType);
4126 sourceExp.expType = null;
4127 ProcessExpressionType(sourceExp);
4130 FreeList(specs, FreeSpecifier);
4134 if(backupSourceExpType) FreeType(backupSourceExpType);
4140 if(computedExp != sourceExp)
4142 FreeExpression(computedExp);
4143 computedExp = sourceExp;
4146 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4147 if(sourceExp.type == identifierExp)
4149 Identifier id = sourceExp.identifier;
4150 if(dest.kind == classType)
4152 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4154 Class _class = dest._class.registered;
4155 Class enumClass = eSystem_FindClass(privateModule, "enum");
4158 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4161 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4162 for(value = e.values.first; value; value = value.next)
4164 if(!strcmp(value.name, id.string))
4169 FreeExpContents(sourceExp);
4170 FreeType(sourceExp.expType);
4172 sourceExp.isConstant = true;
4173 sourceExp.expType = MkClassType(_class.fullName);
4177 sourceExp.type = constantExp;
4178 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
4179 sprintf(constant, "%d", (int) value.data);
4181 sprintf(constant, "0x%X", (int) value.data);
4182 sourceExp.constant = CopyString(constant);
4183 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4193 // Loop through all enum classes
4194 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4205 #define TERTIARY(o, name, m, t, p) \
4206 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4208 exp.type = constantExp; \
4209 exp.string = p(op1.m ? op2.m : op3.m); \
4211 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4215 #define BINARY(o, name, m, t, p) \
4216 static bool name(Expression exp, Operand op1, Operand op2) \
4219 exp.type = constantExp; \
4220 exp.string = p((t)(op1.m o value2)); \
4222 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4226 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4227 static bool name(Expression exp, Operand op1, Operand op2) \
4230 exp.type = constantExp; \
4231 exp.string = p(value2 ? (op1.m o value2) : 0); \
4233 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4237 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4238 static bool name(Expression exp, Operand op1, Operand op2) \
4241 exp.type = constantExp; \
4242 exp.string = p(op1.m o value2); \
4244 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4248 #define UNARY(o, name, m, t, p) \
4249 static bool name(Expression exp, Operand op1) \
4251 exp.type = constantExp; \
4252 exp.string = p((t)(o op1.m)); \
4254 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4258 #define OPERATOR_ALL(macro, o, name) \
4259 macro(o, Int##name, i, int, PrintInt) \
4260 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4261 macro(o, Int64##name, i64, int64, PrintInt64) \
4262 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4263 macro(o, Short##name, s, short, PrintShort) \
4264 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4265 macro(o, Char##name, c, char, PrintChar) \
4266 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4267 macro(o, Float##name, f, float, PrintFloat) \
4268 macro(o, Double##name, d, double, PrintDouble)
4270 #define OPERATOR_INTTYPES(macro, o, name) \
4271 macro(o, Int##name, i, int, PrintInt) \
4272 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4273 macro(o, Int64##name, i64, int64, PrintInt64) \
4274 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4275 macro(o, Short##name, s, short, PrintShort) \
4276 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4277 macro(o, Char##name, c, char, PrintChar) \
4278 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4280 #define OPERATOR_REALTYPES(macro, o, name) \
4281 macro(o, Float##name, f, float, PrintFloat) \
4282 macro(o, Double##name, d, double, PrintDouble)
4284 // binary arithmetic
4285 OPERATOR_ALL(BINARY, +, Add)
4286 OPERATOR_ALL(BINARY, -, Sub)
4287 OPERATOR_ALL(BINARY, *, Mul)
4288 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4289 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4290 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4293 OPERATOR_ALL(UNARY, -, Neg)
4295 // unary arithmetic increment and decrement
4296 OPERATOR_ALL(UNARY, ++, Inc)
4297 OPERATOR_ALL(UNARY, --, Dec)
4299 // binary arithmetic assignment
4300 OPERATOR_ALL(BINARY, =, Asign)
4301 OPERATOR_ALL(BINARY, +=, AddAsign)
4302 OPERATOR_ALL(BINARY, -=, SubAsign)
4303 OPERATOR_ALL(BINARY, *=, MulAsign)
4304 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4305 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4306 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4309 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4310 OPERATOR_INTTYPES(BINARY, |, BitOr)
4311 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4312 OPERATOR_INTTYPES(BINARY, <<, LShift)
4313 OPERATOR_INTTYPES(BINARY, >>, RShift)
4316 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4318 // binary bitwise assignment
4319 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4320 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4321 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4322 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4323 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4325 // unary logical negation
4326 OPERATOR_INTTYPES(UNARY, !, Not)
4328 // binary logical equality
4329 OPERATOR_ALL(BINARY, ==, Equ)
4330 OPERATOR_ALL(BINARY, !=, Nqu)
4333 OPERATOR_ALL(BINARY, &&, And)
4334 OPERATOR_ALL(BINARY, ||, Or)
4336 // binary logical relational
4337 OPERATOR_ALL(BINARY, >, Grt)
4338 OPERATOR_ALL(BINARY, <, Sma)
4339 OPERATOR_ALL(BINARY, >=, GrtEqu)
4340 OPERATOR_ALL(BINARY, <=, SmaEqu)
4342 // tertiary condition operator
4343 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4345 //Add, Sub, Mul, Div, Mod, , Neg, Inc, Dec, Asign, AddAsign, SubAsign, MulAsign, DivAsign, ModAsign, BitAnd, BitOr, BitXor, LShift, RShift, BitNot, AndAsign, OrAsign, XorAsign, LShiftAsign, RShiftAsign, Not, Equ, Nqu, And, Or, Grt, Sma, GrtEqu, SmaEqu
4346 #define OPERATOR_TABLE_ALL(name, type) \
4347 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4349 type##Inc, type##Dec, \
4350 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4351 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4353 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4355 type##Equ, type##Nqu, \
4356 type##And, type##Or, \
4357 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4360 #define OPERATOR_TABLE_INTTYPES(name, type) \
4361 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4363 type##Inc, type##Dec, \
4364 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4365 null, null, null, null, null, \
4367 null, null, null, null, null, \
4369 type##Equ, type##Nqu, \
4370 type##And, type##Or, \
4371 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4374 OPERATOR_TABLE_ALL(int, Int)
4375 OPERATOR_TABLE_ALL(uint, UInt)
4376 OPERATOR_TABLE_ALL(int64, Int64)
4377 OPERATOR_TABLE_ALL(uint64, UInt64)
4378 OPERATOR_TABLE_ALL(short, Short)
4379 OPERATOR_TABLE_ALL(ushort, UShort)
4380 OPERATOR_TABLE_INTTYPES(float, Float)
4381 OPERATOR_TABLE_INTTYPES(double, Double)
4382 OPERATOR_TABLE_ALL(char, Char)
4383 OPERATOR_TABLE_ALL(uchar, UChar)
4385 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4386 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4387 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4388 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4389 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4390 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4391 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4392 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4394 public void ReadString(char * output, char * string)
4396 int len = strlen(string);
4398 bool quoted = false, escaped = false;
4399 for(c = 0; c<len; c++)
4401 char ch = string[c];
4406 case 'n': output[d] = '\n'; break;
4407 case 't': output[d] = '\t'; break;
4408 case 'a': output[d] = '\a'; break;
4409 case 'b': output[d] = '\b'; break;
4410 case 'f': output[d] = '\f'; break;
4411 case 'r': output[d] = '\r'; break;
4412 case 'v': output[d] = '\v'; break;
4413 case '\\': output[d] = '\\'; break;
4414 case '\"': output[d] = '\"'; break;
4415 case '\'': output[d] = '\''; break;
4416 default: output[d] = ch;
4437 // String Unescape Copy
4439 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4440 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4441 public int UnescapeString(char * d, char * s, int len)
4445 while(j < len && (ch = s[j]))
4450 switch((ch = s[++j]))
4452 case 'n': d[k] = '\n'; break;
4453 case 't': d[k] = '\t'; break;
4454 case 'a': d[k] = '\a'; break;
4455 case 'b': d[k] = '\b'; break;
4456 case 'f': d[k] = '\f'; break;
4457 case 'r': d[k] = '\r'; break;
4458 case 'v': d[k] = '\v'; break;
4459 case '\\': d[k] = '\\'; break;
4460 case '\"': d[k] = '\"'; break;
4461 case '\'': d[k] = '\''; break;
4462 default: d[k] = '\\'; d[k] = ch;
4474 public char * OffsetEscapedString(char * s, int len, int offset)
4478 while(j < len && k < offset && (ch = s[j]))
4483 return (k == offset) ? s + j : null;
4486 public Operand GetOperand(Expression exp)
4489 Type type = exp.expType;
4492 while(type.kind == classType &&
4493 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4495 if(!type._class.registered.dataType)
4496 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4497 type = type._class.registered.dataType;
4500 if(exp.type == stringExp && op.kind == pointerType)
4502 op.ui64 = (uint64)exp.string;
4503 op.kind = pointerType;
4506 else if(exp.isConstant && exp.type == constantExp)
4508 op.kind = type.kind;
4509 op.type = exp.expType;
4516 if(exp.constant[0] == '\'')
4518 op.c = exp.constant[1];
4521 else if(type.isSigned)
4523 op.c = (char)strtol(exp.constant, null, 0);
4528 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4536 op.s = (short)strtol(exp.constant, null, 0);
4541 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4549 op.i = (int)strtol(exp.constant, null, 0);
4554 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4562 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4567 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4570 op.kind = int64Type;
4575 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4580 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4583 op.kind = int64Type;
4588 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4593 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4596 op.kind = int64Type;
4599 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4600 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4601 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4602 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4604 op.f = (float)strtod(exp.constant, null);
4608 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4609 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4610 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4611 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4613 op.d = (double)strtod(exp.constant, null);
4616 //case classType: For when we have operator overloading...
4617 // Pointer additions
4618 //case functionType:
4622 op.ui64 = _strtoui64(exp.constant, null, 0);
4623 op.kind = pointerType;
4633 static __attribute__((unused)) void UnusedFunction()
4636 a.OnGetString(0,0,0);
4639 extern int __ecereVMethodID_class_OnGetString;
4642 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4644 DataMember dataMember;
4645 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4647 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4648 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4652 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4654 void * ptr = inst.data + dataMember.offset + offset;
4655 char * result = null;
4656 exp.loc = member.loc = inst.loc;
4657 ((Identifier)member.identifiers->first).loc = inst.loc;
4659 if(!dataMember.dataType)
4660 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4661 type = dataMember.dataType;
4662 if(type.kind == classType)
4664 Class _class = type._class.registered;
4665 if(_class.type == enumClass)
4667 Class enumClass = eSystem_FindClass(privateModule, "enum");
4670 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4672 for(item = e.values.first; item; item = item.next)
4674 if((int)item.data == *(int *)ptr)
4682 exp.identifier = MkIdentifier(result);
4683 exp.type = identifierExp;
4684 exp.destType = MkClassType(_class.fullName);
4685 ProcessExpressionType(exp);
4689 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4691 if(!_class.dataType)
4692 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4693 type = _class.dataType;
4702 FreeExpContents(exp);
4704 exp.constant = PrintFloat(*(float*)ptr);
4705 exp.type = constantExp;
4710 FreeExpContents(exp);
4712 exp.constant = PrintDouble(*(double*)ptr);
4713 exp.type = constantExp;
4718 FreeExpContents(exp);
4720 exp.constant = PrintInt(*(int*)ptr);
4721 exp.type = constantExp;
4726 FreeExpContents(exp);
4728 exp.constant = PrintInt64(*(int64*)ptr);
4729 exp.type = constantExp;
4734 FreeExpContents(exp);
4735 // TODO: This should probably use proper type
4736 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4737 exp.type = constantExp;
4742 FreeExpContents(exp);
4743 // TODO: This should probably use proper type
4744 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4745 exp.type = constantExp;
4749 Compiler_Error($"Unhandled type populating instance\n");
4752 ListAdd(memberList, member);
4755 if(parentDataMember.type == unionMember)
4760 void PopulateInstance(Instantiation inst)
4762 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4763 Class _class = classSym.registered;
4764 DataMember dataMember;
4765 OldList * memberList = MkList();
4766 // Added this check and ->Add to prevent memory leaks on bad code
4768 inst.members = MkListOne(MkMembersInitList(memberList));
4770 inst.members->Add(MkMembersInitList(memberList));
4771 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4773 if(!dataMember.isProperty)
4775 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4776 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4780 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4782 void * ptr = inst.data + dataMember.offset;
4783 char * result = null;
4785 exp.loc = member.loc = inst.loc;
4786 ((Identifier)member.identifiers->first).loc = inst.loc;
4788 if(!dataMember.dataType)
4789 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4790 type = dataMember.dataType;
4791 if(type.kind == classType)
4793 Class _class = type._class.registered;
4794 if(_class.type == enumClass)
4796 Class enumClass = eSystem_FindClass(privateModule, "enum");
4799 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4801 for(item = e.values.first; item; item = item.next)
4803 if((int)item.data == *(int *)ptr)
4812 exp.identifier = MkIdentifier(result);
4813 exp.type = identifierExp;
4814 exp.destType = MkClassType(_class.fullName);
4815 ProcessExpressionType(exp);
4818 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4820 if(!_class.dataType)
4821 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4822 type = _class.dataType;
4831 exp.constant = PrintFloat(*(float*)ptr);
4832 exp.type = constantExp;
4837 exp.constant = PrintDouble(*(double*)ptr);
4838 exp.type = constantExp;
4843 exp.constant = PrintInt(*(int*)ptr);
4844 exp.type = constantExp;
4849 exp.constant = PrintInt64(*(int64*)ptr);
4850 exp.type = constantExp;
4855 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4856 exp.type = constantExp;
4860 Compiler_Error($"Unhandled type populating instance\n");
4863 ListAdd(memberList, member);
4869 void ComputeInstantiation(Expression exp)
4871 Instantiation inst = exp.instance;
4872 MembersInit members;
4873 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4874 Class _class = classSym ? classSym.registered : null;
4875 DataMember curMember = null;
4876 Class curClass = null;
4877 DataMember subMemberStack[256];
4878 int subMemberStackPos = 0;
4881 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4883 // Don't recompute the instantiation...
4884 // Non Simple classes will have become constants by now
4888 if(_class.type == normalClass || _class.type == noHeadClass)
4890 inst.data = (byte *)eInstance_New(_class);
4891 if(_class.type == normalClass)
4892 ((Instance)inst.data)._refCount++;
4895 inst.data = new0 byte[_class.structSize];
4900 for(members = inst.members->first; members; members = members.next)
4902 switch(members.type)
4904 case dataMembersInit:
4906 if(members.dataMembers)
4909 for(member = members.dataMembers->first; member; member = member.next)
4911 Identifier ident = member.identifiers ? member.identifiers->first : null;
4914 Property prop = null;
4915 DataMember dataMember = null;
4916 Method method = null;
4917 uint dataMemberOffset;
4921 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4924 if(curMember.isProperty)
4925 prop = (Property)curMember;
4928 dataMember = curMember;
4930 // CHANGED THIS HERE
4931 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4933 // 2013/17/29 -- It seems that this was missing here!
4934 if(_class.type == normalClass)
4935 dataMemberOffset += _class.base.structSize;
4936 // dataMemberOffset = dataMember.offset;
4943 prop = eClass_FindProperty(_class, ident.string, privateModule);
4947 if(prop.memberAccess == publicAccess)
4949 curMember = (DataMember)prop;
4950 curClass = prop._class;
4955 DataMember _subMemberStack[256];
4956 int _subMemberStackPos = 0;
4958 // FILL MEMBER STACK
4959 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4964 if(dataMember.memberAccess == publicAccess)
4966 curMember = dataMember;
4967 curClass = dataMember._class;
4968 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4969 subMemberStackPos = _subMemberStackPos;
4975 if(found && member.initializer && member.initializer.type == expInitializer)
4977 Expression value = member.initializer.exp;
4979 bool deepMember = false;
4982 type = prop.dataType;
4986 if(!dataMember.dataType)
4987 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4989 type = dataMember.dataType;
4992 if(ident && ident.next)
4996 // for(; ident && type; ident = ident.next)
4997 for(ident = ident.next; ident && type; ident = ident.next)
4999 if(type.kind == classType)
5001 prop = eClass_FindProperty(type._class.registered,
5002 ident.string, privateModule);
5004 type = prop.dataType;
5007 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
5008 ident.string, &dataMemberOffset, privateModule, null, null);
5010 type = dataMember.dataType;
5013 else if(type.kind == structType || type.kind == unionType)
5016 for(memberType = type.members.first; memberType; memberType = memberType.next)
5018 if(!strcmp(memberType.name, ident.string))
5029 FreeType(value.destType);
5030 value.destType = type;
5031 if(type) type.refCount++;
5032 ComputeExpression(value);
5034 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
5036 if(type.kind == classType)
5038 Class _class = type._class.registered;
5039 if(_class.type == bitClass || _class.type == unitClass ||
5040 _class.type == enumClass)
5042 if(!_class.dataType)
5043 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5044 type = _class.dataType;
5050 void * ptr = inst.data + dataMemberOffset;
5052 if(value.type == constantExp)
5058 GetInt(value, (int*)ptr);
5063 GetInt64(value, (int64*)ptr);
5068 GetIntPtr(value, (intptr*)ptr);
5073 GetIntSize(value, (intsize*)ptr);
5078 GetFloat(value, (float*)ptr);
5083 GetDouble(value, (double *)ptr);
5088 else if(value.type == instanceExp)
5090 if(type.kind == classType)
5092 Class _class = type._class.registered;
5093 if(_class.type == structClass)
5095 ComputeTypeSize(type);
5096 if(value.instance.data)
5097 memcpy(ptr, value.instance.data, type.size);
5104 if(value.type == instanceExp && value.instance.data)
5106 if(type.kind == classType)
5108 Class _class = type._class.registered;
5109 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5111 void (*Set)(void *, void *) = (void *)prop.Set;
5112 Set(inst.data, value.instance.data);
5113 PopulateInstance(inst);
5117 else if(value.type == constantExp)
5123 void (*Set)(void *, double) = (void *)prop.Set;
5124 Set(inst.data, strtod(value.constant, null) );
5129 void (*Set)(void *, float) = (void *)prop.Set;
5130 Set(inst.data, (float)(strtod(value.constant, null)));
5135 void (*Set)(void *, int) = (void *)prop.Set;
5136 Set(inst.data, (int)strtol(value.constant, null, 0));
5141 void (*Set)(void *, int64) = (void *)prop.Set;
5142 Set(inst.data, _strtoi64(value.constant, null, 0));
5147 void (*Set)(void *, intptr) = (void *)prop.Set;
5148 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5153 void (*Set)(void *, intsize) = (void *)prop.Set;
5154 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5159 else if(value.type == stringExp)
5162 ReadString(temp, value.string);
5163 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5167 else if(!deepMember && type && _class.type == unitClass)
5171 // Only support converting units to units for now...
5172 if(value.type == constantExp)
5174 if(type.kind == classType)
5176 Class _class = type._class.registered;
5177 if(_class.type == unitClass)
5179 if(!_class.dataType)
5180 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5181 type = _class.dataType;
5184 // TODO: Assuming same base type for units...
5190 float (*Set)(float) = (void *)prop.Set;
5191 GetFloat(member.initializer.exp, &fValue);
5192 exp.constant = PrintFloat(Set(fValue));
5193 exp.type = constantExp;
5199 double (*Set)(double) = (void *)prop.Set;
5200 GetDouble(member.initializer.exp, &dValue);
5201 exp.constant = PrintDouble(Set(dValue));
5202 exp.type = constantExp;
5209 else if(!deepMember && type && _class.type == bitClass)
5213 if(value.type == instanceExp && value.instance.data)
5215 unsigned int (*Set)(void *) = (void *)prop.Set;
5216 bits = Set(value.instance.data);
5218 else if(value.type == constantExp)
5224 BitMember bitMember = (BitMember) dataMember;
5227 bits = (bits & ~bitMember.mask);
5228 if(!bitMember.dataType)
5229 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5230 type = bitMember.dataType;
5231 if(type.kind == classType && type._class && type._class.registered)
5233 if(!type._class.registered.dataType)
5234 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5235 type = type._class.registered.dataType;
5240 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5241 case shortType: { uint16 v; type.isSigned ? GetShort(value, (uint16 *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5243 case longType: { uint v; type.isSigned ? GetInt(value, (uint *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5244 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (uint64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5245 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (uintptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5246 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (uintsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5248 bits |= part << bitMember.pos;
5254 if(_class && _class.type == unitClass)
5256 ComputeExpression(member.initializer.exp);
5257 exp.constant = member.initializer.exp.constant;
5258 exp.type = constantExp;
5260 member.initializer.exp.constant = null;
5270 if(_class && _class.type == bitClass)
5272 exp.constant = PrintHexUInt(bits);
5273 exp.type = constantExp;
5275 if(exp.type != instanceExp)
5281 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5283 bool result = false;
5287 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5288 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5292 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5293 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5296 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5297 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5298 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5301 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5302 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5303 result = GetOpFloat(op, &op.f);
5306 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5307 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5308 result = GetOpDouble(op, &op.d);
5311 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5312 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5313 result = GetOpUIntPtr(op, &op.ui64);
5316 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5317 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5318 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5321 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5322 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5325 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5326 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5332 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5334 if(exp.op.op == SIZEOF)
5336 FreeExpContents(exp);
5337 exp.type = constantExp;
5338 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5349 // Provide default unary +
5350 Expression exp2 = exp.op.exp2;
5352 FreeExpContents(exp);
5353 FreeType(exp.expType);
5354 FreeType(exp.destType);
5360 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5362 // unary arithmetic increment and decrement
5363 //OPERATOR_ALL(UNARY, ++, Inc)
5364 //OPERATOR_ALL(UNARY, --, Dec)
5367 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5369 // unary logical negation
5371 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5377 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5379 if(Promote(op2, op1.kind, op1.type.isSigned))
5380 op2.kind = op1.kind, op2.ops = op1.ops;
5381 else if(Promote(op1, op2.kind, op2.type.isSigned))
5382 op1.kind = op2.kind, op1.ops = op2.ops;
5386 // binary arithmetic
5388 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5391 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5394 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5397 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5400 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5402 // binary arithmetic assignment
5403 //OPERATOR_ALL(BINARY, =, Asign)
5404 //OPERATOR_ALL(BINARY, +=, AddAsign)
5405 //OPERATOR_ALL(BINARY, -=, SubAsign)
5406 //OPERATOR_ALL(BINARY, *=, MulAsign)
5407 //OPERATOR_ALL(BINARY, /=, DivAsign)
5408 //OPERATOR_ALL(BINARY, %=, ModAsign)
5413 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5417 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5420 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5423 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5426 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5428 // binary bitwise assignment
5429 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5430 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5431 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5432 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5433 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5434 // binary logical equality
5436 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5439 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5443 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5446 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5448 // binary logical relational
5450 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5453 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5456 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5459 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5466 void ComputeExpression(Expression exp)
5468 char expString[10240];
5469 expString[0] = '\0';
5471 PrintExpression(exp, expString);
5478 ComputeInstantiation(exp);
5487 Expression exp1, exp2 = null;
5491 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5494 Expression e = exp.op.exp2;
5496 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5498 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5500 if(e.type == extensionCompoundExp)
5501 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5506 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5508 if(e.type == stringExp && e.string)
5510 char * string = e.string;
5511 int len = strlen(string);
5512 char * tmp = new char[len-2+1];
5513 len = UnescapeString(tmp, string + 1, len - 2);
5515 FreeExpContents(exp);
5516 exp.type = constantExp;
5517 exp.constant = PrintUInt(len + 1);
5521 Type type = e.expType;
5523 FreeExpContents(exp);
5524 exp.type = constantExp;
5525 exp.constant = PrintUInt(ComputeTypeSize(type));
5531 ComputeExpression(exp.op.exp2);
5535 ComputeExpression(exp.op.exp1);
5538 op1 = GetOperand(exp1);
5539 if(op1.type) op1.type.refCount++;
5542 op2 = GetOperand(exp2);
5543 if(op2.type) op2.type.refCount++;
5549 op1 = GetOperand(exp1);
5550 if(op1.type) op1.type.refCount++;
5553 CallOperator(exp, exp1, exp2, op1, op2);
5560 if(exp.op.exp1 && exp.op.exp2)
5565 FreeExpContents(exp);
5566 op1.ops.BitAnd(exp, op1, op2);
5575 FreeExpContents(exp);
5576 op1.ops.Mul(exp, op1, op2);
5585 FreeExpContents(exp);
5586 op1.ops.Add(exp, op1, op2);
5591 // Provide default unary +
5592 Expression exp2 = exp.op.exp2;
5594 FreeExpContents(exp);
5595 FreeType(exp.expType);
5596 FreeType(exp.destType);
5607 FreeExpContents(exp);
5608 op1.ops.Sub(exp, op1, op2);
5615 FreeExpContents(exp);
5616 op1.ops.Neg(exp, op1);
5623 FreeExpContents(exp);
5624 op1.ops.BitNot(exp, op1);
5630 FreeExpContents(exp);
5631 op1.ops.Not(exp, op1);
5634 // Binary only operators
5638 FreeExpContents(exp);
5639 op1.ops.Div(exp, op1, op2);
5645 FreeExpContents(exp);
5646 op1.ops.Mod(exp, op1, op2);
5658 FreeExpContents(exp);
5659 op1.ops.Sma(exp, op1, op2);
5668 FreeExpContents(exp);
5669 op1.ops.Grt(exp, op1, op2);
5678 FreeExpContents(exp);
5679 op1.ops.SmaEqu(exp, op1, op2);
5688 FreeExpContents(exp);
5689 op1.ops.GrtEqu(exp, op1, op2);
5698 FreeExpContents(exp);
5699 op1.ops.Equ(exp, op1, op2);
5708 FreeExpContents(exp);
5709 op1.ops.Nqu(exp, op1, op2);
5716 FreeExpContents(exp);
5717 op1.ops.BitOr(exp, op1, op2);
5723 FreeExpContents(exp);
5724 op1.ops.BitXor(exp, op1, op2);
5732 FreeExpContents(exp);
5733 exp.type = constantExp;
5734 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5738 if(op1.type) FreeType(op1.type);
5739 if(op2.type) FreeType(op2.type);
5743 case extensionExpressionExp:
5746 for(e = exp.list->first; e; e = n)
5751 OldList * list = exp.list;
5752 Expression prev = exp.prev;
5753 Expression next = exp.next;
5754 ComputeExpression(e);
5755 //FreeExpContents(exp);
5756 FreeType(exp.expType);
5757 FreeType(exp.destType);
5776 exp.isConstant = true;
5778 ComputeExpression(exp.index.exp);
5779 if(!exp.index.exp.isConstant)
5780 exp.isConstant = false;
5782 for(e = exp.index.index->first; e; e = e.next)
5784 ComputeExpression(e);
5787 // Check if this type is int
5790 exp.isConstant = false;
5792 exp.expType = Dereference(exp.index.exp.expType);
5798 Expression memberExp = exp.member.exp;
5799 Identifier memberID = exp.member.member;
5802 ComputeExpression(exp.member.exp);
5803 type = exp.member.exp.expType;
5806 Class _class = (exp.member.member && exp.member.member.classSym) ? exp.member.member.classSym.registered : (((type.kind == classType || type.kind == subClassType) && type._class) ? type._class.registered : null);
5807 Property prop = null;
5808 DataMember member = null;
5809 Class convertTo = null;
5810 if(type.kind == subClassType && exp.member.exp.type == classExp)
5811 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5818 PrintTypeNoConst(type, string, false, true);
5819 classSym = FindClass(string);
5820 _class = classSym ? classSym.registered : null;
5823 if(exp.member.member)
5825 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5827 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5829 if(!prop && !member && _class && exp.member.member)
5831 Symbol classSym = FindClass(exp.member.member.string);
5833 _class = classSym ? classSym.registered : null;
5834 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5841 Type type = prop.dataType;
5842 // TODO: Assuming same base type for units...
5843 if(_class.type == unitClass)
5845 if(type.kind == classType)
5847 Class _class = type._class.registered;
5848 if(_class.type == unitClass)
5850 if(!_class.dataType)
5851 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5852 type = _class.dataType;
5860 float (*Get)(float) = (void *)prop.Get;
5861 GetFloat(exp.member.exp, &value);
5862 exp.constant = PrintFloat(Get ? Get(value) : value);
5863 exp.type = constantExp;
5869 double (*Get)(double);
5870 GetDouble(exp.member.exp, &value);
5873 Get = (void *)prop.Set;
5875 Get = (void *)prop.Get;
5876 exp.constant = PrintDouble(Get ? Get(value) : value);
5877 exp.type = constantExp;
5886 Expression value = exp.member.exp;
5889 ProcessPropertyType(prop);
5891 type = prop.dataType;
5894 // printf("Investigate this\n");
5896 else if(_class.type == structClass)
5902 Class propertyClass = type._class.registered;
5903 if(propertyClass.type == structClass && value.type == instanceExp)
5905 void (*Set)(void *, void *) = (void *)prop.Set;
5906 exp.instance = Instantiation { };
5907 exp.instance.data = new0 byte[_class.structSize];
5908 exp.instance._class = MkSpecifierName(_class.fullName);
5909 exp.instance.loc = exp.loc;
5910 exp.type = instanceExp;
5911 Set(exp.instance.data, value.instance.data);
5912 PopulateInstance(exp.instance);
5919 void (*Set)(void *, int) = (void *)prop.Set;
5921 exp.instance = Instantiation { };
5922 exp.instance.data = new0 byte[_class.structSize];
5923 exp.instance._class = MkSpecifierName(_class.fullName);
5924 exp.instance.loc = exp.loc;
5925 exp.type = instanceExp;
5927 GetInt(value, &intValue);
5929 Set(exp.instance.data, intValue);
5930 PopulateInstance(exp.instance);
5936 void (*Set)(void *, int64) = (void *)prop.Set;
5938 exp.instance = Instantiation { };
5939 exp.instance.data = new0 byte[_class.structSize];
5940 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5941 exp.instance.loc = exp.loc;
5942 exp.type = instanceExp;
5944 GetInt64(value, &intValue);
5946 Set(exp.instance.data, intValue);
5947 PopulateInstance(exp.instance);
5954 void (*Set)(void *, intptr) = (void *)prop.Set;
5956 exp.instance = Instantiation { };
5957 exp.instance.data = new0 byte[_class.structSize];
5958 exp.instance._class = MkSpecifierName(_class.fullName);
5959 exp.instance.loc = exp.loc;
5960 exp.type = instanceExp;
5962 GetIntPtr(value, &intValue);
5964 Set(exp.instance.data, intValue);
5965 PopulateInstance(exp.instance);
5972 void (*Set)(void *, intsize) = (void *)prop.Set;
5974 exp.instance = Instantiation { };
5975 exp.instance.data = new0 byte[_class.structSize];
5976 exp.instance._class = MkSpecifierName(_class.fullName);
5977 exp.instance.loc = exp.loc;
5978 exp.type = instanceExp;
5980 GetIntSize(value, &intValue);
5982 Set(exp.instance.data, intValue);
5983 PopulateInstance(exp.instance);
5989 void (*Set)(void *, float) = (void *)prop.Set;
5991 exp.instance = Instantiation { };
5992 exp.instance.data = new0 byte[_class.structSize];
5993 exp.instance._class = MkSpecifierName(_class.fullName);
5994 exp.instance.loc = exp.loc;
5995 exp.type = instanceExp;
5997 GetFloat(value, &floatValue);
5999 Set(exp.instance.data, floatValue);
6000 PopulateInstance(exp.instance);
6006 void (*Set)(void *, double) = (void *)prop.Set;
6008 exp.instance = Instantiation { };
6009 exp.instance.data = new0 byte[_class.structSize];
6010 exp.instance._class = MkSpecifierName(_class.fullName);
6011 exp.instance.loc = exp.loc;
6012 exp.type = instanceExp;
6014 GetDouble(value, &doubleValue);
6016 Set(exp.instance.data, doubleValue);
6017 PopulateInstance(exp.instance);
6022 else if(_class.type == bitClass)
6028 Class propertyClass = type._class.registered;
6029 if(propertyClass.type == structClass && value.instance.data)
6031 unsigned int (*Set)(void *) = (void *)prop.Set;
6032 unsigned int bits = Set(value.instance.data);
6033 exp.constant = PrintHexUInt(bits);
6034 exp.type = constantExp;
6037 else if(_class.type == bitClass)
6040 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6043 GetUInt(exp.member.exp, &value);
6045 exp.constant = PrintHexUInt(bits);
6046 exp.type = constantExp;
6054 if(_class.type == bitClass)
6057 GetUInt(exp.member.exp, &value);
6063 Class _class = type._class.registered;
6064 if(_class.type == structClass)
6066 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6068 exp.instance = Instantiation { };
6069 exp.instance.data = new0 byte[_class.structSize];
6070 exp.instance._class = MkSpecifierName(_class.fullName);
6071 exp.instance.loc = exp.loc;
6072 //exp.instance.fullSet = true;
6073 exp.type = instanceExp;
6074 Get(value, exp.instance.data);
6075 PopulateInstance(exp.instance);
6077 else if(_class.type == bitClass)
6079 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6080 uint64 bits = Get(value);
6081 exp.constant = PrintHexUInt64(bits);
6082 exp.type = constantExp;
6088 else if(_class.type == structClass)
6090 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6095 Class _class = type._class.registered;
6096 if(_class.type == structClass && value)
6098 void (*Get)(void *, void *) = (void *)prop.Get;
6100 exp.instance = Instantiation { };
6101 exp.instance.data = new0 byte[_class.structSize];
6102 exp.instance._class = MkSpecifierName(_class.fullName);
6103 exp.instance.loc = exp.loc;
6104 //exp.instance.fullSet = true;
6105 exp.type = instanceExp;
6106 Get(value, exp.instance.data);
6107 PopulateInstance(exp.instance);
6115 char * value = exp.member.exp.instance.data;
6120 Class _class = type._class.registered;
6121 if(_class.type == normalClass)
6123 void *(*Get)(void *) = (void *)prop.Get;
6125 exp.instance = Instantiation { };
6126 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6127 exp.type = instanceExp;
6128 exp.instance.data = Get(value, exp.instance.data);
6140 exp.isConstant = false;
6148 if(exp.type != ExpressionType::memberExp)
6150 FreeExpression(memberExp);
6151 FreeIdentifier(memberID);
6157 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6158 FreeExpContents(exp);
6159 exp.constant = PrintUInt(ComputeTypeSize(type));
6160 exp.type = constantExp;
6166 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6167 if(classSym && classSym.registered)
6169 if(classSym.registered.fixed)
6171 FreeSpecifier(exp._class);
6172 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6173 exp.type = constantExp;
6177 char className[1024];
6178 strcpy(className, "__ecereClass_");
6179 FullClassNameCat(className, classSym.string, true);
6180 MangleClassName(className);
6182 DeclareClass(classSym, className);
6184 FreeExpContents(exp);
6185 exp.type = pointerExp;
6186 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6187 exp.member.member = MkIdentifier("structSize");
6197 if(exp.type == castExp)
6200 ComputeExpression(exp.cast.exp);
6203 if(e && exp.expType)
6206 type = exp.destType;
6209 if(type.kind == classType)
6211 Class _class = type._class.registered;
6212 if(_class && (_class.type == unitClass || _class.type == bitClass))
6214 if(!_class.dataType)
6215 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6216 type = _class.dataType;
6227 if(GetChar(e, &value))
6229 FreeExpContents(exp);
6230 exp.constant = PrintChar(value);
6231 exp.type = constantExp;
6236 unsigned char value = 0;
6237 if(GetUChar(e, &value))
6239 FreeExpContents(exp);
6240 exp.constant = PrintUChar(value);
6241 exp.type = constantExp;
6249 if(GetShort(e, &value))
6251 FreeExpContents(exp);
6252 exp.constant = PrintShort(value);
6253 exp.type = constantExp;
6258 unsigned short value = 0;
6259 if(GetUShort(e, &value))
6261 FreeExpContents(exp);
6262 exp.constant = PrintUShort(value);
6263 exp.type = constantExp;
6271 if(GetInt(e, &value))
6273 FreeExpContents(exp);
6274 exp.constant = PrintInt(value);
6275 exp.type = constantExp;
6280 unsigned int value = 0;
6281 if(GetUInt(e, &value))
6283 FreeExpContents(exp);
6284 exp.constant = PrintUInt(value);
6285 exp.type = constantExp;
6293 if(GetInt64(e, &value))
6295 FreeExpContents(exp);
6296 exp.constant = PrintInt64(value);
6297 exp.type = constantExp;
6303 if(GetUInt64(e, &value))
6305 FreeExpContents(exp);
6306 exp.constant = PrintUInt64(value);
6307 exp.type = constantExp;
6315 if(GetIntPtr(e, &value))
6317 FreeExpContents(exp);
6318 exp.constant = PrintInt64((int64)value);
6319 exp.type = constantExp;
6325 if(GetUIntPtr(e, &value))
6327 FreeExpContents(exp);
6328 exp.constant = PrintUInt64((uint64)value);
6329 exp.type = constantExp;
6337 if(GetIntSize(e, &value))
6339 FreeExpContents(exp);
6340 exp.constant = PrintInt64((int64)value);
6341 exp.type = constantExp;
6347 if(GetUIntSize(e, &value))
6349 FreeExpContents(exp);
6350 exp.constant = PrintUInt64((uint64)value);
6351 exp.type = constantExp;
6358 if(GetFloat(e, &value))
6360 FreeExpContents(exp);
6361 exp.constant = PrintFloat(value);
6362 exp.type = constantExp;
6369 if(GetDouble(e, &value))
6371 FreeExpContents(exp);
6372 exp.constant = PrintDouble(value);
6373 exp.type = constantExp;
6388 // Caring only about last expression for now...
6389 ComputeExpression(exp.cond.exp->last);
6390 if(exp.cond.elseExp)
6391 ComputeExpression(exp.cond.elseExp);
6393 ComputeExpression(exp.cond.cond);
6395 op1 = GetOperand(exp.cond.cond);
6396 if(op1.type) op1.type.refCount++;
6397 op2 = GetOperand(exp.cond.exp->last);
6398 if(op2.type) op2.type.refCount++;
6399 op3 = GetOperand(exp.cond.elseExp);
6400 if(op3.type) op3.type.refCount++;
6402 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6403 if(op1.type) FreeType(op1.type);
6404 if(op2.type) FreeType(op2.type);
6405 if(op3.type) FreeType(op3.type);
6411 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6416 OldList converts { };
6419 if(destType.kind == voidType)
6422 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6426 // for(convert = converts.last; convert; convert = convert.prev)
6427 for(convert = converts.first; convert; convert = convert.next)
6429 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6432 Expression newExp { };
6433 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6435 // TODO: Check this...
6439 newExp.destType = null;
6444 exp.type = memberExp;
6445 exp.addedThis = true;
6446 exp.member.exp = newExp;
6447 FreeType(exp.member.exp.expType);
6449 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6450 exp.member.exp.expType.classObjectType = objectType;
6451 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6452 exp.member.memberType = propertyMember;
6453 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6454 // TESTING THIS... for (int)degrees
6455 exp.needCast = true;
6456 if(exp.expType) exp.expType.refCount++;
6457 ApplyAnyObjectLogic(exp.member.exp);
6462 /*if(exp.isConstant)
6464 // Color { ColorRGB = [exp] };
6465 exp.type = instanceExp;
6466 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6467 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6468 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6472 // If not constant, don't turn it yet into an instantiation
6473 // (Go through the deep members system first)
6474 exp.type = memberExp;
6475 exp.addedThis = true;
6476 exp.member.exp = newExp;
6478 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6479 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6480 newExp.expType._class.registered.type == noHeadClass)
6482 newExp.byReference = true;
6485 FreeType(exp.member.exp.expType);
6486 /*exp.member.exp.expType = convert.convert.dataType;
6487 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6488 exp.member.exp.expType = null;
6489 if(convert.convert.dataType)
6491 exp.member.exp.expType = { };
6492 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6493 exp.member.exp.expType.refCount = 1;
6494 exp.member.exp.expType.classObjectType = objectType;
6495 ApplyAnyObjectLogic(exp.member.exp);
6498 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6499 exp.member.memberType = reverseConversionMember;
6500 exp.expType = convert.resultType ? convert.resultType :
6501 MkClassType(convert.convert._class.fullName);
6502 exp.needCast = true;
6503 if(convert.resultType) convert.resultType.refCount++;
6509 FreeType(exp.expType);
6512 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6513 if(exp.destType.casted)
6514 exp.needCast = true;
6515 if(exp.expType) exp.expType.refCount++;
6519 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6520 if(exp.destType.casted)
6521 exp.needCast = true;
6522 if(convert.resultType)
6523 convert.resultType.refCount++;
6527 if(exp.isConstant && inCompiler)
6528 ComputeExpression(exp);
6530 converts.Free(FreeConvert);
6533 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6535 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6537 if(!result && exp.expType && exp.destType)
6539 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6540 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6541 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6542 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6546 // if(result) CheckTemplateTypes(exp);
6550 void CheckTemplateTypes(Expression exp)
6552 Expression nbExp = GetNonBracketsExp(exp);
6553 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6554 (nbExp == exp || nbExp.type != castExp))
6556 Expression newExp { };
6559 if(exp.destType) exp.destType.refCount++;
6560 if(exp.expType) exp.expType.refCount++;
6564 switch(exp.expType.kind)
6567 if(exp.destType.classObjectType)
6569 // We need to pass the address, just pass it along (Undo what was done above)
6570 if(exp.destType) exp.destType.refCount--;
6571 if(exp.expType) exp.expType.refCount--;
6576 // If we're looking for value:
6577 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6579 OldList * unionDefs = MkList();
6580 OldList * statements = MkList();
6581 context = PushContext();
6582 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6583 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6584 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6585 exp.type = extensionCompoundExp;
6586 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6587 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6588 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6589 exp.compound.compound.context = context;
6590 PopContext(context);
6595 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6596 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6597 exp.needCast = true;
6601 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6603 Expression newExp { };
6607 if(exp.destType) exp.destType.refCount++;
6608 if(exp.expType) exp.expType.refCount++;
6612 switch(exp.expType.kind)
6615 if(exp.destType.classObjectType)
6617 // We need to pass the address, just pass it along (Undo what was done above)
6618 if(exp.destType) exp.destType.refCount--;
6619 if(exp.expType) exp.expType.refCount--;
6624 // If we're looking for value:
6625 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6627 OldList * unionDefs = MkList();
6628 OldList * statements = MkList();
6629 context = PushContext();
6630 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6631 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6632 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6633 exp.type = extensionCompoundExp;
6634 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6635 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6636 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6637 exp.compound.compound.context = context;
6638 PopContext(context);
6643 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6645 exp.type = bracketsExp;
6646 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6647 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6648 ProcessExpressionType(exp.list->first);
6653 exp.type = bracketsExp;
6654 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6655 exp.needTemplateCast = 2;
6656 newExp.needCast = true;
6657 newExp.needTemplateCast = 2;
6658 ProcessExpressionType(exp.list->first);
6664 if(exp.expType.kind == templateType)
6666 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6669 FreeType(exp.destType);
6670 FreeType(exp.expType);
6675 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6680 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6681 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6685 char typeString[1024];
6687 OldList * specs = MkList();
6688 typeString[0] = '\0';
6689 PrintType(exp.expType, typeString, false, false);
6690 decl = SpecDeclFromString(typeString, specs, null);
6693 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6694 exp.cast.typeName = MkTypeName(specs, decl);
6695 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6696 exp.cast.exp.needCast = true;
6703 // TODO: The Symbol tree should be reorganized by namespaces
6705 // - Tree of all symbols within (stored without namespace)
6706 // - Tree of sub-namespaces
6708 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6710 int nsLen = strlen(nameSpace);
6712 // Start at the name space prefix
6713 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6715 char * s = symbol.string;
6716 if(!strncmp(s, nameSpace, nsLen))
6718 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6721 for(c = strlen(s)-1; c >= 0; c--)
6726 if(!strcmp(namePart, name))
6728 // TODO: Error on ambiguity
6738 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6741 char nameSpace[1024];
6742 const char * namePart;
6743 bool gotColon = false;
6745 nameSpace[0] = '\0';
6746 for(c = strlen(name)-1; c >= 0; c--)
6753 namePart = name+c+1;
6754 while(c >= 0 && name[c] == ':') c--;
6757 // Try an exact match first
6758 Symbol symbol = (Symbol)tree.FindString(name);
6762 // Namespace specified
6763 memcpy(nameSpace, name, c + 1);
6766 return ScanWithNameSpace(tree, nameSpace, namePart);
6770 // Looking for a global symbol, e.g. ::Sleep()
6771 Symbol symbol = (Symbol)tree.FindString(namePart);
6776 // Name only (no namespace specified)
6777 Symbol symbol = (Symbol)tree.FindString(namePart);
6780 return ScanWithNameSpace(tree, "", namePart);
6785 static void ProcessDeclaration(Declaration decl);
6787 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6790 //Time startTime = GetTime();
6792 // Optimize this later? Do this before/less?
6794 Symbol symbol = null;
6795 // First, check if the identifier is declared inside the function
6796 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6798 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6800 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6806 strcpy(curName, thisNameSpace);
6807 strcat(curName, "::");
6808 strcat(curName, name);
6809 // Try to resolve in current namespace first
6810 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6813 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6816 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6818 if(symbol || ctx == endContext) break;
6820 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6822 if(symbol.pointerExternal.type == functionExternal)
6824 FunctionDefinition function = symbol.pointerExternal.function;
6826 // Modified this recently...
6827 Context tmpContext = curContext;
6829 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6830 curContext = tmpContext;
6832 symbol.pointerExternal.symbol = symbol;
6835 DeclareType(symbol.type, true, true);
6837 ast->Insert(curExternal.prev, symbol.pointerExternal);
6839 symbol.id = curExternal.symbol.idCode;
6842 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6844 ast->Move(symbol.pointerExternal, curExternal.prev);
6845 symbol.id = curExternal.symbol.idCode;
6849 //findSymbolTotalTime += GetTime() - startTime;
6854 static void GetTypeSpecs(Type type, OldList * specs)
6856 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6861 if(type._class.registered)
6863 if(!type._class.registered.dataType)
6864 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6865 GetTypeSpecs(type._class.registered.dataType, specs);
6869 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6870 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6871 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6872 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6873 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6874 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6875 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6876 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6879 ListAdd(specs, MkSpecifier(INT)); break;
6883 static void PrintArraySize(Type arrayType, char * string)
6888 if(arrayType.enumClass)
6889 strcat(size, arrayType.enumClass.string);
6890 else if(arrayType.arraySizeExp)
6891 PrintExpression(arrayType.arraySizeExp, size);
6893 strcat(string, size);
6896 // WARNING : This function expects a null terminated string since it recursively concatenate...
6897 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6901 if(printConst && type.constant)
6902 strcat(string, "const ");
6907 Symbol c = type._class;
6908 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6909 // look into merging with thisclass ?
6910 if(type.classObjectType == typedObject)
6911 strcat(string, "typed_object");
6912 else if(type.classObjectType == anyObject)
6913 strcat(string, "any_object");
6917 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6919 if(type.byReference)
6920 strcat(string, " &");
6923 case voidType: strcat(string, "void"); break;
6924 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6925 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6926 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6927 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6928 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6929 case _BoolType: strcat(string, "_Bool"); break;
6930 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6931 case floatType: strcat(string, "float"); break;
6932 case doubleType: strcat(string, "double"); break;
6936 strcat(string, "struct ");
6937 strcat(string, type.enumName);
6939 else if(type.typeName)
6940 strcat(string, type.typeName);
6944 strcat(string, "struct { ");
6945 for(member = type.members.first; member; member = member.next)
6947 PrintType(member, string, true, fullName);
6948 strcat(string,"; ");
6956 strcat(string, "union ");
6957 strcat(string, type.enumName);
6959 else if(type.typeName)
6960 strcat(string, type.typeName);
6963 strcat(string, "union ");
6964 strcat(string,"(unnamed)");
6970 strcat(string, "enum ");
6971 strcat(string, type.enumName);
6973 else if(type.typeName)
6974 strcat(string, type.typeName);
6976 strcat(string, "int"); // "enum");
6979 strcat(string, "...");
6982 strcat(string, "subclass(");
6983 strcat(string, type._class ? type._class.string : "int");
6984 strcat(string, ")");
6987 strcat(string, type.templateParameter.identifier.string);
6990 strcat(string, "thisclass");
6993 strcat(string, "__builtin_va_list");
6999 static void PrintName(Type type, char * string, bool fullName)
7001 if(type.name && type.name[0])
7004 strcat(string, type.name);
7007 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7008 if(name) name += 2; else name = type.name;
7009 strcat(string, name);
7014 static void PrintAttribs(Type type, char * string)
7018 if(type.dllExport) strcat(string, "dllexport ");
7019 if(type.attrStdcall) strcat(string, "stdcall ");
7023 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7025 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7027 Type attrType = null;
7028 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7029 PrintAttribs(type, string);
7030 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7031 strcat(string, " const");
7032 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7033 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7034 strcat(string, " (");
7035 if(type.kind == pointerType)
7037 if(type.type.kind == functionType || type.type.kind == methodType)
7038 PrintAttribs(type.type, string);
7040 if(type.kind == pointerType)
7042 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7043 strcat(string, "*");
7045 strcat(string, " *");
7047 if(printConst && type.constant && type.kind == pointerType)
7048 strcat(string, " const");
7051 PrintTypeSpecs(type, string, fullName, printConst);
7054 static void PostPrintType(Type type, char * string, bool fullName)
7056 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7057 strcat(string, ")");
7058 if(type.kind == arrayType)
7059 PrintArraySize(type, string);
7060 else if(type.kind == functionType)
7063 strcat(string, "(");
7064 for(param = type.params.first; param; param = param.next)
7066 PrintType(param, string, true, fullName);
7067 if(param.next) strcat(string, ", ");
7069 strcat(string, ")");
7071 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7072 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7076 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7078 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7080 PrePrintType(type, string, fullName, null, printConst);
7082 if(type.thisClass || (printName && type.name && type.name[0]))
7083 strcat(string, " ");
7084 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7086 Symbol _class = type.thisClass;
7087 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7089 if(type.classObjectType == classPointer)
7090 strcat(string, "class");
7092 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7094 else if(_class && _class.string)
7096 String s = _class.string;
7101 char * name = RSearchString(s, "::", strlen(s), true, false);
7102 if(name) name += 2; else name = s;
7103 strcat(string, name);
7106 strcat(string, "::");
7109 if(printName && type.name)
7110 PrintName(type, string, fullName);
7111 PostPrintType(type, string, fullName);
7112 if(type.bitFieldCount)
7115 sprintf(count, ":%d", type.bitFieldCount);
7116 strcat(string, count);
7120 void PrintType(Type type, char * string, bool printName, bool fullName)
7122 _PrintType(type, string, printName, fullName, true);
7125 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7127 _PrintType(type, string, printName, fullName, false);
7130 static Type FindMember(Type type, char * string)
7133 for(memberType = type.members.first; memberType; memberType = memberType.next)
7135 if(!memberType.name)
7137 Type subType = FindMember(memberType, string);
7141 else if(!strcmp(memberType.name, string))
7147 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7150 for(memberType = type.members.first; memberType; memberType = memberType.next)
7152 if(!memberType.name)
7154 Type subType = FindMember(memberType, string);
7157 *offset += memberType.offset;
7161 else if(!strcmp(memberType.name, string))
7163 *offset += memberType.offset;
7170 public bool GetParseError() { return parseError; }
7172 Expression ParseExpressionString(char * expression)
7176 fileInput = TempFile { };
7177 fileInput.Write(expression, 1, strlen(expression));
7178 fileInput.Seek(0, start);
7181 parsedExpression = null;
7183 expression_yyparse();
7186 return parsedExpression;
7189 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7191 Identifier id = exp.identifier;
7192 Method method = null;
7193 Property prop = null;
7194 DataMember member = null;
7195 ClassProperty classProp = null;
7197 if(_class && _class.type == enumClass)
7199 NamedLink value = null;
7200 Class enumClass = eSystem_FindClass(privateModule, "enum");
7204 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7206 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7207 for(value = e.values.first; value; value = value.next)
7209 if(!strcmp(value.name, id.string))
7216 FreeExpContents(exp);
7218 exp.type = constantExp;
7219 exp.isConstant = true;
7220 if(!strcmp(baseClass.dataTypeString, "int"))
7221 sprintf(constant, "%d",(int)value.data);
7223 sprintf(constant, "0x%X",(int)value.data);
7224 exp.constant = CopyString(constant);
7225 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7226 exp.expType = MkClassType(baseClass.fullName);
7234 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7236 ProcessMethodType(method);
7243 // TOCHECK: Put it back to what it was...
7244 // methodClass = _class;
7245 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7250 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7253 ProcessPropertyType(prop);
7254 exp.expType = prop.dataType;
7255 if(prop.dataType) prop.dataType.refCount++;
7258 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7260 if(!member.dataType)
7261 member.dataType = ProcessTypeString(member.dataTypeString, false);
7262 exp.expType = member.dataType;
7263 if(member.dataType) member.dataType.refCount++;
7266 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7268 if(!classProp.dataType)
7269 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7271 if(classProp.constant)
7273 FreeExpContents(exp);
7275 exp.isConstant = true;
7276 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7278 //char constant[256];
7279 exp.type = stringExp;
7280 exp.constant = QMkString((char *)classProp.Get(_class));
7285 exp.type = constantExp;
7286 sprintf(constant, "%d", (int)classProp.Get(_class));
7287 exp.constant = CopyString(constant);
7295 exp.expType = classProp.dataType;
7296 if(classProp.dataType) classProp.dataType.refCount++;
7302 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7304 BinaryTree * tree = &nameSpace.functions;
7305 GlobalData data = (GlobalData)tree->FindString(name);
7309 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7311 data = ScanGlobalData(child, name);
7319 static GlobalData FindGlobalData(char * name)
7322 NameSpace * nameSpace;
7323 nameSpace = globalData;
7324 for(c = 0; name[c]; c++)
7326 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7328 NameSpace * newSpace;
7329 char * spaceName = new char[c - start + 1];
7330 strncpy(spaceName, name + start, c - start);
7331 spaceName[c-start] = '\0';
7332 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7336 nameSpace = newSpace;
7337 if(name[c] == ':') c++;
7343 return ScanGlobalData(nameSpace, name + start);
7348 static int definedExpStackPos;
7349 static void * definedExpStack[512];
7351 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7352 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7354 Expression prev = checkedExp.prev, next = checkedExp.next;
7356 FreeExpContents(checkedExp);
7357 FreeType(checkedExp.expType);
7358 FreeType(checkedExp.destType);
7360 *checkedExp = *newExp;
7364 checkedExp.prev = prev;
7365 checkedExp.next = next;
7368 void ApplyAnyObjectLogic(Expression e)
7370 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7372 char debugExpString[4096];
7373 debugExpString[0] = '\0';
7374 PrintExpression(e, debugExpString);
7377 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7379 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7380 //ellipsisDestType = destType;
7383 Type type = e.expType;
7384 Class _class = null;
7385 //Type destType = e.destType;
7387 if(type.kind == classType && type._class && type._class.registered)
7389 _class = type._class.registered;
7391 else if(type.kind == subClassType)
7393 _class = FindClass("ecere::com::Class").registered;
7397 char string[1024] = "";
7400 PrintTypeNoConst(type, string, false, true);
7401 classSym = FindClass(string);
7402 if(classSym) _class = classSym.registered;
7405 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...
7406 (!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))) ||
7407 destType.byReference)))
7409 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7411 Expression checkedExp = e, newExp;
7413 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7415 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7417 if(checkedExp.type == extensionCompoundExp)
7419 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7422 checkedExp = checkedExp.list->last;
7424 else if(checkedExp.type == castExp)
7425 checkedExp = checkedExp.cast.exp;
7428 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7430 newExp = checkedExp.op.exp2;
7431 checkedExp.op.exp2 = null;
7432 FreeExpContents(checkedExp);
7434 if(e.expType && e.expType.passAsTemplate)
7437 ComputeTypeSize(e.expType);
7438 sprintf(size, "%d", e.expType.size);
7439 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7440 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7441 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7444 ReplaceExpContents(checkedExp, newExp);
7445 e.byReference = true;
7447 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7449 Expression checkedExp; //, newExp;
7452 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7454 e.type == identifierExp ||
7455 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7456 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7457 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7460 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7462 Context context = PushContext();
7464 OldList * specs = MkList();
7465 char typeString[1024];
7466 Expression newExp { };
7468 typeString[0] = '\0';
7471 //if(e.destType) e.destType.refCount++;
7472 // if(exp.expType) exp.expType.refCount++;
7475 newExp.expType = null;
7477 PrintTypeNoConst(e.expType, typeString, false, true);
7478 decl = SpecDeclFromString(typeString, specs, null);
7479 newExp.destType = ProcessType(specs, decl);
7481 curContext = context;
7483 // We need a current compound for this
7487 OldList * stmts = MkList();
7488 e.type = extensionCompoundExp;
7489 sprintf(name, "__internalValue%03X", internalValueCounter++);
7490 if(!curCompound.compound.declarations)
7491 curCompound.compound.declarations = MkList();
7492 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7493 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7494 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7495 e.compound = MkCompoundStmt(null, stmts);
7498 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7501 e.compound = MkCompoundStmt(
7502 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7503 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7505 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7509 Type type = e.destType;
7511 CopyTypeInto(e.destType, type);
7512 e.destType.refCount = 1;
7513 e.destType.classObjectType = none;
7517 e.compound.compound.context = context;
7518 PopContext(context);
7519 curContext = context.parent;
7523 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7525 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7527 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7529 if(checkedExp.type == extensionCompoundExp)
7531 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7534 checkedExp = checkedExp.list->last;
7536 else if(checkedExp.type == castExp)
7537 checkedExp = checkedExp.cast.exp;
7540 Expression operand { };
7541 operand = *checkedExp;
7542 checkedExp.destType = null;
7543 checkedExp.expType = null;
7545 checkedExp.type = opExp;
7546 checkedExp.op.op = '&';
7547 checkedExp.op.exp1 = null;
7548 checkedExp.op.exp2 = operand;
7550 //newExp = MkExpOp(null, '&', checkedExp);
7552 //ReplaceExpContents(checkedExp, newExp);
7559 // If expression type is a simple class, make it an address
7560 // FixReference(e, true);
7563 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7564 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7565 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7567 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"))
7569 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7573 Expression thisExp { };
7576 thisExp.prev = null;
7577 thisExp.next = null;
7580 e.type = bracketsExp;
7581 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7582 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7583 ((Expression)e.list->first).byReference = true;
7585 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7587 e.expType = thisExp.expType;
7588 e.expType.refCount++;
7593 CopyTypeInto(e.expType, thisExp.expType);
7594 e.expType.byReference = false;
7595 e.expType.refCount = 1;
7597 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7598 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7600 e.expType.classObjectType = none;
7605 // TOFIX: Try this for a nice IDE crash!
7607 // The other way around
7610 if(destType && e.expType &&
7611 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7612 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7613 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7615 if(destType.kind == ellipsisType)
7617 Compiler_Error($"Unspecified type\n");
7619 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7621 bool byReference = e.expType.byReference;
7622 Expression thisExp { };
7624 OldList * specs = MkList();
7625 char typeString[1024]; // Watch buffer overruns
7627 ClassObjectType backupClassObjectType;
7628 bool backupByReference;
7630 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7635 backupClassObjectType = type.classObjectType;
7636 backupByReference = type.byReference;
7638 type.classObjectType = none;
7639 type.byReference = false;
7641 typeString[0] = '\0';
7642 PrintType(type, typeString, false, true);
7643 decl = SpecDeclFromString(typeString, specs, null);
7645 type.classObjectType = backupClassObjectType;
7646 type.byReference = backupByReference;
7649 thisExp.prev = null;
7650 thisExp.next = null;
7653 if( ( type.kind == classType && type._class && type._class.registered &&
7654 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7655 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7656 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7657 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7662 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7665 CopyTypeInto(e.expType, type);
7666 e.expType.byReference = false;
7667 e.expType.refCount = 1;
7672 e.cast.typeName = MkTypeName(specs, decl);
7673 e.cast.exp = thisExp;
7674 e.byReference = true;
7678 e.destType = destType;
7679 destType.refCount++;
7684 void ApplyLocation(Expression exp, Location loc)
7690 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7691 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7697 for(e = exp.list->first; e; e = e.next)
7698 ApplyLocation(e, loc);
7705 for(e = exp.index.index->first; e; e = e.next)
7706 ApplyLocation(e, loc);
7709 ApplyLocation(exp.index.exp, loc);
7712 if(exp.call.arguments)
7715 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7716 ApplyLocation(arg, loc);
7719 ApplyLocation(exp.call.exp, loc);
7724 ApplyLocation(exp.member.exp, loc);
7728 ApplyLocation(exp.cast.exp, loc);
7734 for(e = exp.cond.exp->first; e; e = e.next)
7735 ApplyLocation(e, loc);
7738 ApplyLocation(exp.cond.cond, loc);
7739 if(exp.cond.elseExp)
7740 ApplyLocation(exp.cond.elseExp, loc);
7744 ApplyLocation(exp.vaArg.exp, loc);
7751 void ProcessExpressionType(Expression exp)
7753 bool unresolved = false;
7754 Location oldyylloc = yylloc;
7755 bool notByReference = false;
7757 char debugExpString[4096];
7758 debugExpString[0] = '\0';
7759 PrintExpression(exp, debugExpString);
7761 if(!exp || exp.expType)
7764 //eSystem_Logf("%s\n", expString);
7766 // Testing this here
7772 Identifier id = exp.identifier;
7773 if(!id || !topContext) return;
7775 // DOING THIS LATER NOW...
7776 if(id._class && id._class.name)
7778 id.classSym = id._class.symbol; // FindClass(id._class.name);
7779 /* TODO: Name Space Fix ups
7781 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7785 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7787 exp.expType = ProcessTypeString("Module", true);
7790 else */if(strstr(id.string, "__ecereClass") == id.string)
7792 exp.expType = ProcessTypeString("ecere::com::Class", true);
7795 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7797 // Added this here as well
7798 ReplaceClassMembers(exp, thisClass);
7799 if(exp.type != identifierExp)
7801 ProcessExpressionType(exp);
7805 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7810 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7811 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7812 if(!symbol/* && exp.destType*/)
7814 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7820 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7821 if(exp.type != identifierExp)
7823 ProcessExpressionType(exp);
7827 // Static methods called from inside the _class
7828 else if(currentClass && !id._class)
7830 if(ResolveIdWithClass(exp, currentClass, true))
7833 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7837 // If we manage to resolve this symbol
7840 Type type = symbol.type;
7841 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7843 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7845 Context context = SetupTemplatesContext(_class);
7846 type = ReplaceThisClassType(_class);
7847 FinishTemplatesContext(context);
7848 if(type) type.refCount = 0; // We'll be incrementing it right below...
7851 FreeSpecifier(id._class);
7854 id.string = CopyString(symbol.string);
7861 // Commented this out, it was making non-constant enum parameters seen as constant
7862 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7863 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7864 // Add missing cases here... enum Classes...
7865 exp.isConstant = true;
7867 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7868 if(symbol.isParam || !strcmp(id.string, "this"))
7870 if(_class && _class.type == structClass && !type.declaredWithStruct)
7871 exp.byReference = true;
7873 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7874 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7875 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7876 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7878 Identifier id = exp.identifier;
7879 exp.type = bracketsExp;
7880 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7884 if(symbol.isIterator)
7886 if(symbol.isIterator == 3)
7888 exp.type = bracketsExp;
7889 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7890 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7892 ProcessExpressionType(exp);
7894 else if(symbol.isIterator != 4)
7896 exp.type = memberExp;
7897 exp.member.exp = MkExpIdentifier(exp.identifier);
7898 exp.member.exp.expType = exp.expType;
7899 /*if(symbol.isIterator == 6)
7900 exp.member.member = MkIdentifier("key");
7902 exp.member.member = MkIdentifier("data");
7904 ProcessExpressionType(exp);
7911 DefinedExpression definedExp = null;
7912 if(thisNameSpace && !(id._class && !id._class.name))
7915 strcpy(name, thisNameSpace);
7917 strcat(name, id.string);
7918 definedExp = eSystem_FindDefine(privateModule, name);
7921 definedExp = eSystem_FindDefine(privateModule, id.string);
7925 for(c = 0; c<definedExpStackPos; c++)
7926 if(definedExpStack[c] == definedExp)
7928 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7930 Location backupYylloc = yylloc;
7931 File backInput = fileInput;
7932 definedExpStack[definedExpStackPos++] = definedExp;
7934 fileInput = TempFile { };
7935 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7936 fileInput.Seek(0, start);
7939 parsedExpression = null;
7941 expression_yyparse();
7944 fileInput = backInput;
7946 yylloc = backupYylloc;
7948 if(parsedExpression)
7951 exp.type = bracketsExp;
7952 exp.list = MkListOne(parsedExpression);
7953 ApplyLocation(parsedExpression, yylloc);
7954 ProcessExpressionType(exp);
7955 definedExpStackPos--;
7958 definedExpStackPos--;
7964 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7970 GlobalData data = null;
7971 if(thisNameSpace && !(id._class && !id._class.name))
7974 strcpy(name, thisNameSpace);
7976 strcat(name, id.string);
7977 data = FindGlobalData(name);
7980 data = FindGlobalData(id.string);
7983 DeclareGlobalData(data);
7984 exp.expType = data.dataType;
7985 if(data.dataType) data.dataType.refCount++;
7988 id.string = CopyString(data.fullName);
7989 FreeSpecifier(id._class);
7996 GlobalFunction function = null;
7997 if(thisNameSpace && !(id._class && !id._class.name))
8000 strcpy(name, thisNameSpace);
8002 strcat(name, id.string);
8003 function = eSystem_FindFunction(privateModule, name);
8006 function = eSystem_FindFunction(privateModule, id.string);
8011 id.string = CopyString(function.name);
8014 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8015 strcpy(name, "__ecereFunction_");
8016 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8017 if(DeclareFunction(function, name))
8020 id.string = CopyString(name);
8022 exp.expType = function.dataType;
8023 if(function.dataType) function.dataType.refCount++;
8025 FreeSpecifier(id._class);
8042 if(!exp.instance._class)
8044 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8046 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8050 //classSym = FindClass(exp.instance._class.fullName);
8051 //_class = classSym ? classSym.registered : null;
8053 ProcessInstantiationType(exp.instance);
8055 exp.isConstant = exp.instance.isConstant;
8058 if(_class.type == unitClass && _class.base.type != systemClass)
8061 Type destType = exp.destType;
8063 exp.destType = MkClassType(_class.base.fullName);
8064 exp.expType = MkClassType(_class.fullName);
8065 CheckExpressionType(exp, exp.destType, true);
8067 exp.destType = destType;
8069 exp.expType = MkClassType(_class.fullName);
8072 if(exp.instance._class)
8074 exp.expType = MkClassType(exp.instance._class.name);
8075 /*if(exp.expType._class && exp.expType._class.registered &&
8076 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8077 exp.expType.byReference = true;*/
8085 char * constant = exp.constant;
8093 if(constant[0] == '\'')
8095 if((int)((byte *)constant)[1] > 127)
8098 unichar ch = UTF8GetChar(constant + 1, &nb);
8099 if(nb < 2) ch = constant[1];
8101 exp.constant = PrintUInt(ch);
8102 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8103 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8104 type._class = FindClass("unichar");
8106 type.isSigned = false;
8110 type.kind = charType;
8111 type.isSigned = true;
8116 char * dot = strchr(constant, '.');
8117 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8121 exponent = strchr(constant, 'p');
8122 if(!exponent) exponent = strchr(constant, 'P');
8126 exponent = strchr(constant, 'e');
8127 if(!exponent) exponent = strchr(constant, 'E');
8132 if(strchr(constant, 'f') || strchr(constant, 'F'))
8133 type.kind = floatType;
8135 type.kind = doubleType;
8136 type.isSigned = true;
8140 bool isSigned = constant[0] == '-';
8142 int64 i64 = strtoll(constant, &endP, 0);
8143 uint64 ui64 = strtoull(constant, &endP, 0);
8144 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8157 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8161 else if(constant[0] != '0' || !constant[1])
8164 type.kind = is64Bit ? int64Type : intType;
8165 type.isSigned = isSigned;
8168 exp.isConstant = true;
8169 if(exp.destType && exp.destType.kind == doubleType)
8170 type.kind = doubleType;
8171 else if(exp.destType && exp.destType.kind == floatType)
8172 type.kind = floatType;
8173 else if(exp.destType && exp.destType.kind == int64Type)
8174 type.kind = int64Type;
8180 exp.isConstant = true; // Why wasn't this constant?
8197 ProcessExpressionType(exp._new.size);
8202 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8204 DeclareType(exp.expType.type, false, false);
8208 ProcessExpressionType(exp._renew.size);
8209 ProcessExpressionType(exp._renew.exp);
8214 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8216 DeclareType(exp.expType.type, false, false);
8220 bool assign = false, boolResult = false, boolOps = false;
8221 Type type1 = null, type2 = null;
8222 bool useDestType = false, useSideType = false;
8223 Location oldyylloc = yylloc;
8224 bool useSideUnit = false;
8225 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8227 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8236 // Assignment Operators
8250 // boolean Operators
8252 // Expect boolean operators
8254 //boolResult = true;
8258 // Expect boolean operands
8269 // Gives boolean result
8301 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8307 /*// Implement speed etc.
8313 if(exp.op.op == '&')
8315 // Added this here earlier for Iterator address as key
8316 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8318 Identifier id = exp.op.exp2.identifier;
8319 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8320 if(symbol && symbol.isIterator == 2)
8322 exp.type = memberExp;
8323 exp.member.exp = exp.op.exp2;
8324 exp.member.member = MkIdentifier("key");
8326 exp.op.exp2.expType = symbol.type;
8327 symbol.type.refCount++;
8328 ProcessExpressionType(exp);
8332 // exp.op.exp2.usage.usageRef = true;
8336 //dummy.kind = TypeDummy;
8339 // Added this check here to use the dest type only for units derived from the base unit
8340 // So that untyped units will use the side unit as opposed to the untyped destination unit
8341 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8342 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8343 useDestType = false;
8345 if(destClass && useDestType &&
8346 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8348 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8350 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8351 exp.op.exp1.destType = exp.destType;
8352 exp.op.exp1.opDestType = true;
8354 exp.destType.refCount++;
8358 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8359 exp.op.exp1.destType = dummy;
8363 // TESTING THIS HERE...
8364 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8365 ProcessExpressionType(exp.op.exp1);
8366 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8368 exp.op.exp1.opDestType = false;
8370 // Fix for unit and ++ / --
8371 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8372 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8374 exp.op.exp2 = MkExpConstant("1");
8375 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8379 if(exp.op.exp1.destType == dummy)
8382 exp.op.exp1.destType = null;
8384 type1 = exp.op.exp1.expType;
8389 char expString[10240];
8390 expString[0] = '\0';
8391 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8395 exp.op.exp2.destType = exp.op.exp1.expType;
8396 if(exp.op.exp1.expType)
8397 exp.op.exp1.expType.refCount++;
8401 exp.op.exp2.destType = exp.destType;
8402 if(!exp.op.exp1 || exp.op.op != '&')
8403 exp.op.exp2.opDestType = true;
8405 exp.destType.refCount++;
8408 if(type1) type1.refCount++;
8409 exp.expType = type1;
8414 PrintExpression(exp.op.exp2, expString);
8416 if(type1 && type1.kind == pointerType)
8418 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 ||
8419 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8420 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8421 else if(exp.op.op == '=')
8423 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8424 exp.op.exp2.destType = type1;
8431 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8432 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/* ||
8433 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8436 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8437 exp.op.exp2.destType = type1;
8442 if(type1) type1.refCount++;
8443 exp.expType = type1;
8445 else if(destClass &&
8446 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8447 (destClass.type == enumClass && useDestType)))
8449 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8450 exp.op.exp2.destType = exp.destType;
8451 if(exp.op.op != '&')
8452 exp.op.exp2.opDestType = true;
8454 exp.destType.refCount++;
8458 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8459 exp.op.exp2.destType = dummy;
8463 // TESTING THIS HERE... (DANGEROUS)
8464 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8465 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8467 FreeType(exp.op.exp2.destType);
8468 exp.op.exp2.destType = type1;
8471 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8472 // Cannot lose the cast on a sizeof
8473 if(exp.op.op == SIZEOF)
8475 Expression e = exp.op.exp2;
8476 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8478 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8480 if(e.type == extensionCompoundExp)
8481 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8486 if(e.type == castExp && e.cast.exp)
8487 e.cast.exp.needCast = true;
8489 ProcessExpressionType(exp.op.exp2);
8490 exp.op.exp2.opDestType = false;
8491 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8493 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8495 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)
8497 if(exp.op.op != '=' && type1.type.kind == voidType)
8498 Compiler_Error($"void *: unknown size\n");
8500 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||
8501 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8502 (exp.op.exp2.expType._class.registered.type == normalClass ||
8503 exp.op.exp2.expType._class.registered.type == structClass ||
8504 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8506 if(exp.op.op == ADD_ASSIGN)
8507 Compiler_Error($"cannot add two pointers\n");
8509 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8510 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8512 if(exp.op.op == ADD_ASSIGN)
8513 Compiler_Error($"cannot add two pointers\n");
8517 char type1String[1024];
8518 char type2String[1024];
8519 type1String[0] = '\0';
8520 type2String[0] = '\0';
8522 PrintType(exp.op.exp2.expType, type1String, false, true);
8523 PrintType(type1, type2String, false, true);
8524 ChangeCh(expString, '\n', ' ');
8525 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8529 if(exp.op.exp2.destType == dummy)
8532 exp.op.exp2.destType = null;
8535 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8539 CopyTypeInto(type2, exp.op.exp2.expType);
8540 type2.isSigned = true;
8542 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8544 type2 = { kind = intType };
8546 type2.isSigned = true;
8550 type2 = exp.op.exp2.expType;
8551 if(type2) type2.refCount++;
8555 dummy.kind = voidType;
8557 if(exp.op.op == SIZEOF)
8564 exp.isConstant = true;
8566 // Get type of dereferenced pointer
8567 else if(exp.op.op == '*' && !exp.op.exp1)
8569 exp.expType = Dereference(type2);
8570 if(type2 && type2.kind == classType)
8571 notByReference = true;
8573 else if(exp.op.op == '&' && !exp.op.exp1)
8574 exp.expType = Reference(type2);
8581 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8582 exp.op.exp1.destType = MkClassType("bool");
8583 exp.op.exp1.destType.truth = true;
8584 if(!exp.op.exp1.expType)
8585 ProcessExpressionType(exp.op.exp1);
8587 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8588 FreeType(exp.op.exp1.expType);
8589 exp.op.exp1.expType = MkClassType("bool");
8590 exp.op.exp1.expType.truth = true;
8594 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8595 exp.op.exp2.destType = MkClassType("bool");
8596 exp.op.exp2.destType.truth = true;
8597 if(!exp.op.exp2.expType)
8598 ProcessExpressionType(exp.op.exp2);
8600 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8601 FreeType(exp.op.exp2.expType);
8602 exp.op.exp2.expType = MkClassType("bool");
8603 exp.op.exp2.expType.truth = true;
8606 else if(exp.op.exp1 && exp.op.exp2 &&
8609 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8610 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8611 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8612 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8614 if(type1 && type2 &&
8615 // If either both are class or both are not class
8616 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8618 // Added this check for enum subtraction to result in an int type:
8619 if(exp.op.op == '-' &&
8620 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8621 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8624 if(!type1._class.registered.dataType)
8625 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8626 if(!type2._class.registered.dataType)
8627 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8629 intType = ProcessTypeString(
8630 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8632 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8633 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8634 exp.op.exp1.destType = intType;
8635 exp.op.exp2.destType = intType;
8640 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8641 exp.op.exp2.destType = type1;
8643 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8644 exp.op.exp1.destType = type2;
8648 // Warning here for adding Radians + Degrees with no destination type
8649 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8650 type1._class.registered && type1._class.registered.type == unitClass &&
8651 type2._class.registered && type2._class.registered.type == unitClass &&
8652 type1._class.registered != type2._class.registered)
8653 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8654 type1._class.string, type2._class.string, type1._class.string);
8656 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8658 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8661 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8663 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8664 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8667 ProcessExpressionType(exp.op.exp1);
8669 if(type2.kind != pointerType)
8671 ProcessExpressionType(classExp);
8673 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8675 if(!exp.op.exp2.expType)
8679 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8683 ProcessExpressionType(exp.op.exp2);
8688 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)))
8690 if(type1.kind != classType && type1.type.kind == voidType)
8691 Compiler_Error($"void *: unknown size\n");
8692 exp.expType = type1;
8693 if(type1) type1.refCount++;
8695 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)))
8697 if(type2.kind != classType && type2.type.kind == voidType)
8698 Compiler_Error($"void *: unknown size\n");
8699 exp.expType = type2;
8700 if(type2) type2.refCount++;
8702 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8703 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8705 Compiler_Warning($"different levels of indirection\n");
8709 bool success = false;
8710 if(type1.kind == pointerType && type2.kind == pointerType)
8712 if(exp.op.op == '+')
8713 Compiler_Error($"cannot add two pointers\n");
8714 else if(exp.op.op == '-')
8716 // Pointer Subtraction gives integer
8717 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8726 if(type1.type.kind == templateType)
8728 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8731 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8733 ProcessExpressionType(classExp);
8735 exp.type = bracketsExp;
8736 exp.list = MkListOne(MkExpOp(
8737 MkExpBrackets(MkListOne(MkExpOp(
8738 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8740 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8741 MkExpMember(classExp, MkIdentifier("typeSize"))));
8743 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8752 if(!success && exp.op.exp1.type == constantExp)
8754 // If first expression is constant, try to match that first
8755 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8757 if(exp.expType) FreeType(exp.expType);
8758 exp.expType = exp.op.exp1.destType;
8759 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8762 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8764 if(exp.expType) FreeType(exp.expType);
8765 exp.expType = exp.op.exp2.destType;
8766 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8772 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8774 if(exp.expType) FreeType(exp.expType);
8775 exp.expType = exp.op.exp2.destType;
8776 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8779 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8781 if(exp.expType) FreeType(exp.expType);
8782 exp.expType = exp.op.exp1.destType;
8783 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8789 char expString1[10240];
8790 char expString2[10240];
8793 expString1[0] = '\0';
8794 expString2[0] = '\0';
8799 PrintExpression(exp.op.exp1, expString1);
8800 ChangeCh(expString1, '\n', ' ');
8801 PrintExpression(exp.op.exp2, expString2);
8802 ChangeCh(expString2, '\n', ' ');
8803 PrintType(exp.op.exp1.expType, type1, false, true);
8804 PrintType(exp.op.exp2.expType, type2, false, true);
8807 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8811 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8812 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8814 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8815 // Convert e.g. / 4 into / 4.0
8816 exp.op.exp1.destType = type2._class.registered.dataType;
8817 if(type2._class.registered.dataType)
8818 type2._class.registered.dataType.refCount++;
8819 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8820 exp.expType = type2;
8821 if(type2) type2.refCount++;
8823 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8825 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8826 // Convert e.g. / 4 into / 4.0
8827 exp.op.exp2.destType = type1._class.registered.dataType;
8828 if(type1._class.registered.dataType)
8829 type1._class.registered.dataType.refCount++;
8830 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8831 exp.expType = type1;
8832 if(type1) type1.refCount++;
8838 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8840 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8842 if(!type1._class.registered.dataType)
8843 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8844 exp.op.exp2.destType = type1._class.registered.dataType;
8845 exp.op.exp2.destType.refCount++;
8847 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8850 type2 = exp.op.exp2.destType;
8851 if(type2) type2.refCount++;
8853 exp.expType = type2;
8857 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8859 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8861 if(!type2._class.registered.dataType)
8862 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8863 exp.op.exp1.destType = type2._class.registered.dataType;
8864 exp.op.exp1.destType.refCount++;
8866 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8867 type1 = exp.op.exp1.destType;
8868 exp.expType = type1;
8872 // TESTING THIS NEW CODE
8873 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8875 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8876 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8877 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8879 // Convert the enum to an int instead for these operators
8880 if(op1IsEnum && exp.op.exp2.expType)
8882 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8884 if(exp.expType) FreeType(exp.expType);
8885 exp.expType = exp.op.exp2.expType;
8886 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8890 else if(op2IsEnum && exp.op.exp1.expType)
8892 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8894 if(exp.expType) FreeType(exp.expType);
8895 exp.expType = exp.op.exp1.expType;
8896 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8903 if(op1IsEnum && exp.op.exp2.expType)
8905 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8907 if(exp.expType) FreeType(exp.expType);
8908 exp.expType = exp.op.exp1.expType;
8909 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8913 else if(op2IsEnum && exp.op.exp1.expType)
8915 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8917 if(exp.expType) FreeType(exp.expType);
8918 exp.expType = exp.op.exp2.expType;
8919 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8928 // 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
8929 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8930 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8932 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8933 exp.op.exp1.destType = type2;
8936 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8938 if(exp.expType) FreeType(exp.expType);
8939 exp.expType = exp.op.exp1.destType;
8940 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8945 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8946 exp.op.exp2.destType = type1;
8950 // Maybe this was meant to be an enum...
8951 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8953 Type oldType = exp.op.exp2.expType;
8954 exp.op.exp2.expType = null;
8955 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8958 exp.op.exp2.expType = oldType;
8963 // TESTING THIS HERE... LATEST ADDITION
8964 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8966 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8967 exp.op.exp2.destType = type2._class.registered.dataType;
8968 if(type2._class.registered.dataType)
8969 type2._class.registered.dataType.refCount++;
8970 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8972 //exp.expType = type2._class.registered.dataType; //type2;
8973 //if(type2) type2.refCount++;
8976 // TESTING THIS HERE... LATEST ADDITION
8977 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8979 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8980 exp.op.exp1.destType = type1._class.registered.dataType;
8981 if(type1._class.registered.dataType)
8982 type1._class.registered.dataType.refCount++;
8983 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8984 exp.expType = type1._class.registered.dataType; //type1;
8985 if(type1) type1.refCount++;
8989 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8991 if(exp.expType) FreeType(exp.expType);
8992 exp.expType = exp.op.exp2.destType;
8993 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8995 else if(type1 && type2)
8997 char expString1[10240];
8998 char expString2[10240];
8999 char type1String[1024];
9000 char type2String[1024];
9001 expString1[0] = '\0';
9002 expString2[0] = '\0';
9003 type1String[0] = '\0';
9004 type2String[0] = '\0';
9007 PrintExpression(exp.op.exp1, expString1);
9008 ChangeCh(expString1, '\n', ' ');
9009 PrintExpression(exp.op.exp2, expString2);
9010 ChangeCh(expString2, '\n', ' ');
9011 PrintType(exp.op.exp1.expType, type1String, false, true);
9012 PrintType(exp.op.exp2.expType, type2String, false, true);
9015 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9017 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9019 exp.expType = exp.op.exp1.expType;
9020 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9022 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9024 exp.expType = exp.op.exp2.expType;
9025 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9033 // Maybe this was meant to be an enum...
9034 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9036 Type oldType = exp.op.exp1.expType;
9037 exp.op.exp1.expType = null;
9038 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9041 exp.op.exp1.expType = oldType;
9044 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9045 exp.op.exp1.destType = type2;
9048 // TESTING THIS HERE... LATEST ADDITION
9049 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9051 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9052 exp.op.exp1.destType = type1._class.registered.dataType;
9053 if(type1._class.registered.dataType)
9054 type1._class.registered.dataType.refCount++;
9057 // TESTING THIS HERE... LATEST ADDITION
9058 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9060 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9061 exp.op.exp2.destType = type2._class.registered.dataType;
9062 if(type2._class.registered.dataType)
9063 type2._class.registered.dataType.refCount++;
9067 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9069 if(exp.expType) FreeType(exp.expType);
9070 exp.expType = exp.op.exp1.destType;
9071 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9075 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9077 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9079 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9080 // Convert e.g. / 4 into / 4.0
9081 exp.op.exp1.destType = type2._class.registered.dataType;
9082 if(type2._class.registered.dataType)
9083 type2._class.registered.dataType.refCount++;
9084 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9086 if(exp.op.op == '!')
9088 exp.expType = MkClassType("bool");
9089 exp.expType.truth = true;
9093 exp.expType = type2;
9094 if(type2) type2.refCount++;
9097 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9099 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9101 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9102 // Convert e.g. / 4 into / 4.0
9103 exp.op.exp2.destType = type1._class.registered.dataType;
9104 if(type1._class.registered.dataType)
9105 type1._class.registered.dataType.refCount++;
9106 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9108 exp.expType = type1;
9109 if(type1) type1.refCount++;
9114 if(exp.op.exp1 && !exp.op.exp1.expType)
9116 char expString[10000];
9117 expString[0] = '\0';
9120 PrintExpression(exp.op.exp1, expString);
9121 ChangeCh(expString, '\n', ' ');
9124 Compiler_Error($"couldn't determine type of %s\n", expString);
9126 if(exp.op.exp2 && !exp.op.exp2.expType)
9128 char expString[10240];
9129 expString[0] = '\0';
9132 PrintExpression(exp.op.exp2, expString);
9133 ChangeCh(expString, '\n', ' ');
9136 Compiler_Error($"couldn't determine type of %s\n", expString);
9141 FreeType(exp.expType);
9142 exp.expType = MkClassType("bool");
9143 exp.expType.truth = true;
9146 if(exp.op.op != SIZEOF)
9147 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9148 (!exp.op.exp2 || exp.op.exp2.isConstant);
9150 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9152 DeclareType(exp.op.exp2.expType, false, false);
9163 case extensionExpressionExp:
9166 exp.isConstant = true;
9167 for(e = exp.list->first; e; e = e.next)
9172 FreeType(e.destType);
9173 e.opDestType = exp.opDestType;
9174 e.destType = exp.destType;
9175 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9177 ProcessExpressionType(e);
9179 exp.destType.count--;
9180 if(!exp.expType && !e.next)
9182 exp.expType = e.expType;
9183 if(e.expType) e.expType.refCount++;
9186 exp.isConstant = false;
9189 // In case a cast became a member...
9190 e = exp.list->first;
9191 if(!e.next && e.type == memberExp)
9193 // Preserve prev, next
9194 Expression next = exp.next, prev = exp.prev;
9197 FreeType(exp.expType);
9198 FreeType(exp.destType);
9208 ProcessExpressionType(exp);
9215 exp.isConstant = true;
9217 ProcessExpressionType(exp.index.exp);
9218 if(!exp.index.exp.isConstant)
9219 exp.isConstant = false;
9221 if(exp.index.exp.expType)
9223 Type source = exp.index.exp.expType;
9224 if(source.kind == classType && source._class && source._class.registered)
9226 Class _class = source._class.registered;
9227 Class c = _class.templateClass ? _class.templateClass : _class;
9228 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9230 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9232 if(exp.index.index && exp.index.index->last)
9234 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9236 if(type.kind == classType) type.constant = true;
9237 else if(type.kind == pointerType)
9240 while(t.kind == pointerType) t = t.type;
9244 ((Expression)exp.index.index->last).destType = type;
9250 for(e = exp.index.index->first; e; e = e.next)
9252 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9254 if(e.destType) FreeType(e.destType);
9255 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9257 ProcessExpressionType(e);
9260 // Check if this type is int
9263 exp.isConstant = false;
9267 exp.expType = Dereference(exp.index.exp.expType);
9269 DeclareType(exp.expType, false, false);
9276 Type methodType = null;
9282 PrintExpression(exp.call.exp, name);
9283 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9285 //exp.call.exp.expType = null;
9286 PrintExpression(exp.call.exp, name);
9289 if(exp.call.exp.type == identifierExp)
9291 Expression idExp = exp.call.exp;
9292 Identifier id = idExp.identifier;
9293 if(!strcmp(id.string, "__builtin_frame_address"))
9295 exp.expType = ProcessTypeString("void *", true);
9296 if(exp.call.arguments && exp.call.arguments->first)
9297 ProcessExpressionType(exp.call.arguments->first);
9300 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9302 exp.expType = ProcessTypeString("int", true);
9303 if(exp.call.arguments && exp.call.arguments->first)
9304 ProcessExpressionType(exp.call.arguments->first);
9307 else if(!strcmp(id.string, "Max") ||
9308 !strcmp(id.string, "Min") ||
9309 !strcmp(id.string, "Sgn") ||
9310 !strcmp(id.string, "Abs"))
9312 Expression a = null;
9313 Expression b = null;
9314 Expression tempExp1 = null, tempExp2 = null;
9315 if((!strcmp(id.string, "Max") ||
9316 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9318 a = exp.call.arguments->first;
9319 b = exp.call.arguments->last;
9323 else if(exp.call.arguments->count == 1)
9325 a = exp.call.arguments->first;
9331 exp.call.arguments->Clear();
9332 idExp.identifier = null;
9334 FreeExpContents(exp);
9336 ProcessExpressionType(a);
9338 ProcessExpressionType(b);
9340 exp.type = bracketsExp;
9341 exp.list = MkList();
9343 if(a.expType && (!b || b.expType))
9345 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9347 // Use the simpleStruct name/ids for now...
9350 OldList * specs = MkList();
9351 OldList * decls = MkList();
9353 char temp1[1024], temp2[1024];
9355 GetTypeSpecs(a.expType, specs);
9357 if(a && !a.isConstant && a.type != identifierExp)
9359 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9360 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9361 tempExp1 = QMkExpId(temp1);
9362 tempExp1.expType = a.expType;
9364 a.expType.refCount++;
9365 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9367 if(b && !b.isConstant && b.type != identifierExp)
9369 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9370 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9371 tempExp2 = QMkExpId(temp2);
9372 tempExp2.expType = b.expType;
9374 b.expType.refCount++;
9375 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9378 decl = MkDeclaration(specs, decls);
9379 if(!curCompound.compound.declarations)
9380 curCompound.compound.declarations = MkList();
9381 curCompound.compound.declarations->Insert(null, decl);
9386 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9388 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9390 MkExpCondition(MkExpBrackets(MkListOne(
9391 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9392 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9393 exp.expType = a.expType;
9395 a.expType.refCount++;
9397 else if(!strcmp(id.string, "Abs"))
9400 MkExpCondition(MkExpBrackets(MkListOne(
9401 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9402 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9403 exp.expType = a.expType;
9405 a.expType.refCount++;
9407 else if(!strcmp(id.string, "Sgn"))
9409 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9411 MkExpCondition(MkExpBrackets(MkListOne(
9412 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9413 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9414 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9415 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9416 exp.expType = ProcessTypeString("int", false);
9419 FreeExpression(tempExp1);
9420 if(tempExp2) FreeExpression(tempExp2);
9434 if(!exp.call.exp.destType)
9436 exp.call.exp.destType = dummy;
9439 ProcessExpressionType(exp.call.exp);
9440 if(exp.call.exp.destType == dummy)
9443 exp.call.exp.destType = null;
9448 // Check argument types against parameter types
9449 functionType = exp.call.exp.expType;
9451 if(functionType && functionType.kind == TypeKind::methodType)
9453 methodType = functionType;
9454 functionType = methodType.method.dataType;
9456 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9457 // TOCHECK: Instead of doing this here could this be done per param?
9458 if(exp.call.exp.expType.usedClass)
9460 char typeString[1024];
9461 typeString[0] = '\0';
9463 Symbol back = functionType.thisClass;
9464 // Do not output class specifier here (thisclass was added to this)
9465 functionType.thisClass = null;
9466 PrintType(functionType, typeString, true, true);
9467 functionType.thisClass = back;
9469 if(strstr(typeString, "thisclass"))
9471 OldList * specs = MkList();
9474 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9476 decl = SpecDeclFromString(typeString, specs, null);
9478 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9479 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9480 exp.call.exp.expType.usedClass))
9481 thisClassParams = false;
9483 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9485 Class backupThisClass = thisClass;
9486 thisClass = exp.call.exp.expType.usedClass;
9487 ProcessDeclarator(decl);
9488 thisClass = backupThisClass;
9491 thisClassParams = true;
9493 functionType = ProcessType(specs, decl);
9494 functionType.refCount = 0;
9495 FinishTemplatesContext(context);
9498 FreeList(specs, FreeSpecifier);
9499 FreeDeclarator(decl);
9503 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9505 Type type = functionType.type;
9506 if(!functionType.refCount)
9508 functionType.type = null;
9509 FreeType(functionType);
9511 //methodType = functionType;
9512 functionType = type;
9514 if(functionType && functionType.kind != TypeKind::functionType)
9516 Compiler_Error($"called object %s is not a function\n", name);
9518 else if(functionType)
9520 bool emptyParams = false, noParams = false;
9521 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9522 Type type = functionType.params.first;
9523 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9525 Location oldyylloc = yylloc;
9527 if(!type) emptyParams = true;
9530 if(functionType.extraParam && e && functionType.thisClass)
9532 e.destType = MkClassType(functionType.thisClass.string);
9536 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9537 // Fixed #141 by adding '&& !functionType.extraParam'
9538 if(!functionType.staticMethod && !functionType.extraParam)
9540 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9541 memberExp.member.exp.expType._class)
9543 type = MkClassType(memberExp.member.exp.expType._class.string);
9548 type = functionType.params.first;
9553 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9555 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9556 type.byReference = functionType.byReference;
9557 type.typedByReference = functionType.typedByReference;
9560 // Allow manually passing a class for typed object
9561 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9565 type = functionType.params.first;
9573 if(type && type.kind == voidType)
9576 if(!type.refCount) FreeType(type);
9580 for( ; e; e = e.next)
9582 if(!type && !emptyParams)
9585 if(methodType && methodType.methodClass)
9586 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9587 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9588 noParams ? 0 : functionType.params.count);
9590 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9591 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9592 noParams ? 0 : functionType.params.count);
9596 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9598 Type templatedType = null;
9599 Class _class = methodType.usedClass;
9600 ClassTemplateParameter curParam = null;
9602 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9605 for(sClass = _class; sClass; sClass = sClass.base)
9607 if(sClass.templateClass) sClass = sClass.templateClass;
9609 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9611 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9614 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9616 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9617 id += nextClass.templateParams.count;
9626 if(curParam && _class.templateArgs[id].dataTypeString)
9628 bool constant = type.constant;
9629 ClassTemplateArgument arg = _class.templateArgs[id];
9631 Context context = SetupTemplatesContext(_class);
9634 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9635 templatedType = ProcessTypeString(arg.dataTypeString, false);
9636 FinishTemplatesContext(context);
9639 if(templatedType.kind == classType && constant) templatedType.constant = true;
9640 else if(templatedType.kind == pointerType)
9642 Type t = templatedType.type;
9643 while(t.kind == pointerType) t = t.type;
9644 if(constant) t.constant = constant;
9647 e.destType = templatedType;
9650 templatedType.passAsTemplate = true;
9651 // templatedType.refCount++;
9657 if(type) type.refCount++;
9662 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9664 e.destType = type.prev;
9665 e.destType.refCount++;
9670 if(type) type.refCount++;
9673 // Don't reach the end for the ellipsis
9674 if(type && type.kind != ellipsisType)
9676 Type next = type.next;
9677 if(!type.refCount) FreeType(type);
9682 if(type && type.kind != ellipsisType)
9684 if(methodType && methodType.methodClass)
9685 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9686 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9687 functionType.params.count + extra);
9689 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9690 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9691 functionType.params.count + extra);
9694 if(type && !type.refCount) FreeType(type);
9701 kind = TypeKind::functionType;
9704 if(exp.call.exp.type == identifierExp)
9706 char * string = exp.call.exp.identifier.string;
9710 Location oldyylloc = yylloc;
9712 yylloc = exp.call.exp.identifier.loc;
9713 if(strstr(string, "__builtin_") == string)
9717 functionType.returnType = exp.destType;
9718 exp.destType.refCount++;
9722 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9723 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9724 globalContext.symbols.Add((BTNode)symbol);
9725 if(strstr(symbol.string, "::"))
9726 globalContext.hasNameSpace = true;
9731 else if(exp.call.exp.type == memberExp)
9733 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9734 exp.call.exp.member.member.string);*/
9737 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9739 if(!functionType.returnType)
9741 functionType.returnType = Type
9748 if(functionType && functionType.kind == TypeKind::functionType)
9750 exp.expType = functionType.returnType;
9752 if(functionType.returnType)
9753 functionType.returnType.refCount++;
9755 if(!functionType.refCount)
9756 FreeType(functionType);
9759 if(exp.call.arguments)
9761 for(e = exp.call.arguments->first; e; e = e.next)
9763 Type destType = e.destType;
9764 ProcessExpressionType(e);
9772 Location oldyylloc = yylloc;
9774 Expression checkExp = exp.member.exp;
9777 if(checkExp.type == castExp)
9778 checkExp = checkExp.cast.exp;
9779 else if(checkExp.type == bracketsExp)
9780 checkExp = checkExp.list ? checkExp.list->first : null;
9785 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9786 exp.thisPtr = thisPtr;
9788 // DOING THIS LATER NOW...
9789 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9791 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9792 /* TODO: Name Space Fix ups
9793 if(!exp.member.member.classSym)
9794 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9798 ProcessExpressionType(exp.member.exp);
9799 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9800 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9802 exp.isConstant = false;
9805 exp.isConstant = exp.member.exp.isConstant;
9806 type = exp.member.exp.expType;
9810 if(type && (type.kind == templateType))
9812 Class _class = thisClass ? thisClass : currentClass;
9813 ClassTemplateParameter param = null;
9816 for(param = _class.templateParams.first; param; param = param.next)
9818 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9822 if(param && param.defaultArg.member)
9824 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9827 Expression expMember = exp.member.exp;
9829 OldList * specs = MkList();
9830 char thisClassTypeString[1024];
9832 FreeIdentifier(exp.member.member);
9834 ProcessExpressionType(argExp);
9837 char * colon = strstr(param.defaultArg.memberString, "::");
9840 char className[1024];
9843 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9844 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9847 strcpy(thisClassTypeString, _class.fullName);
9850 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9852 exp.expType = ProcessType(specs, decl);
9853 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9855 Class expClass = exp.expType._class.registered;
9856 Class cClass = null;
9861 char templateString[1024];
9862 ClassTemplateParameter param;
9863 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9864 for(cClass = expClass; cClass; cClass = cClass.base)
9867 for(param = cClass.templateParams.first; param; param = param.next)
9871 ClassTemplateArgument arg;
9872 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9873 arg = expClass.templateArgs[id];
9875 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9877 ClassTemplateParameter cParam;
9878 //int p = numParams - sClass.templateParams.count;
9881 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9883 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9885 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9887 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9889 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9890 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9902 strcat(argument, arg.name.string);
9903 strcat(argument, " = ");
9909 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9910 char expString[1024];
9911 OldList * specs = MkList();
9912 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9914 char * string = PrintHexUInt64(arg.expression.ui64);
9915 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9918 ProcessExpressionType(exp);
9919 ComputeExpression(exp);
9920 expString[0] = '\0';
9921 PrintExpression(exp, expString);
9922 strcat(argument, expString);
9924 FreeExpression(exp);
9929 strcat(argument, arg.member.name);
9932 case TemplateParameterType::type:
9934 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9936 if(!strcmp(arg.dataTypeString, "thisclass"))
9937 strcat(argument, thisClassTypeString);
9939 strcat(argument, arg.dataTypeString);
9946 if(paramCount) strcat(templateString, ", ");
9947 if(lastParam != p - 1)
9949 strcat(templateString, param.name);
9950 strcat(templateString, " = ");
9952 strcat(templateString, argument);
9961 int len = strlen(templateString);
9962 if(templateString[len-1] == '>') templateString[len++] = ' ';
9963 templateString[len++] = '>';
9964 templateString[len++] = '\0';
9967 Context context = SetupTemplatesContext(_class);
9968 FreeType(exp.expType);
9969 exp.expType = ProcessTypeString(templateString, false);
9970 FinishTemplatesContext(context);
9974 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9975 exp.type = bracketsExp;
9976 exp.list = MkListOne(MkExpOp(null, '*',
9981 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9982 MkExpBrackets(MkListOne(
9983 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9985 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9987 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9992 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9993 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9995 type = ProcessTemplateParameterType(type.templateParameter);
9998 // TODO: *** This seems to be where we should add method support for all basic types ***
9999 if(type && (type.kind == templateType));
10000 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10001 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10002 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10003 (type.kind == pointerType && type.type.kind == charType)))
10005 Identifier id = exp.member.member;
10006 TypeKind typeKind = type.kind;
10007 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10008 if(typeKind == subClassType && exp.member.exp.type == classExp)
10010 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10011 typeKind = classType;
10016 if(typeKind == intType || typeKind == enumType)
10017 _class = eSystem_FindClass(privateModule, "int");
10020 if(type.kind == classType && type._class && type._class.registered)
10022 _class = type._class.registered;
10024 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10026 _class = FindClass("char *").registered;
10028 else if(type.kind == pointerType)
10030 _class = eSystem_FindClass(privateModule, "uintptr");
10031 FreeType(exp.expType);
10032 exp.expType = ProcessTypeString("uintptr", false);
10033 exp.byReference = true;
10037 char string[1024] = "";
10039 PrintTypeNoConst(type, string, false, true);
10040 classSym = FindClass(string);
10041 if(classSym) _class = classSym.registered;
10049 (exp.member.exp.type == identifierExp &&
10050 !strcmp(exp.member.exp.identifier.string, "this"));*/
10051 Property prop = null;
10052 Method method = null;
10053 DataMember member = null;
10054 Property revConvert = null;
10055 ClassProperty classProp = null;
10057 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10058 exp.member.memberType = propertyMember;
10060 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10061 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10063 if(typeKind != subClassType)
10065 // Prioritize data members over properties for "this"
10066 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10068 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10069 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10071 prop = eClass_FindProperty(_class, id.string, privateModule);
10075 if(!member && !prop)
10076 prop = eClass_FindProperty(_class, id.string, privateModule);
10077 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10078 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10079 exp.member.thisPtr = true;
10081 // Prioritize properties over data members otherwise
10084 bool useMemberForNonConst = false;
10085 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10088 prop = eClass_FindProperty(_class, id.string, null);
10090 useMemberForNonConst = prop && exp.destType &&
10091 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10092 !strncmp(prop.dataTypeString, "const ", 6);
10094 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10095 member = eClass_FindDataMember(_class, id.string, null, null, null);
10098 if((!prop || useMemberForNonConst) && !member)
10100 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10103 prop = eClass_FindProperty(_class, id.string, privateModule);
10105 useMemberForNonConst |= prop && exp.destType &&
10106 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10107 !strncmp(prop.dataTypeString, "const ", 6);
10109 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10110 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10116 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10123 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10124 method = eClass_FindMethod(_class, id.string, privateModule);
10125 if(!prop && !member && !method)
10127 if(typeKind == subClassType)
10129 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10132 exp.member.memberType = classPropertyMember;
10133 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10137 // Assume this is a class_data member
10138 char structName[1024];
10139 Identifier id = exp.member.member;
10140 Expression classExp = exp.member.exp;
10143 FreeType(classExp.expType);
10144 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10146 strcpy(structName, "__ecereClassData_");
10147 FullClassNameCat(structName, type._class.string, false);
10148 exp.type = pointerExp;
10149 exp.member.member = id;
10151 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10152 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10153 MkExpBrackets(MkListOne(MkExpOp(
10154 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10155 MkExpMember(classExp, MkIdentifier("data"))), '+',
10156 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10161 ProcessExpressionType(exp);
10167 // Check for reverse conversion
10168 // (Convert in an instantiation later, so that we can use
10169 // deep properties system)
10170 Symbol classSym = FindClass(id.string);
10173 Class convertClass = classSym.registered;
10175 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10182 exp.member.memberType = propertyMember;
10184 ProcessPropertyType(prop);
10185 exp.expType = prop.dataType;
10186 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10189 CopyTypeInto(type, exp.expType);
10191 type.constant = true;
10192 exp.expType = type;
10194 else if(prop.dataType)
10195 prop.dataType.refCount++;
10199 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10201 FreeExpContents(exp);
10202 exp.type = identifierExp;
10203 exp.identifier = MkIdentifier("class");
10204 ProcessExpressionType(exp);
10208 exp.member.memberType = dataMember;
10209 DeclareStruct(_class.fullName, false);
10210 if(!member.dataType)
10212 Context context = SetupTemplatesContext(_class);
10213 member.dataType = ProcessTypeString(member.dataTypeString, false);
10214 FinishTemplatesContext(context);
10216 exp.expType = member.dataType;
10217 if(member.dataType) member.dataType.refCount++;
10219 else if(revConvert)
10221 exp.member.memberType = reverseConversionMember;
10222 exp.expType = MkClassType(revConvert._class.fullName);
10230 exp.type = identifierExp;
10231 exp.identifier = exp.member.member;
10234 exp.member.memberType = methodMember;
10236 if(!method.dataType)
10237 ProcessMethodType(method);
10245 // Tricky spot here... To use instance versus class virtual table
10246 // Put it back to what it was... What did we break?
10248 // Had to put it back for overriding Main of Thread global instance
10250 //exp.expType.methodClass = _class;
10251 exp.expType.methodClass = (id && id._class) ? _class : null;
10253 // Need the actual class used for templated classes
10254 exp.expType.usedClass = _class;
10256 else if(!classProp)
10258 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10260 FreeExpContents(exp);
10261 exp.type = identifierExp;
10262 exp.identifier = MkIdentifier("class");
10263 FreeType(exp.expType);
10264 exp.expType = MkClassType("ecere::com::Class");
10267 yylloc = exp.member.member.loc;
10268 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10270 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10273 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10277 tClass = type._class && type._class.registered ? type._class.registered : _class;
10278 while(tClass && !tClass.templateClass) tClass = tClass.base;
10280 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10283 ClassTemplateParameter curParam = null;
10286 for(sClass = tClass; sClass; sClass = sClass.base)
10289 if(sClass.templateClass) sClass = sClass.templateClass;
10290 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10292 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10294 for(sClass = sClass.base; sClass; sClass = sClass.base)
10295 id += sClass.templateParams.count;
10300 if(curParam) break;
10303 if(curParam && tClass.templateArgs[id].dataTypeString)
10305 ClassTemplateArgument arg = tClass.templateArgs[id];
10306 Context context = SetupTemplatesContext(tClass);
10307 bool constant = exp.expType.constant;
10308 /*if(!arg.dataType)
10309 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10310 FreeType(exp.expType);
10312 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10313 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10314 else if(exp.expType.kind == pointerType)
10316 Type t = exp.expType.type;
10317 while(t.kind == pointerType) t = t.type;
10318 if(constant) t.constant = constant;
10322 if(exp.expType.kind == thisClassType)
10324 FreeType(exp.expType);
10325 exp.expType = ReplaceThisClassType(_class);
10328 if(tClass.templateClass && (exp.expType.kind != templateType || (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType))))
10329 exp.expType.passAsTemplate = true;
10330 //exp.expType.refCount++;
10333 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10334 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10335 else if(exp.destType.kind == pointerType)
10337 Type t = exp.destType.type;
10338 while(t.kind == pointerType) t = t.type;
10339 if(constant) t.constant = constant;
10342 //exp.destType.refCount++;
10344 if(exp.destType.kind == thisClassType)
10346 FreeType(exp.destType);
10347 exp.destType = ReplaceThisClassType(_class);
10351 FinishTemplatesContext(context);
10354 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10355 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10358 ClassTemplateParameter curParam = null;
10361 for(sClass = tClass; sClass; sClass = sClass.base)
10364 if(sClass.templateClass) sClass = sClass.templateClass;
10365 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10367 if(curParam.type == TemplateParameterType::type &&
10368 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10370 for(sClass = sClass.base; sClass; sClass = sClass.base)
10371 id += sClass.templateParams.count;
10376 if(curParam) break;
10381 ClassTemplateArgument arg = tClass.templateArgs[id];
10382 Context context = SetupTemplatesContext(tClass);
10384 /*if(!arg.dataType)
10385 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10387 basicType = ProcessTypeString(arg.dataTypeString, false);
10390 if(basicType.kind == thisClassType)
10392 FreeType(basicType);
10393 basicType = ReplaceThisClassType(_class);
10396 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10397 if(tClass.templateClass)
10398 basicType.passAsTemplate = true;
10401 FreeType(exp.expType);
10403 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10404 //exp.expType.refCount++;
10407 exp.destType = exp.expType;
10408 exp.destType.refCount++;
10412 Expression newExp { };
10413 OldList * specs = MkList();
10415 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10417 if(exp.destType) exp.destType.refCount++;
10418 if(exp.expType) exp.expType.refCount++;
10419 exp.type = castExp;
10420 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10421 exp.cast.exp = newExp;
10422 //FreeType(exp.expType);
10423 //exp.expType = null;
10424 //ProcessExpressionType(sourceExp);
10427 FinishTemplatesContext(context);
10430 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10432 Class expClass = exp.expType._class.registered;
10435 Class cClass = null;
10438 int paramCount = 0;
10439 int lastParam = -1;
10440 char templateString[1024];
10441 ClassTemplateParameter param;
10442 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10443 while(cClass != expClass)
10446 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10449 for(param = cClass.templateParams.first; param; param = param.next)
10451 Class cClassCur = null;
10454 ClassTemplateParameter paramCur = null;
10455 ClassTemplateArgument arg;
10456 while(cClassCur != tClass && !paramCur)
10459 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10460 cClassCur = sClassCur;
10462 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10464 if(!strcmp(paramCur.name, param.name))
10472 if(paramCur && paramCur.type == TemplateParameterType::type)
10473 arg = tClass.templateArgs[cp];
10475 arg = expClass.templateArgs[p];
10478 char argument[256];
10479 argument[0] = '\0';
10482 strcat(argument, arg.name.string);
10483 strcat(argument, " = ");
10489 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10490 char expString[1024];
10491 OldList * specs = MkList();
10492 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10494 char * string = PrintHexUInt64(arg.expression.ui64);
10495 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10498 ProcessExpressionType(exp);
10499 ComputeExpression(exp);
10500 expString[0] = '\0';
10501 PrintExpression(exp, expString);
10502 strcat(argument, expString);
10504 FreeExpression(exp);
10509 strcat(argument, arg.member.name);
10512 case TemplateParameterType::type:
10514 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10515 strcat(argument, arg.dataTypeString);
10521 if(paramCount) strcat(templateString, ", ");
10522 if(lastParam != p - 1)
10524 strcat(templateString, param.name);
10525 strcat(templateString, " = ");
10527 strcat(templateString, argument);
10536 int len = strlen(templateString);
10537 if(templateString[len-1] == '>') templateString[len++] = ' ';
10538 templateString[len++] = '>';
10539 templateString[len++] = '\0';
10542 FreeType(exp.expType);
10544 Context context = SetupTemplatesContext(tClass);
10545 exp.expType = ProcessTypeString(templateString, false);
10546 FinishTemplatesContext(context);
10553 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10555 else if(type && (type.kind == structType || type.kind == unionType))
10557 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10560 exp.expType = memberType;
10562 memberType.refCount++;
10567 char expString[10240];
10568 expString[0] = '\0';
10569 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10570 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10573 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10575 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10577 Identifier id = exp.member.member;
10578 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10581 FreeType(exp.expType);
10582 exp.expType = ReplaceThisClassType(_class);
10586 yylloc = oldyylloc;
10589 // Convert x->y into (*x).y
10592 Type destType = exp.destType;
10594 // DOING THIS LATER NOW...
10595 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10597 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10598 /* TODO: Name Space Fix ups
10599 if(!exp.member.member.classSym)
10600 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10604 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10605 exp.type = memberExp;
10608 ProcessExpressionType(exp);
10615 //ComputeExpression(exp);
10617 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10618 if(classSym && classSym.registered)
10620 if(classSym.registered.type == noHeadClass)
10624 DeclareStruct(classSym.string, false);
10625 FreeSpecifier(exp._class);
10626 exp.type = typeSizeExp;
10627 FullClassNameCat(name, classSym.string, false);
10628 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10632 if(classSym.registered.fixed)
10634 FreeSpecifier(exp._class);
10635 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10636 exp.type = constantExp;
10640 char className[1024];
10641 strcpy(className, "__ecereClass_");
10642 FullClassNameCat(className, classSym.string, true);
10643 MangleClassName(className);
10645 DeclareClass(classSym, className);
10647 FreeExpContents(exp);
10648 exp.type = pointerExp;
10649 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10650 exp.member.member = MkIdentifier("structSize");
10658 kind = intSizeType;
10660 // exp.isConstant = true;
10665 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10670 kind = intSizeType;
10672 exp.isConstant = true;
10674 DeclareType(type, false, false);
10680 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10682 FreeType(exp.cast.exp.destType);
10683 exp.cast.exp.destType = type;
10685 type.casted = true;
10686 ProcessExpressionType(exp.cast.exp);
10687 type.casted = false;
10689 exp.expType = type;
10692 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10693 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10695 void * prev = exp.prev, * next = exp.next;
10696 Type expType = exp.cast.exp.destType;
10697 Expression castExp = exp.cast.exp;
10698 Type destType = exp.destType;
10700 if(expType) expType.refCount++;
10702 //FreeType(exp.destType);
10703 FreeType(exp.expType);
10704 FreeTypeName(exp.cast.typeName);
10707 FreeType(exp.expType);
10708 FreeType(exp.destType);
10710 exp.expType = expType;
10711 exp.destType = destType;
10721 exp.isConstant = exp.cast.exp.isConstant;
10726 case extensionInitializerExp:
10728 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10729 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10730 // ProcessInitializer(exp.initializer.initializer, type);
10731 exp.expType = type;
10736 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10737 ProcessExpressionType(exp.vaArg.exp);
10738 exp.expType = type;
10744 exp.isConstant = true;
10746 FreeType(exp.cond.cond.destType);
10747 exp.cond.cond.destType = MkClassType("bool");
10748 exp.cond.cond.destType.truth = true;
10749 ProcessExpressionType(exp.cond.cond);
10750 if(!exp.cond.cond.isConstant)
10751 exp.isConstant = false;
10752 for(e = exp.cond.exp->first; e; e = e.next)
10756 FreeType(e.destType);
10757 e.destType = exp.destType;
10758 if(e.destType) e.destType.refCount++;
10760 ProcessExpressionType(e);
10763 exp.expType = e.expType;
10764 if(e.expType) e.expType.refCount++;
10767 exp.isConstant = false;
10770 FreeType(exp.cond.elseExp.destType);
10771 // Added this check if we failed to find an expType
10772 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10775 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10777 if(exp.cond.elseExp.destType)
10778 exp.cond.elseExp.destType.refCount++;
10779 ProcessExpressionType(exp.cond.elseExp);
10781 // FIXED THIS: Was done before calling process on elseExp
10782 if(!exp.cond.elseExp.isConstant)
10783 exp.isConstant = false;
10786 case extensionCompoundExp:
10788 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10790 Statement last = exp.compound.compound.statements->last;
10791 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10793 ((Expression)last.expressions->last).destType = exp.destType;
10795 exp.destType.refCount++;
10797 ProcessStatement(exp.compound);
10798 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10800 exp.expType.refCount++;
10806 Specifier spec = exp._classExp.specifiers->first;
10807 if(spec && spec.type == nameSpecifier)
10809 exp.expType = MkClassType(spec.name);
10810 exp.expType.kind = subClassType;
10811 exp.byReference = true;
10815 exp.expType = MkClassType("ecere::com::Class");
10816 exp.byReference = true;
10822 Class _class = thisClass ? thisClass : currentClass;
10825 Identifier id = exp.classData.id;
10826 char structName[1024];
10827 Expression classExp;
10828 strcpy(structName, "__ecereClassData_");
10829 FullClassNameCat(structName, _class.fullName, false);
10830 exp.type = pointerExp;
10831 exp.member.member = id;
10832 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10833 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10835 classExp = MkExpIdentifier(MkIdentifier("class"));
10837 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10838 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10839 MkExpBrackets(MkListOne(MkExpOp(
10840 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10841 MkExpMember(classExp, MkIdentifier("data"))), '+',
10842 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10845 ProcessExpressionType(exp);
10853 const char * typeString = null;
10854 char typeStringBuf[1024];
10855 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10856 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10858 Class templateClass = exp.destType._class.registered;
10859 typeString = templateClass.templateArgs[2].dataTypeString;
10863 // Guess type from expressions in the array
10865 for(e = exp.list->first; e; e = e.next)
10867 ProcessExpressionType(e);
10870 if(!type) { type = e.expType; type.refCount++; }
10873 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10874 if(!MatchTypeExpression(e, type, null, false, true))
10880 e = exp.list->first;
10881 ProcessExpressionType(e);
10884 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10885 if(!MatchTypeExpression(e, type, null, false, true))
10887 FreeType(e.expType);
10898 FreeType(e.expType);
10905 typeStringBuf[0] = '\0';
10906 PrintTypeNoConst(type, typeStringBuf, false, true);
10907 typeString = typeStringBuf;
10915 (Container)& (struct BuiltInContainer)
10917 ._vTbl = class(BuiltInContainer)._vTbl,
10918 ._class = class(BuiltInContainer),
10920 .data = (int[]){ 1, 7, 3, 4, 5 },
10922 .type = class(int),
10925 char templateString[1024];
10926 OldList * initializers = MkList();
10927 OldList * structInitializers = MkList();
10928 OldList * specs = MkList();
10930 Declarator decl = SpecDeclFromString(typeString, specs, null);
10931 sprintf(templateString, "Container<%s>", typeString);
10936 type = ProcessTypeString(typeString, false);
10937 while(e = exp.list->first)
10939 exp.list->Remove(e);
10942 ProcessExpressionType(e);
10943 ListAdd(initializers, MkInitializerAssignment(e));
10949 DeclareStruct("ecere::com::BuiltInContainer", false);
10951 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10952 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10953 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10954 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10955 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10956 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10957 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10958 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10959 MkInitializerList(initializers))));
10960 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10961 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10962 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10963 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10964 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10965 exp.expType = ProcessTypeString(templateString, false);
10966 exp.type = bracketsExp;
10967 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10969 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10970 MkInitializerList(structInitializers)))));
10971 ProcessExpressionType(expExt);
10975 exp.expType = ProcessTypeString("Container", false);
10976 Compiler_Error($"Couldn't determine type of array elements\n");
10982 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10984 FreeType(exp.expType);
10985 exp.expType = ReplaceThisClassType(thisClass);
10988 // Resolve structures here
10989 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10991 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10992 // TODO: Fix members reference...
10995 if(exp.expType.kind != enumType)
10998 String enumName = CopyString(exp.expType.enumName);
11000 // Fixed a memory leak on self-referencing C structs typedefs
11001 // by instantiating a new type rather than simply copying members
11002 // into exp.expType
11003 FreeType(exp.expType);
11004 exp.expType = Type { };
11005 exp.expType.kind = symbol.type.kind;
11006 exp.expType.refCount++;
11007 exp.expType.enumName = enumName;
11009 exp.expType.members = symbol.type.members;
11010 for(member = symbol.type.members.first; member; member = member.next)
11016 for(member = symbol.type.members.first; member; member = member.next)
11018 NamedLink value { name = CopyString(member.name) };
11019 exp.expType.members.Add(value);
11026 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11027 else if(exp.destType && !exp.destType.keepCast)
11029 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11030 exp.needTemplateCast = 1;
11032 if(exp.destType.kind == voidType);
11033 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11035 if(!exp.destType.count || unresolved)
11040 if(exp.destType.kind != ellipsisType)
11046 char expString[10240];
11047 expString[0] = '\0';
11049 PrintType(exp.destType, type2, false, true);
11051 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11053 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11054 else if(exp.type != dummyExp)
11055 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11060 char expString[10240] ;
11061 expString[0] = '\0';
11062 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11065 Compiler_Error($"unresolved identifier %s\n", expString);
11066 else if(exp.type != dummyExp)
11067 Compiler_Error($"couldn't determine type of %s\n", expString);
11078 PrintType(exp.expType, type1, false, true);
11079 PrintType(exp.destType, type2, false, true);
11082 //CheckExpressionType(exp, exp.destType, false);
11084 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11085 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11086 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11089 char expString[10240];
11090 expString[0] = '\0';
11091 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11094 CheckExpressionType(exp, exp.destType, false, true);
11096 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11097 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
11098 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11100 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11101 FreeType(exp.expType);
11102 exp.destType.refCount++;
11103 exp.expType = exp.destType;
11108 /*else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
11110 Expression newExp { };
11111 char typeString[1024];
11112 OldList * specs = MkList();
11115 typeString[0] = '\0';
11119 if(exp.expType) exp.expType.refCount++;
11120 if(exp.expType) exp.expType.refCount++;
11121 exp.type = castExp;
11122 newExp.destType = exp.expType;
11124 PrintType(exp.expType, typeString, false, false);
11125 decl = SpecDeclFromString(typeString, specs, null);
11127 exp.cast.typeName = MkTypeName(specs, decl);
11128 exp.cast.exp = newExp;
11131 else if(unresolved)
11133 if(exp.identifier._class && exp.identifier._class.name)
11134 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11135 else if(exp.identifier.string && exp.identifier.string[0])
11136 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11138 else if(!exp.expType && exp.type != dummyExp)
11140 char expString[10240];
11141 expString[0] = '\0';
11142 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11143 Compiler_Error($"couldn't determine type of %s\n", expString);
11146 // Let's try to support any_object & typed_object here:
11148 ApplyAnyObjectLogic(exp);
11150 // Mark nohead classes as by reference, unless we're casting them to an integral type
11151 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11152 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11153 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11154 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11156 exp.byReference = true;
11158 yylloc = oldyylloc;
11161 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11163 // THIS CODE WILL FIND NEXT MEMBER...
11166 *curMember = (*curMember).next;
11168 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11170 *curMember = subMemberStack[--(*subMemberStackPos)];
11171 *curMember = (*curMember).next;
11174 // SKIP ALL PROPERTIES HERE...
11175 while((*curMember) && (*curMember).isProperty)
11176 *curMember = (*curMember).next;
11178 if(subMemberStackPos)
11180 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11182 subMemberStack[(*subMemberStackPos)++] = *curMember;
11184 *curMember = (*curMember).members.first;
11185 while(*curMember && (*curMember).isProperty)
11186 *curMember = (*curMember).next;
11194 if(subMemberStackPos && *subMemberStackPos)
11196 *curMember = subMemberStack[--(*subMemberStackPos)];
11197 *curMember = (*curMember).next;
11201 Class lastCurClass = *curClass;
11203 if(*curClass == _class) break; // REACHED THE END
11205 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11206 *curMember = (*curClass).membersAndProperties.first;
11209 while((*curMember) && (*curMember).isProperty)
11210 *curMember = (*curMember).next;
11211 if(subMemberStackPos)
11213 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11215 subMemberStack[(*subMemberStackPos)++] = *curMember;
11217 *curMember = (*curMember).members.first;
11218 while(*curMember && (*curMember).isProperty)
11219 *curMember = (*curMember).next;
11227 static void ProcessInitializer(Initializer init, Type type)
11231 case expInitializer:
11232 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11234 // TESTING THIS FOR SHUTTING = 0 WARNING
11235 if(init.exp && !init.exp.destType)
11237 FreeType(init.exp.destType);
11238 init.exp.destType = type;
11239 if(type) type.refCount++;
11243 ProcessExpressionType(init.exp);
11244 init.isConstant = init.exp.isConstant;
11250 Expression exp = init.exp;
11251 Instantiation inst = exp.instance;
11252 MembersInit members;
11254 init.type = listInitializer;
11255 init.list = MkList();
11259 for(members = inst.members->first; members; members = members.next)
11261 if(members.type == dataMembersInit)
11264 for(member = members.dataMembers->first; member; member = member.next)
11266 ListAdd(init.list, member.initializer);
11267 member.initializer = null;
11270 // Discard all MembersInitMethod
11273 FreeExpression(exp);
11275 case listInitializer:
11278 Type initializerType = null;
11279 Class curClass = null;
11280 DataMember curMember = null;
11281 DataMember subMemberStack[256];
11282 int subMemberStackPos = 0;
11284 if(type && type.kind == arrayType)
11285 initializerType = Dereference(type);
11286 else if(type && (type.kind == structType || type.kind == unionType))
11287 initializerType = type.members.first;
11289 for(i = init.list->first; i; i = i.next)
11291 if(type && type.kind == classType && type._class && type._class.registered)
11293 // 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)
11294 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11295 // TODO: Generate error on initializing a private data member this way from another module...
11298 if(!curMember.dataType)
11299 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11300 initializerType = curMember.dataType;
11303 ProcessInitializer(i, initializerType);
11304 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11305 initializerType = initializerType.next;
11307 init.isConstant = false;
11310 if(type && type.kind == arrayType)
11311 FreeType(initializerType);
11313 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11315 Compiler_Error($"Assigning list initializer to non list\n");
11322 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11326 case baseSpecifier:
11328 if(spec.specifier == THISCLASS)
11332 spec.type = nameSpecifier;
11333 spec.name = ReplaceThisClass(thisClass);
11334 spec.symbol = FindClass(spec.name);
11335 ProcessSpecifier(spec, declareStruct);
11340 case nameSpecifier:
11342 Symbol symbol = FindType(curContext, spec.name);
11344 DeclareType(symbol.type, true, true);
11345 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11346 DeclareStruct(spec.name, false);
11349 case enumSpecifier:
11354 for(e = spec.list->first; e; e = e.next)
11357 ProcessExpressionType(e.exp);
11362 case structSpecifier:
11363 case unionSpecifier:
11365 if(spec.definitions)
11368 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11370 ProcessClass(spec.definitions, symbol);
11373 for(def = spec.definitions->first; def; def = def.next)
11375 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11376 ProcessDeclaration(def.decl);
11383 case classSpecifier:
11385 Symbol classSym = FindClass(spec.name);
11386 if(classSym && classSym.registered && classSym.registered.type == structClass)
11387 DeclareStruct(spec.name, false);
11395 static void ProcessDeclarator(Declarator decl)
11399 case identifierDeclarator:
11400 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11402 FreeSpecifier(decl.identifier._class);
11403 decl.identifier._class = null;
11406 case arrayDeclarator:
11408 ProcessExpressionType(decl.array.exp);
11409 case structDeclarator:
11410 case bracketsDeclarator:
11411 case functionDeclarator:
11412 case pointerDeclarator:
11413 case extendedDeclarator:
11414 case extendedDeclaratorEnd:
11415 if(decl.declarator)
11416 ProcessDeclarator(decl.declarator);
11417 if(decl.type == functionDeclarator)
11419 Identifier id = GetDeclId(decl);
11420 if(id && id._class)
11424 qualifiers = MkListOne(id._class);
11427 if(!decl.function.parameters)
11428 decl.function.parameters = MkList();
11429 decl.function.parameters->Insert(null, param);
11432 if(decl.function.parameters)
11436 for(param = decl.function.parameters->first; param; param = param.next)
11438 if(param.qualifiers && param.qualifiers->first)
11440 Specifier spec = param.qualifiers->first;
11441 if(spec && spec.specifier == TYPED_OBJECT)
11443 Declarator d = param.declarator;
11446 qualifiers = MkListOne(MkSpecifier(VOID));
11447 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11449 if(d.type != pointerDeclarator)
11450 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11452 FreeList(param.qualifiers, FreeSpecifier);
11454 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11455 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11457 decl.function.parameters->Insert(param, newParam);
11460 else if(spec && spec.specifier == ANY_OBJECT)
11462 Declarator d = param.declarator;
11464 FreeList(param.qualifiers, FreeSpecifier);
11466 param.qualifiers = MkListOne(MkSpecifier(VOID));
11467 if(d.type != pointerDeclarator)
11468 param.qualifiers->Insert(null, MkSpecifier(CONST));
11469 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11471 else if(spec.specifier == THISCLASS)
11475 spec.type = nameSpecifier;
11476 spec.name = ReplaceThisClass(thisClass);
11477 spec.symbol = FindClass(spec.name);
11478 ProcessSpecifier(spec, false);
11483 if(param.declarator)
11484 ProcessDeclarator(param.declarator);
11492 static void ProcessDeclaration(Declaration decl)
11497 case initDeclaration:
11499 bool declareStruct = false;
11501 lineNum = decl.pos.line;
11502 column = decl.pos.col;
11505 if(decl.declarators)
11509 for(d = decl.declarators->first; d; d = d.next)
11511 Type type, subType;
11512 ProcessDeclarator(d.declarator);
11514 type = ProcessType(decl.specifiers, d.declarator);
11518 ProcessInitializer(d.initializer, type);
11520 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11522 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11523 d.initializer.exp.type == instanceExp)
11525 if(type.kind == classType && type._class ==
11526 d.initializer.exp.expType._class)
11528 Instantiation inst = d.initializer.exp.instance;
11529 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11531 d.initializer.exp.instance = null;
11532 if(decl.specifiers)
11533 FreeList(decl.specifiers, FreeSpecifier);
11534 FreeList(decl.declarators, FreeInitDeclarator);
11538 decl.type = instDeclaration;
11543 for(subType = type; subType;)
11545 if(subType.kind == classType)
11547 declareStruct = true;
11550 else if(subType.kind == pointerType)
11552 else if(subType.kind == arrayType)
11553 subType = subType.arrayType;
11563 if(decl.specifiers)
11566 for(s = decl.specifiers->first; s; s = s.next)
11568 ProcessSpecifier(s, declareStruct);
11573 case instDeclaration:
11575 ProcessInstantiationType(decl.inst);
11578 case structDeclaration:
11582 bool declareStruct = false;
11584 if(decl.declarators)
11586 for(d = decl.declarators->first; d; d = d.next)
11588 Type type = ProcessType(decl.specifiers, d.declarator);
11590 ProcessDeclarator(d);
11591 for(subType = type; subType;)
11593 if(subType.kind == classType)
11595 declareStruct = true;
11598 else if(subType.kind == pointerType)
11600 else if(subType.kind == arrayType)
11601 subType = subType.arrayType;
11608 if(decl.specifiers)
11610 for(spec = decl.specifiers->first; spec; spec = spec.next)
11611 ProcessSpecifier(spec, declareStruct);
11618 static FunctionDefinition curFunction;
11620 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11622 char propName[1024], propNameM[1024];
11623 char getName[1024], setName[1024];
11626 DeclareProperty(prop, setName, getName);
11628 // eInstance_FireWatchers(object, prop);
11629 strcpy(propName, "__ecereProp_");
11630 FullClassNameCat(propName, prop._class.fullName, false);
11631 strcat(propName, "_");
11632 // strcat(propName, prop.name);
11633 FullClassNameCat(propName, prop.name, true);
11634 MangleClassName(propName);
11636 strcpy(propNameM, "__ecerePropM_");
11637 FullClassNameCat(propNameM, prop._class.fullName, false);
11638 strcat(propNameM, "_");
11639 // strcat(propNameM, prop.name);
11640 FullClassNameCat(propNameM, prop.name, true);
11641 MangleClassName(propNameM);
11643 if(prop.isWatchable)
11646 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11647 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11648 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11651 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11652 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11653 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11659 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11660 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11661 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11664 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11665 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11666 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11669 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11670 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11671 curFunction.propSet.fireWatchersDone = true;
11674 static void ProcessStatement(Statement stmt)
11678 lineNum = stmt.pos.line;
11679 column = stmt.pos.col;
11684 ProcessStatement(stmt.labeled.stmt);
11687 // This expression should be constant...
11688 if(stmt.caseStmt.exp)
11690 FreeType(stmt.caseStmt.exp.destType);
11691 stmt.caseStmt.exp.destType = curSwitchType;
11692 if(curSwitchType) curSwitchType.refCount++;
11693 ProcessExpressionType(stmt.caseStmt.exp);
11694 ComputeExpression(stmt.caseStmt.exp);
11696 if(stmt.caseStmt.stmt)
11697 ProcessStatement(stmt.caseStmt.stmt);
11701 if(stmt.compound.context)
11706 Statement prevCompound = curCompound;
11707 Context prevContext = curContext;
11709 if(!stmt.compound.isSwitch)
11710 curCompound = stmt;
11711 curContext = stmt.compound.context;
11713 if(stmt.compound.declarations)
11715 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11716 ProcessDeclaration(decl);
11718 if(stmt.compound.statements)
11720 for(s = stmt.compound.statements->first; s; s = s.next)
11721 ProcessStatement(s);
11724 curContext = prevContext;
11725 curCompound = prevCompound;
11729 case expressionStmt:
11732 if(stmt.expressions)
11734 for(exp = stmt.expressions->first; exp; exp = exp.next)
11735 ProcessExpressionType(exp);
11743 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11744 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11745 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11746 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11748 ProcessExpressionType(exp);
11750 if(stmt.ifStmt.stmt)
11751 ProcessStatement(stmt.ifStmt.stmt);
11752 if(stmt.ifStmt.elseStmt)
11753 ProcessStatement(stmt.ifStmt.elseStmt);
11758 Type oldSwitchType = curSwitchType;
11759 if(stmt.switchStmt.exp)
11762 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11772 e.exp.destType = destType;
11775 ProcessExpressionType(exp);
11778 curSwitchType = exp.expType;
11781 ProcessStatement(stmt.switchStmt.stmt);
11782 curSwitchType = oldSwitchType;
11787 if(stmt.whileStmt.exp)
11791 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11792 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11793 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11794 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11796 ProcessExpressionType(exp);
11799 if(stmt.whileStmt.stmt)
11800 ProcessStatement(stmt.whileStmt.stmt);
11805 if(stmt.doWhile.exp)
11809 if(stmt.doWhile.exp->last)
11811 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11812 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11813 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11815 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11817 ProcessExpressionType(exp);
11820 if(stmt.doWhile.stmt)
11821 ProcessStatement(stmt.doWhile.stmt);
11827 if(stmt.forStmt.init)
11828 ProcessStatement(stmt.forStmt.init);
11830 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11832 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11833 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11834 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11837 if(stmt.forStmt.check)
11838 ProcessStatement(stmt.forStmt.check);
11839 if(stmt.forStmt.increment)
11841 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11842 ProcessExpressionType(exp);
11845 if(stmt.forStmt.stmt)
11846 ProcessStatement(stmt.forStmt.stmt);
11851 Identifier id = stmt.forEachStmt.id;
11852 OldList * exp = stmt.forEachStmt.exp;
11853 OldList * filter = stmt.forEachStmt.filter;
11854 Statement block = stmt.forEachStmt.stmt;
11855 char iteratorType[1024];
11858 bool isBuiltin = exp && exp->last &&
11859 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11860 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11861 Expression arrayExp;
11862 const char * typeString = null;
11863 int builtinCount = 0;
11865 for(e = exp ? exp->first : null; e; e = e.next)
11869 FreeType(e.destType);
11870 e.destType = ProcessTypeString("Container", false);
11872 if(!isBuiltin || e.next)
11873 ProcessExpressionType(e);
11876 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11877 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11878 eClass_IsDerived(source._class.registered, containerClass)))
11880 Class _class = source ? source._class.registered : null;
11882 Expression expIt = null;
11883 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
11884 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11885 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11886 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11887 stmt.type = compoundStmt;
11889 stmt.compound.context = Context { };
11890 stmt.compound.context.parent = curContext;
11891 curContext = stmt.compound.context;
11893 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11895 Class mapClass = eSystem_FindClass(privateModule, "Map");
11896 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11897 isCustomAVLTree = true;
11898 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
11900 else */if(eClass_IsDerived(source._class.registered, mapClass))
11903 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11904 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11906 Class listClass = eSystem_FindClass(privateModule, "List");
11908 isList = eClass_IsDerived(source._class.registered, listClass);
11914 OldList * specs = MkList();
11915 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11916 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11917 stmt.compound.declarations = MkListOne(
11918 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11919 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11920 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11921 MkInitializerAssignment(MkExpBrackets(exp))))));
11926 char typeStringBuf[1024];
11928 // TODO: Merge this code?
11929 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11930 if(((Expression)exp->last).type == castExp)
11932 TypeName typeName = ((Expression)exp->last).cast.typeName;
11934 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11937 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11938 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11939 arrayExp.destType._class.registered.templateArgs)
11941 Class templateClass = arrayExp.destType._class.registered;
11942 typeString = templateClass.templateArgs[2].dataTypeString;
11944 else if(arrayExp.list)
11946 // Guess type from expressions in the array
11948 for(e = arrayExp.list->first; e; e = e.next)
11950 ProcessExpressionType(e);
11953 if(!type) { type = e.expType; type.refCount++; }
11956 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11957 if(!MatchTypeExpression(e, type, null, false, true))
11963 e = arrayExp.list->first;
11964 ProcessExpressionType(e);
11967 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11968 if(!MatchTypeExpression(e, type, null, false, true))
11970 FreeType(e.expType);
11981 FreeType(e.expType);
11988 typeStringBuf[0] = '\0';
11989 PrintType(type, typeStringBuf, false, true);
11990 typeString = typeStringBuf;
11996 OldList * initializers = MkList();
11998 OldList * specs = MkList();
12003 builtinCount = arrayExp.list->count;
12004 type = ProcessTypeString(typeString, false);
12005 while(e = arrayExp.list->first)
12007 arrayExp.list->Remove(e);
12010 ProcessExpressionType(e);
12011 ListAdd(initializers, MkInitializerAssignment(e));
12014 delete arrayExp.list;
12016 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12017 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12018 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12020 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12022 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12023 ), MkInitializerList(initializers)))));
12024 FreeList(exp, FreeExpression);
12028 arrayExp.expType = ProcessTypeString("Container", false);
12029 Compiler_Error($"Couldn't determine type of array elements\n");
12034 OldList * specs = MkList();
12036 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12037 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12038 stmt.compound.declarations = MkListOne(
12039 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12040 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12041 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12042 MkInitializerAssignment(MkExpBrackets(exp))))));
12045 else if(isLinkList && !isList)
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("__internalLinkList")),
12053 MkInitializerAssignment(MkExpBrackets(exp))))));
12055 /*else if(isCustomAVLTree)
12058 OldList * specs = MkList();
12059 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12060 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12061 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12062 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12063 MkInitializerAssignment(MkExpBrackets(exp))))));
12065 else if(_class.templateArgs)
12068 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12070 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12072 stmt.compound.declarations = MkListOne(
12073 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12074 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12075 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12077 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12081 // Reparent sub-contexts in this statement
12085 if(block.compound.context)
12086 block.compound.context.parent = stmt.compound.context;
12089 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12090 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12091 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12092 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12095 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12096 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12099 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12100 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12103 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12104 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12107 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12108 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12111 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12112 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12114 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12117 case expressionStmt:
12123 case badDeclarationStmt:
12124 case fireWatchersStmt:
12125 case stopWatchingStmt:
12132 block = MkIfStmt(filter, block, null);
12136 stmt.compound.statements = MkListOne(MkForStmt(
12137 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12138 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12139 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12140 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12142 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12143 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12144 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12149 //OldList * specs = MkList();
12150 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12152 sprintf(count, "%d", builtinCount);
12154 stmt.compound.statements = MkListOne(MkForStmt(
12155 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12156 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12157 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12158 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12162 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12163 stmt.compound.statements = MkListOne(MkForStmt(
12164 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12165 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12166 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12167 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12170 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12171 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12172 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12174 else if(isLinkList && !isList)
12176 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12177 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12178 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12179 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
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)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12189 OldList * specs = MkList();
12190 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12191 stmt.compound.statements = MkListOne(MkForStmt(
12192 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12193 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12194 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12195 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12196 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12199 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12200 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12201 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12203 /*else if(isCustomAVLTree)
12205 stmt.compound.statements = MkListOne(MkForStmt(
12206 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12207 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12208 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12209 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12212 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12213 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12214 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12218 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12219 MkIdentifier("Next")), null)), block));
12221 ProcessExpressionType(expIt);
12222 if(stmt.compound.declarations->first)
12223 ProcessDeclaration(stmt.compound.declarations->first);
12226 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12228 ProcessStatement(stmt);
12229 curContext = stmt.compound.context.parent;
12234 Compiler_Error($"Expression is not a container\n");
12247 if(stmt.expressions)
12249 for(exp = stmt.expressions->first; exp; exp = exp.next)
12253 if(curFunction && !curFunction.type)
12254 curFunction.type = ProcessType(
12255 curFunction.specifiers, curFunction.declarator);
12256 FreeType(exp.destType);
12257 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12258 if(exp.destType) exp.destType.refCount++;
12260 ProcessExpressionType(exp);
12265 case badDeclarationStmt:
12267 ProcessDeclaration(stmt.decl);
12273 if(stmt.asmStmt.inputFields)
12275 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12276 if(field.expression)
12277 ProcessExpressionType(field.expression);
12279 if(stmt.asmStmt.outputFields)
12281 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12282 if(field.expression)
12283 ProcessExpressionType(field.expression);
12285 if(stmt.asmStmt.clobberedFields)
12287 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12289 if(field.expression)
12290 ProcessExpressionType(field.expression);
12297 PropertyWatch propWatch;
12298 OldList * watches = stmt._watch.watches;
12299 Expression object = stmt._watch.object;
12300 Expression watcher = stmt._watch.watcher;
12302 ProcessExpressionType(watcher);
12304 ProcessExpressionType(object);
12308 if(watcher || thisClass)
12310 External external = curExternal;
12311 Context context = curContext;
12313 stmt.type = expressionStmt;
12314 stmt.expressions = MkList();
12316 curExternal = external.prev;
12318 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12320 ClassFunction func;
12321 char watcherName[1024];
12322 Class watcherClass = watcher ?
12323 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12324 External createdExternal;
12326 // Create a declaration above
12327 External externalDecl = MkExternalDeclaration(null);
12328 ast->Insert(curExternal.prev, externalDecl);
12330 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12331 if(propWatch.deleteWatch)
12332 strcat(watcherName, "_delete");
12336 for(propID = propWatch.properties->first; propID; propID = propID.next)
12338 strcat(watcherName, "_");
12339 strcat(watcherName, propID.string);
12343 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12345 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12346 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12347 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12348 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12349 ProcessClassFunctionBody(func, propWatch.compound);
12350 propWatch.compound = null;
12352 //afterExternal = afterExternal ? afterExternal : curExternal;
12354 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12355 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12357 createdExternal.symbol.idCode = external.symbol.idCode;
12359 curExternal = createdExternal;
12360 ProcessFunction(createdExternal.function);
12363 // Create a declaration above
12365 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12366 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12367 externalDecl.declaration = decl;
12368 if(decl.symbol && !decl.symbol.pointerExternal)
12369 decl.symbol.pointerExternal = externalDecl;
12372 if(propWatch.deleteWatch)
12374 OldList * args = MkList();
12375 ListAdd(args, CopyExpression(object));
12376 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12377 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12378 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12382 Class _class = object.expType._class.registered;
12385 for(propID = propWatch.properties->first; propID; propID = propID.next)
12387 char propName[1024];
12388 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12391 char getName[1024], setName[1024];
12392 OldList * args = MkList();
12394 DeclareProperty(prop, setName, getName);
12396 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12397 strcpy(propName, "__ecereProp_");
12398 FullClassNameCat(propName, prop._class.fullName, false);
12399 strcat(propName, "_");
12400 // strcat(propName, prop.name);
12401 FullClassNameCat(propName, prop.name, true);
12403 ListAdd(args, CopyExpression(object));
12404 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12405 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12406 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12408 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12411 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12416 Compiler_Error($"Invalid watched object\n");
12419 curExternal = external;
12420 curContext = context;
12423 FreeExpression(watcher);
12425 FreeExpression(object);
12426 FreeList(watches, FreePropertyWatch);
12429 Compiler_Error($"No observer specified and not inside a _class\n");
12433 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12435 ProcessStatement(propWatch.compound);
12441 case fireWatchersStmt:
12443 OldList * watches = stmt._watch.watches;
12444 Expression object = stmt._watch.object;
12446 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12447 // printf("%X\n", watches);
12448 // printf("%X\n", stmt._watch.watches);
12450 ProcessExpressionType(object);
12455 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12461 stmt.type = expressionStmt;
12462 stmt.expressions = MkList();
12464 // Check if we're inside a property set
12465 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12467 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12471 //Compiler_Error($"No property specified and not inside a property set\n");
12475 for(propID = watches->first; propID; propID = propID.next)
12477 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12480 CreateFireWatcher(prop, object, stmt);
12483 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12488 // Fire all properties!
12491 for(base = _class; base; base = base.base)
12493 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12495 if(prop.isProperty && prop.isWatchable)
12497 CreateFireWatcher(prop, object, stmt);
12504 FreeExpression(object);
12505 FreeList(watches, FreeIdentifier);
12508 Compiler_Error($"Invalid object specified and not inside a class\n");
12512 case stopWatchingStmt:
12514 OldList * watches = stmt._watch.watches;
12515 Expression object = stmt._watch.object;
12516 Expression watcher = stmt._watch.watcher;
12519 ProcessExpressionType(object);
12521 ProcessExpressionType(watcher);
12524 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12526 if(watcher || thisClass)
12532 stmt.type = expressionStmt;
12533 stmt.expressions = MkList();
12538 // eInstance_StopWatching(object, null, watcher);
12540 ListAdd(args, CopyExpression(object));
12541 ListAdd(args, MkExpConstant("0"));
12542 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12543 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12547 for(propID = watches->first; propID; propID = propID.next)
12549 char propName[1024];
12550 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12553 char getName[1024], setName[1024];
12554 OldList * args = MkList();
12556 DeclareProperty(prop, setName, getName);
12558 // eInstance_StopWatching(object, prop, watcher);
12559 strcpy(propName, "__ecereProp_");
12560 FullClassNameCat(propName, prop._class.fullName, false);
12561 strcat(propName, "_");
12562 // strcat(propName, prop.name);
12563 FullClassNameCat(propName, prop.name, true);
12564 MangleClassName(propName);
12566 ListAdd(args, CopyExpression(object));
12567 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12568 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12569 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12572 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12577 FreeExpression(object);
12579 FreeExpression(watcher);
12580 FreeList(watches, FreeIdentifier);
12583 Compiler_Error($"Invalid object specified and not inside a class\n");
12586 Compiler_Error($"No observer specified and not inside a class\n");
12593 static void ProcessFunction(FunctionDefinition function)
12595 Identifier id = GetDeclId(function.declarator);
12596 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12597 Type type = symbol ? symbol.type : null;
12598 Class oldThisClass = thisClass;
12599 Context oldTopContext = topContext;
12601 yylloc = function.loc;
12602 // Process thisClass
12604 if(type && type.thisClass)
12606 Symbol classSym = type.thisClass;
12607 Class _class = type.thisClass.registered;
12608 char className[1024];
12609 char structName[1024];
12610 Declarator funcDecl;
12613 bool typedObject = false;
12615 if(_class && !_class.base)
12617 _class = currentClass;
12618 if(_class && !_class.symbol)
12619 _class.symbol = FindClass(_class.fullName);
12620 classSym = _class ? _class.symbol : null;
12621 typedObject = true;
12624 thisClass = _class;
12626 if(inCompiler && _class)
12628 if(type.kind == functionType)
12630 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12632 //TypeName param = symbol.type.params.first;
12633 Type param = symbol.type.params.first;
12634 symbol.type.params.Remove(param);
12635 //FreeTypeName(param);
12638 if(type.classObjectType != classPointer)
12640 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12641 symbol.type.staticMethod = true;
12642 symbol.type.thisClass = null;
12644 // HIGH DANGER: VERIFYING THIS...
12645 symbol.type.extraParam = false;
12649 strcpy(className, "__ecereClass_");
12650 FullClassNameCat(className, _class.fullName, true);
12652 MangleClassName(className);
12655 FullClassNameCat(structName, _class.fullName, false);
12660 funcDecl = GetFuncDecl(function.declarator);
12663 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12665 TypeName param = funcDecl.function.parameters->first;
12666 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12668 funcDecl.function.parameters->Remove(param);
12669 FreeTypeName(param);
12673 // DANGER: Watch for this... Check if it's a Conversion?
12674 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12676 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12677 if(!function.propertyNoThis)
12679 TypeName thisParam;
12681 if(type.classObjectType != classPointer)
12683 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12684 if(!funcDecl.function.parameters)
12685 funcDecl.function.parameters = MkList();
12686 funcDecl.function.parameters->Insert(null, thisParam);
12691 if(type.classObjectType != classPointer)
12693 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12694 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12697 thisParam = TypeName
12699 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12700 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12702 funcDecl.function.parameters->Insert(null, thisParam);
12707 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12709 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12710 funcDecl = GetFuncDecl(initDecl.declarator);
12713 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12715 TypeName param = funcDecl.function.parameters->first;
12716 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12718 funcDecl.function.parameters->Remove(param);
12719 FreeTypeName(param);
12723 if(type.classObjectType != classPointer)
12725 // DANGER: Watch for this... Check if it's a Conversion?
12726 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12728 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12730 if(!funcDecl.function.parameters)
12731 funcDecl.function.parameters = MkList();
12732 funcDecl.function.parameters->Insert(null, thisParam);
12739 // Add this to the context
12742 if(type.classObjectType != classPointer)
12744 thisSymbol = Symbol
12746 string = CopyString("this");
12747 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12749 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12751 if(typedObject && thisSymbol.type)
12753 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12754 thisSymbol.type.byReference = type.byReference;
12755 thisSymbol.type.typedByReference = type.byReference;
12757 thisSymbol = Symbol { string = CopyString("class") };
12758 function.body.compound.context.symbols.Add(thisSymbol);
12764 // Pointer to class data
12766 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12768 DataMember member = null;
12771 for(base = _class; base && base.type != systemClass; base = base.next)
12773 for(member = base.membersAndProperties.first; member; member = member.next)
12774 if(!member.isProperty)
12780 for(member = _class.membersAndProperties.first; member; member = member.next)
12781 if(!member.isProperty)
12785 char pointerName[1024];
12788 Initializer initializer;
12789 Expression exp, bytePtr;
12791 strcpy(pointerName, "__ecerePointer_");
12792 FullClassNameCat(pointerName, _class.fullName, false);
12794 char className[1024];
12795 strcpy(className, "__ecereClass_");
12796 FullClassNameCat(className, classSym.string, true);
12797 MangleClassName(className);
12800 DeclareClass(classSym, className);
12804 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12809 sprintf(string, "%d", _class.offset);
12810 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12814 // ([bytePtr] + [className]->offset)
12815 exp = QBrackets(MkExpOp(bytePtr, '+',
12816 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12819 // (this ? [exp] : 0)
12820 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12824 kind = pointerType;
12825 type = Type { refCount = 1, kind = voidType };
12830 yylloc = function.body.loc;
12831 // ([structName] *) [exp]
12832 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12833 initializer = MkInitializerAssignment(
12834 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12836 // [structName] * [pointerName] = [initializer];
12837 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12840 Context prevContext = curContext;
12841 curContext = function.body.compound.context;
12843 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12844 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12846 curContext = prevContext;
12850 decl.symbol = null;
12852 if(!function.body.compound.declarations)
12853 function.body.compound.declarations = MkList();
12854 function.body.compound.declarations->Insert(null, decl);
12860 // Loop through the function and replace undeclared identifiers
12861 // which are a member of the class (methods, properties or data)
12862 // by "this.[member]"
12869 FreeSpecifier(id._class);
12872 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12874 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12875 id = GetDeclId(initDecl.declarator);
12877 FreeSpecifier(id._class);
12882 topContext = function.body.compound.context;
12884 FunctionDefinition oldFunction = curFunction;
12885 curFunction = function;
12887 ProcessStatement(function.body);
12889 // If this is a property set and no firewatchers has been done yet, add one here
12890 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12892 Statement prevCompound = curCompound;
12893 Context prevContext = curContext;
12895 Statement fireWatchers = MkFireWatchersStmt(null, null);
12896 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12897 ListAdd(function.body.compound.statements, fireWatchers);
12899 curCompound = function.body;
12900 curContext = function.body.compound.context;
12902 ProcessStatement(fireWatchers);
12904 curContext = prevContext;
12905 curCompound = prevCompound;
12909 curFunction = oldFunction;
12912 if(function.declarator)
12914 ProcessDeclarator(function.declarator);
12917 topContext = oldTopContext;
12918 thisClass = oldThisClass;
12921 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12922 static void ProcessClass(OldList definitions, Symbol symbol)
12925 External external = curExternal;
12926 Class regClass = symbol ? symbol.registered : null;
12928 // Process all functions
12929 for(def = definitions.first; def; def = def.next)
12931 if(def.type == functionClassDef)
12933 if(def.function.declarator)
12934 curExternal = def.function.declarator.symbol.pointerExternal;
12936 curExternal = external;
12938 ProcessFunction((FunctionDefinition)def.function);
12940 else if(def.type == declarationClassDef)
12942 if(def.decl.type == instDeclaration)
12944 thisClass = regClass;
12945 ProcessInstantiationType(def.decl.inst);
12951 Class backThisClass = thisClass;
12952 if(regClass) thisClass = regClass;
12953 ProcessDeclaration(def.decl);
12954 thisClass = backThisClass;
12957 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12959 MemberInit defProperty;
12961 // Add this to the context
12962 Symbol thisSymbol = Symbol
12964 string = CopyString("this");
12965 type = regClass ? MkClassType(regClass.fullName) : null;
12967 globalContext.symbols.Add((BTNode)thisSymbol);
12969 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12971 thisClass = regClass;
12972 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12976 globalContext.symbols.Remove((BTNode)thisSymbol);
12977 FreeSymbol(thisSymbol);
12979 else if(def.type == propertyClassDef && def.propertyDef)
12981 PropertyDef prop = def.propertyDef;
12983 // Add this to the context
12985 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12986 globalContext.symbols.Add(thisSymbol);
12989 thisClass = regClass;
12996 string = CopyString("this");
12997 type = MkClassType(regClass.fullName);
12999 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13002 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13003 ProcessStatement(prop.setStmt);
13011 string = CopyString("this");
13012 type = MkClassType(regClass.fullName);
13014 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13017 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13018 ProcessStatement(prop.getStmt);
13026 string = CopyString("this");
13027 type = MkClassType(regClass.fullName);
13029 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13032 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13033 ProcessStatement(prop.issetStmt);
13039 globalContext.symbols.Remove(thisSymbol);
13040 FreeSymbol(thisSymbol);
13043 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13045 PropertyWatch propertyWatch = def.propertyWatch;
13047 thisClass = regClass;
13048 if(propertyWatch.compound)
13052 string = CopyString("this");
13053 type = regClass ? MkClassType(regClass.fullName) : null;
13056 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13058 curExternal = null;
13059 ProcessStatement(propertyWatch.compound);
13066 void DeclareFunctionUtil(const String s)
13068 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13073 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13074 strcpy(name, "__ecereFunction_");
13075 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13076 DeclareFunction(function, name);
13080 void ComputeDataTypes()
13084 External after = null;
13086 currentClass = null;
13088 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13090 for(external = ast->first; external; external = external.next)
13092 if(external.type == declarationExternal)
13094 Declaration decl = external.declaration;
13097 OldList * decls = decl.declarators;
13100 InitDeclarator initDecl = decls->first;
13103 Declarator declarator = initDecl.declarator;
13104 if(declarator && declarator.type == identifierDeclarator)
13106 Identifier id = declarator.identifier;
13107 if(id && id.string)
13109 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
13111 external.symbol.id = -1001, external.symbol.idCode = -1001;
13122 temp.symbol = Symbol { id = -1000, idCode = -1000 };
13123 ast->Insert(after, temp);
13124 curExternal = temp;
13126 DeclareFunctionUtil("eSystem_New");
13127 DeclareFunctionUtil("eSystem_New0");
13128 DeclareFunctionUtil("eSystem_Renew");
13129 DeclareFunctionUtil("eSystem_Renew0");
13130 DeclareFunctionUtil("eSystem_Delete");
13131 DeclareFunctionUtil("eClass_GetProperty");
13132 DeclareFunctionUtil("eClass_SetProperty");
13133 DeclareFunctionUtil("eInstance_FireSelfWatchers");
13134 DeclareFunctionUtil("eInstance_SetMethod");
13135 DeclareFunctionUtil("eInstance_IncRef");
13136 DeclareFunctionUtil("eInstance_StopWatching");
13137 DeclareFunctionUtil("eInstance_Watch");
13138 DeclareFunctionUtil("eInstance_FireWatchers");
13140 DeclareStruct("ecere::com::Class", false);
13141 DeclareStruct("ecere::com::Instance", false);
13142 DeclareStruct("ecere::com::Property", false);
13143 DeclareStruct("ecere::com::DataMember", false);
13144 DeclareStruct("ecere::com::Method", false);
13145 DeclareStruct("ecere::com::SerialBuffer", false);
13146 DeclareStruct("ecere::com::ClassTemplateArgument", false);
13150 for(external = ast->first; external; external = external.next)
13152 afterExternal = curExternal = external;
13153 if(external.type == functionExternal)
13155 currentClass = external.function._class;
13156 ProcessFunction(external.function);
13158 // There shouldn't be any _class member access here anyways...
13159 else if(external.type == declarationExternal)
13161 currentClass = null;
13162 if(external.declaration)
13163 ProcessDeclaration(external.declaration);
13165 else if(external.type == classExternal)
13167 ClassDefinition _class = external._class;
13168 currentClass = external.symbol.registered;
13169 if(_class.definitions)
13171 ProcessClass(_class.definitions, _class.symbol);
13175 // Free class data...
13176 ast->Remove(external);
13180 else if(external.type == nameSpaceExternal)
13182 thisNameSpace = external.id.string;
13185 currentClass = null;
13186 thisNameSpace = null;
13187 curExternal = null;
13189 delete temp.symbol;