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", (int)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", (int)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;
761 type.alignment = type.type.alignment;
767 for(member = type.members.first; member; member = member.next)
769 uint addSize = ComputeTypeSize(member);
771 member.offset = size;
772 if(member.alignment && size % member.alignment)
773 member.offset += member.alignment - (size % member.alignment);
774 size = member.offset;
776 type.alignment = Max(type.alignment, member.alignment);
779 if(type.alignment && size % type.alignment)
780 size += type.alignment - (size % type.alignment);
786 for(member = type.members.first; member; member = member.next)
788 uint addSize = ComputeTypeSize(member);
790 member.offset = size;
791 if(member.alignment && size % member.alignment)
792 member.offset += member.alignment - (size % member.alignment);
793 size = member.offset;
795 type.alignment = Max(type.alignment, member.alignment);
796 size = Max(size, addSize);
798 if(type.alignment && size % type.alignment)
799 size += type.alignment - (size % type.alignment);
804 TemplateParameter param = type.templateParameter;
805 Type baseType = ProcessTemplateParameterType(param);
808 size = ComputeTypeSize(baseType);
809 type.alignment = baseType.alignment;
812 type.alignment = size = sizeof(uint64);
817 type.alignment = size = sizeof(enum { test });
822 type.alignment = size = targetBits / 8; //sizeof(void *);
827 type.computing = false;
833 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
835 // This function is in need of a major review when implementing private members etc.
836 DataMember topMember = isMember ? (DataMember) _class : null;
841 Context context = isMember ? null : SetupTemplatesContext(_class);
843 *addedPadding = false;
845 if(!isMember && _class.base)
847 maxSize = _class.structSize;
848 //if(_class.base.type != systemClass) // Commented out with new Instance _class
850 // DANGER: Testing this noHeadClass here...
851 if(_class.type == structClass || _class.type == noHeadClass)
852 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
855 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
856 if(maxSize > baseSize)
864 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
866 if(!member.isProperty)
872 if(member.dataTypeString)
874 OldList * specs = MkList(), * decls = MkList();
877 decl = SpecDeclFromString(member.dataTypeString, specs,
878 MkDeclaratorIdentifier(MkIdentifier(member.name)));
879 ListAdd(decls, MkStructDeclarator(decl, null));
880 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
883 member.dataType = ProcessType(specs, decl);
885 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
888 Type type = ProcessType(specs, decl);
889 DeclareType(member.dataType, false, false);
893 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
894 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
895 DeclareStruct(member.dataType._class.string, false);
898 ComputeTypeSize(member.dataType);
899 size = member.dataType.size;
900 alignment = member.dataType.alignment;
904 if(totalSize % alignment)
905 totalSize += alignment - (totalSize % alignment);
914 OldList * specs = MkList(), * list = MkList();
917 AddMembers(list, (Class)member, true, &size, topClass, null);
919 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
920 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
921 alignment = member.structAlignment;
925 if(totalSize % alignment)
926 totalSize += alignment - (totalSize % alignment);
936 if(topMember && topMember.type == unionMember)
937 *retSize = Max(*retSize, totalSize);
939 *retSize += totalSize;
941 else if(totalSize < maxSize && _class.type != systemClass)
944 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
945 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
946 if(totalSize + autoPadding < maxSize)
949 sprintf(sizeString, "%d", maxSize - totalSize);
950 ListAdd(declarations,
951 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
952 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
954 *addedPadding = true;
958 FinishTemplatesContext(context);
959 return topMember ? topMember.memberID : _class.memberID;
962 static int DeclareMembers(Class _class, bool isMember)
964 DataMember topMember = isMember ? (DataMember) _class : null;
967 Context context = isMember ? null : SetupTemplatesContext(_class);
969 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
970 DeclareMembers(_class.base, false);
972 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
974 if(!member.isProperty)
981 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
982 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
983 DeclareStruct(member.dataType._class.string, false);
985 if(!member.dataType && member.dataTypeString)
986 member.dataType = ProcessTypeString(member.dataTypeString, false);
988 DeclareType(member.dataType, false, false);
994 DeclareMembers((Class)member, true);
1001 FinishTemplatesContext(context);
1003 return topMember ? topMember.memberID : _class.memberID;
1006 void DeclareStruct(char * name, bool skipNoHead)
1008 External external = null;
1009 Symbol classSym = FindClass(name);
1011 if(!inCompiler || !classSym) return;
1013 // We don't need any declaration for bit classes...
1014 if(classSym.registered &&
1015 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1018 /*if(classSym.registered.templateClass)
1019 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1022 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1024 // Add typedef struct
1026 OldList * specifiers, * declarators;
1027 OldList * declarations = null;
1028 char structName[1024];
1029 external = (classSym.registered && classSym.registered.type == structClass) ?
1030 classSym.pointerExternal : classSym.structExternal;
1032 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1033 // Moved this one up because DeclareClass done later will need it
1035 classSym.declaring++;
1037 if(strchr(classSym.string, '<'))
1039 if(classSym.registered.templateClass)
1041 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1042 classSym.declaring--;
1048 DeclareMembers(classSym.registered, false);
1051 FullClassNameCat(structName, name, false);
1054 external = MkExternalDeclaration(null);*/
1058 bool addedPadding = false;
1059 classSym.declaredStructSym = true;
1061 declarations = MkList();
1063 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1065 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1066 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1068 if(!declarations->count || (declarations->count == 1 && addedPadding))
1070 FreeList(declarations, FreeClassDef);
1071 declarations = null;
1074 if(skipNoHead || declarations)
1076 if(external && external.declaration)
1078 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1080 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1083 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1086 if(classSym.structExternal)
1087 ast->Move(classSym.structExternal, curExternal.prev);
1088 ast->Move(classSym.pointerExternal, curExternal.prev);
1090 classSym.id = curExternal.symbol.idCode;
1091 classSym.idCode = curExternal.symbol.idCode;
1092 // external = classSym.pointerExternal;
1093 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1099 external = MkExternalDeclaration(null);
1101 specifiers = MkList();
1102 declarators = MkList();
1103 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1106 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1107 ListAdd(declarators, MkInitDeclarator(d, null));
1109 external.declaration = decl = MkDeclaration(specifiers, declarators);
1110 if(decl.symbol && !decl.symbol.pointerExternal)
1111 decl.symbol.pointerExternal = external;
1113 // For simple classes, keep the declaration as the external to move around
1114 if(classSym.registered && classSym.registered.type == structClass)
1116 char className[1024];
1117 strcpy(className, "__ecereClass_");
1118 FullClassNameCat(className, classSym.string, true);
1119 MangleClassName(className);
1122 DeclareClass(classSym, className);
1124 external.symbol = classSym;
1125 classSym.pointerExternal = external;
1126 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1127 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1131 char className[1024];
1132 strcpy(className, "__ecereClass_");
1133 FullClassNameCat(className, classSym.string, true);
1134 MangleClassName(className);
1136 // TOFIX: TESTING THIS...
1137 classSym.structExternal = external;
1138 DeclareClass(classSym, className);
1139 external.symbol = classSym;
1143 ast->Insert(curExternal ? curExternal.prev : null, external);
1147 classSym.declaring--;
1149 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1151 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1152 // Moved this one up because DeclareClass done later will need it
1155 classSym.declaring++;
1159 if(classSym.registered)
1160 DeclareMembers(classSym.registered, false);
1163 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1166 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1169 if(classSym.structExternal)
1170 ast->Move(classSym.structExternal, curExternal.prev);
1171 ast->Move(classSym.pointerExternal, curExternal.prev);
1173 classSym.id = curExternal.symbol.idCode;
1174 classSym.idCode = curExternal.symbol.idCode;
1175 // external = classSym.pointerExternal;
1176 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1179 classSym.declaring--;
1184 void DeclareProperty(Property prop, char * setName, char * getName)
1186 Symbol symbol = prop.symbol;
1187 char propName[1024];
1189 strcpy(setName, "__ecereProp_");
1190 FullClassNameCat(setName, prop._class.fullName, false);
1191 strcat(setName, "_Set_");
1192 // strcat(setName, prop.name);
1193 FullClassNameCat(setName, prop.name, true);
1195 strcpy(getName, "__ecereProp_");
1196 FullClassNameCat(getName, prop._class.fullName, false);
1197 strcat(getName, "_Get_");
1198 FullClassNameCat(getName, prop.name, true);
1199 // strcat(getName, prop.name);
1201 strcpy(propName, "__ecereProp_");
1202 FullClassNameCat(propName, prop._class.fullName, false);
1203 strcat(propName, "_");
1204 FullClassNameCat(propName, prop.name, true);
1205 // strcat(propName, prop.name);
1207 // To support "char *" property
1208 MangleClassName(getName);
1209 MangleClassName(setName);
1210 MangleClassName(propName);
1212 if(prop._class.type == structClass)
1213 DeclareStruct(prop._class.fullName, false);
1215 if(!symbol || curExternal.symbol.idCode < symbol.id)
1217 bool imported = false;
1218 bool dllImport = false;
1219 if(!symbol || symbol._import)
1224 if(!prop._class.symbol)
1225 prop._class.symbol = FindClass(prop._class.fullName);
1226 classSym = prop._class.symbol;
1227 if(classSym && !classSym._import)
1229 ModuleImport module;
1231 if(prop._class.module)
1232 module = FindModule(prop._class.module);
1234 module = mainModule;
1236 classSym._import = ClassImport
1238 name = CopyString(prop._class.fullName);
1239 isRemote = prop._class.isRemote;
1241 module.classes.Add(classSym._import);
1243 symbol = prop.symbol = Symbol { };
1244 symbol._import = (ClassImport)PropertyImport
1246 name = CopyString(prop.name);
1247 isVirtual = false; //prop.isVirtual;
1248 hasSet = prop.Set ? true : false;
1249 hasGet = prop.Get ? true : false;
1252 classSym._import.properties.Add(symbol._import);
1255 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1261 Context context = SetupTemplatesContext(prop._class);
1262 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1263 FinishTemplatesContext(context);
1269 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1272 OldList * specifiers, * declarators;
1277 Declarator typeDecl;
1278 bool simple = false;
1280 specifiers = MkList();
1281 declarators = MkList();
1284 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1285 MkDeclaratorIdentifier(MkIdentifier("this"))));
1287 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1290 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1293 Context context = SetupTemplatesContext(prop._class);
1294 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1295 FinishTemplatesContext(context);
1298 // Make sure the simple _class's type is declared
1299 for(spec = specifiers->first; spec; spec = spec.next)
1301 if(spec.type == nameSpecifier /*SpecifierClass*/)
1303 if((!typeDecl || typeDecl.type == identifierDeclarator))
1305 Symbol classSym = spec.symbol; // FindClass(spec.name);
1306 symbol._class = classSym.registered;
1307 if(classSym.registered && classSym.registered.type == structClass)
1309 DeclareStruct(spec.name, false);
1317 d = PlugDeclarator(typeDecl, d);
1320 ListAdd(params, MkTypeName(specifiers,
1321 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1322 specifiers = MkList();
1325 d = MkDeclaratorFunction(d, params);
1329 specifiers->Insert(null, MkSpecifier(EXTERN));
1330 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1331 specifiers->Insert(null, MkSpecifier(STATIC));
1333 ListAdd(specifiers, MkSpecifier(VOID));
1335 ListAdd(declarators, MkInitDeclarator(d, null));
1337 decl = MkDeclaration(specifiers, declarators);
1339 external = MkExternalDeclaration(decl);
1340 ast->Insert(curExternal.prev, external);
1341 external.symbol = symbol;
1342 symbol.externalGet = external;
1344 ReplaceThisClassSpecifiers(specifiers, prop._class);
1347 FreeDeclarator(typeDecl);
1351 // Move declaration higher...
1352 ast->Move(symbol.externalGet, curExternal.prev);
1359 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1362 OldList * specifiers, * declarators;
1367 Declarator typeDecl;
1369 declarators = MkList();
1372 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1373 if(!prop.conversion || prop._class.type == structClass)
1375 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1376 MkDeclaratorIdentifier(MkIdentifier("this"))));
1379 specifiers = MkList();
1382 Context context = SetupTemplatesContext(prop._class);
1383 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1384 MkDeclaratorIdentifier(MkIdentifier("value")));
1385 FinishTemplatesContext(context);
1387 ListAdd(params, MkTypeName(specifiers, d));
1389 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1392 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1393 d = MkDeclaratorFunction(d, params);
1395 // Make sure the simple _class's type is declared
1396 for(spec = specifiers->first; spec; spec = spec.next)
1398 if(spec.type == nameSpecifier /*SpecifierClass*/)
1400 if((!typeDecl || typeDecl.type == identifierDeclarator))
1402 Symbol classSym = spec.symbol; // FindClass(spec.name);
1403 symbol._class = classSym.registered;
1404 if(classSym.registered && classSym.registered.type == structClass)
1405 DeclareStruct(spec.name, false);
1410 ListAdd(declarators, MkInitDeclarator(d, null));
1412 specifiers = MkList();
1415 specifiers->Insert(null, MkSpecifier(EXTERN));
1416 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1417 specifiers->Insert(null, MkSpecifier(STATIC));
1419 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1420 if(!prop.conversion || prop._class.type == structClass)
1421 ListAdd(specifiers, MkSpecifier(VOID));
1423 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1425 decl = MkDeclaration(specifiers, declarators);
1427 external = MkExternalDeclaration(decl);
1428 ast->Insert(curExternal.prev, external);
1429 external.symbol = symbol;
1430 symbol.externalSet = external;
1432 ReplaceThisClassSpecifiers(specifiers, prop._class);
1436 // Move declaration higher...
1437 ast->Move(symbol.externalSet, curExternal.prev);
1441 // Property (for Watchers)
1442 if(!symbol.externalPtr)
1446 OldList * specifiers = MkList();
1449 specifiers->Insert(null, MkSpecifier(EXTERN));
1451 specifiers->Insert(null, MkSpecifier(STATIC));
1453 ListAdd(specifiers, MkSpecifierName("Property"));
1456 OldList * list = MkList();
1457 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1458 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1462 strcpy(propName, "__ecerePropM_");
1463 FullClassNameCat(propName, prop._class.fullName, false);
1464 strcat(propName, "_");
1465 // strcat(propName, prop.name);
1466 FullClassNameCat(propName, prop.name, true);
1468 MangleClassName(propName);
1470 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1471 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1473 decl = MkDeclaration(specifiers, list);
1476 external = MkExternalDeclaration(decl);
1477 ast->Insert(curExternal.prev, external);
1478 external.symbol = symbol;
1479 symbol.externalPtr = external;
1483 // Move declaration higher...
1484 ast->Move(symbol.externalPtr, curExternal.prev);
1487 symbol.id = curExternal.symbol.idCode;
1491 // ***************** EXPRESSION PROCESSING ***************************
1492 public Type Dereference(Type source)
1497 if(source.kind == pointerType || source.kind == arrayType)
1500 source.type.refCount++;
1502 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1510 // Support dereferencing of no head classes for now...
1511 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1517 Compiler_Error($"cannot dereference type\n");
1522 static Type Reference(Type source)
1538 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1540 Identifier ident = member.identifiers ? member.identifiers->first : null;
1542 DataMember dataMember = null;
1543 Method method = null;
1544 bool freeType = false;
1546 yylloc = member.loc;
1552 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1556 dataMember = *curMember;
1562 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1563 DataMember _subMemberStack[256];
1564 int _subMemberStackPos = 0;
1566 // FILL MEMBER STACK
1568 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1571 dataMember = thisMember;
1572 if(curMember && thisMember.memberAccess == publicAccess)
1574 *curMember = thisMember;
1575 *curClass = thisMember._class;
1576 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1577 *subMemberStackPos = _subMemberStackPos;
1584 method = eClass_FindMethod(_class, ident.string, privateModule);
1585 if(method && method.type == virtualMethod)
1597 if(!dataMember.dataType && dataMember.dataTypeString)
1599 //Context context = SetupTemplatesContext(dataMember._class);
1600 Context context = SetupTemplatesContext(_class);
1601 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1602 FinishTemplatesContext(context);
1604 type = dataMember.dataType;
1608 // This is for destination type...
1609 if(!method.dataType)
1610 ProcessMethodType(method);
1611 //DeclareMethod(method);
1612 // method.dataType = ((Symbol)method.symbol)->type;
1613 type = method.dataType;
1616 if(ident && ident.next)
1618 for(ident = ident.next; ident && type; ident = ident.next)
1620 if(type.kind == classType)
1622 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1624 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1626 type = dataMember.dataType;
1628 else if(type.kind == structType || type.kind == unionType)
1631 for(memberType = type.members.first; memberType; memberType = memberType.next)
1633 if(!strcmp(memberType.name, ident.string))
1643 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1644 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1647 ClassTemplateParameter curParam = null;
1649 for(sClass = _class; sClass; sClass = sClass.base)
1652 if(sClass.templateClass) sClass = sClass.templateClass;
1653 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1655 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1657 for(sClass = sClass.base; sClass; sClass = sClass.base)
1659 if(sClass.templateClass) sClass = sClass.templateClass;
1660 id += sClass.templateParams.count;
1671 ClassTemplateArgument arg = _class.templateArgs[id];
1672 if(arg.dataTypeString)
1675 type = ProcessTypeString(arg.dataTypeString, false);
1677 if(type && _class.templateClass)
1678 type.passAsTemplate = true;
1684 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1685 exp.destType.refCount++;
1691 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1693 Class expClass = type._class.registered;
1694 Class cClass = null;
1699 char templateString[1024];
1700 ClassTemplateParameter param;
1701 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1702 for(cClass = expClass; cClass; cClass = cClass.base)
1705 if(cClass.templateClass) cClass = cClass.templateClass;
1706 for(param = cClass.templateParams.first; param; param = param.next)
1710 ClassTemplateArgument arg;
1711 for(sClass = cClass.base; sClass; sClass = sClass.base)
1713 if(sClass.templateClass) sClass = sClass.templateClass;
1714 id += sClass.templateParams.count;
1716 arg = expClass.templateArgs[id];
1718 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1720 ClassTemplateParameter cParam;
1721 //int p = numParams - sClass.templateParams.count;
1724 if(sClass.templateClass) sClass = sClass.templateClass;
1726 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1728 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1729 p += nextClass.templateParams.count;
1732 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1734 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1736 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1738 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1739 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1751 strcat(argument, arg.name.string);
1752 strcat(argument, " = ");
1758 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1759 char expString[1024];
1760 OldList * specs = MkList();
1761 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1763 char * string = PrintHexUInt64(arg.expression.ui64);
1764 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1766 ProcessExpressionType(exp);
1767 ComputeExpression(exp);
1768 expString[0] = '\0';
1769 PrintExpression(exp, expString);
1770 strcat(argument, expString);
1772 FreeExpression(exp);
1777 strcat(argument, arg.member.name);
1780 case TemplateParameterType::type:
1782 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1783 strcat(argument, arg.dataTypeString);
1789 if(paramCount) strcat(templateString, ", ");
1790 if(lastParam != p - 1)
1792 strcat(templateString, param.name);
1793 strcat(templateString, " = ");
1795 strcat(templateString, argument);
1804 int len = strlen(templateString);
1805 if(templateString[len-1] == '<')
1809 if(templateString[len-1] == '>')
1810 templateString[len++] = ' ';
1811 templateString[len++] = '>';
1813 templateString[len++] = '\0';
1816 Context context = SetupTemplatesContext(_class);
1817 if(freeType) FreeType(type);
1818 type = ProcessTypeString(templateString, false);
1820 FinishTemplatesContext(context);
1824 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1826 ProcessExpressionType(member.initializer.exp);
1827 if(!member.initializer.exp.expType)
1831 char expString[10240];
1832 expString[0] = '\0';
1833 PrintExpression(member.initializer.exp, expString);
1834 ChangeCh(expString, '\n', ' ');
1835 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1838 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1839 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1841 Compiler_Error($"incompatible instance method %s\n", ident.string);
1844 else if(member.initializer)
1847 FreeType(member.exp.destType);
1848 member.exp.destType = type;
1849 if(member.exp.destType)
1850 member.exp.destType.refCount++;
1851 ProcessExpressionType(member.exp);
1854 ProcessInitializer(member.initializer, type);
1856 if(freeType) FreeType(type);
1860 if(_class && _class.type == unitClass)
1862 if(member.initializer)
1865 FreeType(member.exp.destType);
1866 member.exp.destType = MkClassType(_class.fullName);
1867 ProcessExpressionType(member.initializer, type);
1869 Type type = MkClassType(_class.fullName);
1870 ProcessInitializer(member.initializer, type);
1876 if(member.initializer)
1878 //ProcessExpressionType(member.exp);
1879 ProcessInitializer(member.initializer, null);
1885 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1889 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1891 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1895 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1900 void ProcessInstantiationType(Instantiation inst)
1905 MembersInit members;
1906 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1909 /*if(!inst._class.symbol)
1910 inst._class.symbol = FindClass(inst._class.name);*/
1911 classSym = inst._class.symbol;
1912 _class = classSym ? classSym.registered : null;
1914 // DANGER: Patch for mutex not declaring its struct when not needed
1915 if(!_class || _class.type != noHeadClass)
1916 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1918 afterExternal = afterExternal ? afterExternal : curExternal;
1921 ProcessExpressionType(inst.exp);
1923 inst.isConstant = true;
1926 DataMember curMember = null;
1927 Class curClass = null;
1928 DataMember subMemberStack[256];
1929 int subMemberStackPos = 0;
1931 for(members = inst.members->first; members; members = members.next)
1933 switch(members.type)
1935 case methodMembersInit:
1938 static uint instMethodID = 0;
1939 External external = curExternal;
1940 Context context = curContext;
1941 Declarator declarator = members.function.declarator;
1942 Identifier nameID = GetDeclId(declarator);
1943 char * unmangled = nameID ? nameID.string : null;
1945 External createdExternal = null;
1950 //members.function.dontMangle = true;
1951 strcpy(name, "__ecereInstMeth_");
1952 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
1954 strcat(name, nameID.string);
1956 sprintf(number, "_%08d", instMethodID++);
1957 strcat(name, number);
1958 nameID.string = CopyString(name);
1961 // Do modifications here...
1964 Symbol symbol = declarator.symbol;
1965 Method method = eClass_FindMethod(_class, unmangled, privateModule);
1967 if(method && method.type == virtualMethod)
1969 symbol.method = method;
1970 ProcessMethodType(method);
1972 if(!symbol.type.thisClass)
1974 if(method.dataType.thisClass && currentClass &&
1975 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
1977 if(!currentClass.symbol)
1978 currentClass.symbol = FindClass(currentClass.fullName);
1979 symbol.type.thisClass = currentClass.symbol;
1984 _class.symbol = FindClass(_class.fullName);
1985 symbol.type.thisClass = _class.symbol;
1988 // TESTING THIS HERE:
1989 DeclareType(symbol.type, true, true);
1994 Compiler_Error($"couldn't find virtual method %s in class %s\n",
1995 unmangled, classSym.string);
1999 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2000 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2004 FreeSpecifier(nameID._class);
2005 nameID._class = null;
2011 Type type = declarator.symbol.type;
2012 External oldExternal = curExternal;
2014 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2015 // *** It was commented out for problems such as
2017 class VirtualDesktop : Window
2019 clientSize = Size { };
2030 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2032 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2035 if(strcmp(declarator.symbol.string, name))
2037 printf("TOCHECK: Look out for this\n");
2038 delete declarator.symbol.string;
2039 declarator.symbol.string = CopyString(name);
2042 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2044 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2045 excludedSymbols->Remove(declarator.symbol);
2046 globalContext.symbols.Add((BTNode)declarator.symbol);
2047 if(strstr(declarator.symbol.string), "::")
2048 globalContext.hasNameSpace = true;
2053 //curExternal = curExternal.prev;
2054 //afterExternal = afterExternal->next;
2056 //ProcessFunction(afterExternal->function);
2058 //curExternal = afterExternal;
2060 External externalDecl;
2061 externalDecl = MkExternalDeclaration(null);
2062 ast->Insert(oldExternal.prev, externalDecl);
2064 // Which function does this process?
2065 if(createdExternal.function)
2067 ProcessFunction(createdExternal.function);
2069 //curExternal = oldExternal;
2072 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2074 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2075 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2077 //externalDecl = MkExternalDeclaration(decl);
2079 //***** ast->Insert(external.prev, externalDecl);
2080 //ast->Insert(curExternal.prev, externalDecl);
2081 externalDecl.declaration = decl;
2082 if(decl.symbol && !decl.symbol.pointerExternal)
2083 decl.symbol.pointerExternal = externalDecl;
2085 // Trying this out...
2086 declarator.symbol.pointerExternal = externalDecl;
2093 curExternal = declarator.symbol.pointerExternal;
2094 ProcessFunction((FunctionDefinition)members.function);
2096 curExternal = external;
2097 curContext = context;
2101 FreeClassFunction(members.function);
2103 // In this pass, turn this into a MemberInitData
2104 exp = QMkExpId(name);
2105 members.type = dataMembersInit;
2106 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2112 case dataMembersInit:
2114 if(members.dataMembers && classSym)
2117 Location oldyyloc = yylloc;
2118 for(member = members.dataMembers->first; member; member = member.next)
2120 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2121 if(member.initializer && !member.initializer.isConstant)
2122 inst.isConstant = false;
2134 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2136 // OPTIMIZATIONS: TESTING THIS...
2139 if(type.kind == functionType)
2144 for(param = type.params.first; param; param = param.next)
2145 DeclareType(param, declarePointers, true);
2147 DeclareType(type.returnType, declarePointers, true);
2149 else if(type.kind == pointerType && declarePointers)
2150 DeclareType(type.type, declarePointers, false);
2151 else if(type.kind == classType)
2153 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2154 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2156 else if(type.kind == structType || type.kind == unionType)
2159 for(member = type.members.first; member; member = member.next)
2160 DeclareType(member, false, false);
2162 else if(type.kind == arrayType)
2163 DeclareType(type.arrayType, declarePointers, false);
2167 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2169 ClassTemplateArgument * arg = null;
2171 ClassTemplateParameter curParam = null;
2173 for(sClass = _class; sClass; sClass = sClass.base)
2176 if(sClass.templateClass) sClass = sClass.templateClass;
2177 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2179 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2181 for(sClass = sClass.base; sClass; sClass = sClass.base)
2183 if(sClass.templateClass) sClass = sClass.templateClass;
2184 id += sClass.templateParams.count;
2194 arg = &_class.templateArgs[id];
2195 if(arg && param.type == type)
2196 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2201 public Context SetupTemplatesContext(Class _class)
2203 Context context = PushContext();
2204 context.templateTypesOnly = true;
2205 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2207 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2208 for(; param; param = param.next)
2210 if(param.type == type && param.identifier)
2212 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2213 curContext.templateTypes.Add((BTNode)type);
2220 for(sClass = _class; sClass; sClass = sClass.base)
2222 ClassTemplateParameter p;
2223 for(p = sClass.templateParams.first; p; p = p.next)
2225 //OldList * specs = MkList();
2226 //Declarator decl = null;
2227 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2230 TemplateParameter param = p.param;
2234 // ADD DATA TYPE HERE...
2235 p.param = param = TemplateParameter
2237 identifier = MkIdentifier(p.name), type = p.type,
2238 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2241 type = TemplatedType { key = (uintptr)p.name, param = param };
2242 curContext.templateTypes.Add((BTNode)type);
2250 public void FinishTemplatesContext(Context context)
2252 PopContext(context);
2253 FreeContext(context);
2257 public void ProcessMethodType(Method method)
2259 if(!method.dataType)
2261 Context context = SetupTemplatesContext(method._class);
2263 method.dataType = ProcessTypeString(method.dataTypeString, false);
2265 FinishTemplatesContext(context);
2267 if(method.type != virtualMethod && method.dataType)
2269 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2271 if(!method._class.symbol)
2272 method._class.symbol = FindClass(method._class.fullName);
2273 method.dataType.thisClass = method._class.symbol;
2277 // Why was this commented out? Working fine without now...
2280 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2281 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2288 char * par = strstr(type, "(");
2289 char * classOp = null;
2294 for(c = par-type-1; c >= 0; c++)
2296 if(type[c] == ':' && type[c+1] == ':')
2298 classOp = type + c - 1;
2299 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2306 else if(!isspace(type[c]))
2313 int typeLen = strlen(type);
2314 memcpy(temp, classOp, classOpLen);
2315 temp[classOpLen] = '\0';
2317 _class = eSystem_FindClass(module, temp);
2320 method.dataTypeString = new char[typeLen - classOpLen + 1];
2321 memcpy(method.dataTypeString, type, classOp - type);
2322 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2325 method.dataTypeString = type;
2331 public void ProcessPropertyType(Property prop)
2335 Context context = SetupTemplatesContext(prop._class);
2336 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2337 FinishTemplatesContext(context);
2341 public void DeclareMethod(Method method, char * name)
2343 Symbol symbol = method.symbol;
2344 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2346 bool imported = false;
2347 bool dllImport = false;
2349 if(!method.dataType)
2350 method.dataType = ProcessTypeString(method.dataTypeString, false);
2352 if(!symbol || symbol._import || method.type == virtualMethod)
2354 if(!symbol || method.type == virtualMethod)
2357 if(!method._class.symbol)
2358 method._class.symbol = FindClass(method._class.fullName);
2359 classSym = method._class.symbol;
2360 if(!classSym._import)
2362 ModuleImport module;
2364 if(method._class.module && method._class.module.name)
2365 module = FindModule(method._class.module);
2367 module = mainModule;
2368 classSym._import = ClassImport
2370 name = CopyString(method._class.fullName);
2371 isRemote = method._class.isRemote;
2373 module.classes.Add(classSym._import);
2377 symbol = method.symbol = Symbol { };
2381 symbol._import = (ClassImport)MethodImport
2383 name = CopyString(method.name);
2384 isVirtual = method.type == virtualMethod;
2386 classSym._import.methods.Add(symbol._import);
2390 // Set the symbol type
2394 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2396 else if(type.thisClass == (void *)-1)
2398 type.thisClass = null;
2401 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2402 symbol.type = method.dataType;
2403 if(symbol.type) symbol.type.refCount++;
2406 if(!method.thisClass || strcmp(method.thisClass, "void"))
2407 symbol.type.params.Insert(null,
2408 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2411 if(!method.dataType.dllExport)
2414 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2420 if(!method.dataType)
2421 method.dataType = ((Symbol)method.symbol).type;
2422 //ProcessMethodType(method);
2425 if(method.type != virtualMethod && method.dataType)
2426 DeclareType(method.dataType, true, true);
2428 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2430 // We need a declaration here :)
2432 OldList * specifiers, * declarators;
2434 Declarator funcDecl;
2437 specifiers = MkList();
2438 declarators = MkList();
2442 ListAdd(specifiers, MkSpecifier(EXTERN));
2443 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2444 ListAdd(specifiers, MkSpecifier(STATIC));
2446 if(method.type == virtualMethod)
2448 ListAdd(specifiers, MkSpecifier(INT));
2449 d = MkDeclaratorIdentifier(MkIdentifier(name));
2453 d = MkDeclaratorIdentifier(MkIdentifier(name));
2456 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2458 Context context = SetupTemplatesContext(method._class);
2459 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2460 FinishTemplatesContext(context);
2462 funcDecl = GetFuncDecl(d);
2466 Specifier spec, next;
2467 for(spec = specifiers->first; spec; spec = next)
2470 if(spec.type == extendedSpecifier)
2472 specifiers->Remove(spec);
2473 FreeSpecifier(spec);
2478 // Add this parameter if not a static method
2479 if(method.dataType && !method.dataType.staticMethod)
2481 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2483 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2484 TypeName thisParam = MkTypeName(MkListOne(
2485 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2486 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2487 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2488 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2490 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2492 TypeName param = funcDecl.function.parameters->first;
2493 funcDecl.function.parameters->Remove(param);
2494 FreeTypeName(param);
2497 if(!funcDecl.function.parameters)
2498 funcDecl.function.parameters = MkList();
2499 funcDecl.function.parameters->Insert(null, thisParam);
2502 // Make sure we don't have empty parameter declarations for static methods...
2504 else if(!funcDecl.function.parameters)
2506 funcDecl.function.parameters = MkList();
2507 funcDecl.function.parameters->Insert(null,
2508 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2512 ProcessDeclarator(d);
2514 ListAdd(declarators, MkInitDeclarator(d, null));
2516 decl = MkDeclaration(specifiers, declarators);
2518 ReplaceThisClassSpecifiers(specifiers, method._class);
2520 // Keep a different symbol for the function definition than the declaration...
2521 if(symbol.pointerExternal)
2523 Symbol functionSymbol { };
2527 *functionSymbol = *symbol;
2528 functionSymbol.string = CopyString(symbol.string);
2529 if(functionSymbol.type)
2530 functionSymbol.type.refCount++;
2533 excludedSymbols->Add(functionSymbol);
2534 symbol.pointerExternal.symbol = functionSymbol;
2536 external = MkExternalDeclaration(decl);
2538 ast->Insert(curExternal ? curExternal.prev : null, external);
2539 external.symbol = symbol;
2540 symbol.pointerExternal = external;
2544 // Move declaration higher...
2545 ast->Move(symbol.pointerExternal, curExternal.prev);
2548 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2552 char * ReplaceThisClass(Class _class)
2554 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2558 ClassTemplateParameter param;
2561 char className[1024];
2562 strcpy(className, _class.fullName);
2563 for(param = _class.templateParams.first; param; param = param.next)
2565 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2567 if(first) strcat(className, "<");
2568 if(!first) strcat(className, ", ");
2569 if(lastParam + 1 != p)
2571 strcat(className, param.name);
2572 strcat(className, " = ");
2574 strcat(className, param.name);
2582 int len = strlen(className);
2583 if(className[len-1] == '>') className[len++] = ' ';
2584 className[len++] = '>';
2585 className[len++] = '\0';
2587 return CopyString(className);
2590 return CopyString(_class.fullName);
2593 Type ReplaceThisClassType(Class _class)
2595 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2599 ClassTemplateParameter param;
2601 char className[1024];
2602 strcpy(className, _class.fullName);
2604 for(param = _class.templateParams.first; param; param = param.next)
2606 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2608 if(first) strcat(className, "<");
2609 if(!first) strcat(className, ", ");
2610 if(lastParam + 1 != p)
2612 strcat(className, param.name);
2613 strcat(className, " = ");
2615 strcat(className, param.name);
2623 int len = strlen(className);
2624 if(className[len-1] == '>') className[len++] = ' ';
2625 className[len++] = '>';
2626 className[len++] = '\0';
2628 return MkClassType(className);
2629 //return ProcessTypeString(className, false);
2633 return MkClassType(_class.fullName);
2634 //return ProcessTypeString(_class.fullName, false);
2638 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2640 if(specs != null && _class)
2643 for(spec = specs.first; spec; spec = spec.next)
2645 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2647 spec.type = nameSpecifier;
2648 spec.name = ReplaceThisClass(_class);
2649 spec.symbol = FindClass(spec.name); //_class.symbol;
2655 // Returns imported or not
2656 bool DeclareFunction(GlobalFunction function, char * name)
2658 Symbol symbol = function.symbol;
2659 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2661 bool imported = false;
2662 bool dllImport = false;
2664 if(!function.dataType)
2666 function.dataType = ProcessTypeString(function.dataTypeString, false);
2667 if(!function.dataType.thisClass)
2668 function.dataType.staticMethod = true;
2675 ModuleImport module = FindModule(function.module);
2676 // WARNING: This is not added anywhere...
2677 symbol = function.symbol = Symbol { };
2681 if(!function.dataType.dllExport)
2683 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2684 module.functions.Add(symbol._import);
2687 // Set the symbol type
2689 symbol.type = ProcessTypeString(function.dataTypeString, false);
2690 if(!symbol.type.thisClass)
2691 symbol.type.staticMethod = true;
2694 imported = symbol._import ? true : false;
2695 if(imported && function.module != privateModule && function.module.importType != staticImport)
2699 DeclareType(function.dataType, true, true);
2703 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2705 // We need a declaration here :)
2707 OldList * specifiers, * declarators;
2709 Declarator funcDecl;
2712 specifiers = MkList();
2713 declarators = MkList();
2716 ListAdd(specifiers, MkSpecifier(EXTERN));
2719 ListAdd(specifiers, MkSpecifier(STATIC));
2722 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2725 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2727 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2728 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2729 if(function.module.importType == staticImport)
2732 for(spec = specifiers->first; spec; spec = spec.next)
2733 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2735 specifiers->Remove(spec);
2736 FreeSpecifier(spec);
2741 funcDecl = GetFuncDecl(d);
2743 // Make sure we don't have empty parameter declarations for static methods...
2744 if(funcDecl && !funcDecl.function.parameters)
2746 funcDecl.function.parameters = MkList();
2747 funcDecl.function.parameters->Insert(null,
2748 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2751 ListAdd(declarators, MkInitDeclarator(d, null));
2754 Context oldCtx = curContext;
2755 curContext = globalContext;
2756 decl = MkDeclaration(specifiers, declarators);
2757 curContext = oldCtx;
2760 // Keep a different symbol for the function definition than the declaration...
2761 if(symbol.pointerExternal)
2763 Symbol functionSymbol { };
2766 *functionSymbol = *symbol;
2767 functionSymbol.string = CopyString(symbol.string);
2768 if(functionSymbol.type)
2769 functionSymbol.type.refCount++;
2772 excludedSymbols->Add(functionSymbol);
2774 symbol.pointerExternal.symbol = functionSymbol;
2776 external = MkExternalDeclaration(decl);
2778 ast->Insert(curExternal.prev, external);
2779 external.symbol = symbol;
2780 symbol.pointerExternal = external;
2784 // Move declaration higher...
2785 ast->Move(symbol.pointerExternal, curExternal.prev);
2789 symbol.id = curExternal.symbol.idCode;
2792 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2795 void DeclareGlobalData(GlobalData data)
2797 Symbol symbol = data.symbol;
2798 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2803 symbol = data.symbol = Symbol { };
2806 data.dataType = ProcessTypeString(data.dataTypeString, false);
2807 DeclareType(data.dataType, true, true);
2810 if(!symbol.pointerExternal)
2812 // We need a declaration here :)
2814 OldList * specifiers, * declarators;
2818 specifiers = MkList();
2819 declarators = MkList();
2821 ListAdd(specifiers, MkSpecifier(EXTERN));
2822 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2823 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2825 ListAdd(declarators, MkInitDeclarator(d, null));
2827 decl = MkDeclaration(specifiers, declarators);
2828 external = MkExternalDeclaration(decl);
2830 ast->Insert(curExternal.prev, external);
2831 external.symbol = symbol;
2832 symbol.pointerExternal = external;
2836 // Move declaration higher...
2837 ast->Move(symbol.pointerExternal, curExternal.prev);
2841 symbol.id = curExternal.symbol.idCode;
2846 class Conversion : struct
2848 Conversion prev, next;
2854 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2858 // Property convert;
2860 if(source.kind == templateType && dest.kind != templateType)
2862 Type type = ProcessTemplateParameterType(source.templateParameter);
2863 if(type) source = type;
2866 if(dest.kind == templateType && source.kind != templateType)
2868 Type type = ProcessTemplateParameterType(dest.templateParameter);
2869 if(type) dest = type;
2872 if(dest.classObjectType == typedObject)
2874 if(source.classObjectType != anyObject)
2878 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2879 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2887 if(source.classObjectType == anyObject)
2889 if(dest.classObjectType == anyObject && source.classObjectType != typedObject)
2893 if((dest.kind == structType && source.kind == structType) ||
2894 (dest.kind == unionType && source.kind == unionType))
2896 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2897 (source.members.first && source.members.first == dest.members.first))
2901 if(dest.kind == ellipsisType && source.kind != voidType)
2904 if(dest.kind == pointerType && dest.type.kind == voidType &&
2905 ((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))
2906 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2908 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2910 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2912 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2913 ((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))
2914 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2916 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2918 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2921 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2923 if(source._class.registered && source._class.registered.type == unitClass)
2925 if(conversions != null)
2927 if(source._class.registered == dest._class.registered)
2932 Class sourceBase, destBase;
2933 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2934 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2935 if(sourceBase == destBase)
2939 // Don't match enum inheriting from other enum if resolving enumeration values
2940 // TESTING: !dest.classObjectType
2941 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2943 (!source._class.registered || source._class.registered.type != enumClass) ||
2944 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2948 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2950 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2951 ((source._class && source._class.registered && source._class.registered.type != enumClass) || source.kind == classType)) // Added this here for a base enum to be acceptable for a derived enum (#139)
2953 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2961 // JUST ADDED THIS...
2962 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2967 // Just added this for Straight conversion of ColorAlpha => Color
2968 if(source.kind == classType)
2971 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2974 for(convert = _class.conversions.first; convert; convert = convert.next)
2976 if(convert.memberAccess == publicAccess || _class.module == privateModule)
2978 Conversion after = (conversions != null) ? conversions.last : null;
2980 if(!convert.dataType)
2981 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
2982 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
2984 if(!conversions && !convert.Get)
2986 else if(conversions != null)
2988 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
2989 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
2990 (dest.kind != classType || dest._class.registered != _class.base))
2994 Conversion conv { convert = convert, isGet = true };
2995 // conversions.Add(conv);
2996 conversions.Insert(after, conv);
3008 if(dest.kind == classType)
3011 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3014 for(convert = _class.conversions.first; convert; convert = convert.next)
3016 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3018 // Conversion after = (conversions != null) ? conversions.last : null;
3020 if(!convert.dataType)
3021 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3022 // Just added this equality check to prevent recursion.... Make it safer?
3023 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3024 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3026 if(!conversions && !convert.Set)
3028 else if(conversions != null)
3030 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3031 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3032 (source.kind != classType || source._class.registered != _class.base))
3036 // *** Testing this! ***
3037 Conversion conv { convert = convert };
3038 conversions.Add(conv);
3039 //conversions.Insert(after, conv);
3047 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3049 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3050 (source.kind != classType || source._class.registered.type != structClass))
3054 // TESTING THIS... IS THIS OK??
3055 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3057 if(!dest._class.registered.dataType)
3058 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3059 // Only support this for classes...
3060 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3061 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3063 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3072 if(source.kind == classType)
3075 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3078 for(convert = _class.conversions.first; convert; convert = convert.next)
3080 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3082 Conversion after = (conversions != null) ? conversions.last : null;
3084 if(!convert.dataType)
3085 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3086 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3088 if(!conversions && !convert.Get)
3090 else if(conversions != null)
3092 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3093 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3094 (dest.kind != classType || dest._class.registered != _class.base))
3098 Conversion conv { convert = convert, isGet = true };
3100 // conversions.Add(conv);
3101 conversions.Insert(after, conv);
3110 // TESTING THIS... IS THIS OK??
3111 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3113 if(!source._class.registered.dataType)
3114 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3115 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3123 if(source.kind == classType || source.kind == subClassType)
3125 else if(dest.kind == source.kind &&
3126 (dest.kind != structType && dest.kind != unionType &&
3127 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3129 // RECENTLY ADDED THESE
3130 else if(dest.kind == doubleType && source.kind == floatType)
3132 else if(dest.kind == shortType && source.kind == charType)
3134 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == intSizeType /* Exception here for size_t */))
3136 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3138 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3140 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3142 else if(source.kind == enumType &&
3143 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3145 else if(dest.kind == enumType &&
3146 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3148 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3149 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3151 Type paramSource, paramDest;
3153 if(dest.kind == methodType)
3154 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3155 if(source.kind == methodType)
3156 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3158 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3159 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3160 if(dest.kind == methodType)
3161 dest = dest.method.dataType;
3162 if(source.kind == methodType)
3163 source = source.method.dataType;
3165 paramSource = source.params.first;
3166 if(paramSource && paramSource.kind == voidType) paramSource = null;
3167 paramDest = dest.params.first;
3168 if(paramDest && paramDest.kind == voidType) paramDest = null;
3171 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3172 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3174 // Source thisClass must be derived from destination thisClass
3175 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3176 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3178 if(paramDest && paramDest.kind == classType)
3179 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3181 Compiler_Error($"method class should not take an object\n");
3184 paramDest = paramDest.next;
3186 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3188 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3192 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3194 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3200 // THIS WAS BACKWARDS:
3201 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3202 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3205 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3207 Compiler_Error($"overriding class expected to be derived from method class\n");
3211 paramSource = paramSource.next;
3217 // Source thisClass must be derived from destination thisClass
3218 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3220 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3226 // THIS WAS BACKWARDS TOO??
3227 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3228 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3231 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3233 //Compiler_Error($"overriding class expected to be derived from method class\n");
3241 // Source return type must be derived from destination return type
3242 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3244 Compiler_Warning($"incompatible return type for function\n");
3250 for(; paramDest; paramDest = paramDest.next)
3254 //Compiler_Warning($"not enough parameters\n");
3255 Compiler_Error($"not enough parameters\n");
3259 Type paramDestType = paramDest;
3260 Type paramSourceType = paramSource;
3261 Type type = paramDestType;
3263 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3264 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3265 paramSource.kind != templateType)
3268 ClassTemplateParameter curParam = null;
3270 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3273 if(sClass.templateClass) sClass = sClass.templateClass;
3274 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3276 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3278 for(sClass = sClass.base; sClass; sClass = sClass.base)
3280 if(sClass.templateClass) sClass = sClass.templateClass;
3281 id += sClass.templateParams.count;
3292 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3293 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3297 // paramDest must be derived from paramSource
3298 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3299 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3303 PrintType(paramDest, type, false, true);
3304 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3306 if(paramDestType != paramDest)
3307 FreeType(paramDestType);
3310 if(paramDestType != paramDest)
3311 FreeType(paramDestType);
3314 paramSource = paramSource.next;
3318 Compiler_Error($"too many parameters\n");
3323 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3327 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3328 (source.kind == arrayType || source.kind == pointerType))
3330 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3337 static void FreeConvert(Conversion convert)
3339 if(convert.resultType)
3340 FreeType(convert.resultType);
3343 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3344 char * string, OldList conversions)
3348 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3350 Class _class = link.data;
3351 if(_class.type == enumClass)
3353 OldList converts { };
3355 type.kind = classType;
3358 _class.symbol = FindClass(_class.fullName);
3359 type._class = _class.symbol;
3361 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3364 Class enumClass = eSystem_FindClass(privateModule, "enum");
3368 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3370 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3371 for(value = e.values.first; value; value = value.next)
3373 if(!strcmp(value.name, string))
3378 FreeExpContents(sourceExp);
3379 FreeType(sourceExp.expType);
3381 sourceExp.isConstant = true;
3382 sourceExp.expType = MkClassType(baseClass.fullName);
3386 sourceExp.type = constantExp;
3387 if(!strcmp(baseClass.dataTypeString, "int"))
3388 sprintf(constant, "%d",(int)value.data);
3390 sprintf(constant, "0x%X",(int)value.data);
3391 sourceExp.constant = CopyString(constant);
3392 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3395 while(converts.first)
3397 Conversion convert = converts.first;
3398 converts.Remove(convert);
3399 conversions.Add(convert);
3408 converts.Free(FreeConvert);
3412 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3413 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3418 public bool ModuleVisibility(Module searchIn, Module searchFor)
3420 SubModule subModule;
3422 if(searchFor == searchIn)
3425 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3427 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3429 if(ModuleVisibility(subModule.module, searchFor))
3436 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3440 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3442 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3444 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3447 for(module = mainModule.application.allModules.first; module; module = module.next)
3449 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3455 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3457 Type source = sourceExp.expType;
3458 Type realDest = dest;
3459 Type backupSourceExpType = null;
3461 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3464 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3466 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3468 Class sourceBase, destBase;
3469 for(sourceBase = source._class.registered;
3470 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3471 sourceBase = sourceBase.base);
3472 for(destBase = dest._class.registered;
3473 destBase && destBase.base && destBase.base.type != systemClass;
3474 destBase = destBase.base);
3475 //if(source._class.registered == dest._class.registered)
3476 if(sourceBase == destBase)
3485 int64 value = MAXINT;
3490 if(sourceExp.type == constantExp)
3493 value = strtoll(sourceExp.constant, null, 0);
3495 value = strtoull(sourceExp.constant, null, 0);
3497 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3500 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3502 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3505 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3506 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3509 source = Type { kind = intType, isSigned = false, refCount = 1 };
3512 if(dest.kind == classType)
3514 Class _class = dest._class ? dest._class.registered : null;
3516 if(_class && _class.type == unitClass)
3518 if(source.kind != classType)
3521 Type tempDest, tempSource;
3523 for(; _class.base.type != systemClass; _class = _class.base);
3525 tempDest = tempType;
3527 tempType.kind = classType;
3529 _class.symbol = FindClass(_class.fullName);
3531 tempType._class = _class.symbol;
3532 tempType.truth = dest.truth;
3534 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3536 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3537 backupSourceExpType = sourceExp.expType;
3538 sourceExp.expType = dest; dest.refCount++;
3539 //sourceExp.expType = MkClassType(_class.fullName);
3547 // Why wasn't there something like this?
3548 if(_class && _class.type == bitClass && source.kind != classType)
3550 if(!dest._class.registered.dataType)
3551 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3552 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3555 FreeType(sourceExp.expType);
3556 source = sourceExp.expType = MkClassType(dest._class.string);
3559 //source.kind = classType;
3560 //source._class = dest._class;
3564 // Adding two enumerations
3566 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3568 if(!source._class.registered.dataType)
3569 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3570 if(!dest._class.registered.dataType)
3571 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3573 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3576 source = sourceExp.expType = MkClassType(dest._class.string);
3579 //source.kind = classType;
3580 //source._class = dest._class;
3584 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3586 OldList * specs = MkList();
3590 ReadString(string, sourceExp.string);
3591 decl = SpecDeclFromString(string, specs, null);
3593 FreeExpContents(sourceExp);
3594 FreeType(sourceExp.expType);
3596 sourceExp.type = classExp;
3597 sourceExp._classExp.specifiers = specs;
3598 sourceExp._classExp.decl = decl;
3599 sourceExp.expType = dest;
3604 if(backupSourceExpType) FreeType(backupSourceExpType);
3608 else if(source.kind == classType)
3610 Class _class = source._class ? source._class.registered : null;
3612 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3615 if(dest.kind != classType)
3617 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3618 if(!source._class.registered.dataType)
3619 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3622 dest = MkClassType(source._class.string);
3623 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3624 // dest = MkClassType(source._class.string);
3628 if(dest.kind != classType)
3631 Type tempDest, tempSource;
3633 if(!source._class.registered.dataType)
3634 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3636 for(; _class.base.type != systemClass; _class = _class.base);
3638 tempSource = tempType;
3639 tempType.kind = classType;
3640 tempType._class = FindClass(_class.fullName);
3641 tempType.truth = source.truth;
3642 tempType.classObjectType = source.classObjectType;
3645 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3647 // PUT THIS BACK TESTING UNITS?
3648 if(conversions.last)
3650 ((Conversion)(conversions.last)).resultType = dest;
3654 FreeType(sourceExp.expType);
3655 sourceExp.expType = MkClassType(_class.fullName);
3656 sourceExp.expType.truth = source.truth;
3657 sourceExp.expType.classObjectType = source.classObjectType;
3659 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3661 if(!sourceExp.destType)
3663 FreeType(sourceExp.destType);
3664 sourceExp.destType = sourceExp.expType;
3665 if(sourceExp.expType)
3666 sourceExp.expType.refCount++;
3669 //source = _class.dataType;
3672 // TOCHECK: TESTING THIS NEW CODE
3673 if(!_class.dataType)
3674 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3676 dest = MkClassType(source._class.string);
3677 dest.truth = source.truth;
3678 dest.classObjectType = source.classObjectType;
3681 source = _class.dataType;
3691 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3701 if(source.kind == classType)
3703 Class _class = source._class.registered;
3704 if(_class.type == unitClass)
3706 if(!_class.dataType)
3707 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3708 source = _class.dataType;
3712 if(dest.kind == classType)
3714 Class _class = dest._class ? dest._class.registered : null;
3715 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3716 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3718 if(_class.type == normalClass || _class.type == noHeadClass)
3720 Expression newExp { };
3721 *newExp = *sourceExp;
3722 if(sourceExp.destType) sourceExp.destType.refCount++;
3723 if(sourceExp.expType) sourceExp.expType.refCount++;
3724 sourceExp.type = castExp;
3725 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3726 sourceExp.cast.exp = newExp;
3727 FreeType(sourceExp.expType);
3728 sourceExp.expType = null;
3729 ProcessExpressionType(sourceExp);
3731 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3734 FreeType(sourceExp.expType);
3735 sourceExp.expType = dest;
3739 if(inCompiler) FreeType(dest);
3741 if(backupSourceExpType) FreeType(backupSourceExpType);
3745 if(!_class.dataType)
3746 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3748 dest = _class.dataType;
3752 // Accept lower precision types for units, since we want to keep the unit type
3753 if(dest.kind == doubleType &&
3754 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3755 source.kind == charType))
3757 specs = MkListOne(MkSpecifier(DOUBLE));
3759 else if(dest.kind == floatType &&
3760 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3761 source.kind == doubleType))
3763 specs = MkListOne(MkSpecifier(FLOAT));
3765 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3766 source.kind == floatType || source.kind == doubleType))
3769 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3770 ListAdd(specs, MkSpecifier(INT64));
3772 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3773 source.kind == floatType || source.kind == doubleType))
3776 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3777 ListAdd(specs, MkSpecifier(INT));
3779 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
3780 source.kind == floatType || source.kind == doubleType))
3783 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3784 ListAdd(specs, MkSpecifier(SHORT));
3786 else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
3787 source.kind == floatType || source.kind == doubleType))
3790 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3791 ListAdd(specs, MkSpecifier(CHAR));
3797 if(backupSourceExpType)
3799 // Failed to convert: revert previous exp type
3800 if(sourceExp.expType) FreeType(sourceExp.expType);
3801 sourceExp.expType = backupSourceExpType;
3806 else if(dest.kind == doubleType &&
3807 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3808 source.kind == charType))
3810 specs = MkListOne(MkSpecifier(DOUBLE));
3812 else if(dest.kind == floatType &&
3813 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3815 specs = MkListOne(MkSpecifier(FLOAT));
3817 else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3818 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3821 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3822 ListAdd(specs, MkSpecifier(CHAR));
3824 else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
3825 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3828 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3829 ListAdd(specs, MkSpecifier(SHORT));
3831 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
3834 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3835 ListAdd(specs, MkSpecifier(INT));
3837 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3840 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3841 ListAdd(specs, MkSpecifier(INT64));
3843 else if(dest.kind == enumType &&
3844 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3846 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3852 if(backupSourceExpType)
3854 // Failed to convert: revert previous exp type
3855 if(sourceExp.expType) FreeType(sourceExp.expType);
3856 sourceExp.expType = backupSourceExpType;
3863 Expression newExp { };
3864 *newExp = *sourceExp;
3867 if(sourceExp.destType) sourceExp.destType.refCount++;
3868 if(sourceExp.expType) sourceExp.expType.refCount++;
3870 sourceExp.type = castExp;
3871 if(realDest.kind == classType)
3873 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3874 FreeList(specs, FreeSpecifier);
3877 sourceExp.cast.typeName = MkTypeName(specs, null);
3878 if(newExp.type == opExp)
3880 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3883 sourceExp.cast.exp = newExp;
3885 FreeType(sourceExp.expType);
3886 sourceExp.expType = null;
3887 ProcessExpressionType(sourceExp);
3890 FreeList(specs, FreeSpecifier);
3894 if(backupSourceExpType) FreeType(backupSourceExpType);
3900 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3901 if(sourceExp.type == identifierExp)
3903 Identifier id = sourceExp.identifier;
3904 if(dest.kind == classType)
3906 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3908 Class _class = dest._class.registered;
3909 Class enumClass = eSystem_FindClass(privateModule, "enum");
3912 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3915 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3916 for(value = e.values.first; value; value = value.next)
3918 if(!strcmp(value.name, id.string))
3923 FreeExpContents(sourceExp);
3924 FreeType(sourceExp.expType);
3926 sourceExp.isConstant = true;
3927 sourceExp.expType = MkClassType(_class.fullName);
3931 sourceExp.type = constantExp;
3932 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3933 sprintf(constant, "%d", (int) value.data);
3935 sprintf(constant, "0x%X", (int) value.data);
3936 sourceExp.constant = CopyString(constant);
3937 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3946 // Loop through all enum classes
3947 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3954 #define TERTIARY(o, name, m, t, p) \
3955 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3957 exp.type = constantExp; \
3958 exp.string = p(op1.m ? op2.m : op3.m); \
3960 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3964 #define BINARY(o, name, m, t, p) \
3965 static bool name(Expression exp, Operand op1, Operand op2) \
3968 exp.type = constantExp; \
3969 exp.string = p(op1.m o value2); \
3971 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3975 #define BINARY_DIVIDE(o, name, m, t, p) \
3976 static bool name(Expression exp, Operand op1, Operand op2) \
3979 exp.type = constantExp; \
3980 exp.string = p(value2 ? (op1.m o value2) : 0); \
3982 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3986 #define UNARY(o, name, m, t, p) \
3987 static bool name(Expression exp, Operand op1) \
3989 exp.type = constantExp; \
3990 exp.string = p((t)(o op1.m)); \
3992 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3996 #define OPERATOR_ALL(macro, o, name) \
3997 macro(o, Int##name, i, int, PrintInt) \
3998 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
3999 macro(o, Short##name, s, short, PrintShort) \
4000 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4001 macro(o, Char##name, c, char, PrintChar) \
4002 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4003 macro(o, Float##name, f, float, PrintFloat) \
4004 macro(o, Double##name, d, double, PrintDouble)
4006 #define OPERATOR_INTTYPES(macro, o, name) \
4007 macro(o, Int##name, i, int, PrintInt) \
4008 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4009 macro(o, Short##name, s, short, PrintShort) \
4010 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4011 macro(o, Char##name, c, char, PrintChar) \
4012 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4015 // binary arithmetic
4016 OPERATOR_ALL(BINARY, +, Add)
4017 OPERATOR_ALL(BINARY, -, Sub)
4018 OPERATOR_ALL(BINARY, *, Mul)
4019 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4020 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4023 OPERATOR_ALL(UNARY, -, Neg)
4025 // unary arithmetic increment and decrement
4026 OPERATOR_ALL(UNARY, ++, Inc)
4027 OPERATOR_ALL(UNARY, --, Dec)
4029 // binary arithmetic assignment
4030 OPERATOR_ALL(BINARY, =, Asign)
4031 OPERATOR_ALL(BINARY, +=, AddAsign)
4032 OPERATOR_ALL(BINARY, -=, SubAsign)
4033 OPERATOR_ALL(BINARY, *=, MulAsign)
4034 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4035 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4038 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4039 OPERATOR_INTTYPES(BINARY, |, BitOr)
4040 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4041 OPERATOR_INTTYPES(BINARY, <<, LShift)
4042 OPERATOR_INTTYPES(BINARY, >>, RShift)
4045 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4047 // binary bitwise assignment
4048 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4049 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4050 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4051 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4052 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4054 // unary logical negation
4055 OPERATOR_INTTYPES(UNARY, !, Not)
4057 // binary logical equality
4058 OPERATOR_ALL(BINARY, ==, Equ)
4059 OPERATOR_ALL(BINARY, !=, Nqu)
4062 OPERATOR_ALL(BINARY, &&, And)
4063 OPERATOR_ALL(BINARY, ||, Or)
4065 // binary logical relational
4066 OPERATOR_ALL(BINARY, >, Grt)
4067 OPERATOR_ALL(BINARY, <, Sma)
4068 OPERATOR_ALL(BINARY, >=, GrtEqu)
4069 OPERATOR_ALL(BINARY, <=, SmaEqu)
4071 // tertiary condition operator
4072 OPERATOR_ALL(TERTIARY, ?, Cond)
4074 //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
4075 #define OPERATOR_TABLE_ALL(name, type) \
4076 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4078 type##Inc, type##Dec, \
4079 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4080 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4082 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4084 type##Equ, type##Nqu, \
4085 type##And, type##Or, \
4086 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4089 #define OPERATOR_TABLE_INTTYPES(name, type) \
4090 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4092 type##Inc, type##Dec, \
4093 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4094 null, null, null, null, null, \
4096 null, null, null, null, null, \
4098 type##Equ, type##Nqu, \
4099 type##And, type##Or, \
4100 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4103 OPERATOR_TABLE_ALL(int, Int)
4104 OPERATOR_TABLE_ALL(uint, UInt)
4105 OPERATOR_TABLE_ALL(short, Short)
4106 OPERATOR_TABLE_ALL(ushort, UShort)
4107 OPERATOR_TABLE_INTTYPES(float, Float)
4108 OPERATOR_TABLE_INTTYPES(double, Double)
4109 OPERATOR_TABLE_ALL(char, Char)
4110 OPERATOR_TABLE_ALL(uchar, UChar)
4112 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4113 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4114 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4115 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4116 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4117 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4118 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4119 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4121 public void ReadString(char * output, char * string)
4123 int len = strlen(string);
4125 bool quoted = false, escaped = false;
4126 for(c = 0; c<len; c++)
4128 char ch = string[c];
4133 case 'n': output[d] = '\n'; break;
4134 case 't': output[d] = '\t'; break;
4135 case 'a': output[d] = '\a'; break;
4136 case 'b': output[d] = '\b'; break;
4137 case 'f': output[d] = '\f'; break;
4138 case 'r': output[d] = '\r'; break;
4139 case 'v': output[d] = '\v'; break;
4140 case '\\': output[d] = '\\'; break;
4141 case '\"': output[d] = '\"'; break;
4142 default: output[d++] = '\\'; output[d] = ch;
4143 //default: output[d] = ch;
4164 public Operand GetOperand(Expression exp)
4167 Type type = exp.expType;
4170 while(type.kind == classType &&
4171 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4173 if(!type._class.registered.dataType)
4174 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4175 type = type._class.registered.dataType;
4178 op.kind = type.kind;
4179 op.type = exp.expType;
4180 if(exp.isConstant && exp.type == constantExp)
4186 if(exp.constant[0] == '\'')
4187 op.c = exp.constant[1];
4188 else if(type.isSigned)
4190 op.c = (char)strtol(exp.constant, null, 0);
4195 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4203 op.s = (short)strtol(exp.constant, null, 0);
4208 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4216 op.i = (int)strtol(exp.constant, null, 0);
4221 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4229 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4234 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4242 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4247 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4255 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4260 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4266 op.f = (float)strtod(exp.constant, null);
4270 op.d = (double)strtod(exp.constant, null);
4273 //case classType: For when we have operator overloading...
4274 // Pointer additions
4275 //case functionType:
4279 op.ui64 = _strtoui64(exp.constant, null, 0);
4280 op.kind = pointerType;
4290 static void UnusedFunction()
4293 a.OnGetString(0,0,0);
4296 extern int __ecereVMethodID_class_OnGetString;
4299 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4301 DataMember dataMember;
4302 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4304 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4305 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4309 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4311 void * ptr = inst.data + dataMember.offset + offset;
4312 char * result = null;
4313 exp.loc = member.loc = inst.loc;
4314 ((Identifier)member.identifiers->first).loc = inst.loc;
4316 if(!dataMember.dataType)
4317 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4318 type = dataMember.dataType;
4319 if(type.kind == classType)
4321 Class _class = type._class.registered;
4322 if(_class.type == enumClass)
4324 Class enumClass = eSystem_FindClass(privateModule, "enum");
4327 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4329 for(item = e.values.first; item; item = item.next)
4331 if((int)item.data == *(int *)ptr)
4339 exp.identifier = MkIdentifier(result);
4340 exp.type = identifierExp;
4341 exp.destType = MkClassType(_class.fullName);
4342 ProcessExpressionType(exp);
4346 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4348 if(!_class.dataType)
4349 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4350 type = _class.dataType;
4359 FreeExpContents(exp);
4361 exp.constant = PrintFloat(*(float*)ptr);
4362 exp.type = constantExp;
4367 FreeExpContents(exp);
4369 exp.constant = PrintDouble(*(double*)ptr);
4370 exp.type = constantExp;
4375 FreeExpContents(exp);
4377 exp.constant = PrintInt(*(int*)ptr);
4378 exp.type = constantExp;
4383 FreeExpContents(exp);
4385 exp.constant = PrintInt64(*(int64*)ptr);
4386 exp.type = constantExp;
4391 FreeExpContents(exp);
4392 // TODO: This should probably use proper type
4393 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4394 exp.type = constantExp;
4399 FreeExpContents(exp);
4400 // TODO: This should probably use proper type
4401 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4402 exp.type = constantExp;
4406 Compiler_Error($"Unhandled type populating instance\n");
4409 ListAdd(memberList, member);
4412 if(parentDataMember.type == unionMember)
4417 void PopulateInstance(Instantiation inst)
4419 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4420 Class _class = classSym.registered;
4421 DataMember dataMember;
4422 OldList * memberList = MkList();
4423 // Added this check and ->Add to prevent memory leaks on bad code
4425 inst.members = MkListOne(MkMembersInitList(memberList));
4427 inst.members->Add(MkMembersInitList(memberList));
4428 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4430 if(!dataMember.isProperty)
4432 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4433 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4437 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4439 void * ptr = inst.data + dataMember.offset;
4440 char * result = null;
4442 exp.loc = member.loc = inst.loc;
4443 ((Identifier)member.identifiers->first).loc = inst.loc;
4445 if(!dataMember.dataType)
4446 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4447 type = dataMember.dataType;
4448 if(type.kind == classType)
4450 Class _class = type._class.registered;
4451 if(_class.type == enumClass)
4453 Class enumClass = eSystem_FindClass(privateModule, "enum");
4456 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4458 for(item = e.values.first; item; item = item.next)
4460 if((int)item.data == *(int *)ptr)
4469 exp.identifier = MkIdentifier(result);
4470 exp.type = identifierExp;
4471 exp.destType = MkClassType(_class.fullName);
4472 ProcessExpressionType(exp);
4475 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4477 if(!_class.dataType)
4478 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4479 type = _class.dataType;
4488 exp.constant = PrintFloat(*(float*)ptr);
4489 exp.type = constantExp;
4494 exp.constant = PrintDouble(*(double*)ptr);
4495 exp.type = constantExp;
4500 exp.constant = PrintInt(*(int*)ptr);
4501 exp.type = constantExp;
4506 exp.constant = PrintInt64(*(int64*)ptr);
4507 exp.type = constantExp;
4512 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4513 exp.type = constantExp;
4517 Compiler_Error($"Unhandled type populating instance\n");
4520 ListAdd(memberList, member);
4526 void ComputeInstantiation(Expression exp)
4528 Instantiation inst = exp.instance;
4529 MembersInit members;
4530 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4531 Class _class = classSym ? classSym.registered : null;
4532 DataMember curMember = null;
4533 Class curClass = null;
4534 DataMember subMemberStack[256];
4535 int subMemberStackPos = 0;
4538 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4540 // Don't recompute the instantiation...
4541 // Non Simple classes will have become constants by now
4545 if(_class.type == normalClass || _class.type == noHeadClass)
4546 inst.data = (byte *)eInstance_New(_class);
4548 inst.data = new0 byte[_class.structSize];
4553 for(members = inst.members->first; members; members = members.next)
4555 switch(members.type)
4557 case dataMembersInit:
4559 if(members.dataMembers)
4562 for(member = members.dataMembers->first; member; member = member.next)
4564 Identifier ident = member.identifiers ? member.identifiers->first : null;
4567 Property prop = null;
4568 DataMember dataMember = null;
4569 Method method = null;
4570 uint dataMemberOffset;
4574 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4577 if(curMember.isProperty)
4578 prop = (Property)curMember;
4581 dataMember = curMember;
4583 // CHANGED THIS HERE
4584 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4586 // 2013/17/29 -- It seems that this was missing here!
4587 if(_class.type == normalClass)
4588 dataMemberOffset += _class.base.structSize;
4589 // dataMemberOffset = dataMember.offset;
4596 prop = eClass_FindProperty(_class, ident.string, privateModule);
4600 if(prop.memberAccess == publicAccess)
4602 curMember = (DataMember)prop;
4603 curClass = prop._class;
4608 DataMember _subMemberStack[256];
4609 int _subMemberStackPos = 0;
4611 // FILL MEMBER STACK
4612 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4617 if(dataMember.memberAccess == publicAccess)
4619 curMember = dataMember;
4620 curClass = dataMember._class;
4621 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4622 subMemberStackPos = _subMemberStackPos;
4628 if(found && member.initializer && member.initializer.type == expInitializer)
4630 Expression value = member.initializer.exp;
4632 bool deepMember = false;
4635 type = prop.dataType;
4639 if(!dataMember.dataType)
4640 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4642 type = dataMember.dataType;
4645 if(ident && ident.next)
4649 // for(; ident && type; ident = ident.next)
4650 for(ident = ident.next; ident && type; ident = ident.next)
4652 if(type.kind == classType)
4654 prop = eClass_FindProperty(type._class.registered,
4655 ident.string, privateModule);
4657 type = prop.dataType;
4660 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4661 ident.string, &dataMemberOffset, privateModule, null, null);
4663 type = dataMember.dataType;
4666 else if(type.kind == structType || type.kind == unionType)
4669 for(memberType = type.members.first; memberType; memberType = memberType.next)
4671 if(!strcmp(memberType.name, ident.string))
4682 FreeType(value.destType);
4683 value.destType = type;
4684 if(type) type.refCount++;
4685 ComputeExpression(value);
4687 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4689 if(type.kind == classType)
4691 Class _class = type._class.registered;
4692 if(_class.type == bitClass || _class.type == unitClass ||
4693 _class.type == enumClass)
4695 if(!_class.dataType)
4696 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4697 type = _class.dataType;
4703 void * ptr = inst.data + dataMemberOffset;
4705 if(value.type == constantExp)
4711 GetInt(value, (int*)ptr);
4716 GetInt64(value, (int64*)ptr);
4721 GetIntPtr(value, (intptr*)ptr);
4726 GetIntSize(value, (intsize*)ptr);
4731 GetFloat(value, (float*)ptr);
4736 GetDouble(value, (double *)ptr);
4741 else if(value.type == instanceExp)
4743 if(type.kind == classType)
4745 Class _class = type._class.registered;
4746 if(_class.type == structClass)
4748 ComputeTypeSize(type);
4749 if(value.instance.data)
4750 memcpy(ptr, value.instance.data, type.size);
4757 if(value.type == instanceExp && value.instance.data)
4759 if(type.kind == classType)
4761 Class _class = type._class.registered;
4762 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4764 void (*Set)(void *, void *) = (void *)prop.Set;
4765 Set(inst.data, value.instance.data);
4766 PopulateInstance(inst);
4770 else if(value.type == constantExp)
4776 void (*Set)(void *, double) = (void *)prop.Set;
4777 Set(inst.data, strtod(value.constant, null) );
4782 void (*Set)(void *, float) = (void *)prop.Set;
4783 Set(inst.data, (float)(strtod(value.constant, null)));
4788 void (*Set)(void *, int) = (void *)prop.Set;
4789 Set(inst.data, (int)strtol(value.constant, null, 0));
4794 void (*Set)(void *, int64) = (void *)prop.Set;
4795 Set(inst.data, _strtoi64(value.constant, null, 0));
4800 void (*Set)(void *, intptr) = (void *)prop.Set;
4801 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4806 void (*Set)(void *, intsize) = (void *)prop.Set;
4807 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4812 else if(value.type == stringExp)
4815 ReadString(temp, value.string);
4816 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4820 else if(!deepMember && type && _class.type == unitClass)
4824 // Only support converting units to units for now...
4825 if(value.type == constantExp)
4827 if(type.kind == classType)
4829 Class _class = type._class.registered;
4830 if(_class.type == unitClass)
4832 if(!_class.dataType)
4833 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4834 type = _class.dataType;
4837 // TODO: Assuming same base type for units...
4843 float (*Set)(float) = (void *)prop.Set;
4844 GetFloat(member.initializer.exp, &fValue);
4845 exp.constant = PrintFloat(Set(fValue));
4846 exp.type = constantExp;
4852 double (*Set)(double) = (void *)prop.Set;
4853 GetDouble(member.initializer.exp, &dValue);
4854 exp.constant = PrintDouble(Set(dValue));
4855 exp.type = constantExp;
4862 else if(!deepMember && type && _class.type == bitClass)
4866 if(value.type == instanceExp && value.instance.data)
4868 unsigned int (*Set)(void *) = (void *)prop.Set;
4869 bits = Set(value.instance.data);
4871 else if(value.type == constantExp)
4877 BitMember bitMember = (BitMember) dataMember;
4880 GetInt(value, &part);
4881 bits = (bits & ~bitMember.mask);
4882 if(!bitMember.dataType)
4883 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4885 type = bitMember.dataType;
4887 if(type.kind == classType && type._class && type._class.registered)
4889 if(!type._class.registered.dataType)
4890 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4891 type = type._class.registered.dataType;
4898 bits |= ((char)part << bitMember.pos);
4900 bits |= ((unsigned char)part << bitMember.pos);
4904 bits |= ((short)part << bitMember.pos);
4906 bits |= ((unsigned short)part << bitMember.pos);
4911 bits |= ((int)part << bitMember.pos);
4913 bits |= ((unsigned int)part << bitMember.pos);
4917 bits |= ((int64)part << bitMember.pos);
4919 bits |= ((uint64)part << bitMember.pos);
4924 bits |= ((intptr)part << bitMember.pos);
4928 bits |= ((uintptr)part << bitMember.pos);
4934 bits |= ((ssize_t)(intsize)part << bitMember.pos);
4938 bits |= ((size_t) (uintsize)part << bitMember.pos);
4947 if(_class && _class.type == unitClass)
4949 ComputeExpression(member.initializer.exp);
4950 exp.constant = member.initializer.exp.constant;
4951 exp.type = constantExp;
4953 member.initializer.exp.constant = null;
4963 if(_class && _class.type == bitClass)
4965 exp.constant = PrintHexUInt(bits);
4966 exp.type = constantExp;
4968 if(exp.type != instanceExp)
4974 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4976 if(exp.op.op == SIZEOF)
4978 FreeExpContents(exp);
4979 exp.type = constantExp;
4980 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
4991 // Provide default unary +
4992 Expression exp2 = exp.op.exp2;
4994 FreeExpContents(exp);
4995 FreeType(exp.expType);
4996 FreeType(exp.destType);
5002 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5004 // unary arithmetic increment and decrement
5005 //OPERATOR_ALL(UNARY, ++, Inc)
5006 //OPERATOR_ALL(UNARY, --, Dec)
5009 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5011 // unary logical negation
5013 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5021 // binary arithmetic
5023 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5026 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5029 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5032 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5035 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5037 // binary arithmetic assignment
5038 //OPERATOR_ALL(BINARY, =, Asign)
5039 //OPERATOR_ALL(BINARY, +=, AddAsign)
5040 //OPERATOR_ALL(BINARY, -=, SubAsign)
5041 //OPERATOR_ALL(BINARY, *=, MulAsign)
5042 //OPERATOR_ALL(BINARY, /=, DivAsign)
5043 //OPERATOR_ALL(BINARY, %=, ModAsign)
5048 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5052 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5055 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5058 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5061 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5063 // binary bitwise assignment
5064 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5065 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5066 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5067 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5068 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5069 // binary logical equality
5071 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5074 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5078 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5081 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5083 // binary logical relational
5085 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5088 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5091 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5094 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5101 void ComputeExpression(Expression exp)
5103 char expString[10240];
5104 expString[0] = '\0';
5106 PrintExpression(exp, expString);
5113 ComputeInstantiation(exp);
5122 Expression exp1, exp2 = null;
5126 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5128 ComputeExpression(exp.op.exp2);
5131 ComputeExpression(exp.op.exp1);
5134 op1 = GetOperand(exp1);
5135 if(op1.type) op1.type.refCount++;
5138 op2 = GetOperand(exp2);
5139 if(op2.type) op2.type.refCount++;
5145 op1 = GetOperand(exp1);
5146 if(op1.type) op1.type.refCount++;
5149 CallOperator(exp, exp1, exp2, op1, op2);
5156 if(exp.op.exp1 && exp.op.exp2)
5161 FreeExpContents(exp);
5162 op1.ops.BitAnd(exp, op1, op2);
5171 FreeExpContents(exp);
5172 op1.ops.Mul(exp, op1, op2);
5181 FreeExpContents(exp);
5182 op1.ops.Add(exp, op1, op2);
5187 // Provide default unary +
5188 Expression exp2 = exp.op.exp2;
5190 FreeExpContents(exp);
5191 FreeType(exp.expType);
5192 FreeType(exp.destType);
5203 FreeExpContents(exp);
5204 op1.ops.Sub(exp, op1, op2);
5211 FreeExpContents(exp);
5212 op1.ops.Neg(exp, op1);
5219 FreeExpContents(exp);
5220 op1.ops.BitNot(exp, op1);
5226 FreeExpContents(exp);
5227 op1.ops.Not(exp, op1);
5230 // Binary only operators
5234 FreeExpContents(exp);
5235 op1.ops.Div(exp, op1, op2);
5241 FreeExpContents(exp);
5242 op1.ops.Mod(exp, op1, op2);
5254 FreeExpContents(exp);
5255 op1.ops.Sma(exp, op1, op2);
5264 FreeExpContents(exp);
5265 op1.ops.Grt(exp, op1, op2);
5274 FreeExpContents(exp);
5275 op1.ops.SmaEqu(exp, op1, op2);
5284 FreeExpContents(exp);
5285 op1.ops.GrtEqu(exp, op1, op2);
5294 FreeExpContents(exp);
5295 op1.ops.Equ(exp, op1, op2);
5304 FreeExpContents(exp);
5305 op1.ops.Nqu(exp, op1, op2);
5312 FreeExpContents(exp);
5313 op1.ops.BitOr(exp, op1, op2);
5319 FreeExpContents(exp);
5320 op1.ops.BitXor(exp, op1, op2);
5328 FreeExpContents(exp);
5329 exp.type = constantExp;
5330 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5334 if(op1.type) FreeType(op1.type);
5335 if(op2.type) FreeType(op2.type);
5339 case extensionExpressionExp:
5342 for(e = exp.list->first; e; e = n)
5347 OldList * list = exp.list;
5348 ComputeExpression(e);
5349 //FreeExpContents(exp);
5350 FreeType(exp.expType);
5351 FreeType(exp.destType);
5368 exp.isConstant = true;
5370 ComputeExpression(exp.index.exp);
5371 if(!exp.index.exp.isConstant)
5372 exp.isConstant = false;
5374 for(e = exp.index.index->first; e; e = e.next)
5376 ComputeExpression(e);
5379 // Check if this type is int
5382 exp.isConstant = false;
5384 exp.expType = Dereference(exp.index.exp.expType);
5390 Expression memberExp = exp.member.exp;
5391 Identifier memberID = exp.member.member;
5394 ComputeExpression(exp.member.exp);
5395 type = exp.member.exp.expType;
5398 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);
5399 Property prop = null;
5400 DataMember member = null;
5401 Class convertTo = null;
5402 if(type.kind == subClassType && exp.member.exp.type == classExp)
5403 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5410 PrintTypeNoConst(type, string, false, true);
5411 classSym = FindClass(string);
5412 _class = classSym ? classSym.registered : null;
5415 if(exp.member.member)
5417 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5419 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5421 if(!prop && !member && _class && exp.member.member)
5423 Symbol classSym = FindClass(exp.member.member.string);
5425 _class = classSym ? classSym.registered : null;
5426 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5433 Type type = prop.dataType;
5434 // TODO: Assuming same base type for units...
5435 if(_class.type == unitClass)
5437 if(type.kind == classType)
5439 Class _class = type._class.registered;
5440 if(_class.type == unitClass)
5442 if(!_class.dataType)
5443 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5444 type = _class.dataType;
5452 float (*Get)(float) = (void *)prop.Get;
5453 GetFloat(exp.member.exp, &value);
5454 exp.constant = PrintFloat(Get ? Get(value) : value);
5455 exp.type = constantExp;
5461 double (*Get)(double);
5462 GetDouble(exp.member.exp, &value);
5465 Get = (void *)prop.Set;
5467 Get = (void *)prop.Get;
5468 exp.constant = PrintDouble(Get ? Get(value) : value);
5469 exp.type = constantExp;
5478 Expression value = exp.member.exp;
5481 ProcessPropertyType(prop);
5483 type = prop.dataType;
5486 // printf("Investigate this\n");
5488 else if(_class.type == structClass)
5494 Class propertyClass = type._class.registered;
5495 if(propertyClass.type == structClass && value.type == instanceExp)
5497 void (*Set)(void *, void *) = (void *)prop.Set;
5498 exp.instance = Instantiation { };
5499 exp.instance.data = new0 byte[_class.structSize];
5500 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5501 exp.instance.loc = exp.loc;
5502 exp.type = instanceExp;
5503 Set(exp.instance.data, value.instance.data);
5504 PopulateInstance(exp.instance);
5511 void (*Set)(void *, int) = (void *)prop.Set;
5513 exp.instance = Instantiation { };
5514 exp.instance.data = new0 byte[_class.structSize];
5515 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5516 exp.instance.loc = exp.loc;
5517 exp.type = instanceExp;
5519 GetInt(value, &intValue);
5521 Set(exp.instance.data, intValue);
5522 PopulateInstance(exp.instance);
5528 void (*Set)(void *, int64) = (void *)prop.Set;
5530 exp.instance = Instantiation { };
5531 exp.instance.data = new0 byte[_class.structSize];
5532 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5533 exp.instance.loc = exp.loc;
5534 exp.type = instanceExp;
5536 GetInt64(value, &intValue);
5538 Set(exp.instance.data, intValue);
5539 PopulateInstance(exp.instance);
5546 void (*Set)(void *, intptr) = (void *)prop.Set;
5548 exp.instance = Instantiation { };
5549 exp.instance.data = new0 byte[_class.structSize];
5550 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5551 exp.instance.loc = exp.loc;
5552 exp.type = instanceExp;
5554 GetIntPtr(value, &intValue);
5556 Set(exp.instance.data, intValue);
5557 PopulateInstance(exp.instance);
5564 void (*Set)(void *, intsize) = (void *)prop.Set;
5566 exp.instance = Instantiation { };
5567 exp.instance.data = new0 byte[_class.structSize];
5568 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5569 exp.instance.loc = exp.loc;
5570 exp.type = instanceExp;
5572 GetIntSize(value, &intValue);
5574 Set(exp.instance.data, intValue);
5575 PopulateInstance(exp.instance);
5581 void (*Set)(void *, double) = (void *)prop.Set;
5583 exp.instance = Instantiation { };
5584 exp.instance.data = new0 byte[_class.structSize];
5585 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5586 exp.instance.loc = exp.loc;
5587 exp.type = instanceExp;
5589 GetDouble(value, &doubleValue);
5591 Set(exp.instance.data, doubleValue);
5592 PopulateInstance(exp.instance);
5597 else if(_class.type == bitClass)
5603 Class propertyClass = type._class.registered;
5604 if(propertyClass.type == structClass && value.instance.data)
5606 unsigned int (*Set)(void *) = (void *)prop.Set;
5607 unsigned int bits = Set(value.instance.data);
5608 exp.constant = PrintHexUInt(bits);
5609 exp.type = constantExp;
5612 else if(_class.type == bitClass)
5615 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5618 GetUInt(exp.member.exp, &value);
5620 exp.constant = PrintHexUInt(bits);
5621 exp.type = constantExp;
5629 if(_class.type == bitClass)
5632 GetUInt(exp.member.exp, &value);
5638 Class _class = type._class.registered;
5639 if(_class.type == structClass)
5641 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5643 exp.instance = Instantiation { };
5644 exp.instance.data = new0 byte[_class.structSize];
5645 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5646 exp.instance.loc = exp.loc;
5647 //exp.instance.fullSet = true;
5648 exp.type = instanceExp;
5649 Get(value, exp.instance.data);
5650 PopulateInstance(exp.instance);
5652 else if(_class.type == bitClass)
5654 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5655 uint64 bits = Get(value);
5656 exp.constant = PrintHexUInt64(bits);
5657 exp.type = constantExp;
5663 else if(_class.type == structClass)
5665 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5670 Class _class = type._class.registered;
5671 if(_class.type == structClass && value)
5673 void (*Get)(void *, void *) = (void *)prop.Get;
5675 exp.instance = Instantiation { };
5676 exp.instance.data = new0 byte[_class.structSize];
5677 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5678 exp.instance.loc = exp.loc;
5679 //exp.instance.fullSet = true;
5680 exp.type = instanceExp;
5681 Get(value, exp.instance.data);
5682 PopulateInstance(exp.instance);
5690 char * value = exp.member.exp.instance.data;
5695 Class _class = type._class.registered;
5696 if(_class.type == normalClass)
5698 void *(*Get)(void *) = (void *)prop.Get;
5700 exp.instance = Instantiation { };
5701 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5702 exp.type = instanceExp;
5703 exp.instance.data = Get(value, exp.instance.data);
5715 exp.isConstant = false;
5723 if(exp.type != ExpressionType::memberExp)
5725 FreeExpression(memberExp);
5726 FreeIdentifier(memberID);
5732 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5733 FreeExpContents(exp);
5734 exp.constant = PrintUInt(ComputeTypeSize(type));
5735 exp.type = constantExp;
5741 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5742 if(classSym && classSym.registered)
5744 if(classSym.registered.fixed)
5746 FreeSpecifier(exp._class);
5747 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5748 exp.type = constantExp;
5752 char className[1024];
5753 strcpy(className, "__ecereClass_");
5754 FullClassNameCat(className, classSym.string, true);
5755 MangleClassName(className);
5757 FreeExpContents(exp);
5758 exp.type = pointerExp;
5759 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5760 exp.member.member = MkIdentifier("structSize");
5770 if(exp.type == castExp)
5773 ComputeExpression(exp.cast.exp);
5776 if(e && exp.expType)
5779 type = exp.destType;
5782 if(type.kind == classType)
5784 Class _class = type._class.registered;
5785 if(_class && (_class.type == unitClass || _class.type == bitClass))
5787 if(!_class.dataType)
5788 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5789 type = _class.dataType;
5800 FreeExpContents(exp);
5801 exp.constant = PrintChar(value);
5802 exp.type = constantExp;
5806 unsigned char value;
5807 GetUChar(e, &value);
5808 FreeExpContents(exp);
5809 exp.constant = PrintUChar(value);
5810 exp.type = constantExp;
5817 GetShort(e, &value);
5818 FreeExpContents(exp);
5819 exp.constant = PrintShort(value);
5820 exp.type = constantExp;
5824 unsigned short value;
5825 GetUShort(e, &value);
5826 FreeExpContents(exp);
5827 exp.constant = PrintUShort(value);
5828 exp.type = constantExp;
5836 FreeExpContents(exp);
5837 exp.constant = PrintInt(value);
5838 exp.type = constantExp;
5844 FreeExpContents(exp);
5845 exp.constant = PrintUInt(value);
5846 exp.type = constantExp;
5853 GetInt64(e, &value);
5854 FreeExpContents(exp);
5855 exp.constant = PrintInt64(value);
5856 exp.type = constantExp;
5861 GetUInt64(e, &value);
5862 FreeExpContents(exp);
5863 exp.constant = PrintUInt64(value);
5864 exp.type = constantExp;
5871 GetIntPtr(e, &value);
5872 FreeExpContents(exp);
5873 exp.constant = PrintInt64((int64)value);
5874 exp.type = constantExp;
5879 GetUIntPtr(e, &value);
5880 FreeExpContents(exp);
5881 exp.constant = PrintUInt64((uint64)value);
5882 exp.type = constantExp;
5889 GetIntSize(e, &value);
5890 FreeExpContents(exp);
5891 exp.constant = PrintInt64((int64)value);
5892 exp.type = constantExp;
5897 GetUIntSize(e, &value);
5898 FreeExpContents(exp);
5899 exp.constant = PrintUInt64((uint64)value);
5900 exp.type = constantExp;
5906 GetFloat(e, &value);
5907 FreeExpContents(exp);
5908 exp.constant = PrintFloat(value);
5909 exp.type = constantExp;
5915 GetDouble(e, &value);
5916 FreeExpContents(exp);
5917 exp.constant = PrintDouble(value);
5918 exp.type = constantExp;
5932 // Caring only about last expression for now...
5933 ComputeExpression(exp.cond.exp->last);
5934 if(exp.cond.elseExp)
5935 ComputeExpression(exp.cond.elseExp);
5937 ComputeExpression(exp.cond.cond);
5939 op1 = GetOperand(exp.cond.cond);
5940 if(op1.type) op1.type.refCount++;
5941 op2 = GetOperand(exp.cond.exp->last);
5942 if(op2.type) op2.type.refCount++;
5943 op3 = GetOperand(exp.cond.elseExp);
5944 if(op3.type) op3.type.refCount++;
5946 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5947 if(op1.type) FreeType(op1.type);
5948 if(op2.type) FreeType(op2.type);
5949 if(op3.type) FreeType(op3.type);
5955 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5960 OldList converts { };
5963 if(destType.kind == voidType)
5966 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5970 // for(convert = converts.last; convert; convert = convert.prev)
5971 for(convert = converts.first; convert; convert = convert.next)
5973 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
5976 Expression newExp { };
5977 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
5979 // TODO: Check this...
5981 newExp.destType = null;
5986 exp.type = memberExp;
5987 exp.addedThis = true;
5988 exp.member.exp = newExp;
5989 FreeType(exp.member.exp.expType);
5991 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
5992 exp.member.exp.expType.classObjectType = objectType;
5993 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
5994 exp.member.memberType = propertyMember;
5995 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5996 // TESTING THIS... for (int)degrees
5997 exp.needCast = true;
5998 if(exp.expType) exp.expType.refCount++;
5999 ApplyAnyObjectLogic(exp.member.exp);
6004 /*if(exp.isConstant)
6006 // Color { ColorRGB = [exp] };
6007 exp.type = instanceExp;
6008 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6009 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6010 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6014 // If not constant, don't turn it yet into an instantiation
6015 // (Go through the deep members system first)
6016 exp.type = memberExp;
6017 exp.addedThis = true;
6018 exp.member.exp = newExp;
6020 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6021 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6022 newExp.expType._class.registered.type == noHeadClass)
6024 newExp.byReference = true;
6027 FreeType(exp.member.exp.expType);
6028 /*exp.member.exp.expType = convert.convert.dataType;
6029 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6030 exp.member.exp.expType = null;
6031 if(convert.convert.dataType)
6033 exp.member.exp.expType = { };
6034 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6035 exp.member.exp.expType.refCount = 1;
6036 exp.member.exp.expType.classObjectType = objectType;
6037 ApplyAnyObjectLogic(exp.member.exp);
6040 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6041 exp.member.memberType = reverseConversionMember;
6042 exp.expType = convert.resultType ? convert.resultType :
6043 MkClassType(convert.convert._class.fullName);
6044 exp.needCast = true;
6045 if(convert.resultType) convert.resultType.refCount++;
6051 FreeType(exp.expType);
6054 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6055 exp.needCast = true;
6056 if(exp.expType) exp.expType.refCount++;
6060 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6061 exp.needCast = true;
6062 if(convert.resultType)
6063 convert.resultType.refCount++;
6067 if(exp.isConstant && inCompiler)
6068 ComputeExpression(exp);
6070 converts.Free(FreeConvert);
6073 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6075 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6077 if(!result && exp.expType && exp.destType)
6079 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6080 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6081 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6082 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6086 // if(result) CheckTemplateTypes(exp);
6090 void CheckTemplateTypes(Expression exp)
6092 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6094 Expression newExp { };
6098 if(exp.destType) exp.destType.refCount++;
6099 if(exp.expType) exp.expType.refCount++;
6103 switch(exp.expType.kind)
6106 if(exp.destType.classObjectType)
6108 // We need to pass the address, just pass it along (Undo what was done above)
6109 if(exp.destType) exp.destType.refCount--;
6110 if(exp.expType) exp.expType.refCount--;
6115 // If we're looking for value:
6116 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6118 OldList * unionDefs = MkList();
6119 OldList * statements = MkList();
6120 context = PushContext();
6121 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6122 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6123 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6124 exp.type = extensionCompoundExp;
6125 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6126 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6127 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6128 exp.compound.compound.context = context;
6129 PopContext(context);
6134 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6135 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6139 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6141 Expression newExp { };
6145 if(exp.destType) exp.destType.refCount++;
6146 if(exp.expType) exp.expType.refCount++;
6150 switch(exp.expType.kind)
6153 if(exp.destType.classObjectType)
6155 // We need to pass the address, just pass it along (Undo what was done above)
6156 if(exp.destType) exp.destType.refCount--;
6157 if(exp.expType) exp.expType.refCount--;
6162 // If we're looking for value:
6163 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6165 OldList * unionDefs = MkList();
6166 OldList * statements = MkList();
6167 context = PushContext();
6168 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6169 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6170 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6171 exp.type = extensionCompoundExp;
6172 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6173 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6174 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6175 exp.compound.compound.context = context;
6176 PopContext(context);
6181 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6183 exp.type = bracketsExp;
6184 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6185 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6186 ProcessExpressionType(exp.list->first);
6191 exp.type = bracketsExp;
6192 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6193 newExp.needCast = true;
6194 ProcessExpressionType(exp.list->first);
6200 if(exp.expType.kind == templateType)
6202 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6205 FreeType(exp.destType);
6206 FreeType(exp.expType);
6211 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6216 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6217 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6221 char typeString[1024];
6223 OldList * specs = MkList();
6224 typeString[0] = '\0';
6225 PrintType(exp.expType, typeString, false, false);
6226 decl = SpecDeclFromString(typeString, specs, null);
6229 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6230 exp.cast.typeName = MkTypeName(specs, decl);
6231 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6232 exp.cast.exp.needCast = true;
6239 // TODO: The Symbol tree should be reorganized by namespaces
6241 // - Tree of all symbols within (stored without namespace)
6242 // - Tree of sub-namespaces
6244 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6246 int nsLen = strlen(nameSpace);
6248 // Start at the name space prefix
6249 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6251 char * s = symbol.string;
6252 if(!strncmp(s, nameSpace, nsLen))
6254 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6257 for(c = strlen(s)-1; c >= 0; c--)
6262 if(!strcmp(namePart, name))
6264 // TODO: Error on ambiguity
6274 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6277 char nameSpace[1024];
6279 bool gotColon = false;
6281 nameSpace[0] = '\0';
6282 for(c = strlen(name)-1; c >= 0; c--)
6289 namePart = name+c+1;
6290 while(c >= 0 && name[c] == ':') c--;
6293 // Try an exact match first
6294 Symbol symbol = (Symbol)tree.FindString(name);
6298 // Namespace specified
6299 memcpy(nameSpace, name, c + 1);
6302 return ScanWithNameSpace(tree, nameSpace, namePart);
6306 // Looking for a global symbol, e.g. ::Sleep()
6307 Symbol symbol = (Symbol)tree.FindString(namePart);
6312 // Name only (no namespace specified)
6313 Symbol symbol = (Symbol)tree.FindString(namePart);
6316 return ScanWithNameSpace(tree, "", namePart);
6321 static void ProcessDeclaration(Declaration decl);
6323 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6326 //Time startTime = GetTime();
6328 // Optimize this later? Do this before/less?
6330 Symbol symbol = null;
6331 // First, check if the identifier is declared inside the function
6332 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6334 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6336 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6342 strcpy(curName, thisNameSpace);
6343 strcat(curName, "::");
6344 strcat(curName, name);
6345 // Try to resolve in current namespace first
6346 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6349 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6352 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6354 if(symbol || ctx == endContext) break;
6356 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6358 if(symbol.pointerExternal.type == functionExternal)
6360 FunctionDefinition function = symbol.pointerExternal.function;
6362 // Modified this recently...
6363 Context tmpContext = curContext;
6365 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6366 curContext = tmpContext;
6368 symbol.pointerExternal.symbol = symbol;
6371 DeclareType(symbol.type, true, true);
6373 ast->Insert(curExternal.prev, symbol.pointerExternal);
6375 symbol.id = curExternal.symbol.idCode;
6378 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6380 ast->Move(symbol.pointerExternal, curExternal.prev);
6381 symbol.id = curExternal.symbol.idCode;
6385 //findSymbolTotalTime += GetTime() - startTime;
6390 static void GetTypeSpecs(Type type, OldList * specs)
6392 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6397 if(type._class.registered)
6399 if(!type._class.registered.dataType)
6400 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6401 GetTypeSpecs(type._class.registered.dataType, specs);
6405 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6406 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6407 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6408 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6409 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6410 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6411 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6414 ListAdd(specs, MkSpecifier(INT)); break;
6418 static void PrintArraySize(Type arrayType, char * string)
6423 if(arrayType.enumClass)
6424 strcat(size, arrayType.enumClass.string);
6425 else if(arrayType.arraySizeExp)
6426 PrintExpression(arrayType.arraySizeExp, size);
6428 strcat(string, size);
6431 // WARNING : This function expects a null terminated string since it recursively concatenate...
6432 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6436 if(printConst && type.constant)
6437 strcat(string, "const ");
6442 Symbol c = type._class;
6443 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6444 // look into merging with thisclass ?
6445 if(type.classObjectType == typedObject)
6446 strcat(string, "typed_object");
6447 else if(type.classObjectType == anyObject)
6448 strcat(string, "any_object");
6452 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6454 if(type.byReference)
6455 strcat(string, " &");
6458 case voidType: strcat(string, "void"); break;
6459 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6460 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6461 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6462 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6463 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6464 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6465 case floatType: strcat(string, "float"); break;
6466 case doubleType: strcat(string, "double"); break;
6470 strcat(string, "struct ");
6471 strcat(string, type.enumName);
6473 else if(type.typeName)
6474 strcat(string, type.typeName);
6478 strcat(string, "struct { ");
6479 for(member = type.members.first; member; member = member.next)
6481 PrintType(member, string, true, fullName);
6482 strcat(string,"; ");
6490 strcat(string, "union ");
6491 strcat(string, type.enumName);
6493 else if(type.typeName)
6494 strcat(string, type.typeName);
6497 strcat(string, "union ");
6498 strcat(string,"(unnamed)");
6504 strcat(string, "enum ");
6505 strcat(string, type.enumName);
6507 else if(type.typeName)
6508 strcat(string, type.typeName);
6510 strcat(string, "int"); // "enum");
6513 strcat(string, "...");
6516 strcat(string, "subclass(");
6517 strcat(string, type._class ? type._class.string : "int");
6518 strcat(string, ")");
6521 strcat(string, type.templateParameter.identifier.string);
6524 strcat(string, "thisclass");
6527 strcat(string, "__builtin_va_list");
6533 static void PrintName(Type type, char * string, bool fullName)
6535 if(type.name && type.name[0])
6538 strcat(string, type.name);
6541 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6542 if(name) name += 2; else name = type.name;
6543 strcat(string, name);
6548 static void PrintAttribs(Type type, char * string)
6552 if(type.dllExport) strcat(string, "dllexport ");
6553 if(type.attrStdcall) strcat(string, "stdcall ");
6557 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6559 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6561 Type attrType = null;
6562 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6563 PrintAttribs(type, string);
6564 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6565 strcat(string, " const");
6566 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6567 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6568 strcat(string, " (");
6569 if(type.kind == pointerType)
6571 if(type.type.kind == functionType || type.type.kind == methodType)
6572 PrintAttribs(type.type, string);
6574 if(type.kind == pointerType)
6576 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6577 strcat(string, "*");
6579 strcat(string, " *");
6581 if(printConst && type.constant && type.kind == pointerType)
6582 strcat(string, " const");
6585 PrintTypeSpecs(type, string, fullName, printConst);
6588 static void PostPrintType(Type type, char * string, bool fullName)
6590 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6591 strcat(string, ")");
6592 if(type.kind == arrayType)
6593 PrintArraySize(type, string);
6594 else if(type.kind == functionType)
6597 strcat(string, "(");
6598 for(param = type.params.first; param; param = param.next)
6600 PrintType(param, string, true, fullName);
6601 if(param.next) strcat(string, ", ");
6603 strcat(string, ")");
6605 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6606 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6610 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6612 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6614 PrePrintType(type, string, fullName, null, printConst);
6616 if(type.thisClass || (printName && type.name && type.name[0]))
6617 strcat(string, " ");
6618 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6620 Symbol _class = type.thisClass;
6621 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6623 if(type.classObjectType == classPointer)
6624 strcat(string, "class");
6626 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6628 else if(_class && _class.string)
6630 String s = _class.string;
6635 char * name = RSearchString(s, "::", strlen(s), true, false);
6636 if(name) name += 2; else name = s;
6637 strcat(string, name);
6640 strcat(string, "::");
6643 if(printName && type.name)
6644 PrintName(type, string, fullName);
6645 PostPrintType(type, string, fullName);
6646 if(type.bitFieldCount)
6649 sprintf(count, ":%d", type.bitFieldCount);
6650 strcat(string, count);
6654 void PrintType(Type type, char * string, bool printName, bool fullName)
6656 _PrintType(type, string, printName, fullName, true);
6659 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6661 _PrintType(type, string, printName, fullName, false);
6664 static Type FindMember(Type type, char * string)
6667 for(memberType = type.members.first; memberType; memberType = memberType.next)
6669 if(!memberType.name)
6671 Type subType = FindMember(memberType, string);
6675 else if(!strcmp(memberType.name, string))
6681 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6684 for(memberType = type.members.first; memberType; memberType = memberType.next)
6686 if(!memberType.name)
6688 Type subType = FindMember(memberType, string);
6691 *offset += memberType.offset;
6695 else if(!strcmp(memberType.name, string))
6697 *offset += memberType.offset;
6704 Expression ParseExpressionString(char * expression)
6706 fileInput = TempFile { };
6707 fileInput.Write(expression, 1, strlen(expression));
6708 fileInput.Seek(0, start);
6711 parsedExpression = null;
6713 expression_yyparse();
6716 return parsedExpression;
6719 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6721 Identifier id = exp.identifier;
6722 Method method = null;
6723 Property prop = null;
6724 DataMember member = null;
6725 ClassProperty classProp = null;
6727 if(_class && _class.type == enumClass)
6729 NamedLink value = null;
6730 Class enumClass = eSystem_FindClass(privateModule, "enum");
6734 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6736 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6737 for(value = e.values.first; value; value = value.next)
6739 if(!strcmp(value.name, id.string))
6746 FreeExpContents(exp);
6748 exp.type = constantExp;
6749 exp.isConstant = true;
6750 if(!strcmp(baseClass.dataTypeString, "int"))
6751 sprintf(constant, "%d",(int)value.data);
6753 sprintf(constant, "0x%X",(int)value.data);
6754 exp.constant = CopyString(constant);
6755 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6756 exp.expType = MkClassType(baseClass.fullName);
6764 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6766 ProcessMethodType(method);
6773 // TOCHECK: Put it back to what it was...
6774 // methodClass = _class;
6775 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6780 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6783 ProcessPropertyType(prop);
6784 exp.expType = prop.dataType;
6785 if(prop.dataType) prop.dataType.refCount++;
6788 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6790 if(!member.dataType)
6791 member.dataType = ProcessTypeString(member.dataTypeString, false);
6792 exp.expType = member.dataType;
6793 if(member.dataType) member.dataType.refCount++;
6796 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6798 if(!classProp.dataType)
6799 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6801 if(classProp.constant)
6803 FreeExpContents(exp);
6805 exp.isConstant = true;
6806 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6808 //char constant[256];
6809 exp.type = stringExp;
6810 exp.constant = QMkString((char *)classProp.Get(_class));
6815 exp.type = constantExp;
6816 sprintf(constant, "%d", (int)classProp.Get(_class));
6817 exp.constant = CopyString(constant);
6825 exp.expType = classProp.dataType;
6826 if(classProp.dataType) classProp.dataType.refCount++;
6832 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6834 BinaryTree * tree = &nameSpace.functions;
6835 GlobalData data = (GlobalData)tree->FindString(name);
6839 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6841 data = ScanGlobalData(child, name);
6849 static GlobalData FindGlobalData(char * name)
6852 NameSpace * nameSpace;
6853 nameSpace = globalData;
6854 for(c = 0; name[c]; c++)
6856 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6858 NameSpace * newSpace;
6859 char * spaceName = new char[c - start + 1];
6860 strncpy(spaceName, name + start, c - start);
6861 spaceName[c-start] = '\0';
6862 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6866 nameSpace = newSpace;
6867 if(name[c] == ':') c++;
6873 return ScanGlobalData(nameSpace, name + start);
6878 static int definedExpStackPos;
6879 static void * definedExpStack[512];
6881 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6882 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6884 Expression prev = checkedExp.prev, next = checkedExp.next;
6886 FreeExpContents(checkedExp);
6887 FreeType(checkedExp.expType);
6888 FreeType(checkedExp.destType);
6890 *checkedExp = *newExp;
6894 checkedExp.prev = prev;
6895 checkedExp.next = next;
6898 void ApplyAnyObjectLogic(Expression e)
6900 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6901 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6903 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6904 //ellipsisDestType = destType;
6907 Type type = e.expType;
6908 Class _class = null;
6909 //Type destType = e.destType;
6911 if(type.kind == classType && type._class && type._class.registered)
6913 _class = type._class.registered;
6915 else if(type.kind == subClassType)
6917 _class = FindClass("ecere::com::Class").registered;
6921 char string[1024] = "";
6924 PrintTypeNoConst(type, string, false, true);
6925 classSym = FindClass(string);
6926 if(classSym) _class = classSym.registered;
6929 if((_class && (_class.type == enumClass || _class.type == unitClass || _class.type == bitClass || _class.type == systemClass) && strcmp(_class.fullName, "class") && strcmp(_class.fullName, "uintptr") && strcmp(_class.fullName, "intptr")) || // Patched so that class isn't considered SYSTEM...
6930 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != intPtrType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6931 destType.byReference)))
6933 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6935 Expression checkedExp = e, newExp;
6937 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6939 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6941 if(checkedExp.type == extensionCompoundExp)
6943 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6946 checkedExp = checkedExp.list->last;
6948 else if(checkedExp.type == castExp)
6949 checkedExp = checkedExp.cast.exp;
6952 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6954 newExp = checkedExp.op.exp2;
6955 checkedExp.op.exp2 = null;
6956 FreeExpContents(checkedExp);
6958 if(e.expType && e.expType.passAsTemplate)
6961 ComputeTypeSize(e.expType);
6962 sprintf(size, "%d", e.expType.size);
6963 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6964 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6965 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6968 ReplaceExpContents(checkedExp, newExp);
6969 e.byReference = true;
6971 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6973 Expression checkedExp, newExp;
6976 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6978 e.type == identifierExp ||
6979 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6980 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
6981 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
6984 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
6986 Context context = PushContext();
6988 OldList * specs = MkList();
6989 char typeString[1024];
6990 Expression newExp { };
6992 typeString[0] = '\0';
6995 //if(e.destType) e.destType.refCount++;
6996 // if(exp.expType) exp.expType.refCount++;
6999 newExp.expType = null;
7001 PrintTypeNoConst(e.expType, typeString, false, true);
7002 decl = SpecDeclFromString(typeString, specs, null);
7003 newExp.destType = ProcessType(specs, decl);
7005 curContext = context;
7007 // We need a current compound for this
7011 OldList * stmts = MkList();
7012 e.type = extensionCompoundExp;
7013 sprintf(name, "__internalValue%03X", internalValueCounter++);
7014 if(!curCompound.compound.declarations)
7015 curCompound.compound.declarations = MkList();
7016 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7017 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7018 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7019 e.compound = MkCompoundStmt(null, stmts);
7022 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7025 e.compound = MkCompoundStmt(
7026 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7027 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7029 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7033 Type type = e.destType;
7035 CopyTypeInto(e.destType, type);
7036 e.destType.refCount = 1;
7037 e.destType.classObjectType = none;
7041 e.compound.compound.context = context;
7042 PopContext(context);
7043 curContext = context.parent;
7047 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7049 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7051 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7053 if(checkedExp.type == extensionCompoundExp)
7055 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7058 checkedExp = checkedExp.list->last;
7060 else if(checkedExp.type == castExp)
7061 checkedExp = checkedExp.cast.exp;
7064 Expression operand { };
7065 operand = *checkedExp;
7066 checkedExp.destType = null;
7067 checkedExp.expType = null;
7069 checkedExp.type = opExp;
7070 checkedExp.op.op = '&';
7071 checkedExp.op.exp1 = null;
7072 checkedExp.op.exp2 = operand;
7074 //newExp = MkExpOp(null, '&', checkedExp);
7076 //ReplaceExpContents(checkedExp, newExp);
7083 // If expression type is a simple class, make it an address
7084 // FixReference(e, true);
7087 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7088 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7089 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7091 if(e.expType.classObjectType && destType && destType.classObjectType) //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
7093 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7097 Expression thisExp { };
7100 thisExp.prev = null;
7101 thisExp.next = null;
7104 e.type = bracketsExp;
7105 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7106 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7107 ((Expression)e.list->first).byReference = true;
7109 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7111 e.expType = thisExp.expType;
7112 e.expType.refCount++;
7117 CopyTypeInto(e.expType, thisExp.expType);
7118 e.expType.byReference = false;
7119 e.expType.refCount = 1;
7121 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7122 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7124 e.expType.classObjectType = none;
7129 // TOFIX: Try this for a nice IDE crash!
7131 // The other way around
7134 if(destType && e.expType &&
7135 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7136 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7137 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7139 if(destType.kind == ellipsisType)
7141 Compiler_Error($"Unspecified type\n");
7143 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7145 bool byReference = e.expType.byReference;
7146 Expression thisExp { };
7148 OldList * specs = MkList();
7149 char typeString[1024]; // Watch buffer overruns
7151 ClassObjectType backupClassObjectType;
7152 bool backupByReference;
7154 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7159 backupClassObjectType = type.classObjectType;
7160 backupByReference = type.byReference;
7162 type.classObjectType = none;
7163 type.byReference = false;
7165 typeString[0] = '\0';
7166 PrintType(type, typeString, false, true);
7167 decl = SpecDeclFromString(typeString, specs, null);
7169 type.classObjectType = backupClassObjectType;
7170 type.byReference = backupByReference;
7173 thisExp.prev = null;
7174 thisExp.next = null;
7177 if( ( type.kind == classType && type._class && type._class.registered &&
7178 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7179 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7180 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7181 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7186 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7191 e.cast.typeName = MkTypeName(specs, decl);
7192 e.cast.exp = thisExp;
7193 e.byReference = true;
7196 e.destType = destType;
7198 destType.refCount++;
7203 void ProcessExpressionType(Expression exp)
7205 bool unresolved = false;
7206 Location oldyylloc = yylloc;
7207 bool notByReference = false;
7209 char debugExpString[4096];
7210 debugExpString[0] = '\0';
7211 PrintExpression(exp, debugExpString);
7213 if(!exp || exp.expType)
7216 //eSystem_Logf("%s\n", expString);
7218 // Testing this here
7224 Identifier id = exp.identifier;
7227 // DOING THIS LATER NOW...
7228 if(id._class && id._class.name)
7230 id.classSym = id._class.symbol; // FindClass(id._class.name);
7231 /* TODO: Name Space Fix ups
7233 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7237 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7239 exp.expType = ProcessTypeString("Module", true);
7242 else */if(strstr(id.string, "__ecereClass") == id.string)
7244 exp.expType = ProcessTypeString("ecere::com::Class", true);
7247 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7249 // Added this here as well
7250 ReplaceClassMembers(exp, thisClass);
7251 if(exp.type != identifierExp)
7253 ProcessExpressionType(exp);
7257 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7262 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7263 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7264 if(!symbol/* && exp.destType*/)
7266 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7272 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7273 if(exp.type != identifierExp)
7275 ProcessExpressionType(exp);
7279 // Static methods called from inside the _class
7280 else if(currentClass && !id._class)
7282 if(ResolveIdWithClass(exp, currentClass, true))
7285 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7289 // If we manage to resolve this symbol
7292 Type type = symbol.type;
7293 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7295 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7297 Context context = SetupTemplatesContext(_class);
7298 type = ReplaceThisClassType(_class);
7299 FinishTemplatesContext(context);
7300 if(type) type.refCount = 0; // We'll be incrementing it right below...
7303 FreeSpecifier(id._class);
7306 id.string = CopyString(symbol.string);
7312 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7313 // Add missing cases here... enum Classes...
7314 exp.isConstant = true;
7316 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7317 if(symbol.isParam || !strcmp(id.string, "this"))
7319 if(_class && _class.type == structClass && !type.declaredWithStruct)
7320 exp.byReference = true;
7322 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7323 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7324 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7325 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7327 Identifier id = exp.identifier;
7328 exp.type = bracketsExp;
7329 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7333 if(symbol.isIterator)
7335 if(symbol.isIterator == 3)
7337 exp.type = bracketsExp;
7338 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7339 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7341 ProcessExpressionType(exp);
7343 else if(symbol.isIterator != 4)
7345 exp.type = memberExp;
7346 exp.member.exp = MkExpIdentifier(exp.identifier);
7347 exp.member.exp.expType = exp.expType;
7348 /*if(symbol.isIterator == 6)
7349 exp.member.member = MkIdentifier("key");
7351 exp.member.member = MkIdentifier("data");
7353 ProcessExpressionType(exp);
7360 DefinedExpression definedExp = null;
7361 if(thisNameSpace && !(id._class && !id._class.name))
7364 strcpy(name, thisNameSpace);
7366 strcat(name, id.string);
7367 definedExp = eSystem_FindDefine(privateModule, name);
7370 definedExp = eSystem_FindDefine(privateModule, id.string);
7374 for(c = 0; c<definedExpStackPos; c++)
7375 if(definedExpStack[c] == definedExp)
7377 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7379 Location backupYylloc = yylloc;
7380 definedExpStack[definedExpStackPos++] = definedExp;
7381 fileInput = TempFile { };
7382 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7383 fileInput.Seek(0, start);
7386 parsedExpression = null;
7388 expression_yyparse();
7391 yylloc = backupYylloc;
7393 if(parsedExpression)
7396 exp.type = bracketsExp;
7397 exp.list = MkListOne(parsedExpression);
7398 parsedExpression.loc = yylloc;
7399 ProcessExpressionType(exp);
7400 definedExpStackPos--;
7403 definedExpStackPos--;
7409 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7415 GlobalData data = null;
7416 if(thisNameSpace && !(id._class && !id._class.name))
7419 strcpy(name, thisNameSpace);
7421 strcat(name, id.string);
7422 data = FindGlobalData(name);
7425 data = FindGlobalData(id.string);
7428 DeclareGlobalData(data);
7429 exp.expType = data.dataType;
7430 if(data.dataType) data.dataType.refCount++;
7433 id.string = CopyString(data.fullName);
7434 FreeSpecifier(id._class);
7441 GlobalFunction function = null;
7442 if(thisNameSpace && !(id._class && !id._class.name))
7445 strcpy(name, thisNameSpace);
7447 strcat(name, id.string);
7448 function = eSystem_FindFunction(privateModule, name);
7451 function = eSystem_FindFunction(privateModule, id.string);
7456 id.string = CopyString(function.name);
7459 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7460 strcpy(name, "__ecereFunction_");
7461 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7462 if(DeclareFunction(function, name))
7465 id.string = CopyString(name);
7467 exp.expType = function.dataType;
7468 if(function.dataType) function.dataType.refCount++;
7470 FreeSpecifier(id._class);
7487 if(!exp.instance._class)
7489 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7491 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7495 //classSym = FindClass(exp.instance._class.fullName);
7496 //_class = classSym ? classSym.registered : null;
7498 ProcessInstantiationType(exp.instance);
7499 exp.isConstant = exp.instance.isConstant;
7502 if(_class.type == unitClass && _class.base.type != systemClass)
7505 Type destType = exp.destType;
7507 exp.destType = MkClassType(_class.base.fullName);
7508 exp.expType = MkClassType(_class.fullName);
7509 CheckExpressionType(exp, exp.destType, true);
7511 exp.destType = destType;
7513 exp.expType = MkClassType(_class.fullName);
7516 if(exp.instance._class)
7518 exp.expType = MkClassType(exp.instance._class.name);
7519 /*if(exp.expType._class && exp.expType._class.registered &&
7520 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7521 exp.expType.byReference = true;*/
7536 if(exp.constant[0] == '\'')
7538 if((int)((byte *)exp.constant)[1] > 127)
7541 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7542 if(nb < 2) ch = exp.constant[1];
7543 delete exp.constant;
7544 exp.constant = PrintUInt(ch);
7545 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7546 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7547 type._class = FindClass("unichar");
7549 type.isSigned = false;
7553 type.kind = charType;
7554 type.isSigned = true;
7557 else if(strchr(exp.constant, '.'))
7559 char ch = exp.constant[strlen(exp.constant)-1];
7561 type.kind = floatType;
7563 type.kind = doubleType;
7564 type.isSigned = true;
7568 if(exp.constant[0] == '0' && exp.constant[1])
7569 type.isSigned = false;
7570 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7571 type.isSigned = false;
7572 else if(strtoll(exp.constant, null, 0) > MAXINT)
7573 type.isSigned = false;
7575 type.isSigned = true;
7576 type.kind = intType;
7578 exp.isConstant = true;
7579 if(exp.destType && exp.destType.kind == doubleType)
7580 type.kind = doubleType;
7581 else if(exp.destType && exp.destType.kind == floatType)
7582 type.kind = floatType;
7583 else if(exp.destType && exp.destType.kind == int64Type)
7584 type.kind = int64Type;
7590 exp.isConstant = true; // Why wasn't this constant?
7606 ProcessExpressionType(exp._new.size);
7611 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7613 DeclareType(exp.expType.type, false, false);
7617 ProcessExpressionType(exp._renew.size);
7618 ProcessExpressionType(exp._renew.exp);
7623 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7625 DeclareType(exp.expType.type, false, false);
7629 bool assign = false, boolResult = false, boolOps = false;
7630 Type type1 = null, type2 = null;
7631 bool useDestType = false, useSideType = false;
7632 Location oldyylloc = yylloc;
7633 bool useSideUnit = false;
7635 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7644 // Assignment Operators
7658 // boolean Operators
7660 // Expect boolean operators
7662 //boolResult = true;
7666 // Expect boolean operands
7677 // Gives boolean result
7685 // Just added these... testing
7690 // DANGER: Verify units
7695 if(exp.op.op != '*' || exp.op.exp1)
7702 /*// Implement speed etc.
7708 if(exp.op.op == '&')
7710 // Added this here earlier for Iterator address as key
7711 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7713 Identifier id = exp.op.exp2.identifier;
7714 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7715 if(symbol && symbol.isIterator == 2)
7717 exp.type = memberExp;
7718 exp.member.exp = exp.op.exp2;
7719 exp.member.member = MkIdentifier("key");
7721 exp.op.exp2.expType = symbol.type;
7722 symbol.type.refCount++;
7723 ProcessExpressionType(exp);
7727 // exp.op.exp2.usage.usageRef = true;
7731 //dummy.kind = TypeDummy;
7735 if(exp.destType && exp.destType.kind == classType &&
7736 exp.destType._class && exp.destType._class.registered && useDestType &&
7738 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7739 exp.destType._class.registered.type == enumClass ||
7740 exp.destType._class.registered.type == bitClass
7743 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7745 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7746 exp.op.exp1.destType = exp.destType;
7748 exp.destType.refCount++;
7752 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7753 exp.op.exp1.destType = dummy;
7757 // TESTING THIS HERE...
7758 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7759 ProcessExpressionType(exp.op.exp1);
7760 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7762 if(exp.op.exp1.destType == dummy)
7765 exp.op.exp1.destType = null;
7767 type1 = exp.op.exp1.expType;
7772 char expString[10240];
7773 expString[0] = '\0';
7774 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7778 exp.op.exp2.destType = exp.op.exp1.expType;
7779 if(exp.op.exp1.expType)
7780 exp.op.exp1.expType.refCount++;
7784 exp.op.exp2.destType = exp.destType;
7786 exp.destType.refCount++;
7789 if(type1) type1.refCount++;
7790 exp.expType = type1;
7795 PrintExpression(exp.op.exp2, expString);
7797 if(type1 && type1.kind == pointerType)
7799 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 ||
7800 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7801 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7802 else if(exp.op.op == '=')
7804 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7805 exp.op.exp2.destType = type1;
7812 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7813 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/* ||
7814 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7817 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7818 exp.op.exp2.destType = type1;
7823 if(type1) type1.refCount++;
7824 exp.expType = type1;
7826 else if(exp.destType && exp.destType.kind == classType &&
7827 exp.destType._class && exp.destType._class.registered &&
7829 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7830 (exp.destType._class.registered.type == enumClass && useDestType))
7833 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7834 exp.op.exp2.destType = exp.destType;
7836 exp.destType.refCount++;
7840 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7841 exp.op.exp2.destType = dummy;
7845 // TESTING THIS HERE... (DANGEROUS)
7846 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7847 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7849 FreeType(exp.op.exp2.destType);
7850 exp.op.exp2.destType = type1;
7853 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7854 ProcessExpressionType(exp.op.exp2);
7855 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7857 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7859 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)
7861 if(exp.op.op != '=' && type1.type.kind == voidType)
7862 Compiler_Error($"void *: unknown size\n");
7864 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||
7865 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7866 (exp.op.exp2.expType._class.registered.type == normalClass ||
7867 exp.op.exp2.expType._class.registered.type == structClass ||
7868 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7870 if(exp.op.op == ADD_ASSIGN)
7871 Compiler_Error($"cannot add two pointers\n");
7873 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7874 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7876 if(exp.op.op == ADD_ASSIGN)
7877 Compiler_Error($"cannot add two pointers\n");
7881 char type1String[1024];
7882 char type2String[1024];
7883 type1String[0] = '\0';
7884 type2String[0] = '\0';
7886 PrintType(exp.op.exp2.expType, type1String, false, true);
7887 PrintType(type1, type2String, false, true);
7888 ChangeCh(expString, '\n', ' ');
7889 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7893 if(exp.op.exp2.destType == dummy)
7896 exp.op.exp2.destType = null;
7899 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
7903 CopyTypeInto(type2, exp.op.exp2.expType);
7904 type2.isSigned = true;
7906 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
7908 type2 = { kind = intType };
7910 type2.isSigned = true;
7913 type2 = exp.op.exp2.expType;
7916 dummy.kind = voidType;
7918 if(exp.op.op == SIZEOF)
7925 exp.isConstant = true;
7927 // Get type of dereferenced pointer
7928 else if(exp.op.op == '*' && !exp.op.exp1)
7930 exp.expType = Dereference(type2);
7931 if(type2 && type2.kind == classType)
7932 notByReference = true;
7934 else if(exp.op.op == '&' && !exp.op.exp1)
7935 exp.expType = Reference(type2);
7942 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7943 exp.op.exp1.destType = MkClassType("bool");
7944 exp.op.exp1.destType.truth = true;
7945 if(!exp.op.exp1.expType)
7946 ProcessExpressionType(exp.op.exp1);
7948 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7949 FreeType(exp.op.exp1.expType);
7950 exp.op.exp1.expType = MkClassType("bool");
7951 exp.op.exp1.expType.truth = true;
7955 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7956 exp.op.exp2.destType = MkClassType("bool");
7957 exp.op.exp2.destType.truth = true;
7958 if(!exp.op.exp2.expType)
7959 ProcessExpressionType(exp.op.exp2);
7961 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7962 FreeType(exp.op.exp2.expType);
7963 exp.op.exp2.expType = MkClassType("bool");
7964 exp.op.exp2.expType.truth = true;
7967 else if(exp.op.exp1 && exp.op.exp2 &&
7970 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7971 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7972 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7973 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7975 if(type1 && type2 &&
7976 // If either both are class or both are not class
7977 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
7979 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7980 exp.op.exp2.destType = type1;
7982 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7983 exp.op.exp1.destType = type2;
7985 // Warning here for adding Radians + Degrees with no destination type
7986 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7987 type1._class.registered && type1._class.registered.type == unitClass &&
7988 type2._class.registered && type2._class.registered.type == unitClass &&
7989 type1._class.registered != type2._class.registered)
7990 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
7991 type1._class.string, type2._class.string, type1._class.string);
7993 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7995 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7998 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8000 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8001 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8004 ProcessExpressionType(exp.op.exp1);
8006 if(type2.kind != pointerType)
8008 ProcessExpressionType(classExp);
8010 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8011 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8012 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8014 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8017 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8018 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8019 MkPointer(null, null), null)))),
8020 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8022 if(!exp.op.exp2.expType)
8023 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8025 ProcessExpressionType(exp.op.exp2);
8030 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)))
8032 if(type1.kind != classType && type1.type.kind == voidType)
8033 Compiler_Error($"void *: unknown size\n");
8034 exp.expType = type1;
8035 if(type1) type1.refCount++;
8037 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)))
8039 if(type2.kind != classType && type2.type.kind == voidType)
8040 Compiler_Error($"void *: unknown size\n");
8041 exp.expType = type2;
8042 if(type2) type2.refCount++;
8044 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8045 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8047 Compiler_Warning($"different levels of indirection\n");
8051 bool success = false;
8052 if(type1.kind == pointerType && type2.kind == pointerType)
8054 if(exp.op.op == '+')
8055 Compiler_Error($"cannot add two pointers\n");
8056 else if(exp.op.op == '-')
8058 // Pointer Subtraction gives integer
8059 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8068 if(type1.type.kind == templateType)
8070 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8073 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8075 ProcessExpressionType(classExp);
8077 exp.type = bracketsExp;
8078 exp.list = MkListOne(MkExpOp(
8079 MkExpBrackets(MkListOne(MkExpOp(
8080 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8082 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8084 //MkExpMember(classExp, MkIdentifier("typeSize"))
8086 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8087 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8089 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8092 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8093 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8094 MkPointer(null, null), null)))),
8095 MkExpMember(classExp, MkIdentifier("typeSize")))))
8100 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8109 if(!success && exp.op.exp1.type == constantExp)
8111 // If first expression is constant, try to match that first
8112 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8114 if(exp.expType) FreeType(exp.expType);
8115 exp.expType = exp.op.exp1.destType;
8116 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8119 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8121 if(exp.expType) FreeType(exp.expType);
8122 exp.expType = exp.op.exp2.destType;
8123 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8129 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8131 if(exp.expType) FreeType(exp.expType);
8132 exp.expType = exp.op.exp2.destType;
8133 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8136 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8138 if(exp.expType) FreeType(exp.expType);
8139 exp.expType = exp.op.exp1.destType;
8140 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8146 char expString1[10240];
8147 char expString2[10240];
8150 expString1[0] = '\0';
8151 expString2[0] = '\0';
8156 PrintExpression(exp.op.exp1, expString1);
8157 ChangeCh(expString1, '\n', ' ');
8158 PrintExpression(exp.op.exp2, expString2);
8159 ChangeCh(expString2, '\n', ' ');
8160 PrintType(exp.op.exp1.expType, type1, false, true);
8161 PrintType(exp.op.exp2.expType, type2, false, true);
8164 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8168 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8169 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8171 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8172 // Convert e.g. / 4 into / 4.0
8173 exp.op.exp1.destType = type2._class.registered.dataType;
8174 if(type2._class.registered.dataType)
8175 type2._class.registered.dataType.refCount++;
8176 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8177 exp.expType = type2;
8178 if(type2) type2.refCount++;
8180 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8182 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8183 // Convert e.g. / 4 into / 4.0
8184 exp.op.exp2.destType = type1._class.registered.dataType;
8185 if(type1._class.registered.dataType)
8186 type1._class.registered.dataType.refCount++;
8187 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8188 exp.expType = type1;
8189 if(type1) type1.refCount++;
8195 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8197 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8199 if(!type1._class.registered.dataType)
8200 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8201 exp.op.exp2.destType = type1._class.registered.dataType;
8202 exp.op.exp2.destType.refCount++;
8204 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8205 type2 = exp.op.exp2.destType;
8207 exp.expType = type2;
8211 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8213 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8215 if(!type2._class.registered.dataType)
8216 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8217 exp.op.exp1.destType = type2._class.registered.dataType;
8218 exp.op.exp1.destType.refCount++;
8220 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8221 type1 = exp.op.exp1.destType;
8222 exp.expType = type1;
8226 // TESTING THIS NEW CODE
8227 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8229 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8231 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8233 if(exp.expType) FreeType(exp.expType);
8234 exp.expType = exp.op.exp1.expType;
8235 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8240 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8242 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8244 if(exp.expType) FreeType(exp.expType);
8245 exp.expType = exp.op.exp2.expType;
8246 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8254 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8255 exp.op.exp2.destType = type1;
8259 // Maybe this was meant to be an enum...
8260 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8262 Type oldType = exp.op.exp2.expType;
8263 exp.op.exp2.expType = null;
8264 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8267 exp.op.exp2.expType = oldType;
8272 // TESTING THIS HERE... LATEST ADDITION
8273 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8275 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8276 exp.op.exp2.destType = type2._class.registered.dataType;
8277 if(type2._class.registered.dataType)
8278 type2._class.registered.dataType.refCount++;
8279 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8281 //exp.expType = type2._class.registered.dataType; //type2;
8282 //if(type2) type2.refCount++;
8285 // TESTING THIS HERE... LATEST ADDITION
8286 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8288 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8289 exp.op.exp1.destType = type1._class.registered.dataType;
8290 if(type1._class.registered.dataType)
8291 type1._class.registered.dataType.refCount++;
8292 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8293 exp.expType = type1._class.registered.dataType; //type1;
8294 if(type1) type1.refCount++;
8298 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8300 if(exp.expType) FreeType(exp.expType);
8301 exp.expType = exp.op.exp2.destType;
8302 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8304 else if(type1 && type2)
8306 char expString1[10240];
8307 char expString2[10240];
8308 char type1String[1024];
8309 char type2String[1024];
8310 expString1[0] = '\0';
8311 expString2[0] = '\0';
8312 type1String[0] = '\0';
8313 type2String[0] = '\0';
8316 PrintExpression(exp.op.exp1, expString1);
8317 ChangeCh(expString1, '\n', ' ');
8318 PrintExpression(exp.op.exp2, expString2);
8319 ChangeCh(expString2, '\n', ' ');
8320 PrintType(exp.op.exp1.expType, type1String, false, true);
8321 PrintType(exp.op.exp2.expType, type2String, false, true);
8324 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8326 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8328 exp.expType = exp.op.exp1.expType;
8329 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8331 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8333 exp.expType = exp.op.exp2.expType;
8334 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8341 // Maybe this was meant to be an enum...
8342 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8344 Type oldType = exp.op.exp1.expType;
8345 exp.op.exp1.expType = null;
8346 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8349 exp.op.exp1.expType = oldType;
8352 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8353 exp.op.exp1.destType = type2;
8356 // TESTING THIS HERE... LATEST ADDITION
8357 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8359 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8360 exp.op.exp1.destType = type1._class.registered.dataType;
8361 if(type1._class.registered.dataType)
8362 type1._class.registered.dataType.refCount++;
8365 // TESTING THIS HERE... LATEST ADDITION
8366 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8368 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8369 exp.op.exp2.destType = type2._class.registered.dataType;
8370 if(type2._class.registered.dataType)
8371 type2._class.registered.dataType.refCount++;
8375 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8377 if(exp.expType) FreeType(exp.expType);
8378 exp.expType = exp.op.exp1.destType;
8379 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8383 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8385 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8387 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8388 // Convert e.g. / 4 into / 4.0
8389 exp.op.exp1.destType = type2._class.registered.dataType;
8390 if(type2._class.registered.dataType)
8391 type2._class.registered.dataType.refCount++;
8392 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8394 if(exp.op.op == '!')
8396 exp.expType = MkClassType("bool");
8397 exp.expType.truth = true;
8401 exp.expType = type2;
8402 if(type2) type2.refCount++;
8405 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8407 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8409 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8410 // Convert e.g. / 4 into / 4.0
8411 exp.op.exp2.destType = type1._class.registered.dataType;
8412 if(type1._class.registered.dataType)
8413 type1._class.registered.dataType.refCount++;
8414 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8416 exp.expType = type1;
8417 if(type1) type1.refCount++;
8422 if(exp.op.exp1 && !exp.op.exp1.expType)
8424 char expString[10000];
8425 expString[0] = '\0';
8428 PrintExpression(exp.op.exp1, expString);
8429 ChangeCh(expString, '\n', ' ');
8432 Compiler_Error($"couldn't determine type of %s\n", expString);
8434 if(exp.op.exp2 && !exp.op.exp2.expType)
8436 char expString[10240];
8437 expString[0] = '\0';
8440 PrintExpression(exp.op.exp2, expString);
8441 ChangeCh(expString, '\n', ' ');
8444 Compiler_Error($"couldn't determine type of %s\n", expString);
8449 FreeType(exp.expType);
8450 exp.expType = MkClassType("bool");
8451 exp.expType.truth = true;
8454 if(exp.op.op != SIZEOF)
8455 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8456 (!exp.op.exp2 || exp.op.exp2.isConstant);
8458 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8460 DeclareType(exp.op.exp2.expType, false, false);
8469 case extensionExpressionExp:
8472 exp.isConstant = true;
8473 for(e = exp.list->first; e; e = e.next)
8478 FreeType(e.destType);
8479 e.destType = exp.destType;
8480 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8482 ProcessExpressionType(e);
8484 exp.destType.count--;
8485 if(!exp.expType && !e.next)
8487 exp.expType = e.expType;
8488 if(e.expType) e.expType.refCount++;
8491 exp.isConstant = false;
8494 // In case a cast became a member...
8495 e = exp.list->first;
8496 if(!e.next && e.type == memberExp)
8498 // Preserve prev, next
8499 Expression next = exp.next, prev = exp.prev;
8502 FreeType(exp.expType);
8503 FreeType(exp.destType);
8513 ProcessExpressionType(exp);
8520 exp.isConstant = true;
8522 ProcessExpressionType(exp.index.exp);
8523 if(!exp.index.exp.isConstant)
8524 exp.isConstant = false;
8526 if(exp.index.exp.expType)
8528 Type source = exp.index.exp.expType;
8529 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8530 eClass_IsDerived(source._class.registered, containerClass) &&
8531 source._class.registered.templateArgs)
8533 Class _class = source._class.registered;
8534 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8536 if(exp.index.index && exp.index.index->last)
8538 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8543 for(e = exp.index.index->first; e; e = e.next)
8545 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8547 if(e.destType) FreeType(e.destType);
8548 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8550 ProcessExpressionType(e);
8553 // Check if this type is int
8556 exp.isConstant = false;
8560 exp.expType = Dereference(exp.index.exp.expType);
8562 DeclareType(exp.expType, false, false);
8569 Type methodType = null;
8575 PrintExpression(exp.call.exp, name);
8576 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8578 //exp.call.exp.expType = null;
8579 PrintExpression(exp.call.exp, name);
8582 if(exp.call.exp.type == identifierExp)
8584 Expression idExp = exp.call.exp;
8585 Identifier id = idExp.identifier;
8586 if(!strcmp(id.string, "__builtin_frame_address"))
8588 exp.expType = ProcessTypeString("void *", true);
8589 if(exp.call.arguments && exp.call.arguments->first)
8590 ProcessExpressionType(exp.call.arguments->first);
8593 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8595 exp.expType = ProcessTypeString("int", true);
8596 if(exp.call.arguments && exp.call.arguments->first)
8597 ProcessExpressionType(exp.call.arguments->first);
8600 else if(!strcmp(id.string, "Max") ||
8601 !strcmp(id.string, "Min") ||
8602 !strcmp(id.string, "Sgn") ||
8603 !strcmp(id.string, "Abs"))
8605 Expression a = null;
8606 Expression b = null;
8607 Expression tempExp1 = null, tempExp2 = null;
8608 if((!strcmp(id.string, "Max") ||
8609 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8611 a = exp.call.arguments->first;
8612 b = exp.call.arguments->last;
8616 else if(exp.call.arguments->count == 1)
8618 a = exp.call.arguments->first;
8624 exp.call.arguments->Clear();
8625 idExp.identifier = null;
8627 FreeExpContents(exp);
8629 ProcessExpressionType(a);
8631 ProcessExpressionType(b);
8633 exp.type = bracketsExp;
8634 exp.list = MkList();
8636 if(a.expType && (!b || b.expType))
8638 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8640 // Use the simpleStruct name/ids for now...
8643 OldList * specs = MkList();
8644 OldList * decls = MkList();
8646 char temp1[1024], temp2[1024];
8648 GetTypeSpecs(a.expType, specs);
8650 if(a && !a.isConstant && a.type != identifierExp)
8652 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8653 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8654 tempExp1 = QMkExpId(temp1);
8655 tempExp1.expType = a.expType;
8657 a.expType.refCount++;
8658 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8660 if(b && !b.isConstant && b.type != identifierExp)
8662 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8663 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8664 tempExp2 = QMkExpId(temp2);
8665 tempExp2.expType = b.expType;
8667 b.expType.refCount++;
8668 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8671 decl = MkDeclaration(specs, decls);
8672 if(!curCompound.compound.declarations)
8673 curCompound.compound.declarations = MkList();
8674 curCompound.compound.declarations->Insert(null, decl);
8679 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8681 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8683 MkExpCondition(MkExpBrackets(MkListOne(
8684 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8685 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8686 exp.expType = a.expType;
8688 a.expType.refCount++;
8690 else if(!strcmp(id.string, "Abs"))
8693 MkExpCondition(MkExpBrackets(MkListOne(
8694 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8695 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8696 exp.expType = a.expType;
8698 a.expType.refCount++;
8700 else if(!strcmp(id.string, "Sgn"))
8702 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8704 MkExpCondition(MkExpBrackets(MkListOne(
8705 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8706 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8707 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8708 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8709 exp.expType = ProcessTypeString("int", false);
8712 FreeExpression(tempExp1);
8713 if(tempExp2) FreeExpression(tempExp2);
8727 if(!exp.call.exp.destType)
8729 exp.call.exp.destType = dummy;
8732 ProcessExpressionType(exp.call.exp);
8733 if(exp.call.exp.destType == dummy)
8736 exp.call.exp.destType = null;
8741 // Check argument types against parameter types
8742 functionType = exp.call.exp.expType;
8744 if(functionType && functionType.kind == TypeKind::methodType)
8746 methodType = functionType;
8747 functionType = methodType.method.dataType;
8749 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8750 // TOCHECK: Instead of doing this here could this be done per param?
8751 if(exp.call.exp.expType.usedClass)
8753 char typeString[1024];
8754 typeString[0] = '\0';
8756 Symbol back = functionType.thisClass;
8757 // Do not output class specifier here (thisclass was added to this)
8758 functionType.thisClass = null;
8759 PrintType(functionType, typeString, true, true);
8760 functionType.thisClass = back;
8762 if(strstr(typeString, "thisclass"))
8764 OldList * specs = MkList();
8767 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8769 decl = SpecDeclFromString(typeString, specs, null);
8771 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8772 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8773 exp.call.exp.expType.usedClass))
8774 thisClassParams = false;
8776 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8778 Class backupThisClass = thisClass;
8779 thisClass = exp.call.exp.expType.usedClass;
8780 ProcessDeclarator(decl);
8781 thisClass = backupThisClass;
8784 thisClassParams = true;
8786 functionType = ProcessType(specs, decl);
8787 functionType.refCount = 0;
8788 FinishTemplatesContext(context);
8791 FreeList(specs, FreeSpecifier);
8792 FreeDeclarator(decl);
8796 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8798 Type type = functionType.type;
8799 if(!functionType.refCount)
8801 functionType.type = null;
8802 FreeType(functionType);
8804 //methodType = functionType;
8805 functionType = type;
8807 if(functionType && functionType.kind != TypeKind::functionType)
8809 Compiler_Error($"called object %s is not a function\n", name);
8811 else if(functionType)
8813 bool emptyParams = false, noParams = false;
8814 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8815 Type type = functionType.params.first;
8816 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8818 Location oldyylloc = yylloc;
8820 if(!type) emptyParams = true;
8823 if(functionType.extraParam && e && functionType.thisClass)
8825 e.destType = MkClassType(functionType.thisClass.string);
8829 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8830 // Fixed #141 by adding '&& !functionType.extraParam'
8831 if(!functionType.staticMethod && !functionType.extraParam)
8833 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8834 memberExp.member.exp.expType._class)
8836 type = MkClassType(memberExp.member.exp.expType._class.string);
8841 type = functionType.params.first;
8846 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8848 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8853 type = functionType.params.first;
8861 if(type && type.kind == voidType)
8864 if(!type.refCount) FreeType(type);
8868 for( ; e; e = e.next)
8870 if(!type && !emptyParams)
8873 if(methodType && methodType.methodClass)
8874 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8875 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8876 noParams ? 0 : functionType.params.count);
8878 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8879 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8880 noParams ? 0 : functionType.params.count);
8884 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8886 Type templatedType = null;
8887 Class _class = methodType.usedClass;
8888 ClassTemplateParameter curParam = null;
8890 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8893 for(sClass = _class; sClass; sClass = sClass.base)
8895 if(sClass.templateClass) sClass = sClass.templateClass;
8897 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8899 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8902 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8904 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8905 id += nextClass.templateParams.count;
8914 if(curParam && _class.templateArgs[id].dataTypeString)
8916 ClassTemplateArgument arg = _class.templateArgs[id];
8918 Context context = SetupTemplatesContext(_class);
8921 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8922 templatedType = ProcessTypeString(arg.dataTypeString, false);
8923 FinishTemplatesContext(context);
8925 e.destType = templatedType;
8928 templatedType.passAsTemplate = true;
8929 // templatedType.refCount++;
8935 if(type) type.refCount++;
8940 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
8942 e.destType = type.prev;
8943 e.destType.refCount++;
8948 if(type) type.refCount++;
8951 // Don't reach the end for the ellipsis
8952 if(type && type.kind != ellipsisType)
8954 Type next = type.next;
8955 if(!type.refCount) FreeType(type);
8960 if(type && type.kind != ellipsisType)
8962 if(methodType && methodType.methodClass)
8963 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
8964 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8965 functionType.params.count + extra);
8967 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
8968 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8969 functionType.params.count + extra);
8972 if(type && !type.refCount) FreeType(type);
8979 kind = TypeKind::functionType;
8982 if(exp.call.exp.type == identifierExp)
8984 char * string = exp.call.exp.identifier.string;
8988 Location oldyylloc = yylloc;
8990 yylloc = exp.call.exp.identifier.loc;
8991 if(strstr(string, "__builtin_") == string)
8995 functionType.returnType = exp.destType;
8996 exp.destType.refCount++;
9000 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9001 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9002 globalContext.symbols.Add((BTNode)symbol);
9003 if(strstr(symbol.string, "::"))
9004 globalContext.hasNameSpace = true;
9009 else if(exp.call.exp.type == memberExp)
9011 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9012 exp.call.exp.member.member.string);*/
9015 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9017 if(!functionType.returnType)
9019 functionType.returnType = Type
9026 if(functionType && functionType.kind == TypeKind::functionType)
9028 exp.expType = functionType.returnType;
9030 if(functionType.returnType)
9031 functionType.returnType.refCount++;
9033 if(!functionType.refCount)
9034 FreeType(functionType);
9037 if(exp.call.arguments)
9039 for(e = exp.call.arguments->first; e; e = e.next)
9041 Type destType = e.destType;
9042 ProcessExpressionType(e);
9050 Location oldyylloc = yylloc;
9052 Expression checkExp = exp.member.exp;
9055 if(checkExp.type == castExp)
9056 checkExp = checkExp.cast.exp;
9057 else if(checkExp.type == bracketsExp)
9058 checkExp = checkExp.list ? checkExp.list->first : null;
9063 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9064 exp.thisPtr = thisPtr;
9066 // DOING THIS LATER NOW...
9067 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9069 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9070 /* TODO: Name Space Fix ups
9071 if(!exp.member.member.classSym)
9072 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9076 ProcessExpressionType(exp.member.exp);
9077 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9078 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9080 exp.isConstant = false;
9083 exp.isConstant = exp.member.exp.isConstant;
9084 type = exp.member.exp.expType;
9088 if(type && (type.kind == templateType))
9090 Class _class = thisClass ? thisClass : currentClass;
9091 ClassTemplateParameter param = null;
9094 for(param = _class.templateParams.first; param; param = param.next)
9096 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9100 if(param && param.defaultArg.member)
9102 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9105 Expression expMember = exp.member.exp;
9107 OldList * specs = MkList();
9108 char thisClassTypeString[1024];
9110 FreeIdentifier(exp.member.member);
9112 ProcessExpressionType(argExp);
9115 char * colon = strstr(param.defaultArg.memberString, "::");
9118 char className[1024];
9121 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9122 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9125 strcpy(thisClassTypeString, _class.fullName);
9128 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9130 exp.expType = ProcessType(specs, decl);
9131 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9133 Class expClass = exp.expType._class.registered;
9134 Class cClass = null;
9139 char templateString[1024];
9140 ClassTemplateParameter param;
9141 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9142 for(cClass = expClass; cClass; cClass = cClass.base)
9145 for(param = cClass.templateParams.first; param; param = param.next)
9149 ClassTemplateArgument arg;
9150 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9151 arg = expClass.templateArgs[id];
9153 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9155 ClassTemplateParameter cParam;
9156 //int p = numParams - sClass.templateParams.count;
9159 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9161 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9163 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9165 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9167 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9168 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9180 strcat(argument, arg.name.string);
9181 strcat(argument, " = ");
9187 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9188 char expString[1024];
9189 OldList * specs = MkList();
9190 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9192 char * string = PrintHexUInt64(arg.expression.ui64);
9193 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9195 ProcessExpressionType(exp);
9196 ComputeExpression(exp);
9197 expString[0] = '\0';
9198 PrintExpression(exp, expString);
9199 strcat(argument, expString);
9201 FreeExpression(exp);
9206 strcat(argument, arg.member.name);
9209 case TemplateParameterType::type:
9211 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9213 if(!strcmp(arg.dataTypeString, "thisclass"))
9214 strcat(argument, thisClassTypeString);
9216 strcat(argument, arg.dataTypeString);
9223 if(paramCount) strcat(templateString, ", ");
9224 if(lastParam != p - 1)
9226 strcat(templateString, param.name);
9227 strcat(templateString, " = ");
9229 strcat(templateString, argument);
9238 int len = strlen(templateString);
9239 if(templateString[len-1] == '>') templateString[len++] = ' ';
9240 templateString[len++] = '>';
9241 templateString[len++] = '\0';
9244 Context context = SetupTemplatesContext(_class);
9245 FreeType(exp.expType);
9246 exp.expType = ProcessTypeString(templateString, false);
9247 FinishTemplatesContext(context);
9251 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9252 exp.type = bracketsExp;
9253 exp.list = MkListOne(MkExpOp(null, '*',
9258 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9259 MkExpBrackets(MkListOne(
9260 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9262 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9264 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9269 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9270 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9272 type = ProcessTemplateParameterType(type.templateParameter);
9275 // TODO: *** This seems to be where we should add method support for all basic types ***
9276 if(type && (type.kind == templateType));
9277 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9278 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType ||
9279 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9280 (type.kind == pointerType && type.type.kind == charType)))
9282 Identifier id = exp.member.member;
9283 TypeKind typeKind = type.kind;
9284 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9285 if(typeKind == subClassType && exp.member.exp.type == classExp)
9287 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9288 typeKind = classType;
9293 if(typeKind == intType || typeKind == enumType)
9294 _class = eSystem_FindClass(privateModule, "int");
9297 if(type.kind == classType && type._class && type._class.registered)
9299 _class = type._class.registered;
9301 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9303 _class = FindClass("char *").registered;
9305 else if(type.kind == pointerType)
9307 _class = eSystem_FindClass(privateModule, "uintptr");
9308 FreeType(exp.expType);
9309 exp.expType = ProcessTypeString("uintptr", false);
9310 exp.byReference = true;
9314 char string[1024] = "";
9316 PrintTypeNoConst(type, string, false, true);
9317 classSym = FindClass(string);
9318 if(classSym) _class = classSym.registered;
9326 (exp.member.exp.type == identifierExp &&
9327 !strcmp(exp.member.exp.identifier.string, "this"));*/
9328 Property prop = null;
9329 Method method = null;
9330 DataMember member = null;
9331 Property revConvert = null;
9332 ClassProperty classProp = null;
9334 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9335 exp.member.memberType = propertyMember;
9337 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9338 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9340 if(typeKind != subClassType)
9342 // Prioritize data members over properties for "this"
9343 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9345 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9346 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9348 prop = eClass_FindProperty(_class, id.string, privateModule);
9352 if(!member && !prop)
9353 prop = eClass_FindProperty(_class, id.string, privateModule);
9354 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9355 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9356 exp.member.thisPtr = true;
9358 // Prioritize properties over data members otherwise
9361 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9364 prop = eClass_FindProperty(_class, id.string, null);
9365 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9366 member = eClass_FindDataMember(_class, id.string, null, null, null);
9369 if(!prop && !member)
9371 method = eClass_FindMethod(_class, id.string, null);
9374 prop = eClass_FindProperty(_class, id.string, privateModule);
9375 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9376 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9382 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9389 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9390 method = eClass_FindMethod(_class, id.string, privateModule);
9391 if(!prop && !member && !method)
9393 if(typeKind == subClassType)
9395 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9398 exp.member.memberType = classPropertyMember;
9399 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9403 // Assume this is a class_data member
9404 char structName[1024];
9405 Identifier id = exp.member.member;
9406 Expression classExp = exp.member.exp;
9409 FreeType(classExp.expType);
9410 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9412 strcpy(structName, "__ecereClassData_");
9413 FullClassNameCat(structName, type._class.string, false);
9414 exp.type = pointerExp;
9415 exp.member.member = id;
9417 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9418 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9419 MkExpBrackets(MkListOne(MkExpOp(
9420 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9421 MkExpMember(classExp, MkIdentifier("data"))), '+',
9422 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9427 ProcessExpressionType(exp);
9433 // Check for reverse conversion
9434 // (Convert in an instantiation later, so that we can use
9435 // deep properties system)
9436 Symbol classSym = FindClass(id.string);
9439 Class convertClass = classSym.registered;
9441 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9448 exp.member.memberType = propertyMember;
9450 ProcessPropertyType(prop);
9451 exp.expType = prop.dataType;
9452 if(prop.dataType) prop.dataType.refCount++;
9456 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9458 FreeExpContents(exp);
9459 exp.type = identifierExp;
9460 exp.identifier = MkIdentifier("class");
9461 ProcessExpressionType(exp);
9465 exp.member.memberType = dataMember;
9466 DeclareStruct(_class.fullName, false);
9467 if(!member.dataType)
9469 Context context = SetupTemplatesContext(_class);
9470 member.dataType = ProcessTypeString(member.dataTypeString, false);
9471 FinishTemplatesContext(context);
9473 exp.expType = member.dataType;
9474 if(member.dataType) member.dataType.refCount++;
9478 exp.member.memberType = reverseConversionMember;
9479 exp.expType = MkClassType(revConvert._class.fullName);
9487 exp.type = identifierExp;
9488 exp.identifier = exp.member.member;
9491 exp.member.memberType = methodMember;
9493 if(!method.dataType)
9494 ProcessMethodType(method);
9502 // Tricky spot here... To use instance versus class virtual table
9503 // Put it back to what it was... What did we break?
9505 // Had to put it back for overriding Main of Thread global instance
9507 //exp.expType.methodClass = _class;
9508 exp.expType.methodClass = (id && id._class) ? _class : null;
9510 // Need the actual class used for templated classes
9511 exp.expType.usedClass = _class;
9515 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9517 FreeExpContents(exp);
9518 exp.type = identifierExp;
9519 exp.identifier = MkIdentifier("class");
9520 ProcessExpressionType(exp);
9523 yylloc = exp.member.member.loc;
9524 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9526 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9529 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9534 while(tClass && !tClass.templateClass) tClass = tClass.base;
9536 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9539 ClassTemplateParameter curParam = null;
9542 for(sClass = tClass; sClass; sClass = sClass.base)
9545 if(sClass.templateClass) sClass = sClass.templateClass;
9546 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9548 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9550 for(sClass = sClass.base; sClass; sClass = sClass.base)
9551 id += sClass.templateParams.count;
9559 if(curParam && tClass.templateArgs[id].dataTypeString)
9561 ClassTemplateArgument arg = tClass.templateArgs[id];
9562 Context context = SetupTemplatesContext(tClass);
9564 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9565 FreeType(exp.expType);
9566 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9569 if(exp.expType.kind == thisClassType)
9571 FreeType(exp.expType);
9572 exp.expType = ReplaceThisClassType(_class);
9575 if(tClass.templateClass)
9576 exp.expType.passAsTemplate = true;
9577 //exp.expType.refCount++;
9580 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9581 //exp.destType.refCount++;
9583 if(exp.destType.kind == thisClassType)
9585 FreeType(exp.destType);
9586 exp.destType = ReplaceThisClassType(_class);
9590 FinishTemplatesContext(context);
9593 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9594 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9597 ClassTemplateParameter curParam = null;
9600 for(sClass = tClass; sClass; sClass = sClass.base)
9603 if(sClass.templateClass) sClass = sClass.templateClass;
9604 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9606 if(curParam.type == TemplateParameterType::type &&
9607 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9609 for(sClass = sClass.base; sClass; sClass = sClass.base)
9610 id += sClass.templateParams.count;
9620 ClassTemplateArgument arg = tClass.templateArgs[id];
9621 Context context = SetupTemplatesContext(tClass);
9624 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9626 basicType = ProcessTypeString(arg.dataTypeString, false);
9629 if(basicType.kind == thisClassType)
9631 FreeType(basicType);
9632 basicType = ReplaceThisClassType(_class);
9635 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9636 if(tClass.templateClass)
9637 basicType.passAsTemplate = true;
9640 FreeType(exp.expType);
9642 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9643 //exp.expType.refCount++;
9646 exp.destType = exp.expType;
9647 exp.destType.refCount++;
9651 Expression newExp { };
9652 OldList * specs = MkList();
9654 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9656 if(exp.destType) exp.destType.refCount++;
9657 if(exp.expType) exp.expType.refCount++;
9659 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9660 exp.cast.exp = newExp;
9661 //FreeType(exp.expType);
9662 //exp.expType = null;
9663 //ProcessExpressionType(sourceExp);
9666 FinishTemplatesContext(context);
9669 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9671 Class expClass = exp.expType._class.registered;
9674 Class cClass = null;
9679 char templateString[1024];
9680 ClassTemplateParameter param;
9681 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9682 while(cClass != expClass)
9685 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9688 for(param = cClass.templateParams.first; param; param = param.next)
9690 Class cClassCur = null;
9693 ClassTemplateParameter paramCur = null;
9694 ClassTemplateArgument arg;
9695 while(cClassCur != tClass && !paramCur)
9698 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9699 cClassCur = sClassCur;
9701 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9703 if(!strcmp(paramCur.name, param.name))
9711 if(paramCur && paramCur.type == TemplateParameterType::type)
9712 arg = tClass.templateArgs[cp];
9714 arg = expClass.templateArgs[p];
9721 strcat(argument, arg.name.string);
9722 strcat(argument, " = ");
9728 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9729 char expString[1024];
9730 OldList * specs = MkList();
9731 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9733 char * string = PrintHexUInt64(arg.expression.ui64);
9734 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9736 ProcessExpressionType(exp);
9737 ComputeExpression(exp);
9738 expString[0] = '\0';
9739 PrintExpression(exp, expString);
9740 strcat(argument, expString);
9742 FreeExpression(exp);
9747 strcat(argument, arg.member.name);
9750 case TemplateParameterType::type:
9752 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9753 strcat(argument, arg.dataTypeString);
9759 if(paramCount) strcat(templateString, ", ");
9760 if(lastParam != p - 1)
9762 strcat(templateString, param.name);
9763 strcat(templateString, " = ");
9765 strcat(templateString, argument);
9774 int len = strlen(templateString);
9775 if(templateString[len-1] == '>') templateString[len++] = ' ';
9776 templateString[len++] = '>';
9777 templateString[len++] = '\0';
9780 FreeType(exp.expType);
9782 Context context = SetupTemplatesContext(tClass);
9783 exp.expType = ProcessTypeString(templateString, false);
9784 FinishTemplatesContext(context);
9791 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9793 else if(type && (type.kind == structType || type.kind == unionType))
9795 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9798 exp.expType = memberType;
9800 memberType.refCount++;
9805 char expString[10240];
9806 expString[0] = '\0';
9807 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9808 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9811 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9813 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9815 Identifier id = exp.member.member;
9816 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9819 FreeType(exp.expType);
9820 exp.expType = ReplaceThisClassType(_class);
9827 // Convert x->y into (*x).y
9830 Type destType = exp.destType;
9832 // DOING THIS LATER NOW...
9833 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9835 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9836 /* TODO: Name Space Fix ups
9837 if(!exp.member.member.classSym)
9838 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9842 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9843 exp.type = memberExp;
9846 ProcessExpressionType(exp);
9853 //ComputeExpression(exp);
9855 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9856 if(classSym && classSym.registered)
9858 if(classSym.registered.type == noHeadClass)
9862 DeclareStruct(classSym.string, false);
9863 FreeSpecifier(exp._class);
9864 exp.type = typeSizeExp;
9865 FullClassNameCat(name, classSym.string, false);
9866 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9870 if(classSym.registered.fixed)
9872 FreeSpecifier(exp._class);
9873 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9874 exp.type = constantExp;
9878 char className[1024];
9879 strcpy(className, "__ecereClass_");
9880 FullClassNameCat(className, classSym.string, true);
9881 MangleClassName(className);
9883 DeclareClass(classSym, className);
9885 FreeExpContents(exp);
9886 exp.type = pointerExp;
9887 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9888 exp.member.member = MkIdentifier("structSize");
9898 // exp.isConstant = true;
9903 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9910 exp.isConstant = true;
9912 DeclareType(type, false, false);
9918 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9920 FreeType(exp.cast.exp.destType);
9921 exp.cast.exp.destType = type;
9923 ProcessExpressionType(exp.cast.exp);
9928 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9929 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9931 void * prev = exp.prev, * next = exp.next;
9932 Type expType = exp.cast.exp.destType;
9933 Expression castExp = exp.cast.exp;
9934 Type destType = exp.destType;
9936 if(expType) expType.refCount++;
9938 //FreeType(exp.destType);
9939 FreeType(exp.expType);
9940 FreeTypeName(exp.cast.typeName);
9943 FreeType(exp.expType);
9944 FreeType(exp.destType);
9946 exp.expType = expType;
9947 exp.destType = destType;
9957 exp.isConstant = exp.cast.exp.isConstant;
9962 case extensionInitializerExp:
9964 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9965 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
9966 // ProcessInitializer(exp.initializer.initializer, type);
9972 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9973 ProcessExpressionType(exp.vaArg.exp);
9980 exp.isConstant = true;
9982 FreeType(exp.cond.cond.destType);
9983 exp.cond.cond.destType = MkClassType("bool");
9984 exp.cond.cond.destType.truth = true;
9985 ProcessExpressionType(exp.cond.cond);
9986 if(!exp.cond.cond.isConstant)
9987 exp.isConstant = false;
9988 for(e = exp.cond.exp->first; e; e = e.next)
9992 FreeType(e.destType);
9993 e.destType = exp.destType;
9994 if(e.destType) e.destType.refCount++;
9996 ProcessExpressionType(e);
9999 exp.expType = e.expType;
10000 if(e.expType) e.expType.refCount++;
10003 exp.isConstant = false;
10006 FreeType(exp.cond.elseExp.destType);
10007 // Added this check if we failed to find an expType
10008 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10011 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10013 if(exp.cond.elseExp.destType)
10014 exp.cond.elseExp.destType.refCount++;
10015 ProcessExpressionType(exp.cond.elseExp);
10017 // FIXED THIS: Was done before calling process on elseExp
10018 if(!exp.cond.elseExp.isConstant)
10019 exp.isConstant = false;
10022 case extensionCompoundExp:
10024 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10026 Statement last = exp.compound.compound.statements->last;
10027 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10029 ((Expression)last.expressions->last).destType = exp.destType;
10031 exp.destType.refCount++;
10033 ProcessStatement(exp.compound);
10034 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10036 exp.expType.refCount++;
10042 Specifier spec = exp._classExp.specifiers->first;
10043 if(spec && spec.type == nameSpecifier)
10045 exp.expType = MkClassType(spec.name);
10046 exp.expType.kind = subClassType;
10047 exp.byReference = true;
10051 exp.expType = MkClassType("ecere::com::Class");
10052 exp.byReference = true;
10058 Class _class = thisClass ? thisClass : currentClass;
10061 Identifier id = exp.classData.id;
10062 char structName[1024];
10063 Expression classExp;
10064 strcpy(structName, "__ecereClassData_");
10065 FullClassNameCat(structName, _class.fullName, false);
10066 exp.type = pointerExp;
10067 exp.member.member = id;
10068 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10069 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10071 classExp = MkExpIdentifier(MkIdentifier("class"));
10073 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10074 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10075 MkExpBrackets(MkListOne(MkExpOp(
10076 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10077 MkExpMember(classExp, MkIdentifier("data"))), '+',
10078 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10081 ProcessExpressionType(exp);
10089 char * typeString = null;
10090 char typeStringBuf[1024];
10091 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10092 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10094 Class templateClass = exp.destType._class.registered;
10095 typeString = templateClass.templateArgs[2].dataTypeString;
10099 // Guess type from expressions in the array
10101 for(e = exp.list->first; e; e = e.next)
10103 ProcessExpressionType(e);
10106 if(!type) { type = e.expType; type.refCount++; }
10109 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10110 if(!MatchTypeExpression(e, type, null, false))
10116 e = exp.list->first;
10117 ProcessExpressionType(e);
10120 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10121 if(!MatchTypeExpression(e, type, null, false))
10123 FreeType(e.expType);
10134 FreeType(e.expType);
10141 typeStringBuf[0] = '\0';
10142 PrintTypeNoConst(type, typeStringBuf, false, true);
10143 typeString = typeStringBuf;
10151 (Container)& (struct BuiltInContainer)
10153 ._vTbl = class(BuiltInContainer)._vTbl,
10154 ._class = class(BuiltInContainer),
10156 .data = (int[]){ 1, 7, 3, 4, 5 },
10158 .type = class(int),
10161 char templateString[1024];
10162 OldList * initializers = MkList();
10163 OldList * structInitializers = MkList();
10164 OldList * specs = MkList();
10166 Declarator decl = SpecDeclFromString(typeString, specs, null);
10167 sprintf(templateString, "Container<%s>", typeString);
10172 type = ProcessTypeString(typeString, false);
10173 while(e = exp.list->first)
10175 exp.list->Remove(e);
10178 ProcessExpressionType(e);
10179 ListAdd(initializers, MkInitializerAssignment(e));
10185 DeclareStruct("ecere::com::BuiltInContainer", false);
10187 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10188 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10189 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10190 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10191 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10192 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10193 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10194 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10195 MkInitializerList(initializers))));
10196 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10197 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10198 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10199 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10200 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10201 exp.expType = ProcessTypeString(templateString, false);
10202 exp.type = bracketsExp;
10203 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10205 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10206 MkInitializerList(structInitializers)))));
10207 ProcessExpressionType(expExt);
10211 exp.expType = ProcessTypeString("Container", false);
10212 Compiler_Error($"Couldn't determine type of array elements\n");
10218 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10220 FreeType(exp.expType);
10221 exp.expType = ReplaceThisClassType(thisClass);
10224 // Resolve structures here
10225 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10227 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10228 // TODO: Fix members reference...
10231 if(exp.expType.kind != enumType)
10234 String enumName = CopyString(exp.expType.enumName);
10236 // Fixed a memory leak on self-referencing C structs typedefs
10237 // by instantiating a new type rather than simply copying members
10238 // into exp.expType
10239 FreeType(exp.expType);
10240 exp.expType = Type { };
10241 exp.expType.kind = symbol.type.kind;
10242 exp.expType.refCount++;
10243 exp.expType.enumName = enumName;
10245 exp.expType.members = symbol.type.members;
10246 for(member = symbol.type.members.first; member; member = member.next)
10252 for(member = symbol.type.members.first; member; member = member.next)
10254 NamedLink value { name = CopyString(member.name) };
10255 exp.expType.members.Add(value);
10262 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10263 else if(exp.destType && !exp.destType.keepCast)
10265 if(!CheckExpressionType(exp, exp.destType, false))
10267 if(!exp.destType.count || unresolved)
10272 if(exp.destType.kind != ellipsisType)
10278 char expString[10240];
10279 expString[0] = '\0';
10281 PrintType(exp.destType, type2, false, true);
10283 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10285 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10286 else if(exp.type != dummyExp)
10287 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10292 char expString[10240] ;
10293 expString[0] = '\0';
10294 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10297 Compiler_Error($"unresolved identifier %s\n", expString);
10298 else if(exp.type != dummyExp)
10299 Compiler_Error($"couldn't determine type of %s\n", expString);
10310 PrintType(exp.expType, type1, false, true);
10311 PrintType(exp.destType, type2, false, true);
10314 //CheckExpressionType(exp, exp.destType, false);
10316 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10317 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10318 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10321 char expString[10240];
10322 expString[0] = '\0';
10323 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10326 CheckExpressionType(exp, exp.destType, false);
10328 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10329 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10330 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10332 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10333 FreeType(exp.expType);
10334 exp.destType.refCount++;
10335 exp.expType = exp.destType;
10340 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10342 Expression newExp { };
10343 char typeString[1024];
10344 OldList * specs = MkList();
10347 typeString[0] = '\0';
10351 if(exp.expType) exp.expType.refCount++;
10352 if(exp.expType) exp.expType.refCount++;
10353 exp.type = castExp;
10354 newExp.destType = exp.expType;
10356 PrintType(exp.expType, typeString, false, false);
10357 decl = SpecDeclFromString(typeString, specs, null);
10359 exp.cast.typeName = MkTypeName(specs, decl);
10360 exp.cast.exp = newExp;
10363 else if(unresolved)
10365 if(exp.identifier._class && exp.identifier._class.name)
10366 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10367 else if(exp.identifier.string && exp.identifier.string[0])
10368 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10370 else if(!exp.expType && exp.type != dummyExp)
10372 char expString[10240];
10373 expString[0] = '\0';
10374 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10375 Compiler_Error($"couldn't determine type of %s\n", expString);
10378 // Let's try to support any_object & typed_object here:
10380 ApplyAnyObjectLogic(exp);
10382 // Mark nohead classes as by reference, unless we're casting them to an integral type
10383 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10384 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10385 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10386 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType)))
10388 exp.byReference = true;
10390 yylloc = oldyylloc;
10393 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10395 // THIS CODE WILL FIND NEXT MEMBER...
10398 *curMember = (*curMember).next;
10400 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10402 *curMember = subMemberStack[--(*subMemberStackPos)];
10403 *curMember = (*curMember).next;
10406 // SKIP ALL PROPERTIES HERE...
10407 while((*curMember) && (*curMember).isProperty)
10408 *curMember = (*curMember).next;
10410 if(subMemberStackPos)
10412 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10414 subMemberStack[(*subMemberStackPos)++] = *curMember;
10416 *curMember = (*curMember).members.first;
10417 while(*curMember && (*curMember).isProperty)
10418 *curMember = (*curMember).next;
10426 if(subMemberStackPos && *subMemberStackPos)
10428 *curMember = subMemberStack[--(*subMemberStackPos)];
10429 *curMember = (*curMember).next;
10433 Class lastCurClass = *curClass;
10435 if(*curClass == _class) break; // REACHED THE END
10437 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10438 *curMember = (*curClass).membersAndProperties.first;
10441 while((*curMember) && (*curMember).isProperty)
10442 *curMember = (*curMember).next;
10443 if(subMemberStackPos)
10445 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10447 subMemberStack[(*subMemberStackPos)++] = *curMember;
10449 *curMember = (*curMember).members.first;
10450 while(*curMember && (*curMember).isProperty)
10451 *curMember = (*curMember).next;
10459 static void ProcessInitializer(Initializer init, Type type)
10463 case expInitializer:
10464 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10466 // TESTING THIS FOR SHUTTING = 0 WARNING
10467 if(init.exp && !init.exp.destType)
10469 FreeType(init.exp.destType);
10470 init.exp.destType = type;
10471 if(type) type.refCount++;
10475 ProcessExpressionType(init.exp);
10476 init.isConstant = init.exp.isConstant;
10482 Expression exp = init.exp;
10483 Instantiation inst = exp.instance;
10484 MembersInit members;
10486 init.type = listInitializer;
10487 init.list = MkList();
10491 for(members = inst.members->first; members; members = members.next)
10493 if(members.type == dataMembersInit)
10496 for(member = members.dataMembers->first; member; member = member.next)
10498 ListAdd(init.list, member.initializer);
10499 member.initializer = null;
10502 // Discard all MembersInitMethod
10505 FreeExpression(exp);
10507 case listInitializer:
10510 Type initializerType = null;
10511 Class curClass = null;
10512 DataMember curMember = null;
10513 DataMember subMemberStack[256];
10514 int subMemberStackPos = 0;
10516 if(type && type.kind == arrayType)
10517 initializerType = Dereference(type);
10518 else if(type && (type.kind == structType || type.kind == unionType))
10519 initializerType = type.members.first;
10521 for(i = init.list->first; i; i = i.next)
10523 if(type && type.kind == classType && type._class && type._class.registered)
10525 // 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)
10526 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10527 // TODO: Generate error on initializing a private data member this way from another module...
10530 if(!curMember.dataType)
10531 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10532 initializerType = curMember.dataType;
10535 ProcessInitializer(i, initializerType);
10536 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10537 initializerType = initializerType.next;
10539 init.isConstant = false;
10542 if(type && type.kind == arrayType)
10543 FreeType(initializerType);
10545 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10547 Compiler_Error($"Assigning list initializer to non list\n");
10554 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10558 case baseSpecifier:
10560 if(spec.specifier == THISCLASS)
10564 spec.type = nameSpecifier;
10565 spec.name = ReplaceThisClass(thisClass);
10566 spec.symbol = FindClass(spec.name);
10567 ProcessSpecifier(spec, declareStruct);
10572 case nameSpecifier:
10574 Symbol symbol = FindType(curContext, spec.name);
10576 DeclareType(symbol.type, true, true);
10577 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10578 DeclareStruct(spec.name, false);
10581 case enumSpecifier:
10586 for(e = spec.list->first; e; e = e.next)
10589 ProcessExpressionType(e.exp);
10594 case structSpecifier:
10595 case unionSpecifier:
10597 if(spec.definitions)
10600 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10602 ProcessClass(spec.definitions, symbol);
10605 for(def = spec.definitions->first; def; def = def.next)
10607 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10608 ProcessDeclaration(def.decl);
10615 case classSpecifier:
10617 Symbol classSym = FindClass(spec.name);
10618 if(classSym && classSym.registered && classSym.registered.type == structClass)
10619 DeclareStruct(spec.name, false);
10627 static void ProcessDeclarator(Declarator decl)
10631 case identifierDeclarator:
10632 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10634 FreeSpecifier(decl.identifier._class);
10635 decl.identifier._class = null;
10638 case arrayDeclarator:
10640 ProcessExpressionType(decl.array.exp);
10641 case structDeclarator:
10642 case bracketsDeclarator:
10643 case functionDeclarator:
10644 case pointerDeclarator:
10645 case extendedDeclarator:
10646 case extendedDeclaratorEnd:
10647 if(decl.declarator)
10648 ProcessDeclarator(decl.declarator);
10649 if(decl.type == functionDeclarator)
10651 Identifier id = GetDeclId(decl);
10652 if(id && id._class)
10656 qualifiers = MkListOne(id._class);
10659 if(!decl.function.parameters)
10660 decl.function.parameters = MkList();
10661 decl.function.parameters->Insert(null, param);
10664 if(decl.function.parameters)
10668 for(param = decl.function.parameters->first; param; param = param.next)
10670 if(param.qualifiers && param.qualifiers->first)
10672 Specifier spec = param.qualifiers->first;
10673 if(spec && spec.specifier == TYPED_OBJECT)
10675 Declarator d = param.declarator;
10678 qualifiers = MkListOne(MkSpecifier(VOID));
10679 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10682 FreeList(param.qualifiers, FreeSpecifier);
10684 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10685 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10687 decl.function.parameters->Insert(param, newParam);
10690 else if(spec && spec.specifier == ANY_OBJECT)
10692 Declarator d = param.declarator;
10694 FreeList(param.qualifiers, FreeSpecifier);
10696 param.qualifiers = MkListOne(MkSpecifier(VOID));
10697 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10699 else if(spec.specifier == THISCLASS)
10703 spec.type = nameSpecifier;
10704 spec.name = ReplaceThisClass(thisClass);
10705 spec.symbol = FindClass(spec.name);
10706 ProcessSpecifier(spec, false);
10711 if(param.declarator)
10712 ProcessDeclarator(param.declarator);
10720 static void ProcessDeclaration(Declaration decl)
10725 case initDeclaration:
10727 bool declareStruct = false;
10729 lineNum = decl.pos.line;
10730 column = decl.pos.col;
10733 if(decl.declarators)
10737 for(d = decl.declarators->first; d; d = d.next)
10739 Type type, subType;
10740 ProcessDeclarator(d.declarator);
10742 type = ProcessType(decl.specifiers, d.declarator);
10746 ProcessInitializer(d.initializer, type);
10748 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10750 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10751 d.initializer.exp.type == instanceExp)
10753 if(type.kind == classType && type._class ==
10754 d.initializer.exp.expType._class)
10756 Instantiation inst = d.initializer.exp.instance;
10757 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10759 d.initializer.exp.instance = null;
10760 if(decl.specifiers)
10761 FreeList(decl.specifiers, FreeSpecifier);
10762 FreeList(decl.declarators, FreeInitDeclarator);
10766 decl.type = instDeclaration;
10771 for(subType = type; subType;)
10773 if(subType.kind == classType)
10775 declareStruct = true;
10778 else if(subType.kind == pointerType)
10780 else if(subType.kind == arrayType)
10781 subType = subType.arrayType;
10791 if(decl.specifiers)
10794 for(s = decl.specifiers->first; s; s = s.next)
10796 ProcessSpecifier(s, declareStruct);
10801 case instDeclaration:
10803 ProcessInstantiationType(decl.inst);
10806 case structDeclaration:
10810 bool declareStruct = false;
10812 if(decl.declarators)
10814 for(d = decl.declarators->first; d; d = d.next)
10816 Type type = ProcessType(decl.specifiers, d.declarator);
10818 ProcessDeclarator(d);
10819 for(subType = type; subType;)
10821 if(subType.kind == classType)
10823 declareStruct = true;
10826 else if(subType.kind == pointerType)
10828 else if(subType.kind == arrayType)
10829 subType = subType.arrayType;
10836 if(decl.specifiers)
10838 for(spec = decl.specifiers->first; spec; spec = spec.next)
10839 ProcessSpecifier(spec, declareStruct);
10846 static FunctionDefinition curFunction;
10848 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10850 char propName[1024], propNameM[1024];
10851 char getName[1024], setName[1024];
10854 DeclareProperty(prop, setName, getName);
10856 // eInstance_FireWatchers(object, prop);
10857 strcpy(propName, "__ecereProp_");
10858 FullClassNameCat(propName, prop._class.fullName, false);
10859 strcat(propName, "_");
10860 // strcat(propName, prop.name);
10861 FullClassNameCat(propName, prop.name, true);
10862 MangleClassName(propName);
10864 strcpy(propNameM, "__ecerePropM_");
10865 FullClassNameCat(propNameM, prop._class.fullName, false);
10866 strcat(propNameM, "_");
10867 // strcat(propNameM, prop.name);
10868 FullClassNameCat(propNameM, prop.name, true);
10869 MangleClassName(propNameM);
10871 if(prop.isWatchable)
10874 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10875 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10876 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10879 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10880 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10881 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10887 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10888 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10889 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10892 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10893 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10894 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10897 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10898 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10899 curFunction.propSet.fireWatchersDone = true;
10902 static void ProcessStatement(Statement stmt)
10906 lineNum = stmt.pos.line;
10907 column = stmt.pos.col;
10912 ProcessStatement(stmt.labeled.stmt);
10915 // This expression should be constant...
10916 if(stmt.caseStmt.exp)
10918 FreeType(stmt.caseStmt.exp.destType);
10919 stmt.caseStmt.exp.destType = curSwitchType;
10920 if(curSwitchType) curSwitchType.refCount++;
10921 ProcessExpressionType(stmt.caseStmt.exp);
10922 ComputeExpression(stmt.caseStmt.exp);
10924 if(stmt.caseStmt.stmt)
10925 ProcessStatement(stmt.caseStmt.stmt);
10929 if(stmt.compound.context)
10934 Statement prevCompound = curCompound;
10935 Context prevContext = curContext;
10937 if(!stmt.compound.isSwitch)
10939 curCompound = stmt;
10940 curContext = stmt.compound.context;
10943 if(stmt.compound.declarations)
10945 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10946 ProcessDeclaration(decl);
10948 if(stmt.compound.statements)
10950 for(s = stmt.compound.statements->first; s; s = s.next)
10951 ProcessStatement(s);
10954 curContext = prevContext;
10955 curCompound = prevCompound;
10959 case expressionStmt:
10962 if(stmt.expressions)
10964 for(exp = stmt.expressions->first; exp; exp = exp.next)
10965 ProcessExpressionType(exp);
10973 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10974 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10975 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10976 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10978 ProcessExpressionType(exp);
10980 if(stmt.ifStmt.stmt)
10981 ProcessStatement(stmt.ifStmt.stmt);
10982 if(stmt.ifStmt.elseStmt)
10983 ProcessStatement(stmt.ifStmt.elseStmt);
10988 Type oldSwitchType = curSwitchType;
10989 if(stmt.switchStmt.exp)
10992 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11002 e.exp.destType = destType;
11005 ProcessExpressionType(exp);
11008 curSwitchType = exp.expType;
11011 ProcessStatement(stmt.switchStmt.stmt);
11012 curSwitchType = oldSwitchType;
11017 if(stmt.whileStmt.exp)
11021 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11022 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11023 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11024 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11026 ProcessExpressionType(exp);
11029 if(stmt.whileStmt.stmt)
11030 ProcessStatement(stmt.whileStmt.stmt);
11035 if(stmt.doWhile.exp)
11039 if(stmt.doWhile.exp->last)
11041 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11042 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11043 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11045 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11047 ProcessExpressionType(exp);
11050 if(stmt.doWhile.stmt)
11051 ProcessStatement(stmt.doWhile.stmt);
11057 if(stmt.forStmt.init)
11058 ProcessStatement(stmt.forStmt.init);
11060 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11062 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11063 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11064 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11067 if(stmt.forStmt.check)
11068 ProcessStatement(stmt.forStmt.check);
11069 if(stmt.forStmt.increment)
11071 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11072 ProcessExpressionType(exp);
11075 if(stmt.forStmt.stmt)
11076 ProcessStatement(stmt.forStmt.stmt);
11081 Identifier id = stmt.forEachStmt.id;
11082 OldList * exp = stmt.forEachStmt.exp;
11083 OldList * filter = stmt.forEachStmt.filter;
11084 Statement block = stmt.forEachStmt.stmt;
11085 char iteratorType[1024];
11088 bool isBuiltin = exp && exp->last &&
11089 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11090 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11091 Expression arrayExp;
11092 char * typeString = null;
11093 int builtinCount = 0;
11095 for(e = exp ? exp->first : null; e; e = e.next)
11099 FreeType(e.destType);
11100 e.destType = ProcessTypeString("Container", false);
11102 if(!isBuiltin || e.next)
11103 ProcessExpressionType(e);
11106 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11107 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11108 eClass_IsDerived(source._class.registered, containerClass)))
11110 Class _class = source ? source._class.registered : null;
11112 Expression expIt = null;
11113 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11114 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11115 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11116 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11117 stmt.type = compoundStmt;
11119 stmt.compound.context = Context { };
11120 stmt.compound.context.parent = curContext;
11121 curContext = stmt.compound.context;
11123 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11125 Class mapClass = eSystem_FindClass(privateModule, "Map");
11126 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11127 isCustomAVLTree = true;
11128 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11130 else if(eClass_IsDerived(source._class.registered, mapClass))
11133 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11134 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11136 Class listClass = eSystem_FindClass(privateModule, "List");
11138 isList = eClass_IsDerived(source._class.registered, listClass);
11144 OldList * specs = MkList();
11145 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11146 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11147 stmt.compound.declarations = MkListOne(
11148 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11149 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11150 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11151 MkInitializerAssignment(MkExpBrackets(exp))))));
11156 char typeStringBuf[1024];
11158 // TODO: Merge this code?
11159 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11160 if(((Expression)exp->last).type == castExp)
11162 TypeName typeName = ((Expression)exp->last).cast.typeName;
11164 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11167 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11168 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11169 arrayExp.destType._class.registered.templateArgs)
11171 Class templateClass = arrayExp.destType._class.registered;
11172 typeString = templateClass.templateArgs[2].dataTypeString;
11174 else if(arrayExp.list)
11176 // Guess type from expressions in the array
11178 for(e = arrayExp.list->first; e; e = e.next)
11180 ProcessExpressionType(e);
11183 if(!type) { type = e.expType; type.refCount++; }
11186 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11187 if(!MatchTypeExpression(e, type, null, false))
11193 e = arrayExp.list->first;
11194 ProcessExpressionType(e);
11197 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11198 if(!MatchTypeExpression(e, type, null, false))
11200 FreeType(e.expType);
11211 FreeType(e.expType);
11218 typeStringBuf[0] = '\0';
11219 PrintType(type, typeStringBuf, false, true);
11220 typeString = typeStringBuf;
11226 OldList * initializers = MkList();
11228 OldList * specs = MkList();
11233 builtinCount = arrayExp.list->count;
11234 type = ProcessTypeString(typeString, false);
11235 while(e = arrayExp.list->first)
11237 arrayExp.list->Remove(e);
11240 ProcessExpressionType(e);
11241 ListAdd(initializers, MkInitializerAssignment(e));
11244 delete arrayExp.list;
11246 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11247 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11248 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11250 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11252 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11253 ), MkInitializerList(initializers)))));
11254 FreeList(exp, FreeExpression);
11258 arrayExp.expType = ProcessTypeString("Container", false);
11259 Compiler_Error($"Couldn't determine type of array elements\n");
11264 OldList * specs = MkList();
11266 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11267 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11268 stmt.compound.declarations = MkListOne(
11269 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11270 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11271 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11272 MkInitializerAssignment(MkExpBrackets(exp))))));
11275 else if(isLinkList && !isList)
11278 OldList * specs = MkList();
11279 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11280 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11281 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11282 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11283 MkInitializerAssignment(MkExpBrackets(exp))))));
11285 /*else if(isCustomAVLTree)
11288 OldList * specs = MkList();
11289 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11290 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11291 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11292 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11293 MkInitializerAssignment(MkExpBrackets(exp))))));
11295 else if(_class.templateArgs)
11298 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11300 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11302 stmt.compound.declarations = MkListOne(
11303 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11304 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11305 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11307 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11309 if(block && block.type == compoundStmt && block.compound.context)
11311 block.compound.context.parent = stmt.compound.context;
11315 block = MkIfStmt(filter, block, null);
11319 stmt.compound.statements = MkListOne(MkForStmt(
11320 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11321 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11322 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11323 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11325 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11326 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11327 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11332 //OldList * specs = MkList();
11333 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11335 sprintf(count, "%d", builtinCount);
11337 stmt.compound.statements = MkListOne(MkForStmt(
11338 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11339 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11340 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11341 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11345 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11346 stmt.compound.statements = MkListOne(MkForStmt(
11347 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11348 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11349 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11350 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11353 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11354 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11355 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11357 else if(isLinkList && !isList)
11359 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11360 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11361 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11362 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11364 stmt.compound.statements = MkListOne(MkForStmt(
11365 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11366 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11367 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11372 OldList * specs = MkList();
11373 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11374 stmt.compound.statements = MkListOne(MkForStmt(
11375 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11376 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11377 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11378 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11379 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11382 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11383 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11384 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11386 /*else if(isCustomAVLTree)
11388 stmt.compound.statements = MkListOne(MkForStmt(
11389 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11390 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11391 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11392 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11395 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11396 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11397 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11401 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11402 MkIdentifier("Next")), null)), block));
11404 ProcessExpressionType(expIt);
11405 if(stmt.compound.declarations->first)
11406 ProcessDeclaration(stmt.compound.declarations->first);
11409 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11411 ProcessStatement(stmt);
11412 curContext = stmt.compound.context.parent;
11417 Compiler_Error($"Expression is not a container\n");
11430 if(stmt.expressions)
11432 for(exp = stmt.expressions->first; exp; exp = exp.next)
11436 if(curFunction && !curFunction.type)
11437 curFunction.type = ProcessType(
11438 curFunction.specifiers, curFunction.declarator);
11439 FreeType(exp.destType);
11440 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11441 if(exp.destType) exp.destType.refCount++;
11443 ProcessExpressionType(exp);
11448 case badDeclarationStmt:
11450 ProcessDeclaration(stmt.decl);
11456 if(stmt.asmStmt.inputFields)
11458 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11459 if(field.expression)
11460 ProcessExpressionType(field.expression);
11462 if(stmt.asmStmt.outputFields)
11464 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11465 if(field.expression)
11466 ProcessExpressionType(field.expression);
11468 if(stmt.asmStmt.clobberedFields)
11470 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11472 if(field.expression)
11473 ProcessExpressionType(field.expression);
11480 PropertyWatch propWatch;
11481 OldList * watches = stmt._watch.watches;
11482 Expression object = stmt._watch.object;
11483 Expression watcher = stmt._watch.watcher;
11485 ProcessExpressionType(watcher);
11487 ProcessExpressionType(object);
11491 if(watcher || thisClass)
11493 External external = curExternal;
11494 Context context = curContext;
11496 stmt.type = expressionStmt;
11497 stmt.expressions = MkList();
11499 curExternal = external.prev;
11501 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11503 ClassFunction func;
11504 char watcherName[1024];
11505 Class watcherClass = watcher ?
11506 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11507 External createdExternal;
11509 // Create a declaration above
11510 External externalDecl = MkExternalDeclaration(null);
11511 ast->Insert(curExternal.prev, externalDecl);
11513 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11514 if(propWatch.deleteWatch)
11515 strcat(watcherName, "_delete");
11519 for(propID = propWatch.properties->first; propID; propID = propID.next)
11521 strcat(watcherName, "_");
11522 strcat(watcherName, propID.string);
11526 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11528 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11529 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11530 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11531 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11532 ProcessClassFunctionBody(func, propWatch.compound);
11533 propWatch.compound = null;
11535 //afterExternal = afterExternal ? afterExternal : curExternal;
11537 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11538 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11540 createdExternal.symbol.idCode = external.symbol.idCode;
11542 curExternal = createdExternal;
11543 ProcessFunction(createdExternal.function);
11546 // Create a declaration above
11548 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11549 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11550 externalDecl.declaration = decl;
11551 if(decl.symbol && !decl.symbol.pointerExternal)
11552 decl.symbol.pointerExternal = externalDecl;
11555 if(propWatch.deleteWatch)
11557 OldList * args = MkList();
11558 ListAdd(args, CopyExpression(object));
11559 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11560 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11561 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11565 Class _class = object.expType._class.registered;
11568 for(propID = propWatch.properties->first; propID; propID = propID.next)
11570 char propName[1024];
11571 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11574 char getName[1024], setName[1024];
11575 OldList * args = MkList();
11577 DeclareProperty(prop, setName, getName);
11579 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11580 strcpy(propName, "__ecereProp_");
11581 FullClassNameCat(propName, prop._class.fullName, false);
11582 strcat(propName, "_");
11583 // strcat(propName, prop.name);
11584 FullClassNameCat(propName, prop.name, true);
11586 ListAdd(args, CopyExpression(object));
11587 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11588 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11589 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11591 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11594 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11599 Compiler_Error($"Invalid watched object\n");
11602 curExternal = external;
11603 curContext = context;
11606 FreeExpression(watcher);
11608 FreeExpression(object);
11609 FreeList(watches, FreePropertyWatch);
11612 Compiler_Error($"No observer specified and not inside a _class\n");
11616 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11618 ProcessStatement(propWatch.compound);
11624 case fireWatchersStmt:
11626 OldList * watches = stmt._watch.watches;
11627 Expression object = stmt._watch.object;
11629 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11630 // printf("%X\n", watches);
11631 // printf("%X\n", stmt._watch.watches);
11633 ProcessExpressionType(object);
11638 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11644 stmt.type = expressionStmt;
11645 stmt.expressions = MkList();
11647 // Check if we're inside a property set
11648 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11650 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11654 //Compiler_Error($"No property specified and not inside a property set\n");
11658 for(propID = watches->first; propID; propID = propID.next)
11660 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11663 CreateFireWatcher(prop, object, stmt);
11666 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11671 // Fire all properties!
11674 for(base = _class; base; base = base.base)
11676 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11678 if(prop.isProperty && prop.isWatchable)
11680 CreateFireWatcher(prop, object, stmt);
11687 FreeExpression(object);
11688 FreeList(watches, FreeIdentifier);
11691 Compiler_Error($"Invalid object specified and not inside a class\n");
11695 case stopWatchingStmt:
11697 OldList * watches = stmt._watch.watches;
11698 Expression object = stmt._watch.object;
11699 Expression watcher = stmt._watch.watcher;
11702 ProcessExpressionType(object);
11704 ProcessExpressionType(watcher);
11707 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11709 if(watcher || thisClass)
11715 stmt.type = expressionStmt;
11716 stmt.expressions = MkList();
11721 // eInstance_StopWatching(object, null, watcher);
11723 ListAdd(args, CopyExpression(object));
11724 ListAdd(args, MkExpConstant("0"));
11725 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11726 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11730 for(propID = watches->first; propID; propID = propID.next)
11732 char propName[1024];
11733 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11736 char getName[1024], setName[1024];
11737 OldList * args = MkList();
11739 DeclareProperty(prop, setName, getName);
11741 // eInstance_StopWatching(object, prop, watcher);
11742 strcpy(propName, "__ecereProp_");
11743 FullClassNameCat(propName, prop._class.fullName, false);
11744 strcat(propName, "_");
11745 // strcat(propName, prop.name);
11746 FullClassNameCat(propName, prop.name, true);
11747 MangleClassName(propName);
11749 ListAdd(args, CopyExpression(object));
11750 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11751 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11752 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11755 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11760 FreeExpression(object);
11762 FreeExpression(watcher);
11763 FreeList(watches, FreeIdentifier);
11766 Compiler_Error($"Invalid object specified and not inside a class\n");
11769 Compiler_Error($"No observer specified and not inside a class\n");
11776 static void ProcessFunction(FunctionDefinition function)
11778 Identifier id = GetDeclId(function.declarator);
11779 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11780 Type type = symbol ? symbol.type : null;
11781 Class oldThisClass = thisClass;
11782 Context oldTopContext = topContext;
11784 yylloc = function.loc;
11785 // Process thisClass
11787 if(type && type.thisClass)
11789 Symbol classSym = type.thisClass;
11790 Class _class = type.thisClass.registered;
11791 char className[1024];
11792 char structName[1024];
11793 Declarator funcDecl;
11796 bool typedObject = false;
11798 if(_class && !_class.base)
11800 _class = currentClass;
11801 if(_class && !_class.symbol)
11802 _class.symbol = FindClass(_class.fullName);
11803 classSym = _class ? _class.symbol : null;
11804 typedObject = true;
11807 thisClass = _class;
11809 if(inCompiler && _class)
11811 if(type.kind == functionType)
11813 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11815 //TypeName param = symbol.type.params.first;
11816 Type param = symbol.type.params.first;
11817 symbol.type.params.Remove(param);
11818 //FreeTypeName(param);
11821 if(type.classObjectType != classPointer)
11823 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11824 symbol.type.staticMethod = true;
11825 symbol.type.thisClass = null;
11827 // HIGH DANGER: VERIFYING THIS...
11828 symbol.type.extraParam = false;
11832 strcpy(className, "__ecereClass_");
11833 FullClassNameCat(className, _class.fullName, true);
11835 MangleClassName(className);
11838 FullClassNameCat(structName, _class.fullName, false);
11843 funcDecl = GetFuncDecl(function.declarator);
11846 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11848 TypeName param = funcDecl.function.parameters->first;
11849 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11851 funcDecl.function.parameters->Remove(param);
11852 FreeTypeName(param);
11856 // DANGER: Watch for this... Check if it's a Conversion?
11857 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11859 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11860 if(!function.propertyNoThis)
11862 TypeName thisParam;
11864 if(type.classObjectType != classPointer)
11866 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11867 if(!funcDecl.function.parameters)
11868 funcDecl.function.parameters = MkList();
11869 funcDecl.function.parameters->Insert(null, thisParam);
11874 if(type.classObjectType != classPointer)
11876 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11877 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11880 thisParam = TypeName
11882 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11883 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11885 funcDecl.function.parameters->Insert(null, thisParam);
11890 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11892 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11893 funcDecl = GetFuncDecl(initDecl.declarator);
11896 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11898 TypeName param = funcDecl.function.parameters->first;
11899 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11901 funcDecl.function.parameters->Remove(param);
11902 FreeTypeName(param);
11906 if(type.classObjectType != classPointer)
11908 // DANGER: Watch for this... Check if it's a Conversion?
11909 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11911 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11913 if(!funcDecl.function.parameters)
11914 funcDecl.function.parameters = MkList();
11915 funcDecl.function.parameters->Insert(null, thisParam);
11922 // Add this to the context
11925 if(type.classObjectType != classPointer)
11927 thisSymbol = Symbol
11929 string = CopyString("this");
11930 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11932 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11934 if(typedObject && thisSymbol.type)
11936 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11937 thisSymbol.type.byReference = type.byReference;
11939 thisSymbol = Symbol { string = CopyString("class") };
11940 function.body.compound.context.symbols.Add(thisSymbol);
11946 // Pointer to class data
11948 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11950 DataMember member = null;
11953 for(base = _class; base && base.type != systemClass; base = base.next)
11955 for(member = base.membersAndProperties.first; member; member = member.next)
11956 if(!member.isProperty)
11962 for(member = _class.membersAndProperties.first; member; member = member.next)
11963 if(!member.isProperty)
11967 char pointerName[1024];
11970 Initializer initializer;
11971 Expression exp, bytePtr;
11973 strcpy(pointerName, "__ecerePointer_");
11974 FullClassNameCat(pointerName, _class.fullName, false);
11976 char className[1024];
11977 strcpy(className, "__ecereClass_");
11978 FullClassNameCat(className, classSym.string, true);
11979 MangleClassName(className);
11982 DeclareClass(classSym, className);
11986 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11991 sprintf(string, "%d", _class.offset);
11992 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11996 // ([bytePtr] + [className]->offset)
11997 exp = QBrackets(MkExpOp(bytePtr, '+',
11998 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12001 // (this ? [exp] : 0)
12002 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12006 kind = pointerType;
12007 type = Type { refCount = 1, kind = voidType };
12012 yylloc = function.body.loc;
12013 // ([structName] *) [exp]
12014 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12015 initializer = MkInitializerAssignment(
12016 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12018 // [structName] * [pointerName] = [initializer];
12019 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12022 Context prevContext = curContext;
12023 curContext = function.body.compound.context;
12025 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12026 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12028 curContext = prevContext;
12032 decl.symbol = null;
12034 if(!function.body.compound.declarations)
12035 function.body.compound.declarations = MkList();
12036 function.body.compound.declarations->Insert(null, decl);
12042 // Loop through the function and replace undeclared identifiers
12043 // which are a member of the class (methods, properties or data)
12044 // by "this.[member]"
12051 FreeSpecifier(id._class);
12054 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12056 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12057 id = GetDeclId(initDecl.declarator);
12059 FreeSpecifier(id._class);
12064 topContext = function.body.compound.context;
12066 FunctionDefinition oldFunction = curFunction;
12067 curFunction = function;
12069 ProcessStatement(function.body);
12071 // If this is a property set and no firewatchers has been done yet, add one here
12072 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12074 Statement prevCompound = curCompound;
12075 Context prevContext = curContext;
12077 Statement fireWatchers = MkFireWatchersStmt(null, null);
12078 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12079 ListAdd(function.body.compound.statements, fireWatchers);
12081 curCompound = function.body;
12082 curContext = function.body.compound.context;
12084 ProcessStatement(fireWatchers);
12086 curContext = prevContext;
12087 curCompound = prevCompound;
12091 curFunction = oldFunction;
12094 if(function.declarator)
12096 ProcessDeclarator(function.declarator);
12099 topContext = oldTopContext;
12100 thisClass = oldThisClass;
12103 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12104 static void ProcessClass(OldList definitions, Symbol symbol)
12107 External external = curExternal;
12108 Class regClass = symbol ? symbol.registered : null;
12110 // Process all functions
12111 for(def = definitions.first; def; def = def.next)
12113 if(def.type == functionClassDef)
12115 if(def.function.declarator)
12116 curExternal = def.function.declarator.symbol.pointerExternal;
12118 curExternal = external;
12120 ProcessFunction((FunctionDefinition)def.function);
12122 else if(def.type == declarationClassDef)
12124 if(def.decl.type == instDeclaration)
12126 thisClass = regClass;
12127 ProcessInstantiationType(def.decl.inst);
12133 Class backThisClass = thisClass;
12134 if(regClass) thisClass = regClass;
12135 ProcessDeclaration(def.decl);
12136 thisClass = backThisClass;
12139 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12141 MemberInit defProperty;
12143 // Add this to the context
12144 Symbol thisSymbol = Symbol
12146 string = CopyString("this");
12147 type = regClass ? MkClassType(regClass.fullName) : null;
12149 globalContext.symbols.Add((BTNode)thisSymbol);
12151 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12153 thisClass = regClass;
12154 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12158 globalContext.symbols.Remove((BTNode)thisSymbol);
12159 FreeSymbol(thisSymbol);
12161 else if(def.type == propertyClassDef && def.propertyDef)
12163 PropertyDef prop = def.propertyDef;
12165 // Add this to the context
12167 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12168 globalContext.symbols.Add(thisSymbol);
12171 thisClass = regClass;
12178 string = CopyString("this");
12179 type = MkClassType(regClass.fullName);
12181 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12184 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12185 ProcessStatement(prop.setStmt);
12193 string = CopyString("this");
12194 type = MkClassType(regClass.fullName);
12196 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12199 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12200 ProcessStatement(prop.getStmt);
12208 string = CopyString("this");
12209 type = MkClassType(regClass.fullName);
12211 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12214 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12215 ProcessStatement(prop.issetStmt);
12221 globalContext.symbols.Remove(thisSymbol);
12222 FreeSymbol(thisSymbol);
12225 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12227 PropertyWatch propertyWatch = def.propertyWatch;
12229 thisClass = regClass;
12230 if(propertyWatch.compound)
12234 string = CopyString("this");
12235 type = regClass ? MkClassType(regClass.fullName) : null;
12238 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12240 curExternal = null;
12241 ProcessStatement(propertyWatch.compound);
12248 void DeclareFunctionUtil(String s)
12250 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12255 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12256 strcpy(name, "__ecereFunction_");
12257 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12258 DeclareFunction(function, name);
12262 void ComputeDataTypes()
12266 External after = null;
12268 currentClass = null;
12270 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12272 for(external = ast->first; external; external = external.next)
12274 if(external.type == declarationExternal)
12276 Declaration decl = external.declaration;
12279 OldList * decls = decl.declarators;
12282 InitDeclarator initDecl = decls->first;
12285 Declarator declarator = initDecl.declarator;
12286 if(declarator && declarator.type == identifierDeclarator)
12288 Identifier id = declarator.identifier;
12289 if(id && id.string)
12291 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12293 external.symbol.id = -1001, external.symbol.idCode = -1001;
12304 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12305 ast->Insert(after, temp);
12306 curExternal = temp;
12308 DeclareFunctionUtil("eSystem_New");
12309 DeclareFunctionUtil("eSystem_New0");
12310 DeclareFunctionUtil("eSystem_Renew");
12311 DeclareFunctionUtil("eSystem_Renew0");
12312 DeclareFunctionUtil("eClass_GetProperty");
12314 DeclareStruct("ecere::com::Class", false);
12315 DeclareStruct("ecere::com::Instance", false);
12316 DeclareStruct("ecere::com::Property", false);
12317 DeclareStruct("ecere::com::DataMember", false);
12318 DeclareStruct("ecere::com::Method", false);
12319 DeclareStruct("ecere::com::SerialBuffer", false);
12320 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12324 for(external = ast->first; external; external = external.next)
12326 afterExternal = curExternal = external;
12327 if(external.type == functionExternal)
12329 currentClass = external.function._class;
12330 ProcessFunction(external.function);
12332 // There shouldn't be any _class member access here anyways...
12333 else if(external.type == declarationExternal)
12335 currentClass = null;
12336 ProcessDeclaration(external.declaration);
12338 else if(external.type == classExternal)
12340 ClassDefinition _class = external._class;
12341 currentClass = external.symbol.registered;
12342 if(_class.definitions)
12344 ProcessClass(_class.definitions, _class.symbol);
12348 // Free class data...
12349 ast->Remove(external);
12353 else if(external.type == nameSpaceExternal)
12355 thisNameSpace = external.id.string;
12358 currentClass = null;
12359 thisNameSpace = null;
12361 delete temp.symbol;