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;
821 if(!type.members.first && type.enumName)
823 Symbol symbol = FindStruct(curContext, type.enumName);
824 if(symbol && symbol.type)
826 ComputeTypeSize(symbol.type);
827 size = symbol.type.size;
833 for(member = type.members.first; member; member = member.next)
835 uint addSize = ComputeTypeSize(member);
837 member.offset = size;
838 if(member.alignment && size % member.alignment)
839 member.offset += member.alignment - (size % member.alignment);
840 size = member.offset;
842 type.alignment = Max(type.alignment, member.alignment);
845 if(type.alignment && size % type.alignment)
846 size += type.alignment - (size % type.alignment);
852 if(!type.members.first && type.enumName)
854 Symbol symbol = FindStruct(curContext, type.enumName);
855 if(symbol && symbol.type)
857 ComputeTypeSize(symbol.type);
858 size = symbol.type.size;
864 for(member = type.members.first; member; member = member.next)
866 uint addSize = ComputeTypeSize(member);
868 member.offset = size;
869 if(member.alignment && size % member.alignment)
870 member.offset += member.alignment - (size % member.alignment);
871 size = member.offset;
873 type.alignment = Max(type.alignment, member.alignment);
874 size = Max(size, addSize);
876 if(type.alignment && size % type.alignment)
877 size += type.alignment - (size % type.alignment);
883 TemplateParameter param = type.templateParameter;
884 Type baseType = ProcessTemplateParameterType(param);
887 size = ComputeTypeSize(baseType);
888 type.alignment = baseType.alignment;
891 type.alignment = size = sizeof(uint64);
896 type.alignment = size = sizeof(enum { test });
901 type.alignment = size = targetBits / 8; //sizeof(void *);
906 type.computing = false;
912 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
914 // This function is in need of a major review when implementing private members etc.
915 DataMember topMember = isMember ? (DataMember) _class : null;
922 Context context = isMember ? null : SetupTemplatesContext(_class);
924 *addedPadding = false;
926 if(!isMember && _class.base)
928 maxSize = _class.structSize;
929 //if(_class.base.type != systemClass) // Commented out with new Instance _class
931 // DANGER: Testing this noHeadClass here...
932 if(_class.type == structClass || _class.type == noHeadClass)
933 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
936 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
937 if(maxSize > baseSize)
945 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
947 if(!member.isProperty)
953 if(member.dataTypeString)
955 OldList * specs = MkList(), * decls = MkList();
958 decl = SpecDeclFromString(member.dataTypeString, specs,
959 MkDeclaratorIdentifier(MkIdentifier(member.name)));
960 ListAdd(decls, MkStructDeclarator(decl, null));
961 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
964 member.dataType = ProcessType(specs, decl);
966 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
969 Type type = ProcessType(specs, decl);
970 DeclareType(member.dataType, false, false);
974 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
975 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
976 DeclareStruct(member.dataType._class.string, false);
979 ComputeTypeSize(member.dataType);
980 size = member.dataType.size;
981 alignment = member.dataType.alignment;
985 if(totalSize % alignment)
986 totalSize += alignment - (totalSize % alignment);
995 OldList * specs = MkList(), * list = MkList();
997 sprintf(id, "__anon%d", anonID++);
1000 AddMembers(list, (Class)member, true, &size, topClass, null);
1002 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
1003 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
1004 alignment = member.structAlignment;
1008 if(totalSize % alignment)
1009 totalSize += alignment - (totalSize % alignment);
1019 if(topMember && topMember.type == unionMember)
1020 *retSize = Max(*retSize, totalSize);
1022 *retSize += totalSize;
1024 else if(totalSize < maxSize && _class.type != systemClass)
1026 int autoPadding = 0;
1027 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1028 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1029 if(totalSize + autoPadding < maxSize)
1031 char sizeString[50];
1032 sprintf(sizeString, "%d", maxSize - totalSize);
1033 ListAdd(declarations,
1034 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1035 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1037 *addedPadding = true;
1041 FinishTemplatesContext(context);
1042 return topMember ? topMember.memberID : _class.memberID;
1045 static int DeclareMembers(Class _class, bool isMember)
1047 DataMember topMember = isMember ? (DataMember) _class : null;
1049 Context context = isMember ? null : SetupTemplatesContext(_class);
1051 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1052 DeclareMembers(_class.base, false);
1054 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1056 if(!member.isProperty)
1063 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1064 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1065 DeclareStruct(member.dataType._class.string, false);
1067 if(!member.dataType && member.dataTypeString)
1068 member.dataType = ProcessTypeString(member.dataTypeString, false);
1070 DeclareType(member.dataType, false, false);
1076 DeclareMembers((Class)member, true);
1083 FinishTemplatesContext(context);
1085 return topMember ? topMember.memberID : _class.memberID;
1088 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1092 for(def = definitions->first; def; def = def.next)
1094 if(def.type == declarationClassDef)
1096 Declaration decl = def.decl;
1097 if(decl && decl.specifiers)
1100 bool isStruct = false;
1101 for(spec = decl.specifiers->first; spec; spec = spec.next)
1103 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1105 if(spec.definitions)
1106 IdentifyAnonStructs(spec.definitions);
1112 Declarator d = null;
1113 if(decl.declarators)
1115 for(d = decl.declarators->first; d; d = d.next)
1117 Identifier idDecl = GetDeclId(d);
1125 sprintf(id, "__anon%d", anonID++);
1126 if(!decl.declarators)
1127 decl.declarators = MkList();
1128 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1136 void DeclareStruct(const char * name, bool skipNoHead)
1138 External external = null;
1139 Symbol classSym = FindClass(name);
1141 if(!inCompiler || !classSym) return;
1143 // We don't need any declaration for bit classes...
1144 if(classSym.registered &&
1145 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1148 /*if(classSym.registered.templateClass)
1149 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1152 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1154 // Add typedef struct
1156 OldList * specifiers, * declarators;
1157 OldList * declarations = null;
1158 char structName[1024];
1159 Specifier spec = null;
1160 external = (classSym.registered && classSym.registered.type == structClass) ?
1161 classSym.pointerExternal : classSym.structExternal;
1163 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1164 // Moved this one up because DeclareClass done later will need it
1166 classSym.declaring++;
1168 if(strchr(classSym.string, '<'))
1170 if(classSym.registered.templateClass)
1172 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1173 classSym.declaring--;
1179 DeclareMembers(classSym.registered, false);
1182 FullClassNameCat(structName, name, false);
1184 if(external && external.declaration && external.declaration.specifiers)
1186 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1188 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1194 external = MkExternalDeclaration(null);*/
1196 if(!skipNoHead && (!spec || !spec.definitions))
1198 bool addedPadding = false;
1199 classSym.declaredStructSym = true;
1201 declarations = MkList();
1203 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1205 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1206 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1208 if(!declarations->count || (declarations->count == 1 && addedPadding))
1210 FreeList(declarations, FreeClassDef);
1211 declarations = null;
1214 if(skipNoHead || declarations)
1219 spec.definitions = declarations;
1221 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1224 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1227 if(classSym.structExternal)
1228 ast->Move(classSym.structExternal, curExternal.prev);
1229 ast->Move(classSym.pointerExternal, curExternal.prev);
1231 classSym.id = curExternal.symbol.idCode;
1232 classSym.idCode = curExternal.symbol.idCode;
1233 // external = classSym.pointerExternal;
1234 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1240 external = MkExternalDeclaration(null);
1242 specifiers = MkList();
1243 declarators = MkList();
1244 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1247 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1248 ListAdd(declarators, MkInitDeclarator(d, null));
1250 external.declaration = decl = MkDeclaration(specifiers, declarators);
1251 if(decl.symbol && !decl.symbol.pointerExternal)
1252 decl.symbol.pointerExternal = external;
1254 // For simple classes, keep the declaration as the external to move around
1255 if(classSym.registered && classSym.registered.type == structClass)
1257 char className[1024];
1258 strcpy(className, "__ecereClass_");
1259 FullClassNameCat(className, classSym.string, true);
1260 //MangleClassName(className);
1263 DeclareClass(classSym, className);
1265 external.symbol = classSym;
1266 classSym.pointerExternal = external;
1267 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1268 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1272 char className[1024];
1273 strcpy(className, "__ecereClass_");
1274 FullClassNameCat(className, classSym.string, true);
1275 //MangleClassName(className);
1277 // TOFIX: TESTING THIS...
1278 classSym.structExternal = external;
1279 DeclareClass(classSym, className);
1280 external.symbol = classSym;
1284 ast->Insert(curExternal ? curExternal.prev : null, external);
1288 classSym.declaring--;
1292 if(classSym.structExternal && classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1295 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1297 IdentifyAnonStructs(spec.definitions);
1301 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1303 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1304 // Moved this one up because DeclareClass done later will need it
1307 classSym.declaring++;
1311 if(classSym.registered)
1312 DeclareMembers(classSym.registered, false);
1315 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1318 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1321 if(classSym.structExternal)
1322 ast->Move(classSym.structExternal, curExternal.prev);
1323 ast->Move(classSym.pointerExternal, curExternal.prev);
1325 classSym.id = curExternal.symbol.idCode;
1326 classSym.idCode = curExternal.symbol.idCode;
1327 // external = classSym.pointerExternal;
1328 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1331 classSym.declaring--;
1337 void DeclareProperty(Property prop, char * setName, char * getName)
1339 Symbol symbol = prop.symbol;
1341 strcpy(setName, "__ecereProp_");
1342 FullClassNameCat(setName, prop._class.fullName, false);
1343 strcat(setName, "_Set_");
1344 // strcat(setName, prop.name);
1345 FullClassNameCat(setName, prop.name, true);
1346 //MangleClassName(setName);
1348 strcpy(getName, "__ecereProp_");
1349 FullClassNameCat(getName, prop._class.fullName, false);
1350 strcat(getName, "_Get_");
1351 FullClassNameCat(getName, prop.name, true);
1352 // strcat(getName, prop.name);
1354 // To support "char *" property
1355 //MangleClassName(getName);
1357 if(prop._class.type == structClass)
1358 DeclareStruct(prop._class.fullName, false);
1360 if(!symbol || curExternal.symbol.idCode < symbol.id)
1362 bool imported = false;
1363 bool dllImport = false;
1365 if(!symbol || symbol._import)
1370 if(!prop._class.symbol)
1371 prop._class.symbol = FindClass(prop._class.fullName);
1372 classSym = prop._class.symbol;
1373 if(classSym && !classSym._import)
1375 ModuleImport module;
1377 if(prop._class.module)
1378 module = FindModule(prop._class.module);
1380 module = mainModule;
1382 classSym._import = ClassImport
1384 name = CopyString(prop._class.fullName);
1385 isRemote = prop._class.isRemote;
1387 module.classes.Add(classSym._import);
1389 symbol = prop.symbol = Symbol { };
1390 symbol._import = (ClassImport)PropertyImport
1392 name = CopyString(prop.name);
1393 isVirtual = false; //prop.isVirtual;
1394 hasSet = prop.Set ? true : false;
1395 hasGet = prop.Get ? true : false;
1398 classSym._import.properties.Add(symbol._import);
1401 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1402 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1403 prop._class.module.importType != staticImport)
1409 Context context = SetupTemplatesContext(prop._class);
1410 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1411 FinishTemplatesContext(context);
1417 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1420 OldList * specifiers, * declarators;
1425 Declarator typeDecl;
1426 bool simple = false;
1428 specifiers = MkList();
1429 declarators = MkList();
1432 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1433 MkDeclaratorIdentifier(MkIdentifier("this"))));
1435 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1438 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1441 Context context = SetupTemplatesContext(prop._class);
1442 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1443 FinishTemplatesContext(context);
1446 // Make sure the simple _class's type is declared
1447 for(spec = specifiers->first; spec; spec = spec.next)
1449 if(spec.type == nameSpecifier /*SpecifierClass*/)
1451 if((!typeDecl || typeDecl.type == identifierDeclarator))
1453 Symbol classSym = spec.symbol; // FindClass(spec.name);
1454 symbol._class = classSym.registered;
1455 if(classSym.registered && classSym.registered.type == structClass)
1457 DeclareStruct(spec.name, false);
1465 d = PlugDeclarator(typeDecl, d);
1468 ListAdd(params, MkTypeName(specifiers,
1469 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1470 specifiers = MkList();
1473 d = MkDeclaratorFunction(d, params);
1477 specifiers->Insert(null, MkSpecifier(EXTERN));
1478 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1479 specifiers->Insert(null, MkSpecifier(STATIC));
1481 ListAdd(specifiers, MkSpecifier(VOID));
1483 ListAdd(declarators, MkInitDeclarator(d, null));
1485 decl = MkDeclaration(specifiers, declarators);
1487 external = MkExternalDeclaration(decl);
1488 ast->Insert(curExternal.prev, external);
1489 external.symbol = symbol;
1490 symbol.externalGet = external;
1492 ReplaceThisClassSpecifiers(specifiers, prop._class);
1495 FreeDeclarator(typeDecl);
1499 // Move declaration higher...
1500 ast->Move(symbol.externalGet, curExternal.prev);
1507 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1510 OldList * specifiers, * declarators;
1515 Declarator typeDecl;
1517 declarators = MkList();
1520 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1521 if(!prop.conversion || prop._class.type == structClass)
1523 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1524 MkDeclaratorIdentifier(MkIdentifier("this"))));
1527 specifiers = MkList();
1530 Context context = SetupTemplatesContext(prop._class);
1531 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1532 MkDeclaratorIdentifier(MkIdentifier("value")));
1533 FinishTemplatesContext(context);
1535 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1536 specifiers->Insert(null, MkSpecifier(CONST));
1538 ListAdd(params, MkTypeName(specifiers, d));
1540 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1543 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1544 d = MkDeclaratorFunction(d, params);
1546 // Make sure the simple _class's type is declared
1547 for(spec = specifiers->first; spec; spec = spec.next)
1549 if(spec.type == nameSpecifier /*SpecifierClass*/)
1551 if((!typeDecl || typeDecl.type == identifierDeclarator))
1553 Symbol classSym = spec.symbol; // FindClass(spec.name);
1554 symbol._class = classSym.registered;
1555 if(classSym.registered && classSym.registered.type == structClass)
1556 DeclareStruct(spec.name, false);
1561 ListAdd(declarators, MkInitDeclarator(d, null));
1563 specifiers = MkList();
1566 specifiers->Insert(null, MkSpecifier(EXTERN));
1567 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1568 specifiers->Insert(null, MkSpecifier(STATIC));
1570 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1571 if(!prop.conversion || prop._class.type == structClass)
1572 ListAdd(specifiers, MkSpecifier(VOID));
1574 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1576 decl = MkDeclaration(specifiers, declarators);
1578 external = MkExternalDeclaration(decl);
1579 ast->Insert(curExternal.prev, external);
1580 external.symbol = symbol;
1581 symbol.externalSet = external;
1583 ReplaceThisClassSpecifiers(specifiers, prop._class);
1587 // Move declaration higher...
1588 ast->Move(symbol.externalSet, curExternal.prev);
1592 // Property (for Watchers)
1593 if(!symbol.externalPtr)
1597 OldList * specifiers = MkList();
1598 char propName[1024];
1601 specifiers->Insert(null, MkSpecifier(EXTERN));
1604 specifiers->Insert(null, MkSpecifier(STATIC));
1605 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
1608 ListAdd(specifiers, MkSpecifierName("Property"));
1610 strcpy(propName, "__ecereProp_");
1611 FullClassNameCat(propName, prop._class.fullName, false);
1612 strcat(propName, "_");
1613 FullClassNameCat(propName, prop.name, true);
1614 // strcat(propName, prop.name);
1615 //MangleClassName(propName);
1618 OldList * list = MkList();
1619 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1623 strcpy(propName, "__ecerePropM_");
1624 FullClassNameCat(propName, prop._class.fullName, false);
1625 strcat(propName, "_");
1626 // strcat(propName, prop.name);
1627 FullClassNameCat(propName, prop.name, true);
1629 //MangleClassName(propName);
1631 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1633 decl = MkDeclaration(specifiers, list);
1636 external = MkExternalDeclaration(decl);
1637 ast->Insert(curExternal.prev, external);
1638 external.symbol = symbol;
1639 symbol.externalPtr = external;
1643 // Move declaration higher...
1644 ast->Move(symbol.externalPtr, curExternal.prev);
1647 symbol.id = curExternal.symbol.idCode;
1651 // ***************** EXPRESSION PROCESSING ***************************
1652 public Type Dereference(Type source)
1657 if(source.kind == pointerType || source.kind == arrayType)
1660 source.type.refCount++;
1662 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1670 // Support dereferencing of no head classes for now...
1671 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1677 Compiler_Error($"cannot dereference type\n");
1682 static Type Reference(Type source)
1698 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1700 Identifier ident = member.identifiers ? member.identifiers->first : null;
1702 DataMember dataMember = null;
1703 Method method = null;
1704 bool freeType = false;
1706 yylloc = member.loc;
1712 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1716 dataMember = *curMember;
1722 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1723 DataMember _subMemberStack[256];
1724 int _subMemberStackPos = 0;
1726 // FILL MEMBER STACK
1728 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1731 dataMember = thisMember;
1732 if(curMember && thisMember.memberAccess == publicAccess)
1734 *curMember = thisMember;
1735 *curClass = thisMember._class;
1736 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1737 *subMemberStackPos = _subMemberStackPos;
1744 method = eClass_FindMethod(_class, ident.string, privateModule);
1745 if(method && method.type == virtualMethod)
1757 if(!dataMember.dataType && dataMember.dataTypeString)
1759 //Context context = SetupTemplatesContext(dataMember._class);
1760 Context context = SetupTemplatesContext(_class);
1761 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1762 FinishTemplatesContext(context);
1764 type = dataMember.dataType;
1768 // This is for destination type...
1769 if(!method.dataType)
1770 ProcessMethodType(method);
1771 //DeclareMethod(method);
1772 // method.dataType = ((Symbol)method.symbol)->type;
1773 type = method.dataType;
1776 if(ident && ident.next)
1778 for(ident = ident.next; ident && type; ident = ident.next)
1780 if(type.kind == classType)
1782 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1784 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1786 type = dataMember.dataType;
1788 else if(type.kind == structType || type.kind == unionType)
1791 for(memberType = type.members.first; memberType; memberType = memberType.next)
1793 if(!strcmp(memberType.name, ident.string))
1803 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1804 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1807 ClassTemplateParameter curParam = null;
1809 for(sClass = _class; sClass; sClass = sClass.base)
1812 if(sClass.templateClass) sClass = sClass.templateClass;
1813 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1815 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1817 for(sClass = sClass.base; sClass; sClass = sClass.base)
1819 if(sClass.templateClass) sClass = sClass.templateClass;
1820 id += sClass.templateParams.count;
1831 ClassTemplateArgument arg = _class.templateArgs[id];
1832 if(arg.dataTypeString)
1834 bool constant = type.constant;
1836 type = ProcessTypeString(arg.dataTypeString, false);
1837 if(type.kind == classType && constant) type.constant = true;
1838 else if(type.kind == pointerType)
1841 while(t.kind == pointerType) t = t.type;
1842 if(constant) t.constant = constant;
1845 if(type && _class.templateClass)
1846 type.passAsTemplate = true;
1852 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1853 exp.destType.refCount++;
1859 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1861 Class expClass = type._class.registered;
1862 Class cClass = null;
1866 char templateString[1024];
1867 ClassTemplateParameter param;
1868 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1869 for(cClass = expClass; cClass; cClass = cClass.base)
1872 if(cClass.templateClass) cClass = cClass.templateClass;
1873 for(param = cClass.templateParams.first; param; param = param.next)
1877 ClassTemplateArgument arg;
1878 for(sClass = cClass.base; sClass; sClass = sClass.base)
1880 if(sClass.templateClass) sClass = sClass.templateClass;
1881 id += sClass.templateParams.count;
1883 arg = expClass.templateArgs[id];
1885 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1887 ClassTemplateParameter cParam;
1888 //int p = numParams - sClass.templateParams.count;
1891 if(sClass.templateClass) sClass = sClass.templateClass;
1893 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1895 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1896 p += nextClass.templateParams.count;
1899 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1901 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1903 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1905 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1906 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1918 strcat(argument, arg.name.string);
1919 strcat(argument, " = ");
1925 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1926 char expString[1024];
1927 OldList * specs = MkList();
1928 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1930 char * string = PrintHexUInt64(arg.expression.ui64);
1931 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1934 ProcessExpressionType(exp);
1935 ComputeExpression(exp);
1936 expString[0] = '\0';
1937 PrintExpression(exp, expString);
1938 strcat(argument, expString);
1940 FreeExpression(exp);
1945 strcat(argument, arg.member.name);
1948 case TemplateParameterType::type:
1950 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1951 strcat(argument, arg.dataTypeString);
1957 if(paramCount) strcat(templateString, ", ");
1958 if(lastParam != p - 1)
1960 strcat(templateString, param.name);
1961 strcat(templateString, " = ");
1963 strcat(templateString, argument);
1972 int len = strlen(templateString);
1973 if(templateString[len-1] == '<')
1977 if(templateString[len-1] == '>')
1978 templateString[len++] = ' ';
1979 templateString[len++] = '>';
1981 templateString[len++] = '\0';
1984 Context context = SetupTemplatesContext(_class);
1985 if(freeType) FreeType(type);
1986 type = ProcessTypeString(templateString, false);
1988 FinishTemplatesContext(context);
1992 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1994 ProcessExpressionType(member.initializer.exp);
1995 if(!member.initializer.exp.expType)
1999 char expString[10240];
2000 expString[0] = '\0';
2001 PrintExpression(member.initializer.exp, expString);
2002 ChangeCh(expString, '\n', ' ');
2003 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
2006 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
2007 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
2009 Compiler_Error($"incompatible instance method %s\n", ident.string);
2012 else if(member.initializer)
2015 FreeType(member.exp.destType);
2016 member.exp.destType = type;
2017 if(member.exp.destType)
2018 member.exp.destType.refCount++;
2019 ProcessExpressionType(member.exp);
2022 ProcessInitializer(member.initializer, type);
2024 if(freeType) FreeType(type);
2028 if(_class && _class.type == unitClass)
2030 if(member.initializer)
2033 FreeType(member.exp.destType);
2034 member.exp.destType = MkClassType(_class.fullName);
2035 ProcessExpressionType(member.initializer, type);
2037 Type type = MkClassType(_class.fullName);
2038 ProcessInitializer(member.initializer, type);
2044 if(member.initializer)
2046 //ProcessExpressionType(member.exp);
2047 ProcessInitializer(member.initializer, null);
2053 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2057 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2059 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2063 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2068 void ProcessInstantiationType(Instantiation inst)
2073 MembersInit members;
2074 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
2077 /*if(!inst._class.symbol)
2078 inst._class.symbol = FindClass(inst._class.name);*/
2079 classSym = inst._class.symbol;
2080 _class = classSym ? classSym.registered : null;
2082 // DANGER: Patch for mutex not declaring its struct when not needed
2083 if(!_class || _class.type != noHeadClass)
2084 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
2086 afterExternal = afterExternal ? afterExternal : curExternal;
2089 ProcessExpressionType(inst.exp);
2091 inst.isConstant = true;
2094 DataMember curMember = null;
2095 Class curClass = null;
2096 DataMember subMemberStack[256];
2097 int subMemberStackPos = 0;
2099 for(members = inst.members->first; members; members = members.next)
2101 switch(members.type)
2103 case methodMembersInit:
2106 static uint instMethodID = 0;
2107 External external = curExternal;
2108 Context context = curContext;
2109 Declarator declarator = members.function.declarator;
2110 Identifier nameID = GetDeclId(declarator);
2111 char * unmangled = nameID ? nameID.string : null;
2113 External createdExternal = null;
2118 //members.function.dontMangle = true;
2119 strcpy(name, "__ecereInstMeth_");
2120 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2122 strcat(name, nameID.string);
2124 sprintf(number, "_%08d", instMethodID++);
2125 strcat(name, number);
2126 nameID.string = CopyString(name);
2129 // Do modifications here...
2132 Symbol symbol = declarator.symbol;
2133 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2135 if(method && method.type == virtualMethod)
2137 symbol.method = method;
2138 ProcessMethodType(method);
2140 if(!symbol.type.thisClass)
2142 if(method.dataType.thisClass && currentClass &&
2143 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2145 if(!currentClass.symbol)
2146 currentClass.symbol = FindClass(currentClass.fullName);
2147 symbol.type.thisClass = currentClass.symbol;
2152 _class.symbol = FindClass(_class.fullName);
2153 symbol.type.thisClass = _class.symbol;
2156 // TESTING THIS HERE:
2157 DeclareType(symbol.type, true, true);
2162 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2163 unmangled, classSym.string);
2167 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2168 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2172 FreeSpecifier(nameID._class);
2173 nameID._class = null;
2178 //Type type = declarator.symbol.type;
2179 External oldExternal = curExternal;
2181 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2182 // *** It was commented out for problems such as
2184 class VirtualDesktop : Window
2186 clientSize = Size { };
2197 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2199 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2202 if(strcmp(declarator.symbol.string, name))
2204 printf("TOCHECK: Look out for this\n");
2205 delete declarator.symbol.string;
2206 declarator.symbol.string = CopyString(name);
2209 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2211 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2212 excludedSymbols->Remove(declarator.symbol);
2213 globalContext.symbols.Add((BTNode)declarator.symbol);
2214 if(strstr(declarator.symbol.string), "::")
2215 globalContext.hasNameSpace = true;
2220 //curExternal = curExternal.prev;
2221 //afterExternal = afterExternal->next;
2223 //ProcessFunction(afterExternal->function);
2225 //curExternal = afterExternal;
2227 External externalDecl;
2228 externalDecl = MkExternalDeclaration(null);
2229 ast->Insert(oldExternal.prev, externalDecl);
2231 // Which function does this process?
2232 if(createdExternal.function)
2234 ProcessFunction(createdExternal.function);
2236 //curExternal = oldExternal;
2239 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2241 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2242 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2244 //externalDecl = MkExternalDeclaration(decl);
2246 //***** ast->Insert(external.prev, externalDecl);
2247 //ast->Insert(curExternal.prev, externalDecl);
2248 externalDecl.declaration = decl;
2249 if(decl.symbol && !decl.symbol.pointerExternal)
2250 decl.symbol.pointerExternal = externalDecl;
2252 // Trying this out...
2253 declarator.symbol.pointerExternal = externalDecl;
2260 curExternal = declarator.symbol.pointerExternal;
2261 ProcessFunction((FunctionDefinition)members.function);
2263 curExternal = external;
2264 curContext = context;
2268 FreeClassFunction(members.function);
2270 // In this pass, turn this into a MemberInitData
2271 exp = QMkExpId(name);
2272 members.type = dataMembersInit;
2273 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2279 case dataMembersInit:
2281 if(members.dataMembers && classSym)
2284 Location oldyyloc = yylloc;
2285 for(member = members.dataMembers->first; member; member = member.next)
2287 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2288 if(member.initializer && !member.initializer.isConstant)
2289 inst.isConstant = false;
2301 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2303 // OPTIMIZATIONS: TESTING THIS...
2306 if(type.kind == functionType)
2311 for(param = type.params.first; param; param = param.next)
2312 DeclareType(param, declarePointers, true);
2314 DeclareType(type.returnType, declarePointers, true);
2316 else if(type.kind == pointerType && declarePointers)
2317 DeclareType(type.type, declarePointers, false);
2318 else if(type.kind == classType)
2320 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2321 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2323 else if(type.kind == structType || type.kind == unionType)
2326 for(member = type.members.first; member; member = member.next)
2327 DeclareType(member, false, false);
2329 else if(type.kind == arrayType)
2330 DeclareType(type.arrayType, declarePointers, false);
2334 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2336 ClassTemplateArgument * arg = null;
2338 ClassTemplateParameter curParam = null;
2340 for(sClass = _class; sClass; sClass = sClass.base)
2343 if(sClass.templateClass) sClass = sClass.templateClass;
2344 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2346 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2348 for(sClass = sClass.base; sClass; sClass = sClass.base)
2350 if(sClass.templateClass) sClass = sClass.templateClass;
2351 id += sClass.templateParams.count;
2361 arg = &_class.templateArgs[id];
2362 if(arg && param.type == type)
2363 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2368 public Context SetupTemplatesContext(Class _class)
2370 Context context = PushContext();
2371 context.templateTypesOnly = true;
2372 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2374 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2375 for(; param; param = param.next)
2377 if(param.type == type && param.identifier)
2379 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2380 curContext.templateTypes.Add((BTNode)type);
2387 for(sClass = _class; sClass; sClass = sClass.base)
2389 ClassTemplateParameter p;
2390 for(p = sClass.templateParams.first; p; p = p.next)
2392 //OldList * specs = MkList();
2393 //Declarator decl = null;
2394 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2397 TemplateParameter param = p.param;
2401 // ADD DATA TYPE HERE...
2402 p.param = param = TemplateParameter
2404 identifier = MkIdentifier(p.name), type = p.type,
2405 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2408 type = TemplatedType { key = (uintptr)p.name, param = param };
2409 curContext.templateTypes.Add((BTNode)type);
2417 public void FinishTemplatesContext(Context context)
2419 PopContext(context);
2420 FreeContext(context);
2424 public void ProcessMethodType(Method method)
2426 if(!method.dataType)
2428 Context context = SetupTemplatesContext(method._class);
2430 method.dataType = ProcessTypeString(method.dataTypeString, false);
2432 FinishTemplatesContext(context);
2434 if(method.type != virtualMethod && method.dataType)
2436 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2438 if(!method._class.symbol)
2439 method._class.symbol = FindClass(method._class.fullName);
2440 method.dataType.thisClass = method._class.symbol;
2444 // Why was this commented out? Working fine without now...
2447 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2448 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2455 char * par = strstr(type, "(");
2456 char * classOp = null;
2461 for(c = par-type-1; c >= 0; c++)
2463 if(type[c] == ':' && type[c+1] == ':')
2465 classOp = type + c - 1;
2466 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2473 else if(!isspace(type[c]))
2480 int typeLen = strlen(type);
2481 memcpy(temp, classOp, classOpLen);
2482 temp[classOpLen] = '\0';
2484 _class = eSystem_FindClass(module, temp);
2487 method.dataTypeString = new char[typeLen - classOpLen + 1];
2488 memcpy(method.dataTypeString, type, classOp - type);
2489 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2492 method.dataTypeString = type;
2498 public void ProcessPropertyType(Property prop)
2502 Context context = SetupTemplatesContext(prop._class);
2503 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2504 FinishTemplatesContext(context);
2508 public void DeclareMethod(Method method, const char * name)
2510 Symbol symbol = method.symbol;
2511 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2513 //bool imported = false;
2514 bool dllImport = false;
2516 if(!method.dataType)
2517 method.dataType = ProcessTypeString(method.dataTypeString, false);
2519 if(!symbol || symbol._import || method.type == virtualMethod)
2521 if(!symbol || method.type == virtualMethod)
2524 if(!method._class.symbol)
2525 method._class.symbol = FindClass(method._class.fullName);
2526 classSym = method._class.symbol;
2527 if(!classSym._import)
2529 ModuleImport module;
2531 if(method._class.module && method._class.module.name)
2532 module = FindModule(method._class.module);
2534 module = mainModule;
2535 classSym._import = ClassImport
2537 name = CopyString(method._class.fullName);
2538 isRemote = method._class.isRemote;
2540 module.classes.Add(classSym._import);
2544 symbol = method.symbol = Symbol { };
2548 symbol._import = (ClassImport)MethodImport
2550 name = CopyString(method.name);
2551 isVirtual = method.type == virtualMethod;
2553 classSym._import.methods.Add(symbol._import);
2557 // Set the symbol type
2561 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2563 else if(type.thisClass == (void *)-1)
2565 type.thisClass = null;
2568 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2569 symbol.type = method.dataType;
2570 if(symbol.type) symbol.type.refCount++;
2573 if(!method.thisClass || strcmp(method.thisClass, "void"))
2574 symbol.type.params.Insert(null,
2575 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2578 if(!method.dataType.dllExport)
2581 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2587 if(!method.dataType)
2588 method.dataType = ((Symbol)method.symbol).type;
2589 //ProcessMethodType(method);
2592 if(method.type != virtualMethod && method.dataType)
2593 DeclareType(method.dataType, true, true);
2595 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2597 // We need a declaration here :)
2599 OldList * specifiers, * declarators;
2601 Declarator funcDecl;
2604 specifiers = MkList();
2605 declarators = MkList();
2609 ListAdd(specifiers, MkSpecifier(EXTERN));
2610 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2611 ListAdd(specifiers, MkSpecifier(STATIC));
2613 if(method.type == virtualMethod)
2615 ListAdd(specifiers, MkSpecifier(INT));
2616 d = MkDeclaratorIdentifier(MkIdentifier(name));
2620 d = MkDeclaratorIdentifier(MkIdentifier(name));
2623 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2625 Context context = SetupTemplatesContext(method._class);
2626 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2627 FinishTemplatesContext(context);
2629 funcDecl = GetFuncDecl(d);
2633 Specifier spec, next;
2634 for(spec = specifiers->first; spec; spec = next)
2637 if(spec.type == extendedSpecifier)
2639 specifiers->Remove(spec);
2640 FreeSpecifier(spec);
2645 // Add this parameter if not a static method
2646 if(method.dataType && !method.dataType.staticMethod)
2648 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2650 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2651 TypeName thisParam = MkTypeName(MkListOne(
2652 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2653 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2654 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2655 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2657 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2659 TypeName param = funcDecl.function.parameters->first;
2660 funcDecl.function.parameters->Remove(param);
2661 FreeTypeName(param);
2664 if(!funcDecl.function.parameters)
2665 funcDecl.function.parameters = MkList();
2666 funcDecl.function.parameters->Insert(null, thisParam);
2669 // Make sure we don't have empty parameter declarations for static methods...
2671 else if(!funcDecl.function.parameters)
2673 funcDecl.function.parameters = MkList();
2674 funcDecl.function.parameters->Insert(null,
2675 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2679 ProcessDeclarator(d);
2681 ListAdd(declarators, MkInitDeclarator(d, null));
2683 decl = MkDeclaration(specifiers, declarators);
2685 ReplaceThisClassSpecifiers(specifiers, method._class);
2687 // Keep a different symbol for the function definition than the declaration...
2688 if(symbol.pointerExternal)
2690 Symbol functionSymbol { };
2694 *functionSymbol = *symbol;
2695 functionSymbol.string = CopyString(symbol.string);
2696 if(functionSymbol.type)
2697 functionSymbol.type.refCount++;
2700 excludedSymbols->Add(functionSymbol);
2701 symbol.pointerExternal.symbol = functionSymbol;
2703 external = MkExternalDeclaration(decl);
2705 ast->Insert(curExternal ? curExternal.prev : null, external);
2706 external.symbol = symbol;
2707 symbol.pointerExternal = external;
2711 // Move declaration higher...
2712 ast->Move(symbol.pointerExternal, curExternal.prev);
2715 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2719 char * ReplaceThisClass(Class _class)
2721 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2725 ClassTemplateParameter param;
2728 char className[1024];
2729 strcpy(className, _class.fullName);
2730 for(param = _class.templateParams.first; param; param = param.next)
2732 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2734 if(first) strcat(className, "<");
2735 if(!first) strcat(className, ", ");
2736 if(lastParam + 1 != p)
2738 strcat(className, param.name);
2739 strcat(className, " = ");
2741 strcat(className, param.name);
2749 int len = strlen(className);
2750 if(className[len-1] == '>') className[len++] = ' ';
2751 className[len++] = '>';
2752 className[len++] = '\0';
2754 return CopyString(className);
2757 return CopyString(_class.fullName);
2760 Type ReplaceThisClassType(Class _class)
2763 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2767 ClassTemplateParameter param;
2769 char className[1024];
2770 strcpy(className, _class.fullName);
2772 for(param = _class.templateParams.first; param; param = param.next)
2774 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2776 if(first) strcat(className, "<");
2777 if(!first) strcat(className, ", ");
2778 if(lastParam + 1 != p)
2780 strcat(className, param.name);
2781 strcat(className, " = ");
2783 strcat(className, param.name);
2791 int len = strlen(className);
2792 if(className[len-1] == '>') className[len++] = ' ';
2793 className[len++] = '>';
2794 className[len++] = '\0';
2796 type = MkClassType(className);
2797 //type = ProcessTypeString(className, false);
2801 type = MkClassType(_class.fullName);
2802 //type = ProcessTypeString(_class.fullName, false);
2804 //type.wasThisClass = true;
2808 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2810 if(specs != null && _class)
2813 for(spec = specs.first; spec; spec = spec.next)
2815 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2817 spec.type = nameSpecifier;
2818 spec.name = ReplaceThisClass(_class);
2819 spec.symbol = FindClass(spec.name); //_class.symbol;
2825 // Returns imported or not
2826 bool DeclareFunction(GlobalFunction function, char * name)
2828 Symbol symbol = function.symbol;
2829 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2831 bool imported = false;
2832 bool dllImport = false;
2834 if(!function.dataType)
2836 function.dataType = ProcessTypeString(function.dataTypeString, false);
2837 if(!function.dataType.thisClass)
2838 function.dataType.staticMethod = true;
2845 ModuleImport module = FindModule(function.module);
2846 // WARNING: This is not added anywhere...
2847 symbol = function.symbol = Symbol { };
2851 if(!function.dataType.dllExport)
2853 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2854 module.functions.Add(symbol._import);
2857 // Set the symbol type
2859 symbol.type = ProcessTypeString(function.dataTypeString, false);
2860 if(!symbol.type.thisClass)
2861 symbol.type.staticMethod = true;
2864 imported = symbol._import ? true : false;
2865 if(imported && function.module != privateModule && function.module.importType != staticImport)
2869 DeclareType(function.dataType, true, true);
2873 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2875 // We need a declaration here :)
2877 OldList * specifiers, * declarators;
2879 Declarator funcDecl;
2882 specifiers = MkList();
2883 declarators = MkList();
2886 ListAdd(specifiers, MkSpecifier(EXTERN));
2889 ListAdd(specifiers, MkSpecifier(STATIC));
2892 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2895 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2897 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2898 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2899 if(function.module.importType == staticImport)
2902 for(spec = specifiers->first; spec; spec = spec.next)
2903 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2905 specifiers->Remove(spec);
2906 FreeSpecifier(spec);
2911 funcDecl = GetFuncDecl(d);
2913 // Make sure we don't have empty parameter declarations for static methods...
2914 if(funcDecl && !funcDecl.function.parameters)
2916 funcDecl.function.parameters = MkList();
2917 funcDecl.function.parameters->Insert(null,
2918 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2921 ListAdd(declarators, MkInitDeclarator(d, null));
2924 Context oldCtx = curContext;
2925 curContext = globalContext;
2926 decl = MkDeclaration(specifiers, declarators);
2927 curContext = oldCtx;
2930 // Keep a different symbol for the function definition than the declaration...
2931 if(symbol.pointerExternal)
2933 Symbol functionSymbol { };
2936 *functionSymbol = *symbol;
2937 functionSymbol.string = CopyString(symbol.string);
2938 if(functionSymbol.type)
2939 functionSymbol.type.refCount++;
2942 excludedSymbols->Add(functionSymbol);
2944 symbol.pointerExternal.symbol = functionSymbol;
2946 external = MkExternalDeclaration(decl);
2948 ast->Insert(curExternal.prev, external);
2949 external.symbol = symbol;
2950 symbol.pointerExternal = external;
2954 // Move declaration higher...
2955 ast->Move(symbol.pointerExternal, curExternal.prev);
2959 symbol.id = curExternal.symbol.idCode;
2962 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2965 void DeclareGlobalData(GlobalData data)
2967 Symbol symbol = data.symbol;
2968 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2973 symbol = data.symbol = Symbol { };
2976 data.dataType = ProcessTypeString(data.dataTypeString, false);
2977 DeclareType(data.dataType, true, true);
2980 if(!symbol.pointerExternal)
2982 // We need a declaration here :)
2984 OldList * specifiers, * declarators;
2988 specifiers = MkList();
2989 declarators = MkList();
2991 ListAdd(specifiers, MkSpecifier(EXTERN));
2992 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2993 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2995 ListAdd(declarators, MkInitDeclarator(d, null));
2997 decl = MkDeclaration(specifiers, declarators);
2998 external = MkExternalDeclaration(decl);
3000 ast->Insert(curExternal.prev, external);
3001 external.symbol = symbol;
3002 symbol.pointerExternal = external;
3006 // Move declaration higher...
3007 ast->Move(symbol.pointerExternal, curExternal.prev);
3011 symbol.id = curExternal.symbol.idCode;
3016 class Conversion : struct
3018 Conversion prev, next;
3024 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
3027 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
3028 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
3030 Class sourceClass = source.kind == classType ? source._class.registered : null;
3031 Class destClass = dest.kind == classType ? dest._class.registered : null;
3032 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
3033 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
3035 Type sourceType = source, destType = dest;
3036 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
3037 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
3038 if(!destType.constant && sourceType.constant)
3042 Compiler_Warning($"discarding const qualifier\n");
3049 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
3050 bool isConversionExploration, bool warnConst)
3055 CheckConstCompatibility(source, dest, true);
3056 // Property convert;
3058 if(source.kind == templateType && dest.kind != templateType)
3060 Type type = ProcessTemplateParameterType(source.templateParameter);
3061 if(type) source = type;
3064 if(dest.kind == templateType && source.kind != templateType)
3066 Type type = ProcessTemplateParameterType(dest.templateParameter);
3067 if(type) dest = type;
3070 if(dest.classObjectType == typedObject && dest.kind != functionType)
3072 if(source.classObjectType != anyObject)
3076 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
3077 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
3085 if(source.kind != functionType && source.classObjectType == anyObject)
3087 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
3091 if((dest.kind == structType && source.kind == structType) ||
3092 (dest.kind == unionType && source.kind == unionType))
3094 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
3095 (source.members.first && source.members.first == dest.members.first))
3099 if(dest.kind == ellipsisType && source.kind != voidType)
3102 if(dest.kind == pointerType && dest.type.kind == voidType &&
3103 ((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))
3104 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
3106 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
3108 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
3110 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
3111 ((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))
3112 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
3113 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
3115 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
3118 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
3120 if(source._class.registered && source._class.registered.type == unitClass)
3122 if(conversions != null)
3124 if(source._class.registered == dest._class.registered)
3129 Class sourceBase, destBase;
3130 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
3131 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
3132 if(sourceBase == destBase)
3136 // Don't match enum inheriting from other enum if resolving enumeration values
3137 // TESTING: !dest.classObjectType
3138 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3140 (!source._class.registered || source._class.registered.type != enumClass) ||
3141 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3145 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3147 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3148 ((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)
3150 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3158 // JUST ADDED THIS...
3159 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3164 // Just added this for Straight conversion of ColorAlpha => Color
3165 if(source.kind == classType)
3168 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3171 for(convert = _class.conversions.first; convert; convert = convert.next)
3173 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3175 Conversion after = (conversions != null) ? conversions.last : null;
3177 if(!convert.dataType)
3178 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3179 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3180 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3181 MatchTypes(convert.dataType, dest, conversions, null, null,
3182 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3183 convert.dataType.kind == classType, false, true, warnConst))
3185 if(!conversions && !convert.Get)
3187 else if(conversions != null)
3189 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3190 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3191 (dest.kind != classType || dest._class.registered != _class.base))
3195 Conversion conv { convert = convert, isGet = true };
3196 // conversions.Add(conv);
3197 conversions.Insert(after, conv);
3210 if(dest.kind == classType)
3213 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3216 for(convert = _class.conversions.first; convert; convert = convert.next)
3218 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3220 Type constType = null;
3221 bool success = false;
3222 // Conversion after = (conversions != null) ? conversions.last : null;
3224 if(!convert.dataType)
3225 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3227 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3230 constType = { kind = pointerType, refCount = 1, type = ptrType };
3231 CopyTypeInto(ptrType, convert.dataType.type);
3232 ptrType.constant = true;
3235 // Just added this equality check to prevent recursion.... Make it safer?
3236 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3237 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3239 if(!conversions && !convert.Set)
3241 else if(conversions != null)
3243 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3244 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3245 (source.kind != classType || source._class.registered != _class.base))
3249 // *** Testing this! ***
3250 Conversion conv { convert = convert };
3251 conversions.Add(conv);
3252 //conversions.Insert(after, conv);
3258 FreeType(constType);
3264 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3266 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3267 (source.kind != classType || source._class.registered.type != structClass))
3271 // TESTING THIS... IS THIS OK??
3272 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3274 if(!dest._class.registered.dataType)
3275 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3276 // Only support this for classes...
3277 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3278 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3280 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3289 if(source.kind == classType)
3292 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3295 for(convert = _class.conversions.first; convert; convert = convert.next)
3297 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3299 Conversion after = (conversions != null) ? conversions.last : null;
3301 if(!convert.dataType)
3302 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3303 if(convert.dataType != source &&
3304 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3305 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3307 if(!conversions && !convert.Get)
3309 else if(conversions != null)
3311 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3312 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3313 (dest.kind != classType || dest._class.registered != _class.base))
3317 Conversion conv { convert = convert, isGet = true };
3319 // conversions.Add(conv);
3320 conversions.Insert(after, conv);
3329 // TESTING THIS... IS THIS OK??
3330 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3332 if(!source._class.registered.dataType)
3333 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3334 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3336 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))
3338 // For bool to be accepted by byte, short, etc.
3339 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3346 if(source.kind == classType || source.kind == subClassType)
3348 else if(dest.kind == source.kind &&
3349 (dest.kind != structType && dest.kind != unionType &&
3350 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3352 // RECENTLY ADDED THESE
3353 else if(dest.kind == doubleType && source.kind == floatType)
3355 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3357 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3359 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3361 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3363 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3365 else if(source.kind == enumType &&
3366 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3368 else if(dest.kind == enumType && !isConversionExploration &&
3369 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3371 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3372 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3374 Type paramSource, paramDest;
3376 if(dest.kind == methodType)
3377 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3378 if(source.kind == methodType)
3379 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3381 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3382 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3383 if(dest.kind == methodType)
3384 dest = dest.method.dataType;
3385 if(source.kind == methodType)
3386 source = source.method.dataType;
3388 paramSource = source.params.first;
3389 if(paramSource && paramSource.kind == voidType) paramSource = null;
3390 paramDest = dest.params.first;
3391 if(paramDest && paramDest.kind == voidType) paramDest = null;
3394 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3395 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3397 // Source thisClass must be derived from destination thisClass
3398 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3399 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3401 if(paramDest && paramDest.kind == classType)
3402 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3404 Compiler_Error($"method class should not take an object\n");
3407 paramDest = paramDest.next;
3409 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3411 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3415 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3417 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3423 // THIS WAS BACKWARDS:
3424 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3425 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3428 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3430 Compiler_Error($"overriding class expected to be derived from method class\n");
3434 paramSource = paramSource.next;
3440 // Source thisClass must be derived from destination thisClass
3441 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3443 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3449 // THIS WAS BACKWARDS TOO??
3450 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3451 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3454 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3456 //Compiler_Error($"overriding class expected to be derived from method class\n");
3464 // Source return type must be derived from destination return type
3465 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3467 Compiler_Warning($"incompatible return type for function\n");
3470 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3472 CheckConstCompatibility(dest.returnType, source.returnType, true);
3476 for(; paramDest; paramDest = paramDest.next)
3480 //Compiler_Warning($"not enough parameters\n");
3481 Compiler_Error($"not enough parameters\n");
3485 Type paramDestType = paramDest;
3486 Type paramSourceType = paramSource;
3487 Type type = paramDestType;
3489 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3490 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3491 paramSource.kind != templateType)
3494 ClassTemplateParameter curParam = null;
3496 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3499 if(sClass.templateClass) sClass = sClass.templateClass;
3500 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3502 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3504 for(sClass = sClass.base; sClass; sClass = sClass.base)
3506 if(sClass.templateClass) sClass = sClass.templateClass;
3507 id += sClass.templateParams.count;
3518 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3519 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3523 // paramDest must be derived from paramSource
3524 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3525 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3529 PrintType(paramDest, type, false, true);
3530 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3532 if(paramDestType != paramDest)
3533 FreeType(paramDestType);
3536 if(paramDestType != paramDest)
3537 FreeType(paramDestType);
3540 paramSource = paramSource.next;
3544 Compiler_Error($"too many parameters\n");
3549 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3553 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3554 (source.kind == arrayType || source.kind == pointerType))
3556 // Pointers to pointer is incompatible with non normal/nohead classes
3557 if(!(dest.type && dest.type.kind == pointerType && source.type.kind == classType && source.type._class &&
3558 source.type._class.registered && (source.type._class.registered.type != normalClass && source.type._class.registered.type != noHeadClass) && !source.type.byReference))
3560 ComputeTypeSize(source.type);
3561 ComputeTypeSize(dest.type);
3562 if(source.type.size == dest.type.size && MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3570 static void FreeConvert(Conversion convert)
3572 if(convert.resultType)
3573 FreeType(convert.resultType);
3576 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3577 char * string, OldList conversions)
3581 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3583 Class _class = link.data;
3584 if(_class.type == enumClass)
3586 OldList converts { };
3588 type.kind = classType;
3591 _class.symbol = FindClass(_class.fullName);
3592 type._class = _class.symbol;
3594 if(MatchTypes(type, dest, &converts, null, null, dest.kind != classType || !dest._class || strcmp(dest._class.string, "bool"),
3595 false, false, false, false))
3598 Class enumClass = eSystem_FindClass(privateModule, "enum");
3602 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3604 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3605 for(value = e.values.first; value; value = value.next)
3607 if(!strcmp(value.name, string))
3612 FreeType(sourceExp.expType);
3614 sourceExp.isConstant = true;
3615 sourceExp.expType = MkClassType(baseClass.fullName);
3616 if(inCompiler || inPreCompiler || inDebugger)
3619 FreeExpContents(sourceExp);
3621 sourceExp.type = constantExp;
3622 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3623 sprintf(constant, FORMAT64D, value.data);
3625 sprintf(constant, FORMAT64HEXLL, value.data);
3626 sourceExp.constant = CopyString(constant);
3627 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3630 while(converts.first)
3632 Conversion convert = converts.first;
3633 converts.Remove(convert);
3634 conversions.Add(convert);
3643 converts.Free(FreeConvert);
3647 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3648 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3653 public bool ModuleVisibility(Module searchIn, Module searchFor)
3655 SubModule subModule;
3657 if(searchFor == searchIn)
3660 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3662 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3664 if(ModuleVisibility(subModule.module, searchFor))
3671 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3675 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3677 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3679 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3682 for(module = mainModule.application.allModules.first; module; module = module.next)
3684 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3690 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3693 Type realDest = dest;
3694 Type backupSourceExpType = null;
3695 Expression computedExp = sourceExp;
3698 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3699 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3701 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3702 ComputeExpression(computedExp /*sourceExp*/);
3705 source = sourceExp.expType;
3707 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3709 if(computedExp != sourceExp)
3711 FreeExpression(computedExp);
3712 computedExp = sourceExp;
3718 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3720 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3722 Class sourceBase, destBase;
3723 for(sourceBase = source._class.registered;
3724 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3725 sourceBase = sourceBase.base);
3726 for(destBase = dest._class.registered;
3727 destBase && destBase.base && destBase.base.type != systemClass;
3728 destBase = destBase.base);
3729 //if(source._class.registered == dest._class.registered)
3730 if(sourceBase == destBase)
3732 if(computedExp != sourceExp)
3734 FreeExpression(computedExp);
3735 computedExp = sourceExp;
3747 int64 value = MAXINT;
3751 if(computedExp.type == constantExp)
3754 value = strtoll(computedExp.constant, null, 0);
3756 value = strtoull(computedExp.constant, null, 0);
3758 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3761 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3763 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3765 if(computedExp != sourceExp)
3767 FreeExpression(computedExp);
3768 computedExp = sourceExp;
3771 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3772 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3775 source = Type { kind = intType, isSigned = false, refCount = 1 };
3778 if(dest.kind == classType)
3780 Class _class = dest._class ? dest._class.registered : null;
3782 if(_class && _class.type == unitClass)
3784 if(source.kind != classType)
3787 Type tempDest, tempSource;
3789 for(; _class.base.type != systemClass; _class = _class.base);
3791 tempDest = tempType;
3793 tempType.kind = classType;
3795 _class.symbol = FindClass(_class.fullName);
3797 tempType._class = _class.symbol;
3798 tempType.truth = dest.truth;
3800 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3802 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3803 backupSourceExpType = sourceExp.expType;
3804 if(dest.passAsTemplate)
3806 // Don't carry passAsTemplate
3807 sourceExp.expType = { };
3808 CopyTypeInto(sourceExp.expType, dest);
3809 sourceExp.expType.passAsTemplate = false;
3813 sourceExp.expType = dest;
3816 //sourceExp.expType = MkClassType(_class.fullName);
3824 // Why wasn't there something like this?
3825 if(_class && _class.type == bitClass && source.kind != classType)
3827 if(!dest._class.registered.dataType)
3828 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3829 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3832 FreeType(sourceExp.expType);
3833 source = sourceExp.expType = MkClassType(dest._class.string);
3836 //source.kind = classType;
3837 //source._class = dest._class;
3841 // Adding two enumerations
3843 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3845 if(!source._class.registered.dataType)
3846 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3847 if(!dest._class.registered.dataType)
3848 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3850 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3853 source = sourceExp.expType = MkClassType(dest._class.string);
3856 //source.kind = classType;
3857 //source._class = dest._class;
3861 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3863 OldList * specs = MkList();
3867 ReadString(string, sourceExp.string);
3868 decl = SpecDeclFromString(string, specs, null);
3870 FreeExpContents(sourceExp);
3871 FreeType(sourceExp.expType);
3873 sourceExp.type = classExp;
3874 sourceExp._classExp.specifiers = specs;
3875 sourceExp._classExp.decl = decl;
3876 sourceExp.expType = dest;
3881 if(backupSourceExpType) FreeType(backupSourceExpType);
3885 else if(source.kind == classType)
3887 Class _class = source._class ? source._class.registered : null;
3889 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3892 if(dest.kind != classType)
3894 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3895 if(!source._class.registered.dataType)
3896 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3899 dest = MkClassType(source._class.string);
3900 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3901 // dest = MkClassType(source._class.string);
3905 if(dest.kind != classType)
3908 Type tempDest, tempSource;
3910 if(!source._class.registered.dataType)
3911 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3913 for(; _class.base.type != systemClass; _class = _class.base);
3915 tempSource = tempType;
3916 tempType.kind = classType;
3917 tempType._class = FindClass(_class.fullName);
3918 tempType.truth = source.truth;
3919 tempType.classObjectType = source.classObjectType;
3922 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3924 // PUT THIS BACK TESTING UNITS?
3925 if(conversions && conversions.last)
3927 ((Conversion)(conversions.last)).resultType = dest;
3931 FreeType(sourceExp.expType);
3932 sourceExp.expType = MkClassType(_class.fullName);
3933 sourceExp.expType.truth = source.truth;
3934 sourceExp.expType.classObjectType = source.classObjectType;
3936 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3938 if(!sourceExp.destType)
3940 FreeType(sourceExp.destType);
3941 sourceExp.destType = sourceExp.expType;
3942 if(sourceExp.expType)
3943 sourceExp.expType.refCount++;
3946 //source = _class.dataType;
3949 // TOCHECK: TESTING THIS NEW CODE
3950 if(!_class.dataType)
3951 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3953 dest = MkClassType(source._class.string);
3954 dest.truth = source.truth;
3955 dest.classObjectType = source.classObjectType;
3958 source = _class.dataType;
3968 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3978 if(source.kind == classType)
3980 Class _class = source._class.registered;
3981 if(_class.type == unitClass)
3983 if(!_class.dataType)
3984 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3985 source = _class.dataType;
3989 if(dest.kind == classType)
3991 Class _class = dest._class ? dest._class.registered : null;
3992 bool fittingValue = false;
3993 if(_class && _class.type == enumClass)
3995 Class enumClass = eSystem_FindClass(privateModule, "enum");
3996 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3997 if(c && value >= 0 && value <= c.largest)
3998 fittingValue = true;
4001 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
4002 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
4004 if(_class.type == normalClass || _class.type == noHeadClass)
4006 Expression newExp { };
4007 *newExp = *sourceExp;
4008 if(sourceExp.destType) sourceExp.destType.refCount++;
4009 if(sourceExp.expType) sourceExp.expType.refCount++;
4010 sourceExp.type = castExp;
4011 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
4012 sourceExp.cast.exp = newExp;
4013 FreeType(sourceExp.expType);
4014 sourceExp.expType = null;
4015 ProcessExpressionType(sourceExp);
4017 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
4020 FreeType(sourceExp.expType);
4021 sourceExp.expType = dest;
4025 if(inCompiler) FreeType(dest);
4027 if(backupSourceExpType) FreeType(backupSourceExpType);
4031 if(!_class.dataType)
4032 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4034 dest = _class.dataType;
4038 // Accept lower precision types for units, since we want to keep the unit type
4039 if(dest.kind == doubleType &&
4040 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
4041 source.kind == charType || source.kind == _BoolType))
4043 specs = MkListOne(MkSpecifier(DOUBLE));
4045 else if(dest.kind == floatType &&
4046 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4047 source.kind == _BoolType || source.kind == doubleType))
4049 specs = MkListOne(MkSpecifier(FLOAT));
4051 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4052 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4055 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4056 ListAdd(specs, MkSpecifier(INT64));
4058 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
4059 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4062 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4063 ListAdd(specs, MkSpecifier(INT));
4065 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
4066 source.kind == floatType || source.kind == doubleType))
4069 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4070 ListAdd(specs, MkSpecifier(SHORT));
4072 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
4073 source.kind == floatType || source.kind == doubleType))
4076 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4077 ListAdd(specs, MkSpecifier(CHAR));
4083 if(backupSourceExpType)
4085 // Failed to convert: revert previous exp type
4086 if(sourceExp.expType) FreeType(sourceExp.expType);
4087 sourceExp.expType = backupSourceExpType;
4092 else if(dest.kind == doubleType &&
4093 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
4094 source.kind == _BoolType || source.kind == charType))
4096 specs = MkListOne(MkSpecifier(DOUBLE));
4098 else if(dest.kind == floatType &&
4099 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4101 specs = MkListOne(MkSpecifier(FLOAT));
4103 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4104 (value == 1 || value == 0))
4107 ListAdd(specs, MkSpecifier(BOOL));
4109 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4110 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
4113 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4114 ListAdd(specs, MkSpecifier(CHAR));
4116 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
4117 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
4120 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4121 ListAdd(specs, MkSpecifier(SHORT));
4123 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
4126 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4127 ListAdd(specs, MkSpecifier(INT));
4129 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
4132 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4133 ListAdd(specs, MkSpecifier(INT64));
4135 else if(dest.kind == enumType &&
4136 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4138 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4144 if(backupSourceExpType)
4146 // Failed to convert: revert previous exp type
4147 if(sourceExp.expType) FreeType(sourceExp.expType);
4148 sourceExp.expType = backupSourceExpType;
4153 if(!flag && !sourceExp.opDestType)
4155 Expression newExp { };
4156 *newExp = *sourceExp;
4159 if(sourceExp.destType) sourceExp.destType.refCount++;
4160 if(sourceExp.expType) sourceExp.expType.refCount++;
4162 sourceExp.type = castExp;
4163 if(realDest.kind == classType)
4165 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4166 FreeList(specs, FreeSpecifier);
4169 sourceExp.cast.typeName = MkTypeName(specs, null);
4170 if(newExp.type == opExp)
4172 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4175 sourceExp.cast.exp = newExp;
4177 FreeType(sourceExp.expType);
4178 sourceExp.expType = null;
4179 ProcessExpressionType(sourceExp);
4182 FreeList(specs, FreeSpecifier);
4186 if(backupSourceExpType) FreeType(backupSourceExpType);
4192 if(computedExp != sourceExp)
4194 FreeExpression(computedExp);
4195 computedExp = sourceExp;
4198 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4199 if(sourceExp.type == identifierExp)
4201 Identifier id = sourceExp.identifier;
4202 if(dest.kind == classType)
4204 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4206 Class _class = dest._class.registered;
4207 Class enumClass = eSystem_FindClass(privateModule, "enum");
4210 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4213 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4214 for(value = e.values.first; value; value = value.next)
4216 if(!strcmp(value.name, id.string))
4221 FreeType(sourceExp.expType);
4223 sourceExp.isConstant = true;
4224 sourceExp.expType = MkClassType(_class.fullName);
4225 if(inCompiler || inPreCompiler || inDebugger)
4227 FreeExpContents(sourceExp);
4229 sourceExp.type = constantExp;
4230 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4231 sourceExp.constant = PrintInt64(value.data);
4233 sourceExp.constant = PrintUInt64(value.data);
4234 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4244 // Loop through all enum classes
4245 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4256 #define TERTIARY(o, name, m, t, p) \
4257 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4259 exp.type = constantExp; \
4260 exp.string = p(op1.m ? op2.m : op3.m); \
4262 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4266 #define BINARY(o, name, m, t, p) \
4267 static bool name(Expression exp, Operand op1, Operand op2) \
4270 exp.type = constantExp; \
4271 exp.string = p((t)(op1.m o value2)); \
4273 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4277 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4278 static bool name(Expression exp, Operand op1, Operand op2) \
4281 exp.type = constantExp; \
4282 exp.string = p(value2 ? (op1.m o value2) : 0); \
4284 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4288 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4289 static bool name(Expression exp, Operand op1, Operand op2) \
4292 exp.type = constantExp; \
4293 exp.string = p(op1.m o value2); \
4295 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4299 #define UNARY(o, name, m, t, p) \
4300 static bool name(Expression exp, Operand op1) \
4302 exp.type = constantExp; \
4303 exp.string = p((t)(o op1.m)); \
4305 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4309 #define OPERATOR_ALL(macro, o, name) \
4310 macro(o, Int##name, i, int, PrintInt) \
4311 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4312 macro(o, Int64##name, i64, int64, PrintInt64) \
4313 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4314 macro(o, Short##name, s, short, PrintShort) \
4315 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4316 macro(o, Char##name, c, char, PrintChar) \
4317 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4318 macro(o, Float##name, f, float, PrintFloat) \
4319 macro(o, Double##name, d, double, PrintDouble)
4321 #define OPERATOR_INTTYPES(macro, o, name) \
4322 macro(o, Int##name, i, int, PrintInt) \
4323 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4324 macro(o, Int64##name, i64, int64, PrintInt64) \
4325 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4326 macro(o, Short##name, s, short, PrintShort) \
4327 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4328 macro(o, Char##name, c, char, PrintChar) \
4329 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4331 #define OPERATOR_REALTYPES(macro, o, name) \
4332 macro(o, Float##name, f, float, PrintFloat) \
4333 macro(o, Double##name, d, double, PrintDouble)
4335 // binary arithmetic
4336 OPERATOR_ALL(BINARY, +, Add)
4337 OPERATOR_ALL(BINARY, -, Sub)
4338 OPERATOR_ALL(BINARY, *, Mul)
4339 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4340 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4341 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4344 OPERATOR_ALL(UNARY, -, Neg)
4346 // unary arithmetic increment and decrement
4347 OPERATOR_ALL(UNARY, ++, Inc)
4348 OPERATOR_ALL(UNARY, --, Dec)
4350 // binary arithmetic assignment
4351 OPERATOR_ALL(BINARY, =, Asign)
4352 OPERATOR_ALL(BINARY, +=, AddAsign)
4353 OPERATOR_ALL(BINARY, -=, SubAsign)
4354 OPERATOR_ALL(BINARY, *=, MulAsign)
4355 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4356 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4357 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4360 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4361 OPERATOR_INTTYPES(BINARY, |, BitOr)
4362 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4363 OPERATOR_INTTYPES(BINARY, <<, LShift)
4364 OPERATOR_INTTYPES(BINARY, >>, RShift)
4367 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4369 // binary bitwise assignment
4370 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4371 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4372 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4373 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4374 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4376 // unary logical negation
4377 OPERATOR_INTTYPES(UNARY, !, Not)
4379 // binary logical equality
4380 OPERATOR_ALL(BINARY, ==, Equ)
4381 OPERATOR_ALL(BINARY, !=, Nqu)
4384 OPERATOR_ALL(BINARY, &&, And)
4385 OPERATOR_ALL(BINARY, ||, Or)
4387 // binary logical relational
4388 OPERATOR_ALL(BINARY, >, Grt)
4389 OPERATOR_ALL(BINARY, <, Sma)
4390 OPERATOR_ALL(BINARY, >=, GrtEqu)
4391 OPERATOR_ALL(BINARY, <=, SmaEqu)
4393 // tertiary condition operator
4394 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4396 //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
4397 #define OPERATOR_TABLE_ALL(name, type) \
4398 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4400 type##Inc, type##Dec, \
4401 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4402 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4404 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4406 type##Equ, type##Nqu, \
4407 type##And, type##Or, \
4408 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4411 #define OPERATOR_TABLE_INTTYPES(name, type) \
4412 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4414 type##Inc, type##Dec, \
4415 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4416 null, null, null, null, null, \
4418 null, null, null, null, null, \
4420 type##Equ, type##Nqu, \
4421 type##And, type##Or, \
4422 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4425 OPERATOR_TABLE_ALL(int, Int)
4426 OPERATOR_TABLE_ALL(uint, UInt)
4427 OPERATOR_TABLE_ALL(int64, Int64)
4428 OPERATOR_TABLE_ALL(uint64, UInt64)
4429 OPERATOR_TABLE_ALL(short, Short)
4430 OPERATOR_TABLE_ALL(ushort, UShort)
4431 OPERATOR_TABLE_INTTYPES(float, Float)
4432 OPERATOR_TABLE_INTTYPES(double, Double)
4433 OPERATOR_TABLE_ALL(char, Char)
4434 OPERATOR_TABLE_ALL(uchar, UChar)
4436 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4437 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4438 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4439 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4440 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4441 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4442 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4443 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4445 public void ReadString(char * output, char * string)
4447 int len = strlen(string);
4449 bool quoted = false, escaped = false;
4450 for(c = 0; c<len; c++)
4452 char ch = string[c];
4457 case 'n': output[d] = '\n'; break;
4458 case 't': output[d] = '\t'; break;
4459 case 'a': output[d] = '\a'; break;
4460 case 'b': output[d] = '\b'; break;
4461 case 'f': output[d] = '\f'; break;
4462 case 'r': output[d] = '\r'; break;
4463 case 'v': output[d] = '\v'; break;
4464 case '\\': output[d] = '\\'; break;
4465 case '\"': output[d] = '\"'; break;
4466 case '\'': output[d] = '\''; break;
4467 default: output[d] = ch;
4488 // String Unescape Copy
4490 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4491 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4492 public int UnescapeString(char * d, char * s, int len)
4496 while(j < len && (ch = s[j]))
4501 switch((ch = s[++j]))
4503 case 'n': d[k] = '\n'; break;
4504 case 't': d[k] = '\t'; break;
4505 case 'a': d[k] = '\a'; break;
4506 case 'b': d[k] = '\b'; break;
4507 case 'f': d[k] = '\f'; break;
4508 case 'r': d[k] = '\r'; break;
4509 case 'v': d[k] = '\v'; break;
4510 case '\\': d[k] = '\\'; break;
4511 case '\"': d[k] = '\"'; break;
4512 case '\'': d[k] = '\''; break;
4513 default: d[k] = '\\'; d[k] = ch;
4525 public char * OffsetEscapedString(char * s, int len, int offset)
4529 while(j < len && k < offset && (ch = s[j]))
4534 return (k == offset) ? s + j : null;
4537 public Operand GetOperand(Expression exp)
4540 Type type = exp.expType;
4543 while(type.kind == classType &&
4544 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4546 if(!type._class.registered.dataType)
4547 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4548 type = type._class.registered.dataType;
4551 if(exp.type == stringExp && op.kind == pointerType)
4553 op.ui64 = (uint64)(uintptr)exp.string;
4554 op.kind = pointerType;
4557 else if(exp.isConstant && exp.type == constantExp)
4559 op.kind = type.kind;
4567 if(exp.constant[0] == '\'')
4569 op.c = exp.constant[1];
4572 else if(type.isSigned)
4574 op.c = (char)strtol(exp.constant, null, 0);
4579 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4587 op.s = (short)strtol(exp.constant, null, 0);
4592 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4600 op.i = (int)strtol(exp.constant, null, 0);
4605 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4613 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4618 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4621 op.kind = int64Type;
4626 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4631 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4634 op.kind = int64Type;
4639 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4644 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4647 op.kind = int64Type;
4650 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4651 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4652 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4653 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4655 op.f = (float)strtod(exp.constant, null);
4659 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4660 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4661 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4662 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4664 op.d = (double)strtod(exp.constant, null);
4667 //case classType: For when we have operator overloading...
4668 // Pointer additions
4669 //case functionType:
4673 op.ui64 = _strtoui64(exp.constant, null, 0);
4674 op.kind = pointerType;
4684 static int64 GetEnumValue(Class _class, void * ptr)
4687 switch(_class.typeSize)
4690 if(!strcmp(_class.dataTypeString, "uint64"))
4691 v = (int64)*(uint64 *)ptr;
4693 v = (int64)*(int64 *)ptr;
4696 if(!strcmp(_class.dataTypeString, "uint"))
4697 v = (int64)*(uint *)ptr;
4699 v = (int64)*(int *)ptr;
4702 if(!strcmp(_class.dataTypeString, "uint16"))
4703 v = (int64)*(uint16 *)ptr;
4705 v = (int64)*(short *)ptr;
4708 if(!strcmp(_class.dataTypeString, "byte"))
4709 v = (int64)*(byte *)ptr;
4711 v = (int64)*(char *)ptr;
4717 static __attribute__((unused)) void UnusedFunction()
4720 a.OnGetString(0,0,0);
4723 extern int __ecereVMethodID_class_OnGetString;
4726 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4728 DataMember dataMember;
4729 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4731 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4732 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4736 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4738 void * ptr = inst.data + dataMember.offset + offset;
4739 char * result = null;
4740 exp.loc = member.loc = inst.loc;
4741 ((Identifier)member.identifiers->first).loc = inst.loc;
4743 if(!dataMember.dataType)
4744 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4745 type = dataMember.dataType;
4746 if(type.kind == classType)
4748 Class _class = type._class.registered;
4749 if(_class.type == enumClass)
4751 Class enumClass = eSystem_FindClass(privateModule, "enum");
4754 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4756 for(item = e.values.first; item; item = item.next)
4758 if(item.data == GetEnumValue(_class, ptr))
4766 exp.identifier = MkIdentifier(result);
4767 exp.type = identifierExp;
4768 exp.destType = MkClassType(_class.fullName);
4769 ProcessExpressionType(exp);
4773 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4775 if(!_class.dataType)
4776 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4777 type = _class.dataType;
4786 FreeExpContents(exp);
4788 exp.constant = PrintFloat(*(float*)ptr);
4789 exp.type = constantExp;
4794 FreeExpContents(exp);
4796 exp.constant = PrintDouble(*(double*)ptr);
4797 exp.type = constantExp;
4802 FreeExpContents(exp);
4804 exp.constant = PrintInt(*(int*)ptr);
4805 exp.type = constantExp;
4810 FreeExpContents(exp);
4812 exp.constant = PrintInt64(*(int64*)ptr);
4813 exp.type = constantExp;
4818 FreeExpContents(exp);
4819 // TODO: This should probably use proper type
4820 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4821 exp.type = constantExp;
4826 FreeExpContents(exp);
4827 // TODO: This should probably use proper type
4828 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4829 exp.type = constantExp;
4833 Compiler_Error($"Unhandled type populating instance\n");
4836 ListAdd(memberList, member);
4839 if(parentDataMember.type == unionMember)
4844 void PopulateInstance(Instantiation inst)
4846 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4847 Class _class = classSym.registered;
4848 DataMember dataMember;
4849 OldList * memberList = MkList();
4850 // Added this check and ->Add to prevent memory leaks on bad code
4852 inst.members = MkListOne(MkMembersInitList(memberList));
4854 inst.members->Add(MkMembersInitList(memberList));
4855 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4857 if(!dataMember.isProperty)
4859 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4860 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4864 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4866 void * ptr = inst.data + dataMember.offset;
4867 char * result = null;
4869 exp.loc = member.loc = inst.loc;
4870 ((Identifier)member.identifiers->first).loc = inst.loc;
4872 if(!dataMember.dataType)
4873 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4874 type = dataMember.dataType;
4875 if(type.kind == classType)
4877 Class _class = type._class.registered;
4878 if(_class.type == enumClass)
4880 Class enumClass = eSystem_FindClass(privateModule, "enum");
4883 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4885 for(item = e.values.first; item; item = item.next)
4887 if(item.data == GetEnumValue(_class, ptr))
4896 exp.identifier = MkIdentifier(result);
4897 exp.type = identifierExp;
4898 exp.destType = MkClassType(_class.fullName);
4899 ProcessExpressionType(exp);
4902 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4904 if(!_class.dataType)
4905 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4906 type = _class.dataType;
4915 exp.constant = PrintFloat(*(float*)ptr);
4916 exp.type = constantExp;
4921 exp.constant = PrintDouble(*(double*)ptr);
4922 exp.type = constantExp;
4927 exp.constant = PrintInt(*(int*)ptr);
4928 exp.type = constantExp;
4933 exp.constant = PrintInt64(*(int64*)ptr);
4934 exp.type = constantExp;
4939 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4940 exp.type = constantExp;
4944 Compiler_Error($"Unhandled type populating instance\n");
4947 ListAdd(memberList, member);
4953 void ComputeInstantiation(Expression exp)
4955 Instantiation inst = exp.instance;
4956 MembersInit members;
4957 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4958 Class _class = classSym ? classSym.registered : null;
4959 DataMember curMember = null;
4960 Class curClass = null;
4961 DataMember subMemberStack[256];
4962 int subMemberStackPos = 0;
4965 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4967 // Don't recompute the instantiation...
4968 // Non Simple classes will have become constants by now
4972 if(_class.type == normalClass || _class.type == noHeadClass)
4974 inst.data = (byte *)eInstance_New(_class);
4975 if(_class.type == normalClass)
4976 ((Instance)inst.data)._refCount++;
4979 inst.data = new0 byte[_class.structSize];
4984 for(members = inst.members->first; members; members = members.next)
4986 switch(members.type)
4988 case dataMembersInit:
4990 if(members.dataMembers)
4993 for(member = members.dataMembers->first; member; member = member.next)
4995 Identifier ident = member.identifiers ? member.identifiers->first : null;
4998 Property prop = null;
4999 DataMember dataMember = null;
5000 uint dataMemberOffset;
5004 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
5007 if(curMember.isProperty)
5008 prop = (Property)curMember;
5011 dataMember = curMember;
5013 // CHANGED THIS HERE
5014 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
5016 // 2013/17/29 -- It seems that this was missing here!
5017 if(_class.type == normalClass)
5018 dataMemberOffset += _class.base.structSize;
5019 // dataMemberOffset = dataMember.offset;
5026 prop = eClass_FindProperty(_class, ident.string, privateModule);
5030 if(prop.memberAccess == publicAccess)
5032 curMember = (DataMember)prop;
5033 curClass = prop._class;
5038 DataMember _subMemberStack[256];
5039 int _subMemberStackPos = 0;
5041 // FILL MEMBER STACK
5042 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
5047 if(dataMember.memberAccess == publicAccess)
5049 curMember = dataMember;
5050 curClass = dataMember._class;
5051 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
5052 subMemberStackPos = _subMemberStackPos;
5058 if(found && member.initializer && member.initializer.type == expInitializer)
5060 Expression value = member.initializer.exp;
5062 bool deepMember = false;
5065 type = prop.dataType;
5069 if(!dataMember.dataType)
5070 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
5072 type = dataMember.dataType;
5075 if(ident && ident.next)
5079 // for(; ident && type; ident = ident.next)
5080 for(ident = ident.next; ident && type; ident = ident.next)
5082 if(type.kind == classType)
5084 prop = eClass_FindProperty(type._class.registered,
5085 ident.string, privateModule);
5087 type = prop.dataType;
5090 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
5091 ident.string, &dataMemberOffset, privateModule, null, null);
5093 type = dataMember.dataType;
5096 else if(type.kind == structType || type.kind == unionType)
5099 for(memberType = type.members.first; memberType; memberType = memberType.next)
5101 if(!strcmp(memberType.name, ident.string))
5112 FreeType(value.destType);
5113 value.destType = type;
5114 if(type) type.refCount++;
5115 ComputeExpression(value);
5117 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
5119 if(type.kind == classType)
5121 Class _class = type._class.registered;
5122 if(_class && (_class.type == bitClass || _class.type == unitClass || _class.type == enumClass))
5124 if(!_class.dataType)
5125 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5126 type = _class.dataType;
5132 void * ptr = inst.data + dataMemberOffset;
5134 if(value.type == constantExp)
5140 GetInt(value, (int*)ptr);
5145 GetInt64(value, (int64*)ptr);
5150 GetIntPtr(value, (intptr*)ptr);
5155 GetIntSize(value, (intsize*)ptr);
5160 GetFloat(value, (float*)ptr);
5165 GetDouble(value, (double *)ptr);
5170 else if(value.type == instanceExp)
5172 if(type.kind == classType)
5174 Class _class = type._class.registered;
5175 if(_class.type == structClass)
5177 ComputeTypeSize(type);
5178 if(value.instance.data)
5179 memcpy(ptr, value.instance.data, type.size);
5184 else if(prop && prop.Set != (void *)(intptr)1)
5186 if(value.type == instanceExp && value.instance.data)
5188 if(type.kind == classType)
5190 Class _class = type._class.registered;
5191 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5193 void (*Set)(void *, void *) = (void *)prop.Set;
5194 Set(inst.data, value.instance.data);
5195 PopulateInstance(inst);
5199 else if(value.type == constantExp)
5205 void (*Set)(void *, double) = (void *)prop.Set;
5206 Set(inst.data, strtod(value.constant, null) );
5211 void (*Set)(void *, float) = (void *)prop.Set;
5212 Set(inst.data, (float)(strtod(value.constant, null)));
5217 void (*Set)(void *, int) = (void *)prop.Set;
5218 Set(inst.data, (int)strtol(value.constant, null, 0));
5223 void (*Set)(void *, int64) = (void *)prop.Set;
5224 Set(inst.data, _strtoi64(value.constant, null, 0));
5229 void (*Set)(void *, intptr) = (void *)prop.Set;
5230 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5235 void (*Set)(void *, intsize) = (void *)prop.Set;
5236 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5241 else if(value.type == stringExp)
5244 ReadString(temp, value.string);
5245 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5249 else if(!deepMember && type && _class.type == unitClass)
5253 // Only support converting units to units for now...
5254 if(value.type == constantExp)
5256 if(type.kind == classType)
5258 Class _class = type._class.registered;
5259 if(_class.type == unitClass)
5261 if(!_class.dataType)
5262 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5263 type = _class.dataType;
5266 // TODO: Assuming same base type for units...
5272 float (*Set)(float) = (void *)prop.Set;
5273 GetFloat(member.initializer.exp, &fValue);
5274 exp.constant = PrintFloat(Set(fValue));
5275 exp.type = constantExp;
5281 double (*Set)(double) = (void *)prop.Set;
5282 GetDouble(member.initializer.exp, &dValue);
5283 exp.constant = PrintDouble(Set(dValue));
5284 exp.type = constantExp;
5291 else if(!deepMember && type && _class.type == bitClass)
5295 if(value.type == instanceExp && value.instance.data)
5297 unsigned int (*Set)(void *) = (void *)prop.Set;
5298 bits = Set(value.instance.data);
5300 else if(value.type == constantExp)
5306 BitMember bitMember = (BitMember) dataMember;
5309 bits = (bits & ~bitMember.mask);
5310 if(!bitMember.dataType)
5311 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5312 type = bitMember.dataType;
5313 if(type.kind == classType && type._class && type._class.registered)
5315 if(!type._class.registered.dataType)
5316 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5317 type = type._class.registered.dataType;
5322 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5323 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5325 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5326 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5327 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5328 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5330 bits |= part << bitMember.pos;
5336 if(_class && _class.type == unitClass)
5338 ComputeExpression(member.initializer.exp);
5339 exp.constant = member.initializer.exp.constant;
5340 exp.type = constantExp;
5342 member.initializer.exp.constant = null;
5352 if(_class && _class.type == bitClass)
5354 exp.constant = PrintHexUInt(bits);
5355 exp.type = constantExp;
5357 if(exp.type != instanceExp)
5363 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5365 bool result = false;
5369 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5370 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5374 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5375 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5378 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5379 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5380 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5383 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5384 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5385 result = GetOpFloat(op, &op.f);
5388 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5389 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5390 result = GetOpDouble(op, &op.d);
5393 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5394 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5395 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5398 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5399 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5400 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5403 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5404 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5407 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5408 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5414 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5416 if(exp.op.op == SIZEOF)
5418 FreeExpContents(exp);
5419 exp.type = constantExp;
5420 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5431 // Provide default unary +
5432 Expression exp2 = exp.op.exp2;
5434 FreeExpContents(exp);
5435 FreeType(exp.expType);
5436 FreeType(exp.destType);
5442 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5444 // unary arithmetic increment and decrement
5445 //OPERATOR_ALL(UNARY, ++, Inc)
5446 //OPERATOR_ALL(UNARY, --, Dec)
5449 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5451 // unary logical negation
5453 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5459 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5461 if(Promote(op2, op1.kind, op1.type.isSigned))
5462 op2.kind = op1.kind, op2.ops = op1.ops;
5463 else if(Promote(op1, op2.kind, op2.type.isSigned))
5464 op1.kind = op2.kind, op1.ops = op2.ops;
5468 // binary arithmetic
5470 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5473 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5476 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5479 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5482 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5484 // binary arithmetic assignment
5485 //OPERATOR_ALL(BINARY, =, Asign)
5486 //OPERATOR_ALL(BINARY, +=, AddAsign)
5487 //OPERATOR_ALL(BINARY, -=, SubAsign)
5488 //OPERATOR_ALL(BINARY, *=, MulAsign)
5489 //OPERATOR_ALL(BINARY, /=, DivAsign)
5490 //OPERATOR_ALL(BINARY, %=, ModAsign)
5495 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5499 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5502 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5505 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5508 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5510 // binary bitwise assignment
5511 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5512 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5513 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5514 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5515 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5516 // binary logical equality
5518 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5521 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5525 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5528 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5530 // binary logical relational
5532 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5535 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5538 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5541 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5548 void ComputeExpression(Expression exp)
5551 char expString[10240];
5552 expString[0] = '\0';
5553 PrintExpression(exp, expString);
5560 Identifier id = exp.identifier;
5561 if(id && exp.isConstant && !inCompiler && !inPreCompiler && !inDebugger)
5563 Class c = (exp.expType && exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
5564 if(c && c.type == enumClass)
5566 Class enumClass = eSystem_FindClass(privateModule, "enum");
5570 EnumClassData e = ACCESS_CLASSDATA(c, enumClass);
5571 for(value = e.values.first; value; value = value.next)
5573 if(!strcmp(value.name, id.string))
5578 const String dts = c.dataTypeString;
5579 FreeExpContents(exp);
5580 exp.type = constantExp;
5581 exp.constant = (dts && (!strcmp(dts, "int") || !strcmp(dts, "int64") || !strcmp(dts, "short") || !strcmp(dts, "char"))) ? PrintInt64(value.data) : PrintUInt64(value.data);
5590 ComputeInstantiation(exp);
5599 Expression exp1, exp2 = null;
5603 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5606 Expression e = exp.op.exp2;
5608 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5610 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5612 if(e.type == extensionCompoundExp)
5613 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5618 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5620 if(e.type == stringExp && e.string)
5622 char * string = e.string;
5623 int len = strlen(string);
5624 char * tmp = new char[len-2+1];
5625 len = UnescapeString(tmp, string + 1, len - 2);
5627 FreeExpContents(exp);
5628 exp.type = constantExp;
5629 exp.constant = PrintUInt(len + 1);
5633 Type type = e.expType;
5635 FreeExpContents(exp);
5636 exp.type = constantExp;
5637 exp.constant = PrintUInt(ComputeTypeSize(type));
5643 ComputeExpression(exp.op.exp2);
5647 ComputeExpression(exp.op.exp1);
5650 op1 = GetOperand(exp1);
5651 if(op1.type) op1.type.refCount++;
5654 op2 = GetOperand(exp2);
5655 if(op2.type) op2.type.refCount++;
5661 op1 = GetOperand(exp1);
5662 if(op1.type) op1.type.refCount++;
5665 CallOperator(exp, exp1, exp2, op1, op2);
5672 if(exp.op.exp1 && exp.op.exp2)
5677 FreeExpContents(exp);
5678 op1.ops.BitAnd(exp, op1, op2);
5687 FreeExpContents(exp);
5688 op1.ops.Mul(exp, op1, op2);
5697 FreeExpContents(exp);
5698 op1.ops.Add(exp, op1, op2);
5703 // Provide default unary +
5704 Expression exp2 = exp.op.exp2;
5706 FreeExpContents(exp);
5707 FreeType(exp.expType);
5708 FreeType(exp.destType);
5719 FreeExpContents(exp);
5720 op1.ops.Sub(exp, op1, op2);
5727 FreeExpContents(exp);
5728 op1.ops.Neg(exp, op1);
5735 FreeExpContents(exp);
5736 op1.ops.BitNot(exp, op1);
5742 FreeExpContents(exp);
5743 op1.ops.Not(exp, op1);
5746 // Binary only operators
5750 FreeExpContents(exp);
5751 op1.ops.Div(exp, op1, op2);
5757 FreeExpContents(exp);
5758 op1.ops.Mod(exp, op1, op2);
5770 FreeExpContents(exp);
5771 op1.ops.Sma(exp, op1, op2);
5780 FreeExpContents(exp);
5781 op1.ops.Grt(exp, op1, op2);
5790 FreeExpContents(exp);
5791 op1.ops.SmaEqu(exp, op1, op2);
5800 FreeExpContents(exp);
5801 op1.ops.GrtEqu(exp, op1, op2);
5810 FreeExpContents(exp);
5811 op1.ops.Equ(exp, op1, op2);
5820 FreeExpContents(exp);
5821 op1.ops.Nqu(exp, op1, op2);
5828 FreeExpContents(exp);
5829 op1.ops.BitOr(exp, op1, op2);
5835 FreeExpContents(exp);
5836 op1.ops.BitXor(exp, op1, op2);
5844 FreeExpContents(exp);
5845 exp.type = constantExp;
5846 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5850 if(op1.type) FreeType(op1.type);
5851 if(op2.type) FreeType(op2.type);
5855 case extensionExpressionExp:
5858 for(e = exp.list->first; e; e = n)
5863 OldList * list = exp.list;
5864 Expression prev = exp.prev;
5865 Expression next = exp.next;
5866 ComputeExpression(e);
5867 //FreeExpContents(exp);
5868 FreeType(exp.expType);
5869 FreeType(exp.destType);
5888 exp.isConstant = true;
5890 ComputeExpression(exp.index.exp);
5891 if(!exp.index.exp.isConstant)
5892 exp.isConstant = false;
5894 for(e = exp.index.index->first; e; e = e.next)
5896 ComputeExpression(e);
5899 // Check if this type is int
5902 exp.isConstant = false;
5904 exp.expType = Dereference(exp.index.exp.expType);
5910 Expression memberExp = exp.member.exp;
5911 Identifier memberID = exp.member.member;
5914 ComputeExpression(exp.member.exp);
5915 type = exp.member.exp.expType;
5918 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);
5919 Property prop = null;
5920 DataMember member = null;
5921 Class convertTo = null;
5922 if(type.kind == subClassType && exp.member.exp.type == classExp)
5923 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5930 PrintTypeNoConst(type, string, false, true);
5931 classSym = FindClass(string);
5932 _class = classSym ? classSym.registered : null;
5935 if(exp.member.member)
5937 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5939 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5941 if(!prop && !member && _class && exp.member.member)
5943 Symbol classSym = FindClass(exp.member.member.string);
5945 _class = classSym ? classSym.registered : null;
5946 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5953 Type type = prop.dataType;
5954 // TODO: Assuming same base type for units...
5955 if(_class.type == unitClass)
5957 if(type.kind == classType)
5959 Class _class = type._class.registered;
5960 if(_class.type == unitClass)
5962 if(!_class.dataType)
5963 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5964 type = _class.dataType;
5972 float (*Get)(float) = (void *)prop.Get;
5973 GetFloat(exp.member.exp, &value);
5974 exp.constant = PrintFloat(Get ? Get(value) : value);
5975 exp.type = constantExp;
5981 double (*Get)(double);
5982 GetDouble(exp.member.exp, &value);
5985 Get = (void *)prop.Set;
5987 Get = (void *)prop.Get;
5988 exp.constant = PrintDouble(Get ? Get(value) : value);
5989 exp.type = constantExp;
5998 Expression value = exp.member.exp;
6001 ProcessPropertyType(prop);
6003 type = prop.dataType;
6006 // printf("Investigate this\n");
6008 else if(_class.type == structClass)
6014 Class propertyClass = type._class.registered;
6015 if(propertyClass.type == structClass && value.type == instanceExp)
6017 void (*Set)(void *, void *) = (void *)prop.Set;
6018 exp.instance = Instantiation { };
6019 exp.instance.data = new0 byte[_class.structSize];
6020 exp.instance._class = MkSpecifierName(_class.fullName);
6021 exp.instance.loc = exp.loc;
6022 exp.type = instanceExp;
6023 Set(exp.instance.data, value.instance.data);
6024 PopulateInstance(exp.instance);
6031 void (*Set)(void *, int) = (void *)prop.Set;
6033 exp.instance = Instantiation { };
6034 exp.instance.data = new0 byte[_class.structSize];
6035 exp.instance._class = MkSpecifierName(_class.fullName);
6036 exp.instance.loc = exp.loc;
6037 exp.type = instanceExp;
6039 GetInt(value, &intValue);
6041 Set(exp.instance.data, intValue);
6042 PopulateInstance(exp.instance);
6048 void (*Set)(void *, int64) = (void *)prop.Set;
6050 exp.instance = Instantiation { };
6051 exp.instance.data = new0 byte[_class.structSize];
6052 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
6053 exp.instance.loc = exp.loc;
6054 exp.type = instanceExp;
6056 GetInt64(value, &intValue);
6058 Set(exp.instance.data, intValue);
6059 PopulateInstance(exp.instance);
6066 void (*Set)(void *, intptr) = (void *)prop.Set;
6068 exp.instance = Instantiation { };
6069 exp.instance.data = new0 byte[_class.structSize];
6070 exp.instance._class = MkSpecifierName(_class.fullName);
6071 exp.instance.loc = exp.loc;
6072 exp.type = instanceExp;
6074 GetIntPtr(value, &intValue);
6076 Set(exp.instance.data, intValue);
6077 PopulateInstance(exp.instance);
6084 void (*Set)(void *, intsize) = (void *)prop.Set;
6086 exp.instance = Instantiation { };
6087 exp.instance.data = new0 byte[_class.structSize];
6088 exp.instance._class = MkSpecifierName(_class.fullName);
6089 exp.instance.loc = exp.loc;
6090 exp.type = instanceExp;
6092 GetIntSize(value, &intValue);
6094 Set(exp.instance.data, intValue);
6095 PopulateInstance(exp.instance);
6101 void (*Set)(void *, float) = (void *)prop.Set;
6103 exp.instance = Instantiation { };
6104 exp.instance.data = new0 byte[_class.structSize];
6105 exp.instance._class = MkSpecifierName(_class.fullName);
6106 exp.instance.loc = exp.loc;
6107 exp.type = instanceExp;
6109 GetFloat(value, &floatValue);
6111 Set(exp.instance.data, floatValue);
6112 PopulateInstance(exp.instance);
6118 void (*Set)(void *, double) = (void *)prop.Set;
6120 exp.instance = Instantiation { };
6121 exp.instance.data = new0 byte[_class.structSize];
6122 exp.instance._class = MkSpecifierName(_class.fullName);
6123 exp.instance.loc = exp.loc;
6124 exp.type = instanceExp;
6126 GetDouble(value, &doubleValue);
6128 Set(exp.instance.data, doubleValue);
6129 PopulateInstance(exp.instance);
6134 else if(_class.type == bitClass)
6140 Class propertyClass = type._class.registered;
6141 if(propertyClass.type == structClass && value.instance.data)
6143 unsigned int (*Set)(void *) = (void *)prop.Set;
6144 unsigned int bits = Set(value.instance.data);
6145 exp.constant = PrintHexUInt(bits);
6146 exp.type = constantExp;
6149 else if(_class.type == bitClass)
6152 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6155 GetUInt(exp.member.exp, &value);
6157 exp.constant = PrintHexUInt(bits);
6158 exp.type = constantExp;
6166 if(_class.type == bitClass)
6169 GetUInt(exp.member.exp, &value);
6175 Class _class = type._class.registered;
6176 if(_class.type == structClass)
6178 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6180 exp.instance = Instantiation { };
6181 exp.instance.data = new0 byte[_class.structSize];
6182 exp.instance._class = MkSpecifierName(_class.fullName);
6183 exp.instance.loc = exp.loc;
6184 //exp.instance.fullSet = true;
6185 exp.type = instanceExp;
6186 Get(value, exp.instance.data);
6187 PopulateInstance(exp.instance);
6189 else if(_class.type == bitClass)
6191 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6192 uint64 bits = Get(value);
6193 exp.constant = PrintHexUInt64(bits);
6194 exp.type = constantExp;
6200 else if(_class.type == structClass)
6202 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6207 Class _class = type._class.registered;
6208 if(_class.type == structClass && value)
6210 void (*Get)(void *, void *) = (void *)prop.Get;
6212 exp.instance = Instantiation { };
6213 exp.instance.data = new0 byte[_class.structSize];
6214 exp.instance._class = MkSpecifierName(_class.fullName);
6215 exp.instance.loc = exp.loc;
6216 //exp.instance.fullSet = true;
6217 exp.type = instanceExp;
6218 Get(value, exp.instance.data);
6219 PopulateInstance(exp.instance);
6227 char * value = exp.member.exp.instance.data;
6232 Class _class = type._class.registered;
6233 if(_class.type == normalClass)
6235 void *(*Get)(void *) = (void *)prop.Get;
6237 exp.instance = Instantiation { };
6238 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6239 exp.type = instanceExp;
6240 exp.instance.data = Get(value, exp.instance.data);
6252 exp.isConstant = false;
6260 if(exp.type != ExpressionType::memberExp)
6262 FreeExpression(memberExp);
6263 FreeIdentifier(memberID);
6269 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6270 FreeExpContents(exp);
6271 exp.constant = PrintUInt(ComputeTypeSize(type));
6272 exp.type = constantExp;
6278 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6279 if(classSym && classSym.registered)
6281 if(classSym.registered.fixed)
6283 FreeSpecifier(exp._class);
6284 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6285 exp.type = constantExp;
6289 char className[1024];
6290 strcpy(className, "__ecereClass_");
6291 FullClassNameCat(className, classSym.string, true);
6292 //MangleClassName(className);
6294 DeclareClass(classSym, className);
6296 FreeExpContents(exp);
6297 exp.type = pointerExp;
6298 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6299 exp.member.member = MkIdentifier("structSize");
6309 if(exp.type == castExp)
6312 ComputeExpression(exp.cast.exp);
6315 if(e && exp.expType)
6318 type = exp.destType;
6321 if(type.kind == classType)
6323 Class _class = type._class.registered;
6324 if(_class && (_class.type == unitClass || _class.type == bitClass))
6326 if(!_class.dataType)
6327 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6328 type = _class.dataType;
6339 if(GetChar(e, &value))
6341 FreeExpContents(exp);
6342 exp.constant = PrintChar(value);
6343 exp.type = constantExp;
6348 unsigned char value = 0;
6349 if(GetUChar(e, &value))
6351 FreeExpContents(exp);
6352 exp.constant = PrintUChar(value);
6353 exp.type = constantExp;
6361 if(GetShort(e, &value))
6363 FreeExpContents(exp);
6364 exp.constant = PrintShort(value);
6365 exp.type = constantExp;
6370 unsigned short value = 0;
6371 if(GetUShort(e, &value))
6373 FreeExpContents(exp);
6374 exp.constant = PrintUShort(value);
6375 exp.type = constantExp;
6383 if(GetInt(e, &value))
6385 FreeExpContents(exp);
6386 exp.constant = PrintInt(value);
6387 exp.type = constantExp;
6392 unsigned int value = 0;
6393 if(GetUInt(e, &value))
6395 FreeExpContents(exp);
6396 exp.constant = PrintUInt(value);
6397 exp.type = constantExp;
6405 if(GetInt64(e, &value))
6407 FreeExpContents(exp);
6408 exp.constant = PrintInt64(value);
6409 exp.type = constantExp;
6415 if(GetUInt64(e, &value))
6417 FreeExpContents(exp);
6418 exp.constant = PrintUInt64(value);
6419 exp.type = constantExp;
6427 if(GetIntPtr(e, &value))
6429 FreeExpContents(exp);
6430 exp.constant = PrintInt64((int64)value);
6431 exp.type = constantExp;
6437 if(GetUIntPtr(e, &value))
6439 FreeExpContents(exp);
6440 exp.constant = PrintUInt64((uint64)value);
6441 exp.type = constantExp;
6449 if(GetIntSize(e, &value))
6451 FreeExpContents(exp);
6452 exp.constant = PrintInt64((int64)value);
6453 exp.type = constantExp;
6459 if(GetUIntSize(e, &value))
6461 FreeExpContents(exp);
6462 exp.constant = PrintUInt64((uint64)value);
6463 exp.type = constantExp;
6470 if(GetFloat(e, &value))
6472 FreeExpContents(exp);
6473 exp.constant = PrintFloat(value);
6474 exp.type = constantExp;
6481 if(GetDouble(e, &value))
6483 FreeExpContents(exp);
6484 exp.constant = PrintDouble(value);
6485 exp.type = constantExp;
6500 // Caring only about last expression for now...
6501 ComputeExpression(exp.cond.exp->last);
6502 if(exp.cond.elseExp)
6503 ComputeExpression(exp.cond.elseExp);
6505 ComputeExpression(exp.cond.cond);
6507 op1 = GetOperand(exp.cond.cond);
6508 if(op1.type) op1.type.refCount++;
6509 op2 = GetOperand(exp.cond.exp->last);
6510 if(op2.type) op2.type.refCount++;
6511 op3 = GetOperand(exp.cond.elseExp);
6512 if(op3.type) op3.type.refCount++;
6514 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6515 if(op1.type) FreeType(op1.type);
6516 if(op2.type) FreeType(op2.type);
6517 if(op3.type) FreeType(op3.type);
6523 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6528 OldList converts { };
6531 if(destType.kind == voidType)
6534 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6538 // for(convert = converts.last; convert; convert = convert.prev)
6539 for(convert = converts.first; convert; convert = convert.next)
6541 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6544 Expression newExp { };
6545 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6547 // TODO: Check this...
6551 newExp.destType = null;
6556 exp.type = memberExp;
6557 exp.addedThis = true;
6558 exp.member.exp = newExp;
6559 FreeType(exp.member.exp.expType);
6561 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6562 exp.member.exp.expType.classObjectType = objectType;
6563 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6564 exp.member.memberType = propertyMember;
6565 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6566 // TESTING THIS... for (int)degrees
6567 exp.needCast = true;
6568 if(exp.expType) exp.expType.refCount++;
6569 ApplyAnyObjectLogic(exp.member.exp);
6574 /*if(exp.isConstant)
6576 // Color { ColorRGB = [exp] };
6577 exp.type = instanceExp;
6578 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6579 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6580 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6584 // If not constant, don't turn it yet into an instantiation
6585 // (Go through the deep members system first)
6586 exp.type = memberExp;
6587 exp.addedThis = true;
6588 exp.member.exp = newExp;
6590 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6591 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6592 newExp.expType._class.registered.type == noHeadClass)
6594 newExp.byReference = true;
6597 FreeType(exp.member.exp.expType);
6598 /*exp.member.exp.expType = convert.convert.dataType;
6599 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6600 exp.member.exp.expType = null;
6601 if(convert.convert.dataType)
6603 exp.member.exp.expType = { };
6604 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6605 exp.member.exp.expType.refCount = 1;
6606 exp.member.exp.expType.classObjectType = objectType;
6607 ApplyAnyObjectLogic(exp.member.exp);
6610 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6611 exp.member.memberType = reverseConversionMember;
6612 exp.expType = convert.resultType ? convert.resultType :
6613 MkClassType(convert.convert._class.fullName);
6614 exp.needCast = true;
6615 if(convert.resultType) convert.resultType.refCount++;
6621 FreeType(exp.expType);
6624 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6625 if(exp.destType.casted)
6626 exp.needCast = true;
6627 if(exp.expType) exp.expType.refCount++;
6631 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6632 if(exp.destType.casted)
6633 exp.needCast = true;
6634 if(convert.resultType)
6635 convert.resultType.refCount++;
6639 if(exp.isConstant && inCompiler)
6640 ComputeExpression(exp);
6642 converts.Free(FreeConvert);
6645 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6647 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6649 if(!result && exp.expType && exp.destType)
6651 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6652 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6653 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6654 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6658 // if(result) CheckTemplateTypes(exp);
6662 void CheckTemplateTypes(Expression exp)
6665 bool et = exp.expType ? exp.expType.passAsTemplate : false;
6666 bool dt = exp.destType ? exp.destType.passAsTemplate : false;
6668 Expression nbExp = GetNonBracketsExp(exp);
6669 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6670 (nbExp == exp || nbExp.type != castExp))
6672 Expression newExp { };
6674 TypeKind kind = exp.expType.kind;
6676 if(exp.destType) exp.destType.refCount++;
6677 if(exp.expType) exp.expType.refCount++;
6681 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6683 Class c = exp.expType._class.registered;
6684 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6687 c.dataType = ProcessTypeString(c.dataTypeString, false);
6688 kind = c.dataType.kind;
6695 if(exp.destType.classObjectType)
6697 // We need to pass the address, just pass it along (Undo what was done above)
6698 if(exp.destType) exp.destType.refCount--;
6699 if(exp.expType) exp.expType.refCount--;
6704 // If we're looking for value:
6705 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6707 OldList * unionDefs = MkList();
6708 OldList * statements = MkList();
6709 context = PushContext();
6710 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6711 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6712 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6713 exp.type = extensionCompoundExp;
6714 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6715 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6716 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6717 exp.compound.compound.context = context;
6718 PopContext(context);
6723 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6724 if((exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass) || exp.expType.isPointerType)
6725 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
6727 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6728 exp.needCast = true;
6732 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6734 Expression newExp { };
6736 TypeKind kind = exp.expType.kind;
6738 if(exp.destType) exp.destType.refCount++;
6739 if(exp.expType) exp.expType.refCount++;
6743 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6745 Class c = exp.expType._class.registered;
6746 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6749 c.dataType = ProcessTypeString(c.dataTypeString, false);
6750 kind = c.dataType.kind;
6757 if(exp.destType.classObjectType)
6759 // We need to pass the address, just pass it along (Undo what was done above)
6760 if(exp.destType) exp.destType.refCount--;
6761 if(exp.expType) exp.expType.refCount--;
6766 // If we're looking for value:
6767 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6769 OldList * unionDefs = MkList();
6770 OldList * statements = MkList();
6771 context = PushContext();
6772 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6773 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6774 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6775 exp.type = extensionCompoundExp;
6776 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6777 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6778 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6779 exp.compound.compound.context = context;
6780 PopContext(context);
6785 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6787 exp.type = bracketsExp;
6789 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6790 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6791 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6792 ProcessExpressionType(exp.list->first);
6797 exp.type = bracketsExp;
6798 if(exp.expType.isPointerType)
6800 exp.needTemplateCast = 2;
6801 newExp.needCast = true;
6802 newExp.needTemplateCast = 2;
6803 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6806 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6807 exp.needTemplateCast = 2;
6808 newExp.needCast = true;
6809 newExp.needTemplateCast = 2;
6810 ProcessExpressionType(exp.list->first);
6816 if(exp.expType.kind == templateType)
6818 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6821 FreeType(exp.destType);
6822 FreeType(exp.expType);
6827 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6832 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6833 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6837 char typeString[1024];
6839 OldList * specs = MkList();
6840 typeString[0] = '\0';
6841 PrintType(exp.expType, typeString, false, false);
6842 decl = SpecDeclFromString(typeString, specs, null);
6845 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6846 exp.cast.typeName = MkTypeName(specs, decl);
6847 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6848 exp.cast.exp.needCast = true;
6855 // TODO: The Symbol tree should be reorganized by namespaces
6857 // - Tree of all symbols within (stored without namespace)
6858 // - Tree of sub-namespaces
6860 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6862 int nsLen = strlen(nameSpace);
6864 // Start at the name space prefix
6865 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6867 char * s = symbol.string;
6868 if(!strncmp(s, nameSpace, nsLen))
6870 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6873 for(c = strlen(s)-1; c >= 0; c--)
6878 if(!strcmp(namePart, name))
6880 // TODO: Error on ambiguity
6890 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6893 char nameSpace[1024];
6894 const char * namePart;
6895 bool gotColon = false;
6897 nameSpace[0] = '\0';
6898 for(c = strlen(name)-1; c >= 0; c--)
6905 namePart = name+c+1;
6906 while(c >= 0 && name[c] == ':') c--;
6909 // Try an exact match first
6910 Symbol symbol = (Symbol)tree.FindString(name);
6914 // Namespace specified
6915 memcpy(nameSpace, name, c + 1);
6918 return ScanWithNameSpace(tree, nameSpace, namePart);
6922 // Looking for a global symbol, e.g. ::Sleep()
6923 Symbol symbol = (Symbol)tree.FindString(namePart);
6928 // Name only (no namespace specified)
6929 Symbol symbol = (Symbol)tree.FindString(namePart);
6932 return ScanWithNameSpace(tree, "", namePart);
6937 static void ProcessDeclaration(Declaration decl);
6939 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6942 //Time startTime = GetTime();
6944 // Optimize this later? Do this before/less?
6946 Symbol symbol = null;
6947 // First, check if the identifier is declared inside the function
6948 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6950 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6952 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6958 strcpy(curName, thisNameSpace);
6959 strcat(curName, "::");
6960 strcat(curName, name);
6961 // Try to resolve in current namespace first
6962 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6965 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6968 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6970 if(symbol || ctx == endContext) break;
6972 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6974 if(symbol.pointerExternal.type == functionExternal)
6976 FunctionDefinition function = symbol.pointerExternal.function;
6978 // Modified this recently...
6979 Context tmpContext = curContext;
6981 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6982 curContext = tmpContext;
6984 symbol.pointerExternal.symbol = symbol;
6987 DeclareType(symbol.type, true, true);
6989 ast->Insert(curExternal.prev, symbol.pointerExternal);
6991 symbol.id = curExternal.symbol.idCode;
6994 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6996 ast->Move(symbol.pointerExternal, curExternal.prev);
6997 symbol.id = curExternal.symbol.idCode;
7001 //findSymbolTotalTime += GetTime() - startTime;
7006 static void GetTypeSpecs(Type type, OldList * specs)
7008 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
7013 if(type._class.registered)
7015 if(!type._class.registered.dataType)
7016 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
7017 GetTypeSpecs(type._class.registered.dataType, specs);
7021 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
7022 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
7023 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
7024 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
7025 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
7026 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
7027 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
7028 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
7031 ListAdd(specs, MkSpecifier(INT)); break;
7035 static void PrintArraySize(Type arrayType, char * string)
7040 if(arrayType.enumClass)
7041 strcat(size, arrayType.enumClass.string);
7042 else if(arrayType.arraySizeExp)
7043 PrintExpression(arrayType.arraySizeExp, size);
7045 strcat(string, size);
7048 // WARNING : This function expects a null terminated string since it recursively concatenate...
7049 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
7053 if(printConst && type.constant)
7054 strcat(string, "const ");
7059 Symbol c = type._class;
7060 bool isObjectBaseClass = !c || !c.string || !strcmp(c.string, "class");
7061 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
7062 // look into merging with thisclass ?
7063 if(type.classObjectType == typedObject && isObjectBaseClass)
7064 strcat(string, "typed_object");
7065 else if(type.classObjectType == anyObject && isObjectBaseClass)
7066 strcat(string, "any_object");
7070 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
7072 if(type.byReference)
7073 strcat(string, " &");
7076 case voidType: strcat(string, "void"); break;
7077 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
7078 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
7079 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
7080 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
7081 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
7082 case _BoolType: strcat(string, "_Bool"); break;
7083 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
7084 case floatType: strcat(string, "float"); break;
7085 case doubleType: strcat(string, "double"); break;
7089 strcat(string, "struct ");
7090 strcat(string, type.enumName);
7092 else if(type.typeName)
7093 strcat(string, type.typeName);
7097 strcat(string, "struct { ");
7098 for(member = type.members.first; member; member = member.next)
7100 PrintType(member, string, true, fullName);
7101 strcat(string,"; ");
7109 strcat(string, "union ");
7110 strcat(string, type.enumName);
7112 else if(type.typeName)
7113 strcat(string, type.typeName);
7116 strcat(string, "union ");
7117 strcat(string,"(unnamed)");
7123 strcat(string, "enum ");
7124 strcat(string, type.enumName);
7126 else if(type.typeName)
7127 strcat(string, type.typeName);
7129 strcat(string, "int"); // "enum");
7132 strcat(string, "...");
7135 strcat(string, "subclass(");
7136 strcat(string, type._class ? type._class.string : "int");
7137 strcat(string, ")");
7140 strcat(string, type.templateParameter.identifier.string);
7143 strcat(string, "thisclass");
7146 strcat(string, "__builtin_va_list");
7152 static void PrintName(Type type, char * string, bool fullName)
7154 if(type.name && type.name[0])
7157 strcat(string, type.name);
7160 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7161 if(name) name += 2; else name = type.name;
7162 strcat(string, name);
7167 static void PrintAttribs(Type type, char * string)
7171 if(type.dllExport) strcat(string, "dllexport ");
7172 if(type.attrStdcall) strcat(string, "stdcall ");
7176 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7178 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7180 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7181 PrintAttribs(type, string);
7182 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7183 strcat(string, " const");
7184 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7185 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7186 strcat(string, " (");
7187 if(type.kind == pointerType)
7189 if(type.type.kind == functionType || type.type.kind == methodType)
7190 PrintAttribs(type.type, string);
7192 if(type.kind == pointerType)
7194 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7195 strcat(string, "*");
7197 strcat(string, " *");
7199 if(printConst && type.constant && type.kind == pointerType)
7200 strcat(string, " const");
7203 PrintTypeSpecs(type, string, fullName, printConst);
7206 static void PostPrintType(Type type, char * string, bool fullName)
7208 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7209 strcat(string, ")");
7210 if(type.kind == arrayType)
7211 PrintArraySize(type, string);
7212 else if(type.kind == functionType)
7215 strcat(string, "(");
7216 for(param = type.params.first; param; param = param.next)
7218 PrintType(param, string, true, fullName);
7219 if(param.next) strcat(string, ", ");
7221 strcat(string, ")");
7223 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7224 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7228 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7230 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7232 PrePrintType(type, string, fullName, null, printConst);
7234 if(type.thisClass || (printName && type.name && type.name[0]))
7235 strcat(string, " ");
7236 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7238 Symbol _class = type.thisClass;
7239 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7241 if(type.classObjectType == classPointer)
7242 strcat(string, "class");
7244 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7246 else if(_class && _class.string)
7248 String s = _class.string;
7253 char * name = RSearchString(s, "::", strlen(s), true, false);
7254 if(name) name += 2; else name = s;
7255 strcat(string, name);
7258 strcat(string, "::");
7261 if(printName && type.name)
7262 PrintName(type, string, fullName);
7263 PostPrintType(type, string, fullName);
7264 if(type.bitFieldCount)
7267 sprintf(count, ":%d", type.bitFieldCount);
7268 strcat(string, count);
7272 void PrintType(Type type, char * string, bool printName, bool fullName)
7274 _PrintType(type, string, printName, fullName, true);
7277 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7279 _PrintType(type, string, printName, fullName, false);
7282 static Type FindMember(Type type, char * string)
7285 for(memberType = type.members.first; memberType; memberType = memberType.next)
7287 if(!memberType.name)
7289 Type subType = FindMember(memberType, string);
7293 else if(!strcmp(memberType.name, string))
7299 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7302 for(memberType = type.members.first; memberType; memberType = memberType.next)
7304 if(!memberType.name)
7306 Type subType = FindMember(memberType, string);
7309 *offset += memberType.offset;
7313 else if(!strcmp(memberType.name, string))
7315 *offset += memberType.offset;
7322 public bool GetParseError() { return parseError; }
7324 Expression ParseExpressionString(char * expression)
7328 fileInput = TempFile { };
7329 fileInput.Write(expression, 1, strlen(expression));
7330 fileInput.Seek(0, start);
7333 parsedExpression = null;
7335 expression_yyparse();
7338 return parsedExpression;
7341 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7343 Identifier id = exp.identifier;
7344 Method method = null;
7345 Property prop = null;
7346 DataMember member = null;
7347 ClassProperty classProp = null;
7349 if(_class && _class.type == enumClass)
7351 NamedLink64 value = null;
7352 Class enumClass = eSystem_FindClass(privateModule, "enum");
7356 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7358 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7359 for(value = e.values.first; value; value = value.next)
7361 if(!strcmp(value.name, id.string))
7366 exp.isConstant = true;
7367 if(inCompiler || inPreCompiler || inDebugger)
7370 FreeExpContents(exp);
7372 exp.type = constantExp;
7373 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7374 sprintf(constant, FORMAT64D, value.data);
7376 sprintf(constant, FORMAT64HEX, value.data);
7377 exp.constant = CopyString(constant);
7379 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7380 exp.expType = MkClassType(baseClass.fullName);
7388 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7390 ProcessMethodType(method);
7397 // TOCHECK: Put it back to what it was...
7398 // methodClass = _class;
7399 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7404 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7407 ProcessPropertyType(prop);
7408 exp.expType = prop.dataType;
7409 if(prop.dataType) prop.dataType.refCount++;
7412 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7414 if(!member.dataType)
7415 member.dataType = ProcessTypeString(member.dataTypeString, false);
7416 exp.expType = member.dataType;
7417 if(member.dataType) member.dataType.refCount++;
7420 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7422 if(!classProp.dataType)
7423 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7425 if(classProp.constant)
7427 FreeExpContents(exp);
7429 exp.isConstant = true;
7430 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7432 //char constant[256];
7433 exp.type = stringExp;
7434 exp.constant = QMkString((char *)(uintptr)classProp.Get(_class));
7439 exp.type = constantExp;
7440 sprintf(constant, "%d", (int)classProp.Get(_class));
7441 exp.constant = CopyString(constant);
7449 exp.expType = classProp.dataType;
7450 if(classProp.dataType) classProp.dataType.refCount++;
7456 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7458 BinaryTree * tree = &nameSpace.functions;
7459 GlobalData data = (GlobalData)tree->FindString(name);
7463 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7465 data = ScanGlobalData(child, name);
7473 static GlobalData FindGlobalData(char * name)
7476 NameSpace * nameSpace;
7477 nameSpace = globalData;
7478 for(c = 0; name[c]; c++)
7480 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7482 NameSpace * newSpace;
7483 char * spaceName = new char[c - start + 1];
7484 strncpy(spaceName, name + start, c - start);
7485 spaceName[c-start] = '\0';
7486 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7490 nameSpace = newSpace;
7491 if(name[c] == ':') c++;
7497 return ScanGlobalData(nameSpace, name + start);
7502 static int definedExpStackPos;
7503 static void * definedExpStack[512];
7505 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7506 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7508 Expression prev = checkedExp.prev, next = checkedExp.next;
7510 FreeExpContents(checkedExp);
7511 FreeType(checkedExp.expType);
7512 FreeType(checkedExp.destType);
7514 *checkedExp = *newExp;
7518 checkedExp.prev = prev;
7519 checkedExp.next = next;
7522 void ApplyAnyObjectLogic(Expression e)
7524 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7526 char debugExpString[4096];
7527 debugExpString[0] = '\0';
7528 PrintExpression(e, debugExpString);
7531 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7533 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7534 //ellipsisDestType = destType;
7537 Type type = e.expType;
7538 Class _class = null;
7539 //Type destType = e.destType;
7541 if(type.kind == classType && type._class && type._class.registered)
7543 _class = type._class.registered;
7545 else if(type.kind == subClassType)
7547 _class = FindClass("ecere::com::Class").registered;
7551 char string[1024] = "";
7554 PrintTypeNoConst(type, string, false, true);
7555 classSym = FindClass(string);
7556 if(classSym) _class = classSym.registered;
7559 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...
7560 (!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))) ||
7561 destType.byReference)))
7563 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7565 Expression checkedExp = e, newExp;
7567 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7569 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7571 if(checkedExp.type == extensionCompoundExp)
7573 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7576 checkedExp = checkedExp.list->last;
7578 else if(checkedExp.type == castExp)
7579 checkedExp = checkedExp.cast.exp;
7582 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7584 newExp = checkedExp.op.exp2;
7585 checkedExp.op.exp2 = null;
7586 FreeExpContents(checkedExp);
7588 if(e.expType && e.expType.passAsTemplate)
7591 ComputeTypeSize(e.expType);
7592 sprintf(size, "%d", e.expType.size);
7593 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7594 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7595 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7598 ReplaceExpContents(checkedExp, newExp);
7599 e.byReference = true;
7601 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7603 Expression checkedExp; //, newExp;
7606 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7608 e.type == identifierExp ||
7609 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7610 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7611 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7614 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7616 Context context = PushContext();
7618 OldList * specs = MkList();
7619 char typeString[1024];
7620 Expression newExp { };
7622 typeString[0] = '\0';
7625 //if(e.destType) e.destType.refCount++;
7626 // if(exp.expType) exp.expType.refCount++;
7629 newExp.expType = null;
7631 PrintTypeNoConst(e.expType, typeString, false, true);
7632 decl = SpecDeclFromString(typeString, specs, null);
7633 newExp.destType = ProcessType(specs, decl);
7635 curContext = context;
7637 // We need a current compound for this
7641 OldList * stmts = MkList();
7642 e.type = extensionCompoundExp;
7643 sprintf(name, "__internalValue%03X", internalValueCounter++);
7644 if(!curCompound.compound.declarations)
7645 curCompound.compound.declarations = MkList();
7646 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7647 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7648 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7649 e.compound = MkCompoundStmt(null, stmts);
7652 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7655 e.compound = MkCompoundStmt(
7656 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7657 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7659 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7663 Type type = e.destType;
7665 CopyTypeInto(e.destType, type);
7666 e.destType.refCount = 1;
7667 e.destType.classObjectType = none;
7671 e.compound.compound.context = context;
7672 PopContext(context);
7673 curContext = context.parent;
7677 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7679 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7681 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7683 if(checkedExp.type == extensionCompoundExp)
7685 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7688 checkedExp = checkedExp.list->last;
7690 else if(checkedExp.type == castExp)
7691 checkedExp = checkedExp.cast.exp;
7694 Expression operand { };
7695 operand = *checkedExp;
7697 checkedExp.destType = ProcessTypeString("void *", false);
7698 checkedExp.expType = checkedExp.destType;
7699 checkedExp.destType.refCount++;
7701 checkedExp.type = opExp;
7702 checkedExp.op.op = '&';
7703 checkedExp.op.exp1 = null;
7704 checkedExp.op.exp2 = operand;
7706 //newExp = MkExpOp(null, '&', checkedExp);
7708 //ReplaceExpContents(checkedExp, newExp);
7715 // If expression type is a simple class, make it an address
7716 // FixReference(e, true);
7719 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7720 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7721 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7723 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"))
7725 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7729 Expression thisExp { };
7732 thisExp.prev = null;
7733 thisExp.next = null;
7736 e.type = bracketsExp;
7737 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7738 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7739 ((Expression)e.list->first).byReference = true;
7741 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7743 e.expType = thisExp.expType;
7744 e.expType.refCount++;
7749 CopyTypeInto(e.expType, thisExp.expType);
7750 e.expType.byReference = false;
7751 e.expType.refCount = 1;
7753 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7754 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7756 e.expType.classObjectType = none;
7761 // TOFIX: Try this for a nice IDE crash!
7763 // The other way around
7766 if(destType && e.expType &&
7767 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7768 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7769 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7771 if(destType.kind == ellipsisType)
7773 Compiler_Error($"Unspecified type\n");
7775 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7777 bool byReference = e.expType.byReference;
7778 Expression thisExp { };
7780 OldList * specs = MkList();
7781 char typeString[1024]; // Watch buffer overruns
7783 ClassObjectType backupClassObjectType;
7784 bool backupByReference;
7786 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7791 backupClassObjectType = type.classObjectType;
7792 backupByReference = type.byReference;
7794 type.classObjectType = none;
7795 type.byReference = false;
7797 typeString[0] = '\0';
7798 PrintType(type, typeString, false, true);
7799 decl = SpecDeclFromString(typeString, specs, null);
7801 type.classObjectType = backupClassObjectType;
7802 type.byReference = backupByReference;
7805 thisExp.prev = null;
7806 thisExp.next = null;
7809 if( ( type.kind == classType && type._class && type._class.registered &&
7810 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7811 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7812 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7813 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7815 bool passAsTemplate = thisExp.destType.passAsTemplate;
7818 destType.refCount++;
7823 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7826 CopyTypeInto(t, thisExp.destType);
7827 t.passAsTemplate = false;
7828 FreeType(thisExp.destType);
7829 thisExp.destType = t;
7832 CopyTypeInto(t, destType);
7833 t.passAsTemplate = passAsTemplate;
7836 destType.refCount = 0;
7839 CopyTypeInto(e.expType, type);
7840 if(type.passAsTemplate)
7842 e.expType.classObjectType = none;
7843 e.expType.passAsTemplate = false;
7845 e.expType.byReference = false;
7846 e.expType.refCount = 1;
7851 e.cast.typeName = MkTypeName(specs, decl);
7852 e.cast.exp = thisExp;
7853 e.byReference = true;
7859 FreeType(e.destType);
7861 e.destType = destType;
7862 destType.refCount++;
7867 void ApplyLocation(Expression exp, Location loc)
7873 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7874 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7880 for(e = exp.list->first; e; e = e.next)
7881 ApplyLocation(e, loc);
7888 for(e = exp.index.index->first; e; e = e.next)
7889 ApplyLocation(e, loc);
7892 ApplyLocation(exp.index.exp, loc);
7895 if(exp.call.arguments)
7898 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7899 ApplyLocation(arg, loc);
7902 ApplyLocation(exp.call.exp, loc);
7907 ApplyLocation(exp.member.exp, loc);
7911 ApplyLocation(exp.cast.exp, loc);
7917 for(e = exp.cond.exp->first; e; e = e.next)
7918 ApplyLocation(e, loc);
7921 ApplyLocation(exp.cond.cond, loc);
7922 if(exp.cond.elseExp)
7923 ApplyLocation(exp.cond.elseExp, loc);
7927 ApplyLocation(exp.vaArg.exp, loc);
7934 void ProcessExpressionType(Expression exp)
7936 bool unresolved = false;
7937 Location oldyylloc = yylloc;
7938 bool notByReference = false;
7940 char debugExpString[4096];
7941 debugExpString[0] = '\0';
7942 PrintExpression(exp, debugExpString);
7944 if(!exp || exp.expType)
7947 //eSystem_Logf("%s\n", expString);
7949 // Testing this here
7955 Identifier id = exp.identifier;
7956 if(!id || !topContext) return;
7958 // DOING THIS LATER NOW...
7959 if(id._class && id._class.name)
7961 id.classSym = id._class.symbol; // FindClass(id._class.name);
7962 /* TODO: Name Space Fix ups
7964 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7968 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7970 exp.expType = ProcessTypeString("Module", true);
7974 if(!strcmp(id.string, "__runtimePlatform"))
7976 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7979 else if(strstr(id.string, "__ecereClass") == id.string)
7981 exp.expType = ProcessTypeString("ecere::com::Class", true);
7984 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7986 // Added this here as well
7987 ReplaceClassMembers(exp, thisClass);
7988 if(exp.type != identifierExp)
7990 ProcessExpressionType(exp);
7994 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7999 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
8000 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
8001 if(!symbol/* && exp.destType*/)
8003 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
8009 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
8010 if(exp.type != identifierExp)
8012 ProcessExpressionType(exp);
8016 // Static methods called from inside the _class
8017 else if(currentClass && !id._class)
8019 if(ResolveIdWithClass(exp, currentClass, true))
8022 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
8026 // If we manage to resolve this symbol
8029 Type type = symbol.type;
8030 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
8032 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
8034 Context context = SetupTemplatesContext(_class);
8035 type = ReplaceThisClassType(_class);
8036 FinishTemplatesContext(context);
8037 if(type) type.refCount = 0; // We'll be incrementing it right below...
8040 FreeSpecifier(id._class);
8043 id.string = CopyString(symbol.string);
8050 // Commented this out, it was making non-constant enum parameters seen as constant
8051 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
8052 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
8053 // Add missing cases here... enum Classes...
8054 exp.isConstant = true;
8056 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
8057 if(symbol.isParam || !strcmp(id.string, "this"))
8059 if(_class && _class.type == structClass && !type.declaredWithStruct)
8060 exp.byReference = true;
8062 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
8063 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
8064 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
8065 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
8067 Identifier id = exp.identifier;
8068 exp.type = bracketsExp;
8069 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
8073 if(symbol.isIterator)
8075 if(symbol.isIterator == 3)
8077 exp.type = bracketsExp;
8078 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
8079 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
8081 ProcessExpressionType(exp);
8083 else if(symbol.isIterator != 4)
8085 exp.type = memberExp;
8086 exp.member.exp = MkExpIdentifier(exp.identifier);
8087 exp.member.exp.expType = exp.expType;
8088 /*if(symbol.isIterator == 6)
8089 exp.member.member = MkIdentifier("key");
8091 exp.member.member = MkIdentifier("data");
8093 ProcessExpressionType(exp);
8100 DefinedExpression definedExp = null;
8101 if(thisNameSpace && !(id._class && !id._class.name))
8104 strcpy(name, thisNameSpace);
8106 strcat(name, id.string);
8107 definedExp = eSystem_FindDefine(privateModule, name);
8110 definedExp = eSystem_FindDefine(privateModule, id.string);
8114 for(c = 0; c<definedExpStackPos; c++)
8115 if(definedExpStack[c] == definedExp)
8117 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
8119 Location backupYylloc = yylloc;
8120 File backInput = fileInput;
8121 definedExpStack[definedExpStackPos++] = definedExp;
8123 fileInput = TempFile { };
8124 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
8125 fileInput.Seek(0, start);
8128 parsedExpression = null;
8130 expression_yyparse();
8133 fileInput = backInput;
8135 yylloc = backupYylloc;
8137 if(parsedExpression)
8140 exp.type = bracketsExp;
8141 exp.list = MkListOne(parsedExpression);
8142 ApplyLocation(parsedExpression, yylloc);
8143 ProcessExpressionType(exp);
8144 definedExpStackPos--;
8147 definedExpStackPos--;
8153 Compiler_Error($"Recursion in defined expression %s\n", id.string);
8159 GlobalData data = null;
8160 if(thisNameSpace && !(id._class && !id._class.name))
8163 strcpy(name, thisNameSpace);
8165 strcat(name, id.string);
8166 data = FindGlobalData(name);
8169 data = FindGlobalData(id.string);
8172 DeclareGlobalData(data);
8173 exp.expType = data.dataType;
8174 if(data.dataType) data.dataType.refCount++;
8177 id.string = CopyString(data.fullName);
8178 FreeSpecifier(id._class);
8185 GlobalFunction function = null;
8186 if(thisNameSpace && !(id._class && !id._class.name))
8189 strcpy(name, thisNameSpace);
8191 strcat(name, id.string);
8192 function = eSystem_FindFunction(privateModule, name);
8195 function = eSystem_FindFunction(privateModule, id.string);
8200 id.string = CopyString(function.name);
8203 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8204 strcpy(name, "__ecereFunction_");
8205 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8206 if(DeclareFunction(function, name))
8209 id.string = CopyString(name);
8211 exp.expType = function.dataType;
8212 if(function.dataType) function.dataType.refCount++;
8214 FreeSpecifier(id._class);
8231 if(!exp.instance._class)
8233 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8235 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8239 //classSym = FindClass(exp.instance._class.fullName);
8240 //_class = classSym ? classSym.registered : null;
8242 ProcessInstantiationType(exp.instance);
8244 exp.isConstant = exp.instance.isConstant;
8247 if(_class.type == unitClass && _class.base.type != systemClass)
8250 Type destType = exp.destType;
8252 exp.destType = MkClassType(_class.base.fullName);
8253 exp.expType = MkClassType(_class.fullName);
8254 CheckExpressionType(exp, exp.destType, true);
8256 exp.destType = destType;
8258 exp.expType = MkClassType(_class.fullName);
8261 if(exp.instance._class)
8263 exp.expType = MkClassType(exp.instance._class.name);
8264 /*if(exp.expType._class && exp.expType._class.registered &&
8265 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8266 exp.expType.byReference = true;*/
8274 char * constant = exp.constant;
8282 if(constant[0] == '\'')
8284 if((int)((byte *)constant)[1] > 127)
8287 unichar ch = UTF8GetChar(constant + 1, &nb);
8288 if(nb < 2) ch = constant[1];
8290 exp.constant = PrintUInt(ch);
8291 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8292 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8293 type._class = FindClass("unichar");
8295 type.isSigned = false;
8299 type.kind = charType;
8300 type.isSigned = true;
8305 char * dot = strchr(constant, '.');
8306 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8310 exponent = strchr(constant, 'p');
8311 if(!exponent) exponent = strchr(constant, 'P');
8315 exponent = strchr(constant, 'e');
8316 if(!exponent) exponent = strchr(constant, 'E');
8321 if(strchr(constant, 'f') || strchr(constant, 'F'))
8322 type.kind = floatType;
8324 type.kind = doubleType;
8325 type.isSigned = true;
8329 bool isSigned = constant[0] == '-';
8331 int64 i64 = strtoll(constant, &endP, 0);
8332 uint64 ui64 = strtoull(constant, &endP, 0);
8333 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8346 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8350 else if(constant[0] != '0' || !constant[1])
8353 type.kind = is64Bit ? int64Type : intType;
8354 type.isSigned = isSigned;
8357 exp.isConstant = true;
8358 if(exp.destType && exp.destType.kind == doubleType)
8359 type.kind = doubleType;
8360 else if(exp.destType && exp.destType.kind == floatType)
8361 type.kind = floatType;
8362 else if(exp.destType && exp.destType.kind == int64Type)
8363 type.kind = int64Type;
8369 exp.isConstant = true; // Why wasn't this constant?
8377 kind = exp.wideString ? shortType : charType;
8379 isSigned = exp.wideString ? false : true;
8386 ProcessExpressionType(exp._new.size);
8391 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8393 DeclareType(exp.expType.type, false, false);
8397 ProcessExpressionType(exp._renew.size);
8398 ProcessExpressionType(exp._renew.exp);
8403 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8405 DeclareType(exp.expType.type, false, false);
8409 bool assign = false, boolResult = false, boolOps = false;
8410 Type type1 = null, type2 = null;
8411 bool useDestType = false, useSideType = false;
8412 Location oldyylloc = yylloc;
8413 bool useSideUnit = false;
8414 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8416 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8425 // Assignment Operators
8439 // boolean Operators
8441 // Expect boolean operators
8443 //boolResult = true;
8447 // Expect boolean operands
8458 // Gives boolean result
8490 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8496 /*// Implement speed etc.
8502 if(exp.op.op == '&')
8504 // Added this here earlier for Iterator address as key
8505 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8507 Identifier id = exp.op.exp2.identifier;
8508 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8509 if(symbol && symbol.isIterator == 2)
8511 exp.type = memberExp;
8512 exp.member.exp = exp.op.exp2;
8513 exp.member.member = MkIdentifier("key");
8515 exp.op.exp2.expType = symbol.type;
8516 symbol.type.refCount++;
8517 ProcessExpressionType(exp);
8521 // exp.op.exp2.usage.usageRef = true;
8525 //dummy.kind = TypeDummy;
8528 // Added this check here to use the dest type only for units derived from the base unit
8529 // So that untyped units will use the side unit as opposed to the untyped destination unit
8530 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8531 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8532 useDestType = false;
8534 if(destClass && useDestType &&
8535 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8537 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8539 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8540 exp.op.exp1.destType = exp.destType;
8541 exp.op.exp1.opDestType = true;
8543 exp.destType.refCount++;
8547 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8548 exp.op.exp1.destType = dummy;
8552 // TESTING THIS HERE...
8553 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8554 ProcessExpressionType(exp.op.exp1);
8555 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8557 exp.op.exp1.opDestType = false;
8559 // Fix for unit and ++ / --
8560 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8561 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8563 exp.op.exp2 = MkExpConstant("1");
8564 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8568 if(exp.op.exp1.destType == dummy)
8571 exp.op.exp1.destType = null;
8573 type1 = exp.op.exp1.expType;
8578 char expString[10240];
8579 expString[0] = '\0';
8580 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8584 exp.op.exp2.destType = exp.op.exp1.expType;
8585 if(exp.op.exp1.expType)
8586 exp.op.exp1.expType.refCount++;
8590 exp.op.exp2.destType = exp.destType;
8591 if(!exp.op.exp1 || exp.op.op != '&')
8592 exp.op.exp2.opDestType = true;
8594 exp.destType.refCount++;
8597 if(type1) type1.refCount++;
8598 exp.expType = type1;
8603 PrintExpression(exp.op.exp2, expString);
8605 if(type1 && type1.kind == pointerType)
8607 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 ||
8608 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8609 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8610 else if(exp.op.op == '=')
8612 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8613 exp.op.exp2.destType = type1;
8620 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8621 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/* ||
8622 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8625 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8626 exp.op.exp2.destType = type1;
8631 if(type1) type1.refCount++;
8632 exp.expType = type1;
8634 else if(destClass &&
8635 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8636 (destClass.type == enumClass && useDestType)))
8638 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8639 exp.op.exp2.destType = exp.destType;
8640 if(exp.op.op != '&')
8641 exp.op.exp2.opDestType = true;
8643 exp.destType.refCount++;
8647 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8648 exp.op.exp2.destType = dummy;
8652 // TESTING THIS HERE... (DANGEROUS)
8653 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8654 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8656 FreeType(exp.op.exp2.destType);
8657 exp.op.exp2.destType = type1;
8660 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8661 // Cannot lose the cast on a sizeof
8662 if(exp.op.op == SIZEOF)
8664 Expression e = exp.op.exp2;
8665 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8667 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8669 if(e.type == extensionCompoundExp)
8670 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8675 if(e.type == castExp && e.cast.exp)
8676 e.cast.exp.needCast = true;
8678 ProcessExpressionType(exp.op.exp2);
8679 exp.op.exp2.opDestType = false;
8680 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8682 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8684 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)
8686 if(exp.op.op != '=' && type1.type.kind == voidType)
8687 Compiler_Error($"void *: unknown size\n");
8689 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||
8690 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8691 (exp.op.exp2.expType._class.registered.type == normalClass ||
8692 exp.op.exp2.expType._class.registered.type == structClass ||
8693 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8695 if(exp.op.op == ADD_ASSIGN)
8696 Compiler_Error($"cannot add two pointers\n");
8698 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8699 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8701 if(exp.op.op == ADD_ASSIGN)
8702 Compiler_Error($"cannot add two pointers\n");
8706 char type1String[1024];
8707 char type2String[1024];
8708 type1String[0] = '\0';
8709 type2String[0] = '\0';
8711 PrintType(exp.op.exp2.expType, type1String, false, true);
8712 PrintType(type1, type2String, false, true);
8713 ChangeCh(expString, '\n', ' ');
8714 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8718 if(exp.op.exp2.destType == dummy)
8721 exp.op.exp2.destType = null;
8724 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8728 CopyTypeInto(type2, exp.op.exp2.expType);
8729 type2.isSigned = true;
8731 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8733 type2 = { kind = intType };
8735 type2.isSigned = true;
8739 type2 = exp.op.exp2.expType;
8740 if(type2) type2.refCount++;
8744 dummy.kind = voidType;
8746 if(exp.op.op == SIZEOF)
8753 exp.isConstant = true;
8755 // Get type of dereferenced pointer
8756 else if(exp.op.op == '*' && !exp.op.exp1)
8758 exp.expType = Dereference(type2);
8759 if(type2 && type2.kind == classType)
8760 notByReference = true;
8762 else if(exp.op.op == '&' && !exp.op.exp1)
8763 exp.expType = Reference(type2);
8770 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8771 exp.op.exp1.destType = MkClassType("bool");
8772 exp.op.exp1.destType.truth = true;
8773 if(!exp.op.exp1.expType)
8774 ProcessExpressionType(exp.op.exp1);
8776 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8777 FreeType(exp.op.exp1.expType);
8778 exp.op.exp1.expType = MkClassType("bool");
8779 exp.op.exp1.expType.truth = true;
8783 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8784 exp.op.exp2.destType = MkClassType("bool");
8785 exp.op.exp2.destType.truth = true;
8786 if(!exp.op.exp2.expType)
8787 ProcessExpressionType(exp.op.exp2);
8789 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8790 FreeType(exp.op.exp2.expType);
8791 exp.op.exp2.expType = MkClassType("bool");
8792 exp.op.exp2.expType.truth = true;
8795 else if(exp.op.exp1 && exp.op.exp2 &&
8798 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8799 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8800 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8801 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8803 if(type1 && type2 &&
8804 // If either both are class or both are not class
8805 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8807 // Added this check for enum subtraction to result in an int type:
8808 if(exp.op.op == '-' &&
8809 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8810 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8813 if(!type1._class.registered.dataType)
8814 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8815 if(!type2._class.registered.dataType)
8816 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8818 intType = ProcessTypeString(
8819 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8821 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8822 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8823 exp.op.exp1.destType = intType;
8824 exp.op.exp2.destType = intType;
8829 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8830 exp.op.exp2.destType = type1;
8832 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8833 exp.op.exp1.destType = type2;
8837 // Warning here for adding Radians + Degrees with no destination type
8838 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8839 type1._class.registered && type1._class.registered.type == unitClass &&
8840 type2._class.registered && type2._class.registered.type == unitClass &&
8841 type1._class.registered != type2._class.registered)
8842 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8843 type1._class.string, type2._class.string, type1._class.string);
8845 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8847 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8850 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8852 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8853 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8856 ProcessExpressionType(exp.op.exp1);
8858 if(type2.kind != pointerType)
8860 ProcessExpressionType(classExp);
8862 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8864 if(!exp.op.exp2.expType)
8868 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8872 ProcessExpressionType(exp.op.exp2);
8877 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)))
8879 if(type1.kind != classType && type1.type.kind == voidType)
8880 Compiler_Error($"void *: unknown size\n");
8881 exp.expType = type1;
8882 if(type1) type1.refCount++;
8884 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)))
8886 if(type2.kind != classType && type2.type.kind == voidType)
8887 Compiler_Error($"void *: unknown size\n");
8888 exp.expType = type2;
8889 if(type2) type2.refCount++;
8891 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8892 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8894 Compiler_Warning($"different levels of indirection\n");
8898 bool success = false;
8899 if(type1.kind == pointerType && type2.kind == pointerType)
8901 if(exp.op.op == '+')
8902 Compiler_Error($"cannot add two pointers\n");
8903 else if(exp.op.op == '-')
8905 // Pointer Subtraction gives integer
8906 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8915 if(type1.type.kind == templateType)
8917 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8920 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8922 ProcessExpressionType(classExp);
8924 exp.type = bracketsExp;
8925 exp.list = MkListOne(MkExpOp(
8926 MkExpBrackets(MkListOne(MkExpOp(
8927 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8929 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8930 MkExpMember(classExp, MkIdentifier("typeSize"))));
8932 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8941 if(!success && exp.op.exp1.type == constantExp)
8943 // If first expression is constant, try to match that first
8944 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8946 if(exp.expType) FreeType(exp.expType);
8947 exp.expType = exp.op.exp1.destType;
8948 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8951 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8953 if(exp.expType) FreeType(exp.expType);
8954 exp.expType = exp.op.exp2.destType;
8955 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8961 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8963 if(exp.expType) FreeType(exp.expType);
8964 exp.expType = exp.op.exp2.destType;
8965 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8968 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8970 if(exp.expType) FreeType(exp.expType);
8971 exp.expType = exp.op.exp1.destType;
8972 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8978 char expString1[10240];
8979 char expString2[10240];
8982 expString1[0] = '\0';
8983 expString2[0] = '\0';
8988 PrintExpression(exp.op.exp1, expString1);
8989 ChangeCh(expString1, '\n', ' ');
8990 PrintExpression(exp.op.exp2, expString2);
8991 ChangeCh(expString2, '\n', ' ');
8992 PrintType(exp.op.exp1.expType, type1, false, true);
8993 PrintType(exp.op.exp2.expType, type2, false, true);
8996 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
9000 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
9001 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9003 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9004 // Convert e.g. / 4 into / 4.0
9005 exp.op.exp1.destType = type2._class.registered.dataType;
9006 if(type2._class.registered.dataType)
9007 type2._class.registered.dataType.refCount++;
9008 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9009 exp.expType = type2;
9010 if(type2) type2.refCount++;
9012 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9014 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9015 // Convert e.g. / 4 into / 4.0
9016 exp.op.exp2.destType = type1._class.registered.dataType;
9017 if(type1._class.registered.dataType)
9018 type1._class.registered.dataType.refCount++;
9019 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9020 exp.expType = type1;
9021 if(type1) type1.refCount++;
9027 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9029 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9031 if(!type1._class.registered.dataType)
9032 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
9033 exp.op.exp2.destType = type1._class.registered.dataType;
9034 exp.op.exp2.destType.refCount++;
9036 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9039 type2 = exp.op.exp2.destType;
9040 if(type2) type2.refCount++;
9042 exp.expType = type2;
9046 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9048 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9050 if(!type2._class.registered.dataType)
9051 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
9052 exp.op.exp1.destType = type2._class.registered.dataType;
9053 exp.op.exp1.destType.refCount++;
9055 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9056 type1 = exp.op.exp1.destType;
9057 exp.expType = type1;
9061 // TESTING THIS NEW CODE
9062 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
9064 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
9065 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
9066 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
9068 // Convert the enum to an int instead for these operators
9069 if(op1IsEnum && exp.op.exp2.expType)
9071 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
9073 if(exp.expType) FreeType(exp.expType);
9074 exp.expType = exp.op.exp2.expType;
9075 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9079 else if(op2IsEnum && exp.op.exp1.expType)
9081 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
9083 if(exp.expType) FreeType(exp.expType);
9084 exp.expType = exp.op.exp1.expType;
9085 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9092 if(op1IsEnum && exp.op.exp2.expType)
9094 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
9096 if(exp.expType) FreeType(exp.expType);
9097 exp.expType = exp.op.exp1.expType;
9098 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9102 else if(op2IsEnum && exp.op.exp1.expType)
9104 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
9106 if(exp.expType) FreeType(exp.expType);
9107 exp.expType = exp.op.exp2.expType;
9108 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9117 // 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
9118 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
9119 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
9121 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9122 exp.op.exp1.destType = type2;
9125 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9127 if(exp.expType) FreeType(exp.expType);
9128 exp.expType = exp.op.exp1.destType;
9129 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9134 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9135 exp.op.exp2.destType = type1;
9139 // Maybe this was meant to be an enum...
9140 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9142 Type oldType = exp.op.exp2.expType;
9143 exp.op.exp2.expType = null;
9144 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9147 exp.op.exp2.expType = oldType;
9152 // TESTING THIS HERE... LATEST ADDITION
9153 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9155 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9156 exp.op.exp2.destType = type2._class.registered.dataType;
9157 if(type2._class.registered.dataType)
9158 type2._class.registered.dataType.refCount++;
9159 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9161 //exp.expType = type2._class.registered.dataType; //type2;
9162 //if(type2) type2.refCount++;
9165 // TESTING THIS HERE... LATEST ADDITION
9166 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9168 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9169 exp.op.exp1.destType = type1._class.registered.dataType;
9170 if(type1._class.registered.dataType)
9171 type1._class.registered.dataType.refCount++;
9172 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9173 exp.expType = type1._class.registered.dataType; //type1;
9174 if(type1) type1.refCount++;
9178 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9180 if(exp.expType) FreeType(exp.expType);
9181 exp.expType = exp.op.exp2.destType;
9182 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9184 else if(type1 && type2)
9186 char expString1[10240];
9187 char expString2[10240];
9188 char type1String[1024];
9189 char type2String[1024];
9190 expString1[0] = '\0';
9191 expString2[0] = '\0';
9192 type1String[0] = '\0';
9193 type2String[0] = '\0';
9196 PrintExpression(exp.op.exp1, expString1);
9197 ChangeCh(expString1, '\n', ' ');
9198 PrintExpression(exp.op.exp2, expString2);
9199 ChangeCh(expString2, '\n', ' ');
9200 PrintType(exp.op.exp1.expType, type1String, false, true);
9201 PrintType(exp.op.exp2.expType, type2String, false, true);
9204 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9206 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9208 exp.expType = exp.op.exp1.expType;
9209 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9211 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9213 exp.expType = exp.op.exp2.expType;
9214 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9222 // Maybe this was meant to be an enum...
9223 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9225 Type oldType = exp.op.exp1.expType;
9226 exp.op.exp1.expType = null;
9227 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9230 exp.op.exp1.expType = oldType;
9233 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9234 exp.op.exp1.destType = type2;
9237 // TESTING THIS HERE... LATEST ADDITION
9238 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9240 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9241 exp.op.exp1.destType = type1._class.registered.dataType;
9242 if(type1._class.registered.dataType)
9243 type1._class.registered.dataType.refCount++;
9246 // TESTING THIS HERE... LATEST ADDITION
9247 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9249 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9250 exp.op.exp2.destType = type2._class.registered.dataType;
9251 if(type2._class.registered.dataType)
9252 type2._class.registered.dataType.refCount++;
9256 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9258 if(exp.expType) FreeType(exp.expType);
9259 exp.expType = exp.op.exp1.destType;
9260 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9264 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9266 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9268 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9269 // Convert e.g. / 4 into / 4.0
9270 exp.op.exp1.destType = type2._class.registered.dataType;
9271 if(type2._class.registered.dataType)
9272 type2._class.registered.dataType.refCount++;
9273 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9275 if(exp.op.op == '!')
9277 exp.expType = MkClassType("bool");
9278 exp.expType.truth = true;
9282 exp.expType = type2;
9283 if(type2) type2.refCount++;
9286 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9288 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9290 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9291 // Convert e.g. / 4 into / 4.0
9292 exp.op.exp2.destType = type1._class.registered.dataType;
9293 if(type1._class.registered.dataType)
9294 type1._class.registered.dataType.refCount++;
9295 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9297 exp.expType = type1;
9298 if(type1) type1.refCount++;
9303 if(exp.op.exp1 && !exp.op.exp1.expType)
9305 char expString[10000];
9306 expString[0] = '\0';
9309 PrintExpression(exp.op.exp1, expString);
9310 ChangeCh(expString, '\n', ' ');
9313 Compiler_Error($"couldn't determine type of %s\n", expString);
9315 if(exp.op.exp2 && !exp.op.exp2.expType)
9317 char expString[10240];
9318 expString[0] = '\0';
9321 PrintExpression(exp.op.exp2, expString);
9322 ChangeCh(expString, '\n', ' ');
9325 Compiler_Error($"couldn't determine type of %s\n", expString);
9330 FreeType(exp.expType);
9331 exp.expType = MkClassType("bool");
9332 exp.expType.truth = true;
9335 if(exp.op.op != SIZEOF)
9336 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9337 (!exp.op.exp2 || exp.op.exp2.isConstant);
9339 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9341 DeclareType(exp.op.exp2.expType, false, false);
9344 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9345 Compiler_Warning($"deleting const qualified object\n");
9355 case extensionExpressionExp:
9358 exp.isConstant = true;
9359 for(e = exp.list->first; e; e = e.next)
9361 //bool inced = false;
9364 FreeType(e.destType);
9365 e.opDestType = exp.opDestType;
9366 e.destType = exp.destType;
9367 if(e.destType) { exp.destType.refCount++; /*e.destType.count++; inced = true;*/ }
9369 ProcessExpressionType(e);
9371 exp.destType.count--;*/
9372 if(!exp.expType && !e.next)
9374 exp.expType = e.expType;
9375 if(e.expType) e.expType.refCount++;
9378 exp.isConstant = false;
9381 // In case a cast became a member...
9382 e = exp.list->first;
9383 if(!e.next && e.type == memberExp)
9385 // Preserve prev, next
9386 Expression next = exp.next, prev = exp.prev;
9389 FreeType(exp.expType);
9390 FreeType(exp.destType);
9400 ProcessExpressionType(exp);
9407 exp.isConstant = true;
9409 ProcessExpressionType(exp.index.exp);
9410 if(!exp.index.exp.isConstant)
9411 exp.isConstant = false;
9413 if(exp.index.exp.expType)
9415 Type source = exp.index.exp.expType;
9416 if(source.kind == classType && source._class && source._class.registered)
9418 Class _class = source._class.registered;
9419 Class c = _class.templateClass ? _class.templateClass : _class;
9420 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9422 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9424 if(exp.index.index && exp.index.index->last)
9426 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9428 if(type.kind == classType) type.constant = true;
9429 else if(type.kind == pointerType)
9432 while(t.kind == pointerType) t = t.type;
9436 ((Expression)exp.index.index->last).destType = type;
9442 for(e = exp.index.index->first; e; e = e.next)
9444 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9446 if(e.destType) FreeType(e.destType);
9447 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9449 ProcessExpressionType(e);
9452 // Check if this type is int
9455 exp.isConstant = false;
9459 exp.expType = Dereference(exp.index.exp.expType);
9461 DeclareType(exp.expType, false, false);
9468 Type methodType = null;
9474 PrintExpression(exp.call.exp, name);
9475 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9477 //exp.call.exp.expType = null;
9478 PrintExpression(exp.call.exp, name);
9481 if(exp.call.exp.type == identifierExp)
9483 Expression idExp = exp.call.exp;
9484 Identifier id = idExp.identifier;
9485 if(!strcmp(id.string, "__builtin_frame_address"))
9487 exp.expType = ProcessTypeString("void *", true);
9488 if(exp.call.arguments && exp.call.arguments->first)
9489 ProcessExpressionType(exp.call.arguments->first);
9492 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9494 exp.expType = ProcessTypeString("int", true);
9495 if(exp.call.arguments && exp.call.arguments->first)
9496 ProcessExpressionType(exp.call.arguments->first);
9499 else if(!strcmp(id.string, "Max") ||
9500 !strcmp(id.string, "Min") ||
9501 !strcmp(id.string, "Sgn") ||
9502 !strcmp(id.string, "Abs"))
9504 Expression a = null;
9505 Expression b = null;
9506 Expression tempExp1 = null, tempExp2 = null;
9507 if((!strcmp(id.string, "Max") ||
9508 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9510 a = exp.call.arguments->first;
9511 b = exp.call.arguments->last;
9515 else if(exp.call.arguments->count == 1)
9517 a = exp.call.arguments->first;
9523 exp.call.arguments->Clear();
9524 idExp.identifier = null;
9526 FreeExpContents(exp);
9528 ProcessExpressionType(a);
9530 ProcessExpressionType(b);
9532 exp.type = bracketsExp;
9533 exp.list = MkList();
9535 if(a.expType && (!b || b.expType))
9537 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9539 // Use the simpleStruct name/ids for now...
9542 OldList * specs = MkList();
9543 OldList * decls = MkList();
9545 char temp1[1024], temp2[1024];
9547 GetTypeSpecs(a.expType, specs);
9549 if(a && !a.isConstant && a.type != identifierExp)
9551 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9552 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9553 tempExp1 = QMkExpId(temp1);
9554 tempExp1.expType = a.expType;
9556 a.expType.refCount++;
9557 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9559 if(b && !b.isConstant && b.type != identifierExp)
9561 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9562 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9563 tempExp2 = QMkExpId(temp2);
9564 tempExp2.expType = b.expType;
9566 b.expType.refCount++;
9567 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9570 decl = MkDeclaration(specs, decls);
9571 if(!curCompound.compound.declarations)
9572 curCompound.compound.declarations = MkList();
9573 curCompound.compound.declarations->Insert(null, decl);
9578 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9580 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9582 MkExpCondition(MkExpBrackets(MkListOne(
9583 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9584 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9585 exp.expType = a.expType;
9587 a.expType.refCount++;
9589 else if(!strcmp(id.string, "Abs"))
9592 MkExpCondition(MkExpBrackets(MkListOne(
9593 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9594 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9595 exp.expType = a.expType;
9597 a.expType.refCount++;
9599 else if(!strcmp(id.string, "Sgn"))
9601 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9603 MkExpCondition(MkExpBrackets(MkListOne(
9604 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9605 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9606 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9607 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9608 exp.expType = ProcessTypeString("int", false);
9611 FreeExpression(tempExp1);
9612 if(tempExp2) FreeExpression(tempExp2);
9626 if(!exp.call.exp.destType)
9628 exp.call.exp.destType = dummy;
9631 ProcessExpressionType(exp.call.exp);
9632 if(exp.call.exp.destType == dummy)
9635 exp.call.exp.destType = null;
9640 // Check argument types against parameter types
9641 functionType = exp.call.exp.expType;
9643 if(functionType && functionType.kind == TypeKind::methodType)
9645 methodType = functionType;
9646 functionType = methodType.method.dataType;
9648 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9649 // TOCHECK: Instead of doing this here could this be done per param?
9650 if(exp.call.exp.expType.usedClass)
9652 char typeString[1024];
9653 typeString[0] = '\0';
9655 Symbol back = functionType.thisClass;
9656 // Do not output class specifier here (thisclass was added to this)
9657 functionType.thisClass = null;
9658 PrintType(functionType, typeString, true, true);
9659 functionType.thisClass = back;
9661 if(strstr(typeString, "thisclass"))
9663 OldList * specs = MkList();
9666 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9668 decl = SpecDeclFromString(typeString, specs, null);
9670 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9671 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9672 exp.call.exp.expType.usedClass))
9673 thisClassParams = false;
9675 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9677 Class backupThisClass = thisClass;
9678 thisClass = exp.call.exp.expType.usedClass;
9679 ProcessDeclarator(decl);
9680 thisClass = backupThisClass;
9683 thisClassParams = true;
9685 functionType = ProcessType(specs, decl);
9686 functionType.refCount = 0;
9687 FinishTemplatesContext(context);
9689 // Mark parameters that were 'thisclass'
9692 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9693 p.wasThisClass = op.kind == thisClassType;
9697 FreeList(specs, FreeSpecifier);
9698 FreeDeclarator(decl);
9702 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9704 Type type = functionType.type;
9705 if(!functionType.refCount)
9707 functionType.type = null;
9708 FreeType(functionType);
9710 //methodType = functionType;
9711 functionType = type;
9713 if(functionType && functionType.kind != TypeKind::functionType)
9715 Compiler_Error($"called object %s is not a function\n", name);
9717 else if(functionType)
9719 bool emptyParams = false, noParams = false;
9720 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9721 Type type = functionType.params.first;
9722 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9724 Location oldyylloc = yylloc;
9726 if(!type) emptyParams = true;
9729 if(functionType.extraParam && e && functionType.thisClass)
9731 e.destType = MkClassType(functionType.thisClass.string);
9735 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9736 // Fixed #141 by adding '&& !functionType.extraParam'
9737 if(!functionType.staticMethod && !functionType.extraParam)
9739 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9740 memberExp.member.exp.expType._class)
9742 type = MkClassType(memberExp.member.exp.expType._class.string);
9747 type = functionType.params.first;
9752 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9754 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9755 type.byReference = functionType.byReference;
9756 type.typedByReference = functionType.typedByReference;
9759 // Allow manually passing a class for typed object
9760 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9764 type = functionType.params.first;
9772 if(type && type.kind == voidType)
9775 if(!type.refCount) FreeType(type);
9779 for( ; e; e = e.next)
9781 if(!type && !emptyParams)
9784 if(methodType && methodType.methodClass)
9785 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9786 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9787 noParams ? 0 : functionType.params.count);
9789 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9790 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9791 noParams ? 0 : functionType.params.count);
9795 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9797 Type templatedType = null;
9798 Class _class = methodType.usedClass;
9799 ClassTemplateParameter curParam = null;
9801 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9804 for(sClass = _class; sClass; sClass = sClass.base)
9806 if(sClass.templateClass) sClass = sClass.templateClass;
9808 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9810 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9813 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9815 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9816 id += nextClass.templateParams.count;
9825 if(curParam && _class.templateArgs[id].dataTypeString)
9827 bool constant = type.constant;
9828 ClassTemplateArgument arg = _class.templateArgs[id];
9830 Context context = SetupTemplatesContext(_class);
9833 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9834 templatedType = ProcessTypeString(arg.dataTypeString, false);
9835 FinishTemplatesContext(context);
9838 if(templatedType.kind == classType && constant) templatedType.constant = true;
9839 else if(templatedType.kind == pointerType)
9841 Type t = templatedType.type;
9842 while(t.kind == pointerType) t = t.type;
9843 if(constant) t.constant = constant;
9846 e.destType = templatedType;
9849 templatedType.passAsTemplate = true;
9850 // templatedType.refCount++;
9856 if(type) type.refCount++;
9861 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9863 e.destType = type.prev;
9864 e.destType.refCount++;
9869 if(type) type.refCount++;
9872 // Don't reach the end for the ellipsis
9873 if(type && type.kind != ellipsisType)
9875 Type next = type.next;
9876 if(!type.refCount) FreeType(type);
9881 if(type && type.kind != ellipsisType)
9883 if(methodType && methodType.methodClass)
9884 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9885 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9886 functionType.params.count + extra);
9888 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9889 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9890 functionType.params.count + extra);
9893 if(type && !type.refCount) FreeType(type);
9900 kind = TypeKind::functionType;
9903 if(exp.call.exp.type == identifierExp)
9905 char * string = exp.call.exp.identifier.string;
9909 Location oldyylloc = yylloc;
9911 yylloc = exp.call.exp.identifier.loc;
9912 if(strstr(string, "__builtin_") == string)
9916 functionType.returnType = exp.destType;
9917 exp.destType.refCount++;
9921 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9922 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9923 globalContext.symbols.Add((BTNode)symbol);
9924 if(strstr(symbol.string, "::"))
9925 globalContext.hasNameSpace = true;
9930 else if(exp.call.exp.type == memberExp)
9932 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9933 exp.call.exp.member.member.string);*/
9936 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9938 if(!functionType.returnType)
9940 functionType.returnType = Type
9947 if(functionType && functionType.kind == TypeKind::functionType)
9949 exp.expType = functionType.returnType;
9951 if(functionType.returnType)
9952 functionType.returnType.refCount++;
9954 if(!functionType.refCount)
9955 FreeType(functionType);
9958 if(exp.call.arguments)
9960 for(e = exp.call.arguments->first; e; e = e.next)
9961 ProcessExpressionType(e);
9968 Location oldyylloc = yylloc;
9970 Expression checkExp = exp.member.exp;
9973 if(checkExp.type == castExp)
9974 checkExp = checkExp.cast.exp;
9975 else if(checkExp.type == bracketsExp)
9976 checkExp = checkExp.list ? checkExp.list->first : null;
9981 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9982 exp.thisPtr = thisPtr;
9984 // DOING THIS LATER NOW...
9985 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9987 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9988 /* TODO: Name Space Fix ups
9989 if(!exp.member.member.classSym)
9990 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9994 ProcessExpressionType(exp.member.exp);
9995 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9996 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9998 exp.isConstant = false;
10001 exp.isConstant = exp.member.exp.isConstant;
10002 type = exp.member.exp.expType;
10006 if(type && (type.kind == templateType))
10008 Class _class = thisClass ? thisClass : currentClass;
10009 ClassTemplateParameter param = null;
10012 for(param = _class.templateParams.first; param; param = param.next)
10014 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
10018 if(param && param.defaultArg.member)
10020 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
10023 Expression expMember = exp.member.exp;
10025 OldList * specs = MkList();
10026 char thisClassTypeString[1024];
10028 FreeIdentifier(exp.member.member);
10030 ProcessExpressionType(argExp);
10033 char * colon = strstr(param.defaultArg.memberString, "::");
10036 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
10037 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
10040 strcpy(thisClassTypeString, _class.fullName);
10043 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
10045 exp.expType = ProcessType(specs, decl);
10046 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
10048 Class expClass = exp.expType._class.registered;
10049 Class cClass = null;
10050 int paramCount = 0;
10051 int lastParam = -1;
10053 char templateString[1024];
10054 ClassTemplateParameter param;
10055 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10056 for(cClass = expClass; cClass; cClass = cClass.base)
10059 for(param = cClass.templateParams.first; param; param = param.next)
10063 ClassTemplateArgument arg;
10064 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
10065 arg = expClass.templateArgs[id];
10067 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
10069 ClassTemplateParameter cParam;
10070 //int p = numParams - sClass.templateParams.count;
10073 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
10075 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
10077 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
10079 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10081 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
10082 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
10090 char argument[256];
10091 argument[0] = '\0';
10094 strcat(argument, arg.name.string);
10095 strcat(argument, " = ");
10101 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10102 char expString[1024];
10103 OldList * specs = MkList();
10104 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10106 char * string = PrintHexUInt64(arg.expression.ui64);
10107 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10110 ProcessExpressionType(exp);
10111 ComputeExpression(exp);
10112 expString[0] = '\0';
10113 PrintExpression(exp, expString);
10114 strcat(argument, expString);
10116 FreeExpression(exp);
10121 strcat(argument, arg.member.name);
10124 case TemplateParameterType::type:
10126 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10128 if(!strcmp(arg.dataTypeString, "thisclass"))
10129 strcat(argument, thisClassTypeString);
10131 strcat(argument, arg.dataTypeString);
10138 if(paramCount) strcat(templateString, ", ");
10139 if(lastParam != p - 1)
10141 strcat(templateString, param.name);
10142 strcat(templateString, " = ");
10144 strcat(templateString, argument);
10153 int len = strlen(templateString);
10154 if(templateString[len-1] == '>') templateString[len++] = ' ';
10155 templateString[len++] = '>';
10156 templateString[len++] = '\0';
10159 Context context = SetupTemplatesContext(_class);
10160 FreeType(exp.expType);
10161 exp.expType = ProcessTypeString(templateString, false);
10162 FinishTemplatesContext(context);
10166 if(!expMember.expType.isPointerType)
10167 expMember = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), expMember);
10168 // *([expType] *)(((byte *)(uintptr)[exp.member.exp]) + [argExp].member.offset)
10169 exp.type = bracketsExp;
10170 exp.list = MkListOne(MkExpOp(null, '*',
10173 exp.op.exp1 = null;
10175 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10176 MkExpBrackets(MkListOne(
10177 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
10180 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10182 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10187 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10188 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10190 type = ProcessTemplateParameterType(type.templateParameter);
10193 // TODO: *** This seems to be where we should add method support for all basic types ***
10194 if(type && (type.kind == templateType));
10195 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10196 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10197 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10198 (type.kind == pointerType && type.type.kind == charType)))
10200 Identifier id = exp.member.member;
10201 TypeKind typeKind = type.kind;
10202 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10203 if(typeKind == subClassType && exp.member.exp.type == classExp)
10205 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10206 typeKind = classType;
10211 if(typeKind == intType || typeKind == enumType)
10212 _class = eSystem_FindClass(privateModule, "int");
10215 if(type.kind == classType && type._class && type._class.registered)
10217 _class = type._class.registered;
10219 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10221 _class = FindClass("char *").registered;
10223 else if(type.kind == pointerType)
10225 _class = eSystem_FindClass(privateModule, "uintptr");
10226 FreeType(exp.expType);
10227 exp.expType = ProcessTypeString("uintptr", false);
10228 exp.byReference = true;
10232 char string[1024] = "";
10234 PrintTypeNoConst(type, string, false, true);
10235 classSym = FindClass(string);
10236 if(classSym) _class = classSym.registered;
10244 (exp.member.exp.type == identifierExp &&
10245 !strcmp(exp.member.exp.identifier.string, "this"));*/
10246 Property prop = null;
10247 Method method = null;
10248 DataMember member = null;
10249 Property revConvert = null;
10250 ClassProperty classProp = null;
10252 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10253 exp.member.memberType = propertyMember;
10255 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10256 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10258 if(typeKind != subClassType)
10260 // Prioritize data members over properties for "this"
10261 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10263 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10264 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10266 prop = eClass_FindProperty(_class, id.string, privateModule);
10270 if(!member && !prop)
10271 prop = eClass_FindProperty(_class, id.string, privateModule);
10272 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10273 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10274 exp.member.thisPtr = true;
10276 // Prioritize properties over data members otherwise
10279 bool useMemberForNonConst = false;
10280 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10283 prop = eClass_FindProperty(_class, id.string, null);
10285 useMemberForNonConst = prop && exp.destType &&
10286 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10287 !strncmp(prop.dataTypeString, "const ", 6);
10289 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10290 member = eClass_FindDataMember(_class, id.string, null, null, null);
10293 if((!prop || useMemberForNonConst) && !member)
10295 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10298 prop = eClass_FindProperty(_class, id.string, privateModule);
10300 useMemberForNonConst |= prop && exp.destType &&
10301 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10302 !strncmp(prop.dataTypeString, "const ", 6);
10304 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10305 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10311 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10318 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10319 method = eClass_FindMethod(_class, id.string, privateModule);
10320 if(!prop && !member && !method)
10322 if(typeKind == subClassType)
10324 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10327 exp.member.memberType = classPropertyMember;
10328 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10332 // Assume this is a class_data member
10333 char structName[1024];
10334 Identifier id = exp.member.member;
10335 Expression classExp = exp.member.exp;
10338 FreeType(classExp.expType);
10339 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10341 strcpy(structName, "__ecereClassData_");
10342 FullClassNameCat(structName, type._class.string, false);
10343 exp.type = pointerExp;
10344 exp.member.member = id;
10346 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10347 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10348 MkExpBrackets(MkListOne(MkExpOp(
10349 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10350 MkExpMember(classExp, MkIdentifier("data"))), '+',
10351 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10356 ProcessExpressionType(exp);
10362 // Check for reverse conversion
10363 // (Convert in an instantiation later, so that we can use
10364 // deep properties system)
10365 Symbol classSym = FindClass(id.string);
10368 Class convertClass = classSym.registered;
10370 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10375 //if(!exp.member.exp.destType)
10376 if(exp.member.exp.destType)
10377 FreeType(exp.member.exp.destType);
10379 if(method && !method._class.symbol)
10380 method._class.symbol = FindClass(method._class.fullName);
10381 if(prop && !prop._class.symbol)
10382 prop._class.symbol = FindClass(prop._class.fullName);
10384 exp.member.exp.destType = Type
10388 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10389 // wasThisClass = type ? type.wasThisClass : false;
10395 exp.member.memberType = propertyMember;
10397 ProcessPropertyType(prop);
10398 exp.expType = prop.dataType;
10399 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10402 CopyTypeInto(type, exp.expType);
10404 type.constant = true;
10405 exp.expType = type;
10407 else if(prop.dataType)
10408 prop.dataType.refCount++;
10412 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10414 FreeExpContents(exp);
10415 exp.type = identifierExp;
10416 exp.identifier = MkIdentifier("class");
10417 ProcessExpressionType(exp);
10421 exp.member.memberType = dataMember;
10422 DeclareStruct(_class.fullName, false);
10423 if(!member.dataType)
10425 Context context = SetupTemplatesContext(_class);
10426 member.dataType = ProcessTypeString(member.dataTypeString, false);
10427 FinishTemplatesContext(context);
10429 exp.expType = member.dataType;
10430 if(member.dataType) member.dataType.refCount++;
10432 else if(revConvert)
10434 exp.member.memberType = reverseConversionMember;
10435 exp.expType = MkClassType(revConvert._class.fullName);
10443 exp.type = identifierExp;
10444 exp.identifier = exp.member.member;
10447 exp.member.memberType = methodMember;
10449 if(!method.dataType)
10450 ProcessMethodType(method);
10458 // Tricky spot here... To use instance versus class virtual table
10459 // Put it back to what it was... What did we break?
10461 // Had to put it back for overriding Main of Thread global instance
10463 //exp.expType.methodClass = _class;
10464 exp.expType.methodClass = (id && id._class) ? _class : null;
10466 // Need the actual class used for templated classes
10467 exp.expType.usedClass = _class;
10469 else if(!classProp)
10471 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10473 FreeExpContents(exp);
10474 exp.type = identifierExp;
10475 exp.identifier = MkIdentifier("class");
10476 FreeType(exp.expType);
10477 exp.expType = MkClassType("ecere::com::Class");
10480 yylloc = exp.member.member.loc;
10481 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10483 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10486 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10490 tClass = type._class && type._class.registered ? type._class.registered : _class;
10491 while(tClass && !tClass.templateClass) tClass = tClass.base;
10493 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10496 ClassTemplateParameter curParam = null;
10499 for(sClass = tClass; sClass; sClass = sClass.base)
10502 if(sClass.templateClass) sClass = sClass.templateClass;
10503 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10505 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10507 for(sClass = sClass.base; sClass; sClass = sClass.base)
10508 id += sClass.templateParams.count;
10513 if(curParam) break;
10516 if(curParam && tClass.templateArgs[id].dataTypeString)
10518 ClassTemplateArgument arg = tClass.templateArgs[id];
10519 Context context = SetupTemplatesContext(tClass);
10520 bool constant = exp.expType.constant;
10521 /*if(!arg.dataType)
10522 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10523 FreeType(exp.expType);
10525 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10526 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10527 else if(exp.expType.kind == pointerType)
10529 Type t = exp.expType.type;
10530 while(t.kind == pointerType) t = t.type;
10531 if(constant) t.constant = constant;
10535 if(exp.expType.kind == thisClassType)
10537 FreeType(exp.expType);
10538 exp.expType = ReplaceThisClassType(_class);
10541 if(tClass.templateClass && (exp.expType.kind != templateType || (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType))))
10542 exp.expType.passAsTemplate = true;
10543 //exp.expType.refCount++;
10546 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10547 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10548 else if(exp.destType.kind == pointerType)
10550 Type t = exp.destType.type;
10551 while(t.kind == pointerType) t = t.type;
10552 if(constant) t.constant = constant;
10555 //exp.destType.refCount++;
10557 if(exp.destType.kind == thisClassType)
10559 FreeType(exp.destType);
10560 exp.destType = ReplaceThisClassType(_class);
10564 FinishTemplatesContext(context);
10567 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10568 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10571 ClassTemplateParameter curParam = null;
10574 for(sClass = tClass; sClass; sClass = sClass.base)
10577 if(sClass.templateClass) sClass = sClass.templateClass;
10578 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10580 if(curParam.type == TemplateParameterType::type &&
10581 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10583 for(sClass = sClass.base; sClass; sClass = sClass.base)
10584 id += sClass.templateParams.count;
10589 if(curParam) break;
10594 ClassTemplateArgument arg = tClass.templateArgs[id];
10595 Context context = SetupTemplatesContext(tClass);
10597 /*if(!arg.dataType)
10598 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10600 basicType = ProcessTypeString(arg.dataTypeString, false);
10603 if(basicType.kind == thisClassType)
10605 FreeType(basicType);
10606 basicType = ReplaceThisClassType(_class);
10609 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10610 if(tClass.templateClass)
10611 basicType.passAsTemplate = true;
10614 FreeType(exp.expType);
10616 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10617 //exp.expType.refCount++;
10620 exp.destType = exp.expType;
10621 exp.destType.refCount++;
10625 Expression newExp { };
10626 OldList * specs = MkList();
10628 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10630 if(exp.destType) exp.destType.refCount++;
10631 if(exp.expType) exp.expType.refCount++;
10632 exp.type = castExp;
10633 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10634 exp.cast.exp = newExp;
10635 //FreeType(exp.expType);
10636 //exp.expType = null;
10637 //ProcessExpressionType(sourceExp);
10640 FinishTemplatesContext(context);
10643 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10645 Class expClass = exp.expType._class.registered;
10648 Class cClass = null;
10650 int paramCount = 0;
10651 int lastParam = -1;
10652 char templateString[1024];
10653 ClassTemplateParameter param;
10654 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10655 while(cClass != expClass)
10658 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10661 for(param = cClass.templateParams.first; param; param = param.next)
10663 Class cClassCur = null;
10665 ClassTemplateParameter paramCur = null;
10666 ClassTemplateArgument arg;
10667 while(cClassCur != tClass && !paramCur)
10670 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10671 cClassCur = sClassCur;
10673 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10675 if(!strcmp(paramCur.name, param.name))
10683 if(paramCur && paramCur.type == TemplateParameterType::type)
10684 arg = tClass.templateArgs[cp];
10686 arg = expClass.templateArgs[p];
10689 char argument[256];
10690 argument[0] = '\0';
10693 strcat(argument, arg.name.string);
10694 strcat(argument, " = ");
10700 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10701 char expString[1024];
10702 OldList * specs = MkList();
10703 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10705 char * string = PrintHexUInt64(arg.expression.ui64);
10706 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10709 ProcessExpressionType(exp);
10710 ComputeExpression(exp);
10711 expString[0] = '\0';
10712 PrintExpression(exp, expString);
10713 strcat(argument, expString);
10715 FreeExpression(exp);
10720 strcat(argument, arg.member.name);
10723 case TemplateParameterType::type:
10725 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10726 strcat(argument, arg.dataTypeString);
10732 if(paramCount) strcat(templateString, ", ");
10733 if(lastParam != p - 1)
10735 strcat(templateString, param.name);
10736 strcat(templateString, " = ");
10738 strcat(templateString, argument);
10747 int len = strlen(templateString);
10748 if(templateString[len-1] == '>') templateString[len++] = ' ';
10749 templateString[len++] = '>';
10750 templateString[len++] = '\0';
10753 FreeType(exp.expType);
10755 Context context = SetupTemplatesContext(tClass);
10756 exp.expType = ProcessTypeString(templateString, false);
10757 FinishTemplatesContext(context);
10764 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10766 else if(type && (type.kind == structType || type.kind == unionType))
10768 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10771 exp.expType = memberType;
10773 memberType.refCount++;
10778 char expString[10240];
10779 expString[0] = '\0';
10780 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10781 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10784 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10786 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10788 Identifier id = exp.member.member;
10789 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10792 FreeType(exp.expType);
10793 exp.expType = ReplaceThisClassType(_class);
10797 yylloc = oldyylloc;
10800 // Convert x->y into (*x).y
10803 Type destType = exp.destType;
10805 // DOING THIS LATER NOW...
10806 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10808 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10809 /* TODO: Name Space Fix ups
10810 if(!exp.member.member.classSym)
10811 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10815 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10816 exp.type = memberExp;
10819 ProcessExpressionType(exp);
10826 //ComputeExpression(exp);
10828 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10829 if(classSym && classSym.registered)
10831 if(classSym.registered.type == noHeadClass)
10835 DeclareStruct(classSym.string, false);
10836 FreeSpecifier(exp._class);
10837 exp.type = typeSizeExp;
10838 FullClassNameCat(name, classSym.string, false);
10839 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10843 if(classSym.registered.fixed)
10845 FreeSpecifier(exp._class);
10846 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10847 exp.type = constantExp;
10851 char className[1024];
10852 strcpy(className, "__ecereClass_");
10853 FullClassNameCat(className, classSym.string, true);
10854 //MangleClassName(className);
10856 DeclareClass(classSym, className);
10858 FreeExpContents(exp);
10859 exp.type = pointerExp;
10860 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10861 exp.member.member = MkIdentifier("structSize");
10869 kind = intSizeType;
10871 // exp.isConstant = true;
10876 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10881 kind = intSizeType;
10883 exp.isConstant = true;
10885 DeclareType(type, false, false);
10891 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10893 FreeType(exp.cast.exp.destType);
10894 exp.cast.exp.destType = type;
10896 type.casted = true;
10897 ProcessExpressionType(exp.cast.exp);
10898 type.casted = false;
10900 exp.expType = type;
10903 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10904 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10906 void * prev = exp.prev, * next = exp.next;
10907 Type expType = exp.cast.exp.destType;
10908 Expression castExp = exp.cast.exp;
10909 Type destType = exp.destType;
10911 if(expType) expType.refCount++;
10913 //FreeType(exp.destType);
10914 FreeType(exp.expType);
10915 FreeTypeName(exp.cast.typeName);
10918 FreeType(exp.expType);
10919 FreeType(exp.destType);
10921 exp.expType = expType;
10922 exp.destType = destType;
10932 exp.isConstant = exp.cast.exp.isConstant;
10937 case extensionInitializerExp:
10939 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10940 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10941 // ProcessInitializer(exp.initializer.initializer, type);
10942 exp.expType = type;
10947 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10948 ProcessExpressionType(exp.vaArg.exp);
10949 exp.expType = type;
10955 Type t = exp.destType;
10956 if(t && !exp.destType.casted)
10959 CopyTypeInto(t, exp.destType);
10965 exp.isConstant = true;
10967 FreeType(exp.cond.cond.destType);
10968 exp.cond.cond.destType = MkClassType("bool");
10969 exp.cond.cond.destType.truth = true;
10970 ProcessExpressionType(exp.cond.cond);
10971 if(!exp.cond.cond.isConstant)
10972 exp.isConstant = false;
10973 for(e = exp.cond.exp->first; e; e = e.next)
10977 FreeType(e.destType);
10979 if(e.destType) e.destType.refCount++;
10981 ProcessExpressionType(e);
10984 exp.expType = e.expType;
10985 if(e.expType) e.expType.refCount++;
10988 exp.isConstant = false;
10991 FreeType(exp.cond.elseExp.destType);
10992 // Added this check if we failed to find an expType
10993 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10996 exp.cond.elseExp.destType = t ? t : exp.expType;
10998 if(exp.cond.elseExp.destType)
10999 exp.cond.elseExp.destType.refCount++;
11000 ProcessExpressionType(exp.cond.elseExp);
11002 // FIXED THIS: Was done before calling process on elseExp
11003 if(!exp.cond.elseExp.isConstant)
11004 exp.isConstant = false;
11009 case extensionCompoundExp:
11011 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
11013 Statement last = exp.compound.compound.statements->last;
11014 if(last.type == expressionStmt && last.expressions && last.expressions->last)
11016 ((Expression)last.expressions->last).destType = exp.destType;
11018 exp.destType.refCount++;
11020 ProcessStatement(exp.compound);
11021 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
11023 exp.expType.refCount++;
11029 Specifier spec = exp._classExp.specifiers->first;
11030 if(spec && spec.type == nameSpecifier)
11032 exp.expType = MkClassType(spec.name);
11033 exp.expType.kind = subClassType;
11034 exp.byReference = true;
11038 exp.expType = MkClassType("ecere::com::Class");
11039 exp.byReference = true;
11045 Class _class = thisClass ? thisClass : currentClass;
11048 Identifier id = exp.classData.id;
11049 char structName[1024];
11050 Expression classExp;
11051 strcpy(structName, "__ecereClassData_");
11052 FullClassNameCat(structName, _class.fullName, false);
11053 exp.type = pointerExp;
11054 exp.member.member = id;
11055 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
11056 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
11058 classExp = MkExpIdentifier(MkIdentifier("class"));
11060 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
11061 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
11062 MkExpBrackets(MkListOne(MkExpOp(
11063 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
11064 MkExpMember(classExp, MkIdentifier("data"))), '+',
11065 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
11068 ProcessExpressionType(exp);
11076 const char * typeString = null;
11077 char typeStringBuf[1024];
11078 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
11079 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
11081 Class templateClass = exp.destType._class.registered;
11082 typeString = templateClass.templateArgs[2].dataTypeString;
11086 // Guess type from expressions in the array
11088 for(e = exp.list->first; e; e = e.next)
11090 ProcessExpressionType(e);
11093 if(!type) { type = e.expType; type.refCount++; }
11096 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11097 if(!MatchTypeExpression(e, type, null, false, true))
11103 e = exp.list->first;
11104 ProcessExpressionType(e);
11107 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
11108 if(!MatchTypeExpression(e, type, null, false, true))
11110 FreeType(e.expType);
11121 FreeType(e.expType);
11128 typeStringBuf[0] = '\0';
11129 PrintTypeNoConst(type, typeStringBuf, false, true);
11130 typeString = typeStringBuf;
11138 (Container)& (struct BuiltInContainer)
11140 ._vTbl = class(BuiltInContainer)._vTbl,
11141 ._class = class(BuiltInContainer),
11143 .data = (int[]){ 1, 7, 3, 4, 5 },
11145 .type = class(int),
11148 char templateString[1024];
11149 OldList * initializers = MkList();
11150 OldList * structInitializers = MkList();
11151 OldList * specs = MkList();
11153 Declarator decl = SpecDeclFromString(typeString, specs, null);
11154 sprintf(templateString, "Container<%s>", typeString);
11159 type = ProcessTypeString(typeString, false);
11160 while((e = exp.list->first))
11162 exp.list->Remove(e);
11165 ProcessExpressionType(e);
11166 ListAdd(initializers, MkInitializerAssignment(e));
11172 DeclareStruct("ecere::com::BuiltInContainer", false);
11174 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11175 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11176 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11177 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11178 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11179 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11180 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11181 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11182 MkInitializerList(initializers))));
11183 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11184 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11185 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11186 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11187 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11188 exp.expType = ProcessTypeString(templateString, false);
11189 exp.type = bracketsExp;
11190 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11192 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11193 MkInitializerList(structInitializers)))));
11194 ProcessExpressionType(expExt);
11198 exp.expType = ProcessTypeString("Container", false);
11199 Compiler_Error($"Couldn't determine type of array elements\n");
11205 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11207 FreeType(exp.expType);
11208 exp.expType = ReplaceThisClassType(thisClass);
11211 // Resolve structures here
11212 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11214 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11215 // TODO: Fix members reference...
11218 if(exp.expType.kind != enumType)
11221 String enumName = CopyString(exp.expType.enumName);
11223 // Fixed a memory leak on self-referencing C structs typedefs
11224 // by instantiating a new type rather than simply copying members
11225 // into exp.expType
11226 FreeType(exp.expType);
11227 exp.expType = Type { };
11228 exp.expType.kind = symbol.type.kind;
11229 exp.expType.refCount++;
11230 exp.expType.enumName = enumName;
11232 exp.expType.members = symbol.type.members;
11233 for(member = symbol.type.members.first; member; member = member.next)
11238 NamedLink64 member;
11239 for(member = symbol.type.members.first; member; member = member.next)
11241 NamedLink64 value { name = CopyString(member.name) };
11242 exp.expType.members.Add(value);
11249 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11250 else if(exp.destType && !exp.destType.keepCast)
11252 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11253 exp.needTemplateCast = 1;
11255 if(exp.destType.kind == voidType);
11256 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11258 // Warn for casting unrelated types to/from struct classes
11259 bool invalidCast = false;
11260 if(inCompiler && exp.destType.count && exp.expType)
11262 Class c1 = (exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
11263 Class c2 = (exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
11264 if(c1 && c1.type != structClass) c1 = null;
11265 if(c2 && c2.type != structClass) c2 = null;
11266 if((c1 && !exp.expType.byReference && !c2 && !exp.destType.isPointerType) || (c2 && !exp.destType.byReference && !c1 && !exp.expType.isPointerType))
11267 invalidCast = true;
11269 if(!exp.destType.count || unresolved || invalidCast)
11274 if(exp.destType.kind != ellipsisType)
11280 char expString[10240];
11281 expString[0] = '\0';
11283 PrintType(exp.destType, type2, false, true);
11285 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11287 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11288 else if(exp.type != dummyExp)
11289 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11294 char expString[10240] ;
11295 expString[0] = '\0';
11296 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11299 Compiler_Error($"unresolved identifier %s\n", expString);
11300 else if(exp.type != dummyExp)
11301 Compiler_Error($"couldn't determine type of %s\n", expString);
11312 PrintType(exp.expType, type1, false, true);
11313 PrintType(exp.destType, type2, false, true);
11316 //CheckExpressionType(exp, exp.destType, false);
11318 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11319 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11320 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11323 char expString[10240];
11324 expString[0] = '\0';
11325 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11328 CheckExpressionType(exp, exp.destType, false, true);
11330 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11331 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11332 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11333 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11334 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11337 Compiler_Error($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11339 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11342 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11345 FreeType(exp.expType);
11346 exp.destType.refCount++;
11347 exp.expType = exp.destType;
11353 // Cast function pointers to void * as eC already checked compatibility
11354 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11355 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11357 Expression nbExp = GetNonBracketsExp(exp);
11358 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11360 Expression e = MoveExpContents(exp);
11361 exp.cast.exp = MkExpBrackets(MkListOne(e));
11362 exp.type = castExp;
11363 exp.cast.exp.destType = exp.destType;
11364 if(exp.destType) exp.destType.refCount++;
11365 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11369 else if(unresolved)
11371 if(exp.identifier._class && exp.identifier._class.name)
11372 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11373 else if(exp.identifier.string && exp.identifier.string[0])
11374 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11376 else if(!exp.expType && exp.type != dummyExp)
11378 char expString[10240];
11379 expString[0] = '\0';
11380 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11381 Compiler_Error($"couldn't determine type of %s\n", expString);
11384 // Let's try to support any_object & typed_object here:
11386 ApplyAnyObjectLogic(exp);
11388 // Mark nohead classes as by reference, unless we're casting them to an integral type
11389 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11390 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11391 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11392 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11394 exp.byReference = true;
11396 yylloc = oldyylloc;
11399 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11401 // THIS CODE WILL FIND NEXT MEMBER...
11404 *curMember = (*curMember).next;
11406 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11408 *curMember = subMemberStack[--(*subMemberStackPos)];
11409 *curMember = (*curMember).next;
11412 // SKIP ALL PROPERTIES HERE...
11413 while((*curMember) && (*curMember).isProperty)
11414 *curMember = (*curMember).next;
11416 if(subMemberStackPos)
11418 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11420 subMemberStack[(*subMemberStackPos)++] = *curMember;
11422 *curMember = (*curMember).members.first;
11423 while(*curMember && (*curMember).isProperty)
11424 *curMember = (*curMember).next;
11432 if(subMemberStackPos && *subMemberStackPos)
11434 *curMember = subMemberStack[--(*subMemberStackPos)];
11435 *curMember = (*curMember).next;
11439 Class lastCurClass = *curClass;
11441 if(*curClass == _class) break; // REACHED THE END
11443 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11444 *curMember = (*curClass).membersAndProperties.first;
11447 while((*curMember) && (*curMember).isProperty)
11448 *curMember = (*curMember).next;
11449 if(subMemberStackPos)
11451 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11453 subMemberStack[(*subMemberStackPos)++] = *curMember;
11455 *curMember = (*curMember).members.first;
11456 while(*curMember && (*curMember).isProperty)
11457 *curMember = (*curMember).next;
11465 static void ProcessInitializer(Initializer init, Type type)
11469 case expInitializer:
11470 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11472 // TESTING THIS FOR SHUTTING = 0 WARNING
11473 if(init.exp && !init.exp.destType)
11475 FreeType(init.exp.destType);
11476 init.exp.destType = type;
11477 if(type) type.refCount++;
11481 ProcessExpressionType(init.exp);
11482 init.isConstant = init.exp.isConstant;
11488 Expression exp = init.exp;
11489 Instantiation inst = exp.instance;
11490 MembersInit members;
11492 init.type = listInitializer;
11493 init.list = MkList();
11497 for(members = inst.members->first; members; members = members.next)
11499 if(members.type == dataMembersInit)
11502 for(member = members.dataMembers->first; member; member = member.next)
11504 ListAdd(init.list, member.initializer);
11505 member.initializer = null;
11508 // Discard all MembersInitMethod
11511 FreeExpression(exp);
11513 case listInitializer:
11516 Type initializerType = null;
11517 Class curClass = null;
11518 DataMember curMember = null;
11519 DataMember subMemberStack[256];
11520 int subMemberStackPos = 0;
11522 if(type && type.kind == arrayType)
11523 initializerType = Dereference(type);
11524 else if(type && (type.kind == structType || type.kind == unionType))
11525 initializerType = type.members.first;
11527 for(i = init.list->first; i; i = i.next)
11529 if(type && type.kind == classType && type._class && type._class.registered)
11531 // 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)
11532 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11533 // TODO: Generate error on initializing a private data member this way from another module...
11536 if(!curMember.dataType)
11537 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11538 initializerType = curMember.dataType;
11541 ProcessInitializer(i, initializerType);
11542 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11543 initializerType = initializerType.next;
11545 init.isConstant = false;
11548 if(type && type.kind == arrayType)
11549 FreeType(initializerType);
11551 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11553 Compiler_Error($"Assigning list initializer to non list\n");
11560 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11564 case baseSpecifier:
11566 if(spec.specifier == THISCLASS)
11570 spec.type = nameSpecifier;
11571 spec.name = ReplaceThisClass(thisClass);
11572 spec.symbol = FindClass(spec.name);
11573 ProcessSpecifier(spec, declareStruct);
11578 case nameSpecifier:
11580 Symbol symbol = FindType(curContext, spec.name);
11582 DeclareType(symbol.type, true, true);
11583 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11584 DeclareStruct(spec.name, false);
11587 case enumSpecifier:
11592 for(e = spec.list->first; e; e = e.next)
11595 ProcessExpressionType(e.exp);
11598 // Fall through for IDE type processing
11602 case structSpecifier:
11603 case unionSpecifier:
11605 if(spec.definitions)
11608 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11610 ProcessClass(spec.definitions, symbol);
11613 for(def = spec.definitions->first; def; def = def.next)
11615 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11616 ProcessDeclaration(def.decl);
11623 case classSpecifier:
11625 Symbol classSym = FindClass(spec.name);
11626 if(classSym && classSym.registered && classSym.registered.type == structClass)
11627 DeclareStruct(spec.name, false);
11635 static void ProcessDeclarator(Declarator decl)
11639 case identifierDeclarator:
11640 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11642 FreeSpecifier(decl.identifier._class);
11643 decl.identifier._class = null;
11646 case arrayDeclarator:
11648 ProcessExpressionType(decl.array.exp);
11649 case structDeclarator:
11650 case bracketsDeclarator:
11651 case functionDeclarator:
11652 case pointerDeclarator:
11653 case extendedDeclarator:
11654 case extendedDeclaratorEnd:
11655 if(decl.declarator)
11656 ProcessDeclarator(decl.declarator);
11657 if(decl.type == functionDeclarator)
11659 Identifier id = GetDeclId(decl);
11660 if(id && id._class)
11664 qualifiers = MkListOne(id._class);
11667 if(!decl.function.parameters)
11668 decl.function.parameters = MkList();
11669 decl.function.parameters->Insert(null, param);
11672 if(decl.function.parameters)
11676 for(param = decl.function.parameters->first; param; param = param.next)
11678 if(param.qualifiers && param.qualifiers->first)
11680 Specifier spec = param.qualifiers->first;
11681 if(spec && spec.specifier == TYPED_OBJECT)
11683 Declarator d = param.declarator;
11686 qualifiers = MkListOne(MkSpecifier(VOID));
11687 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11689 if(d.type != pointerDeclarator)
11690 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11692 FreeList(param.qualifiers, FreeSpecifier);
11694 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11695 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11697 decl.function.parameters->Insert(param, newParam);
11700 else if(spec && spec.specifier == ANY_OBJECT)
11702 Declarator d = param.declarator;
11704 FreeList(param.qualifiers, FreeSpecifier);
11706 param.qualifiers = MkListOne(MkSpecifier(VOID));
11707 if(d.type != pointerDeclarator)
11708 param.qualifiers->Insert(null, MkSpecifier(CONST));
11709 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11711 else if(spec.specifier == THISCLASS)
11715 spec.type = nameSpecifier;
11716 spec.name = ReplaceThisClass(thisClass);
11717 spec.symbol = FindClass(spec.name);
11718 ProcessSpecifier(spec, false);
11723 if(param.declarator)
11724 ProcessDeclarator(param.declarator);
11732 static void ProcessDeclaration(Declaration decl)
11737 case initDeclaration:
11739 bool declareStruct = false;
11741 lineNum = decl.pos.line;
11742 column = decl.pos.col;
11745 if(decl.declarators)
11749 for(d = decl.declarators->first; d; d = d.next)
11751 Type type, subType;
11752 ProcessDeclarator(d.declarator);
11754 type = ProcessType(decl.specifiers, d.declarator);
11758 ProcessInitializer(d.initializer, type);
11760 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11762 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11763 d.initializer.exp.type == instanceExp)
11765 if(type.kind == classType && type._class ==
11766 d.initializer.exp.expType._class)
11768 Instantiation inst = d.initializer.exp.instance;
11769 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11771 d.initializer.exp.instance = null;
11772 if(decl.specifiers)
11773 FreeList(decl.specifiers, FreeSpecifier);
11774 FreeList(decl.declarators, FreeInitDeclarator);
11778 decl.type = instDeclaration;
11783 for(subType = type; subType;)
11785 if(subType.kind == classType)
11787 declareStruct = true;
11790 else if(subType.kind == pointerType)
11792 else if(subType.kind == arrayType)
11793 subType = subType.arrayType;
11803 if(decl.specifiers)
11806 for(s = decl.specifiers->first; s; s = s.next)
11808 ProcessSpecifier(s, declareStruct);
11813 case instDeclaration:
11815 ProcessInstantiationType(decl.inst);
11818 case structDeclaration:
11822 bool declareStruct = false;
11824 if(decl.declarators)
11826 for(d = decl.declarators->first; d; d = d.next)
11828 Type type = ProcessType(decl.specifiers, d.declarator);
11830 ProcessDeclarator(d);
11831 for(subType = type; subType;)
11833 if(subType.kind == classType)
11835 declareStruct = true;
11838 else if(subType.kind == pointerType)
11840 else if(subType.kind == arrayType)
11841 subType = subType.arrayType;
11848 if(decl.specifiers)
11850 for(spec = decl.specifiers->first; spec; spec = spec.next)
11851 ProcessSpecifier(spec, declareStruct);
11858 static FunctionDefinition curFunction;
11860 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11862 char propName[1024], propNameM[1024];
11863 char getName[1024], setName[1024];
11866 DeclareProperty(prop, setName, getName);
11868 // eInstance_FireWatchers(object, prop);
11869 strcpy(propName, "__ecereProp_");
11870 FullClassNameCat(propName, prop._class.fullName, false);
11871 strcat(propName, "_");
11872 // strcat(propName, prop.name);
11873 FullClassNameCat(propName, prop.name, true);
11874 //MangleClassName(propName);
11876 strcpy(propNameM, "__ecerePropM_");
11877 FullClassNameCat(propNameM, prop._class.fullName, false);
11878 strcat(propNameM, "_");
11879 // strcat(propNameM, prop.name);
11880 FullClassNameCat(propNameM, prop.name, true);
11881 //MangleClassName(propNameM);
11883 if(prop.isWatchable)
11886 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11887 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11888 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11891 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11892 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11893 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11899 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11900 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11901 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11904 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11905 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11906 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11909 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11910 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11911 curFunction.propSet.fireWatchersDone = true;
11914 static void ProcessStatement(Statement stmt)
11918 lineNum = stmt.pos.line;
11919 column = stmt.pos.col;
11924 ProcessStatement(stmt.labeled.stmt);
11927 // This expression should be constant...
11928 if(stmt.caseStmt.exp)
11930 FreeType(stmt.caseStmt.exp.destType);
11931 stmt.caseStmt.exp.destType = curSwitchType;
11932 if(curSwitchType) curSwitchType.refCount++;
11933 ProcessExpressionType(stmt.caseStmt.exp);
11934 ComputeExpression(stmt.caseStmt.exp);
11936 if(stmt.caseStmt.stmt)
11937 ProcessStatement(stmt.caseStmt.stmt);
11941 if(stmt.compound.context)
11946 Statement prevCompound = curCompound;
11947 Context prevContext = curContext;
11949 if(!stmt.compound.isSwitch)
11950 curCompound = stmt;
11951 curContext = stmt.compound.context;
11953 if(stmt.compound.declarations)
11955 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11956 ProcessDeclaration(decl);
11958 if(stmt.compound.statements)
11960 for(s = stmt.compound.statements->first; s; s = s.next)
11961 ProcessStatement(s);
11964 curContext = prevContext;
11965 curCompound = prevCompound;
11969 case expressionStmt:
11972 if(stmt.expressions)
11974 for(exp = stmt.expressions->first; exp; exp = exp.next)
11975 ProcessExpressionType(exp);
11983 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11984 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11985 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11986 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11988 ProcessExpressionType(exp);
11990 if(stmt.ifStmt.stmt)
11991 ProcessStatement(stmt.ifStmt.stmt);
11992 if(stmt.ifStmt.elseStmt)
11993 ProcessStatement(stmt.ifStmt.elseStmt);
11998 Type oldSwitchType = curSwitchType;
11999 if(stmt.switchStmt.exp)
12002 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
12012 e.exp.destType = destType;
12015 ProcessExpressionType(exp);
12018 curSwitchType = exp.expType;
12021 ProcessStatement(stmt.switchStmt.stmt);
12022 curSwitchType = oldSwitchType;
12027 if(stmt.whileStmt.exp)
12031 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
12032 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
12033 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
12034 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
12036 ProcessExpressionType(exp);
12039 if(stmt.whileStmt.stmt)
12040 ProcessStatement(stmt.whileStmt.stmt);
12045 if(stmt.doWhile.exp)
12049 if(stmt.doWhile.exp->last)
12051 FreeType(((Expression)stmt.doWhile.exp->last).destType);
12052 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
12053 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
12055 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
12057 ProcessExpressionType(exp);
12060 if(stmt.doWhile.stmt)
12061 ProcessStatement(stmt.doWhile.stmt);
12067 if(stmt.forStmt.init)
12068 ProcessStatement(stmt.forStmt.init);
12070 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
12072 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
12073 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
12074 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
12077 if(stmt.forStmt.check)
12078 ProcessStatement(stmt.forStmt.check);
12079 if(stmt.forStmt.increment)
12081 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
12082 ProcessExpressionType(exp);
12085 if(stmt.forStmt.stmt)
12086 ProcessStatement(stmt.forStmt.stmt);
12091 Identifier id = stmt.forEachStmt.id;
12092 OldList * exp = stmt.forEachStmt.exp;
12093 OldList * filter = stmt.forEachStmt.filter;
12094 Statement block = stmt.forEachStmt.stmt;
12095 char iteratorType[1024];
12098 bool isBuiltin = exp && exp->last &&
12099 (((Expression)exp->last).type == ExpressionType::arrayExp ||
12100 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
12101 Expression arrayExp;
12102 const char * typeString = null;
12103 int builtinCount = 0;
12105 for(e = exp ? exp->first : null; e; e = e.next)
12109 FreeType(e.destType);
12110 e.destType = ProcessTypeString("Container", false);
12112 if(!isBuiltin || e.next)
12113 ProcessExpressionType(e);
12116 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
12117 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
12118 eClass_IsDerived(source._class.registered, containerClass)))
12120 Class _class = source ? source._class.registered : null;
12122 Expression expIt = null;
12123 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
12124 Class arrayClass = eSystem_FindClass(privateModule, "Array");
12125 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
12126 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
12130 stmt.type = compoundStmt;
12132 stmt.compound.context = Context { };
12133 stmt.compound.context.parent = curContext;
12134 curContext = stmt.compound.context;
12137 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
12139 Class mapClass = eSystem_FindClass(privateModule, "Map");
12140 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
12141 isCustomAVLTree = true;
12142 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
12144 else */if(eClass_IsDerived(source._class.registered, mapClass))
12147 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
12148 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
12150 Class listClass = eSystem_FindClass(privateModule, "List");
12152 isList = eClass_IsDerived(source._class.registered, listClass);
12155 if(inCompiler && isArray)
12158 OldList * specs = MkList();
12159 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12160 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12161 stmt.compound.declarations = MkListOne(
12162 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12163 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12164 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12165 MkInitializerAssignment(MkExpBrackets(exp))))));
12170 char typeStringBuf[1024];
12172 // TODO: Merge this code?
12173 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12174 if(((Expression)exp->last).type == castExp)
12176 TypeName typeName = ((Expression)exp->last).cast.typeName;
12178 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12181 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12182 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12183 arrayExp.destType._class.registered.templateArgs)
12185 Class templateClass = arrayExp.destType._class.registered;
12186 typeString = templateClass.templateArgs[2].dataTypeString;
12188 else if(arrayExp.list)
12190 // Guess type from expressions in the array
12192 for(e = arrayExp.list->first; e; e = e.next)
12194 ProcessExpressionType(e);
12197 if(!type) { type = e.expType; type.refCount++; }
12200 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12201 if(!MatchTypeExpression(e, type, null, false, true))
12207 e = arrayExp.list->first;
12208 ProcessExpressionType(e);
12211 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12212 if(!MatchTypeExpression(e, type, null, false, true))
12214 FreeType(e.expType);
12225 FreeType(e.expType);
12232 typeStringBuf[0] = '\0';
12233 PrintType(type, typeStringBuf, false, true);
12234 typeString = typeStringBuf;
12242 OldList * initializers = MkList();
12244 OldList * specs = MkList();
12249 builtinCount = arrayExp.list->count;
12250 type = ProcessTypeString(typeString, false);
12251 while((e = arrayExp.list->first))
12253 arrayExp.list->Remove(e);
12256 ProcessExpressionType(e);
12258 ListAdd(initializers, MkInitializerAssignment(e));
12261 delete arrayExp.list;
12263 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12265 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12266 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12268 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12270 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12271 ), MkInitializerList(initializers)))));
12272 FreeList(exp, FreeExpression);
12274 else if(arrayExp.list)
12277 type = ProcessTypeString(typeString, false);
12278 for(e = arrayExp.list->first; e; e = e.next)
12282 ProcessExpressionType(e);
12289 arrayExp.expType = ProcessTypeString("Container", false);
12290 Compiler_Error($"Couldn't determine type of array elements\n");
12295 OldList * specs = MkList();
12297 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12298 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12299 stmt.compound.declarations = MkListOne(
12300 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12301 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12302 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12303 MkInitializerAssignment(MkExpBrackets(exp))))));
12306 else if(inCompiler && isLinkList && !isList)
12309 OldList * specs = MkList();
12310 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12311 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12312 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12313 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12314 MkInitializerAssignment(MkExpBrackets(exp))))));
12316 /*else if(isCustomAVLTree)
12319 OldList * specs = MkList();
12320 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12321 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12322 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12323 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12324 MkInitializerAssignment(MkExpBrackets(exp))))));
12326 else if(inCompiler && _class.templateArgs)
12329 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12331 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12333 stmt.compound.declarations = MkListOne(
12334 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12335 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12336 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12340 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12344 // Reparent sub-contexts in this statement
12348 if(block.compound.context)
12349 block.compound.context.parent = stmt.compound.context;
12352 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12353 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12354 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12355 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12358 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12359 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12362 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12363 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12366 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12367 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12370 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12371 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12374 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12375 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12377 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12380 case expressionStmt:
12386 case badDeclarationStmt:
12387 case fireWatchersStmt:
12388 case stopWatchingStmt:
12396 block = MkIfStmt(filter, block, null);
12400 stmt.compound.statements = MkListOne(MkForStmt(
12401 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12402 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12403 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12404 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12406 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12407 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12408 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12413 //OldList * specs = MkList();
12414 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12416 sprintf(count, "%d", builtinCount);
12418 stmt.compound.statements = MkListOne(MkForStmt(
12419 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12420 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12421 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12422 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12426 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12427 stmt.compound.statements = MkListOne(MkForStmt(
12428 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12429 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12430 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12431 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12434 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12435 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12436 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12438 else if(isLinkList && !isList)
12440 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12441 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12442 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12443 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12445 stmt.compound.statements = MkListOne(MkForStmt(
12446 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12447 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12448 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12453 OldList * specs = MkList();
12454 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12455 stmt.compound.statements = MkListOne(MkForStmt(
12456 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12457 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12458 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12459 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12460 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12463 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12464 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12465 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12467 /*else if(isCustomAVLTree)
12469 stmt.compound.statements = MkListOne(MkForStmt(
12470 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12471 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12472 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12473 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12476 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12477 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12478 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12482 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12483 MkIdentifier("Next")), null)), block));
12485 ProcessExpressionType(expIt);
12486 if(stmt.compound.declarations->first)
12487 ProcessDeclaration(stmt.compound.declarations->first);
12490 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12492 ProcessStatement(stmt);
12495 ProcessStatement(stmt.forEachStmt.stmt);
12497 curContext = stmt.compound.context.parent;
12502 Compiler_Error($"Expression is not a container\n");
12515 if(stmt.expressions)
12517 for(exp = stmt.expressions->first; exp; exp = exp.next)
12521 if(curFunction && !curFunction.type)
12522 curFunction.type = ProcessType(
12523 curFunction.specifiers, curFunction.declarator);
12524 FreeType(exp.destType);
12525 // TODO: current property if not compiling
12526 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12527 if(exp.destType) exp.destType.refCount++;
12529 ProcessExpressionType(exp);
12534 case badDeclarationStmt:
12536 ProcessDeclaration(stmt.decl);
12542 if(stmt.asmStmt.inputFields)
12544 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12545 if(field.expression)
12546 ProcessExpressionType(field.expression);
12548 if(stmt.asmStmt.outputFields)
12550 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12551 if(field.expression)
12552 ProcessExpressionType(field.expression);
12554 if(stmt.asmStmt.clobberedFields)
12556 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12558 if(field.expression)
12559 ProcessExpressionType(field.expression);
12566 PropertyWatch propWatch;
12567 OldList * watches = stmt._watch.watches;
12568 Expression object = stmt._watch.object;
12569 Expression watcher = stmt._watch.watcher;
12571 ProcessExpressionType(watcher);
12573 ProcessExpressionType(object);
12577 if(watcher || thisClass)
12579 External external = curExternal;
12580 Context context = curContext;
12582 stmt.type = expressionStmt;
12583 stmt.expressions = MkList();
12585 curExternal = external.prev;
12587 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12589 ClassFunction func;
12590 char watcherName[1024];
12591 Class watcherClass = watcher ?
12592 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12593 External createdExternal;
12595 // Create a declaration above
12596 External externalDecl = MkExternalDeclaration(null);
12597 ast->Insert(curExternal.prev, externalDecl);
12599 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12600 if(propWatch.deleteWatch)
12601 strcat(watcherName, "_delete");
12605 for(propID = propWatch.properties->first; propID; propID = propID.next)
12607 strcat(watcherName, "_");
12608 strcat(watcherName, propID.string);
12612 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12614 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12615 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12616 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12617 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12618 ProcessClassFunctionBody(func, propWatch.compound);
12619 propWatch.compound = null;
12621 //afterExternal = afterExternal ? afterExternal : curExternal;
12623 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12624 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12626 createdExternal.symbol.idCode = external.symbol.idCode;
12628 curExternal = createdExternal;
12629 ProcessFunction(createdExternal.function);
12632 // Create a declaration above
12634 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12635 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12636 externalDecl.declaration = decl;
12637 if(decl.symbol && !decl.symbol.pointerExternal)
12638 decl.symbol.pointerExternal = externalDecl;
12641 if(propWatch.deleteWatch)
12643 OldList * args = MkList();
12644 ListAdd(args, CopyExpression(object));
12645 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12646 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12647 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12651 Class _class = object.expType._class.registered;
12654 for(propID = propWatch.properties->first; propID; propID = propID.next)
12656 char propName[1024];
12657 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12660 char getName[1024], setName[1024];
12661 OldList * args = MkList();
12663 DeclareProperty(prop, setName, getName);
12665 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12666 strcpy(propName, "__ecereProp_");
12667 FullClassNameCat(propName, prop._class.fullName, false);
12668 strcat(propName, "_");
12669 // strcat(propName, prop.name);
12670 FullClassNameCat(propName, prop.name, true);
12672 ListAdd(args, CopyExpression(object));
12673 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12674 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12675 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12677 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12680 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12685 Compiler_Error($"Invalid watched object\n");
12688 curExternal = external;
12689 curContext = context;
12692 FreeExpression(watcher);
12694 FreeExpression(object);
12695 FreeList(watches, FreePropertyWatch);
12698 Compiler_Error($"No observer specified and not inside a _class\n");
12702 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12704 ProcessStatement(propWatch.compound);
12710 case fireWatchersStmt:
12712 OldList * watches = stmt._watch.watches;
12713 Expression object = stmt._watch.object;
12715 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12716 // printf("%X\n", watches);
12717 // printf("%X\n", stmt._watch.watches);
12719 ProcessExpressionType(object);
12724 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12730 stmt.type = expressionStmt;
12731 stmt.expressions = MkList();
12733 // Check if we're inside a property set
12734 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12736 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12740 //Compiler_Error($"No property specified and not inside a property set\n");
12744 for(propID = watches->first; propID; propID = propID.next)
12746 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12749 CreateFireWatcher(prop, object, stmt);
12752 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12757 // Fire all properties!
12760 for(base = _class; base; base = base.base)
12762 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12764 if(prop.isProperty && prop.isWatchable)
12766 CreateFireWatcher(prop, object, stmt);
12773 FreeExpression(object);
12774 FreeList(watches, FreeIdentifier);
12777 Compiler_Error($"Invalid object specified and not inside a class\n");
12781 case stopWatchingStmt:
12783 OldList * watches = stmt._watch.watches;
12784 Expression object = stmt._watch.object;
12785 Expression watcher = stmt._watch.watcher;
12788 ProcessExpressionType(object);
12790 ProcessExpressionType(watcher);
12793 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12795 if(watcher || thisClass)
12801 stmt.type = expressionStmt;
12802 stmt.expressions = MkList();
12807 // eInstance_StopWatching(object, null, watcher);
12809 ListAdd(args, CopyExpression(object));
12810 ListAdd(args, MkExpConstant("0"));
12811 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12812 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12816 for(propID = watches->first; propID; propID = propID.next)
12818 char propName[1024];
12819 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12822 char getName[1024], setName[1024];
12823 OldList * args = MkList();
12825 DeclareProperty(prop, setName, getName);
12827 // eInstance_StopWatching(object, prop, watcher);
12828 strcpy(propName, "__ecereProp_");
12829 FullClassNameCat(propName, prop._class.fullName, false);
12830 strcat(propName, "_");
12831 // strcat(propName, prop.name);
12832 FullClassNameCat(propName, prop.name, true);
12833 //MangleClassName(propName);
12835 ListAdd(args, CopyExpression(object));
12836 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12837 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12838 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12841 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12846 FreeExpression(object);
12848 FreeExpression(watcher);
12849 FreeList(watches, FreeIdentifier);
12852 Compiler_Error($"Invalid object specified and not inside a class\n");
12855 Compiler_Error($"No observer specified and not inside a class\n");
12862 static void ProcessFunction(FunctionDefinition function)
12864 Identifier id = GetDeclId(function.declarator);
12865 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12866 Type type = symbol ? symbol.type : null;
12867 Class oldThisClass = thisClass;
12868 Context oldTopContext = topContext;
12870 yylloc = function.loc;
12871 // Process thisClass
12873 if(type && type.thisClass)
12875 Symbol classSym = type.thisClass;
12876 Class _class = type.thisClass.registered;
12877 char className[1024];
12878 char structName[1024];
12879 Declarator funcDecl;
12882 bool typedObject = false;
12884 if(_class && !_class.base)
12886 _class = currentClass;
12887 if(_class && !_class.symbol)
12888 _class.symbol = FindClass(_class.fullName);
12889 classSym = _class ? _class.symbol : null;
12890 typedObject = true;
12893 thisClass = _class;
12895 if(inCompiler && _class)
12897 if(type.kind == functionType)
12899 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12901 //TypeName param = symbol.type.params.first;
12902 Type param = symbol.type.params.first;
12903 symbol.type.params.Remove(param);
12904 //FreeTypeName(param);
12907 if(type.classObjectType != classPointer)
12909 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12910 symbol.type.staticMethod = true;
12911 symbol.type.thisClass = null;
12913 // HIGH DANGER: VERIFYING THIS...
12914 symbol.type.extraParam = false;
12918 strcpy(className, "__ecereClass_");
12919 FullClassNameCat(className, _class.fullName, true);
12921 //MangleClassName(className);
12924 FullClassNameCat(structName, _class.fullName, false);
12929 funcDecl = GetFuncDecl(function.declarator);
12932 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12934 TypeName param = funcDecl.function.parameters->first;
12935 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12937 funcDecl.function.parameters->Remove(param);
12938 FreeTypeName(param);
12942 // DANGER: Watch for this... Check if it's a Conversion?
12943 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12945 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12946 if(!function.propertyNoThis)
12948 TypeName thisParam = null;
12950 if(type.classObjectType != classPointer)
12952 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12953 if(!funcDecl.function.parameters)
12954 funcDecl.function.parameters = MkList();
12955 funcDecl.function.parameters->Insert(null, thisParam);
12960 if(type.classObjectType != classPointer)
12962 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12963 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12966 thisParam = TypeName
12968 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12969 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12971 funcDecl.function.parameters->Insert(null, thisParam);
12976 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12978 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12979 funcDecl = GetFuncDecl(initDecl.declarator);
12982 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12984 TypeName param = funcDecl.function.parameters->first;
12985 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12987 funcDecl.function.parameters->Remove(param);
12988 FreeTypeName(param);
12992 if(type.classObjectType != classPointer)
12994 // DANGER: Watch for this... Check if it's a Conversion?
12995 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12997 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12999 if(!funcDecl.function.parameters)
13000 funcDecl.function.parameters = MkList();
13001 funcDecl.function.parameters->Insert(null, thisParam);
13008 // Add this to the context
13011 if(type.classObjectType != classPointer)
13013 thisSymbol = Symbol
13015 string = CopyString("this");
13016 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
13018 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
13020 if(typedObject && thisSymbol.type)
13022 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
13023 thisSymbol.type.byReference = type.byReference;
13024 thisSymbol.type.typedByReference = type.byReference;
13026 thisSymbol = Symbol { string = CopyString("class") };
13027 function.body.compound.context.symbols.Add(thisSymbol);
13033 // Pointer to class data
13035 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
13037 DataMember member = null;
13040 for(base = _class; base && base.type != systemClass; base = base.next)
13042 for(member = base.membersAndProperties.first; member; member = member.next)
13043 if(!member.isProperty)
13049 for(member = _class.membersAndProperties.first; member; member = member.next)
13050 if(!member.isProperty)
13054 char pointerName[1024];
13057 Initializer initializer;
13058 Expression exp, bytePtr;
13060 strcpy(pointerName, "__ecerePointer_");
13061 FullClassNameCat(pointerName, _class.fullName, false);
13063 char className[1024];
13064 strcpy(className, "__ecereClass_");
13065 FullClassNameCat(className, classSym.string, true);
13066 //MangleClassName(className);
13069 DeclareClass(classSym, className);
13073 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
13078 sprintf(string, "%d", _class.offset);
13079 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
13083 // ([bytePtr] + [className]->offset)
13084 exp = QBrackets(MkExpOp(bytePtr, '+',
13085 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
13088 // (this ? [exp] : 0)
13089 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
13093 kind = pointerType;
13094 type = Type { refCount = 1, kind = voidType };
13099 yylloc = function.body.loc;
13100 // ([structName] *) [exp]
13101 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
13102 initializer = MkInitializerAssignment(
13103 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
13105 // [structName] * [pointerName] = [initializer];
13106 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
13109 Context prevContext = curContext;
13111 curContext = function.body.compound.context;
13113 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
13114 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
13115 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
13117 curContext = prevContext;
13121 decl.symbol = null;
13123 if(!function.body.compound.declarations)
13124 function.body.compound.declarations = MkList();
13125 function.body.compound.declarations->Insert(null, decl);
13131 // Loop through the function and replace undeclared identifiers
13132 // which are a member of the class (methods, properties or data)
13133 // by "this.[member]"
13140 FreeSpecifier(id._class);
13143 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13145 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13146 id = GetDeclId(initDecl.declarator);
13148 FreeSpecifier(id._class);
13153 topContext = function.body.compound.context;
13155 FunctionDefinition oldFunction = curFunction;
13156 curFunction = function;
13158 ProcessStatement(function.body);
13160 // If this is a property set and no firewatchers has been done yet, add one here
13161 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
13163 Statement prevCompound = curCompound;
13164 Context prevContext = curContext;
13166 Statement fireWatchers = MkFireWatchersStmt(null, null);
13167 if(!function.body.compound.statements) function.body.compound.statements = MkList();
13168 ListAdd(function.body.compound.statements, fireWatchers);
13170 curCompound = function.body;
13171 curContext = function.body.compound.context;
13173 ProcessStatement(fireWatchers);
13175 curContext = prevContext;
13176 curCompound = prevCompound;
13180 curFunction = oldFunction;
13183 if(function.declarator)
13185 ProcessDeclarator(function.declarator);
13188 topContext = oldTopContext;
13189 thisClass = oldThisClass;
13192 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13193 static void ProcessClass(OldList definitions, Symbol symbol)
13196 External external = curExternal;
13197 Class regClass = symbol ? symbol.registered : null;
13199 // Process all functions
13200 for(def = definitions.first; def; def = def.next)
13202 if(def.type == functionClassDef)
13204 if(def.function.declarator)
13205 curExternal = def.function.declarator.symbol.pointerExternal;
13207 curExternal = external;
13209 ProcessFunction((FunctionDefinition)def.function);
13211 else if(def.type == declarationClassDef)
13213 if(def.decl.type == instDeclaration)
13215 thisClass = regClass;
13216 ProcessInstantiationType(def.decl.inst);
13222 Class backThisClass = thisClass;
13223 if(regClass) thisClass = regClass;
13224 ProcessDeclaration(def.decl);
13225 thisClass = backThisClass;
13228 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13230 MemberInit defProperty;
13232 // Add this to the context
13233 Symbol thisSymbol = Symbol
13235 string = CopyString("this");
13236 type = regClass ? MkClassType(regClass.fullName) : null;
13238 globalContext.symbols.Add((BTNode)thisSymbol);
13240 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13242 thisClass = regClass;
13243 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13247 globalContext.symbols.Remove((BTNode)thisSymbol);
13248 FreeSymbol(thisSymbol);
13250 else if(def.type == propertyClassDef && def.propertyDef)
13252 PropertyDef prop = def.propertyDef;
13254 // Add this to the context
13256 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
13257 globalContext.symbols.Add(thisSymbol);
13260 thisClass = regClass;
13267 string = CopyString("this");
13268 type = MkClassType(regClass.fullName);
13270 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13273 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13274 ProcessStatement(prop.setStmt);
13282 string = CopyString("this");
13283 type = MkClassType(regClass.fullName);
13285 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13288 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13289 ProcessStatement(prop.getStmt);
13297 string = CopyString("this");
13298 type = MkClassType(regClass.fullName);
13300 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13303 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13304 ProcessStatement(prop.issetStmt);
13310 globalContext.symbols.Remove(thisSymbol);
13311 FreeSymbol(thisSymbol);
13314 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13316 PropertyWatch propertyWatch = def.propertyWatch;
13318 thisClass = regClass;
13319 if(propertyWatch.compound)
13323 string = CopyString("this");
13324 type = regClass ? MkClassType(regClass.fullName) : null;
13327 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13329 curExternal = null;
13330 ProcessStatement(propertyWatch.compound);
13337 void DeclareFunctionUtil(const String s)
13339 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13344 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13345 strcpy(name, "__ecereFunction_");
13346 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13347 DeclareFunction(function, name);
13351 void ComputeDataTypes()
13355 External after = null;
13357 currentClass = null;
13359 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13361 for(external = ast->first; external; external = external.next)
13363 if(external.type == declarationExternal)
13365 Declaration decl = external.declaration;
13368 OldList * decls = decl.declarators;
13371 InitDeclarator initDecl = decls->first;
13374 Declarator declarator = initDecl.declarator;
13375 if(declarator && declarator.type == identifierDeclarator)
13377 Identifier id = declarator.identifier;
13378 if(id && id.string)
13380 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
13382 external.symbol.id = -1001, external.symbol.idCode = -1001;
13394 // Workaround until we have proper toposort for declarations reordering
13395 External e = MkExternalDeclaration(MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Instance"), null)), null));
13396 ast->Insert(after, e);
13400 temp.symbol = Symbol { id = -1000, idCode = -1000 };
13401 ast->Insert(after, temp);
13402 curExternal = temp;
13404 DeclareFunctionUtil("eSystem_New");
13405 DeclareFunctionUtil("eSystem_New0");
13406 DeclareFunctionUtil("eSystem_Renew");
13407 DeclareFunctionUtil("eSystem_Renew0");
13408 DeclareFunctionUtil("eSystem_Delete");
13409 DeclareFunctionUtil("eClass_GetProperty");
13410 DeclareFunctionUtil("eClass_SetProperty");
13411 DeclareFunctionUtil("eInstance_FireSelfWatchers");
13412 DeclareFunctionUtil("eInstance_SetMethod");
13413 DeclareFunctionUtil("eInstance_IncRef");
13414 DeclareFunctionUtil("eInstance_StopWatching");
13415 DeclareFunctionUtil("eInstance_Watch");
13416 DeclareFunctionUtil("eInstance_FireWatchers");
13419 DeclareFunctionUtil("MemoryGuard_PushLoc");
13420 DeclareFunctionUtil("MemoryGuard_PopLoc");
13423 DeclareStruct("ecere::com::Class", false);
13424 DeclareStruct("ecere::com::Instance", false);
13425 DeclareStruct("ecere::com::Property", false);
13426 DeclareStruct("ecere::com::DataMember", false);
13427 DeclareStruct("ecere::com::Method", false);
13428 DeclareStruct("ecere::com::SerialBuffer", false);
13429 DeclareStruct("ecere::com::ClassTemplateArgument", false);
13433 for(external = ast->first; external; external = external.next)
13435 afterExternal = curExternal = external;
13436 if(external.type == functionExternal)
13438 currentClass = external.function._class;
13439 ProcessFunction(external.function);
13441 // There shouldn't be any _class member access here anyways...
13442 else if(external.type == declarationExternal)
13444 currentClass = null;
13445 if(external.declaration)
13446 ProcessDeclaration(external.declaration);
13448 else if(external.type == classExternal)
13450 ClassDefinition _class = external._class;
13451 currentClass = external.symbol.registered;
13452 if(_class.definitions)
13454 ProcessClass(_class.definitions, _class.symbol);
13458 // Free class data...
13459 ast->Remove(external);
13463 else if(external.type == nameSpaceExternal)
13465 thisNameSpace = external.id.string;
13468 currentClass = null;
13469 thisNameSpace = null;
13470 curExternal = null;
13472 delete temp.symbol;