4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
37 uint internalValueCounter;
40 Time findSymbolTotalTime;
43 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
44 /*static */public void PrintExpression(Expression exp, char * string)
52 OutputExpression(exp, f);
54 count = strlen(string);
55 count += f.Read(string + count, 1, 1023);
61 Type ProcessTemplateParameterType(TemplateParameter param)
63 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
65 // TOFIX: Will need to free this Type
68 if(param.dataTypeString)
69 param.baseType = ProcessTypeString(param.dataTypeString, false);
71 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
73 return param.baseType;
78 bool NeedCast(Type type1, Type type2)
80 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
82 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
87 if(type1.kind == type2.kind)
97 if(type1.passAsTemplate && !type2.passAsTemplate)
99 return type1.isSigned != type2.isSigned;
101 return type1._class != type2._class;
103 return NeedCast(type1.type, type2.type);
105 return true; //false; ????
111 static void ReplaceClassMembers(Expression exp, Class _class)
113 if(exp.type == identifierExp && exp.identifier)
115 Identifier id = exp.identifier;
117 Symbol symbol = null;
118 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
120 // First, check if the identifier is declared inside the function
121 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
123 symbol = (Symbol)ctx.symbols.FindString(id.string);
128 // If it is not, check if it is a member of the _class
129 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
131 Property prop = eClass_FindProperty(_class, id.string, privateModule);
132 Method method = null;
133 DataMember member = null;
134 ClassProperty classProp = null;
137 method = eClass_FindMethod(_class, id.string, privateModule);
140 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
141 if(!prop && !method && !member)
143 classProp = eClass_FindClassProperty(_class, id.string);
145 if(prop || method || member || classProp)
147 // Replace by this.[member]
148 exp.type = memberExp;
149 exp.member.member = id;
150 exp.member.memberType = unresolvedMember;
151 exp.member.exp = QMkExpId("this");
152 //exp.member.exp.loc = exp.loc;
153 exp.addedThis = true;
155 else if(_class && _class.templateParams.first)
158 for(sClass = _class; sClass; sClass = sClass.base)
160 if(sClass.templateParams.first)
162 ClassTemplateParameter param;
163 for(param = sClass.templateParams.first; param; param = param.next)
165 if(param.type == expression && !strcmp(param.name, id.string))
167 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
172 OldList * specs = MkList();
174 FreeIdentifier(exp.member.member);
176 ProcessExpressionType(argExp);
178 decl = SpecDeclFromString(param.dataTypeString, specs, null);
180 exp.expType = ProcessType(specs, decl);
182 // *[expType] *[argExp]
183 exp.type = bracketsExp;
184 exp.list = MkListOne(MkExpOp(null, '*',
185 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
196 ////////////////////////////////////////////////////////////////////////
197 // PRINTING ////////////////////////////////////////////////////////////
198 ////////////////////////////////////////////////////////////////////////
200 public char * PrintInt(int64 result)
203 if(result > MAXINT64)
204 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
206 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
207 return CopyString(temp);
210 public char * PrintUInt(uint64 result)
213 if(result > MAXDWORD)
214 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
215 else if(result > MAXINT)
216 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
218 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
219 return CopyString(temp);
222 public char * PrintInt64(int64 result)
225 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
226 return CopyString(temp);
229 public char * PrintUInt64(uint64 result)
232 if(result > MAXINT64)
233 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
235 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
236 return CopyString(temp);
239 public char * PrintHexUInt(uint64 result)
242 if(result > MAXDWORD)
243 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
245 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
246 return CopyString(temp);
249 public char * PrintHexUInt64(uint64 result)
252 if(result > MAXDWORD)
253 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
255 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
256 return CopyString(temp);
259 public char * PrintShort(short result)
262 sprintf(temp, "%d", (unsigned short)result);
263 return CopyString(temp);
266 public char * PrintUShort(unsigned short result)
270 sprintf(temp, "0x%X", (int)result);
272 sprintf(temp, "%d", result);
273 return CopyString(temp);
276 public char * PrintChar(char result)
279 if(result > 0 && isprint(result))
280 sprintf(temp, "'%c'", result);
282 sprintf(temp, "%d", result);
284 //sprintf(temp, "%#X", result);
285 sprintf(temp, "0x%X", (unsigned char)result);
286 return CopyString(temp);
289 public char * PrintUChar(unsigned char result)
292 sprintf(temp, "0x%X", result);
293 return CopyString(temp);
296 public char * PrintFloat(float result)
299 sprintf(temp, "%.16ff", result);
300 return CopyString(temp);
303 public char * PrintDouble(double result)
306 sprintf(temp, "%.16f", result);
307 return CopyString(temp);
310 ////////////////////////////////////////////////////////////////////////
311 ////////////////////////////////////////////////////////////////////////
313 //public Operand GetOperand(Expression exp);
315 #define GETVALUE(name, t) \
316 public bool Get##name(Expression exp, t * value2) \
318 Operand op2 = GetOperand(exp); \
319 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
320 else if(op2.kind == intType) *value2 = (t) op2.ui; \
321 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
322 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
323 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
324 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
325 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
326 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
327 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
328 else if(op2.kind == shortType) *value2 = (t) op2.us; \
329 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
330 else if(op2.kind == charType) *value2 = (t) op2.uc; \
331 else if(op2.kind == floatType) *value2 = (t) op2.f; \
332 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
333 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
339 // To help the deubugger currently not preprocessing...
342 GETVALUE(Int, HELP(int));
343 GETVALUE(UInt, HELP(unsigned int));
344 GETVALUE(Int64, HELP(int64));
345 GETVALUE(UInt64, HELP(uint64));
346 GETVALUE(IntPtr, HELP(intptr));
347 GETVALUE(UIntPtr, HELP(uintptr));
348 GETVALUE(IntSize, HELP(intsize));
349 GETVALUE(UIntSize, HELP(uintsize));
350 GETVALUE(Short, HELP(short));
351 GETVALUE(UShort, HELP(unsigned short));
352 GETVALUE(Char, HELP(char));
353 GETVALUE(UChar, HELP(unsigned char));
354 GETVALUE(Float, HELP(float));
355 GETVALUE(Double, HELP(double));
357 void ComputeExpression(Expression exp);
359 void ComputeClassMembers(Class _class, bool isMember)
361 DataMember member = isMember ? (DataMember) _class : null;
362 Context context = isMember ? null : SetupTemplatesContext(_class);
363 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
364 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
367 int unionMemberOffset = 0;
371 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
372 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
377 member.memberOffset = 0;
378 if(targetBits < sizeof(void *) * 8)
379 member.structAlignment = 0;
381 else if(targetBits < sizeof(void *) * 8)
382 _class.structAlignment = 0;
384 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
385 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
386 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
388 if(!member && _class.destructionWatchOffset)
389 _class.memberOffset += sizeof(OldList);
391 // To avoid reentrancy...
392 //_class.structSize = -1;
395 DataMember dataMember;
396 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
398 if(!dataMember.isProperty)
400 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
402 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
403 /*if(!dataMember.dataType)
404 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
412 DataMember dataMember;
413 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
415 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
417 if(!isMember && _class.type == bitClass && dataMember.dataType)
419 BitMember bitMember = (BitMember) dataMember;
423 ComputeTypeSize(dataMember.dataType);
425 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
426 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
428 _class.memberOffset = bitMember.pos + bitMember.size;
429 for(d = 0; d<bitMember.size; d++)
435 bitMember.mask = mask << bitMember.pos;
437 else if(dataMember.type == normalMember && dataMember.dataType)
442 // Prevent infinite recursion
443 if(dataMember.dataType.kind != classType ||
444 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
445 _class.type != structClass)))
446 ComputeTypeSize(dataMember.dataType);
448 if(dataMember.dataType.bitFieldCount)
450 bitFields += dataMember.dataType.bitFieldCount;
457 int size = (bitFields + 7) / 8;
461 // TESTING THIS PADDING CODE
464 member.structAlignment = Max(member.structAlignment, alignment);
466 if(member.memberOffset % alignment)
467 member.memberOffset += alignment - (member.memberOffset % alignment);
470 dataMember.offset = member.memberOffset;
471 if(member.type == unionMember)
472 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
475 member.memberOffset += size;
480 // TESTING THIS PADDING CODE
483 _class.structAlignment = Max(_class.structAlignment, alignment);
485 if(_class.memberOffset % alignment)
486 _class.memberOffset += alignment - (_class.memberOffset % alignment);
489 dataMember.offset = _class.memberOffset;
490 _class.memberOffset += size;
494 size = dataMember.dataType.size;
495 alignment = dataMember.dataType.alignment;
500 // TESTING THIS PADDING CODE
503 member.structAlignment = Max(member.structAlignment, alignment);
505 if(member.memberOffset % alignment)
506 member.memberOffset += alignment - (member.memberOffset % alignment);
509 dataMember.offset = member.memberOffset;
510 if(member.type == unionMember)
511 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
514 member.memberOffset += size;
519 // TESTING THIS PADDING CODE
522 _class.structAlignment = Max(_class.structAlignment, alignment);
524 if(_class.memberOffset % alignment)
525 _class.memberOffset += alignment - (_class.memberOffset % alignment);
528 dataMember.offset = _class.memberOffset;
529 _class.memberOffset += size;
536 ComputeClassMembers((Class)dataMember, true);
537 alignment = dataMember.structAlignment;
543 if(member.memberOffset % alignment)
544 member.memberOffset += alignment - (member.memberOffset % alignment);
546 member.structAlignment = Max(member.structAlignment, alignment);
548 dataMember.offset = member.memberOffset;
549 if(member.type == unionMember)
550 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
552 member.memberOffset += dataMember.memberOffset;
558 if(_class.memberOffset % alignment)
559 _class.memberOffset += alignment - (_class.memberOffset % alignment);
560 _class.structAlignment = Max(_class.structAlignment, alignment);
562 dataMember.offset = _class.memberOffset;
563 _class.memberOffset += dataMember.memberOffset;
571 int size = (bitFields + 7) / 8;
575 // TESTING THIS PADDING CODE
578 member.structAlignment = Max(member.structAlignment, alignment);
580 if(member.memberOffset % alignment)
581 member.memberOffset += alignment - (member.memberOffset % alignment);
584 if(member.type == unionMember)
585 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
588 member.memberOffset += size;
593 // TESTING THIS PADDING CODE
596 _class.structAlignment = Max(_class.structAlignment, alignment);
598 if(_class.memberOffset % alignment)
599 _class.memberOffset += alignment - (_class.memberOffset % alignment);
601 _class.memberOffset += size;
606 if(member && member.type == unionMember)
608 member.memberOffset = unionMemberOffset;
613 /*if(_class.type == structClass)
614 _class.size = _class.memberOffset;
618 if(_class.type != bitClass)
621 if(_class.structAlignment)
623 if(_class.memberOffset % _class.structAlignment)
624 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
626 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
630 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
632 if(prop.isProperty && prop.isWatchable)
634 prop.watcherOffset = _class.structSize;
635 _class.structSize += sizeof(OldList);
643 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
645 Class deriv = derivative.data;
647 if(deriv.computeSize)
649 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
650 deriv.offset = /*_class.offset + */_class.structSize;
651 deriv.memberOffset = 0;
652 // ----------------------
654 deriv.structSize = deriv.offset;
656 ComputeClassMembers(deriv, false);
664 FinishTemplatesContext(context);
667 public void ComputeModuleClasses(Module module)
672 for(subModule = module.modules.first; subModule; subModule = subModule.next)
673 ComputeModuleClasses(subModule.data);
674 for(_class = module.classes.first; _class; _class = _class.next)
675 ComputeClassMembers(_class, false);
679 public int ComputeTypeSize(Type type)
681 uint size = type ? type.size : 0;
682 if(!size && type && !type.computing)
684 type.computing = true;
687 case charType: type.alignment = size = sizeof(char); break;
688 case intType: type.alignment = size = sizeof(int); break;
689 case int64Type: type.alignment = size = sizeof(int64); break;
690 case intPtrType: type.alignment = size = targetBits / 8; break;
691 case intSizeType: type.alignment = size = targetBits / 8; break;
692 case longType: type.alignment = size = sizeof(long); break;
693 case shortType: type.alignment = size = sizeof(short); break;
694 case floatType: type.alignment = size = sizeof(float); break;
695 case doubleType: type.alignment = size = sizeof(double); break;
698 Class _class = type._class ? type._class.registered : null;
700 if(_class && _class.type == structClass)
702 // Ensure all members are properly registered
703 ComputeClassMembers(_class, false);
704 type.alignment = _class.structAlignment;
705 size = _class.structSize;
706 if(type.alignment && size % type.alignment)
707 size += type.alignment - (size % type.alignment);
710 else if(_class && (_class.type == unitClass ||
711 _class.type == enumClass ||
712 _class.type == bitClass))
715 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
716 size = type.alignment = ComputeTypeSize(_class.dataType);
719 size = type.alignment = targetBits / 8; // sizeof(Instance *);
722 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
724 if(type.arraySizeExp)
726 ProcessExpressionType(type.arraySizeExp);
727 ComputeExpression(type.arraySizeExp);
728 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
729 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
731 Location oldLoc = yylloc;
732 // bool isConstant = type.arraySizeExp.isConstant;
733 char expression[10240];
734 expression[0] = '\0';
735 type.arraySizeExp.expType = null;
736 yylloc = type.arraySizeExp.loc;
738 PrintExpression(type.arraySizeExp, expression);
739 Compiler_Error($"Array size not constant int (%s)\n", expression);
742 GetInt(type.arraySizeExp, &type.arraySize);
744 else if(type.enumClass)
746 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
748 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
755 // Unimplemented auto size
759 size = ComputeTypeSize(type.type) * type.arraySize;
760 type.alignment = type.type.alignment;
766 for(member = type.members.first; member; member = member.next)
768 uint addSize = ComputeTypeSize(member);
770 member.offset = size;
771 if(member.alignment && size % member.alignment)
772 member.offset += member.alignment - (size % member.alignment);
773 size = member.offset;
775 type.alignment = Max(type.alignment, member.alignment);
778 if(type.alignment && size % type.alignment)
779 size += type.alignment - (size % type.alignment);
785 for(member = type.members.first; member; member = member.next)
787 uint addSize = ComputeTypeSize(member);
789 member.offset = size;
790 if(member.alignment && size % member.alignment)
791 member.offset += member.alignment - (size % member.alignment);
792 size = member.offset;
794 type.alignment = Max(type.alignment, member.alignment);
795 size = Max(size, addSize);
797 if(type.alignment && size % type.alignment)
798 size += type.alignment - (size % type.alignment);
803 TemplateParameter param = type.templateParameter;
804 Type baseType = ProcessTemplateParameterType(param);
807 size = ComputeTypeSize(baseType);
808 type.alignment = baseType.alignment;
811 type.alignment = size = sizeof(uint64);
816 type.alignment = size = sizeof(enum { test });
821 type.alignment = size = targetBits / 8; //sizeof(void *);
826 type.computing = false;
832 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
834 // This function is in need of a major review when implementing private members etc.
835 DataMember topMember = isMember ? (DataMember) _class : null;
840 Context context = isMember ? null : SetupTemplatesContext(_class);
842 *addedPadding = false;
844 if(!isMember && _class.base)
846 maxSize = _class.structSize;
847 //if(_class.base.type != systemClass) // Commented out with new Instance _class
849 // DANGER: Testing this noHeadClass here...
850 if(_class.type == structClass || _class.type == noHeadClass)
851 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
854 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
855 if(maxSize > baseSize)
863 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
865 if(!member.isProperty)
871 if(member.dataTypeString)
873 OldList * specs = MkList(), * decls = MkList();
876 decl = SpecDeclFromString(member.dataTypeString, specs,
877 MkDeclaratorIdentifier(MkIdentifier(member.name)));
878 ListAdd(decls, MkStructDeclarator(decl, null));
879 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
882 member.dataType = ProcessType(specs, decl);
884 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
887 Type type = ProcessType(specs, decl);
888 DeclareType(member.dataType, false, false);
892 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
893 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
894 DeclareStruct(member.dataType._class.string, false);
897 ComputeTypeSize(member.dataType);
898 size = member.dataType.size;
899 alignment = member.dataType.alignment;
903 if(totalSize % alignment)
904 totalSize += alignment - (totalSize % alignment);
913 OldList * specs = MkList(), * list = MkList();
916 AddMembers(list, (Class)member, true, &size, topClass, null);
918 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
919 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
920 alignment = member.structAlignment;
924 if(totalSize % alignment)
925 totalSize += alignment - (totalSize % alignment);
935 if(topMember && topMember.type == unionMember)
936 *retSize = Max(*retSize, totalSize);
938 *retSize += totalSize;
940 else if(totalSize < maxSize && _class.type != systemClass)
943 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
944 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
945 if(totalSize + autoPadding < maxSize)
948 sprintf(sizeString, "%d", maxSize - totalSize);
949 ListAdd(declarations,
950 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
951 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
953 *addedPadding = true;
957 FinishTemplatesContext(context);
958 return topMember ? topMember.memberID : _class.memberID;
961 static int DeclareMembers(Class _class, bool isMember)
963 DataMember topMember = isMember ? (DataMember) _class : null;
966 Context context = isMember ? null : SetupTemplatesContext(_class);
968 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
969 DeclareMembers(_class.base, false);
971 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
973 if(!member.isProperty)
980 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
981 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
982 DeclareStruct(member.dataType._class.string, false);
984 if(!member.dataType && member.dataTypeString)
985 member.dataType = ProcessTypeString(member.dataTypeString, false);
987 DeclareType(member.dataType, false, false);
993 DeclareMembers((Class)member, true);
1000 FinishTemplatesContext(context);
1002 return topMember ? topMember.memberID : _class.memberID;
1005 void DeclareStruct(char * name, bool skipNoHead)
1007 External external = null;
1008 Symbol classSym = FindClass(name);
1010 if(!inCompiler || !classSym) return;
1012 // We don't need any declaration for bit classes...
1013 if(classSym.registered &&
1014 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1017 /*if(classSym.registered.templateClass)
1018 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1021 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1023 // Add typedef struct
1025 OldList * specifiers, * declarators;
1026 OldList * declarations = null;
1027 char structName[1024];
1028 external = (classSym.registered && classSym.registered.type == structClass) ?
1029 classSym.pointerExternal : classSym.structExternal;
1031 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1032 // Moved this one up because DeclareClass done later will need it
1034 classSym.declaring++;
1036 if(strchr(classSym.string, '<'))
1038 if(classSym.registered.templateClass)
1040 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1041 classSym.declaring--;
1047 DeclareMembers(classSym.registered, false);
1050 FullClassNameCat(structName, name, false);
1053 external = MkExternalDeclaration(null);*/
1057 bool addedPadding = false;
1058 classSym.declaredStructSym = true;
1060 declarations = MkList();
1062 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1064 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1065 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1067 if(!declarations->count || (declarations->count == 1 && addedPadding))
1069 FreeList(declarations, FreeClassDef);
1070 declarations = null;
1073 if(skipNoHead || declarations)
1075 if(external && external.declaration)
1077 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1079 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1082 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1085 if(classSym.structExternal)
1086 ast->Move(classSym.structExternal, curExternal.prev);
1087 ast->Move(classSym.pointerExternal, curExternal.prev);
1089 classSym.id = curExternal.symbol.idCode;
1090 classSym.idCode = curExternal.symbol.idCode;
1091 // external = classSym.pointerExternal;
1092 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1098 external = MkExternalDeclaration(null);
1100 specifiers = MkList();
1101 declarators = MkList();
1102 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1105 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1106 ListAdd(declarators, MkInitDeclarator(d, null));
1108 external.declaration = decl = MkDeclaration(specifiers, declarators);
1109 if(decl.symbol && !decl.symbol.pointerExternal)
1110 decl.symbol.pointerExternal = external;
1112 // For simple classes, keep the declaration as the external to move around
1113 if(classSym.registered && classSym.registered.type == structClass)
1115 char className[1024];
1116 strcpy(className, "__ecereClass_");
1117 FullClassNameCat(className, classSym.string, true);
1118 MangleClassName(className);
1121 DeclareClass(classSym, className);
1123 external.symbol = classSym;
1124 classSym.pointerExternal = external;
1125 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1126 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1130 char className[1024];
1131 strcpy(className, "__ecereClass_");
1132 FullClassNameCat(className, classSym.string, true);
1133 MangleClassName(className);
1135 // TOFIX: TESTING THIS...
1136 classSym.structExternal = external;
1137 DeclareClass(classSym, className);
1138 external.symbol = classSym;
1142 ast->Insert(curExternal ? curExternal.prev : null, external);
1146 classSym.declaring--;
1148 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1150 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1151 // Moved this one up because DeclareClass done later will need it
1154 classSym.declaring++;
1158 if(classSym.registered)
1159 DeclareMembers(classSym.registered, false);
1162 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1165 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1168 if(classSym.structExternal)
1169 ast->Move(classSym.structExternal, curExternal.prev);
1170 ast->Move(classSym.pointerExternal, curExternal.prev);
1172 classSym.id = curExternal.symbol.idCode;
1173 classSym.idCode = curExternal.symbol.idCode;
1174 // external = classSym.pointerExternal;
1175 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1178 classSym.declaring--;
1183 void DeclareProperty(Property prop, char * setName, char * getName)
1185 Symbol symbol = prop.symbol;
1186 char propName[1024];
1188 strcpy(setName, "__ecereProp_");
1189 FullClassNameCat(setName, prop._class.fullName, false);
1190 strcat(setName, "_Set_");
1191 // strcat(setName, prop.name);
1192 FullClassNameCat(setName, prop.name, true);
1194 strcpy(getName, "__ecereProp_");
1195 FullClassNameCat(getName, prop._class.fullName, false);
1196 strcat(getName, "_Get_");
1197 FullClassNameCat(getName, prop.name, true);
1198 // strcat(getName, prop.name);
1200 strcpy(propName, "__ecereProp_");
1201 FullClassNameCat(propName, prop._class.fullName, false);
1202 strcat(propName, "_");
1203 FullClassNameCat(propName, prop.name, true);
1204 // strcat(propName, prop.name);
1206 // To support "char *" property
1207 MangleClassName(getName);
1208 MangleClassName(setName);
1209 MangleClassName(propName);
1211 if(prop._class.type == structClass)
1212 DeclareStruct(prop._class.fullName, false);
1214 if(!symbol || curExternal.symbol.idCode < symbol.id)
1216 bool imported = false;
1217 bool dllImport = false;
1218 if(!symbol || symbol._import)
1223 if(!prop._class.symbol)
1224 prop._class.symbol = FindClass(prop._class.fullName);
1225 classSym = prop._class.symbol;
1226 if(classSym && !classSym._import)
1228 ModuleImport module;
1230 if(prop._class.module)
1231 module = FindModule(prop._class.module);
1233 module = mainModule;
1235 classSym._import = ClassImport
1237 name = CopyString(prop._class.fullName);
1238 isRemote = prop._class.isRemote;
1240 module.classes.Add(classSym._import);
1242 symbol = prop.symbol = Symbol { };
1243 symbol._import = (ClassImport)PropertyImport
1245 name = CopyString(prop.name);
1246 isVirtual = false; //prop.isVirtual;
1247 hasSet = prop.Set ? true : false;
1248 hasGet = prop.Get ? true : false;
1251 classSym._import.properties.Add(symbol._import);
1254 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1260 Context context = SetupTemplatesContext(prop._class);
1261 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1262 FinishTemplatesContext(context);
1268 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1271 OldList * specifiers, * declarators;
1276 Declarator typeDecl;
1277 bool simple = false;
1279 specifiers = MkList();
1280 declarators = MkList();
1283 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1284 MkDeclaratorIdentifier(MkIdentifier("this"))));
1286 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1289 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1292 Context context = SetupTemplatesContext(prop._class);
1293 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1294 FinishTemplatesContext(context);
1297 // Make sure the simple _class's type is declared
1298 for(spec = specifiers->first; spec; spec = spec.next)
1300 if(spec.type == nameSpecifier /*SpecifierClass*/)
1302 if((!typeDecl || typeDecl.type == identifierDeclarator))
1304 Symbol classSym = spec.symbol; // FindClass(spec.name);
1305 symbol._class = classSym.registered;
1306 if(classSym.registered && classSym.registered.type == structClass)
1308 DeclareStruct(spec.name, false);
1316 d = PlugDeclarator(typeDecl, d);
1319 ListAdd(params, MkTypeName(specifiers,
1320 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1321 specifiers = MkList();
1324 d = MkDeclaratorFunction(d, params);
1328 specifiers->Insert(null, MkSpecifier(EXTERN));
1329 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1330 specifiers->Insert(null, MkSpecifier(STATIC));
1332 ListAdd(specifiers, MkSpecifier(VOID));
1334 ListAdd(declarators, MkInitDeclarator(d, null));
1336 decl = MkDeclaration(specifiers, declarators);
1338 external = MkExternalDeclaration(decl);
1339 ast->Insert(curExternal.prev, external);
1340 external.symbol = symbol;
1341 symbol.externalGet = external;
1343 ReplaceThisClassSpecifiers(specifiers, prop._class);
1346 FreeDeclarator(typeDecl);
1350 // Move declaration higher...
1351 ast->Move(symbol.externalGet, curExternal.prev);
1358 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1361 OldList * specifiers, * declarators;
1366 Declarator typeDecl;
1368 declarators = MkList();
1371 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1372 if(!prop.conversion || prop._class.type == structClass)
1374 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1375 MkDeclaratorIdentifier(MkIdentifier("this"))));
1378 specifiers = MkList();
1381 Context context = SetupTemplatesContext(prop._class);
1382 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1383 MkDeclaratorIdentifier(MkIdentifier("value")));
1384 FinishTemplatesContext(context);
1386 ListAdd(params, MkTypeName(specifiers, d));
1388 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1391 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1392 d = MkDeclaratorFunction(d, params);
1394 // Make sure the simple _class's type is declared
1395 for(spec = specifiers->first; spec; spec = spec.next)
1397 if(spec.type == nameSpecifier /*SpecifierClass*/)
1399 if((!typeDecl || typeDecl.type == identifierDeclarator))
1401 Symbol classSym = spec.symbol; // FindClass(spec.name);
1402 symbol._class = classSym.registered;
1403 if(classSym.registered && classSym.registered.type == structClass)
1404 DeclareStruct(spec.name, false);
1409 ListAdd(declarators, MkInitDeclarator(d, null));
1411 specifiers = MkList();
1414 specifiers->Insert(null, MkSpecifier(EXTERN));
1415 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1416 specifiers->Insert(null, MkSpecifier(STATIC));
1418 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1419 if(!prop.conversion || prop._class.type == structClass)
1420 ListAdd(specifiers, MkSpecifier(VOID));
1422 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1424 decl = MkDeclaration(specifiers, declarators);
1426 external = MkExternalDeclaration(decl);
1427 ast->Insert(curExternal.prev, external);
1428 external.symbol = symbol;
1429 symbol.externalSet = external;
1431 ReplaceThisClassSpecifiers(specifiers, prop._class);
1435 // Move declaration higher...
1436 ast->Move(symbol.externalSet, curExternal.prev);
1440 // Property (for Watchers)
1441 if(!symbol.externalPtr)
1445 OldList * specifiers = MkList();
1448 specifiers->Insert(null, MkSpecifier(EXTERN));
1450 specifiers->Insert(null, MkSpecifier(STATIC));
1452 ListAdd(specifiers, MkSpecifierName("Property"));
1455 OldList * list = MkList();
1456 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1457 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1461 strcpy(propName, "__ecerePropM_");
1462 FullClassNameCat(propName, prop._class.fullName, false);
1463 strcat(propName, "_");
1464 // strcat(propName, prop.name);
1465 FullClassNameCat(propName, prop.name, true);
1467 MangleClassName(propName);
1469 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1470 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1472 decl = MkDeclaration(specifiers, list);
1475 external = MkExternalDeclaration(decl);
1476 ast->Insert(curExternal.prev, external);
1477 external.symbol = symbol;
1478 symbol.externalPtr = external;
1482 // Move declaration higher...
1483 ast->Move(symbol.externalPtr, curExternal.prev);
1486 symbol.id = curExternal.symbol.idCode;
1490 // ***************** EXPRESSION PROCESSING ***************************
1491 public Type Dereference(Type source)
1496 if(source.kind == pointerType || source.kind == arrayType)
1499 source.type.refCount++;
1501 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1509 // Support dereferencing of no head classes for now...
1510 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1516 Compiler_Error($"cannot dereference type\n");
1521 static Type Reference(Type source)
1537 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1539 Identifier ident = member.identifiers ? member.identifiers->first : null;
1541 DataMember dataMember = null;
1542 Method method = null;
1543 bool freeType = false;
1545 yylloc = member.loc;
1551 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1555 dataMember = *curMember;
1561 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1562 DataMember _subMemberStack[256];
1563 int _subMemberStackPos = 0;
1565 // FILL MEMBER STACK
1567 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1570 dataMember = thisMember;
1571 if(curMember && thisMember.memberAccess == publicAccess)
1573 *curMember = thisMember;
1574 *curClass = thisMember._class;
1575 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
1576 *subMemberStackPos = _subMemberStackPos;
1583 method = eClass_FindMethod(_class, ident.string, privateModule);
1584 if(method && method.type == virtualMethod)
1596 if(!dataMember.dataType && dataMember.dataTypeString)
1598 //Context context = SetupTemplatesContext(dataMember._class);
1599 Context context = SetupTemplatesContext(_class);
1600 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1601 FinishTemplatesContext(context);
1603 type = dataMember.dataType;
1607 // This is for destination type...
1608 if(!method.dataType)
1609 ProcessMethodType(method);
1610 //DeclareMethod(method);
1611 // method.dataType = ((Symbol)method.symbol)->type;
1612 type = method.dataType;
1615 if(ident && ident.next)
1617 for(ident = ident.next; ident && type; ident = ident.next)
1619 if(type.kind == classType)
1621 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1623 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1625 type = dataMember.dataType;
1627 else if(type.kind == structType || type.kind == unionType)
1630 for(memberType = type.members.first; memberType; memberType = memberType.next)
1632 if(!strcmp(memberType.name, ident.string))
1642 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1643 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1646 ClassTemplateParameter curParam = null;
1648 for(sClass = _class; sClass; sClass = sClass.base)
1651 if(sClass.templateClass) sClass = sClass.templateClass;
1652 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1654 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1656 for(sClass = sClass.base; sClass; sClass = sClass.base)
1658 if(sClass.templateClass) sClass = sClass.templateClass;
1659 id += sClass.templateParams.count;
1670 ClassTemplateArgument arg = _class.templateArgs[id];
1671 if(arg.dataTypeString)
1674 type = ProcessTypeString(arg.dataTypeString, false);
1676 if(type && _class.templateClass)
1677 type.passAsTemplate = true;
1683 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1684 exp.destType.refCount++;
1690 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1692 Class expClass = type._class.registered;
1693 Class cClass = null;
1698 char templateString[1024];
1699 ClassTemplateParameter param;
1700 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1701 for(cClass = expClass; cClass; cClass = cClass.base)
1704 if(cClass.templateClass) cClass = cClass.templateClass;
1705 for(param = cClass.templateParams.first; param; param = param.next)
1709 ClassTemplateArgument arg;
1710 for(sClass = cClass.base; sClass; sClass = sClass.base)
1712 if(sClass.templateClass) sClass = sClass.templateClass;
1713 id += sClass.templateParams.count;
1715 arg = expClass.templateArgs[id];
1717 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1719 ClassTemplateParameter cParam;
1720 //int p = numParams - sClass.templateParams.count;
1723 if(sClass.templateClass) sClass = sClass.templateClass;
1725 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1727 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1728 p += nextClass.templateParams.count;
1731 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1733 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1735 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1737 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1738 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1750 strcat(argument, arg.name.string);
1751 strcat(argument, " = ");
1757 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1758 char expString[1024];
1759 OldList * specs = MkList();
1760 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1762 char * string = PrintHexUInt64(arg.expression.ui64);
1763 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1765 ProcessExpressionType(exp);
1766 ComputeExpression(exp);
1767 expString[0] = '\0';
1768 PrintExpression(exp, expString);
1769 strcat(argument, expString);
1771 FreeExpression(exp);
1776 strcat(argument, arg.member.name);
1779 case TemplateParameterType::type:
1781 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1782 strcat(argument, arg.dataTypeString);
1788 if(paramCount) strcat(templateString, ", ");
1789 if(lastParam != p - 1)
1791 strcat(templateString, param.name);
1792 strcat(templateString, " = ");
1794 strcat(templateString, argument);
1803 int len = strlen(templateString);
1804 if(templateString[len-1] == '<')
1808 if(templateString[len-1] == '>')
1809 templateString[len++] = ' ';
1810 templateString[len++] = '>';
1812 templateString[len++] = '\0';
1815 Context context = SetupTemplatesContext(_class);
1816 if(freeType) FreeType(type);
1817 type = ProcessTypeString(templateString, false);
1819 FinishTemplatesContext(context);
1823 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1825 ProcessExpressionType(member.initializer.exp);
1826 if(!member.initializer.exp.expType)
1830 char expString[10240];
1831 expString[0] = '\0';
1832 PrintExpression(member.initializer.exp, expString);
1833 ChangeCh(expString, '\n', ' ');
1834 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1837 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1838 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1840 Compiler_Error($"incompatible instance method %s\n", ident.string);
1843 else if(member.initializer)
1846 FreeType(member.exp.destType);
1847 member.exp.destType = type;
1848 if(member.exp.destType)
1849 member.exp.destType.refCount++;
1850 ProcessExpressionType(member.exp);
1853 ProcessInitializer(member.initializer, type);
1855 if(freeType) FreeType(type);
1859 if(_class && _class.type == unitClass)
1861 if(member.initializer)
1864 FreeType(member.exp.destType);
1865 member.exp.destType = MkClassType(_class.fullName);
1866 ProcessExpressionType(member.initializer, type);
1868 Type type = MkClassType(_class.fullName);
1869 ProcessInitializer(member.initializer, type);
1875 if(member.initializer)
1877 //ProcessExpressionType(member.exp);
1878 ProcessInitializer(member.initializer, null);
1884 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1888 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1890 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1894 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1899 void ProcessInstantiationType(Instantiation inst)
1904 MembersInit members;
1905 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1908 /*if(!inst._class.symbol)
1909 inst._class.symbol = FindClass(inst._class.name);*/
1910 classSym = inst._class.symbol;
1911 _class = classSym ? classSym.registered : null;
1913 // DANGER: Patch for mutex not declaring its struct when not needed
1914 if(!_class || _class.type != noHeadClass)
1915 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1917 afterExternal = afterExternal ? afterExternal : curExternal;
1920 ProcessExpressionType(inst.exp);
1922 inst.isConstant = true;
1925 DataMember curMember = null;
1926 Class curClass = null;
1927 DataMember subMemberStack[256];
1928 int subMemberStackPos = 0;
1930 for(members = inst.members->first; members; members = members.next)
1932 switch(members.type)
1934 case methodMembersInit:
1937 static uint instMethodID = 0;
1938 External external = curExternal;
1939 Context context = curContext;
1940 Declarator declarator = members.function.declarator;
1941 Identifier nameID = GetDeclId(declarator);
1942 char * unmangled = nameID ? nameID.string : null;
1944 External createdExternal = null;
1949 //members.function.dontMangle = true;
1950 strcpy(name, "__ecereInstMeth_");
1951 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
1953 strcat(name, nameID.string);
1955 sprintf(number, "_%08d", instMethodID++);
1956 strcat(name, number);
1957 nameID.string = CopyString(name);
1960 // Do modifications here...
1963 Symbol symbol = declarator.symbol;
1964 Method method = eClass_FindMethod(_class, unmangled, privateModule);
1966 if(method && method.type == virtualMethod)
1968 symbol.method = method;
1969 ProcessMethodType(method);
1971 if(!symbol.type.thisClass)
1973 if(method.dataType.thisClass && currentClass &&
1974 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
1976 if(!currentClass.symbol)
1977 currentClass.symbol = FindClass(currentClass.fullName);
1978 symbol.type.thisClass = currentClass.symbol;
1983 _class.symbol = FindClass(_class.fullName);
1984 symbol.type.thisClass = _class.symbol;
1987 // TESTING THIS HERE:
1988 DeclareType(symbol.type, true, true);
1993 Compiler_Error($"couldn't find virtual method %s in class %s\n",
1994 unmangled, classSym.string);
1998 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
1999 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2003 FreeSpecifier(nameID._class);
2004 nameID._class = null;
2010 Type type = declarator.symbol.type;
2011 External oldExternal = curExternal;
2013 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2014 // *** It was commented out for problems such as
2016 class VirtualDesktop : Window
2018 clientSize = Size { };
2029 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2031 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2034 if(strcmp(declarator.symbol.string, name))
2036 printf("TOCHECK: Look out for this\n");
2037 delete declarator.symbol.string;
2038 declarator.symbol.string = CopyString(name);
2041 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2043 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2044 excludedSymbols->Remove(declarator.symbol);
2045 globalContext.symbols.Add((BTNode)declarator.symbol);
2046 if(strstr(declarator.symbol.string), "::")
2047 globalContext.hasNameSpace = true;
2052 //curExternal = curExternal.prev;
2053 //afterExternal = afterExternal->next;
2055 //ProcessFunction(afterExternal->function);
2057 //curExternal = afterExternal;
2059 External externalDecl;
2060 externalDecl = MkExternalDeclaration(null);
2061 ast->Insert(oldExternal.prev, externalDecl);
2063 // Which function does this process?
2064 if(createdExternal.function)
2066 ProcessFunction(createdExternal.function);
2068 //curExternal = oldExternal;
2071 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2073 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2074 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2076 //externalDecl = MkExternalDeclaration(decl);
2078 //***** ast->Insert(external.prev, externalDecl);
2079 //ast->Insert(curExternal.prev, externalDecl);
2080 externalDecl.declaration = decl;
2081 if(decl.symbol && !decl.symbol.pointerExternal)
2082 decl.symbol.pointerExternal = externalDecl;
2084 // Trying this out...
2085 declarator.symbol.pointerExternal = externalDecl;
2092 curExternal = declarator.symbol.pointerExternal;
2093 ProcessFunction((FunctionDefinition)members.function);
2095 curExternal = external;
2096 curContext = context;
2100 FreeClassFunction(members.function);
2102 // In this pass, turn this into a MemberInitData
2103 exp = QMkExpId(name);
2104 members.type = dataMembersInit;
2105 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2111 case dataMembersInit:
2113 if(members.dataMembers && classSym)
2116 Location oldyyloc = yylloc;
2117 for(member = members.dataMembers->first; member; member = member.next)
2119 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2120 if(member.initializer && !member.initializer.isConstant)
2121 inst.isConstant = false;
2133 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2135 // OPTIMIZATIONS: TESTING THIS...
2138 if(type.kind == functionType)
2143 for(param = type.params.first; param; param = param.next)
2144 DeclareType(param, declarePointers, true);
2146 DeclareType(type.returnType, declarePointers, true);
2148 else if(type.kind == pointerType && declarePointers)
2149 DeclareType(type.type, declarePointers, false);
2150 else if(type.kind == classType)
2152 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2153 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2155 else if(type.kind == structType || type.kind == unionType)
2158 for(member = type.members.first; member; member = member.next)
2159 DeclareType(member, false, false);
2161 else if(type.kind == arrayType)
2162 DeclareType(type.arrayType, declarePointers, false);
2166 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2168 ClassTemplateArgument * arg = null;
2170 ClassTemplateParameter curParam = null;
2172 for(sClass = _class; sClass; sClass = sClass.base)
2175 if(sClass.templateClass) sClass = sClass.templateClass;
2176 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2178 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2180 for(sClass = sClass.base; sClass; sClass = sClass.base)
2182 if(sClass.templateClass) sClass = sClass.templateClass;
2183 id += sClass.templateParams.count;
2193 arg = &_class.templateArgs[id];
2194 if(arg && param.type == type)
2195 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2200 public Context SetupTemplatesContext(Class _class)
2202 Context context = PushContext();
2203 context.templateTypesOnly = true;
2204 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2206 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2207 for(; param; param = param.next)
2209 if(param.type == type && param.identifier)
2211 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2212 curContext.templateTypes.Add((BTNode)type);
2219 for(sClass = _class; sClass; sClass = sClass.base)
2221 ClassTemplateParameter p;
2222 for(p = sClass.templateParams.first; p; p = p.next)
2224 //OldList * specs = MkList();
2225 //Declarator decl = null;
2226 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2229 TemplateParameter param = p.param;
2233 // ADD DATA TYPE HERE...
2234 p.param = param = TemplateParameter
2236 identifier = MkIdentifier(p.name), type = p.type,
2237 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2240 type = TemplatedType { key = (uintptr)p.name, param = param };
2241 curContext.templateTypes.Add((BTNode)type);
2249 public void FinishTemplatesContext(Context context)
2251 PopContext(context);
2252 FreeContext(context);
2256 public void ProcessMethodType(Method method)
2258 if(!method.dataType)
2260 Context context = SetupTemplatesContext(method._class);
2262 method.dataType = ProcessTypeString(method.dataTypeString, false);
2264 FinishTemplatesContext(context);
2266 if(method.type != virtualMethod && method.dataType)
2268 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2270 if(!method._class.symbol)
2271 method._class.symbol = FindClass(method._class.fullName);
2272 method.dataType.thisClass = method._class.symbol;
2276 // Why was this commented out? Working fine without now...
2279 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2280 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2287 char * par = strstr(type, "(");
2288 char * classOp = null;
2293 for(c = par-type-1; c >= 0; c++)
2295 if(type[c] == ':' && type[c+1] == ':')
2297 classOp = type + c - 1;
2298 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2305 else if(!isspace(type[c]))
2312 int typeLen = strlen(type);
2313 memcpy(temp, classOp, classOpLen);
2314 temp[classOpLen] = '\0';
2316 _class = eSystem_FindClass(module, temp);
2319 method.dataTypeString = new char[typeLen - classOpLen + 1];
2320 memcpy(method.dataTypeString, type, classOp - type);
2321 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2324 method.dataTypeString = type;
2330 public void ProcessPropertyType(Property prop)
2334 Context context = SetupTemplatesContext(prop._class);
2335 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2336 FinishTemplatesContext(context);
2340 public void DeclareMethod(Method method, char * name)
2342 Symbol symbol = method.symbol;
2343 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2345 bool imported = false;
2346 bool dllImport = false;
2348 if(!method.dataType)
2349 method.dataType = ProcessTypeString(method.dataTypeString, false);
2351 if(!symbol || symbol._import || method.type == virtualMethod)
2353 if(!symbol || method.type == virtualMethod)
2356 if(!method._class.symbol)
2357 method._class.symbol = FindClass(method._class.fullName);
2358 classSym = method._class.symbol;
2359 if(!classSym._import)
2361 ModuleImport module;
2363 if(method._class.module && method._class.module.name)
2364 module = FindModule(method._class.module);
2366 module = mainModule;
2367 classSym._import = ClassImport
2369 name = CopyString(method._class.fullName);
2370 isRemote = method._class.isRemote;
2372 module.classes.Add(classSym._import);
2376 symbol = method.symbol = Symbol { };
2380 symbol._import = (ClassImport)MethodImport
2382 name = CopyString(method.name);
2383 isVirtual = method.type == virtualMethod;
2385 classSym._import.methods.Add(symbol._import);
2389 // Set the symbol type
2393 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2395 else if(type.thisClass == (void *)-1)
2397 type.thisClass = null;
2400 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2401 symbol.type = method.dataType;
2402 if(symbol.type) symbol.type.refCount++;
2405 if(!method.thisClass || strcmp(method.thisClass, "void"))
2406 symbol.type.params.Insert(null,
2407 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2410 if(!method.dataType.dllExport)
2413 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2419 if(!method.dataType)
2420 method.dataType = ((Symbol)method.symbol).type;
2421 //ProcessMethodType(method);
2424 if(method.type != virtualMethod && method.dataType)
2425 DeclareType(method.dataType, true, true);
2427 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2429 // We need a declaration here :)
2431 OldList * specifiers, * declarators;
2433 Declarator funcDecl;
2436 specifiers = MkList();
2437 declarators = MkList();
2441 ListAdd(specifiers, MkSpecifier(EXTERN));
2442 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2443 ListAdd(specifiers, MkSpecifier(STATIC));
2445 if(method.type == virtualMethod)
2447 ListAdd(specifiers, MkSpecifier(INT));
2448 d = MkDeclaratorIdentifier(MkIdentifier(name));
2452 d = MkDeclaratorIdentifier(MkIdentifier(name));
2455 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2457 Context context = SetupTemplatesContext(method._class);
2458 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2459 FinishTemplatesContext(context);
2461 funcDecl = GetFuncDecl(d);
2465 Specifier spec, next;
2466 for(spec = specifiers->first; spec; spec = next)
2469 if(spec.type == extendedSpecifier)
2471 specifiers->Remove(spec);
2472 FreeSpecifier(spec);
2477 // Add this parameter if not a static method
2478 if(method.dataType && !method.dataType.staticMethod)
2480 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2482 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2483 TypeName thisParam = MkTypeName(MkListOne(
2484 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2485 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2486 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2487 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2489 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2491 TypeName param = funcDecl.function.parameters->first;
2492 funcDecl.function.parameters->Remove(param);
2493 FreeTypeName(param);
2496 if(!funcDecl.function.parameters)
2497 funcDecl.function.parameters = MkList();
2498 funcDecl.function.parameters->Insert(null, thisParam);
2501 // Make sure we don't have empty parameter declarations for static methods...
2503 else if(!funcDecl.function.parameters)
2505 funcDecl.function.parameters = MkList();
2506 funcDecl.function.parameters->Insert(null,
2507 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2511 ProcessDeclarator(d);
2513 ListAdd(declarators, MkInitDeclarator(d, null));
2515 decl = MkDeclaration(specifiers, declarators);
2517 ReplaceThisClassSpecifiers(specifiers, method._class);
2519 // Keep a different symbol for the function definition than the declaration...
2520 if(symbol.pointerExternal)
2522 Symbol functionSymbol { };
2526 *functionSymbol = *symbol;
2527 functionSymbol.string = CopyString(symbol.string);
2528 if(functionSymbol.type)
2529 functionSymbol.type.refCount++;
2532 excludedSymbols->Add(functionSymbol);
2533 symbol.pointerExternal.symbol = functionSymbol;
2535 external = MkExternalDeclaration(decl);
2537 ast->Insert(curExternal ? curExternal.prev : null, external);
2538 external.symbol = symbol;
2539 symbol.pointerExternal = external;
2543 // Move declaration higher...
2544 ast->Move(symbol.pointerExternal, curExternal.prev);
2547 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2551 char * ReplaceThisClass(Class _class)
2553 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2557 ClassTemplateParameter param;
2560 char className[1024];
2561 strcpy(className, _class.fullName);
2562 for(param = _class.templateParams.first; param; param = param.next)
2564 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2566 if(first) strcat(className, "<");
2567 if(!first) strcat(className, ", ");
2568 if(lastParam + 1 != p)
2570 strcat(className, param.name);
2571 strcat(className, " = ");
2573 strcat(className, param.name);
2581 int len = strlen(className);
2582 if(className[len-1] == '>') className[len++] = ' ';
2583 className[len++] = '>';
2584 className[len++] = '\0';
2586 return CopyString(className);
2589 return CopyString(_class.fullName);
2592 Type ReplaceThisClassType(Class _class)
2594 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2598 ClassTemplateParameter param;
2600 char className[1024];
2601 strcpy(className, _class.fullName);
2603 for(param = _class.templateParams.first; param; param = param.next)
2605 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2607 if(first) strcat(className, "<");
2608 if(!first) strcat(className, ", ");
2609 if(lastParam + 1 != p)
2611 strcat(className, param.name);
2612 strcat(className, " = ");
2614 strcat(className, param.name);
2622 int len = strlen(className);
2623 if(className[len-1] == '>') className[len++] = ' ';
2624 className[len++] = '>';
2625 className[len++] = '\0';
2627 return MkClassType(className);
2628 //return ProcessTypeString(className, false);
2632 return MkClassType(_class.fullName);
2633 //return ProcessTypeString(_class.fullName, false);
2637 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2639 if(specs != null && _class)
2642 for(spec = specs.first; spec; spec = spec.next)
2644 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2646 spec.type = nameSpecifier;
2647 spec.name = ReplaceThisClass(_class);
2648 spec.symbol = FindClass(spec.name); //_class.symbol;
2654 // Returns imported or not
2655 bool DeclareFunction(GlobalFunction function, char * name)
2657 Symbol symbol = function.symbol;
2658 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2660 bool imported = false;
2661 bool dllImport = false;
2663 if(!function.dataType)
2665 function.dataType = ProcessTypeString(function.dataTypeString, false);
2666 if(!function.dataType.thisClass)
2667 function.dataType.staticMethod = true;
2674 ModuleImport module = FindModule(function.module);
2675 // WARNING: This is not added anywhere...
2676 symbol = function.symbol = Symbol { };
2680 if(!function.dataType.dllExport)
2682 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2683 module.functions.Add(symbol._import);
2686 // Set the symbol type
2688 symbol.type = ProcessTypeString(function.dataTypeString, false);
2689 if(!symbol.type.thisClass)
2690 symbol.type.staticMethod = true;
2693 imported = symbol._import ? true : false;
2694 if(imported && function.module != privateModule && function.module.importType != staticImport)
2698 DeclareType(function.dataType, true, true);
2702 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2704 // We need a declaration here :)
2706 OldList * specifiers, * declarators;
2708 Declarator funcDecl;
2711 specifiers = MkList();
2712 declarators = MkList();
2715 ListAdd(specifiers, MkSpecifier(EXTERN));
2718 ListAdd(specifiers, MkSpecifier(STATIC));
2721 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2724 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2726 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2727 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2728 if(function.module.importType == staticImport)
2731 for(spec = specifiers->first; spec; spec = spec.next)
2732 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2734 specifiers->Remove(spec);
2735 FreeSpecifier(spec);
2740 funcDecl = GetFuncDecl(d);
2742 // Make sure we don't have empty parameter declarations for static methods...
2743 if(funcDecl && !funcDecl.function.parameters)
2745 funcDecl.function.parameters = MkList();
2746 funcDecl.function.parameters->Insert(null,
2747 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2750 ListAdd(declarators, MkInitDeclarator(d, null));
2753 Context oldCtx = curContext;
2754 curContext = globalContext;
2755 decl = MkDeclaration(specifiers, declarators);
2756 curContext = oldCtx;
2759 // Keep a different symbol for the function definition than the declaration...
2760 if(symbol.pointerExternal)
2762 Symbol functionSymbol { };
2765 *functionSymbol = *symbol;
2766 functionSymbol.string = CopyString(symbol.string);
2767 if(functionSymbol.type)
2768 functionSymbol.type.refCount++;
2771 excludedSymbols->Add(functionSymbol);
2773 symbol.pointerExternal.symbol = functionSymbol;
2775 external = MkExternalDeclaration(decl);
2777 ast->Insert(curExternal.prev, external);
2778 external.symbol = symbol;
2779 symbol.pointerExternal = external;
2783 // Move declaration higher...
2784 ast->Move(symbol.pointerExternal, curExternal.prev);
2788 symbol.id = curExternal.symbol.idCode;
2791 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2794 void DeclareGlobalData(GlobalData data)
2796 Symbol symbol = data.symbol;
2797 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2802 symbol = data.symbol = Symbol { };
2805 data.dataType = ProcessTypeString(data.dataTypeString, false);
2806 DeclareType(data.dataType, true, true);
2809 if(!symbol.pointerExternal)
2811 // We need a declaration here :)
2813 OldList * specifiers, * declarators;
2817 specifiers = MkList();
2818 declarators = MkList();
2820 ListAdd(specifiers, MkSpecifier(EXTERN));
2821 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2822 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2824 ListAdd(declarators, MkInitDeclarator(d, null));
2826 decl = MkDeclaration(specifiers, declarators);
2827 external = MkExternalDeclaration(decl);
2829 ast->Insert(curExternal.prev, external);
2830 external.symbol = symbol;
2831 symbol.pointerExternal = external;
2835 // Move declaration higher...
2836 ast->Move(symbol.pointerExternal, curExternal.prev);
2840 symbol.id = curExternal.symbol.idCode;
2845 class Conversion : struct
2847 Conversion prev, next;
2853 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2857 // Property convert;
2859 if(source.kind == templateType && dest.kind != templateType)
2861 Type type = ProcessTemplateParameterType(source.templateParameter);
2862 if(type) source = type;
2865 if(dest.kind == templateType && source.kind != templateType)
2867 Type type = ProcessTemplateParameterType(dest.templateParameter);
2868 if(type) dest = type;
2871 if((dest.classObjectType == typedObject && source.classObjectType != anyObject) || (dest.classObjectType == anyObject && source.classObjectType != typedObject))
2876 if(source.classObjectType == anyObject && dest.classObjectType != typedObject)
2881 if((dest.kind == structType && source.kind == structType) ||
2882 (dest.kind == unionType && source.kind == unionType))
2884 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2885 (source.members.first && source.members.first == dest.members.first))
2889 if(dest.kind == ellipsisType && source.kind != voidType)
2892 if(dest.kind == pointerType && dest.type.kind == voidType &&
2893 ((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))
2894 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2896 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2898 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2900 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2901 ((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))
2902 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2904 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2906 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2909 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2911 if(source._class.registered && source._class.registered.type == unitClass)
2913 if(conversions != null)
2915 if(source._class.registered == dest._class.registered)
2920 Class sourceBase, destBase;
2921 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2922 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2923 if(sourceBase == destBase)
2927 // Don't match enum inheriting from other enum if resolving enumeration values
2928 // TESTING: !dest.classObjectType
2929 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2931 (!source._class.registered || source._class.registered.type != enumClass) ||
2932 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2936 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2938 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2939 source._class && source._class.registered && source._class.registered.type != enumClass)
2941 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2949 // JUST ADDED THIS...
2950 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2955 // Just added this for Straight conversion of ColorAlpha => Color
2956 if(source.kind == classType)
2959 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2962 for(convert = _class.conversions.first; convert; convert = convert.next)
2964 if(convert.memberAccess == publicAccess || _class.module == privateModule)
2966 Conversion after = (conversions != null) ? conversions.last : null;
2968 if(!convert.dataType)
2969 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
2970 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
2972 if(!conversions && !convert.Get)
2974 else if(conversions != null)
2976 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
2977 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
2978 (dest.kind != classType || dest._class.registered != _class.base))
2982 Conversion conv { convert = convert, isGet = true };
2983 // conversions.Add(conv);
2984 conversions.Insert(after, conv);
2996 if(dest.kind == classType)
2999 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3002 for(convert = _class.conversions.first; convert; convert = convert.next)
3004 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3006 // Conversion after = (conversions != null) ? conversions.last : null;
3008 if(!convert.dataType)
3009 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3010 // Just added this equality check to prevent recursion.... Make it safer?
3011 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3012 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3014 if(!conversions && !convert.Set)
3016 else if(conversions != null)
3018 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3019 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3020 (source.kind != classType || source._class.registered != _class.base))
3024 // *** Testing this! ***
3025 Conversion conv { convert = convert };
3026 conversions.Add(conv);
3027 //conversions.Insert(after, conv);
3035 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3037 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3038 (source.kind != classType || source._class.registered.type != structClass))
3042 // TESTING THIS... IS THIS OK??
3043 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3045 if(!dest._class.registered.dataType)
3046 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3047 // Only support this for classes...
3048 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3049 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3051 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3060 if(source.kind == classType)
3063 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3066 for(convert = _class.conversions.first; convert; convert = convert.next)
3068 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3070 Conversion after = (conversions != null) ? conversions.last : null;
3072 if(!convert.dataType)
3073 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3074 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3076 if(!conversions && !convert.Get)
3078 else if(conversions != null)
3080 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3081 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3082 (dest.kind != classType || dest._class.registered != _class.base))
3086 Conversion conv { convert = convert, isGet = true };
3088 // conversions.Add(conv);
3089 conversions.Insert(after, conv);
3098 // TESTING THIS... IS THIS OK??
3099 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3101 if(!source._class.registered.dataType)
3102 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3103 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3111 if(source.kind == classType || source.kind == subClassType)
3113 else if(dest.kind == source.kind &&
3114 (dest.kind != structType && dest.kind != unionType &&
3115 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3117 // RECENTLY ADDED THESE
3118 else if(dest.kind == doubleType && source.kind == floatType)
3120 else if(dest.kind == shortType && source.kind == charType)
3122 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == intSizeType /* Exception here for size_t */))
3124 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3126 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3128 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3130 else if(source.kind == enumType &&
3131 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3133 else if(dest.kind == enumType &&
3134 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3136 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3137 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3139 Type paramSource, paramDest;
3141 if(dest.kind == methodType)
3142 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3143 if(source.kind == methodType)
3144 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3146 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3147 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3148 if(dest.kind == methodType)
3149 dest = dest.method.dataType;
3150 if(source.kind == methodType)
3151 source = source.method.dataType;
3153 paramSource = source.params.first;
3154 if(paramSource && paramSource.kind == voidType) paramSource = null;
3155 paramDest = dest.params.first;
3156 if(paramDest && paramDest.kind == voidType) paramDest = null;
3159 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3160 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3162 // Source thisClass must be derived from destination thisClass
3163 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3164 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3166 if(paramDest && paramDest.kind == classType)
3167 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3169 Compiler_Error($"method class should not take an object\n");
3172 paramDest = paramDest.next;
3174 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3176 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3180 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3182 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3188 // THIS WAS BACKWARDS:
3189 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3190 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3193 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3195 Compiler_Error($"overriding class expected to be derived from method class\n");
3199 paramSource = paramSource.next;
3205 // Source thisClass must be derived from destination thisClass
3206 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3208 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3214 // THIS WAS BACKWARDS TOO??
3215 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3216 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3219 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3221 //Compiler_Error($"overriding class expected to be derived from method class\n");
3229 // Source return type must be derived from destination return type
3230 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3232 Compiler_Warning($"incompatible return type for function\n");
3238 for(; paramDest; paramDest = paramDest.next)
3242 //Compiler_Warning($"not enough parameters\n");
3243 Compiler_Error($"not enough parameters\n");
3247 Type paramDestType = paramDest;
3248 Type paramSourceType = paramSource;
3249 Type type = paramDestType;
3251 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3252 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3253 paramSource.kind != templateType)
3256 ClassTemplateParameter curParam = null;
3258 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3261 if(sClass.templateClass) sClass = sClass.templateClass;
3262 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3264 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3266 for(sClass = sClass.base; sClass; sClass = sClass.base)
3268 if(sClass.templateClass) sClass = sClass.templateClass;
3269 id += sClass.templateParams.count;
3280 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3281 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3285 // paramDest must be derived from paramSource
3286 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3287 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3291 PrintType(paramDest, type, false, true);
3292 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3294 if(paramDestType != paramDest)
3295 FreeType(paramDestType);
3298 if(paramDestType != paramDest)
3299 FreeType(paramDestType);
3302 paramSource = paramSource.next;
3306 Compiler_Error($"too many parameters\n");
3311 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3315 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3316 (source.kind == arrayType || source.kind == pointerType))
3318 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3325 static void FreeConvert(Conversion convert)
3327 if(convert.resultType)
3328 FreeType(convert.resultType);
3331 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3332 char * string, OldList conversions)
3336 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3338 Class _class = link.data;
3339 if(_class.type == enumClass)
3341 OldList converts { };
3343 type.kind = classType;
3346 _class.symbol = FindClass(_class.fullName);
3347 type._class = _class.symbol;
3349 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3352 Class enumClass = eSystem_FindClass(privateModule, "enum");
3356 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3358 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3359 for(value = e.values.first; value; value = value.next)
3361 if(!strcmp(value.name, string))
3366 FreeExpContents(sourceExp);
3367 FreeType(sourceExp.expType);
3369 sourceExp.isConstant = true;
3370 sourceExp.expType = MkClassType(baseClass.fullName);
3374 sourceExp.type = constantExp;
3375 if(!strcmp(baseClass.dataTypeString, "int"))
3376 sprintf(constant, "%d",value.data);
3378 sprintf(constant, "0x%X",value.data);
3379 sourceExp.constant = CopyString(constant);
3380 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3383 while(converts.first)
3385 Conversion convert = converts.first;
3386 converts.Remove(convert);
3387 conversions.Add(convert);
3396 converts.Free(FreeConvert);
3400 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3401 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3406 public bool ModuleVisibility(Module searchIn, Module searchFor)
3408 SubModule subModule;
3410 if(searchFor == searchIn)
3413 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3415 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3417 if(ModuleVisibility(subModule.module, searchFor))
3424 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3428 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3430 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3432 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3435 for(module = mainModule.application.allModules.first; module; module = module.next)
3437 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3443 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3445 Type source = sourceExp.expType;
3446 Type realDest = dest;
3447 Type backupSourceExpType = null;
3449 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3452 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3454 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3456 Class sourceBase, destBase;
3457 for(sourceBase = source._class.registered;
3458 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3459 sourceBase = sourceBase.base);
3460 for(destBase = dest._class.registered;
3461 destBase && destBase.base && destBase.base.type != systemClass;
3462 destBase = destBase.base);
3463 //if(source._class.registered == dest._class.registered)
3464 if(sourceBase == destBase)
3473 int64 value = MAXINT;
3478 if(sourceExp.type == constantExp)
3481 value = strtoll(sourceExp.constant, null, 0);
3483 value = strtoull(sourceExp.constant, null, 0);
3485 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3488 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3490 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3493 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3494 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3497 source = Type { kind = intType, isSigned = false, refCount = 1 };
3500 if(dest.kind == classType)
3502 Class _class = dest._class ? dest._class.registered : null;
3504 if(_class && _class.type == unitClass)
3506 if(source.kind != classType)
3509 Type tempDest, tempSource;
3511 for(; _class.base.type != systemClass; _class = _class.base);
3513 tempDest = tempType;
3515 tempType.kind = classType;
3517 _class.symbol = FindClass(_class.fullName);
3519 tempType._class = _class.symbol;
3520 tempType.truth = dest.truth;
3522 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3524 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3525 backupSourceExpType = sourceExp.expType;
3526 sourceExp.expType = dest; dest.refCount++;
3527 //sourceExp.expType = MkClassType(_class.fullName);
3535 // Why wasn't there something like this?
3536 if(_class && _class.type == bitClass && source.kind != classType)
3538 if(!dest._class.registered.dataType)
3539 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3540 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3543 FreeType(sourceExp.expType);
3544 source = sourceExp.expType = MkClassType(dest._class.string);
3547 //source.kind = classType;
3548 //source._class = dest._class;
3552 // Adding two enumerations
3554 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3556 if(!source._class.registered.dataType)
3557 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3558 if(!dest._class.registered.dataType)
3559 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3561 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3564 source = sourceExp.expType = MkClassType(dest._class.string);
3567 //source.kind = classType;
3568 //source._class = dest._class;
3572 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3574 OldList * specs = MkList();
3578 ReadString(string, sourceExp.string);
3579 decl = SpecDeclFromString(string, specs, null);
3581 FreeExpContents(sourceExp);
3582 FreeType(sourceExp.expType);
3584 sourceExp.type = classExp;
3585 sourceExp._classExp.specifiers = specs;
3586 sourceExp._classExp.decl = decl;
3587 sourceExp.expType = dest;
3592 if(backupSourceExpType) FreeType(backupSourceExpType);
3596 else if(source.kind == classType)
3598 Class _class = source._class ? source._class.registered : null;
3600 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3603 if(dest.kind != classType)
3605 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3606 if(!source._class.registered.dataType)
3607 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3610 dest = MkClassType(source._class.string);
3611 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3612 // dest = MkClassType(source._class.string);
3616 if(dest.kind != classType)
3619 Type tempDest, tempSource;
3621 if(!source._class.registered.dataType)
3622 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3624 for(; _class.base.type != systemClass; _class = _class.base);
3626 tempSource = tempType;
3627 tempType.kind = classType;
3628 tempType._class = FindClass(_class.fullName);
3629 tempType.truth = source.truth;
3630 tempType.classObjectType = source.classObjectType;
3633 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3635 // PUT THIS BACK TESTING UNITS?
3636 if(conversions.last)
3638 ((Conversion)(conversions.last)).resultType = dest;
3642 FreeType(sourceExp.expType);
3643 sourceExp.expType = MkClassType(_class.fullName);
3644 sourceExp.expType.truth = source.truth;
3645 sourceExp.expType.classObjectType = source.classObjectType;
3647 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3649 if(!sourceExp.destType)
3651 FreeType(sourceExp.destType);
3652 sourceExp.destType = sourceExp.expType;
3653 if(sourceExp.expType)
3654 sourceExp.expType.refCount++;
3657 //source = _class.dataType;
3660 // TOCHECK: TESTING THIS NEW CODE
3661 if(!_class.dataType)
3662 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3664 dest = MkClassType(source._class.string);
3665 dest.truth = source.truth;
3666 dest.classObjectType = source.classObjectType;
3669 source = _class.dataType;
3679 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3689 if(source.kind == classType)
3691 Class _class = source._class.registered;
3692 if(_class.type == unitClass)
3694 if(!_class.dataType)
3695 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3696 source = _class.dataType;
3700 if(dest.kind == classType)
3702 Class _class = dest._class ? dest._class.registered : null;
3703 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3704 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3706 if(_class.type == normalClass || _class.type == noHeadClass)
3708 Expression newExp { };
3709 *newExp = *sourceExp;
3710 if(sourceExp.destType) sourceExp.destType.refCount++;
3711 if(sourceExp.expType) sourceExp.expType.refCount++;
3712 sourceExp.type = castExp;
3713 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3714 sourceExp.cast.exp = newExp;
3715 FreeType(sourceExp.expType);
3716 sourceExp.expType = null;
3717 ProcessExpressionType(sourceExp);
3719 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3722 FreeType(sourceExp.expType);
3723 sourceExp.expType = dest;
3727 if(inCompiler) FreeType(dest);
3729 if(backupSourceExpType) FreeType(backupSourceExpType);
3733 if(!_class.dataType)
3734 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3736 dest = _class.dataType;
3740 // Accept lower precision types for units, since we want to keep the unit type
3741 if(dest.kind == doubleType &&
3742 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3743 source.kind == charType))
3745 specs = MkListOne(MkSpecifier(DOUBLE));
3747 else if(dest.kind == floatType &&
3748 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3749 source.kind == doubleType))
3751 specs = MkListOne(MkSpecifier(FLOAT));
3753 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3754 source.kind == floatType || source.kind == doubleType))
3757 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3758 ListAdd(specs, MkSpecifier(INT64));
3760 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3761 source.kind == floatType || source.kind == doubleType))
3764 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3765 ListAdd(specs, MkSpecifier(INT));
3767 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
3768 source.kind == floatType || source.kind == doubleType))
3771 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3772 ListAdd(specs, MkSpecifier(SHORT));
3774 else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
3775 source.kind == floatType || source.kind == doubleType))
3778 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3779 ListAdd(specs, MkSpecifier(CHAR));
3785 if(backupSourceExpType)
3787 // Failed to convert: revert previous exp type
3788 if(sourceExp.expType) FreeType(sourceExp.expType);
3789 sourceExp.expType = backupSourceExpType;
3794 else if(dest.kind == doubleType &&
3795 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3796 source.kind == charType))
3798 specs = MkListOne(MkSpecifier(DOUBLE));
3800 else if(dest.kind == floatType &&
3801 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3803 specs = MkListOne(MkSpecifier(FLOAT));
3805 else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3806 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3809 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3810 ListAdd(specs, MkSpecifier(CHAR));
3812 else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
3813 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3816 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3817 ListAdd(specs, MkSpecifier(SHORT));
3819 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
3822 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3823 ListAdd(specs, MkSpecifier(INT));
3825 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3828 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3829 ListAdd(specs, MkSpecifier(INT64));
3831 else if(dest.kind == enumType &&
3832 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3834 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3840 if(backupSourceExpType)
3842 // Failed to convert: revert previous exp type
3843 if(sourceExp.expType) FreeType(sourceExp.expType);
3844 sourceExp.expType = backupSourceExpType;
3851 Expression newExp { };
3852 *newExp = *sourceExp;
3855 if(sourceExp.destType) sourceExp.destType.refCount++;
3856 if(sourceExp.expType) sourceExp.expType.refCount++;
3858 sourceExp.type = castExp;
3859 if(realDest.kind == classType)
3861 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3862 FreeList(specs, FreeSpecifier);
3865 sourceExp.cast.typeName = MkTypeName(specs, null);
3866 if(newExp.type == opExp)
3868 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3871 sourceExp.cast.exp = newExp;
3873 FreeType(sourceExp.expType);
3874 sourceExp.expType = null;
3875 ProcessExpressionType(sourceExp);
3878 FreeList(specs, FreeSpecifier);
3882 if(backupSourceExpType) FreeType(backupSourceExpType);
3888 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3889 if(sourceExp.type == identifierExp)
3891 Identifier id = sourceExp.identifier;
3892 if(dest.kind == classType)
3894 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3896 Class _class = dest._class.registered;
3897 Class enumClass = eSystem_FindClass(privateModule, "enum");
3900 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3903 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3904 for(value = e.values.first; value; value = value.next)
3906 if(!strcmp(value.name, id.string))
3911 FreeExpContents(sourceExp);
3912 FreeType(sourceExp.expType);
3914 sourceExp.isConstant = true;
3915 sourceExp.expType = MkClassType(_class.fullName);
3919 sourceExp.type = constantExp;
3920 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3921 sprintf(constant, "%d",value.data);
3923 sprintf(constant, "0x%X",value.data);
3924 sourceExp.constant = CopyString(constant);
3925 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3934 // Loop through all enum classes
3935 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3942 #define TERTIARY(o, name, m, t, p) \
3943 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3945 exp.type = constantExp; \
3946 exp.string = p(op1.m ? op2.m : op3.m); \
3948 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3952 #define BINARY(o, name, m, t, p) \
3953 static bool name(Expression exp, Operand op1, Operand op2) \
3956 exp.type = constantExp; \
3957 exp.string = p(op1.m o value2); \
3959 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3963 #define BINARY_DIVIDE(o, name, m, t, p) \
3964 static bool name(Expression exp, Operand op1, Operand op2) \
3967 exp.type = constantExp; \
3968 exp.string = p(value2 ? (op1.m o value2) : 0); \
3970 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3974 #define UNARY(o, name, m, t, p) \
3975 static bool name(Expression exp, Operand op1) \
3977 exp.type = constantExp; \
3978 exp.string = p(o op1.m); \
3980 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3984 #define OPERATOR_ALL(macro, o, name) \
3985 macro(o, Int##name, i, int, PrintInt) \
3986 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
3987 macro(o, Short##name, s, short, PrintShort) \
3988 macro(o, UShort##name, us, unsigned short, PrintUShort) \
3989 macro(o, Char##name, c, char, PrintChar) \
3990 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
3991 macro(o, Float##name, f, float, PrintFloat) \
3992 macro(o, Double##name, d, double, PrintDouble)
3994 #define OPERATOR_INTTYPES(macro, o, name) \
3995 macro(o, Int##name, i, int, PrintInt) \
3996 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
3997 macro(o, Short##name, s, short, PrintShort) \
3998 macro(o, UShort##name, us, unsigned short, PrintUShort) \
3999 macro(o, Char##name, c, char, PrintChar) \
4000 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4003 // binary arithmetic
4004 OPERATOR_ALL(BINARY, +, Add)
4005 OPERATOR_ALL(BINARY, -, Sub)
4006 OPERATOR_ALL(BINARY, *, Mul)
4007 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4008 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4011 OPERATOR_ALL(UNARY, -, Neg)
4013 // unary arithmetic increment and decrement
4014 OPERATOR_ALL(UNARY, ++, Inc)
4015 OPERATOR_ALL(UNARY, --, Dec)
4017 // binary arithmetic assignment
4018 OPERATOR_ALL(BINARY, =, Asign)
4019 OPERATOR_ALL(BINARY, +=, AddAsign)
4020 OPERATOR_ALL(BINARY, -=, SubAsign)
4021 OPERATOR_ALL(BINARY, *=, MulAsign)
4022 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4023 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4026 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4027 OPERATOR_INTTYPES(BINARY, |, BitOr)
4028 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4029 OPERATOR_INTTYPES(BINARY, <<, LShift)
4030 OPERATOR_INTTYPES(BINARY, >>, RShift)
4033 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4035 // binary bitwise assignment
4036 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4037 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4038 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4039 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4040 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4042 // unary logical negation
4043 OPERATOR_INTTYPES(UNARY, !, Not)
4045 // binary logical equality
4046 OPERATOR_ALL(BINARY, ==, Equ)
4047 OPERATOR_ALL(BINARY, !=, Nqu)
4050 OPERATOR_ALL(BINARY, &&, And)
4051 OPERATOR_ALL(BINARY, ||, Or)
4053 // binary logical relational
4054 OPERATOR_ALL(BINARY, >, Grt)
4055 OPERATOR_ALL(BINARY, <, Sma)
4056 OPERATOR_ALL(BINARY, >=, GrtEqu)
4057 OPERATOR_ALL(BINARY, <=, SmaEqu)
4059 // tertiary condition operator
4060 OPERATOR_ALL(TERTIARY, ?, Cond)
4062 //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
4063 #define OPERATOR_TABLE_ALL(name, type) \
4064 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4066 type##Inc, type##Dec, \
4067 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4068 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4070 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4072 type##Equ, type##Nqu, \
4073 type##And, type##Or, \
4074 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4077 #define OPERATOR_TABLE_INTTYPES(name, type) \
4078 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4080 type##Inc, type##Dec, \
4081 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4082 null, null, null, null, null, \
4084 null, null, null, null, null, \
4086 type##Equ, type##Nqu, \
4087 type##And, type##Or, \
4088 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4091 OPERATOR_TABLE_ALL(int, Int)
4092 OPERATOR_TABLE_ALL(uint, UInt)
4093 OPERATOR_TABLE_ALL(short, Short)
4094 OPERATOR_TABLE_ALL(ushort, UShort)
4095 OPERATOR_TABLE_INTTYPES(float, Float)
4096 OPERATOR_TABLE_INTTYPES(double, Double)
4097 OPERATOR_TABLE_ALL(char, Char)
4098 OPERATOR_TABLE_ALL(uchar, UChar)
4100 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4101 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4102 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4103 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4104 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4105 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4106 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4107 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4109 public void ReadString(char * output, char * string)
4111 int len = strlen(string);
4113 bool quoted = false, escaped = false;
4114 for(c = 0; c<len; c++)
4116 char ch = string[c];
4121 case 'n': output[d] = '\n'; break;
4122 case 't': output[d] = '\t'; break;
4123 case 'a': output[d] = '\a'; break;
4124 case 'b': output[d] = '\b'; break;
4125 case 'f': output[d] = '\f'; break;
4126 case 'r': output[d] = '\r'; break;
4127 case 'v': output[d] = '\v'; break;
4128 case '\\': output[d] = '\\'; break;
4129 case '\"': output[d] = '\"'; break;
4130 default: output[d++] = '\\'; output[d] = ch;
4131 //default: output[d] = ch;
4152 public Operand GetOperand(Expression exp)
4155 Type type = exp.expType;
4158 while(type.kind == classType &&
4159 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4161 if(!type._class.registered.dataType)
4162 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4163 type = type._class.registered.dataType;
4166 op.kind = type.kind;
4167 op.type = exp.expType;
4168 if(exp.isConstant && exp.type == constantExp)
4174 if(exp.constant[0] == '\'')
4175 op.c = exp.constant[1];
4176 else if(type.isSigned)
4178 op.c = (char)strtol(exp.constant, null, 0);
4183 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4191 op.s = (short)strtol(exp.constant, null, 0);
4196 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4204 op.i = (int)strtol(exp.constant, null, 0);
4209 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4217 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4222 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4230 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4235 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4243 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4248 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4254 op.f = (float)strtod(exp.constant, null);
4258 op.d = (double)strtod(exp.constant, null);
4261 //case classType: For when we have operator overloading...
4262 // Pointer additions
4263 //case functionType:
4267 op.ui64 = _strtoui64(exp.constant, null, 0);
4268 op.kind = pointerType;
4278 static void UnusedFunction()
4281 a.OnGetString(0,0,0);
4284 extern int __ecereVMethodID_class_OnGetString;
4287 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4289 DataMember dataMember;
4290 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4292 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4293 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4297 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4299 void * ptr = inst.data + dataMember.offset + offset;
4300 char * result = null;
4301 exp.loc = member.loc = inst.loc;
4302 ((Identifier)member.identifiers->first).loc = inst.loc;
4304 if(!dataMember.dataType)
4305 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4306 type = dataMember.dataType;
4307 if(type.kind == classType)
4309 Class _class = type._class.registered;
4310 if(_class.type == enumClass)
4312 Class enumClass = eSystem_FindClass(privateModule, "enum");
4315 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4317 for(item = e.values.first; item; item = item.next)
4319 if((int)item.data == *(int *)ptr)
4327 exp.identifier = MkIdentifier(result);
4328 exp.type = identifierExp;
4329 exp.destType = MkClassType(_class.fullName);
4330 ProcessExpressionType(exp);
4334 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4336 if(!_class.dataType)
4337 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4338 type = _class.dataType;
4347 FreeExpContents(exp);
4349 exp.constant = PrintFloat(*(float*)ptr);
4350 exp.type = constantExp;
4355 FreeExpContents(exp);
4357 exp.constant = PrintDouble(*(double*)ptr);
4358 exp.type = constantExp;
4363 FreeExpContents(exp);
4365 exp.constant = PrintInt(*(int*)ptr);
4366 exp.type = constantExp;
4371 FreeExpContents(exp);
4373 exp.constant = PrintInt64(*(int64*)ptr);
4374 exp.type = constantExp;
4379 FreeExpContents(exp);
4380 // TODO: This should probably use proper type
4381 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4382 exp.type = constantExp;
4387 FreeExpContents(exp);
4388 // TODO: This should probably use proper type
4389 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4390 exp.type = constantExp;
4394 Compiler_Error($"Unhandled type populating instance\n");
4397 ListAdd(memberList, member);
4400 if(parentDataMember.type == unionMember)
4405 void PopulateInstance(Instantiation inst)
4407 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4408 Class _class = classSym.registered;
4409 DataMember dataMember;
4410 OldList * memberList = MkList();
4411 inst.members = MkListOne(MkMembersInitList(memberList));
4412 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4414 if(!dataMember.isProperty)
4416 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4417 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4421 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4423 void * ptr = inst.data + dataMember.offset;
4424 char * result = null;
4426 exp.loc = member.loc = inst.loc;
4427 ((Identifier)member.identifiers->first).loc = inst.loc;
4429 if(!dataMember.dataType)
4430 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4431 type = dataMember.dataType;
4432 if(type.kind == classType)
4434 Class _class = type._class.registered;
4435 if(_class.type == enumClass)
4437 Class enumClass = eSystem_FindClass(privateModule, "enum");
4440 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4442 for(item = e.values.first; item; item = item.next)
4444 if((int)item.data == *(int *)ptr)
4453 exp.identifier = MkIdentifier(result);
4454 exp.type = identifierExp;
4455 exp.destType = MkClassType(_class.fullName);
4456 ProcessExpressionType(exp);
4459 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4461 if(!_class.dataType)
4462 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4463 type = _class.dataType;
4472 exp.constant = PrintFloat(*(float*)ptr);
4473 exp.type = constantExp;
4478 exp.constant = PrintDouble(*(double*)ptr);
4479 exp.type = constantExp;
4484 exp.constant = PrintInt(*(int*)ptr);
4485 exp.type = constantExp;
4490 exp.constant = PrintInt64(*(int64*)ptr);
4491 exp.type = constantExp;
4496 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4497 exp.type = constantExp;
4501 Compiler_Error($"Unhandled type populating instance\n");
4504 ListAdd(memberList, member);
4510 void ComputeInstantiation(Expression exp)
4512 Instantiation inst = exp.instance;
4513 MembersInit members;
4514 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4515 Class _class = classSym ? classSym.registered : null;
4516 DataMember curMember = null;
4517 Class curClass = null;
4518 DataMember subMemberStack[256];
4519 int subMemberStackPos = 0;
4522 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4524 // Don't recompute the instantiation...
4525 // Non Simple classes will have become constants by now
4529 if(_class.type == normalClass || _class.type == noHeadClass)
4530 inst.data = (byte *)eInstance_New(_class);
4532 inst.data = new0 byte[_class.structSize];
4537 for(members = inst.members->first; members; members = members.next)
4539 switch(members.type)
4541 case dataMembersInit:
4543 if(members.dataMembers)
4546 for(member = members.dataMembers->first; member; member = member.next)
4548 Identifier ident = member.identifiers ? member.identifiers->first : null;
4551 Property prop = null;
4552 DataMember dataMember = null;
4553 Method method = null;
4554 uint dataMemberOffset;
4558 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4561 if(curMember.isProperty)
4562 prop = (Property)curMember;
4565 dataMember = curMember;
4567 // CHANGED THIS HERE
4568 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4569 // dataMemberOffset = dataMember.offset;
4576 prop = eClass_FindProperty(_class, ident.string, privateModule);
4580 if(prop.memberAccess == publicAccess)
4582 curMember = (DataMember)prop;
4583 curClass = prop._class;
4588 DataMember _subMemberStack[256];
4589 int _subMemberStackPos = 0;
4591 // FILL MEMBER STACK
4592 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4597 if(dataMember.memberAccess == publicAccess)
4599 curMember = dataMember;
4600 curClass = dataMember._class;
4601 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
4602 subMemberStackPos = _subMemberStackPos;
4608 if(found && member.initializer && member.initializer.type == expInitializer)
4610 Expression value = member.initializer.exp;
4614 type = prop.dataType;
4618 if(!dataMember.dataType)
4619 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4621 type = dataMember.dataType;
4624 if(ident && ident.next)
4626 // for(; ident && type; ident = ident.next)
4627 for(ident = ident.next; ident && type; ident = ident.next)
4629 if(type.kind == classType)
4631 prop = eClass_FindProperty(type._class.registered,
4632 ident.string, privateModule);
4634 type = prop.dataType;
4637 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4638 ident.string, &dataMemberOffset, privateModule, null, null);
4640 type = dataMember.dataType;
4643 else if(type.kind == structType || type.kind == unionType)
4646 for(memberType = type.members.first; memberType; memberType = memberType.next)
4648 if(!strcmp(memberType.name, ident.string))
4659 FreeType(value.destType);
4660 value.destType = type;
4661 if(type) type.refCount++;
4662 ComputeExpression(value);
4664 if(value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4666 if(type.kind == classType)
4668 Class _class = type._class.registered;
4669 if(_class.type == bitClass || _class.type == unitClass ||
4670 _class.type == enumClass)
4672 if(!_class.dataType)
4673 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4674 type = _class.dataType;
4680 void * ptr = inst.data + dataMemberOffset;
4682 if(value.type == constantExp)
4688 GetInt(value, (int*)ptr);
4693 GetInt64(value, (int64*)ptr);
4698 GetIntPtr(value, (intptr*)ptr);
4703 GetIntSize(value, (intsize*)ptr);
4708 GetFloat(value, (float*)ptr);
4713 GetDouble(value, (double *)ptr);
4718 else if(value.type == instanceExp)
4720 if(type.kind == classType)
4722 Class _class = type._class.registered;
4723 if(_class.type == structClass)
4725 ComputeTypeSize(type);
4726 if(value.instance.data)
4727 memcpy(ptr, value.instance.data, type.size);
4734 if(value.type == instanceExp && value.instance.data)
4736 void (*Set)(void *, void *) = (void *)prop.Set;
4737 Set(inst.data, value.instance.data);
4738 PopulateInstance(inst);
4740 else if(value.type == constantExp)
4746 void (*Set)(void *, double) = (void *)prop.Set;
4747 Set(inst.data, strtod(value.constant, null) );
4752 void (*Set)(void *, float) = (void *)prop.Set;
4753 Set(inst.data, (float)(strtod(value.constant, null)));
4758 void (*Set)(void *, int) = (void *)prop.Set;
4759 Set(inst.data, strtol(value.constant, null, 0));
4764 void (*Set)(void *, int64) = (void *)prop.Set;
4765 Set(inst.data, _strtoi64(value.constant, null, 0));
4770 void (*Set)(void *, intptr) = (void *)prop.Set;
4771 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4776 void (*Set)(void *, intsize) = (void *)prop.Set;
4777 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4782 else if(value.type == stringExp)
4785 ReadString(temp, value.string);
4786 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4790 else if(_class.type == unitClass)
4794 // Only support converting units to units for now...
4795 if(value.type == constantExp)
4797 if(type.kind == classType)
4799 Class _class = type._class.registered;
4800 if(_class.type == unitClass)
4802 if(!_class.dataType)
4803 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4804 type = _class.dataType;
4807 // TODO: Assuming same base type for units...
4813 float (*Set)(float) = (void *)prop.Set;
4814 GetFloat(member.initializer.exp, &fValue);
4815 exp.constant = PrintFloat(Set(fValue));
4816 exp.type = constantExp;
4822 double (*Set)(double) = (void *)prop.Set;
4823 GetDouble(member.initializer.exp, &dValue);
4824 exp.constant = PrintDouble(Set(dValue));
4825 exp.type = constantExp;
4832 else if(_class.type == bitClass)
4836 if(value.type == instanceExp && value.instance.data)
4838 unsigned int (*Set)(void *) = (void *)prop.Set;
4839 bits = Set(value.instance.data);
4841 else if(value.type == constantExp)
4847 BitMember bitMember = (BitMember) dataMember;
4850 GetInt(value, &part);
4851 bits = (bits & ~bitMember.mask);
4852 if(!bitMember.dataType)
4853 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4855 type = bitMember.dataType;
4857 if(type.kind == classType && type._class && type._class.registered)
4859 if(!type._class.registered.dataType)
4860 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4861 type = type._class.registered.dataType;
4868 bits |= ((char)part << bitMember.pos);
4870 bits |= ((unsigned char)part << bitMember.pos);
4874 bits |= ((short)part << bitMember.pos);
4876 bits |= ((unsigned short)part << bitMember.pos);
4881 bits |= ((int)part << bitMember.pos);
4883 bits |= ((unsigned int)part << bitMember.pos);
4887 bits |= ((int64)part << bitMember.pos);
4889 bits |= ((uint64)part << bitMember.pos);
4894 bits |= ((intptr)part << bitMember.pos);
4898 bits |= ((uintptr)part << bitMember.pos);
4904 bits |= ((ssize_t)(intsize)part << bitMember.pos);
4908 bits |= ((size_t) (uintsize)part << bitMember.pos);
4917 if(_class && _class.type == unitClass)
4919 ComputeExpression(member.initializer.exp);
4920 exp.constant = member.initializer.exp.constant;
4921 exp.type = constantExp;
4923 member.initializer.exp.constant = null;
4933 if(_class && _class.type == bitClass)
4935 exp.constant = PrintHexUInt(bits);
4936 exp.type = constantExp;
4938 if(exp.type != instanceExp)
4944 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4946 if(exp.op.op == SIZEOF)
4948 FreeExpContents(exp);
4949 exp.type = constantExp;
4950 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
4961 // Provide default unary +
4962 Expression exp2 = exp.op.exp2;
4964 FreeExpContents(exp);
4965 FreeType(exp.expType);
4966 FreeType(exp.destType);
4972 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
4974 // unary arithmetic increment and decrement
4975 //OPERATOR_ALL(UNARY, ++, Inc)
4976 //OPERATOR_ALL(UNARY, --, Dec)
4979 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
4981 // unary logical negation
4983 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
4991 // binary arithmetic
4993 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
4996 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
4999 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5002 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5005 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5007 // binary arithmetic assignment
5008 //OPERATOR_ALL(BINARY, =, Asign)
5009 //OPERATOR_ALL(BINARY, +=, AddAsign)
5010 //OPERATOR_ALL(BINARY, -=, SubAsign)
5011 //OPERATOR_ALL(BINARY, *=, MulAsign)
5012 //OPERATOR_ALL(BINARY, /=, DivAsign)
5013 //OPERATOR_ALL(BINARY, %=, ModAsign)
5018 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5022 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5025 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5028 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5031 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5033 // binary bitwise assignment
5034 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5035 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5036 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5037 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5038 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5039 // binary logical equality
5041 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5044 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5048 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5051 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5053 // binary logical relational
5055 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5058 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5061 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5064 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5071 void ComputeExpression(Expression exp)
5073 char expString[10240];
5074 expString[0] = '\0';
5076 PrintExpression(exp, expString);
5083 ComputeInstantiation(exp);
5092 Expression exp1, exp2 = null;
5096 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5098 ComputeExpression(exp.op.exp2);
5101 ComputeExpression(exp.op.exp1);
5104 op1 = GetOperand(exp1);
5105 if(op1.type) op1.type.refCount++;
5108 op2 = GetOperand(exp2);
5109 if(op2.type) op2.type.refCount++;
5115 op1 = GetOperand(exp1);
5116 if(op1.type) op1.type.refCount++;
5119 CallOperator(exp, exp1, exp2, op1, op2);
5126 if(exp.op.exp1 && exp.op.exp2)
5131 FreeExpContents(exp);
5132 op1.ops.BitAnd(exp, op1, op2);
5141 FreeExpContents(exp);
5142 op1.ops.Mul(exp, op1, op2);
5151 FreeExpContents(exp);
5152 op1.ops.Add(exp, op1, op2);
5157 // Provide default unary +
5158 Expression exp2 = exp.op.exp2;
5160 FreeExpContents(exp);
5161 FreeType(exp.expType);
5162 FreeType(exp.destType);
5173 FreeExpContents(exp);
5174 op1.ops.Sub(exp, op1, op2);
5181 FreeExpContents(exp);
5182 op1.ops.Neg(exp, op1);
5189 FreeExpContents(exp);
5190 op1.ops.BitNot(exp, op1);
5196 FreeExpContents(exp);
5197 op1.ops.Not(exp, op1);
5200 // Binary only operators
5204 FreeExpContents(exp);
5205 op1.ops.Div(exp, op1, op2);
5211 FreeExpContents(exp);
5212 op1.ops.Mod(exp, op1, op2);
5224 FreeExpContents(exp);
5225 op1.ops.Sma(exp, op1, op2);
5234 FreeExpContents(exp);
5235 op1.ops.Grt(exp, op1, op2);
5244 FreeExpContents(exp);
5245 op1.ops.SmaEqu(exp, op1, op2);
5254 FreeExpContents(exp);
5255 op1.ops.GrtEqu(exp, op1, op2);
5264 FreeExpContents(exp);
5265 op1.ops.Equ(exp, op1, op2);
5274 FreeExpContents(exp);
5275 op1.ops.Nqu(exp, op1, op2);
5282 FreeExpContents(exp);
5283 op1.ops.BitOr(exp, op1, op2);
5289 FreeExpContents(exp);
5290 op1.ops.BitXor(exp, op1, op2);
5298 FreeExpContents(exp);
5299 exp.type = constantExp;
5300 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5304 if(op1.type) FreeType(op1.type);
5305 if(op2.type) FreeType(op2.type);
5309 case extensionExpressionExp:
5312 for(e = exp.list->first; e; e = n)
5317 OldList * list = exp.list;
5318 ComputeExpression(e);
5319 //FreeExpContents(exp);
5320 FreeType(exp.expType);
5321 FreeType(exp.destType);
5338 exp.isConstant = true;
5340 ComputeExpression(exp.index.exp);
5341 if(!exp.index.exp.isConstant)
5342 exp.isConstant = false;
5344 for(e = exp.index.index->first; e; e = e.next)
5346 ComputeExpression(e);
5349 // Check if this type is int
5352 exp.isConstant = false;
5354 exp.expType = Dereference(exp.index.exp.expType);
5360 Expression memberExp = exp.member.exp;
5361 Identifier memberID = exp.member.member;
5364 ComputeExpression(exp.member.exp);
5365 type = exp.member.exp.expType;
5368 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);
5369 Property prop = null;
5370 DataMember member = null;
5371 Class convertTo = null;
5372 if(type.kind == subClassType && exp.member.exp.type == classExp)
5373 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5380 PrintType(type, string, false, true);
5381 classSym = FindClass(string);
5382 _class = classSym ? classSym.registered : null;
5385 if(exp.member.member)
5387 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5389 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5391 if(!prop && !member && _class && exp.member.member)
5393 Symbol classSym = FindClass(exp.member.member.string);
5395 _class = classSym ? classSym.registered : null;
5396 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5403 Type type = prop.dataType;
5404 // TODO: Assuming same base type for units...
5405 if(_class.type == unitClass)
5407 if(type.kind == classType)
5409 Class _class = type._class.registered;
5410 if(_class.type == unitClass)
5412 if(!_class.dataType)
5413 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5414 type = _class.dataType;
5422 float (*Get)(float) = (void *)prop.Get;
5423 GetFloat(exp.member.exp, &value);
5424 exp.constant = PrintFloat(Get ? Get(value) : value);
5425 exp.type = constantExp;
5431 double (*Get)(double);
5432 GetDouble(exp.member.exp, &value);
5435 Get = (void *)prop.Set;
5437 Get = (void *)prop.Get;
5438 exp.constant = PrintDouble(Get ? Get(value) : value);
5439 exp.type = constantExp;
5448 Expression value = exp.member.exp;
5451 ProcessPropertyType(prop);
5453 type = prop.dataType;
5456 // printf("Investigate this\n");
5458 else if(_class.type == structClass)
5464 Class propertyClass = type._class.registered;
5465 if(propertyClass.type == structClass && value.type == instanceExp)
5467 void (*Set)(void *, void *) = (void *)prop.Set;
5468 exp.instance = Instantiation { };
5469 exp.instance.data = new0 byte[_class.structSize];
5470 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5471 exp.instance.loc = exp.loc;
5472 exp.type = instanceExp;
5473 Set(exp.instance.data, value.instance.data);
5474 PopulateInstance(exp.instance);
5481 void (*Set)(void *, int) = (void *)prop.Set;
5483 exp.instance = Instantiation { };
5484 exp.instance.data = new0 byte[_class.structSize];
5485 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5486 exp.instance.loc = exp.loc;
5487 exp.type = instanceExp;
5489 GetInt(value, &intValue);
5491 Set(exp.instance.data, intValue);
5492 PopulateInstance(exp.instance);
5498 void (*Set)(void *, int64) = (void *)prop.Set;
5500 exp.instance = Instantiation { };
5501 exp.instance.data = new0 byte[_class.structSize];
5502 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5503 exp.instance.loc = exp.loc;
5504 exp.type = instanceExp;
5506 GetInt64(value, &intValue);
5508 Set(exp.instance.data, intValue);
5509 PopulateInstance(exp.instance);
5516 void (*Set)(void *, intptr) = (void *)prop.Set;
5518 exp.instance = Instantiation { };
5519 exp.instance.data = new0 byte[_class.structSize];
5520 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5521 exp.instance.loc = exp.loc;
5522 exp.type = instanceExp;
5524 GetIntPtr(value, &intValue);
5526 Set(exp.instance.data, intValue);
5527 PopulateInstance(exp.instance);
5534 void (*Set)(void *, intsize) = (void *)prop.Set;
5536 exp.instance = Instantiation { };
5537 exp.instance.data = new0 byte[_class.structSize];
5538 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5539 exp.instance.loc = exp.loc;
5540 exp.type = instanceExp;
5542 GetIntSize(value, &intValue);
5544 Set(exp.instance.data, intValue);
5545 PopulateInstance(exp.instance);
5551 void (*Set)(void *, double) = (void *)prop.Set;
5553 exp.instance = Instantiation { };
5554 exp.instance.data = new0 byte[_class.structSize];
5555 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5556 exp.instance.loc = exp.loc;
5557 exp.type = instanceExp;
5559 GetDouble(value, &doubleValue);
5561 Set(exp.instance.data, doubleValue);
5562 PopulateInstance(exp.instance);
5567 else if(_class.type == bitClass)
5573 Class propertyClass = type._class.registered;
5574 if(propertyClass.type == structClass && value.instance.data)
5576 unsigned int (*Set)(void *) = (void *)prop.Set;
5577 unsigned int bits = Set(value.instance.data);
5578 exp.constant = PrintHexUInt(bits);
5579 exp.type = constantExp;
5582 else if(_class.type == bitClass)
5585 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5588 GetUInt(exp.member.exp, &value);
5590 exp.constant = PrintHexUInt(bits);
5591 exp.type = constantExp;
5599 if(_class.type == bitClass)
5602 GetUInt(exp.member.exp, &value);
5608 Class _class = type._class.registered;
5609 if(_class.type == structClass)
5611 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5613 exp.instance = Instantiation { };
5614 exp.instance.data = new0 byte[_class.structSize];
5615 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5616 exp.instance.loc = exp.loc;
5617 //exp.instance.fullSet = true;
5618 exp.type = instanceExp;
5619 Get(value, exp.instance.data);
5620 PopulateInstance(exp.instance);
5622 else if(_class.type == bitClass)
5624 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5625 uint64 bits = Get(value);
5626 exp.constant = PrintHexUInt64(bits);
5627 exp.type = constantExp;
5633 else if(_class.type == structClass)
5635 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5640 Class _class = type._class.registered;
5641 if(_class.type == structClass && value)
5643 void (*Get)(void *, void *) = (void *)prop.Get;
5645 exp.instance = Instantiation { };
5646 exp.instance.data = new0 byte[_class.structSize];
5647 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5648 exp.instance.loc = exp.loc;
5649 //exp.instance.fullSet = true;
5650 exp.type = instanceExp;
5651 Get(value, exp.instance.data);
5652 PopulateInstance(exp.instance);
5660 char * value = exp.member.exp.instance.data;
5665 Class _class = type._class.registered;
5666 if(_class.type == normalClass)
5668 void *(*Get)(void *) = (void *)prop.Get;
5670 exp.instance = Instantiation { };
5671 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5672 exp.type = instanceExp;
5673 exp.instance.data = Get(value, exp.instance.data);
5685 exp.isConstant = false;
5693 if(exp.type != ExpressionType::memberExp)
5695 FreeExpression(memberExp);
5696 FreeIdentifier(memberID);
5702 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5703 FreeExpContents(exp);
5704 exp.constant = PrintUInt(ComputeTypeSize(type));
5705 exp.type = constantExp;
5711 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5712 if(classSym && classSym.registered)
5714 if(classSym.registered.fixed)
5716 FreeSpecifier(exp._class);
5717 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5718 exp.type = constantExp;
5722 char className[1024];
5723 strcpy(className, "__ecereClass_");
5724 FullClassNameCat(className, classSym.string, true);
5725 MangleClassName(className);
5727 FreeExpContents(exp);
5728 exp.type = pointerExp;
5729 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5730 exp.member.member = MkIdentifier("structSize");
5740 if(exp.type == castExp)
5743 ComputeExpression(exp.cast.exp);
5746 if(e && exp.expType)
5749 type = exp.destType;
5752 if(type.kind == classType)
5754 Class _class = type._class.registered;
5755 if(_class && (_class.type == unitClass || _class.type == bitClass))
5757 if(!_class.dataType)
5758 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5759 type = _class.dataType;
5770 FreeExpContents(exp);
5771 exp.constant = PrintChar(value);
5772 exp.type = constantExp;
5776 unsigned char value;
5777 GetUChar(e, &value);
5778 FreeExpContents(exp);
5779 exp.constant = PrintUChar(value);
5780 exp.type = constantExp;
5787 GetShort(e, &value);
5788 FreeExpContents(exp);
5789 exp.constant = PrintShort(value);
5790 exp.type = constantExp;
5794 unsigned short value;
5795 GetUShort(e, &value);
5796 FreeExpContents(exp);
5797 exp.constant = PrintUShort(value);
5798 exp.type = constantExp;
5806 FreeExpContents(exp);
5807 exp.constant = PrintInt(value);
5808 exp.type = constantExp;
5814 FreeExpContents(exp);
5815 exp.constant = PrintUInt(value);
5816 exp.type = constantExp;
5823 GetInt64(e, &value);
5824 FreeExpContents(exp);
5825 exp.constant = PrintInt64(value);
5826 exp.type = constantExp;
5831 GetUInt64(e, &value);
5832 FreeExpContents(exp);
5833 exp.constant = PrintUInt64(value);
5834 exp.type = constantExp;
5841 GetIntPtr(e, &value);
5842 FreeExpContents(exp);
5843 exp.constant = PrintInt64((int64)value);
5844 exp.type = constantExp;
5849 GetUIntPtr(e, &value);
5850 FreeExpContents(exp);
5851 exp.constant = PrintUInt64((uint64)value);
5852 exp.type = constantExp;
5859 GetIntSize(e, &value);
5860 FreeExpContents(exp);
5861 exp.constant = PrintInt64((int64)value);
5862 exp.type = constantExp;
5867 GetUIntSize(e, &value);
5868 FreeExpContents(exp);
5869 exp.constant = PrintUInt64((uint64)value);
5870 exp.type = constantExp;
5876 GetFloat(e, &value);
5877 FreeExpContents(exp);
5878 exp.constant = PrintFloat(value);
5879 exp.type = constantExp;
5885 GetDouble(e, &value);
5886 FreeExpContents(exp);
5887 exp.constant = PrintDouble(value);
5888 exp.type = constantExp;
5902 // Caring only about last expression for now...
5903 ComputeExpression(exp.cond.exp->last);
5904 if(exp.cond.elseExp)
5905 ComputeExpression(exp.cond.elseExp);
5907 ComputeExpression(exp.cond.cond);
5909 op1 = GetOperand(exp.cond.cond);
5910 if(op1.type) op1.type.refCount++;
5911 op2 = GetOperand(exp.cond.exp->last);
5912 if(op2.type) op2.type.refCount++;
5913 op3 = GetOperand(exp.cond.elseExp);
5914 if(op3.type) op3.type.refCount++;
5916 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5917 if(op1.type) FreeType(op1.type);
5918 if(op2.type) FreeType(op2.type);
5919 if(op3.type) FreeType(op3.type);
5925 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5930 OldList converts { };
5933 if(destType.kind == voidType)
5936 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5940 // for(convert = converts.last; convert; convert = convert.prev)
5941 for(convert = converts.first; convert; convert = convert.next)
5943 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
5946 Expression newExp { };
5947 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
5949 // TODO: Check this...
5951 newExp.destType = null;
5956 exp.type = memberExp;
5957 exp.addedThis = true;
5958 exp.member.exp = newExp;
5959 FreeType(exp.member.exp.expType);
5961 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
5962 exp.member.exp.expType.classObjectType = objectType;
5963 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
5964 exp.member.memberType = propertyMember;
5965 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5966 // TESTING THIS... for (int)degrees
5967 exp.needCast = true;
5968 if(exp.expType) exp.expType.refCount++;
5969 ApplyAnyObjectLogic(exp.member.exp);
5974 /*if(exp.isConstant)
5976 // Color { ColorRGB = [exp] };
5977 exp.type = instanceExp;
5978 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
5979 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
5980 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
5984 // If not constant, don't turn it yet into an instantiation
5985 // (Go through the deep members system first)
5986 exp.type = memberExp;
5987 exp.addedThis = true;
5988 exp.member.exp = newExp;
5990 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
5991 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
5992 newExp.expType._class.registered.type == noHeadClass)
5994 newExp.byReference = true;
5997 FreeType(exp.member.exp.expType);
5998 /*exp.member.exp.expType = convert.convert.dataType;
5999 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6000 exp.member.exp.expType = null;
6001 if(convert.convert.dataType)
6003 exp.member.exp.expType = { };
6004 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6005 exp.member.exp.expType.refCount = 1;
6006 exp.member.exp.expType.classObjectType = objectType;
6007 ApplyAnyObjectLogic(exp.member.exp);
6010 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6011 exp.member.memberType = reverseConversionMember;
6012 exp.expType = convert.resultType ? convert.resultType :
6013 MkClassType(convert.convert._class.fullName);
6014 exp.needCast = true;
6015 if(convert.resultType) convert.resultType.refCount++;
6021 FreeType(exp.expType);
6024 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6025 exp.needCast = true;
6026 if(exp.expType) exp.expType.refCount++;
6030 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6031 exp.needCast = true;
6032 if(convert.resultType)
6033 convert.resultType.refCount++;
6037 if(exp.isConstant && inCompiler)
6038 ComputeExpression(exp);
6040 converts.Free(FreeConvert);
6043 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6045 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6047 if(!result && exp.expType && exp.destType)
6049 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6050 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6051 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6052 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6056 // if(result) CheckTemplateTypes(exp);
6060 void CheckTemplateTypes(Expression exp)
6062 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6064 Expression newExp { };
6068 if(exp.destType) exp.destType.refCount++;
6069 if(exp.expType) exp.expType.refCount++;
6073 switch(exp.expType.kind)
6076 if(exp.destType.classObjectType)
6078 // We need to pass the address, just pass it along (Undo what was done above)
6079 if(exp.destType) exp.destType.refCount--;
6080 if(exp.expType) exp.expType.refCount--;
6085 // If we're looking for value:
6086 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6088 OldList * unionDefs = MkList();
6089 OldList * statements = MkList();
6090 context = PushContext();
6091 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6092 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6093 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6094 exp.type = extensionCompoundExp;
6095 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6096 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6097 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6098 exp.compound.compound.context = context;
6099 PopContext(context);
6104 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6105 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6109 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6111 Expression newExp { };
6115 if(exp.destType) exp.destType.refCount++;
6116 if(exp.expType) exp.expType.refCount++;
6120 switch(exp.expType.kind)
6123 if(exp.destType.classObjectType)
6125 // We need to pass the address, just pass it along (Undo what was done above)
6126 if(exp.destType) exp.destType.refCount--;
6127 if(exp.expType) exp.expType.refCount--;
6132 // If we're looking for value:
6133 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6135 OldList * unionDefs = MkList();
6136 OldList * statements = MkList();
6137 context = PushContext();
6138 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6139 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6140 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6141 exp.type = extensionCompoundExp;
6142 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6143 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6144 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6145 exp.compound.compound.context = context;
6146 PopContext(context);
6151 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6153 exp.type = bracketsExp;
6154 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6155 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6156 ProcessExpressionType(exp.list->first);
6161 exp.type = bracketsExp;
6162 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6163 newExp.needCast = true;
6164 ProcessExpressionType(exp.list->first);
6170 if(exp.expType.kind == templateType)
6172 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6175 FreeType(exp.destType);
6176 FreeType(exp.expType);
6181 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6186 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6187 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6191 char typeString[1024];
6193 OldList * specs = MkList();
6194 typeString[0] = '\0';
6195 PrintType(exp.expType, typeString, false, false);
6196 decl = SpecDeclFromString(typeString, specs, null);
6199 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6200 exp.cast.typeName = MkTypeName(specs, decl);
6201 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6202 exp.cast.exp.needCast = true;
6209 // TODO: The Symbol tree should be reorganized by namespaces
6211 // - Tree of all symbols within (stored without namespace)
6212 // - Tree of sub-namespaces
6214 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6216 int nsLen = strlen(nameSpace);
6218 // Start at the name space prefix
6219 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6221 char * s = symbol.string;
6222 if(!strncmp(s, nameSpace, nsLen))
6224 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6227 for(c = strlen(s)-1; c >= 0; c--)
6232 if(!strcmp(namePart, name))
6234 // TODO: Error on ambiguity
6244 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6247 char nameSpace[1024];
6249 bool gotColon = false;
6251 nameSpace[0] = '\0';
6252 for(c = strlen(name)-1; c >= 0; c--)
6259 namePart = name+c+1;
6260 while(c >= 0 && name[c] == ':') c--;
6263 // Try an exact match first
6264 Symbol symbol = (Symbol)tree.FindString(name);
6268 // Namespace specified
6269 memcpy(nameSpace, name, c + 1);
6272 return ScanWithNameSpace(tree, nameSpace, namePart);
6276 // Looking for a global symbol, e.g. ::Sleep()
6277 Symbol symbol = (Symbol)tree.FindString(namePart);
6282 // Name only (no namespace specified)
6283 Symbol symbol = (Symbol)tree.FindString(namePart);
6286 return ScanWithNameSpace(tree, "", namePart);
6291 static void ProcessDeclaration(Declaration decl);
6293 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6296 //Time startTime = GetTime();
6298 // Optimize this later? Do this before/less?
6300 Symbol symbol = null;
6301 // First, check if the identifier is declared inside the function
6302 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6304 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6306 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6312 strcpy(curName, thisNameSpace);
6313 strcat(curName, "::");
6314 strcat(curName, name);
6315 // Try to resolve in current namespace first
6316 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6319 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6322 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6324 if(symbol || ctx == endContext) break;
6326 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6328 if(symbol.pointerExternal.type == functionExternal)
6330 FunctionDefinition function = symbol.pointerExternal.function;
6332 // Modified this recently...
6333 Context tmpContext = curContext;
6335 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6336 curContext = tmpContext;
6338 symbol.pointerExternal.symbol = symbol;
6341 DeclareType(symbol.type, true, true);
6343 ast->Insert(curExternal.prev, symbol.pointerExternal);
6345 symbol.id = curExternal.symbol.idCode;
6348 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6350 ast->Move(symbol.pointerExternal, curExternal.prev);
6351 symbol.id = curExternal.symbol.idCode;
6355 //findSymbolTotalTime += GetTime() - startTime;
6360 static void GetTypeSpecs(Type type, OldList * specs)
6362 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6367 if(type._class.registered)
6369 if(!type._class.registered.dataType)
6370 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6371 GetTypeSpecs(type._class.registered.dataType, specs);
6375 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6376 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6377 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6378 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6379 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6380 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6381 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6384 ListAdd(specs, MkSpecifier(INT)); break;
6388 // WARNING : This function expects a null terminated string since it recursively concatenate...
6389 static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
6396 if(type._class && type._class.string)
6398 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6399 // look into merging with thisclass ?
6400 if(type.classObjectType == typedObject)
6401 strcat(string, "typed_object");
6403 strcat(string, type._class.string);
6406 if(type._class.registered)
6407 strcat(string, type._class.registered.name);
6409 strcat(string, type._class.string);
6416 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6417 if(funcType && funcType.kind == functionType)
6420 PrintType(funcType.returnType, string, false, fullName);
6421 strcat(string, "(*");
6422 if(printName || funcType.thisClass)
6424 strcat(string, " ");
6425 if(funcType.thisClass)
6427 strcat(string, funcType.thisClass.string);
6428 strcat(string, "::");
6431 strcat(string, type.name);
6433 strcat(string, ")(");
6434 for(param = funcType.params.first; param; param = param.next)
6436 PrintType(param, string, false, fullName);
6437 if(param.next) strcat(string, ", ");
6439 strcat(string, ")");
6443 _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
6444 strcat(string, " *");
6448 case voidType: strcat(string, "void"); break;
6449 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6450 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6451 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6452 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6453 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6454 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6455 case floatType: strcat(string, "float"); break;
6456 case doubleType: strcat(string, "double"); break;
6460 strcat(string, "struct ");
6461 strcat(string, type.enumName);
6463 else if(type.typeName)
6465 strcat(string, type.typeName);
6470 strcat(string, "struct ");
6471 strcat(string,"(unnamed)");
6474 strcat(string, "struct {");
6475 for(member = type.members.first; member; member = member.next)
6477 PrintType(member, string, true, fullName);
6478 strcat(string,"; ");
6486 strcat(string, "union ");
6487 strcat(string, type.enumName);
6489 else if(type.typeName)
6491 strcat(string, type.typeName);
6495 strcat(string, "union ");
6496 strcat(string,"(unnamed)");
6502 strcat(string, "enum ");
6503 strcat(string, type.enumName);
6505 else if(type.typeName)
6507 strcat(string, type.typeName);
6510 strcat(string, "enum");
6517 strcat(string, "dllexport ");
6518 PrintType(type.returnType, string, false, fullName);
6519 strcat(string, " ");
6522 // DANGER: Testing This
6528 strcat(string, type.name);
6531 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6532 if(name) name += 2; else name = type.name;
6533 strcat(string, name);
6541 strcat(string, "(");
6542 for(param = type.params.first; param; param = param.next)
6544 PrintType(param, string, true, fullName);
6545 if(param.next) strcat(string, ", ");
6547 strcat(string, ")");
6554 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6555 if(funcType && funcType.kind == functionType)
6558 PrintType(funcType.returnType, string, false, fullName);
6559 strcat(string, "(*");
6560 if(printName || funcType.thisClass)
6562 strcat(string, " ");
6563 if(funcType.thisClass)
6565 strcat(string, funcType.thisClass.string);
6566 strcat(string, "::");
6569 strcat(string, type.name);
6571 strcat(string, ")(");
6572 for(param = funcType.params.first; param; param = param.next)
6574 PrintType(param, string, false, fullName);
6575 if(param.next) strcat(string, ", ");
6577 strcat(string, ")");
6581 char baseType[1024], size[256];
6582 Type arrayType = type;
6586 while(arrayType.kind == TypeKind::arrayType)
6589 if(arrayType.enumClass)
6590 strcat(size, arrayType.enumClass.string);
6591 else if(arrayType.arraySizeExp)
6592 PrintExpression(arrayType.arraySizeExp, size);
6593 //sprintf(string, "%s[%s]", baseType, size);
6596 arrayType = arrayType.arrayType;
6598 _PrintType(arrayType, baseType, printName, printFunction, fullName);
6599 strcat(string, baseType);
6600 strcat(string, size);
6604 PrintType(type.arrayType, baseType, printName, fullName);
6606 strcpy(size, type.enumClass.string);
6607 else if(type.arraySizeExp)
6608 PrintExpression(type.arraySizeExp, size);
6609 //sprintf(string, "%s[%s]", baseType, size);
6610 strcat(string, baseType);
6611 strcat(string, "[");
6612 strcat(string, size);
6613 strcat(string, "]");
6620 strcat(string, "...");
6623 _PrintType(type.method.dataType, string, false, printFunction, fullName);
6626 strcat(string, "subclass(");
6627 strcat(string, type._class ? type._class.string : "int");
6628 strcat(string, ")");
6631 strcat(string, type.templateParameter.identifier.string);
6634 strcat(string, "thisclass");
6637 strcat(string, "__builtin_va_list");
6640 if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
6642 strcat(string, " ");
6643 strcat(string, type.name);
6649 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6651 void PrintType(Type type, char * string, bool printName, bool fullName)
6654 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6655 if(funcType && funcType.kind == functionType && type != funcType)
6657 char typeString[1024];
6660 PrintType(funcType.returnType, string, false, fullName);
6661 strcat(string, "(");
6662 _PrintType(type, string, printName, false, fullName);
6663 strcat(string, ")");
6665 strcat(string, "(");
6666 for(param = funcType.params.first; param; param = param.next)
6668 PrintType(param, string, true, fullName);
6669 if(param.next) strcat(string, ", ");
6671 strcat(string, ")");
6674 _PrintType(type, string, printName, true, fullName);
6675 if(type.bitFieldCount)
6678 sprintf(count, ":%d", type.bitFieldCount);
6679 strcat(string, count);
6683 static Type FindMember(Type type, char * string)
6686 for(memberType = type.members.first; memberType; memberType = memberType.next)
6688 if(!memberType.name)
6690 Type subType = FindMember(memberType, string);
6694 else if(!strcmp(memberType.name, string))
6700 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6703 for(memberType = type.members.first; memberType; memberType = memberType.next)
6705 if(!memberType.name)
6707 Type subType = FindMember(memberType, string);
6710 *offset += memberType.offset;
6714 else if(!strcmp(memberType.name, string))
6716 *offset += memberType.offset;
6723 Expression ParseExpressionString(char * expression)
6725 fileInput = TempFile { };
6726 fileInput.Write(expression, 1, strlen(expression));
6727 fileInput.Seek(0, start);
6730 parsedExpression = null;
6732 expression_yyparse();
6735 return parsedExpression;
6738 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6740 Identifier id = exp.identifier;
6741 Method method = null;
6742 Property prop = null;
6743 DataMember member = null;
6744 ClassProperty classProp = null;
6746 if(_class && _class.type == enumClass)
6748 NamedLink value = null;
6749 Class enumClass = eSystem_FindClass(privateModule, "enum");
6753 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6755 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6756 for(value = e.values.first; value; value = value.next)
6758 if(!strcmp(value.name, id.string))
6765 FreeExpContents(exp);
6767 exp.type = constantExp;
6768 exp.isConstant = true;
6769 if(!strcmp(baseClass.dataTypeString, "int"))
6770 sprintf(constant, "%d",value.data);
6772 sprintf(constant, "0x%X",value.data);
6773 exp.constant = CopyString(constant);
6774 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6775 exp.expType = MkClassType(baseClass.fullName);
6783 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6785 ProcessMethodType(method);
6792 // TOCHECK: Put it back to what it was...
6793 // methodClass = _class;
6794 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6799 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6802 ProcessPropertyType(prop);
6803 exp.expType = prop.dataType;
6804 if(prop.dataType) prop.dataType.refCount++;
6807 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6809 if(!member.dataType)
6810 member.dataType = ProcessTypeString(member.dataTypeString, false);
6811 exp.expType = member.dataType;
6812 if(member.dataType) member.dataType.refCount++;
6815 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6817 if(!classProp.dataType)
6818 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6820 if(classProp.constant)
6822 FreeExpContents(exp);
6824 exp.isConstant = true;
6825 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6827 //char constant[256];
6828 exp.type = stringExp;
6829 exp.constant = QMkString((char *)classProp.Get(_class));
6834 exp.type = constantExp;
6835 sprintf(constant, "%d", (int)classProp.Get(_class));
6836 exp.constant = CopyString(constant);
6844 exp.expType = classProp.dataType;
6845 if(classProp.dataType) classProp.dataType.refCount++;
6851 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6853 BinaryTree * tree = &nameSpace.functions;
6854 GlobalData data = (GlobalData)tree->FindString(name);
6858 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6860 data = ScanGlobalData(child, name);
6868 static GlobalData FindGlobalData(char * name)
6871 NameSpace * nameSpace;
6872 nameSpace = globalData;
6873 for(c = 0; name[c]; c++)
6875 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6877 NameSpace * newSpace;
6878 char * spaceName = new char[c - start + 1];
6879 strncpy(spaceName, name + start, c - start);
6880 spaceName[c-start] = '\0';
6881 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6885 nameSpace = newSpace;
6886 if(name[c] == ':') c++;
6892 return ScanGlobalData(nameSpace, name + start);
6897 static int definedExpStackPos;
6898 static void * definedExpStack[512];
6900 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6901 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6903 Expression prev = checkedExp.prev, next = checkedExp.next;
6905 FreeExpContents(checkedExp);
6906 FreeType(checkedExp.expType);
6907 FreeType(checkedExp.destType);
6909 *checkedExp = *newExp;
6913 checkedExp.prev = prev;
6914 checkedExp.next = next;
6917 void ApplyAnyObjectLogic(Expression e)
6919 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6920 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6922 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6923 //ellipsisDestType = destType;
6926 Type type = e.expType;
6927 Class _class = null;
6928 //Type destType = e.destType;
6930 if(type.kind == classType && type._class && type._class.registered)
6932 _class = type._class.registered;
6934 else if(type.kind == subClassType)
6936 _class = FindClass("ecere::com::Class").registered;
6940 char string[1024] = "";
6943 PrintType(type, string, false, true);
6944 classSym = FindClass(string);
6945 if(classSym) _class = classSym.registered;
6948 if((_class && (_class.type == enumClass || _class.type == unitClass || _class.type == bitClass || _class.type == systemClass) && strcmp(_class.fullName, "class") && strcmp(_class.fullName, "ecere::com::Class")) || // Patched so that class isn't considered SYSTEM...
6949 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6950 destType.byReference)))
6952 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6954 Expression checkedExp = e, newExp;
6956 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6958 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6960 if(checkedExp.type == extensionCompoundExp)
6962 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6965 checkedExp = checkedExp.list->last;
6967 else if(checkedExp.type == castExp)
6968 checkedExp = checkedExp.cast.exp;
6971 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6973 newExp = checkedExp.op.exp2;
6974 checkedExp.op.exp2 = null;
6975 FreeExpContents(checkedExp);
6977 if(e.expType && e.expType.passAsTemplate)
6980 ComputeTypeSize(e.expType);
6981 sprintf(size, "%d", e.expType.size);
6982 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6983 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6984 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6987 ReplaceExpContents(checkedExp, newExp);
6988 e.byReference = true;
6990 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6992 Expression checkedExp, newExp;
6995 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6997 e.type == identifierExp ||
6998 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6999 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7000 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7003 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7005 Context context = PushContext();
7007 OldList * specs = MkList();
7008 char typeString[1024];
7009 Expression newExp { };
7011 typeString[0] = '\0';
7014 //if(e.destType) e.destType.refCount++;
7015 // if(exp.expType) exp.expType.refCount++;
7018 newExp.expType = null;
7020 PrintType(e.expType, typeString, false, true);
7021 decl = SpecDeclFromString(typeString, specs, null);
7022 newExp.destType = ProcessType(specs, decl);
7024 curContext = context;
7025 e.type = extensionCompoundExp;
7027 // We need a current compound for this
7031 OldList * stmts = MkList();
7032 sprintf(name, "__internalValue%03X", internalValueCounter++);
7033 if(!curCompound.compound.declarations)
7034 curCompound.compound.declarations = MkList();
7035 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7036 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7037 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7038 e.compound = MkCompoundStmt(null, stmts);
7041 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7044 e.compound = MkCompoundStmt(
7045 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7046 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7048 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7052 Type type = e.destType;
7054 CopyTypeInto(e.destType, type);
7055 e.destType.refCount = 1;
7056 e.destType.classObjectType = none;
7060 e.compound.compound.context = context;
7061 PopContext(context);
7062 curContext = context.parent;
7066 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7068 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7070 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7072 if(checkedExp.type == extensionCompoundExp)
7074 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7077 checkedExp = checkedExp.list->last;
7079 else if(checkedExp.type == castExp)
7080 checkedExp = checkedExp.cast.exp;
7083 Expression operand { };
7084 operand = *checkedExp;
7085 checkedExp.destType = null;
7086 checkedExp.expType = null;
7088 checkedExp.type = opExp;
7089 checkedExp.op.op = '&';
7090 checkedExp.op.exp1 = null;
7091 checkedExp.op.exp2 = operand;
7093 //newExp = MkExpOp(null, '&', checkedExp);
7095 //ReplaceExpContents(checkedExp, newExp);
7102 // If expression type is a simple class, make it an address
7103 // FixReference(e, true);
7106 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7107 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7108 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7110 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
7112 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7116 Expression thisExp { };
7119 thisExp.prev = null;
7120 thisExp.next = null;
7123 e.type = bracketsExp;
7124 e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
7125 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7126 ((Expression)e.list->first).byReference = true;
7128 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7130 e.expType = thisExp.expType;
7131 e.expType.refCount++;
7136 CopyTypeInto(e.expType, thisExp.expType);
7137 e.expType.byReference = false;
7138 e.expType.refCount = 1;
7140 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7141 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7143 e.expType.classObjectType = none;
7148 // TOFIX: Try this for a nice IDE crash!
7150 // The other way around
7153 if(destType && e.expType &&
7154 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7155 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7156 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7158 if(destType.kind == ellipsisType)
7160 Compiler_Error($"Unspecified type\n");
7162 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7164 bool byReference = e.expType.byReference;
7165 Expression thisExp { };
7167 OldList * specs = MkList();
7168 char typeString[1024]; // Watch buffer overruns
7170 ClassObjectType backupClassObjectType;
7172 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7177 backupClassObjectType = type.classObjectType;
7179 type.classObjectType = none;
7181 typeString[0] = '\0';
7182 PrintType(type, typeString, false, true);
7183 decl = SpecDeclFromString(typeString, specs, null);
7185 type.classObjectType = backupClassObjectType;
7188 thisExp.prev = null;
7189 thisExp.next = null;
7192 if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
7193 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7194 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7195 (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
7196 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7201 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7206 e.cast.typeName = MkTypeName(specs, decl);
7207 e.cast.exp = thisExp;
7208 e.byReference = true;
7211 e.destType = destType;
7213 destType.refCount++;
7218 void ProcessExpressionType(Expression exp)
7220 bool unresolved = false;
7221 Location oldyylloc = yylloc;
7222 bool notByReference = false;
7224 char debugExpString[4096];
7225 debugExpString[0] = '\0';
7226 PrintExpression(exp, debugExpString);
7228 if(!exp || exp.expType)
7231 //eSystem_Logf("%s\n", expString);
7233 // Testing this here
7239 Identifier id = exp.identifier;
7242 // DOING THIS LATER NOW...
7243 if(id._class && id._class.name)
7245 id.classSym = id._class.symbol; // FindClass(id._class.name);
7246 /* TODO: Name Space Fix ups
7248 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7252 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7254 exp.expType = ProcessTypeString("Module", true);
7257 else */if(strstr(id.string, "__ecereClass") == id.string)
7259 exp.expType = ProcessTypeString("ecere::com::Class", true);
7262 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7264 // Added this here as well
7265 ReplaceClassMembers(exp, thisClass);
7266 if(exp.type != identifierExp)
7268 ProcessExpressionType(exp);
7272 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7277 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7278 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7279 if(!symbol/* && exp.destType*/)
7281 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7287 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7288 if(exp.type != identifierExp)
7290 ProcessExpressionType(exp);
7294 // Static methods called from inside the _class
7295 else if(currentClass && !id._class)
7297 if(ResolveIdWithClass(exp, currentClass, true))
7300 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7304 // If we manage to resolve this symbol
7307 Type type = symbol.type;
7308 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7310 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7312 Context context = SetupTemplatesContext(_class);
7313 type = ReplaceThisClassType(_class);
7314 FinishTemplatesContext(context);
7315 if(type) type.refCount = 0; // We'll be incrementing it right below...
7318 FreeSpecifier(id._class);
7321 id.string = CopyString(symbol.string);
7327 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7328 // Add missing cases here... enum Classes...
7329 exp.isConstant = true;
7331 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7332 if(symbol.isParam || !strcmp(id.string, "this"))
7334 if(_class && _class.type == structClass)
7335 exp.byReference = true;
7337 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7338 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7339 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7340 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7342 Identifier id = exp.identifier;
7343 exp.type = bracketsExp;
7344 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7348 if(symbol.isIterator)
7350 if(symbol.isIterator == 3)
7352 exp.type = bracketsExp;
7353 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7354 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7356 ProcessExpressionType(exp);
7358 else if(symbol.isIterator != 4)
7360 exp.type = memberExp;
7361 exp.member.exp = MkExpIdentifier(exp.identifier);
7362 exp.member.exp.expType = exp.expType;
7363 /*if(symbol.isIterator == 6)
7364 exp.member.member = MkIdentifier("key");
7366 exp.member.member = MkIdentifier("data");
7368 ProcessExpressionType(exp);
7375 DefinedExpression definedExp = null;
7376 if(thisNameSpace && !(id._class && !id._class.name))
7379 strcpy(name, thisNameSpace);
7381 strcat(name, id.string);
7382 definedExp = eSystem_FindDefine(privateModule, name);
7385 definedExp = eSystem_FindDefine(privateModule, id.string);
7389 for(c = 0; c<definedExpStackPos; c++)
7390 if(definedExpStack[c] == definedExp)
7392 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7394 Location backupYylloc = yylloc;
7395 definedExpStack[definedExpStackPos++] = definedExp;
7396 fileInput = TempFile { };
7397 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7398 fileInput.Seek(0, start);
7401 parsedExpression = null;
7403 expression_yyparse();
7406 yylloc = backupYylloc;
7408 if(parsedExpression)
7411 exp.type = bracketsExp;
7412 exp.list = MkListOne(parsedExpression);
7413 parsedExpression.loc = yylloc;
7414 ProcessExpressionType(exp);
7415 definedExpStackPos--;
7418 definedExpStackPos--;
7424 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7430 GlobalData data = null;
7431 if(thisNameSpace && !(id._class && !id._class.name))
7434 strcpy(name, thisNameSpace);
7436 strcat(name, id.string);
7437 data = FindGlobalData(name);
7440 data = FindGlobalData(id.string);
7443 DeclareGlobalData(data);
7444 exp.expType = data.dataType;
7445 if(data.dataType) data.dataType.refCount++;
7448 id.string = CopyString(data.fullName);
7449 FreeSpecifier(id._class);
7456 GlobalFunction function = null;
7457 if(thisNameSpace && !(id._class && !id._class.name))
7460 strcpy(name, thisNameSpace);
7462 strcat(name, id.string);
7463 function = eSystem_FindFunction(privateModule, name);
7466 function = eSystem_FindFunction(privateModule, id.string);
7471 id.string = CopyString(function.name);
7474 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7475 strcpy(name, "__ecereFunction_");
7476 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7477 if(DeclareFunction(function, name))
7480 id.string = CopyString(name);
7482 exp.expType = function.dataType;
7483 if(function.dataType) function.dataType.refCount++;
7485 FreeSpecifier(id._class);
7502 if(!exp.instance._class)
7504 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7506 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7510 //classSym = FindClass(exp.instance._class.fullName);
7511 //_class = classSym ? classSym.registered : null;
7513 ProcessInstantiationType(exp.instance);
7514 exp.isConstant = exp.instance.isConstant;
7517 if(_class.type == unitClass && _class.base.type != systemClass)
7520 Type destType = exp.destType;
7522 exp.destType = MkClassType(_class.base.fullName);
7523 exp.expType = MkClassType(_class.fullName);
7524 CheckExpressionType(exp, exp.destType, true);
7526 exp.destType = destType;
7528 exp.expType = MkClassType(_class.fullName);
7531 if(exp.instance._class)
7533 exp.expType = MkClassType(exp.instance._class.name);
7534 /*if(exp.expType._class && exp.expType._class.registered &&
7535 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7536 exp.expType.byReference = true;*/
7551 if(exp.constant[0] == '\'')
7553 if((int)((byte *)exp.constant)[1] > 127)
7556 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7557 if(nb < 2) ch = exp.constant[1];
7558 delete exp.constant;
7559 exp.constant = PrintUInt(ch);
7560 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7561 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7562 type._class = FindClass("unichar");
7564 type.isSigned = false;
7568 type.kind = charType;
7569 type.isSigned = true;
7572 else if(strchr(exp.constant, '.'))
7574 char ch = exp.constant[strlen(exp.constant)-1];
7576 type.kind = floatType;
7578 type.kind = doubleType;
7579 type.isSigned = true;
7583 if(exp.constant[0] == '0' && exp.constant[1])
7584 type.isSigned = false;
7585 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7586 type.isSigned = false;
7587 else if(strtoll(exp.constant, null, 0) > MAXINT)
7588 type.isSigned = false;
7590 type.isSigned = true;
7591 type.kind = intType;
7593 exp.isConstant = true;
7599 exp.isConstant = true; // Why wasn't this constant?
7615 ProcessExpressionType(exp._new.size);
7620 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7622 DeclareType(exp.expType.type, false, false);
7626 ProcessExpressionType(exp._renew.size);
7627 ProcessExpressionType(exp._renew.exp);
7632 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7634 DeclareType(exp.expType.type, false, false);
7638 bool assign = false, boolResult = false, boolOps = false;
7639 Type type1 = null, type2 = null;
7640 bool useDestType = false, useSideType = false;
7641 Location oldyylloc = yylloc;
7642 bool useSideUnit = false;
7644 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7653 // Assignment Operators
7667 // boolean Operators
7669 // Expect boolean operators
7671 //boolResult = true;
7675 // Expect boolean operands
7686 // Gives boolean result
7694 // Just added these... testing
7699 // DANGER: Verify units
7704 if(exp.op.op != '*' || exp.op.exp1)
7711 /*// Implement speed etc.
7717 if(exp.op.op == '&')
7719 // Added this here earlier for Iterator address as key
7720 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7722 Identifier id = exp.op.exp2.identifier;
7723 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7724 if(symbol && symbol.isIterator == 2)
7726 exp.type = memberExp;
7727 exp.member.exp = exp.op.exp2;
7728 exp.member.member = MkIdentifier("key");
7730 exp.op.exp2.expType = symbol.type;
7731 symbol.type.refCount++;
7732 ProcessExpressionType(exp);
7736 // exp.op.exp2.usage.usageRef = true;
7740 //dummy.kind = TypeDummy;
7744 if(exp.destType && exp.destType.kind == classType &&
7745 exp.destType._class && exp.destType._class.registered && useDestType &&
7747 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7748 exp.destType._class.registered.type == enumClass ||
7749 exp.destType._class.registered.type == bitClass
7752 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7754 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7755 exp.op.exp1.destType = exp.destType;
7757 exp.destType.refCount++;
7761 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7762 exp.op.exp1.destType = dummy;
7766 // TESTING THIS HERE...
7767 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7768 ProcessExpressionType(exp.op.exp1);
7769 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7771 if(exp.op.exp1.destType == dummy)
7774 exp.op.exp1.destType = null;
7776 type1 = exp.op.exp1.expType;
7781 char expString[10240];
7782 expString[0] = '\0';
7783 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7787 exp.op.exp2.destType = exp.op.exp1.expType;
7788 if(exp.op.exp1.expType)
7789 exp.op.exp1.expType.refCount++;
7793 exp.op.exp2.destType = exp.destType;
7795 exp.destType.refCount++;
7798 if(type1) type1.refCount++;
7799 exp.expType = type1;
7804 PrintExpression(exp.op.exp2, expString);
7806 if(type1 && type1.kind == pointerType)
7808 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 ||
7809 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7810 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7811 else if(exp.op.op == '=')
7813 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7814 exp.op.exp2.destType = type1;
7821 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7822 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/* ||
7823 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7826 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7827 exp.op.exp2.destType = type1;
7832 if(type1) type1.refCount++;
7833 exp.expType = type1;
7835 else if(exp.destType && exp.destType.kind == classType &&
7836 exp.destType._class && exp.destType._class.registered &&
7838 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7839 (exp.destType._class.registered.type == enumClass && useDestType))
7842 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7843 exp.op.exp2.destType = exp.destType;
7845 exp.destType.refCount++;
7849 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7850 exp.op.exp2.destType = dummy;
7854 // TESTING THIS HERE... (DANGEROUS)
7855 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7856 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7858 FreeType(exp.op.exp2.destType);
7859 exp.op.exp2.destType = type1;
7862 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7863 ProcessExpressionType(exp.op.exp2);
7864 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7866 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7868 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)
7870 if(exp.op.op != '=' && type1.type.kind == voidType)
7871 Compiler_Error($"void *: unknown size\n");
7873 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||
7874 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7875 (exp.op.exp2.expType._class.registered.type == normalClass ||
7876 exp.op.exp2.expType._class.registered.type == structClass ||
7877 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7879 if(exp.op.op == ADD_ASSIGN)
7880 Compiler_Error($"cannot add two pointers\n");
7882 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7883 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7885 if(exp.op.op == ADD_ASSIGN)
7886 Compiler_Error($"cannot add two pointers\n");
7890 char type1String[1024];
7891 char type2String[1024];
7892 type1String[0] = '\0';
7893 type2String[0] = '\0';
7895 PrintType(exp.op.exp2.expType, type1String, false, true);
7896 PrintType(type1, type2String, false, true);
7897 ChangeCh(expString, '\n', ' ');
7898 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7902 if(exp.op.exp2.destType == dummy)
7905 exp.op.exp2.destType = null;
7908 type2 = exp.op.exp2.expType;
7911 dummy.kind = voidType;
7913 if(exp.op.op == SIZEOF)
7920 exp.isConstant = true;
7922 // Get type of dereferenced pointer
7923 else if(exp.op.op == '*' && !exp.op.exp1)
7925 exp.expType = Dereference(type2);
7926 if(type2 && type2.kind == classType)
7927 notByReference = true;
7929 else if(exp.op.op == '&' && !exp.op.exp1)
7930 exp.expType = Reference(type2);
7937 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7938 exp.op.exp1.destType = MkClassType("bool");
7939 exp.op.exp1.destType.truth = true;
7940 if(!exp.op.exp1.expType)
7941 ProcessExpressionType(exp.op.exp1);
7943 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7944 FreeType(exp.op.exp1.expType);
7945 exp.op.exp1.expType = MkClassType("bool");
7946 exp.op.exp1.expType.truth = true;
7950 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7951 exp.op.exp2.destType = MkClassType("bool");
7952 exp.op.exp2.destType.truth = true;
7953 if(!exp.op.exp2.expType)
7954 ProcessExpressionType(exp.op.exp2);
7956 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7957 FreeType(exp.op.exp2.expType);
7958 exp.op.exp2.expType = MkClassType("bool");
7959 exp.op.exp2.expType.truth = true;
7962 else if(exp.op.exp1 && exp.op.exp2 &&
7965 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7966 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7967 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7968 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7970 if(type1 && type2 &&
7971 // If either both are class or both are not class
7972 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
7974 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7975 exp.op.exp2.destType = type1;
7977 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7978 exp.op.exp1.destType = type2;
7980 // Warning here for adding Radians + Degrees with no destination type
7981 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7982 type1._class.registered && type1._class.registered.type == unitClass &&
7983 type2._class.registered && type2._class.registered.type == unitClass &&
7984 type1._class.registered != type2._class.registered)
7985 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
7986 type1._class.string, type2._class.string, type1._class.string);
7988 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7990 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7993 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7995 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
7996 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
7999 ProcessExpressionType(exp.op.exp1);
8001 if(type2.kind != pointerType)
8003 ProcessExpressionType(classExp);
8005 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8006 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8007 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8009 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8012 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8013 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8014 MkPointer(null, null), null)))),
8015 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8017 if(!exp.op.exp2.expType)
8018 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8020 ProcessExpressionType(exp.op.exp2);
8025 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)))
8027 if(type1.kind != classType && type1.type.kind == voidType)
8028 Compiler_Error($"void *: unknown size\n");
8029 exp.expType = type1;
8030 if(type1) type1.refCount++;
8032 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)))
8034 if(type2.kind != classType && type2.type.kind == voidType)
8035 Compiler_Error($"void *: unknown size\n");
8036 exp.expType = type2;
8037 if(type2) type2.refCount++;
8039 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8040 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8042 Compiler_Warning($"different levels of indirection\n");
8046 bool success = false;
8047 if(type1.kind == pointerType && type2.kind == pointerType)
8049 if(exp.op.op == '+')
8050 Compiler_Error($"cannot add two pointers\n");
8051 else if(exp.op.op == '-')
8053 // Pointer Subtraction gives integer
8054 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8063 if(type1.type.kind == templateType)
8065 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8068 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8070 ProcessExpressionType(classExp);
8072 exp.type = bracketsExp;
8073 exp.list = MkListOne(MkExpOp(
8074 MkExpBrackets(MkListOne(MkExpOp(
8075 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8077 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8079 //MkExpMember(classExp, MkIdentifier("typeSize"))
8081 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8082 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8084 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8087 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8088 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8089 MkPointer(null, null), null)))),
8090 MkExpMember(classExp, MkIdentifier("typeSize")))))
8095 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8104 if(!success && exp.op.exp1.type == constantExp)
8106 // If first expression is constant, try to match that first
8107 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8109 if(exp.expType) FreeType(exp.expType);
8110 exp.expType = exp.op.exp1.destType;
8111 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8114 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8116 if(exp.expType) FreeType(exp.expType);
8117 exp.expType = exp.op.exp2.destType;
8118 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8124 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8126 if(exp.expType) FreeType(exp.expType);
8127 exp.expType = exp.op.exp2.destType;
8128 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8131 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8133 if(exp.expType) FreeType(exp.expType);
8134 exp.expType = exp.op.exp1.destType;
8135 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8141 char expString1[10240];
8142 char expString2[10240];
8145 expString1[0] = '\0';
8146 expString2[0] = '\0';
8151 PrintExpression(exp.op.exp1, expString1);
8152 ChangeCh(expString1, '\n', ' ');
8153 PrintExpression(exp.op.exp2, expString2);
8154 ChangeCh(expString2, '\n', ' ');
8155 PrintType(exp.op.exp1.expType, type1, false, true);
8156 PrintType(exp.op.exp2.expType, type2, false, true);
8159 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8163 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8164 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8166 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8167 // Convert e.g. / 4 into / 4.0
8168 exp.op.exp1.destType = type2._class.registered.dataType;
8169 if(type2._class.registered.dataType)
8170 type2._class.registered.dataType.refCount++;
8171 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8172 exp.expType = type2;
8173 if(type2) type2.refCount++;
8175 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8177 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8178 // Convert e.g. / 4 into / 4.0
8179 exp.op.exp2.destType = type1._class.registered.dataType;
8180 if(type1._class.registered.dataType)
8181 type1._class.registered.dataType.refCount++;
8182 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8183 exp.expType = type1;
8184 if(type1) type1.refCount++;
8190 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8192 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8194 if(!type1._class.registered.dataType)
8195 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8196 exp.op.exp2.destType = type1._class.registered.dataType;
8197 exp.op.exp2.destType.refCount++;
8199 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8200 type2 = exp.op.exp2.destType;
8202 exp.expType = type2;
8206 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8208 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8210 if(!type2._class.registered.dataType)
8211 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8212 exp.op.exp1.destType = type2._class.registered.dataType;
8213 exp.op.exp1.destType.refCount++;
8215 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8216 type1 = exp.op.exp1.destType;
8217 exp.expType = type1;
8221 // TESTING THIS NEW CODE
8222 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8224 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8226 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8228 if(exp.expType) FreeType(exp.expType);
8229 exp.expType = exp.op.exp1.expType;
8230 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8235 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8237 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8239 if(exp.expType) FreeType(exp.expType);
8240 exp.expType = exp.op.exp2.expType;
8241 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8249 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8250 exp.op.exp2.destType = type1;
8254 // Maybe this was meant to be an enum...
8255 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8257 Type oldType = exp.op.exp2.expType;
8258 exp.op.exp2.expType = null;
8259 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8262 exp.op.exp2.expType = oldType;
8267 // TESTING THIS HERE... LATEST ADDITION
8268 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8270 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8271 exp.op.exp2.destType = type2._class.registered.dataType;
8272 if(type2._class.registered.dataType)
8273 type2._class.registered.dataType.refCount++;
8274 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8276 //exp.expType = type2._class.registered.dataType; //type2;
8277 //if(type2) type2.refCount++;
8280 // TESTING THIS HERE... LATEST ADDITION
8281 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8283 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8284 exp.op.exp1.destType = type1._class.registered.dataType;
8285 if(type1._class.registered.dataType)
8286 type1._class.registered.dataType.refCount++;
8287 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8288 exp.expType = type1._class.registered.dataType; //type1;
8289 if(type1) type1.refCount++;
8293 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8295 if(exp.expType) FreeType(exp.expType);
8296 exp.expType = exp.op.exp2.destType;
8297 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8299 else if(type1 && type2)
8301 char expString1[10240];
8302 char expString2[10240];
8303 char type1String[1024];
8304 char type2String[1024];
8305 expString1[0] = '\0';
8306 expString2[0] = '\0';
8307 type1String[0] = '\0';
8308 type2String[0] = '\0';
8311 PrintExpression(exp.op.exp1, expString1);
8312 ChangeCh(expString1, '\n', ' ');
8313 PrintExpression(exp.op.exp2, expString2);
8314 ChangeCh(expString2, '\n', ' ');
8315 PrintType(exp.op.exp1.expType, type1String, false, true);
8316 PrintType(exp.op.exp2.expType, type2String, false, true);
8319 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8321 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8323 exp.expType = exp.op.exp1.expType;
8324 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8326 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8328 exp.expType = exp.op.exp2.expType;
8329 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8336 // Maybe this was meant to be an enum...
8337 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8339 Type oldType = exp.op.exp1.expType;
8340 exp.op.exp1.expType = null;
8341 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8344 exp.op.exp1.expType = oldType;
8347 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8348 exp.op.exp1.destType = type2;
8351 // TESTING THIS HERE... LATEST ADDITION
8352 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8354 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8355 exp.op.exp1.destType = type1._class.registered.dataType;
8356 if(type1._class.registered.dataType)
8357 type1._class.registered.dataType.refCount++;
8360 // TESTING THIS HERE... LATEST ADDITION
8361 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8363 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8364 exp.op.exp2.destType = type2._class.registered.dataType;
8365 if(type2._class.registered.dataType)
8366 type2._class.registered.dataType.refCount++;
8370 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8372 if(exp.expType) FreeType(exp.expType);
8373 exp.expType = exp.op.exp1.destType;
8374 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8378 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8380 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8382 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8383 // Convert e.g. / 4 into / 4.0
8384 exp.op.exp1.destType = type2._class.registered.dataType;
8385 if(type2._class.registered.dataType)
8386 type2._class.registered.dataType.refCount++;
8387 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8389 if(exp.op.op == '!')
8391 exp.expType = MkClassType("bool");
8392 exp.expType.truth = true;
8396 exp.expType = type2;
8397 if(type2) type2.refCount++;
8400 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8402 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8404 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8405 // Convert e.g. / 4 into / 4.0
8406 exp.op.exp2.destType = type1._class.registered.dataType;
8407 if(type1._class.registered.dataType)
8408 type1._class.registered.dataType.refCount++;
8409 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8411 exp.expType = type1;
8412 if(type1) type1.refCount++;
8417 if(exp.op.exp1 && !exp.op.exp1.expType)
8419 char expString[10000];
8420 expString[0] = '\0';
8423 PrintExpression(exp.op.exp1, expString);
8424 ChangeCh(expString, '\n', ' ');
8427 Compiler_Error($"couldn't determine type of %s\n", expString);
8429 if(exp.op.exp2 && !exp.op.exp2.expType)
8431 char expString[10240];
8432 expString[0] = '\0';
8435 PrintExpression(exp.op.exp2, expString);
8436 ChangeCh(expString, '\n', ' ');
8439 Compiler_Error($"couldn't determine type of %s\n", expString);
8444 FreeType(exp.expType);
8445 exp.expType = MkClassType("bool");
8446 exp.expType.truth = true;
8449 if(exp.op.op != SIZEOF)
8450 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8451 (!exp.op.exp2 || exp.op.exp2.isConstant);
8453 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8455 DeclareType(exp.op.exp2.expType, false, false);
8464 case extensionExpressionExp:
8467 exp.isConstant = true;
8468 for(e = exp.list->first; e; e = e.next)
8473 FreeType(e.destType);
8474 e.destType = exp.destType;
8475 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8477 ProcessExpressionType(e);
8479 exp.destType.count--;
8480 if(!exp.expType && !e.next)
8482 exp.expType = e.expType;
8483 if(e.expType) e.expType.refCount++;
8486 exp.isConstant = false;
8489 // In case a cast became a member...
8490 e = exp.list->first;
8491 if(!e.next && e.type == memberExp)
8493 // Preserve prev, next
8494 Expression next = exp.next, prev = exp.prev;
8497 FreeType(exp.expType);
8498 FreeType(exp.destType);
8508 ProcessExpressionType(exp);
8515 exp.isConstant = true;
8517 ProcessExpressionType(exp.index.exp);
8518 if(!exp.index.exp.isConstant)
8519 exp.isConstant = false;
8521 if(exp.index.exp.expType)
8523 Type source = exp.index.exp.expType;
8524 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8525 eClass_IsDerived(source._class.registered, containerClass) &&
8526 source._class.registered.templateArgs)
8528 Class _class = source._class.registered;
8529 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8531 if(exp.index.index && exp.index.index->last)
8533 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8538 for(e = exp.index.index->first; e; e = e.next)
8540 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8542 if(e.destType) FreeType(e.destType);
8543 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8545 ProcessExpressionType(e);
8548 // Check if this type is int
8551 exp.isConstant = false;
8555 exp.expType = Dereference(exp.index.exp.expType);
8557 DeclareType(exp.expType, false, false);
8564 Type methodType = null;
8570 PrintExpression(exp.call.exp, name);
8571 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8573 //exp.call.exp.expType = null;
8574 PrintExpression(exp.call.exp, name);
8577 if(exp.call.exp.type == identifierExp)
8579 Expression idExp = exp.call.exp;
8580 Identifier id = idExp.identifier;
8581 if(!strcmp(id.string, "__builtin_frame_address"))
8583 exp.expType = ProcessTypeString("void *", true);
8584 if(exp.call.arguments && exp.call.arguments->first)
8585 ProcessExpressionType(exp.call.arguments->first);
8588 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8590 exp.expType = ProcessTypeString("int", true);
8591 if(exp.call.arguments && exp.call.arguments->first)
8592 ProcessExpressionType(exp.call.arguments->first);
8595 else if(!strcmp(id.string, "Max") ||
8596 !strcmp(id.string, "Min") ||
8597 !strcmp(id.string, "Sgn") ||
8598 !strcmp(id.string, "Abs"))
8600 Expression a = null;
8601 Expression b = null;
8602 Expression tempExp1 = null, tempExp2 = null;
8603 if((!strcmp(id.string, "Max") ||
8604 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8606 a = exp.call.arguments->first;
8607 b = exp.call.arguments->last;
8611 else if(exp.call.arguments->count == 1)
8613 a = exp.call.arguments->first;
8619 exp.call.arguments->Clear();
8620 idExp.identifier = null;
8622 FreeExpContents(exp);
8624 ProcessExpressionType(a);
8626 ProcessExpressionType(b);
8628 exp.type = bracketsExp;
8629 exp.list = MkList();
8631 if(a.expType && (!b || b.expType))
8633 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8635 // Use the simpleStruct name/ids for now...
8638 OldList * specs = MkList();
8639 OldList * decls = MkList();
8641 char temp1[1024], temp2[1024];
8643 GetTypeSpecs(a.expType, specs);
8645 if(a && !a.isConstant && a.type != identifierExp)
8647 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8648 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8649 tempExp1 = QMkExpId(temp1);
8650 tempExp1.expType = a.expType;
8652 a.expType.refCount++;
8653 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8655 if(b && !b.isConstant && b.type != identifierExp)
8657 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8658 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8659 tempExp2 = QMkExpId(temp2);
8660 tempExp2.expType = b.expType;
8662 b.expType.refCount++;
8663 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8666 decl = MkDeclaration(specs, decls);
8667 if(!curCompound.compound.declarations)
8668 curCompound.compound.declarations = MkList();
8669 curCompound.compound.declarations->Insert(null, decl);
8674 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8676 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8678 MkExpCondition(MkExpBrackets(MkListOne(
8679 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8680 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8681 exp.expType = a.expType;
8683 a.expType.refCount++;
8685 else if(!strcmp(id.string, "Abs"))
8688 MkExpCondition(MkExpBrackets(MkListOne(
8689 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8690 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8691 exp.expType = a.expType;
8693 a.expType.refCount++;
8695 else if(!strcmp(id.string, "Sgn"))
8697 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8699 MkExpCondition(MkExpBrackets(MkListOne(
8700 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8701 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8702 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8703 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8704 exp.expType = ProcessTypeString("int", false);
8707 FreeExpression(tempExp1);
8708 if(tempExp2) FreeExpression(tempExp2);
8722 if(!exp.call.exp.destType)
8724 exp.call.exp.destType = dummy;
8727 ProcessExpressionType(exp.call.exp);
8728 if(exp.call.exp.destType == dummy)
8731 exp.call.exp.destType = null;
8736 // Check argument types against parameter types
8737 functionType = exp.call.exp.expType;
8739 if(functionType && functionType.kind == TypeKind::methodType)
8741 methodType = functionType;
8742 functionType = methodType.method.dataType;
8744 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8745 // TOCHECK: Instead of doing this here could this be done per param?
8746 if(exp.call.exp.expType.usedClass)
8748 char typeString[1024];
8749 typeString[0] = '\0';
8750 PrintType(functionType, typeString, true, true);
8751 if(strstr(typeString, "thisclass"))
8753 OldList * specs = MkList();
8756 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8758 decl = SpecDeclFromString(typeString, specs, null);
8760 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8761 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8762 exp.call.exp.expType.usedClass))
8763 thisClassParams = false;
8765 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8767 Class backupThisClass = thisClass;
8768 thisClass = exp.call.exp.expType.usedClass;
8769 ProcessDeclarator(decl);
8770 thisClass = backupThisClass;
8773 thisClassParams = true;
8775 functionType = ProcessType(specs, decl);
8776 functionType.refCount = 0;
8777 FinishTemplatesContext(context);
8780 FreeList(specs, FreeSpecifier);
8781 FreeDeclarator(decl);
8785 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8787 Type type = functionType.type;
8788 if(!functionType.refCount)
8790 functionType.type = null;
8791 FreeType(functionType);
8793 //methodType = functionType;
8794 functionType = type;
8796 if(functionType && functionType.kind != TypeKind::functionType)
8798 Compiler_Error($"called object %s is not a function\n", name);
8800 else if(functionType)
8802 bool emptyParams = false, noParams = false;
8803 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8804 Type type = functionType.params.first;
8805 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8807 Location oldyylloc = yylloc;
8809 if(!type) emptyParams = true;
8812 if(functionType.extraParam && e && functionType.thisClass)
8814 e.destType = MkClassType(functionType.thisClass.string);
8818 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8819 if(!functionType.staticMethod)
8821 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8822 memberExp.member.exp.expType._class)
8824 type = MkClassType(memberExp.member.exp.expType._class.string);
8829 type = functionType.params.first;
8834 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8836 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8841 type = functionType.params.first;
8849 if(type && type.kind == voidType)
8852 if(!type.refCount) FreeType(type);
8856 for( ; e; e = e.next)
8858 if(!type && !emptyParams)
8861 if(methodType && methodType.methodClass)
8862 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8863 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8864 noParams ? 0 : functionType.params.count);
8866 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8867 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8868 noParams ? 0 : functionType.params.count);
8872 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8874 Type templatedType = null;
8875 Class _class = methodType.usedClass;
8876 ClassTemplateParameter curParam = null;
8878 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8881 for(sClass = _class; sClass; sClass = sClass.base)
8883 if(sClass.templateClass) sClass = sClass.templateClass;
8885 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8887 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8890 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8892 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8893 id += nextClass.templateParams.count;
8902 if(curParam && _class.templateArgs[id].dataTypeString)
8904 ClassTemplateArgument arg = _class.templateArgs[id];
8906 Context context = SetupTemplatesContext(_class);
8909 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8910 templatedType = ProcessTypeString(arg.dataTypeString, false);
8911 FinishTemplatesContext(context);
8913 e.destType = templatedType;
8916 templatedType.passAsTemplate = true;
8917 // templatedType.refCount++;
8923 if(type) type.refCount++;
8928 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
8930 e.destType = type.prev;
8931 e.destType.refCount++;
8936 if(type) type.refCount++;
8939 // Don't reach the end for the ellipsis
8940 if(type && type.kind != ellipsisType)
8942 Type next = type.next;
8943 if(!type.refCount) FreeType(type);
8948 if(type && type.kind != ellipsisType)
8950 if(methodType && methodType.methodClass)
8951 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
8952 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8953 functionType.params.count + extra);
8955 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
8956 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8957 functionType.params.count + extra);
8960 if(type && !type.refCount) FreeType(type);
8967 kind = TypeKind::functionType;
8970 if(exp.call.exp.type == identifierExp)
8972 char * string = exp.call.exp.identifier.string;
8976 Location oldyylloc = yylloc;
8978 yylloc = exp.call.exp.identifier.loc;
8979 if(strstr(string, "__builtin_") == string);
8981 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
8982 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
8983 globalContext.symbols.Add((BTNode)symbol);
8984 if(strstr(symbol.string, "::"))
8985 globalContext.hasNameSpace = true;
8990 else if(exp.call.exp.type == memberExp)
8992 /*Compiler_Warning($"%s undefined; assuming returning int\n",
8993 exp.call.exp.member.member.string);*/
8996 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
8998 if(!functionType.returnType)
9000 functionType.returnType = Type
9007 if(functionType && functionType.kind == TypeKind::functionType)
9009 exp.expType = functionType.returnType;
9011 if(functionType.returnType)
9012 functionType.returnType.refCount++;
9014 if(!functionType.refCount)
9015 FreeType(functionType);
9018 if(exp.call.arguments)
9020 for(e = exp.call.arguments->first; e; e = e.next)
9022 Type destType = e.destType;
9023 ProcessExpressionType(e);
9031 Location oldyylloc = yylloc;
9032 bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
9033 exp.thisPtr = thisPtr;
9035 // DOING THIS LATER NOW...
9036 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9038 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9039 /* TODO: Name Space Fix ups
9040 if(!exp.member.member.classSym)
9041 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9045 ProcessExpressionType(exp.member.exp);
9046 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9047 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9049 exp.isConstant = false;
9052 exp.isConstant = exp.member.exp.isConstant;
9053 type = exp.member.exp.expType;
9057 if(type && (type.kind == templateType))
9059 Class _class = thisClass ? thisClass : currentClass;
9060 ClassTemplateParameter param = null;
9063 for(param = _class.templateParams.first; param; param = param.next)
9065 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9069 if(param && param.defaultArg.member)
9071 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9074 Expression expMember = exp.member.exp;
9076 OldList * specs = MkList();
9077 char thisClassTypeString[1024];
9079 FreeIdentifier(exp.member.member);
9081 ProcessExpressionType(argExp);
9084 char * colon = strstr(param.defaultArg.memberString, "::");
9087 char className[1024];
9090 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9091 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9094 strcpy(thisClassTypeString, _class.fullName);
9097 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9099 exp.expType = ProcessType(specs, decl);
9100 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9102 Class expClass = exp.expType._class.registered;
9103 Class cClass = null;
9108 char templateString[1024];
9109 ClassTemplateParameter param;
9110 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9111 for(cClass = expClass; cClass; cClass = cClass.base)
9114 for(param = cClass.templateParams.first; param; param = param.next)
9118 ClassTemplateArgument arg;
9119 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9120 arg = expClass.templateArgs[id];
9122 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9124 ClassTemplateParameter cParam;
9125 //int p = numParams - sClass.templateParams.count;
9128 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9130 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9132 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9134 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9136 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9137 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9149 strcat(argument, arg.name.string);
9150 strcat(argument, " = ");
9156 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9157 char expString[1024];
9158 OldList * specs = MkList();
9159 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9161 char * string = PrintHexUInt64(arg.expression.ui64);
9162 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9164 ProcessExpressionType(exp);
9165 ComputeExpression(exp);
9166 expString[0] = '\0';
9167 PrintExpression(exp, expString);
9168 strcat(argument, expString);
9170 FreeExpression(exp);
9175 strcat(argument, arg.member.name);
9178 case TemplateParameterType::type:
9180 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9182 if(!strcmp(arg.dataTypeString, "thisclass"))
9183 strcat(argument, thisClassTypeString);
9185 strcat(argument, arg.dataTypeString);
9192 if(paramCount) strcat(templateString, ", ");
9193 if(lastParam != p - 1)
9195 strcat(templateString, param.name);
9196 strcat(templateString, " = ");
9198 strcat(templateString, argument);
9207 int len = strlen(templateString);
9208 if(templateString[len-1] == '>') templateString[len++] = ' ';
9209 templateString[len++] = '>';
9210 templateString[len++] = '\0';
9213 Context context = SetupTemplatesContext(_class);
9214 FreeType(exp.expType);
9215 exp.expType = ProcessTypeString(templateString, false);
9216 FinishTemplatesContext(context);
9220 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9221 exp.type = bracketsExp;
9222 exp.list = MkListOne(MkExpOp(null, '*',
9227 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9228 MkExpBrackets(MkListOne(
9229 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9231 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9233 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9238 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9239 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9241 type = ProcessTemplateParameterType(type.templateParameter);
9245 if(type && (type.kind == templateType));
9246 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9248 Identifier id = exp.member.member;
9249 TypeKind typeKind = type.kind;
9250 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9251 if(typeKind == subClassType && exp.member.exp.type == classExp)
9253 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9254 typeKind = classType;
9257 if(id && (typeKind == intType || typeKind == enumType))
9258 _class = eSystem_FindClass(privateModule, "int");
9263 (exp.member.exp.type == identifierExp &&
9264 !strcmp(exp.member.exp.identifier.string, "this"));*/
9265 Property prop = null;
9266 Method method = null;
9267 DataMember member = null;
9268 Property revConvert = null;
9269 ClassProperty classProp = null;
9271 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9272 exp.member.memberType = propertyMember;
9274 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9275 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9277 if(typeKind != subClassType)
9279 // Prioritize data members over properties for "this"
9280 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9282 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9283 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9285 prop = eClass_FindProperty(_class, id.string, privateModule);
9289 if(!member && !prop)
9290 prop = eClass_FindProperty(_class, id.string, privateModule);
9291 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9292 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9293 exp.member.thisPtr = true;
9295 // Prioritize properties over data members otherwise
9298 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9301 prop = eClass_FindProperty(_class, id.string, null);
9302 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9303 member = eClass_FindDataMember(_class, id.string, null, null, null);
9306 if(!prop && !member)
9308 method = eClass_FindMethod(_class, id.string, null);
9311 prop = eClass_FindProperty(_class, id.string, privateModule);
9312 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9313 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9319 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9326 if(!prop && !member)
9327 method = eClass_FindMethod(_class, id.string, privateModule);
9328 if(!prop && !member && !method)
9330 if(typeKind == subClassType)
9332 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9335 exp.member.memberType = classPropertyMember;
9336 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9340 // Assume this is a class_data member
9341 char structName[1024];
9342 Identifier id = exp.member.member;
9343 Expression classExp = exp.member.exp;
9346 FreeType(classExp.expType);
9347 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9349 strcpy(structName, "__ecereClassData_");
9350 FullClassNameCat(structName, type._class.string, false);
9351 exp.type = pointerExp;
9352 exp.member.member = id;
9354 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9355 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9356 MkExpBrackets(MkListOne(MkExpOp(
9357 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9358 MkExpMember(classExp, MkIdentifier("data"))), '+',
9359 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9364 ProcessExpressionType(exp);
9370 // Check for reverse conversion
9371 // (Convert in an instantiation later, so that we can use
9372 // deep properties system)
9373 Symbol classSym = FindClass(id.string);
9376 Class convertClass = classSym.registered;
9378 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9385 exp.member.memberType = propertyMember;
9387 ProcessPropertyType(prop);
9388 exp.expType = prop.dataType;
9389 if(prop.dataType) prop.dataType.refCount++;
9393 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9395 FreeExpContents(exp);
9396 exp.type = identifierExp;
9397 exp.identifier = MkIdentifier("class");
9398 ProcessExpressionType(exp);
9402 exp.member.memberType = dataMember;
9403 DeclareStruct(_class.fullName, false);
9404 if(!member.dataType)
9406 Context context = SetupTemplatesContext(_class);
9407 member.dataType = ProcessTypeString(member.dataTypeString, false);
9408 FinishTemplatesContext(context);
9410 exp.expType = member.dataType;
9411 if(member.dataType) member.dataType.refCount++;
9415 exp.member.memberType = reverseConversionMember;
9416 exp.expType = MkClassType(revConvert._class.fullName);
9424 exp.type = identifierExp;
9425 exp.identifier = exp.member.member;
9428 exp.member.memberType = methodMember;
9430 if(!method.dataType)
9431 ProcessMethodType(method);
9439 // Tricky spot here... To use instance versus class virtual table
9440 // Put it back to what it was... What did we break?
9442 // Had to put it back for overriding Main of Thread global instance
9444 //exp.expType.methodClass = _class;
9445 exp.expType.methodClass = (id && id._class) ? _class : null;
9447 // Need the actual class used for templated classes
9448 exp.expType.usedClass = _class;
9452 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9454 FreeExpContents(exp);
9455 exp.type = identifierExp;
9456 exp.identifier = MkIdentifier("class");
9457 ProcessExpressionType(exp);
9460 yylloc = exp.member.member.loc;
9461 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9463 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9466 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9471 while(tClass && !tClass.templateClass) tClass = tClass.base;
9473 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9476 ClassTemplateParameter curParam = null;
9479 for(sClass = tClass; sClass; sClass = sClass.base)
9482 if(sClass.templateClass) sClass = sClass.templateClass;
9483 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9485 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9487 for(sClass = sClass.base; sClass; sClass = sClass.base)
9488 id += sClass.templateParams.count;
9496 if(curParam && tClass.templateArgs[id].dataTypeString)
9498 ClassTemplateArgument arg = tClass.templateArgs[id];
9499 Context context = SetupTemplatesContext(tClass);
9501 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9502 FreeType(exp.expType);
9503 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9506 if(exp.expType.kind == thisClassType)
9508 FreeType(exp.expType);
9509 exp.expType = ReplaceThisClassType(_class);
9512 if(tClass.templateClass)
9513 exp.expType.passAsTemplate = true;
9514 //exp.expType.refCount++;
9517 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9518 //exp.destType.refCount++;
9520 if(exp.destType.kind == thisClassType)
9522 FreeType(exp.destType);
9523 exp.destType = ReplaceThisClassType(_class);
9527 FinishTemplatesContext(context);
9530 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9531 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9534 ClassTemplateParameter curParam = null;
9537 for(sClass = tClass; sClass; sClass = sClass.base)
9540 if(sClass.templateClass) sClass = sClass.templateClass;
9541 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9543 if(curParam.type == TemplateParameterType::type &&
9544 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9546 for(sClass = sClass.base; sClass; sClass = sClass.base)
9547 id += sClass.templateParams.count;
9557 ClassTemplateArgument arg = tClass.templateArgs[id];
9558 Context context = SetupTemplatesContext(tClass);
9561 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9563 basicType = ProcessTypeString(arg.dataTypeString, false);
9566 if(basicType.kind == thisClassType)
9568 FreeType(basicType);
9569 basicType = ReplaceThisClassType(_class);
9572 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9573 if(tClass.templateClass)
9574 basicType.passAsTemplate = true;
9577 FreeType(exp.expType);
9579 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9580 //exp.expType.refCount++;
9583 exp.destType = exp.expType;
9584 exp.destType.refCount++;
9588 Expression newExp { };
9589 OldList * specs = MkList();
9591 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9593 if(exp.destType) exp.destType.refCount++;
9594 if(exp.expType) exp.expType.refCount++;
9596 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9597 exp.cast.exp = newExp;
9598 //FreeType(exp.expType);
9599 //exp.expType = null;
9600 //ProcessExpressionType(sourceExp);
9603 FinishTemplatesContext(context);
9606 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9608 Class expClass = exp.expType._class.registered;
9611 Class cClass = null;
9616 char templateString[1024];
9617 ClassTemplateParameter param;
9618 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9619 while(cClass != expClass)
9622 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9625 for(param = cClass.templateParams.first; param; param = param.next)
9627 Class cClassCur = null;
9630 ClassTemplateParameter paramCur = null;
9631 ClassTemplateArgument arg;
9632 while(cClassCur != tClass && !paramCur)
9635 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9636 cClassCur = sClassCur;
9638 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9640 if(!strcmp(paramCur.name, param.name))
9648 if(paramCur && paramCur.type == TemplateParameterType::type)
9649 arg = tClass.templateArgs[cp];
9651 arg = expClass.templateArgs[p];
9658 strcat(argument, arg.name.string);
9659 strcat(argument, " = ");
9665 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9666 char expString[1024];
9667 OldList * specs = MkList();
9668 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9670 char * string = PrintHexUInt64(arg.expression.ui64);
9671 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9673 ProcessExpressionType(exp);
9674 ComputeExpression(exp);
9675 expString[0] = '\0';
9676 PrintExpression(exp, expString);
9677 strcat(argument, expString);
9679 FreeExpression(exp);
9684 strcat(argument, arg.member.name);
9687 case TemplateParameterType::type:
9689 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9690 strcat(argument, arg.dataTypeString);
9696 if(paramCount) strcat(templateString, ", ");
9697 if(lastParam != p - 1)
9699 strcat(templateString, param.name);
9700 strcat(templateString, " = ");
9702 strcat(templateString, argument);
9711 int len = strlen(templateString);
9712 if(templateString[len-1] == '>') templateString[len++] = ' ';
9713 templateString[len++] = '>';
9714 templateString[len++] = '\0';
9717 FreeType(exp.expType);
9719 Context context = SetupTemplatesContext(tClass);
9720 exp.expType = ProcessTypeString(templateString, false);
9721 FinishTemplatesContext(context);
9728 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9730 else if(type && (type.kind == structType || type.kind == unionType))
9732 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9735 exp.expType = memberType;
9737 memberType.refCount++;
9742 char expString[10240];
9743 expString[0] = '\0';
9744 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9745 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9748 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9750 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9752 Identifier id = exp.member.member;
9753 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9756 FreeType(exp.expType);
9757 exp.expType = ReplaceThisClassType(_class);
9764 // Convert x->y into (*x).y
9767 Type destType = exp.destType;
9769 // DOING THIS LATER NOW...
9770 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9772 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9773 /* TODO: Name Space Fix ups
9774 if(!exp.member.member.classSym)
9775 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9779 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9780 exp.type = memberExp;
9783 ProcessExpressionType(exp);
9790 //ComputeExpression(exp);
9792 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9793 if(classSym && classSym.registered)
9795 if(classSym.registered.type == noHeadClass)
9799 DeclareStruct(classSym.string, false);
9800 FreeSpecifier(exp._class);
9801 exp.type = typeSizeExp;
9802 FullClassNameCat(name, classSym.string, false);
9803 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9807 if(classSym.registered.fixed)
9809 FreeSpecifier(exp._class);
9810 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9811 exp.type = constantExp;
9815 char className[1024];
9816 strcpy(className, "__ecereClass_");
9817 FullClassNameCat(className, classSym.string, true);
9818 MangleClassName(className);
9820 DeclareClass(classSym, className);
9822 FreeExpContents(exp);
9823 exp.type = pointerExp;
9824 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9825 exp.member.member = MkIdentifier("structSize");
9835 // exp.isConstant = true;
9840 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9847 exp.isConstant = true;
9849 DeclareType(type, false, false);
9855 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9857 FreeType(exp.cast.exp.destType);
9858 exp.cast.exp.destType = type;
9860 ProcessExpressionType(exp.cast.exp);
9865 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9866 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9868 void * prev = exp.prev, * next = exp.next;
9869 Type expType = exp.cast.exp.destType;
9870 Expression castExp = exp.cast.exp;
9871 Type destType = exp.destType;
9873 if(expType) expType.refCount++;
9875 //FreeType(exp.destType);
9876 FreeType(exp.expType);
9877 FreeTypeName(exp.cast.typeName);
9880 FreeType(exp.expType);
9881 FreeType(exp.destType);
9883 exp.expType = expType;
9884 exp.destType = destType;
9894 exp.isConstant = exp.cast.exp.isConstant;
9899 case extensionInitializerExp:
9901 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9904 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
9905 // ProcessInitializer(exp.initializer.initializer, type);
9911 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9912 ProcessExpressionType(exp.vaArg.exp);
9920 exp.isConstant = true;
9922 FreeType(exp.cond.cond.destType);
9923 exp.cond.cond.destType = MkClassType("bool");
9924 exp.cond.cond.destType.truth = true;
9925 ProcessExpressionType(exp.cond.cond);
9926 if(!exp.cond.cond.isConstant)
9927 exp.isConstant = false;
9928 for(e = exp.cond.exp->first; e; e = e.next)
9932 FreeType(e.destType);
9933 e.destType = exp.destType;
9934 if(e.destType) e.destType.refCount++;
9936 ProcessExpressionType(e);
9939 exp.expType = e.expType;
9940 if(e.expType) e.expType.refCount++;
9943 exp.isConstant = false;
9946 FreeType(exp.cond.elseExp.destType);
9947 // Added this check if we failed to find an expType
9948 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
9951 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
9953 if(exp.cond.elseExp.destType)
9954 exp.cond.elseExp.destType.refCount++;
9955 ProcessExpressionType(exp.cond.elseExp);
9957 // FIXED THIS: Was done before calling process on elseExp
9958 if(!exp.cond.elseExp.isConstant)
9959 exp.isConstant = false;
9962 case extensionCompoundExp:
9964 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
9966 Statement last = exp.compound.compound.statements->last;
9967 if(last.type == expressionStmt && last.expressions && last.expressions->last)
9969 ((Expression)last.expressions->last).destType = exp.destType;
9971 exp.destType.refCount++;
9973 ProcessStatement(exp.compound);
9974 exp.expType = ((Expression)last.expressions->last).expType;
9975 if(((Expression)last.expressions->last).expType)
9976 exp.expType.refCount++;
9982 Specifier spec = exp._classExp.specifiers->first;
9983 if(spec && spec.type == nameSpecifier)
9985 exp.expType = MkClassType(spec.name);
9986 exp.expType.kind = subClassType;
9987 exp.byReference = true;
9991 exp.expType = MkClassType("ecere::com::Class");
9992 exp.byReference = true;
9998 Class _class = thisClass ? thisClass : currentClass;
10001 Identifier id = exp.classData.id;
10002 char structName[1024];
10003 Expression classExp;
10004 strcpy(structName, "__ecereClassData_");
10005 FullClassNameCat(structName, _class.fullName, false);
10006 exp.type = pointerExp;
10007 exp.member.member = id;
10008 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10009 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10011 classExp = MkExpIdentifier(MkIdentifier("class"));
10013 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10014 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10015 MkExpBrackets(MkListOne(MkExpOp(
10016 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10017 MkExpMember(classExp, MkIdentifier("data"))), '+',
10018 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10021 ProcessExpressionType(exp);
10029 char * typeString = null;
10030 char typeStringBuf[1024];
10031 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10032 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10034 Class templateClass = exp.destType._class.registered;
10035 typeString = templateClass.templateArgs[2].dataTypeString;
10039 // Guess type from expressions in the array
10041 for(e = exp.list->first; e; e = e.next)
10043 ProcessExpressionType(e);
10046 if(!type) { type = e.expType; type.refCount++; }
10049 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10050 if(!MatchTypeExpression(e, type, null, false))
10056 e = exp.list->first;
10057 ProcessExpressionType(e);
10060 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10061 if(!MatchTypeExpression(e, type, null, false))
10063 FreeType(e.expType);
10074 FreeType(e.expType);
10081 typeStringBuf[0] = '\0';
10082 PrintType(type, typeStringBuf, false, true);
10083 typeString = typeStringBuf;
10091 (Container)& (struct BuiltInContainer)
10093 ._vTbl = class(BuiltInContainer)._vTbl,
10094 ._class = class(BuiltInContainer),
10096 .data = (int[]){ 1, 7, 3, 4, 5 },
10098 .type = class(int),
10101 char templateString[1024];
10102 OldList * initializers = MkList();
10103 OldList * structInitializers = MkList();
10104 OldList * specs = MkList();
10106 Declarator decl = SpecDeclFromString(typeString, specs, null);
10107 sprintf(templateString, "Container<%s>", typeString);
10112 type = ProcessTypeString(typeString, false);
10113 while(e = exp.list->first)
10115 exp.list->Remove(e);
10118 ProcessExpressionType(e);
10119 ListAdd(initializers, MkInitializerAssignment(e));
10125 DeclareStruct("ecere::com::BuiltInContainer", false);
10127 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10128 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10129 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10130 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10131 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10132 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10133 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10134 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10135 MkInitializerList(initializers))));
10136 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10137 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10138 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10139 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10140 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10141 exp.expType = ProcessTypeString(templateString, false);
10142 exp.type = bracketsExp;
10143 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10145 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10146 MkInitializerList(structInitializers)))));
10147 ProcessExpressionType(expExt);
10151 exp.expType = ProcessTypeString("Container", false);
10152 Compiler_Error($"Couldn't determine type of array elements\n");
10158 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10160 FreeType(exp.expType);
10161 exp.expType = ReplaceThisClassType(thisClass);
10164 // Resolve structures here
10165 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10167 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10168 // TODO: Fix members reference...
10171 if(exp.expType.kind != enumType)
10174 String enumName = CopyString(exp.expType.enumName);
10176 // Fixed a memory leak on self-referencing C structs typedefs
10177 // by instantiating a new type rather than simply copying members
10178 // into exp.expType
10179 FreeType(exp.expType);
10180 exp.expType = Type { };
10181 exp.expType.kind = symbol.type.kind;
10182 exp.expType.refCount++;
10183 exp.expType.enumName = enumName;
10185 exp.expType.members = symbol.type.members;
10186 for(member = symbol.type.members.first; member; member = member.next)
10192 for(member = symbol.type.members.first; member; member = member.next)
10194 NamedLink value { name = CopyString(member.name) };
10195 exp.expType.members.Add(value);
10202 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10203 else if(exp.destType && !exp.destType.keepCast)
10205 if(!CheckExpressionType(exp, exp.destType, false))
10207 if(!exp.destType.count || unresolved)
10212 if(exp.destType.kind != ellipsisType)
10218 char expString[10240];
10219 expString[0] = '\0';
10221 PrintType(exp.destType, type2, false, true);
10223 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10225 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10226 else if(exp.type != dummyExp)
10227 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10232 char expString[10240] ;
10233 expString[0] = '\0';
10234 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10237 Compiler_Error($"unresolved identifier %s\n", expString);
10238 else if(exp.type != dummyExp)
10239 Compiler_Error($"couldn't determine type of %s\n", expString);
10250 PrintType(exp.expType, type1, false, true);
10251 PrintType(exp.destType, type2, false, true);
10254 //CheckExpressionType(exp, exp.destType, false);
10256 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10257 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10258 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10261 char expString[10240];
10262 expString[0] = '\0';
10263 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10266 CheckExpressionType(exp, exp.destType, false);
10268 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10269 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10270 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10272 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10273 FreeType(exp.expType);
10274 exp.destType.refCount++;
10275 exp.expType = exp.destType;
10280 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10282 Expression newExp { };
10283 char typeString[1024];
10284 OldList * specs = MkList();
10287 typeString[0] = '\0';
10291 if(exp.expType) exp.expType.refCount++;
10292 if(exp.expType) exp.expType.refCount++;
10293 exp.type = castExp;
10294 newExp.destType = exp.expType;
10296 PrintType(exp.expType, typeString, false, false);
10297 decl = SpecDeclFromString(typeString, specs, null);
10299 exp.cast.typeName = MkTypeName(specs, decl);
10300 exp.cast.exp = newExp;
10303 else if(unresolved)
10305 if(exp.identifier._class && exp.identifier._class.name)
10306 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10307 else if(exp.identifier.string && exp.identifier.string[0])
10308 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10310 else if(!exp.expType && exp.type != dummyExp)
10312 char expString[10240];
10313 expString[0] = '\0';
10314 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10315 Compiler_Error($"couldn't determine type of %s\n", expString);
10318 // Let's try to support any_object & typed_object here:
10319 ApplyAnyObjectLogic(exp);
10321 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10322 exp.expType._class.registered.type == noHeadClass)
10324 exp.byReference = true;
10326 /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10327 exp.destType._class.registered.type == noHeadClass)
10329 exp.byReference = true;
10331 yylloc = oldyylloc;
10334 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10336 // THIS CODE WILL FIND NEXT MEMBER...
10339 *curMember = (*curMember).next;
10341 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10343 *curMember = subMemberStack[--(*subMemberStackPos)];
10344 *curMember = (*curMember).next;
10347 // SKIP ALL PROPERTIES HERE...
10348 while((*curMember) && (*curMember).isProperty)
10349 *curMember = (*curMember).next;
10351 if(subMemberStackPos)
10353 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10355 subMemberStack[(*subMemberStackPos)++] = *curMember;
10357 *curMember = (*curMember).members.first;
10358 while(*curMember && (*curMember).isProperty)
10359 *curMember = (*curMember).next;
10367 if(subMemberStackPos && *subMemberStackPos)
10369 *curMember = subMemberStack[--(*subMemberStackPos)];
10370 *curMember = (*curMember).next;
10374 Class lastCurClass = *curClass;
10376 if(*curClass == _class) break; // REACHED THE END
10378 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10379 *curMember = (*curClass).membersAndProperties.first;
10382 while((*curMember) && (*curMember).isProperty)
10383 *curMember = (*curMember).next;
10384 if(subMemberStackPos)
10386 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10388 subMemberStack[(*subMemberStackPos)++] = *curMember;
10390 *curMember = (*curMember).members.first;
10391 while(*curMember && (*curMember).isProperty)
10392 *curMember = (*curMember).next;
10400 static void ProcessInitializer(Initializer init, Type type)
10404 case expInitializer:
10405 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10407 // TESTING THIS FOR SHUTTING = 0 WARNING
10408 if(init.exp && !init.exp.destType)
10410 FreeType(init.exp.destType);
10411 init.exp.destType = type;
10412 if(type) type.refCount++;
10416 ProcessExpressionType(init.exp);
10417 init.isConstant = init.exp.isConstant;
10423 Expression exp = init.exp;
10424 Instantiation inst = exp.instance;
10425 MembersInit members;
10427 init.type = listInitializer;
10428 init.list = MkList();
10432 for(members = inst.members->first; members; members = members.next)
10434 if(members.type == dataMembersInit)
10437 for(member = members.dataMembers->first; member; member = member.next)
10439 ListAdd(init.list, member.initializer);
10440 member.initializer = null;
10443 // Discard all MembersInitMethod
10446 FreeExpression(exp);
10448 case listInitializer:
10451 Type initializerType = null;
10452 Class curClass = null;
10453 DataMember curMember = null;
10454 DataMember subMemberStack[256];
10455 int subMemberStackPos = 0;
10457 if(type && type.kind == arrayType)
10458 initializerType = Dereference(type);
10459 else if(type && (type.kind == structType || type.kind == unionType))
10460 initializerType = type.members.first;
10462 for(i = init.list->first; i; i = i.next)
10464 if(type && type.kind == classType && type._class && type._class.registered)
10466 // 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)
10467 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10468 // TODO: Generate error on initializing a private data member this way from another module...
10471 if(!curMember.dataType)
10472 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10473 initializerType = curMember.dataType;
10476 ProcessInitializer(i, initializerType);
10477 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10478 initializerType = initializerType.next;
10480 init.isConstant = false;
10483 if(type && type.kind == arrayType)
10484 FreeType(initializerType);
10486 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10488 Compiler_Error($"Assigning list initializer to non list\n");
10495 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10499 case baseSpecifier:
10501 if(spec.specifier == THISCLASS)
10505 spec.type = nameSpecifier;
10506 spec.name = ReplaceThisClass(thisClass);
10507 spec.symbol = FindClass(spec.name);
10508 ProcessSpecifier(spec, declareStruct);
10513 case nameSpecifier:
10515 Symbol symbol = FindType(curContext, spec.name);
10517 DeclareType(symbol.type, true, true);
10518 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10519 DeclareStruct(spec.name, false);
10522 case enumSpecifier:
10527 for(e = spec.list->first; e; e = e.next)
10530 ProcessExpressionType(e.exp);
10535 case structSpecifier:
10536 case unionSpecifier:
10538 if(spec.definitions)
10541 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10543 ProcessClass(spec.definitions, symbol);
10546 for(def = spec.definitions->first; def; def = def.next)
10548 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10549 ProcessDeclaration(def.decl);
10556 case classSpecifier:
10558 Symbol classSym = FindClass(spec.name);
10559 if(classSym && classSym.registered && classSym.registered.type == structClass)
10560 DeclareStruct(spec.name, false);
10568 static void ProcessDeclarator(Declarator decl)
10572 case identifierDeclarator:
10573 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10575 FreeSpecifier(decl.identifier._class);
10576 decl.identifier._class = null;
10579 case arrayDeclarator:
10581 ProcessExpressionType(decl.array.exp);
10582 case structDeclarator:
10583 case bracketsDeclarator:
10584 case functionDeclarator:
10585 case pointerDeclarator:
10586 case extendedDeclarator:
10587 case extendedDeclaratorEnd:
10588 if(decl.declarator)
10589 ProcessDeclarator(decl.declarator);
10590 if(decl.type == functionDeclarator)
10592 Identifier id = GetDeclId(decl);
10593 if(id && id._class)
10597 qualifiers = MkListOne(id._class);
10600 if(!decl.function.parameters)
10601 decl.function.parameters = MkList();
10602 decl.function.parameters->Insert(null, param);
10605 if(decl.function.parameters)
10609 for(param = decl.function.parameters->first; param; param = param.next)
10611 if(param.qualifiers && param.qualifiers->first)
10613 Specifier spec = param.qualifiers->first;
10614 if(spec && spec.specifier == TYPED_OBJECT)
10616 Declarator d = param.declarator;
10619 qualifiers = MkListOne(MkSpecifier(VOID));
10620 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10623 FreeList(param.qualifiers, FreeSpecifier);
10625 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10626 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10628 decl.function.parameters->Insert(param, newParam);
10631 else if(spec && spec.specifier == ANY_OBJECT)
10633 Declarator d = param.declarator;
10635 FreeList(param.qualifiers, FreeSpecifier);
10637 param.qualifiers = MkListOne(MkSpecifier(VOID));
10638 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10640 else if(spec.specifier == THISCLASS)
10644 spec.type = nameSpecifier;
10645 spec.name = ReplaceThisClass(thisClass);
10646 spec.symbol = FindClass(spec.name);
10647 ProcessSpecifier(spec, false);
10652 if(param.declarator)
10653 ProcessDeclarator(param.declarator);
10661 static void ProcessDeclaration(Declaration decl)
10666 case initDeclaration:
10668 bool declareStruct = false;
10670 lineNum = decl.pos.line;
10671 column = decl.pos.col;
10674 if(decl.declarators)
10678 for(d = decl.declarators->first; d; d = d.next)
10680 Type type, subType;
10681 ProcessDeclarator(d.declarator);
10683 type = ProcessType(decl.specifiers, d.declarator);
10687 ProcessInitializer(d.initializer, type);
10689 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10691 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10692 d.initializer.exp.type == instanceExp)
10694 if(type.kind == classType && type._class ==
10695 d.initializer.exp.expType._class)
10697 Instantiation inst = d.initializer.exp.instance;
10698 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10700 d.initializer.exp.instance = null;
10701 if(decl.specifiers)
10702 FreeList(decl.specifiers, FreeSpecifier);
10703 FreeList(decl.declarators, FreeInitDeclarator);
10707 decl.type = instDeclaration;
10712 for(subType = type; subType;)
10714 if(subType.kind == classType)
10716 declareStruct = true;
10719 else if(subType.kind == pointerType)
10721 else if(subType.kind == arrayType)
10722 subType = subType.arrayType;
10732 if(decl.specifiers)
10735 for(s = decl.specifiers->first; s; s = s.next)
10737 ProcessSpecifier(s, declareStruct);
10742 case instDeclaration:
10744 ProcessInstantiationType(decl.inst);
10747 case structDeclaration:
10751 bool declareStruct = false;
10753 if(decl.declarators)
10755 for(d = decl.declarators->first; d; d = d.next)
10757 Type type = ProcessType(decl.specifiers, d.declarator);
10759 ProcessDeclarator(d);
10760 for(subType = type; subType;)
10762 if(subType.kind == classType)
10764 declareStruct = true;
10767 else if(subType.kind == pointerType)
10769 else if(subType.kind == arrayType)
10770 subType = subType.arrayType;
10777 if(decl.specifiers)
10779 for(spec = decl.specifiers->first; spec; spec = spec.next)
10780 ProcessSpecifier(spec, declareStruct);
10787 static FunctionDefinition curFunction;
10789 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10791 char propName[1024], propNameM[1024];
10792 char getName[1024], setName[1024];
10795 DeclareProperty(prop, setName, getName);
10797 // eInstance_FireWatchers(object, prop);
10798 strcpy(propName, "__ecereProp_");
10799 FullClassNameCat(propName, prop._class.fullName, false);
10800 strcat(propName, "_");
10801 // strcat(propName, prop.name);
10802 FullClassNameCat(propName, prop.name, true);
10803 MangleClassName(propName);
10805 strcpy(propNameM, "__ecerePropM_");
10806 FullClassNameCat(propNameM, prop._class.fullName, false);
10807 strcat(propNameM, "_");
10808 // strcat(propNameM, prop.name);
10809 FullClassNameCat(propNameM, prop.name, true);
10810 MangleClassName(propNameM);
10812 if(prop.isWatchable)
10815 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10816 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10817 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10820 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10821 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10822 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10828 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10829 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10830 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10833 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10834 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10835 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10838 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10839 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10840 curFunction.propSet.fireWatchersDone = true;
10843 static void ProcessStatement(Statement stmt)
10847 lineNum = stmt.pos.line;
10848 column = stmt.pos.col;
10853 ProcessStatement(stmt.labeled.stmt);
10856 // This expression should be constant...
10857 if(stmt.caseStmt.exp)
10859 FreeType(stmt.caseStmt.exp.destType);
10860 stmt.caseStmt.exp.destType = curSwitchType;
10861 if(curSwitchType) curSwitchType.refCount++;
10862 ProcessExpressionType(stmt.caseStmt.exp);
10863 ComputeExpression(stmt.caseStmt.exp);
10865 if(stmt.caseStmt.stmt)
10866 ProcessStatement(stmt.caseStmt.stmt);
10870 if(stmt.compound.context)
10875 Statement prevCompound = curCompound;
10876 Context prevContext = curContext;
10878 if(!stmt.compound.isSwitch)
10880 curCompound = stmt;
10881 curContext = stmt.compound.context;
10884 if(stmt.compound.declarations)
10886 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10887 ProcessDeclaration(decl);
10889 if(stmt.compound.statements)
10891 for(s = stmt.compound.statements->first; s; s = s.next)
10892 ProcessStatement(s);
10895 curContext = prevContext;
10896 curCompound = prevCompound;
10900 case expressionStmt:
10903 if(stmt.expressions)
10905 for(exp = stmt.expressions->first; exp; exp = exp.next)
10906 ProcessExpressionType(exp);
10914 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10915 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10916 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10917 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10919 ProcessExpressionType(exp);
10921 if(stmt.ifStmt.stmt)
10922 ProcessStatement(stmt.ifStmt.stmt);
10923 if(stmt.ifStmt.elseStmt)
10924 ProcessStatement(stmt.ifStmt.elseStmt);
10929 Type oldSwitchType = curSwitchType;
10930 if(stmt.switchStmt.exp)
10933 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
10943 e.exp.destType = destType;
10946 ProcessExpressionType(exp);
10949 curSwitchType = exp.expType;
10952 ProcessStatement(stmt.switchStmt.stmt);
10953 curSwitchType = oldSwitchType;
10958 if(stmt.whileStmt.exp)
10962 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
10963 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
10964 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
10965 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
10967 ProcessExpressionType(exp);
10970 if(stmt.whileStmt.stmt)
10971 ProcessStatement(stmt.whileStmt.stmt);
10976 if(stmt.doWhile.exp)
10980 if(stmt.doWhile.exp->last)
10982 FreeType(((Expression)stmt.doWhile.exp->last).destType);
10983 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
10984 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
10986 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
10988 ProcessExpressionType(exp);
10991 if(stmt.doWhile.stmt)
10992 ProcessStatement(stmt.doWhile.stmt);
10998 if(stmt.forStmt.init)
10999 ProcessStatement(stmt.forStmt.init);
11001 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11003 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11004 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11005 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11008 if(stmt.forStmt.check)
11009 ProcessStatement(stmt.forStmt.check);
11010 if(stmt.forStmt.increment)
11012 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11013 ProcessExpressionType(exp);
11016 if(stmt.forStmt.stmt)
11017 ProcessStatement(stmt.forStmt.stmt);
11022 Identifier id = stmt.forEachStmt.id;
11023 OldList * exp = stmt.forEachStmt.exp;
11024 OldList * filter = stmt.forEachStmt.filter;
11025 Statement block = stmt.forEachStmt.stmt;
11026 char iteratorType[1024];
11029 bool isBuiltin = exp && exp->last &&
11030 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11031 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11032 Expression arrayExp;
11033 char * typeString = null;
11034 int builtinCount = 0;
11036 for(e = exp ? exp->first : null; e; e = e.next)
11040 FreeType(e.destType);
11041 e.destType = ProcessTypeString("Container", false);
11043 if(!isBuiltin || e.next)
11044 ProcessExpressionType(e);
11047 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11048 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11049 eClass_IsDerived(source._class.registered, containerClass)))
11051 Class _class = source ? source._class.registered : null;
11053 Expression expIt = null;
11054 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11055 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11056 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11057 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11058 stmt.type = compoundStmt;
11060 stmt.compound.context = Context { };
11061 stmt.compound.context.parent = curContext;
11062 curContext = stmt.compound.context;
11064 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11066 Class mapClass = eSystem_FindClass(privateModule, "Map");
11067 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11068 isCustomAVLTree = true;
11069 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11071 else if(eClass_IsDerived(source._class.registered, mapClass))
11074 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11075 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11077 Class listClass = eSystem_FindClass(privateModule, "List");
11079 isList = eClass_IsDerived(source._class.registered, listClass);
11085 OldList * specs = MkList();
11086 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11087 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11088 stmt.compound.declarations = MkListOne(
11089 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11090 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11091 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11092 MkInitializerAssignment(MkExpBrackets(exp))))));
11097 char typeStringBuf[1024];
11099 // TODO: Merge this code?
11100 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11101 if(((Expression)exp->last).type == castExp)
11103 TypeName typeName = ((Expression)exp->last).cast.typeName;
11105 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11108 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11109 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11110 arrayExp.destType._class.registered.templateArgs)
11112 Class templateClass = arrayExp.destType._class.registered;
11113 typeString = templateClass.templateArgs[2].dataTypeString;
11115 else if(arrayExp.list)
11117 // Guess type from expressions in the array
11119 for(e = arrayExp.list->first; e; e = e.next)
11121 ProcessExpressionType(e);
11124 if(!type) { type = e.expType; type.refCount++; }
11127 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11128 if(!MatchTypeExpression(e, type, null, false))
11134 e = arrayExp.list->first;
11135 ProcessExpressionType(e);
11138 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11139 if(!MatchTypeExpression(e, type, null, false))
11141 FreeType(e.expType);
11152 FreeType(e.expType);
11159 typeStringBuf[0] = '\0';
11160 PrintType(type, typeStringBuf, false, true);
11161 typeString = typeStringBuf;
11167 OldList * initializers = MkList();
11169 OldList * specs = MkList();
11174 builtinCount = arrayExp.list->count;
11175 type = ProcessTypeString(typeString, false);
11176 while(e = arrayExp.list->first)
11178 arrayExp.list->Remove(e);
11181 ProcessExpressionType(e);
11182 ListAdd(initializers, MkInitializerAssignment(e));
11185 delete arrayExp.list;
11187 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11188 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11189 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11191 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
11192 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
11194 FreeList(exp, FreeExpression);
11198 arrayExp.expType = ProcessTypeString("Container", false);
11199 Compiler_Error($"Couldn't determine type of array elements\n");
11204 OldList * specs = MkList();
11206 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11207 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11208 stmt.compound.declarations = MkListOne(
11209 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11210 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11211 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11212 MkInitializerAssignment(MkExpBrackets(exp))))));
11215 else if(isLinkList && !isList)
11218 OldList * specs = MkList();
11219 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11220 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11221 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11222 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11223 MkInitializerAssignment(MkExpBrackets(exp))))));
11225 /*else if(isCustomAVLTree)
11228 OldList * specs = MkList();
11229 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11230 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11231 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11232 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11233 MkInitializerAssignment(MkExpBrackets(exp))))));
11235 else if(_class.templateArgs)
11238 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11240 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11242 stmt.compound.declarations = MkListOne(
11243 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11244 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11245 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11247 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11249 if(block && block.type == compoundStmt && block.compound.context)
11251 block.compound.context.parent = stmt.compound.context;
11255 block = MkIfStmt(filter, block, null);
11259 stmt.compound.statements = MkListOne(MkForStmt(
11260 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11261 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11262 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11263 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11265 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11266 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11267 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11272 //OldList * specs = MkList();
11273 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11275 sprintf(count, "%d", builtinCount);
11277 stmt.compound.statements = MkListOne(MkForStmt(
11278 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11279 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11280 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11281 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11285 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11286 stmt.compound.statements = MkListOne(MkForStmt(
11287 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11288 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11289 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11290 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11293 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11294 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11295 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11297 else if(isLinkList && !isList)
11299 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11300 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11301 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11302 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11304 stmt.compound.statements = MkListOne(MkForStmt(
11305 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11306 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11307 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11312 OldList * specs = MkList();
11313 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11314 stmt.compound.statements = MkListOne(MkForStmt(
11315 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11316 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11317 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11318 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11319 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11322 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11323 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11324 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11326 /*else if(isCustomAVLTree)
11328 stmt.compound.statements = MkListOne(MkForStmt(
11329 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11330 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11331 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11332 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11335 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11336 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11337 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11341 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11342 MkIdentifier("Next")), null)), block));
11344 ProcessExpressionType(expIt);
11345 if(stmt.compound.declarations->first)
11346 ProcessDeclaration(stmt.compound.declarations->first);
11349 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11351 ProcessStatement(stmt);
11352 curContext = stmt.compound.context.parent;
11357 Compiler_Error($"Expression is not a container\n");
11370 if(stmt.expressions)
11372 for(exp = stmt.expressions->first; exp; exp = exp.next)
11376 if(curFunction && !curFunction.type)
11377 curFunction.type = ProcessType(
11378 curFunction.specifiers, curFunction.declarator);
11379 FreeType(exp.destType);
11380 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11381 if(exp.destType) exp.destType.refCount++;
11383 ProcessExpressionType(exp);
11388 case badDeclarationStmt:
11390 ProcessDeclaration(stmt.decl);
11396 if(stmt.asmStmt.inputFields)
11398 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11399 if(field.expression)
11400 ProcessExpressionType(field.expression);
11402 if(stmt.asmStmt.outputFields)
11404 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11405 if(field.expression)
11406 ProcessExpressionType(field.expression);
11408 if(stmt.asmStmt.clobberedFields)
11410 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11412 if(field.expression)
11413 ProcessExpressionType(field.expression);
11420 PropertyWatch propWatch;
11421 OldList * watches = stmt._watch.watches;
11422 Expression object = stmt._watch.object;
11423 Expression watcher = stmt._watch.watcher;
11425 ProcessExpressionType(watcher);
11427 ProcessExpressionType(object);
11431 if(watcher || thisClass)
11433 External external = curExternal;
11434 Context context = curContext;
11436 stmt.type = expressionStmt;
11437 stmt.expressions = MkList();
11439 curExternal = external.prev;
11441 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11443 ClassFunction func;
11444 char watcherName[1024];
11445 Class watcherClass = watcher ?
11446 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11447 External createdExternal;
11449 // Create a declaration above
11450 External externalDecl = MkExternalDeclaration(null);
11451 ast->Insert(curExternal.prev, externalDecl);
11453 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11454 if(propWatch.deleteWatch)
11455 strcat(watcherName, "_delete");
11459 for(propID = propWatch.properties->first; propID; propID = propID.next)
11461 strcat(watcherName, "_");
11462 strcat(watcherName, propID.string);
11466 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11468 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11469 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11470 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11471 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11472 ProcessClassFunctionBody(func, propWatch.compound);
11473 propWatch.compound = null;
11475 //afterExternal = afterExternal ? afterExternal : curExternal;
11477 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11478 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11480 createdExternal.symbol.idCode = external.symbol.idCode;
11482 curExternal = createdExternal;
11483 ProcessFunction(createdExternal.function);
11486 // Create a declaration above
11488 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11489 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11490 externalDecl.declaration = decl;
11491 if(decl.symbol && !decl.symbol.pointerExternal)
11492 decl.symbol.pointerExternal = externalDecl;
11495 if(propWatch.deleteWatch)
11497 OldList * args = MkList();
11498 ListAdd(args, CopyExpression(object));
11499 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11500 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11501 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11505 Class _class = object.expType._class.registered;
11508 for(propID = propWatch.properties->first; propID; propID = propID.next)
11510 char propName[1024];
11511 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11514 char getName[1024], setName[1024];
11515 OldList * args = MkList();
11517 DeclareProperty(prop, setName, getName);
11519 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11520 strcpy(propName, "__ecereProp_");
11521 FullClassNameCat(propName, prop._class.fullName, false);
11522 strcat(propName, "_");
11523 // strcat(propName, prop.name);
11524 FullClassNameCat(propName, prop.name, true);
11526 ListAdd(args, CopyExpression(object));
11527 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11528 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11529 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11531 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11534 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11539 Compiler_Error($"Invalid watched object\n");
11542 curExternal = external;
11543 curContext = context;
11546 FreeExpression(watcher);
11548 FreeExpression(object);
11549 FreeList(watches, FreePropertyWatch);
11552 Compiler_Error($"No observer specified and not inside a _class\n");
11556 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11558 ProcessStatement(propWatch.compound);
11564 case fireWatchersStmt:
11566 OldList * watches = stmt._watch.watches;
11567 Expression object = stmt._watch.object;
11569 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11570 // printf("%X\n", watches);
11571 // printf("%X\n", stmt._watch.watches);
11573 ProcessExpressionType(object);
11578 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11584 stmt.type = expressionStmt;
11585 stmt.expressions = MkList();
11587 // Check if we're inside a property set
11588 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11590 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11594 //Compiler_Error($"No property specified and not inside a property set\n");
11598 for(propID = watches->first; propID; propID = propID.next)
11600 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11603 CreateFireWatcher(prop, object, stmt);
11606 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11611 // Fire all properties!
11614 for(base = _class; base; base = base.base)
11616 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11618 if(prop.isProperty && prop.isWatchable)
11620 CreateFireWatcher(prop, object, stmt);
11627 FreeExpression(object);
11628 FreeList(watches, FreeIdentifier);
11631 Compiler_Error($"Invalid object specified and not inside a class\n");
11635 case stopWatchingStmt:
11637 OldList * watches = stmt._watch.watches;
11638 Expression object = stmt._watch.object;
11639 Expression watcher = stmt._watch.watcher;
11642 ProcessExpressionType(object);
11644 ProcessExpressionType(watcher);
11647 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11649 if(watcher || thisClass)
11655 stmt.type = expressionStmt;
11656 stmt.expressions = MkList();
11661 // eInstance_StopWatching(object, null, watcher);
11663 ListAdd(args, CopyExpression(object));
11664 ListAdd(args, MkExpConstant("0"));
11665 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11666 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11670 for(propID = watches->first; propID; propID = propID.next)
11672 char propName[1024];
11673 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11676 char getName[1024], setName[1024];
11677 OldList * args = MkList();
11679 DeclareProperty(prop, setName, getName);
11681 // eInstance_StopWatching(object, prop, watcher);
11682 strcpy(propName, "__ecereProp_");
11683 FullClassNameCat(propName, prop._class.fullName, false);
11684 strcat(propName, "_");
11685 // strcat(propName, prop.name);
11686 FullClassNameCat(propName, prop.name, true);
11687 MangleClassName(propName);
11689 ListAdd(args, CopyExpression(object));
11690 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11691 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11692 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11695 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11700 FreeExpression(object);
11702 FreeExpression(watcher);
11703 FreeList(watches, FreeIdentifier);
11706 Compiler_Error($"Invalid object specified and not inside a class\n");
11709 Compiler_Error($"No observer specified and not inside a class\n");
11716 static void ProcessFunction(FunctionDefinition function)
11718 Identifier id = GetDeclId(function.declarator);
11719 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11720 Type type = symbol ? symbol.type : null;
11721 Class oldThisClass = thisClass;
11722 Context oldTopContext = topContext;
11724 yylloc = function.loc;
11725 // Process thisClass
11727 if(type && type.thisClass)
11729 Symbol classSym = type.thisClass;
11730 Class _class = type.thisClass.registered;
11731 char className[1024];
11732 char structName[1024];
11733 Declarator funcDecl;
11736 bool typedObject = false;
11738 if(_class && !_class.base)
11740 _class = currentClass;
11741 if(_class && !_class.symbol)
11742 _class.symbol = FindClass(_class.fullName);
11743 classSym = _class ? _class.symbol : null;
11744 typedObject = true;
11747 thisClass = _class;
11749 if(inCompiler && _class)
11751 if(type.kind == functionType)
11753 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11755 //TypeName param = symbol.type.params.first;
11756 Type param = symbol.type.params.first;
11757 symbol.type.params.Remove(param);
11758 //FreeTypeName(param);
11761 if(type.classObjectType != classPointer)
11763 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11764 symbol.type.staticMethod = true;
11765 symbol.type.thisClass = null;
11767 // HIGH DANGER: VERIFYING THIS...
11768 symbol.type.extraParam = false;
11772 strcpy(className, "__ecereClass_");
11773 FullClassNameCat(className, _class.fullName, true);
11775 MangleClassName(className);
11778 FullClassNameCat(structName, _class.fullName, false);
11783 funcDecl = GetFuncDecl(function.declarator);
11786 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11788 TypeName param = funcDecl.function.parameters->first;
11789 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11791 funcDecl.function.parameters->Remove(param);
11792 FreeTypeName(param);
11796 // DANGER: Watch for this... Check if it's a Conversion?
11797 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11799 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11800 if(!function.propertyNoThis)
11802 TypeName thisParam;
11804 if(type.classObjectType != classPointer)
11806 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11807 if(!funcDecl.function.parameters)
11808 funcDecl.function.parameters = MkList();
11809 funcDecl.function.parameters->Insert(null, thisParam);
11814 if(type.classObjectType != classPointer)
11816 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11817 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11820 thisParam = TypeName
11822 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11823 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11825 funcDecl.function.parameters->Insert(null, thisParam);
11830 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11832 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11833 funcDecl = GetFuncDecl(initDecl.declarator);
11836 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11838 TypeName param = funcDecl.function.parameters->first;
11839 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11841 funcDecl.function.parameters->Remove(param);
11842 FreeTypeName(param);
11846 if(type.classObjectType != classPointer)
11848 // DANGER: Watch for this... Check if it's a Conversion?
11849 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11851 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11853 if(!funcDecl.function.parameters)
11854 funcDecl.function.parameters = MkList();
11855 funcDecl.function.parameters->Insert(null, thisParam);
11862 // Add this to the context
11865 if(type.classObjectType != classPointer)
11867 thisSymbol = Symbol
11869 string = CopyString("this");
11870 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11872 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11874 if(typedObject && thisSymbol.type)
11876 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11877 thisSymbol.type.byReference = type.byReference;
11879 thisSymbol = Symbol { string = CopyString("class") };
11880 function.body.compound.context.symbols.Add(thisSymbol);
11886 // Pointer to class data
11888 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11890 DataMember member = null;
11893 for(base = _class; base && base.type != systemClass; base = base.next)
11895 for(member = base.membersAndProperties.first; member; member = member.next)
11896 if(!member.isProperty)
11902 for(member = _class.membersAndProperties.first; member; member = member.next)
11903 if(!member.isProperty)
11907 char pointerName[1024];
11910 Initializer initializer;
11911 Expression exp, bytePtr;
11913 strcpy(pointerName, "__ecerePointer_");
11914 FullClassNameCat(pointerName, _class.fullName, false);
11916 char className[1024];
11917 strcpy(className, "__ecereClass_");
11918 FullClassNameCat(className, classSym.string, true);
11919 MangleClassName(className);
11922 DeclareClass(classSym, className);
11926 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11931 sprintf(string, "%d", _class.offset);
11932 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11936 // ([bytePtr] + [className]->offset)
11937 exp = QBrackets(MkExpOp(bytePtr, '+',
11938 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
11941 // (this ? [exp] : 0)
11942 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
11946 kind = pointerType;
11947 type = Type { refCount = 1, kind = voidType };
11952 yylloc = function.body.loc;
11953 // ([structName] *) [exp]
11954 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
11955 initializer = MkInitializerAssignment(
11956 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
11958 // [structName] * [pointerName] = [initializer];
11959 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
11962 Context prevContext = curContext;
11963 curContext = function.body.compound.context;
11965 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
11966 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
11968 curContext = prevContext;
11972 decl.symbol = null;
11974 if(!function.body.compound.declarations)
11975 function.body.compound.declarations = MkList();
11976 function.body.compound.declarations->Insert(null, decl);
11982 // Loop through the function and replace undeclared identifiers
11983 // which are a member of the class (methods, properties or data)
11984 // by "this.[member]"
11991 FreeSpecifier(id._class);
11994 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11996 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11997 id = GetDeclId(initDecl.declarator);
11999 FreeSpecifier(id._class);
12004 topContext = function.body.compound.context;
12006 FunctionDefinition oldFunction = curFunction;
12007 curFunction = function;
12009 ProcessStatement(function.body);
12011 // If this is a property set and no firewatchers has been done yet, add one here
12012 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12014 Statement prevCompound = curCompound;
12015 Context prevContext = curContext;
12017 Statement fireWatchers = MkFireWatchersStmt(null, null);
12018 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12019 ListAdd(function.body.compound.statements, fireWatchers);
12021 curCompound = function.body;
12022 curContext = function.body.compound.context;
12024 ProcessStatement(fireWatchers);
12026 curContext = prevContext;
12027 curCompound = prevCompound;
12031 curFunction = oldFunction;
12034 if(function.declarator)
12036 ProcessDeclarator(function.declarator);
12039 topContext = oldTopContext;
12040 thisClass = oldThisClass;
12043 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12044 static void ProcessClass(OldList definitions, Symbol symbol)
12047 External external = curExternal;
12048 Class regClass = symbol ? symbol.registered : null;
12050 // Process all functions
12051 for(def = definitions.first; def; def = def.next)
12053 if(def.type == functionClassDef)
12055 if(def.function.declarator)
12056 curExternal = def.function.declarator.symbol.pointerExternal;
12058 curExternal = external;
12060 ProcessFunction((FunctionDefinition)def.function);
12062 else if(def.type == declarationClassDef)
12064 if(def.decl.type == instDeclaration)
12066 thisClass = regClass;
12067 ProcessInstantiationType(def.decl.inst);
12073 Class backThisClass = thisClass;
12074 if(regClass) thisClass = regClass;
12075 ProcessDeclaration(def.decl);
12076 thisClass = backThisClass;
12079 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12081 MemberInit defProperty;
12083 // Add this to the context
12084 Symbol thisSymbol = Symbol
12086 string = CopyString("this");
12087 type = regClass ? MkClassType(regClass.fullName) : null;
12089 globalContext.symbols.Add((BTNode)thisSymbol);
12091 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12093 thisClass = regClass;
12094 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12098 globalContext.symbols.Remove((BTNode)thisSymbol);
12099 FreeSymbol(thisSymbol);
12101 else if(def.type == propertyClassDef && def.propertyDef)
12103 PropertyDef prop = def.propertyDef;
12105 // Add this to the context
12107 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12108 globalContext.symbols.Add(thisSymbol);
12111 thisClass = regClass;
12118 string = CopyString("this");
12119 type = MkClassType(regClass.fullName);
12121 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12124 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12125 ProcessStatement(prop.setStmt);
12133 string = CopyString("this");
12134 type = MkClassType(regClass.fullName);
12136 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12139 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12140 ProcessStatement(prop.getStmt);
12148 string = CopyString("this");
12149 type = MkClassType(regClass.fullName);
12151 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12154 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12155 ProcessStatement(prop.issetStmt);
12161 globalContext.symbols.Remove(thisSymbol);
12162 FreeSymbol(thisSymbol);
12165 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12167 PropertyWatch propertyWatch = def.propertyWatch;
12169 thisClass = regClass;
12170 if(propertyWatch.compound)
12174 string = CopyString("this");
12175 type = regClass ? MkClassType(regClass.fullName) : null;
12178 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12180 curExternal = null;
12181 ProcessStatement(propertyWatch.compound);
12188 void DeclareFunctionUtil(String s)
12190 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12195 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12196 strcpy(name, "__ecereFunction_");
12197 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12198 DeclareFunction(function, name);
12202 void ComputeDataTypes()
12206 External after = null;
12208 currentClass = null;
12210 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12212 for(external = ast->first; external; external = external.next)
12214 if(external.type == declarationExternal)
12216 Declaration decl = external.declaration;
12219 OldList * decls = decl.declarators;
12222 InitDeclarator initDecl = decls->first;
12225 Declarator declarator = initDecl.declarator;
12226 if(declarator && declarator.type == identifierDeclarator)
12228 Identifier id = declarator.identifier;
12229 if(id && id.string)
12231 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12233 external.symbol.id = -1001, external.symbol.idCode = -1001;
12244 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12245 ast->Insert(after, temp);
12246 curExternal = temp;
12248 DeclareFunctionUtil("eSystem_New");
12249 DeclareFunctionUtil("eSystem_New0");
12250 DeclareFunctionUtil("eSystem_Renew");
12251 DeclareFunctionUtil("eSystem_Renew0");
12252 DeclareFunctionUtil("eClass_GetProperty");
12254 DeclareStruct("ecere::com::Class", false);
12255 DeclareStruct("ecere::com::Instance", false);
12256 DeclareStruct("ecere::com::Property", false);
12257 DeclareStruct("ecere::com::DataMember", false);
12258 DeclareStruct("ecere::com::Method", false);
12259 DeclareStruct("ecere::com::SerialBuffer", false);
12260 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12264 for(external = ast->first; external; external = external.next)
12266 afterExternal = curExternal = external;
12267 if(external.type == functionExternal)
12269 currentClass = external.function._class;
12270 ProcessFunction(external.function);
12272 // There shouldn't be any _class member access here anyways...
12273 else if(external.type == declarationExternal)
12275 currentClass = null;
12276 ProcessDeclaration(external.declaration);
12278 else if(external.type == classExternal)
12280 ClassDefinition _class = external._class;
12281 currentClass = external.symbol.registered;
12282 if(_class.definitions)
12284 ProcessClass(_class.definitions, _class.symbol);
12288 // Free class data...
12289 ast->Remove(external);
12293 else if(external.type == nameSpaceExternal)
12295 thisNameSpace = external.id.string;
12298 currentClass = null;
12299 thisNameSpace = null;
12301 delete temp.symbol;