3 static Map<String, uintptr> oneArgFns
5 { "sqrt", (uintptr)sqrt },
6 { "log", (uintptr)log },
7 { "log10", (uintptr)log10 },
8 { "sin", (uintptr)sin },
9 { "cos", (uintptr)cos },
10 { "tan", (uintptr)tan },
11 { "asin", (uintptr)asin },
12 { "acos", (uintptr)acos },
13 { "atan", (uintptr)atan },
14 { "sinh", (uintptr)sinh },
15 { "cosh", (uintptr)cosh },
16 { "tanh", (uintptr)tanh },
17 { "asinh", (uintptr)asinh },
18 { "acosh", (uintptr)acosh },
19 { "atanh", (uintptr)atanh },
20 { "exp", (uintptr)exp },
21 { "floor", (uintptr)floor },
22 { "ceil", (uintptr)ceil },
23 { "fabs", (uintptr)sqrt }
26 static Map<String, uintptr> twoArgFns
28 { "pow", (uintptr)pow },
29 { "atan2", (uintptr)atan2 },
30 { "fmod", (uintptr)fmod }
33 static void CarryExpressionError(Expression exp, Expression expError)
37 // This function assumes that expError is contained within exp,
38 // and therefore these types will be freed when freeing the old contents
39 // of the expression we're carying into.
41 if(expError.destType) expError.destType.refCount++;
42 if(expError.expType) expError.expType.refCount++;
46 // -- Careful: this could be problematic as FreeExpContents will free the contents of expError
47 // Nulling things that may be freed now, but this is all overly messy/complex
50 case functionCallErrorExp:
51 expError.call.exp = null;
52 expError.call.arguments = null;
55 expError.identifier = null;
58 expError.constant = null;
60 case memberPropertyErrorExp:
61 case memberSymbolErrorExp:
62 expError.member.exp = null;
63 expError.member.member = null;
68 Identifier identifier = expError.identifier;
69 expError.identifier = null;
71 exp.identifier = identifier;
72 exp.type = expError.type;
74 if(exp.expType) FreeType(exp.expType);
75 if(exp.destType) FreeType(exp.destType);
77 *exp = *temp; //*expError;
79 // memset(expError, 0, sizeof(class Expression));
82 static char GetGdbFormatChar(Type type)
84 // x : Regard the bits of the value as an integer, and print the integer in hexadecimal.
85 // d : Print as integer in signed decimal.
86 // u : Print as integer in unsigned decimal.
87 // o : Print as integer in octal.
88 // t : Print as integer in binary. The letter `t' stands for "two". (4)
89 // a : Print as an address, both absolute in hexadecimal and as an offset from the nearest preceding symbol. You can use this format used to discover where (in what function) an unknown address is located:
90 // c : Regard as an integer and print it as a character constant. This prints both the numerical value and its character representation. The character representation is replaced with the octal escape `\nnn' for characters outside the 7-bit ASCII range.
91 // f : Regard the bits of the value as a floating point number and print using typical floating point syntax.
121 // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
131 /*static */bool ExpressionIsError(Expression exp)
133 return (exp.type == dereferenceErrorExp || exp.type == symbolErrorExp ||
134 exp.type == memberSymbolErrorExp || exp.type == memoryErrorExp || exp.type == unknownErrorExp ||
135 exp.type == noDebuggerErrorExp || exp.type == memberPropertyErrorExp || exp.type == functionCallErrorExp || exp.type == divideBy0ErrorExp);
138 void DebugComputeExpression(Expression exp)
141 char expString[1024] = "";
144 PrintExpression(exp, expString);
145 // printf("%s (exp.type = %s)\n", expString, exp.type.OnGetString(temp, null, null));
151 Expression prev = exp.prev, next = exp.next;
152 char * evaluation = null;
153 ExpressionType evalError = dummyExp;
155 TypeKind kind = dummyType;
156 Type dataType = exp.expType;
159 bool isPointer = false;
160 bool evaluate = false;
161 bool evaluateAddress = false;
162 String idString = null;
163 if(exp.identifier.string)
165 const String start = (exp.identifier.string[0] == ':' && exp.identifier.string[1] == ':') ? exp.identifier.string + 2 : exp.identifier.string;
166 if(strstr(start, "::"))
168 char prefix[] = "__ecereNameSpace__";
169 int len = strlen(start);
170 idString = new char[len + sizeof(prefix)];
171 memcpy(idString, prefix, sizeof(prefix) - 1);
172 memcpy(idString + sizeof(prefix) - 1, start, len + 1);
173 ChangeCh(idString + sizeof(prefix) - 1, ':', '_');
176 idString = CopyString(exp.identifier.string);
179 if(dataType && dataType.kind == classType && dataType._class.registered)
181 Class _class = dataType._class.registered;
182 if(_class.type == bitClass || _class.type == unitClass || _class.type == enumClass)
185 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
186 dataType = _class.dataType;
188 else if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass) // Added systemClass here for Instance
193 else if(dataType && dataType.kind == classType && !dataType._class.registered)
196 kind = dataType.kind;
199 exp.type = symbolErrorExp;
200 evalError = symbolErrorExp;
204 case intPtrType: case intSizeType: case _BoolType:
205 case charType: case shortType: case intType: case int64Type: case longType: case floatType: case doubleType:
212 evaluateAddress = true;
215 if(exp.byReference && dataType._class && dataType._class.registered && dataType._class.registered.type == structClass)
216 // if(!dataType._class || !dataType._class.registered || dataType._class.registered.type != structClass || exp.byReference)
217 evaluateAddress = false;
219 evaluateAddress = true;
226 // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
236 strcpy(temp + 1, idString);
239 strcpy(temp, idString);
241 evaluation = Debugger::EvaluateExpression(temp, &evalError);
244 address = _strtoui64(evaluation, null, 0);
255 if(evalError == dummyExp)
261 evaluation = Debugger::EvaluateExpression(idString, &evalError);
266 temp = strstr(evaluation, " '");
267 //len = strlen(temp);
271 for(c = 0; c < len; c++)
273 eString_TrimRSpaces(evaluation, evaluation);
289 evaluation = Debugger::EvaluateExpression(idString, &evalError);
292 if(kind == pointerType)
295 value = _strtoui64(evaluation, null, 0);
297 evaluation = PrintHexUInt64(value);
307 //evaluation = Debugger::EvaluateExpression(idString, &evalError);
308 size = ComputeTypeSize(exp.expType); //exp.expType.arrayType.size;
309 format = GetGdbFormatChar(exp.expType);
310 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
312 StripQuotes(evaluation, evaluation);
318 //evaluation = Debugger::EvaluateExpression(idString, &evalError);
323 // for classType --> if(_class.type == structClass) ?
325 //sprintf(temp, "&%s", idString);
326 //evaluation = Debugger::EvaluateExpression(temp, &evalError);
332 // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
335 evaluation = Debugger::EvaluateExpression(idString, &evalError);
342 if(evaluation && (exp.type != symbolErrorExp || !exp.identifier || !idString || strcmp(evaluation, idString)))
344 char * lt = strchr(evaluation, '<');
347 // Going back to parsing the expression string so as to catch inf/-inf/nan/-nan etc.
348 expNew = ParseExpressionString(evaluation);
349 //expNew = MkExpConstant(evaluation);
350 //printf("Evaluation = %s\n", evaluation);
352 expNew.destType = exp.expType;
354 // WHY EXACTLY MUST WE PROCESS THIS EXPRESSION TYPE AGAIN ? ADDED THIS FOR 0x00000000
355 if(exp.expType && (exp.expType.kind == pointerType || exp.expType.kind == classType) && expNew.destType)
357 expNew.expType = expNew.destType;
358 expNew.destType.refCount++;
359 // For negative values parsed as opExp
360 if(expNew.type == opExp && expNew.op.op == '-' && !expNew.op.exp1 && expNew.op.exp2)
362 expNew.op.exp2.expType = expNew.destType;
363 expNew.destType.refCount++;
364 expNew.op.exp2.isConstant = true;
368 ProcessExpressionType(expNew);
369 FreeType(exp.destType);
370 FreeExpContents(exp);
372 DebugComputeExpression(expNew);
375 expNew.isConstant = true;
376 expNew.address = address;
377 expNew.hasAddress = hasAddress;
383 // Unhandled code path, evaluation is null
384 FreeExpContents(exp);
385 exp.type = unknownErrorExp;
389 // Keep the identifier
390 exp.type = evalError;
393 FreeExpContents(exp);
394 exp.type = evalError;
401 Instantiation inst = exp.instance;
403 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
404 Class _class = classSym ? classSym.registered : null;
405 DataMember curMember = null;
406 Class curClass = null;
407 DataMember subMemberStack[256];
408 int subMemberStackPos = 0;
411 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
413 // Don't recompute the instantiation...
414 // Non Simple classes will have become constants by now
418 if(_class.type == normalClass || _class.type == noHeadClass)
420 inst.data = (byte *)eInstance_New(_class);
421 if(_class.type == normalClass)
422 ((Instance)inst.data)._refCount++;
425 inst.data = new0 byte[_class.structSize];
430 for(members = inst.members->first; members; members = members.next)
434 case dataMembersInit:
436 if(members.dataMembers)
439 for(member = members.dataMembers->first; member; member = member.next)
441 Identifier ident = member.identifiers ? member.identifiers->first : null;
444 Property prop = null;
445 DataMember dataMember = null;
446 uint dataMemberOffset;
450 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
453 if(curMember.isProperty)
455 prop = (Property)curMember; // TOFIX: (eC II ? THe mss
459 dataMember = curMember;
462 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, GetPrivateModule(), null, null);
464 // 2013/17/29 -- It seems that this was missing here!
465 if(_class.type == normalClass)
466 dataMemberOffset += _class.base.structSize;
467 // dataMemberOffset = dataMember.offset;
474 prop = eClass_FindProperty(_class, ident.string, GetPrivateModule());
478 if(prop.memberAccess == publicAccess)
480 curMember = (DataMember)prop;
481 curClass = prop._class;
486 DataMember _subMemberStack[256];
487 int _subMemberStackPos = 0;
490 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, GetPrivateModule(), _subMemberStack, &_subMemberStackPos);
495 if(dataMember.memberAccess == publicAccess)
497 curMember = dataMember;
498 curClass = dataMember._class;
499 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
500 subMemberStackPos = _subMemberStackPos;
506 if(found && member.initializer && member.initializer.type == expInitializer)
508 Expression value = member.initializer.exp;
510 bool deepMember = false;
513 type = prop.dataType;
517 if(!dataMember.dataType)
518 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
520 type = dataMember.dataType;
523 if(ident && ident.next)
527 // for(; ident && type; ident = ident.next)
528 for(ident = ident.next; ident && type; ident = ident.next)
530 if(type.kind == classType)
532 prop = eClass_FindProperty(type._class.registered,
533 ident.string, GetPrivateModule());
535 type = prop.dataType;
538 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
539 ident.string, &dataMemberOffset, GetPrivateModule(), null, null);
541 type = dataMember.dataType;
544 else if(type.kind == structType || type.kind == unionType)
547 for(memberType = type.members.first; memberType; memberType = memberType.next)
549 if(!strcmp(memberType.name, ident.string))
560 FreeType(value.destType);
561 value.destType = type;
562 if(type) type.refCount++;
563 DebugComputeExpression(value);
565 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
567 if(type.kind == classType)
569 Class _class = type._class.registered;
570 if(_class.type == bitClass || _class.type == unitClass ||
571 _class.type == enumClass)
574 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
575 type = _class.dataType;
581 void * ptr = inst.data + dataMemberOffset;
583 if(value.type == constantExp)
589 GetInt(value, (int*)ptr);
594 GetInt64(value, (int64*)ptr);
599 GetIntPtr(value, (intptr*)ptr);
604 GetIntSize(value, (intsize*)ptr);
609 GetFloat(value, (float*)ptr);
614 GetDouble(value, (double *)ptr);
619 else if(value.type == instanceExp)
621 if(type.kind == classType)
623 Class _class = type._class.registered;
624 if(_class.type == structClass)
626 ComputeTypeSize(type);
627 if(value.instance.data)
628 memcpy(ptr, value.instance.data, type.size);
635 if(value.type == instanceExp && value.instance.data)
637 if(type.kind == classType)
639 Class _class = type._class.registered;
640 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
642 void (*Set)(void *, void *) = (void *)prop.Set;
643 Set(inst.data, value.instance.data);
644 PopulateInstance(inst);
648 else if(value.type == constantExp)
654 void (*Set)(void *, double) = (void *)prop.Set;
655 Set(inst.data, strtod(value.constant, null) );
660 void (*Set)(void *, float) = (void *)prop.Set;
661 Set(inst.data, (float)(strtod(value.constant, null)));
666 void (*Set)(void *, int) = (void *)prop.Set;
667 Set(inst.data, (int)strtol(value.constant, null, 0));
672 void (*Set)(void *, int64) = (void *)prop.Set;
673 Set(inst.data, _strtoi64(value.constant, null, 0));
678 void (*Set)(void *, intptr) = (void *)prop.Set;
679 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
684 void (*Set)(void *, intsize) = (void *)prop.Set;
685 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
690 else if(value.type == stringExp)
693 ReadString(temp, value.string);
694 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
698 else if(!deepMember && type && _class.type == unitClass)
702 // Only support converting units to units for now...
703 if(value.type == constantExp)
705 if(type.kind == classType)
707 Class _class = type._class.registered;
708 if(_class.type == unitClass)
711 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
712 type = _class.dataType;
715 // TODO: Assuming same base type for units...
721 float (*Set)(float) = (void *)prop.Set;
722 GetFloat(member.initializer.exp, &fValue);
723 exp.constant = PrintFloat(Set(fValue));
724 exp.type = constantExp;
730 double (*Set)(double) = (void *)prop.Set;
731 GetDouble(member.initializer.exp, &dValue);
732 exp.constant = PrintDouble(Set(dValue));
733 exp.type = constantExp;
740 else if(!deepMember && type && _class.type == bitClass)
744 if(value.type == instanceExp && value.instance.data)
746 unsigned int (*Set)(void *) = (void *)prop.Set;
747 bits = Set(value.instance.data);
749 else if(value.type == constantExp)
755 BitMember bitMember = (BitMember) dataMember;
758 GetInt(value, &part);
759 bits = (bits & ~bitMember.mask);
760 if(!bitMember.dataType)
761 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
763 type = bitMember.dataType;
765 if(type.kind == classType && type._class && type._class.registered)
767 if(!type._class.registered.dataType)
768 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
769 type = type._class.registered.dataType;
777 bits |= ((char)part << bitMember.pos);
779 bits |= ((unsigned char)part << bitMember.pos);
783 bits |= ((short)part << bitMember.pos);
785 bits |= ((unsigned short)part << bitMember.pos);
790 bits |= ((int)part << bitMember.pos);
792 bits |= ((unsigned int)part << bitMember.pos);
796 bits |= ((int64)part << bitMember.pos);
798 bits |= ((uint64)part << bitMember.pos);
803 bits |= ((intptr)part << bitMember.pos);
807 bits |= ((uintptr)part << bitMember.pos);
813 bits |= ((ssize_t)(intsize)part << bitMember.pos);
817 bits |= ((size_t) (uintsize)part << bitMember.pos);
826 if(_class && _class.type == unitClass)
828 DebugComputeExpression(member.initializer.exp);
829 exp.constant = member.initializer.exp.constant;
830 exp.type = constantExp;
832 member.initializer.exp.constant = null;
842 if(_class && _class.type == bitClass)
844 exp.constant = PrintHexUInt(bits);
845 exp.type = constantExp;
847 if(exp.type != instanceExp)
859 Expression expError = null;
860 Expression exp1 = null, exp2 = null;
861 Operand op1 = { 0 }, op2 = { 0 };
864 if(exp.op.op == '&' || exp.op.op == '*')
866 if(!exp.op.exp1 && exp.op.exp2)
868 if(exp.op.exp2.type == identifierExp)
870 Expression prev = exp.prev, next = exp.next;
871 char * evaluation = null;
872 ExpressionType evalError = dummyExp;
875 sprintf(temp, "%c%s", exp.op.op, exp.op.exp2.identifier.string);
876 evaluation = Debugger::EvaluateExpression(temp, &evalError);
877 if(evalError != dummyExp)
879 exp.type = evalError;
880 exp.constant = CopyString("");
884 expNew = ParseExpressionString(evaluation);
886 expNew.destType = exp.expType;
887 FreeType(exp.destType);
888 FreeExpContents(exp);
889 ProcessExpressionType(expNew);
890 DebugComputeExpression(expNew);
893 expNew.isConstant = true;
898 exp.type = ExpUnknownError;
908 DebugComputeExpression(exp.op.exp2);
909 size = ComputeTypeSize(exp.op.exp2.expType);
910 format = GetGdbFormatChar(exp.op.exp2.expType);
911 GetInt(exp.op.exp2, &address);
912 //sprintf(temp, "%c%s", exp.op.op, exp.op.exp2.constant);
913 evaluation = Debug_ReadMemory(address, size, format, &evalError);
916 evalError = ExpUnknownError;
922 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
925 Expression e = exp.op.exp2;
927 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
929 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
931 if(e.type == extensionCompoundExp)
932 e = ((Statement)e.compound.compound.statements->last).expressions->last;
937 if(exp.op.op == TokenType::sizeOf && e && e.expType)
939 if(e.type == stringExp && e.string)
941 char * string = e.string;
942 int len = strlen(string);
943 char * tmp = new char[len-2+1];
944 len = UnescapeString(tmp, string + 1, len - 2);
946 FreeExpContents(exp);
947 exp.type = constantExp;
948 exp.constant = PrintUInt(len + 1);
952 Type type = e.expType;
954 FreeExpContents(exp);
955 exp.type = constantExp;
956 exp.constant = PrintUInt(ComputeTypeSize(type));
963 DebugComputeExpression(exp.op.exp2);
964 if(ExpressionIsError(exp.op.exp2))
965 expError = exp.op.exp2;
972 DebugComputeExpression(exp.op.exp1);
973 if(ExpressionIsError(exp.op.exp1))
974 expError = exp.op.exp1;
979 if(ExpressionIsError(exp.op.exp2))
980 expError = exp.op.exp2;
985 op1 = GetOperand(exp1);
986 if(op1.type) op1.type.refCount++;
987 op2 = GetOperand(exp2);
988 if(op2.type) op2.type.refCount++;
994 op1 = GetOperand(exp1);
995 if(op1.type) op1.type.refCount++;
1001 if(ExpressionIsError(exp.op.exp2))
1002 expError = exp.op.exp2;
1006 if(exp.op.op == '&' || exp.op.op == '*')
1008 Expression prev = exp1.prev, next = exp1.next;
1010 ExpressionType evalError = dummyExp;
1011 char * evaluation = null;
1012 if(exp.op.op == '&')
1017 //sprintf(temp, "%u", exp1.address);
1018 temp = PrintHexUInt64(exp1.address);
1019 expNew = ParseExpressionString(temp);
1021 //expNew.address = exp1.address;
1022 expNew.expType = exp.expType;
1024 expNew.destType = exp.expType;
1025 expNew.destType.refCount++;
1027 FreeType(exp.destType);
1028 FreeExpContents(exp);
1029 ProcessExpressionType(expNew);
1030 DebugComputeExpression(expNew);
1033 expNew.isConstant = true;
1040 else if(exp.op.op == '*')
1042 // TODO: Common pathway for * and [ ]
1046 FreeExpContents(exp1);
1047 exp1.type = dereferenceErrorExp;
1055 Expression e = exp1;
1057 bool gotAddress = false;
1059 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
1061 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
1063 if(e.type == extensionCompoundExp)
1064 e = ((Statement)e.compound.compound.statements->last).expressions->last;
1068 else if(e.type == castExp)
1072 if(e.expType.kind == structType)
1074 address = exp1.address;
1078 gotAddress = GetUInt64(e, &address);
1079 size = ComputeTypeSize(exp.expType); //exp.expType.arrayType.size;
1080 if(exp.expType && exp.expType.type && exp.expType.kind == arrayType)
1081 // For multilevels arrays
1084 format = GetGdbFormatChar(exp.expType);
1085 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
1087 Expression e1 = e.op.exp1, e2 = e.op.exp2;
1088 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1090 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1092 if(e1.type == extensionCompoundExp)
1093 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1097 else if(e1.type == castExp)
1100 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1102 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1104 if(e2.type == extensionCompoundExp)
1105 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1109 else if(e2.type == castExp)
1113 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1115 offset += strtol(e.op.exp2.constant, null, 0);
1118 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1120 offset += strtol(e.op.exp1.constant, null, 0);
1127 if(e.type == stringExp)
1130 String string = e.string;
1132 Type expType = exp1.expType.type;
1133 if(expType) expType.refCount++;
1137 int len = string ? strlen(string) : 0;
1138 tmp = new char[len-2+1];
1139 len = UnescapeString(tmp, string + 1, len - 2);
1140 if(len >= 0 && offset * size + size-1 <= len)
1144 FreeExpContents(exp);
1146 exp.type = dereferenceErrorExp;
1149 exp.type = constantExp;
1150 exp.isConstant = true;
1151 switch(expType.kind)
1153 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1154 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1155 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1156 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1157 case floatType: exp.constant = PrintFloat(((float *)tmp)[offset]); break;
1158 case doubleType: exp.constant = PrintDouble(((double *)tmp)[offset]); break;
1160 exp.type = unknownErrorExp;
1164 exp.type = unknownErrorExp;
1168 else if(gotAddress && exp.expType.kind == arrayType)
1170 FreeExpContents(exp);
1171 exp.type = constantExp;
1172 exp.isConstant = true;
1173 exp.constant = PrintHexUInt64(address);
1174 exp.address = address;
1175 exp.hasAddress = true;
1177 else if(gotAddress && format)
1179 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1185 expNew = ParseExpressionString(evaluation);
1186 expNew.address = address;
1187 expNew.hasAddress = true;
1189 expNew.destType = exp.expType;
1190 FreeType(exp.destType);
1191 FreeExpContents(exp);
1192 ProcessExpressionType(expNew);
1193 DebugComputeExpression(expNew);
1196 expNew.isConstant = true;
1202 // Unhandled code path, evaluation is null
1203 FreeExpContents(exp);
1204 exp.type = unknownErrorExp;
1207 case memoryErrorExp:
1209 FreeExpContents(exp1);
1210 exp1.type = evalError;
1211 exp1.constant = PrintHexUInt64(address);
1216 FreeExpContents(exp1);
1217 exp1.type = evalError;
1224 FreeExpContents(exp1);
1225 exp1.type = unknownErrorExp; // Not supported yet, generate error to fallback to GDB printout
1232 op1 = GetOperand(exp1);
1233 if(op1.type) op1.type.refCount++;
1238 CarryExpressionError(exp, expError);
1239 else if(exp.type == opExp)
1241 if(exp1 && exp2 && exp1.expType && exp2.expType &&
1242 ((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) ||
1243 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
1246 if((exp.op.op == '+' || exp.op.op == '-') && (op2.type || op1.type))
1248 Expression e1 = exp1, e2 = exp2;
1249 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1251 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1253 if(e1.type == extensionCompoundExp)
1254 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1258 else if(e1.type == castExp)
1261 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1263 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1265 if(e2.type == extensionCompoundExp)
1266 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1270 else if(e2.type == castExp)
1274 if((e1.type == stringExp && op2.type && op2.type.kind == intType) || (e2.type == stringExp && op1.type && op1.type.kind == intType))
1276 uint64 offset = ((exp.op.op == '+') ? 1 : -1) * (e1.type == stringExp ? op2.i64 : op1.i64);
1277 String newString = null;
1278 Expression e = e1.type == stringExp ? e1 : e2;
1281 int len = strlen(e.string) - 2;
1282 char * tmp = OffsetEscapedString(e.string + 1, len, (int)offset);
1285 len -= tmp - (e.string + 1);
1286 newString = new char[2 + len + 1];
1287 newString[0] = '\"';
1288 memcpy(newString + 1, tmp, len);
1289 newString[1 + len] = '\"';
1290 newString[1 + len + 1] = 0;
1294 FreeExpContents(exp);
1297 exp.type = stringExp;
1298 exp.string = newString;
1301 exp.type = dereferenceErrorExp;
1303 // Can't add 2 pointers...
1304 else if(exp.op.op != '+' ||
1305 !((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) &&
1306 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
1308 bool op1IsPointer = exp1.expType.kind == pointerType || exp1.expType.kind == arrayType;
1309 bool op2IsPointer = exp2.expType.kind == pointerType || exp2.expType.kind == arrayType;
1310 bool addressResult = !op1IsPointer || !op2IsPointer;
1314 size = ComputeTypeSize(exp1.expType.type);
1315 else if(op2IsPointer)
1316 size = ComputeTypeSize(exp2.expType.type);
1318 if(addressResult && size)
1320 if(op1IsPointer) op2.ui64 *= size;
1321 else if(op1IsPointer) op1.ui64 *= size;
1324 CallOperator(exp, exp1, exp2, op1, op2);
1325 if(exp.type == constantExp)
1329 exp.address = _strtoui64(exp.constant, null, 0);
1330 delete exp.constant;
1331 exp.constant = PrintHexUInt64(exp.address);
1332 if(op1.type.kind == arrayType || op2.type.kind == arrayType)
1333 exp.hasAddress = true;
1337 int64 v = _strtoi64(exp.constant, null, 0);
1339 delete exp.constant;
1340 exp.constant = PrintInt(v);
1347 FreeExpContents(exp);
1348 exp.type = unknownErrorExp; // We should have an invalid operands error
1353 if(!exp2 && exp1 && exp1.type == constantExp && exp1.constant && !strcmp(exp1.constant, "nan") && exp.op.op == '-')
1355 FreeExpContents(exp);
1356 exp.constant = CopyString("-nan");
1357 exp.type = constantExp;
1361 if((exp.op.op == '/' || exp.op.op == '%') && op2.kind != doubleType && op1.kind != doubleType && op2.kind != floatType && op1.kind != floatType &&
1362 (((op2.kind == int64Type || op2.kind == intPtrType || op2.kind == intSizeType) && !op2.i64) ||
1363 (op2.kind == intType && !op2.i) || (op2.kind == shortType && !op2.s) || (op2.kind == charType && !op2.c)))
1365 FreeExpContents(exp);
1366 exp.type = divideBy0ErrorExp;
1369 CallOperator(exp, exp1, exp2, op1, op2);
1374 if(exp.type == constantExp)
1375 exp.isConstant = true;
1383 // e = (*exp.list).first, n = e ? e.next : null;
1385 // e = n, n = n?(n.next) : null)
1387 for(e = exp.list->first; e; e = n)
1392 OldList * list = exp.list;
1393 DebugComputeExpression(e);
1394 //if(ExpressionIsError(e)) //.type == ExpSymbolError
1395 // CarryExpressionError(exp, e);
1396 //FreeExpContents(exp);
1397 FreeType(exp.expType);
1398 FreeType(exp.destType);
1415 exp.isConstant = true;
1417 DebugComputeExpression(exp.index.exp);
1418 if(ExpressionIsError(exp.index.exp)) //.type == ExpSymbolError
1419 CarryExpressionError(exp, exp.index.exp);
1422 Expression prev = exp.prev, next = exp.next;
1423 char * evaluation = null;
1424 ExpressionType evalError = dummyExp;
1425 Type dataType = exp.index.exp.expType ? exp.index.exp.expType.type : null;
1427 if(!exp.index.exp.isConstant)
1428 exp.isConstant = false;
1431 // 4 == size = ComputeTypeSize(exp.expType);
1432 // 0 == size = ComputeTypeSize(exp.expType.arrayType);
1433 // 4 == size = ComputeTypeSize(exp.index.exp.expType);
1434 // 0 == size = ComputeTypeSize(exp.index.exp.expType.arrayType);
1436 size = ComputeTypeSize(dataType);
1437 if(dataType && dataType.type && dataType.kind == arrayType)
1438 // For multilevels arrays
1441 format = GetGdbFormatChar(dataType);
1443 for(e = exp.index.index->first; e; e = e.next)
1445 DebugComputeExpression(e);
1446 if(ExpressionIsError(e)) //.type == ExpSymbolError
1448 CarryExpressionError(exp, e);
1453 // Check if this type is int
1456 exp.isConstant = false;
1458 if(!ExpressionIsError(exp))
1460 // Is this necessary here? pass15 had done this already...
1461 if(exp.expType) FreeType(exp.expType);
1462 exp.expType = Dereference(exp.index.exp.expType);
1467 FreeExpContents(exp);
1468 exp.type = dereferenceErrorExp;
1470 else if(exp.index.index && exp.index.index->last && ((Expression)exp.index.index->last) && ((Expression)exp.index.index->last).expType)
1472 Type type = ((Expression)exp.index.index->last).expType;
1473 if(type.kind == intType || type.kind == charType || type.kind == shortType || type.kind == int64Type || type.kind == intPtrType ||
1474 type.kind == intSizeType || type.kind == longType || type.kind == _BoolType || type.kind == enumType ||
1475 (type.kind == classType && type._class && type._class.registered &&
1476 type._class.registered.type == enumClass))
1478 bool gotAddress = false;
1479 uint64 address = 0, offset = 0;
1480 Expression expNew, last = (Expression)exp.index.index->last;
1481 Expression e = exp.index.exp;
1483 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
1485 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
1487 if(e.type == extensionCompoundExp)
1488 e = ((Statement)e.compound.compound.statements->last).expressions->last;
1492 else if(e.type == castExp)
1496 //GetUInt(exp.index.exp, &address);
1498 GetUInt64(last, &offset);
1500 // TOFIX: Check if it has address: TESTING
1501 if(exp.index.exp.hasAddress && exp.index.exp.expType.kind == arrayType)
1503 address = exp.index.exp.address;
1506 else if(exp.index.exp.type == constantExp)
1507 gotAddress = GetUInt64(exp.index.exp, &address);
1509 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
1511 Expression e1 = e.op.exp1, e2 = e.op.exp2;
1512 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1514 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1516 if(e1.type == extensionCompoundExp)
1517 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1521 else if(e1.type == castExp)
1524 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1526 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1528 if(e2.type == extensionCompoundExp)
1529 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1533 else if(e2.type == castExp)
1537 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1539 offset += strtol(e.op.exp2.constant, null, 0);
1542 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1544 offset += strtol(e.op.exp1.constant, null, 0);
1551 //size = ComputeTypeSize(exp.expType.arrayType); //exp.expType.arrayType.size;
1552 address += offset * size;
1554 if(e.type == stringExp)
1557 String string = e.string;
1559 Type expType = exp.index.exp.expType.type;
1560 if(expType) expType.refCount++;
1564 int len = string ? strlen(string) : 0;
1565 tmp = new char[len-2+1];
1566 len = UnescapeString(tmp, string + 1, len - 2);
1567 if(len >= 0 && offset * size + size-1 <= len)
1571 FreeExpContents(exp);
1573 exp.type = dereferenceErrorExp;
1576 exp.type = constantExp;
1577 exp.isConstant = true;
1578 switch(expType.kind)
1580 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1581 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1582 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1583 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1584 case floatType: exp.constant = PrintFloat(((float *)tmp)[offset]); break;
1585 case doubleType: exp.constant = PrintDouble(((double *)tmp)[offset]); break;
1587 exp.type = unknownErrorExp;
1591 exp.type = unknownErrorExp;
1595 else if(gotAddress && exp.expType.kind == arrayType)
1597 FreeExpContents(exp);
1598 exp.type = constantExp;
1599 exp.isConstant = true;
1600 exp.constant = PrintHexUInt64(address);
1601 exp.address = address;
1602 exp.hasAddress = true;
1606 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1612 expNew = ParseExpressionString(evaluation);
1614 expNew.destType = exp.expType;
1615 FreeType(exp.destType);
1616 FreeExpContents(exp);
1617 ProcessExpressionType(expNew);
1618 DebugComputeExpression(expNew);
1620 // TOFIX: Only for Array Types
1621 expNew.address = address;
1623 expNew.hasAddress = true;
1626 expNew.isConstant = true;
1632 // Unhandled code path, evaluation is null
1633 FreeExpContents(exp);
1634 exp.type = unknownErrorExp;
1637 case memoryErrorExp:
1639 FreeExpContents(exp);
1640 exp.type = evalError;
1641 exp.constant = PrintHexUInt64(address);
1645 FreeExpContents(exp);
1646 exp.type = evalError;
1652 FreeExpContents(exp);
1653 exp.type = unknownErrorExp;
1663 Expression callExp = exp.call.exp;
1664 Identifier id = (callExp && callExp.type == identifierExp) ? callExp.identifier : null;
1665 bool resolved = false;
1668 if(!strcmp(id.string, "nan") || !strcmp(id.string, "inf"))
1670 String s = id.string;
1672 FreeExpContents(exp);
1673 exp.type = constantExp;
1677 else if(exp.call.arguments)
1679 if(exp.call.arguments->count == 1)
1681 double (* fn1)(double) = (void *)oneArgFns[id.string];
1684 Expression arg = exp.call.arguments->first;
1685 DebugComputeExpression(arg);
1686 if(ExpressionIsError(arg))
1687 CarryExpressionError(exp, arg);
1688 else if(arg.isConstant && arg.type == constantExp)
1691 if(GetDouble(arg, &v))
1693 FreeExpContents(exp);
1694 exp.type = constantExp;
1696 exp.constant = PrintDouble(v);
1697 exp.isConstant = true;
1703 else if(exp.call.arguments->count == 2)
1705 double (* fn2)(double, double) = (void *)twoArgFns[id.string];
1708 Expression arg1 = exp.call.arguments->first;
1709 Expression arg2 = exp.call.arguments->last;
1710 DebugComputeExpression(arg1);
1711 DebugComputeExpression(arg2);
1712 if(ExpressionIsError(arg1))
1713 CarryExpressionError(exp, arg1);
1714 else if(ExpressionIsError(arg2))
1715 CarryExpressionError(exp, arg2);
1716 else if(arg1.isConstant && arg1.type == constantExp && arg2.isConstant && arg2.type == constantExp)
1719 if(GetDouble(arg1, &v1) && GetDouble(arg2, &v2))
1721 FreeExpContents(exp);
1722 exp.type = constantExp;
1724 exp.constant = PrintDouble(v1);
1725 exp.isConstant = true;
1734 exp.type = functionCallErrorExp;
1739 Expression memberExp = exp.member.exp;
1740 Identifier memberID = exp.member.member;
1742 Property prop = null;
1743 DataMember member = null;
1744 Class convertTo = null;
1745 uint offset = 0; // THIS WASN'T INITIALIZED... IS IT ALWAYS SET?
1747 Type type; // = memberExp.expType;
1748 DebugComputeExpression(memberExp);
1749 type = memberExp.expType;
1750 if(ExpressionIsError(memberExp))
1751 CarryExpressionError(exp, memberExp);
1754 // _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
1755 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);
1758 char string[256] = "";
1760 PrintTypeNoConst(type, string, false, true);
1761 classSym = FindClass(string);
1762 _class = classSym ? classSym.registered : null;
1765 if(memberID && _class)
1768 prop = eClass_FindProperty(_class, memberID.string);
1770 member = eClass_FindDataMember(_class, memberID.string);
1772 // member = eClass_FindDataMember(_class, memberID.string);
1773 member = eClass_FindDataMemberAndOffset(_class, memberID.string, &offset, _class.module.application, null, null);
1775 prop = eClass_FindProperty(_class, memberID.string, _class.module.application);
1777 if(!prop && !member && _class && memberID)
1779 Symbol classSym = FindClass(memberID.string);
1781 _class = classSym ? classSym.registered : null;
1783 prop = eClass_FindProperty(_class, convertTo.fullName, _class.module.application);
1786 //DebugComputeExpression(memberExp);
1787 if(ExpressionIsError(memberExp))
1788 CarryExpressionError(exp, memberExp);
1791 if(exp.member.memberType == methodMember)
1793 FreeExpContents(exp);
1794 exp.type = unknownErrorExp;
1798 bool supported = false;
1801 Type type = prop.dataType;
1802 // TODO: Assuming same base type for units...
1803 if(_class.type == unitClass)
1805 if(type.kind == classType)
1807 Class _class = type._class.registered;
1808 if(_class.type == unitClass)
1810 if(!_class.dataType)
1811 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
1812 type = _class.dataType;
1820 float (*Get)(float) = (convertTo ? (void *)prop.Set : (void *)prop.Get);
1821 GetFloat(memberExp, &value);
1823 FreeExpContents(exp);
1824 exp.constant = PrintFloat(Get ? Get(value) : value);
1825 exp.type = constantExp;
1826 exp.isConstant = true;
1833 double (*Get)(double) = (convertTo ? (void *)prop.Set : (void *)prop.Get);
1834 GetDouble(memberExp, &value);
1836 FreeExpContents(exp);
1837 exp.constant = PrintDouble(Get ? Get(value) : value);
1838 exp.isConstant = true;
1839 exp.type = constantExp;
1849 Expression value = memberExp;
1850 Type type = prop.dataType;
1851 exp.member.exp = null;
1853 if(_class.type == structClass)
1859 Class propertyClass = type._class.registered;
1860 if(propertyClass.type == structClass && value.type == instanceExp)
1862 void (*Set)(void *, void *) = (void *)prop.Set;
1863 FreeExpContents(exp);
1864 exp.instance = Instantiation
1866 data = new0 byte[_class.structSize];
1867 _class = MkSpecifierName(_class.name);
1870 exp.type = instanceExp;
1872 Set(exp.instance.data, value.instance.data);
1873 PopulateInstance(exp.instance);
1881 void (*Set)(void *, int) = (void *)prop.Set;
1883 GetInt(value, &intValue);
1884 FreeExpContents(exp);
1885 exp.instance = Instantiation
1887 data = new0 byte[_class.structSize];
1888 _class = MkSpecifierName/*MkClassName*/(_class.name);
1891 exp.type = instanceExp;
1893 Set(exp.instance.data, intValue);
1894 PopulateInstance(exp.instance);
1901 void (*Set)(void *, int64) = (void *)prop.Set;
1903 GetInt64(value, &intValue);
1904 FreeExpContents(exp);
1905 exp.instance = Instantiation
1907 data = new0 byte[_class.structSize];
1908 _class = MkSpecifierName/*MkClassName*/(_class.name);
1911 exp.type = instanceExp;
1913 Set(exp.instance.data, intValue);
1914 PopulateInstance(exp.instance);
1921 void (*Set)(void *, float) = (void *)prop.Set;
1923 GetFloat(value, &floatValue);
1924 FreeExpContents(exp);
1925 exp.instance = Instantiation
1927 data = new0 byte[_class.structSize];
1928 _class = MkSpecifierName/*MkClassName*/(_class.name);
1931 exp.type = instanceExp;
1933 Set(exp.instance.data, floatValue);
1934 PopulateInstance(exp.instance);
1941 void (*Set)(void *, double) = (void *)prop.Set;
1943 GetDouble(value, &doubleValue);
1944 FreeExpContents(exp);
1945 exp.instance = Instantiation
1947 data = new0 byte[_class.structSize];
1948 _class = MkSpecifierName/*MkClassName*/(_class.name);
1951 exp.type = instanceExp;
1953 Set(exp.instance.data, doubleValue);
1954 PopulateInstance(exp.instance);
1960 else if(_class.type == bitClass)
1966 Class propertyClass = type._class.registered;
1967 if(propertyClass.type == structClass && value.instance.data)
1969 unsigned int (*Set)(void *) = (void *)prop.Set;
1970 unsigned int bits = Set(value.instance.data);
1971 FreeExpContents(exp);
1972 exp.constant = PrintHexUInt(bits);
1973 exp.type = constantExp;
1977 else if(_class.type == bitClass)
1980 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
1983 GetUInt(memberExp, &value);
1985 FreeExpContents(exp);
1986 exp.constant = PrintHexUInt(bits);
1987 exp.type = constantExp;
1993 FreeExpression(value);
1997 if(_class.type == bitClass)
2000 GetUInt(memberExp, &value);
2006 Class _class = type._class.registered;
2007 if(_class.type == structClass)
2009 void (*Get)(unsigned int, void *) = (void *)prop.Get;
2011 FreeExpContents(exp);
2012 exp.instance = Instantiation
2014 data = new0 byte[_class.structSize];
2015 _class = MkSpecifierName/*MkClassName*/(_class.name);
2018 //exp.instance.fullSet = true;
2019 exp.type = instanceExp;
2020 Get(value, exp.instance.data);
2021 PopulateInstance(exp.instance);
2024 else if(_class.type == bitClass)
2026 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
2027 uint64 bits = Get(value);
2028 exp.constant = PrintHexUInt64(bits);
2029 exp.type = constantExp;
2036 else if(_class.type == structClass)
2038 byte * value = (memberExp.type == instanceExp ) ? memberExp.instance.data : null;
2040 memberExp.instance.data = null;
2046 Class _class = type._class.registered;
2047 if(_class.type == structClass && value)
2049 void (*Get)(void *, void *) = (void *)prop.Get;
2051 FreeExpContents(exp);
2052 exp.instance = Instantiation
2054 data = new0 byte[_class.structSize];
2055 _class = MkSpecifierName/*MkClassName*/(_class.name);
2058 //exp.instance.fullSet = true;
2059 exp.type = instanceExp;
2060 Get(value, exp.instance.data);
2061 PopulateInstance(exp.instance);
2072 char * value = memberExp.instance.data;
2077 Class _class = type._class.registered;
2078 if(_class.type == normalClass)
2080 void *(*Get)(void *) = (void *)prop.Get;
2082 FreeExpContents(exp);
2083 exp.instance = Instantiation
2085 data = Get(value, exp.instance.data); ?????
2086 _class = MkSpecifierName(_class.name); //MkClassName(_class.name);
2089 exp.type = instanceExp;
2101 exp.type = memberPropertyErrorExp;
2102 exp.isConstant = false;
2107 if(memberExp.hasAddress || memberExp.type == constantExp || (memberExp.type == instanceExp && memberExp.instance && memberExp.instance.data))
2108 //if(memberExp.expType && memberExp.expType.kind == intType) // && !exp.index.exp.expType.isSigned
2110 if(_class.type == bitClass)
2112 if(memberExp.type == constantExp)
2114 // Unfinished business...
2115 BitMember bitMember = (BitMember)member;
2117 GetUInt64(memberExp, &bits);
2118 bits &= bitMember.mask;
2119 bits >>= bitMember.pos;
2121 FreeExpression(exp.member.exp);
2122 FreeIdentifier(exp.member.member);
2124 exp.constant = PrintUInt64(bits);
2126 exp.isConstant = true;
2127 exp.type = constantExp;
2128 exp.hasAddress = false;
2133 char * evaluation = null;
2134 ExpressionType evalError = dummyExp;
2135 bool gotAddress = false;
2137 Expression prev = exp.prev, next = exp.next;
2141 Type dataType = member.dataType;
2144 dataType = member.dataType = ProcessTypeString(member.dataTypeString, false);
2146 if(dataType.kind == classType && dataType._class.registered &&
2147 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
2149 if(dataType._class.registered.dataTypeString)
2150 dataType._class.registered.dataType = ProcessTypeString(dataType._class.registered.dataTypeString, false);
2151 dataType = dataType._class.registered.dataType;
2153 dataType = ProcessTypeString("int", false);
2156 size = ComputeTypeSize(member.dataType);
2158 format = GetGdbFormatChar(dataType);
2159 //if(memberExp.address)
2161 //GetInt(memberExp, &address);
2162 //offset = member.offset;
2164 // TESTING NOHEAD HERE?
2165 if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass)
2166 offset += member._class.offset;
2168 // VERIFY THIS: (trying to fix primitive.type)
2169 // if(memberExp.type == constantExp)
2170 if(memberExp.hasAddress && (_class.type != normalClass && _class.type != noHeadClass && _class.type != systemClass))
2172 address = memberExp.address;
2175 else if(memberExp.type == constantExp)
2176 gotAddress = GetUInt64(memberExp, &address);
2179 gotAddress = GetUInt64(memberExp, &address);
2180 //printf("Unhandled !!\n");
2182 //printf("memberExp.hasAddress = %d\n", memberExp.hasAddress);
2183 //printf("memberExp.type = %d\n", memberExp.type);
2184 //printf("_class.name = %s, _class.type = %d\n", _class.name, _class.type);
2189 if(memberExp.type == instanceExp)
2191 String constant = null;
2192 byte * data = memberExp.instance.data + offset;
2193 switch(dataType.kind)
2196 if(dataType.isSigned)
2197 constant = PrintChar(*(char *)data);
2199 constant = PrintUChar(*(byte *)data);
2202 if(dataType.isSigned)
2203 constant = PrintShort(*(short *)data);
2205 constant = PrintUShort(*(uint16 *)data);
2208 if(dataType.isSigned)
2209 constant = PrintInt(*(int *)data);
2211 constant = PrintUInt(*(uint *)data);
2215 if(dataType.isSigned)
2216 constant = PrintInt64(*(int64 *)data);
2218 constant = PrintUInt64(*(uint64 *)data);
2220 case floatType: constant = PrintFloat(*(float *)data); break;
2221 case doubleType: constant = PrintDouble(*(double *)data); break;
2225 FreeExpContents(exp);
2226 exp.constant = constant;
2227 exp.type = constantExp;
2228 exp.isConstant = true;
2231 exp.type = unknownErrorExp;
2233 else if(!gotAddress)
2235 FreeExpContents(exp);
2236 exp.type = unknownErrorExp;
2238 else if((dataType.kind == classType && dataType._class &&
2239 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
2240 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
2242 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
2243 if(evalError != dummyExp)
2245 exp.type = evalError;
2246 exp.constant = PrintHexUInt64(address);
2250 //printf("evaluation = %s\n", evaluation);
2251 expNew = ParseExpressionString(evaluation);
2253 expNew.destType = exp.expType;
2255 exp.expType.refCount++;
2256 //FreeType(memberExp.destType);
2257 FreeType(exp.expType);
2258 FreeType(exp.destType);
2259 FreeExpContents(exp);
2260 ProcessExpressionType(expNew);
2261 DebugComputeExpression(expNew);
2264 expNew.isConstant = true;
2265 expNew.address = address;
2266 expNew.hasAddress = true;
2272 FreeExpContents(exp);
2273 exp.type = unknownErrorExp;
2278 // TESTING THIS HERE...
2279 exp.type = constantExp;
2280 exp.constant = PrintHexUInt64(address);
2282 exp.address = address;
2283 exp.hasAddress = true;
2284 exp.isConstant = true;
2289 // exp.type = ExpUnknownError;
2291 //FreeExpContents(exp);
2292 //exp.constant = PrintUInt64(value);
2293 //exp.type = constantExp;
2298 if(type && (type.kind == structType || type.kind == unionType))
2301 Type memberType = exp.member.member ? FindMemberAndOffset(type, exp.member.member.string, &offset) : null;
2304 char * evaluation = null;
2305 ExpressionType evalError = dummyExp;
2307 bool gotAddress = false;
2308 Expression prev = exp.prev, next = exp.next;
2310 int size = memberType.size;
2312 Type dataType = memberType;
2314 if(dataType.kind == classType && dataType._class.registered &&
2315 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
2316 dataType = dataType._class.registered.dataType;
2318 format = GetGdbFormatChar(dataType);
2320 if(memberExp.hasAddress)
2322 address = memberExp.address;
2325 else if(memberExp.type == constantExp)
2326 gotAddress = GetUInt64(memberExp, &address);
2332 FreeExpContents(exp);
2333 exp.type = unknownErrorExp;
2335 else if((dataType.kind == classType && dataType._class &&
2336 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
2337 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
2339 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
2340 if(evalError != dummyExp)
2342 exp.type = evalError;
2343 exp.constant = PrintHexUInt64(address);
2347 expNew = ParseExpressionString(evaluation);
2349 expNew.destType = exp.expType;
2351 exp.expType.refCount++;
2352 //FreeType(memberExp.destType);
2353 FreeType(exp.expType);
2354 FreeType(exp.destType);
2355 FreeExpContents(exp);
2356 ProcessExpressionType(expNew);
2357 DebugComputeExpression(expNew);
2360 expNew.isConstant = true;
2361 expNew.address = address;
2362 expNew.hasAddress = true;
2368 FreeExpContents(exp);
2369 exp.type = unknownErrorExp;
2374 FreeExpContents(exp);
2376 // TESTING THIS HERE...
2377 exp.type = constantExp;
2378 exp.constant = PrintHexUInt64(address);
2380 exp.address = address;
2381 exp.hasAddress = true;
2382 exp.isConstant = true;
2386 exp.type = memberSymbolErrorExp;
2389 exp.type = memberSymbolErrorExp;
2393 //if(exp.type != memberExp)
2395 //FreeExpression(memberExp);
2396 //FreeIdentifier(memberID);
2401 exp.type = memberSymbolErrorExp;
2407 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
2408 FreeExpContents(exp);
2409 exp.constant = PrintUInt(ComputeTypeSize(type));
2410 exp.type = constantExp;
2416 Symbol classSym = FindClass(exp._class.name);
2417 if(classSym && classSym.registered)
2419 //exp.constant = PrintUInt(classSym.registered.size);
2420 //exp.type = constantExp;
2422 char className[1024];
2423 sprintf(className, "__ecereClass_%s", classSym.string);
2424 FreeExpContents(exp);
2425 exp.type = pointerExp;
2426 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
2427 exp.member.member = MkIdentifier("size");
2433 DebugComputeExpression(exp.cast.exp);
2435 if(ExpressionIsError(exp.cast.exp)) //.type == ExpSymbolError
2436 CarryExpressionError(exp, exp.cast.exp);
2439 exp.hasAddress = exp.cast.exp.hasAddress;
2440 exp.address = exp.cast.exp.address;
2441 if(exp.cast.exp.type == instanceExp && exp.cast.exp.expType && exp.expType && exp.cast.exp.expType.kind == classType && exp.expType.kind == classType &&
2442 exp.cast.exp.expType._class && exp.expType._class && exp.cast.exp.expType._class.registered && exp.expType._class.registered &&
2443 exp.cast.exp.expType._class.registered == exp.expType._class.registered)
2445 Instantiation inst = exp.cast.exp.instance;
2446 exp.cast.exp.instance = null;
2447 FreeExpContents(exp);
2448 exp.instance = inst;
2449 exp.type = instanceExp;
2451 else if(exp.cast.exp.type == constantExp && exp.expType)
2453 Type type = exp.expType;
2454 if(type.kind == classType && type._class && type._class.registered)
2456 Class _class = type._class.registered;
2457 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
2459 if(!_class.dataType)
2460 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
2461 type = _class.dataType;
2463 else if(_class.type == structClass && !type.byReference)
2465 FreeExpContents(exp);
2466 exp.type = unknownErrorExp;
2477 if(GetChar(exp.cast.exp, &value))
2479 FreeExpContents(exp);
2480 exp.constant = PrintChar(value);
2481 exp.type = constantExp;
2482 exp.isConstant = true;
2487 unsigned char value = 0;
2488 if(GetUChar(exp.cast.exp, &value))
2490 FreeExpContents(exp);
2491 exp.constant = PrintUChar(value);
2492 exp.type = constantExp;
2493 exp.isConstant = true;
2501 if(GetShort(exp.cast.exp, &value))
2503 FreeExpContents(exp);
2504 exp.constant = PrintShort(value);
2505 exp.type = constantExp;
2506 exp.isConstant = true;
2511 unsigned short value = 0;
2512 if(GetUShort(exp.cast.exp, &value))
2514 FreeExpContents(exp);
2515 exp.constant = PrintUShort(value);
2516 exp.type = constantExp;
2517 exp.isConstant = true;
2525 if(GetInt(exp.cast.exp, &value))
2527 FreeExpContents(exp);
2528 exp.constant = PrintInt(value);
2529 exp.type = constantExp;
2530 exp.isConstant = true;
2535 unsigned int value = 0;
2536 if(GetUInt(exp.cast.exp, &value))
2538 FreeExpContents(exp);
2539 exp.constant = PrintUInt(value);
2540 exp.type = constantExp;
2541 exp.isConstant = true;
2549 if(GetInt64(exp.cast.exp, &value))
2551 FreeExpContents(exp);
2552 exp.constant = PrintInt64(value);
2553 exp.type = constantExp;
2554 exp.isConstant = true;
2560 if(GetUInt64(exp.cast.exp, &value))
2562 FreeExpContents(exp);
2563 exp.constant = PrintUInt64(value);
2564 exp.type = constantExp;
2565 exp.isConstant = true;
2573 if(GetUInt64(exp.cast.exp, &value))
2575 FreeExpContents(exp);
2576 if(type.kind == pointerType || type.kind == classType)
2577 exp.constant = PrintHexUInt64(value);
2579 exp.constant = PrintUInt64(value);
2580 exp.type = constantExp;
2581 exp.isConstant = true;
2588 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
2589 (!strcmpi(exp.cast.exp.constant, "nan") ||
2590 !strcmpi(exp.cast.exp.constant, "-nan") ||
2591 !strcmpi(exp.cast.exp.constant, "inf") ||
2592 !strcmpi(exp.cast.exp.constant, "-inf")))
2594 String constant = exp.cast.exp.constant;
2595 exp.cast.exp.constant = null;
2596 FreeExpContents(exp);
2597 exp.constant = constant;
2598 exp.type = constantExp;
2599 exp.isConstant = true;
2601 else if(GetFloat(exp.cast.exp, &value))
2603 FreeExpContents(exp);
2604 exp.constant = PrintFloat(value);
2605 exp.type = constantExp;
2606 exp.isConstant = true;
2613 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
2614 (!strcmpi(exp.cast.exp.constant, "nan") ||
2615 !strcmpi(exp.cast.exp.constant, "-nan") ||
2616 !strcmpi(exp.cast.exp.constant, "inf") ||
2617 !strcmpi(exp.cast.exp.constant, "-inf")))
2619 String constant = exp.cast.exp.constant;
2620 exp.cast.exp.constant = null;
2621 FreeExpContents(exp);
2622 exp.constant = constant;
2623 exp.type = constantExp;
2624 exp.isConstant = true;
2626 else if(GetDouble(exp.cast.exp, &value))
2628 FreeExpContents(exp);
2629 exp.constant = PrintDouble(value);
2630 exp.type = constantExp;
2631 exp.isConstant = true;
2644 DebugComputeExpression(exp.cond.cond);
2646 if(ExpressionIsError(exp.cond.cond))
2647 CarryExpressionError(exp, exp.cond.cond);
2648 else if(exp.cond.cond.type == constantExp && exp.cond.cond.constant)
2650 Expression e = null;
2651 if(strtol(exp.cond.cond.constant, null, 0))
2653 for(e = exp.cond.exp ? exp.cond.exp->first : null; e; e = e.next)
2655 DebugComputeExpression(e);
2660 if(ExpressionIsError(e))
2662 CarryExpressionError(exp, e);
2666 exp.cond.exp->Remove(e);
2671 e = exp.cond.elseExp;
2674 DebugComputeExpression(e);
2675 if(ExpressionIsError(e))
2677 CarryExpressionError(exp, e);
2681 exp.cond.elseExp = null;
2686 FreeType(exp.expType);
2687 FreeType(exp.destType);
2690 FreeExpContents(exp);
2694 else if(!ExpressionIsError(exp))
2696 FreeExpContents(exp);
2697 exp.type = unknownErrorExp;
2702 FreeExpContents(exp);
2703 exp.type = unknownErrorExp;
2708 FreeExpContents(exp);
2709 exp.type = unknownErrorExp;
2716 void ApplyUnitConverters(Expression exp)
2718 Property convert = null;
2719 Type type = exp.expType;
2720 bool useGet = false;
2721 if(type.kind == classType && type._class && type._class.registered)
2723 Class _class = type._class.registered;
2724 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
2726 if(_class.type == unitClass && _class.base.type == unitClass)
2729 for(p = _class.conversions.first; p; p = p.next)
2731 if(!strcmp(p.name, _class.base.fullName))
2738 Class c = eSystem_FindClass(_class.module, p.name);
2742 for(p2 = c.conversions.first; p2; p2 = p2.next)
2744 if(!strcmp(p2.name, _class.base.fullName))
2757 if(!_class.dataType)
2758 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
2759 type = _class.dataType;
2770 if(GetChar(exp, &value))
2772 FreeExpContents(exp);
2773 exp.constant = PrintChar(value);
2774 exp.type = constantExp;
2775 exp.isConstant = true;
2780 unsigned char value = 0;
2781 if(GetUChar(exp, &value))
2783 FreeExpContents(exp);
2784 exp.constant = PrintUChar(value);
2785 exp.type = constantExp;
2786 exp.isConstant = true;
2794 if(GetShort(exp, &value))
2796 FreeExpContents(exp);
2797 exp.constant = PrintShort(value);
2798 exp.type = constantExp;
2799 exp.isConstant = true;
2804 unsigned short value = 0;
2805 if(GetUShort(exp, &value))
2807 FreeExpContents(exp);
2808 exp.constant = PrintUShort(value);
2809 exp.type = constantExp;
2810 exp.isConstant = true;
2818 if(GetInt(exp, &value))
2820 FreeExpContents(exp);
2821 exp.constant = PrintInt(value);
2822 exp.type = constantExp;
2823 exp.isConstant = true;
2828 unsigned int value = 0;
2829 if(GetUInt(exp, &value))
2831 FreeExpContents(exp);
2832 exp.constant = PrintUInt(value);
2833 exp.type = constantExp;
2834 exp.isConstant = true;
2842 if(GetInt64(exp, &value))
2844 FreeExpContents(exp);
2845 exp.constant = PrintInt64(value);
2846 exp.type = constantExp;
2847 exp.isConstant = true;
2853 if(GetUInt64(exp, &value))
2855 FreeExpContents(exp);
2856 exp.constant = PrintUInt64(value);
2857 exp.type = constantExp;
2858 exp.isConstant = true;
2866 if(GetUInt64(exp, &value))
2868 FreeExpContents(exp);
2869 if(type.kind == pointerType || type.kind == classType)
2870 exp.constant = PrintHexUInt64(value);
2872 exp.constant = PrintUInt64(value);
2873 exp.type = constantExp;
2874 exp.isConstant = true;
2881 if(exp.type == constantExp && exp.constant &&
2882 (!strcmpi(exp.constant, "nan") ||
2883 !strcmpi(exp.constant, "-nan") ||
2884 !strcmpi(exp.constant, "inf") ||
2885 !strcmpi(exp.constant, "-inf")))
2887 String constant = exp.constant;
2888 exp.constant = null;
2889 FreeExpContents(exp);
2890 exp.constant = constant;
2891 exp.type = constantExp;
2892 exp.isConstant = true;
2894 else if(GetFloat(exp, &value))
2898 float (*convertFn)(float) = (useGet ? (void *)convert.Get : (void *)convert.Set);
2900 value = convertFn(value);
2902 FreeExpContents(exp);
2903 exp.constant = PrintFloat(value);
2904 exp.type = constantExp;
2905 exp.isConstant = true;
2912 if(exp.type == constantExp && exp.constant &&
2913 (!strcmpi(exp.constant, "nan") ||
2914 !strcmpi(exp.constant, "-nan") ||
2915 !strcmpi(exp.constant, "inf") ||
2916 !strcmpi(exp.constant, "-inf")))
2918 String constant = exp.constant;
2919 exp.constant = null;
2920 FreeExpContents(exp);
2921 exp.constant = constant;
2922 exp.type = constantExp;
2923 exp.isConstant = true;
2925 else if(GetDouble(exp, &value))
2929 double (*convertFn)(double) = (useGet ? (void *)convert.Get : (void *)convert.Set);
2931 value = convertFn(value);
2933 FreeExpContents(exp);
2934 exp.constant = PrintDouble(value);
2935 exp.type = constantExp;
2936 exp.isConstant = true;