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;
892 Context context = isMember ? null : SetupTemplatesContext(_class);
894 *addedPadding = false;
896 if(!isMember && _class.base)
898 maxSize = _class.structSize;
899 //if(_class.base.type != systemClass) // Commented out with new Instance _class
901 // DANGER: Testing this noHeadClass here...
902 if(_class.type == structClass || _class.type == noHeadClass)
903 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
906 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
907 if(maxSize > baseSize)
915 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
917 if(!member.isProperty)
923 if(member.dataTypeString)
925 OldList * specs = MkList(), * decls = MkList();
928 decl = SpecDeclFromString(member.dataTypeString, specs,
929 MkDeclaratorIdentifier(MkIdentifier(member.name)));
930 ListAdd(decls, MkStructDeclarator(decl, null));
931 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
934 member.dataType = ProcessType(specs, decl);
936 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
939 Type type = ProcessType(specs, decl);
940 DeclareType(member.dataType, false, false);
944 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
945 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
946 DeclareStruct(member.dataType._class.string, false);
949 ComputeTypeSize(member.dataType);
950 size = member.dataType.size;
951 alignment = member.dataType.alignment;
955 if(totalSize % alignment)
956 totalSize += alignment - (totalSize % alignment);
965 OldList * specs = MkList(), * list = MkList();
968 AddMembers(list, (Class)member, true, &size, topClass, null);
970 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
971 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
972 alignment = member.structAlignment;
976 if(totalSize % alignment)
977 totalSize += alignment - (totalSize % alignment);
987 if(topMember && topMember.type == unionMember)
988 *retSize = Max(*retSize, totalSize);
990 *retSize += totalSize;
992 else if(totalSize < maxSize && _class.type != systemClass)
995 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
996 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
997 if(totalSize + autoPadding < maxSize)
1000 sprintf(sizeString, "%d", maxSize - totalSize);
1001 ListAdd(declarations,
1002 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1003 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1005 *addedPadding = true;
1009 FinishTemplatesContext(context);
1010 return topMember ? topMember.memberID : _class.memberID;
1013 static int DeclareMembers(Class _class, bool isMember)
1015 DataMember topMember = isMember ? (DataMember) _class : null;
1017 Context context = isMember ? null : SetupTemplatesContext(_class);
1019 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1020 DeclareMembers(_class.base, false);
1022 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1024 if(!member.isProperty)
1031 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1032 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1033 DeclareStruct(member.dataType._class.string, false);
1035 if(!member.dataType && member.dataTypeString)
1036 member.dataType = ProcessTypeString(member.dataTypeString, false);
1038 DeclareType(member.dataType, false, false);
1044 DeclareMembers((Class)member, true);
1051 FinishTemplatesContext(context);
1053 return topMember ? topMember.memberID : _class.memberID;
1056 void DeclareStruct(const char * name, bool skipNoHead)
1058 External external = null;
1059 Symbol classSym = FindClass(name);
1061 if(!inCompiler || !classSym) return;
1063 // We don't need any declaration for bit classes...
1064 if(classSym.registered &&
1065 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1068 /*if(classSym.registered.templateClass)
1069 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1072 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1074 // Add typedef struct
1076 OldList * specifiers, * declarators;
1077 OldList * declarations = null;
1078 char structName[1024];
1079 Specifier spec = null;
1080 external = (classSym.registered && classSym.registered.type == structClass) ?
1081 classSym.pointerExternal : classSym.structExternal;
1083 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1084 // Moved this one up because DeclareClass done later will need it
1086 classSym.declaring++;
1088 if(strchr(classSym.string, '<'))
1090 if(classSym.registered.templateClass)
1092 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1093 classSym.declaring--;
1099 DeclareMembers(classSym.registered, false);
1102 FullClassNameCat(structName, name, false);
1104 if(external && external.declaration && external.declaration.specifiers)
1106 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1108 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1114 external = MkExternalDeclaration(null);*/
1116 if(!skipNoHead && (!spec || !spec.definitions))
1118 bool addedPadding = false;
1119 classSym.declaredStructSym = true;
1121 declarations = MkList();
1123 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1125 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1126 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1128 if(!declarations->count || (declarations->count == 1 && addedPadding))
1130 FreeList(declarations, FreeClassDef);
1131 declarations = null;
1134 if(skipNoHead || declarations)
1139 spec.definitions = declarations;
1141 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1144 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1147 if(classSym.structExternal)
1148 ast->Move(classSym.structExternal, curExternal.prev);
1149 ast->Move(classSym.pointerExternal, curExternal.prev);
1151 classSym.id = curExternal.symbol.idCode;
1152 classSym.idCode = curExternal.symbol.idCode;
1153 // external = classSym.pointerExternal;
1154 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1160 external = MkExternalDeclaration(null);
1162 specifiers = MkList();
1163 declarators = MkList();
1164 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1167 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1168 ListAdd(declarators, MkInitDeclarator(d, null));
1170 external.declaration = decl = MkDeclaration(specifiers, declarators);
1171 if(decl.symbol && !decl.symbol.pointerExternal)
1172 decl.symbol.pointerExternal = external;
1174 // For simple classes, keep the declaration as the external to move around
1175 if(classSym.registered && classSym.registered.type == structClass)
1177 char className[1024];
1178 strcpy(className, "__ecereClass_");
1179 FullClassNameCat(className, classSym.string, true);
1180 MangleClassName(className);
1183 DeclareClass(classSym, className);
1185 external.symbol = classSym;
1186 classSym.pointerExternal = external;
1187 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1188 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1192 char className[1024];
1193 strcpy(className, "__ecereClass_");
1194 FullClassNameCat(className, classSym.string, true);
1195 MangleClassName(className);
1197 // TOFIX: TESTING THIS...
1198 classSym.structExternal = external;
1199 DeclareClass(classSym, className);
1200 external.symbol = classSym;
1204 ast->Insert(curExternal ? curExternal.prev : null, external);
1208 classSym.declaring--;
1210 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1212 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1213 // Moved this one up because DeclareClass done later will need it
1216 classSym.declaring++;
1220 if(classSym.registered)
1221 DeclareMembers(classSym.registered, false);
1224 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1227 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1230 if(classSym.structExternal)
1231 ast->Move(classSym.structExternal, curExternal.prev);
1232 ast->Move(classSym.pointerExternal, curExternal.prev);
1234 classSym.id = curExternal.symbol.idCode;
1235 classSym.idCode = curExternal.symbol.idCode;
1236 // external = classSym.pointerExternal;
1237 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1240 classSym.declaring--;
1245 void DeclareProperty(Property prop, char * setName, char * getName)
1247 Symbol symbol = prop.symbol;
1249 strcpy(setName, "__ecereProp_");
1250 FullClassNameCat(setName, prop._class.fullName, false);
1251 strcat(setName, "_Set_");
1252 // strcat(setName, prop.name);
1253 FullClassNameCat(setName, prop.name, true);
1254 MangleClassName(setName);
1256 strcpy(getName, "__ecereProp_");
1257 FullClassNameCat(getName, prop._class.fullName, false);
1258 strcat(getName, "_Get_");
1259 FullClassNameCat(getName, prop.name, true);
1260 // strcat(getName, prop.name);
1262 // To support "char *" property
1263 MangleClassName(getName);
1265 if(prop._class.type == structClass)
1266 DeclareStruct(prop._class.fullName, false);
1268 if(!symbol || curExternal.symbol.idCode < symbol.id)
1270 bool imported = false;
1271 bool dllImport = false;
1273 if(!symbol || symbol._import)
1278 if(!prop._class.symbol)
1279 prop._class.symbol = FindClass(prop._class.fullName);
1280 classSym = prop._class.symbol;
1281 if(classSym && !classSym._import)
1283 ModuleImport module;
1285 if(prop._class.module)
1286 module = FindModule(prop._class.module);
1288 module = mainModule;
1290 classSym._import = ClassImport
1292 name = CopyString(prop._class.fullName);
1293 isRemote = prop._class.isRemote;
1295 module.classes.Add(classSym._import);
1297 symbol = prop.symbol = Symbol { };
1298 symbol._import = (ClassImport)PropertyImport
1300 name = CopyString(prop.name);
1301 isVirtual = false; //prop.isVirtual;
1302 hasSet = prop.Set ? true : false;
1303 hasGet = prop.Get ? true : false;
1306 classSym._import.properties.Add(symbol._import);
1309 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1310 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1311 prop._class.module.importType != staticImport)
1317 Context context = SetupTemplatesContext(prop._class);
1318 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1319 FinishTemplatesContext(context);
1325 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1328 OldList * specifiers, * declarators;
1333 Declarator typeDecl;
1334 bool simple = false;
1336 specifiers = MkList();
1337 declarators = MkList();
1340 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1341 MkDeclaratorIdentifier(MkIdentifier("this"))));
1343 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1346 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1349 Context context = SetupTemplatesContext(prop._class);
1350 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1351 FinishTemplatesContext(context);
1354 // Make sure the simple _class's type is declared
1355 for(spec = specifiers->first; spec; spec = spec.next)
1357 if(spec.type == nameSpecifier /*SpecifierClass*/)
1359 if((!typeDecl || typeDecl.type == identifierDeclarator))
1361 Symbol classSym = spec.symbol; // FindClass(spec.name);
1362 symbol._class = classSym.registered;
1363 if(classSym.registered && classSym.registered.type == structClass)
1365 DeclareStruct(spec.name, false);
1373 d = PlugDeclarator(typeDecl, d);
1376 ListAdd(params, MkTypeName(specifiers,
1377 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1378 specifiers = MkList();
1381 d = MkDeclaratorFunction(d, params);
1385 specifiers->Insert(null, MkSpecifier(EXTERN));
1386 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1387 specifiers->Insert(null, MkSpecifier(STATIC));
1389 ListAdd(specifiers, MkSpecifier(VOID));
1391 ListAdd(declarators, MkInitDeclarator(d, null));
1393 decl = MkDeclaration(specifiers, declarators);
1395 external = MkExternalDeclaration(decl);
1396 ast->Insert(curExternal.prev, external);
1397 external.symbol = symbol;
1398 symbol.externalGet = external;
1400 ReplaceThisClassSpecifiers(specifiers, prop._class);
1403 FreeDeclarator(typeDecl);
1407 // Move declaration higher...
1408 ast->Move(symbol.externalGet, curExternal.prev);
1415 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1418 OldList * specifiers, * declarators;
1423 Declarator typeDecl;
1425 declarators = MkList();
1428 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1429 if(!prop.conversion || prop._class.type == structClass)
1431 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1432 MkDeclaratorIdentifier(MkIdentifier("this"))));
1435 specifiers = MkList();
1438 Context context = SetupTemplatesContext(prop._class);
1439 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1440 MkDeclaratorIdentifier(MkIdentifier("value")));
1441 FinishTemplatesContext(context);
1443 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1444 specifiers->Insert(null, MkSpecifier(CONST));
1446 ListAdd(params, MkTypeName(specifiers, d));
1448 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1451 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1452 d = MkDeclaratorFunction(d, params);
1454 // Make sure the simple _class's type is declared
1455 for(spec = specifiers->first; spec; spec = spec.next)
1457 if(spec.type == nameSpecifier /*SpecifierClass*/)
1459 if((!typeDecl || typeDecl.type == identifierDeclarator))
1461 Symbol classSym = spec.symbol; // FindClass(spec.name);
1462 symbol._class = classSym.registered;
1463 if(classSym.registered && classSym.registered.type == structClass)
1464 DeclareStruct(spec.name, false);
1469 ListAdd(declarators, MkInitDeclarator(d, null));
1471 specifiers = MkList();
1474 specifiers->Insert(null, MkSpecifier(EXTERN));
1475 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1476 specifiers->Insert(null, MkSpecifier(STATIC));
1478 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1479 if(!prop.conversion || prop._class.type == structClass)
1480 ListAdd(specifiers, MkSpecifier(VOID));
1482 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1484 decl = MkDeclaration(specifiers, declarators);
1486 external = MkExternalDeclaration(decl);
1487 ast->Insert(curExternal.prev, external);
1488 external.symbol = symbol;
1489 symbol.externalSet = external;
1491 ReplaceThisClassSpecifiers(specifiers, prop._class);
1495 // Move declaration higher...
1496 ast->Move(symbol.externalSet, curExternal.prev);
1500 // Property (for Watchers)
1501 if(!symbol.externalPtr)
1505 OldList * specifiers = MkList();
1506 char propName[1024];
1509 specifiers->Insert(null, MkSpecifier(EXTERN));
1511 specifiers->Insert(null, MkSpecifier(STATIC));
1513 ListAdd(specifiers, MkSpecifierName("Property"));
1515 strcpy(propName, "__ecereProp_");
1516 FullClassNameCat(propName, prop._class.fullName, false);
1517 strcat(propName, "_");
1518 FullClassNameCat(propName, prop.name, true);
1519 // strcat(propName, prop.name);
1520 MangleClassName(propName);
1523 OldList * list = MkList();
1524 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1525 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1529 strcpy(propName, "__ecerePropM_");
1530 FullClassNameCat(propName, prop._class.fullName, false);
1531 strcat(propName, "_");
1532 // strcat(propName, prop.name);
1533 FullClassNameCat(propName, prop.name, true);
1535 MangleClassName(propName);
1537 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1538 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1540 decl = MkDeclaration(specifiers, list);
1543 external = MkExternalDeclaration(decl);
1544 ast->Insert(curExternal.prev, external);
1545 external.symbol = symbol;
1546 symbol.externalPtr = external;
1550 // Move declaration higher...
1551 ast->Move(symbol.externalPtr, curExternal.prev);
1554 symbol.id = curExternal.symbol.idCode;
1558 // ***************** EXPRESSION PROCESSING ***************************
1559 public Type Dereference(Type source)
1564 if(source.kind == pointerType || source.kind == arrayType)
1567 source.type.refCount++;
1569 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1577 // Support dereferencing of no head classes for now...
1578 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1584 Compiler_Error($"cannot dereference type\n");
1589 static Type Reference(Type source)
1605 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1607 Identifier ident = member.identifiers ? member.identifiers->first : null;
1609 DataMember dataMember = null;
1610 Method method = null;
1611 bool freeType = false;
1613 yylloc = member.loc;
1619 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1623 dataMember = *curMember;
1629 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1630 DataMember _subMemberStack[256];
1631 int _subMemberStackPos = 0;
1633 // FILL MEMBER STACK
1635 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1638 dataMember = thisMember;
1639 if(curMember && thisMember.memberAccess == publicAccess)
1641 *curMember = thisMember;
1642 *curClass = thisMember._class;
1643 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1644 *subMemberStackPos = _subMemberStackPos;
1651 method = eClass_FindMethod(_class, ident.string, privateModule);
1652 if(method && method.type == virtualMethod)
1664 if(!dataMember.dataType && dataMember.dataTypeString)
1666 //Context context = SetupTemplatesContext(dataMember._class);
1667 Context context = SetupTemplatesContext(_class);
1668 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1669 FinishTemplatesContext(context);
1671 type = dataMember.dataType;
1675 // This is for destination type...
1676 if(!method.dataType)
1677 ProcessMethodType(method);
1678 //DeclareMethod(method);
1679 // method.dataType = ((Symbol)method.symbol)->type;
1680 type = method.dataType;
1683 if(ident && ident.next)
1685 for(ident = ident.next; ident && type; ident = ident.next)
1687 if(type.kind == classType)
1689 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1691 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1693 type = dataMember.dataType;
1695 else if(type.kind == structType || type.kind == unionType)
1698 for(memberType = type.members.first; memberType; memberType = memberType.next)
1700 if(!strcmp(memberType.name, ident.string))
1710 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1711 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1714 ClassTemplateParameter curParam = null;
1716 for(sClass = _class; sClass; sClass = sClass.base)
1719 if(sClass.templateClass) sClass = sClass.templateClass;
1720 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1722 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1724 for(sClass = sClass.base; sClass; sClass = sClass.base)
1726 if(sClass.templateClass) sClass = sClass.templateClass;
1727 id += sClass.templateParams.count;
1738 ClassTemplateArgument arg = _class.templateArgs[id];
1739 if(arg.dataTypeString)
1741 bool constant = type.constant;
1743 type = ProcessTypeString(arg.dataTypeString, false);
1744 if(type.kind == classType && constant) type.constant = true;
1745 else if(type.kind == pointerType)
1748 while(t.kind == pointerType) t = t.type;
1749 if(constant) t.constant = constant;
1752 if(type && _class.templateClass)
1753 type.passAsTemplate = true;
1759 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1760 exp.destType.refCount++;
1766 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1768 Class expClass = type._class.registered;
1769 Class cClass = null;
1774 char templateString[1024];
1775 ClassTemplateParameter param;
1776 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1777 for(cClass = expClass; cClass; cClass = cClass.base)
1780 if(cClass.templateClass) cClass = cClass.templateClass;
1781 for(param = cClass.templateParams.first; param; param = param.next)
1785 ClassTemplateArgument arg;
1786 for(sClass = cClass.base; sClass; sClass = sClass.base)
1788 if(sClass.templateClass) sClass = sClass.templateClass;
1789 id += sClass.templateParams.count;
1791 arg = expClass.templateArgs[id];
1793 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1795 ClassTemplateParameter cParam;
1796 //int p = numParams - sClass.templateParams.count;
1799 if(sClass.templateClass) sClass = sClass.templateClass;
1801 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1803 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1804 p += nextClass.templateParams.count;
1807 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1809 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1811 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1813 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1814 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1826 strcat(argument, arg.name.string);
1827 strcat(argument, " = ");
1833 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1834 char expString[1024];
1835 OldList * specs = MkList();
1836 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1838 char * string = PrintHexUInt64(arg.expression.ui64);
1839 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1842 ProcessExpressionType(exp);
1843 ComputeExpression(exp);
1844 expString[0] = '\0';
1845 PrintExpression(exp, expString);
1846 strcat(argument, expString);
1848 FreeExpression(exp);
1853 strcat(argument, arg.member.name);
1856 case TemplateParameterType::type:
1858 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1859 strcat(argument, arg.dataTypeString);
1865 if(paramCount) strcat(templateString, ", ");
1866 if(lastParam != p - 1)
1868 strcat(templateString, param.name);
1869 strcat(templateString, " = ");
1871 strcat(templateString, argument);
1880 int len = strlen(templateString);
1881 if(templateString[len-1] == '<')
1885 if(templateString[len-1] == '>')
1886 templateString[len++] = ' ';
1887 templateString[len++] = '>';
1889 templateString[len++] = '\0';
1892 Context context = SetupTemplatesContext(_class);
1893 if(freeType) FreeType(type);
1894 type = ProcessTypeString(templateString, false);
1896 FinishTemplatesContext(context);
1900 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1902 ProcessExpressionType(member.initializer.exp);
1903 if(!member.initializer.exp.expType)
1907 char expString[10240];
1908 expString[0] = '\0';
1909 PrintExpression(member.initializer.exp, expString);
1910 ChangeCh(expString, '\n', ' ');
1911 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1914 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1915 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1917 Compiler_Error($"incompatible instance method %s\n", ident.string);
1920 else if(member.initializer)
1923 FreeType(member.exp.destType);
1924 member.exp.destType = type;
1925 if(member.exp.destType)
1926 member.exp.destType.refCount++;
1927 ProcessExpressionType(member.exp);
1930 ProcessInitializer(member.initializer, type);
1932 if(freeType) FreeType(type);
1936 if(_class && _class.type == unitClass)
1938 if(member.initializer)
1941 FreeType(member.exp.destType);
1942 member.exp.destType = MkClassType(_class.fullName);
1943 ProcessExpressionType(member.initializer, type);
1945 Type type = MkClassType(_class.fullName);
1946 ProcessInitializer(member.initializer, type);
1952 if(member.initializer)
1954 //ProcessExpressionType(member.exp);
1955 ProcessInitializer(member.initializer, null);
1961 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1965 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1967 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1971 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1976 void ProcessInstantiationType(Instantiation inst)
1981 MembersInit members;
1982 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1985 /*if(!inst._class.symbol)
1986 inst._class.symbol = FindClass(inst._class.name);*/
1987 classSym = inst._class.symbol;
1988 _class = classSym ? classSym.registered : null;
1990 // DANGER: Patch for mutex not declaring its struct when not needed
1991 if(!_class || _class.type != noHeadClass)
1992 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1994 afterExternal = afterExternal ? afterExternal : curExternal;
1997 ProcessExpressionType(inst.exp);
1999 inst.isConstant = true;
2002 DataMember curMember = null;
2003 Class curClass = null;
2004 DataMember subMemberStack[256];
2005 int subMemberStackPos = 0;
2007 for(members = inst.members->first; members; members = members.next)
2009 switch(members.type)
2011 case methodMembersInit:
2014 static uint instMethodID = 0;
2015 External external = curExternal;
2016 Context context = curContext;
2017 Declarator declarator = members.function.declarator;
2018 Identifier nameID = GetDeclId(declarator);
2019 char * unmangled = nameID ? nameID.string : null;
2021 External createdExternal = null;
2026 //members.function.dontMangle = true;
2027 strcpy(name, "__ecereInstMeth_");
2028 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2030 strcat(name, nameID.string);
2032 sprintf(number, "_%08d", instMethodID++);
2033 strcat(name, number);
2034 nameID.string = CopyString(name);
2037 // Do modifications here...
2040 Symbol symbol = declarator.symbol;
2041 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2043 if(method && method.type == virtualMethod)
2045 symbol.method = method;
2046 ProcessMethodType(method);
2048 if(!symbol.type.thisClass)
2050 if(method.dataType.thisClass && currentClass &&
2051 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2053 if(!currentClass.symbol)
2054 currentClass.symbol = FindClass(currentClass.fullName);
2055 symbol.type.thisClass = currentClass.symbol;
2060 _class.symbol = FindClass(_class.fullName);
2061 symbol.type.thisClass = _class.symbol;
2064 // TESTING THIS HERE:
2065 DeclareType(symbol.type, true, true);
2070 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2071 unmangled, classSym.string);
2075 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2076 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2080 FreeSpecifier(nameID._class);
2081 nameID._class = null;
2086 //Type type = declarator.symbol.type;
2087 External oldExternal = curExternal;
2089 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2090 // *** It was commented out for problems such as
2092 class VirtualDesktop : Window
2094 clientSize = Size { };
2105 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2107 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2110 if(strcmp(declarator.symbol.string, name))
2112 printf("TOCHECK: Look out for this\n");
2113 delete declarator.symbol.string;
2114 declarator.symbol.string = CopyString(name);
2117 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2119 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2120 excludedSymbols->Remove(declarator.symbol);
2121 globalContext.symbols.Add((BTNode)declarator.symbol);
2122 if(strstr(declarator.symbol.string), "::")
2123 globalContext.hasNameSpace = true;
2128 //curExternal = curExternal.prev;
2129 //afterExternal = afterExternal->next;
2131 //ProcessFunction(afterExternal->function);
2133 //curExternal = afterExternal;
2135 External externalDecl;
2136 externalDecl = MkExternalDeclaration(null);
2137 ast->Insert(oldExternal.prev, externalDecl);
2139 // Which function does this process?
2140 if(createdExternal.function)
2142 ProcessFunction(createdExternal.function);
2144 //curExternal = oldExternal;
2147 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2149 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2150 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2152 //externalDecl = MkExternalDeclaration(decl);
2154 //***** ast->Insert(external.prev, externalDecl);
2155 //ast->Insert(curExternal.prev, externalDecl);
2156 externalDecl.declaration = decl;
2157 if(decl.symbol && !decl.symbol.pointerExternal)
2158 decl.symbol.pointerExternal = externalDecl;
2160 // Trying this out...
2161 declarator.symbol.pointerExternal = externalDecl;
2168 curExternal = declarator.symbol.pointerExternal;
2169 ProcessFunction((FunctionDefinition)members.function);
2171 curExternal = external;
2172 curContext = context;
2176 FreeClassFunction(members.function);
2178 // In this pass, turn this into a MemberInitData
2179 exp = QMkExpId(name);
2180 members.type = dataMembersInit;
2181 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2187 case dataMembersInit:
2189 if(members.dataMembers && classSym)
2192 Location oldyyloc = yylloc;
2193 for(member = members.dataMembers->first; member; member = member.next)
2195 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2196 if(member.initializer && !member.initializer.isConstant)
2197 inst.isConstant = false;
2209 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2211 // OPTIMIZATIONS: TESTING THIS...
2214 if(type.kind == functionType)
2219 for(param = type.params.first; param; param = param.next)
2220 DeclareType(param, declarePointers, true);
2222 DeclareType(type.returnType, declarePointers, true);
2224 else if(type.kind == pointerType && declarePointers)
2225 DeclareType(type.type, declarePointers, false);
2226 else if(type.kind == classType)
2228 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2229 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2231 else if(type.kind == structType || type.kind == unionType)
2234 for(member = type.members.first; member; member = member.next)
2235 DeclareType(member, false, false);
2237 else if(type.kind == arrayType)
2238 DeclareType(type.arrayType, declarePointers, false);
2242 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2244 ClassTemplateArgument * arg = null;
2246 ClassTemplateParameter curParam = null;
2248 for(sClass = _class; sClass; sClass = sClass.base)
2251 if(sClass.templateClass) sClass = sClass.templateClass;
2252 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2254 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2256 for(sClass = sClass.base; sClass; sClass = sClass.base)
2258 if(sClass.templateClass) sClass = sClass.templateClass;
2259 id += sClass.templateParams.count;
2269 arg = &_class.templateArgs[id];
2270 if(arg && param.type == type)
2271 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2276 public Context SetupTemplatesContext(Class _class)
2278 Context context = PushContext();
2279 context.templateTypesOnly = true;
2280 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2282 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2283 for(; param; param = param.next)
2285 if(param.type == type && param.identifier)
2287 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2288 curContext.templateTypes.Add((BTNode)type);
2295 for(sClass = _class; sClass; sClass = sClass.base)
2297 ClassTemplateParameter p;
2298 for(p = sClass.templateParams.first; p; p = p.next)
2300 //OldList * specs = MkList();
2301 //Declarator decl = null;
2302 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2305 TemplateParameter param = p.param;
2309 // ADD DATA TYPE HERE...
2310 p.param = param = TemplateParameter
2312 identifier = MkIdentifier(p.name), type = p.type,
2313 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2316 type = TemplatedType { key = (uintptr)p.name, param = param };
2317 curContext.templateTypes.Add((BTNode)type);
2325 public void FinishTemplatesContext(Context context)
2327 PopContext(context);
2328 FreeContext(context);
2332 public void ProcessMethodType(Method method)
2334 if(!method.dataType)
2336 Context context = SetupTemplatesContext(method._class);
2338 method.dataType = ProcessTypeString(method.dataTypeString, false);
2340 FinishTemplatesContext(context);
2342 if(method.type != virtualMethod && method.dataType)
2344 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2346 if(!method._class.symbol)
2347 method._class.symbol = FindClass(method._class.fullName);
2348 method.dataType.thisClass = method._class.symbol;
2352 // Why was this commented out? Working fine without now...
2355 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2356 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2363 char * par = strstr(type, "(");
2364 char * classOp = null;
2369 for(c = par-type-1; c >= 0; c++)
2371 if(type[c] == ':' && type[c+1] == ':')
2373 classOp = type + c - 1;
2374 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2381 else if(!isspace(type[c]))
2388 int typeLen = strlen(type);
2389 memcpy(temp, classOp, classOpLen);
2390 temp[classOpLen] = '\0';
2392 _class = eSystem_FindClass(module, temp);
2395 method.dataTypeString = new char[typeLen - classOpLen + 1];
2396 memcpy(method.dataTypeString, type, classOp - type);
2397 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2400 method.dataTypeString = type;
2406 public void ProcessPropertyType(Property prop)
2410 Context context = SetupTemplatesContext(prop._class);
2411 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2412 FinishTemplatesContext(context);
2416 public void DeclareMethod(Method method, const char * name)
2418 Symbol symbol = method.symbol;
2419 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2421 bool imported = false;
2422 bool dllImport = false;
2424 if(!method.dataType)
2425 method.dataType = ProcessTypeString(method.dataTypeString, false);
2427 if(!symbol || symbol._import || method.type == virtualMethod)
2429 if(!symbol || method.type == virtualMethod)
2432 if(!method._class.symbol)
2433 method._class.symbol = FindClass(method._class.fullName);
2434 classSym = method._class.symbol;
2435 if(!classSym._import)
2437 ModuleImport module;
2439 if(method._class.module && method._class.module.name)
2440 module = FindModule(method._class.module);
2442 module = mainModule;
2443 classSym._import = ClassImport
2445 name = CopyString(method._class.fullName);
2446 isRemote = method._class.isRemote;
2448 module.classes.Add(classSym._import);
2452 symbol = method.symbol = Symbol { };
2456 symbol._import = (ClassImport)MethodImport
2458 name = CopyString(method.name);
2459 isVirtual = method.type == virtualMethod;
2461 classSym._import.methods.Add(symbol._import);
2465 // Set the symbol type
2469 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2471 else if(type.thisClass == (void *)-1)
2473 type.thisClass = null;
2476 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2477 symbol.type = method.dataType;
2478 if(symbol.type) symbol.type.refCount++;
2481 if(!method.thisClass || strcmp(method.thisClass, "void"))
2482 symbol.type.params.Insert(null,
2483 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2486 if(!method.dataType.dllExport)
2489 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2495 if(!method.dataType)
2496 method.dataType = ((Symbol)method.symbol).type;
2497 //ProcessMethodType(method);
2500 if(method.type != virtualMethod && method.dataType)
2501 DeclareType(method.dataType, true, true);
2503 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2505 // We need a declaration here :)
2507 OldList * specifiers, * declarators;
2509 Declarator funcDecl;
2512 specifiers = MkList();
2513 declarators = MkList();
2517 ListAdd(specifiers, MkSpecifier(EXTERN));
2518 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2519 ListAdd(specifiers, MkSpecifier(STATIC));
2521 if(method.type == virtualMethod)
2523 ListAdd(specifiers, MkSpecifier(INT));
2524 d = MkDeclaratorIdentifier(MkIdentifier(name));
2528 d = MkDeclaratorIdentifier(MkIdentifier(name));
2531 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2533 Context context = SetupTemplatesContext(method._class);
2534 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2535 FinishTemplatesContext(context);
2537 funcDecl = GetFuncDecl(d);
2541 Specifier spec, next;
2542 for(spec = specifiers->first; spec; spec = next)
2545 if(spec.type == extendedSpecifier)
2547 specifiers->Remove(spec);
2548 FreeSpecifier(spec);
2553 // Add this parameter if not a static method
2554 if(method.dataType && !method.dataType.staticMethod)
2556 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2558 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2559 TypeName thisParam = MkTypeName(MkListOne(
2560 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2561 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2562 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2563 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2565 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2567 TypeName param = funcDecl.function.parameters->first;
2568 funcDecl.function.parameters->Remove(param);
2569 FreeTypeName(param);
2572 if(!funcDecl.function.parameters)
2573 funcDecl.function.parameters = MkList();
2574 funcDecl.function.parameters->Insert(null, thisParam);
2577 // Make sure we don't have empty parameter declarations for static methods...
2579 else if(!funcDecl.function.parameters)
2581 funcDecl.function.parameters = MkList();
2582 funcDecl.function.parameters->Insert(null,
2583 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2587 ProcessDeclarator(d);
2589 ListAdd(declarators, MkInitDeclarator(d, null));
2591 decl = MkDeclaration(specifiers, declarators);
2593 ReplaceThisClassSpecifiers(specifiers, method._class);
2595 // Keep a different symbol for the function definition than the declaration...
2596 if(symbol.pointerExternal)
2598 Symbol functionSymbol { };
2602 *functionSymbol = *symbol;
2603 functionSymbol.string = CopyString(symbol.string);
2604 if(functionSymbol.type)
2605 functionSymbol.type.refCount++;
2608 excludedSymbols->Add(functionSymbol);
2609 symbol.pointerExternal.symbol = functionSymbol;
2611 external = MkExternalDeclaration(decl);
2613 ast->Insert(curExternal ? curExternal.prev : null, external);
2614 external.symbol = symbol;
2615 symbol.pointerExternal = external;
2619 // Move declaration higher...
2620 ast->Move(symbol.pointerExternal, curExternal.prev);
2623 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2627 char * ReplaceThisClass(Class _class)
2629 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2633 ClassTemplateParameter param;
2636 char className[1024];
2637 strcpy(className, _class.fullName);
2638 for(param = _class.templateParams.first; param; param = param.next)
2640 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2642 if(first) strcat(className, "<");
2643 if(!first) strcat(className, ", ");
2644 if(lastParam + 1 != p)
2646 strcat(className, param.name);
2647 strcat(className, " = ");
2649 strcat(className, param.name);
2657 int len = strlen(className);
2658 if(className[len-1] == '>') className[len++] = ' ';
2659 className[len++] = '>';
2660 className[len++] = '\0';
2662 return CopyString(className);
2665 return CopyString(_class.fullName);
2668 Type ReplaceThisClassType(Class _class)
2670 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2674 ClassTemplateParameter param;
2676 char className[1024];
2677 strcpy(className, _class.fullName);
2679 for(param = _class.templateParams.first; param; param = param.next)
2681 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2683 if(first) strcat(className, "<");
2684 if(!first) strcat(className, ", ");
2685 if(lastParam + 1 != p)
2687 strcat(className, param.name);
2688 strcat(className, " = ");
2690 strcat(className, param.name);
2698 int len = strlen(className);
2699 if(className[len-1] == '>') className[len++] = ' ';
2700 className[len++] = '>';
2701 className[len++] = '\0';
2703 return MkClassType(className);
2704 //return ProcessTypeString(className, false);
2708 return MkClassType(_class.fullName);
2709 //return ProcessTypeString(_class.fullName, false);
2713 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2715 if(specs != null && _class)
2718 for(spec = specs.first; spec; spec = spec.next)
2720 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2722 spec.type = nameSpecifier;
2723 spec.name = ReplaceThisClass(_class);
2724 spec.symbol = FindClass(spec.name); //_class.symbol;
2730 // Returns imported or not
2731 bool DeclareFunction(GlobalFunction function, char * name)
2733 Symbol symbol = function.symbol;
2734 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2736 bool imported = false;
2737 bool dllImport = false;
2739 if(!function.dataType)
2741 function.dataType = ProcessTypeString(function.dataTypeString, false);
2742 if(!function.dataType.thisClass)
2743 function.dataType.staticMethod = true;
2750 ModuleImport module = FindModule(function.module);
2751 // WARNING: This is not added anywhere...
2752 symbol = function.symbol = Symbol { };
2756 if(!function.dataType.dllExport)
2758 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2759 module.functions.Add(symbol._import);
2762 // Set the symbol type
2764 symbol.type = ProcessTypeString(function.dataTypeString, false);
2765 if(!symbol.type.thisClass)
2766 symbol.type.staticMethod = true;
2769 imported = symbol._import ? true : false;
2770 if(imported && function.module != privateModule && function.module.importType != staticImport)
2774 DeclareType(function.dataType, true, true);
2778 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2780 // We need a declaration here :)
2782 OldList * specifiers, * declarators;
2784 Declarator funcDecl;
2787 specifiers = MkList();
2788 declarators = MkList();
2791 ListAdd(specifiers, MkSpecifier(EXTERN));
2794 ListAdd(specifiers, MkSpecifier(STATIC));
2797 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2800 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2802 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2803 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2804 if(function.module.importType == staticImport)
2807 for(spec = specifiers->first; spec; spec = spec.next)
2808 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2810 specifiers->Remove(spec);
2811 FreeSpecifier(spec);
2816 funcDecl = GetFuncDecl(d);
2818 // Make sure we don't have empty parameter declarations for static methods...
2819 if(funcDecl && !funcDecl.function.parameters)
2821 funcDecl.function.parameters = MkList();
2822 funcDecl.function.parameters->Insert(null,
2823 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2826 ListAdd(declarators, MkInitDeclarator(d, null));
2829 Context oldCtx = curContext;
2830 curContext = globalContext;
2831 decl = MkDeclaration(specifiers, declarators);
2832 curContext = oldCtx;
2835 // Keep a different symbol for the function definition than the declaration...
2836 if(symbol.pointerExternal)
2838 Symbol functionSymbol { };
2841 *functionSymbol = *symbol;
2842 functionSymbol.string = CopyString(symbol.string);
2843 if(functionSymbol.type)
2844 functionSymbol.type.refCount++;
2847 excludedSymbols->Add(functionSymbol);
2849 symbol.pointerExternal.symbol = functionSymbol;
2851 external = MkExternalDeclaration(decl);
2853 ast->Insert(curExternal.prev, external);
2854 external.symbol = symbol;
2855 symbol.pointerExternal = external;
2859 // Move declaration higher...
2860 ast->Move(symbol.pointerExternal, curExternal.prev);
2864 symbol.id = curExternal.symbol.idCode;
2867 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2870 void DeclareGlobalData(GlobalData data)
2872 Symbol symbol = data.symbol;
2873 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2878 symbol = data.symbol = Symbol { };
2881 data.dataType = ProcessTypeString(data.dataTypeString, false);
2882 DeclareType(data.dataType, true, true);
2885 if(!symbol.pointerExternal)
2887 // We need a declaration here :)
2889 OldList * specifiers, * declarators;
2893 specifiers = MkList();
2894 declarators = MkList();
2896 ListAdd(specifiers, MkSpecifier(EXTERN));
2897 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2898 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2900 ListAdd(declarators, MkInitDeclarator(d, null));
2902 decl = MkDeclaration(specifiers, declarators);
2903 external = MkExternalDeclaration(decl);
2905 ast->Insert(curExternal.prev, external);
2906 external.symbol = symbol;
2907 symbol.pointerExternal = external;
2911 // Move declaration higher...
2912 ast->Move(symbol.pointerExternal, curExternal.prev);
2916 symbol.id = curExternal.symbol.idCode;
2921 class Conversion : struct
2923 Conversion prev, next;
2929 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2932 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2933 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2935 Class sourceClass = source.kind == classType ? source._class.registered : null;
2936 Class destClass = dest.kind == classType ? dest._class.registered : null;
2937 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
2938 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
2940 Type sourceType = source, destType = dest;
2941 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
2942 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
2943 if(!destType.constant && sourceType.constant)
2947 Compiler_Warning($"discarding const qualifier\n");
2954 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
2955 bool isConversionExploration, bool warnConst)
2960 CheckConstCompatibility(source, dest, true);
2961 // Property convert;
2963 if(source.kind == templateType && dest.kind != templateType)
2965 Type type = ProcessTemplateParameterType(source.templateParameter);
2966 if(type) source = type;
2969 if(dest.kind == templateType && source.kind != templateType)
2971 Type type = ProcessTemplateParameterType(dest.templateParameter);
2972 if(type) dest = type;
2975 if(dest.classObjectType == typedObject && dest.kind != functionType)
2977 if(source.classObjectType != anyObject)
2981 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2982 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2990 if(source.kind != functionType && source.classObjectType == anyObject)
2992 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
2996 if((dest.kind == structType && source.kind == structType) ||
2997 (dest.kind == unionType && source.kind == unionType))
2999 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
3000 (source.members.first && source.members.first == dest.members.first))
3004 if(dest.kind == ellipsisType && source.kind != voidType)
3007 if(dest.kind == pointerType && dest.type.kind == voidType &&
3008 ((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))
3009 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
3011 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
3013 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
3015 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
3016 ((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))
3017 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
3018 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
3020 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
3023 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
3025 if(source._class.registered && source._class.registered.type == unitClass)
3027 if(conversions != null)
3029 if(source._class.registered == dest._class.registered)
3034 Class sourceBase, destBase;
3035 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
3036 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
3037 if(sourceBase == destBase)
3041 // Don't match enum inheriting from other enum if resolving enumeration values
3042 // TESTING: !dest.classObjectType
3043 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3045 (!source._class.registered || source._class.registered.type != enumClass) ||
3046 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3050 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3052 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3053 ((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)
3055 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3063 // JUST ADDED THIS...
3064 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3069 // Just added this for Straight conversion of ColorAlpha => Color
3070 if(source.kind == classType)
3073 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3076 for(convert = _class.conversions.first; convert; convert = convert.next)
3078 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3080 Conversion after = (conversions != null) ? conversions.last : null;
3082 if(!convert.dataType)
3083 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3084 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3085 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3086 MatchTypes(convert.dataType, dest, conversions, null, null,
3087 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3088 convert.dataType.kind == classType, false, true, warnConst))
3090 if(!conversions && !convert.Get)
3092 else if(conversions != null)
3094 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3095 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3096 (dest.kind != classType || dest._class.registered != _class.base))
3100 Conversion conv { convert = convert, isGet = true };
3101 // conversions.Add(conv);
3102 conversions.Insert(after, conv);
3115 if(dest.kind == classType)
3118 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3121 for(convert = _class.conversions.first; convert; convert = convert.next)
3123 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3125 Type constType = null;
3126 bool success = false;
3127 // Conversion after = (conversions != null) ? conversions.last : null;
3129 if(!convert.dataType)
3130 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3132 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3135 constType = { kind = pointerType, refCount = 1, type = ptrType };
3136 CopyTypeInto(ptrType, convert.dataType.type);
3138 ptrType.constant = true;
3141 // Just added this equality check to prevent recursion.... Make it safer?
3142 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3143 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3145 if(!conversions && !convert.Set)
3147 else if(conversions != null)
3149 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3150 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3151 (source.kind != classType || source._class.registered != _class.base))
3155 // *** Testing this! ***
3156 Conversion conv { convert = convert };
3157 conversions.Add(conv);
3158 //conversions.Insert(after, conv);
3166 FreeType(constType);
3170 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3172 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3173 (source.kind != classType || source._class.registered.type != structClass))
3177 // TESTING THIS... IS THIS OK??
3178 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3180 if(!dest._class.registered.dataType)
3181 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3182 // Only support this for classes...
3183 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3184 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3186 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3195 if(source.kind == classType)
3198 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3201 for(convert = _class.conversions.first; convert; convert = convert.next)
3203 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3205 Conversion after = (conversions != null) ? conversions.last : null;
3207 if(!convert.dataType)
3208 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3209 if(convert.dataType != source &&
3210 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3211 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3213 if(!conversions && !convert.Get)
3215 else if(conversions != null)
3217 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3218 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3219 (dest.kind != classType || dest._class.registered != _class.base))
3223 Conversion conv { convert = convert, isGet = true };
3225 // conversions.Add(conv);
3226 conversions.Insert(after, conv);
3235 // TESTING THIS... IS THIS OK??
3236 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3238 if(!source._class.registered.dataType)
3239 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3240 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3242 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))
3244 // For bool to be accepted by byte, short, etc.
3245 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3252 if(source.kind == classType || source.kind == subClassType)
3254 else if(dest.kind == source.kind &&
3255 (dest.kind != structType && dest.kind != unionType &&
3256 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3258 // RECENTLY ADDED THESE
3259 else if(dest.kind == doubleType && source.kind == floatType)
3261 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3263 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3265 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3267 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3269 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3271 else if(source.kind == enumType &&
3272 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3274 else if(dest.kind == enumType && !isConversionExploration &&
3275 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3277 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3278 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3280 Type paramSource, paramDest;
3282 if(dest.kind == methodType)
3283 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3284 if(source.kind == methodType)
3285 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3287 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3288 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3289 if(dest.kind == methodType)
3290 dest = dest.method.dataType;
3291 if(source.kind == methodType)
3292 source = source.method.dataType;
3294 paramSource = source.params.first;
3295 if(paramSource && paramSource.kind == voidType) paramSource = null;
3296 paramDest = dest.params.first;
3297 if(paramDest && paramDest.kind == voidType) paramDest = null;
3300 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3301 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3303 // Source thisClass must be derived from destination thisClass
3304 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3305 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3307 if(paramDest && paramDest.kind == classType)
3308 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3310 Compiler_Error($"method class should not take an object\n");
3313 paramDest = paramDest.next;
3315 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3317 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3321 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3323 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3329 // THIS WAS BACKWARDS:
3330 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3331 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3334 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3336 Compiler_Error($"overriding class expected to be derived from method class\n");
3340 paramSource = paramSource.next;
3346 // Source thisClass must be derived from destination thisClass
3347 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3349 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3355 // THIS WAS BACKWARDS TOO??
3356 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3357 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3360 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3362 //Compiler_Error($"overriding class expected to be derived from method class\n");
3370 // Source return type must be derived from destination return type
3371 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3373 Compiler_Warning($"incompatible return type for function\n");
3376 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3378 CheckConstCompatibility(dest.returnType, source.returnType, true);
3382 for(; paramDest; paramDest = paramDest.next)
3386 //Compiler_Warning($"not enough parameters\n");
3387 Compiler_Error($"not enough parameters\n");
3391 Type paramDestType = paramDest;
3392 Type paramSourceType = paramSource;
3393 Type type = paramDestType;
3395 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3396 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3397 paramSource.kind != templateType)
3400 ClassTemplateParameter curParam = null;
3402 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3405 if(sClass.templateClass) sClass = sClass.templateClass;
3406 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3408 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3410 for(sClass = sClass.base; sClass; sClass = sClass.base)
3412 if(sClass.templateClass) sClass = sClass.templateClass;
3413 id += sClass.templateParams.count;
3424 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3425 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3429 // paramDest must be derived from paramSource
3430 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3431 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3435 PrintType(paramDest, type, false, true);
3436 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3438 if(paramDestType != paramDest)
3439 FreeType(paramDestType);
3442 if(paramDestType != paramDest)
3443 FreeType(paramDestType);
3446 paramSource = paramSource.next;
3450 Compiler_Error($"too many parameters\n");
3455 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3459 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3460 (source.kind == arrayType || source.kind == pointerType))
3462 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3469 static void FreeConvert(Conversion convert)
3471 if(convert.resultType)
3472 FreeType(convert.resultType);
3475 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3476 char * string, OldList conversions)
3480 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3482 Class _class = link.data;
3483 if(_class.type == enumClass)
3485 OldList converts { };
3487 type.kind = classType;
3490 _class.symbol = FindClass(_class.fullName);
3491 type._class = _class.symbol;
3493 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false, false))
3496 Class enumClass = eSystem_FindClass(privateModule, "enum");
3500 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3502 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3503 for(value = e.values.first; value; value = value.next)
3505 if(!strcmp(value.name, string))
3510 FreeExpContents(sourceExp);
3511 FreeType(sourceExp.expType);
3513 sourceExp.isConstant = true;
3514 sourceExp.expType = MkClassType(baseClass.fullName);
3518 sourceExp.type = constantExp;
3519 if(!strcmp(baseClass.dataTypeString, "int"))
3520 sprintf(constant, "%d",(int)value.data);
3522 sprintf(constant, "0x%X",(int)value.data);
3523 sourceExp.constant = CopyString(constant);
3524 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3527 while(converts.first)
3529 Conversion convert = converts.first;
3530 converts.Remove(convert);
3531 conversions.Add(convert);
3540 converts.Free(FreeConvert);
3544 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3545 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3550 public bool ModuleVisibility(Module searchIn, Module searchFor)
3552 SubModule subModule;
3554 if(searchFor == searchIn)
3557 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3559 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3561 if(ModuleVisibility(subModule.module, searchFor))
3568 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3572 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3574 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3576 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3579 for(module = mainModule.application.allModules.first; module; module = module.next)
3581 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3587 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3590 Type realDest = dest;
3591 Type backupSourceExpType = null;
3592 Expression computedExp = sourceExp;
3595 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3596 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3598 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3599 ComputeExpression(computedExp /*sourceExp*/);
3602 source = sourceExp.expType;
3604 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3606 if(computedExp != sourceExp)
3608 FreeExpression(computedExp);
3609 computedExp = sourceExp;
3615 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3617 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3619 Class sourceBase, destBase;
3620 for(sourceBase = source._class.registered;
3621 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3622 sourceBase = sourceBase.base);
3623 for(destBase = dest._class.registered;
3624 destBase && destBase.base && destBase.base.type != systemClass;
3625 destBase = destBase.base);
3626 //if(source._class.registered == dest._class.registered)
3627 if(sourceBase == destBase)
3629 if(computedExp != sourceExp)
3631 FreeExpression(computedExp);
3632 computedExp = sourceExp;
3644 int64 value = MAXINT;
3648 if(computedExp.type == constantExp)
3651 value = strtoll(computedExp.constant, null, 0);
3653 value = strtoull(computedExp.constant, null, 0);
3655 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3658 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3660 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3662 if(computedExp != sourceExp)
3664 FreeExpression(computedExp);
3665 computedExp = sourceExp;
3668 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3669 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3672 source = Type { kind = intType, isSigned = false, refCount = 1 };
3675 if(dest.kind == classType)
3677 Class _class = dest._class ? dest._class.registered : null;
3679 if(_class && _class.type == unitClass)
3681 if(source.kind != classType)
3684 Type tempDest, tempSource;
3686 for(; _class.base.type != systemClass; _class = _class.base);
3688 tempDest = tempType;
3690 tempType.kind = classType;
3692 _class.symbol = FindClass(_class.fullName);
3694 tempType._class = _class.symbol;
3695 tempType.truth = dest.truth;
3697 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3699 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3700 backupSourceExpType = sourceExp.expType;
3701 sourceExp.expType = dest; dest.refCount++;
3702 //sourceExp.expType = MkClassType(_class.fullName);
3710 // Why wasn't there something like this?
3711 if(_class && _class.type == bitClass && source.kind != classType)
3713 if(!dest._class.registered.dataType)
3714 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3715 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3718 FreeType(sourceExp.expType);
3719 source = sourceExp.expType = MkClassType(dest._class.string);
3722 //source.kind = classType;
3723 //source._class = dest._class;
3727 // Adding two enumerations
3729 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3731 if(!source._class.registered.dataType)
3732 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3733 if(!dest._class.registered.dataType)
3734 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3736 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3739 source = sourceExp.expType = MkClassType(dest._class.string);
3742 //source.kind = classType;
3743 //source._class = dest._class;
3747 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3749 OldList * specs = MkList();
3753 ReadString(string, sourceExp.string);
3754 decl = SpecDeclFromString(string, specs, null);
3756 FreeExpContents(sourceExp);
3757 FreeType(sourceExp.expType);
3759 sourceExp.type = classExp;
3760 sourceExp._classExp.specifiers = specs;
3761 sourceExp._classExp.decl = decl;
3762 sourceExp.expType = dest;
3767 if(backupSourceExpType) FreeType(backupSourceExpType);
3771 else if(source.kind == classType)
3773 Class _class = source._class ? source._class.registered : null;
3775 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3778 if(dest.kind != classType)
3780 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3781 if(!source._class.registered.dataType)
3782 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3785 dest = MkClassType(source._class.string);
3786 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3787 // dest = MkClassType(source._class.string);
3791 if(dest.kind != classType)
3794 Type tempDest, tempSource;
3796 if(!source._class.registered.dataType)
3797 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3799 for(; _class.base.type != systemClass; _class = _class.base);
3801 tempSource = tempType;
3802 tempType.kind = classType;
3803 tempType._class = FindClass(_class.fullName);
3804 tempType.truth = source.truth;
3805 tempType.classObjectType = source.classObjectType;
3808 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3810 // PUT THIS BACK TESTING UNITS?
3811 if(conversions.last)
3813 ((Conversion)(conversions.last)).resultType = dest;
3817 FreeType(sourceExp.expType);
3818 sourceExp.expType = MkClassType(_class.fullName);
3819 sourceExp.expType.truth = source.truth;
3820 sourceExp.expType.classObjectType = source.classObjectType;
3822 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3824 if(!sourceExp.destType)
3826 FreeType(sourceExp.destType);
3827 sourceExp.destType = sourceExp.expType;
3828 if(sourceExp.expType)
3829 sourceExp.expType.refCount++;
3832 //source = _class.dataType;
3835 // TOCHECK: TESTING THIS NEW CODE
3836 if(!_class.dataType)
3837 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3839 dest = MkClassType(source._class.string);
3840 dest.truth = source.truth;
3841 dest.classObjectType = source.classObjectType;
3844 source = _class.dataType;
3854 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3864 if(source.kind == classType)
3866 Class _class = source._class.registered;
3867 if(_class.type == unitClass)
3869 if(!_class.dataType)
3870 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3871 source = _class.dataType;
3875 if(dest.kind == classType)
3877 Class _class = dest._class ? dest._class.registered : null;
3878 bool fittingValue = false;
3879 if(_class && _class.type == enumClass)
3881 Class enumClass = eSystem_FindClass(privateModule, "enum");
3882 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3883 if(c && value >= 0 && value <= c.largest)
3884 fittingValue = true;
3887 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3888 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3890 if(_class.type == normalClass || _class.type == noHeadClass)
3892 Expression newExp { };
3893 *newExp = *sourceExp;
3894 if(sourceExp.destType) sourceExp.destType.refCount++;
3895 if(sourceExp.expType) sourceExp.expType.refCount++;
3896 sourceExp.type = castExp;
3897 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3898 sourceExp.cast.exp = newExp;
3899 FreeType(sourceExp.expType);
3900 sourceExp.expType = null;
3901 ProcessExpressionType(sourceExp);
3903 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3906 FreeType(sourceExp.expType);
3907 sourceExp.expType = dest;
3911 if(inCompiler) FreeType(dest);
3913 if(backupSourceExpType) FreeType(backupSourceExpType);
3917 if(!_class.dataType)
3918 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3920 dest = _class.dataType;
3924 // Accept lower precision types for units, since we want to keep the unit type
3925 if(dest.kind == doubleType &&
3926 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3927 source.kind == charType || source.kind == _BoolType))
3929 specs = MkListOne(MkSpecifier(DOUBLE));
3931 else if(dest.kind == floatType &&
3932 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3933 source.kind == _BoolType || source.kind == doubleType))
3935 specs = MkListOne(MkSpecifier(FLOAT));
3937 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3938 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3941 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3942 ListAdd(specs, MkSpecifier(INT64));
3944 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3945 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3948 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3949 ListAdd(specs, MkSpecifier(INT));
3951 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3952 source.kind == floatType || source.kind == doubleType))
3955 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3956 ListAdd(specs, MkSpecifier(SHORT));
3958 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3959 source.kind == floatType || source.kind == doubleType))
3962 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3963 ListAdd(specs, MkSpecifier(CHAR));
3969 if(backupSourceExpType)
3971 // Failed to convert: revert previous exp type
3972 if(sourceExp.expType) FreeType(sourceExp.expType);
3973 sourceExp.expType = backupSourceExpType;
3978 else if(dest.kind == doubleType &&
3979 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3980 source.kind == _BoolType || source.kind == charType))
3982 specs = MkListOne(MkSpecifier(DOUBLE));
3984 else if(dest.kind == floatType &&
3985 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3987 specs = MkListOne(MkSpecifier(FLOAT));
3989 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3990 (value == 1 || value == 0))
3993 ListAdd(specs, MkSpecifier(BOOL));
3995 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3996 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3999 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4000 ListAdd(specs, MkSpecifier(CHAR));
4002 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
4003 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
4006 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4007 ListAdd(specs, MkSpecifier(SHORT));
4009 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
4012 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4013 ListAdd(specs, MkSpecifier(INT));
4015 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
4018 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4019 ListAdd(specs, MkSpecifier(INT64));
4021 else if(dest.kind == enumType &&
4022 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4024 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4030 if(backupSourceExpType)
4032 // Failed to convert: revert previous exp type
4033 if(sourceExp.expType) FreeType(sourceExp.expType);
4034 sourceExp.expType = backupSourceExpType;
4039 if(!flag && !sourceExp.opDestType)
4041 Expression newExp { };
4042 *newExp = *sourceExp;
4045 if(sourceExp.destType) sourceExp.destType.refCount++;
4046 if(sourceExp.expType) sourceExp.expType.refCount++;
4048 sourceExp.type = castExp;
4049 if(realDest.kind == classType)
4051 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4052 FreeList(specs, FreeSpecifier);
4055 sourceExp.cast.typeName = MkTypeName(specs, null);
4056 if(newExp.type == opExp)
4058 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4061 sourceExp.cast.exp = newExp;
4063 FreeType(sourceExp.expType);
4064 sourceExp.expType = null;
4065 ProcessExpressionType(sourceExp);
4068 FreeList(specs, FreeSpecifier);
4072 if(backupSourceExpType) FreeType(backupSourceExpType);
4078 if(computedExp != sourceExp)
4080 FreeExpression(computedExp);
4081 computedExp = sourceExp;
4084 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4085 if(sourceExp.type == identifierExp)
4087 Identifier id = sourceExp.identifier;
4088 if(dest.kind == classType)
4090 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4092 Class _class = dest._class.registered;
4093 Class enumClass = eSystem_FindClass(privateModule, "enum");
4096 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4099 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4100 for(value = e.values.first; value; value = value.next)
4102 if(!strcmp(value.name, id.string))
4107 FreeExpContents(sourceExp);
4108 FreeType(sourceExp.expType);
4110 sourceExp.isConstant = true;
4111 sourceExp.expType = MkClassType(_class.fullName);
4115 sourceExp.type = constantExp;
4116 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
4117 sprintf(constant, "%d", (int) value.data);
4119 sprintf(constant, "0x%X", (int) value.data);
4120 sourceExp.constant = CopyString(constant);
4121 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4131 // Loop through all enum classes
4132 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4143 #define TERTIARY(o, name, m, t, p) \
4144 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4146 exp.type = constantExp; \
4147 exp.string = p(op1.m ? op2.m : op3.m); \
4149 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4153 #define BINARY(o, name, m, t, p) \
4154 static bool name(Expression exp, Operand op1, Operand op2) \
4157 exp.type = constantExp; \
4158 exp.string = p((t)(op1.m o value2)); \
4160 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4164 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4165 static bool name(Expression exp, Operand op1, Operand op2) \
4168 exp.type = constantExp; \
4169 exp.string = p(value2 ? (op1.m o value2) : 0); \
4171 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4175 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4176 static bool name(Expression exp, Operand op1, Operand op2) \
4179 exp.type = constantExp; \
4180 exp.string = p(op1.m o value2); \
4182 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4186 #define UNARY(o, name, m, t, p) \
4187 static bool name(Expression exp, Operand op1) \
4189 exp.type = constantExp; \
4190 exp.string = p((t)(o op1.m)); \
4192 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4196 #define OPERATOR_ALL(macro, o, name) \
4197 macro(o, Int##name, i, int, PrintInt) \
4198 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4199 macro(o, Int64##name, i64, int64, PrintInt64) \
4200 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4201 macro(o, Short##name, s, short, PrintShort) \
4202 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4203 macro(o, Char##name, c, char, PrintChar) \
4204 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4205 macro(o, Float##name, f, float, PrintFloat) \
4206 macro(o, Double##name, d, double, PrintDouble)
4208 #define OPERATOR_INTTYPES(macro, o, name) \
4209 macro(o, Int##name, i, int, PrintInt) \
4210 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4211 macro(o, Int64##name, i64, int64, PrintInt64) \
4212 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4213 macro(o, Short##name, s, short, PrintShort) \
4214 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4215 macro(o, Char##name, c, char, PrintChar) \
4216 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4218 #define OPERATOR_REALTYPES(macro, o, name) \
4219 macro(o, Float##name, f, float, PrintFloat) \
4220 macro(o, Double##name, d, double, PrintDouble)
4222 // binary arithmetic
4223 OPERATOR_ALL(BINARY, +, Add)
4224 OPERATOR_ALL(BINARY, -, Sub)
4225 OPERATOR_ALL(BINARY, *, Mul)
4226 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4227 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4228 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4231 OPERATOR_ALL(UNARY, -, Neg)
4233 // unary arithmetic increment and decrement
4234 OPERATOR_ALL(UNARY, ++, Inc)
4235 OPERATOR_ALL(UNARY, --, Dec)
4237 // binary arithmetic assignment
4238 OPERATOR_ALL(BINARY, =, Asign)
4239 OPERATOR_ALL(BINARY, +=, AddAsign)
4240 OPERATOR_ALL(BINARY, -=, SubAsign)
4241 OPERATOR_ALL(BINARY, *=, MulAsign)
4242 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4243 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4244 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4247 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4248 OPERATOR_INTTYPES(BINARY, |, BitOr)
4249 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4250 OPERATOR_INTTYPES(BINARY, <<, LShift)
4251 OPERATOR_INTTYPES(BINARY, >>, RShift)
4254 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4256 // binary bitwise assignment
4257 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4258 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4259 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4260 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4261 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4263 // unary logical negation
4264 OPERATOR_INTTYPES(UNARY, !, Not)
4266 // binary logical equality
4267 OPERATOR_ALL(BINARY, ==, Equ)
4268 OPERATOR_ALL(BINARY, !=, Nqu)
4271 OPERATOR_ALL(BINARY, &&, And)
4272 OPERATOR_ALL(BINARY, ||, Or)
4274 // binary logical relational
4275 OPERATOR_ALL(BINARY, >, Grt)
4276 OPERATOR_ALL(BINARY, <, Sma)
4277 OPERATOR_ALL(BINARY, >=, GrtEqu)
4278 OPERATOR_ALL(BINARY, <=, SmaEqu)
4280 // tertiary condition operator
4281 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4283 //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
4284 #define OPERATOR_TABLE_ALL(name, type) \
4285 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4287 type##Inc, type##Dec, \
4288 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4289 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4291 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4293 type##Equ, type##Nqu, \
4294 type##And, type##Or, \
4295 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4298 #define OPERATOR_TABLE_INTTYPES(name, type) \
4299 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4301 type##Inc, type##Dec, \
4302 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4303 null, null, null, null, null, \
4305 null, null, null, null, null, \
4307 type##Equ, type##Nqu, \
4308 type##And, type##Or, \
4309 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4312 OPERATOR_TABLE_ALL(int, Int)
4313 OPERATOR_TABLE_ALL(uint, UInt)
4314 OPERATOR_TABLE_ALL(int64, Int64)
4315 OPERATOR_TABLE_ALL(uint64, UInt64)
4316 OPERATOR_TABLE_ALL(short, Short)
4317 OPERATOR_TABLE_ALL(ushort, UShort)
4318 OPERATOR_TABLE_INTTYPES(float, Float)
4319 OPERATOR_TABLE_INTTYPES(double, Double)
4320 OPERATOR_TABLE_ALL(char, Char)
4321 OPERATOR_TABLE_ALL(uchar, UChar)
4323 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4324 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4325 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4326 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4327 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4328 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4329 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4330 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4332 public void ReadString(char * output, char * string)
4334 int len = strlen(string);
4336 bool quoted = false, escaped = false;
4337 for(c = 0; c<len; c++)
4339 char ch = string[c];
4344 case 'n': output[d] = '\n'; break;
4345 case 't': output[d] = '\t'; break;
4346 case 'a': output[d] = '\a'; break;
4347 case 'b': output[d] = '\b'; break;
4348 case 'f': output[d] = '\f'; break;
4349 case 'r': output[d] = '\r'; break;
4350 case 'v': output[d] = '\v'; break;
4351 case '\\': output[d] = '\\'; break;
4352 case '\"': output[d] = '\"'; break;
4353 case '\'': output[d] = '\''; break;
4354 default: output[d] = ch;
4375 // String Unescape Copy
4377 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4378 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4379 public int UnescapeString(char * d, char * s, int len)
4383 while(j < len && (ch = s[j]))
4388 switch((ch = s[++j]))
4390 case 'n': d[k] = '\n'; break;
4391 case 't': d[k] = '\t'; break;
4392 case 'a': d[k] = '\a'; break;
4393 case 'b': d[k] = '\b'; break;
4394 case 'f': d[k] = '\f'; break;
4395 case 'r': d[k] = '\r'; break;
4396 case 'v': d[k] = '\v'; break;
4397 case '\\': d[k] = '\\'; break;
4398 case '\"': d[k] = '\"'; break;
4399 case '\'': d[k] = '\''; break;
4400 default: d[k] = '\\'; d[k] = ch;
4412 public char * OffsetEscapedString(char * s, int len, int offset)
4416 while(j < len && k < offset && (ch = s[j]))
4421 return (k == offset) ? s + j : null;
4424 public Operand GetOperand(Expression exp)
4427 Type type = exp.expType;
4430 while(type.kind == classType &&
4431 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4433 if(!type._class.registered.dataType)
4434 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4435 type = type._class.registered.dataType;
4438 if(exp.type == stringExp && op.kind == pointerType)
4440 op.ui64 = (uint64)exp.string;
4441 op.kind = pointerType;
4444 else if(exp.isConstant && exp.type == constantExp)
4446 op.kind = type.kind;
4447 op.type = exp.expType;
4454 if(exp.constant[0] == '\'')
4456 op.c = exp.constant[1];
4459 else if(type.isSigned)
4461 op.c = (char)strtol(exp.constant, null, 0);
4466 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4474 op.s = (short)strtol(exp.constant, null, 0);
4479 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4487 op.i = (int)strtol(exp.constant, null, 0);
4492 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4500 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4505 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4508 op.kind = int64Type;
4513 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4518 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4521 op.kind = int64Type;
4526 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4531 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4534 op.kind = int64Type;
4537 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4538 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4539 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4540 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4542 op.f = (float)strtod(exp.constant, null);
4546 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4547 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4548 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4549 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4551 op.d = (double)strtod(exp.constant, null);
4554 //case classType: For when we have operator overloading...
4555 // Pointer additions
4556 //case functionType:
4560 op.ui64 = _strtoui64(exp.constant, null, 0);
4561 op.kind = pointerType;
4571 static __attribute__((unused)) void UnusedFunction()
4574 a.OnGetString(0,0,0);
4577 extern int __ecereVMethodID_class_OnGetString;
4580 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4582 DataMember dataMember;
4583 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4585 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4586 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4590 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4592 void * ptr = inst.data + dataMember.offset + offset;
4593 char * result = null;
4594 exp.loc = member.loc = inst.loc;
4595 ((Identifier)member.identifiers->first).loc = inst.loc;
4597 if(!dataMember.dataType)
4598 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4599 type = dataMember.dataType;
4600 if(type.kind == classType)
4602 Class _class = type._class.registered;
4603 if(_class.type == enumClass)
4605 Class enumClass = eSystem_FindClass(privateModule, "enum");
4608 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4610 for(item = e.values.first; item; item = item.next)
4612 if((int)item.data == *(int *)ptr)
4620 exp.identifier = MkIdentifier(result);
4621 exp.type = identifierExp;
4622 exp.destType = MkClassType(_class.fullName);
4623 ProcessExpressionType(exp);
4627 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4629 if(!_class.dataType)
4630 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4631 type = _class.dataType;
4640 FreeExpContents(exp);
4642 exp.constant = PrintFloat(*(float*)ptr);
4643 exp.type = constantExp;
4648 FreeExpContents(exp);
4650 exp.constant = PrintDouble(*(double*)ptr);
4651 exp.type = constantExp;
4656 FreeExpContents(exp);
4658 exp.constant = PrintInt(*(int*)ptr);
4659 exp.type = constantExp;
4664 FreeExpContents(exp);
4666 exp.constant = PrintInt64(*(int64*)ptr);
4667 exp.type = constantExp;
4672 FreeExpContents(exp);
4673 // TODO: This should probably use proper type
4674 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4675 exp.type = constantExp;
4680 FreeExpContents(exp);
4681 // TODO: This should probably use proper type
4682 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4683 exp.type = constantExp;
4687 Compiler_Error($"Unhandled type populating instance\n");
4690 ListAdd(memberList, member);
4693 if(parentDataMember.type == unionMember)
4698 void PopulateInstance(Instantiation inst)
4700 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4701 Class _class = classSym.registered;
4702 DataMember dataMember;
4703 OldList * memberList = MkList();
4704 // Added this check and ->Add to prevent memory leaks on bad code
4706 inst.members = MkListOne(MkMembersInitList(memberList));
4708 inst.members->Add(MkMembersInitList(memberList));
4709 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4711 if(!dataMember.isProperty)
4713 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4714 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4718 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4720 void * ptr = inst.data + dataMember.offset;
4721 char * result = null;
4723 exp.loc = member.loc = inst.loc;
4724 ((Identifier)member.identifiers->first).loc = inst.loc;
4726 if(!dataMember.dataType)
4727 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4728 type = dataMember.dataType;
4729 if(type.kind == classType)
4731 Class _class = type._class.registered;
4732 if(_class.type == enumClass)
4734 Class enumClass = eSystem_FindClass(privateModule, "enum");
4737 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4739 for(item = e.values.first; item; item = item.next)
4741 if((int)item.data == *(int *)ptr)
4750 exp.identifier = MkIdentifier(result);
4751 exp.type = identifierExp;
4752 exp.destType = MkClassType(_class.fullName);
4753 ProcessExpressionType(exp);
4756 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4758 if(!_class.dataType)
4759 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4760 type = _class.dataType;
4769 exp.constant = PrintFloat(*(float*)ptr);
4770 exp.type = constantExp;
4775 exp.constant = PrintDouble(*(double*)ptr);
4776 exp.type = constantExp;
4781 exp.constant = PrintInt(*(int*)ptr);
4782 exp.type = constantExp;
4787 exp.constant = PrintInt64(*(int64*)ptr);
4788 exp.type = constantExp;
4793 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4794 exp.type = constantExp;
4798 Compiler_Error($"Unhandled type populating instance\n");
4801 ListAdd(memberList, member);
4807 void ComputeInstantiation(Expression exp)
4809 Instantiation inst = exp.instance;
4810 MembersInit members;
4811 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4812 Class _class = classSym ? classSym.registered : null;
4813 DataMember curMember = null;
4814 Class curClass = null;
4815 DataMember subMemberStack[256];
4816 int subMemberStackPos = 0;
4819 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4821 // Don't recompute the instantiation...
4822 // Non Simple classes will have become constants by now
4826 if(_class.type == normalClass || _class.type == noHeadClass)
4828 inst.data = (byte *)eInstance_New(_class);
4829 if(_class.type == normalClass)
4830 ((Instance)inst.data)._refCount++;
4833 inst.data = new0 byte[_class.structSize];
4838 for(members = inst.members->first; members; members = members.next)
4840 switch(members.type)
4842 case dataMembersInit:
4844 if(members.dataMembers)
4847 for(member = members.dataMembers->first; member; member = member.next)
4849 Identifier ident = member.identifiers ? member.identifiers->first : null;
4852 Property prop = null;
4853 DataMember dataMember = null;
4854 Method method = null;
4855 uint dataMemberOffset;
4859 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4862 if(curMember.isProperty)
4863 prop = (Property)curMember;
4866 dataMember = curMember;
4868 // CHANGED THIS HERE
4869 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4871 // 2013/17/29 -- It seems that this was missing here!
4872 if(_class.type == normalClass)
4873 dataMemberOffset += _class.base.structSize;
4874 // dataMemberOffset = dataMember.offset;
4881 prop = eClass_FindProperty(_class, ident.string, privateModule);
4885 if(prop.memberAccess == publicAccess)
4887 curMember = (DataMember)prop;
4888 curClass = prop._class;
4893 DataMember _subMemberStack[256];
4894 int _subMemberStackPos = 0;
4896 // FILL MEMBER STACK
4897 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4902 if(dataMember.memberAccess == publicAccess)
4904 curMember = dataMember;
4905 curClass = dataMember._class;
4906 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4907 subMemberStackPos = _subMemberStackPos;
4913 if(found && member.initializer && member.initializer.type == expInitializer)
4915 Expression value = member.initializer.exp;
4917 bool deepMember = false;
4920 type = prop.dataType;
4924 if(!dataMember.dataType)
4925 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4927 type = dataMember.dataType;
4930 if(ident && ident.next)
4934 // for(; ident && type; ident = ident.next)
4935 for(ident = ident.next; ident && type; ident = ident.next)
4937 if(type.kind == classType)
4939 prop = eClass_FindProperty(type._class.registered,
4940 ident.string, privateModule);
4942 type = prop.dataType;
4945 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4946 ident.string, &dataMemberOffset, privateModule, null, null);
4948 type = dataMember.dataType;
4951 else if(type.kind == structType || type.kind == unionType)
4954 for(memberType = type.members.first; memberType; memberType = memberType.next)
4956 if(!strcmp(memberType.name, ident.string))
4967 FreeType(value.destType);
4968 value.destType = type;
4969 if(type) type.refCount++;
4970 ComputeExpression(value);
4972 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4974 if(type.kind == classType)
4976 Class _class = type._class.registered;
4977 if(_class.type == bitClass || _class.type == unitClass ||
4978 _class.type == enumClass)
4980 if(!_class.dataType)
4981 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4982 type = _class.dataType;
4988 void * ptr = inst.data + dataMemberOffset;
4990 if(value.type == constantExp)
4996 GetInt(value, (int*)ptr);
5001 GetInt64(value, (int64*)ptr);
5006 GetIntPtr(value, (intptr*)ptr);
5011 GetIntSize(value, (intsize*)ptr);
5016 GetFloat(value, (float*)ptr);
5021 GetDouble(value, (double *)ptr);
5026 else if(value.type == instanceExp)
5028 if(type.kind == classType)
5030 Class _class = type._class.registered;
5031 if(_class.type == structClass)
5033 ComputeTypeSize(type);
5034 if(value.instance.data)
5035 memcpy(ptr, value.instance.data, type.size);
5042 if(value.type == instanceExp && value.instance.data)
5044 if(type.kind == classType)
5046 Class _class = type._class.registered;
5047 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5049 void (*Set)(void *, void *) = (void *)prop.Set;
5050 Set(inst.data, value.instance.data);
5051 PopulateInstance(inst);
5055 else if(value.type == constantExp)
5061 void (*Set)(void *, double) = (void *)prop.Set;
5062 Set(inst.data, strtod(value.constant, null) );
5067 void (*Set)(void *, float) = (void *)prop.Set;
5068 Set(inst.data, (float)(strtod(value.constant, null)));
5073 void (*Set)(void *, int) = (void *)prop.Set;
5074 Set(inst.data, (int)strtol(value.constant, null, 0));
5079 void (*Set)(void *, int64) = (void *)prop.Set;
5080 Set(inst.data, _strtoi64(value.constant, null, 0));
5085 void (*Set)(void *, intptr) = (void *)prop.Set;
5086 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5091 void (*Set)(void *, intsize) = (void *)prop.Set;
5092 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5097 else if(value.type == stringExp)
5100 ReadString(temp, value.string);
5101 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5105 else if(!deepMember && type && _class.type == unitClass)
5109 // Only support converting units to units for now...
5110 if(value.type == constantExp)
5112 if(type.kind == classType)
5114 Class _class = type._class.registered;
5115 if(_class.type == unitClass)
5117 if(!_class.dataType)
5118 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5119 type = _class.dataType;
5122 // TODO: Assuming same base type for units...
5128 float (*Set)(float) = (void *)prop.Set;
5129 GetFloat(member.initializer.exp, &fValue);
5130 exp.constant = PrintFloat(Set(fValue));
5131 exp.type = constantExp;
5137 double (*Set)(double) = (void *)prop.Set;
5138 GetDouble(member.initializer.exp, &dValue);
5139 exp.constant = PrintDouble(Set(dValue));
5140 exp.type = constantExp;
5147 else if(!deepMember && type && _class.type == bitClass)
5151 if(value.type == instanceExp && value.instance.data)
5153 unsigned int (*Set)(void *) = (void *)prop.Set;
5154 bits = Set(value.instance.data);
5156 else if(value.type == constantExp)
5162 BitMember bitMember = (BitMember) dataMember;
5165 bits = (bits & ~bitMember.mask);
5166 if(!bitMember.dataType)
5167 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5168 type = bitMember.dataType;
5169 if(type.kind == classType && type._class && type._class.registered)
5171 if(!type._class.registered.dataType)
5172 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5173 type = type._class.registered.dataType;
5178 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5179 case shortType: { uint16 v; type.isSigned ? GetShort(value, (uint16 *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5181 case longType: { uint v; type.isSigned ? GetInt(value, (uint *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5182 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (uint64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5183 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (uintptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5184 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (uintsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5186 bits |= part << bitMember.pos;
5192 if(_class && _class.type == unitClass)
5194 ComputeExpression(member.initializer.exp);
5195 exp.constant = member.initializer.exp.constant;
5196 exp.type = constantExp;
5198 member.initializer.exp.constant = null;
5208 if(_class && _class.type == bitClass)
5210 exp.constant = PrintHexUInt(bits);
5211 exp.type = constantExp;
5213 if(exp.type != instanceExp)
5219 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5221 bool result = false;
5225 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5226 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5230 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5231 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5234 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5235 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5236 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5239 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5240 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5241 result = GetOpFloat(op, &op.f);
5244 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5245 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5246 result = GetOpDouble(op, &op.d);
5249 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5250 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5251 result = GetOpUIntPtr(op, &op.ui64);
5254 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5255 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5256 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5259 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5260 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5263 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5264 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5270 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5272 if(exp.op.op == SIZEOF)
5274 FreeExpContents(exp);
5275 exp.type = constantExp;
5276 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5287 // Provide default unary +
5288 Expression exp2 = exp.op.exp2;
5290 FreeExpContents(exp);
5291 FreeType(exp.expType);
5292 FreeType(exp.destType);
5298 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5300 // unary arithmetic increment and decrement
5301 //OPERATOR_ALL(UNARY, ++, Inc)
5302 //OPERATOR_ALL(UNARY, --, Dec)
5305 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5307 // unary logical negation
5309 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5315 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5317 if(Promote(op2, op1.kind, op1.type.isSigned))
5318 op2.kind = op1.kind, op2.ops = op1.ops;
5319 else if(Promote(op1, op2.kind, op2.type.isSigned))
5320 op1.kind = op2.kind, op1.ops = op2.ops;
5324 // binary arithmetic
5326 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5329 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5332 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5335 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5338 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5340 // binary arithmetic assignment
5341 //OPERATOR_ALL(BINARY, =, Asign)
5342 //OPERATOR_ALL(BINARY, +=, AddAsign)
5343 //OPERATOR_ALL(BINARY, -=, SubAsign)
5344 //OPERATOR_ALL(BINARY, *=, MulAsign)
5345 //OPERATOR_ALL(BINARY, /=, DivAsign)
5346 //OPERATOR_ALL(BINARY, %=, ModAsign)
5351 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5355 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5358 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5361 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5364 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5366 // binary bitwise assignment
5367 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5368 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5369 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5370 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5371 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5372 // binary logical equality
5374 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5377 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5381 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5384 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5386 // binary logical relational
5388 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5391 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5394 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5397 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5404 void ComputeExpression(Expression exp)
5406 char expString[10240];
5407 expString[0] = '\0';
5409 PrintExpression(exp, expString);
5416 ComputeInstantiation(exp);
5425 Expression exp1, exp2 = null;
5429 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5432 Expression e = exp.op.exp2;
5434 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5436 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5438 if(e.type == extensionCompoundExp)
5439 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5444 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5446 if(e.type == stringExp && e.string)
5448 char * string = e.string;
5449 int len = strlen(string);
5450 char * tmp = new char[len-2+1];
5451 len = UnescapeString(tmp, string + 1, len - 2);
5453 FreeExpContents(exp);
5454 exp.type = constantExp;
5455 exp.constant = PrintUInt(len + 1);
5459 Type type = e.expType;
5461 FreeExpContents(exp);
5462 exp.type = constantExp;
5463 exp.constant = PrintUInt(ComputeTypeSize(type));
5469 ComputeExpression(exp.op.exp2);
5473 ComputeExpression(exp.op.exp1);
5476 op1 = GetOperand(exp1);
5477 if(op1.type) op1.type.refCount++;
5480 op2 = GetOperand(exp2);
5481 if(op2.type) op2.type.refCount++;
5487 op1 = GetOperand(exp1);
5488 if(op1.type) op1.type.refCount++;
5491 CallOperator(exp, exp1, exp2, op1, op2);
5498 if(exp.op.exp1 && exp.op.exp2)
5503 FreeExpContents(exp);
5504 op1.ops.BitAnd(exp, op1, op2);
5513 FreeExpContents(exp);
5514 op1.ops.Mul(exp, op1, op2);
5523 FreeExpContents(exp);
5524 op1.ops.Add(exp, op1, op2);
5529 // Provide default unary +
5530 Expression exp2 = exp.op.exp2;
5532 FreeExpContents(exp);
5533 FreeType(exp.expType);
5534 FreeType(exp.destType);
5545 FreeExpContents(exp);
5546 op1.ops.Sub(exp, op1, op2);
5553 FreeExpContents(exp);
5554 op1.ops.Neg(exp, op1);
5561 FreeExpContents(exp);
5562 op1.ops.BitNot(exp, op1);
5568 FreeExpContents(exp);
5569 op1.ops.Not(exp, op1);
5572 // Binary only operators
5576 FreeExpContents(exp);
5577 op1.ops.Div(exp, op1, op2);
5583 FreeExpContents(exp);
5584 op1.ops.Mod(exp, op1, op2);
5596 FreeExpContents(exp);
5597 op1.ops.Sma(exp, op1, op2);
5606 FreeExpContents(exp);
5607 op1.ops.Grt(exp, op1, op2);
5616 FreeExpContents(exp);
5617 op1.ops.SmaEqu(exp, op1, op2);
5626 FreeExpContents(exp);
5627 op1.ops.GrtEqu(exp, op1, op2);
5636 FreeExpContents(exp);
5637 op1.ops.Equ(exp, op1, op2);
5646 FreeExpContents(exp);
5647 op1.ops.Nqu(exp, op1, op2);
5654 FreeExpContents(exp);
5655 op1.ops.BitOr(exp, op1, op2);
5661 FreeExpContents(exp);
5662 op1.ops.BitXor(exp, op1, op2);
5670 FreeExpContents(exp);
5671 exp.type = constantExp;
5672 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5676 if(op1.type) FreeType(op1.type);
5677 if(op2.type) FreeType(op2.type);
5681 case extensionExpressionExp:
5684 for(e = exp.list->first; e; e = n)
5689 OldList * list = exp.list;
5690 Expression prev = exp.prev;
5691 Expression next = exp.next;
5692 ComputeExpression(e);
5693 //FreeExpContents(exp);
5694 FreeType(exp.expType);
5695 FreeType(exp.destType);
5714 exp.isConstant = true;
5716 ComputeExpression(exp.index.exp);
5717 if(!exp.index.exp.isConstant)
5718 exp.isConstant = false;
5720 for(e = exp.index.index->first; e; e = e.next)
5722 ComputeExpression(e);
5725 // Check if this type is int
5728 exp.isConstant = false;
5730 exp.expType = Dereference(exp.index.exp.expType);
5736 Expression memberExp = exp.member.exp;
5737 Identifier memberID = exp.member.member;
5740 ComputeExpression(exp.member.exp);
5741 type = exp.member.exp.expType;
5744 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);
5745 Property prop = null;
5746 DataMember member = null;
5747 Class convertTo = null;
5748 if(type.kind == subClassType && exp.member.exp.type == classExp)
5749 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5756 PrintTypeNoConst(type, string, false, true);
5757 classSym = FindClass(string);
5758 _class = classSym ? classSym.registered : null;
5761 if(exp.member.member)
5763 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5765 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5767 if(!prop && !member && _class && exp.member.member)
5769 Symbol classSym = FindClass(exp.member.member.string);
5771 _class = classSym ? classSym.registered : null;
5772 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5779 Type type = prop.dataType;
5780 // TODO: Assuming same base type for units...
5781 if(_class.type == unitClass)
5783 if(type.kind == classType)
5785 Class _class = type._class.registered;
5786 if(_class.type == unitClass)
5788 if(!_class.dataType)
5789 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5790 type = _class.dataType;
5798 float (*Get)(float) = (void *)prop.Get;
5799 GetFloat(exp.member.exp, &value);
5800 exp.constant = PrintFloat(Get ? Get(value) : value);
5801 exp.type = constantExp;
5807 double (*Get)(double);
5808 GetDouble(exp.member.exp, &value);
5811 Get = (void *)prop.Set;
5813 Get = (void *)prop.Get;
5814 exp.constant = PrintDouble(Get ? Get(value) : value);
5815 exp.type = constantExp;
5824 Expression value = exp.member.exp;
5827 ProcessPropertyType(prop);
5829 type = prop.dataType;
5832 // printf("Investigate this\n");
5834 else if(_class.type == structClass)
5840 Class propertyClass = type._class.registered;
5841 if(propertyClass.type == structClass && value.type == instanceExp)
5843 void (*Set)(void *, void *) = (void *)prop.Set;
5844 exp.instance = Instantiation { };
5845 exp.instance.data = new0 byte[_class.structSize];
5846 exp.instance._class = MkSpecifierName(_class.fullName);
5847 exp.instance.loc = exp.loc;
5848 exp.type = instanceExp;
5849 Set(exp.instance.data, value.instance.data);
5850 PopulateInstance(exp.instance);
5857 void (*Set)(void *, int) = (void *)prop.Set;
5859 exp.instance = Instantiation { };
5860 exp.instance.data = new0 byte[_class.structSize];
5861 exp.instance._class = MkSpecifierName(_class.fullName);
5862 exp.instance.loc = exp.loc;
5863 exp.type = instanceExp;
5865 GetInt(value, &intValue);
5867 Set(exp.instance.data, intValue);
5868 PopulateInstance(exp.instance);
5874 void (*Set)(void *, int64) = (void *)prop.Set;
5876 exp.instance = Instantiation { };
5877 exp.instance.data = new0 byte[_class.structSize];
5878 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5879 exp.instance.loc = exp.loc;
5880 exp.type = instanceExp;
5882 GetInt64(value, &intValue);
5884 Set(exp.instance.data, intValue);
5885 PopulateInstance(exp.instance);
5892 void (*Set)(void *, intptr) = (void *)prop.Set;
5894 exp.instance = Instantiation { };
5895 exp.instance.data = new0 byte[_class.structSize];
5896 exp.instance._class = MkSpecifierName(_class.fullName);
5897 exp.instance.loc = exp.loc;
5898 exp.type = instanceExp;
5900 GetIntPtr(value, &intValue);
5902 Set(exp.instance.data, intValue);
5903 PopulateInstance(exp.instance);
5910 void (*Set)(void *, intsize) = (void *)prop.Set;
5912 exp.instance = Instantiation { };
5913 exp.instance.data = new0 byte[_class.structSize];
5914 exp.instance._class = MkSpecifierName(_class.fullName);
5915 exp.instance.loc = exp.loc;
5916 exp.type = instanceExp;
5918 GetIntSize(value, &intValue);
5920 Set(exp.instance.data, intValue);
5921 PopulateInstance(exp.instance);
5927 void (*Set)(void *, float) = (void *)prop.Set;
5929 exp.instance = Instantiation { };
5930 exp.instance.data = new0 byte[_class.structSize];
5931 exp.instance._class = MkSpecifierName(_class.fullName);
5932 exp.instance.loc = exp.loc;
5933 exp.type = instanceExp;
5935 GetFloat(value, &floatValue);
5937 Set(exp.instance.data, floatValue);
5938 PopulateInstance(exp.instance);
5944 void (*Set)(void *, double) = (void *)prop.Set;
5946 exp.instance = Instantiation { };
5947 exp.instance.data = new0 byte[_class.structSize];
5948 exp.instance._class = MkSpecifierName(_class.fullName);
5949 exp.instance.loc = exp.loc;
5950 exp.type = instanceExp;
5952 GetDouble(value, &doubleValue);
5954 Set(exp.instance.data, doubleValue);
5955 PopulateInstance(exp.instance);
5960 else if(_class.type == bitClass)
5966 Class propertyClass = type._class.registered;
5967 if(propertyClass.type == structClass && value.instance.data)
5969 unsigned int (*Set)(void *) = (void *)prop.Set;
5970 unsigned int bits = Set(value.instance.data);
5971 exp.constant = PrintHexUInt(bits);
5972 exp.type = constantExp;
5975 else if(_class.type == bitClass)
5978 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5981 GetUInt(exp.member.exp, &value);
5983 exp.constant = PrintHexUInt(bits);
5984 exp.type = constantExp;
5992 if(_class.type == bitClass)
5995 GetUInt(exp.member.exp, &value);
6001 Class _class = type._class.registered;
6002 if(_class.type == structClass)
6004 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6006 exp.instance = Instantiation { };
6007 exp.instance.data = new0 byte[_class.structSize];
6008 exp.instance._class = MkSpecifierName(_class.fullName);
6009 exp.instance.loc = exp.loc;
6010 //exp.instance.fullSet = true;
6011 exp.type = instanceExp;
6012 Get(value, exp.instance.data);
6013 PopulateInstance(exp.instance);
6015 else if(_class.type == bitClass)
6017 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6018 uint64 bits = Get(value);
6019 exp.constant = PrintHexUInt64(bits);
6020 exp.type = constantExp;
6026 else if(_class.type == structClass)
6028 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6033 Class _class = type._class.registered;
6034 if(_class.type == structClass && value)
6036 void (*Get)(void *, void *) = (void *)prop.Get;
6038 exp.instance = Instantiation { };
6039 exp.instance.data = new0 byte[_class.structSize];
6040 exp.instance._class = MkSpecifierName(_class.fullName);
6041 exp.instance.loc = exp.loc;
6042 //exp.instance.fullSet = true;
6043 exp.type = instanceExp;
6044 Get(value, exp.instance.data);
6045 PopulateInstance(exp.instance);
6053 char * value = exp.member.exp.instance.data;
6058 Class _class = type._class.registered;
6059 if(_class.type == normalClass)
6061 void *(*Get)(void *) = (void *)prop.Get;
6063 exp.instance = Instantiation { };
6064 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6065 exp.type = instanceExp;
6066 exp.instance.data = Get(value, exp.instance.data);
6078 exp.isConstant = false;
6086 if(exp.type != ExpressionType::memberExp)
6088 FreeExpression(memberExp);
6089 FreeIdentifier(memberID);
6095 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6096 FreeExpContents(exp);
6097 exp.constant = PrintUInt(ComputeTypeSize(type));
6098 exp.type = constantExp;
6104 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6105 if(classSym && classSym.registered)
6107 if(classSym.registered.fixed)
6109 FreeSpecifier(exp._class);
6110 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6111 exp.type = constantExp;
6115 char className[1024];
6116 strcpy(className, "__ecereClass_");
6117 FullClassNameCat(className, classSym.string, true);
6118 MangleClassName(className);
6120 DeclareClass(classSym, className);
6122 FreeExpContents(exp);
6123 exp.type = pointerExp;
6124 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6125 exp.member.member = MkIdentifier("structSize");
6135 if(exp.type == castExp)
6138 ComputeExpression(exp.cast.exp);
6141 if(e && exp.expType)
6144 type = exp.destType;
6147 if(type.kind == classType)
6149 Class _class = type._class.registered;
6150 if(_class && (_class.type == unitClass || _class.type == bitClass))
6152 if(!_class.dataType)
6153 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6154 type = _class.dataType;
6165 if(GetChar(e, &value))
6167 FreeExpContents(exp);
6168 exp.constant = PrintChar(value);
6169 exp.type = constantExp;
6174 unsigned char value = 0;
6175 if(GetUChar(e, &value))
6177 FreeExpContents(exp);
6178 exp.constant = PrintUChar(value);
6179 exp.type = constantExp;
6187 if(GetShort(e, &value))
6189 FreeExpContents(exp);
6190 exp.constant = PrintShort(value);
6191 exp.type = constantExp;
6196 unsigned short value = 0;
6197 if(GetUShort(e, &value))
6199 FreeExpContents(exp);
6200 exp.constant = PrintUShort(value);
6201 exp.type = constantExp;
6209 if(GetInt(e, &value))
6211 FreeExpContents(exp);
6212 exp.constant = PrintInt(value);
6213 exp.type = constantExp;
6218 unsigned int value = 0;
6219 if(GetUInt(e, &value))
6221 FreeExpContents(exp);
6222 exp.constant = PrintUInt(value);
6223 exp.type = constantExp;
6231 if(GetInt64(e, &value))
6233 FreeExpContents(exp);
6234 exp.constant = PrintInt64(value);
6235 exp.type = constantExp;
6241 if(GetUInt64(e, &value))
6243 FreeExpContents(exp);
6244 exp.constant = PrintUInt64(value);
6245 exp.type = constantExp;
6253 if(GetIntPtr(e, &value))
6255 FreeExpContents(exp);
6256 exp.constant = PrintInt64((int64)value);
6257 exp.type = constantExp;
6263 if(GetUIntPtr(e, &value))
6265 FreeExpContents(exp);
6266 exp.constant = PrintUInt64((uint64)value);
6267 exp.type = constantExp;
6275 if(GetIntSize(e, &value))
6277 FreeExpContents(exp);
6278 exp.constant = PrintInt64((int64)value);
6279 exp.type = constantExp;
6285 if(GetUIntSize(e, &value))
6287 FreeExpContents(exp);
6288 exp.constant = PrintUInt64((uint64)value);
6289 exp.type = constantExp;
6296 if(GetFloat(e, &value))
6298 FreeExpContents(exp);
6299 exp.constant = PrintFloat(value);
6300 exp.type = constantExp;
6307 if(GetDouble(e, &value))
6309 FreeExpContents(exp);
6310 exp.constant = PrintDouble(value);
6311 exp.type = constantExp;
6326 // Caring only about last expression for now...
6327 ComputeExpression(exp.cond.exp->last);
6328 if(exp.cond.elseExp)
6329 ComputeExpression(exp.cond.elseExp);
6331 ComputeExpression(exp.cond.cond);
6333 op1 = GetOperand(exp.cond.cond);
6334 if(op1.type) op1.type.refCount++;
6335 op2 = GetOperand(exp.cond.exp->last);
6336 if(op2.type) op2.type.refCount++;
6337 op3 = GetOperand(exp.cond.elseExp);
6338 if(op3.type) op3.type.refCount++;
6340 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6341 if(op1.type) FreeType(op1.type);
6342 if(op2.type) FreeType(op2.type);
6343 if(op3.type) FreeType(op3.type);
6349 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6354 OldList converts { };
6357 if(destType.kind == voidType)
6360 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6364 // for(convert = converts.last; convert; convert = convert.prev)
6365 for(convert = converts.first; convert; convert = convert.next)
6367 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6370 Expression newExp { };
6371 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6373 // TODO: Check this...
6377 newExp.destType = null;
6382 exp.type = memberExp;
6383 exp.addedThis = true;
6384 exp.member.exp = newExp;
6385 FreeType(exp.member.exp.expType);
6387 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6388 exp.member.exp.expType.classObjectType = objectType;
6389 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6390 exp.member.memberType = propertyMember;
6391 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6392 // TESTING THIS... for (int)degrees
6393 exp.needCast = true;
6394 if(exp.expType) exp.expType.refCount++;
6395 ApplyAnyObjectLogic(exp.member.exp);
6400 /*if(exp.isConstant)
6402 // Color { ColorRGB = [exp] };
6403 exp.type = instanceExp;
6404 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6405 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6406 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6410 // If not constant, don't turn it yet into an instantiation
6411 // (Go through the deep members system first)
6412 exp.type = memberExp;
6413 exp.addedThis = true;
6414 exp.member.exp = newExp;
6416 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6417 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6418 newExp.expType._class.registered.type == noHeadClass)
6420 newExp.byReference = true;
6423 FreeType(exp.member.exp.expType);
6424 /*exp.member.exp.expType = convert.convert.dataType;
6425 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6426 exp.member.exp.expType = null;
6427 if(convert.convert.dataType)
6429 exp.member.exp.expType = { };
6430 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6431 exp.member.exp.expType.refCount = 1;
6432 exp.member.exp.expType.classObjectType = objectType;
6433 ApplyAnyObjectLogic(exp.member.exp);
6436 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6437 exp.member.memberType = reverseConversionMember;
6438 exp.expType = convert.resultType ? convert.resultType :
6439 MkClassType(convert.convert._class.fullName);
6440 exp.needCast = true;
6441 if(convert.resultType) convert.resultType.refCount++;
6447 FreeType(exp.expType);
6450 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6451 exp.needCast = true;
6452 if(exp.expType) exp.expType.refCount++;
6456 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6457 exp.needCast = true;
6458 if(convert.resultType)
6459 convert.resultType.refCount++;
6463 if(exp.isConstant && inCompiler)
6464 ComputeExpression(exp);
6466 converts.Free(FreeConvert);
6469 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6471 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6473 if(!result && exp.expType && exp.destType)
6475 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6476 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6477 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6478 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6482 // if(result) CheckTemplateTypes(exp);
6486 void CheckTemplateTypes(Expression exp)
6488 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6490 Expression newExp { };
6493 if(exp.destType) exp.destType.refCount++;
6494 if(exp.expType) exp.expType.refCount++;
6498 switch(exp.expType.kind)
6501 if(exp.destType.classObjectType)
6503 // We need to pass the address, just pass it along (Undo what was done above)
6504 if(exp.destType) exp.destType.refCount--;
6505 if(exp.expType) exp.expType.refCount--;
6510 // If we're looking for value:
6511 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6513 OldList * unionDefs = MkList();
6514 OldList * statements = MkList();
6515 context = PushContext();
6516 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6517 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6518 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6519 exp.type = extensionCompoundExp;
6520 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6521 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6522 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6523 exp.compound.compound.context = context;
6524 PopContext(context);
6529 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6530 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6534 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6536 Expression newExp { };
6540 if(exp.destType) exp.destType.refCount++;
6541 if(exp.expType) exp.expType.refCount++;
6545 switch(exp.expType.kind)
6548 if(exp.destType.classObjectType)
6550 // We need to pass the address, just pass it along (Undo what was done above)
6551 if(exp.destType) exp.destType.refCount--;
6552 if(exp.expType) exp.expType.refCount--;
6557 // If we're looking for value:
6558 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6560 OldList * unionDefs = MkList();
6561 OldList * statements = MkList();
6562 context = PushContext();
6563 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6564 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6565 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6566 exp.type = extensionCompoundExp;
6567 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6568 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6569 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6570 exp.compound.compound.context = context;
6571 PopContext(context);
6576 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6578 exp.type = bracketsExp;
6579 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6580 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6581 ProcessExpressionType(exp.list->first);
6586 exp.type = bracketsExp;
6587 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6588 newExp.needCast = true;
6589 ProcessExpressionType(exp.list->first);
6595 if(exp.expType.kind == templateType)
6597 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6600 FreeType(exp.destType);
6601 FreeType(exp.expType);
6606 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6611 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6612 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6616 char typeString[1024];
6618 OldList * specs = MkList();
6619 typeString[0] = '\0';
6620 PrintType(exp.expType, typeString, false, false);
6621 decl = SpecDeclFromString(typeString, specs, null);
6624 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6625 exp.cast.typeName = MkTypeName(specs, decl);
6626 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6627 exp.cast.exp.needCast = true;
6634 // TODO: The Symbol tree should be reorganized by namespaces
6636 // - Tree of all symbols within (stored without namespace)
6637 // - Tree of sub-namespaces
6639 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6641 int nsLen = strlen(nameSpace);
6643 // Start at the name space prefix
6644 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6646 char * s = symbol.string;
6647 if(!strncmp(s, nameSpace, nsLen))
6649 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6652 for(c = strlen(s)-1; c >= 0; c--)
6657 if(!strcmp(namePart, name))
6659 // TODO: Error on ambiguity
6669 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6672 char nameSpace[1024];
6673 const char * namePart;
6674 bool gotColon = false;
6676 nameSpace[0] = '\0';
6677 for(c = strlen(name)-1; c >= 0; c--)
6684 namePart = name+c+1;
6685 while(c >= 0 && name[c] == ':') c--;
6688 // Try an exact match first
6689 Symbol symbol = (Symbol)tree.FindString(name);
6693 // Namespace specified
6694 memcpy(nameSpace, name, c + 1);
6697 return ScanWithNameSpace(tree, nameSpace, namePart);
6701 // Looking for a global symbol, e.g. ::Sleep()
6702 Symbol symbol = (Symbol)tree.FindString(namePart);
6707 // Name only (no namespace specified)
6708 Symbol symbol = (Symbol)tree.FindString(namePart);
6711 return ScanWithNameSpace(tree, "", namePart);
6716 static void ProcessDeclaration(Declaration decl);
6718 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6721 //Time startTime = GetTime();
6723 // Optimize this later? Do this before/less?
6725 Symbol symbol = null;
6726 // First, check if the identifier is declared inside the function
6727 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6729 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6731 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6737 strcpy(curName, thisNameSpace);
6738 strcat(curName, "::");
6739 strcat(curName, name);
6740 // Try to resolve in current namespace first
6741 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6744 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6747 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6749 if(symbol || ctx == endContext) break;
6751 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6753 if(symbol.pointerExternal.type == functionExternal)
6755 FunctionDefinition function = symbol.pointerExternal.function;
6757 // Modified this recently...
6758 Context tmpContext = curContext;
6760 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6761 curContext = tmpContext;
6763 symbol.pointerExternal.symbol = symbol;
6766 DeclareType(symbol.type, true, true);
6768 ast->Insert(curExternal.prev, symbol.pointerExternal);
6770 symbol.id = curExternal.symbol.idCode;
6773 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6775 ast->Move(symbol.pointerExternal, curExternal.prev);
6776 symbol.id = curExternal.symbol.idCode;
6780 //findSymbolTotalTime += GetTime() - startTime;
6785 static void GetTypeSpecs(Type type, OldList * specs)
6787 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6792 if(type._class.registered)
6794 if(!type._class.registered.dataType)
6795 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6796 GetTypeSpecs(type._class.registered.dataType, specs);
6800 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6801 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6802 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6803 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6804 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6805 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6806 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6807 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6810 ListAdd(specs, MkSpecifier(INT)); break;
6814 static void PrintArraySize(Type arrayType, char * string)
6819 if(arrayType.enumClass)
6820 strcat(size, arrayType.enumClass.string);
6821 else if(arrayType.arraySizeExp)
6822 PrintExpression(arrayType.arraySizeExp, size);
6824 strcat(string, size);
6827 // WARNING : This function expects a null terminated string since it recursively concatenate...
6828 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6832 if(printConst && type.constant)
6833 strcat(string, "const ");
6838 Symbol c = type._class;
6839 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6840 // look into merging with thisclass ?
6841 if(type.classObjectType == typedObject)
6842 strcat(string, "typed_object");
6843 else if(type.classObjectType == anyObject)
6844 strcat(string, "any_object");
6848 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6850 if(type.byReference)
6851 strcat(string, " &");
6854 case voidType: strcat(string, "void"); break;
6855 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6856 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6857 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6858 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6859 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6860 case _BoolType: strcat(string, "_Bool"); break;
6861 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6862 case floatType: strcat(string, "float"); break;
6863 case doubleType: strcat(string, "double"); break;
6867 strcat(string, "struct ");
6868 strcat(string, type.enumName);
6870 else if(type.typeName)
6871 strcat(string, type.typeName);
6875 strcat(string, "struct { ");
6876 for(member = type.members.first; member; member = member.next)
6878 PrintType(member, string, true, fullName);
6879 strcat(string,"; ");
6887 strcat(string, "union ");
6888 strcat(string, type.enumName);
6890 else if(type.typeName)
6891 strcat(string, type.typeName);
6894 strcat(string, "union ");
6895 strcat(string,"(unnamed)");
6901 strcat(string, "enum ");
6902 strcat(string, type.enumName);
6904 else if(type.typeName)
6905 strcat(string, type.typeName);
6907 strcat(string, "int"); // "enum");
6910 strcat(string, "...");
6913 strcat(string, "subclass(");
6914 strcat(string, type._class ? type._class.string : "int");
6915 strcat(string, ")");
6918 strcat(string, type.templateParameter.identifier.string);
6921 strcat(string, "thisclass");
6924 strcat(string, "__builtin_va_list");
6930 static void PrintName(Type type, char * string, bool fullName)
6932 if(type.name && type.name[0])
6935 strcat(string, type.name);
6938 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6939 if(name) name += 2; else name = type.name;
6940 strcat(string, name);
6945 static void PrintAttribs(Type type, char * string)
6949 if(type.dllExport) strcat(string, "dllexport ");
6950 if(type.attrStdcall) strcat(string, "stdcall ");
6954 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6956 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6958 Type attrType = null;
6959 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6960 PrintAttribs(type, string);
6961 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6962 strcat(string, " const");
6963 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6964 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6965 strcat(string, " (");
6966 if(type.kind == pointerType)
6968 if(type.type.kind == functionType || type.type.kind == methodType)
6969 PrintAttribs(type.type, string);
6971 if(type.kind == pointerType)
6973 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6974 strcat(string, "*");
6976 strcat(string, " *");
6978 if(printConst && type.constant && type.kind == pointerType)
6979 strcat(string, " const");
6982 PrintTypeSpecs(type, string, fullName, printConst);
6985 static void PostPrintType(Type type, char * string, bool fullName)
6987 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6988 strcat(string, ")");
6989 if(type.kind == arrayType)
6990 PrintArraySize(type, string);
6991 else if(type.kind == functionType)
6994 strcat(string, "(");
6995 for(param = type.params.first; param; param = param.next)
6997 PrintType(param, string, true, fullName);
6998 if(param.next) strcat(string, ", ");
7000 strcat(string, ")");
7002 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7003 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7007 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7009 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7011 PrePrintType(type, string, fullName, null, printConst);
7013 if(type.thisClass || (printName && type.name && type.name[0]))
7014 strcat(string, " ");
7015 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7017 Symbol _class = type.thisClass;
7018 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7020 if(type.classObjectType == classPointer)
7021 strcat(string, "class");
7023 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7025 else if(_class && _class.string)
7027 String s = _class.string;
7032 char * name = RSearchString(s, "::", strlen(s), true, false);
7033 if(name) name += 2; else name = s;
7034 strcat(string, name);
7037 strcat(string, "::");
7040 if(printName && type.name)
7041 PrintName(type, string, fullName);
7042 PostPrintType(type, string, fullName);
7043 if(type.bitFieldCount)
7046 sprintf(count, ":%d", type.bitFieldCount);
7047 strcat(string, count);
7051 void PrintType(Type type, char * string, bool printName, bool fullName)
7053 _PrintType(type, string, printName, fullName, true);
7056 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7058 _PrintType(type, string, printName, fullName, false);
7061 static Type FindMember(Type type, char * string)
7064 for(memberType = type.members.first; memberType; memberType = memberType.next)
7066 if(!memberType.name)
7068 Type subType = FindMember(memberType, string);
7072 else if(!strcmp(memberType.name, string))
7078 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7081 for(memberType = type.members.first; memberType; memberType = memberType.next)
7083 if(!memberType.name)
7085 Type subType = FindMember(memberType, string);
7088 *offset += memberType.offset;
7092 else if(!strcmp(memberType.name, string))
7094 *offset += memberType.offset;
7101 public bool GetParseError() { return parseError; }
7103 Expression ParseExpressionString(char * expression)
7107 fileInput = TempFile { };
7108 fileInput.Write(expression, 1, strlen(expression));
7109 fileInput.Seek(0, start);
7112 parsedExpression = null;
7114 expression_yyparse();
7117 return parsedExpression;
7120 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7122 Identifier id = exp.identifier;
7123 Method method = null;
7124 Property prop = null;
7125 DataMember member = null;
7126 ClassProperty classProp = null;
7128 if(_class && _class.type == enumClass)
7130 NamedLink value = null;
7131 Class enumClass = eSystem_FindClass(privateModule, "enum");
7135 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7137 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7138 for(value = e.values.first; value; value = value.next)
7140 if(!strcmp(value.name, id.string))
7147 FreeExpContents(exp);
7149 exp.type = constantExp;
7150 exp.isConstant = true;
7151 if(!strcmp(baseClass.dataTypeString, "int"))
7152 sprintf(constant, "%d",(int)value.data);
7154 sprintf(constant, "0x%X",(int)value.data);
7155 exp.constant = CopyString(constant);
7156 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7157 exp.expType = MkClassType(baseClass.fullName);
7165 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7167 ProcessMethodType(method);
7174 // TOCHECK: Put it back to what it was...
7175 // methodClass = _class;
7176 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7181 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7184 ProcessPropertyType(prop);
7185 exp.expType = prop.dataType;
7186 if(prop.dataType) prop.dataType.refCount++;
7189 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7191 if(!member.dataType)
7192 member.dataType = ProcessTypeString(member.dataTypeString, false);
7193 exp.expType = member.dataType;
7194 if(member.dataType) member.dataType.refCount++;
7197 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7199 if(!classProp.dataType)
7200 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7202 if(classProp.constant)
7204 FreeExpContents(exp);
7206 exp.isConstant = true;
7207 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7209 //char constant[256];
7210 exp.type = stringExp;
7211 exp.constant = QMkString((char *)classProp.Get(_class));
7216 exp.type = constantExp;
7217 sprintf(constant, "%d", (int)classProp.Get(_class));
7218 exp.constant = CopyString(constant);
7226 exp.expType = classProp.dataType;
7227 if(classProp.dataType) classProp.dataType.refCount++;
7233 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7235 BinaryTree * tree = &nameSpace.functions;
7236 GlobalData data = (GlobalData)tree->FindString(name);
7240 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7242 data = ScanGlobalData(child, name);
7250 static GlobalData FindGlobalData(char * name)
7253 NameSpace * nameSpace;
7254 nameSpace = globalData;
7255 for(c = 0; name[c]; c++)
7257 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7259 NameSpace * newSpace;
7260 char * spaceName = new char[c - start + 1];
7261 strncpy(spaceName, name + start, c - start);
7262 spaceName[c-start] = '\0';
7263 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7267 nameSpace = newSpace;
7268 if(name[c] == ':') c++;
7274 return ScanGlobalData(nameSpace, name + start);
7279 static int definedExpStackPos;
7280 static void * definedExpStack[512];
7282 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7283 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7285 Expression prev = checkedExp.prev, next = checkedExp.next;
7287 FreeExpContents(checkedExp);
7288 FreeType(checkedExp.expType);
7289 FreeType(checkedExp.destType);
7291 *checkedExp = *newExp;
7295 checkedExp.prev = prev;
7296 checkedExp.next = next;
7299 void ApplyAnyObjectLogic(Expression e)
7301 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7303 char debugExpString[4096];
7304 debugExpString[0] = '\0';
7305 PrintExpression(e, debugExpString);
7308 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7310 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7311 //ellipsisDestType = destType;
7314 Type type = e.expType;
7315 Class _class = null;
7316 //Type destType = e.destType;
7318 if(type.kind == classType && type._class && type._class.registered)
7320 _class = type._class.registered;
7322 else if(type.kind == subClassType)
7324 _class = FindClass("ecere::com::Class").registered;
7328 char string[1024] = "";
7331 PrintTypeNoConst(type, string, false, true);
7332 classSym = FindClass(string);
7333 if(classSym) _class = classSym.registered;
7336 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...
7337 (!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))) ||
7338 destType.byReference)))
7340 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7342 Expression checkedExp = e, newExp;
7344 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7346 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7348 if(checkedExp.type == extensionCompoundExp)
7350 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7353 checkedExp = checkedExp.list->last;
7355 else if(checkedExp.type == castExp)
7356 checkedExp = checkedExp.cast.exp;
7359 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7361 newExp = checkedExp.op.exp2;
7362 checkedExp.op.exp2 = null;
7363 FreeExpContents(checkedExp);
7365 if(e.expType && e.expType.passAsTemplate)
7368 ComputeTypeSize(e.expType);
7369 sprintf(size, "%d", e.expType.size);
7370 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7371 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7372 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7375 ReplaceExpContents(checkedExp, newExp);
7376 e.byReference = true;
7378 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7380 Expression checkedExp; //, newExp;
7383 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7385 e.type == identifierExp ||
7386 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7387 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7388 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7391 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7393 Context context = PushContext();
7395 OldList * specs = MkList();
7396 char typeString[1024];
7397 Expression newExp { };
7399 typeString[0] = '\0';
7402 //if(e.destType) e.destType.refCount++;
7403 // if(exp.expType) exp.expType.refCount++;
7406 newExp.expType = null;
7408 PrintTypeNoConst(e.expType, typeString, false, true);
7409 decl = SpecDeclFromString(typeString, specs, null);
7410 newExp.destType = ProcessType(specs, decl);
7412 curContext = context;
7414 // We need a current compound for this
7418 OldList * stmts = MkList();
7419 e.type = extensionCompoundExp;
7420 sprintf(name, "__internalValue%03X", internalValueCounter++);
7421 if(!curCompound.compound.declarations)
7422 curCompound.compound.declarations = MkList();
7423 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7424 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7425 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7426 e.compound = MkCompoundStmt(null, stmts);
7429 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7432 e.compound = MkCompoundStmt(
7433 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7434 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7436 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7440 Type type = e.destType;
7442 CopyTypeInto(e.destType, type);
7443 e.destType.refCount = 1;
7444 e.destType.classObjectType = none;
7448 e.compound.compound.context = context;
7449 PopContext(context);
7450 curContext = context.parent;
7454 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7456 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7458 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7460 if(checkedExp.type == extensionCompoundExp)
7462 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7465 checkedExp = checkedExp.list->last;
7467 else if(checkedExp.type == castExp)
7468 checkedExp = checkedExp.cast.exp;
7471 Expression operand { };
7472 operand = *checkedExp;
7473 checkedExp.destType = null;
7474 checkedExp.expType = null;
7476 checkedExp.type = opExp;
7477 checkedExp.op.op = '&';
7478 checkedExp.op.exp1 = null;
7479 checkedExp.op.exp2 = operand;
7481 //newExp = MkExpOp(null, '&', checkedExp);
7483 //ReplaceExpContents(checkedExp, newExp);
7490 // If expression type is a simple class, make it an address
7491 // FixReference(e, true);
7494 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7495 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7496 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7498 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"))
7500 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7504 Expression thisExp { };
7507 thisExp.prev = null;
7508 thisExp.next = null;
7511 e.type = bracketsExp;
7512 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7513 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7514 ((Expression)e.list->first).byReference = true;
7516 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7518 e.expType = thisExp.expType;
7519 e.expType.refCount++;
7524 CopyTypeInto(e.expType, thisExp.expType);
7525 e.expType.byReference = false;
7526 e.expType.refCount = 1;
7528 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7529 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7531 e.expType.classObjectType = none;
7536 // TOFIX: Try this for a nice IDE crash!
7538 // The other way around
7541 if(destType && e.expType &&
7542 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7543 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7544 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7546 if(destType.kind == ellipsisType)
7548 Compiler_Error($"Unspecified type\n");
7550 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7552 bool byReference = e.expType.byReference;
7553 Expression thisExp { };
7555 OldList * specs = MkList();
7556 char typeString[1024]; // Watch buffer overruns
7558 ClassObjectType backupClassObjectType;
7559 bool backupByReference;
7561 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7566 backupClassObjectType = type.classObjectType;
7567 backupByReference = type.byReference;
7569 type.classObjectType = none;
7570 type.byReference = false;
7572 typeString[0] = '\0';
7573 PrintType(type, typeString, false, true);
7574 decl = SpecDeclFromString(typeString, specs, null);
7576 type.classObjectType = backupClassObjectType;
7577 type.byReference = backupByReference;
7580 thisExp.prev = null;
7581 thisExp.next = null;
7584 if( ( type.kind == classType && type._class && type._class.registered &&
7585 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7586 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7587 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7588 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7593 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7596 CopyTypeInto(e.expType, type);
7597 e.expType.byReference = false;
7598 e.expType.refCount = 1;
7603 e.cast.typeName = MkTypeName(specs, decl);
7604 e.cast.exp = thisExp;
7605 e.byReference = true;
7609 e.destType = destType;
7610 destType.refCount++;
7615 void ApplyLocation(Expression exp, Location loc)
7621 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7622 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7628 for(e = exp.list->first; e; e = e.next)
7629 ApplyLocation(e, loc);
7636 for(e = exp.index.index->first; e; e = e.next)
7637 ApplyLocation(e, loc);
7640 ApplyLocation(exp.index.exp, loc);
7643 if(exp.call.arguments)
7646 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7647 ApplyLocation(arg, loc);
7650 ApplyLocation(exp.call.exp, loc);
7655 ApplyLocation(exp.member.exp, loc);
7659 ApplyLocation(exp.cast.exp, loc);
7665 for(e = exp.cond.exp->first; e; e = e.next)
7666 ApplyLocation(e, loc);
7669 ApplyLocation(exp.cond.cond, loc);
7670 if(exp.cond.elseExp)
7671 ApplyLocation(exp.cond.elseExp, loc);
7675 ApplyLocation(exp.vaArg.exp, loc);
7682 void ProcessExpressionType(Expression exp)
7684 bool unresolved = false;
7685 Location oldyylloc = yylloc;
7686 bool notByReference = false;
7688 char debugExpString[4096];
7689 debugExpString[0] = '\0';
7690 PrintExpression(exp, debugExpString);
7692 if(!exp || exp.expType)
7695 //eSystem_Logf("%s\n", expString);
7697 // Testing this here
7703 Identifier id = exp.identifier;
7704 if(!id || !topContext) return;
7706 // DOING THIS LATER NOW...
7707 if(id._class && id._class.name)
7709 id.classSym = id._class.symbol; // FindClass(id._class.name);
7710 /* TODO: Name Space Fix ups
7712 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7716 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7718 exp.expType = ProcessTypeString("Module", true);
7721 else */if(strstr(id.string, "__ecereClass") == id.string)
7723 exp.expType = ProcessTypeString("ecere::com::Class", true);
7726 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7728 // Added this here as well
7729 ReplaceClassMembers(exp, thisClass);
7730 if(exp.type != identifierExp)
7732 ProcessExpressionType(exp);
7736 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7741 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7742 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7743 if(!symbol/* && exp.destType*/)
7745 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7751 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7752 if(exp.type != identifierExp)
7754 ProcessExpressionType(exp);
7758 // Static methods called from inside the _class
7759 else if(currentClass && !id._class)
7761 if(ResolveIdWithClass(exp, currentClass, true))
7764 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7768 // If we manage to resolve this symbol
7771 Type type = symbol.type;
7772 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7774 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7776 Context context = SetupTemplatesContext(_class);
7777 type = ReplaceThisClassType(_class);
7778 FinishTemplatesContext(context);
7779 if(type) type.refCount = 0; // We'll be incrementing it right below...
7782 FreeSpecifier(id._class);
7785 id.string = CopyString(symbol.string);
7792 // Commented this out, it was making non-constant enum parameters seen as constant
7793 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7794 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7795 // Add missing cases here... enum Classes...
7796 exp.isConstant = true;
7798 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7799 if(symbol.isParam || !strcmp(id.string, "this"))
7801 if(_class && _class.type == structClass && !type.declaredWithStruct)
7802 exp.byReference = true;
7804 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7805 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7806 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7807 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7809 Identifier id = exp.identifier;
7810 exp.type = bracketsExp;
7811 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7815 if(symbol.isIterator)
7817 if(symbol.isIterator == 3)
7819 exp.type = bracketsExp;
7820 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7821 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7823 ProcessExpressionType(exp);
7825 else if(symbol.isIterator != 4)
7827 exp.type = memberExp;
7828 exp.member.exp = MkExpIdentifier(exp.identifier);
7829 exp.member.exp.expType = exp.expType;
7830 /*if(symbol.isIterator == 6)
7831 exp.member.member = MkIdentifier("key");
7833 exp.member.member = MkIdentifier("data");
7835 ProcessExpressionType(exp);
7842 DefinedExpression definedExp = null;
7843 if(thisNameSpace && !(id._class && !id._class.name))
7846 strcpy(name, thisNameSpace);
7848 strcat(name, id.string);
7849 definedExp = eSystem_FindDefine(privateModule, name);
7852 definedExp = eSystem_FindDefine(privateModule, id.string);
7856 for(c = 0; c<definedExpStackPos; c++)
7857 if(definedExpStack[c] == definedExp)
7859 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7861 Location backupYylloc = yylloc;
7862 File backInput = fileInput;
7863 definedExpStack[definedExpStackPos++] = definedExp;
7865 fileInput = TempFile { };
7866 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7867 fileInput.Seek(0, start);
7870 parsedExpression = null;
7872 expression_yyparse();
7875 fileInput = backInput;
7877 yylloc = backupYylloc;
7879 if(parsedExpression)
7882 exp.type = bracketsExp;
7883 exp.list = MkListOne(parsedExpression);
7884 ApplyLocation(parsedExpression, yylloc);
7885 ProcessExpressionType(exp);
7886 definedExpStackPos--;
7889 definedExpStackPos--;
7895 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7901 GlobalData data = null;
7902 if(thisNameSpace && !(id._class && !id._class.name))
7905 strcpy(name, thisNameSpace);
7907 strcat(name, id.string);
7908 data = FindGlobalData(name);
7911 data = FindGlobalData(id.string);
7914 DeclareGlobalData(data);
7915 exp.expType = data.dataType;
7916 if(data.dataType) data.dataType.refCount++;
7919 id.string = CopyString(data.fullName);
7920 FreeSpecifier(id._class);
7927 GlobalFunction function = null;
7928 if(thisNameSpace && !(id._class && !id._class.name))
7931 strcpy(name, thisNameSpace);
7933 strcat(name, id.string);
7934 function = eSystem_FindFunction(privateModule, name);
7937 function = eSystem_FindFunction(privateModule, id.string);
7942 id.string = CopyString(function.name);
7945 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7946 strcpy(name, "__ecereFunction_");
7947 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7948 if(DeclareFunction(function, name))
7951 id.string = CopyString(name);
7953 exp.expType = function.dataType;
7954 if(function.dataType) function.dataType.refCount++;
7956 FreeSpecifier(id._class);
7973 if(!exp.instance._class)
7975 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7977 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7981 //classSym = FindClass(exp.instance._class.fullName);
7982 //_class = classSym ? classSym.registered : null;
7984 ProcessInstantiationType(exp.instance);
7986 exp.isConstant = exp.instance.isConstant;
7989 if(_class.type == unitClass && _class.base.type != systemClass)
7992 Type destType = exp.destType;
7994 exp.destType = MkClassType(_class.base.fullName);
7995 exp.expType = MkClassType(_class.fullName);
7996 CheckExpressionType(exp, exp.destType, true);
7998 exp.destType = destType;
8000 exp.expType = MkClassType(_class.fullName);
8003 if(exp.instance._class)
8005 exp.expType = MkClassType(exp.instance._class.name);
8006 /*if(exp.expType._class && exp.expType._class.registered &&
8007 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8008 exp.expType.byReference = true;*/
8016 char * constant = exp.constant;
8024 if(constant[0] == '\'')
8026 if((int)((byte *)constant)[1] > 127)
8029 unichar ch = UTF8GetChar(constant + 1, &nb);
8030 if(nb < 2) ch = constant[1];
8032 exp.constant = PrintUInt(ch);
8033 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8034 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8035 type._class = FindClass("unichar");
8037 type.isSigned = false;
8041 type.kind = charType;
8042 type.isSigned = true;
8047 char * dot = strchr(constant, '.');
8048 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8052 exponent = strchr(constant, 'p');
8053 if(!exponent) exponent = strchr(constant, 'P');
8057 exponent = strchr(constant, 'e');
8058 if(!exponent) exponent = strchr(constant, 'E');
8063 if(strchr(constant, 'f') || strchr(constant, 'F'))
8064 type.kind = floatType;
8066 type.kind = doubleType;
8067 type.isSigned = true;
8071 bool isSigned = constant[0] == '-';
8073 int64 i64 = strtoll(constant, &endP, 0);
8074 uint64 ui64 = strtoull(constant, &endP, 0);
8075 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8088 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8092 else if(constant[0] != '0' || !constant[1])
8095 type.kind = is64Bit ? int64Type : intType;
8096 type.isSigned = isSigned;
8099 exp.isConstant = true;
8100 if(exp.destType && exp.destType.kind == doubleType)
8101 type.kind = doubleType;
8102 else if(exp.destType && exp.destType.kind == floatType)
8103 type.kind = floatType;
8104 else if(exp.destType && exp.destType.kind == int64Type)
8105 type.kind = int64Type;
8111 exp.isConstant = true; // Why wasn't this constant?
8128 ProcessExpressionType(exp._new.size);
8133 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8135 DeclareType(exp.expType.type, false, false);
8139 ProcessExpressionType(exp._renew.size);
8140 ProcessExpressionType(exp._renew.exp);
8145 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8147 DeclareType(exp.expType.type, false, false);
8151 bool assign = false, boolResult = false, boolOps = false;
8152 Type type1 = null, type2 = null;
8153 bool useDestType = false, useSideType = false;
8154 Location oldyylloc = yylloc;
8155 bool useSideUnit = false;
8156 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8158 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8167 // Assignment Operators
8181 // boolean Operators
8183 // Expect boolean operators
8185 //boolResult = true;
8189 // Expect boolean operands
8200 // Gives boolean result
8232 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8238 /*// Implement speed etc.
8244 if(exp.op.op == '&')
8246 // Added this here earlier for Iterator address as key
8247 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8249 Identifier id = exp.op.exp2.identifier;
8250 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8251 if(symbol && symbol.isIterator == 2)
8253 exp.type = memberExp;
8254 exp.member.exp = exp.op.exp2;
8255 exp.member.member = MkIdentifier("key");
8257 exp.op.exp2.expType = symbol.type;
8258 symbol.type.refCount++;
8259 ProcessExpressionType(exp);
8263 // exp.op.exp2.usage.usageRef = true;
8267 //dummy.kind = TypeDummy;
8270 // Added this check here to use the dest type only for units derived from the base unit
8271 // So that untyped units will use the side unit as opposed to the untyped destination unit
8272 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8273 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8274 useDestType = false;
8276 if(destClass && useDestType &&
8277 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8279 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8281 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8282 exp.op.exp1.destType = exp.destType;
8283 exp.op.exp1.opDestType = true;
8285 exp.destType.refCount++;
8289 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8290 exp.op.exp1.destType = dummy;
8294 // TESTING THIS HERE...
8295 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8296 ProcessExpressionType(exp.op.exp1);
8297 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8299 exp.op.exp1.opDestType = false;
8301 // Fix for unit and ++ / --
8302 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8303 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8305 exp.op.exp2 = MkExpConstant("1");
8306 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8310 if(exp.op.exp1.destType == dummy)
8313 exp.op.exp1.destType = null;
8315 type1 = exp.op.exp1.expType;
8320 char expString[10240];
8321 expString[0] = '\0';
8322 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8326 exp.op.exp2.destType = exp.op.exp1.expType;
8327 if(exp.op.exp1.expType)
8328 exp.op.exp1.expType.refCount++;
8332 exp.op.exp2.destType = exp.destType;
8333 if(!exp.op.exp1 || exp.op.op != '&')
8334 exp.op.exp2.opDestType = true;
8336 exp.destType.refCount++;
8339 if(type1) type1.refCount++;
8340 exp.expType = type1;
8345 PrintExpression(exp.op.exp2, expString);
8347 if(type1 && type1.kind == pointerType)
8349 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 ||
8350 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8351 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8352 else if(exp.op.op == '=')
8354 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8355 exp.op.exp2.destType = type1;
8362 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8363 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/* ||
8364 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8367 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8368 exp.op.exp2.destType = type1;
8373 if(type1) type1.refCount++;
8374 exp.expType = type1;
8376 else if(destClass &&
8377 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8378 (destClass.type == enumClass && useDestType)))
8380 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8381 exp.op.exp2.destType = exp.destType;
8382 if(exp.op.op != '&')
8383 exp.op.exp2.opDestType = true;
8385 exp.destType.refCount++;
8389 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8390 exp.op.exp2.destType = dummy;
8394 // TESTING THIS HERE... (DANGEROUS)
8395 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8396 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8398 FreeType(exp.op.exp2.destType);
8399 exp.op.exp2.destType = type1;
8402 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8403 // Cannot lose the cast on a sizeof
8404 if(exp.op.op == SIZEOF)
8406 Expression e = exp.op.exp2;
8407 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8409 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8411 if(e.type == extensionCompoundExp)
8412 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8417 if(e.type == castExp && e.cast.exp)
8418 e.cast.exp.needCast = true;
8420 ProcessExpressionType(exp.op.exp2);
8421 exp.op.exp2.opDestType = false;
8422 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8424 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8426 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)
8428 if(exp.op.op != '=' && type1.type.kind == voidType)
8429 Compiler_Error($"void *: unknown size\n");
8431 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||
8432 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8433 (exp.op.exp2.expType._class.registered.type == normalClass ||
8434 exp.op.exp2.expType._class.registered.type == structClass ||
8435 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8437 if(exp.op.op == ADD_ASSIGN)
8438 Compiler_Error($"cannot add two pointers\n");
8440 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8441 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8443 if(exp.op.op == ADD_ASSIGN)
8444 Compiler_Error($"cannot add two pointers\n");
8448 char type1String[1024];
8449 char type2String[1024];
8450 type1String[0] = '\0';
8451 type2String[0] = '\0';
8453 PrintType(exp.op.exp2.expType, type1String, false, true);
8454 PrintType(type1, type2String, false, true);
8455 ChangeCh(expString, '\n', ' ');
8456 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8460 if(exp.op.exp2.destType == dummy)
8463 exp.op.exp2.destType = null;
8466 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8470 CopyTypeInto(type2, exp.op.exp2.expType);
8471 type2.isSigned = true;
8473 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8475 type2 = { kind = intType };
8477 type2.isSigned = true;
8481 type2 = exp.op.exp2.expType;
8482 if(type2) type2.refCount++;
8486 dummy.kind = voidType;
8488 if(exp.op.op == SIZEOF)
8495 exp.isConstant = true;
8497 // Get type of dereferenced pointer
8498 else if(exp.op.op == '*' && !exp.op.exp1)
8500 exp.expType = Dereference(type2);
8501 if(type2 && type2.kind == classType)
8502 notByReference = true;
8504 else if(exp.op.op == '&' && !exp.op.exp1)
8505 exp.expType = Reference(type2);
8512 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8513 exp.op.exp1.destType = MkClassType("bool");
8514 exp.op.exp1.destType.truth = true;
8515 if(!exp.op.exp1.expType)
8516 ProcessExpressionType(exp.op.exp1);
8518 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8519 FreeType(exp.op.exp1.expType);
8520 exp.op.exp1.expType = MkClassType("bool");
8521 exp.op.exp1.expType.truth = true;
8525 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8526 exp.op.exp2.destType = MkClassType("bool");
8527 exp.op.exp2.destType.truth = true;
8528 if(!exp.op.exp2.expType)
8529 ProcessExpressionType(exp.op.exp2);
8531 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8532 FreeType(exp.op.exp2.expType);
8533 exp.op.exp2.expType = MkClassType("bool");
8534 exp.op.exp2.expType.truth = true;
8537 else if(exp.op.exp1 && exp.op.exp2 &&
8540 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8541 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8542 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8543 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8545 if(type1 && type2 &&
8546 // If either both are class or both are not class
8547 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8549 // Added this check for enum subtraction to result in an int type:
8550 if(exp.op.op == '-' &&
8551 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8552 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8555 if(!type1._class.registered.dataType)
8556 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8557 if(!type2._class.registered.dataType)
8558 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8560 intType = ProcessTypeString(
8561 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8563 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8564 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8565 exp.op.exp1.destType = intType;
8566 exp.op.exp2.destType = intType;
8571 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8572 exp.op.exp2.destType = type1;
8574 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8575 exp.op.exp1.destType = type2;
8579 // Warning here for adding Radians + Degrees with no destination type
8580 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8581 type1._class.registered && type1._class.registered.type == unitClass &&
8582 type2._class.registered && type2._class.registered.type == unitClass &&
8583 type1._class.registered != type2._class.registered)
8584 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8585 type1._class.string, type2._class.string, type1._class.string);
8587 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8589 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8592 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8594 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8595 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8598 ProcessExpressionType(exp.op.exp1);
8600 if(type2.kind != pointerType)
8602 ProcessExpressionType(classExp);
8604 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8605 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8606 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8608 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8611 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8612 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8613 MkPointer(null, null), null)))),
8614 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8616 if(!exp.op.exp2.expType)
8620 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8624 ProcessExpressionType(exp.op.exp2);
8629 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)))
8631 if(type1.kind != classType && type1.type.kind == voidType)
8632 Compiler_Error($"void *: unknown size\n");
8633 exp.expType = type1;
8634 if(type1) type1.refCount++;
8636 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)))
8638 if(type2.kind != classType && type2.type.kind == voidType)
8639 Compiler_Error($"void *: unknown size\n");
8640 exp.expType = type2;
8641 if(type2) type2.refCount++;
8643 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8644 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8646 Compiler_Warning($"different levels of indirection\n");
8650 bool success = false;
8651 if(type1.kind == pointerType && type2.kind == pointerType)
8653 if(exp.op.op == '+')
8654 Compiler_Error($"cannot add two pointers\n");
8655 else if(exp.op.op == '-')
8657 // Pointer Subtraction gives integer
8658 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8667 if(type1.type.kind == templateType)
8669 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8672 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8674 ProcessExpressionType(classExp);
8676 exp.type = bracketsExp;
8677 exp.list = MkListOne(MkExpOp(
8678 MkExpBrackets(MkListOne(MkExpOp(
8679 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8681 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8683 //MkExpMember(classExp, MkIdentifier("typeSize"))
8685 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8686 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8688 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8691 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8692 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8693 MkPointer(null, null), null)))),
8694 MkExpMember(classExp, MkIdentifier("typeSize")))))
8699 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8708 if(!success && exp.op.exp1.type == constantExp)
8710 // If first expression is constant, try to match that first
8711 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8713 if(exp.expType) FreeType(exp.expType);
8714 exp.expType = exp.op.exp1.destType;
8715 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8718 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8720 if(exp.expType) FreeType(exp.expType);
8721 exp.expType = exp.op.exp2.destType;
8722 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8728 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8730 if(exp.expType) FreeType(exp.expType);
8731 exp.expType = exp.op.exp2.destType;
8732 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8735 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8737 if(exp.expType) FreeType(exp.expType);
8738 exp.expType = exp.op.exp1.destType;
8739 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8745 char expString1[10240];
8746 char expString2[10240];
8749 expString1[0] = '\0';
8750 expString2[0] = '\0';
8755 PrintExpression(exp.op.exp1, expString1);
8756 ChangeCh(expString1, '\n', ' ');
8757 PrintExpression(exp.op.exp2, expString2);
8758 ChangeCh(expString2, '\n', ' ');
8759 PrintType(exp.op.exp1.expType, type1, false, true);
8760 PrintType(exp.op.exp2.expType, type2, false, true);
8763 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8767 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8768 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8770 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8771 // Convert e.g. / 4 into / 4.0
8772 exp.op.exp1.destType = type2._class.registered.dataType;
8773 if(type2._class.registered.dataType)
8774 type2._class.registered.dataType.refCount++;
8775 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8776 exp.expType = type2;
8777 if(type2) type2.refCount++;
8779 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8781 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8782 // Convert e.g. / 4 into / 4.0
8783 exp.op.exp2.destType = type1._class.registered.dataType;
8784 if(type1._class.registered.dataType)
8785 type1._class.registered.dataType.refCount++;
8786 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8787 exp.expType = type1;
8788 if(type1) type1.refCount++;
8794 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8796 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8798 if(!type1._class.registered.dataType)
8799 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8800 exp.op.exp2.destType = type1._class.registered.dataType;
8801 exp.op.exp2.destType.refCount++;
8803 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8806 type2 = exp.op.exp2.destType;
8807 if(type2) type2.refCount++;
8809 exp.expType = type2;
8813 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8815 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8817 if(!type2._class.registered.dataType)
8818 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8819 exp.op.exp1.destType = type2._class.registered.dataType;
8820 exp.op.exp1.destType.refCount++;
8822 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8823 type1 = exp.op.exp1.destType;
8824 exp.expType = type1;
8828 // TESTING THIS NEW CODE
8829 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8831 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8832 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8833 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8835 // Convert the enum to an int instead for these operators
8836 if(op1IsEnum && exp.op.exp2.expType)
8838 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8840 if(exp.expType) FreeType(exp.expType);
8841 exp.expType = exp.op.exp2.expType;
8842 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8846 else if(op2IsEnum && exp.op.exp1.expType)
8848 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8850 if(exp.expType) FreeType(exp.expType);
8851 exp.expType = exp.op.exp1.expType;
8852 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8859 if(op1IsEnum && exp.op.exp2.expType)
8861 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8863 if(exp.expType) FreeType(exp.expType);
8864 exp.expType = exp.op.exp1.expType;
8865 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8869 else if(op2IsEnum && exp.op.exp1.expType)
8871 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8873 if(exp.expType) FreeType(exp.expType);
8874 exp.expType = exp.op.exp2.expType;
8875 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8884 // 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
8885 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8886 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8888 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8889 exp.op.exp1.destType = type2;
8892 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8894 if(exp.expType) FreeType(exp.expType);
8895 exp.expType = exp.op.exp1.destType;
8896 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8901 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8902 exp.op.exp2.destType = type1;
8906 // Maybe this was meant to be an enum...
8907 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8909 Type oldType = exp.op.exp2.expType;
8910 exp.op.exp2.expType = null;
8911 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8914 exp.op.exp2.expType = oldType;
8919 // TESTING THIS HERE... LATEST ADDITION
8920 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8922 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8923 exp.op.exp2.destType = type2._class.registered.dataType;
8924 if(type2._class.registered.dataType)
8925 type2._class.registered.dataType.refCount++;
8926 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8928 //exp.expType = type2._class.registered.dataType; //type2;
8929 //if(type2) type2.refCount++;
8932 // TESTING THIS HERE... LATEST ADDITION
8933 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8935 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8936 exp.op.exp1.destType = type1._class.registered.dataType;
8937 if(type1._class.registered.dataType)
8938 type1._class.registered.dataType.refCount++;
8939 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8940 exp.expType = type1._class.registered.dataType; //type1;
8941 if(type1) type1.refCount++;
8945 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8947 if(exp.expType) FreeType(exp.expType);
8948 exp.expType = exp.op.exp2.destType;
8949 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8951 else if(type1 && type2)
8953 char expString1[10240];
8954 char expString2[10240];
8955 char type1String[1024];
8956 char type2String[1024];
8957 expString1[0] = '\0';
8958 expString2[0] = '\0';
8959 type1String[0] = '\0';
8960 type2String[0] = '\0';
8963 PrintExpression(exp.op.exp1, expString1);
8964 ChangeCh(expString1, '\n', ' ');
8965 PrintExpression(exp.op.exp2, expString2);
8966 ChangeCh(expString2, '\n', ' ');
8967 PrintType(exp.op.exp1.expType, type1String, false, true);
8968 PrintType(exp.op.exp2.expType, type2String, false, true);
8971 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8973 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8975 exp.expType = exp.op.exp1.expType;
8976 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8978 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8980 exp.expType = exp.op.exp2.expType;
8981 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8989 // Maybe this was meant to be an enum...
8990 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8992 Type oldType = exp.op.exp1.expType;
8993 exp.op.exp1.expType = null;
8994 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8997 exp.op.exp1.expType = oldType;
9000 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9001 exp.op.exp1.destType = type2;
9004 // TESTING THIS HERE... LATEST ADDITION
9005 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9007 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9008 exp.op.exp1.destType = type1._class.registered.dataType;
9009 if(type1._class.registered.dataType)
9010 type1._class.registered.dataType.refCount++;
9013 // TESTING THIS HERE... LATEST ADDITION
9014 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9016 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9017 exp.op.exp2.destType = type2._class.registered.dataType;
9018 if(type2._class.registered.dataType)
9019 type2._class.registered.dataType.refCount++;
9023 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9025 if(exp.expType) FreeType(exp.expType);
9026 exp.expType = exp.op.exp1.destType;
9027 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9031 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9033 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9035 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9036 // Convert e.g. / 4 into / 4.0
9037 exp.op.exp1.destType = type2._class.registered.dataType;
9038 if(type2._class.registered.dataType)
9039 type2._class.registered.dataType.refCount++;
9040 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9042 if(exp.op.op == '!')
9044 exp.expType = MkClassType("bool");
9045 exp.expType.truth = true;
9049 exp.expType = type2;
9050 if(type2) type2.refCount++;
9053 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9055 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9057 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9058 // Convert e.g. / 4 into / 4.0
9059 exp.op.exp2.destType = type1._class.registered.dataType;
9060 if(type1._class.registered.dataType)
9061 type1._class.registered.dataType.refCount++;
9062 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9064 exp.expType = type1;
9065 if(type1) type1.refCount++;
9070 if(exp.op.exp1 && !exp.op.exp1.expType)
9072 char expString[10000];
9073 expString[0] = '\0';
9076 PrintExpression(exp.op.exp1, expString);
9077 ChangeCh(expString, '\n', ' ');
9080 Compiler_Error($"couldn't determine type of %s\n", expString);
9082 if(exp.op.exp2 && !exp.op.exp2.expType)
9084 char expString[10240];
9085 expString[0] = '\0';
9088 PrintExpression(exp.op.exp2, expString);
9089 ChangeCh(expString, '\n', ' ');
9092 Compiler_Error($"couldn't determine type of %s\n", expString);
9097 FreeType(exp.expType);
9098 exp.expType = MkClassType("bool");
9099 exp.expType.truth = true;
9102 if(exp.op.op != SIZEOF)
9103 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9104 (!exp.op.exp2 || exp.op.exp2.isConstant);
9106 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9108 DeclareType(exp.op.exp2.expType, false, false);
9119 case extensionExpressionExp:
9122 exp.isConstant = true;
9123 for(e = exp.list->first; e; e = e.next)
9128 FreeType(e.destType);
9129 e.opDestType = exp.opDestType;
9130 e.destType = exp.destType;
9131 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9133 ProcessExpressionType(e);
9135 exp.destType.count--;
9136 if(!exp.expType && !e.next)
9138 exp.expType = e.expType;
9139 if(e.expType) e.expType.refCount++;
9142 exp.isConstant = false;
9145 // In case a cast became a member...
9146 e = exp.list->first;
9147 if(!e.next && e.type == memberExp)
9149 // Preserve prev, next
9150 Expression next = exp.next, prev = exp.prev;
9153 FreeType(exp.expType);
9154 FreeType(exp.destType);
9164 ProcessExpressionType(exp);
9171 exp.isConstant = true;
9173 ProcessExpressionType(exp.index.exp);
9174 if(!exp.index.exp.isConstant)
9175 exp.isConstant = false;
9177 if(exp.index.exp.expType)
9179 Type source = exp.index.exp.expType;
9180 if(source.kind == classType && source._class && source._class.registered)
9182 Class _class = source._class.registered;
9183 Class c = _class.templateClass ? _class.templateClass : _class;
9184 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9186 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9188 if(exp.index.index && exp.index.index->last)
9190 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9192 if(type.kind == classType) type.constant = true;
9193 else if(type.kind == pointerType)
9196 while(t.kind == pointerType) t = t.type;
9200 ((Expression)exp.index.index->last).destType = type;
9206 for(e = exp.index.index->first; e; e = e.next)
9208 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9210 if(e.destType) FreeType(e.destType);
9211 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9213 ProcessExpressionType(e);
9216 // Check if this type is int
9219 exp.isConstant = false;
9223 exp.expType = Dereference(exp.index.exp.expType);
9225 DeclareType(exp.expType, false, false);
9232 Type methodType = null;
9238 PrintExpression(exp.call.exp, name);
9239 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9241 //exp.call.exp.expType = null;
9242 PrintExpression(exp.call.exp, name);
9245 if(exp.call.exp.type == identifierExp)
9247 Expression idExp = exp.call.exp;
9248 Identifier id = idExp.identifier;
9249 if(!strcmp(id.string, "__builtin_frame_address"))
9251 exp.expType = ProcessTypeString("void *", true);
9252 if(exp.call.arguments && exp.call.arguments->first)
9253 ProcessExpressionType(exp.call.arguments->first);
9256 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9258 exp.expType = ProcessTypeString("int", true);
9259 if(exp.call.arguments && exp.call.arguments->first)
9260 ProcessExpressionType(exp.call.arguments->first);
9263 else if(!strcmp(id.string, "Max") ||
9264 !strcmp(id.string, "Min") ||
9265 !strcmp(id.string, "Sgn") ||
9266 !strcmp(id.string, "Abs"))
9268 Expression a = null;
9269 Expression b = null;
9270 Expression tempExp1 = null, tempExp2 = null;
9271 if((!strcmp(id.string, "Max") ||
9272 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9274 a = exp.call.arguments->first;
9275 b = exp.call.arguments->last;
9279 else if(exp.call.arguments->count == 1)
9281 a = exp.call.arguments->first;
9287 exp.call.arguments->Clear();
9288 idExp.identifier = null;
9290 FreeExpContents(exp);
9292 ProcessExpressionType(a);
9294 ProcessExpressionType(b);
9296 exp.type = bracketsExp;
9297 exp.list = MkList();
9299 if(a.expType && (!b || b.expType))
9301 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9303 // Use the simpleStruct name/ids for now...
9306 OldList * specs = MkList();
9307 OldList * decls = MkList();
9309 char temp1[1024], temp2[1024];
9311 GetTypeSpecs(a.expType, specs);
9313 if(a && !a.isConstant && a.type != identifierExp)
9315 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9316 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9317 tempExp1 = QMkExpId(temp1);
9318 tempExp1.expType = a.expType;
9320 a.expType.refCount++;
9321 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9323 if(b && !b.isConstant && b.type != identifierExp)
9325 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9326 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9327 tempExp2 = QMkExpId(temp2);
9328 tempExp2.expType = b.expType;
9330 b.expType.refCount++;
9331 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9334 decl = MkDeclaration(specs, decls);
9335 if(!curCompound.compound.declarations)
9336 curCompound.compound.declarations = MkList();
9337 curCompound.compound.declarations->Insert(null, decl);
9342 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9344 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9346 MkExpCondition(MkExpBrackets(MkListOne(
9347 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9348 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9349 exp.expType = a.expType;
9351 a.expType.refCount++;
9353 else if(!strcmp(id.string, "Abs"))
9356 MkExpCondition(MkExpBrackets(MkListOne(
9357 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9358 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9359 exp.expType = a.expType;
9361 a.expType.refCount++;
9363 else if(!strcmp(id.string, "Sgn"))
9365 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9367 MkExpCondition(MkExpBrackets(MkListOne(
9368 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9369 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9370 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9371 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9372 exp.expType = ProcessTypeString("int", false);
9375 FreeExpression(tempExp1);
9376 if(tempExp2) FreeExpression(tempExp2);
9390 if(!exp.call.exp.destType)
9392 exp.call.exp.destType = dummy;
9395 ProcessExpressionType(exp.call.exp);
9396 if(exp.call.exp.destType == dummy)
9399 exp.call.exp.destType = null;
9404 // Check argument types against parameter types
9405 functionType = exp.call.exp.expType;
9407 if(functionType && functionType.kind == TypeKind::methodType)
9409 methodType = functionType;
9410 functionType = methodType.method.dataType;
9412 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9413 // TOCHECK: Instead of doing this here could this be done per param?
9414 if(exp.call.exp.expType.usedClass)
9416 char typeString[1024];
9417 typeString[0] = '\0';
9419 Symbol back = functionType.thisClass;
9420 // Do not output class specifier here (thisclass was added to this)
9421 functionType.thisClass = null;
9422 PrintType(functionType, typeString, true, true);
9423 functionType.thisClass = back;
9425 if(strstr(typeString, "thisclass"))
9427 OldList * specs = MkList();
9430 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9432 decl = SpecDeclFromString(typeString, specs, null);
9434 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9435 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9436 exp.call.exp.expType.usedClass))
9437 thisClassParams = false;
9439 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9441 Class backupThisClass = thisClass;
9442 thisClass = exp.call.exp.expType.usedClass;
9443 ProcessDeclarator(decl);
9444 thisClass = backupThisClass;
9447 thisClassParams = true;
9449 functionType = ProcessType(specs, decl);
9450 functionType.refCount = 0;
9451 FinishTemplatesContext(context);
9454 FreeList(specs, FreeSpecifier);
9455 FreeDeclarator(decl);
9459 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9461 Type type = functionType.type;
9462 if(!functionType.refCount)
9464 functionType.type = null;
9465 FreeType(functionType);
9467 //methodType = functionType;
9468 functionType = type;
9470 if(functionType && functionType.kind != TypeKind::functionType)
9472 Compiler_Error($"called object %s is not a function\n", name);
9474 else if(functionType)
9476 bool emptyParams = false, noParams = false;
9477 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9478 Type type = functionType.params.first;
9479 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9481 Location oldyylloc = yylloc;
9483 if(!type) emptyParams = true;
9486 if(functionType.extraParam && e && functionType.thisClass)
9488 e.destType = MkClassType(functionType.thisClass.string);
9492 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9493 // Fixed #141 by adding '&& !functionType.extraParam'
9494 if(!functionType.staticMethod && !functionType.extraParam)
9496 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9497 memberExp.member.exp.expType._class)
9499 type = MkClassType(memberExp.member.exp.expType._class.string);
9504 type = functionType.params.first;
9509 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9511 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9512 type.byReference = functionType.byReference;
9513 type.typedByReference = functionType.typedByReference;
9516 // Allow manually passing a class for typed object
9517 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9521 type = functionType.params.first;
9529 if(type && type.kind == voidType)
9532 if(!type.refCount) FreeType(type);
9536 for( ; e; e = e.next)
9538 if(!type && !emptyParams)
9541 if(methodType && methodType.methodClass)
9542 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9543 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9544 noParams ? 0 : functionType.params.count);
9546 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9547 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9548 noParams ? 0 : functionType.params.count);
9552 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9554 Type templatedType = null;
9555 Class _class = methodType.usedClass;
9556 ClassTemplateParameter curParam = null;
9558 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9561 for(sClass = _class; sClass; sClass = sClass.base)
9563 if(sClass.templateClass) sClass = sClass.templateClass;
9565 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9567 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9570 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9572 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9573 id += nextClass.templateParams.count;
9582 if(curParam && _class.templateArgs[id].dataTypeString)
9584 bool constant = type.constant;
9585 ClassTemplateArgument arg = _class.templateArgs[id];
9587 Context context = SetupTemplatesContext(_class);
9590 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9591 templatedType = ProcessTypeString(arg.dataTypeString, false);
9592 FinishTemplatesContext(context);
9595 if(templatedType.kind == classType && constant) templatedType.constant = true;
9596 else if(templatedType.kind == pointerType)
9598 Type t = templatedType.type;
9599 while(t.kind == pointerType) t = t.type;
9600 if(constant) t.constant = constant;
9603 e.destType = templatedType;
9606 templatedType.passAsTemplate = true;
9607 // templatedType.refCount++;
9613 if(type) type.refCount++;
9618 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9620 e.destType = type.prev;
9621 e.destType.refCount++;
9626 if(type) type.refCount++;
9629 // Don't reach the end for the ellipsis
9630 if(type && type.kind != ellipsisType)
9632 Type next = type.next;
9633 if(!type.refCount) FreeType(type);
9638 if(type && type.kind != ellipsisType)
9640 if(methodType && methodType.methodClass)
9641 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9642 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9643 functionType.params.count + extra);
9645 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9646 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9647 functionType.params.count + extra);
9650 if(type && !type.refCount) FreeType(type);
9657 kind = TypeKind::functionType;
9660 if(exp.call.exp.type == identifierExp)
9662 char * string = exp.call.exp.identifier.string;
9666 Location oldyylloc = yylloc;
9668 yylloc = exp.call.exp.identifier.loc;
9669 if(strstr(string, "__builtin_") == string)
9673 functionType.returnType = exp.destType;
9674 exp.destType.refCount++;
9678 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9679 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9680 globalContext.symbols.Add((BTNode)symbol);
9681 if(strstr(symbol.string, "::"))
9682 globalContext.hasNameSpace = true;
9687 else if(exp.call.exp.type == memberExp)
9689 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9690 exp.call.exp.member.member.string);*/
9693 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9695 if(!functionType.returnType)
9697 functionType.returnType = Type
9704 if(functionType && functionType.kind == TypeKind::functionType)
9706 exp.expType = functionType.returnType;
9708 if(functionType.returnType)
9709 functionType.returnType.refCount++;
9711 if(!functionType.refCount)
9712 FreeType(functionType);
9715 if(exp.call.arguments)
9717 for(e = exp.call.arguments->first; e; e = e.next)
9719 Type destType = e.destType;
9720 ProcessExpressionType(e);
9728 Location oldyylloc = yylloc;
9730 Expression checkExp = exp.member.exp;
9733 if(checkExp.type == castExp)
9734 checkExp = checkExp.cast.exp;
9735 else if(checkExp.type == bracketsExp)
9736 checkExp = checkExp.list ? checkExp.list->first : null;
9741 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9742 exp.thisPtr = thisPtr;
9744 // DOING THIS LATER NOW...
9745 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9747 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9748 /* TODO: Name Space Fix ups
9749 if(!exp.member.member.classSym)
9750 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9754 ProcessExpressionType(exp.member.exp);
9755 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9756 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9758 exp.isConstant = false;
9761 exp.isConstant = exp.member.exp.isConstant;
9762 type = exp.member.exp.expType;
9766 if(type && (type.kind == templateType))
9768 Class _class = thisClass ? thisClass : currentClass;
9769 ClassTemplateParameter param = null;
9772 for(param = _class.templateParams.first; param; param = param.next)
9774 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9778 if(param && param.defaultArg.member)
9780 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9783 Expression expMember = exp.member.exp;
9785 OldList * specs = MkList();
9786 char thisClassTypeString[1024];
9788 FreeIdentifier(exp.member.member);
9790 ProcessExpressionType(argExp);
9793 char * colon = strstr(param.defaultArg.memberString, "::");
9796 char className[1024];
9799 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9800 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9803 strcpy(thisClassTypeString, _class.fullName);
9806 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9808 exp.expType = ProcessType(specs, decl);
9809 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9811 Class expClass = exp.expType._class.registered;
9812 Class cClass = null;
9817 char templateString[1024];
9818 ClassTemplateParameter param;
9819 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9820 for(cClass = expClass; cClass; cClass = cClass.base)
9823 for(param = cClass.templateParams.first; param; param = param.next)
9827 ClassTemplateArgument arg;
9828 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9829 arg = expClass.templateArgs[id];
9831 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9833 ClassTemplateParameter cParam;
9834 //int p = numParams - sClass.templateParams.count;
9837 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9839 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9841 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9843 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9845 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9846 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9858 strcat(argument, arg.name.string);
9859 strcat(argument, " = ");
9865 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9866 char expString[1024];
9867 OldList * specs = MkList();
9868 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9870 char * string = PrintHexUInt64(arg.expression.ui64);
9871 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9874 ProcessExpressionType(exp);
9875 ComputeExpression(exp);
9876 expString[0] = '\0';
9877 PrintExpression(exp, expString);
9878 strcat(argument, expString);
9880 FreeExpression(exp);
9885 strcat(argument, arg.member.name);
9888 case TemplateParameterType::type:
9890 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9892 if(!strcmp(arg.dataTypeString, "thisclass"))
9893 strcat(argument, thisClassTypeString);
9895 strcat(argument, arg.dataTypeString);
9902 if(paramCount) strcat(templateString, ", ");
9903 if(lastParam != p - 1)
9905 strcat(templateString, param.name);
9906 strcat(templateString, " = ");
9908 strcat(templateString, argument);
9917 int len = strlen(templateString);
9918 if(templateString[len-1] == '>') templateString[len++] = ' ';
9919 templateString[len++] = '>';
9920 templateString[len++] = '\0';
9923 Context context = SetupTemplatesContext(_class);
9924 FreeType(exp.expType);
9925 exp.expType = ProcessTypeString(templateString, false);
9926 FinishTemplatesContext(context);
9930 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9931 exp.type = bracketsExp;
9932 exp.list = MkListOne(MkExpOp(null, '*',
9937 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9938 MkExpBrackets(MkListOne(
9939 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9941 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9943 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9948 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9949 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9951 type = ProcessTemplateParameterType(type.templateParameter);
9954 // TODO: *** This seems to be where we should add method support for all basic types ***
9955 if(type && (type.kind == templateType));
9956 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9957 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9958 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9959 (type.kind == pointerType && type.type.kind == charType)))
9961 Identifier id = exp.member.member;
9962 TypeKind typeKind = type.kind;
9963 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9964 if(typeKind == subClassType && exp.member.exp.type == classExp)
9966 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9967 typeKind = classType;
9972 if(typeKind == intType || typeKind == enumType)
9973 _class = eSystem_FindClass(privateModule, "int");
9976 if(type.kind == classType && type._class && type._class.registered)
9978 _class = type._class.registered;
9980 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9982 _class = FindClass("char *").registered;
9984 else if(type.kind == pointerType)
9986 _class = eSystem_FindClass(privateModule, "uintptr");
9987 FreeType(exp.expType);
9988 exp.expType = ProcessTypeString("uintptr", false);
9989 exp.byReference = true;
9993 char string[1024] = "";
9995 PrintTypeNoConst(type, string, false, true);
9996 classSym = FindClass(string);
9997 if(classSym) _class = classSym.registered;
10005 (exp.member.exp.type == identifierExp &&
10006 !strcmp(exp.member.exp.identifier.string, "this"));*/
10007 Property prop = null;
10008 Method method = null;
10009 DataMember member = null;
10010 Property revConvert = null;
10011 ClassProperty classProp = null;
10013 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10014 exp.member.memberType = propertyMember;
10016 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10017 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10019 if(typeKind != subClassType)
10021 // Prioritize data members over properties for "this"
10022 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10024 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10025 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10027 prop = eClass_FindProperty(_class, id.string, privateModule);
10031 if(!member && !prop)
10032 prop = eClass_FindProperty(_class, id.string, privateModule);
10033 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10034 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10035 exp.member.thisPtr = true;
10037 // Prioritize properties over data members otherwise
10040 bool useMemberForNonConst = false;
10041 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10044 prop = eClass_FindProperty(_class, id.string, null);
10046 useMemberForNonConst = prop && exp.destType &&
10047 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10048 !strncmp(prop.dataTypeString, "const ", 6);
10050 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10051 member = eClass_FindDataMember(_class, id.string, null, null, null);
10054 if((!prop || useMemberForNonConst) && !member)
10056 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10059 prop = eClass_FindProperty(_class, id.string, privateModule);
10061 useMemberForNonConst |= prop && exp.destType &&
10062 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10063 !strncmp(prop.dataTypeString, "const ", 6);
10065 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10066 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10072 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10079 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10080 method = eClass_FindMethod(_class, id.string, privateModule);
10081 if(!prop && !member && !method)
10083 if(typeKind == subClassType)
10085 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10088 exp.member.memberType = classPropertyMember;
10089 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10093 // Assume this is a class_data member
10094 char structName[1024];
10095 Identifier id = exp.member.member;
10096 Expression classExp = exp.member.exp;
10099 FreeType(classExp.expType);
10100 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10102 strcpy(structName, "__ecereClassData_");
10103 FullClassNameCat(structName, type._class.string, false);
10104 exp.type = pointerExp;
10105 exp.member.member = id;
10107 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10108 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10109 MkExpBrackets(MkListOne(MkExpOp(
10110 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10111 MkExpMember(classExp, MkIdentifier("data"))), '+',
10112 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10117 ProcessExpressionType(exp);
10123 // Check for reverse conversion
10124 // (Convert in an instantiation later, so that we can use
10125 // deep properties system)
10126 Symbol classSym = FindClass(id.string);
10129 Class convertClass = classSym.registered;
10131 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10138 exp.member.memberType = propertyMember;
10140 ProcessPropertyType(prop);
10141 exp.expType = prop.dataType;
10142 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10145 CopyTypeInto(type, exp.expType);
10147 type.constant = true;
10148 exp.expType = type;
10150 else if(prop.dataType)
10151 prop.dataType.refCount++;
10155 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10157 FreeExpContents(exp);
10158 exp.type = identifierExp;
10159 exp.identifier = MkIdentifier("class");
10160 ProcessExpressionType(exp);
10164 exp.member.memberType = dataMember;
10165 DeclareStruct(_class.fullName, false);
10166 if(!member.dataType)
10168 Context context = SetupTemplatesContext(_class);
10169 member.dataType = ProcessTypeString(member.dataTypeString, false);
10170 FinishTemplatesContext(context);
10172 exp.expType = member.dataType;
10173 if(member.dataType) member.dataType.refCount++;
10175 else if(revConvert)
10177 exp.member.memberType = reverseConversionMember;
10178 exp.expType = MkClassType(revConvert._class.fullName);
10186 exp.type = identifierExp;
10187 exp.identifier = exp.member.member;
10190 exp.member.memberType = methodMember;
10192 if(!method.dataType)
10193 ProcessMethodType(method);
10201 // Tricky spot here... To use instance versus class virtual table
10202 // Put it back to what it was... What did we break?
10204 // Had to put it back for overriding Main of Thread global instance
10206 //exp.expType.methodClass = _class;
10207 exp.expType.methodClass = (id && id._class) ? _class : null;
10209 // Need the actual class used for templated classes
10210 exp.expType.usedClass = _class;
10212 else if(!classProp)
10214 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10216 FreeExpContents(exp);
10217 exp.type = identifierExp;
10218 exp.identifier = MkIdentifier("class");
10219 FreeType(exp.expType);
10220 exp.expType = MkClassType("ecere::com::Class");
10223 yylloc = exp.member.member.loc;
10224 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10226 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10229 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10234 while(tClass && !tClass.templateClass) tClass = tClass.base;
10236 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10239 ClassTemplateParameter curParam = null;
10242 for(sClass = tClass; sClass; sClass = sClass.base)
10245 if(sClass.templateClass) sClass = sClass.templateClass;
10246 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10248 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10250 for(sClass = sClass.base; sClass; sClass = sClass.base)
10251 id += sClass.templateParams.count;
10256 if(curParam) break;
10259 if(curParam && tClass.templateArgs[id].dataTypeString)
10261 ClassTemplateArgument arg = tClass.templateArgs[id];
10262 Context context = SetupTemplatesContext(tClass);
10263 bool constant = exp.expType.constant;
10264 /*if(!arg.dataType)
10265 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10266 FreeType(exp.expType);
10268 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10269 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10270 else if(exp.expType.kind == pointerType)
10272 Type t = exp.expType.type;
10273 while(t.kind == pointerType) t = t.type;
10274 if(constant) t.constant = constant;
10278 if(exp.expType.kind == thisClassType)
10280 FreeType(exp.expType);
10281 exp.expType = ReplaceThisClassType(_class);
10284 if(tClass.templateClass)
10285 exp.expType.passAsTemplate = true;
10286 //exp.expType.refCount++;
10289 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10290 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10291 else if(exp.destType.kind == pointerType)
10293 Type t = exp.destType.type;
10294 while(t.kind == pointerType) t = t.type;
10295 if(constant) t.constant = constant;
10298 //exp.destType.refCount++;
10300 if(exp.destType.kind == thisClassType)
10302 FreeType(exp.destType);
10303 exp.destType = ReplaceThisClassType(_class);
10307 FinishTemplatesContext(context);
10310 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10311 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10314 ClassTemplateParameter curParam = null;
10317 for(sClass = tClass; sClass; sClass = sClass.base)
10320 if(sClass.templateClass) sClass = sClass.templateClass;
10321 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10323 if(curParam.type == TemplateParameterType::type &&
10324 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10326 for(sClass = sClass.base; sClass; sClass = sClass.base)
10327 id += sClass.templateParams.count;
10332 if(curParam) break;
10337 ClassTemplateArgument arg = tClass.templateArgs[id];
10338 Context context = SetupTemplatesContext(tClass);
10340 /*if(!arg.dataType)
10341 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10343 basicType = ProcessTypeString(arg.dataTypeString, false);
10346 if(basicType.kind == thisClassType)
10348 FreeType(basicType);
10349 basicType = ReplaceThisClassType(_class);
10352 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10353 if(tClass.templateClass)
10354 basicType.passAsTemplate = true;
10357 FreeType(exp.expType);
10359 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10360 //exp.expType.refCount++;
10363 exp.destType = exp.expType;
10364 exp.destType.refCount++;
10368 Expression newExp { };
10369 OldList * specs = MkList();
10371 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10373 if(exp.destType) exp.destType.refCount++;
10374 if(exp.expType) exp.expType.refCount++;
10375 exp.type = castExp;
10376 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10377 exp.cast.exp = newExp;
10378 //FreeType(exp.expType);
10379 //exp.expType = null;
10380 //ProcessExpressionType(sourceExp);
10383 FinishTemplatesContext(context);
10386 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10388 Class expClass = exp.expType._class.registered;
10391 Class cClass = null;
10394 int paramCount = 0;
10395 int lastParam = -1;
10396 char templateString[1024];
10397 ClassTemplateParameter param;
10398 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10399 while(cClass != expClass)
10402 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10405 for(param = cClass.templateParams.first; param; param = param.next)
10407 Class cClassCur = null;
10410 ClassTemplateParameter paramCur = null;
10411 ClassTemplateArgument arg;
10412 while(cClassCur != tClass && !paramCur)
10415 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10416 cClassCur = sClassCur;
10418 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10420 if(!strcmp(paramCur.name, param.name))
10428 if(paramCur && paramCur.type == TemplateParameterType::type)
10429 arg = tClass.templateArgs[cp];
10431 arg = expClass.templateArgs[p];
10434 char argument[256];
10435 argument[0] = '\0';
10438 strcat(argument, arg.name.string);
10439 strcat(argument, " = ");
10445 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10446 char expString[1024];
10447 OldList * specs = MkList();
10448 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10450 char * string = PrintHexUInt64(arg.expression.ui64);
10451 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10454 ProcessExpressionType(exp);
10455 ComputeExpression(exp);
10456 expString[0] = '\0';
10457 PrintExpression(exp, expString);
10458 strcat(argument, expString);
10460 FreeExpression(exp);
10465 strcat(argument, arg.member.name);
10468 case TemplateParameterType::type:
10470 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10471 strcat(argument, arg.dataTypeString);
10477 if(paramCount) strcat(templateString, ", ");
10478 if(lastParam != p - 1)
10480 strcat(templateString, param.name);
10481 strcat(templateString, " = ");
10483 strcat(templateString, argument);
10492 int len = strlen(templateString);
10493 if(templateString[len-1] == '>') templateString[len++] = ' ';
10494 templateString[len++] = '>';
10495 templateString[len++] = '\0';
10498 FreeType(exp.expType);
10500 Context context = SetupTemplatesContext(tClass);
10501 exp.expType = ProcessTypeString(templateString, false);
10502 FinishTemplatesContext(context);
10509 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10511 else if(type && (type.kind == structType || type.kind == unionType))
10513 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10516 exp.expType = memberType;
10518 memberType.refCount++;
10523 char expString[10240];
10524 expString[0] = '\0';
10525 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10526 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10529 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10531 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10533 Identifier id = exp.member.member;
10534 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10537 FreeType(exp.expType);
10538 exp.expType = ReplaceThisClassType(_class);
10542 yylloc = oldyylloc;
10545 // Convert x->y into (*x).y
10548 Type destType = exp.destType;
10550 // DOING THIS LATER NOW...
10551 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10553 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10554 /* TODO: Name Space Fix ups
10555 if(!exp.member.member.classSym)
10556 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10560 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10561 exp.type = memberExp;
10564 ProcessExpressionType(exp);
10571 //ComputeExpression(exp);
10573 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10574 if(classSym && classSym.registered)
10576 if(classSym.registered.type == noHeadClass)
10580 DeclareStruct(classSym.string, false);
10581 FreeSpecifier(exp._class);
10582 exp.type = typeSizeExp;
10583 FullClassNameCat(name, classSym.string, false);
10584 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10588 if(classSym.registered.fixed)
10590 FreeSpecifier(exp._class);
10591 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10592 exp.type = constantExp;
10596 char className[1024];
10597 strcpy(className, "__ecereClass_");
10598 FullClassNameCat(className, classSym.string, true);
10599 MangleClassName(className);
10601 DeclareClass(classSym, className);
10603 FreeExpContents(exp);
10604 exp.type = pointerExp;
10605 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10606 exp.member.member = MkIdentifier("structSize");
10614 kind = intSizeType;
10616 // exp.isConstant = true;
10621 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10626 kind = intSizeType;
10628 exp.isConstant = true;
10630 DeclareType(type, false, false);
10636 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10638 FreeType(exp.cast.exp.destType);
10639 exp.cast.exp.destType = type;
10641 type.casted = true;
10642 ProcessExpressionType(exp.cast.exp);
10643 type.casted = false;
10645 exp.expType = type;
10648 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10649 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10651 void * prev = exp.prev, * next = exp.next;
10652 Type expType = exp.cast.exp.destType;
10653 Expression castExp = exp.cast.exp;
10654 Type destType = exp.destType;
10656 if(expType) expType.refCount++;
10658 //FreeType(exp.destType);
10659 FreeType(exp.expType);
10660 FreeTypeName(exp.cast.typeName);
10663 FreeType(exp.expType);
10664 FreeType(exp.destType);
10666 exp.expType = expType;
10667 exp.destType = destType;
10677 exp.isConstant = exp.cast.exp.isConstant;
10682 case extensionInitializerExp:
10684 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10685 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10686 // ProcessInitializer(exp.initializer.initializer, type);
10687 exp.expType = type;
10692 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10693 ProcessExpressionType(exp.vaArg.exp);
10694 exp.expType = type;
10700 exp.isConstant = true;
10702 FreeType(exp.cond.cond.destType);
10703 exp.cond.cond.destType = MkClassType("bool");
10704 exp.cond.cond.destType.truth = true;
10705 ProcessExpressionType(exp.cond.cond);
10706 if(!exp.cond.cond.isConstant)
10707 exp.isConstant = false;
10708 for(e = exp.cond.exp->first; e; e = e.next)
10712 FreeType(e.destType);
10713 e.destType = exp.destType;
10714 if(e.destType) e.destType.refCount++;
10716 ProcessExpressionType(e);
10719 exp.expType = e.expType;
10720 if(e.expType) e.expType.refCount++;
10723 exp.isConstant = false;
10726 FreeType(exp.cond.elseExp.destType);
10727 // Added this check if we failed to find an expType
10728 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10731 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10733 if(exp.cond.elseExp.destType)
10734 exp.cond.elseExp.destType.refCount++;
10735 ProcessExpressionType(exp.cond.elseExp);
10737 // FIXED THIS: Was done before calling process on elseExp
10738 if(!exp.cond.elseExp.isConstant)
10739 exp.isConstant = false;
10742 case extensionCompoundExp:
10744 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10746 Statement last = exp.compound.compound.statements->last;
10747 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10749 ((Expression)last.expressions->last).destType = exp.destType;
10751 exp.destType.refCount++;
10753 ProcessStatement(exp.compound);
10754 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10756 exp.expType.refCount++;
10762 Specifier spec = exp._classExp.specifiers->first;
10763 if(spec && spec.type == nameSpecifier)
10765 exp.expType = MkClassType(spec.name);
10766 exp.expType.kind = subClassType;
10767 exp.byReference = true;
10771 exp.expType = MkClassType("ecere::com::Class");
10772 exp.byReference = true;
10778 Class _class = thisClass ? thisClass : currentClass;
10781 Identifier id = exp.classData.id;
10782 char structName[1024];
10783 Expression classExp;
10784 strcpy(structName, "__ecereClassData_");
10785 FullClassNameCat(structName, _class.fullName, false);
10786 exp.type = pointerExp;
10787 exp.member.member = id;
10788 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10789 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10791 classExp = MkExpIdentifier(MkIdentifier("class"));
10793 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10794 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10795 MkExpBrackets(MkListOne(MkExpOp(
10796 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10797 MkExpMember(classExp, MkIdentifier("data"))), '+',
10798 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10801 ProcessExpressionType(exp);
10809 const char * typeString = null;
10810 char typeStringBuf[1024];
10811 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10812 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10814 Class templateClass = exp.destType._class.registered;
10815 typeString = templateClass.templateArgs[2].dataTypeString;
10819 // Guess type from expressions in the array
10821 for(e = exp.list->first; e; e = e.next)
10823 ProcessExpressionType(e);
10826 if(!type) { type = e.expType; type.refCount++; }
10829 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10830 if(!MatchTypeExpression(e, type, null, false, true))
10836 e = exp.list->first;
10837 ProcessExpressionType(e);
10840 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10841 if(!MatchTypeExpression(e, type, null, false, true))
10843 FreeType(e.expType);
10854 FreeType(e.expType);
10861 typeStringBuf[0] = '\0';
10862 PrintTypeNoConst(type, typeStringBuf, false, true);
10863 typeString = typeStringBuf;
10871 (Container)& (struct BuiltInContainer)
10873 ._vTbl = class(BuiltInContainer)._vTbl,
10874 ._class = class(BuiltInContainer),
10876 .data = (int[]){ 1, 7, 3, 4, 5 },
10878 .type = class(int),
10881 char templateString[1024];
10882 OldList * initializers = MkList();
10883 OldList * structInitializers = MkList();
10884 OldList * specs = MkList();
10886 Declarator decl = SpecDeclFromString(typeString, specs, null);
10887 sprintf(templateString, "Container<%s>", typeString);
10892 type = ProcessTypeString(typeString, false);
10893 while(e = exp.list->first)
10895 exp.list->Remove(e);
10898 ProcessExpressionType(e);
10899 ListAdd(initializers, MkInitializerAssignment(e));
10905 DeclareStruct("ecere::com::BuiltInContainer", false);
10907 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10908 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10909 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10910 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10911 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10912 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10913 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10914 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10915 MkInitializerList(initializers))));
10916 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10917 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10918 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10919 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10920 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10921 exp.expType = ProcessTypeString(templateString, false);
10922 exp.type = bracketsExp;
10923 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10925 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10926 MkInitializerList(structInitializers)))));
10927 ProcessExpressionType(expExt);
10931 exp.expType = ProcessTypeString("Container", false);
10932 Compiler_Error($"Couldn't determine type of array elements\n");
10938 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10940 FreeType(exp.expType);
10941 exp.expType = ReplaceThisClassType(thisClass);
10944 // Resolve structures here
10945 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10947 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10948 // TODO: Fix members reference...
10951 if(exp.expType.kind != enumType)
10954 String enumName = CopyString(exp.expType.enumName);
10956 // Fixed a memory leak on self-referencing C structs typedefs
10957 // by instantiating a new type rather than simply copying members
10958 // into exp.expType
10959 FreeType(exp.expType);
10960 exp.expType = Type { };
10961 exp.expType.kind = symbol.type.kind;
10962 exp.expType.refCount++;
10963 exp.expType.enumName = enumName;
10965 exp.expType.members = symbol.type.members;
10966 for(member = symbol.type.members.first; member; member = member.next)
10972 for(member = symbol.type.members.first; member; member = member.next)
10974 NamedLink value { name = CopyString(member.name) };
10975 exp.expType.members.Add(value);
10982 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10983 else if(exp.destType && !exp.destType.keepCast)
10985 if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
10987 if(!exp.destType.count || unresolved)
10992 if(exp.destType.kind != ellipsisType)
10998 char expString[10240];
10999 expString[0] = '\0';
11001 PrintType(exp.destType, type2, false, true);
11003 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11005 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11006 else if(exp.type != dummyExp)
11007 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11012 char expString[10240] ;
11013 expString[0] = '\0';
11014 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11017 Compiler_Error($"unresolved identifier %s\n", expString);
11018 else if(exp.type != dummyExp)
11019 Compiler_Error($"couldn't determine type of %s\n", expString);
11030 PrintType(exp.expType, type1, false, true);
11031 PrintType(exp.destType, type2, false, true);
11034 //CheckExpressionType(exp, exp.destType, false);
11036 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11037 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11038 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11041 char expString[10240];
11042 expString[0] = '\0';
11043 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11046 CheckExpressionType(exp, exp.destType, false, true);
11048 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11049 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
11050 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11052 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11053 FreeType(exp.expType);
11054 exp.destType.refCount++;
11055 exp.expType = exp.destType;
11060 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
11062 Expression newExp { };
11063 char typeString[1024];
11064 OldList * specs = MkList();
11067 typeString[0] = '\0';
11071 if(exp.expType) exp.expType.refCount++;
11072 if(exp.expType) exp.expType.refCount++;
11073 exp.type = castExp;
11074 newExp.destType = exp.expType;
11076 PrintType(exp.expType, typeString, false, false);
11077 decl = SpecDeclFromString(typeString, specs, null);
11079 exp.cast.typeName = MkTypeName(specs, decl);
11080 exp.cast.exp = newExp;
11083 else if(unresolved)
11085 if(exp.identifier._class && exp.identifier._class.name)
11086 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11087 else if(exp.identifier.string && exp.identifier.string[0])
11088 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11090 else if(!exp.expType && exp.type != dummyExp)
11092 char expString[10240];
11093 expString[0] = '\0';
11094 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11095 Compiler_Error($"couldn't determine type of %s\n", expString);
11098 // Let's try to support any_object & typed_object here:
11100 ApplyAnyObjectLogic(exp);
11102 // Mark nohead classes as by reference, unless we're casting them to an integral type
11103 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11104 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11105 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11106 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11108 exp.byReference = true;
11110 yylloc = oldyylloc;
11113 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11115 // THIS CODE WILL FIND NEXT MEMBER...
11118 *curMember = (*curMember).next;
11120 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11122 *curMember = subMemberStack[--(*subMemberStackPos)];
11123 *curMember = (*curMember).next;
11126 // SKIP ALL PROPERTIES HERE...
11127 while((*curMember) && (*curMember).isProperty)
11128 *curMember = (*curMember).next;
11130 if(subMemberStackPos)
11132 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11134 subMemberStack[(*subMemberStackPos)++] = *curMember;
11136 *curMember = (*curMember).members.first;
11137 while(*curMember && (*curMember).isProperty)
11138 *curMember = (*curMember).next;
11146 if(subMemberStackPos && *subMemberStackPos)
11148 *curMember = subMemberStack[--(*subMemberStackPos)];
11149 *curMember = (*curMember).next;
11153 Class lastCurClass = *curClass;
11155 if(*curClass == _class) break; // REACHED THE END
11157 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11158 *curMember = (*curClass).membersAndProperties.first;
11161 while((*curMember) && (*curMember).isProperty)
11162 *curMember = (*curMember).next;
11163 if(subMemberStackPos)
11165 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11167 subMemberStack[(*subMemberStackPos)++] = *curMember;
11169 *curMember = (*curMember).members.first;
11170 while(*curMember && (*curMember).isProperty)
11171 *curMember = (*curMember).next;
11179 static void ProcessInitializer(Initializer init, Type type)
11183 case expInitializer:
11184 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11186 // TESTING THIS FOR SHUTTING = 0 WARNING
11187 if(init.exp && !init.exp.destType)
11189 FreeType(init.exp.destType);
11190 init.exp.destType = type;
11191 if(type) type.refCount++;
11195 ProcessExpressionType(init.exp);
11196 init.isConstant = init.exp.isConstant;
11202 Expression exp = init.exp;
11203 Instantiation inst = exp.instance;
11204 MembersInit members;
11206 init.type = listInitializer;
11207 init.list = MkList();
11211 for(members = inst.members->first; members; members = members.next)
11213 if(members.type == dataMembersInit)
11216 for(member = members.dataMembers->first; member; member = member.next)
11218 ListAdd(init.list, member.initializer);
11219 member.initializer = null;
11222 // Discard all MembersInitMethod
11225 FreeExpression(exp);
11227 case listInitializer:
11230 Type initializerType = null;
11231 Class curClass = null;
11232 DataMember curMember = null;
11233 DataMember subMemberStack[256];
11234 int subMemberStackPos = 0;
11236 if(type && type.kind == arrayType)
11237 initializerType = Dereference(type);
11238 else if(type && (type.kind == structType || type.kind == unionType))
11239 initializerType = type.members.first;
11241 for(i = init.list->first; i; i = i.next)
11243 if(type && type.kind == classType && type._class && type._class.registered)
11245 // 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)
11246 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11247 // TODO: Generate error on initializing a private data member this way from another module...
11250 if(!curMember.dataType)
11251 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11252 initializerType = curMember.dataType;
11255 ProcessInitializer(i, initializerType);
11256 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11257 initializerType = initializerType.next;
11259 init.isConstant = false;
11262 if(type && type.kind == arrayType)
11263 FreeType(initializerType);
11265 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11267 Compiler_Error($"Assigning list initializer to non list\n");
11274 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11278 case baseSpecifier:
11280 if(spec.specifier == THISCLASS)
11284 spec.type = nameSpecifier;
11285 spec.name = ReplaceThisClass(thisClass);
11286 spec.symbol = FindClass(spec.name);
11287 ProcessSpecifier(spec, declareStruct);
11292 case nameSpecifier:
11294 Symbol symbol = FindType(curContext, spec.name);
11296 DeclareType(symbol.type, true, true);
11297 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11298 DeclareStruct(spec.name, false);
11301 case enumSpecifier:
11306 for(e = spec.list->first; e; e = e.next)
11309 ProcessExpressionType(e.exp);
11314 case structSpecifier:
11315 case unionSpecifier:
11317 if(spec.definitions)
11320 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11322 ProcessClass(spec.definitions, symbol);
11325 for(def = spec.definitions->first; def; def = def.next)
11327 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11328 ProcessDeclaration(def.decl);
11335 case classSpecifier:
11337 Symbol classSym = FindClass(spec.name);
11338 if(classSym && classSym.registered && classSym.registered.type == structClass)
11339 DeclareStruct(spec.name, false);
11347 static void ProcessDeclarator(Declarator decl)
11351 case identifierDeclarator:
11352 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11354 FreeSpecifier(decl.identifier._class);
11355 decl.identifier._class = null;
11358 case arrayDeclarator:
11360 ProcessExpressionType(decl.array.exp);
11361 case structDeclarator:
11362 case bracketsDeclarator:
11363 case functionDeclarator:
11364 case pointerDeclarator:
11365 case extendedDeclarator:
11366 case extendedDeclaratorEnd:
11367 if(decl.declarator)
11368 ProcessDeclarator(decl.declarator);
11369 if(decl.type == functionDeclarator)
11371 Identifier id = GetDeclId(decl);
11372 if(id && id._class)
11376 qualifiers = MkListOne(id._class);
11379 if(!decl.function.parameters)
11380 decl.function.parameters = MkList();
11381 decl.function.parameters->Insert(null, param);
11384 if(decl.function.parameters)
11388 for(param = decl.function.parameters->first; param; param = param.next)
11390 if(param.qualifiers && param.qualifiers->first)
11392 Specifier spec = param.qualifiers->first;
11393 if(spec && spec.specifier == TYPED_OBJECT)
11395 Declarator d = param.declarator;
11398 qualifiers = MkListOne(MkSpecifier(VOID));
11399 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11401 if(d.type != pointerDeclarator)
11402 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11404 FreeList(param.qualifiers, FreeSpecifier);
11406 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11407 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11409 decl.function.parameters->Insert(param, newParam);
11412 else if(spec && spec.specifier == ANY_OBJECT)
11414 Declarator d = param.declarator;
11416 FreeList(param.qualifiers, FreeSpecifier);
11418 param.qualifiers = MkListOne(MkSpecifier(VOID));
11419 if(d.type != pointerDeclarator)
11420 param.qualifiers->Insert(null, MkSpecifier(CONST));
11421 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11423 else if(spec.specifier == THISCLASS)
11427 spec.type = nameSpecifier;
11428 spec.name = ReplaceThisClass(thisClass);
11429 spec.symbol = FindClass(spec.name);
11430 ProcessSpecifier(spec, false);
11435 if(param.declarator)
11436 ProcessDeclarator(param.declarator);
11444 static void ProcessDeclaration(Declaration decl)
11449 case initDeclaration:
11451 bool declareStruct = false;
11453 lineNum = decl.pos.line;
11454 column = decl.pos.col;
11457 if(decl.declarators)
11461 for(d = decl.declarators->first; d; d = d.next)
11463 Type type, subType;
11464 ProcessDeclarator(d.declarator);
11466 type = ProcessType(decl.specifiers, d.declarator);
11470 ProcessInitializer(d.initializer, type);
11472 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11474 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11475 d.initializer.exp.type == instanceExp)
11477 if(type.kind == classType && type._class ==
11478 d.initializer.exp.expType._class)
11480 Instantiation inst = d.initializer.exp.instance;
11481 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11483 d.initializer.exp.instance = null;
11484 if(decl.specifiers)
11485 FreeList(decl.specifiers, FreeSpecifier);
11486 FreeList(decl.declarators, FreeInitDeclarator);
11490 decl.type = instDeclaration;
11495 for(subType = type; subType;)
11497 if(subType.kind == classType)
11499 declareStruct = true;
11502 else if(subType.kind == pointerType)
11504 else if(subType.kind == arrayType)
11505 subType = subType.arrayType;
11515 if(decl.specifiers)
11518 for(s = decl.specifiers->first; s; s = s.next)
11520 ProcessSpecifier(s, declareStruct);
11525 case instDeclaration:
11527 ProcessInstantiationType(decl.inst);
11530 case structDeclaration:
11534 bool declareStruct = false;
11536 if(decl.declarators)
11538 for(d = decl.declarators->first; d; d = d.next)
11540 Type type = ProcessType(decl.specifiers, d.declarator);
11542 ProcessDeclarator(d);
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;
11560 if(decl.specifiers)
11562 for(spec = decl.specifiers->first; spec; spec = spec.next)
11563 ProcessSpecifier(spec, declareStruct);
11570 static FunctionDefinition curFunction;
11572 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11574 char propName[1024], propNameM[1024];
11575 char getName[1024], setName[1024];
11578 DeclareProperty(prop, setName, getName);
11580 // eInstance_FireWatchers(object, prop);
11581 strcpy(propName, "__ecereProp_");
11582 FullClassNameCat(propName, prop._class.fullName, false);
11583 strcat(propName, "_");
11584 // strcat(propName, prop.name);
11585 FullClassNameCat(propName, prop.name, true);
11586 MangleClassName(propName);
11588 strcpy(propNameM, "__ecerePropM_");
11589 FullClassNameCat(propNameM, prop._class.fullName, false);
11590 strcat(propNameM, "_");
11591 // strcat(propNameM, prop.name);
11592 FullClassNameCat(propNameM, prop.name, true);
11593 MangleClassName(propNameM);
11595 if(prop.isWatchable)
11598 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11599 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11600 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11603 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11604 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11605 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11611 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11612 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11613 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11616 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11617 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11618 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11621 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11622 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11623 curFunction.propSet.fireWatchersDone = true;
11626 static void ProcessStatement(Statement stmt)
11630 lineNum = stmt.pos.line;
11631 column = stmt.pos.col;
11636 ProcessStatement(stmt.labeled.stmt);
11639 // This expression should be constant...
11640 if(stmt.caseStmt.exp)
11642 FreeType(stmt.caseStmt.exp.destType);
11643 stmt.caseStmt.exp.destType = curSwitchType;
11644 if(curSwitchType) curSwitchType.refCount++;
11645 ProcessExpressionType(stmt.caseStmt.exp);
11646 ComputeExpression(stmt.caseStmt.exp);
11648 if(stmt.caseStmt.stmt)
11649 ProcessStatement(stmt.caseStmt.stmt);
11653 if(stmt.compound.context)
11658 Statement prevCompound = curCompound;
11659 Context prevContext = curContext;
11661 if(!stmt.compound.isSwitch)
11662 curCompound = stmt;
11663 curContext = stmt.compound.context;
11665 if(stmt.compound.declarations)
11667 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11668 ProcessDeclaration(decl);
11670 if(stmt.compound.statements)
11672 for(s = stmt.compound.statements->first; s; s = s.next)
11673 ProcessStatement(s);
11676 curContext = prevContext;
11677 curCompound = prevCompound;
11681 case expressionStmt:
11684 if(stmt.expressions)
11686 for(exp = stmt.expressions->first; exp; exp = exp.next)
11687 ProcessExpressionType(exp);
11695 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11696 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11697 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11698 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11700 ProcessExpressionType(exp);
11702 if(stmt.ifStmt.stmt)
11703 ProcessStatement(stmt.ifStmt.stmt);
11704 if(stmt.ifStmt.elseStmt)
11705 ProcessStatement(stmt.ifStmt.elseStmt);
11710 Type oldSwitchType = curSwitchType;
11711 if(stmt.switchStmt.exp)
11714 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11724 e.exp.destType = destType;
11727 ProcessExpressionType(exp);
11730 curSwitchType = exp.expType;
11733 ProcessStatement(stmt.switchStmt.stmt);
11734 curSwitchType = oldSwitchType;
11739 if(stmt.whileStmt.exp)
11743 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11744 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11745 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11746 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11748 ProcessExpressionType(exp);
11751 if(stmt.whileStmt.stmt)
11752 ProcessStatement(stmt.whileStmt.stmt);
11757 if(stmt.doWhile.exp)
11761 if(stmt.doWhile.exp->last)
11763 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11764 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11765 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11767 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11769 ProcessExpressionType(exp);
11772 if(stmt.doWhile.stmt)
11773 ProcessStatement(stmt.doWhile.stmt);
11779 if(stmt.forStmt.init)
11780 ProcessStatement(stmt.forStmt.init);
11782 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11784 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11785 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11786 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11789 if(stmt.forStmt.check)
11790 ProcessStatement(stmt.forStmt.check);
11791 if(stmt.forStmt.increment)
11793 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11794 ProcessExpressionType(exp);
11797 if(stmt.forStmt.stmt)
11798 ProcessStatement(stmt.forStmt.stmt);
11803 Identifier id = stmt.forEachStmt.id;
11804 OldList * exp = stmt.forEachStmt.exp;
11805 OldList * filter = stmt.forEachStmt.filter;
11806 Statement block = stmt.forEachStmt.stmt;
11807 char iteratorType[1024];
11810 bool isBuiltin = exp && exp->last &&
11811 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11812 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11813 Expression arrayExp;
11814 const char * typeString = null;
11815 int builtinCount = 0;
11817 for(e = exp ? exp->first : null; e; e = e.next)
11821 FreeType(e.destType);
11822 e.destType = ProcessTypeString("Container", false);
11824 if(!isBuiltin || e.next)
11825 ProcessExpressionType(e);
11828 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11829 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11830 eClass_IsDerived(source._class.registered, containerClass)))
11832 Class _class = source ? source._class.registered : null;
11834 Expression expIt = null;
11835 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
11836 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11837 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11838 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11839 stmt.type = compoundStmt;
11841 stmt.compound.context = Context { };
11842 stmt.compound.context.parent = curContext;
11843 curContext = stmt.compound.context;
11845 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11847 Class mapClass = eSystem_FindClass(privateModule, "Map");
11848 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11849 isCustomAVLTree = true;
11850 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
11852 else */if(eClass_IsDerived(source._class.registered, mapClass))
11855 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11856 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11858 Class listClass = eSystem_FindClass(privateModule, "List");
11860 isList = eClass_IsDerived(source._class.registered, listClass);
11866 OldList * specs = MkList();
11867 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11868 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11869 stmt.compound.declarations = MkListOne(
11870 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11871 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11872 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11873 MkInitializerAssignment(MkExpBrackets(exp))))));
11878 char typeStringBuf[1024];
11880 // TODO: Merge this code?
11881 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11882 if(((Expression)exp->last).type == castExp)
11884 TypeName typeName = ((Expression)exp->last).cast.typeName;
11886 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11889 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11890 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11891 arrayExp.destType._class.registered.templateArgs)
11893 Class templateClass = arrayExp.destType._class.registered;
11894 typeString = templateClass.templateArgs[2].dataTypeString;
11896 else if(arrayExp.list)
11898 // Guess type from expressions in the array
11900 for(e = arrayExp.list->first; e; e = e.next)
11902 ProcessExpressionType(e);
11905 if(!type) { type = e.expType; type.refCount++; }
11908 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11909 if(!MatchTypeExpression(e, type, null, false, true))
11915 e = arrayExp.list->first;
11916 ProcessExpressionType(e);
11919 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11920 if(!MatchTypeExpression(e, type, null, false, true))
11922 FreeType(e.expType);
11933 FreeType(e.expType);
11940 typeStringBuf[0] = '\0';
11941 PrintType(type, typeStringBuf, false, true);
11942 typeString = typeStringBuf;
11948 OldList * initializers = MkList();
11950 OldList * specs = MkList();
11955 builtinCount = arrayExp.list->count;
11956 type = ProcessTypeString(typeString, false);
11957 while(e = arrayExp.list->first)
11959 arrayExp.list->Remove(e);
11962 ProcessExpressionType(e);
11963 ListAdd(initializers, MkInitializerAssignment(e));
11966 delete arrayExp.list;
11968 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11969 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11970 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11972 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11974 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11975 ), MkInitializerList(initializers)))));
11976 FreeList(exp, FreeExpression);
11980 arrayExp.expType = ProcessTypeString("Container", false);
11981 Compiler_Error($"Couldn't determine type of array elements\n");
11986 OldList * specs = MkList();
11988 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11989 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11990 stmt.compound.declarations = MkListOne(
11991 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11992 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11993 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11994 MkInitializerAssignment(MkExpBrackets(exp))))));
11997 else if(isLinkList && !isList)
12000 OldList * specs = MkList();
12001 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12002 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12003 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12004 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12005 MkInitializerAssignment(MkExpBrackets(exp))))));
12007 /*else if(isCustomAVLTree)
12010 OldList * specs = MkList();
12011 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12012 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12013 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12014 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12015 MkInitializerAssignment(MkExpBrackets(exp))))));
12017 else if(_class.templateArgs)
12020 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12022 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12024 stmt.compound.declarations = MkListOne(
12025 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12026 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12027 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12029 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12033 // Reparent sub-contexts in this statement
12037 if(block.compound.context)
12038 block.compound.context.parent = stmt.compound.context;
12041 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12042 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12043 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12044 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12047 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12048 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12051 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12052 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12055 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12056 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12059 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12060 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12063 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12064 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12066 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12069 case expressionStmt:
12075 case badDeclarationStmt:
12076 case fireWatchersStmt:
12077 case stopWatchingStmt:
12084 block = MkIfStmt(filter, block, null);
12088 stmt.compound.statements = MkListOne(MkForStmt(
12089 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12090 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12091 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12092 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12094 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12095 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12096 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12101 //OldList * specs = MkList();
12102 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12104 sprintf(count, "%d", builtinCount);
12106 stmt.compound.statements = MkListOne(MkForStmt(
12107 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12108 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12109 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12110 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12114 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12115 stmt.compound.statements = MkListOne(MkForStmt(
12116 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12117 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12118 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12119 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12122 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12123 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12124 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12126 else if(isLinkList && !isList)
12128 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12129 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12130 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12131 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12133 stmt.compound.statements = MkListOne(MkForStmt(
12134 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12135 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12136 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12141 OldList * specs = MkList();
12142 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12143 stmt.compound.statements = MkListOne(MkForStmt(
12144 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12145 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12146 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12147 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12148 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12151 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12152 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12153 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12155 /*else if(isCustomAVLTree)
12157 stmt.compound.statements = MkListOne(MkForStmt(
12158 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12159 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12160 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12161 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12164 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12165 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12166 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12170 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12171 MkIdentifier("Next")), null)), block));
12173 ProcessExpressionType(expIt);
12174 if(stmt.compound.declarations->first)
12175 ProcessDeclaration(stmt.compound.declarations->first);
12178 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12180 ProcessStatement(stmt);
12181 curContext = stmt.compound.context.parent;
12186 Compiler_Error($"Expression is not a container\n");
12199 if(stmt.expressions)
12201 for(exp = stmt.expressions->first; exp; exp = exp.next)
12205 if(curFunction && !curFunction.type)
12206 curFunction.type = ProcessType(
12207 curFunction.specifiers, curFunction.declarator);
12208 FreeType(exp.destType);
12209 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12210 if(exp.destType) exp.destType.refCount++;
12212 ProcessExpressionType(exp);
12217 case badDeclarationStmt:
12219 ProcessDeclaration(stmt.decl);
12225 if(stmt.asmStmt.inputFields)
12227 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12228 if(field.expression)
12229 ProcessExpressionType(field.expression);
12231 if(stmt.asmStmt.outputFields)
12233 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12234 if(field.expression)
12235 ProcessExpressionType(field.expression);
12237 if(stmt.asmStmt.clobberedFields)
12239 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12241 if(field.expression)
12242 ProcessExpressionType(field.expression);
12249 PropertyWatch propWatch;
12250 OldList * watches = stmt._watch.watches;
12251 Expression object = stmt._watch.object;
12252 Expression watcher = stmt._watch.watcher;
12254 ProcessExpressionType(watcher);
12256 ProcessExpressionType(object);
12260 if(watcher || thisClass)
12262 External external = curExternal;
12263 Context context = curContext;
12265 stmt.type = expressionStmt;
12266 stmt.expressions = MkList();
12268 curExternal = external.prev;
12270 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12272 ClassFunction func;
12273 char watcherName[1024];
12274 Class watcherClass = watcher ?
12275 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12276 External createdExternal;
12278 // Create a declaration above
12279 External externalDecl = MkExternalDeclaration(null);
12280 ast->Insert(curExternal.prev, externalDecl);
12282 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12283 if(propWatch.deleteWatch)
12284 strcat(watcherName, "_delete");
12288 for(propID = propWatch.properties->first; propID; propID = propID.next)
12290 strcat(watcherName, "_");
12291 strcat(watcherName, propID.string);
12295 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12297 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12298 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12299 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12300 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12301 ProcessClassFunctionBody(func, propWatch.compound);
12302 propWatch.compound = null;
12304 //afterExternal = afterExternal ? afterExternal : curExternal;
12306 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12307 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12309 createdExternal.symbol.idCode = external.symbol.idCode;
12311 curExternal = createdExternal;
12312 ProcessFunction(createdExternal.function);
12315 // Create a declaration above
12317 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12318 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12319 externalDecl.declaration = decl;
12320 if(decl.symbol && !decl.symbol.pointerExternal)
12321 decl.symbol.pointerExternal = externalDecl;
12324 if(propWatch.deleteWatch)
12326 OldList * args = MkList();
12327 ListAdd(args, CopyExpression(object));
12328 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12329 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12330 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12334 Class _class = object.expType._class.registered;
12337 for(propID = propWatch.properties->first; propID; propID = propID.next)
12339 char propName[1024];
12340 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12343 char getName[1024], setName[1024];
12344 OldList * args = MkList();
12346 DeclareProperty(prop, setName, getName);
12348 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12349 strcpy(propName, "__ecereProp_");
12350 FullClassNameCat(propName, prop._class.fullName, false);
12351 strcat(propName, "_");
12352 // strcat(propName, prop.name);
12353 FullClassNameCat(propName, prop.name, true);
12355 ListAdd(args, CopyExpression(object));
12356 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12357 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12358 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12360 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12363 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12368 Compiler_Error($"Invalid watched object\n");
12371 curExternal = external;
12372 curContext = context;
12375 FreeExpression(watcher);
12377 FreeExpression(object);
12378 FreeList(watches, FreePropertyWatch);
12381 Compiler_Error($"No observer specified and not inside a _class\n");
12385 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12387 ProcessStatement(propWatch.compound);
12393 case fireWatchersStmt:
12395 OldList * watches = stmt._watch.watches;
12396 Expression object = stmt._watch.object;
12398 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12399 // printf("%X\n", watches);
12400 // printf("%X\n", stmt._watch.watches);
12402 ProcessExpressionType(object);
12407 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12413 stmt.type = expressionStmt;
12414 stmt.expressions = MkList();
12416 // Check if we're inside a property set
12417 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12419 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12423 //Compiler_Error($"No property specified and not inside a property set\n");
12427 for(propID = watches->first; propID; propID = propID.next)
12429 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12432 CreateFireWatcher(prop, object, stmt);
12435 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12440 // Fire all properties!
12443 for(base = _class; base; base = base.base)
12445 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12447 if(prop.isProperty && prop.isWatchable)
12449 CreateFireWatcher(prop, object, stmt);
12456 FreeExpression(object);
12457 FreeList(watches, FreeIdentifier);
12460 Compiler_Error($"Invalid object specified and not inside a class\n");
12464 case stopWatchingStmt:
12466 OldList * watches = stmt._watch.watches;
12467 Expression object = stmt._watch.object;
12468 Expression watcher = stmt._watch.watcher;
12471 ProcessExpressionType(object);
12473 ProcessExpressionType(watcher);
12476 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12478 if(watcher || thisClass)
12484 stmt.type = expressionStmt;
12485 stmt.expressions = MkList();
12490 // eInstance_StopWatching(object, null, watcher);
12492 ListAdd(args, CopyExpression(object));
12493 ListAdd(args, MkExpConstant("0"));
12494 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12495 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12499 for(propID = watches->first; propID; propID = propID.next)
12501 char propName[1024];
12502 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12505 char getName[1024], setName[1024];
12506 OldList * args = MkList();
12508 DeclareProperty(prop, setName, getName);
12510 // eInstance_StopWatching(object, prop, watcher);
12511 strcpy(propName, "__ecereProp_");
12512 FullClassNameCat(propName, prop._class.fullName, false);
12513 strcat(propName, "_");
12514 // strcat(propName, prop.name);
12515 FullClassNameCat(propName, prop.name, true);
12516 MangleClassName(propName);
12518 ListAdd(args, CopyExpression(object));
12519 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12520 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12521 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12524 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12529 FreeExpression(object);
12531 FreeExpression(watcher);
12532 FreeList(watches, FreeIdentifier);
12535 Compiler_Error($"Invalid object specified and not inside a class\n");
12538 Compiler_Error($"No observer specified and not inside a class\n");
12545 static void ProcessFunction(FunctionDefinition function)
12547 Identifier id = GetDeclId(function.declarator);
12548 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12549 Type type = symbol ? symbol.type : null;
12550 Class oldThisClass = thisClass;
12551 Context oldTopContext = topContext;
12553 yylloc = function.loc;
12554 // Process thisClass
12556 if(type && type.thisClass)
12558 Symbol classSym = type.thisClass;
12559 Class _class = type.thisClass.registered;
12560 char className[1024];
12561 char structName[1024];
12562 Declarator funcDecl;
12565 bool typedObject = false;
12567 if(_class && !_class.base)
12569 _class = currentClass;
12570 if(_class && !_class.symbol)
12571 _class.symbol = FindClass(_class.fullName);
12572 classSym = _class ? _class.symbol : null;
12573 typedObject = true;
12576 thisClass = _class;
12578 if(inCompiler && _class)
12580 if(type.kind == functionType)
12582 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12584 //TypeName param = symbol.type.params.first;
12585 Type param = symbol.type.params.first;
12586 symbol.type.params.Remove(param);
12587 //FreeTypeName(param);
12590 if(type.classObjectType != classPointer)
12592 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12593 symbol.type.staticMethod = true;
12594 symbol.type.thisClass = null;
12596 // HIGH DANGER: VERIFYING THIS...
12597 symbol.type.extraParam = false;
12601 strcpy(className, "__ecereClass_");
12602 FullClassNameCat(className, _class.fullName, true);
12604 MangleClassName(className);
12607 FullClassNameCat(structName, _class.fullName, false);
12612 funcDecl = GetFuncDecl(function.declarator);
12615 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12617 TypeName param = funcDecl.function.parameters->first;
12618 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12620 funcDecl.function.parameters->Remove(param);
12621 FreeTypeName(param);
12625 // DANGER: Watch for this... Check if it's a Conversion?
12626 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12628 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12629 if(!function.propertyNoThis)
12631 TypeName thisParam;
12633 if(type.classObjectType != classPointer)
12635 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12636 if(!funcDecl.function.parameters)
12637 funcDecl.function.parameters = MkList();
12638 funcDecl.function.parameters->Insert(null, thisParam);
12643 if(type.classObjectType != classPointer)
12645 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12646 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12649 thisParam = TypeName
12651 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12652 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12654 funcDecl.function.parameters->Insert(null, thisParam);
12659 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12661 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12662 funcDecl = GetFuncDecl(initDecl.declarator);
12665 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12667 TypeName param = funcDecl.function.parameters->first;
12668 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12670 funcDecl.function.parameters->Remove(param);
12671 FreeTypeName(param);
12675 if(type.classObjectType != classPointer)
12677 // DANGER: Watch for this... Check if it's a Conversion?
12678 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12680 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12682 if(!funcDecl.function.parameters)
12683 funcDecl.function.parameters = MkList();
12684 funcDecl.function.parameters->Insert(null, thisParam);
12691 // Add this to the context
12694 if(type.classObjectType != classPointer)
12696 thisSymbol = Symbol
12698 string = CopyString("this");
12699 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12701 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12703 if(typedObject && thisSymbol.type)
12705 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12706 thisSymbol.type.byReference = type.byReference;
12707 thisSymbol.type.typedByReference = type.byReference;
12709 thisSymbol = Symbol { string = CopyString("class") };
12710 function.body.compound.context.symbols.Add(thisSymbol);
12716 // Pointer to class data
12718 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12720 DataMember member = null;
12723 for(base = _class; base && base.type != systemClass; base = base.next)
12725 for(member = base.membersAndProperties.first; member; member = member.next)
12726 if(!member.isProperty)
12732 for(member = _class.membersAndProperties.first; member; member = member.next)
12733 if(!member.isProperty)
12737 char pointerName[1024];
12740 Initializer initializer;
12741 Expression exp, bytePtr;
12743 strcpy(pointerName, "__ecerePointer_");
12744 FullClassNameCat(pointerName, _class.fullName, false);
12746 char className[1024];
12747 strcpy(className, "__ecereClass_");
12748 FullClassNameCat(className, classSym.string, true);
12749 MangleClassName(className);
12752 DeclareClass(classSym, className);
12756 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12761 sprintf(string, "%d", _class.offset);
12762 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12766 // ([bytePtr] + [className]->offset)
12767 exp = QBrackets(MkExpOp(bytePtr, '+',
12768 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12771 // (this ? [exp] : 0)
12772 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12776 kind = pointerType;
12777 type = Type { refCount = 1, kind = voidType };
12782 yylloc = function.body.loc;
12783 // ([structName] *) [exp]
12784 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12785 initializer = MkInitializerAssignment(
12786 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12788 // [structName] * [pointerName] = [initializer];
12789 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12792 Context prevContext = curContext;
12793 curContext = function.body.compound.context;
12795 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12796 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12798 curContext = prevContext;
12802 decl.symbol = null;
12804 if(!function.body.compound.declarations)
12805 function.body.compound.declarations = MkList();
12806 function.body.compound.declarations->Insert(null, decl);
12812 // Loop through the function and replace undeclared identifiers
12813 // which are a member of the class (methods, properties or data)
12814 // by "this.[member]"
12821 FreeSpecifier(id._class);
12824 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12826 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12827 id = GetDeclId(initDecl.declarator);
12829 FreeSpecifier(id._class);
12834 topContext = function.body.compound.context;
12836 FunctionDefinition oldFunction = curFunction;
12837 curFunction = function;
12839 ProcessStatement(function.body);
12841 // If this is a property set and no firewatchers has been done yet, add one here
12842 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12844 Statement prevCompound = curCompound;
12845 Context prevContext = curContext;
12847 Statement fireWatchers = MkFireWatchersStmt(null, null);
12848 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12849 ListAdd(function.body.compound.statements, fireWatchers);
12851 curCompound = function.body;
12852 curContext = function.body.compound.context;
12854 ProcessStatement(fireWatchers);
12856 curContext = prevContext;
12857 curCompound = prevCompound;
12861 curFunction = oldFunction;
12864 if(function.declarator)
12866 ProcessDeclarator(function.declarator);
12869 topContext = oldTopContext;
12870 thisClass = oldThisClass;
12873 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12874 static void ProcessClass(OldList definitions, Symbol symbol)
12877 External external = curExternal;
12878 Class regClass = symbol ? symbol.registered : null;
12880 // Process all functions
12881 for(def = definitions.first; def; def = def.next)
12883 if(def.type == functionClassDef)
12885 if(def.function.declarator)
12886 curExternal = def.function.declarator.symbol.pointerExternal;
12888 curExternal = external;
12890 ProcessFunction((FunctionDefinition)def.function);
12892 else if(def.type == declarationClassDef)
12894 if(def.decl.type == instDeclaration)
12896 thisClass = regClass;
12897 ProcessInstantiationType(def.decl.inst);
12903 Class backThisClass = thisClass;
12904 if(regClass) thisClass = regClass;
12905 ProcessDeclaration(def.decl);
12906 thisClass = backThisClass;
12909 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12911 MemberInit defProperty;
12913 // Add this to the context
12914 Symbol thisSymbol = Symbol
12916 string = CopyString("this");
12917 type = regClass ? MkClassType(regClass.fullName) : null;
12919 globalContext.symbols.Add((BTNode)thisSymbol);
12921 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12923 thisClass = regClass;
12924 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12928 globalContext.symbols.Remove((BTNode)thisSymbol);
12929 FreeSymbol(thisSymbol);
12931 else if(def.type == propertyClassDef && def.propertyDef)
12933 PropertyDef prop = def.propertyDef;
12935 // Add this to the context
12937 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12938 globalContext.symbols.Add(thisSymbol);
12941 thisClass = regClass;
12948 string = CopyString("this");
12949 type = MkClassType(regClass.fullName);
12951 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12954 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12955 ProcessStatement(prop.setStmt);
12963 string = CopyString("this");
12964 type = MkClassType(regClass.fullName);
12966 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12969 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12970 ProcessStatement(prop.getStmt);
12978 string = CopyString("this");
12979 type = MkClassType(regClass.fullName);
12981 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12984 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12985 ProcessStatement(prop.issetStmt);
12991 globalContext.symbols.Remove(thisSymbol);
12992 FreeSymbol(thisSymbol);
12995 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12997 PropertyWatch propertyWatch = def.propertyWatch;
12999 thisClass = regClass;
13000 if(propertyWatch.compound)
13004 string = CopyString("this");
13005 type = regClass ? MkClassType(regClass.fullName) : null;
13008 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13010 curExternal = null;
13011 ProcessStatement(propertyWatch.compound);
13018 void DeclareFunctionUtil(const String s)
13020 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13025 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13026 strcpy(name, "__ecereFunction_");
13027 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13028 DeclareFunction(function, name);
13032 void ComputeDataTypes()
13036 External after = null;
13038 currentClass = null;
13040 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13042 for(external = ast->first; external; external = external.next)
13044 if(external.type == declarationExternal)
13046 Declaration decl = external.declaration;
13049 OldList * decls = decl.declarators;
13052 InitDeclarator initDecl = decls->first;
13055 Declarator declarator = initDecl.declarator;
13056 if(declarator && declarator.type == identifierDeclarator)
13058 Identifier id = declarator.identifier;
13059 if(id && id.string)
13061 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
13063 external.symbol.id = -1001, external.symbol.idCode = -1001;
13074 temp.symbol = Symbol { id = -1000, idCode = -1000 };
13075 ast->Insert(after, temp);
13076 curExternal = temp;
13078 DeclareFunctionUtil("eSystem_New");
13079 DeclareFunctionUtil("eSystem_New0");
13080 DeclareFunctionUtil("eSystem_Renew");
13081 DeclareFunctionUtil("eSystem_Renew0");
13082 DeclareFunctionUtil("eSystem_Delete");
13083 DeclareFunctionUtil("eClass_GetProperty");
13084 DeclareFunctionUtil("eClass_SetProperty");
13085 DeclareFunctionUtil("eInstance_FireSelfWatchers");
13086 DeclareFunctionUtil("eInstance_SetMethod");
13087 DeclareFunctionUtil("eInstance_IncRef");
13088 DeclareFunctionUtil("eInstance_StopWatching");
13089 DeclareFunctionUtil("eInstance_Watch");
13090 DeclareFunctionUtil("eInstance_FireWatchers");
13092 DeclareStruct("ecere::com::Class", false);
13093 DeclareStruct("ecere::com::Instance", false);
13094 DeclareStruct("ecere::com::Property", false);
13095 DeclareStruct("ecere::com::DataMember", false);
13096 DeclareStruct("ecere::com::Method", false);
13097 DeclareStruct("ecere::com::SerialBuffer", false);
13098 DeclareStruct("ecere::com::ClassTemplateArgument", false);
13102 for(external = ast->first; external; external = external.next)
13104 afterExternal = curExternal = external;
13105 if(external.type == functionExternal)
13107 currentClass = external.function._class;
13108 ProcessFunction(external.function);
13110 // There shouldn't be any _class member access here anyways...
13111 else if(external.type == declarationExternal)
13113 currentClass = null;
13114 if(external.declaration)
13115 ProcessDeclaration(external.declaration);
13117 else if(external.type == classExternal)
13119 ClassDefinition _class = external._class;
13120 currentClass = external.symbol.registered;
13121 if(_class.definitions)
13123 ProcessClass(_class.definitions, _class.symbol);
13127 // Free class data...
13128 ast->Remove(external);
13132 else if(external.type == nameSpaceExternal)
13134 thisNameSpace = external.id.string;
13137 currentClass = null;
13138 thisNameSpace = null;
13139 curExternal = null;
13141 delete temp.symbol;