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;
161 bool isPointer = false;
163 if(dataType && dataType.kind == classType && dataType._class.registered)
165 Class _class = dataType._class.registered;
166 if(_class.type == bitClass || _class.type == unitClass || _class.type == enumClass)
169 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
170 dataType = _class.dataType;
172 else if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass) // Added systemClass here for Instance
177 else if(dataType && dataType.kind == classType && !dataType._class.registered)
180 kind = dataType.kind;
182 exp.type = symbolErrorExp;
186 case intPtrType: case intSizeType: case _BoolType:
187 case charType: case shortType: case intType: case int64Type: case longType: case floatType: case doubleType:
193 sprintf(temp, "&%s", exp.identifier.string);
196 if(exp.byReference && dataType._class && dataType._class.registered && dataType._class.registered.type == structClass)
197 // if(!dataType._class || !dataType._class.registered || dataType._class.registered.type != structClass || exp.byReference)
198 strcpy(temp, exp.identifier.string);
200 sprintf(temp, "&%s", exp.identifier.string);
206 // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
212 evaluation = Debugger::EvaluateExpression(temp, &evalError);
215 address = _strtoui64(evaluation, null, 0);
226 if(evalError == dummyExp)
232 evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
237 temp = strstr(evaluation, " '");
238 //len = strlen(temp);
242 for(c = 0; c < len; c++)
244 eString_TrimRSpaces(evaluation, evaluation);
260 evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
263 if(kind == pointerType)
266 value = _strtoui64(evaluation, null, 0);
268 evaluation = PrintHexUInt64(value);
278 //evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
279 size = ComputeTypeSize(exp.expType); //exp.expType.arrayType.size;
280 format = GetGdbFormatChar(exp.expType);
281 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
283 StripQuotes(evaluation, evaluation);
289 //evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
294 // for classType --> if(_class.type == structClass) ?
296 //sprintf(temp, "&%s", exp.identifier.string);
297 //evaluation = Debugger::EvaluateExpression(temp, &evalError);
303 // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
306 evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
315 // Going back to parsing the expression string so as to catch inf/-inf/nan/-nan etc.
316 expNew = ParseExpressionString(evaluation);
317 //expNew = MkExpConstant(evaluation);
318 //printf("Evaluation = %s\n", evaluation);
320 expNew.destType = exp.expType;
322 // WHY EXACTLY MUST WE PROCESS THIS EXPRESSION TYPE AGAIN ? ADDED THIS FOR 0x00000000
323 if(exp.expType && (exp.expType.kind == pointerType || exp.expType.kind == classType) && expNew.destType)
325 expNew.expType = expNew.destType;
326 expNew.destType.refCount++;
327 // For negative values parsed as opExp
328 if(expNew.type == opExp && expNew.op.op == '-' && !expNew.op.exp1 && expNew.op.exp2)
330 expNew.op.exp2.expType = expNew.destType;
331 expNew.destType.refCount++;
332 expNew.op.exp2.isConstant = true;
336 ProcessExpressionType(expNew);
337 FreeType(exp.destType);
338 FreeExpContents(exp);
340 DebugComputeExpression(expNew);
343 expNew.isConstant = true;
344 expNew.address = address;
345 expNew.hasAddress = hasAddress;
351 // Unhandled code path, evaluation is null
352 FreeExpContents(exp);
353 exp.type = unknownErrorExp;
357 // Keep the identifier
358 exp.type = evalError;
361 FreeExpContents(exp);
362 exp.type = evalError;
369 Instantiation inst = exp.instance;
371 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
372 Class _class = classSym ? classSym.registered : null;
373 DataMember curMember = null;
374 Class curClass = null;
375 DataMember subMemberStack[256];
376 int subMemberStackPos = 0;
379 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
381 // Don't recompute the instantiation...
382 // Non Simple classes will have become constants by now
386 if(_class.type == normalClass || _class.type == noHeadClass)
388 inst.data = (byte *)eInstance_New(_class);
389 if(_class.type == normalClass)
390 ((Instance)inst.data)._refCount++;
393 inst.data = new0 byte[_class.structSize];
398 for(members = inst.members->first; members; members = members.next)
402 case dataMembersInit:
404 if(members.dataMembers)
407 for(member = members.dataMembers->first; member; member = member.next)
409 Identifier ident = member.identifiers ? member.identifiers->first : null;
412 Property prop = null;
413 DataMember dataMember = null;
414 Method method = null;
415 uint dataMemberOffset;
419 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
422 if(curMember.isProperty)
424 prop = (Property)curMember; // TOFIX: (eC II ? THe mss
428 dataMember = curMember;
431 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, GetPrivateModule(), null, null);
433 // 2013/17/29 -- It seems that this was missing here!
434 if(_class.type == normalClass)
435 dataMemberOffset += _class.base.structSize;
436 // dataMemberOffset = dataMember.offset;
443 prop = eClass_FindProperty(_class, ident.string, GetPrivateModule());
447 if(prop.memberAccess == publicAccess)
449 curMember = (DataMember)prop;
450 curClass = prop._class;
455 DataMember _subMemberStack[256];
456 int _subMemberStackPos = 0;
459 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, GetPrivateModule(), _subMemberStack, &_subMemberStackPos);
464 if(dataMember.memberAccess == publicAccess)
466 curMember = dataMember;
467 curClass = dataMember._class;
468 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
469 subMemberStackPos = _subMemberStackPos;
475 if(found && member.initializer && member.initializer.type == expInitializer)
477 Expression value = member.initializer.exp;
479 bool deepMember = false;
482 type = prop.dataType;
486 if(!dataMember.dataType)
487 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
489 type = dataMember.dataType;
492 if(ident && ident.next)
496 // for(; ident && type; ident = ident.next)
497 for(ident = ident.next; ident && type; ident = ident.next)
499 if(type.kind == classType)
501 prop = eClass_FindProperty(type._class.registered,
502 ident.string, GetPrivateModule());
504 type = prop.dataType;
507 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
508 ident.string, &dataMemberOffset, GetPrivateModule(), null, null);
510 type = dataMember.dataType;
513 else if(type.kind == structType || type.kind == unionType)
516 for(memberType = type.members.first; memberType; memberType = memberType.next)
518 if(!strcmp(memberType.name, ident.string))
529 FreeType(value.destType);
530 value.destType = type;
531 if(type) type.refCount++;
532 DebugComputeExpression(value);
534 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
536 if(type.kind == classType)
538 Class _class = type._class.registered;
539 if(_class.type == bitClass || _class.type == unitClass ||
540 _class.type == enumClass)
543 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
544 type = _class.dataType;
550 void * ptr = inst.data + dataMemberOffset;
552 if(value.type == constantExp)
558 GetInt(value, (int*)ptr);
563 GetInt64(value, (int64*)ptr);
568 GetIntPtr(value, (intptr*)ptr);
573 GetIntSize(value, (intsize*)ptr);
578 GetFloat(value, (float*)ptr);
583 GetDouble(value, (double *)ptr);
588 else if(value.type == instanceExp)
590 if(type.kind == classType)
592 Class _class = type._class.registered;
593 if(_class.type == structClass)
595 ComputeTypeSize(type);
596 if(value.instance.data)
597 memcpy(ptr, value.instance.data, type.size);
604 if(value.type == instanceExp && value.instance.data)
606 if(type.kind == classType)
608 Class _class = type._class.registered;
609 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
611 void (*Set)(void *, void *) = (void *)prop.Set;
612 Set(inst.data, value.instance.data);
613 PopulateInstance(inst);
617 else if(value.type == constantExp)
623 void (*Set)(void *, double) = (void *)prop.Set;
624 Set(inst.data, strtod(value.constant, null) );
629 void (*Set)(void *, float) = (void *)prop.Set;
630 Set(inst.data, (float)(strtod(value.constant, null)));
635 void (*Set)(void *, int) = (void *)prop.Set;
636 Set(inst.data, (int)strtol(value.constant, null, 0));
641 void (*Set)(void *, int64) = (void *)prop.Set;
642 Set(inst.data, _strtoi64(value.constant, null, 0));
647 void (*Set)(void *, intptr) = (void *)prop.Set;
648 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
653 void (*Set)(void *, intsize) = (void *)prop.Set;
654 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
659 else if(value.type == stringExp)
662 ReadString(temp, value.string);
663 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
667 else if(!deepMember && type && _class.type == unitClass)
671 // Only support converting units to units for now...
672 if(value.type == constantExp)
674 if(type.kind == classType)
676 Class _class = type._class.registered;
677 if(_class.type == unitClass)
680 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
681 type = _class.dataType;
684 // TODO: Assuming same base type for units...
690 float (*Set)(float) = (void *)prop.Set;
691 GetFloat(member.initializer.exp, &fValue);
692 exp.constant = PrintFloat(Set(fValue));
693 exp.type = constantExp;
699 double (*Set)(double) = (void *)prop.Set;
700 GetDouble(member.initializer.exp, &dValue);
701 exp.constant = PrintDouble(Set(dValue));
702 exp.type = constantExp;
709 else if(!deepMember && type && _class.type == bitClass)
713 if(value.type == instanceExp && value.instance.data)
715 unsigned int (*Set)(void *) = (void *)prop.Set;
716 bits = Set(value.instance.data);
718 else if(value.type == constantExp)
724 BitMember bitMember = (BitMember) dataMember;
727 GetInt(value, &part);
728 bits = (bits & ~bitMember.mask);
729 if(!bitMember.dataType)
730 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
732 type = bitMember.dataType;
734 if(type.kind == classType && type._class && type._class.registered)
736 if(!type._class.registered.dataType)
737 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
738 type = type._class.registered.dataType;
746 bits |= ((char)part << bitMember.pos);
748 bits |= ((unsigned char)part << bitMember.pos);
752 bits |= ((short)part << bitMember.pos);
754 bits |= ((unsigned short)part << bitMember.pos);
759 bits |= ((int)part << bitMember.pos);
761 bits |= ((unsigned int)part << bitMember.pos);
765 bits |= ((int64)part << bitMember.pos);
767 bits |= ((uint64)part << bitMember.pos);
772 bits |= ((intptr)part << bitMember.pos);
776 bits |= ((uintptr)part << bitMember.pos);
782 bits |= ((ssize_t)(intsize)part << bitMember.pos);
786 bits |= ((size_t) (uintsize)part << bitMember.pos);
795 if(_class && _class.type == unitClass)
797 DebugComputeExpression(member.initializer.exp);
798 exp.constant = member.initializer.exp.constant;
799 exp.type = constantExp;
801 member.initializer.exp.constant = null;
811 if(_class && _class.type == bitClass)
813 exp.constant = PrintHexUInt(bits);
814 exp.type = constantExp;
816 if(exp.type != instanceExp)
828 Expression expError = null;
829 Expression exp1, exp2 = null;
830 Operand op1 = { 0 }, op2 = { 0 };
833 if(exp.op.op == '&' || exp.op.op == '*')
835 if(!exp.op.exp1 && exp.op.exp2)
837 if(exp.op.exp2.type == identifierExp)
839 Expression prev = exp.prev, next = exp.next;
840 char * evaluation = null;
841 ExpressionType evalError = dummyExp;
844 sprintf(temp, "%c%s", exp.op.op, exp.op.exp2.identifier.string);
845 evaluation = Debugger::EvaluateExpression(temp, &evalError);
846 if(evalError != dummyExp)
848 exp.type = evalError;
849 exp.constant = CopyString("");
853 expNew = ParseExpressionString(evaluation);
855 expNew.destType = exp.expType;
856 FreeType(exp.destType);
857 FreeExpContents(exp);
858 ProcessExpressionType(expNew);
859 DebugComputeExpression(expNew);
862 expNew.isConstant = true;
867 exp.type = ExpUnknownError;
877 DebugComputeExpression(exp.op.exp2);
878 size = ComputeTypeSize(exp.op.exp2.expType);
879 format = GetGdbFormatChar(exp.op.exp2.expType);
880 GetInt(exp.op.exp2, &address);
881 //sprintf(temp, "%c%s", exp.op.op, exp.op.exp2.constant);
882 evaluation = Debug_ReadMemory(address, size, format, &evalError);
885 evalError = ExpUnknownError;
891 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
894 Expression e = exp.op.exp2;
896 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
898 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
900 if(e.type == extensionCompoundExp)
901 e = ((Statement)e.compound.compound.statements->last).expressions->last;
906 if(exp.op.op == TokenType::sizeOf && e && e.expType)
908 if(e.type == stringExp && e.string)
910 char * string = e.string;
911 int len = strlen(string);
912 char * tmp = new char[len-2+1];
913 len = UnescapeString(tmp, string + 1, len - 2);
915 FreeExpContents(exp);
916 exp.type = constantExp;
917 exp.constant = PrintUInt(len + 1);
921 Type type = e.expType;
923 FreeExpContents(exp);
924 exp.type = constantExp;
925 exp.constant = PrintUInt(ComputeTypeSize(type));
932 DebugComputeExpression(exp.op.exp2);
933 if(ExpressionIsError(exp.op.exp2))
934 expError = exp.op.exp2;
941 DebugComputeExpression(exp.op.exp1);
942 if(ExpressionIsError(exp.op.exp1))
943 expError = exp.op.exp1;
948 if(ExpressionIsError(exp.op.exp2))
949 expError = exp.op.exp2;
954 op1 = GetOperand(exp1);
955 if(op1.type) op1.type.refCount++;
956 op2 = GetOperand(exp2);
957 if(op2.type) op2.type.refCount++;
964 if(ExpressionIsError(exp.op.exp2))
965 expError = exp.op.exp2;
969 if(exp.op.op == '&' || exp.op.op == '*')
971 Expression prev = exp1.prev, next = exp1.next;
973 ExpressionType evalError = dummyExp;
974 char * evaluation = null;
980 //sprintf(temp, "%u", exp1.address);
981 temp = PrintHexUInt64(exp1.address);
982 expNew = ParseExpressionString(temp);
984 //expNew.address = exp1.address;
985 expNew.expType = exp.expType;
987 expNew.destType = exp.expType;
988 expNew.destType.refCount++;
990 FreeType(exp.destType);
991 FreeExpContents(exp);
992 ProcessExpressionType(expNew);
993 DebugComputeExpression(expNew);
996 expNew.isConstant = true;
1003 else if(exp.op.op == '*')
1005 // TODO: Common pathway for * and [ ]
1009 FreeExpContents(exp1);
1010 exp1.type = dereferenceErrorExp;
1018 Expression e = exp1;
1020 bool gotAddress = false;
1022 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
1024 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
1026 if(e.type == extensionCompoundExp)
1027 e = ((Statement)e.compound.compound.statements->last).expressions->last;
1031 else if(e.type == castExp)
1035 if(e.expType.kind == structType)
1037 address = exp1.address;
1041 gotAddress = GetUInt64(e, &address);
1042 size = ComputeTypeSize(exp.expType); //exp.expType.arrayType.size;
1043 if(exp.expType && exp.expType.type && exp.expType.kind == arrayType)
1044 // For multilevels arrays
1047 format = GetGdbFormatChar(exp.expType);
1048 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
1050 Expression e1 = e.op.exp1, e2 = e.op.exp2;
1051 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1053 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1055 if(e1.type == extensionCompoundExp)
1056 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1060 else if(e1.type == castExp)
1063 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1065 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1067 if(e2.type == extensionCompoundExp)
1068 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1072 else if(e2.type == castExp)
1076 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1078 offset += strtol(e.op.exp2.constant, null, 0);
1081 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1083 offset += strtol(e.op.exp1.constant, null, 0);
1090 if(e.type == stringExp)
1093 String string = e.string;
1095 Type expType = exp1.expType.type;
1096 if(expType) expType.refCount++;
1100 int len = string ? strlen(string) : 0;
1101 tmp = new char[len-2+1];
1102 len = UnescapeString(tmp, string + 1, len - 2);
1103 if(len >= 0 && offset * size + size-1 <= len)
1107 FreeExpContents(exp);
1109 exp.type = dereferenceErrorExp;
1112 exp.type = constantExp;
1113 exp.isConstant = true;
1114 switch(expType.kind)
1116 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1117 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1118 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1119 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1120 case floatType: exp.constant = PrintFloat(((float *)tmp)[offset]); break;
1121 case doubleType: exp.constant = PrintDouble(((double *)tmp)[offset]); break;
1123 exp.type = unknownErrorExp;
1127 exp.type = unknownErrorExp;
1131 else if(gotAddress && exp.expType.kind == arrayType)
1133 FreeExpContents(exp);
1134 exp.type = constantExp;
1135 exp.isConstant = true;
1136 exp.constant = PrintHexUInt64(address);
1137 exp.address = address;
1138 exp.hasAddress = true;
1140 else if(gotAddress && format)
1142 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1148 expNew = ParseExpressionString(evaluation);
1149 expNew.address = address;
1150 expNew.hasAddress = true;
1152 expNew.destType = exp.expType;
1153 FreeType(exp.destType);
1154 FreeExpContents(exp);
1155 ProcessExpressionType(expNew);
1156 DebugComputeExpression(expNew);
1159 expNew.isConstant = true;
1165 // Unhandled code path, evaluation is null
1166 FreeExpContents(exp);
1167 exp.type = unknownErrorExp;
1170 case memoryErrorExp:
1172 FreeExpContents(exp1);
1173 exp1.type = evalError;
1174 exp1.constant = PrintHexUInt64(address);
1179 FreeExpContents(exp1);
1180 exp1.type = evalError;
1187 FreeExpContents(exp1);
1188 exp1.type = unknownErrorExp; // Not supported yet, generate error to fallback to GDB printout
1195 op1 = GetOperand(exp1);
1196 if(op1.type) op1.type.refCount++;
1201 CarryExpressionError(exp, expError);
1202 else if(exp.type == opExp)
1204 if(exp1 && exp2 && exp1.expType && exp2.expType &&
1205 ((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) ||
1206 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
1209 if((exp.op.op == '+' || exp.op.op == '-') && (op2.type || op1.type))
1211 Expression e1 = exp1, e2 = exp2;
1212 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1214 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1216 if(e1.type == extensionCompoundExp)
1217 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1221 else if(e1.type == castExp)
1224 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1226 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1228 if(e2.type == extensionCompoundExp)
1229 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1233 else if(e2.type == castExp)
1237 if((e1.type == stringExp && op2.type && op2.type.kind == intType) || (e2.type == stringExp && op1.type && op1.type.kind == intType))
1239 uint64 offset = ((exp.op.op == '+') ? 1 : -1) * (e1.type == stringExp ? op2.i64 : op1.i64);
1240 String newString = null;
1241 Expression e = e1.type == stringExp ? e1 : e2;
1244 int len = strlen(e.string) - 2;
1245 char * tmp = OffsetEscapedString(e.string + 1, len, (int)offset);
1248 len -= tmp - (e.string + 1);
1249 newString = new char[2 + len + 1];
1250 newString[0] = '\"';
1251 memcpy(newString + 1, tmp, len);
1252 newString[1 + len] = '\"';
1253 newString[1 + len + 1] = 0;
1257 FreeExpContents(exp);
1260 exp.type = stringExp;
1261 exp.string = newString;
1264 exp.type = dereferenceErrorExp;
1266 // Can't add 2 pointers...
1267 else if(exp.op.op != '+' ||
1268 !((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) &&
1269 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
1271 bool op1IsPointer = exp1.expType.kind == pointerType || exp1.expType.kind == arrayType;
1272 bool op2IsPointer = exp2.expType.kind == pointerType || exp2.expType.kind == arrayType;
1273 bool addressResult = !op1IsPointer || !op2IsPointer;
1278 size = ComputeTypeSize(exp1.expType.type);
1279 else if(op2IsPointer)
1280 size = ComputeTypeSize(exp2.expType.type);
1282 if(addressResult && size)
1284 if(op1IsPointer) op2.ui64 *= size;
1285 else if(op1IsPointer) op1.ui64 *= size;
1288 CallOperator(exp, exp1, exp2, op1, op2);
1289 if(exp.type == constantExp)
1293 exp.address = _strtoui64(exp.constant, null, 0);
1294 delete exp.constant;
1295 exp.constant = PrintHexUInt64(exp.address);
1296 if(op1.type.kind == arrayType || op2.type.kind == arrayType)
1297 exp.hasAddress = true;
1301 int64 v = _strtoi64(exp.constant, null, 0);
1303 delete exp.constant;
1304 exp.constant = PrintInt(v);
1311 FreeExpContents(exp);
1312 exp.type = unknownErrorExp; // We should have an invalid operands error
1317 if(!exp2 && exp1 && exp1.type == constantExp && exp1.constant && !strcmp(exp1.constant, "nan") && exp.op.op == '-')
1319 FreeExpContents(exp);
1320 exp.constant = CopyString("-nan");
1321 exp.type = constantExp;
1325 if((exp.op.op == '/' || exp.op.op == '%') && op2.kind != doubleType && op1.kind != doubleType && op2.kind != floatType && op1.kind != floatType &&
1326 (((op2.kind == int64Type || op2.kind == intPtrType || op2.kind == intSizeType) && !op2.i64) ||
1327 (op2.kind == intType && !op2.i) || (op2.kind == shortType && !op2.s) || (op2.kind == charType && !op2.c)))
1329 FreeExpContents(exp);
1330 exp.type = divideBy0ErrorExp;
1333 CallOperator(exp, exp1, exp2, op1, op2);
1338 if(exp.type == constantExp)
1339 exp.isConstant = true;
1347 // e = (*exp.list).first, n = e ? e.next : null;
1349 // e = n, n = n?(n.next) : null)
1351 for(e = exp.list->first; e; e = n)
1356 OldList * list = exp.list;
1357 DebugComputeExpression(e);
1358 //if(ExpressionIsError(e)) //.type == ExpSymbolError
1359 // CarryExpressionError(exp, e);
1360 //FreeExpContents(exp);
1361 FreeType(exp.expType);
1362 FreeType(exp.destType);
1379 exp.isConstant = true;
1381 DebugComputeExpression(exp.index.exp);
1382 if(ExpressionIsError(exp.index.exp)) //.type == ExpSymbolError
1383 CarryExpressionError(exp, exp.index.exp);
1386 Expression prev = exp.prev, next = exp.next;
1387 char * evaluation = null;
1388 ExpressionType evalError = dummyExp;
1390 if(!exp.index.exp.isConstant)
1391 exp.isConstant = false;
1394 // 4 == size = ComputeTypeSize(exp.expType);
1395 // 0 == size = ComputeTypeSize(exp.expType.arrayType);
1396 // 4 == size = ComputeTypeSize(exp.index.exp.expType);
1397 // 0 == size = ComputeTypeSize(exp.index.exp.expType.arrayType);
1399 size = ComputeTypeSize(exp.expType);
1400 if(exp.expType && exp.expType.type && exp.expType.kind == arrayType)
1401 // For multilevels arrays
1404 format = GetGdbFormatChar(exp.expType);
1406 for(e = exp.index.index->first; e; e = e.next)
1408 DebugComputeExpression(e);
1409 if(ExpressionIsError(e)) //.type == ExpSymbolError
1411 CarryExpressionError(exp, e);
1416 // Check if this type is int
1419 exp.isConstant = false;
1421 if(!ExpressionIsError(exp))
1423 // Is this necessary here? pass15 had done this already...
1424 if(exp.expType) FreeType(exp.expType);
1425 exp.expType = Dereference(exp.index.exp.expType);
1430 FreeExpContents(exp);
1431 exp.type = dereferenceErrorExp;
1433 else if(exp.index.index && exp.index.index->last && ((Expression)exp.index.index->last) && ((Expression)exp.index.index->last).expType)
1435 Type type = ((Expression)exp.index.index->last).expType;
1436 if(type.kind == intType || type.kind == charType || type.kind == shortType || type.kind == int64Type || type.kind == intPtrType ||
1437 type.kind == intSizeType || type.kind == longType || type.kind == _BoolType || type.kind == enumType ||
1438 (type.kind == classType && type._class && type._class.registered &&
1439 type._class.registered.type == enumClass))
1441 bool gotAddress = false;
1442 uint64 address = 0, offset = 0;
1443 Expression expNew, last = (Expression)exp.index.index->last;
1444 Expression e = exp.index.exp;
1446 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
1448 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
1450 if(e.type == extensionCompoundExp)
1451 e = ((Statement)e.compound.compound.statements->last).expressions->last;
1455 else if(e.type == castExp)
1459 //GetUInt(exp.index.exp, &address);
1461 GetUInt64(last, &offset);
1463 // TOFIX: Check if it has address: TESTING
1464 if(exp.index.exp.hasAddress && exp.index.exp.expType.kind == arrayType)
1466 address = exp.index.exp.address;
1469 else if(exp.index.exp.type == constantExp)
1470 gotAddress = GetUInt64(exp.index.exp, &address);
1472 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
1474 Expression e1 = e.op.exp1, e2 = e.op.exp2;
1475 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1477 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1479 if(e1.type == extensionCompoundExp)
1480 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1484 else if(e1.type == castExp)
1487 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1489 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1491 if(e2.type == extensionCompoundExp)
1492 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1496 else if(e2.type == castExp)
1500 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1502 offset += strtol(e.op.exp2.constant, null, 0);
1505 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1507 offset += strtol(e.op.exp1.constant, null, 0);
1514 //size = ComputeTypeSize(exp.expType.arrayType); //exp.expType.arrayType.size;
1515 address += offset * size;
1517 if(e.type == stringExp)
1520 String string = e.string;
1522 Type expType = exp.index.exp.expType.type;
1523 if(expType) expType.refCount++;
1527 int len = string ? strlen(string) : 0;
1528 tmp = new char[len-2+1];
1529 len = UnescapeString(tmp, string + 1, len - 2);
1530 if(len >= 0 && offset * size + size-1 <= len)
1534 FreeExpContents(exp);
1536 exp.type = dereferenceErrorExp;
1539 exp.type = constantExp;
1540 exp.isConstant = true;
1541 switch(expType.kind)
1543 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1544 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1545 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1546 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1547 case floatType: exp.constant = PrintFloat(((float *)tmp)[offset]); break;
1548 case doubleType: exp.constant = PrintDouble(((double *)tmp)[offset]); break;
1550 exp.type = unknownErrorExp;
1554 exp.type = unknownErrorExp;
1558 else if(gotAddress && exp.expType.kind == arrayType)
1560 FreeExpContents(exp);
1561 exp.type = constantExp;
1562 exp.isConstant = true;
1563 exp.constant = PrintHexUInt64(address);
1564 exp.address = address;
1565 exp.hasAddress = true;
1569 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1575 expNew = ParseExpressionString(evaluation);
1577 expNew.destType = exp.expType;
1578 FreeType(exp.destType);
1579 FreeExpContents(exp);
1580 ProcessExpressionType(expNew);
1581 DebugComputeExpression(expNew);
1583 // TOFIX: Only for Array Types
1584 expNew.address = address;
1586 expNew.hasAddress = true;
1589 expNew.isConstant = true;
1595 // Unhandled code path, evaluation is null
1596 FreeExpContents(exp);
1597 exp.type = unknownErrorExp;
1600 case memoryErrorExp:
1602 FreeExpContents(exp);
1603 exp.type = evalError;
1604 exp.constant = PrintHexUInt64(address);
1608 FreeExpContents(exp);
1609 exp.type = evalError;
1615 FreeExpContents(exp);
1616 exp.type = unknownErrorExp;
1626 Expression callExp = exp.call.exp;
1627 Identifier id = (callExp && callExp.type == identifierExp) ? callExp.identifier : null;
1628 bool resolved = false;
1631 if(!strcmp(id.string, "nan") || !strcmp(id.string, "inf"))
1633 String s = id.string;
1635 FreeExpContents(exp);
1636 exp.type = constantExp;
1640 else if(exp.call.arguments)
1642 if(exp.call.arguments->count == 1)
1644 double (* fn1)(double) = (void *)oneArgFns[id.string];
1647 Expression arg = exp.call.arguments->first;
1648 DebugComputeExpression(arg);
1649 if(ExpressionIsError(arg))
1650 CarryExpressionError(exp, arg);
1651 else if(arg.isConstant && arg.type == constantExp)
1654 if(GetDouble(arg, &v))
1656 FreeExpContents(exp);
1657 exp.type = constantExp;
1659 exp.constant = PrintDouble(v);
1660 exp.isConstant = true;
1666 else if(exp.call.arguments->count == 2)
1668 double (* fn2)(double, double) = (void *)twoArgFns[id.string];
1671 Expression arg1 = exp.call.arguments->first;
1672 Expression arg2 = exp.call.arguments->last;
1673 DebugComputeExpression(arg1);
1674 DebugComputeExpression(arg2);
1675 if(ExpressionIsError(arg1))
1676 CarryExpressionError(exp, arg1);
1677 else if(ExpressionIsError(arg2))
1678 CarryExpressionError(exp, arg2);
1679 else if(arg1.isConstant && arg1.type == constantExp && arg2.isConstant && arg2.type == constantExp)
1682 if(GetDouble(arg1, &v1) && GetDouble(arg2, &v2))
1684 FreeExpContents(exp);
1685 exp.type = constantExp;
1687 exp.constant = PrintDouble(v1);
1688 exp.isConstant = true;
1697 exp.type = functionCallErrorExp;
1702 Expression memberExp = exp.member.exp;
1703 Identifier memberID = exp.member.member;
1705 Property prop = null;
1706 DataMember member = null;
1707 Class convertTo = null;
1708 uint offset = 0; // THIS WASN'T INITIALIZED... IS IT ALWAYS SET?
1710 Type type; // = memberExp.expType;
1711 DebugComputeExpression(memberExp);
1712 type = memberExp.expType;
1713 if(ExpressionIsError(memberExp))
1714 CarryExpressionError(exp, memberExp);
1717 // _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
1718 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);
1721 char string[256] = "";
1723 PrintTypeNoConst(type, string, false, true);
1724 classSym = FindClass(string);
1725 _class = classSym ? classSym.registered : null;
1728 if(memberID && _class)
1731 prop = eClass_FindProperty(_class, memberID.string);
1733 member = eClass_FindDataMember(_class, memberID.string);
1735 // member = eClass_FindDataMember(_class, memberID.string);
1736 member = eClass_FindDataMemberAndOffset(_class, memberID.string, &offset, _class.module.application, null, null);
1738 prop = eClass_FindProperty(_class, memberID.string, _class.module.application);
1740 if(!prop && !member && _class && memberID)
1742 Symbol classSym = FindClass(memberID.string);
1744 _class = classSym ? classSym.registered : null;
1746 prop = eClass_FindProperty(_class, convertTo.fullName, _class.module.application);
1749 //DebugComputeExpression(memberExp);
1750 if(ExpressionIsError(memberExp))
1751 CarryExpressionError(exp, memberExp);
1754 if(exp.member.memberType == methodMember)
1756 FreeExpContents(exp);
1757 exp.type = unknownErrorExp;
1761 bool supported = false;
1764 Type type = prop.dataType;
1765 // TODO: Assuming same base type for units...
1766 if(_class.type == unitClass)
1768 if(type.kind == classType)
1770 Class _class = type._class.registered;
1771 if(_class.type == unitClass)
1773 if(!_class.dataType)
1774 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
1775 type = _class.dataType;
1783 float (*Get)(float) = (void *) (convertTo ? prop.Set : prop.Get);
1784 GetFloat(memberExp, &value);
1786 FreeExpContents(exp);
1787 exp.constant = PrintFloat(Get ? Get(value) : value);
1788 exp.type = constantExp;
1789 exp.isConstant = true;
1796 double (*Get)(double) = (void *) (convertTo ? prop.Set : prop.Get);
1797 GetDouble(memberExp, &value);
1799 FreeExpContents(exp);
1800 exp.constant = PrintDouble(Get ? Get(value) : value);
1801 exp.isConstant = true;
1802 exp.type = constantExp;
1812 Expression value = memberExp;
1813 Type type = prop.dataType;
1814 exp.member.exp = null;
1816 if(_class.type == structClass)
1822 Class propertyClass = type._class.registered;
1823 if(propertyClass.type == structClass && value.type == instanceExp)
1825 void (*Set)(void *, void *) = (void *)prop.Set;
1826 FreeExpContents(exp);
1827 exp.instance = Instantiation
1829 data = new0 byte[_class.structSize];
1830 _class = MkSpecifierName(_class.name);
1833 exp.type = instanceExp;
1835 Set(exp.instance.data, value.instance.data);
1836 PopulateInstance(exp.instance);
1844 void (*Set)(void *, int) = (void *)prop.Set;
1846 GetInt(value, &intValue);
1847 FreeExpContents(exp);
1848 exp.instance = Instantiation
1850 data = new0 byte[_class.structSize];
1851 _class = MkSpecifierName/*MkClassName*/(_class.name);
1854 exp.type = instanceExp;
1856 Set(exp.instance.data, intValue);
1857 PopulateInstance(exp.instance);
1864 void (*Set)(void *, int64) = (void *)prop.Set;
1866 GetInt64(value, &intValue);
1867 FreeExpContents(exp);
1868 exp.instance = Instantiation
1870 data = new0 byte[_class.structSize];
1871 _class = MkSpecifierName/*MkClassName*/(_class.name);
1874 exp.type = instanceExp;
1876 Set(exp.instance.data, intValue);
1877 PopulateInstance(exp.instance);
1884 void (*Set)(void *, float) = (void *)prop.Set;
1886 GetFloat(value, &floatValue);
1887 FreeExpContents(exp);
1888 exp.instance = Instantiation
1890 data = new0 byte[_class.structSize];
1891 _class = MkSpecifierName/*MkClassName*/(_class.name);
1894 exp.type = instanceExp;
1896 Set(exp.instance.data, floatValue);
1897 PopulateInstance(exp.instance);
1904 void (*Set)(void *, double) = (void *)prop.Set;
1906 GetDouble(value, &doubleValue);
1907 FreeExpContents(exp);
1908 exp.instance = Instantiation
1910 data = new0 byte[_class.structSize];
1911 _class = MkSpecifierName/*MkClassName*/(_class.name);
1914 exp.type = instanceExp;
1916 Set(exp.instance.data, doubleValue);
1917 PopulateInstance(exp.instance);
1923 else if(_class.type == bitClass)
1929 Class propertyClass = type._class.registered;
1930 if(propertyClass.type == structClass && value.instance.data)
1932 unsigned int (*Set)(void *) = (void *)prop.Set;
1933 unsigned int bits = Set(value.instance.data);
1934 FreeExpContents(exp);
1935 exp.constant = PrintHexUInt(bits);
1936 exp.type = constantExp;
1940 else if(_class.type == bitClass)
1943 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
1946 GetUInt(memberExp, &value);
1948 FreeExpContents(exp);
1949 exp.constant = PrintHexUInt(bits);
1950 exp.type = constantExp;
1956 FreeExpression(value);
1960 if(_class.type == bitClass)
1963 GetUInt(memberExp, &value);
1969 Class _class = type._class.registered;
1970 if(_class.type == structClass)
1972 void (*Get)(unsigned int, void *) = (void *)prop.Get;
1974 FreeExpContents(exp);
1975 exp.instance = Instantiation
1977 data = new0 byte[_class.structSize];
1978 _class = MkSpecifierName/*MkClassName*/(_class.name);
1981 //exp.instance.fullSet = true;
1982 exp.type = instanceExp;
1983 Get(value, exp.instance.data);
1984 PopulateInstance(exp.instance);
1987 else if(_class.type == bitClass)
1989 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
1990 uint64 bits = Get(value);
1991 exp.constant = PrintHexUInt64(bits);
1992 exp.type = constantExp;
1999 else if(_class.type == structClass)
2001 char * value = (memberExp.type == instanceExp ) ? memberExp.instance.data : null;
2003 memberExp.instance.data = null;
2009 Class _class = type._class.registered;
2010 if(_class.type == structClass && value)
2012 void (*Get)(void *, void *) = (void *)prop.Get;
2014 FreeExpContents(exp);
2015 exp.instance = Instantiation
2017 data = new0 byte[_class.structSize];
2018 _class = MkSpecifierName/*MkClassName*/(_class.name);
2021 //exp.instance.fullSet = true;
2022 exp.type = instanceExp;
2023 Get(value, exp.instance.data);
2024 PopulateInstance(exp.instance);
2035 char * value = memberExp.instance.data;
2040 Class _class = type._class.registered;
2041 if(_class.type == normalClass)
2043 void *(*Get)(void *) = (void *)prop.Get;
2045 FreeExpContents(exp);
2046 exp.instance = Instantiation
2048 data = Get(value, exp.instance.data); ?????
2049 _class = MkSpecifierName(_class.name); //MkClassName(_class.name);
2052 exp.type = instanceExp;
2064 exp.type = memberPropertyErrorExp;
2065 exp.isConstant = false;
2070 if(memberExp.hasAddress || memberExp.type == constantExp || (memberExp.type == instanceExp && memberExp.instance && memberExp.instance.data))
2071 //if(memberExp.expType && memberExp.expType.kind == intType) // && !exp.index.exp.expType.isSigned
2073 if(_class.type == bitClass)
2075 if(memberExp.type == constantExp)
2077 // Unfinished business...
2078 BitMember bitMember = (BitMember)member;
2080 GetUInt64(memberExp, &bits);
2081 bits &= bitMember.mask;
2082 bits >>= bitMember.pos;
2084 FreeExpression(exp.member.exp);
2085 FreeIdentifier(exp.member.member);
2087 exp.constant = PrintUInt64(bits);
2089 exp.isConstant = true;
2090 exp.type = constantExp;
2091 exp.hasAddress = false;
2096 char * evaluation = null;
2097 ExpressionType evalError = dummyExp;
2098 bool gotAddress = false;
2100 Expression prev = exp.prev, next = exp.next;
2104 TypeKind kind = dummyType;
2105 Type dataType = member.dataType;
2108 dataType = member.dataType = ProcessTypeString(member.dataTypeString, false);
2110 if(dataType.kind == classType && dataType._class.registered &&
2111 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
2113 if(dataType._class.registered.dataTypeString)
2114 dataType._class.registered.dataType = ProcessTypeString(dataType._class.registered.dataTypeString, false);
2115 dataType = dataType._class.registered.dataType;
2117 dataType = ProcessTypeString("int", false);
2120 size = ComputeTypeSize(member.dataType);
2122 format = GetGdbFormatChar(dataType);
2123 //if(memberExp.address)
2125 //GetInt(memberExp, &address);
2126 //offset = member.offset;
2128 // TESTING NOHEAD HERE?
2129 if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass)
2130 offset += member._class.offset;
2132 // VERIFY THIS: (trying to fix primitive.type)
2133 // if(memberExp.type == constantExp)
2134 if(memberExp.hasAddress && (_class.type != normalClass && _class.type != noHeadClass && _class.type != systemClass))
2136 address = memberExp.address;
2139 else if(memberExp.type == constantExp)
2140 gotAddress = GetUInt64(memberExp, &address);
2143 gotAddress = GetUInt64(memberExp, &address);
2144 //printf("Unhandled !!\n");
2146 //printf("memberExp.hasAddress = %d\n", memberExp.hasAddress);
2147 //printf("memberExp.type = %d\n", memberExp.type);
2148 //printf("_class.name = %s, _class.type = %d\n", _class.name, _class.type);
2153 if(memberExp.type == instanceExp)
2155 String constant = null;
2156 byte * data = memberExp.instance.data + offset;
2157 switch(dataType.kind)
2160 if(dataType.isSigned)
2161 constant = PrintChar(*(char *)data);
2163 constant = PrintUChar(*(byte *)data);
2166 if(dataType.isSigned)
2167 constant = PrintShort(*(short *)data);
2169 constant = PrintUShort(*(uint16 *)data);
2172 if(dataType.isSigned)
2173 constant = PrintInt(*(int *)data);
2175 constant = PrintUInt(*(uint *)data);
2179 if(dataType.isSigned)
2180 constant = PrintInt64(*(int64 *)data);
2182 constant = PrintUInt64(*(uint64 *)data);
2184 case floatType: constant = PrintFloat(*(float *)data); break;
2185 case doubleType: constant = PrintDouble(*(double *)data); break;
2189 FreeExpContents(exp);
2190 exp.constant = constant;
2191 exp.type = constantExp;
2192 exp.isConstant = true;
2195 exp.type = unknownErrorExp;
2197 else if(!gotAddress)
2199 FreeExpContents(exp);
2200 exp.type = unknownErrorExp;
2202 else if((dataType.kind == classType && dataType._class &&
2203 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
2204 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
2206 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
2207 if(evalError != dummyExp)
2209 exp.type = evalError;
2210 exp.constant = PrintHexUInt64(address);
2214 //printf("evaluation = %s\n", evaluation);
2215 expNew = ParseExpressionString(evaluation);
2217 expNew.destType = exp.expType;
2219 exp.expType.refCount++;
2220 //FreeType(memberExp.destType);
2221 FreeType(exp.expType);
2222 FreeType(exp.destType);
2223 FreeExpContents(exp);
2224 ProcessExpressionType(expNew);
2225 DebugComputeExpression(expNew);
2228 expNew.isConstant = true;
2229 expNew.address = address;
2230 expNew.hasAddress = true;
2236 FreeExpContents(exp);
2237 exp.type = unknownErrorExp;
2242 // TESTING THIS HERE...
2243 exp.type = constantExp;
2244 exp.constant = PrintHexUInt64(address);
2246 exp.address = address;
2247 exp.hasAddress = true;
2248 exp.isConstant = true;
2253 // exp.type = ExpUnknownError;
2255 //FreeExpContents(exp);
2256 //exp.constant = PrintUInt64(value);
2257 //exp.type = constantExp;
2262 if(type && (type.kind == structType || type.kind == unionType))
2265 Type memberType = exp.member.member ? FindMemberAndOffset(type, exp.member.member.string, &offset) : null;
2268 char * evaluation = null;
2269 ExpressionType evalError = dummyExp;
2271 bool gotAddress = false;
2272 Expression prev = exp.prev, next = exp.next;
2274 int size = memberType.size;
2276 Type dataType = memberType;
2277 TypeKind kind = dummyType;
2279 if(dataType.kind == classType && dataType._class.registered &&
2280 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
2281 dataType = dataType._class.registered.dataType;
2283 format = GetGdbFormatChar(dataType);
2285 if(memberExp.hasAddress)
2287 address = memberExp.address;
2290 else if(memberExp.type == constantExp)
2291 gotAddress = GetUInt64(memberExp, &address);
2297 FreeExpContents(exp);
2298 exp.type = unknownErrorExp;
2300 else if((dataType.kind == classType && dataType._class &&
2301 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
2302 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
2304 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
2305 if(evalError != dummyExp)
2307 exp.type = evalError;
2308 exp.constant = PrintHexUInt64(address);
2312 expNew = ParseExpressionString(evaluation);
2314 expNew.destType = exp.expType;
2316 exp.expType.refCount++;
2317 //FreeType(memberExp.destType);
2318 FreeType(exp.expType);
2319 FreeType(exp.destType);
2320 FreeExpContents(exp);
2321 ProcessExpressionType(expNew);
2322 DebugComputeExpression(expNew);
2325 expNew.isConstant = true;
2326 expNew.address = address;
2327 expNew.hasAddress = true;
2333 FreeExpContents(exp);
2334 exp.type = unknownErrorExp;
2339 FreeExpContents(exp);
2341 // TESTING THIS HERE...
2342 exp.type = constantExp;
2343 exp.constant = PrintHexUInt64(address);
2345 exp.address = address;
2346 exp.hasAddress = true;
2347 exp.isConstant = true;
2351 exp.type = memberSymbolErrorExp;
2354 exp.type = memberSymbolErrorExp;
2358 //if(exp.type != memberExp)
2360 //FreeExpression(memberExp);
2361 //FreeIdentifier(memberID);
2366 exp.type = memberSymbolErrorExp;
2372 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
2373 FreeExpContents(exp);
2374 exp.constant = PrintUInt(ComputeTypeSize(type));
2375 exp.type = constantExp;
2381 Symbol classSym = FindClass(exp._class.name);
2382 if(classSym && classSym.registered)
2384 //exp.constant = PrintUInt(classSym.registered.size);
2385 //exp.type = constantExp;
2387 char className[1024];
2388 sprintf(className, "__ecereClass_%s", classSym.string);
2389 FreeExpContents(exp);
2390 exp.type = pointerExp;
2391 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
2392 exp.member.member = MkIdentifier("size");
2398 DebugComputeExpression(exp.cast.exp);
2400 if(ExpressionIsError(exp.cast.exp)) //.type == ExpSymbolError
2401 CarryExpressionError(exp, exp.cast.exp);
2404 exp.hasAddress = exp.cast.exp.hasAddress;
2405 exp.address = exp.cast.exp.address;
2406 if(exp.cast.exp.type == instanceExp && exp.cast.exp.expType && exp.expType && exp.cast.exp.expType.kind == classType && exp.expType.kind == classType &&
2407 exp.cast.exp.expType._class && exp.expType._class && exp.cast.exp.expType._class.registered && exp.expType._class.registered &&
2408 exp.cast.exp.expType._class.registered == exp.expType._class.registered)
2410 Instantiation inst = exp.cast.exp.instance;
2411 exp.cast.exp.instance = null;
2412 FreeExpContents(exp);
2413 exp.instance = inst;
2414 exp.type = instanceExp;
2416 else if(exp.cast.exp.type == constantExp && exp.expType)
2418 Type type = exp.expType;
2419 if(type.kind == classType && type._class && type._class.registered)
2421 Class _class = type._class.registered;
2422 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
2424 if(!_class.dataType)
2425 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
2426 type = _class.dataType;
2428 else if(_class.type == structClass && !type.byReference)
2430 FreeExpContents(exp);
2431 exp.type = unknownErrorExp;
2442 if(GetChar(exp.cast.exp, &value))
2444 FreeExpContents(exp);
2445 exp.constant = PrintChar(value);
2446 exp.type = constantExp;
2447 exp.isConstant = true;
2452 unsigned char value = 0;
2453 if(GetUChar(exp.cast.exp, &value))
2455 FreeExpContents(exp);
2456 exp.constant = PrintUChar(value);
2457 exp.type = constantExp;
2458 exp.isConstant = true;
2466 if(GetShort(exp.cast.exp, &value))
2468 FreeExpContents(exp);
2469 exp.constant = PrintShort(value);
2470 exp.type = constantExp;
2471 exp.isConstant = true;
2476 unsigned short value = 0;
2477 if(GetUShort(exp.cast.exp, &value))
2479 FreeExpContents(exp);
2480 exp.constant = PrintUShort(value);
2481 exp.type = constantExp;
2482 exp.isConstant = true;
2490 if(GetInt(exp.cast.exp, &value))
2492 FreeExpContents(exp);
2493 exp.constant = PrintInt(value);
2494 exp.type = constantExp;
2495 exp.isConstant = true;
2500 unsigned int value = 0;
2501 if(GetUInt(exp.cast.exp, &value))
2503 FreeExpContents(exp);
2504 exp.constant = PrintUInt(value);
2505 exp.type = constantExp;
2506 exp.isConstant = true;
2514 if(GetInt64(exp.cast.exp, &value))
2516 FreeExpContents(exp);
2517 exp.constant = PrintInt64(value);
2518 exp.type = constantExp;
2519 exp.isConstant = true;
2525 if(GetUInt64(exp.cast.exp, &value))
2527 FreeExpContents(exp);
2528 exp.constant = PrintUInt64(value);
2529 exp.type = constantExp;
2530 exp.isConstant = true;
2538 if(GetUInt64(exp.cast.exp, &value))
2540 FreeExpContents(exp);
2541 if(type.kind == pointerType || type.kind == classType)
2542 exp.constant = PrintHexUInt64(value);
2544 exp.constant = PrintUInt64(value);
2545 exp.type = constantExp;
2546 exp.isConstant = true;
2553 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
2554 (!strcmpi(exp.cast.exp.constant, "nan") ||
2555 !strcmpi(exp.cast.exp.constant, "-nan") ||
2556 !strcmpi(exp.cast.exp.constant, "inf") ||
2557 !strcmpi(exp.cast.exp.constant, "-inf")))
2559 String constant = exp.cast.exp.constant;
2560 exp.cast.exp.constant = null;
2561 FreeExpContents(exp);
2562 exp.constant = constant;
2563 exp.type = constantExp;
2564 exp.isConstant = true;
2566 else if(GetFloat(exp.cast.exp, &value))
2568 FreeExpContents(exp);
2569 exp.constant = PrintFloat(value);
2570 exp.type = constantExp;
2571 exp.isConstant = true;
2578 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
2579 (!strcmpi(exp.cast.exp.constant, "nan") ||
2580 !strcmpi(exp.cast.exp.constant, "-nan") ||
2581 !strcmpi(exp.cast.exp.constant, "inf") ||
2582 !strcmpi(exp.cast.exp.constant, "-inf")))
2584 String constant = exp.cast.exp.constant;
2585 exp.cast.exp.constant = null;
2586 FreeExpContents(exp);
2587 exp.constant = constant;
2588 exp.type = constantExp;
2589 exp.isConstant = true;
2591 else if(GetDouble(exp.cast.exp, &value))
2593 FreeExpContents(exp);
2594 exp.constant = PrintDouble(value);
2595 exp.type = constantExp;
2596 exp.isConstant = true;
2609 DebugComputeExpression(exp.cond.cond);
2611 if(ExpressionIsError(exp.cond.cond))
2612 CarryExpressionError(exp, exp.cond.cond);
2613 else if(exp.cond.cond.type == constantExp && exp.cond.cond.constant)
2615 Expression e = null;
2616 if(strtol(exp.cond.cond.constant, null, 0))
2618 for(e = exp.cond.exp ? exp.cond.exp->first : null; e; e = e.next)
2620 DebugComputeExpression(e);
2625 if(ExpressionIsError(e))
2627 CarryExpressionError(exp, e);
2631 exp.cond.exp->Remove(e);
2636 e = exp.cond.elseExp;
2639 DebugComputeExpression(e);
2640 if(ExpressionIsError(e))
2642 CarryExpressionError(exp, e);
2646 exp.cond.elseExp = null;
2651 FreeType(exp.expType);
2652 FreeType(exp.destType);
2655 FreeExpContents(exp);
2659 else if(!ExpressionIsError(exp))
2661 FreeExpContents(exp);
2662 exp.type = unknownErrorExp;
2667 FreeExpContents(exp);
2668 exp.type = unknownErrorExp;
2673 FreeExpContents(exp);
2674 exp.type = unknownErrorExp;
2681 void ApplyUnitConverters(Expression exp)
2683 Property convert = null;
2684 Type type = exp.expType;
2685 bool useGet = false;
2686 if(type.kind == classType && type._class && type._class.registered)
2688 Class _class = type._class.registered;
2689 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
2691 if(_class.type == unitClass && _class.base.type == unitClass)
2694 for(p = _class.conversions.first; p; p = p.next)
2696 if(!strcmp(p.name, _class.base.fullName))
2703 Class c = eSystem_FindClass(_class.module, p.name);
2707 for(p2 = c.conversions.first; p2; p2 = p2.next)
2709 if(!strcmp(p2.name, _class.base.fullName))
2722 if(!_class.dataType)
2723 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
2724 type = _class.dataType;
2735 if(GetChar(exp, &value))
2737 FreeExpContents(exp);
2738 exp.constant = PrintChar(value);
2739 exp.type = constantExp;
2740 exp.isConstant = true;
2745 unsigned char value = 0;
2746 if(GetUChar(exp, &value))
2748 FreeExpContents(exp);
2749 exp.constant = PrintUChar(value);
2750 exp.type = constantExp;
2751 exp.isConstant = true;
2759 if(GetShort(exp, &value))
2761 FreeExpContents(exp);
2762 exp.constant = PrintShort(value);
2763 exp.type = constantExp;
2764 exp.isConstant = true;
2769 unsigned short value = 0;
2770 if(GetUShort(exp, &value))
2772 FreeExpContents(exp);
2773 exp.constant = PrintUShort(value);
2774 exp.type = constantExp;
2775 exp.isConstant = true;
2783 if(GetInt(exp, &value))
2785 FreeExpContents(exp);
2786 exp.constant = PrintInt(value);
2787 exp.type = constantExp;
2788 exp.isConstant = true;
2793 unsigned int value = 0;
2794 if(GetUInt(exp, &value))
2796 FreeExpContents(exp);
2797 exp.constant = PrintUInt(value);
2798 exp.type = constantExp;
2799 exp.isConstant = true;
2807 if(GetInt64(exp, &value))
2809 FreeExpContents(exp);
2810 exp.constant = PrintInt64(value);
2811 exp.type = constantExp;
2812 exp.isConstant = true;
2818 if(GetUInt64(exp, &value))
2820 FreeExpContents(exp);
2821 exp.constant = PrintUInt64(value);
2822 exp.type = constantExp;
2823 exp.isConstant = true;
2831 if(GetUInt64(exp, &value))
2833 FreeExpContents(exp);
2834 if(type.kind == pointerType || type.kind == classType)
2835 exp.constant = PrintHexUInt64(value);
2837 exp.constant = PrintUInt64(value);
2838 exp.type = constantExp;
2839 exp.isConstant = true;
2846 if(exp.type == constantExp && exp.constant &&
2847 (!strcmpi(exp.constant, "nan") ||
2848 !strcmpi(exp.constant, "-nan") ||
2849 !strcmpi(exp.constant, "inf") ||
2850 !strcmpi(exp.constant, "-inf")))
2852 String constant = exp.constant;
2853 exp.constant = null;
2854 FreeExpContents(exp);
2855 exp.constant = constant;
2856 exp.type = constantExp;
2857 exp.isConstant = true;
2859 else if(GetFloat(exp, &value))
2863 float (*convertFn)(float) = (void *)(useGet ? convert.Get : convert.Set);
2865 value = convertFn(value);
2867 FreeExpContents(exp);
2868 exp.constant = PrintFloat(value);
2869 exp.type = constantExp;
2870 exp.isConstant = true;
2877 if(exp.type == constantExp && exp.constant &&
2878 (!strcmpi(exp.constant, "nan") ||
2879 !strcmpi(exp.constant, "-nan") ||
2880 !strcmpi(exp.constant, "inf") ||
2881 !strcmpi(exp.constant, "-inf")))
2883 String constant = exp.constant;
2884 exp.constant = null;
2885 FreeExpContents(exp);
2886 exp.constant = constant;
2887 exp.type = constantExp;
2888 exp.isConstant = true;
2890 else if(GetDouble(exp, &value))
2894 double (*convertFn)(double) = (void *)(useGet ? convert.Get : convert.Set);
2896 value = convertFn(value);
2898 FreeExpContents(exp);
2899 exp.constant = PrintDouble(value);
2900 exp.type = constantExp;
2901 exp.isConstant = true;