4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
37 uint internalValueCounter;
40 Time findSymbolTotalTime;
43 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
44 /*static */public void PrintExpression(Expression exp, char * string)
50 bool backOutputLineNumbers = outputLineNumbers;
51 outputLineNumbers = false;
54 OutputExpression(exp, f);
56 count = strlen(string);
57 count += f.Read(string + count, 1, 1023);
61 outputLineNumbers = backOutputLineNumbers;
65 Type ProcessTemplateParameterType(TemplateParameter param)
67 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
69 // TOFIX: Will need to free this Type
72 if(param.dataTypeString)
73 param.baseType = ProcessTypeString(param.dataTypeString, false);
75 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
77 return param.baseType;
82 bool NeedCast(Type type1, Type type2)
84 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
86 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
91 if(type1.kind == type2.kind)
102 if(type1.passAsTemplate && !type2.passAsTemplate)
104 return type1.isSigned != type2.isSigned;
106 return type1._class != type2._class;
108 return (type1.type && type2.type && type1.type.constant != type2.type.constant) || NeedCast(type1.type, type2.type);
110 return true; //false; ????
116 static void ReplaceClassMembers(Expression exp, Class _class)
118 if(exp.type == identifierExp && exp.identifier)
120 Identifier id = exp.identifier;
122 Symbol symbol = null;
123 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
125 // First, check if the identifier is declared inside the function
126 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
128 symbol = (Symbol)ctx.symbols.FindString(id.string);
133 // If it is not, check if it is a member of the _class
134 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
136 Property prop = eClass_FindProperty(_class, id.string, privateModule);
137 Method method = null;
138 DataMember member = null;
139 ClassProperty classProp = null;
142 method = eClass_FindMethod(_class, id.string, privateModule);
145 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
146 if(!prop && !method && !member)
148 classProp = eClass_FindClassProperty(_class, id.string);
150 if(prop || method || member || classProp)
152 // Replace by this.[member]
153 exp.type = memberExp;
154 exp.member.member = id;
155 exp.member.memberType = unresolvedMember;
156 exp.member.exp = QMkExpId("this");
157 //exp.member.exp.loc = exp.loc;
158 exp.addedThis = true;
160 else if(_class && _class.templateParams.first)
163 for(sClass = _class; sClass; sClass = sClass.base)
165 if(sClass.templateParams.first)
167 ClassTemplateParameter param;
168 for(param = sClass.templateParams.first; param; param = param.next)
170 if(param.type == expression && !strcmp(param.name, id.string))
172 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
177 OldList * specs = MkList();
179 FreeIdentifier(exp.member.member);
181 ProcessExpressionType(argExp);
183 decl = SpecDeclFromString(param.dataTypeString, specs, null);
185 exp.expType = ProcessType(specs, decl);
187 // *[expType] *[argExp]
188 exp.type = bracketsExp;
189 exp.list = MkListOne(MkExpOp(null, '*',
190 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
201 ////////////////////////////////////////////////////////////////////////
202 // PRINTING ////////////////////////////////////////////////////////////
203 ////////////////////////////////////////////////////////////////////////
205 public char * PrintInt(int64 result)
209 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
211 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
212 if(result > MAXINT || result < MININT)
214 return CopyString(temp);
217 public char * PrintUInt(uint64 result)
220 if(result > MAXDWORD)
221 sprintf(temp, FORMAT64HEXLL /*"0x%I64X"*/, result);
222 else if(result > MAXINT)
223 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
225 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
226 return CopyString(temp);
229 public char * PrintInt64(int64 result)
232 if(result > MAXINT || result < MININT)
233 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
235 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
236 return CopyString(temp);
239 public char * PrintUInt64(uint64 result)
242 if(result > MAXDWORD)
243 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
244 else if(result > MAXINT)
245 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
247 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
248 return CopyString(temp);
251 public char * PrintHexUInt(uint64 result)
254 if(result > MAXDWORD)
255 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
257 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
258 if(result > MAXDWORD)
260 return CopyString(temp);
263 public char * PrintHexUInt64(uint64 result)
266 if(result > MAXDWORD)
267 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
269 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
270 return CopyString(temp);
273 public char * PrintShort(short result)
276 sprintf(temp, "%d", (unsigned short)result);
277 return CopyString(temp);
280 public char * PrintUShort(unsigned short result)
284 sprintf(temp, "0x%X", (int)result);
286 sprintf(temp, "%d", (int)result);
287 return CopyString(temp);
290 public char * PrintChar(char result)
293 if(result > 0 && isprint(result))
294 sprintf(temp, "'%c'", result);
296 sprintf(temp, "%d", (int)result);
298 //sprintf(temp, "%#X", result);
299 sprintf(temp, "0x%X", (unsigned char)result);
300 return CopyString(temp);
303 public char * PrintUChar(unsigned char result)
306 sprintf(temp, "0x%X", result);
307 return CopyString(temp);
310 public char * PrintFloat(float result)
316 strcpy(temp, "-inf");
320 else if(result.isNan)
323 strcpy(temp, "-nan");
328 sprintf(temp, "%.16ff", result);
329 return CopyString(temp);
332 public char * PrintDouble(double result)
338 strcpy(temp, "-inf");
342 else if(result.isNan)
345 strcpy(temp, "-nan");
350 sprintf(temp, "%.16f", result);
351 return CopyString(temp);
354 ////////////////////////////////////////////////////////////////////////
355 ////////////////////////////////////////////////////////////////////////
357 //public Operand GetOperand(Expression exp);
359 #define GETVALUE(name, t) \
360 public bool GetOp##name(Operand op2, t * value2) \
362 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
363 else if(op2.kind == intType) *value2 = (t) op2.ui; \
364 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
365 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
366 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
367 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
368 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
369 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
370 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
371 else if(op2.kind == shortType) *value2 = (t) op2.us; \
372 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
373 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
374 else if(op2.kind == floatType) *value2 = (t) op2.f; \
375 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
376 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
381 public bool Get##name(Expression exp, t * value2) \
383 Operand op2 = GetOperand(exp); \
384 return GetOp##name(op2, value2); \
387 // To help the debugger currently not preprocessing...
390 GETVALUE(Int, HELP(int));
391 GETVALUE(UInt, HELP(unsigned int));
392 GETVALUE(Int64, HELP(int64));
393 GETVALUE(UInt64, HELP(uint64));
394 GETVALUE(IntPtr, HELP(intptr));
395 GETVALUE(UIntPtr, HELP(uintptr));
396 GETVALUE(IntSize, HELP(intsize));
397 GETVALUE(UIntSize, HELP(uintsize));
398 GETVALUE(Short, HELP(short));
399 GETVALUE(UShort, HELP(unsigned short));
400 GETVALUE(Char, HELP(char));
401 GETVALUE(UChar, HELP(unsigned char));
402 GETVALUE(Float, HELP(float));
403 GETVALUE(Double, HELP(double));
405 void ComputeExpression(Expression exp);
407 void ComputeClassMembers(Class _class, bool isMember)
409 DataMember member = isMember ? (DataMember) _class : null;
410 Context context = isMember ? null : SetupTemplatesContext(_class);
411 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
412 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
414 int unionMemberOffset = 0;
418 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
419 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
424 member.memberOffset = 0;
425 if(targetBits < sizeof(void *) * 8)
426 member.structAlignment = 0;
428 else if(targetBits < sizeof(void *) * 8)
429 _class.structAlignment = 0;
431 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
432 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
433 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
435 if(!member && _class.destructionWatchOffset)
436 _class.memberOffset += sizeof(OldList);
438 // To avoid reentrancy...
439 //_class.structSize = -1;
442 DataMember dataMember;
443 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
445 if(!dataMember.isProperty)
447 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
449 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
450 /*if(!dataMember.dataType)
451 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
459 DataMember dataMember;
460 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
462 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
464 if(!isMember && _class.type == bitClass && dataMember.dataType)
466 BitMember bitMember = (BitMember) dataMember;
470 ComputeTypeSize(dataMember.dataType);
472 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
473 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
475 _class.memberOffset = bitMember.pos + bitMember.size;
476 for(d = 0; d<bitMember.size; d++)
482 bitMember.mask = mask << bitMember.pos;
484 else if(dataMember.type == normalMember && dataMember.dataType)
489 // Prevent infinite recursion
490 if(dataMember.dataType.kind != classType ||
491 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
492 _class.type != structClass)))
493 ComputeTypeSize(dataMember.dataType);
495 if(dataMember.dataType.bitFieldCount)
497 bitFields += dataMember.dataType.bitFieldCount;
504 int size = (bitFields + 7) / 8;
508 // TESTING THIS PADDING CODE
511 member.structAlignment = Max(member.structAlignment, alignment);
513 if(member.memberOffset % alignment)
514 member.memberOffset += alignment - (member.memberOffset % alignment);
517 dataMember.offset = member.memberOffset;
518 if(member.type == unionMember)
519 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
522 member.memberOffset += size;
527 // TESTING THIS PADDING CODE
530 _class.structAlignment = Max(_class.structAlignment, alignment);
532 if(_class.memberOffset % alignment)
533 _class.memberOffset += alignment - (_class.memberOffset % alignment);
536 dataMember.offset = _class.memberOffset;
537 _class.memberOffset += size;
541 size = dataMember.dataType.size;
542 alignment = dataMember.dataType.alignment;
547 // TESTING THIS PADDING CODE
550 member.structAlignment = Max(member.structAlignment, alignment);
552 if(member.memberOffset % alignment)
553 member.memberOffset += alignment - (member.memberOffset % alignment);
556 dataMember.offset = member.memberOffset;
557 if(member.type == unionMember)
558 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
561 member.memberOffset += size;
566 // TESTING THIS PADDING CODE
569 _class.structAlignment = Max(_class.structAlignment, alignment);
571 if(_class.memberOffset % alignment)
572 _class.memberOffset += alignment - (_class.memberOffset % alignment);
575 dataMember.offset = _class.memberOffset;
576 _class.memberOffset += size;
583 ComputeClassMembers((Class)dataMember, true);
584 alignment = dataMember.structAlignment;
590 if(member.memberOffset % alignment)
591 member.memberOffset += alignment - (member.memberOffset % alignment);
593 member.structAlignment = Max(member.structAlignment, alignment);
595 dataMember.offset = member.memberOffset;
596 if(member.type == unionMember)
597 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
599 member.memberOffset += dataMember.memberOffset;
605 if(_class.memberOffset % alignment)
606 _class.memberOffset += alignment - (_class.memberOffset % alignment);
607 _class.structAlignment = Max(_class.structAlignment, alignment);
609 dataMember.offset = _class.memberOffset;
610 _class.memberOffset += dataMember.memberOffset;
618 int size = (bitFields + 7) / 8;
622 // TESTING THIS PADDING CODE
625 member.structAlignment = Max(member.structAlignment, alignment);
627 if(member.memberOffset % alignment)
628 member.memberOffset += alignment - (member.memberOffset % alignment);
631 if(member.type == unionMember)
632 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
635 member.memberOffset += size;
640 // TESTING THIS PADDING CODE
643 _class.structAlignment = Max(_class.structAlignment, alignment);
645 if(_class.memberOffset % alignment)
646 _class.memberOffset += alignment - (_class.memberOffset % alignment);
648 _class.memberOffset += size;
653 if(member && member.type == unionMember)
655 member.memberOffset = unionMemberOffset;
660 /*if(_class.type == structClass)
661 _class.size = _class.memberOffset;
665 if(_class.type != bitClass)
668 if(_class.structAlignment)
670 if(_class.memberOffset % _class.structAlignment)
671 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
673 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
677 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
679 if(prop.isProperty && prop.isWatchable)
681 prop.watcherOffset = _class.structSize;
682 _class.structSize += sizeof(OldList);
690 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
692 Class deriv = derivative.data;
694 if(deriv.computeSize)
696 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
697 deriv.offset = /*_class.offset + */_class.structSize;
698 deriv.memberOffset = 0;
699 // ----------------------
701 deriv.structSize = deriv.offset;
703 ComputeClassMembers(deriv, false);
711 FinishTemplatesContext(context);
714 public void ComputeModuleClasses(Module module)
719 for(subModule = module.modules.first; subModule; subModule = subModule.next)
720 ComputeModuleClasses(subModule.data);
721 for(_class = module.classes.first; _class; _class = _class.next)
722 ComputeClassMembers(_class, false);
726 public int ComputeTypeSize(Type type)
728 uint size = type ? type.size : 0;
729 if(!size && type && !type.computing)
731 type.computing = true;
734 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
735 case charType: type.alignment = size = sizeof(char); break;
736 case intType: type.alignment = size = sizeof(int); break;
737 case int64Type: type.alignment = size = sizeof(int64); break;
738 case intPtrType: type.alignment = size = targetBits / 8; break;
739 case intSizeType: type.alignment = size = targetBits / 8; break;
740 case longType: type.alignment = size = sizeof(long); break;
741 case shortType: type.alignment = size = sizeof(short); break;
742 case floatType: type.alignment = size = sizeof(float); break;
743 case doubleType: type.alignment = size = sizeof(double); break;
746 Class _class = type._class ? type._class.registered : null;
748 if(_class && _class.type == structClass)
750 // Ensure all members are properly registered
751 ComputeClassMembers(_class, false);
752 type.alignment = _class.structAlignment;
753 size = _class.structSize;
754 if(type.alignment && size % type.alignment)
755 size += type.alignment - (size % type.alignment);
758 else if(_class && (_class.type == unitClass ||
759 _class.type == enumClass ||
760 _class.type == bitClass))
763 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
764 size = type.alignment = ComputeTypeSize(_class.dataType);
767 size = type.alignment = targetBits / 8; // sizeof(Instance *);
770 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
772 if(type.arraySizeExp)
774 ProcessExpressionType(type.arraySizeExp);
775 ComputeExpression(type.arraySizeExp);
776 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
777 type.arraySizeExp.expType.kind != shortType &&
778 type.arraySizeExp.expType.kind != charType &&
779 type.arraySizeExp.expType.kind != longType &&
780 type.arraySizeExp.expType.kind != int64Type &&
781 type.arraySizeExp.expType.kind != intSizeType &&
782 type.arraySizeExp.expType.kind != intPtrType &&
783 type.arraySizeExp.expType.kind != enumType &&
784 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
786 Location oldLoc = yylloc;
787 // bool isConstant = type.arraySizeExp.isConstant;
788 char expression[10240];
789 expression[0] = '\0';
790 type.arraySizeExp.expType = null;
791 yylloc = type.arraySizeExp.loc;
793 PrintExpression(type.arraySizeExp, expression);
794 Compiler_Error($"Array size not constant int (%s)\n", expression);
797 GetInt(type.arraySizeExp, &type.arraySize);
799 else if(type.enumClass)
801 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
803 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
810 // Unimplemented auto size
814 size = ComputeTypeSize(type.type) * type.arraySize;
816 type.alignment = type.type.alignment;
822 for(member = type.members.first; member; member = member.next)
824 uint addSize = ComputeTypeSize(member);
826 member.offset = size;
827 if(member.alignment && size % member.alignment)
828 member.offset += member.alignment - (size % member.alignment);
829 size = member.offset;
831 type.alignment = Max(type.alignment, member.alignment);
834 if(type.alignment && size % type.alignment)
835 size += type.alignment - (size % type.alignment);
841 for(member = type.members.first; member; member = member.next)
843 uint addSize = ComputeTypeSize(member);
845 member.offset = size;
846 if(member.alignment && size % member.alignment)
847 member.offset += member.alignment - (size % member.alignment);
848 size = member.offset;
850 type.alignment = Max(type.alignment, member.alignment);
851 size = Max(size, addSize);
853 if(type.alignment && size % type.alignment)
854 size += type.alignment - (size % type.alignment);
859 TemplateParameter param = type.templateParameter;
860 Type baseType = ProcessTemplateParameterType(param);
863 size = ComputeTypeSize(baseType);
864 type.alignment = baseType.alignment;
867 type.alignment = size = sizeof(uint64);
872 type.alignment = size = sizeof(enum { test });
877 type.alignment = size = targetBits / 8; //sizeof(void *);
882 type.computing = false;
888 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
890 // This function is in need of a major review when implementing private members etc.
891 DataMember topMember = isMember ? (DataMember) _class : null;
898 Context context = isMember ? null : SetupTemplatesContext(_class);
900 *addedPadding = false;
902 if(!isMember && _class.base)
904 maxSize = _class.structSize;
905 //if(_class.base.type != systemClass) // Commented out with new Instance _class
907 // DANGER: Testing this noHeadClass here...
908 if(_class.type == structClass || _class.type == noHeadClass)
909 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
912 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
913 if(maxSize > baseSize)
921 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
923 if(!member.isProperty)
929 if(member.dataTypeString)
931 OldList * specs = MkList(), * decls = MkList();
934 decl = SpecDeclFromString(member.dataTypeString, specs,
935 MkDeclaratorIdentifier(MkIdentifier(member.name)));
936 ListAdd(decls, MkStructDeclarator(decl, null));
937 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
940 member.dataType = ProcessType(specs, decl);
942 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
945 Type type = ProcessType(specs, decl);
946 DeclareType(member.dataType, false, false);
950 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
951 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
952 DeclareStruct(member.dataType._class.string, false);
955 ComputeTypeSize(member.dataType);
956 size = member.dataType.size;
957 alignment = member.dataType.alignment;
961 if(totalSize % alignment)
962 totalSize += alignment - (totalSize % alignment);
971 OldList * specs = MkList(), * list = MkList();
973 sprintf(id, "__anon%d", anonID++);
976 AddMembers(list, (Class)member, true, &size, topClass, null);
978 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
979 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
980 alignment = member.structAlignment;
984 if(totalSize % alignment)
985 totalSize += alignment - (totalSize % alignment);
995 if(topMember && topMember.type == unionMember)
996 *retSize = Max(*retSize, totalSize);
998 *retSize += totalSize;
1000 else if(totalSize < maxSize && _class.type != systemClass)
1002 int autoPadding = 0;
1003 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1004 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1005 if(totalSize + autoPadding < maxSize)
1007 char sizeString[50];
1008 sprintf(sizeString, "%d", maxSize - totalSize);
1009 ListAdd(declarations,
1010 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1011 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1013 *addedPadding = true;
1017 FinishTemplatesContext(context);
1018 return topMember ? topMember.memberID : _class.memberID;
1021 static int DeclareMembers(Class _class, bool isMember)
1023 DataMember topMember = isMember ? (DataMember) _class : null;
1025 Context context = isMember ? null : SetupTemplatesContext(_class);
1027 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1028 DeclareMembers(_class.base, false);
1030 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1032 if(!member.isProperty)
1039 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1040 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1041 DeclareStruct(member.dataType._class.string, false);
1043 if(!member.dataType && member.dataTypeString)
1044 member.dataType = ProcessTypeString(member.dataTypeString, false);
1046 DeclareType(member.dataType, false, false);
1052 DeclareMembers((Class)member, true);
1059 FinishTemplatesContext(context);
1061 return topMember ? topMember.memberID : _class.memberID;
1064 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1068 for(def = definitions->first; def; def = def.next)
1070 if(def.type == declarationClassDef)
1072 Declaration decl = def.decl;
1073 if(decl && decl.specifiers)
1076 bool isStruct = false;
1077 for(spec = decl.specifiers->first; spec; spec = spec.next)
1079 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1081 if(spec.definitions)
1082 IdentifyAnonStructs(spec.definitions);
1088 Declarator d = null;
1089 if(decl.declarators)
1091 for(d = decl.declarators->first; d; d = d.next)
1093 Identifier idDecl = GetDeclId(d);
1101 sprintf(id, "__anon%d", anonID++);
1102 if(!decl.declarators)
1103 decl.declarators = MkList();
1104 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1112 void DeclareStruct(const char * name, bool skipNoHead)
1114 External external = null;
1115 Symbol classSym = FindClass(name);
1117 if(!inCompiler || !classSym) return;
1119 // We don't need any declaration for bit classes...
1120 if(classSym.registered &&
1121 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1124 /*if(classSym.registered.templateClass)
1125 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1128 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1130 // Add typedef struct
1132 OldList * specifiers, * declarators;
1133 OldList * declarations = null;
1134 char structName[1024];
1135 Specifier spec = null;
1136 external = (classSym.registered && classSym.registered.type == structClass) ?
1137 classSym.pointerExternal : classSym.structExternal;
1139 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1140 // Moved this one up because DeclareClass done later will need it
1142 classSym.declaring++;
1144 if(strchr(classSym.string, '<'))
1146 if(classSym.registered.templateClass)
1148 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1149 classSym.declaring--;
1155 DeclareMembers(classSym.registered, false);
1158 FullClassNameCat(structName, name, false);
1160 if(external && external.declaration && external.declaration.specifiers)
1162 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1164 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1170 external = MkExternalDeclaration(null);*/
1172 if(!skipNoHead && (!spec || !spec.definitions))
1174 bool addedPadding = false;
1175 classSym.declaredStructSym = true;
1177 declarations = MkList();
1179 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1181 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1182 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1184 if(!declarations->count || (declarations->count == 1 && addedPadding))
1186 FreeList(declarations, FreeClassDef);
1187 declarations = null;
1190 if(skipNoHead || declarations)
1195 spec.definitions = declarations;
1197 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1200 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1203 if(classSym.structExternal)
1204 ast->Move(classSym.structExternal, curExternal.prev);
1205 ast->Move(classSym.pointerExternal, curExternal.prev);
1207 classSym.id = curExternal.symbol.idCode;
1208 classSym.idCode = curExternal.symbol.idCode;
1209 // external = classSym.pointerExternal;
1210 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1216 external = MkExternalDeclaration(null);
1218 specifiers = MkList();
1219 declarators = MkList();
1220 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1223 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1224 ListAdd(declarators, MkInitDeclarator(d, null));
1226 external.declaration = decl = MkDeclaration(specifiers, declarators);
1227 if(decl.symbol && !decl.symbol.pointerExternal)
1228 decl.symbol.pointerExternal = external;
1230 // For simple classes, keep the declaration as the external to move around
1231 if(classSym.registered && classSym.registered.type == structClass)
1233 char className[1024];
1234 strcpy(className, "__ecereClass_");
1235 FullClassNameCat(className, classSym.string, true);
1236 //MangleClassName(className);
1239 DeclareClass(classSym, className);
1241 external.symbol = classSym;
1242 classSym.pointerExternal = external;
1243 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1244 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1248 char className[1024];
1249 strcpy(className, "__ecereClass_");
1250 FullClassNameCat(className, classSym.string, true);
1251 //MangleClassName(className);
1253 // TOFIX: TESTING THIS...
1254 classSym.structExternal = external;
1255 DeclareClass(classSym, className);
1256 external.symbol = classSym;
1260 ast->Insert(curExternal ? curExternal.prev : null, external);
1264 classSym.declaring--;
1268 if(classSym.structExternal && classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1271 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1273 IdentifyAnonStructs(spec.definitions);
1277 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1279 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1280 // Moved this one up because DeclareClass done later will need it
1283 classSym.declaring++;
1287 if(classSym.registered)
1288 DeclareMembers(classSym.registered, false);
1291 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1294 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1297 if(classSym.structExternal)
1298 ast->Move(classSym.structExternal, curExternal.prev);
1299 ast->Move(classSym.pointerExternal, curExternal.prev);
1301 classSym.id = curExternal.symbol.idCode;
1302 classSym.idCode = curExternal.symbol.idCode;
1303 // external = classSym.pointerExternal;
1304 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1307 classSym.declaring--;
1313 void DeclareProperty(Property prop, char * setName, char * getName)
1315 Symbol symbol = prop.symbol;
1317 strcpy(setName, "__ecereProp_");
1318 FullClassNameCat(setName, prop._class.fullName, false);
1319 strcat(setName, "_Set_");
1320 // strcat(setName, prop.name);
1321 FullClassNameCat(setName, prop.name, true);
1322 //MangleClassName(setName);
1324 strcpy(getName, "__ecereProp_");
1325 FullClassNameCat(getName, prop._class.fullName, false);
1326 strcat(getName, "_Get_");
1327 FullClassNameCat(getName, prop.name, true);
1328 // strcat(getName, prop.name);
1330 // To support "char *" property
1331 //MangleClassName(getName);
1333 if(prop._class.type == structClass)
1334 DeclareStruct(prop._class.fullName, false);
1336 if(!symbol || curExternal.symbol.idCode < symbol.id)
1338 bool imported = false;
1339 bool dllImport = false;
1341 if(!symbol || symbol._import)
1346 if(!prop._class.symbol)
1347 prop._class.symbol = FindClass(prop._class.fullName);
1348 classSym = prop._class.symbol;
1349 if(classSym && !classSym._import)
1351 ModuleImport module;
1353 if(prop._class.module)
1354 module = FindModule(prop._class.module);
1356 module = mainModule;
1358 classSym._import = ClassImport
1360 name = CopyString(prop._class.fullName);
1361 isRemote = prop._class.isRemote;
1363 module.classes.Add(classSym._import);
1365 symbol = prop.symbol = Symbol { };
1366 symbol._import = (ClassImport)PropertyImport
1368 name = CopyString(prop.name);
1369 isVirtual = false; //prop.isVirtual;
1370 hasSet = prop.Set ? true : false;
1371 hasGet = prop.Get ? true : false;
1374 classSym._import.properties.Add(symbol._import);
1377 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1378 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1379 prop._class.module.importType != staticImport)
1385 Context context = SetupTemplatesContext(prop._class);
1386 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1387 FinishTemplatesContext(context);
1393 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1396 OldList * specifiers, * declarators;
1401 Declarator typeDecl;
1402 bool simple = false;
1404 specifiers = MkList();
1405 declarators = MkList();
1408 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1409 MkDeclaratorIdentifier(MkIdentifier("this"))));
1411 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1414 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1417 Context context = SetupTemplatesContext(prop._class);
1418 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1419 FinishTemplatesContext(context);
1422 // Make sure the simple _class's type is declared
1423 for(spec = specifiers->first; spec; spec = spec.next)
1425 if(spec.type == nameSpecifier /*SpecifierClass*/)
1427 if((!typeDecl || typeDecl.type == identifierDeclarator))
1429 Symbol classSym = spec.symbol; // FindClass(spec.name);
1430 symbol._class = classSym.registered;
1431 if(classSym.registered && classSym.registered.type == structClass)
1433 DeclareStruct(spec.name, false);
1441 d = PlugDeclarator(typeDecl, d);
1444 ListAdd(params, MkTypeName(specifiers,
1445 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1446 specifiers = MkList();
1449 d = MkDeclaratorFunction(d, params);
1453 specifiers->Insert(null, MkSpecifier(EXTERN));
1454 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1455 specifiers->Insert(null, MkSpecifier(STATIC));
1457 ListAdd(specifiers, MkSpecifier(VOID));
1459 ListAdd(declarators, MkInitDeclarator(d, null));
1461 decl = MkDeclaration(specifiers, declarators);
1463 external = MkExternalDeclaration(decl);
1464 ast->Insert(curExternal.prev, external);
1465 external.symbol = symbol;
1466 symbol.externalGet = external;
1468 ReplaceThisClassSpecifiers(specifiers, prop._class);
1471 FreeDeclarator(typeDecl);
1475 // Move declaration higher...
1476 ast->Move(symbol.externalGet, curExternal.prev);
1483 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1486 OldList * specifiers, * declarators;
1491 Declarator typeDecl;
1493 declarators = MkList();
1496 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1497 if(!prop.conversion || prop._class.type == structClass)
1499 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1500 MkDeclaratorIdentifier(MkIdentifier("this"))));
1503 specifiers = MkList();
1506 Context context = SetupTemplatesContext(prop._class);
1507 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1508 MkDeclaratorIdentifier(MkIdentifier("value")));
1509 FinishTemplatesContext(context);
1511 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1512 specifiers->Insert(null, MkSpecifier(CONST));
1514 ListAdd(params, MkTypeName(specifiers, d));
1516 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1519 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1520 d = MkDeclaratorFunction(d, params);
1522 // Make sure the simple _class's type is declared
1523 for(spec = specifiers->first; spec; spec = spec.next)
1525 if(spec.type == nameSpecifier /*SpecifierClass*/)
1527 if((!typeDecl || typeDecl.type == identifierDeclarator))
1529 Symbol classSym = spec.symbol; // FindClass(spec.name);
1530 symbol._class = classSym.registered;
1531 if(classSym.registered && classSym.registered.type == structClass)
1532 DeclareStruct(spec.name, false);
1537 ListAdd(declarators, MkInitDeclarator(d, null));
1539 specifiers = MkList();
1542 specifiers->Insert(null, MkSpecifier(EXTERN));
1543 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1544 specifiers->Insert(null, MkSpecifier(STATIC));
1546 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1547 if(!prop.conversion || prop._class.type == structClass)
1548 ListAdd(specifiers, MkSpecifier(VOID));
1550 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1552 decl = MkDeclaration(specifiers, declarators);
1554 external = MkExternalDeclaration(decl);
1555 ast->Insert(curExternal.prev, external);
1556 external.symbol = symbol;
1557 symbol.externalSet = external;
1559 ReplaceThisClassSpecifiers(specifiers, prop._class);
1563 // Move declaration higher...
1564 ast->Move(symbol.externalSet, curExternal.prev);
1568 // Property (for Watchers)
1569 if(!symbol.externalPtr)
1573 OldList * specifiers = MkList();
1574 char propName[1024];
1577 specifiers->Insert(null, MkSpecifier(EXTERN));
1580 specifiers->Insert(null, MkSpecifier(STATIC));
1581 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
1584 ListAdd(specifiers, MkSpecifierName("Property"));
1586 strcpy(propName, "__ecereProp_");
1587 FullClassNameCat(propName, prop._class.fullName, false);
1588 strcat(propName, "_");
1589 FullClassNameCat(propName, prop.name, true);
1590 // strcat(propName, prop.name);
1591 //MangleClassName(propName);
1594 OldList * list = MkList();
1595 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1596 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1600 strcpy(propName, "__ecerePropM_");
1601 FullClassNameCat(propName, prop._class.fullName, false);
1602 strcat(propName, "_");
1603 // strcat(propName, prop.name);
1604 FullClassNameCat(propName, prop.name, true);
1606 //MangleClassName(propName);
1608 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1609 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1611 decl = MkDeclaration(specifiers, list);
1614 external = MkExternalDeclaration(decl);
1615 ast->Insert(curExternal.prev, external);
1616 external.symbol = symbol;
1617 symbol.externalPtr = external;
1621 // Move declaration higher...
1622 ast->Move(symbol.externalPtr, curExternal.prev);
1625 symbol.id = curExternal.symbol.idCode;
1629 // ***************** EXPRESSION PROCESSING ***************************
1630 public Type Dereference(Type source)
1635 if(source.kind == pointerType || source.kind == arrayType)
1638 source.type.refCount++;
1640 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1648 // Support dereferencing of no head classes for now...
1649 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1655 Compiler_Error($"cannot dereference type\n");
1660 static Type Reference(Type source)
1676 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1678 Identifier ident = member.identifiers ? member.identifiers->first : null;
1680 DataMember dataMember = null;
1681 Method method = null;
1682 bool freeType = false;
1684 yylloc = member.loc;
1690 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1694 dataMember = *curMember;
1700 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1701 DataMember _subMemberStack[256];
1702 int _subMemberStackPos = 0;
1704 // FILL MEMBER STACK
1706 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1709 dataMember = thisMember;
1710 if(curMember && thisMember.memberAccess == publicAccess)
1712 *curMember = thisMember;
1713 *curClass = thisMember._class;
1714 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1715 *subMemberStackPos = _subMemberStackPos;
1722 method = eClass_FindMethod(_class, ident.string, privateModule);
1723 if(method && method.type == virtualMethod)
1735 if(!dataMember.dataType && dataMember.dataTypeString)
1737 //Context context = SetupTemplatesContext(dataMember._class);
1738 Context context = SetupTemplatesContext(_class);
1739 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1740 FinishTemplatesContext(context);
1742 type = dataMember.dataType;
1746 // This is for destination type...
1747 if(!method.dataType)
1748 ProcessMethodType(method);
1749 //DeclareMethod(method);
1750 // method.dataType = ((Symbol)method.symbol)->type;
1751 type = method.dataType;
1754 if(ident && ident.next)
1756 for(ident = ident.next; ident && type; ident = ident.next)
1758 if(type.kind == classType)
1760 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1762 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1764 type = dataMember.dataType;
1766 else if(type.kind == structType || type.kind == unionType)
1769 for(memberType = type.members.first; memberType; memberType = memberType.next)
1771 if(!strcmp(memberType.name, ident.string))
1781 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1782 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1785 ClassTemplateParameter curParam = null;
1787 for(sClass = _class; sClass; sClass = sClass.base)
1790 if(sClass.templateClass) sClass = sClass.templateClass;
1791 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1793 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1795 for(sClass = sClass.base; sClass; sClass = sClass.base)
1797 if(sClass.templateClass) sClass = sClass.templateClass;
1798 id += sClass.templateParams.count;
1809 ClassTemplateArgument arg = _class.templateArgs[id];
1810 if(arg.dataTypeString)
1812 bool constant = type.constant;
1814 type = ProcessTypeString(arg.dataTypeString, false);
1815 if(type.kind == classType && constant) type.constant = true;
1816 else if(type.kind == pointerType)
1819 while(t.kind == pointerType) t = t.type;
1820 if(constant) t.constant = constant;
1823 if(type && _class.templateClass)
1824 type.passAsTemplate = true;
1830 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1831 exp.destType.refCount++;
1837 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1839 Class expClass = type._class.registered;
1840 Class cClass = null;
1844 char templateString[1024];
1845 ClassTemplateParameter param;
1846 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1847 for(cClass = expClass; cClass; cClass = cClass.base)
1850 if(cClass.templateClass) cClass = cClass.templateClass;
1851 for(param = cClass.templateParams.first; param; param = param.next)
1855 ClassTemplateArgument arg;
1856 for(sClass = cClass.base; sClass; sClass = sClass.base)
1858 if(sClass.templateClass) sClass = sClass.templateClass;
1859 id += sClass.templateParams.count;
1861 arg = expClass.templateArgs[id];
1863 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1865 ClassTemplateParameter cParam;
1866 //int p = numParams - sClass.templateParams.count;
1869 if(sClass.templateClass) sClass = sClass.templateClass;
1871 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1873 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1874 p += nextClass.templateParams.count;
1877 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1879 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1881 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1883 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1884 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1896 strcat(argument, arg.name.string);
1897 strcat(argument, " = ");
1903 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1904 char expString[1024];
1905 OldList * specs = MkList();
1906 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1908 char * string = PrintHexUInt64(arg.expression.ui64);
1909 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1912 ProcessExpressionType(exp);
1913 ComputeExpression(exp);
1914 expString[0] = '\0';
1915 PrintExpression(exp, expString);
1916 strcat(argument, expString);
1918 FreeExpression(exp);
1923 strcat(argument, arg.member.name);
1926 case TemplateParameterType::type:
1928 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1929 strcat(argument, arg.dataTypeString);
1935 if(paramCount) strcat(templateString, ", ");
1936 if(lastParam != p - 1)
1938 strcat(templateString, param.name);
1939 strcat(templateString, " = ");
1941 strcat(templateString, argument);
1950 int len = strlen(templateString);
1951 if(templateString[len-1] == '<')
1955 if(templateString[len-1] == '>')
1956 templateString[len++] = ' ';
1957 templateString[len++] = '>';
1959 templateString[len++] = '\0';
1962 Context context = SetupTemplatesContext(_class);
1963 if(freeType) FreeType(type);
1964 type = ProcessTypeString(templateString, false);
1966 FinishTemplatesContext(context);
1970 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1972 ProcessExpressionType(member.initializer.exp);
1973 if(!member.initializer.exp.expType)
1977 char expString[10240];
1978 expString[0] = '\0';
1979 PrintExpression(member.initializer.exp, expString);
1980 ChangeCh(expString, '\n', ' ');
1981 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1984 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1985 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1987 Compiler_Error($"incompatible instance method %s\n", ident.string);
1990 else if(member.initializer)
1993 FreeType(member.exp.destType);
1994 member.exp.destType = type;
1995 if(member.exp.destType)
1996 member.exp.destType.refCount++;
1997 ProcessExpressionType(member.exp);
2000 ProcessInitializer(member.initializer, type);
2002 if(freeType) FreeType(type);
2006 if(_class && _class.type == unitClass)
2008 if(member.initializer)
2011 FreeType(member.exp.destType);
2012 member.exp.destType = MkClassType(_class.fullName);
2013 ProcessExpressionType(member.initializer, type);
2015 Type type = MkClassType(_class.fullName);
2016 ProcessInitializer(member.initializer, type);
2022 if(member.initializer)
2024 //ProcessExpressionType(member.exp);
2025 ProcessInitializer(member.initializer, null);
2031 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2035 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2037 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2041 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2046 void ProcessInstantiationType(Instantiation inst)
2051 MembersInit members;
2052 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
2055 /*if(!inst._class.symbol)
2056 inst._class.symbol = FindClass(inst._class.name);*/
2057 classSym = inst._class.symbol;
2058 _class = classSym ? classSym.registered : null;
2060 // DANGER: Patch for mutex not declaring its struct when not needed
2061 if(!_class || _class.type != noHeadClass)
2062 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
2064 afterExternal = afterExternal ? afterExternal : curExternal;
2067 ProcessExpressionType(inst.exp);
2069 inst.isConstant = true;
2072 DataMember curMember = null;
2073 Class curClass = null;
2074 DataMember subMemberStack[256];
2075 int subMemberStackPos = 0;
2077 for(members = inst.members->first; members; members = members.next)
2079 switch(members.type)
2081 case methodMembersInit:
2084 static uint instMethodID = 0;
2085 External external = curExternal;
2086 Context context = curContext;
2087 Declarator declarator = members.function.declarator;
2088 Identifier nameID = GetDeclId(declarator);
2089 char * unmangled = nameID ? nameID.string : null;
2091 External createdExternal = null;
2096 //members.function.dontMangle = true;
2097 strcpy(name, "__ecereInstMeth_");
2098 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2100 strcat(name, nameID.string);
2102 sprintf(number, "_%08d", instMethodID++);
2103 strcat(name, number);
2104 nameID.string = CopyString(name);
2107 // Do modifications here...
2110 Symbol symbol = declarator.symbol;
2111 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2113 if(method && method.type == virtualMethod)
2115 symbol.method = method;
2116 ProcessMethodType(method);
2118 if(!symbol.type.thisClass)
2120 if(method.dataType.thisClass && currentClass &&
2121 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2123 if(!currentClass.symbol)
2124 currentClass.symbol = FindClass(currentClass.fullName);
2125 symbol.type.thisClass = currentClass.symbol;
2130 _class.symbol = FindClass(_class.fullName);
2131 symbol.type.thisClass = _class.symbol;
2134 // TESTING THIS HERE:
2135 DeclareType(symbol.type, true, true);
2140 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2141 unmangled, classSym.string);
2145 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2146 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2150 FreeSpecifier(nameID._class);
2151 nameID._class = null;
2156 //Type type = declarator.symbol.type;
2157 External oldExternal = curExternal;
2159 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2160 // *** It was commented out for problems such as
2162 class VirtualDesktop : Window
2164 clientSize = Size { };
2175 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2177 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2180 if(strcmp(declarator.symbol.string, name))
2182 printf("TOCHECK: Look out for this\n");
2183 delete declarator.symbol.string;
2184 declarator.symbol.string = CopyString(name);
2187 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2189 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2190 excludedSymbols->Remove(declarator.symbol);
2191 globalContext.symbols.Add((BTNode)declarator.symbol);
2192 if(strstr(declarator.symbol.string), "::")
2193 globalContext.hasNameSpace = true;
2198 //curExternal = curExternal.prev;
2199 //afterExternal = afterExternal->next;
2201 //ProcessFunction(afterExternal->function);
2203 //curExternal = afterExternal;
2205 External externalDecl;
2206 externalDecl = MkExternalDeclaration(null);
2207 ast->Insert(oldExternal.prev, externalDecl);
2209 // Which function does this process?
2210 if(createdExternal.function)
2212 ProcessFunction(createdExternal.function);
2214 //curExternal = oldExternal;
2217 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2219 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2220 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2222 //externalDecl = MkExternalDeclaration(decl);
2224 //***** ast->Insert(external.prev, externalDecl);
2225 //ast->Insert(curExternal.prev, externalDecl);
2226 externalDecl.declaration = decl;
2227 if(decl.symbol && !decl.symbol.pointerExternal)
2228 decl.symbol.pointerExternal = externalDecl;
2230 // Trying this out...
2231 declarator.symbol.pointerExternal = externalDecl;
2238 curExternal = declarator.symbol.pointerExternal;
2239 ProcessFunction((FunctionDefinition)members.function);
2241 curExternal = external;
2242 curContext = context;
2246 FreeClassFunction(members.function);
2248 // In this pass, turn this into a MemberInitData
2249 exp = QMkExpId(name);
2250 members.type = dataMembersInit;
2251 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2257 case dataMembersInit:
2259 if(members.dataMembers && classSym)
2262 Location oldyyloc = yylloc;
2263 for(member = members.dataMembers->first; member; member = member.next)
2265 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2266 if(member.initializer && !member.initializer.isConstant)
2267 inst.isConstant = false;
2279 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2281 // OPTIMIZATIONS: TESTING THIS...
2284 if(type.kind == functionType)
2289 for(param = type.params.first; param; param = param.next)
2290 DeclareType(param, declarePointers, true);
2292 DeclareType(type.returnType, declarePointers, true);
2294 else if(type.kind == pointerType && declarePointers)
2295 DeclareType(type.type, declarePointers, false);
2296 else if(type.kind == classType)
2298 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2299 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2301 else if(type.kind == structType || type.kind == unionType)
2304 for(member = type.members.first; member; member = member.next)
2305 DeclareType(member, false, false);
2307 else if(type.kind == arrayType)
2308 DeclareType(type.arrayType, declarePointers, false);
2312 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2314 ClassTemplateArgument * arg = null;
2316 ClassTemplateParameter curParam = null;
2318 for(sClass = _class; sClass; sClass = sClass.base)
2321 if(sClass.templateClass) sClass = sClass.templateClass;
2322 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2324 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2326 for(sClass = sClass.base; sClass; sClass = sClass.base)
2328 if(sClass.templateClass) sClass = sClass.templateClass;
2329 id += sClass.templateParams.count;
2339 arg = &_class.templateArgs[id];
2340 if(arg && param.type == type)
2341 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2346 public Context SetupTemplatesContext(Class _class)
2348 Context context = PushContext();
2349 context.templateTypesOnly = true;
2350 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2352 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2353 for(; param; param = param.next)
2355 if(param.type == type && param.identifier)
2357 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2358 curContext.templateTypes.Add((BTNode)type);
2365 for(sClass = _class; sClass; sClass = sClass.base)
2367 ClassTemplateParameter p;
2368 for(p = sClass.templateParams.first; p; p = p.next)
2370 //OldList * specs = MkList();
2371 //Declarator decl = null;
2372 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2375 TemplateParameter param = p.param;
2379 // ADD DATA TYPE HERE...
2380 p.param = param = TemplateParameter
2382 identifier = MkIdentifier(p.name), type = p.type,
2383 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2386 type = TemplatedType { key = (uintptr)p.name, param = param };
2387 curContext.templateTypes.Add((BTNode)type);
2395 public void FinishTemplatesContext(Context context)
2397 PopContext(context);
2398 FreeContext(context);
2402 public void ProcessMethodType(Method method)
2404 if(!method.dataType)
2406 Context context = SetupTemplatesContext(method._class);
2408 method.dataType = ProcessTypeString(method.dataTypeString, false);
2410 FinishTemplatesContext(context);
2412 if(method.type != virtualMethod && method.dataType)
2414 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2416 if(!method._class.symbol)
2417 method._class.symbol = FindClass(method._class.fullName);
2418 method.dataType.thisClass = method._class.symbol;
2422 // Why was this commented out? Working fine without now...
2425 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2426 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2433 char * par = strstr(type, "(");
2434 char * classOp = null;
2439 for(c = par-type-1; c >= 0; c++)
2441 if(type[c] == ':' && type[c+1] == ':')
2443 classOp = type + c - 1;
2444 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2451 else if(!isspace(type[c]))
2458 int typeLen = strlen(type);
2459 memcpy(temp, classOp, classOpLen);
2460 temp[classOpLen] = '\0';
2462 _class = eSystem_FindClass(module, temp);
2465 method.dataTypeString = new char[typeLen - classOpLen + 1];
2466 memcpy(method.dataTypeString, type, classOp - type);
2467 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2470 method.dataTypeString = type;
2476 public void ProcessPropertyType(Property prop)
2480 Context context = SetupTemplatesContext(prop._class);
2481 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2482 FinishTemplatesContext(context);
2486 public void DeclareMethod(Method method, const char * name)
2488 Symbol symbol = method.symbol;
2489 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2491 //bool imported = false;
2492 bool dllImport = false;
2494 if(!method.dataType)
2495 method.dataType = ProcessTypeString(method.dataTypeString, false);
2497 if(!symbol || symbol._import || method.type == virtualMethod)
2499 if(!symbol || method.type == virtualMethod)
2502 if(!method._class.symbol)
2503 method._class.symbol = FindClass(method._class.fullName);
2504 classSym = method._class.symbol;
2505 if(!classSym._import)
2507 ModuleImport module;
2509 if(method._class.module && method._class.module.name)
2510 module = FindModule(method._class.module);
2512 module = mainModule;
2513 classSym._import = ClassImport
2515 name = CopyString(method._class.fullName);
2516 isRemote = method._class.isRemote;
2518 module.classes.Add(classSym._import);
2522 symbol = method.symbol = Symbol { };
2526 symbol._import = (ClassImport)MethodImport
2528 name = CopyString(method.name);
2529 isVirtual = method.type == virtualMethod;
2531 classSym._import.methods.Add(symbol._import);
2535 // Set the symbol type
2539 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2541 else if(type.thisClass == (void *)-1)
2543 type.thisClass = null;
2546 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2547 symbol.type = method.dataType;
2548 if(symbol.type) symbol.type.refCount++;
2551 if(!method.thisClass || strcmp(method.thisClass, "void"))
2552 symbol.type.params.Insert(null,
2553 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2556 if(!method.dataType.dllExport)
2559 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2565 if(!method.dataType)
2566 method.dataType = ((Symbol)method.symbol).type;
2567 //ProcessMethodType(method);
2570 if(method.type != virtualMethod && method.dataType)
2571 DeclareType(method.dataType, true, true);
2573 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2575 // We need a declaration here :)
2577 OldList * specifiers, * declarators;
2579 Declarator funcDecl;
2582 specifiers = MkList();
2583 declarators = MkList();
2587 ListAdd(specifiers, MkSpecifier(EXTERN));
2588 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2589 ListAdd(specifiers, MkSpecifier(STATIC));
2591 if(method.type == virtualMethod)
2593 ListAdd(specifiers, MkSpecifier(INT));
2594 d = MkDeclaratorIdentifier(MkIdentifier(name));
2598 d = MkDeclaratorIdentifier(MkIdentifier(name));
2601 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2603 Context context = SetupTemplatesContext(method._class);
2604 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2605 FinishTemplatesContext(context);
2607 funcDecl = GetFuncDecl(d);
2611 Specifier spec, next;
2612 for(spec = specifiers->first; spec; spec = next)
2615 if(spec.type == extendedSpecifier)
2617 specifiers->Remove(spec);
2618 FreeSpecifier(spec);
2623 // Add this parameter if not a static method
2624 if(method.dataType && !method.dataType.staticMethod)
2626 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2628 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2629 TypeName thisParam = MkTypeName(MkListOne(
2630 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2631 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2632 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2633 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2635 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2637 TypeName param = funcDecl.function.parameters->first;
2638 funcDecl.function.parameters->Remove(param);
2639 FreeTypeName(param);
2642 if(!funcDecl.function.parameters)
2643 funcDecl.function.parameters = MkList();
2644 funcDecl.function.parameters->Insert(null, thisParam);
2647 // Make sure we don't have empty parameter declarations for static methods...
2649 else if(!funcDecl.function.parameters)
2651 funcDecl.function.parameters = MkList();
2652 funcDecl.function.parameters->Insert(null,
2653 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2657 ProcessDeclarator(d);
2659 ListAdd(declarators, MkInitDeclarator(d, null));
2661 decl = MkDeclaration(specifiers, declarators);
2663 ReplaceThisClassSpecifiers(specifiers, method._class);
2665 // Keep a different symbol for the function definition than the declaration...
2666 if(symbol.pointerExternal)
2668 Symbol functionSymbol { };
2672 *functionSymbol = *symbol;
2673 functionSymbol.string = CopyString(symbol.string);
2674 if(functionSymbol.type)
2675 functionSymbol.type.refCount++;
2678 excludedSymbols->Add(functionSymbol);
2679 symbol.pointerExternal.symbol = functionSymbol;
2681 external = MkExternalDeclaration(decl);
2683 ast->Insert(curExternal ? curExternal.prev : null, external);
2684 external.symbol = symbol;
2685 symbol.pointerExternal = external;
2689 // Move declaration higher...
2690 ast->Move(symbol.pointerExternal, curExternal.prev);
2693 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2697 char * ReplaceThisClass(Class _class)
2699 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2703 ClassTemplateParameter param;
2706 char className[1024];
2707 strcpy(className, _class.fullName);
2708 for(param = _class.templateParams.first; param; param = param.next)
2710 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2712 if(first) strcat(className, "<");
2713 if(!first) strcat(className, ", ");
2714 if(lastParam + 1 != p)
2716 strcat(className, param.name);
2717 strcat(className, " = ");
2719 strcat(className, param.name);
2727 int len = strlen(className);
2728 if(className[len-1] == '>') className[len++] = ' ';
2729 className[len++] = '>';
2730 className[len++] = '\0';
2732 return CopyString(className);
2735 return CopyString(_class.fullName);
2738 Type ReplaceThisClassType(Class _class)
2741 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2745 ClassTemplateParameter param;
2747 char className[1024];
2748 strcpy(className, _class.fullName);
2750 for(param = _class.templateParams.first; param; param = param.next)
2752 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2754 if(first) strcat(className, "<");
2755 if(!first) strcat(className, ", ");
2756 if(lastParam + 1 != p)
2758 strcat(className, param.name);
2759 strcat(className, " = ");
2761 strcat(className, param.name);
2769 int len = strlen(className);
2770 if(className[len-1] == '>') className[len++] = ' ';
2771 className[len++] = '>';
2772 className[len++] = '\0';
2774 type = MkClassType(className);
2775 //type = ProcessTypeString(className, false);
2779 type = MkClassType(_class.fullName);
2780 //type = ProcessTypeString(_class.fullName, false);
2782 //type.wasThisClass = true;
2786 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2788 if(specs != null && _class)
2791 for(spec = specs.first; spec; spec = spec.next)
2793 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2795 spec.type = nameSpecifier;
2796 spec.name = ReplaceThisClass(_class);
2797 spec.symbol = FindClass(spec.name); //_class.symbol;
2803 // Returns imported or not
2804 bool DeclareFunction(GlobalFunction function, char * name)
2806 Symbol symbol = function.symbol;
2807 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2809 bool imported = false;
2810 bool dllImport = false;
2812 if(!function.dataType)
2814 function.dataType = ProcessTypeString(function.dataTypeString, false);
2815 if(!function.dataType.thisClass)
2816 function.dataType.staticMethod = true;
2823 ModuleImport module = FindModule(function.module);
2824 // WARNING: This is not added anywhere...
2825 symbol = function.symbol = Symbol { };
2829 if(!function.dataType.dllExport)
2831 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2832 module.functions.Add(symbol._import);
2835 // Set the symbol type
2837 symbol.type = ProcessTypeString(function.dataTypeString, false);
2838 if(!symbol.type.thisClass)
2839 symbol.type.staticMethod = true;
2842 imported = symbol._import ? true : false;
2843 if(imported && function.module != privateModule && function.module.importType != staticImport)
2847 DeclareType(function.dataType, true, true);
2851 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2853 // We need a declaration here :)
2855 OldList * specifiers, * declarators;
2857 Declarator funcDecl;
2860 specifiers = MkList();
2861 declarators = MkList();
2864 ListAdd(specifiers, MkSpecifier(EXTERN));
2867 ListAdd(specifiers, MkSpecifier(STATIC));
2870 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2873 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2875 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2876 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2877 if(function.module.importType == staticImport)
2880 for(spec = specifiers->first; spec; spec = spec.next)
2881 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2883 specifiers->Remove(spec);
2884 FreeSpecifier(spec);
2889 funcDecl = GetFuncDecl(d);
2891 // Make sure we don't have empty parameter declarations for static methods...
2892 if(funcDecl && !funcDecl.function.parameters)
2894 funcDecl.function.parameters = MkList();
2895 funcDecl.function.parameters->Insert(null,
2896 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2899 ListAdd(declarators, MkInitDeclarator(d, null));
2902 Context oldCtx = curContext;
2903 curContext = globalContext;
2904 decl = MkDeclaration(specifiers, declarators);
2905 curContext = oldCtx;
2908 // Keep a different symbol for the function definition than the declaration...
2909 if(symbol.pointerExternal)
2911 Symbol functionSymbol { };
2914 *functionSymbol = *symbol;
2915 functionSymbol.string = CopyString(symbol.string);
2916 if(functionSymbol.type)
2917 functionSymbol.type.refCount++;
2920 excludedSymbols->Add(functionSymbol);
2922 symbol.pointerExternal.symbol = functionSymbol;
2924 external = MkExternalDeclaration(decl);
2926 ast->Insert(curExternal.prev, external);
2927 external.symbol = symbol;
2928 symbol.pointerExternal = external;
2932 // Move declaration higher...
2933 ast->Move(symbol.pointerExternal, curExternal.prev);
2937 symbol.id = curExternal.symbol.idCode;
2940 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2943 void DeclareGlobalData(GlobalData data)
2945 Symbol symbol = data.symbol;
2946 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2951 symbol = data.symbol = Symbol { };
2954 data.dataType = ProcessTypeString(data.dataTypeString, false);
2955 DeclareType(data.dataType, true, true);
2958 if(!symbol.pointerExternal)
2960 // We need a declaration here :)
2962 OldList * specifiers, * declarators;
2966 specifiers = MkList();
2967 declarators = MkList();
2969 ListAdd(specifiers, MkSpecifier(EXTERN));
2970 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2971 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2973 ListAdd(declarators, MkInitDeclarator(d, null));
2975 decl = MkDeclaration(specifiers, declarators);
2976 external = MkExternalDeclaration(decl);
2978 ast->Insert(curExternal.prev, external);
2979 external.symbol = symbol;
2980 symbol.pointerExternal = external;
2984 // Move declaration higher...
2985 ast->Move(symbol.pointerExternal, curExternal.prev);
2989 symbol.id = curExternal.symbol.idCode;
2994 class Conversion : struct
2996 Conversion prev, next;
3002 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
3005 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
3006 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
3008 Class sourceClass = source.kind == classType ? source._class.registered : null;
3009 Class destClass = dest.kind == classType ? dest._class.registered : null;
3010 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
3011 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
3013 Type sourceType = source, destType = dest;
3014 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
3015 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
3016 if(!destType.constant && sourceType.constant)
3020 Compiler_Warning($"discarding const qualifier\n");
3027 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
3028 bool isConversionExploration, bool warnConst)
3033 CheckConstCompatibility(source, dest, true);
3034 // Property convert;
3036 if(source.kind == templateType && dest.kind != templateType)
3038 Type type = ProcessTemplateParameterType(source.templateParameter);
3039 if(type) source = type;
3042 if(dest.kind == templateType && source.kind != templateType)
3044 Type type = ProcessTemplateParameterType(dest.templateParameter);
3045 if(type) dest = type;
3048 if(dest.classObjectType == typedObject && dest.kind != functionType)
3050 if(source.classObjectType != anyObject)
3054 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
3055 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
3063 if(source.kind != functionType && source.classObjectType == anyObject)
3065 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
3069 if((dest.kind == structType && source.kind == structType) ||
3070 (dest.kind == unionType && source.kind == unionType))
3072 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
3073 (source.members.first && source.members.first == dest.members.first))
3077 if(dest.kind == ellipsisType && source.kind != voidType)
3080 if(dest.kind == pointerType && dest.type.kind == voidType &&
3081 ((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))
3082 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
3084 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
3086 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
3088 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
3089 ((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))
3090 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
3091 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
3093 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
3096 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
3098 if(source._class.registered && source._class.registered.type == unitClass)
3100 if(conversions != null)
3102 if(source._class.registered == dest._class.registered)
3107 Class sourceBase, destBase;
3108 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
3109 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
3110 if(sourceBase == destBase)
3114 // Don't match enum inheriting from other enum if resolving enumeration values
3115 // TESTING: !dest.classObjectType
3116 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3118 (!source._class.registered || source._class.registered.type != enumClass) ||
3119 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3123 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3125 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3126 ((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)
3128 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3136 // JUST ADDED THIS...
3137 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3142 // Just added this for Straight conversion of ColorAlpha => Color
3143 if(source.kind == classType)
3146 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3149 for(convert = _class.conversions.first; convert; convert = convert.next)
3151 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3153 Conversion after = (conversions != null) ? conversions.last : null;
3155 if(!convert.dataType)
3156 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3157 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3158 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3159 MatchTypes(convert.dataType, dest, conversions, null, null,
3160 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3161 convert.dataType.kind == classType, false, true, warnConst))
3163 if(!conversions && !convert.Get)
3165 else if(conversions != null)
3167 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3168 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3169 (dest.kind != classType || dest._class.registered != _class.base))
3173 Conversion conv { convert = convert, isGet = true };
3174 // conversions.Add(conv);
3175 conversions.Insert(after, conv);
3188 if(dest.kind == classType)
3191 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3194 for(convert = _class.conversions.first; convert; convert = convert.next)
3196 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3198 Type constType = null;
3199 bool success = false;
3200 // Conversion after = (conversions != null) ? conversions.last : null;
3202 if(!convert.dataType)
3203 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3205 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3208 constType = { kind = pointerType, refCount = 1, type = ptrType };
3209 CopyTypeInto(ptrType, convert.dataType.type);
3210 ptrType.constant = true;
3213 // Just added this equality check to prevent recursion.... Make it safer?
3214 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3215 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3217 if(!conversions && !convert.Set)
3219 else if(conversions != null)
3221 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3222 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3223 (source.kind != classType || source._class.registered != _class.base))
3227 // *** Testing this! ***
3228 Conversion conv { convert = convert };
3229 conversions.Add(conv);
3230 //conversions.Insert(after, conv);
3236 FreeType(constType);
3242 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3244 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3245 (source.kind != classType || source._class.registered.type != structClass))
3249 // TESTING THIS... IS THIS OK??
3250 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3252 if(!dest._class.registered.dataType)
3253 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3254 // Only support this for classes...
3255 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3256 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3258 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3267 if(source.kind == classType)
3270 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3273 for(convert = _class.conversions.first; convert; convert = convert.next)
3275 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3277 Conversion after = (conversions != null) ? conversions.last : null;
3279 if(!convert.dataType)
3280 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3281 if(convert.dataType != source &&
3282 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3283 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3285 if(!conversions && !convert.Get)
3287 else if(conversions != null)
3289 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3290 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3291 (dest.kind != classType || dest._class.registered != _class.base))
3295 Conversion conv { convert = convert, isGet = true };
3297 // conversions.Add(conv);
3298 conversions.Insert(after, conv);
3307 // TESTING THIS... IS THIS OK??
3308 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3310 if(!source._class.registered.dataType)
3311 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3312 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3314 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false, warnConst))
3316 // For bool to be accepted by byte, short, etc.
3317 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3324 if(source.kind == classType || source.kind == subClassType)
3326 else if(dest.kind == source.kind &&
3327 (dest.kind != structType && dest.kind != unionType &&
3328 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3330 // RECENTLY ADDED THESE
3331 else if(dest.kind == doubleType && source.kind == floatType)
3333 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3335 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3337 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3339 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3341 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3343 else if(source.kind == enumType &&
3344 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3346 else if(dest.kind == enumType && !isConversionExploration &&
3347 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3349 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3350 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3352 Type paramSource, paramDest;
3354 if(dest.kind == methodType)
3355 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3356 if(source.kind == methodType)
3357 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3359 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3360 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3361 if(dest.kind == methodType)
3362 dest = dest.method.dataType;
3363 if(source.kind == methodType)
3364 source = source.method.dataType;
3366 paramSource = source.params.first;
3367 if(paramSource && paramSource.kind == voidType) paramSource = null;
3368 paramDest = dest.params.first;
3369 if(paramDest && paramDest.kind == voidType) paramDest = null;
3372 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3373 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3375 // Source thisClass must be derived from destination thisClass
3376 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3377 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3379 if(paramDest && paramDest.kind == classType)
3380 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3382 Compiler_Error($"method class should not take an object\n");
3385 paramDest = paramDest.next;
3387 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3389 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3393 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3395 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3401 // THIS WAS BACKWARDS:
3402 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3403 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3406 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3408 Compiler_Error($"overriding class expected to be derived from method class\n");
3412 paramSource = paramSource.next;
3418 // Source thisClass must be derived from destination thisClass
3419 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3421 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3427 // THIS WAS BACKWARDS TOO??
3428 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3429 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3432 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3434 //Compiler_Error($"overriding class expected to be derived from method class\n");
3442 // Source return type must be derived from destination return type
3443 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3445 Compiler_Warning($"incompatible return type for function\n");
3448 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3450 CheckConstCompatibility(dest.returnType, source.returnType, true);
3454 for(; paramDest; paramDest = paramDest.next)
3458 //Compiler_Warning($"not enough parameters\n");
3459 Compiler_Error($"not enough parameters\n");
3463 Type paramDestType = paramDest;
3464 Type paramSourceType = paramSource;
3465 Type type = paramDestType;
3467 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3468 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3469 paramSource.kind != templateType)
3472 ClassTemplateParameter curParam = null;
3474 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3477 if(sClass.templateClass) sClass = sClass.templateClass;
3478 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3480 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3482 for(sClass = sClass.base; sClass; sClass = sClass.base)
3484 if(sClass.templateClass) sClass = sClass.templateClass;
3485 id += sClass.templateParams.count;
3496 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3497 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3501 // paramDest must be derived from paramSource
3502 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3503 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3507 PrintType(paramDest, type, false, true);
3508 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3510 if(paramDestType != paramDest)
3511 FreeType(paramDestType);
3514 if(paramDestType != paramDest)
3515 FreeType(paramDestType);
3518 paramSource = paramSource.next;
3522 Compiler_Error($"too many parameters\n");
3527 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3531 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3532 (source.kind == arrayType || source.kind == pointerType))
3534 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3541 static void FreeConvert(Conversion convert)
3543 if(convert.resultType)
3544 FreeType(convert.resultType);
3547 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3548 char * string, OldList conversions)
3552 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3554 Class _class = link.data;
3555 if(_class.type == enumClass)
3557 OldList converts { };
3559 type.kind = classType;
3562 _class.symbol = FindClass(_class.fullName);
3563 type._class = _class.symbol;
3565 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false, false))
3568 Class enumClass = eSystem_FindClass(privateModule, "enum");
3572 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3574 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3575 for(value = e.values.first; value; value = value.next)
3577 if(!strcmp(value.name, string))
3582 FreeExpContents(sourceExp);
3583 FreeType(sourceExp.expType);
3585 sourceExp.isConstant = true;
3586 sourceExp.expType = MkClassType(baseClass.fullName);
3590 sourceExp.type = constantExp;
3591 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3592 sprintf(constant, FORMAT64D, value.data);
3594 sprintf(constant, FORMAT64HEXLL, value.data);
3595 sourceExp.constant = CopyString(constant);
3596 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3599 while(converts.first)
3601 Conversion convert = converts.first;
3602 converts.Remove(convert);
3603 conversions.Add(convert);
3612 converts.Free(FreeConvert);
3616 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3617 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3622 public bool ModuleVisibility(Module searchIn, Module searchFor)
3624 SubModule subModule;
3626 if(searchFor == searchIn)
3629 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3631 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3633 if(ModuleVisibility(subModule.module, searchFor))
3640 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3644 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3646 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3648 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3651 for(module = mainModule.application.allModules.first; module; module = module.next)
3653 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3659 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3662 Type realDest = dest;
3663 Type backupSourceExpType = null;
3664 Expression computedExp = sourceExp;
3667 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3668 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3670 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3671 ComputeExpression(computedExp /*sourceExp*/);
3674 source = sourceExp.expType;
3676 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3678 if(computedExp != sourceExp)
3680 FreeExpression(computedExp);
3681 computedExp = sourceExp;
3687 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3689 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3691 Class sourceBase, destBase;
3692 for(sourceBase = source._class.registered;
3693 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3694 sourceBase = sourceBase.base);
3695 for(destBase = dest._class.registered;
3696 destBase && destBase.base && destBase.base.type != systemClass;
3697 destBase = destBase.base);
3698 //if(source._class.registered == dest._class.registered)
3699 if(sourceBase == destBase)
3701 if(computedExp != sourceExp)
3703 FreeExpression(computedExp);
3704 computedExp = sourceExp;
3716 int64 value = MAXINT;
3720 if(computedExp.type == constantExp)
3723 value = strtoll(computedExp.constant, null, 0);
3725 value = strtoull(computedExp.constant, null, 0);
3727 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3730 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3732 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3734 if(computedExp != sourceExp)
3736 FreeExpression(computedExp);
3737 computedExp = sourceExp;
3740 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3741 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3744 source = Type { kind = intType, isSigned = false, refCount = 1 };
3747 if(dest.kind == classType)
3749 Class _class = dest._class ? dest._class.registered : null;
3751 if(_class && _class.type == unitClass)
3753 if(source.kind != classType)
3756 Type tempDest, tempSource;
3758 for(; _class.base.type != systemClass; _class = _class.base);
3760 tempDest = tempType;
3762 tempType.kind = classType;
3764 _class.symbol = FindClass(_class.fullName);
3766 tempType._class = _class.symbol;
3767 tempType.truth = dest.truth;
3769 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3771 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3772 backupSourceExpType = sourceExp.expType;
3773 sourceExp.expType = dest; dest.refCount++;
3774 //sourceExp.expType = MkClassType(_class.fullName);
3782 // Why wasn't there something like this?
3783 if(_class && _class.type == bitClass && source.kind != classType)
3785 if(!dest._class.registered.dataType)
3786 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3787 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3790 FreeType(sourceExp.expType);
3791 source = sourceExp.expType = MkClassType(dest._class.string);
3794 //source.kind = classType;
3795 //source._class = dest._class;
3799 // Adding two enumerations
3801 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3803 if(!source._class.registered.dataType)
3804 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3805 if(!dest._class.registered.dataType)
3806 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3808 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3811 source = sourceExp.expType = MkClassType(dest._class.string);
3814 //source.kind = classType;
3815 //source._class = dest._class;
3819 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3821 OldList * specs = MkList();
3825 ReadString(string, sourceExp.string);
3826 decl = SpecDeclFromString(string, specs, null);
3828 FreeExpContents(sourceExp);
3829 FreeType(sourceExp.expType);
3831 sourceExp.type = classExp;
3832 sourceExp._classExp.specifiers = specs;
3833 sourceExp._classExp.decl = decl;
3834 sourceExp.expType = dest;
3839 if(backupSourceExpType) FreeType(backupSourceExpType);
3843 else if(source.kind == classType)
3845 Class _class = source._class ? source._class.registered : null;
3847 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3850 if(dest.kind != classType)
3852 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3853 if(!source._class.registered.dataType)
3854 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3857 dest = MkClassType(source._class.string);
3858 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3859 // dest = MkClassType(source._class.string);
3863 if(dest.kind != classType)
3866 Type tempDest, tempSource;
3868 if(!source._class.registered.dataType)
3869 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3871 for(; _class.base.type != systemClass; _class = _class.base);
3873 tempSource = tempType;
3874 tempType.kind = classType;
3875 tempType._class = FindClass(_class.fullName);
3876 tempType.truth = source.truth;
3877 tempType.classObjectType = source.classObjectType;
3880 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3882 // PUT THIS BACK TESTING UNITS?
3883 if(conversions.last)
3885 ((Conversion)(conversions.last)).resultType = dest;
3889 FreeType(sourceExp.expType);
3890 sourceExp.expType = MkClassType(_class.fullName);
3891 sourceExp.expType.truth = source.truth;
3892 sourceExp.expType.classObjectType = source.classObjectType;
3894 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3896 if(!sourceExp.destType)
3898 FreeType(sourceExp.destType);
3899 sourceExp.destType = sourceExp.expType;
3900 if(sourceExp.expType)
3901 sourceExp.expType.refCount++;
3904 //source = _class.dataType;
3907 // TOCHECK: TESTING THIS NEW CODE
3908 if(!_class.dataType)
3909 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3911 dest = MkClassType(source._class.string);
3912 dest.truth = source.truth;
3913 dest.classObjectType = source.classObjectType;
3916 source = _class.dataType;
3926 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3936 if(source.kind == classType)
3938 Class _class = source._class.registered;
3939 if(_class.type == unitClass)
3941 if(!_class.dataType)
3942 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3943 source = _class.dataType;
3947 if(dest.kind == classType)
3949 Class _class = dest._class ? dest._class.registered : null;
3950 bool fittingValue = false;
3951 if(_class && _class.type == enumClass)
3953 Class enumClass = eSystem_FindClass(privateModule, "enum");
3954 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3955 if(c && value >= 0 && value <= c.largest)
3956 fittingValue = true;
3959 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3960 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3962 if(_class.type == normalClass || _class.type == noHeadClass)
3964 Expression newExp { };
3965 *newExp = *sourceExp;
3966 if(sourceExp.destType) sourceExp.destType.refCount++;
3967 if(sourceExp.expType) sourceExp.expType.refCount++;
3968 sourceExp.type = castExp;
3969 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3970 sourceExp.cast.exp = newExp;
3971 FreeType(sourceExp.expType);
3972 sourceExp.expType = null;
3973 ProcessExpressionType(sourceExp);
3975 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3978 FreeType(sourceExp.expType);
3979 sourceExp.expType = dest;
3983 if(inCompiler) FreeType(dest);
3985 if(backupSourceExpType) FreeType(backupSourceExpType);
3989 if(!_class.dataType)
3990 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3992 dest = _class.dataType;
3996 // Accept lower precision types for units, since we want to keep the unit type
3997 if(dest.kind == doubleType &&
3998 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3999 source.kind == charType || source.kind == _BoolType))
4001 specs = MkListOne(MkSpecifier(DOUBLE));
4003 else if(dest.kind == floatType &&
4004 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4005 source.kind == _BoolType || source.kind == doubleType))
4007 specs = MkListOne(MkSpecifier(FLOAT));
4009 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4010 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4013 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4014 ListAdd(specs, MkSpecifier(INT64));
4016 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
4017 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4020 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4021 ListAdd(specs, MkSpecifier(INT));
4023 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
4024 source.kind == floatType || source.kind == doubleType))
4027 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4028 ListAdd(specs, MkSpecifier(SHORT));
4030 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
4031 source.kind == floatType || source.kind == doubleType))
4034 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4035 ListAdd(specs, MkSpecifier(CHAR));
4041 if(backupSourceExpType)
4043 // Failed to convert: revert previous exp type
4044 if(sourceExp.expType) FreeType(sourceExp.expType);
4045 sourceExp.expType = backupSourceExpType;
4050 else if(dest.kind == doubleType &&
4051 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
4052 source.kind == _BoolType || source.kind == charType))
4054 specs = MkListOne(MkSpecifier(DOUBLE));
4056 else if(dest.kind == floatType &&
4057 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4059 specs = MkListOne(MkSpecifier(FLOAT));
4061 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4062 (value == 1 || value == 0))
4065 ListAdd(specs, MkSpecifier(BOOL));
4067 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4068 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
4071 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4072 ListAdd(specs, MkSpecifier(CHAR));
4074 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
4075 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
4078 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4079 ListAdd(specs, MkSpecifier(SHORT));
4081 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
4084 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4085 ListAdd(specs, MkSpecifier(INT));
4087 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
4090 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4091 ListAdd(specs, MkSpecifier(INT64));
4093 else if(dest.kind == enumType &&
4094 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4096 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4102 if(backupSourceExpType)
4104 // Failed to convert: revert previous exp type
4105 if(sourceExp.expType) FreeType(sourceExp.expType);
4106 sourceExp.expType = backupSourceExpType;
4111 if(!flag && !sourceExp.opDestType)
4113 Expression newExp { };
4114 *newExp = *sourceExp;
4117 if(sourceExp.destType) sourceExp.destType.refCount++;
4118 if(sourceExp.expType) sourceExp.expType.refCount++;
4120 sourceExp.type = castExp;
4121 if(realDest.kind == classType)
4123 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4124 FreeList(specs, FreeSpecifier);
4127 sourceExp.cast.typeName = MkTypeName(specs, null);
4128 if(newExp.type == opExp)
4130 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4133 sourceExp.cast.exp = newExp;
4135 FreeType(sourceExp.expType);
4136 sourceExp.expType = null;
4137 ProcessExpressionType(sourceExp);
4140 FreeList(specs, FreeSpecifier);
4144 if(backupSourceExpType) FreeType(backupSourceExpType);
4150 if(computedExp != sourceExp)
4152 FreeExpression(computedExp);
4153 computedExp = sourceExp;
4156 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4157 if(sourceExp.type == identifierExp)
4159 Identifier id = sourceExp.identifier;
4160 if(dest.kind == classType)
4162 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4164 Class _class = dest._class.registered;
4165 Class enumClass = eSystem_FindClass(privateModule, "enum");
4168 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4171 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4172 for(value = e.values.first; value; value = value.next)
4174 if(!strcmp(value.name, id.string))
4179 FreeExpContents(sourceExp);
4180 FreeType(sourceExp.expType);
4182 sourceExp.isConstant = true;
4183 sourceExp.expType = MkClassType(_class.fullName);
4186 sourceExp.type = constantExp;
4187 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4188 sourceExp.constant = PrintInt64(value.data);
4190 sourceExp.constant = PrintUInt64(value.data);
4191 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4201 // Loop through all enum classes
4202 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4213 #define TERTIARY(o, name, m, t, p) \
4214 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4216 exp.type = constantExp; \
4217 exp.string = p(op1.m ? op2.m : op3.m); \
4219 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4223 #define BINARY(o, name, m, t, p) \
4224 static bool name(Expression exp, Operand op1, Operand op2) \
4227 exp.type = constantExp; \
4228 exp.string = p((t)(op1.m o value2)); \
4230 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4234 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4235 static bool name(Expression exp, Operand op1, Operand op2) \
4238 exp.type = constantExp; \
4239 exp.string = p(value2 ? (op1.m o value2) : 0); \
4241 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4245 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4246 static bool name(Expression exp, Operand op1, Operand op2) \
4249 exp.type = constantExp; \
4250 exp.string = p(op1.m o value2); \
4252 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4256 #define UNARY(o, name, m, t, p) \
4257 static bool name(Expression exp, Operand op1) \
4259 exp.type = constantExp; \
4260 exp.string = p((t)(o op1.m)); \
4262 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4266 #define OPERATOR_ALL(macro, o, name) \
4267 macro(o, Int##name, i, int, PrintInt) \
4268 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4269 macro(o, Int64##name, i64, int64, PrintInt64) \
4270 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4271 macro(o, Short##name, s, short, PrintShort) \
4272 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4273 macro(o, Char##name, c, char, PrintChar) \
4274 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4275 macro(o, Float##name, f, float, PrintFloat) \
4276 macro(o, Double##name, d, double, PrintDouble)
4278 #define OPERATOR_INTTYPES(macro, o, name) \
4279 macro(o, Int##name, i, int, PrintInt) \
4280 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4281 macro(o, Int64##name, i64, int64, PrintInt64) \
4282 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4283 macro(o, Short##name, s, short, PrintShort) \
4284 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4285 macro(o, Char##name, c, char, PrintChar) \
4286 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4288 #define OPERATOR_REALTYPES(macro, o, name) \
4289 macro(o, Float##name, f, float, PrintFloat) \
4290 macro(o, Double##name, d, double, PrintDouble)
4292 // binary arithmetic
4293 OPERATOR_ALL(BINARY, +, Add)
4294 OPERATOR_ALL(BINARY, -, Sub)
4295 OPERATOR_ALL(BINARY, *, Mul)
4296 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4297 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4298 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4301 OPERATOR_ALL(UNARY, -, Neg)
4303 // unary arithmetic increment and decrement
4304 OPERATOR_ALL(UNARY, ++, Inc)
4305 OPERATOR_ALL(UNARY, --, Dec)
4307 // binary arithmetic assignment
4308 OPERATOR_ALL(BINARY, =, Asign)
4309 OPERATOR_ALL(BINARY, +=, AddAsign)
4310 OPERATOR_ALL(BINARY, -=, SubAsign)
4311 OPERATOR_ALL(BINARY, *=, MulAsign)
4312 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4313 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4314 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4317 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4318 OPERATOR_INTTYPES(BINARY, |, BitOr)
4319 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4320 OPERATOR_INTTYPES(BINARY, <<, LShift)
4321 OPERATOR_INTTYPES(BINARY, >>, RShift)
4324 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4326 // binary bitwise assignment
4327 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4328 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4329 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4330 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4331 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4333 // unary logical negation
4334 OPERATOR_INTTYPES(UNARY, !, Not)
4336 // binary logical equality
4337 OPERATOR_ALL(BINARY, ==, Equ)
4338 OPERATOR_ALL(BINARY, !=, Nqu)
4341 OPERATOR_ALL(BINARY, &&, And)
4342 OPERATOR_ALL(BINARY, ||, Or)
4344 // binary logical relational
4345 OPERATOR_ALL(BINARY, >, Grt)
4346 OPERATOR_ALL(BINARY, <, Sma)
4347 OPERATOR_ALL(BINARY, >=, GrtEqu)
4348 OPERATOR_ALL(BINARY, <=, SmaEqu)
4350 // tertiary condition operator
4351 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4353 //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
4354 #define OPERATOR_TABLE_ALL(name, type) \
4355 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4357 type##Inc, type##Dec, \
4358 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4359 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4361 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4363 type##Equ, type##Nqu, \
4364 type##And, type##Or, \
4365 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4368 #define OPERATOR_TABLE_INTTYPES(name, type) \
4369 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4371 type##Inc, type##Dec, \
4372 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4373 null, null, null, null, null, \
4375 null, null, null, null, null, \
4377 type##Equ, type##Nqu, \
4378 type##And, type##Or, \
4379 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4382 OPERATOR_TABLE_ALL(int, Int)
4383 OPERATOR_TABLE_ALL(uint, UInt)
4384 OPERATOR_TABLE_ALL(int64, Int64)
4385 OPERATOR_TABLE_ALL(uint64, UInt64)
4386 OPERATOR_TABLE_ALL(short, Short)
4387 OPERATOR_TABLE_ALL(ushort, UShort)
4388 OPERATOR_TABLE_INTTYPES(float, Float)
4389 OPERATOR_TABLE_INTTYPES(double, Double)
4390 OPERATOR_TABLE_ALL(char, Char)
4391 OPERATOR_TABLE_ALL(uchar, UChar)
4393 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4394 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4395 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4396 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4397 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4398 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4399 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4400 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4402 public void ReadString(char * output, char * string)
4404 int len = strlen(string);
4406 bool quoted = false, escaped = false;
4407 for(c = 0; c<len; c++)
4409 char ch = string[c];
4414 case 'n': output[d] = '\n'; break;
4415 case 't': output[d] = '\t'; break;
4416 case 'a': output[d] = '\a'; break;
4417 case 'b': output[d] = '\b'; break;
4418 case 'f': output[d] = '\f'; break;
4419 case 'r': output[d] = '\r'; break;
4420 case 'v': output[d] = '\v'; break;
4421 case '\\': output[d] = '\\'; break;
4422 case '\"': output[d] = '\"'; break;
4423 case '\'': output[d] = '\''; break;
4424 default: output[d] = ch;
4445 // String Unescape Copy
4447 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4448 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4449 public int UnescapeString(char * d, char * s, int len)
4453 while(j < len && (ch = s[j]))
4458 switch((ch = s[++j]))
4460 case 'n': d[k] = '\n'; break;
4461 case 't': d[k] = '\t'; break;
4462 case 'a': d[k] = '\a'; break;
4463 case 'b': d[k] = '\b'; break;
4464 case 'f': d[k] = '\f'; break;
4465 case 'r': d[k] = '\r'; break;
4466 case 'v': d[k] = '\v'; break;
4467 case '\\': d[k] = '\\'; break;
4468 case '\"': d[k] = '\"'; break;
4469 case '\'': d[k] = '\''; break;
4470 default: d[k] = '\\'; d[k] = ch;
4482 public char * OffsetEscapedString(char * s, int len, int offset)
4486 while(j < len && k < offset && (ch = s[j]))
4491 return (k == offset) ? s + j : null;
4494 public Operand GetOperand(Expression exp)
4497 Type type = exp.expType;
4500 while(type.kind == classType &&
4501 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4503 if(!type._class.registered.dataType)
4504 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4505 type = type._class.registered.dataType;
4508 if(exp.type == stringExp && op.kind == pointerType)
4510 op.ui64 = (uint64)exp.string;
4511 op.kind = pointerType;
4514 else if(exp.isConstant && exp.type == constantExp)
4516 op.kind = type.kind;
4524 if(exp.constant[0] == '\'')
4526 op.c = exp.constant[1];
4529 else if(type.isSigned)
4531 op.c = (char)strtol(exp.constant, null, 0);
4536 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4544 op.s = (short)strtol(exp.constant, null, 0);
4549 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4557 op.i = (int)strtol(exp.constant, null, 0);
4562 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4570 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4575 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4578 op.kind = int64Type;
4583 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4588 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4591 op.kind = int64Type;
4596 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4601 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4604 op.kind = int64Type;
4607 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4608 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4609 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4610 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4612 op.f = (float)strtod(exp.constant, null);
4616 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4617 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4618 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4619 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4621 op.d = (double)strtod(exp.constant, null);
4624 //case classType: For when we have operator overloading...
4625 // Pointer additions
4626 //case functionType:
4630 op.ui64 = _strtoui64(exp.constant, null, 0);
4631 op.kind = pointerType;
4641 static int64 GetEnumValue(Class _class, void * ptr)
4644 switch(_class.typeSize)
4647 if(!strcmp(_class.dataTypeString, "uint64"))
4648 v = (int64)*(uint64 *)ptr;
4650 v = (int64)*(int64 *)ptr;
4653 if(!strcmp(_class.dataTypeString, "uint"))
4654 v = (int64)*(uint *)ptr;
4656 v = (int64)*(int *)ptr;
4659 if(!strcmp(_class.dataTypeString, "uint16"))
4660 v = (int64)*(uint16 *)ptr;
4662 v = (int64)*(short *)ptr;
4665 if(!strcmp(_class.dataTypeString, "byte"))
4666 v = (int64)*(byte *)ptr;
4668 v = (int64)*(char *)ptr;
4674 static __attribute__((unused)) void UnusedFunction()
4677 a.OnGetString(0,0,0);
4680 extern int __ecereVMethodID_class_OnGetString;
4683 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4685 DataMember dataMember;
4686 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4688 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4689 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4693 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4695 void * ptr = inst.data + dataMember.offset + offset;
4696 char * result = null;
4697 exp.loc = member.loc = inst.loc;
4698 ((Identifier)member.identifiers->first).loc = inst.loc;
4700 if(!dataMember.dataType)
4701 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4702 type = dataMember.dataType;
4703 if(type.kind == classType)
4705 Class _class = type._class.registered;
4706 if(_class.type == enumClass)
4708 Class enumClass = eSystem_FindClass(privateModule, "enum");
4711 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4713 for(item = e.values.first; item; item = item.next)
4715 if(item.data == GetEnumValue(_class, ptr))
4723 exp.identifier = MkIdentifier(result);
4724 exp.type = identifierExp;
4725 exp.destType = MkClassType(_class.fullName);
4726 ProcessExpressionType(exp);
4730 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4732 if(!_class.dataType)
4733 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4734 type = _class.dataType;
4743 FreeExpContents(exp);
4745 exp.constant = PrintFloat(*(float*)ptr);
4746 exp.type = constantExp;
4751 FreeExpContents(exp);
4753 exp.constant = PrintDouble(*(double*)ptr);
4754 exp.type = constantExp;
4759 FreeExpContents(exp);
4761 exp.constant = PrintInt(*(int*)ptr);
4762 exp.type = constantExp;
4767 FreeExpContents(exp);
4769 exp.constant = PrintInt64(*(int64*)ptr);
4770 exp.type = constantExp;
4775 FreeExpContents(exp);
4776 // TODO: This should probably use proper type
4777 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4778 exp.type = constantExp;
4783 FreeExpContents(exp);
4784 // TODO: This should probably use proper type
4785 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4786 exp.type = constantExp;
4790 Compiler_Error($"Unhandled type populating instance\n");
4793 ListAdd(memberList, member);
4796 if(parentDataMember.type == unionMember)
4801 void PopulateInstance(Instantiation inst)
4803 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4804 Class _class = classSym.registered;
4805 DataMember dataMember;
4806 OldList * memberList = MkList();
4807 // Added this check and ->Add to prevent memory leaks on bad code
4809 inst.members = MkListOne(MkMembersInitList(memberList));
4811 inst.members->Add(MkMembersInitList(memberList));
4812 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4814 if(!dataMember.isProperty)
4816 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4817 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4821 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4823 void * ptr = inst.data + dataMember.offset;
4824 char * result = null;
4826 exp.loc = member.loc = inst.loc;
4827 ((Identifier)member.identifiers->first).loc = inst.loc;
4829 if(!dataMember.dataType)
4830 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4831 type = dataMember.dataType;
4832 if(type.kind == classType)
4834 Class _class = type._class.registered;
4835 if(_class.type == enumClass)
4837 Class enumClass = eSystem_FindClass(privateModule, "enum");
4840 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4842 for(item = e.values.first; item; item = item.next)
4844 if(item.data == GetEnumValue(_class, ptr))
4853 exp.identifier = MkIdentifier(result);
4854 exp.type = identifierExp;
4855 exp.destType = MkClassType(_class.fullName);
4856 ProcessExpressionType(exp);
4859 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4861 if(!_class.dataType)
4862 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4863 type = _class.dataType;
4872 exp.constant = PrintFloat(*(float*)ptr);
4873 exp.type = constantExp;
4878 exp.constant = PrintDouble(*(double*)ptr);
4879 exp.type = constantExp;
4884 exp.constant = PrintInt(*(int*)ptr);
4885 exp.type = constantExp;
4890 exp.constant = PrintInt64(*(int64*)ptr);
4891 exp.type = constantExp;
4896 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4897 exp.type = constantExp;
4901 Compiler_Error($"Unhandled type populating instance\n");
4904 ListAdd(memberList, member);
4910 void ComputeInstantiation(Expression exp)
4912 Instantiation inst = exp.instance;
4913 MembersInit members;
4914 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4915 Class _class = classSym ? classSym.registered : null;
4916 DataMember curMember = null;
4917 Class curClass = null;
4918 DataMember subMemberStack[256];
4919 int subMemberStackPos = 0;
4922 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4924 // Don't recompute the instantiation...
4925 // Non Simple classes will have become constants by now
4929 if(_class.type == normalClass || _class.type == noHeadClass)
4931 inst.data = (byte *)eInstance_New(_class);
4932 if(_class.type == normalClass)
4933 ((Instance)inst.data)._refCount++;
4936 inst.data = new0 byte[_class.structSize];
4941 for(members = inst.members->first; members; members = members.next)
4943 switch(members.type)
4945 case dataMembersInit:
4947 if(members.dataMembers)
4950 for(member = members.dataMembers->first; member; member = member.next)
4952 Identifier ident = member.identifiers ? member.identifiers->first : null;
4955 Property prop = null;
4956 DataMember dataMember = null;
4957 uint dataMemberOffset;
4961 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4964 if(curMember.isProperty)
4965 prop = (Property)curMember;
4968 dataMember = curMember;
4970 // CHANGED THIS HERE
4971 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4973 // 2013/17/29 -- It seems that this was missing here!
4974 if(_class.type == normalClass)
4975 dataMemberOffset += _class.base.structSize;
4976 // dataMemberOffset = dataMember.offset;
4983 prop = eClass_FindProperty(_class, ident.string, privateModule);
4987 if(prop.memberAccess == publicAccess)
4989 curMember = (DataMember)prop;
4990 curClass = prop._class;
4995 DataMember _subMemberStack[256];
4996 int _subMemberStackPos = 0;
4998 // FILL MEMBER STACK
4999 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
5004 if(dataMember.memberAccess == publicAccess)
5006 curMember = dataMember;
5007 curClass = dataMember._class;
5008 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
5009 subMemberStackPos = _subMemberStackPos;
5015 if(found && member.initializer && member.initializer.type == expInitializer)
5017 Expression value = member.initializer.exp;
5019 bool deepMember = false;
5022 type = prop.dataType;
5026 if(!dataMember.dataType)
5027 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
5029 type = dataMember.dataType;
5032 if(ident && ident.next)
5036 // for(; ident && type; ident = ident.next)
5037 for(ident = ident.next; ident && type; ident = ident.next)
5039 if(type.kind == classType)
5041 prop = eClass_FindProperty(type._class.registered,
5042 ident.string, privateModule);
5044 type = prop.dataType;
5047 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
5048 ident.string, &dataMemberOffset, privateModule, null, null);
5050 type = dataMember.dataType;
5053 else if(type.kind == structType || type.kind == unionType)
5056 for(memberType = type.members.first; memberType; memberType = memberType.next)
5058 if(!strcmp(memberType.name, ident.string))
5069 FreeType(value.destType);
5070 value.destType = type;
5071 if(type) type.refCount++;
5072 ComputeExpression(value);
5074 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
5076 if(type.kind == classType)
5078 Class _class = type._class.registered;
5079 if(_class.type == bitClass || _class.type == unitClass ||
5080 _class.type == enumClass)
5082 if(!_class.dataType)
5083 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5084 type = _class.dataType;
5090 void * ptr = inst.data + dataMemberOffset;
5092 if(value.type == constantExp)
5098 GetInt(value, (int*)ptr);
5103 GetInt64(value, (int64*)ptr);
5108 GetIntPtr(value, (intptr*)ptr);
5113 GetIntSize(value, (intsize*)ptr);
5118 GetFloat(value, (float*)ptr);
5123 GetDouble(value, (double *)ptr);
5128 else if(value.type == instanceExp)
5130 if(type.kind == classType)
5132 Class _class = type._class.registered;
5133 if(_class.type == structClass)
5135 ComputeTypeSize(type);
5136 if(value.instance.data)
5137 memcpy(ptr, value.instance.data, type.size);
5144 if(value.type == instanceExp && value.instance.data)
5146 if(type.kind == classType)
5148 Class _class = type._class.registered;
5149 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5151 void (*Set)(void *, void *) = (void *)prop.Set;
5152 Set(inst.data, value.instance.data);
5153 PopulateInstance(inst);
5157 else if(value.type == constantExp)
5163 void (*Set)(void *, double) = (void *)prop.Set;
5164 Set(inst.data, strtod(value.constant, null) );
5169 void (*Set)(void *, float) = (void *)prop.Set;
5170 Set(inst.data, (float)(strtod(value.constant, null)));
5175 void (*Set)(void *, int) = (void *)prop.Set;
5176 Set(inst.data, (int)strtol(value.constant, null, 0));
5181 void (*Set)(void *, int64) = (void *)prop.Set;
5182 Set(inst.data, _strtoi64(value.constant, null, 0));
5187 void (*Set)(void *, intptr) = (void *)prop.Set;
5188 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5193 void (*Set)(void *, intsize) = (void *)prop.Set;
5194 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5199 else if(value.type == stringExp)
5202 ReadString(temp, value.string);
5203 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5207 else if(!deepMember && type && _class.type == unitClass)
5211 // Only support converting units to units for now...
5212 if(value.type == constantExp)
5214 if(type.kind == classType)
5216 Class _class = type._class.registered;
5217 if(_class.type == unitClass)
5219 if(!_class.dataType)
5220 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5221 type = _class.dataType;
5224 // TODO: Assuming same base type for units...
5230 float (*Set)(float) = (void *)prop.Set;
5231 GetFloat(member.initializer.exp, &fValue);
5232 exp.constant = PrintFloat(Set(fValue));
5233 exp.type = constantExp;
5239 double (*Set)(double) = (void *)prop.Set;
5240 GetDouble(member.initializer.exp, &dValue);
5241 exp.constant = PrintDouble(Set(dValue));
5242 exp.type = constantExp;
5249 else if(!deepMember && type && _class.type == bitClass)
5253 if(value.type == instanceExp && value.instance.data)
5255 unsigned int (*Set)(void *) = (void *)prop.Set;
5256 bits = Set(value.instance.data);
5258 else if(value.type == constantExp)
5264 BitMember bitMember = (BitMember) dataMember;
5267 bits = (bits & ~bitMember.mask);
5268 if(!bitMember.dataType)
5269 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5270 type = bitMember.dataType;
5271 if(type.kind == classType && type._class && type._class.registered)
5273 if(!type._class.registered.dataType)
5274 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5275 type = type._class.registered.dataType;
5280 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5281 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5283 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5284 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5285 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5286 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5288 bits |= part << bitMember.pos;
5294 if(_class && _class.type == unitClass)
5296 ComputeExpression(member.initializer.exp);
5297 exp.constant = member.initializer.exp.constant;
5298 exp.type = constantExp;
5300 member.initializer.exp.constant = null;
5310 if(_class && _class.type == bitClass)
5312 exp.constant = PrintHexUInt(bits);
5313 exp.type = constantExp;
5315 if(exp.type != instanceExp)
5321 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5323 bool result = false;
5327 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5328 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5332 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5333 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5336 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5337 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5338 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5341 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5342 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5343 result = GetOpFloat(op, &op.f);
5346 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5347 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5348 result = GetOpDouble(op, &op.d);
5351 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5352 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5353 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5356 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5357 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5358 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5361 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5362 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5365 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5366 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5372 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5374 if(exp.op.op == SIZEOF)
5376 FreeExpContents(exp);
5377 exp.type = constantExp;
5378 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5389 // Provide default unary +
5390 Expression exp2 = exp.op.exp2;
5392 FreeExpContents(exp);
5393 FreeType(exp.expType);
5394 FreeType(exp.destType);
5400 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5402 // unary arithmetic increment and decrement
5403 //OPERATOR_ALL(UNARY, ++, Inc)
5404 //OPERATOR_ALL(UNARY, --, Dec)
5407 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5409 // unary logical negation
5411 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5417 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5419 if(Promote(op2, op1.kind, op1.type.isSigned))
5420 op2.kind = op1.kind, op2.ops = op1.ops;
5421 else if(Promote(op1, op2.kind, op2.type.isSigned))
5422 op1.kind = op2.kind, op1.ops = op2.ops;
5426 // binary arithmetic
5428 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5431 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5434 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5437 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5440 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5442 // binary arithmetic assignment
5443 //OPERATOR_ALL(BINARY, =, Asign)
5444 //OPERATOR_ALL(BINARY, +=, AddAsign)
5445 //OPERATOR_ALL(BINARY, -=, SubAsign)
5446 //OPERATOR_ALL(BINARY, *=, MulAsign)
5447 //OPERATOR_ALL(BINARY, /=, DivAsign)
5448 //OPERATOR_ALL(BINARY, %=, ModAsign)
5453 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5457 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5460 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5463 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5466 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5468 // binary bitwise assignment
5469 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5470 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5471 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5472 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5473 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5474 // binary logical equality
5476 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5479 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5483 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5486 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5488 // binary logical relational
5490 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5493 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5496 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5499 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5506 void ComputeExpression(Expression exp)
5509 char expString[10240];
5510 expString[0] = '\0';
5511 PrintExpression(exp, expString);
5518 ComputeInstantiation(exp);
5527 Expression exp1, exp2 = null;
5531 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5534 Expression e = exp.op.exp2;
5536 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5538 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5540 if(e.type == extensionCompoundExp)
5541 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5546 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5548 if(e.type == stringExp && e.string)
5550 char * string = e.string;
5551 int len = strlen(string);
5552 char * tmp = new char[len-2+1];
5553 len = UnescapeString(tmp, string + 1, len - 2);
5555 FreeExpContents(exp);
5556 exp.type = constantExp;
5557 exp.constant = PrintUInt(len + 1);
5561 Type type = e.expType;
5563 FreeExpContents(exp);
5564 exp.type = constantExp;
5565 exp.constant = PrintUInt(ComputeTypeSize(type));
5571 ComputeExpression(exp.op.exp2);
5575 ComputeExpression(exp.op.exp1);
5578 op1 = GetOperand(exp1);
5579 if(op1.type) op1.type.refCount++;
5582 op2 = GetOperand(exp2);
5583 if(op2.type) op2.type.refCount++;
5589 op1 = GetOperand(exp1);
5590 if(op1.type) op1.type.refCount++;
5593 CallOperator(exp, exp1, exp2, op1, op2);
5600 if(exp.op.exp1 && exp.op.exp2)
5605 FreeExpContents(exp);
5606 op1.ops.BitAnd(exp, op1, op2);
5615 FreeExpContents(exp);
5616 op1.ops.Mul(exp, op1, op2);
5625 FreeExpContents(exp);
5626 op1.ops.Add(exp, op1, op2);
5631 // Provide default unary +
5632 Expression exp2 = exp.op.exp2;
5634 FreeExpContents(exp);
5635 FreeType(exp.expType);
5636 FreeType(exp.destType);
5647 FreeExpContents(exp);
5648 op1.ops.Sub(exp, op1, op2);
5655 FreeExpContents(exp);
5656 op1.ops.Neg(exp, op1);
5663 FreeExpContents(exp);
5664 op1.ops.BitNot(exp, op1);
5670 FreeExpContents(exp);
5671 op1.ops.Not(exp, op1);
5674 // Binary only operators
5678 FreeExpContents(exp);
5679 op1.ops.Div(exp, op1, op2);
5685 FreeExpContents(exp);
5686 op1.ops.Mod(exp, op1, op2);
5698 FreeExpContents(exp);
5699 op1.ops.Sma(exp, op1, op2);
5708 FreeExpContents(exp);
5709 op1.ops.Grt(exp, op1, op2);
5718 FreeExpContents(exp);
5719 op1.ops.SmaEqu(exp, op1, op2);
5728 FreeExpContents(exp);
5729 op1.ops.GrtEqu(exp, op1, op2);
5738 FreeExpContents(exp);
5739 op1.ops.Equ(exp, op1, op2);
5748 FreeExpContents(exp);
5749 op1.ops.Nqu(exp, op1, op2);
5756 FreeExpContents(exp);
5757 op1.ops.BitOr(exp, op1, op2);
5763 FreeExpContents(exp);
5764 op1.ops.BitXor(exp, op1, op2);
5772 FreeExpContents(exp);
5773 exp.type = constantExp;
5774 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5778 if(op1.type) FreeType(op1.type);
5779 if(op2.type) FreeType(op2.type);
5783 case extensionExpressionExp:
5786 for(e = exp.list->first; e; e = n)
5791 OldList * list = exp.list;
5792 Expression prev = exp.prev;
5793 Expression next = exp.next;
5794 ComputeExpression(e);
5795 //FreeExpContents(exp);
5796 FreeType(exp.expType);
5797 FreeType(exp.destType);
5816 exp.isConstant = true;
5818 ComputeExpression(exp.index.exp);
5819 if(!exp.index.exp.isConstant)
5820 exp.isConstant = false;
5822 for(e = exp.index.index->first; e; e = e.next)
5824 ComputeExpression(e);
5827 // Check if this type is int
5830 exp.isConstant = false;
5832 exp.expType = Dereference(exp.index.exp.expType);
5838 Expression memberExp = exp.member.exp;
5839 Identifier memberID = exp.member.member;
5842 ComputeExpression(exp.member.exp);
5843 type = exp.member.exp.expType;
5846 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);
5847 Property prop = null;
5848 DataMember member = null;
5849 Class convertTo = null;
5850 if(type.kind == subClassType && exp.member.exp.type == classExp)
5851 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5858 PrintTypeNoConst(type, string, false, true);
5859 classSym = FindClass(string);
5860 _class = classSym ? classSym.registered : null;
5863 if(exp.member.member)
5865 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5867 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5869 if(!prop && !member && _class && exp.member.member)
5871 Symbol classSym = FindClass(exp.member.member.string);
5873 _class = classSym ? classSym.registered : null;
5874 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5881 Type type = prop.dataType;
5882 // TODO: Assuming same base type for units...
5883 if(_class.type == unitClass)
5885 if(type.kind == classType)
5887 Class _class = type._class.registered;
5888 if(_class.type == unitClass)
5890 if(!_class.dataType)
5891 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5892 type = _class.dataType;
5900 float (*Get)(float) = (void *)prop.Get;
5901 GetFloat(exp.member.exp, &value);
5902 exp.constant = PrintFloat(Get ? Get(value) : value);
5903 exp.type = constantExp;
5909 double (*Get)(double);
5910 GetDouble(exp.member.exp, &value);
5913 Get = (void *)prop.Set;
5915 Get = (void *)prop.Get;
5916 exp.constant = PrintDouble(Get ? Get(value) : value);
5917 exp.type = constantExp;
5926 Expression value = exp.member.exp;
5929 ProcessPropertyType(prop);
5931 type = prop.dataType;
5934 // printf("Investigate this\n");
5936 else if(_class.type == structClass)
5942 Class propertyClass = type._class.registered;
5943 if(propertyClass.type == structClass && value.type == instanceExp)
5945 void (*Set)(void *, void *) = (void *)prop.Set;
5946 exp.instance = Instantiation { };
5947 exp.instance.data = new0 byte[_class.structSize];
5948 exp.instance._class = MkSpecifierName(_class.fullName);
5949 exp.instance.loc = exp.loc;
5950 exp.type = instanceExp;
5951 Set(exp.instance.data, value.instance.data);
5952 PopulateInstance(exp.instance);
5959 void (*Set)(void *, int) = (void *)prop.Set;
5961 exp.instance = Instantiation { };
5962 exp.instance.data = new0 byte[_class.structSize];
5963 exp.instance._class = MkSpecifierName(_class.fullName);
5964 exp.instance.loc = exp.loc;
5965 exp.type = instanceExp;
5967 GetInt(value, &intValue);
5969 Set(exp.instance.data, intValue);
5970 PopulateInstance(exp.instance);
5976 void (*Set)(void *, int64) = (void *)prop.Set;
5978 exp.instance = Instantiation { };
5979 exp.instance.data = new0 byte[_class.structSize];
5980 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5981 exp.instance.loc = exp.loc;
5982 exp.type = instanceExp;
5984 GetInt64(value, &intValue);
5986 Set(exp.instance.data, intValue);
5987 PopulateInstance(exp.instance);
5994 void (*Set)(void *, intptr) = (void *)prop.Set;
5996 exp.instance = Instantiation { };
5997 exp.instance.data = new0 byte[_class.structSize];
5998 exp.instance._class = MkSpecifierName(_class.fullName);
5999 exp.instance.loc = exp.loc;
6000 exp.type = instanceExp;
6002 GetIntPtr(value, &intValue);
6004 Set(exp.instance.data, intValue);
6005 PopulateInstance(exp.instance);
6012 void (*Set)(void *, intsize) = (void *)prop.Set;
6014 exp.instance = Instantiation { };
6015 exp.instance.data = new0 byte[_class.structSize];
6016 exp.instance._class = MkSpecifierName(_class.fullName);
6017 exp.instance.loc = exp.loc;
6018 exp.type = instanceExp;
6020 GetIntSize(value, &intValue);
6022 Set(exp.instance.data, intValue);
6023 PopulateInstance(exp.instance);
6029 void (*Set)(void *, float) = (void *)prop.Set;
6031 exp.instance = Instantiation { };
6032 exp.instance.data = new0 byte[_class.structSize];
6033 exp.instance._class = MkSpecifierName(_class.fullName);
6034 exp.instance.loc = exp.loc;
6035 exp.type = instanceExp;
6037 GetFloat(value, &floatValue);
6039 Set(exp.instance.data, floatValue);
6040 PopulateInstance(exp.instance);
6046 void (*Set)(void *, double) = (void *)prop.Set;
6048 exp.instance = Instantiation { };
6049 exp.instance.data = new0 byte[_class.structSize];
6050 exp.instance._class = MkSpecifierName(_class.fullName);
6051 exp.instance.loc = exp.loc;
6052 exp.type = instanceExp;
6054 GetDouble(value, &doubleValue);
6056 Set(exp.instance.data, doubleValue);
6057 PopulateInstance(exp.instance);
6062 else if(_class.type == bitClass)
6068 Class propertyClass = type._class.registered;
6069 if(propertyClass.type == structClass && value.instance.data)
6071 unsigned int (*Set)(void *) = (void *)prop.Set;
6072 unsigned int bits = Set(value.instance.data);
6073 exp.constant = PrintHexUInt(bits);
6074 exp.type = constantExp;
6077 else if(_class.type == bitClass)
6080 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6083 GetUInt(exp.member.exp, &value);
6085 exp.constant = PrintHexUInt(bits);
6086 exp.type = constantExp;
6094 if(_class.type == bitClass)
6097 GetUInt(exp.member.exp, &value);
6103 Class _class = type._class.registered;
6104 if(_class.type == structClass)
6106 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6108 exp.instance = Instantiation { };
6109 exp.instance.data = new0 byte[_class.structSize];
6110 exp.instance._class = MkSpecifierName(_class.fullName);
6111 exp.instance.loc = exp.loc;
6112 //exp.instance.fullSet = true;
6113 exp.type = instanceExp;
6114 Get(value, exp.instance.data);
6115 PopulateInstance(exp.instance);
6117 else if(_class.type == bitClass)
6119 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6120 uint64 bits = Get(value);
6121 exp.constant = PrintHexUInt64(bits);
6122 exp.type = constantExp;
6128 else if(_class.type == structClass)
6130 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6135 Class _class = type._class.registered;
6136 if(_class.type == structClass && value)
6138 void (*Get)(void *, void *) = (void *)prop.Get;
6140 exp.instance = Instantiation { };
6141 exp.instance.data = new0 byte[_class.structSize];
6142 exp.instance._class = MkSpecifierName(_class.fullName);
6143 exp.instance.loc = exp.loc;
6144 //exp.instance.fullSet = true;
6145 exp.type = instanceExp;
6146 Get(value, exp.instance.data);
6147 PopulateInstance(exp.instance);
6155 char * value = exp.member.exp.instance.data;
6160 Class _class = type._class.registered;
6161 if(_class.type == normalClass)
6163 void *(*Get)(void *) = (void *)prop.Get;
6165 exp.instance = Instantiation { };
6166 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6167 exp.type = instanceExp;
6168 exp.instance.data = Get(value, exp.instance.data);
6180 exp.isConstant = false;
6188 if(exp.type != ExpressionType::memberExp)
6190 FreeExpression(memberExp);
6191 FreeIdentifier(memberID);
6197 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6198 FreeExpContents(exp);
6199 exp.constant = PrintUInt(ComputeTypeSize(type));
6200 exp.type = constantExp;
6206 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6207 if(classSym && classSym.registered)
6209 if(classSym.registered.fixed)
6211 FreeSpecifier(exp._class);
6212 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6213 exp.type = constantExp;
6217 char className[1024];
6218 strcpy(className, "__ecereClass_");
6219 FullClassNameCat(className, classSym.string, true);
6220 //MangleClassName(className);
6222 DeclareClass(classSym, className);
6224 FreeExpContents(exp);
6225 exp.type = pointerExp;
6226 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6227 exp.member.member = MkIdentifier("structSize");
6237 if(exp.type == castExp)
6240 ComputeExpression(exp.cast.exp);
6243 if(e && exp.expType)
6246 type = exp.destType;
6249 if(type.kind == classType)
6251 Class _class = type._class.registered;
6252 if(_class && (_class.type == unitClass || _class.type == bitClass))
6254 if(!_class.dataType)
6255 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6256 type = _class.dataType;
6267 if(GetChar(e, &value))
6269 FreeExpContents(exp);
6270 exp.constant = PrintChar(value);
6271 exp.type = constantExp;
6276 unsigned char value = 0;
6277 if(GetUChar(e, &value))
6279 FreeExpContents(exp);
6280 exp.constant = PrintUChar(value);
6281 exp.type = constantExp;
6289 if(GetShort(e, &value))
6291 FreeExpContents(exp);
6292 exp.constant = PrintShort(value);
6293 exp.type = constantExp;
6298 unsigned short value = 0;
6299 if(GetUShort(e, &value))
6301 FreeExpContents(exp);
6302 exp.constant = PrintUShort(value);
6303 exp.type = constantExp;
6311 if(GetInt(e, &value))
6313 FreeExpContents(exp);
6314 exp.constant = PrintInt(value);
6315 exp.type = constantExp;
6320 unsigned int value = 0;
6321 if(GetUInt(e, &value))
6323 FreeExpContents(exp);
6324 exp.constant = PrintUInt(value);
6325 exp.type = constantExp;
6333 if(GetInt64(e, &value))
6335 FreeExpContents(exp);
6336 exp.constant = PrintInt64(value);
6337 exp.type = constantExp;
6343 if(GetUInt64(e, &value))
6345 FreeExpContents(exp);
6346 exp.constant = PrintUInt64(value);
6347 exp.type = constantExp;
6355 if(GetIntPtr(e, &value))
6357 FreeExpContents(exp);
6358 exp.constant = PrintInt64((int64)value);
6359 exp.type = constantExp;
6365 if(GetUIntPtr(e, &value))
6367 FreeExpContents(exp);
6368 exp.constant = PrintUInt64((uint64)value);
6369 exp.type = constantExp;
6377 if(GetIntSize(e, &value))
6379 FreeExpContents(exp);
6380 exp.constant = PrintInt64((int64)value);
6381 exp.type = constantExp;
6387 if(GetUIntSize(e, &value))
6389 FreeExpContents(exp);
6390 exp.constant = PrintUInt64((uint64)value);
6391 exp.type = constantExp;
6398 if(GetFloat(e, &value))
6400 FreeExpContents(exp);
6401 exp.constant = PrintFloat(value);
6402 exp.type = constantExp;
6409 if(GetDouble(e, &value))
6411 FreeExpContents(exp);
6412 exp.constant = PrintDouble(value);
6413 exp.type = constantExp;
6428 // Caring only about last expression for now...
6429 ComputeExpression(exp.cond.exp->last);
6430 if(exp.cond.elseExp)
6431 ComputeExpression(exp.cond.elseExp);
6433 ComputeExpression(exp.cond.cond);
6435 op1 = GetOperand(exp.cond.cond);
6436 if(op1.type) op1.type.refCount++;
6437 op2 = GetOperand(exp.cond.exp->last);
6438 if(op2.type) op2.type.refCount++;
6439 op3 = GetOperand(exp.cond.elseExp);
6440 if(op3.type) op3.type.refCount++;
6442 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6443 if(op1.type) FreeType(op1.type);
6444 if(op2.type) FreeType(op2.type);
6445 if(op3.type) FreeType(op3.type);
6451 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6456 OldList converts { };
6459 if(destType.kind == voidType)
6462 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6466 // for(convert = converts.last; convert; convert = convert.prev)
6467 for(convert = converts.first; convert; convert = convert.next)
6469 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6472 Expression newExp { };
6473 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6475 // TODO: Check this...
6479 newExp.destType = null;
6484 exp.type = memberExp;
6485 exp.addedThis = true;
6486 exp.member.exp = newExp;
6487 FreeType(exp.member.exp.expType);
6489 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6490 exp.member.exp.expType.classObjectType = objectType;
6491 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6492 exp.member.memberType = propertyMember;
6493 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6494 // TESTING THIS... for (int)degrees
6495 exp.needCast = true;
6496 if(exp.expType) exp.expType.refCount++;
6497 ApplyAnyObjectLogic(exp.member.exp);
6502 /*if(exp.isConstant)
6504 // Color { ColorRGB = [exp] };
6505 exp.type = instanceExp;
6506 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6507 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6508 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6512 // If not constant, don't turn it yet into an instantiation
6513 // (Go through the deep members system first)
6514 exp.type = memberExp;
6515 exp.addedThis = true;
6516 exp.member.exp = newExp;
6518 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6519 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6520 newExp.expType._class.registered.type == noHeadClass)
6522 newExp.byReference = true;
6525 FreeType(exp.member.exp.expType);
6526 /*exp.member.exp.expType = convert.convert.dataType;
6527 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6528 exp.member.exp.expType = null;
6529 if(convert.convert.dataType)
6531 exp.member.exp.expType = { };
6532 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6533 exp.member.exp.expType.refCount = 1;
6534 exp.member.exp.expType.classObjectType = objectType;
6535 ApplyAnyObjectLogic(exp.member.exp);
6538 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6539 exp.member.memberType = reverseConversionMember;
6540 exp.expType = convert.resultType ? convert.resultType :
6541 MkClassType(convert.convert._class.fullName);
6542 exp.needCast = true;
6543 if(convert.resultType) convert.resultType.refCount++;
6549 FreeType(exp.expType);
6552 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6553 if(exp.destType.casted)
6554 exp.needCast = true;
6555 if(exp.expType) exp.expType.refCount++;
6559 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6560 if(exp.destType.casted)
6561 exp.needCast = true;
6562 if(convert.resultType)
6563 convert.resultType.refCount++;
6567 if(exp.isConstant && inCompiler)
6568 ComputeExpression(exp);
6570 converts.Free(FreeConvert);
6573 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6575 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6577 if(!result && exp.expType && exp.destType)
6579 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6580 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6581 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6582 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6586 // if(result) CheckTemplateTypes(exp);
6590 void CheckTemplateTypes(Expression exp)
6592 Expression nbExp = GetNonBracketsExp(exp);
6593 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6594 (nbExp == exp || nbExp.type != castExp))
6596 Expression newExp { };
6599 if(exp.destType) exp.destType.refCount++;
6600 if(exp.expType) exp.expType.refCount++;
6604 switch(exp.expType.kind)
6607 if(exp.destType.classObjectType)
6609 // We need to pass the address, just pass it along (Undo what was done above)
6610 if(exp.destType) exp.destType.refCount--;
6611 if(exp.expType) exp.expType.refCount--;
6616 // If we're looking for value:
6617 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6619 OldList * unionDefs = MkList();
6620 OldList * statements = MkList();
6621 context = PushContext();
6622 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6623 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6624 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6625 exp.type = extensionCompoundExp;
6626 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6627 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6628 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6629 exp.compound.compound.context = context;
6630 PopContext(context);
6635 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6636 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6637 exp.needCast = true;
6641 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6643 Expression newExp { };
6646 if(exp.destType) exp.destType.refCount++;
6647 if(exp.expType) exp.expType.refCount++;
6651 switch(exp.expType.kind)
6654 if(exp.destType.classObjectType)
6656 // We need to pass the address, just pass it along (Undo what was done above)
6657 if(exp.destType) exp.destType.refCount--;
6658 if(exp.expType) exp.expType.refCount--;
6663 // If we're looking for value:
6664 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6666 OldList * unionDefs = MkList();
6667 OldList * statements = MkList();
6668 context = PushContext();
6669 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6670 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6671 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6672 exp.type = extensionCompoundExp;
6673 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6674 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6675 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6676 exp.compound.compound.context = context;
6677 PopContext(context);
6682 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6684 exp.type = bracketsExp;
6685 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6686 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6687 ProcessExpressionType(exp.list->first);
6692 exp.type = bracketsExp;
6693 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6694 exp.needTemplateCast = 2;
6695 newExp.needCast = true;
6696 newExp.needTemplateCast = 2;
6697 ProcessExpressionType(exp.list->first);
6703 if(exp.expType.kind == templateType)
6705 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6708 FreeType(exp.destType);
6709 FreeType(exp.expType);
6714 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6719 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6720 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6724 char typeString[1024];
6726 OldList * specs = MkList();
6727 typeString[0] = '\0';
6728 PrintType(exp.expType, typeString, false, false);
6729 decl = SpecDeclFromString(typeString, specs, null);
6732 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6733 exp.cast.typeName = MkTypeName(specs, decl);
6734 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6735 exp.cast.exp.needCast = true;
6742 // TODO: The Symbol tree should be reorganized by namespaces
6744 // - Tree of all symbols within (stored without namespace)
6745 // - Tree of sub-namespaces
6747 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6749 int nsLen = strlen(nameSpace);
6751 // Start at the name space prefix
6752 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6754 char * s = symbol.string;
6755 if(!strncmp(s, nameSpace, nsLen))
6757 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6760 for(c = strlen(s)-1; c >= 0; c--)
6765 if(!strcmp(namePart, name))
6767 // TODO: Error on ambiguity
6777 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6780 char nameSpace[1024];
6781 const char * namePart;
6782 bool gotColon = false;
6784 nameSpace[0] = '\0';
6785 for(c = strlen(name)-1; c >= 0; c--)
6792 namePart = name+c+1;
6793 while(c >= 0 && name[c] == ':') c--;
6796 // Try an exact match first
6797 Symbol symbol = (Symbol)tree.FindString(name);
6801 // Namespace specified
6802 memcpy(nameSpace, name, c + 1);
6805 return ScanWithNameSpace(tree, nameSpace, namePart);
6809 // Looking for a global symbol, e.g. ::Sleep()
6810 Symbol symbol = (Symbol)tree.FindString(namePart);
6815 // Name only (no namespace specified)
6816 Symbol symbol = (Symbol)tree.FindString(namePart);
6819 return ScanWithNameSpace(tree, "", namePart);
6824 static void ProcessDeclaration(Declaration decl);
6826 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6829 //Time startTime = GetTime();
6831 // Optimize this later? Do this before/less?
6833 Symbol symbol = null;
6834 // First, check if the identifier is declared inside the function
6835 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6837 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6839 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6845 strcpy(curName, thisNameSpace);
6846 strcat(curName, "::");
6847 strcat(curName, name);
6848 // Try to resolve in current namespace first
6849 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6852 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6855 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6857 if(symbol || ctx == endContext) break;
6859 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6861 if(symbol.pointerExternal.type == functionExternal)
6863 FunctionDefinition function = symbol.pointerExternal.function;
6865 // Modified this recently...
6866 Context tmpContext = curContext;
6868 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6869 curContext = tmpContext;
6871 symbol.pointerExternal.symbol = symbol;
6874 DeclareType(symbol.type, true, true);
6876 ast->Insert(curExternal.prev, symbol.pointerExternal);
6878 symbol.id = curExternal.symbol.idCode;
6881 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6883 ast->Move(symbol.pointerExternal, curExternal.prev);
6884 symbol.id = curExternal.symbol.idCode;
6888 //findSymbolTotalTime += GetTime() - startTime;
6893 static void GetTypeSpecs(Type type, OldList * specs)
6895 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6900 if(type._class.registered)
6902 if(!type._class.registered.dataType)
6903 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6904 GetTypeSpecs(type._class.registered.dataType, specs);
6908 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6909 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6910 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6911 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6912 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6913 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6914 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6915 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6918 ListAdd(specs, MkSpecifier(INT)); break;
6922 static void PrintArraySize(Type arrayType, char * string)
6927 if(arrayType.enumClass)
6928 strcat(size, arrayType.enumClass.string);
6929 else if(arrayType.arraySizeExp)
6930 PrintExpression(arrayType.arraySizeExp, size);
6932 strcat(string, size);
6935 // WARNING : This function expects a null terminated string since it recursively concatenate...
6936 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6940 if(printConst && type.constant)
6941 strcat(string, "const ");
6946 Symbol c = type._class;
6947 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6948 // look into merging with thisclass ?
6949 if(type.classObjectType == typedObject)
6950 strcat(string, "typed_object");
6951 else if(type.classObjectType == anyObject)
6952 strcat(string, "any_object");
6956 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6958 if(type.byReference)
6959 strcat(string, " &");
6962 case voidType: strcat(string, "void"); break;
6963 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6964 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6965 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6966 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6967 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6968 case _BoolType: strcat(string, "_Bool"); break;
6969 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6970 case floatType: strcat(string, "float"); break;
6971 case doubleType: strcat(string, "double"); break;
6975 strcat(string, "struct ");
6976 strcat(string, type.enumName);
6978 else if(type.typeName)
6979 strcat(string, type.typeName);
6983 strcat(string, "struct { ");
6984 for(member = type.members.first; member; member = member.next)
6986 PrintType(member, string, true, fullName);
6987 strcat(string,"; ");
6995 strcat(string, "union ");
6996 strcat(string, type.enumName);
6998 else if(type.typeName)
6999 strcat(string, type.typeName);
7002 strcat(string, "union ");
7003 strcat(string,"(unnamed)");
7009 strcat(string, "enum ");
7010 strcat(string, type.enumName);
7012 else if(type.typeName)
7013 strcat(string, type.typeName);
7015 strcat(string, "int"); // "enum");
7018 strcat(string, "...");
7021 strcat(string, "subclass(");
7022 strcat(string, type._class ? type._class.string : "int");
7023 strcat(string, ")");
7026 strcat(string, type.templateParameter.identifier.string);
7029 strcat(string, "thisclass");
7032 strcat(string, "__builtin_va_list");
7038 static void PrintName(Type type, char * string, bool fullName)
7040 if(type.name && type.name[0])
7043 strcat(string, type.name);
7046 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7047 if(name) name += 2; else name = type.name;
7048 strcat(string, name);
7053 static void PrintAttribs(Type type, char * string)
7057 if(type.dllExport) strcat(string, "dllexport ");
7058 if(type.attrStdcall) strcat(string, "stdcall ");
7062 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7064 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7066 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7067 PrintAttribs(type, string);
7068 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7069 strcat(string, " const");
7070 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7071 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7072 strcat(string, " (");
7073 if(type.kind == pointerType)
7075 if(type.type.kind == functionType || type.type.kind == methodType)
7076 PrintAttribs(type.type, string);
7078 if(type.kind == pointerType)
7080 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7081 strcat(string, "*");
7083 strcat(string, " *");
7085 if(printConst && type.constant && type.kind == pointerType)
7086 strcat(string, " const");
7089 PrintTypeSpecs(type, string, fullName, printConst);
7092 static void PostPrintType(Type type, char * string, bool fullName)
7094 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7095 strcat(string, ")");
7096 if(type.kind == arrayType)
7097 PrintArraySize(type, string);
7098 else if(type.kind == functionType)
7101 strcat(string, "(");
7102 for(param = type.params.first; param; param = param.next)
7104 PrintType(param, string, true, fullName);
7105 if(param.next) strcat(string, ", ");
7107 strcat(string, ")");
7109 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7110 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7114 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7116 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7118 PrePrintType(type, string, fullName, null, printConst);
7120 if(type.thisClass || (printName && type.name && type.name[0]))
7121 strcat(string, " ");
7122 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7124 Symbol _class = type.thisClass;
7125 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7127 if(type.classObjectType == classPointer)
7128 strcat(string, "class");
7130 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7132 else if(_class && _class.string)
7134 String s = _class.string;
7139 char * name = RSearchString(s, "::", strlen(s), true, false);
7140 if(name) name += 2; else name = s;
7141 strcat(string, name);
7144 strcat(string, "::");
7147 if(printName && type.name)
7148 PrintName(type, string, fullName);
7149 PostPrintType(type, string, fullName);
7150 if(type.bitFieldCount)
7153 sprintf(count, ":%d", type.bitFieldCount);
7154 strcat(string, count);
7158 void PrintType(Type type, char * string, bool printName, bool fullName)
7160 _PrintType(type, string, printName, fullName, true);
7163 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7165 _PrintType(type, string, printName, fullName, false);
7168 static Type FindMember(Type type, char * string)
7171 for(memberType = type.members.first; memberType; memberType = memberType.next)
7173 if(!memberType.name)
7175 Type subType = FindMember(memberType, string);
7179 else if(!strcmp(memberType.name, string))
7185 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7188 for(memberType = type.members.first; memberType; memberType = memberType.next)
7190 if(!memberType.name)
7192 Type subType = FindMember(memberType, string);
7195 *offset += memberType.offset;
7199 else if(!strcmp(memberType.name, string))
7201 *offset += memberType.offset;
7208 public bool GetParseError() { return parseError; }
7210 Expression ParseExpressionString(char * expression)
7214 fileInput = TempFile { };
7215 fileInput.Write(expression, 1, strlen(expression));
7216 fileInput.Seek(0, start);
7219 parsedExpression = null;
7221 expression_yyparse();
7224 return parsedExpression;
7227 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7229 Identifier id = exp.identifier;
7230 Method method = null;
7231 Property prop = null;
7232 DataMember member = null;
7233 ClassProperty classProp = null;
7235 if(_class && _class.type == enumClass)
7237 NamedLink64 value = null;
7238 Class enumClass = eSystem_FindClass(privateModule, "enum");
7242 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7244 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7245 for(value = e.values.first; value; value = value.next)
7247 if(!strcmp(value.name, id.string))
7254 FreeExpContents(exp);
7256 exp.type = constantExp;
7257 exp.isConstant = true;
7258 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7259 sprintf(constant, FORMAT64D, value.data);
7261 sprintf(constant, FORMAT64HEX, value.data);
7262 exp.constant = CopyString(constant);
7263 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7264 exp.expType = MkClassType(baseClass.fullName);
7272 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7274 ProcessMethodType(method);
7281 // TOCHECK: Put it back to what it was...
7282 // methodClass = _class;
7283 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7288 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7291 ProcessPropertyType(prop);
7292 exp.expType = prop.dataType;
7293 if(prop.dataType) prop.dataType.refCount++;
7296 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7298 if(!member.dataType)
7299 member.dataType = ProcessTypeString(member.dataTypeString, false);
7300 exp.expType = member.dataType;
7301 if(member.dataType) member.dataType.refCount++;
7304 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7306 if(!classProp.dataType)
7307 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7309 if(classProp.constant)
7311 FreeExpContents(exp);
7313 exp.isConstant = true;
7314 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7316 //char constant[256];
7317 exp.type = stringExp;
7318 exp.constant = QMkString((char *)classProp.Get(_class));
7323 exp.type = constantExp;
7324 sprintf(constant, "%d", (int)classProp.Get(_class));
7325 exp.constant = CopyString(constant);
7333 exp.expType = classProp.dataType;
7334 if(classProp.dataType) classProp.dataType.refCount++;
7340 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7342 BinaryTree * tree = &nameSpace.functions;
7343 GlobalData data = (GlobalData)tree->FindString(name);
7347 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7349 data = ScanGlobalData(child, name);
7357 static GlobalData FindGlobalData(char * name)
7360 NameSpace * nameSpace;
7361 nameSpace = globalData;
7362 for(c = 0; name[c]; c++)
7364 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7366 NameSpace * newSpace;
7367 char * spaceName = new char[c - start + 1];
7368 strncpy(spaceName, name + start, c - start);
7369 spaceName[c-start] = '\0';
7370 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7374 nameSpace = newSpace;
7375 if(name[c] == ':') c++;
7381 return ScanGlobalData(nameSpace, name + start);
7386 static int definedExpStackPos;
7387 static void * definedExpStack[512];
7389 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7390 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7392 Expression prev = checkedExp.prev, next = checkedExp.next;
7394 FreeExpContents(checkedExp);
7395 FreeType(checkedExp.expType);
7396 FreeType(checkedExp.destType);
7398 *checkedExp = *newExp;
7402 checkedExp.prev = prev;
7403 checkedExp.next = next;
7406 void ApplyAnyObjectLogic(Expression e)
7408 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7410 char debugExpString[4096];
7411 debugExpString[0] = '\0';
7412 PrintExpression(e, debugExpString);
7415 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7417 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7418 //ellipsisDestType = destType;
7421 Type type = e.expType;
7422 Class _class = null;
7423 //Type destType = e.destType;
7425 if(type.kind == classType && type._class && type._class.registered)
7427 _class = type._class.registered;
7429 else if(type.kind == subClassType)
7431 _class = FindClass("ecere::com::Class").registered;
7435 char string[1024] = "";
7438 PrintTypeNoConst(type, string, false, true);
7439 classSym = FindClass(string);
7440 if(classSym) _class = classSym.registered;
7443 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...
7444 (!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))) ||
7445 destType.byReference)))
7447 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7449 Expression checkedExp = e, newExp;
7451 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7453 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7455 if(checkedExp.type == extensionCompoundExp)
7457 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7460 checkedExp = checkedExp.list->last;
7462 else if(checkedExp.type == castExp)
7463 checkedExp = checkedExp.cast.exp;
7466 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7468 newExp = checkedExp.op.exp2;
7469 checkedExp.op.exp2 = null;
7470 FreeExpContents(checkedExp);
7472 if(e.expType && e.expType.passAsTemplate)
7475 ComputeTypeSize(e.expType);
7476 sprintf(size, "%d", e.expType.size);
7477 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7478 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7479 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7482 ReplaceExpContents(checkedExp, newExp);
7483 e.byReference = true;
7485 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7487 Expression checkedExp; //, newExp;
7490 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7492 e.type == identifierExp ||
7493 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7494 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7495 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7498 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7500 Context context = PushContext();
7502 OldList * specs = MkList();
7503 char typeString[1024];
7504 Expression newExp { };
7506 typeString[0] = '\0';
7509 //if(e.destType) e.destType.refCount++;
7510 // if(exp.expType) exp.expType.refCount++;
7513 newExp.expType = null;
7515 PrintTypeNoConst(e.expType, typeString, false, true);
7516 decl = SpecDeclFromString(typeString, specs, null);
7517 newExp.destType = ProcessType(specs, decl);
7519 curContext = context;
7521 // We need a current compound for this
7525 OldList * stmts = MkList();
7526 e.type = extensionCompoundExp;
7527 sprintf(name, "__internalValue%03X", internalValueCounter++);
7528 if(!curCompound.compound.declarations)
7529 curCompound.compound.declarations = MkList();
7530 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7531 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7532 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7533 e.compound = MkCompoundStmt(null, stmts);
7536 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7539 e.compound = MkCompoundStmt(
7540 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7541 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7543 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7547 Type type = e.destType;
7549 CopyTypeInto(e.destType, type);
7550 e.destType.refCount = 1;
7551 e.destType.classObjectType = none;
7555 e.compound.compound.context = context;
7556 PopContext(context);
7557 curContext = context.parent;
7561 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7563 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7565 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7567 if(checkedExp.type == extensionCompoundExp)
7569 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7572 checkedExp = checkedExp.list->last;
7574 else if(checkedExp.type == castExp)
7575 checkedExp = checkedExp.cast.exp;
7578 Expression operand { };
7579 operand = *checkedExp;
7581 checkedExp.destType = ProcessTypeString("void *", false);
7582 checkedExp.expType = checkedExp.destType;
7583 checkedExp.destType.refCount++;
7585 checkedExp.type = opExp;
7586 checkedExp.op.op = '&';
7587 checkedExp.op.exp1 = null;
7588 checkedExp.op.exp2 = operand;
7590 //newExp = MkExpOp(null, '&', checkedExp);
7592 //ReplaceExpContents(checkedExp, newExp);
7599 // If expression type is a simple class, make it an address
7600 // FixReference(e, true);
7603 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7604 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7605 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7607 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"))
7609 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7613 Expression thisExp { };
7616 thisExp.prev = null;
7617 thisExp.next = null;
7620 e.type = bracketsExp;
7621 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7622 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7623 ((Expression)e.list->first).byReference = true;
7625 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7627 e.expType = thisExp.expType;
7628 e.expType.refCount++;
7633 CopyTypeInto(e.expType, thisExp.expType);
7634 e.expType.byReference = false;
7635 e.expType.refCount = 1;
7637 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7638 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7640 e.expType.classObjectType = none;
7645 // TOFIX: Try this for a nice IDE crash!
7647 // The other way around
7650 if(destType && e.expType &&
7651 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7652 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7653 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7655 if(destType.kind == ellipsisType)
7657 Compiler_Error($"Unspecified type\n");
7659 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7661 bool byReference = e.expType.byReference;
7662 Expression thisExp { };
7664 OldList * specs = MkList();
7665 char typeString[1024]; // Watch buffer overruns
7667 ClassObjectType backupClassObjectType;
7668 bool backupByReference;
7670 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7675 backupClassObjectType = type.classObjectType;
7676 backupByReference = type.byReference;
7678 type.classObjectType = none;
7679 type.byReference = false;
7681 typeString[0] = '\0';
7682 PrintType(type, typeString, false, true);
7683 decl = SpecDeclFromString(typeString, specs, null);
7685 type.classObjectType = backupClassObjectType;
7686 type.byReference = backupByReference;
7689 thisExp.prev = null;
7690 thisExp.next = null;
7693 if( ( type.kind == classType && type._class && type._class.registered &&
7694 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7695 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7696 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7697 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7702 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7705 CopyTypeInto(e.expType, type);
7706 e.expType.byReference = false;
7707 e.expType.refCount = 1;
7712 e.cast.typeName = MkTypeName(specs, decl);
7713 e.cast.exp = thisExp;
7714 e.byReference = true;
7718 e.destType = destType;
7719 destType.refCount++;
7724 void ApplyLocation(Expression exp, Location loc)
7730 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7731 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7737 for(e = exp.list->first; e; e = e.next)
7738 ApplyLocation(e, loc);
7745 for(e = exp.index.index->first; e; e = e.next)
7746 ApplyLocation(e, loc);
7749 ApplyLocation(exp.index.exp, loc);
7752 if(exp.call.arguments)
7755 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7756 ApplyLocation(arg, loc);
7759 ApplyLocation(exp.call.exp, loc);
7764 ApplyLocation(exp.member.exp, loc);
7768 ApplyLocation(exp.cast.exp, loc);
7774 for(e = exp.cond.exp->first; e; e = e.next)
7775 ApplyLocation(e, loc);
7778 ApplyLocation(exp.cond.cond, loc);
7779 if(exp.cond.elseExp)
7780 ApplyLocation(exp.cond.elseExp, loc);
7784 ApplyLocation(exp.vaArg.exp, loc);
7791 void ProcessExpressionType(Expression exp)
7793 bool unresolved = false;
7794 Location oldyylloc = yylloc;
7795 bool notByReference = false;
7797 char debugExpString[4096];
7798 debugExpString[0] = '\0';
7799 PrintExpression(exp, debugExpString);
7801 if(!exp || exp.expType)
7804 //eSystem_Logf("%s\n", expString);
7806 // Testing this here
7812 Identifier id = exp.identifier;
7813 if(!id || !topContext) return;
7815 // DOING THIS LATER NOW...
7816 if(id._class && id._class.name)
7818 id.classSym = id._class.symbol; // FindClass(id._class.name);
7819 /* TODO: Name Space Fix ups
7821 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7825 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7827 exp.expType = ProcessTypeString("Module", true);
7831 if(!strcmp(id.string, "__runtimePlatform"))
7833 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7836 else if(strstr(id.string, "__ecereClass") == id.string)
7838 exp.expType = ProcessTypeString("ecere::com::Class", true);
7841 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7843 // Added this here as well
7844 ReplaceClassMembers(exp, thisClass);
7845 if(exp.type != identifierExp)
7847 ProcessExpressionType(exp);
7851 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7856 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7857 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7858 if(!symbol/* && exp.destType*/)
7860 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7866 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7867 if(exp.type != identifierExp)
7869 ProcessExpressionType(exp);
7873 // Static methods called from inside the _class
7874 else if(currentClass && !id._class)
7876 if(ResolveIdWithClass(exp, currentClass, true))
7879 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7883 // If we manage to resolve this symbol
7886 Type type = symbol.type;
7887 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7889 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7891 Context context = SetupTemplatesContext(_class);
7892 type = ReplaceThisClassType(_class);
7893 FinishTemplatesContext(context);
7894 if(type) type.refCount = 0; // We'll be incrementing it right below...
7897 FreeSpecifier(id._class);
7900 id.string = CopyString(symbol.string);
7907 // Commented this out, it was making non-constant enum parameters seen as constant
7908 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7909 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7910 // Add missing cases here... enum Classes...
7911 exp.isConstant = true;
7913 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7914 if(symbol.isParam || !strcmp(id.string, "this"))
7916 if(_class && _class.type == structClass && !type.declaredWithStruct)
7917 exp.byReference = true;
7919 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7920 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7921 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7922 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7924 Identifier id = exp.identifier;
7925 exp.type = bracketsExp;
7926 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7930 if(symbol.isIterator)
7932 if(symbol.isIterator == 3)
7934 exp.type = bracketsExp;
7935 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7936 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7938 ProcessExpressionType(exp);
7940 else if(symbol.isIterator != 4)
7942 exp.type = memberExp;
7943 exp.member.exp = MkExpIdentifier(exp.identifier);
7944 exp.member.exp.expType = exp.expType;
7945 /*if(symbol.isIterator == 6)
7946 exp.member.member = MkIdentifier("key");
7948 exp.member.member = MkIdentifier("data");
7950 ProcessExpressionType(exp);
7957 DefinedExpression definedExp = null;
7958 if(thisNameSpace && !(id._class && !id._class.name))
7961 strcpy(name, thisNameSpace);
7963 strcat(name, id.string);
7964 definedExp = eSystem_FindDefine(privateModule, name);
7967 definedExp = eSystem_FindDefine(privateModule, id.string);
7971 for(c = 0; c<definedExpStackPos; c++)
7972 if(definedExpStack[c] == definedExp)
7974 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7976 Location backupYylloc = yylloc;
7977 File backInput = fileInput;
7978 definedExpStack[definedExpStackPos++] = definedExp;
7980 fileInput = TempFile { };
7981 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7982 fileInput.Seek(0, start);
7985 parsedExpression = null;
7987 expression_yyparse();
7990 fileInput = backInput;
7992 yylloc = backupYylloc;
7994 if(parsedExpression)
7997 exp.type = bracketsExp;
7998 exp.list = MkListOne(parsedExpression);
7999 ApplyLocation(parsedExpression, yylloc);
8000 ProcessExpressionType(exp);
8001 definedExpStackPos--;
8004 definedExpStackPos--;
8010 Compiler_Error($"Recursion in defined expression %s\n", id.string);
8016 GlobalData data = null;
8017 if(thisNameSpace && !(id._class && !id._class.name))
8020 strcpy(name, thisNameSpace);
8022 strcat(name, id.string);
8023 data = FindGlobalData(name);
8026 data = FindGlobalData(id.string);
8029 DeclareGlobalData(data);
8030 exp.expType = data.dataType;
8031 if(data.dataType) data.dataType.refCount++;
8034 id.string = CopyString(data.fullName);
8035 FreeSpecifier(id._class);
8042 GlobalFunction function = null;
8043 if(thisNameSpace && !(id._class && !id._class.name))
8046 strcpy(name, thisNameSpace);
8048 strcat(name, id.string);
8049 function = eSystem_FindFunction(privateModule, name);
8052 function = eSystem_FindFunction(privateModule, id.string);
8057 id.string = CopyString(function.name);
8060 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8061 strcpy(name, "__ecereFunction_");
8062 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8063 if(DeclareFunction(function, name))
8066 id.string = CopyString(name);
8068 exp.expType = function.dataType;
8069 if(function.dataType) function.dataType.refCount++;
8071 FreeSpecifier(id._class);
8088 if(!exp.instance._class)
8090 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8092 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8096 //classSym = FindClass(exp.instance._class.fullName);
8097 //_class = classSym ? classSym.registered : null;
8099 ProcessInstantiationType(exp.instance);
8101 exp.isConstant = exp.instance.isConstant;
8104 if(_class.type == unitClass && _class.base.type != systemClass)
8107 Type destType = exp.destType;
8109 exp.destType = MkClassType(_class.base.fullName);
8110 exp.expType = MkClassType(_class.fullName);
8111 CheckExpressionType(exp, exp.destType, true);
8113 exp.destType = destType;
8115 exp.expType = MkClassType(_class.fullName);
8118 if(exp.instance._class)
8120 exp.expType = MkClassType(exp.instance._class.name);
8121 /*if(exp.expType._class && exp.expType._class.registered &&
8122 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8123 exp.expType.byReference = true;*/
8131 char * constant = exp.constant;
8139 if(constant[0] == '\'')
8141 if((int)((byte *)constant)[1] > 127)
8144 unichar ch = UTF8GetChar(constant + 1, &nb);
8145 if(nb < 2) ch = constant[1];
8147 exp.constant = PrintUInt(ch);
8148 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8149 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8150 type._class = FindClass("unichar");
8152 type.isSigned = false;
8156 type.kind = charType;
8157 type.isSigned = true;
8162 char * dot = strchr(constant, '.');
8163 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8167 exponent = strchr(constant, 'p');
8168 if(!exponent) exponent = strchr(constant, 'P');
8172 exponent = strchr(constant, 'e');
8173 if(!exponent) exponent = strchr(constant, 'E');
8178 if(strchr(constant, 'f') || strchr(constant, 'F'))
8179 type.kind = floatType;
8181 type.kind = doubleType;
8182 type.isSigned = true;
8186 bool isSigned = constant[0] == '-';
8188 int64 i64 = strtoll(constant, &endP, 0);
8189 uint64 ui64 = strtoull(constant, &endP, 0);
8190 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8203 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8207 else if(constant[0] != '0' || !constant[1])
8210 type.kind = is64Bit ? int64Type : intType;
8211 type.isSigned = isSigned;
8214 exp.isConstant = true;
8215 if(exp.destType && exp.destType.kind == doubleType)
8216 type.kind = doubleType;
8217 else if(exp.destType && exp.destType.kind == floatType)
8218 type.kind = floatType;
8219 else if(exp.destType && exp.destType.kind == int64Type)
8220 type.kind = int64Type;
8226 exp.isConstant = true; // Why wasn't this constant?
8243 ProcessExpressionType(exp._new.size);
8248 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8250 DeclareType(exp.expType.type, false, false);
8254 ProcessExpressionType(exp._renew.size);
8255 ProcessExpressionType(exp._renew.exp);
8260 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8262 DeclareType(exp.expType.type, false, false);
8266 bool assign = false, boolResult = false, boolOps = false;
8267 Type type1 = null, type2 = null;
8268 bool useDestType = false, useSideType = false;
8269 Location oldyylloc = yylloc;
8270 bool useSideUnit = false;
8271 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8273 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8282 // Assignment Operators
8296 // boolean Operators
8298 // Expect boolean operators
8300 //boolResult = true;
8304 // Expect boolean operands
8315 // Gives boolean result
8347 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8353 /*// Implement speed etc.
8359 if(exp.op.op == '&')
8361 // Added this here earlier for Iterator address as key
8362 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8364 Identifier id = exp.op.exp2.identifier;
8365 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8366 if(symbol && symbol.isIterator == 2)
8368 exp.type = memberExp;
8369 exp.member.exp = exp.op.exp2;
8370 exp.member.member = MkIdentifier("key");
8372 exp.op.exp2.expType = symbol.type;
8373 symbol.type.refCount++;
8374 ProcessExpressionType(exp);
8378 // exp.op.exp2.usage.usageRef = true;
8382 //dummy.kind = TypeDummy;
8385 // Added this check here to use the dest type only for units derived from the base unit
8386 // So that untyped units will use the side unit as opposed to the untyped destination unit
8387 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8388 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8389 useDestType = false;
8391 if(destClass && useDestType &&
8392 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8394 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8396 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8397 exp.op.exp1.destType = exp.destType;
8398 exp.op.exp1.opDestType = true;
8400 exp.destType.refCount++;
8404 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8405 exp.op.exp1.destType = dummy;
8409 // TESTING THIS HERE...
8410 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8411 ProcessExpressionType(exp.op.exp1);
8412 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8414 exp.op.exp1.opDestType = false;
8416 // Fix for unit and ++ / --
8417 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8418 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8420 exp.op.exp2 = MkExpConstant("1");
8421 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8425 if(exp.op.exp1.destType == dummy)
8428 exp.op.exp1.destType = null;
8430 type1 = exp.op.exp1.expType;
8435 char expString[10240];
8436 expString[0] = '\0';
8437 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8441 exp.op.exp2.destType = exp.op.exp1.expType;
8442 if(exp.op.exp1.expType)
8443 exp.op.exp1.expType.refCount++;
8447 exp.op.exp2.destType = exp.destType;
8448 if(!exp.op.exp1 || exp.op.op != '&')
8449 exp.op.exp2.opDestType = true;
8451 exp.destType.refCount++;
8454 if(type1) type1.refCount++;
8455 exp.expType = type1;
8460 PrintExpression(exp.op.exp2, expString);
8462 if(type1 && type1.kind == pointerType)
8464 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 ||
8465 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8466 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8467 else if(exp.op.op == '=')
8469 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8470 exp.op.exp2.destType = type1;
8477 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8478 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/* ||
8479 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8482 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8483 exp.op.exp2.destType = type1;
8488 if(type1) type1.refCount++;
8489 exp.expType = type1;
8491 else if(destClass &&
8492 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8493 (destClass.type == enumClass && useDestType)))
8495 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8496 exp.op.exp2.destType = exp.destType;
8497 if(exp.op.op != '&')
8498 exp.op.exp2.opDestType = true;
8500 exp.destType.refCount++;
8504 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8505 exp.op.exp2.destType = dummy;
8509 // TESTING THIS HERE... (DANGEROUS)
8510 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8511 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8513 FreeType(exp.op.exp2.destType);
8514 exp.op.exp2.destType = type1;
8517 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8518 // Cannot lose the cast on a sizeof
8519 if(exp.op.op == SIZEOF)
8521 Expression e = exp.op.exp2;
8522 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8524 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8526 if(e.type == extensionCompoundExp)
8527 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8532 if(e.type == castExp && e.cast.exp)
8533 e.cast.exp.needCast = true;
8535 ProcessExpressionType(exp.op.exp2);
8536 exp.op.exp2.opDestType = false;
8537 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8539 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8541 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)
8543 if(exp.op.op != '=' && type1.type.kind == voidType)
8544 Compiler_Error($"void *: unknown size\n");
8546 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||
8547 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8548 (exp.op.exp2.expType._class.registered.type == normalClass ||
8549 exp.op.exp2.expType._class.registered.type == structClass ||
8550 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8552 if(exp.op.op == ADD_ASSIGN)
8553 Compiler_Error($"cannot add two pointers\n");
8555 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8556 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8558 if(exp.op.op == ADD_ASSIGN)
8559 Compiler_Error($"cannot add two pointers\n");
8563 char type1String[1024];
8564 char type2String[1024];
8565 type1String[0] = '\0';
8566 type2String[0] = '\0';
8568 PrintType(exp.op.exp2.expType, type1String, false, true);
8569 PrintType(type1, type2String, false, true);
8570 ChangeCh(expString, '\n', ' ');
8571 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8575 if(exp.op.exp2.destType == dummy)
8578 exp.op.exp2.destType = null;
8581 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8585 CopyTypeInto(type2, exp.op.exp2.expType);
8586 type2.isSigned = true;
8588 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8590 type2 = { kind = intType };
8592 type2.isSigned = true;
8596 type2 = exp.op.exp2.expType;
8597 if(type2) type2.refCount++;
8601 dummy.kind = voidType;
8603 if(exp.op.op == SIZEOF)
8610 exp.isConstant = true;
8612 // Get type of dereferenced pointer
8613 else if(exp.op.op == '*' && !exp.op.exp1)
8615 exp.expType = Dereference(type2);
8616 if(type2 && type2.kind == classType)
8617 notByReference = true;
8619 else if(exp.op.op == '&' && !exp.op.exp1)
8620 exp.expType = Reference(type2);
8627 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8628 exp.op.exp1.destType = MkClassType("bool");
8629 exp.op.exp1.destType.truth = true;
8630 if(!exp.op.exp1.expType)
8631 ProcessExpressionType(exp.op.exp1);
8633 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8634 FreeType(exp.op.exp1.expType);
8635 exp.op.exp1.expType = MkClassType("bool");
8636 exp.op.exp1.expType.truth = true;
8640 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8641 exp.op.exp2.destType = MkClassType("bool");
8642 exp.op.exp2.destType.truth = true;
8643 if(!exp.op.exp2.expType)
8644 ProcessExpressionType(exp.op.exp2);
8646 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8647 FreeType(exp.op.exp2.expType);
8648 exp.op.exp2.expType = MkClassType("bool");
8649 exp.op.exp2.expType.truth = true;
8652 else if(exp.op.exp1 && exp.op.exp2 &&
8655 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8656 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8657 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8658 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8660 if(type1 && type2 &&
8661 // If either both are class or both are not class
8662 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8664 // Added this check for enum subtraction to result in an int type:
8665 if(exp.op.op == '-' &&
8666 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8667 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8670 if(!type1._class.registered.dataType)
8671 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8672 if(!type2._class.registered.dataType)
8673 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8675 intType = ProcessTypeString(
8676 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8678 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8679 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8680 exp.op.exp1.destType = intType;
8681 exp.op.exp2.destType = intType;
8686 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8687 exp.op.exp2.destType = type1;
8689 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8690 exp.op.exp1.destType = type2;
8694 // Warning here for adding Radians + Degrees with no destination type
8695 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8696 type1._class.registered && type1._class.registered.type == unitClass &&
8697 type2._class.registered && type2._class.registered.type == unitClass &&
8698 type1._class.registered != type2._class.registered)
8699 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8700 type1._class.string, type2._class.string, type1._class.string);
8702 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8704 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8707 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8709 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8710 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8713 ProcessExpressionType(exp.op.exp1);
8715 if(type2.kind != pointerType)
8717 ProcessExpressionType(classExp);
8719 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8721 if(!exp.op.exp2.expType)
8725 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8729 ProcessExpressionType(exp.op.exp2);
8734 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)))
8736 if(type1.kind != classType && type1.type.kind == voidType)
8737 Compiler_Error($"void *: unknown size\n");
8738 exp.expType = type1;
8739 if(type1) type1.refCount++;
8741 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)))
8743 if(type2.kind != classType && type2.type.kind == voidType)
8744 Compiler_Error($"void *: unknown size\n");
8745 exp.expType = type2;
8746 if(type2) type2.refCount++;
8748 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8749 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8751 Compiler_Warning($"different levels of indirection\n");
8755 bool success = false;
8756 if(type1.kind == pointerType && type2.kind == pointerType)
8758 if(exp.op.op == '+')
8759 Compiler_Error($"cannot add two pointers\n");
8760 else if(exp.op.op == '-')
8762 // Pointer Subtraction gives integer
8763 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8772 if(type1.type.kind == templateType)
8774 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8777 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8779 ProcessExpressionType(classExp);
8781 exp.type = bracketsExp;
8782 exp.list = MkListOne(MkExpOp(
8783 MkExpBrackets(MkListOne(MkExpOp(
8784 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8786 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8787 MkExpMember(classExp, MkIdentifier("typeSize"))));
8789 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8798 if(!success && exp.op.exp1.type == constantExp)
8800 // If first expression is constant, try to match that first
8801 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8803 if(exp.expType) FreeType(exp.expType);
8804 exp.expType = exp.op.exp1.destType;
8805 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8808 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8810 if(exp.expType) FreeType(exp.expType);
8811 exp.expType = exp.op.exp2.destType;
8812 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8818 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8820 if(exp.expType) FreeType(exp.expType);
8821 exp.expType = exp.op.exp2.destType;
8822 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8825 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8827 if(exp.expType) FreeType(exp.expType);
8828 exp.expType = exp.op.exp1.destType;
8829 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8835 char expString1[10240];
8836 char expString2[10240];
8839 expString1[0] = '\0';
8840 expString2[0] = '\0';
8845 PrintExpression(exp.op.exp1, expString1);
8846 ChangeCh(expString1, '\n', ' ');
8847 PrintExpression(exp.op.exp2, expString2);
8848 ChangeCh(expString2, '\n', ' ');
8849 PrintType(exp.op.exp1.expType, type1, false, true);
8850 PrintType(exp.op.exp2.expType, type2, false, true);
8853 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8857 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8858 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8860 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8861 // Convert e.g. / 4 into / 4.0
8862 exp.op.exp1.destType = type2._class.registered.dataType;
8863 if(type2._class.registered.dataType)
8864 type2._class.registered.dataType.refCount++;
8865 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8866 exp.expType = type2;
8867 if(type2) type2.refCount++;
8869 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8871 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8872 // Convert e.g. / 4 into / 4.0
8873 exp.op.exp2.destType = type1._class.registered.dataType;
8874 if(type1._class.registered.dataType)
8875 type1._class.registered.dataType.refCount++;
8876 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8877 exp.expType = type1;
8878 if(type1) type1.refCount++;
8884 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8886 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8888 if(!type1._class.registered.dataType)
8889 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8890 exp.op.exp2.destType = type1._class.registered.dataType;
8891 exp.op.exp2.destType.refCount++;
8893 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8896 type2 = exp.op.exp2.destType;
8897 if(type2) type2.refCount++;
8899 exp.expType = type2;
8903 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8905 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8907 if(!type2._class.registered.dataType)
8908 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8909 exp.op.exp1.destType = type2._class.registered.dataType;
8910 exp.op.exp1.destType.refCount++;
8912 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8913 type1 = exp.op.exp1.destType;
8914 exp.expType = type1;
8918 // TESTING THIS NEW CODE
8919 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8921 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8922 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8923 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8925 // Convert the enum to an int instead for these operators
8926 if(op1IsEnum && exp.op.exp2.expType)
8928 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8930 if(exp.expType) FreeType(exp.expType);
8931 exp.expType = exp.op.exp2.expType;
8932 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8936 else if(op2IsEnum && exp.op.exp1.expType)
8938 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8940 if(exp.expType) FreeType(exp.expType);
8941 exp.expType = exp.op.exp1.expType;
8942 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8949 if(op1IsEnum && exp.op.exp2.expType)
8951 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8953 if(exp.expType) FreeType(exp.expType);
8954 exp.expType = exp.op.exp1.expType;
8955 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8959 else if(op2IsEnum && exp.op.exp1.expType)
8961 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8963 if(exp.expType) FreeType(exp.expType);
8964 exp.expType = exp.op.exp2.expType;
8965 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8974 // Added this first part of the if here to handle 5 + Degrees { 5 } with either a base unit dest or not a unit dest type
8975 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8976 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8978 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8979 exp.op.exp1.destType = type2;
8982 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8984 if(exp.expType) FreeType(exp.expType);
8985 exp.expType = exp.op.exp1.destType;
8986 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8991 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8992 exp.op.exp2.destType = type1;
8996 // Maybe this was meant to be an enum...
8997 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8999 Type oldType = exp.op.exp2.expType;
9000 exp.op.exp2.expType = null;
9001 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9004 exp.op.exp2.expType = oldType;
9009 // TESTING THIS HERE... LATEST ADDITION
9010 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9012 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9013 exp.op.exp2.destType = type2._class.registered.dataType;
9014 if(type2._class.registered.dataType)
9015 type2._class.registered.dataType.refCount++;
9016 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9018 //exp.expType = type2._class.registered.dataType; //type2;
9019 //if(type2) type2.refCount++;
9022 // TESTING THIS HERE... LATEST ADDITION
9023 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9025 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9026 exp.op.exp1.destType = type1._class.registered.dataType;
9027 if(type1._class.registered.dataType)
9028 type1._class.registered.dataType.refCount++;
9029 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9030 exp.expType = type1._class.registered.dataType; //type1;
9031 if(type1) type1.refCount++;
9035 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9037 if(exp.expType) FreeType(exp.expType);
9038 exp.expType = exp.op.exp2.destType;
9039 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9041 else if(type1 && type2)
9043 char expString1[10240];
9044 char expString2[10240];
9045 char type1String[1024];
9046 char type2String[1024];
9047 expString1[0] = '\0';
9048 expString2[0] = '\0';
9049 type1String[0] = '\0';
9050 type2String[0] = '\0';
9053 PrintExpression(exp.op.exp1, expString1);
9054 ChangeCh(expString1, '\n', ' ');
9055 PrintExpression(exp.op.exp2, expString2);
9056 ChangeCh(expString2, '\n', ' ');
9057 PrintType(exp.op.exp1.expType, type1String, false, true);
9058 PrintType(exp.op.exp2.expType, type2String, false, true);
9061 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9063 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9065 exp.expType = exp.op.exp1.expType;
9066 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9068 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9070 exp.expType = exp.op.exp2.expType;
9071 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9079 // Maybe this was meant to be an enum...
9080 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9082 Type oldType = exp.op.exp1.expType;
9083 exp.op.exp1.expType = null;
9084 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9087 exp.op.exp1.expType = oldType;
9090 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9091 exp.op.exp1.destType = type2;
9094 // TESTING THIS HERE... LATEST ADDITION
9095 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9097 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9098 exp.op.exp1.destType = type1._class.registered.dataType;
9099 if(type1._class.registered.dataType)
9100 type1._class.registered.dataType.refCount++;
9103 // TESTING THIS HERE... LATEST ADDITION
9104 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9106 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9107 exp.op.exp2.destType = type2._class.registered.dataType;
9108 if(type2._class.registered.dataType)
9109 type2._class.registered.dataType.refCount++;
9113 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9115 if(exp.expType) FreeType(exp.expType);
9116 exp.expType = exp.op.exp1.destType;
9117 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9121 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9123 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9125 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9126 // Convert e.g. / 4 into / 4.0
9127 exp.op.exp1.destType = type2._class.registered.dataType;
9128 if(type2._class.registered.dataType)
9129 type2._class.registered.dataType.refCount++;
9130 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9132 if(exp.op.op == '!')
9134 exp.expType = MkClassType("bool");
9135 exp.expType.truth = true;
9139 exp.expType = type2;
9140 if(type2) type2.refCount++;
9143 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9145 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9147 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9148 // Convert e.g. / 4 into / 4.0
9149 exp.op.exp2.destType = type1._class.registered.dataType;
9150 if(type1._class.registered.dataType)
9151 type1._class.registered.dataType.refCount++;
9152 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9154 exp.expType = type1;
9155 if(type1) type1.refCount++;
9160 if(exp.op.exp1 && !exp.op.exp1.expType)
9162 char expString[10000];
9163 expString[0] = '\0';
9166 PrintExpression(exp.op.exp1, expString);
9167 ChangeCh(expString, '\n', ' ');
9170 Compiler_Error($"couldn't determine type of %s\n", expString);
9172 if(exp.op.exp2 && !exp.op.exp2.expType)
9174 char expString[10240];
9175 expString[0] = '\0';
9178 PrintExpression(exp.op.exp2, expString);
9179 ChangeCh(expString, '\n', ' ');
9182 Compiler_Error($"couldn't determine type of %s\n", expString);
9187 FreeType(exp.expType);
9188 exp.expType = MkClassType("bool");
9189 exp.expType.truth = true;
9192 if(exp.op.op != SIZEOF)
9193 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9194 (!exp.op.exp2 || exp.op.exp2.isConstant);
9196 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9198 DeclareType(exp.op.exp2.expType, false, false);
9201 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9202 Compiler_Warning($"deleting const qualified object\n");
9212 case extensionExpressionExp:
9215 exp.isConstant = true;
9216 for(e = exp.list->first; e; e = e.next)
9221 FreeType(e.destType);
9222 e.opDestType = exp.opDestType;
9223 e.destType = exp.destType;
9224 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9226 ProcessExpressionType(e);
9228 exp.destType.count--;
9229 if(!exp.expType && !e.next)
9231 exp.expType = e.expType;
9232 if(e.expType) e.expType.refCount++;
9235 exp.isConstant = false;
9238 // In case a cast became a member...
9239 e = exp.list->first;
9240 if(!e.next && e.type == memberExp)
9242 // Preserve prev, next
9243 Expression next = exp.next, prev = exp.prev;
9246 FreeType(exp.expType);
9247 FreeType(exp.destType);
9257 ProcessExpressionType(exp);
9264 exp.isConstant = true;
9266 ProcessExpressionType(exp.index.exp);
9267 if(!exp.index.exp.isConstant)
9268 exp.isConstant = false;
9270 if(exp.index.exp.expType)
9272 Type source = exp.index.exp.expType;
9273 if(source.kind == classType && source._class && source._class.registered)
9275 Class _class = source._class.registered;
9276 Class c = _class.templateClass ? _class.templateClass : _class;
9277 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9279 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9281 if(exp.index.index && exp.index.index->last)
9283 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9285 if(type.kind == classType) type.constant = true;
9286 else if(type.kind == pointerType)
9289 while(t.kind == pointerType) t = t.type;
9293 ((Expression)exp.index.index->last).destType = type;
9299 for(e = exp.index.index->first; e; e = e.next)
9301 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9303 if(e.destType) FreeType(e.destType);
9304 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9306 ProcessExpressionType(e);
9309 // Check if this type is int
9312 exp.isConstant = false;
9316 exp.expType = Dereference(exp.index.exp.expType);
9318 DeclareType(exp.expType, false, false);
9325 Type methodType = null;
9331 PrintExpression(exp.call.exp, name);
9332 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9334 //exp.call.exp.expType = null;
9335 PrintExpression(exp.call.exp, name);
9338 if(exp.call.exp.type == identifierExp)
9340 Expression idExp = exp.call.exp;
9341 Identifier id = idExp.identifier;
9342 if(!strcmp(id.string, "__builtin_frame_address"))
9344 exp.expType = ProcessTypeString("void *", true);
9345 if(exp.call.arguments && exp.call.arguments->first)
9346 ProcessExpressionType(exp.call.arguments->first);
9349 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9351 exp.expType = ProcessTypeString("int", true);
9352 if(exp.call.arguments && exp.call.arguments->first)
9353 ProcessExpressionType(exp.call.arguments->first);
9356 else if(!strcmp(id.string, "Max") ||
9357 !strcmp(id.string, "Min") ||
9358 !strcmp(id.string, "Sgn") ||
9359 !strcmp(id.string, "Abs"))
9361 Expression a = null;
9362 Expression b = null;
9363 Expression tempExp1 = null, tempExp2 = null;
9364 if((!strcmp(id.string, "Max") ||
9365 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9367 a = exp.call.arguments->first;
9368 b = exp.call.arguments->last;
9372 else if(exp.call.arguments->count == 1)
9374 a = exp.call.arguments->first;
9380 exp.call.arguments->Clear();
9381 idExp.identifier = null;
9383 FreeExpContents(exp);
9385 ProcessExpressionType(a);
9387 ProcessExpressionType(b);
9389 exp.type = bracketsExp;
9390 exp.list = MkList();
9392 if(a.expType && (!b || b.expType))
9394 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9396 // Use the simpleStruct name/ids for now...
9399 OldList * specs = MkList();
9400 OldList * decls = MkList();
9402 char temp1[1024], temp2[1024];
9404 GetTypeSpecs(a.expType, specs);
9406 if(a && !a.isConstant && a.type != identifierExp)
9408 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9409 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9410 tempExp1 = QMkExpId(temp1);
9411 tempExp1.expType = a.expType;
9413 a.expType.refCount++;
9414 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9416 if(b && !b.isConstant && b.type != identifierExp)
9418 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9419 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9420 tempExp2 = QMkExpId(temp2);
9421 tempExp2.expType = b.expType;
9423 b.expType.refCount++;
9424 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9427 decl = MkDeclaration(specs, decls);
9428 if(!curCompound.compound.declarations)
9429 curCompound.compound.declarations = MkList();
9430 curCompound.compound.declarations->Insert(null, decl);
9435 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9437 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9439 MkExpCondition(MkExpBrackets(MkListOne(
9440 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9441 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9442 exp.expType = a.expType;
9444 a.expType.refCount++;
9446 else if(!strcmp(id.string, "Abs"))
9449 MkExpCondition(MkExpBrackets(MkListOne(
9450 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9451 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9452 exp.expType = a.expType;
9454 a.expType.refCount++;
9456 else if(!strcmp(id.string, "Sgn"))
9458 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9460 MkExpCondition(MkExpBrackets(MkListOne(
9461 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9462 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9463 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9464 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9465 exp.expType = ProcessTypeString("int", false);
9468 FreeExpression(tempExp1);
9469 if(tempExp2) FreeExpression(tempExp2);
9483 if(!exp.call.exp.destType)
9485 exp.call.exp.destType = dummy;
9488 ProcessExpressionType(exp.call.exp);
9489 if(exp.call.exp.destType == dummy)
9492 exp.call.exp.destType = null;
9497 // Check argument types against parameter types
9498 functionType = exp.call.exp.expType;
9500 if(functionType && functionType.kind == TypeKind::methodType)
9502 methodType = functionType;
9503 functionType = methodType.method.dataType;
9505 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9506 // TOCHECK: Instead of doing this here could this be done per param?
9507 if(exp.call.exp.expType.usedClass)
9509 char typeString[1024];
9510 typeString[0] = '\0';
9512 Symbol back = functionType.thisClass;
9513 // Do not output class specifier here (thisclass was added to this)
9514 functionType.thisClass = null;
9515 PrintType(functionType, typeString, true, true);
9516 functionType.thisClass = back;
9518 if(strstr(typeString, "thisclass"))
9520 OldList * specs = MkList();
9523 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9525 decl = SpecDeclFromString(typeString, specs, null);
9527 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9528 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9529 exp.call.exp.expType.usedClass))
9530 thisClassParams = false;
9532 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9534 Class backupThisClass = thisClass;
9535 thisClass = exp.call.exp.expType.usedClass;
9536 ProcessDeclarator(decl);
9537 thisClass = backupThisClass;
9540 thisClassParams = true;
9542 functionType = ProcessType(specs, decl);
9543 functionType.refCount = 0;
9544 FinishTemplatesContext(context);
9546 // Mark parameters that were 'thisclass'
9549 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9550 p.wasThisClass = op.kind == thisClassType;
9554 FreeList(specs, FreeSpecifier);
9555 FreeDeclarator(decl);
9559 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9561 Type type = functionType.type;
9562 if(!functionType.refCount)
9564 functionType.type = null;
9565 FreeType(functionType);
9567 //methodType = functionType;
9568 functionType = type;
9570 if(functionType && functionType.kind != TypeKind::functionType)
9572 Compiler_Error($"called object %s is not a function\n", name);
9574 else if(functionType)
9576 bool emptyParams = false, noParams = false;
9577 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9578 Type type = functionType.params.first;
9579 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9581 Location oldyylloc = yylloc;
9583 if(!type) emptyParams = true;
9586 if(functionType.extraParam && e && functionType.thisClass)
9588 e.destType = MkClassType(functionType.thisClass.string);
9592 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9593 // Fixed #141 by adding '&& !functionType.extraParam'
9594 if(!functionType.staticMethod && !functionType.extraParam)
9596 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9597 memberExp.member.exp.expType._class)
9599 type = MkClassType(memberExp.member.exp.expType._class.string);
9604 type = functionType.params.first;
9609 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9611 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9612 type.byReference = functionType.byReference;
9613 type.typedByReference = functionType.typedByReference;
9616 // Allow manually passing a class for typed object
9617 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9621 type = functionType.params.first;
9629 if(type && type.kind == voidType)
9632 if(!type.refCount) FreeType(type);
9636 for( ; e; e = e.next)
9638 if(!type && !emptyParams)
9641 if(methodType && methodType.methodClass)
9642 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9643 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9644 noParams ? 0 : functionType.params.count);
9646 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9647 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9648 noParams ? 0 : functionType.params.count);
9652 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9654 Type templatedType = null;
9655 Class _class = methodType.usedClass;
9656 ClassTemplateParameter curParam = null;
9658 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9661 for(sClass = _class; sClass; sClass = sClass.base)
9663 if(sClass.templateClass) sClass = sClass.templateClass;
9665 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9667 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9670 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9672 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9673 id += nextClass.templateParams.count;
9682 if(curParam && _class.templateArgs[id].dataTypeString)
9684 bool constant = type.constant;
9685 ClassTemplateArgument arg = _class.templateArgs[id];
9687 Context context = SetupTemplatesContext(_class);
9690 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9691 templatedType = ProcessTypeString(arg.dataTypeString, false);
9692 FinishTemplatesContext(context);
9695 if(templatedType.kind == classType && constant) templatedType.constant = true;
9696 else if(templatedType.kind == pointerType)
9698 Type t = templatedType.type;
9699 while(t.kind == pointerType) t = t.type;
9700 if(constant) t.constant = constant;
9703 e.destType = templatedType;
9706 templatedType.passAsTemplate = true;
9707 // templatedType.refCount++;
9713 if(type) type.refCount++;
9718 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9720 e.destType = type.prev;
9721 e.destType.refCount++;
9726 if(type) type.refCount++;
9729 // Don't reach the end for the ellipsis
9730 if(type && type.kind != ellipsisType)
9732 Type next = type.next;
9733 if(!type.refCount) FreeType(type);
9738 if(type && type.kind != ellipsisType)
9740 if(methodType && methodType.methodClass)
9741 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9742 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9743 functionType.params.count + extra);
9745 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9746 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9747 functionType.params.count + extra);
9750 if(type && !type.refCount) FreeType(type);
9757 kind = TypeKind::functionType;
9760 if(exp.call.exp.type == identifierExp)
9762 char * string = exp.call.exp.identifier.string;
9766 Location oldyylloc = yylloc;
9768 yylloc = exp.call.exp.identifier.loc;
9769 if(strstr(string, "__builtin_") == string)
9773 functionType.returnType = exp.destType;
9774 exp.destType.refCount++;
9778 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9779 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9780 globalContext.symbols.Add((BTNode)symbol);
9781 if(strstr(symbol.string, "::"))
9782 globalContext.hasNameSpace = true;
9787 else if(exp.call.exp.type == memberExp)
9789 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9790 exp.call.exp.member.member.string);*/
9793 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9795 if(!functionType.returnType)
9797 functionType.returnType = Type
9804 if(functionType && functionType.kind == TypeKind::functionType)
9806 exp.expType = functionType.returnType;
9808 if(functionType.returnType)
9809 functionType.returnType.refCount++;
9811 if(!functionType.refCount)
9812 FreeType(functionType);
9815 if(exp.call.arguments)
9817 for(e = exp.call.arguments->first; e; e = e.next)
9818 ProcessExpressionType(e);
9825 Location oldyylloc = yylloc;
9827 Expression checkExp = exp.member.exp;
9830 if(checkExp.type == castExp)
9831 checkExp = checkExp.cast.exp;
9832 else if(checkExp.type == bracketsExp)
9833 checkExp = checkExp.list ? checkExp.list->first : null;
9838 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9839 exp.thisPtr = thisPtr;
9841 // DOING THIS LATER NOW...
9842 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9844 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9845 /* TODO: Name Space Fix ups
9846 if(!exp.member.member.classSym)
9847 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9851 ProcessExpressionType(exp.member.exp);
9852 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9853 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9855 exp.isConstant = false;
9858 exp.isConstant = exp.member.exp.isConstant;
9859 type = exp.member.exp.expType;
9863 if(type && (type.kind == templateType))
9865 Class _class = thisClass ? thisClass : currentClass;
9866 ClassTemplateParameter param = null;
9869 for(param = _class.templateParams.first; param; param = param.next)
9871 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9875 if(param && param.defaultArg.member)
9877 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9880 Expression expMember = exp.member.exp;
9882 OldList * specs = MkList();
9883 char thisClassTypeString[1024];
9885 FreeIdentifier(exp.member.member);
9887 ProcessExpressionType(argExp);
9890 char * colon = strstr(param.defaultArg.memberString, "::");
9893 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9894 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9897 strcpy(thisClassTypeString, _class.fullName);
9900 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9902 exp.expType = ProcessType(specs, decl);
9903 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9905 Class expClass = exp.expType._class.registered;
9906 Class cClass = null;
9910 char templateString[1024];
9911 ClassTemplateParameter param;
9912 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9913 for(cClass = expClass; cClass; cClass = cClass.base)
9916 for(param = cClass.templateParams.first; param; param = param.next)
9920 ClassTemplateArgument arg;
9921 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9922 arg = expClass.templateArgs[id];
9924 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9926 ClassTemplateParameter cParam;
9927 //int p = numParams - sClass.templateParams.count;
9930 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9932 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9934 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9936 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9938 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9939 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9951 strcat(argument, arg.name.string);
9952 strcat(argument, " = ");
9958 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9959 char expString[1024];
9960 OldList * specs = MkList();
9961 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9963 char * string = PrintHexUInt64(arg.expression.ui64);
9964 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9967 ProcessExpressionType(exp);
9968 ComputeExpression(exp);
9969 expString[0] = '\0';
9970 PrintExpression(exp, expString);
9971 strcat(argument, expString);
9973 FreeExpression(exp);
9978 strcat(argument, arg.member.name);
9981 case TemplateParameterType::type:
9983 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9985 if(!strcmp(arg.dataTypeString, "thisclass"))
9986 strcat(argument, thisClassTypeString);
9988 strcat(argument, arg.dataTypeString);
9995 if(paramCount) strcat(templateString, ", ");
9996 if(lastParam != p - 1)
9998 strcat(templateString, param.name);
9999 strcat(templateString, " = ");
10001 strcat(templateString, argument);
10010 int len = strlen(templateString);
10011 if(templateString[len-1] == '>') templateString[len++] = ' ';
10012 templateString[len++] = '>';
10013 templateString[len++] = '\0';
10016 Context context = SetupTemplatesContext(_class);
10017 FreeType(exp.expType);
10018 exp.expType = ProcessTypeString(templateString, false);
10019 FinishTemplatesContext(context);
10023 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
10024 exp.type = bracketsExp;
10025 exp.list = MkListOne(MkExpOp(null, '*',
10028 exp.op.exp1 = null;
10030 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10031 MkExpBrackets(MkListOne(
10032 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
10034 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10036 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10041 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10042 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10044 type = ProcessTemplateParameterType(type.templateParameter);
10047 // TODO: *** This seems to be where we should add method support for all basic types ***
10048 if(type && (type.kind == templateType));
10049 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10050 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10051 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10052 (type.kind == pointerType && type.type.kind == charType)))
10054 Identifier id = exp.member.member;
10055 TypeKind typeKind = type.kind;
10056 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10057 if(typeKind == subClassType && exp.member.exp.type == classExp)
10059 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10060 typeKind = classType;
10065 if(typeKind == intType || typeKind == enumType)
10066 _class = eSystem_FindClass(privateModule, "int");
10069 if(type.kind == classType && type._class && type._class.registered)
10071 _class = type._class.registered;
10073 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10075 _class = FindClass("char *").registered;
10077 else if(type.kind == pointerType)
10079 _class = eSystem_FindClass(privateModule, "uintptr");
10080 FreeType(exp.expType);
10081 exp.expType = ProcessTypeString("uintptr", false);
10082 exp.byReference = true;
10086 char string[1024] = "";
10088 PrintTypeNoConst(type, string, false, true);
10089 classSym = FindClass(string);
10090 if(classSym) _class = classSym.registered;
10098 (exp.member.exp.type == identifierExp &&
10099 !strcmp(exp.member.exp.identifier.string, "this"));*/
10100 Property prop = null;
10101 Method method = null;
10102 DataMember member = null;
10103 Property revConvert = null;
10104 ClassProperty classProp = null;
10106 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10107 exp.member.memberType = propertyMember;
10109 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10110 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10112 if(typeKind != subClassType)
10114 // Prioritize data members over properties for "this"
10115 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10117 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10118 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10120 prop = eClass_FindProperty(_class, id.string, privateModule);
10124 if(!member && !prop)
10125 prop = eClass_FindProperty(_class, id.string, privateModule);
10126 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10127 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10128 exp.member.thisPtr = true;
10130 // Prioritize properties over data members otherwise
10133 bool useMemberForNonConst = false;
10134 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10137 prop = eClass_FindProperty(_class, id.string, null);
10139 useMemberForNonConst = prop && exp.destType &&
10140 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10141 !strncmp(prop.dataTypeString, "const ", 6);
10143 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10144 member = eClass_FindDataMember(_class, id.string, null, null, null);
10147 if((!prop || useMemberForNonConst) && !member)
10149 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10152 prop = eClass_FindProperty(_class, id.string, privateModule);
10154 useMemberForNonConst |= prop && exp.destType &&
10155 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10156 !strncmp(prop.dataTypeString, "const ", 6);
10158 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10159 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10165 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10172 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10173 method = eClass_FindMethod(_class, id.string, privateModule);
10174 if(!prop && !member && !method)
10176 if(typeKind == subClassType)
10178 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10181 exp.member.memberType = classPropertyMember;
10182 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10186 // Assume this is a class_data member
10187 char structName[1024];
10188 Identifier id = exp.member.member;
10189 Expression classExp = exp.member.exp;
10192 FreeType(classExp.expType);
10193 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10195 strcpy(structName, "__ecereClassData_");
10196 FullClassNameCat(structName, type._class.string, false);
10197 exp.type = pointerExp;
10198 exp.member.member = id;
10200 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10201 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10202 MkExpBrackets(MkListOne(MkExpOp(
10203 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10204 MkExpMember(classExp, MkIdentifier("data"))), '+',
10205 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10210 ProcessExpressionType(exp);
10216 // Check for reverse conversion
10217 // (Convert in an instantiation later, so that we can use
10218 // deep properties system)
10219 Symbol classSym = FindClass(id.string);
10222 Class convertClass = classSym.registered;
10224 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10229 //if(!exp.member.exp.destType)
10230 if(exp.member.exp.destType)
10231 FreeType(exp.member.exp.destType);
10233 if(method && !method._class.symbol)
10234 method._class.symbol = FindClass(method._class.fullName);
10235 if(prop && !prop._class.symbol)
10236 prop._class.symbol = FindClass(prop._class.fullName);
10238 exp.member.exp.destType = Type
10242 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10243 // wasThisClass = type ? type.wasThisClass : false;
10249 exp.member.memberType = propertyMember;
10251 ProcessPropertyType(prop);
10252 exp.expType = prop.dataType;
10253 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10256 CopyTypeInto(type, exp.expType);
10258 type.constant = true;
10259 exp.expType = type;
10261 else if(prop.dataType)
10262 prop.dataType.refCount++;
10266 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10268 FreeExpContents(exp);
10269 exp.type = identifierExp;
10270 exp.identifier = MkIdentifier("class");
10271 ProcessExpressionType(exp);
10275 exp.member.memberType = dataMember;
10276 DeclareStruct(_class.fullName, false);
10277 if(!member.dataType)
10279 Context context = SetupTemplatesContext(_class);
10280 member.dataType = ProcessTypeString(member.dataTypeString, false);
10281 FinishTemplatesContext(context);
10283 exp.expType = member.dataType;
10284 if(member.dataType) member.dataType.refCount++;
10286 else if(revConvert)
10288 exp.member.memberType = reverseConversionMember;
10289 exp.expType = MkClassType(revConvert._class.fullName);
10297 exp.type = identifierExp;
10298 exp.identifier = exp.member.member;
10301 exp.member.memberType = methodMember;
10303 if(!method.dataType)
10304 ProcessMethodType(method);
10312 // Tricky spot here... To use instance versus class virtual table
10313 // Put it back to what it was... What did we break?
10315 // Had to put it back for overriding Main of Thread global instance
10317 //exp.expType.methodClass = _class;
10318 exp.expType.methodClass = (id && id._class) ? _class : null;
10320 // Need the actual class used for templated classes
10321 exp.expType.usedClass = _class;
10323 else if(!classProp)
10325 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10327 FreeExpContents(exp);
10328 exp.type = identifierExp;
10329 exp.identifier = MkIdentifier("class");
10330 FreeType(exp.expType);
10331 exp.expType = MkClassType("ecere::com::Class");
10334 yylloc = exp.member.member.loc;
10335 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10337 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10340 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10344 tClass = type._class && type._class.registered ? type._class.registered : _class;
10345 while(tClass && !tClass.templateClass) tClass = tClass.base;
10347 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10350 ClassTemplateParameter curParam = null;
10353 for(sClass = tClass; sClass; sClass = sClass.base)
10356 if(sClass.templateClass) sClass = sClass.templateClass;
10357 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10359 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10361 for(sClass = sClass.base; sClass; sClass = sClass.base)
10362 id += sClass.templateParams.count;
10367 if(curParam) break;
10370 if(curParam && tClass.templateArgs[id].dataTypeString)
10372 ClassTemplateArgument arg = tClass.templateArgs[id];
10373 Context context = SetupTemplatesContext(tClass);
10374 bool constant = exp.expType.constant;
10375 /*if(!arg.dataType)
10376 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10377 FreeType(exp.expType);
10379 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10380 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10381 else if(exp.expType.kind == pointerType)
10383 Type t = exp.expType.type;
10384 while(t.kind == pointerType) t = t.type;
10385 if(constant) t.constant = constant;
10389 if(exp.expType.kind == thisClassType)
10391 FreeType(exp.expType);
10392 exp.expType = ReplaceThisClassType(_class);
10395 if(tClass.templateClass && (exp.expType.kind != templateType || (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType))))
10396 exp.expType.passAsTemplate = true;
10397 //exp.expType.refCount++;
10400 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10401 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10402 else if(exp.destType.kind == pointerType)
10404 Type t = exp.destType.type;
10405 while(t.kind == pointerType) t = t.type;
10406 if(constant) t.constant = constant;
10409 //exp.destType.refCount++;
10411 if(exp.destType.kind == thisClassType)
10413 FreeType(exp.destType);
10414 exp.destType = ReplaceThisClassType(_class);
10418 FinishTemplatesContext(context);
10421 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10422 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10425 ClassTemplateParameter curParam = null;
10428 for(sClass = tClass; sClass; sClass = sClass.base)
10431 if(sClass.templateClass) sClass = sClass.templateClass;
10432 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10434 if(curParam.type == TemplateParameterType::type &&
10435 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10437 for(sClass = sClass.base; sClass; sClass = sClass.base)
10438 id += sClass.templateParams.count;
10443 if(curParam) break;
10448 ClassTemplateArgument arg = tClass.templateArgs[id];
10449 Context context = SetupTemplatesContext(tClass);
10451 /*if(!arg.dataType)
10452 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10454 basicType = ProcessTypeString(arg.dataTypeString, false);
10457 if(basicType.kind == thisClassType)
10459 FreeType(basicType);
10460 basicType = ReplaceThisClassType(_class);
10463 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10464 if(tClass.templateClass)
10465 basicType.passAsTemplate = true;
10468 FreeType(exp.expType);
10470 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10471 //exp.expType.refCount++;
10474 exp.destType = exp.expType;
10475 exp.destType.refCount++;
10479 Expression newExp { };
10480 OldList * specs = MkList();
10482 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10484 if(exp.destType) exp.destType.refCount++;
10485 if(exp.expType) exp.expType.refCount++;
10486 exp.type = castExp;
10487 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10488 exp.cast.exp = newExp;
10489 //FreeType(exp.expType);
10490 //exp.expType = null;
10491 //ProcessExpressionType(sourceExp);
10494 FinishTemplatesContext(context);
10497 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10499 Class expClass = exp.expType._class.registered;
10502 Class cClass = null;
10504 int paramCount = 0;
10505 int lastParam = -1;
10506 char templateString[1024];
10507 ClassTemplateParameter param;
10508 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10509 while(cClass != expClass)
10512 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10515 for(param = cClass.templateParams.first; param; param = param.next)
10517 Class cClassCur = null;
10519 ClassTemplateParameter paramCur = null;
10520 ClassTemplateArgument arg;
10521 while(cClassCur != tClass && !paramCur)
10524 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10525 cClassCur = sClassCur;
10527 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10529 if(!strcmp(paramCur.name, param.name))
10537 if(paramCur && paramCur.type == TemplateParameterType::type)
10538 arg = tClass.templateArgs[cp];
10540 arg = expClass.templateArgs[p];
10543 char argument[256];
10544 argument[0] = '\0';
10547 strcat(argument, arg.name.string);
10548 strcat(argument, " = ");
10554 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10555 char expString[1024];
10556 OldList * specs = MkList();
10557 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10559 char * string = PrintHexUInt64(arg.expression.ui64);
10560 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10563 ProcessExpressionType(exp);
10564 ComputeExpression(exp);
10565 expString[0] = '\0';
10566 PrintExpression(exp, expString);
10567 strcat(argument, expString);
10569 FreeExpression(exp);
10574 strcat(argument, arg.member.name);
10577 case TemplateParameterType::type:
10579 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10580 strcat(argument, arg.dataTypeString);
10586 if(paramCount) strcat(templateString, ", ");
10587 if(lastParam != p - 1)
10589 strcat(templateString, param.name);
10590 strcat(templateString, " = ");
10592 strcat(templateString, argument);
10601 int len = strlen(templateString);
10602 if(templateString[len-1] == '>') templateString[len++] = ' ';
10603 templateString[len++] = '>';
10604 templateString[len++] = '\0';
10607 FreeType(exp.expType);
10609 Context context = SetupTemplatesContext(tClass);
10610 exp.expType = ProcessTypeString(templateString, false);
10611 FinishTemplatesContext(context);
10618 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10620 else if(type && (type.kind == structType || type.kind == unionType))
10622 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10625 exp.expType = memberType;
10627 memberType.refCount++;
10632 char expString[10240];
10633 expString[0] = '\0';
10634 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10635 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10638 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10640 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10642 Identifier id = exp.member.member;
10643 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10646 FreeType(exp.expType);
10647 exp.expType = ReplaceThisClassType(_class);
10651 yylloc = oldyylloc;
10654 // Convert x->y into (*x).y
10657 Type destType = exp.destType;
10659 // DOING THIS LATER NOW...
10660 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10662 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10663 /* TODO: Name Space Fix ups
10664 if(!exp.member.member.classSym)
10665 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10669 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10670 exp.type = memberExp;
10673 ProcessExpressionType(exp);
10680 //ComputeExpression(exp);
10682 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10683 if(classSym && classSym.registered)
10685 if(classSym.registered.type == noHeadClass)
10689 DeclareStruct(classSym.string, false);
10690 FreeSpecifier(exp._class);
10691 exp.type = typeSizeExp;
10692 FullClassNameCat(name, classSym.string, false);
10693 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10697 if(classSym.registered.fixed)
10699 FreeSpecifier(exp._class);
10700 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10701 exp.type = constantExp;
10705 char className[1024];
10706 strcpy(className, "__ecereClass_");
10707 FullClassNameCat(className, classSym.string, true);
10708 //MangleClassName(className);
10710 DeclareClass(classSym, className);
10712 FreeExpContents(exp);
10713 exp.type = pointerExp;
10714 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10715 exp.member.member = MkIdentifier("structSize");
10723 kind = intSizeType;
10725 // exp.isConstant = true;
10730 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10735 kind = intSizeType;
10737 exp.isConstant = true;
10739 DeclareType(type, false, false);
10745 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10747 FreeType(exp.cast.exp.destType);
10748 exp.cast.exp.destType = type;
10750 type.casted = true;
10751 ProcessExpressionType(exp.cast.exp);
10752 type.casted = false;
10754 exp.expType = type;
10757 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10758 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10760 void * prev = exp.prev, * next = exp.next;
10761 Type expType = exp.cast.exp.destType;
10762 Expression castExp = exp.cast.exp;
10763 Type destType = exp.destType;
10765 if(expType) expType.refCount++;
10767 //FreeType(exp.destType);
10768 FreeType(exp.expType);
10769 FreeTypeName(exp.cast.typeName);
10772 FreeType(exp.expType);
10773 FreeType(exp.destType);
10775 exp.expType = expType;
10776 exp.destType = destType;
10786 exp.isConstant = exp.cast.exp.isConstant;
10791 case extensionInitializerExp:
10793 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10794 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10795 // ProcessInitializer(exp.initializer.initializer, type);
10796 exp.expType = type;
10801 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10802 ProcessExpressionType(exp.vaArg.exp);
10803 exp.expType = type;
10809 exp.isConstant = true;
10811 FreeType(exp.cond.cond.destType);
10812 exp.cond.cond.destType = MkClassType("bool");
10813 exp.cond.cond.destType.truth = true;
10814 ProcessExpressionType(exp.cond.cond);
10815 if(!exp.cond.cond.isConstant)
10816 exp.isConstant = false;
10817 for(e = exp.cond.exp->first; e; e = e.next)
10821 FreeType(e.destType);
10822 e.destType = exp.destType;
10823 if(e.destType) e.destType.refCount++;
10825 ProcessExpressionType(e);
10828 exp.expType = e.expType;
10829 if(e.expType) e.expType.refCount++;
10832 exp.isConstant = false;
10835 FreeType(exp.cond.elseExp.destType);
10836 // Added this check if we failed to find an expType
10837 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10840 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10842 if(exp.cond.elseExp.destType)
10843 exp.cond.elseExp.destType.refCount++;
10844 ProcessExpressionType(exp.cond.elseExp);
10846 // FIXED THIS: Was done before calling process on elseExp
10847 if(!exp.cond.elseExp.isConstant)
10848 exp.isConstant = false;
10851 case extensionCompoundExp:
10853 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10855 Statement last = exp.compound.compound.statements->last;
10856 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10858 ((Expression)last.expressions->last).destType = exp.destType;
10860 exp.destType.refCount++;
10862 ProcessStatement(exp.compound);
10863 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10865 exp.expType.refCount++;
10871 Specifier spec = exp._classExp.specifiers->first;
10872 if(spec && spec.type == nameSpecifier)
10874 exp.expType = MkClassType(spec.name);
10875 exp.expType.kind = subClassType;
10876 exp.byReference = true;
10880 exp.expType = MkClassType("ecere::com::Class");
10881 exp.byReference = true;
10887 Class _class = thisClass ? thisClass : currentClass;
10890 Identifier id = exp.classData.id;
10891 char structName[1024];
10892 Expression classExp;
10893 strcpy(structName, "__ecereClassData_");
10894 FullClassNameCat(structName, _class.fullName, false);
10895 exp.type = pointerExp;
10896 exp.member.member = id;
10897 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10898 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10900 classExp = MkExpIdentifier(MkIdentifier("class"));
10902 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10903 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10904 MkExpBrackets(MkListOne(MkExpOp(
10905 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10906 MkExpMember(classExp, MkIdentifier("data"))), '+',
10907 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10910 ProcessExpressionType(exp);
10918 const char * typeString = null;
10919 char typeStringBuf[1024];
10920 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10921 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10923 Class templateClass = exp.destType._class.registered;
10924 typeString = templateClass.templateArgs[2].dataTypeString;
10928 // Guess type from expressions in the array
10930 for(e = exp.list->first; e; e = e.next)
10932 ProcessExpressionType(e);
10935 if(!type) { type = e.expType; type.refCount++; }
10938 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10939 if(!MatchTypeExpression(e, type, null, false, true))
10945 e = exp.list->first;
10946 ProcessExpressionType(e);
10949 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10950 if(!MatchTypeExpression(e, type, null, false, true))
10952 FreeType(e.expType);
10963 FreeType(e.expType);
10970 typeStringBuf[0] = '\0';
10971 PrintTypeNoConst(type, typeStringBuf, false, true);
10972 typeString = typeStringBuf;
10980 (Container)& (struct BuiltInContainer)
10982 ._vTbl = class(BuiltInContainer)._vTbl,
10983 ._class = class(BuiltInContainer),
10985 .data = (int[]){ 1, 7, 3, 4, 5 },
10987 .type = class(int),
10990 char templateString[1024];
10991 OldList * initializers = MkList();
10992 OldList * structInitializers = MkList();
10993 OldList * specs = MkList();
10995 Declarator decl = SpecDeclFromString(typeString, specs, null);
10996 sprintf(templateString, "Container<%s>", typeString);
11001 type = ProcessTypeString(typeString, false);
11002 while((e = exp.list->first))
11004 exp.list->Remove(e);
11007 ProcessExpressionType(e);
11008 ListAdd(initializers, MkInitializerAssignment(e));
11014 DeclareStruct("ecere::com::BuiltInContainer", false);
11016 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11017 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11018 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11019 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11020 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11021 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11022 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11023 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11024 MkInitializerList(initializers))));
11025 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11026 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11027 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11028 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11029 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11030 exp.expType = ProcessTypeString(templateString, false);
11031 exp.type = bracketsExp;
11032 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11034 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11035 MkInitializerList(structInitializers)))));
11036 ProcessExpressionType(expExt);
11040 exp.expType = ProcessTypeString("Container", false);
11041 Compiler_Error($"Couldn't determine type of array elements\n");
11047 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11049 FreeType(exp.expType);
11050 exp.expType = ReplaceThisClassType(thisClass);
11053 // Resolve structures here
11054 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11056 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11057 // TODO: Fix members reference...
11060 if(exp.expType.kind != enumType)
11063 String enumName = CopyString(exp.expType.enumName);
11065 // Fixed a memory leak on self-referencing C structs typedefs
11066 // by instantiating a new type rather than simply copying members
11067 // into exp.expType
11068 FreeType(exp.expType);
11069 exp.expType = Type { };
11070 exp.expType.kind = symbol.type.kind;
11071 exp.expType.refCount++;
11072 exp.expType.enumName = enumName;
11074 exp.expType.members = symbol.type.members;
11075 for(member = symbol.type.members.first; member; member = member.next)
11080 NamedLink64 member;
11081 for(member = symbol.type.members.first; member; member = member.next)
11083 NamedLink64 value { name = CopyString(member.name) };
11084 exp.expType.members.Add(value);
11091 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11092 else if(exp.destType && !exp.destType.keepCast)
11094 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11095 exp.needTemplateCast = 1;
11097 if(exp.destType.kind == voidType);
11098 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11100 if(!exp.destType.count || unresolved)
11105 if(exp.destType.kind != ellipsisType)
11111 char expString[10240];
11112 expString[0] = '\0';
11114 PrintType(exp.destType, type2, false, true);
11116 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11118 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11119 else if(exp.type != dummyExp)
11120 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11125 char expString[10240] ;
11126 expString[0] = '\0';
11127 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11130 Compiler_Error($"unresolved identifier %s\n", expString);
11131 else if(exp.type != dummyExp)
11132 Compiler_Error($"couldn't determine type of %s\n", expString);
11143 PrintType(exp.expType, type1, false, true);
11144 PrintType(exp.destType, type2, false, true);
11147 //CheckExpressionType(exp, exp.destType, false);
11149 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11150 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11151 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11154 char expString[10240];
11155 expString[0] = '\0';
11156 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11159 CheckExpressionType(exp, exp.destType, false, true);
11161 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11162 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
11163 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11165 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11166 FreeType(exp.expType);
11167 exp.destType.refCount++;
11168 exp.expType = exp.destType;
11173 /*else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
11175 Expression newExp { };
11176 char typeString[1024];
11177 OldList * specs = MkList();
11180 typeString[0] = '\0';
11184 if(exp.expType) exp.expType.refCount++;
11185 if(exp.expType) exp.expType.refCount++;
11186 exp.type = castExp;
11187 newExp.destType = exp.expType;
11189 PrintType(exp.expType, typeString, false, false);
11190 decl = SpecDeclFromString(typeString, specs, null);
11192 exp.cast.typeName = MkTypeName(specs, decl);
11193 exp.cast.exp = newExp;
11196 else if(unresolved)
11198 if(exp.identifier._class && exp.identifier._class.name)
11199 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11200 else if(exp.identifier.string && exp.identifier.string[0])
11201 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11203 else if(!exp.expType && exp.type != dummyExp)
11205 char expString[10240];
11206 expString[0] = '\0';
11207 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11208 Compiler_Error($"couldn't determine type of %s\n", expString);
11211 // Let's try to support any_object & typed_object here:
11213 ApplyAnyObjectLogic(exp);
11215 // Mark nohead classes as by reference, unless we're casting them to an integral type
11216 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11217 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11218 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11219 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11221 exp.byReference = true;
11223 yylloc = oldyylloc;
11226 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11228 // THIS CODE WILL FIND NEXT MEMBER...
11231 *curMember = (*curMember).next;
11233 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11235 *curMember = subMemberStack[--(*subMemberStackPos)];
11236 *curMember = (*curMember).next;
11239 // SKIP ALL PROPERTIES HERE...
11240 while((*curMember) && (*curMember).isProperty)
11241 *curMember = (*curMember).next;
11243 if(subMemberStackPos)
11245 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11247 subMemberStack[(*subMemberStackPos)++] = *curMember;
11249 *curMember = (*curMember).members.first;
11250 while(*curMember && (*curMember).isProperty)
11251 *curMember = (*curMember).next;
11259 if(subMemberStackPos && *subMemberStackPos)
11261 *curMember = subMemberStack[--(*subMemberStackPos)];
11262 *curMember = (*curMember).next;
11266 Class lastCurClass = *curClass;
11268 if(*curClass == _class) break; // REACHED THE END
11270 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11271 *curMember = (*curClass).membersAndProperties.first;
11274 while((*curMember) && (*curMember).isProperty)
11275 *curMember = (*curMember).next;
11276 if(subMemberStackPos)
11278 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11280 subMemberStack[(*subMemberStackPos)++] = *curMember;
11282 *curMember = (*curMember).members.first;
11283 while(*curMember && (*curMember).isProperty)
11284 *curMember = (*curMember).next;
11292 static void ProcessInitializer(Initializer init, Type type)
11296 case expInitializer:
11297 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11299 // TESTING THIS FOR SHUTTING = 0 WARNING
11300 if(init.exp && !init.exp.destType)
11302 FreeType(init.exp.destType);
11303 init.exp.destType = type;
11304 if(type) type.refCount++;
11308 ProcessExpressionType(init.exp);
11309 init.isConstant = init.exp.isConstant;
11315 Expression exp = init.exp;
11316 Instantiation inst = exp.instance;
11317 MembersInit members;
11319 init.type = listInitializer;
11320 init.list = MkList();
11324 for(members = inst.members->first; members; members = members.next)
11326 if(members.type == dataMembersInit)
11329 for(member = members.dataMembers->first; member; member = member.next)
11331 ListAdd(init.list, member.initializer);
11332 member.initializer = null;
11335 // Discard all MembersInitMethod
11338 FreeExpression(exp);
11340 case listInitializer:
11343 Type initializerType = null;
11344 Class curClass = null;
11345 DataMember curMember = null;
11346 DataMember subMemberStack[256];
11347 int subMemberStackPos = 0;
11349 if(type && type.kind == arrayType)
11350 initializerType = Dereference(type);
11351 else if(type && (type.kind == structType || type.kind == unionType))
11352 initializerType = type.members.first;
11354 for(i = init.list->first; i; i = i.next)
11356 if(type && type.kind == classType && type._class && type._class.registered)
11358 // 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)
11359 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11360 // TODO: Generate error on initializing a private data member this way from another module...
11363 if(!curMember.dataType)
11364 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11365 initializerType = curMember.dataType;
11368 ProcessInitializer(i, initializerType);
11369 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11370 initializerType = initializerType.next;
11372 init.isConstant = false;
11375 if(type && type.kind == arrayType)
11376 FreeType(initializerType);
11378 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11380 Compiler_Error($"Assigning list initializer to non list\n");
11387 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11391 case baseSpecifier:
11393 if(spec.specifier == THISCLASS)
11397 spec.type = nameSpecifier;
11398 spec.name = ReplaceThisClass(thisClass);
11399 spec.symbol = FindClass(spec.name);
11400 ProcessSpecifier(spec, declareStruct);
11405 case nameSpecifier:
11407 Symbol symbol = FindType(curContext, spec.name);
11409 DeclareType(symbol.type, true, true);
11410 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11411 DeclareStruct(spec.name, false);
11414 case enumSpecifier:
11419 for(e = spec.list->first; e; e = e.next)
11422 ProcessExpressionType(e.exp);
11427 case structSpecifier:
11428 case unionSpecifier:
11430 if(spec.definitions)
11433 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11435 ProcessClass(spec.definitions, symbol);
11438 for(def = spec.definitions->first; def; def = def.next)
11440 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11441 ProcessDeclaration(def.decl);
11448 case classSpecifier:
11450 Symbol classSym = FindClass(spec.name);
11451 if(classSym && classSym.registered && classSym.registered.type == structClass)
11452 DeclareStruct(spec.name, false);
11460 static void ProcessDeclarator(Declarator decl)
11464 case identifierDeclarator:
11465 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11467 FreeSpecifier(decl.identifier._class);
11468 decl.identifier._class = null;
11471 case arrayDeclarator:
11473 ProcessExpressionType(decl.array.exp);
11474 case structDeclarator:
11475 case bracketsDeclarator:
11476 case functionDeclarator:
11477 case pointerDeclarator:
11478 case extendedDeclarator:
11479 case extendedDeclaratorEnd:
11480 if(decl.declarator)
11481 ProcessDeclarator(decl.declarator);
11482 if(decl.type == functionDeclarator)
11484 Identifier id = GetDeclId(decl);
11485 if(id && id._class)
11489 qualifiers = MkListOne(id._class);
11492 if(!decl.function.parameters)
11493 decl.function.parameters = MkList();
11494 decl.function.parameters->Insert(null, param);
11497 if(decl.function.parameters)
11501 for(param = decl.function.parameters->first; param; param = param.next)
11503 if(param.qualifiers && param.qualifiers->first)
11505 Specifier spec = param.qualifiers->first;
11506 if(spec && spec.specifier == TYPED_OBJECT)
11508 Declarator d = param.declarator;
11511 qualifiers = MkListOne(MkSpecifier(VOID));
11512 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11514 if(d.type != pointerDeclarator)
11515 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11517 FreeList(param.qualifiers, FreeSpecifier);
11519 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11520 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11522 decl.function.parameters->Insert(param, newParam);
11525 else if(spec && spec.specifier == ANY_OBJECT)
11527 Declarator d = param.declarator;
11529 FreeList(param.qualifiers, FreeSpecifier);
11531 param.qualifiers = MkListOne(MkSpecifier(VOID));
11532 if(d.type != pointerDeclarator)
11533 param.qualifiers->Insert(null, MkSpecifier(CONST));
11534 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11536 else if(spec.specifier == THISCLASS)
11540 spec.type = nameSpecifier;
11541 spec.name = ReplaceThisClass(thisClass);
11542 spec.symbol = FindClass(spec.name);
11543 ProcessSpecifier(spec, false);
11548 if(param.declarator)
11549 ProcessDeclarator(param.declarator);
11557 static void ProcessDeclaration(Declaration decl)
11562 case initDeclaration:
11564 bool declareStruct = false;
11566 lineNum = decl.pos.line;
11567 column = decl.pos.col;
11570 if(decl.declarators)
11574 for(d = decl.declarators->first; d; d = d.next)
11576 Type type, subType;
11577 ProcessDeclarator(d.declarator);
11579 type = ProcessType(decl.specifiers, d.declarator);
11583 ProcessInitializer(d.initializer, type);
11585 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11587 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11588 d.initializer.exp.type == instanceExp)
11590 if(type.kind == classType && type._class ==
11591 d.initializer.exp.expType._class)
11593 Instantiation inst = d.initializer.exp.instance;
11594 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11596 d.initializer.exp.instance = null;
11597 if(decl.specifiers)
11598 FreeList(decl.specifiers, FreeSpecifier);
11599 FreeList(decl.declarators, FreeInitDeclarator);
11603 decl.type = instDeclaration;
11608 for(subType = type; subType;)
11610 if(subType.kind == classType)
11612 declareStruct = true;
11615 else if(subType.kind == pointerType)
11617 else if(subType.kind == arrayType)
11618 subType = subType.arrayType;
11628 if(decl.specifiers)
11631 for(s = decl.specifiers->first; s; s = s.next)
11633 ProcessSpecifier(s, declareStruct);
11638 case instDeclaration:
11640 ProcessInstantiationType(decl.inst);
11643 case structDeclaration:
11647 bool declareStruct = false;
11649 if(decl.declarators)
11651 for(d = decl.declarators->first; d; d = d.next)
11653 Type type = ProcessType(decl.specifiers, d.declarator);
11655 ProcessDeclarator(d);
11656 for(subType = type; subType;)
11658 if(subType.kind == classType)
11660 declareStruct = true;
11663 else if(subType.kind == pointerType)
11665 else if(subType.kind == arrayType)
11666 subType = subType.arrayType;
11673 if(decl.specifiers)
11675 for(spec = decl.specifiers->first; spec; spec = spec.next)
11676 ProcessSpecifier(spec, declareStruct);
11683 static FunctionDefinition curFunction;
11685 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11687 char propName[1024], propNameM[1024];
11688 char getName[1024], setName[1024];
11691 DeclareProperty(prop, setName, getName);
11693 // eInstance_FireWatchers(object, prop);
11694 strcpy(propName, "__ecereProp_");
11695 FullClassNameCat(propName, prop._class.fullName, false);
11696 strcat(propName, "_");
11697 // strcat(propName, prop.name);
11698 FullClassNameCat(propName, prop.name, true);
11699 //MangleClassName(propName);
11701 strcpy(propNameM, "__ecerePropM_");
11702 FullClassNameCat(propNameM, prop._class.fullName, false);
11703 strcat(propNameM, "_");
11704 // strcat(propNameM, prop.name);
11705 FullClassNameCat(propNameM, prop.name, true);
11706 //MangleClassName(propNameM);
11708 if(prop.isWatchable)
11711 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11712 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11713 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11716 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11717 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11718 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11724 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11725 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11726 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11729 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11730 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11731 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11734 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11735 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11736 curFunction.propSet.fireWatchersDone = true;
11739 static void ProcessStatement(Statement stmt)
11743 lineNum = stmt.pos.line;
11744 column = stmt.pos.col;
11749 ProcessStatement(stmt.labeled.stmt);
11752 // This expression should be constant...
11753 if(stmt.caseStmt.exp)
11755 FreeType(stmt.caseStmt.exp.destType);
11756 stmt.caseStmt.exp.destType = curSwitchType;
11757 if(curSwitchType) curSwitchType.refCount++;
11758 ProcessExpressionType(stmt.caseStmt.exp);
11759 ComputeExpression(stmt.caseStmt.exp);
11761 if(stmt.caseStmt.stmt)
11762 ProcessStatement(stmt.caseStmt.stmt);
11766 if(stmt.compound.context)
11771 Statement prevCompound = curCompound;
11772 Context prevContext = curContext;
11774 if(!stmt.compound.isSwitch)
11775 curCompound = stmt;
11776 curContext = stmt.compound.context;
11778 if(stmt.compound.declarations)
11780 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11781 ProcessDeclaration(decl);
11783 if(stmt.compound.statements)
11785 for(s = stmt.compound.statements->first; s; s = s.next)
11786 ProcessStatement(s);
11789 curContext = prevContext;
11790 curCompound = prevCompound;
11794 case expressionStmt:
11797 if(stmt.expressions)
11799 for(exp = stmt.expressions->first; exp; exp = exp.next)
11800 ProcessExpressionType(exp);
11808 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11809 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11810 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11811 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11813 ProcessExpressionType(exp);
11815 if(stmt.ifStmt.stmt)
11816 ProcessStatement(stmt.ifStmt.stmt);
11817 if(stmt.ifStmt.elseStmt)
11818 ProcessStatement(stmt.ifStmt.elseStmt);
11823 Type oldSwitchType = curSwitchType;
11824 if(stmt.switchStmt.exp)
11827 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11837 e.exp.destType = destType;
11840 ProcessExpressionType(exp);
11843 curSwitchType = exp.expType;
11846 ProcessStatement(stmt.switchStmt.stmt);
11847 curSwitchType = oldSwitchType;
11852 if(stmt.whileStmt.exp)
11856 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11857 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11858 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11859 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11861 ProcessExpressionType(exp);
11864 if(stmt.whileStmt.stmt)
11865 ProcessStatement(stmt.whileStmt.stmt);
11870 if(stmt.doWhile.exp)
11874 if(stmt.doWhile.exp->last)
11876 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11877 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11878 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11880 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11882 ProcessExpressionType(exp);
11885 if(stmt.doWhile.stmt)
11886 ProcessStatement(stmt.doWhile.stmt);
11892 if(stmt.forStmt.init)
11893 ProcessStatement(stmt.forStmt.init);
11895 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11897 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11898 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11899 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11902 if(stmt.forStmt.check)
11903 ProcessStatement(stmt.forStmt.check);
11904 if(stmt.forStmt.increment)
11906 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11907 ProcessExpressionType(exp);
11910 if(stmt.forStmt.stmt)
11911 ProcessStatement(stmt.forStmt.stmt);
11916 Identifier id = stmt.forEachStmt.id;
11917 OldList * exp = stmt.forEachStmt.exp;
11918 OldList * filter = stmt.forEachStmt.filter;
11919 Statement block = stmt.forEachStmt.stmt;
11920 char iteratorType[1024];
11923 bool isBuiltin = exp && exp->last &&
11924 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11925 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11926 Expression arrayExp;
11927 const char * typeString = null;
11928 int builtinCount = 0;
11930 for(e = exp ? exp->first : null; e; e = e.next)
11934 FreeType(e.destType);
11935 e.destType = ProcessTypeString("Container", false);
11937 if(!isBuiltin || e.next)
11938 ProcessExpressionType(e);
11941 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11942 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11943 eClass_IsDerived(source._class.registered, containerClass)))
11945 Class _class = source ? source._class.registered : null;
11947 Expression expIt = null;
11948 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
11949 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11950 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11951 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11952 stmt.type = compoundStmt;
11954 stmt.compound.context = Context { };
11955 stmt.compound.context.parent = curContext;
11956 curContext = stmt.compound.context;
11958 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11960 Class mapClass = eSystem_FindClass(privateModule, "Map");
11961 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11962 isCustomAVLTree = true;
11963 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
11965 else */if(eClass_IsDerived(source._class.registered, mapClass))
11968 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11969 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11971 Class listClass = eSystem_FindClass(privateModule, "List");
11973 isList = eClass_IsDerived(source._class.registered, listClass);
11979 OldList * specs = MkList();
11980 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11981 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11982 stmt.compound.declarations = MkListOne(
11983 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11984 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11985 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11986 MkInitializerAssignment(MkExpBrackets(exp))))));
11991 char typeStringBuf[1024];
11993 // TODO: Merge this code?
11994 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11995 if(((Expression)exp->last).type == castExp)
11997 TypeName typeName = ((Expression)exp->last).cast.typeName;
11999 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12002 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12003 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12004 arrayExp.destType._class.registered.templateArgs)
12006 Class templateClass = arrayExp.destType._class.registered;
12007 typeString = templateClass.templateArgs[2].dataTypeString;
12009 else if(arrayExp.list)
12011 // Guess type from expressions in the array
12013 for(e = arrayExp.list->first; e; e = e.next)
12015 ProcessExpressionType(e);
12018 if(!type) { type = e.expType; type.refCount++; }
12021 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12022 if(!MatchTypeExpression(e, type, null, false, true))
12028 e = arrayExp.list->first;
12029 ProcessExpressionType(e);
12032 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12033 if(!MatchTypeExpression(e, type, null, false, true))
12035 FreeType(e.expType);
12046 FreeType(e.expType);
12053 typeStringBuf[0] = '\0';
12054 PrintType(type, typeStringBuf, false, true);
12055 typeString = typeStringBuf;
12061 OldList * initializers = MkList();
12063 OldList * specs = MkList();
12068 builtinCount = arrayExp.list->count;
12069 type = ProcessTypeString(typeString, false);
12070 while((e = arrayExp.list->first))
12072 arrayExp.list->Remove(e);
12075 ProcessExpressionType(e);
12076 ListAdd(initializers, MkInitializerAssignment(e));
12079 delete arrayExp.list;
12081 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12082 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12083 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12085 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12087 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12088 ), MkInitializerList(initializers)))));
12089 FreeList(exp, FreeExpression);
12093 arrayExp.expType = ProcessTypeString("Container", false);
12094 Compiler_Error($"Couldn't determine type of array elements\n");
12099 OldList * specs = MkList();
12101 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12102 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12103 stmt.compound.declarations = MkListOne(
12104 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12105 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12106 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12107 MkInitializerAssignment(MkExpBrackets(exp))))));
12110 else if(isLinkList && !isList)
12113 OldList * specs = MkList();
12114 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12115 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12116 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12117 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12118 MkInitializerAssignment(MkExpBrackets(exp))))));
12120 /*else if(isCustomAVLTree)
12123 OldList * specs = MkList();
12124 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12125 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12126 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12127 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12128 MkInitializerAssignment(MkExpBrackets(exp))))));
12130 else if(_class.templateArgs)
12133 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12135 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12137 stmt.compound.declarations = MkListOne(
12138 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12139 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12140 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12142 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12146 // Reparent sub-contexts in this statement
12150 if(block.compound.context)
12151 block.compound.context.parent = stmt.compound.context;
12154 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12155 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12156 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12157 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12160 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12161 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12164 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12165 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12168 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12169 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12172 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12173 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12176 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12177 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12179 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12182 case expressionStmt:
12188 case badDeclarationStmt:
12189 case fireWatchersStmt:
12190 case stopWatchingStmt:
12197 block = MkIfStmt(filter, block, null);
12201 stmt.compound.statements = MkListOne(MkForStmt(
12202 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12203 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12204 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12205 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12207 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12208 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12209 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12214 //OldList * specs = MkList();
12215 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12217 sprintf(count, "%d", builtinCount);
12219 stmt.compound.statements = MkListOne(MkForStmt(
12220 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12221 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12222 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12223 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12227 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12228 stmt.compound.statements = MkListOne(MkForStmt(
12229 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12230 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12231 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12232 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12235 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12236 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12237 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12239 else if(isLinkList && !isList)
12241 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12242 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12243 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12244 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12246 stmt.compound.statements = MkListOne(MkForStmt(
12247 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12248 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12249 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12254 OldList * specs = MkList();
12255 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12256 stmt.compound.statements = MkListOne(MkForStmt(
12257 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12258 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12259 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12260 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12261 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12264 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12265 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12266 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12268 /*else if(isCustomAVLTree)
12270 stmt.compound.statements = MkListOne(MkForStmt(
12271 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12272 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12273 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12274 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12277 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12278 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12279 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12283 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12284 MkIdentifier("Next")), null)), block));
12286 ProcessExpressionType(expIt);
12287 if(stmt.compound.declarations->first)
12288 ProcessDeclaration(stmt.compound.declarations->first);
12291 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12293 ProcessStatement(stmt);
12294 curContext = stmt.compound.context.parent;
12299 Compiler_Error($"Expression is not a container\n");
12312 if(stmt.expressions)
12314 for(exp = stmt.expressions->first; exp; exp = exp.next)
12318 if(curFunction && !curFunction.type)
12319 curFunction.type = ProcessType(
12320 curFunction.specifiers, curFunction.declarator);
12321 FreeType(exp.destType);
12322 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12323 if(exp.destType) exp.destType.refCount++;
12325 ProcessExpressionType(exp);
12330 case badDeclarationStmt:
12332 ProcessDeclaration(stmt.decl);
12338 if(stmt.asmStmt.inputFields)
12340 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12341 if(field.expression)
12342 ProcessExpressionType(field.expression);
12344 if(stmt.asmStmt.outputFields)
12346 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12347 if(field.expression)
12348 ProcessExpressionType(field.expression);
12350 if(stmt.asmStmt.clobberedFields)
12352 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12354 if(field.expression)
12355 ProcessExpressionType(field.expression);
12362 PropertyWatch propWatch;
12363 OldList * watches = stmt._watch.watches;
12364 Expression object = stmt._watch.object;
12365 Expression watcher = stmt._watch.watcher;
12367 ProcessExpressionType(watcher);
12369 ProcessExpressionType(object);
12373 if(watcher || thisClass)
12375 External external = curExternal;
12376 Context context = curContext;
12378 stmt.type = expressionStmt;
12379 stmt.expressions = MkList();
12381 curExternal = external.prev;
12383 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12385 ClassFunction func;
12386 char watcherName[1024];
12387 Class watcherClass = watcher ?
12388 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12389 External createdExternal;
12391 // Create a declaration above
12392 External externalDecl = MkExternalDeclaration(null);
12393 ast->Insert(curExternal.prev, externalDecl);
12395 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12396 if(propWatch.deleteWatch)
12397 strcat(watcherName, "_delete");
12401 for(propID = propWatch.properties->first; propID; propID = propID.next)
12403 strcat(watcherName, "_");
12404 strcat(watcherName, propID.string);
12408 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12410 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12411 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12412 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12413 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12414 ProcessClassFunctionBody(func, propWatch.compound);
12415 propWatch.compound = null;
12417 //afterExternal = afterExternal ? afterExternal : curExternal;
12419 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12420 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12422 createdExternal.symbol.idCode = external.symbol.idCode;
12424 curExternal = createdExternal;
12425 ProcessFunction(createdExternal.function);
12428 // Create a declaration above
12430 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12431 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12432 externalDecl.declaration = decl;
12433 if(decl.symbol && !decl.symbol.pointerExternal)
12434 decl.symbol.pointerExternal = externalDecl;
12437 if(propWatch.deleteWatch)
12439 OldList * args = MkList();
12440 ListAdd(args, CopyExpression(object));
12441 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12442 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12443 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12447 Class _class = object.expType._class.registered;
12450 for(propID = propWatch.properties->first; propID; propID = propID.next)
12452 char propName[1024];
12453 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12456 char getName[1024], setName[1024];
12457 OldList * args = MkList();
12459 DeclareProperty(prop, setName, getName);
12461 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12462 strcpy(propName, "__ecereProp_");
12463 FullClassNameCat(propName, prop._class.fullName, false);
12464 strcat(propName, "_");
12465 // strcat(propName, prop.name);
12466 FullClassNameCat(propName, prop.name, true);
12468 ListAdd(args, CopyExpression(object));
12469 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12470 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12471 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12473 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12476 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12481 Compiler_Error($"Invalid watched object\n");
12484 curExternal = external;
12485 curContext = context;
12488 FreeExpression(watcher);
12490 FreeExpression(object);
12491 FreeList(watches, FreePropertyWatch);
12494 Compiler_Error($"No observer specified and not inside a _class\n");
12498 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12500 ProcessStatement(propWatch.compound);
12506 case fireWatchersStmt:
12508 OldList * watches = stmt._watch.watches;
12509 Expression object = stmt._watch.object;
12511 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12512 // printf("%X\n", watches);
12513 // printf("%X\n", stmt._watch.watches);
12515 ProcessExpressionType(object);
12520 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12526 stmt.type = expressionStmt;
12527 stmt.expressions = MkList();
12529 // Check if we're inside a property set
12530 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12532 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12536 //Compiler_Error($"No property specified and not inside a property set\n");
12540 for(propID = watches->first; propID; propID = propID.next)
12542 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12545 CreateFireWatcher(prop, object, stmt);
12548 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12553 // Fire all properties!
12556 for(base = _class; base; base = base.base)
12558 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12560 if(prop.isProperty && prop.isWatchable)
12562 CreateFireWatcher(prop, object, stmt);
12569 FreeExpression(object);
12570 FreeList(watches, FreeIdentifier);
12573 Compiler_Error($"Invalid object specified and not inside a class\n");
12577 case stopWatchingStmt:
12579 OldList * watches = stmt._watch.watches;
12580 Expression object = stmt._watch.object;
12581 Expression watcher = stmt._watch.watcher;
12584 ProcessExpressionType(object);
12586 ProcessExpressionType(watcher);
12589 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12591 if(watcher || thisClass)
12597 stmt.type = expressionStmt;
12598 stmt.expressions = MkList();
12603 // eInstance_StopWatching(object, null, watcher);
12605 ListAdd(args, CopyExpression(object));
12606 ListAdd(args, MkExpConstant("0"));
12607 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12608 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12612 for(propID = watches->first; propID; propID = propID.next)
12614 char propName[1024];
12615 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12618 char getName[1024], setName[1024];
12619 OldList * args = MkList();
12621 DeclareProperty(prop, setName, getName);
12623 // eInstance_StopWatching(object, prop, watcher);
12624 strcpy(propName, "__ecereProp_");
12625 FullClassNameCat(propName, prop._class.fullName, false);
12626 strcat(propName, "_");
12627 // strcat(propName, prop.name);
12628 FullClassNameCat(propName, prop.name, true);
12629 //MangleClassName(propName);
12631 ListAdd(args, CopyExpression(object));
12632 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12633 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12634 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12637 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12642 FreeExpression(object);
12644 FreeExpression(watcher);
12645 FreeList(watches, FreeIdentifier);
12648 Compiler_Error($"Invalid object specified and not inside a class\n");
12651 Compiler_Error($"No observer specified and not inside a class\n");
12658 static void ProcessFunction(FunctionDefinition function)
12660 Identifier id = GetDeclId(function.declarator);
12661 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12662 Type type = symbol ? symbol.type : null;
12663 Class oldThisClass = thisClass;
12664 Context oldTopContext = topContext;
12666 yylloc = function.loc;
12667 // Process thisClass
12669 if(type && type.thisClass)
12671 Symbol classSym = type.thisClass;
12672 Class _class = type.thisClass.registered;
12673 char className[1024];
12674 char structName[1024];
12675 Declarator funcDecl;
12678 bool typedObject = false;
12680 if(_class && !_class.base)
12682 _class = currentClass;
12683 if(_class && !_class.symbol)
12684 _class.symbol = FindClass(_class.fullName);
12685 classSym = _class ? _class.symbol : null;
12686 typedObject = true;
12689 thisClass = _class;
12691 if(inCompiler && _class)
12693 if(type.kind == functionType)
12695 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12697 //TypeName param = symbol.type.params.first;
12698 Type param = symbol.type.params.first;
12699 symbol.type.params.Remove(param);
12700 //FreeTypeName(param);
12703 if(type.classObjectType != classPointer)
12705 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12706 symbol.type.staticMethod = true;
12707 symbol.type.thisClass = null;
12709 // HIGH DANGER: VERIFYING THIS...
12710 symbol.type.extraParam = false;
12714 strcpy(className, "__ecereClass_");
12715 FullClassNameCat(className, _class.fullName, true);
12717 //MangleClassName(className);
12720 FullClassNameCat(structName, _class.fullName, false);
12725 funcDecl = GetFuncDecl(function.declarator);
12728 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12730 TypeName param = funcDecl.function.parameters->first;
12731 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12733 funcDecl.function.parameters->Remove(param);
12734 FreeTypeName(param);
12738 // DANGER: Watch for this... Check if it's a Conversion?
12739 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12741 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12742 if(!function.propertyNoThis)
12744 TypeName thisParam = null;
12746 if(type.classObjectType != classPointer)
12748 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12749 if(!funcDecl.function.parameters)
12750 funcDecl.function.parameters = MkList();
12751 funcDecl.function.parameters->Insert(null, thisParam);
12756 if(type.classObjectType != classPointer)
12758 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12759 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12762 thisParam = TypeName
12764 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12765 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12767 funcDecl.function.parameters->Insert(null, thisParam);
12772 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12774 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12775 funcDecl = GetFuncDecl(initDecl.declarator);
12778 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12780 TypeName param = funcDecl.function.parameters->first;
12781 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12783 funcDecl.function.parameters->Remove(param);
12784 FreeTypeName(param);
12788 if(type.classObjectType != classPointer)
12790 // DANGER: Watch for this... Check if it's a Conversion?
12791 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12793 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12795 if(!funcDecl.function.parameters)
12796 funcDecl.function.parameters = MkList();
12797 funcDecl.function.parameters->Insert(null, thisParam);
12804 // Add this to the context
12807 if(type.classObjectType != classPointer)
12809 thisSymbol = Symbol
12811 string = CopyString("this");
12812 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12814 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12816 if(typedObject && thisSymbol.type)
12818 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12819 thisSymbol.type.byReference = type.byReference;
12820 thisSymbol.type.typedByReference = type.byReference;
12822 thisSymbol = Symbol { string = CopyString("class") };
12823 function.body.compound.context.symbols.Add(thisSymbol);
12829 // Pointer to class data
12831 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12833 DataMember member = null;
12836 for(base = _class; base && base.type != systemClass; base = base.next)
12838 for(member = base.membersAndProperties.first; member; member = member.next)
12839 if(!member.isProperty)
12845 for(member = _class.membersAndProperties.first; member; member = member.next)
12846 if(!member.isProperty)
12850 char pointerName[1024];
12853 Initializer initializer;
12854 Expression exp, bytePtr;
12856 strcpy(pointerName, "__ecerePointer_");
12857 FullClassNameCat(pointerName, _class.fullName, false);
12859 char className[1024];
12860 strcpy(className, "__ecereClass_");
12861 FullClassNameCat(className, classSym.string, true);
12862 //MangleClassName(className);
12865 DeclareClass(classSym, className);
12869 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12874 sprintf(string, "%d", _class.offset);
12875 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12879 // ([bytePtr] + [className]->offset)
12880 exp = QBrackets(MkExpOp(bytePtr, '+',
12881 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12884 // (this ? [exp] : 0)
12885 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12889 kind = pointerType;
12890 type = Type { refCount = 1, kind = voidType };
12895 yylloc = function.body.loc;
12896 // ([structName] *) [exp]
12897 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12898 initializer = MkInitializerAssignment(
12899 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12901 // [structName] * [pointerName] = [initializer];
12902 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12905 Context prevContext = curContext;
12907 curContext = function.body.compound.context;
12909 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
12910 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12911 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
12913 curContext = prevContext;
12917 decl.symbol = null;
12919 if(!function.body.compound.declarations)
12920 function.body.compound.declarations = MkList();
12921 function.body.compound.declarations->Insert(null, decl);
12927 // Loop through the function and replace undeclared identifiers
12928 // which are a member of the class (methods, properties or data)
12929 // by "this.[member]"
12936 FreeSpecifier(id._class);
12939 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12941 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12942 id = GetDeclId(initDecl.declarator);
12944 FreeSpecifier(id._class);
12949 topContext = function.body.compound.context;
12951 FunctionDefinition oldFunction = curFunction;
12952 curFunction = function;
12954 ProcessStatement(function.body);
12956 // If this is a property set and no firewatchers has been done yet, add one here
12957 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12959 Statement prevCompound = curCompound;
12960 Context prevContext = curContext;
12962 Statement fireWatchers = MkFireWatchersStmt(null, null);
12963 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12964 ListAdd(function.body.compound.statements, fireWatchers);
12966 curCompound = function.body;
12967 curContext = function.body.compound.context;
12969 ProcessStatement(fireWatchers);
12971 curContext = prevContext;
12972 curCompound = prevCompound;
12976 curFunction = oldFunction;
12979 if(function.declarator)
12981 ProcessDeclarator(function.declarator);
12984 topContext = oldTopContext;
12985 thisClass = oldThisClass;
12988 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12989 static void ProcessClass(OldList definitions, Symbol symbol)
12992 External external = curExternal;
12993 Class regClass = symbol ? symbol.registered : null;
12995 // Process all functions
12996 for(def = definitions.first; def; def = def.next)
12998 if(def.type == functionClassDef)
13000 if(def.function.declarator)
13001 curExternal = def.function.declarator.symbol.pointerExternal;
13003 curExternal = external;
13005 ProcessFunction((FunctionDefinition)def.function);
13007 else if(def.type == declarationClassDef)
13009 if(def.decl.type == instDeclaration)
13011 thisClass = regClass;
13012 ProcessInstantiationType(def.decl.inst);
13018 Class backThisClass = thisClass;
13019 if(regClass) thisClass = regClass;
13020 ProcessDeclaration(def.decl);
13021 thisClass = backThisClass;
13024 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13026 MemberInit defProperty;
13028 // Add this to the context
13029 Symbol thisSymbol = Symbol
13031 string = CopyString("this");
13032 type = regClass ? MkClassType(regClass.fullName) : null;
13034 globalContext.symbols.Add((BTNode)thisSymbol);
13036 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13038 thisClass = regClass;
13039 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13043 globalContext.symbols.Remove((BTNode)thisSymbol);
13044 FreeSymbol(thisSymbol);
13046 else if(def.type == propertyClassDef && def.propertyDef)
13048 PropertyDef prop = def.propertyDef;
13050 // Add this to the context
13052 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
13053 globalContext.symbols.Add(thisSymbol);
13056 thisClass = regClass;
13063 string = CopyString("this");
13064 type = MkClassType(regClass.fullName);
13066 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13069 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13070 ProcessStatement(prop.setStmt);
13078 string = CopyString("this");
13079 type = MkClassType(regClass.fullName);
13081 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13084 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13085 ProcessStatement(prop.getStmt);
13093 string = CopyString("this");
13094 type = MkClassType(regClass.fullName);
13096 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13099 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13100 ProcessStatement(prop.issetStmt);
13106 globalContext.symbols.Remove(thisSymbol);
13107 FreeSymbol(thisSymbol);
13110 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13112 PropertyWatch propertyWatch = def.propertyWatch;
13114 thisClass = regClass;
13115 if(propertyWatch.compound)
13119 string = CopyString("this");
13120 type = regClass ? MkClassType(regClass.fullName) : null;
13123 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13125 curExternal = null;
13126 ProcessStatement(propertyWatch.compound);
13133 void DeclareFunctionUtil(const String s)
13135 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13140 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13141 strcpy(name, "__ecereFunction_");
13142 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13143 DeclareFunction(function, name);
13147 void ComputeDataTypes()
13151 External after = null;
13153 currentClass = null;
13155 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13157 for(external = ast->first; external; external = external.next)
13159 if(external.type == declarationExternal)
13161 Declaration decl = external.declaration;
13164 OldList * decls = decl.declarators;
13167 InitDeclarator initDecl = decls->first;
13170 Declarator declarator = initDecl.declarator;
13171 if(declarator && declarator.type == identifierDeclarator)
13173 Identifier id = declarator.identifier;
13174 if(id && id.string)
13176 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
13178 external.symbol.id = -1001, external.symbol.idCode = -1001;
13190 // Workaround until we have proper toposort for declarations reordering
13191 External e = MkExternalDeclaration(MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Instance"), null)), null));
13192 ast->Insert(after, e);
13196 temp.symbol = Symbol { id = -1000, idCode = -1000 };
13197 ast->Insert(after, temp);
13198 curExternal = temp;
13200 DeclareFunctionUtil("eSystem_New");
13201 DeclareFunctionUtil("eSystem_New0");
13202 DeclareFunctionUtil("eSystem_Renew");
13203 DeclareFunctionUtil("eSystem_Renew0");
13204 DeclareFunctionUtil("eSystem_Delete");
13205 DeclareFunctionUtil("eClass_GetProperty");
13206 DeclareFunctionUtil("eClass_SetProperty");
13207 DeclareFunctionUtil("eInstance_FireSelfWatchers");
13208 DeclareFunctionUtil("eInstance_SetMethod");
13209 DeclareFunctionUtil("eInstance_IncRef");
13210 DeclareFunctionUtil("eInstance_StopWatching");
13211 DeclareFunctionUtil("eInstance_Watch");
13212 DeclareFunctionUtil("eInstance_FireWatchers");
13214 DeclareStruct("ecere::com::Class", false);
13215 DeclareStruct("ecere::com::Instance", false);
13216 DeclareStruct("ecere::com::Property", false);
13217 DeclareStruct("ecere::com::DataMember", false);
13218 DeclareStruct("ecere::com::Method", false);
13219 DeclareStruct("ecere::com::SerialBuffer", false);
13220 DeclareStruct("ecere::com::ClassTemplateArgument", false);
13224 for(external = ast->first; external; external = external.next)
13226 afterExternal = curExternal = external;
13227 if(external.type == functionExternal)
13229 currentClass = external.function._class;
13230 ProcessFunction(external.function);
13232 // There shouldn't be any _class member access here anyways...
13233 else if(external.type == declarationExternal)
13235 currentClass = null;
13236 if(external.declaration)
13237 ProcessDeclaration(external.declaration);
13239 else if(external.type == classExternal)
13241 ClassDefinition _class = external._class;
13242 currentClass = external.symbol.registered;
13243 if(_class.definitions)
13245 ProcessClass(_class.definitions, _class.symbol);
13249 // Free class data...
13250 ast->Remove(external);
13254 else if(external.type == nameSpaceExternal)
13256 thisNameSpace = external.id.string;
13259 currentClass = null;
13260 thisNameSpace = null;
13261 curExternal = null;
13263 delete temp.symbol;