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 sourceExp.expType = dest; dest.refCount++;
3805 //sourceExp.expType = MkClassType(_class.fullName);
3813 // Why wasn't there something like this?
3814 if(_class && _class.type == bitClass && source.kind != classType)
3816 if(!dest._class.registered.dataType)
3817 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3818 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3821 FreeType(sourceExp.expType);
3822 source = sourceExp.expType = MkClassType(dest._class.string);
3825 //source.kind = classType;
3826 //source._class = dest._class;
3830 // Adding two enumerations
3832 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3834 if(!source._class.registered.dataType)
3835 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3836 if(!dest._class.registered.dataType)
3837 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3839 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3842 source = sourceExp.expType = MkClassType(dest._class.string);
3845 //source.kind = classType;
3846 //source._class = dest._class;
3850 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3852 OldList * specs = MkList();
3856 ReadString(string, sourceExp.string);
3857 decl = SpecDeclFromString(string, specs, null);
3859 FreeExpContents(sourceExp);
3860 FreeType(sourceExp.expType);
3862 sourceExp.type = classExp;
3863 sourceExp._classExp.specifiers = specs;
3864 sourceExp._classExp.decl = decl;
3865 sourceExp.expType = dest;
3870 if(backupSourceExpType) FreeType(backupSourceExpType);
3874 else if(source.kind == classType)
3876 Class _class = source._class ? source._class.registered : null;
3878 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3881 if(dest.kind != classType)
3883 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3884 if(!source._class.registered.dataType)
3885 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3888 dest = MkClassType(source._class.string);
3889 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3890 // dest = MkClassType(source._class.string);
3894 if(dest.kind != classType)
3897 Type tempDest, tempSource;
3899 if(!source._class.registered.dataType)
3900 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3902 for(; _class.base.type != systemClass; _class = _class.base);
3904 tempSource = tempType;
3905 tempType.kind = classType;
3906 tempType._class = FindClass(_class.fullName);
3907 tempType.truth = source.truth;
3908 tempType.classObjectType = source.classObjectType;
3911 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3913 // PUT THIS BACK TESTING UNITS?
3914 if(conversions && conversions.last)
3916 ((Conversion)(conversions.last)).resultType = dest;
3920 FreeType(sourceExp.expType);
3921 sourceExp.expType = MkClassType(_class.fullName);
3922 sourceExp.expType.truth = source.truth;
3923 sourceExp.expType.classObjectType = source.classObjectType;
3925 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3927 if(!sourceExp.destType)
3929 FreeType(sourceExp.destType);
3930 sourceExp.destType = sourceExp.expType;
3931 if(sourceExp.expType)
3932 sourceExp.expType.refCount++;
3935 //source = _class.dataType;
3938 // TOCHECK: TESTING THIS NEW CODE
3939 if(!_class.dataType)
3940 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3942 dest = MkClassType(source._class.string);
3943 dest.truth = source.truth;
3944 dest.classObjectType = source.classObjectType;
3947 source = _class.dataType;
3957 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3967 if(source.kind == classType)
3969 Class _class = source._class.registered;
3970 if(_class.type == unitClass)
3972 if(!_class.dataType)
3973 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3974 source = _class.dataType;
3978 if(dest.kind == classType)
3980 Class _class = dest._class ? dest._class.registered : null;
3981 bool fittingValue = false;
3982 if(_class && _class.type == enumClass)
3984 Class enumClass = eSystem_FindClass(privateModule, "enum");
3985 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3986 if(c && value >= 0 && value <= c.largest)
3987 fittingValue = true;
3990 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3991 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3993 if(_class.type == normalClass || _class.type == noHeadClass)
3995 Expression newExp { };
3996 *newExp = *sourceExp;
3997 if(sourceExp.destType) sourceExp.destType.refCount++;
3998 if(sourceExp.expType) sourceExp.expType.refCount++;
3999 sourceExp.type = castExp;
4000 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
4001 sourceExp.cast.exp = newExp;
4002 FreeType(sourceExp.expType);
4003 sourceExp.expType = null;
4004 ProcessExpressionType(sourceExp);
4006 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
4009 FreeType(sourceExp.expType);
4010 sourceExp.expType = dest;
4014 if(inCompiler) FreeType(dest);
4016 if(backupSourceExpType) FreeType(backupSourceExpType);
4020 if(!_class.dataType)
4021 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4023 dest = _class.dataType;
4027 // Accept lower precision types for units, since we want to keep the unit type
4028 if(dest.kind == doubleType &&
4029 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
4030 source.kind == charType || source.kind == _BoolType))
4032 specs = MkListOne(MkSpecifier(DOUBLE));
4034 else if(dest.kind == floatType &&
4035 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4036 source.kind == _BoolType || source.kind == doubleType))
4038 specs = MkListOne(MkSpecifier(FLOAT));
4040 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4041 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4044 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4045 ListAdd(specs, MkSpecifier(INT64));
4047 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
4048 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4051 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4052 ListAdd(specs, MkSpecifier(INT));
4054 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
4055 source.kind == floatType || source.kind == doubleType))
4058 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4059 ListAdd(specs, MkSpecifier(SHORT));
4061 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
4062 source.kind == floatType || source.kind == doubleType))
4065 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4066 ListAdd(specs, MkSpecifier(CHAR));
4072 if(backupSourceExpType)
4074 // Failed to convert: revert previous exp type
4075 if(sourceExp.expType) FreeType(sourceExp.expType);
4076 sourceExp.expType = backupSourceExpType;
4081 else if(dest.kind == doubleType &&
4082 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
4083 source.kind == _BoolType || source.kind == charType))
4085 specs = MkListOne(MkSpecifier(DOUBLE));
4087 else if(dest.kind == floatType &&
4088 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4090 specs = MkListOne(MkSpecifier(FLOAT));
4092 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4093 (value == 1 || value == 0))
4096 ListAdd(specs, MkSpecifier(BOOL));
4098 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4099 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
4102 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4103 ListAdd(specs, MkSpecifier(CHAR));
4105 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
4106 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
4109 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4110 ListAdd(specs, MkSpecifier(SHORT));
4112 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
4115 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4116 ListAdd(specs, MkSpecifier(INT));
4118 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
4121 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4122 ListAdd(specs, MkSpecifier(INT64));
4124 else if(dest.kind == enumType &&
4125 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4127 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4133 if(backupSourceExpType)
4135 // Failed to convert: revert previous exp type
4136 if(sourceExp.expType) FreeType(sourceExp.expType);
4137 sourceExp.expType = backupSourceExpType;
4142 if(!flag && !sourceExp.opDestType)
4144 Expression newExp { };
4145 *newExp = *sourceExp;
4148 if(sourceExp.destType) sourceExp.destType.refCount++;
4149 if(sourceExp.expType) sourceExp.expType.refCount++;
4151 sourceExp.type = castExp;
4152 if(realDest.kind == classType)
4154 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4155 FreeList(specs, FreeSpecifier);
4158 sourceExp.cast.typeName = MkTypeName(specs, null);
4159 if(newExp.type == opExp)
4161 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4164 sourceExp.cast.exp = newExp;
4166 FreeType(sourceExp.expType);
4167 sourceExp.expType = null;
4168 ProcessExpressionType(sourceExp);
4171 FreeList(specs, FreeSpecifier);
4175 if(backupSourceExpType) FreeType(backupSourceExpType);
4181 if(computedExp != sourceExp)
4183 FreeExpression(computedExp);
4184 computedExp = sourceExp;
4187 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4188 if(sourceExp.type == identifierExp)
4190 Identifier id = sourceExp.identifier;
4191 if(dest.kind == classType)
4193 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4195 Class _class = dest._class.registered;
4196 Class enumClass = eSystem_FindClass(privateModule, "enum");
4199 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4202 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4203 for(value = e.values.first; value; value = value.next)
4205 if(!strcmp(value.name, id.string))
4210 FreeType(sourceExp.expType);
4212 sourceExp.isConstant = true;
4213 sourceExp.expType = MkClassType(_class.fullName);
4214 if(inCompiler || inPreCompiler || inDebugger)
4216 FreeExpContents(sourceExp);
4218 sourceExp.type = constantExp;
4219 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4220 sourceExp.constant = PrintInt64(value.data);
4222 sourceExp.constant = PrintUInt64(value.data);
4223 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4233 // Loop through all enum classes
4234 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4245 #define TERTIARY(o, name, m, t, p) \
4246 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4248 exp.type = constantExp; \
4249 exp.string = p(op1.m ? op2.m : op3.m); \
4251 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4255 #define BINARY(o, name, m, t, p) \
4256 static bool name(Expression exp, Operand op1, Operand op2) \
4259 exp.type = constantExp; \
4260 exp.string = p((t)(op1.m o value2)); \
4262 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4266 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4267 static bool name(Expression exp, Operand op1, Operand op2) \
4270 exp.type = constantExp; \
4271 exp.string = p(value2 ? (op1.m o value2) : 0); \
4273 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4277 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4278 static bool name(Expression exp, Operand op1, Operand op2) \
4281 exp.type = constantExp; \
4282 exp.string = p(op1.m o value2); \
4284 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4288 #define UNARY(o, name, m, t, p) \
4289 static bool name(Expression exp, Operand op1) \
4291 exp.type = constantExp; \
4292 exp.string = p((t)(o op1.m)); \
4294 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4298 #define OPERATOR_ALL(macro, o, name) \
4299 macro(o, Int##name, i, int, PrintInt) \
4300 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4301 macro(o, Int64##name, i64, int64, PrintInt64) \
4302 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4303 macro(o, Short##name, s, short, PrintShort) \
4304 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4305 macro(o, Char##name, c, char, PrintChar) \
4306 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4307 macro(o, Float##name, f, float, PrintFloat) \
4308 macro(o, Double##name, d, double, PrintDouble)
4310 #define OPERATOR_INTTYPES(macro, o, name) \
4311 macro(o, Int##name, i, int, PrintInt) \
4312 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4313 macro(o, Int64##name, i64, int64, PrintInt64) \
4314 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4315 macro(o, Short##name, s, short, PrintShort) \
4316 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4317 macro(o, Char##name, c, char, PrintChar) \
4318 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4320 #define OPERATOR_REALTYPES(macro, o, name) \
4321 macro(o, Float##name, f, float, PrintFloat) \
4322 macro(o, Double##name, d, double, PrintDouble)
4324 // binary arithmetic
4325 OPERATOR_ALL(BINARY, +, Add)
4326 OPERATOR_ALL(BINARY, -, Sub)
4327 OPERATOR_ALL(BINARY, *, Mul)
4328 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4329 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4330 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4333 OPERATOR_ALL(UNARY, -, Neg)
4335 // unary arithmetic increment and decrement
4336 OPERATOR_ALL(UNARY, ++, Inc)
4337 OPERATOR_ALL(UNARY, --, Dec)
4339 // binary arithmetic assignment
4340 OPERATOR_ALL(BINARY, =, Asign)
4341 OPERATOR_ALL(BINARY, +=, AddAsign)
4342 OPERATOR_ALL(BINARY, -=, SubAsign)
4343 OPERATOR_ALL(BINARY, *=, MulAsign)
4344 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4345 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4346 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4349 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4350 OPERATOR_INTTYPES(BINARY, |, BitOr)
4351 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4352 OPERATOR_INTTYPES(BINARY, <<, LShift)
4353 OPERATOR_INTTYPES(BINARY, >>, RShift)
4356 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4358 // binary bitwise assignment
4359 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4360 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4361 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4362 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4363 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4365 // unary logical negation
4366 OPERATOR_INTTYPES(UNARY, !, Not)
4368 // binary logical equality
4369 OPERATOR_ALL(BINARY, ==, Equ)
4370 OPERATOR_ALL(BINARY, !=, Nqu)
4373 OPERATOR_ALL(BINARY, &&, And)
4374 OPERATOR_ALL(BINARY, ||, Or)
4376 // binary logical relational
4377 OPERATOR_ALL(BINARY, >, Grt)
4378 OPERATOR_ALL(BINARY, <, Sma)
4379 OPERATOR_ALL(BINARY, >=, GrtEqu)
4380 OPERATOR_ALL(BINARY, <=, SmaEqu)
4382 // tertiary condition operator
4383 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4385 //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
4386 #define OPERATOR_TABLE_ALL(name, type) \
4387 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4389 type##Inc, type##Dec, \
4390 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4391 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4393 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4395 type##Equ, type##Nqu, \
4396 type##And, type##Or, \
4397 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4400 #define OPERATOR_TABLE_INTTYPES(name, type) \
4401 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4403 type##Inc, type##Dec, \
4404 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4405 null, null, null, null, null, \
4407 null, null, null, null, null, \
4409 type##Equ, type##Nqu, \
4410 type##And, type##Or, \
4411 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4414 OPERATOR_TABLE_ALL(int, Int)
4415 OPERATOR_TABLE_ALL(uint, UInt)
4416 OPERATOR_TABLE_ALL(int64, Int64)
4417 OPERATOR_TABLE_ALL(uint64, UInt64)
4418 OPERATOR_TABLE_ALL(short, Short)
4419 OPERATOR_TABLE_ALL(ushort, UShort)
4420 OPERATOR_TABLE_INTTYPES(float, Float)
4421 OPERATOR_TABLE_INTTYPES(double, Double)
4422 OPERATOR_TABLE_ALL(char, Char)
4423 OPERATOR_TABLE_ALL(uchar, UChar)
4425 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4426 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4427 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4428 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4429 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4430 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4431 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4432 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4434 public void ReadString(char * output, char * string)
4436 int len = strlen(string);
4438 bool quoted = false, escaped = false;
4439 for(c = 0; c<len; c++)
4441 char ch = string[c];
4446 case 'n': output[d] = '\n'; break;
4447 case 't': output[d] = '\t'; break;
4448 case 'a': output[d] = '\a'; break;
4449 case 'b': output[d] = '\b'; break;
4450 case 'f': output[d] = '\f'; break;
4451 case 'r': output[d] = '\r'; break;
4452 case 'v': output[d] = '\v'; break;
4453 case '\\': output[d] = '\\'; break;
4454 case '\"': output[d] = '\"'; break;
4455 case '\'': output[d] = '\''; break;
4456 default: output[d] = ch;
4477 // String Unescape Copy
4479 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4480 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4481 public int UnescapeString(char * d, char * s, int len)
4485 while(j < len && (ch = s[j]))
4490 switch((ch = s[++j]))
4492 case 'n': d[k] = '\n'; break;
4493 case 't': d[k] = '\t'; break;
4494 case 'a': d[k] = '\a'; break;
4495 case 'b': d[k] = '\b'; break;
4496 case 'f': d[k] = '\f'; break;
4497 case 'r': d[k] = '\r'; break;
4498 case 'v': d[k] = '\v'; break;
4499 case '\\': d[k] = '\\'; break;
4500 case '\"': d[k] = '\"'; break;
4501 case '\'': d[k] = '\''; break;
4502 default: d[k] = '\\'; d[k] = ch;
4514 public char * OffsetEscapedString(char * s, int len, int offset)
4518 while(j < len && k < offset && (ch = s[j]))
4523 return (k == offset) ? s + j : null;
4526 public Operand GetOperand(Expression exp)
4529 Type type = exp.expType;
4532 while(type.kind == classType &&
4533 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4535 if(!type._class.registered.dataType)
4536 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4537 type = type._class.registered.dataType;
4540 if(exp.type == stringExp && op.kind == pointerType)
4542 op.ui64 = (uint64)(uintptr)exp.string;
4543 op.kind = pointerType;
4546 else if(exp.isConstant && exp.type == constantExp)
4548 op.kind = type.kind;
4556 if(exp.constant[0] == '\'')
4558 op.c = exp.constant[1];
4561 else if(type.isSigned)
4563 op.c = (char)strtol(exp.constant, null, 0);
4568 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4576 op.s = (short)strtol(exp.constant, null, 0);
4581 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4589 op.i = (int)strtol(exp.constant, null, 0);
4594 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4602 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4607 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4610 op.kind = int64Type;
4615 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4620 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4623 op.kind = int64Type;
4628 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4633 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4636 op.kind = int64Type;
4639 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4640 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4641 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4642 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4644 op.f = (float)strtod(exp.constant, null);
4648 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4649 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4650 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4651 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4653 op.d = (double)strtod(exp.constant, null);
4656 //case classType: For when we have operator overloading...
4657 // Pointer additions
4658 //case functionType:
4662 op.ui64 = _strtoui64(exp.constant, null, 0);
4663 op.kind = pointerType;
4673 static int64 GetEnumValue(Class _class, void * ptr)
4676 switch(_class.typeSize)
4679 if(!strcmp(_class.dataTypeString, "uint64"))
4680 v = (int64)*(uint64 *)ptr;
4682 v = (int64)*(int64 *)ptr;
4685 if(!strcmp(_class.dataTypeString, "uint"))
4686 v = (int64)*(uint *)ptr;
4688 v = (int64)*(int *)ptr;
4691 if(!strcmp(_class.dataTypeString, "uint16"))
4692 v = (int64)*(uint16 *)ptr;
4694 v = (int64)*(short *)ptr;
4697 if(!strcmp(_class.dataTypeString, "byte"))
4698 v = (int64)*(byte *)ptr;
4700 v = (int64)*(char *)ptr;
4706 static __attribute__((unused)) void UnusedFunction()
4709 a.OnGetString(0,0,0);
4712 extern int __ecereVMethodID_class_OnGetString;
4715 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4717 DataMember dataMember;
4718 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4720 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4721 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4725 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4727 void * ptr = inst.data + dataMember.offset + offset;
4728 char * result = null;
4729 exp.loc = member.loc = inst.loc;
4730 ((Identifier)member.identifiers->first).loc = inst.loc;
4732 if(!dataMember.dataType)
4733 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4734 type = dataMember.dataType;
4735 if(type.kind == classType)
4737 Class _class = type._class.registered;
4738 if(_class.type == enumClass)
4740 Class enumClass = eSystem_FindClass(privateModule, "enum");
4743 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4745 for(item = e.values.first; item; item = item.next)
4747 if(item.data == GetEnumValue(_class, ptr))
4755 exp.identifier = MkIdentifier(result);
4756 exp.type = identifierExp;
4757 exp.destType = MkClassType(_class.fullName);
4758 ProcessExpressionType(exp);
4762 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4764 if(!_class.dataType)
4765 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4766 type = _class.dataType;
4775 FreeExpContents(exp);
4777 exp.constant = PrintFloat(*(float*)ptr);
4778 exp.type = constantExp;
4783 FreeExpContents(exp);
4785 exp.constant = PrintDouble(*(double*)ptr);
4786 exp.type = constantExp;
4791 FreeExpContents(exp);
4793 exp.constant = PrintInt(*(int*)ptr);
4794 exp.type = constantExp;
4799 FreeExpContents(exp);
4801 exp.constant = PrintInt64(*(int64*)ptr);
4802 exp.type = constantExp;
4807 FreeExpContents(exp);
4808 // TODO: This should probably use proper type
4809 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4810 exp.type = constantExp;
4815 FreeExpContents(exp);
4816 // TODO: This should probably use proper type
4817 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4818 exp.type = constantExp;
4822 Compiler_Error($"Unhandled type populating instance\n");
4825 ListAdd(memberList, member);
4828 if(parentDataMember.type == unionMember)
4833 void PopulateInstance(Instantiation inst)
4835 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4836 Class _class = classSym.registered;
4837 DataMember dataMember;
4838 OldList * memberList = MkList();
4839 // Added this check and ->Add to prevent memory leaks on bad code
4841 inst.members = MkListOne(MkMembersInitList(memberList));
4843 inst.members->Add(MkMembersInitList(memberList));
4844 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4846 if(!dataMember.isProperty)
4848 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4849 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4853 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4855 void * ptr = inst.data + dataMember.offset;
4856 char * result = null;
4858 exp.loc = member.loc = inst.loc;
4859 ((Identifier)member.identifiers->first).loc = inst.loc;
4861 if(!dataMember.dataType)
4862 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4863 type = dataMember.dataType;
4864 if(type.kind == classType)
4866 Class _class = type._class.registered;
4867 if(_class.type == enumClass)
4869 Class enumClass = eSystem_FindClass(privateModule, "enum");
4872 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4874 for(item = e.values.first; item; item = item.next)
4876 if(item.data == GetEnumValue(_class, ptr))
4885 exp.identifier = MkIdentifier(result);
4886 exp.type = identifierExp;
4887 exp.destType = MkClassType(_class.fullName);
4888 ProcessExpressionType(exp);
4891 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4893 if(!_class.dataType)
4894 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4895 type = _class.dataType;
4904 exp.constant = PrintFloat(*(float*)ptr);
4905 exp.type = constantExp;
4910 exp.constant = PrintDouble(*(double*)ptr);
4911 exp.type = constantExp;
4916 exp.constant = PrintInt(*(int*)ptr);
4917 exp.type = constantExp;
4922 exp.constant = PrintInt64(*(int64*)ptr);
4923 exp.type = constantExp;
4928 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4929 exp.type = constantExp;
4933 Compiler_Error($"Unhandled type populating instance\n");
4936 ListAdd(memberList, member);
4942 void ComputeInstantiation(Expression exp)
4944 Instantiation inst = exp.instance;
4945 MembersInit members;
4946 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4947 Class _class = classSym ? classSym.registered : null;
4948 DataMember curMember = null;
4949 Class curClass = null;
4950 DataMember subMemberStack[256];
4951 int subMemberStackPos = 0;
4954 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4956 // Don't recompute the instantiation...
4957 // Non Simple classes will have become constants by now
4961 if(_class.type == normalClass || _class.type == noHeadClass)
4963 inst.data = (byte *)eInstance_New(_class);
4964 if(_class.type == normalClass)
4965 ((Instance)inst.data)._refCount++;
4968 inst.data = new0 byte[_class.structSize];
4973 for(members = inst.members->first; members; members = members.next)
4975 switch(members.type)
4977 case dataMembersInit:
4979 if(members.dataMembers)
4982 for(member = members.dataMembers->first; member; member = member.next)
4984 Identifier ident = member.identifiers ? member.identifiers->first : null;
4987 Property prop = null;
4988 DataMember dataMember = null;
4989 uint dataMemberOffset;
4993 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4996 if(curMember.isProperty)
4997 prop = (Property)curMember;
5000 dataMember = curMember;
5002 // CHANGED THIS HERE
5003 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
5005 // 2013/17/29 -- It seems that this was missing here!
5006 if(_class.type == normalClass)
5007 dataMemberOffset += _class.base.structSize;
5008 // dataMemberOffset = dataMember.offset;
5015 prop = eClass_FindProperty(_class, ident.string, privateModule);
5019 if(prop.memberAccess == publicAccess)
5021 curMember = (DataMember)prop;
5022 curClass = prop._class;
5027 DataMember _subMemberStack[256];
5028 int _subMemberStackPos = 0;
5030 // FILL MEMBER STACK
5031 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
5036 if(dataMember.memberAccess == publicAccess)
5038 curMember = dataMember;
5039 curClass = dataMember._class;
5040 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
5041 subMemberStackPos = _subMemberStackPos;
5047 if(found && member.initializer && member.initializer.type == expInitializer)
5049 Expression value = member.initializer.exp;
5051 bool deepMember = false;
5054 type = prop.dataType;
5058 if(!dataMember.dataType)
5059 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
5061 type = dataMember.dataType;
5064 if(ident && ident.next)
5068 // for(; ident && type; ident = ident.next)
5069 for(ident = ident.next; ident && type; ident = ident.next)
5071 if(type.kind == classType)
5073 prop = eClass_FindProperty(type._class.registered,
5074 ident.string, privateModule);
5076 type = prop.dataType;
5079 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
5080 ident.string, &dataMemberOffset, privateModule, null, null);
5082 type = dataMember.dataType;
5085 else if(type.kind == structType || type.kind == unionType)
5088 for(memberType = type.members.first; memberType; memberType = memberType.next)
5090 if(!strcmp(memberType.name, ident.string))
5101 FreeType(value.destType);
5102 value.destType = type;
5103 if(type) type.refCount++;
5104 ComputeExpression(value);
5106 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
5108 if(type.kind == classType)
5110 Class _class = type._class.registered;
5111 if(_class.type == bitClass || _class.type == unitClass ||
5112 _class.type == enumClass)
5114 if(!_class.dataType)
5115 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5116 type = _class.dataType;
5122 void * ptr = inst.data + dataMemberOffset;
5124 if(value.type == constantExp)
5130 GetInt(value, (int*)ptr);
5135 GetInt64(value, (int64*)ptr);
5140 GetIntPtr(value, (intptr*)ptr);
5145 GetIntSize(value, (intsize*)ptr);
5150 GetFloat(value, (float*)ptr);
5155 GetDouble(value, (double *)ptr);
5160 else if(value.type == instanceExp)
5162 if(type.kind == classType)
5164 Class _class = type._class.registered;
5165 if(_class.type == structClass)
5167 ComputeTypeSize(type);
5168 if(value.instance.data)
5169 memcpy(ptr, value.instance.data, type.size);
5174 else if(prop && prop.Set != (void *)(intptr)1)
5176 if(value.type == instanceExp && value.instance.data)
5178 if(type.kind == classType)
5180 Class _class = type._class.registered;
5181 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5183 void (*Set)(void *, void *) = (void *)prop.Set;
5184 Set(inst.data, value.instance.data);
5185 PopulateInstance(inst);
5189 else if(value.type == constantExp)
5195 void (*Set)(void *, double) = (void *)prop.Set;
5196 Set(inst.data, strtod(value.constant, null) );
5201 void (*Set)(void *, float) = (void *)prop.Set;
5202 Set(inst.data, (float)(strtod(value.constant, null)));
5207 void (*Set)(void *, int) = (void *)prop.Set;
5208 Set(inst.data, (int)strtol(value.constant, null, 0));
5213 void (*Set)(void *, int64) = (void *)prop.Set;
5214 Set(inst.data, _strtoi64(value.constant, null, 0));
5219 void (*Set)(void *, intptr) = (void *)prop.Set;
5220 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5225 void (*Set)(void *, intsize) = (void *)prop.Set;
5226 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5231 else if(value.type == stringExp)
5234 ReadString(temp, value.string);
5235 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5239 else if(!deepMember && type && _class.type == unitClass)
5243 // Only support converting units to units for now...
5244 if(value.type == constantExp)
5246 if(type.kind == classType)
5248 Class _class = type._class.registered;
5249 if(_class.type == unitClass)
5251 if(!_class.dataType)
5252 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5253 type = _class.dataType;
5256 // TODO: Assuming same base type for units...
5262 float (*Set)(float) = (void *)prop.Set;
5263 GetFloat(member.initializer.exp, &fValue);
5264 exp.constant = PrintFloat(Set(fValue));
5265 exp.type = constantExp;
5271 double (*Set)(double) = (void *)prop.Set;
5272 GetDouble(member.initializer.exp, &dValue);
5273 exp.constant = PrintDouble(Set(dValue));
5274 exp.type = constantExp;
5281 else if(!deepMember && type && _class.type == bitClass)
5285 if(value.type == instanceExp && value.instance.data)
5287 unsigned int (*Set)(void *) = (void *)prop.Set;
5288 bits = Set(value.instance.data);
5290 else if(value.type == constantExp)
5296 BitMember bitMember = (BitMember) dataMember;
5299 bits = (bits & ~bitMember.mask);
5300 if(!bitMember.dataType)
5301 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5302 type = bitMember.dataType;
5303 if(type.kind == classType && type._class && type._class.registered)
5305 if(!type._class.registered.dataType)
5306 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5307 type = type._class.registered.dataType;
5312 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5313 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5315 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5316 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5317 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5318 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5320 bits |= part << bitMember.pos;
5326 if(_class && _class.type == unitClass)
5328 ComputeExpression(member.initializer.exp);
5329 exp.constant = member.initializer.exp.constant;
5330 exp.type = constantExp;
5332 member.initializer.exp.constant = null;
5342 if(_class && _class.type == bitClass)
5344 exp.constant = PrintHexUInt(bits);
5345 exp.type = constantExp;
5347 if(exp.type != instanceExp)
5353 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5355 bool result = false;
5359 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5360 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5364 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5365 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5368 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5369 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5370 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5373 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5374 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5375 result = GetOpFloat(op, &op.f);
5378 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5379 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5380 result = GetOpDouble(op, &op.d);
5383 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5384 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5385 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5388 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5389 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5390 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5393 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5394 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5397 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5398 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5404 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5406 if(exp.op.op == SIZEOF)
5408 FreeExpContents(exp);
5409 exp.type = constantExp;
5410 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5421 // Provide default unary +
5422 Expression exp2 = exp.op.exp2;
5424 FreeExpContents(exp);
5425 FreeType(exp.expType);
5426 FreeType(exp.destType);
5432 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5434 // unary arithmetic increment and decrement
5435 //OPERATOR_ALL(UNARY, ++, Inc)
5436 //OPERATOR_ALL(UNARY, --, Dec)
5439 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5441 // unary logical negation
5443 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5449 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5451 if(Promote(op2, op1.kind, op1.type.isSigned))
5452 op2.kind = op1.kind, op2.ops = op1.ops;
5453 else if(Promote(op1, op2.kind, op2.type.isSigned))
5454 op1.kind = op2.kind, op1.ops = op2.ops;
5458 // binary arithmetic
5460 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5463 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5466 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5469 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5472 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5474 // binary arithmetic assignment
5475 //OPERATOR_ALL(BINARY, =, Asign)
5476 //OPERATOR_ALL(BINARY, +=, AddAsign)
5477 //OPERATOR_ALL(BINARY, -=, SubAsign)
5478 //OPERATOR_ALL(BINARY, *=, MulAsign)
5479 //OPERATOR_ALL(BINARY, /=, DivAsign)
5480 //OPERATOR_ALL(BINARY, %=, ModAsign)
5485 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5489 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5492 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5495 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5498 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5500 // binary bitwise assignment
5501 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5502 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5503 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5504 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5505 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5506 // binary logical equality
5508 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5511 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5515 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5518 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5520 // binary logical relational
5522 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5525 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5528 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5531 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5538 void ComputeExpression(Expression exp)
5541 char expString[10240];
5542 expString[0] = '\0';
5543 PrintExpression(exp, expString);
5550 Identifier id = exp.identifier;
5551 if(id && exp.isConstant && !inCompiler && !inPreCompiler && !inDebugger)
5553 Class c = (exp.expType && exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
5554 if(c && c.type == enumClass)
5556 Class enumClass = eSystem_FindClass(privateModule, "enum");
5560 EnumClassData e = ACCESS_CLASSDATA(c, enumClass);
5561 for(value = e.values.first; value; value = value.next)
5563 if(!strcmp(value.name, id.string))
5568 const String dts = c.dataTypeString;
5569 FreeExpContents(exp);
5570 exp.type = constantExp;
5571 exp.constant = (dts && (!strcmp(dts, "int") || !strcmp(dts, "int64") || !strcmp(dts, "short") || !strcmp(dts, "char"))) ? PrintInt64(value.data) : PrintUInt64(value.data);
5580 ComputeInstantiation(exp);
5589 Expression exp1, exp2 = null;
5593 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5596 Expression e = exp.op.exp2;
5598 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5600 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5602 if(e.type == extensionCompoundExp)
5603 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5608 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5610 if(e.type == stringExp && e.string)
5612 char * string = e.string;
5613 int len = strlen(string);
5614 char * tmp = new char[len-2+1];
5615 len = UnescapeString(tmp, string + 1, len - 2);
5617 FreeExpContents(exp);
5618 exp.type = constantExp;
5619 exp.constant = PrintUInt(len + 1);
5623 Type type = e.expType;
5625 FreeExpContents(exp);
5626 exp.type = constantExp;
5627 exp.constant = PrintUInt(ComputeTypeSize(type));
5633 ComputeExpression(exp.op.exp2);
5637 ComputeExpression(exp.op.exp1);
5640 op1 = GetOperand(exp1);
5641 if(op1.type) op1.type.refCount++;
5644 op2 = GetOperand(exp2);
5645 if(op2.type) op2.type.refCount++;
5651 op1 = GetOperand(exp1);
5652 if(op1.type) op1.type.refCount++;
5655 CallOperator(exp, exp1, exp2, op1, op2);
5662 if(exp.op.exp1 && exp.op.exp2)
5667 FreeExpContents(exp);
5668 op1.ops.BitAnd(exp, op1, op2);
5677 FreeExpContents(exp);
5678 op1.ops.Mul(exp, op1, op2);
5687 FreeExpContents(exp);
5688 op1.ops.Add(exp, op1, op2);
5693 // Provide default unary +
5694 Expression exp2 = exp.op.exp2;
5696 FreeExpContents(exp);
5697 FreeType(exp.expType);
5698 FreeType(exp.destType);
5709 FreeExpContents(exp);
5710 op1.ops.Sub(exp, op1, op2);
5717 FreeExpContents(exp);
5718 op1.ops.Neg(exp, op1);
5725 FreeExpContents(exp);
5726 op1.ops.BitNot(exp, op1);
5732 FreeExpContents(exp);
5733 op1.ops.Not(exp, op1);
5736 // Binary only operators
5740 FreeExpContents(exp);
5741 op1.ops.Div(exp, op1, op2);
5747 FreeExpContents(exp);
5748 op1.ops.Mod(exp, op1, op2);
5760 FreeExpContents(exp);
5761 op1.ops.Sma(exp, op1, op2);
5770 FreeExpContents(exp);
5771 op1.ops.Grt(exp, op1, op2);
5780 FreeExpContents(exp);
5781 op1.ops.SmaEqu(exp, op1, op2);
5790 FreeExpContents(exp);
5791 op1.ops.GrtEqu(exp, op1, op2);
5800 FreeExpContents(exp);
5801 op1.ops.Equ(exp, op1, op2);
5810 FreeExpContents(exp);
5811 op1.ops.Nqu(exp, op1, op2);
5818 FreeExpContents(exp);
5819 op1.ops.BitOr(exp, op1, op2);
5825 FreeExpContents(exp);
5826 op1.ops.BitXor(exp, op1, op2);
5834 FreeExpContents(exp);
5835 exp.type = constantExp;
5836 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5840 if(op1.type) FreeType(op1.type);
5841 if(op2.type) FreeType(op2.type);
5845 case extensionExpressionExp:
5848 for(e = exp.list->first; e; e = n)
5853 OldList * list = exp.list;
5854 Expression prev = exp.prev;
5855 Expression next = exp.next;
5856 ComputeExpression(e);
5857 //FreeExpContents(exp);
5858 FreeType(exp.expType);
5859 FreeType(exp.destType);
5878 exp.isConstant = true;
5880 ComputeExpression(exp.index.exp);
5881 if(!exp.index.exp.isConstant)
5882 exp.isConstant = false;
5884 for(e = exp.index.index->first; e; e = e.next)
5886 ComputeExpression(e);
5889 // Check if this type is int
5892 exp.isConstant = false;
5894 exp.expType = Dereference(exp.index.exp.expType);
5900 Expression memberExp = exp.member.exp;
5901 Identifier memberID = exp.member.member;
5904 ComputeExpression(exp.member.exp);
5905 type = exp.member.exp.expType;
5908 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);
5909 Property prop = null;
5910 DataMember member = null;
5911 Class convertTo = null;
5912 if(type.kind == subClassType && exp.member.exp.type == classExp)
5913 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5920 PrintTypeNoConst(type, string, false, true);
5921 classSym = FindClass(string);
5922 _class = classSym ? classSym.registered : null;
5925 if(exp.member.member)
5927 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5929 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5931 if(!prop && !member && _class && exp.member.member)
5933 Symbol classSym = FindClass(exp.member.member.string);
5935 _class = classSym ? classSym.registered : null;
5936 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5943 Type type = prop.dataType;
5944 // TODO: Assuming same base type for units...
5945 if(_class.type == unitClass)
5947 if(type.kind == classType)
5949 Class _class = type._class.registered;
5950 if(_class.type == unitClass)
5952 if(!_class.dataType)
5953 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5954 type = _class.dataType;
5962 float (*Get)(float) = (void *)prop.Get;
5963 GetFloat(exp.member.exp, &value);
5964 exp.constant = PrintFloat(Get ? Get(value) : value);
5965 exp.type = constantExp;
5971 double (*Get)(double);
5972 GetDouble(exp.member.exp, &value);
5975 Get = (void *)prop.Set;
5977 Get = (void *)prop.Get;
5978 exp.constant = PrintDouble(Get ? Get(value) : value);
5979 exp.type = constantExp;
5988 Expression value = exp.member.exp;
5991 ProcessPropertyType(prop);
5993 type = prop.dataType;
5996 // printf("Investigate this\n");
5998 else if(_class.type == structClass)
6004 Class propertyClass = type._class.registered;
6005 if(propertyClass.type == structClass && value.type == instanceExp)
6007 void (*Set)(void *, void *) = (void *)prop.Set;
6008 exp.instance = Instantiation { };
6009 exp.instance.data = new0 byte[_class.structSize];
6010 exp.instance._class = MkSpecifierName(_class.fullName);
6011 exp.instance.loc = exp.loc;
6012 exp.type = instanceExp;
6013 Set(exp.instance.data, value.instance.data);
6014 PopulateInstance(exp.instance);
6021 void (*Set)(void *, int) = (void *)prop.Set;
6023 exp.instance = Instantiation { };
6024 exp.instance.data = new0 byte[_class.structSize];
6025 exp.instance._class = MkSpecifierName(_class.fullName);
6026 exp.instance.loc = exp.loc;
6027 exp.type = instanceExp;
6029 GetInt(value, &intValue);
6031 Set(exp.instance.data, intValue);
6032 PopulateInstance(exp.instance);
6038 void (*Set)(void *, int64) = (void *)prop.Set;
6040 exp.instance = Instantiation { };
6041 exp.instance.data = new0 byte[_class.structSize];
6042 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
6043 exp.instance.loc = exp.loc;
6044 exp.type = instanceExp;
6046 GetInt64(value, &intValue);
6048 Set(exp.instance.data, intValue);
6049 PopulateInstance(exp.instance);
6056 void (*Set)(void *, intptr) = (void *)prop.Set;
6058 exp.instance = Instantiation { };
6059 exp.instance.data = new0 byte[_class.structSize];
6060 exp.instance._class = MkSpecifierName(_class.fullName);
6061 exp.instance.loc = exp.loc;
6062 exp.type = instanceExp;
6064 GetIntPtr(value, &intValue);
6066 Set(exp.instance.data, intValue);
6067 PopulateInstance(exp.instance);
6074 void (*Set)(void *, intsize) = (void *)prop.Set;
6076 exp.instance = Instantiation { };
6077 exp.instance.data = new0 byte[_class.structSize];
6078 exp.instance._class = MkSpecifierName(_class.fullName);
6079 exp.instance.loc = exp.loc;
6080 exp.type = instanceExp;
6082 GetIntSize(value, &intValue);
6084 Set(exp.instance.data, intValue);
6085 PopulateInstance(exp.instance);
6091 void (*Set)(void *, float) = (void *)prop.Set;
6093 exp.instance = Instantiation { };
6094 exp.instance.data = new0 byte[_class.structSize];
6095 exp.instance._class = MkSpecifierName(_class.fullName);
6096 exp.instance.loc = exp.loc;
6097 exp.type = instanceExp;
6099 GetFloat(value, &floatValue);
6101 Set(exp.instance.data, floatValue);
6102 PopulateInstance(exp.instance);
6108 void (*Set)(void *, double) = (void *)prop.Set;
6110 exp.instance = Instantiation { };
6111 exp.instance.data = new0 byte[_class.structSize];
6112 exp.instance._class = MkSpecifierName(_class.fullName);
6113 exp.instance.loc = exp.loc;
6114 exp.type = instanceExp;
6116 GetDouble(value, &doubleValue);
6118 Set(exp.instance.data, doubleValue);
6119 PopulateInstance(exp.instance);
6124 else if(_class.type == bitClass)
6130 Class propertyClass = type._class.registered;
6131 if(propertyClass.type == structClass && value.instance.data)
6133 unsigned int (*Set)(void *) = (void *)prop.Set;
6134 unsigned int bits = Set(value.instance.data);
6135 exp.constant = PrintHexUInt(bits);
6136 exp.type = constantExp;
6139 else if(_class.type == bitClass)
6142 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6145 GetUInt(exp.member.exp, &value);
6147 exp.constant = PrintHexUInt(bits);
6148 exp.type = constantExp;
6156 if(_class.type == bitClass)
6159 GetUInt(exp.member.exp, &value);
6165 Class _class = type._class.registered;
6166 if(_class.type == structClass)
6168 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6170 exp.instance = Instantiation { };
6171 exp.instance.data = new0 byte[_class.structSize];
6172 exp.instance._class = MkSpecifierName(_class.fullName);
6173 exp.instance.loc = exp.loc;
6174 //exp.instance.fullSet = true;
6175 exp.type = instanceExp;
6176 Get(value, exp.instance.data);
6177 PopulateInstance(exp.instance);
6179 else if(_class.type == bitClass)
6181 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6182 uint64 bits = Get(value);
6183 exp.constant = PrintHexUInt64(bits);
6184 exp.type = constantExp;
6190 else if(_class.type == structClass)
6192 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6197 Class _class = type._class.registered;
6198 if(_class.type == structClass && value)
6200 void (*Get)(void *, void *) = (void *)prop.Get;
6202 exp.instance = Instantiation { };
6203 exp.instance.data = new0 byte[_class.structSize];
6204 exp.instance._class = MkSpecifierName(_class.fullName);
6205 exp.instance.loc = exp.loc;
6206 //exp.instance.fullSet = true;
6207 exp.type = instanceExp;
6208 Get(value, exp.instance.data);
6209 PopulateInstance(exp.instance);
6217 char * value = exp.member.exp.instance.data;
6222 Class _class = type._class.registered;
6223 if(_class.type == normalClass)
6225 void *(*Get)(void *) = (void *)prop.Get;
6227 exp.instance = Instantiation { };
6228 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6229 exp.type = instanceExp;
6230 exp.instance.data = Get(value, exp.instance.data);
6242 exp.isConstant = false;
6250 if(exp.type != ExpressionType::memberExp)
6252 FreeExpression(memberExp);
6253 FreeIdentifier(memberID);
6259 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6260 FreeExpContents(exp);
6261 exp.constant = PrintUInt(ComputeTypeSize(type));
6262 exp.type = constantExp;
6268 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6269 if(classSym && classSym.registered)
6271 if(classSym.registered.fixed)
6273 FreeSpecifier(exp._class);
6274 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6275 exp.type = constantExp;
6279 char className[1024];
6280 strcpy(className, "__ecereClass_");
6281 FullClassNameCat(className, classSym.string, true);
6282 //MangleClassName(className);
6284 DeclareClass(classSym, className);
6286 FreeExpContents(exp);
6287 exp.type = pointerExp;
6288 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6289 exp.member.member = MkIdentifier("structSize");
6299 if(exp.type == castExp)
6302 ComputeExpression(exp.cast.exp);
6305 if(e && exp.expType)
6308 type = exp.destType;
6311 if(type.kind == classType)
6313 Class _class = type._class.registered;
6314 if(_class && (_class.type == unitClass || _class.type == bitClass))
6316 if(!_class.dataType)
6317 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6318 type = _class.dataType;
6329 if(GetChar(e, &value))
6331 FreeExpContents(exp);
6332 exp.constant = PrintChar(value);
6333 exp.type = constantExp;
6338 unsigned char value = 0;
6339 if(GetUChar(e, &value))
6341 FreeExpContents(exp);
6342 exp.constant = PrintUChar(value);
6343 exp.type = constantExp;
6351 if(GetShort(e, &value))
6353 FreeExpContents(exp);
6354 exp.constant = PrintShort(value);
6355 exp.type = constantExp;
6360 unsigned short value = 0;
6361 if(GetUShort(e, &value))
6363 FreeExpContents(exp);
6364 exp.constant = PrintUShort(value);
6365 exp.type = constantExp;
6373 if(GetInt(e, &value))
6375 FreeExpContents(exp);
6376 exp.constant = PrintInt(value);
6377 exp.type = constantExp;
6382 unsigned int value = 0;
6383 if(GetUInt(e, &value))
6385 FreeExpContents(exp);
6386 exp.constant = PrintUInt(value);
6387 exp.type = constantExp;
6395 if(GetInt64(e, &value))
6397 FreeExpContents(exp);
6398 exp.constant = PrintInt64(value);
6399 exp.type = constantExp;
6405 if(GetUInt64(e, &value))
6407 FreeExpContents(exp);
6408 exp.constant = PrintUInt64(value);
6409 exp.type = constantExp;
6417 if(GetIntPtr(e, &value))
6419 FreeExpContents(exp);
6420 exp.constant = PrintInt64((int64)value);
6421 exp.type = constantExp;
6427 if(GetUIntPtr(e, &value))
6429 FreeExpContents(exp);
6430 exp.constant = PrintUInt64((uint64)value);
6431 exp.type = constantExp;
6439 if(GetIntSize(e, &value))
6441 FreeExpContents(exp);
6442 exp.constant = PrintInt64((int64)value);
6443 exp.type = constantExp;
6449 if(GetUIntSize(e, &value))
6451 FreeExpContents(exp);
6452 exp.constant = PrintUInt64((uint64)value);
6453 exp.type = constantExp;
6460 if(GetFloat(e, &value))
6462 FreeExpContents(exp);
6463 exp.constant = PrintFloat(value);
6464 exp.type = constantExp;
6471 if(GetDouble(e, &value))
6473 FreeExpContents(exp);
6474 exp.constant = PrintDouble(value);
6475 exp.type = constantExp;
6490 // Caring only about last expression for now...
6491 ComputeExpression(exp.cond.exp->last);
6492 if(exp.cond.elseExp)
6493 ComputeExpression(exp.cond.elseExp);
6495 ComputeExpression(exp.cond.cond);
6497 op1 = GetOperand(exp.cond.cond);
6498 if(op1.type) op1.type.refCount++;
6499 op2 = GetOperand(exp.cond.exp->last);
6500 if(op2.type) op2.type.refCount++;
6501 op3 = GetOperand(exp.cond.elseExp);
6502 if(op3.type) op3.type.refCount++;
6504 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6505 if(op1.type) FreeType(op1.type);
6506 if(op2.type) FreeType(op2.type);
6507 if(op3.type) FreeType(op3.type);
6513 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6518 OldList converts { };
6521 if(destType.kind == voidType)
6524 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6528 // for(convert = converts.last; convert; convert = convert.prev)
6529 for(convert = converts.first; convert; convert = convert.next)
6531 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6534 Expression newExp { };
6535 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6537 // TODO: Check this...
6541 newExp.destType = null;
6546 exp.type = memberExp;
6547 exp.addedThis = true;
6548 exp.member.exp = newExp;
6549 FreeType(exp.member.exp.expType);
6551 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6552 exp.member.exp.expType.classObjectType = objectType;
6553 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6554 exp.member.memberType = propertyMember;
6555 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6556 // TESTING THIS... for (int)degrees
6557 exp.needCast = true;
6558 if(exp.expType) exp.expType.refCount++;
6559 ApplyAnyObjectLogic(exp.member.exp);
6564 /*if(exp.isConstant)
6566 // Color { ColorRGB = [exp] };
6567 exp.type = instanceExp;
6568 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6569 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6570 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6574 // If not constant, don't turn it yet into an instantiation
6575 // (Go through the deep members system first)
6576 exp.type = memberExp;
6577 exp.addedThis = true;
6578 exp.member.exp = newExp;
6580 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6581 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6582 newExp.expType._class.registered.type == noHeadClass)
6584 newExp.byReference = true;
6587 FreeType(exp.member.exp.expType);
6588 /*exp.member.exp.expType = convert.convert.dataType;
6589 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6590 exp.member.exp.expType = null;
6591 if(convert.convert.dataType)
6593 exp.member.exp.expType = { };
6594 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6595 exp.member.exp.expType.refCount = 1;
6596 exp.member.exp.expType.classObjectType = objectType;
6597 ApplyAnyObjectLogic(exp.member.exp);
6600 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6601 exp.member.memberType = reverseConversionMember;
6602 exp.expType = convert.resultType ? convert.resultType :
6603 MkClassType(convert.convert._class.fullName);
6604 exp.needCast = true;
6605 if(convert.resultType) convert.resultType.refCount++;
6611 FreeType(exp.expType);
6614 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6615 if(exp.destType.casted)
6616 exp.needCast = true;
6617 if(exp.expType) exp.expType.refCount++;
6621 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6622 if(exp.destType.casted)
6623 exp.needCast = true;
6624 if(convert.resultType)
6625 convert.resultType.refCount++;
6629 if(exp.isConstant && inCompiler)
6630 ComputeExpression(exp);
6632 converts.Free(FreeConvert);
6635 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6637 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6639 if(!result && exp.expType && exp.destType)
6641 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6642 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6643 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6644 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6648 // if(result) CheckTemplateTypes(exp);
6652 void CheckTemplateTypes(Expression exp)
6654 Expression nbExp = GetNonBracketsExp(exp);
6655 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6656 (nbExp == exp || nbExp.type != castExp))
6658 Expression newExp { };
6661 if(exp.destType) exp.destType.refCount++;
6662 if(exp.expType) exp.expType.refCount++;
6666 switch(exp.expType.kind)
6669 if(exp.destType.classObjectType)
6671 // We need to pass the address, just pass it along (Undo what was done above)
6672 if(exp.destType) exp.destType.refCount--;
6673 if(exp.expType) exp.expType.refCount--;
6678 // If we're looking for value:
6679 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6681 OldList * unionDefs = MkList();
6682 OldList * statements = MkList();
6683 context = PushContext();
6684 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6685 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6686 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6687 exp.type = extensionCompoundExp;
6688 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6689 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6690 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6691 exp.compound.compound.context = context;
6692 PopContext(context);
6697 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6698 if(exp.expType.isPointerType)
6699 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
6701 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6702 exp.needCast = true;
6706 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6708 Expression newExp { };
6711 if(exp.destType) exp.destType.refCount++;
6712 if(exp.expType) exp.expType.refCount++;
6716 switch(exp.expType.kind)
6719 if(exp.destType.classObjectType)
6721 // We need to pass the address, just pass it along (Undo what was done above)
6722 if(exp.destType) exp.destType.refCount--;
6723 if(exp.expType) exp.expType.refCount--;
6728 // If we're looking for value:
6729 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6731 OldList * unionDefs = MkList();
6732 OldList * statements = MkList();
6733 context = PushContext();
6734 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6735 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6736 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6737 exp.type = extensionCompoundExp;
6738 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6739 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6740 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6741 exp.compound.compound.context = context;
6742 PopContext(context);
6747 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6749 exp.type = bracketsExp;
6751 if(exp.expType.isPointerType)
6752 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6753 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6754 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6755 ProcessExpressionType(exp.list->first);
6760 exp.type = bracketsExp;
6761 if(exp.expType.isPointerType)
6763 exp.needTemplateCast = 2;
6764 newExp.needCast = true;
6765 newExp.needTemplateCast = 2;
6766 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6769 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6770 exp.needTemplateCast = 2;
6771 newExp.needCast = true;
6772 newExp.needTemplateCast = 2;
6773 ProcessExpressionType(exp.list->first);
6779 if(exp.expType.kind == templateType)
6781 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6784 FreeType(exp.destType);
6785 FreeType(exp.expType);
6790 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6795 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6796 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6800 char typeString[1024];
6802 OldList * specs = MkList();
6803 typeString[0] = '\0';
6804 PrintType(exp.expType, typeString, false, false);
6805 decl = SpecDeclFromString(typeString, specs, null);
6808 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6809 exp.cast.typeName = MkTypeName(specs, decl);
6810 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6811 exp.cast.exp.needCast = true;
6818 // TODO: The Symbol tree should be reorganized by namespaces
6820 // - Tree of all symbols within (stored without namespace)
6821 // - Tree of sub-namespaces
6823 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6825 int nsLen = strlen(nameSpace);
6827 // Start at the name space prefix
6828 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6830 char * s = symbol.string;
6831 if(!strncmp(s, nameSpace, nsLen))
6833 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6836 for(c = strlen(s)-1; c >= 0; c--)
6841 if(!strcmp(namePart, name))
6843 // TODO: Error on ambiguity
6853 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6856 char nameSpace[1024];
6857 const char * namePart;
6858 bool gotColon = false;
6860 nameSpace[0] = '\0';
6861 for(c = strlen(name)-1; c >= 0; c--)
6868 namePart = name+c+1;
6869 while(c >= 0 && name[c] == ':') c--;
6872 // Try an exact match first
6873 Symbol symbol = (Symbol)tree.FindString(name);
6877 // Namespace specified
6878 memcpy(nameSpace, name, c + 1);
6881 return ScanWithNameSpace(tree, nameSpace, namePart);
6885 // Looking for a global symbol, e.g. ::Sleep()
6886 Symbol symbol = (Symbol)tree.FindString(namePart);
6891 // Name only (no namespace specified)
6892 Symbol symbol = (Symbol)tree.FindString(namePart);
6895 return ScanWithNameSpace(tree, "", namePart);
6900 static void ProcessDeclaration(Declaration decl);
6902 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6905 //Time startTime = GetTime();
6907 // Optimize this later? Do this before/less?
6909 Symbol symbol = null;
6910 // First, check if the identifier is declared inside the function
6911 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6913 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6915 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6921 strcpy(curName, thisNameSpace);
6922 strcat(curName, "::");
6923 strcat(curName, name);
6924 // Try to resolve in current namespace first
6925 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6928 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6931 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6933 if(symbol || ctx == endContext) break;
6935 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6937 if(symbol.pointerExternal.type == functionExternal)
6939 FunctionDefinition function = symbol.pointerExternal.function;
6941 // Modified this recently...
6942 Context tmpContext = curContext;
6944 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6945 curContext = tmpContext;
6947 symbol.pointerExternal.symbol = symbol;
6950 DeclareType(symbol.type, true, true);
6952 ast->Insert(curExternal.prev, symbol.pointerExternal);
6954 symbol.id = curExternal.symbol.idCode;
6957 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6959 ast->Move(symbol.pointerExternal, curExternal.prev);
6960 symbol.id = curExternal.symbol.idCode;
6964 //findSymbolTotalTime += GetTime() - startTime;
6969 static void GetTypeSpecs(Type type, OldList * specs)
6971 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6976 if(type._class.registered)
6978 if(!type._class.registered.dataType)
6979 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6980 GetTypeSpecs(type._class.registered.dataType, specs);
6984 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6985 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6986 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6987 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6988 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6989 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6990 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6991 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6994 ListAdd(specs, MkSpecifier(INT)); break;
6998 static void PrintArraySize(Type arrayType, char * string)
7003 if(arrayType.enumClass)
7004 strcat(size, arrayType.enumClass.string);
7005 else if(arrayType.arraySizeExp)
7006 PrintExpression(arrayType.arraySizeExp, size);
7008 strcat(string, size);
7011 // WARNING : This function expects a null terminated string since it recursively concatenate...
7012 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
7016 if(printConst && type.constant)
7017 strcat(string, "const ");
7022 Symbol c = type._class;
7023 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
7024 // look into merging with thisclass ?
7025 if(type.classObjectType == typedObject)
7026 strcat(string, "typed_object");
7027 else if(type.classObjectType == anyObject)
7028 strcat(string, "any_object");
7032 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
7034 if(type.byReference)
7035 strcat(string, " &");
7038 case voidType: strcat(string, "void"); break;
7039 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
7040 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
7041 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
7042 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
7043 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
7044 case _BoolType: strcat(string, "_Bool"); break;
7045 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
7046 case floatType: strcat(string, "float"); break;
7047 case doubleType: strcat(string, "double"); break;
7051 strcat(string, "struct ");
7052 strcat(string, type.enumName);
7054 else if(type.typeName)
7055 strcat(string, type.typeName);
7059 strcat(string, "struct { ");
7060 for(member = type.members.first; member; member = member.next)
7062 PrintType(member, string, true, fullName);
7063 strcat(string,"; ");
7071 strcat(string, "union ");
7072 strcat(string, type.enumName);
7074 else if(type.typeName)
7075 strcat(string, type.typeName);
7078 strcat(string, "union ");
7079 strcat(string,"(unnamed)");
7085 strcat(string, "enum ");
7086 strcat(string, type.enumName);
7088 else if(type.typeName)
7089 strcat(string, type.typeName);
7091 strcat(string, "int"); // "enum");
7094 strcat(string, "...");
7097 strcat(string, "subclass(");
7098 strcat(string, type._class ? type._class.string : "int");
7099 strcat(string, ")");
7102 strcat(string, type.templateParameter.identifier.string);
7105 strcat(string, "thisclass");
7108 strcat(string, "__builtin_va_list");
7114 static void PrintName(Type type, char * string, bool fullName)
7116 if(type.name && type.name[0])
7119 strcat(string, type.name);
7122 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7123 if(name) name += 2; else name = type.name;
7124 strcat(string, name);
7129 static void PrintAttribs(Type type, char * string)
7133 if(type.dllExport) strcat(string, "dllexport ");
7134 if(type.attrStdcall) strcat(string, "stdcall ");
7138 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7140 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7142 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7143 PrintAttribs(type, string);
7144 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7145 strcat(string, " const");
7146 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7147 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7148 strcat(string, " (");
7149 if(type.kind == pointerType)
7151 if(type.type.kind == functionType || type.type.kind == methodType)
7152 PrintAttribs(type.type, string);
7154 if(type.kind == pointerType)
7156 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7157 strcat(string, "*");
7159 strcat(string, " *");
7161 if(printConst && type.constant && type.kind == pointerType)
7162 strcat(string, " const");
7165 PrintTypeSpecs(type, string, fullName, printConst);
7168 static void PostPrintType(Type type, char * string, bool fullName)
7170 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7171 strcat(string, ")");
7172 if(type.kind == arrayType)
7173 PrintArraySize(type, string);
7174 else if(type.kind == functionType)
7177 strcat(string, "(");
7178 for(param = type.params.first; param; param = param.next)
7180 PrintType(param, string, true, fullName);
7181 if(param.next) strcat(string, ", ");
7183 strcat(string, ")");
7185 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7186 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7190 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7192 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7194 PrePrintType(type, string, fullName, null, printConst);
7196 if(type.thisClass || (printName && type.name && type.name[0]))
7197 strcat(string, " ");
7198 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7200 Symbol _class = type.thisClass;
7201 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7203 if(type.classObjectType == classPointer)
7204 strcat(string, "class");
7206 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7208 else if(_class && _class.string)
7210 String s = _class.string;
7215 char * name = RSearchString(s, "::", strlen(s), true, false);
7216 if(name) name += 2; else name = s;
7217 strcat(string, name);
7220 strcat(string, "::");
7223 if(printName && type.name)
7224 PrintName(type, string, fullName);
7225 PostPrintType(type, string, fullName);
7226 if(type.bitFieldCount)
7229 sprintf(count, ":%d", type.bitFieldCount);
7230 strcat(string, count);
7234 void PrintType(Type type, char * string, bool printName, bool fullName)
7236 _PrintType(type, string, printName, fullName, true);
7239 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7241 _PrintType(type, string, printName, fullName, false);
7244 static Type FindMember(Type type, char * string)
7247 for(memberType = type.members.first; memberType; memberType = memberType.next)
7249 if(!memberType.name)
7251 Type subType = FindMember(memberType, string);
7255 else if(!strcmp(memberType.name, string))
7261 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7264 for(memberType = type.members.first; memberType; memberType = memberType.next)
7266 if(!memberType.name)
7268 Type subType = FindMember(memberType, string);
7271 *offset += memberType.offset;
7275 else if(!strcmp(memberType.name, string))
7277 *offset += memberType.offset;
7284 public bool GetParseError() { return parseError; }
7286 Expression ParseExpressionString(char * expression)
7290 fileInput = TempFile { };
7291 fileInput.Write(expression, 1, strlen(expression));
7292 fileInput.Seek(0, start);
7295 parsedExpression = null;
7297 expression_yyparse();
7300 return parsedExpression;
7303 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7305 Identifier id = exp.identifier;
7306 Method method = null;
7307 Property prop = null;
7308 DataMember member = null;
7309 ClassProperty classProp = null;
7311 if(_class && _class.type == enumClass)
7313 NamedLink64 value = null;
7314 Class enumClass = eSystem_FindClass(privateModule, "enum");
7318 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7320 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7321 for(value = e.values.first; value; value = value.next)
7323 if(!strcmp(value.name, id.string))
7328 exp.isConstant = true;
7329 if(inCompiler || inPreCompiler || inDebugger)
7332 FreeExpContents(exp);
7334 exp.type = constantExp;
7335 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7336 sprintf(constant, FORMAT64D, value.data);
7338 sprintf(constant, FORMAT64HEX, value.data);
7339 exp.constant = CopyString(constant);
7341 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7342 exp.expType = MkClassType(baseClass.fullName);
7350 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7352 ProcessMethodType(method);
7359 // TOCHECK: Put it back to what it was...
7360 // methodClass = _class;
7361 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7366 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7369 ProcessPropertyType(prop);
7370 exp.expType = prop.dataType;
7371 if(prop.dataType) prop.dataType.refCount++;
7374 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7376 if(!member.dataType)
7377 member.dataType = ProcessTypeString(member.dataTypeString, false);
7378 exp.expType = member.dataType;
7379 if(member.dataType) member.dataType.refCount++;
7382 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7384 if(!classProp.dataType)
7385 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7387 if(classProp.constant)
7389 FreeExpContents(exp);
7391 exp.isConstant = true;
7392 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7394 //char constant[256];
7395 exp.type = stringExp;
7396 exp.constant = QMkString((char *)(uintptr)classProp.Get(_class));
7401 exp.type = constantExp;
7402 sprintf(constant, "%d", (int)classProp.Get(_class));
7403 exp.constant = CopyString(constant);
7411 exp.expType = classProp.dataType;
7412 if(classProp.dataType) classProp.dataType.refCount++;
7418 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7420 BinaryTree * tree = &nameSpace.functions;
7421 GlobalData data = (GlobalData)tree->FindString(name);
7425 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7427 data = ScanGlobalData(child, name);
7435 static GlobalData FindGlobalData(char * name)
7438 NameSpace * nameSpace;
7439 nameSpace = globalData;
7440 for(c = 0; name[c]; c++)
7442 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7444 NameSpace * newSpace;
7445 char * spaceName = new char[c - start + 1];
7446 strncpy(spaceName, name + start, c - start);
7447 spaceName[c-start] = '\0';
7448 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7452 nameSpace = newSpace;
7453 if(name[c] == ':') c++;
7459 return ScanGlobalData(nameSpace, name + start);
7464 static int definedExpStackPos;
7465 static void * definedExpStack[512];
7467 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7468 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7470 Expression prev = checkedExp.prev, next = checkedExp.next;
7472 FreeExpContents(checkedExp);
7473 FreeType(checkedExp.expType);
7474 FreeType(checkedExp.destType);
7476 *checkedExp = *newExp;
7480 checkedExp.prev = prev;
7481 checkedExp.next = next;
7484 void ApplyAnyObjectLogic(Expression e)
7486 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7488 char debugExpString[4096];
7489 debugExpString[0] = '\0';
7490 PrintExpression(e, debugExpString);
7493 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7495 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7496 //ellipsisDestType = destType;
7499 Type type = e.expType;
7500 Class _class = null;
7501 //Type destType = e.destType;
7503 if(type.kind == classType && type._class && type._class.registered)
7505 _class = type._class.registered;
7507 else if(type.kind == subClassType)
7509 _class = FindClass("ecere::com::Class").registered;
7513 char string[1024] = "";
7516 PrintTypeNoConst(type, string, false, true);
7517 classSym = FindClass(string);
7518 if(classSym) _class = classSym.registered;
7521 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...
7522 (!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))) ||
7523 destType.byReference)))
7525 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7527 Expression checkedExp = e, newExp;
7529 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7531 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7533 if(checkedExp.type == extensionCompoundExp)
7535 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7538 checkedExp = checkedExp.list->last;
7540 else if(checkedExp.type == castExp)
7541 checkedExp = checkedExp.cast.exp;
7544 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7546 newExp = checkedExp.op.exp2;
7547 checkedExp.op.exp2 = null;
7548 FreeExpContents(checkedExp);
7550 if(e.expType && e.expType.passAsTemplate)
7553 ComputeTypeSize(e.expType);
7554 sprintf(size, "%d", e.expType.size);
7555 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7556 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7557 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7560 ReplaceExpContents(checkedExp, newExp);
7561 e.byReference = true;
7563 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7565 Expression checkedExp; //, newExp;
7568 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7570 e.type == identifierExp ||
7571 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7572 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7573 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7576 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7578 Context context = PushContext();
7580 OldList * specs = MkList();
7581 char typeString[1024];
7582 Expression newExp { };
7584 typeString[0] = '\0';
7587 //if(e.destType) e.destType.refCount++;
7588 // if(exp.expType) exp.expType.refCount++;
7591 newExp.expType = null;
7593 PrintTypeNoConst(e.expType, typeString, false, true);
7594 decl = SpecDeclFromString(typeString, specs, null);
7595 newExp.destType = ProcessType(specs, decl);
7597 curContext = context;
7599 // We need a current compound for this
7603 OldList * stmts = MkList();
7604 e.type = extensionCompoundExp;
7605 sprintf(name, "__internalValue%03X", internalValueCounter++);
7606 if(!curCompound.compound.declarations)
7607 curCompound.compound.declarations = MkList();
7608 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7609 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7610 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7611 e.compound = MkCompoundStmt(null, stmts);
7614 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7617 e.compound = MkCompoundStmt(
7618 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7619 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7621 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7625 Type type = e.destType;
7627 CopyTypeInto(e.destType, type);
7628 e.destType.refCount = 1;
7629 e.destType.classObjectType = none;
7633 e.compound.compound.context = context;
7634 PopContext(context);
7635 curContext = context.parent;
7639 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7641 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7643 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7645 if(checkedExp.type == extensionCompoundExp)
7647 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7650 checkedExp = checkedExp.list->last;
7652 else if(checkedExp.type == castExp)
7653 checkedExp = checkedExp.cast.exp;
7656 Expression operand { };
7657 operand = *checkedExp;
7659 checkedExp.destType = ProcessTypeString("void *", false);
7660 checkedExp.expType = checkedExp.destType;
7661 checkedExp.destType.refCount++;
7663 checkedExp.type = opExp;
7664 checkedExp.op.op = '&';
7665 checkedExp.op.exp1 = null;
7666 checkedExp.op.exp2 = operand;
7668 //newExp = MkExpOp(null, '&', checkedExp);
7670 //ReplaceExpContents(checkedExp, newExp);
7677 // If expression type is a simple class, make it an address
7678 // FixReference(e, true);
7681 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7682 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7683 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7685 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"))
7687 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7691 Expression thisExp { };
7694 thisExp.prev = null;
7695 thisExp.next = null;
7698 e.type = bracketsExp;
7699 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7700 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7701 ((Expression)e.list->first).byReference = true;
7703 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7705 e.expType = thisExp.expType;
7706 e.expType.refCount++;
7711 CopyTypeInto(e.expType, thisExp.expType);
7712 e.expType.byReference = false;
7713 e.expType.refCount = 1;
7715 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7716 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7718 e.expType.classObjectType = none;
7723 // TOFIX: Try this for a nice IDE crash!
7725 // The other way around
7728 if(destType && e.expType &&
7729 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7730 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7731 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7733 if(destType.kind == ellipsisType)
7735 Compiler_Error($"Unspecified type\n");
7737 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7739 bool byReference = e.expType.byReference;
7740 Expression thisExp { };
7742 OldList * specs = MkList();
7743 char typeString[1024]; // Watch buffer overruns
7745 ClassObjectType backupClassObjectType;
7746 bool backupByReference;
7748 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7753 backupClassObjectType = type.classObjectType;
7754 backupByReference = type.byReference;
7756 type.classObjectType = none;
7757 type.byReference = false;
7759 typeString[0] = '\0';
7760 PrintType(type, typeString, false, true);
7761 decl = SpecDeclFromString(typeString, specs, null);
7763 type.classObjectType = backupClassObjectType;
7764 type.byReference = backupByReference;
7767 thisExp.prev = null;
7768 thisExp.next = null;
7771 if( ( type.kind == classType && type._class && type._class.registered &&
7772 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7773 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7774 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7775 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7780 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7783 CopyTypeInto(e.expType, type);
7784 e.expType.byReference = false;
7785 e.expType.refCount = 1;
7790 e.cast.typeName = MkTypeName(specs, decl);
7791 e.cast.exp = thisExp;
7792 e.byReference = true;
7796 e.destType = destType;
7797 destType.refCount++;
7802 void ApplyLocation(Expression exp, Location loc)
7808 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7809 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7815 for(e = exp.list->first; e; e = e.next)
7816 ApplyLocation(e, loc);
7823 for(e = exp.index.index->first; e; e = e.next)
7824 ApplyLocation(e, loc);
7827 ApplyLocation(exp.index.exp, loc);
7830 if(exp.call.arguments)
7833 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7834 ApplyLocation(arg, loc);
7837 ApplyLocation(exp.call.exp, loc);
7842 ApplyLocation(exp.member.exp, loc);
7846 ApplyLocation(exp.cast.exp, loc);
7852 for(e = exp.cond.exp->first; e; e = e.next)
7853 ApplyLocation(e, loc);
7856 ApplyLocation(exp.cond.cond, loc);
7857 if(exp.cond.elseExp)
7858 ApplyLocation(exp.cond.elseExp, loc);
7862 ApplyLocation(exp.vaArg.exp, loc);
7869 void ProcessExpressionType(Expression exp)
7871 bool unresolved = false;
7872 Location oldyylloc = yylloc;
7873 bool notByReference = false;
7875 char debugExpString[4096];
7876 debugExpString[0] = '\0';
7877 PrintExpression(exp, debugExpString);
7879 if(!exp || exp.expType)
7882 //eSystem_Logf("%s\n", expString);
7884 // Testing this here
7890 Identifier id = exp.identifier;
7891 if(!id || !topContext) return;
7893 // DOING THIS LATER NOW...
7894 if(id._class && id._class.name)
7896 id.classSym = id._class.symbol; // FindClass(id._class.name);
7897 /* TODO: Name Space Fix ups
7899 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7903 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7905 exp.expType = ProcessTypeString("Module", true);
7909 if(!strcmp(id.string, "__runtimePlatform"))
7911 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7914 else if(strstr(id.string, "__ecereClass") == id.string)
7916 exp.expType = ProcessTypeString("ecere::com::Class", true);
7919 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7921 // Added this here as well
7922 ReplaceClassMembers(exp, thisClass);
7923 if(exp.type != identifierExp)
7925 ProcessExpressionType(exp);
7929 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7934 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7935 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7936 if(!symbol/* && exp.destType*/)
7938 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7944 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7945 if(exp.type != identifierExp)
7947 ProcessExpressionType(exp);
7951 // Static methods called from inside the _class
7952 else if(currentClass && !id._class)
7954 if(ResolveIdWithClass(exp, currentClass, true))
7957 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7961 // If we manage to resolve this symbol
7964 Type type = symbol.type;
7965 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7967 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7969 Context context = SetupTemplatesContext(_class);
7970 type = ReplaceThisClassType(_class);
7971 FinishTemplatesContext(context);
7972 if(type) type.refCount = 0; // We'll be incrementing it right below...
7975 FreeSpecifier(id._class);
7978 id.string = CopyString(symbol.string);
7985 // Commented this out, it was making non-constant enum parameters seen as constant
7986 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7987 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7988 // Add missing cases here... enum Classes...
7989 exp.isConstant = true;
7991 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7992 if(symbol.isParam || !strcmp(id.string, "this"))
7994 if(_class && _class.type == structClass && !type.declaredWithStruct)
7995 exp.byReference = true;
7997 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7998 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7999 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
8000 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
8002 Identifier id = exp.identifier;
8003 exp.type = bracketsExp;
8004 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
8008 if(symbol.isIterator)
8010 if(symbol.isIterator == 3)
8012 exp.type = bracketsExp;
8013 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
8014 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
8016 ProcessExpressionType(exp);
8018 else if(symbol.isIterator != 4)
8020 exp.type = memberExp;
8021 exp.member.exp = MkExpIdentifier(exp.identifier);
8022 exp.member.exp.expType = exp.expType;
8023 /*if(symbol.isIterator == 6)
8024 exp.member.member = MkIdentifier("key");
8026 exp.member.member = MkIdentifier("data");
8028 ProcessExpressionType(exp);
8035 DefinedExpression definedExp = null;
8036 if(thisNameSpace && !(id._class && !id._class.name))
8039 strcpy(name, thisNameSpace);
8041 strcat(name, id.string);
8042 definedExp = eSystem_FindDefine(privateModule, name);
8045 definedExp = eSystem_FindDefine(privateModule, id.string);
8049 for(c = 0; c<definedExpStackPos; c++)
8050 if(definedExpStack[c] == definedExp)
8052 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
8054 Location backupYylloc = yylloc;
8055 File backInput = fileInput;
8056 definedExpStack[definedExpStackPos++] = definedExp;
8058 fileInput = TempFile { };
8059 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
8060 fileInput.Seek(0, start);
8063 parsedExpression = null;
8065 expression_yyparse();
8068 fileInput = backInput;
8070 yylloc = backupYylloc;
8072 if(parsedExpression)
8075 exp.type = bracketsExp;
8076 exp.list = MkListOne(parsedExpression);
8077 ApplyLocation(parsedExpression, yylloc);
8078 ProcessExpressionType(exp);
8079 definedExpStackPos--;
8082 definedExpStackPos--;
8088 Compiler_Error($"Recursion in defined expression %s\n", id.string);
8094 GlobalData data = null;
8095 if(thisNameSpace && !(id._class && !id._class.name))
8098 strcpy(name, thisNameSpace);
8100 strcat(name, id.string);
8101 data = FindGlobalData(name);
8104 data = FindGlobalData(id.string);
8107 DeclareGlobalData(data);
8108 exp.expType = data.dataType;
8109 if(data.dataType) data.dataType.refCount++;
8112 id.string = CopyString(data.fullName);
8113 FreeSpecifier(id._class);
8120 GlobalFunction function = null;
8121 if(thisNameSpace && !(id._class && !id._class.name))
8124 strcpy(name, thisNameSpace);
8126 strcat(name, id.string);
8127 function = eSystem_FindFunction(privateModule, name);
8130 function = eSystem_FindFunction(privateModule, id.string);
8135 id.string = CopyString(function.name);
8138 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8139 strcpy(name, "__ecereFunction_");
8140 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8141 if(DeclareFunction(function, name))
8144 id.string = CopyString(name);
8146 exp.expType = function.dataType;
8147 if(function.dataType) function.dataType.refCount++;
8149 FreeSpecifier(id._class);
8166 if(!exp.instance._class)
8168 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8170 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8174 //classSym = FindClass(exp.instance._class.fullName);
8175 //_class = classSym ? classSym.registered : null;
8177 ProcessInstantiationType(exp.instance);
8179 exp.isConstant = exp.instance.isConstant;
8182 if(_class.type == unitClass && _class.base.type != systemClass)
8185 Type destType = exp.destType;
8187 exp.destType = MkClassType(_class.base.fullName);
8188 exp.expType = MkClassType(_class.fullName);
8189 CheckExpressionType(exp, exp.destType, true);
8191 exp.destType = destType;
8193 exp.expType = MkClassType(_class.fullName);
8196 if(exp.instance._class)
8198 exp.expType = MkClassType(exp.instance._class.name);
8199 /*if(exp.expType._class && exp.expType._class.registered &&
8200 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8201 exp.expType.byReference = true;*/
8209 char * constant = exp.constant;
8217 if(constant[0] == '\'')
8219 if((int)((byte *)constant)[1] > 127)
8222 unichar ch = UTF8GetChar(constant + 1, &nb);
8223 if(nb < 2) ch = constant[1];
8225 exp.constant = PrintUInt(ch);
8226 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8227 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8228 type._class = FindClass("unichar");
8230 type.isSigned = false;
8234 type.kind = charType;
8235 type.isSigned = true;
8240 char * dot = strchr(constant, '.');
8241 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8245 exponent = strchr(constant, 'p');
8246 if(!exponent) exponent = strchr(constant, 'P');
8250 exponent = strchr(constant, 'e');
8251 if(!exponent) exponent = strchr(constant, 'E');
8256 if(strchr(constant, 'f') || strchr(constant, 'F'))
8257 type.kind = floatType;
8259 type.kind = doubleType;
8260 type.isSigned = true;
8264 bool isSigned = constant[0] == '-';
8266 int64 i64 = strtoll(constant, &endP, 0);
8267 uint64 ui64 = strtoull(constant, &endP, 0);
8268 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8281 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8285 else if(constant[0] != '0' || !constant[1])
8288 type.kind = is64Bit ? int64Type : intType;
8289 type.isSigned = isSigned;
8292 exp.isConstant = true;
8293 if(exp.destType && exp.destType.kind == doubleType)
8294 type.kind = doubleType;
8295 else if(exp.destType && exp.destType.kind == floatType)
8296 type.kind = floatType;
8297 else if(exp.destType && exp.destType.kind == int64Type)
8298 type.kind = int64Type;
8304 exp.isConstant = true; // Why wasn't this constant?
8312 kind = exp.wideString ? shortType : charType;
8314 isSigned = exp.wideString ? false : true;
8321 ProcessExpressionType(exp._new.size);
8326 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8328 DeclareType(exp.expType.type, false, false);
8332 ProcessExpressionType(exp._renew.size);
8333 ProcessExpressionType(exp._renew.exp);
8338 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8340 DeclareType(exp.expType.type, false, false);
8344 bool assign = false, boolResult = false, boolOps = false;
8345 Type type1 = null, type2 = null;
8346 bool useDestType = false, useSideType = false;
8347 Location oldyylloc = yylloc;
8348 bool useSideUnit = false;
8349 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8351 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8360 // Assignment Operators
8374 // boolean Operators
8376 // Expect boolean operators
8378 //boolResult = true;
8382 // Expect boolean operands
8393 // Gives boolean result
8425 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8431 /*// Implement speed etc.
8437 if(exp.op.op == '&')
8439 // Added this here earlier for Iterator address as key
8440 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8442 Identifier id = exp.op.exp2.identifier;
8443 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8444 if(symbol && symbol.isIterator == 2)
8446 exp.type = memberExp;
8447 exp.member.exp = exp.op.exp2;
8448 exp.member.member = MkIdentifier("key");
8450 exp.op.exp2.expType = symbol.type;
8451 symbol.type.refCount++;
8452 ProcessExpressionType(exp);
8456 // exp.op.exp2.usage.usageRef = true;
8460 //dummy.kind = TypeDummy;
8463 // Added this check here to use the dest type only for units derived from the base unit
8464 // So that untyped units will use the side unit as opposed to the untyped destination unit
8465 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8466 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8467 useDestType = false;
8469 if(destClass && useDestType &&
8470 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8472 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8474 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8475 exp.op.exp1.destType = exp.destType;
8476 exp.op.exp1.opDestType = true;
8478 exp.destType.refCount++;
8482 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8483 exp.op.exp1.destType = dummy;
8487 // TESTING THIS HERE...
8488 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8489 ProcessExpressionType(exp.op.exp1);
8490 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8492 exp.op.exp1.opDestType = false;
8494 // Fix for unit and ++ / --
8495 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8496 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8498 exp.op.exp2 = MkExpConstant("1");
8499 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8503 if(exp.op.exp1.destType == dummy)
8506 exp.op.exp1.destType = null;
8508 type1 = exp.op.exp1.expType;
8513 char expString[10240];
8514 expString[0] = '\0';
8515 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8519 exp.op.exp2.destType = exp.op.exp1.expType;
8520 if(exp.op.exp1.expType)
8521 exp.op.exp1.expType.refCount++;
8525 exp.op.exp2.destType = exp.destType;
8526 if(!exp.op.exp1 || exp.op.op != '&')
8527 exp.op.exp2.opDestType = true;
8529 exp.destType.refCount++;
8532 if(type1) type1.refCount++;
8533 exp.expType = type1;
8538 PrintExpression(exp.op.exp2, expString);
8540 if(type1 && type1.kind == pointerType)
8542 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 ||
8543 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8544 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8545 else if(exp.op.op == '=')
8547 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8548 exp.op.exp2.destType = type1;
8555 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8556 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/* ||
8557 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8560 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8561 exp.op.exp2.destType = type1;
8566 if(type1) type1.refCount++;
8567 exp.expType = type1;
8569 else if(destClass &&
8570 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8571 (destClass.type == enumClass && useDestType)))
8573 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8574 exp.op.exp2.destType = exp.destType;
8575 if(exp.op.op != '&')
8576 exp.op.exp2.opDestType = true;
8578 exp.destType.refCount++;
8582 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8583 exp.op.exp2.destType = dummy;
8587 // TESTING THIS HERE... (DANGEROUS)
8588 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8589 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8591 FreeType(exp.op.exp2.destType);
8592 exp.op.exp2.destType = type1;
8595 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8596 // Cannot lose the cast on a sizeof
8597 if(exp.op.op == SIZEOF)
8599 Expression e = exp.op.exp2;
8600 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8602 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8604 if(e.type == extensionCompoundExp)
8605 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8610 if(e.type == castExp && e.cast.exp)
8611 e.cast.exp.needCast = true;
8613 ProcessExpressionType(exp.op.exp2);
8614 exp.op.exp2.opDestType = false;
8615 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8617 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8619 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)
8621 if(exp.op.op != '=' && type1.type.kind == voidType)
8622 Compiler_Error($"void *: unknown size\n");
8624 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||
8625 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8626 (exp.op.exp2.expType._class.registered.type == normalClass ||
8627 exp.op.exp2.expType._class.registered.type == structClass ||
8628 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8630 if(exp.op.op == ADD_ASSIGN)
8631 Compiler_Error($"cannot add two pointers\n");
8633 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8634 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8636 if(exp.op.op == ADD_ASSIGN)
8637 Compiler_Error($"cannot add two pointers\n");
8641 char type1String[1024];
8642 char type2String[1024];
8643 type1String[0] = '\0';
8644 type2String[0] = '\0';
8646 PrintType(exp.op.exp2.expType, type1String, false, true);
8647 PrintType(type1, type2String, false, true);
8648 ChangeCh(expString, '\n', ' ');
8649 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8653 if(exp.op.exp2.destType == dummy)
8656 exp.op.exp2.destType = null;
8659 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8663 CopyTypeInto(type2, exp.op.exp2.expType);
8664 type2.isSigned = true;
8666 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8668 type2 = { kind = intType };
8670 type2.isSigned = true;
8674 type2 = exp.op.exp2.expType;
8675 if(type2) type2.refCount++;
8679 dummy.kind = voidType;
8681 if(exp.op.op == SIZEOF)
8688 exp.isConstant = true;
8690 // Get type of dereferenced pointer
8691 else if(exp.op.op == '*' && !exp.op.exp1)
8693 exp.expType = Dereference(type2);
8694 if(type2 && type2.kind == classType)
8695 notByReference = true;
8697 else if(exp.op.op == '&' && !exp.op.exp1)
8698 exp.expType = Reference(type2);
8705 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8706 exp.op.exp1.destType = MkClassType("bool");
8707 exp.op.exp1.destType.truth = true;
8708 if(!exp.op.exp1.expType)
8709 ProcessExpressionType(exp.op.exp1);
8711 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8712 FreeType(exp.op.exp1.expType);
8713 exp.op.exp1.expType = MkClassType("bool");
8714 exp.op.exp1.expType.truth = true;
8718 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8719 exp.op.exp2.destType = MkClassType("bool");
8720 exp.op.exp2.destType.truth = true;
8721 if(!exp.op.exp2.expType)
8722 ProcessExpressionType(exp.op.exp2);
8724 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8725 FreeType(exp.op.exp2.expType);
8726 exp.op.exp2.expType = MkClassType("bool");
8727 exp.op.exp2.expType.truth = true;
8730 else if(exp.op.exp1 && exp.op.exp2 &&
8733 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8734 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8735 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8736 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8738 if(type1 && type2 &&
8739 // If either both are class or both are not class
8740 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8742 // Added this check for enum subtraction to result in an int type:
8743 if(exp.op.op == '-' &&
8744 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8745 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8748 if(!type1._class.registered.dataType)
8749 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8750 if(!type2._class.registered.dataType)
8751 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8753 intType = ProcessTypeString(
8754 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8756 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8757 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8758 exp.op.exp1.destType = intType;
8759 exp.op.exp2.destType = intType;
8764 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8765 exp.op.exp2.destType = type1;
8767 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8768 exp.op.exp1.destType = type2;
8772 // Warning here for adding Radians + Degrees with no destination type
8773 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8774 type1._class.registered && type1._class.registered.type == unitClass &&
8775 type2._class.registered && type2._class.registered.type == unitClass &&
8776 type1._class.registered != type2._class.registered)
8777 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8778 type1._class.string, type2._class.string, type1._class.string);
8780 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8782 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8785 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8787 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8788 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8791 ProcessExpressionType(exp.op.exp1);
8793 if(type2.kind != pointerType)
8795 ProcessExpressionType(classExp);
8797 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8799 if(!exp.op.exp2.expType)
8803 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8807 ProcessExpressionType(exp.op.exp2);
8812 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)))
8814 if(type1.kind != classType && type1.type.kind == voidType)
8815 Compiler_Error($"void *: unknown size\n");
8816 exp.expType = type1;
8817 if(type1) type1.refCount++;
8819 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)))
8821 if(type2.kind != classType && type2.type.kind == voidType)
8822 Compiler_Error($"void *: unknown size\n");
8823 exp.expType = type2;
8824 if(type2) type2.refCount++;
8826 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8827 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8829 Compiler_Warning($"different levels of indirection\n");
8833 bool success = false;
8834 if(type1.kind == pointerType && type2.kind == pointerType)
8836 if(exp.op.op == '+')
8837 Compiler_Error($"cannot add two pointers\n");
8838 else if(exp.op.op == '-')
8840 // Pointer Subtraction gives integer
8841 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8850 if(type1.type.kind == templateType)
8852 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8855 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8857 ProcessExpressionType(classExp);
8859 exp.type = bracketsExp;
8860 exp.list = MkListOne(MkExpOp(
8861 MkExpBrackets(MkListOne(MkExpOp(
8862 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8864 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8865 MkExpMember(classExp, MkIdentifier("typeSize"))));
8867 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8876 if(!success && exp.op.exp1.type == constantExp)
8878 // If first expression is constant, try to match that first
8879 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8881 if(exp.expType) FreeType(exp.expType);
8882 exp.expType = exp.op.exp1.destType;
8883 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8886 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8888 if(exp.expType) FreeType(exp.expType);
8889 exp.expType = exp.op.exp2.destType;
8890 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8896 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8898 if(exp.expType) FreeType(exp.expType);
8899 exp.expType = exp.op.exp2.destType;
8900 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8903 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8905 if(exp.expType) FreeType(exp.expType);
8906 exp.expType = exp.op.exp1.destType;
8907 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8913 char expString1[10240];
8914 char expString2[10240];
8917 expString1[0] = '\0';
8918 expString2[0] = '\0';
8923 PrintExpression(exp.op.exp1, expString1);
8924 ChangeCh(expString1, '\n', ' ');
8925 PrintExpression(exp.op.exp2, expString2);
8926 ChangeCh(expString2, '\n', ' ');
8927 PrintType(exp.op.exp1.expType, type1, false, true);
8928 PrintType(exp.op.exp2.expType, type2, false, true);
8931 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8935 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8936 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8938 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8939 // Convert e.g. / 4 into / 4.0
8940 exp.op.exp1.destType = type2._class.registered.dataType;
8941 if(type2._class.registered.dataType)
8942 type2._class.registered.dataType.refCount++;
8943 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8944 exp.expType = type2;
8945 if(type2) type2.refCount++;
8947 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8949 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8950 // Convert e.g. / 4 into / 4.0
8951 exp.op.exp2.destType = type1._class.registered.dataType;
8952 if(type1._class.registered.dataType)
8953 type1._class.registered.dataType.refCount++;
8954 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8955 exp.expType = type1;
8956 if(type1) type1.refCount++;
8962 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8964 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8966 if(!type1._class.registered.dataType)
8967 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8968 exp.op.exp2.destType = type1._class.registered.dataType;
8969 exp.op.exp2.destType.refCount++;
8971 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8974 type2 = exp.op.exp2.destType;
8975 if(type2) type2.refCount++;
8977 exp.expType = type2;
8981 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8983 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8985 if(!type2._class.registered.dataType)
8986 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8987 exp.op.exp1.destType = type2._class.registered.dataType;
8988 exp.op.exp1.destType.refCount++;
8990 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8991 type1 = exp.op.exp1.destType;
8992 exp.expType = type1;
8996 // TESTING THIS NEW CODE
8997 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8999 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
9000 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
9001 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
9003 // Convert the enum to an int instead for these operators
9004 if(op1IsEnum && exp.op.exp2.expType)
9006 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
9008 if(exp.expType) FreeType(exp.expType);
9009 exp.expType = exp.op.exp2.expType;
9010 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9014 else if(op2IsEnum && exp.op.exp1.expType)
9016 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
9018 if(exp.expType) FreeType(exp.expType);
9019 exp.expType = exp.op.exp1.expType;
9020 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9027 if(op1IsEnum && exp.op.exp2.expType)
9029 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
9031 if(exp.expType) FreeType(exp.expType);
9032 exp.expType = exp.op.exp1.expType;
9033 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9037 else if(op2IsEnum && exp.op.exp1.expType)
9039 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
9041 if(exp.expType) FreeType(exp.expType);
9042 exp.expType = exp.op.exp2.expType;
9043 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9052 // 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
9053 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
9054 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
9056 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9057 exp.op.exp1.destType = type2;
9060 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9062 if(exp.expType) FreeType(exp.expType);
9063 exp.expType = exp.op.exp1.destType;
9064 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9069 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9070 exp.op.exp2.destType = type1;
9074 // Maybe this was meant to be an enum...
9075 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9077 Type oldType = exp.op.exp2.expType;
9078 exp.op.exp2.expType = null;
9079 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9082 exp.op.exp2.expType = oldType;
9087 // TESTING THIS HERE... LATEST ADDITION
9088 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9090 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9091 exp.op.exp2.destType = type2._class.registered.dataType;
9092 if(type2._class.registered.dataType)
9093 type2._class.registered.dataType.refCount++;
9094 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9096 //exp.expType = type2._class.registered.dataType; //type2;
9097 //if(type2) type2.refCount++;
9100 // TESTING THIS HERE... LATEST ADDITION
9101 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9103 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9104 exp.op.exp1.destType = type1._class.registered.dataType;
9105 if(type1._class.registered.dataType)
9106 type1._class.registered.dataType.refCount++;
9107 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9108 exp.expType = type1._class.registered.dataType; //type1;
9109 if(type1) type1.refCount++;
9113 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9115 if(exp.expType) FreeType(exp.expType);
9116 exp.expType = exp.op.exp2.destType;
9117 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9119 else if(type1 && type2)
9121 char expString1[10240];
9122 char expString2[10240];
9123 char type1String[1024];
9124 char type2String[1024];
9125 expString1[0] = '\0';
9126 expString2[0] = '\0';
9127 type1String[0] = '\0';
9128 type2String[0] = '\0';
9131 PrintExpression(exp.op.exp1, expString1);
9132 ChangeCh(expString1, '\n', ' ');
9133 PrintExpression(exp.op.exp2, expString2);
9134 ChangeCh(expString2, '\n', ' ');
9135 PrintType(exp.op.exp1.expType, type1String, false, true);
9136 PrintType(exp.op.exp2.expType, type2String, false, true);
9139 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9141 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9143 exp.expType = exp.op.exp1.expType;
9144 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9146 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9148 exp.expType = exp.op.exp2.expType;
9149 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9157 // Maybe this was meant to be an enum...
9158 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9160 Type oldType = exp.op.exp1.expType;
9161 exp.op.exp1.expType = null;
9162 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9165 exp.op.exp1.expType = oldType;
9168 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9169 exp.op.exp1.destType = type2;
9172 // TESTING THIS HERE... LATEST ADDITION
9173 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9175 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9176 exp.op.exp1.destType = type1._class.registered.dataType;
9177 if(type1._class.registered.dataType)
9178 type1._class.registered.dataType.refCount++;
9181 // TESTING THIS HERE... LATEST ADDITION
9182 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9184 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9185 exp.op.exp2.destType = type2._class.registered.dataType;
9186 if(type2._class.registered.dataType)
9187 type2._class.registered.dataType.refCount++;
9191 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9193 if(exp.expType) FreeType(exp.expType);
9194 exp.expType = exp.op.exp1.destType;
9195 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9199 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9201 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9203 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9204 // Convert e.g. / 4 into / 4.0
9205 exp.op.exp1.destType = type2._class.registered.dataType;
9206 if(type2._class.registered.dataType)
9207 type2._class.registered.dataType.refCount++;
9208 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9210 if(exp.op.op == '!')
9212 exp.expType = MkClassType("bool");
9213 exp.expType.truth = true;
9217 exp.expType = type2;
9218 if(type2) type2.refCount++;
9221 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9223 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9225 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9226 // Convert e.g. / 4 into / 4.0
9227 exp.op.exp2.destType = type1._class.registered.dataType;
9228 if(type1._class.registered.dataType)
9229 type1._class.registered.dataType.refCount++;
9230 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9232 exp.expType = type1;
9233 if(type1) type1.refCount++;
9238 if(exp.op.exp1 && !exp.op.exp1.expType)
9240 char expString[10000];
9241 expString[0] = '\0';
9244 PrintExpression(exp.op.exp1, expString);
9245 ChangeCh(expString, '\n', ' ');
9248 Compiler_Error($"couldn't determine type of %s\n", expString);
9250 if(exp.op.exp2 && !exp.op.exp2.expType)
9252 char expString[10240];
9253 expString[0] = '\0';
9256 PrintExpression(exp.op.exp2, expString);
9257 ChangeCh(expString, '\n', ' ');
9260 Compiler_Error($"couldn't determine type of %s\n", expString);
9265 FreeType(exp.expType);
9266 exp.expType = MkClassType("bool");
9267 exp.expType.truth = true;
9270 if(exp.op.op != SIZEOF)
9271 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9272 (!exp.op.exp2 || exp.op.exp2.isConstant);
9274 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9276 DeclareType(exp.op.exp2.expType, false, false);
9279 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9280 Compiler_Warning($"deleting const qualified object\n");
9290 case extensionExpressionExp:
9293 exp.isConstant = true;
9294 for(e = exp.list->first; e; e = e.next)
9299 FreeType(e.destType);
9300 e.opDestType = exp.opDestType;
9301 e.destType = exp.destType;
9302 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9304 ProcessExpressionType(e);
9306 exp.destType.count--;
9307 if(!exp.expType && !e.next)
9309 exp.expType = e.expType;
9310 if(e.expType) e.expType.refCount++;
9313 exp.isConstant = false;
9316 // In case a cast became a member...
9317 e = exp.list->first;
9318 if(!e.next && e.type == memberExp)
9320 // Preserve prev, next
9321 Expression next = exp.next, prev = exp.prev;
9324 FreeType(exp.expType);
9325 FreeType(exp.destType);
9335 ProcessExpressionType(exp);
9342 exp.isConstant = true;
9344 ProcessExpressionType(exp.index.exp);
9345 if(!exp.index.exp.isConstant)
9346 exp.isConstant = false;
9348 if(exp.index.exp.expType)
9350 Type source = exp.index.exp.expType;
9351 if(source.kind == classType && source._class && source._class.registered)
9353 Class _class = source._class.registered;
9354 Class c = _class.templateClass ? _class.templateClass : _class;
9355 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9357 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9359 if(exp.index.index && exp.index.index->last)
9361 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9363 if(type.kind == classType) type.constant = true;
9364 else if(type.kind == pointerType)
9367 while(t.kind == pointerType) t = t.type;
9371 ((Expression)exp.index.index->last).destType = type;
9377 for(e = exp.index.index->first; e; e = e.next)
9379 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9381 if(e.destType) FreeType(e.destType);
9382 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9384 ProcessExpressionType(e);
9387 // Check if this type is int
9390 exp.isConstant = false;
9394 exp.expType = Dereference(exp.index.exp.expType);
9396 DeclareType(exp.expType, false, false);
9403 Type methodType = null;
9409 PrintExpression(exp.call.exp, name);
9410 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9412 //exp.call.exp.expType = null;
9413 PrintExpression(exp.call.exp, name);
9416 if(exp.call.exp.type == identifierExp)
9418 Expression idExp = exp.call.exp;
9419 Identifier id = idExp.identifier;
9420 if(!strcmp(id.string, "__builtin_frame_address"))
9422 exp.expType = ProcessTypeString("void *", true);
9423 if(exp.call.arguments && exp.call.arguments->first)
9424 ProcessExpressionType(exp.call.arguments->first);
9427 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9429 exp.expType = ProcessTypeString("int", true);
9430 if(exp.call.arguments && exp.call.arguments->first)
9431 ProcessExpressionType(exp.call.arguments->first);
9434 else if(!strcmp(id.string, "Max") ||
9435 !strcmp(id.string, "Min") ||
9436 !strcmp(id.string, "Sgn") ||
9437 !strcmp(id.string, "Abs"))
9439 Expression a = null;
9440 Expression b = null;
9441 Expression tempExp1 = null, tempExp2 = null;
9442 if((!strcmp(id.string, "Max") ||
9443 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9445 a = exp.call.arguments->first;
9446 b = exp.call.arguments->last;
9450 else if(exp.call.arguments->count == 1)
9452 a = exp.call.arguments->first;
9458 exp.call.arguments->Clear();
9459 idExp.identifier = null;
9461 FreeExpContents(exp);
9463 ProcessExpressionType(a);
9465 ProcessExpressionType(b);
9467 exp.type = bracketsExp;
9468 exp.list = MkList();
9470 if(a.expType && (!b || b.expType))
9472 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9474 // Use the simpleStruct name/ids for now...
9477 OldList * specs = MkList();
9478 OldList * decls = MkList();
9480 char temp1[1024], temp2[1024];
9482 GetTypeSpecs(a.expType, specs);
9484 if(a && !a.isConstant && a.type != identifierExp)
9486 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9487 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9488 tempExp1 = QMkExpId(temp1);
9489 tempExp1.expType = a.expType;
9491 a.expType.refCount++;
9492 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9494 if(b && !b.isConstant && b.type != identifierExp)
9496 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9497 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9498 tempExp2 = QMkExpId(temp2);
9499 tempExp2.expType = b.expType;
9501 b.expType.refCount++;
9502 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9505 decl = MkDeclaration(specs, decls);
9506 if(!curCompound.compound.declarations)
9507 curCompound.compound.declarations = MkList();
9508 curCompound.compound.declarations->Insert(null, decl);
9513 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9515 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9517 MkExpCondition(MkExpBrackets(MkListOne(
9518 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9519 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9520 exp.expType = a.expType;
9522 a.expType.refCount++;
9524 else if(!strcmp(id.string, "Abs"))
9527 MkExpCondition(MkExpBrackets(MkListOne(
9528 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9529 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9530 exp.expType = a.expType;
9532 a.expType.refCount++;
9534 else if(!strcmp(id.string, "Sgn"))
9536 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9538 MkExpCondition(MkExpBrackets(MkListOne(
9539 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9540 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9541 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9542 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9543 exp.expType = ProcessTypeString("int", false);
9546 FreeExpression(tempExp1);
9547 if(tempExp2) FreeExpression(tempExp2);
9561 if(!exp.call.exp.destType)
9563 exp.call.exp.destType = dummy;
9566 ProcessExpressionType(exp.call.exp);
9567 if(exp.call.exp.destType == dummy)
9570 exp.call.exp.destType = null;
9575 // Check argument types against parameter types
9576 functionType = exp.call.exp.expType;
9578 if(functionType && functionType.kind == TypeKind::methodType)
9580 methodType = functionType;
9581 functionType = methodType.method.dataType;
9583 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9584 // TOCHECK: Instead of doing this here could this be done per param?
9585 if(exp.call.exp.expType.usedClass)
9587 char typeString[1024];
9588 typeString[0] = '\0';
9590 Symbol back = functionType.thisClass;
9591 // Do not output class specifier here (thisclass was added to this)
9592 functionType.thisClass = null;
9593 PrintType(functionType, typeString, true, true);
9594 functionType.thisClass = back;
9596 if(strstr(typeString, "thisclass"))
9598 OldList * specs = MkList();
9601 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9603 decl = SpecDeclFromString(typeString, specs, null);
9605 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9606 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9607 exp.call.exp.expType.usedClass))
9608 thisClassParams = false;
9610 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9612 Class backupThisClass = thisClass;
9613 thisClass = exp.call.exp.expType.usedClass;
9614 ProcessDeclarator(decl);
9615 thisClass = backupThisClass;
9618 thisClassParams = true;
9620 functionType = ProcessType(specs, decl);
9621 functionType.refCount = 0;
9622 FinishTemplatesContext(context);
9624 // Mark parameters that were 'thisclass'
9627 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9628 p.wasThisClass = op.kind == thisClassType;
9632 FreeList(specs, FreeSpecifier);
9633 FreeDeclarator(decl);
9637 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9639 Type type = functionType.type;
9640 if(!functionType.refCount)
9642 functionType.type = null;
9643 FreeType(functionType);
9645 //methodType = functionType;
9646 functionType = type;
9648 if(functionType && functionType.kind != TypeKind::functionType)
9650 Compiler_Error($"called object %s is not a function\n", name);
9652 else if(functionType)
9654 bool emptyParams = false, noParams = false;
9655 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9656 Type type = functionType.params.first;
9657 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9659 Location oldyylloc = yylloc;
9661 if(!type) emptyParams = true;
9664 if(functionType.extraParam && e && functionType.thisClass)
9666 e.destType = MkClassType(functionType.thisClass.string);
9670 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9671 // Fixed #141 by adding '&& !functionType.extraParam'
9672 if(!functionType.staticMethod && !functionType.extraParam)
9674 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9675 memberExp.member.exp.expType._class)
9677 type = MkClassType(memberExp.member.exp.expType._class.string);
9682 type = functionType.params.first;
9687 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9689 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9690 type.byReference = functionType.byReference;
9691 type.typedByReference = functionType.typedByReference;
9694 // Allow manually passing a class for typed object
9695 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9699 type = functionType.params.first;
9707 if(type && type.kind == voidType)
9710 if(!type.refCount) FreeType(type);
9714 for( ; e; e = e.next)
9716 if(!type && !emptyParams)
9719 if(methodType && methodType.methodClass)
9720 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9721 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9722 noParams ? 0 : functionType.params.count);
9724 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9725 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9726 noParams ? 0 : functionType.params.count);
9730 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9732 Type templatedType = null;
9733 Class _class = methodType.usedClass;
9734 ClassTemplateParameter curParam = null;
9736 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9739 for(sClass = _class; sClass; sClass = sClass.base)
9741 if(sClass.templateClass) sClass = sClass.templateClass;
9743 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9745 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9748 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9750 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9751 id += nextClass.templateParams.count;
9760 if(curParam && _class.templateArgs[id].dataTypeString)
9762 bool constant = type.constant;
9763 ClassTemplateArgument arg = _class.templateArgs[id];
9765 Context context = SetupTemplatesContext(_class);
9768 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9769 templatedType = ProcessTypeString(arg.dataTypeString, false);
9770 FinishTemplatesContext(context);
9773 if(templatedType.kind == classType && constant) templatedType.constant = true;
9774 else if(templatedType.kind == pointerType)
9776 Type t = templatedType.type;
9777 while(t.kind == pointerType) t = t.type;
9778 if(constant) t.constant = constant;
9781 e.destType = templatedType;
9784 templatedType.passAsTemplate = true;
9785 // templatedType.refCount++;
9791 if(type) type.refCount++;
9796 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9798 e.destType = type.prev;
9799 e.destType.refCount++;
9804 if(type) type.refCount++;
9807 // Don't reach the end for the ellipsis
9808 if(type && type.kind != ellipsisType)
9810 Type next = type.next;
9811 if(!type.refCount) FreeType(type);
9816 if(type && type.kind != ellipsisType)
9818 if(methodType && methodType.methodClass)
9819 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9820 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9821 functionType.params.count + extra);
9823 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9824 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9825 functionType.params.count + extra);
9828 if(type && !type.refCount) FreeType(type);
9835 kind = TypeKind::functionType;
9838 if(exp.call.exp.type == identifierExp)
9840 char * string = exp.call.exp.identifier.string;
9844 Location oldyylloc = yylloc;
9846 yylloc = exp.call.exp.identifier.loc;
9847 if(strstr(string, "__builtin_") == string)
9851 functionType.returnType = exp.destType;
9852 exp.destType.refCount++;
9856 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9857 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9858 globalContext.symbols.Add((BTNode)symbol);
9859 if(strstr(symbol.string, "::"))
9860 globalContext.hasNameSpace = true;
9865 else if(exp.call.exp.type == memberExp)
9867 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9868 exp.call.exp.member.member.string);*/
9871 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9873 if(!functionType.returnType)
9875 functionType.returnType = Type
9882 if(functionType && functionType.kind == TypeKind::functionType)
9884 exp.expType = functionType.returnType;
9886 if(functionType.returnType)
9887 functionType.returnType.refCount++;
9889 if(!functionType.refCount)
9890 FreeType(functionType);
9893 if(exp.call.arguments)
9895 for(e = exp.call.arguments->first; e; e = e.next)
9896 ProcessExpressionType(e);
9903 Location oldyylloc = yylloc;
9905 Expression checkExp = exp.member.exp;
9908 if(checkExp.type == castExp)
9909 checkExp = checkExp.cast.exp;
9910 else if(checkExp.type == bracketsExp)
9911 checkExp = checkExp.list ? checkExp.list->first : null;
9916 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9917 exp.thisPtr = thisPtr;
9919 // DOING THIS LATER NOW...
9920 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9922 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9923 /* TODO: Name Space Fix ups
9924 if(!exp.member.member.classSym)
9925 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9929 ProcessExpressionType(exp.member.exp);
9930 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9931 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9933 exp.isConstant = false;
9936 exp.isConstant = exp.member.exp.isConstant;
9937 type = exp.member.exp.expType;
9941 if(type && (type.kind == templateType))
9943 Class _class = thisClass ? thisClass : currentClass;
9944 ClassTemplateParameter param = null;
9947 for(param = _class.templateParams.first; param; param = param.next)
9949 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9953 if(param && param.defaultArg.member)
9955 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9958 Expression expMember = exp.member.exp;
9960 OldList * specs = MkList();
9961 char thisClassTypeString[1024];
9963 FreeIdentifier(exp.member.member);
9965 ProcessExpressionType(argExp);
9968 char * colon = strstr(param.defaultArg.memberString, "::");
9971 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9972 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9975 strcpy(thisClassTypeString, _class.fullName);
9978 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9980 exp.expType = ProcessType(specs, decl);
9981 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9983 Class expClass = exp.expType._class.registered;
9984 Class cClass = null;
9988 char templateString[1024];
9989 ClassTemplateParameter param;
9990 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9991 for(cClass = expClass; cClass; cClass = cClass.base)
9994 for(param = cClass.templateParams.first; param; param = param.next)
9998 ClassTemplateArgument arg;
9999 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
10000 arg = expClass.templateArgs[id];
10002 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
10004 ClassTemplateParameter cParam;
10005 //int p = numParams - sClass.templateParams.count;
10008 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
10010 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
10012 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
10014 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10016 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
10017 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
10025 char argument[256];
10026 argument[0] = '\0';
10029 strcat(argument, arg.name.string);
10030 strcat(argument, " = ");
10036 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10037 char expString[1024];
10038 OldList * specs = MkList();
10039 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10041 char * string = PrintHexUInt64(arg.expression.ui64);
10042 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10045 ProcessExpressionType(exp);
10046 ComputeExpression(exp);
10047 expString[0] = '\0';
10048 PrintExpression(exp, expString);
10049 strcat(argument, expString);
10051 FreeExpression(exp);
10056 strcat(argument, arg.member.name);
10059 case TemplateParameterType::type:
10061 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10063 if(!strcmp(arg.dataTypeString, "thisclass"))
10064 strcat(argument, thisClassTypeString);
10066 strcat(argument, arg.dataTypeString);
10073 if(paramCount) strcat(templateString, ", ");
10074 if(lastParam != p - 1)
10076 strcat(templateString, param.name);
10077 strcat(templateString, " = ");
10079 strcat(templateString, argument);
10088 int len = strlen(templateString);
10089 if(templateString[len-1] == '>') templateString[len++] = ' ';
10090 templateString[len++] = '>';
10091 templateString[len++] = '\0';
10094 Context context = SetupTemplatesContext(_class);
10095 FreeType(exp.expType);
10096 exp.expType = ProcessTypeString(templateString, false);
10097 FinishTemplatesContext(context);
10101 if(!expMember.expType.isPointerType)
10102 expMember = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), expMember);
10103 // *([expType] *)(((byte *)(uintptr)[exp.member.exp]) + [argExp].member.offset)
10104 exp.type = bracketsExp;
10105 exp.list = MkListOne(MkExpOp(null, '*',
10108 exp.op.exp1 = null;
10110 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10111 MkExpBrackets(MkListOne(
10112 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
10115 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10117 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10122 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10123 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10125 type = ProcessTemplateParameterType(type.templateParameter);
10128 // TODO: *** This seems to be where we should add method support for all basic types ***
10129 if(type && (type.kind == templateType));
10130 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10131 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10132 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10133 (type.kind == pointerType && type.type.kind == charType)))
10135 Identifier id = exp.member.member;
10136 TypeKind typeKind = type.kind;
10137 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10138 if(typeKind == subClassType && exp.member.exp.type == classExp)
10140 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10141 typeKind = classType;
10146 if(typeKind == intType || typeKind == enumType)
10147 _class = eSystem_FindClass(privateModule, "int");
10150 if(type.kind == classType && type._class && type._class.registered)
10152 _class = type._class.registered;
10154 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10156 _class = FindClass("char *").registered;
10158 else if(type.kind == pointerType)
10160 _class = eSystem_FindClass(privateModule, "uintptr");
10161 FreeType(exp.expType);
10162 exp.expType = ProcessTypeString("uintptr", false);
10163 exp.byReference = true;
10167 char string[1024] = "";
10169 PrintTypeNoConst(type, string, false, true);
10170 classSym = FindClass(string);
10171 if(classSym) _class = classSym.registered;
10179 (exp.member.exp.type == identifierExp &&
10180 !strcmp(exp.member.exp.identifier.string, "this"));*/
10181 Property prop = null;
10182 Method method = null;
10183 DataMember member = null;
10184 Property revConvert = null;
10185 ClassProperty classProp = null;
10187 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10188 exp.member.memberType = propertyMember;
10190 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10191 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10193 if(typeKind != subClassType)
10195 // Prioritize data members over properties for "this"
10196 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10198 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10199 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10201 prop = eClass_FindProperty(_class, id.string, privateModule);
10205 if(!member && !prop)
10206 prop = eClass_FindProperty(_class, id.string, privateModule);
10207 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10208 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10209 exp.member.thisPtr = true;
10211 // Prioritize properties over data members otherwise
10214 bool useMemberForNonConst = false;
10215 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10218 prop = eClass_FindProperty(_class, id.string, null);
10220 useMemberForNonConst = prop && exp.destType &&
10221 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10222 !strncmp(prop.dataTypeString, "const ", 6);
10224 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10225 member = eClass_FindDataMember(_class, id.string, null, null, null);
10228 if((!prop || useMemberForNonConst) && !member)
10230 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10233 prop = eClass_FindProperty(_class, id.string, privateModule);
10235 useMemberForNonConst |= prop && exp.destType &&
10236 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10237 !strncmp(prop.dataTypeString, "const ", 6);
10239 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10240 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10246 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10253 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10254 method = eClass_FindMethod(_class, id.string, privateModule);
10255 if(!prop && !member && !method)
10257 if(typeKind == subClassType)
10259 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10262 exp.member.memberType = classPropertyMember;
10263 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10267 // Assume this is a class_data member
10268 char structName[1024];
10269 Identifier id = exp.member.member;
10270 Expression classExp = exp.member.exp;
10273 FreeType(classExp.expType);
10274 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10276 strcpy(structName, "__ecereClassData_");
10277 FullClassNameCat(structName, type._class.string, false);
10278 exp.type = pointerExp;
10279 exp.member.member = id;
10281 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10282 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10283 MkExpBrackets(MkListOne(MkExpOp(
10284 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10285 MkExpMember(classExp, MkIdentifier("data"))), '+',
10286 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10291 ProcessExpressionType(exp);
10297 // Check for reverse conversion
10298 // (Convert in an instantiation later, so that we can use
10299 // deep properties system)
10300 Symbol classSym = FindClass(id.string);
10303 Class convertClass = classSym.registered;
10305 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10310 //if(!exp.member.exp.destType)
10311 if(exp.member.exp.destType)
10312 FreeType(exp.member.exp.destType);
10314 if(method && !method._class.symbol)
10315 method._class.symbol = FindClass(method._class.fullName);
10316 if(prop && !prop._class.symbol)
10317 prop._class.symbol = FindClass(prop._class.fullName);
10319 exp.member.exp.destType = Type
10323 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10324 // wasThisClass = type ? type.wasThisClass : false;
10330 exp.member.memberType = propertyMember;
10332 ProcessPropertyType(prop);
10333 exp.expType = prop.dataType;
10334 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10337 CopyTypeInto(type, exp.expType);
10339 type.constant = true;
10340 exp.expType = type;
10342 else if(prop.dataType)
10343 prop.dataType.refCount++;
10347 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10349 FreeExpContents(exp);
10350 exp.type = identifierExp;
10351 exp.identifier = MkIdentifier("class");
10352 ProcessExpressionType(exp);
10356 exp.member.memberType = dataMember;
10357 DeclareStruct(_class.fullName, false);
10358 if(!member.dataType)
10360 Context context = SetupTemplatesContext(_class);
10361 member.dataType = ProcessTypeString(member.dataTypeString, false);
10362 FinishTemplatesContext(context);
10364 exp.expType = member.dataType;
10365 if(member.dataType) member.dataType.refCount++;
10367 else if(revConvert)
10369 exp.member.memberType = reverseConversionMember;
10370 exp.expType = MkClassType(revConvert._class.fullName);
10378 exp.type = identifierExp;
10379 exp.identifier = exp.member.member;
10382 exp.member.memberType = methodMember;
10384 if(!method.dataType)
10385 ProcessMethodType(method);
10393 // Tricky spot here... To use instance versus class virtual table
10394 // Put it back to what it was... What did we break?
10396 // Had to put it back for overriding Main of Thread global instance
10398 //exp.expType.methodClass = _class;
10399 exp.expType.methodClass = (id && id._class) ? _class : null;
10401 // Need the actual class used for templated classes
10402 exp.expType.usedClass = _class;
10404 else if(!classProp)
10406 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10408 FreeExpContents(exp);
10409 exp.type = identifierExp;
10410 exp.identifier = MkIdentifier("class");
10411 FreeType(exp.expType);
10412 exp.expType = MkClassType("ecere::com::Class");
10415 yylloc = exp.member.member.loc;
10416 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10418 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10421 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10425 tClass = type._class && type._class.registered ? type._class.registered : _class;
10426 while(tClass && !tClass.templateClass) tClass = tClass.base;
10428 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10431 ClassTemplateParameter curParam = null;
10434 for(sClass = tClass; sClass; sClass = sClass.base)
10437 if(sClass.templateClass) sClass = sClass.templateClass;
10438 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10440 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10442 for(sClass = sClass.base; sClass; sClass = sClass.base)
10443 id += sClass.templateParams.count;
10448 if(curParam) break;
10451 if(curParam && tClass.templateArgs[id].dataTypeString)
10453 ClassTemplateArgument arg = tClass.templateArgs[id];
10454 Context context = SetupTemplatesContext(tClass);
10455 bool constant = exp.expType.constant;
10456 /*if(!arg.dataType)
10457 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10458 FreeType(exp.expType);
10460 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10461 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10462 else if(exp.expType.kind == pointerType)
10464 Type t = exp.expType.type;
10465 while(t.kind == pointerType) t = t.type;
10466 if(constant) t.constant = constant;
10470 if(exp.expType.kind == thisClassType)
10472 FreeType(exp.expType);
10473 exp.expType = ReplaceThisClassType(_class);
10476 if(tClass.templateClass && (exp.expType.kind != templateType || (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType))))
10477 exp.expType.passAsTemplate = true;
10478 //exp.expType.refCount++;
10481 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10482 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10483 else if(exp.destType.kind == pointerType)
10485 Type t = exp.destType.type;
10486 while(t.kind == pointerType) t = t.type;
10487 if(constant) t.constant = constant;
10490 //exp.destType.refCount++;
10492 if(exp.destType.kind == thisClassType)
10494 FreeType(exp.destType);
10495 exp.destType = ReplaceThisClassType(_class);
10499 FinishTemplatesContext(context);
10502 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10503 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10506 ClassTemplateParameter curParam = null;
10509 for(sClass = tClass; sClass; sClass = sClass.base)
10512 if(sClass.templateClass) sClass = sClass.templateClass;
10513 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10515 if(curParam.type == TemplateParameterType::type &&
10516 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10518 for(sClass = sClass.base; sClass; sClass = sClass.base)
10519 id += sClass.templateParams.count;
10524 if(curParam) break;
10529 ClassTemplateArgument arg = tClass.templateArgs[id];
10530 Context context = SetupTemplatesContext(tClass);
10532 /*if(!arg.dataType)
10533 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10535 basicType = ProcessTypeString(arg.dataTypeString, false);
10538 if(basicType.kind == thisClassType)
10540 FreeType(basicType);
10541 basicType = ReplaceThisClassType(_class);
10544 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10545 if(tClass.templateClass)
10546 basicType.passAsTemplate = true;
10549 FreeType(exp.expType);
10551 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10552 //exp.expType.refCount++;
10555 exp.destType = exp.expType;
10556 exp.destType.refCount++;
10560 Expression newExp { };
10561 OldList * specs = MkList();
10563 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10565 if(exp.destType) exp.destType.refCount++;
10566 if(exp.expType) exp.expType.refCount++;
10567 exp.type = castExp;
10568 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10569 exp.cast.exp = newExp;
10570 //FreeType(exp.expType);
10571 //exp.expType = null;
10572 //ProcessExpressionType(sourceExp);
10575 FinishTemplatesContext(context);
10578 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10580 Class expClass = exp.expType._class.registered;
10583 Class cClass = null;
10585 int paramCount = 0;
10586 int lastParam = -1;
10587 char templateString[1024];
10588 ClassTemplateParameter param;
10589 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10590 while(cClass != expClass)
10593 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10596 for(param = cClass.templateParams.first; param; param = param.next)
10598 Class cClassCur = null;
10600 ClassTemplateParameter paramCur = null;
10601 ClassTemplateArgument arg;
10602 while(cClassCur != tClass && !paramCur)
10605 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10606 cClassCur = sClassCur;
10608 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10610 if(!strcmp(paramCur.name, param.name))
10618 if(paramCur && paramCur.type == TemplateParameterType::type)
10619 arg = tClass.templateArgs[cp];
10621 arg = expClass.templateArgs[p];
10624 char argument[256];
10625 argument[0] = '\0';
10628 strcat(argument, arg.name.string);
10629 strcat(argument, " = ");
10635 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10636 char expString[1024];
10637 OldList * specs = MkList();
10638 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10640 char * string = PrintHexUInt64(arg.expression.ui64);
10641 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10644 ProcessExpressionType(exp);
10645 ComputeExpression(exp);
10646 expString[0] = '\0';
10647 PrintExpression(exp, expString);
10648 strcat(argument, expString);
10650 FreeExpression(exp);
10655 strcat(argument, arg.member.name);
10658 case TemplateParameterType::type:
10660 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10661 strcat(argument, arg.dataTypeString);
10667 if(paramCount) strcat(templateString, ", ");
10668 if(lastParam != p - 1)
10670 strcat(templateString, param.name);
10671 strcat(templateString, " = ");
10673 strcat(templateString, argument);
10682 int len = strlen(templateString);
10683 if(templateString[len-1] == '>') templateString[len++] = ' ';
10684 templateString[len++] = '>';
10685 templateString[len++] = '\0';
10688 FreeType(exp.expType);
10690 Context context = SetupTemplatesContext(tClass);
10691 exp.expType = ProcessTypeString(templateString, false);
10692 FinishTemplatesContext(context);
10699 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10701 else if(type && (type.kind == structType || type.kind == unionType))
10703 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10706 exp.expType = memberType;
10708 memberType.refCount++;
10713 char expString[10240];
10714 expString[0] = '\0';
10715 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10716 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10719 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10721 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10723 Identifier id = exp.member.member;
10724 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10727 FreeType(exp.expType);
10728 exp.expType = ReplaceThisClassType(_class);
10732 yylloc = oldyylloc;
10735 // Convert x->y into (*x).y
10738 Type destType = exp.destType;
10740 // DOING THIS LATER NOW...
10741 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10743 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10744 /* TODO: Name Space Fix ups
10745 if(!exp.member.member.classSym)
10746 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10750 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10751 exp.type = memberExp;
10754 ProcessExpressionType(exp);
10761 //ComputeExpression(exp);
10763 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10764 if(classSym && classSym.registered)
10766 if(classSym.registered.type == noHeadClass)
10770 DeclareStruct(classSym.string, false);
10771 FreeSpecifier(exp._class);
10772 exp.type = typeSizeExp;
10773 FullClassNameCat(name, classSym.string, false);
10774 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10778 if(classSym.registered.fixed)
10780 FreeSpecifier(exp._class);
10781 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10782 exp.type = constantExp;
10786 char className[1024];
10787 strcpy(className, "__ecereClass_");
10788 FullClassNameCat(className, classSym.string, true);
10789 //MangleClassName(className);
10791 DeclareClass(classSym, className);
10793 FreeExpContents(exp);
10794 exp.type = pointerExp;
10795 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10796 exp.member.member = MkIdentifier("structSize");
10804 kind = intSizeType;
10806 // exp.isConstant = true;
10811 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10816 kind = intSizeType;
10818 exp.isConstant = true;
10820 DeclareType(type, false, false);
10826 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10828 FreeType(exp.cast.exp.destType);
10829 exp.cast.exp.destType = type;
10831 type.casted = true;
10832 ProcessExpressionType(exp.cast.exp);
10833 type.casted = false;
10835 exp.expType = type;
10838 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10839 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10841 void * prev = exp.prev, * next = exp.next;
10842 Type expType = exp.cast.exp.destType;
10843 Expression castExp = exp.cast.exp;
10844 Type destType = exp.destType;
10846 if(expType) expType.refCount++;
10848 //FreeType(exp.destType);
10849 FreeType(exp.expType);
10850 FreeTypeName(exp.cast.typeName);
10853 FreeType(exp.expType);
10854 FreeType(exp.destType);
10856 exp.expType = expType;
10857 exp.destType = destType;
10867 exp.isConstant = exp.cast.exp.isConstant;
10872 case extensionInitializerExp:
10874 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10875 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10876 // ProcessInitializer(exp.initializer.initializer, type);
10877 exp.expType = type;
10882 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10883 ProcessExpressionType(exp.vaArg.exp);
10884 exp.expType = type;
10890 exp.isConstant = true;
10892 FreeType(exp.cond.cond.destType);
10893 exp.cond.cond.destType = MkClassType("bool");
10894 exp.cond.cond.destType.truth = true;
10895 ProcessExpressionType(exp.cond.cond);
10896 if(!exp.cond.cond.isConstant)
10897 exp.isConstant = false;
10898 for(e = exp.cond.exp->first; e; e = e.next)
10902 FreeType(e.destType);
10903 e.destType = exp.destType;
10904 if(e.destType) e.destType.refCount++;
10906 ProcessExpressionType(e);
10909 exp.expType = e.expType;
10910 if(e.expType) e.expType.refCount++;
10913 exp.isConstant = false;
10916 FreeType(exp.cond.elseExp.destType);
10917 // Added this check if we failed to find an expType
10918 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10921 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10923 if(exp.cond.elseExp.destType)
10924 exp.cond.elseExp.destType.refCount++;
10925 ProcessExpressionType(exp.cond.elseExp);
10927 // FIXED THIS: Was done before calling process on elseExp
10928 if(!exp.cond.elseExp.isConstant)
10929 exp.isConstant = false;
10932 case extensionCompoundExp:
10934 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10936 Statement last = exp.compound.compound.statements->last;
10937 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10939 ((Expression)last.expressions->last).destType = exp.destType;
10941 exp.destType.refCount++;
10943 ProcessStatement(exp.compound);
10944 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10946 exp.expType.refCount++;
10952 Specifier spec = exp._classExp.specifiers->first;
10953 if(spec && spec.type == nameSpecifier)
10955 exp.expType = MkClassType(spec.name);
10956 exp.expType.kind = subClassType;
10957 exp.byReference = true;
10961 exp.expType = MkClassType("ecere::com::Class");
10962 exp.byReference = true;
10968 Class _class = thisClass ? thisClass : currentClass;
10971 Identifier id = exp.classData.id;
10972 char structName[1024];
10973 Expression classExp;
10974 strcpy(structName, "__ecereClassData_");
10975 FullClassNameCat(structName, _class.fullName, false);
10976 exp.type = pointerExp;
10977 exp.member.member = id;
10978 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10979 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10981 classExp = MkExpIdentifier(MkIdentifier("class"));
10983 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10984 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10985 MkExpBrackets(MkListOne(MkExpOp(
10986 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10987 MkExpMember(classExp, MkIdentifier("data"))), '+',
10988 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10991 ProcessExpressionType(exp);
10999 const char * typeString = null;
11000 char typeStringBuf[1024];
11001 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
11002 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
11004 Class templateClass = exp.destType._class.registered;
11005 typeString = templateClass.templateArgs[2].dataTypeString;
11009 // Guess type from expressions in the array
11011 for(e = exp.list->first; e; e = e.next)
11013 ProcessExpressionType(e);
11016 if(!type) { type = e.expType; type.refCount++; }
11019 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11020 if(!MatchTypeExpression(e, type, null, false, true))
11026 e = exp.list->first;
11027 ProcessExpressionType(e);
11030 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
11031 if(!MatchTypeExpression(e, type, null, false, true))
11033 FreeType(e.expType);
11044 FreeType(e.expType);
11051 typeStringBuf[0] = '\0';
11052 PrintTypeNoConst(type, typeStringBuf, false, true);
11053 typeString = typeStringBuf;
11061 (Container)& (struct BuiltInContainer)
11063 ._vTbl = class(BuiltInContainer)._vTbl,
11064 ._class = class(BuiltInContainer),
11066 .data = (int[]){ 1, 7, 3, 4, 5 },
11068 .type = class(int),
11071 char templateString[1024];
11072 OldList * initializers = MkList();
11073 OldList * structInitializers = MkList();
11074 OldList * specs = MkList();
11076 Declarator decl = SpecDeclFromString(typeString, specs, null);
11077 sprintf(templateString, "Container<%s>", typeString);
11082 type = ProcessTypeString(typeString, false);
11083 while((e = exp.list->first))
11085 exp.list->Remove(e);
11088 ProcessExpressionType(e);
11089 ListAdd(initializers, MkInitializerAssignment(e));
11095 DeclareStruct("ecere::com::BuiltInContainer", false);
11097 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11098 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11099 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11100 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11101 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11102 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11103 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11104 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11105 MkInitializerList(initializers))));
11106 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11107 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11108 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11109 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11110 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11111 exp.expType = ProcessTypeString(templateString, false);
11112 exp.type = bracketsExp;
11113 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11115 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11116 MkInitializerList(structInitializers)))));
11117 ProcessExpressionType(expExt);
11121 exp.expType = ProcessTypeString("Container", false);
11122 Compiler_Error($"Couldn't determine type of array elements\n");
11128 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11130 FreeType(exp.expType);
11131 exp.expType = ReplaceThisClassType(thisClass);
11134 // Resolve structures here
11135 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11137 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11138 // TODO: Fix members reference...
11141 if(exp.expType.kind != enumType)
11144 String enumName = CopyString(exp.expType.enumName);
11146 // Fixed a memory leak on self-referencing C structs typedefs
11147 // by instantiating a new type rather than simply copying members
11148 // into exp.expType
11149 FreeType(exp.expType);
11150 exp.expType = Type { };
11151 exp.expType.kind = symbol.type.kind;
11152 exp.expType.refCount++;
11153 exp.expType.enumName = enumName;
11155 exp.expType.members = symbol.type.members;
11156 for(member = symbol.type.members.first; member; member = member.next)
11161 NamedLink64 member;
11162 for(member = symbol.type.members.first; member; member = member.next)
11164 NamedLink64 value { name = CopyString(member.name) };
11165 exp.expType.members.Add(value);
11172 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11173 else if(exp.destType && !exp.destType.keepCast)
11175 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11176 exp.needTemplateCast = 1;
11178 if(exp.destType.kind == voidType);
11179 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11181 if(!exp.destType.count || unresolved)
11186 if(exp.destType.kind != ellipsisType)
11192 char expString[10240];
11193 expString[0] = '\0';
11195 PrintType(exp.destType, type2, false, true);
11197 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11199 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11200 else if(exp.type != dummyExp)
11201 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11206 char expString[10240] ;
11207 expString[0] = '\0';
11208 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11211 Compiler_Error($"unresolved identifier %s\n", expString);
11212 else if(exp.type != dummyExp)
11213 Compiler_Error($"couldn't determine type of %s\n", expString);
11224 PrintType(exp.expType, type1, false, true);
11225 PrintType(exp.destType, type2, false, true);
11228 //CheckExpressionType(exp, exp.destType, false);
11230 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11231 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11232 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11235 char expString[10240];
11236 expString[0] = '\0';
11237 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11240 CheckExpressionType(exp, exp.destType, false, true);
11242 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11243 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11244 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11245 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11246 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11247 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11249 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11250 FreeType(exp.expType);
11251 exp.destType.refCount++;
11252 exp.expType = exp.destType;
11257 // Cast function pointers to void * as eC already checked compatibility
11258 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11259 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11261 Expression nbExp = GetNonBracketsExp(exp);
11262 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11264 Expression e = MoveExpContents(exp);
11265 exp.cast.exp = MkExpBrackets(MkListOne(e));
11266 exp.type = castExp;
11267 exp.cast.exp.destType = exp.destType;
11268 if(exp.destType) exp.destType.refCount++;
11269 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11273 else if(unresolved)
11275 if(exp.identifier._class && exp.identifier._class.name)
11276 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11277 else if(exp.identifier.string && exp.identifier.string[0])
11278 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11280 else if(!exp.expType && exp.type != dummyExp)
11282 char expString[10240];
11283 expString[0] = '\0';
11284 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11285 Compiler_Error($"couldn't determine type of %s\n", expString);
11288 // Let's try to support any_object & typed_object here:
11290 ApplyAnyObjectLogic(exp);
11292 // Mark nohead classes as by reference, unless we're casting them to an integral type
11293 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11294 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11295 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11296 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11298 exp.byReference = true;
11300 yylloc = oldyylloc;
11303 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11305 // THIS CODE WILL FIND NEXT MEMBER...
11308 *curMember = (*curMember).next;
11310 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11312 *curMember = subMemberStack[--(*subMemberStackPos)];
11313 *curMember = (*curMember).next;
11316 // SKIP ALL PROPERTIES HERE...
11317 while((*curMember) && (*curMember).isProperty)
11318 *curMember = (*curMember).next;
11320 if(subMemberStackPos)
11322 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11324 subMemberStack[(*subMemberStackPos)++] = *curMember;
11326 *curMember = (*curMember).members.first;
11327 while(*curMember && (*curMember).isProperty)
11328 *curMember = (*curMember).next;
11336 if(subMemberStackPos && *subMemberStackPos)
11338 *curMember = subMemberStack[--(*subMemberStackPos)];
11339 *curMember = (*curMember).next;
11343 Class lastCurClass = *curClass;
11345 if(*curClass == _class) break; // REACHED THE END
11347 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11348 *curMember = (*curClass).membersAndProperties.first;
11351 while((*curMember) && (*curMember).isProperty)
11352 *curMember = (*curMember).next;
11353 if(subMemberStackPos)
11355 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11357 subMemberStack[(*subMemberStackPos)++] = *curMember;
11359 *curMember = (*curMember).members.first;
11360 while(*curMember && (*curMember).isProperty)
11361 *curMember = (*curMember).next;
11369 static void ProcessInitializer(Initializer init, Type type)
11373 case expInitializer:
11374 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11376 // TESTING THIS FOR SHUTTING = 0 WARNING
11377 if(init.exp && !init.exp.destType)
11379 FreeType(init.exp.destType);
11380 init.exp.destType = type;
11381 if(type) type.refCount++;
11385 ProcessExpressionType(init.exp);
11386 init.isConstant = init.exp.isConstant;
11392 Expression exp = init.exp;
11393 Instantiation inst = exp.instance;
11394 MembersInit members;
11396 init.type = listInitializer;
11397 init.list = MkList();
11401 for(members = inst.members->first; members; members = members.next)
11403 if(members.type == dataMembersInit)
11406 for(member = members.dataMembers->first; member; member = member.next)
11408 ListAdd(init.list, member.initializer);
11409 member.initializer = null;
11412 // Discard all MembersInitMethod
11415 FreeExpression(exp);
11417 case listInitializer:
11420 Type initializerType = null;
11421 Class curClass = null;
11422 DataMember curMember = null;
11423 DataMember subMemberStack[256];
11424 int subMemberStackPos = 0;
11426 if(type && type.kind == arrayType)
11427 initializerType = Dereference(type);
11428 else if(type && (type.kind == structType || type.kind == unionType))
11429 initializerType = type.members.first;
11431 for(i = init.list->first; i; i = i.next)
11433 if(type && type.kind == classType && type._class && type._class.registered)
11435 // 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)
11436 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11437 // TODO: Generate error on initializing a private data member this way from another module...
11440 if(!curMember.dataType)
11441 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11442 initializerType = curMember.dataType;
11445 ProcessInitializer(i, initializerType);
11446 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11447 initializerType = initializerType.next;
11449 init.isConstant = false;
11452 if(type && type.kind == arrayType)
11453 FreeType(initializerType);
11455 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11457 Compiler_Error($"Assigning list initializer to non list\n");
11464 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11468 case baseSpecifier:
11470 if(spec.specifier == THISCLASS)
11474 spec.type = nameSpecifier;
11475 spec.name = ReplaceThisClass(thisClass);
11476 spec.symbol = FindClass(spec.name);
11477 ProcessSpecifier(spec, declareStruct);
11482 case nameSpecifier:
11484 Symbol symbol = FindType(curContext, spec.name);
11486 DeclareType(symbol.type, true, true);
11487 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11488 DeclareStruct(spec.name, false);
11491 case enumSpecifier:
11496 for(e = spec.list->first; e; e = e.next)
11499 ProcessExpressionType(e.exp);
11502 // Fall through for IDE type processing
11506 case structSpecifier:
11507 case unionSpecifier:
11509 if(spec.definitions)
11512 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11514 ProcessClass(spec.definitions, symbol);
11517 for(def = spec.definitions->first; def; def = def.next)
11519 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11520 ProcessDeclaration(def.decl);
11527 case classSpecifier:
11529 Symbol classSym = FindClass(spec.name);
11530 if(classSym && classSym.registered && classSym.registered.type == structClass)
11531 DeclareStruct(spec.name, false);
11539 static void ProcessDeclarator(Declarator decl)
11543 case identifierDeclarator:
11544 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11546 FreeSpecifier(decl.identifier._class);
11547 decl.identifier._class = null;
11550 case arrayDeclarator:
11552 ProcessExpressionType(decl.array.exp);
11553 case structDeclarator:
11554 case bracketsDeclarator:
11555 case functionDeclarator:
11556 case pointerDeclarator:
11557 case extendedDeclarator:
11558 case extendedDeclaratorEnd:
11559 if(decl.declarator)
11560 ProcessDeclarator(decl.declarator);
11561 if(decl.type == functionDeclarator)
11563 Identifier id = GetDeclId(decl);
11564 if(id && id._class)
11568 qualifiers = MkListOne(id._class);
11571 if(!decl.function.parameters)
11572 decl.function.parameters = MkList();
11573 decl.function.parameters->Insert(null, param);
11576 if(decl.function.parameters)
11580 for(param = decl.function.parameters->first; param; param = param.next)
11582 if(param.qualifiers && param.qualifiers->first)
11584 Specifier spec = param.qualifiers->first;
11585 if(spec && spec.specifier == TYPED_OBJECT)
11587 Declarator d = param.declarator;
11590 qualifiers = MkListOne(MkSpecifier(VOID));
11591 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11593 if(d.type != pointerDeclarator)
11594 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11596 FreeList(param.qualifiers, FreeSpecifier);
11598 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11599 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11601 decl.function.parameters->Insert(param, newParam);
11604 else if(spec && spec.specifier == ANY_OBJECT)
11606 Declarator d = param.declarator;
11608 FreeList(param.qualifiers, FreeSpecifier);
11610 param.qualifiers = MkListOne(MkSpecifier(VOID));
11611 if(d.type != pointerDeclarator)
11612 param.qualifiers->Insert(null, MkSpecifier(CONST));
11613 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11615 else if(spec.specifier == THISCLASS)
11619 spec.type = nameSpecifier;
11620 spec.name = ReplaceThisClass(thisClass);
11621 spec.symbol = FindClass(spec.name);
11622 ProcessSpecifier(spec, false);
11627 if(param.declarator)
11628 ProcessDeclarator(param.declarator);
11636 static void ProcessDeclaration(Declaration decl)
11641 case initDeclaration:
11643 bool declareStruct = false;
11645 lineNum = decl.pos.line;
11646 column = decl.pos.col;
11649 if(decl.declarators)
11653 for(d = decl.declarators->first; d; d = d.next)
11655 Type type, subType;
11656 ProcessDeclarator(d.declarator);
11658 type = ProcessType(decl.specifiers, d.declarator);
11662 ProcessInitializer(d.initializer, type);
11664 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11666 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11667 d.initializer.exp.type == instanceExp)
11669 if(type.kind == classType && type._class ==
11670 d.initializer.exp.expType._class)
11672 Instantiation inst = d.initializer.exp.instance;
11673 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11675 d.initializer.exp.instance = null;
11676 if(decl.specifiers)
11677 FreeList(decl.specifiers, FreeSpecifier);
11678 FreeList(decl.declarators, FreeInitDeclarator);
11682 decl.type = instDeclaration;
11687 for(subType = type; subType;)
11689 if(subType.kind == classType)
11691 declareStruct = true;
11694 else if(subType.kind == pointerType)
11696 else if(subType.kind == arrayType)
11697 subType = subType.arrayType;
11707 if(decl.specifiers)
11710 for(s = decl.specifiers->first; s; s = s.next)
11712 ProcessSpecifier(s, declareStruct);
11717 case instDeclaration:
11719 ProcessInstantiationType(decl.inst);
11722 case structDeclaration:
11726 bool declareStruct = false;
11728 if(decl.declarators)
11730 for(d = decl.declarators->first; d; d = d.next)
11732 Type type = ProcessType(decl.specifiers, d.declarator);
11734 ProcessDeclarator(d);
11735 for(subType = type; subType;)
11737 if(subType.kind == classType)
11739 declareStruct = true;
11742 else if(subType.kind == pointerType)
11744 else if(subType.kind == arrayType)
11745 subType = subType.arrayType;
11752 if(decl.specifiers)
11754 for(spec = decl.specifiers->first; spec; spec = spec.next)
11755 ProcessSpecifier(spec, declareStruct);
11762 static FunctionDefinition curFunction;
11764 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11766 char propName[1024], propNameM[1024];
11767 char getName[1024], setName[1024];
11770 DeclareProperty(prop, setName, getName);
11772 // eInstance_FireWatchers(object, prop);
11773 strcpy(propName, "__ecereProp_");
11774 FullClassNameCat(propName, prop._class.fullName, false);
11775 strcat(propName, "_");
11776 // strcat(propName, prop.name);
11777 FullClassNameCat(propName, prop.name, true);
11778 //MangleClassName(propName);
11780 strcpy(propNameM, "__ecerePropM_");
11781 FullClassNameCat(propNameM, prop._class.fullName, false);
11782 strcat(propNameM, "_");
11783 // strcat(propNameM, prop.name);
11784 FullClassNameCat(propNameM, prop.name, true);
11785 //MangleClassName(propNameM);
11787 if(prop.isWatchable)
11790 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11791 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11792 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11795 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11796 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11797 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11803 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11804 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11805 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11808 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11809 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11810 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11813 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11814 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11815 curFunction.propSet.fireWatchersDone = true;
11818 static void ProcessStatement(Statement stmt)
11822 lineNum = stmt.pos.line;
11823 column = stmt.pos.col;
11828 ProcessStatement(stmt.labeled.stmt);
11831 // This expression should be constant...
11832 if(stmt.caseStmt.exp)
11834 FreeType(stmt.caseStmt.exp.destType);
11835 stmt.caseStmt.exp.destType = curSwitchType;
11836 if(curSwitchType) curSwitchType.refCount++;
11837 ProcessExpressionType(stmt.caseStmt.exp);
11838 ComputeExpression(stmt.caseStmt.exp);
11840 if(stmt.caseStmt.stmt)
11841 ProcessStatement(stmt.caseStmt.stmt);
11845 if(stmt.compound.context)
11850 Statement prevCompound = curCompound;
11851 Context prevContext = curContext;
11853 if(!stmt.compound.isSwitch)
11854 curCompound = stmt;
11855 curContext = stmt.compound.context;
11857 if(stmt.compound.declarations)
11859 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11860 ProcessDeclaration(decl);
11862 if(stmt.compound.statements)
11864 for(s = stmt.compound.statements->first; s; s = s.next)
11865 ProcessStatement(s);
11868 curContext = prevContext;
11869 curCompound = prevCompound;
11873 case expressionStmt:
11876 if(stmt.expressions)
11878 for(exp = stmt.expressions->first; exp; exp = exp.next)
11879 ProcessExpressionType(exp);
11887 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11888 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11889 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11890 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11892 ProcessExpressionType(exp);
11894 if(stmt.ifStmt.stmt)
11895 ProcessStatement(stmt.ifStmt.stmt);
11896 if(stmt.ifStmt.elseStmt)
11897 ProcessStatement(stmt.ifStmt.elseStmt);
11902 Type oldSwitchType = curSwitchType;
11903 if(stmt.switchStmt.exp)
11906 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11916 e.exp.destType = destType;
11919 ProcessExpressionType(exp);
11922 curSwitchType = exp.expType;
11925 ProcessStatement(stmt.switchStmt.stmt);
11926 curSwitchType = oldSwitchType;
11931 if(stmt.whileStmt.exp)
11935 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11936 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11937 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11938 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11940 ProcessExpressionType(exp);
11943 if(stmt.whileStmt.stmt)
11944 ProcessStatement(stmt.whileStmt.stmt);
11949 if(stmt.doWhile.exp)
11953 if(stmt.doWhile.exp->last)
11955 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11956 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11957 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11959 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11961 ProcessExpressionType(exp);
11964 if(stmt.doWhile.stmt)
11965 ProcessStatement(stmt.doWhile.stmt);
11971 if(stmt.forStmt.init)
11972 ProcessStatement(stmt.forStmt.init);
11974 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11976 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11977 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11978 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11981 if(stmt.forStmt.check)
11982 ProcessStatement(stmt.forStmt.check);
11983 if(stmt.forStmt.increment)
11985 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11986 ProcessExpressionType(exp);
11989 if(stmt.forStmt.stmt)
11990 ProcessStatement(stmt.forStmt.stmt);
11995 Identifier id = stmt.forEachStmt.id;
11996 OldList * exp = stmt.forEachStmt.exp;
11997 OldList * filter = stmt.forEachStmt.filter;
11998 Statement block = stmt.forEachStmt.stmt;
11999 char iteratorType[1024];
12002 bool isBuiltin = exp && exp->last &&
12003 (((Expression)exp->last).type == ExpressionType::arrayExp ||
12004 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
12005 Expression arrayExp;
12006 const char * typeString = null;
12007 int builtinCount = 0;
12009 for(e = exp ? exp->first : null; e; e = e.next)
12013 FreeType(e.destType);
12014 e.destType = ProcessTypeString("Container", false);
12016 if(!isBuiltin || e.next)
12017 ProcessExpressionType(e);
12020 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
12021 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
12022 eClass_IsDerived(source._class.registered, containerClass)))
12024 Class _class = source ? source._class.registered : null;
12026 Expression expIt = null;
12027 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
12028 Class arrayClass = eSystem_FindClass(privateModule, "Array");
12029 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
12030 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
12034 stmt.type = compoundStmt;
12036 stmt.compound.context = Context { };
12037 stmt.compound.context.parent = curContext;
12038 curContext = stmt.compound.context;
12041 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
12043 Class mapClass = eSystem_FindClass(privateModule, "Map");
12044 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
12045 isCustomAVLTree = true;
12046 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
12048 else */if(eClass_IsDerived(source._class.registered, mapClass))
12051 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
12052 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
12054 Class listClass = eSystem_FindClass(privateModule, "List");
12056 isList = eClass_IsDerived(source._class.registered, listClass);
12059 if(inCompiler && isArray)
12062 OldList * specs = MkList();
12063 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12064 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12065 stmt.compound.declarations = MkListOne(
12066 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12067 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12068 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12069 MkInitializerAssignment(MkExpBrackets(exp))))));
12074 char typeStringBuf[1024];
12076 // TODO: Merge this code?
12077 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12078 if(((Expression)exp->last).type == castExp)
12080 TypeName typeName = ((Expression)exp->last).cast.typeName;
12082 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12085 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12086 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12087 arrayExp.destType._class.registered.templateArgs)
12089 Class templateClass = arrayExp.destType._class.registered;
12090 typeString = templateClass.templateArgs[2].dataTypeString;
12092 else if(arrayExp.list)
12094 // Guess type from expressions in the array
12096 for(e = arrayExp.list->first; e; e = e.next)
12098 ProcessExpressionType(e);
12101 if(!type) { type = e.expType; type.refCount++; }
12104 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12105 if(!MatchTypeExpression(e, type, null, false, true))
12111 e = arrayExp.list->first;
12112 ProcessExpressionType(e);
12115 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12116 if(!MatchTypeExpression(e, type, null, false, true))
12118 FreeType(e.expType);
12129 FreeType(e.expType);
12136 typeStringBuf[0] = '\0';
12137 PrintType(type, typeStringBuf, false, true);
12138 typeString = typeStringBuf;
12146 OldList * initializers = MkList();
12148 OldList * specs = MkList();
12153 builtinCount = arrayExp.list->count;
12154 type = ProcessTypeString(typeString, false);
12155 while((e = arrayExp.list->first))
12157 arrayExp.list->Remove(e);
12160 ProcessExpressionType(e);
12162 ListAdd(initializers, MkInitializerAssignment(e));
12165 delete arrayExp.list;
12167 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12169 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12170 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12172 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12174 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12175 ), MkInitializerList(initializers)))));
12176 FreeList(exp, FreeExpression);
12178 else if(arrayExp.list)
12181 type = ProcessTypeString(typeString, false);
12182 for(e = arrayExp.list->first; e; e = e.next)
12186 ProcessExpressionType(e);
12193 arrayExp.expType = ProcessTypeString("Container", false);
12194 Compiler_Error($"Couldn't determine type of array elements\n");
12199 OldList * specs = MkList();
12201 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12202 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12203 stmt.compound.declarations = MkListOne(
12204 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12205 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12206 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12207 MkInitializerAssignment(MkExpBrackets(exp))))));
12210 else if(inCompiler && isLinkList && !isList)
12213 OldList * specs = MkList();
12214 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12215 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12216 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12217 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12218 MkInitializerAssignment(MkExpBrackets(exp))))));
12220 /*else if(isCustomAVLTree)
12223 OldList * specs = MkList();
12224 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12225 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12226 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12227 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12228 MkInitializerAssignment(MkExpBrackets(exp))))));
12230 else if(inCompiler && _class.templateArgs)
12233 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12235 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12237 stmt.compound.declarations = MkListOne(
12238 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12239 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12240 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12244 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12248 // Reparent sub-contexts in this statement
12252 if(block.compound.context)
12253 block.compound.context.parent = stmt.compound.context;
12256 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12257 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12258 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12259 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12262 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12263 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12266 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12267 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12270 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12271 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12274 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12275 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12278 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12279 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12281 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12284 case expressionStmt:
12290 case badDeclarationStmt:
12291 case fireWatchersStmt:
12292 case stopWatchingStmt:
12300 block = MkIfStmt(filter, block, null);
12304 stmt.compound.statements = MkListOne(MkForStmt(
12305 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12306 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12307 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12308 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12310 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12311 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12312 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12317 //OldList * specs = MkList();
12318 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12320 sprintf(count, "%d", builtinCount);
12322 stmt.compound.statements = MkListOne(MkForStmt(
12323 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12324 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12325 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12326 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12330 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12331 stmt.compound.statements = MkListOne(MkForStmt(
12332 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12333 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12334 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12335 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12338 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12339 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12340 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12342 else if(isLinkList && !isList)
12344 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12345 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12346 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12347 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12349 stmt.compound.statements = MkListOne(MkForStmt(
12350 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12351 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12352 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12357 OldList * specs = MkList();
12358 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12359 stmt.compound.statements = MkListOne(MkForStmt(
12360 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12361 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12362 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12363 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12364 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12367 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12368 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12369 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12371 /*else if(isCustomAVLTree)
12373 stmt.compound.statements = MkListOne(MkForStmt(
12374 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12375 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12376 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12377 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12380 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12381 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12382 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12386 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12387 MkIdentifier("Next")), null)), block));
12389 ProcessExpressionType(expIt);
12390 if(stmt.compound.declarations->first)
12391 ProcessDeclaration(stmt.compound.declarations->first);
12394 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12396 ProcessStatement(stmt);
12399 ProcessStatement(stmt.forEachStmt.stmt);
12401 curContext = stmt.compound.context.parent;
12406 Compiler_Error($"Expression is not a container\n");
12419 if(stmt.expressions)
12421 for(exp = stmt.expressions->first; exp; exp = exp.next)
12425 if(curFunction && !curFunction.type)
12426 curFunction.type = ProcessType(
12427 curFunction.specifiers, curFunction.declarator);
12428 FreeType(exp.destType);
12429 // TODO: current property if not compiling
12430 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12431 if(exp.destType) exp.destType.refCount++;
12433 ProcessExpressionType(exp);
12438 case badDeclarationStmt:
12440 ProcessDeclaration(stmt.decl);
12446 if(stmt.asmStmt.inputFields)
12448 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12449 if(field.expression)
12450 ProcessExpressionType(field.expression);
12452 if(stmt.asmStmt.outputFields)
12454 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12455 if(field.expression)
12456 ProcessExpressionType(field.expression);
12458 if(stmt.asmStmt.clobberedFields)
12460 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12462 if(field.expression)
12463 ProcessExpressionType(field.expression);
12470 PropertyWatch propWatch;
12471 OldList * watches = stmt._watch.watches;
12472 Expression object = stmt._watch.object;
12473 Expression watcher = stmt._watch.watcher;
12475 ProcessExpressionType(watcher);
12477 ProcessExpressionType(object);
12481 if(watcher || thisClass)
12483 External external = curExternal;
12484 Context context = curContext;
12486 stmt.type = expressionStmt;
12487 stmt.expressions = MkList();
12489 curExternal = external.prev;
12491 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12493 ClassFunction func;
12494 char watcherName[1024];
12495 Class watcherClass = watcher ?
12496 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12497 External createdExternal;
12499 // Create a declaration above
12500 External externalDecl = MkExternalDeclaration(null);
12501 ast->Insert(curExternal.prev, externalDecl);
12503 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12504 if(propWatch.deleteWatch)
12505 strcat(watcherName, "_delete");
12509 for(propID = propWatch.properties->first; propID; propID = propID.next)
12511 strcat(watcherName, "_");
12512 strcat(watcherName, propID.string);
12516 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12518 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12519 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12520 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12521 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12522 ProcessClassFunctionBody(func, propWatch.compound);
12523 propWatch.compound = null;
12525 //afterExternal = afterExternal ? afterExternal : curExternal;
12527 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12528 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12530 createdExternal.symbol.idCode = external.symbol.idCode;
12532 curExternal = createdExternal;
12533 ProcessFunction(createdExternal.function);
12536 // Create a declaration above
12538 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12539 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12540 externalDecl.declaration = decl;
12541 if(decl.symbol && !decl.symbol.pointerExternal)
12542 decl.symbol.pointerExternal = externalDecl;
12545 if(propWatch.deleteWatch)
12547 OldList * args = MkList();
12548 ListAdd(args, CopyExpression(object));
12549 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12550 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12551 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12555 Class _class = object.expType._class.registered;
12558 for(propID = propWatch.properties->first; propID; propID = propID.next)
12560 char propName[1024];
12561 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12564 char getName[1024], setName[1024];
12565 OldList * args = MkList();
12567 DeclareProperty(prop, setName, getName);
12569 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12570 strcpy(propName, "__ecereProp_");
12571 FullClassNameCat(propName, prop._class.fullName, false);
12572 strcat(propName, "_");
12573 // strcat(propName, prop.name);
12574 FullClassNameCat(propName, prop.name, true);
12576 ListAdd(args, CopyExpression(object));
12577 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12578 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12579 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12581 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12584 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12589 Compiler_Error($"Invalid watched object\n");
12592 curExternal = external;
12593 curContext = context;
12596 FreeExpression(watcher);
12598 FreeExpression(object);
12599 FreeList(watches, FreePropertyWatch);
12602 Compiler_Error($"No observer specified and not inside a _class\n");
12606 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12608 ProcessStatement(propWatch.compound);
12614 case fireWatchersStmt:
12616 OldList * watches = stmt._watch.watches;
12617 Expression object = stmt._watch.object;
12619 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12620 // printf("%X\n", watches);
12621 // printf("%X\n", stmt._watch.watches);
12623 ProcessExpressionType(object);
12628 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12634 stmt.type = expressionStmt;
12635 stmt.expressions = MkList();
12637 // Check if we're inside a property set
12638 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12640 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12644 //Compiler_Error($"No property specified and not inside a property set\n");
12648 for(propID = watches->first; propID; propID = propID.next)
12650 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12653 CreateFireWatcher(prop, object, stmt);
12656 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12661 // Fire all properties!
12664 for(base = _class; base; base = base.base)
12666 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12668 if(prop.isProperty && prop.isWatchable)
12670 CreateFireWatcher(prop, object, stmt);
12677 FreeExpression(object);
12678 FreeList(watches, FreeIdentifier);
12681 Compiler_Error($"Invalid object specified and not inside a class\n");
12685 case stopWatchingStmt:
12687 OldList * watches = stmt._watch.watches;
12688 Expression object = stmt._watch.object;
12689 Expression watcher = stmt._watch.watcher;
12692 ProcessExpressionType(object);
12694 ProcessExpressionType(watcher);
12697 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12699 if(watcher || thisClass)
12705 stmt.type = expressionStmt;
12706 stmt.expressions = MkList();
12711 // eInstance_StopWatching(object, null, watcher);
12713 ListAdd(args, CopyExpression(object));
12714 ListAdd(args, MkExpConstant("0"));
12715 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12716 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12720 for(propID = watches->first; propID; propID = propID.next)
12722 char propName[1024];
12723 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12726 char getName[1024], setName[1024];
12727 OldList * args = MkList();
12729 DeclareProperty(prop, setName, getName);
12731 // eInstance_StopWatching(object, prop, watcher);
12732 strcpy(propName, "__ecereProp_");
12733 FullClassNameCat(propName, prop._class.fullName, false);
12734 strcat(propName, "_");
12735 // strcat(propName, prop.name);
12736 FullClassNameCat(propName, prop.name, true);
12737 //MangleClassName(propName);
12739 ListAdd(args, CopyExpression(object));
12740 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12741 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12742 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12745 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12750 FreeExpression(object);
12752 FreeExpression(watcher);
12753 FreeList(watches, FreeIdentifier);
12756 Compiler_Error($"Invalid object specified and not inside a class\n");
12759 Compiler_Error($"No observer specified and not inside a class\n");
12766 static void ProcessFunction(FunctionDefinition function)
12768 Identifier id = GetDeclId(function.declarator);
12769 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12770 Type type = symbol ? symbol.type : null;
12771 Class oldThisClass = thisClass;
12772 Context oldTopContext = topContext;
12774 yylloc = function.loc;
12775 // Process thisClass
12777 if(type && type.thisClass)
12779 Symbol classSym = type.thisClass;
12780 Class _class = type.thisClass.registered;
12781 char className[1024];
12782 char structName[1024];
12783 Declarator funcDecl;
12786 bool typedObject = false;
12788 if(_class && !_class.base)
12790 _class = currentClass;
12791 if(_class && !_class.symbol)
12792 _class.symbol = FindClass(_class.fullName);
12793 classSym = _class ? _class.symbol : null;
12794 typedObject = true;
12797 thisClass = _class;
12799 if(inCompiler && _class)
12801 if(type.kind == functionType)
12803 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12805 //TypeName param = symbol.type.params.first;
12806 Type param = symbol.type.params.first;
12807 symbol.type.params.Remove(param);
12808 //FreeTypeName(param);
12811 if(type.classObjectType != classPointer)
12813 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12814 symbol.type.staticMethod = true;
12815 symbol.type.thisClass = null;
12817 // HIGH DANGER: VERIFYING THIS...
12818 symbol.type.extraParam = false;
12822 strcpy(className, "__ecereClass_");
12823 FullClassNameCat(className, _class.fullName, true);
12825 //MangleClassName(className);
12828 FullClassNameCat(structName, _class.fullName, false);
12833 funcDecl = GetFuncDecl(function.declarator);
12836 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12838 TypeName param = funcDecl.function.parameters->first;
12839 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12841 funcDecl.function.parameters->Remove(param);
12842 FreeTypeName(param);
12846 // DANGER: Watch for this... Check if it's a Conversion?
12847 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12849 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12850 if(!function.propertyNoThis)
12852 TypeName thisParam = null;
12854 if(type.classObjectType != classPointer)
12856 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12857 if(!funcDecl.function.parameters)
12858 funcDecl.function.parameters = MkList();
12859 funcDecl.function.parameters->Insert(null, thisParam);
12864 if(type.classObjectType != classPointer)
12866 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12867 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12870 thisParam = TypeName
12872 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12873 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12875 funcDecl.function.parameters->Insert(null, thisParam);
12880 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12882 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12883 funcDecl = GetFuncDecl(initDecl.declarator);
12886 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12888 TypeName param = funcDecl.function.parameters->first;
12889 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12891 funcDecl.function.parameters->Remove(param);
12892 FreeTypeName(param);
12896 if(type.classObjectType != classPointer)
12898 // DANGER: Watch for this... Check if it's a Conversion?
12899 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12901 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12903 if(!funcDecl.function.parameters)
12904 funcDecl.function.parameters = MkList();
12905 funcDecl.function.parameters->Insert(null, thisParam);
12912 // Add this to the context
12915 if(type.classObjectType != classPointer)
12917 thisSymbol = Symbol
12919 string = CopyString("this");
12920 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12922 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12924 if(typedObject && thisSymbol.type)
12926 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12927 thisSymbol.type.byReference = type.byReference;
12928 thisSymbol.type.typedByReference = type.byReference;
12930 thisSymbol = Symbol { string = CopyString("class") };
12931 function.body.compound.context.symbols.Add(thisSymbol);
12937 // Pointer to class data
12939 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12941 DataMember member = null;
12944 for(base = _class; base && base.type != systemClass; base = base.next)
12946 for(member = base.membersAndProperties.first; member; member = member.next)
12947 if(!member.isProperty)
12953 for(member = _class.membersAndProperties.first; member; member = member.next)
12954 if(!member.isProperty)
12958 char pointerName[1024];
12961 Initializer initializer;
12962 Expression exp, bytePtr;
12964 strcpy(pointerName, "__ecerePointer_");
12965 FullClassNameCat(pointerName, _class.fullName, false);
12967 char className[1024];
12968 strcpy(className, "__ecereClass_");
12969 FullClassNameCat(className, classSym.string, true);
12970 //MangleClassName(className);
12973 DeclareClass(classSym, className);
12977 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12982 sprintf(string, "%d", _class.offset);
12983 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12987 // ([bytePtr] + [className]->offset)
12988 exp = QBrackets(MkExpOp(bytePtr, '+',
12989 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12992 // (this ? [exp] : 0)
12993 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12997 kind = pointerType;
12998 type = Type { refCount = 1, kind = voidType };
13003 yylloc = function.body.loc;
13004 // ([structName] *) [exp]
13005 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
13006 initializer = MkInitializerAssignment(
13007 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
13009 // [structName] * [pointerName] = [initializer];
13010 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
13013 Context prevContext = curContext;
13015 curContext = function.body.compound.context;
13017 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
13018 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
13019 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
13021 curContext = prevContext;
13025 decl.symbol = null;
13027 if(!function.body.compound.declarations)
13028 function.body.compound.declarations = MkList();
13029 function.body.compound.declarations->Insert(null, decl);
13035 // Loop through the function and replace undeclared identifiers
13036 // which are a member of the class (methods, properties or data)
13037 // by "this.[member]"
13044 FreeSpecifier(id._class);
13047 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13049 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13050 id = GetDeclId(initDecl.declarator);
13052 FreeSpecifier(id._class);
13057 topContext = function.body.compound.context;
13059 FunctionDefinition oldFunction = curFunction;
13060 curFunction = function;
13062 ProcessStatement(function.body);
13064 // If this is a property set and no firewatchers has been done yet, add one here
13065 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
13067 Statement prevCompound = curCompound;
13068 Context prevContext = curContext;
13070 Statement fireWatchers = MkFireWatchersStmt(null, null);
13071 if(!function.body.compound.statements) function.body.compound.statements = MkList();
13072 ListAdd(function.body.compound.statements, fireWatchers);
13074 curCompound = function.body;
13075 curContext = function.body.compound.context;
13077 ProcessStatement(fireWatchers);
13079 curContext = prevContext;
13080 curCompound = prevCompound;
13084 curFunction = oldFunction;
13087 if(function.declarator)
13089 ProcessDeclarator(function.declarator);
13092 topContext = oldTopContext;
13093 thisClass = oldThisClass;
13096 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13097 static void ProcessClass(OldList definitions, Symbol symbol)
13100 External external = curExternal;
13101 Class regClass = symbol ? symbol.registered : null;
13103 // Process all functions
13104 for(def = definitions.first; def; def = def.next)
13106 if(def.type == functionClassDef)
13108 if(def.function.declarator)
13109 curExternal = def.function.declarator.symbol.pointerExternal;
13111 curExternal = external;
13113 ProcessFunction((FunctionDefinition)def.function);
13115 else if(def.type == declarationClassDef)
13117 if(def.decl.type == instDeclaration)
13119 thisClass = regClass;
13120 ProcessInstantiationType(def.decl.inst);
13126 Class backThisClass = thisClass;
13127 if(regClass) thisClass = regClass;
13128 ProcessDeclaration(def.decl);
13129 thisClass = backThisClass;
13132 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13134 MemberInit defProperty;
13136 // Add this to the context
13137 Symbol thisSymbol = Symbol
13139 string = CopyString("this");
13140 type = regClass ? MkClassType(regClass.fullName) : null;
13142 globalContext.symbols.Add((BTNode)thisSymbol);
13144 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13146 thisClass = regClass;
13147 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13151 globalContext.symbols.Remove((BTNode)thisSymbol);
13152 FreeSymbol(thisSymbol);
13154 else if(def.type == propertyClassDef && def.propertyDef)
13156 PropertyDef prop = def.propertyDef;
13158 // Add this to the context
13160 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
13161 globalContext.symbols.Add(thisSymbol);
13164 thisClass = regClass;
13171 string = CopyString("this");
13172 type = MkClassType(regClass.fullName);
13174 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13177 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13178 ProcessStatement(prop.setStmt);
13186 string = CopyString("this");
13187 type = MkClassType(regClass.fullName);
13189 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13192 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13193 ProcessStatement(prop.getStmt);
13201 string = CopyString("this");
13202 type = MkClassType(regClass.fullName);
13204 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13207 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13208 ProcessStatement(prop.issetStmt);
13214 globalContext.symbols.Remove(thisSymbol);
13215 FreeSymbol(thisSymbol);
13218 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13220 PropertyWatch propertyWatch = def.propertyWatch;
13222 thisClass = regClass;
13223 if(propertyWatch.compound)
13227 string = CopyString("this");
13228 type = regClass ? MkClassType(regClass.fullName) : null;
13231 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13233 curExternal = null;
13234 ProcessStatement(propertyWatch.compound);
13241 void DeclareFunctionUtil(const String s)
13243 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13248 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13249 strcpy(name, "__ecereFunction_");
13250 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13251 DeclareFunction(function, name);
13255 void ComputeDataTypes()
13259 External after = null;
13261 currentClass = null;
13263 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13265 for(external = ast->first; external; external = external.next)
13267 if(external.type == declarationExternal)
13269 Declaration decl = external.declaration;
13272 OldList * decls = decl.declarators;
13275 InitDeclarator initDecl = decls->first;
13278 Declarator declarator = initDecl.declarator;
13279 if(declarator && declarator.type == identifierDeclarator)
13281 Identifier id = declarator.identifier;
13282 if(id && id.string)
13284 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
13286 external.symbol.id = -1001, external.symbol.idCode = -1001;
13298 // Workaround until we have proper toposort for declarations reordering
13299 External e = MkExternalDeclaration(MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Instance"), null)), null));
13300 ast->Insert(after, e);
13304 temp.symbol = Symbol { id = -1000, idCode = -1000 };
13305 ast->Insert(after, temp);
13306 curExternal = temp;
13308 DeclareFunctionUtil("eSystem_New");
13309 DeclareFunctionUtil("eSystem_New0");
13310 DeclareFunctionUtil("eSystem_Renew");
13311 DeclareFunctionUtil("eSystem_Renew0");
13312 DeclareFunctionUtil("eSystem_Delete");
13313 DeclareFunctionUtil("eClass_GetProperty");
13314 DeclareFunctionUtil("eClass_SetProperty");
13315 DeclareFunctionUtil("eInstance_FireSelfWatchers");
13316 DeclareFunctionUtil("eInstance_SetMethod");
13317 DeclareFunctionUtil("eInstance_IncRef");
13318 DeclareFunctionUtil("eInstance_StopWatching");
13319 DeclareFunctionUtil("eInstance_Watch");
13320 DeclareFunctionUtil("eInstance_FireWatchers");
13323 DeclareFunctionUtil("MemoryGuard_PushLoc");
13324 DeclareFunctionUtil("MemoryGuard_PopLoc");
13327 DeclareStruct("ecere::com::Class", false);
13328 DeclareStruct("ecere::com::Instance", false);
13329 DeclareStruct("ecere::com::Property", false);
13330 DeclareStruct("ecere::com::DataMember", false);
13331 DeclareStruct("ecere::com::Method", false);
13332 DeclareStruct("ecere::com::SerialBuffer", false);
13333 DeclareStruct("ecere::com::ClassTemplateArgument", false);
13337 for(external = ast->first; external; external = external.next)
13339 afterExternal = curExternal = external;
13340 if(external.type == functionExternal)
13342 currentClass = external.function._class;
13343 ProcessFunction(external.function);
13345 // There shouldn't be any _class member access here anyways...
13346 else if(external.type == declarationExternal)
13348 currentClass = null;
13349 if(external.declaration)
13350 ProcessDeclaration(external.declaration);
13352 else if(external.type == classExternal)
13354 ClassDefinition _class = external._class;
13355 currentClass = external.symbol.registered;
13356 if(_class.definitions)
13358 ProcessClass(_class.definitions, _class.symbol);
13362 // Free class data...
13363 ast->Remove(external);
13367 else if(external.type == nameSpaceExternal)
13369 thisNameSpace = external.id.string;
13372 currentClass = null;
13373 thisNameSpace = null;
13374 curExternal = null;
13376 delete temp.symbol;