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);
313 if(evaluation && !strchr(evaluation, '<') && (exp.type != symbolErrorExp || !exp.identifier || !exp.identifier.string || strcmp(evaluation, exp.identifier.string)))
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 uint dataMemberOffset;
418 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
421 if(curMember.isProperty)
423 prop = (Property)curMember; // TOFIX: (eC II ? THe mss
427 dataMember = curMember;
430 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, GetPrivateModule(), null, null);
432 // 2013/17/29 -- It seems that this was missing here!
433 if(_class.type == normalClass)
434 dataMemberOffset += _class.base.structSize;
435 // dataMemberOffset = dataMember.offset;
442 prop = eClass_FindProperty(_class, ident.string, GetPrivateModule());
446 if(prop.memberAccess == publicAccess)
448 curMember = (DataMember)prop;
449 curClass = prop._class;
454 DataMember _subMemberStack[256];
455 int _subMemberStackPos = 0;
458 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, GetPrivateModule(), _subMemberStack, &_subMemberStackPos);
463 if(dataMember.memberAccess == publicAccess)
465 curMember = dataMember;
466 curClass = dataMember._class;
467 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
468 subMemberStackPos = _subMemberStackPos;
474 if(found && member.initializer && member.initializer.type == expInitializer)
476 Expression value = member.initializer.exp;
478 bool deepMember = false;
481 type = prop.dataType;
485 if(!dataMember.dataType)
486 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
488 type = dataMember.dataType;
491 if(ident && ident.next)
495 // for(; ident && type; ident = ident.next)
496 for(ident = ident.next; ident && type; ident = ident.next)
498 if(type.kind == classType)
500 prop = eClass_FindProperty(type._class.registered,
501 ident.string, GetPrivateModule());
503 type = prop.dataType;
506 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
507 ident.string, &dataMemberOffset, GetPrivateModule(), null, null);
509 type = dataMember.dataType;
512 else if(type.kind == structType || type.kind == unionType)
515 for(memberType = type.members.first; memberType; memberType = memberType.next)
517 if(!strcmp(memberType.name, ident.string))
528 FreeType(value.destType);
529 value.destType = type;
530 if(type) type.refCount++;
531 DebugComputeExpression(value);
533 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
535 if(type.kind == classType)
537 Class _class = type._class.registered;
538 if(_class.type == bitClass || _class.type == unitClass ||
539 _class.type == enumClass)
542 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
543 type = _class.dataType;
549 void * ptr = inst.data + dataMemberOffset;
551 if(value.type == constantExp)
557 GetInt(value, (int*)ptr);
562 GetInt64(value, (int64*)ptr);
567 GetIntPtr(value, (intptr*)ptr);
572 GetIntSize(value, (intsize*)ptr);
577 GetFloat(value, (float*)ptr);
582 GetDouble(value, (double *)ptr);
587 else if(value.type == instanceExp)
589 if(type.kind == classType)
591 Class _class = type._class.registered;
592 if(_class.type == structClass)
594 ComputeTypeSize(type);
595 if(value.instance.data)
596 memcpy(ptr, value.instance.data, type.size);
603 if(value.type == instanceExp && value.instance.data)
605 if(type.kind == classType)
607 Class _class = type._class.registered;
608 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
610 void (*Set)(void *, void *) = (void *)prop.Set;
611 Set(inst.data, value.instance.data);
612 PopulateInstance(inst);
616 else if(value.type == constantExp)
622 void (*Set)(void *, double) = (void *)prop.Set;
623 Set(inst.data, strtod(value.constant, null) );
628 void (*Set)(void *, float) = (void *)prop.Set;
629 Set(inst.data, (float)(strtod(value.constant, null)));
634 void (*Set)(void *, int) = (void *)prop.Set;
635 Set(inst.data, (int)strtol(value.constant, null, 0));
640 void (*Set)(void *, int64) = (void *)prop.Set;
641 Set(inst.data, _strtoi64(value.constant, null, 0));
646 void (*Set)(void *, intptr) = (void *)prop.Set;
647 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
652 void (*Set)(void *, intsize) = (void *)prop.Set;
653 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
658 else if(value.type == stringExp)
661 ReadString(temp, value.string);
662 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
666 else if(!deepMember && type && _class.type == unitClass)
670 // Only support converting units to units for now...
671 if(value.type == constantExp)
673 if(type.kind == classType)
675 Class _class = type._class.registered;
676 if(_class.type == unitClass)
679 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
680 type = _class.dataType;
683 // TODO: Assuming same base type for units...
689 float (*Set)(float) = (void *)prop.Set;
690 GetFloat(member.initializer.exp, &fValue);
691 exp.constant = PrintFloat(Set(fValue));
692 exp.type = constantExp;
698 double (*Set)(double) = (void *)prop.Set;
699 GetDouble(member.initializer.exp, &dValue);
700 exp.constant = PrintDouble(Set(dValue));
701 exp.type = constantExp;
708 else if(!deepMember && type && _class.type == bitClass)
712 if(value.type == instanceExp && value.instance.data)
714 unsigned int (*Set)(void *) = (void *)prop.Set;
715 bits = Set(value.instance.data);
717 else if(value.type == constantExp)
723 BitMember bitMember = (BitMember) dataMember;
726 GetInt(value, &part);
727 bits = (bits & ~bitMember.mask);
728 if(!bitMember.dataType)
729 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
731 type = bitMember.dataType;
733 if(type.kind == classType && type._class && type._class.registered)
735 if(!type._class.registered.dataType)
736 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
737 type = type._class.registered.dataType;
745 bits |= ((char)part << bitMember.pos);
747 bits |= ((unsigned char)part << bitMember.pos);
751 bits |= ((short)part << bitMember.pos);
753 bits |= ((unsigned short)part << bitMember.pos);
758 bits |= ((int)part << bitMember.pos);
760 bits |= ((unsigned int)part << bitMember.pos);
764 bits |= ((int64)part << bitMember.pos);
766 bits |= ((uint64)part << bitMember.pos);
771 bits |= ((intptr)part << bitMember.pos);
775 bits |= ((uintptr)part << bitMember.pos);
781 bits |= ((ssize_t)(intsize)part << bitMember.pos);
785 bits |= ((size_t) (uintsize)part << bitMember.pos);
794 if(_class && _class.type == unitClass)
796 DebugComputeExpression(member.initializer.exp);
797 exp.constant = member.initializer.exp.constant;
798 exp.type = constantExp;
800 member.initializer.exp.constant = null;
810 if(_class && _class.type == bitClass)
812 exp.constant = PrintHexUInt(bits);
813 exp.type = constantExp;
815 if(exp.type != instanceExp)
827 Expression expError = null;
828 Expression exp1 = null, exp2 = null;
829 Operand op1 = { 0 }, op2 = { 0 };
832 if(exp.op.op == '&' || exp.op.op == '*')
834 if(!exp.op.exp1 && exp.op.exp2)
836 if(exp.op.exp2.type == identifierExp)
838 Expression prev = exp.prev, next = exp.next;
839 char * evaluation = null;
840 ExpressionType evalError = dummyExp;
843 sprintf(temp, "%c%s", exp.op.op, exp.op.exp2.identifier.string);
844 evaluation = Debugger::EvaluateExpression(temp, &evalError);
845 if(evalError != dummyExp)
847 exp.type = evalError;
848 exp.constant = CopyString("");
852 expNew = ParseExpressionString(evaluation);
854 expNew.destType = exp.expType;
855 FreeType(exp.destType);
856 FreeExpContents(exp);
857 ProcessExpressionType(expNew);
858 DebugComputeExpression(expNew);
861 expNew.isConstant = true;
866 exp.type = ExpUnknownError;
876 DebugComputeExpression(exp.op.exp2);
877 size = ComputeTypeSize(exp.op.exp2.expType);
878 format = GetGdbFormatChar(exp.op.exp2.expType);
879 GetInt(exp.op.exp2, &address);
880 //sprintf(temp, "%c%s", exp.op.op, exp.op.exp2.constant);
881 evaluation = Debug_ReadMemory(address, size, format, &evalError);
884 evalError = ExpUnknownError;
890 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
893 Expression e = exp.op.exp2;
895 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
897 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
899 if(e.type == extensionCompoundExp)
900 e = ((Statement)e.compound.compound.statements->last).expressions->last;
905 if(exp.op.op == TokenType::sizeOf && e && e.expType)
907 if(e.type == stringExp && e.string)
909 char * string = e.string;
910 int len = strlen(string);
911 char * tmp = new char[len-2+1];
912 len = UnescapeString(tmp, string + 1, len - 2);
914 FreeExpContents(exp);
915 exp.type = constantExp;
916 exp.constant = PrintUInt(len + 1);
920 Type type = e.expType;
922 FreeExpContents(exp);
923 exp.type = constantExp;
924 exp.constant = PrintUInt(ComputeTypeSize(type));
931 DebugComputeExpression(exp.op.exp2);
932 if(ExpressionIsError(exp.op.exp2))
933 expError = exp.op.exp2;
940 DebugComputeExpression(exp.op.exp1);
941 if(ExpressionIsError(exp.op.exp1))
942 expError = exp.op.exp1;
947 if(ExpressionIsError(exp.op.exp2))
948 expError = exp.op.exp2;
953 op1 = GetOperand(exp1);
954 if(op1.type) op1.type.refCount++;
955 op2 = GetOperand(exp2);
956 if(op2.type) op2.type.refCount++;
962 op1 = GetOperand(exp1);
963 if(op1.type) op1.type.refCount++;
969 if(ExpressionIsError(exp.op.exp2))
970 expError = exp.op.exp2;
974 if(exp.op.op == '&' || exp.op.op == '*')
976 Expression prev = exp1.prev, next = exp1.next;
978 ExpressionType evalError = dummyExp;
979 char * evaluation = null;
985 //sprintf(temp, "%u", exp1.address);
986 temp = PrintHexUInt64(exp1.address);
987 expNew = ParseExpressionString(temp);
989 //expNew.address = exp1.address;
990 expNew.expType = exp.expType;
992 expNew.destType = exp.expType;
993 expNew.destType.refCount++;
995 FreeType(exp.destType);
996 FreeExpContents(exp);
997 ProcessExpressionType(expNew);
998 DebugComputeExpression(expNew);
1001 expNew.isConstant = true;
1008 else if(exp.op.op == '*')
1010 // TODO: Common pathway for * and [ ]
1014 FreeExpContents(exp1);
1015 exp1.type = dereferenceErrorExp;
1023 Expression e = exp1;
1025 bool gotAddress = false;
1027 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
1029 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
1031 if(e.type == extensionCompoundExp)
1032 e = ((Statement)e.compound.compound.statements->last).expressions->last;
1036 else if(e.type == castExp)
1040 if(e.expType.kind == structType)
1042 address = exp1.address;
1046 gotAddress = GetUInt64(e, &address);
1047 size = ComputeTypeSize(exp.expType); //exp.expType.arrayType.size;
1048 if(exp.expType && exp.expType.type && exp.expType.kind == arrayType)
1049 // For multilevels arrays
1052 format = GetGdbFormatChar(exp.expType);
1053 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
1055 Expression e1 = e.op.exp1, e2 = e.op.exp2;
1056 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1058 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1060 if(e1.type == extensionCompoundExp)
1061 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1065 else if(e1.type == castExp)
1068 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1070 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1072 if(e2.type == extensionCompoundExp)
1073 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1077 else if(e2.type == castExp)
1081 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1083 offset += strtol(e.op.exp2.constant, null, 0);
1086 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1088 offset += strtol(e.op.exp1.constant, null, 0);
1095 if(e.type == stringExp)
1098 String string = e.string;
1100 Type expType = exp1.expType.type;
1101 if(expType) expType.refCount++;
1105 int len = string ? strlen(string) : 0;
1106 tmp = new char[len-2+1];
1107 len = UnescapeString(tmp, string + 1, len - 2);
1108 if(len >= 0 && offset * size + size-1 <= len)
1112 FreeExpContents(exp);
1114 exp.type = dereferenceErrorExp;
1117 exp.type = constantExp;
1118 exp.isConstant = true;
1119 switch(expType.kind)
1121 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1122 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1123 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1124 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1125 case floatType: exp.constant = PrintFloat(((float *)tmp)[offset]); break;
1126 case doubleType: exp.constant = PrintDouble(((double *)tmp)[offset]); break;
1128 exp.type = unknownErrorExp;
1132 exp.type = unknownErrorExp;
1136 else if(gotAddress && exp.expType.kind == arrayType)
1138 FreeExpContents(exp);
1139 exp.type = constantExp;
1140 exp.isConstant = true;
1141 exp.constant = PrintHexUInt64(address);
1142 exp.address = address;
1143 exp.hasAddress = true;
1145 else if(gotAddress && format)
1147 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1153 expNew = ParseExpressionString(evaluation);
1154 expNew.address = address;
1155 expNew.hasAddress = true;
1157 expNew.destType = exp.expType;
1158 FreeType(exp.destType);
1159 FreeExpContents(exp);
1160 ProcessExpressionType(expNew);
1161 DebugComputeExpression(expNew);
1164 expNew.isConstant = true;
1170 // Unhandled code path, evaluation is null
1171 FreeExpContents(exp);
1172 exp.type = unknownErrorExp;
1175 case memoryErrorExp:
1177 FreeExpContents(exp1);
1178 exp1.type = evalError;
1179 exp1.constant = PrintHexUInt64(address);
1184 FreeExpContents(exp1);
1185 exp1.type = evalError;
1192 FreeExpContents(exp1);
1193 exp1.type = unknownErrorExp; // Not supported yet, generate error to fallback to GDB printout
1200 op1 = GetOperand(exp1);
1201 if(op1.type) op1.type.refCount++;
1206 CarryExpressionError(exp, expError);
1207 else if(exp.type == opExp)
1209 if(exp1 && exp2 && exp1.expType && exp2.expType &&
1210 ((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) ||
1211 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
1214 if((exp.op.op == '+' || exp.op.op == '-') && (op2.type || op1.type))
1216 Expression e1 = exp1, e2 = exp2;
1217 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1219 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1221 if(e1.type == extensionCompoundExp)
1222 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1226 else if(e1.type == castExp)
1229 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1231 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1233 if(e2.type == extensionCompoundExp)
1234 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1238 else if(e2.type == castExp)
1242 if((e1.type == stringExp && op2.type && op2.type.kind == intType) || (e2.type == stringExp && op1.type && op1.type.kind == intType))
1244 uint64 offset = ((exp.op.op == '+') ? 1 : -1) * (e1.type == stringExp ? op2.i64 : op1.i64);
1245 String newString = null;
1246 Expression e = e1.type == stringExp ? e1 : e2;
1249 int len = strlen(e.string) - 2;
1250 char * tmp = OffsetEscapedString(e.string + 1, len, (int)offset);
1253 len -= tmp - (e.string + 1);
1254 newString = new char[2 + len + 1];
1255 newString[0] = '\"';
1256 memcpy(newString + 1, tmp, len);
1257 newString[1 + len] = '\"';
1258 newString[1 + len + 1] = 0;
1262 FreeExpContents(exp);
1265 exp.type = stringExp;
1266 exp.string = newString;
1269 exp.type = dereferenceErrorExp;
1271 // Can't add 2 pointers...
1272 else if(exp.op.op != '+' ||
1273 !((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) &&
1274 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
1276 bool op1IsPointer = exp1.expType.kind == pointerType || exp1.expType.kind == arrayType;
1277 bool op2IsPointer = exp2.expType.kind == pointerType || exp2.expType.kind == arrayType;
1278 bool addressResult = !op1IsPointer || !op2IsPointer;
1282 size = ComputeTypeSize(exp1.expType.type);
1283 else if(op2IsPointer)
1284 size = ComputeTypeSize(exp2.expType.type);
1286 if(addressResult && size)
1288 if(op1IsPointer) op2.ui64 *= size;
1289 else if(op1IsPointer) op1.ui64 *= size;
1292 CallOperator(exp, exp1, exp2, op1, op2);
1293 if(exp.type == constantExp)
1297 exp.address = _strtoui64(exp.constant, null, 0);
1298 delete exp.constant;
1299 exp.constant = PrintHexUInt64(exp.address);
1300 if(op1.type.kind == arrayType || op2.type.kind == arrayType)
1301 exp.hasAddress = true;
1305 int64 v = _strtoi64(exp.constant, null, 0);
1307 delete exp.constant;
1308 exp.constant = PrintInt(v);
1315 FreeExpContents(exp);
1316 exp.type = unknownErrorExp; // We should have an invalid operands error
1321 if(!exp2 && exp1 && exp1.type == constantExp && exp1.constant && !strcmp(exp1.constant, "nan") && exp.op.op == '-')
1323 FreeExpContents(exp);
1324 exp.constant = CopyString("-nan");
1325 exp.type = constantExp;
1329 if((exp.op.op == '/' || exp.op.op == '%') && op2.kind != doubleType && op1.kind != doubleType && op2.kind != floatType && op1.kind != floatType &&
1330 (((op2.kind == int64Type || op2.kind == intPtrType || op2.kind == intSizeType) && !op2.i64) ||
1331 (op2.kind == intType && !op2.i) || (op2.kind == shortType && !op2.s) || (op2.kind == charType && !op2.c)))
1333 FreeExpContents(exp);
1334 exp.type = divideBy0ErrorExp;
1337 CallOperator(exp, exp1, exp2, op1, op2);
1342 if(exp.type == constantExp)
1343 exp.isConstant = true;
1351 // e = (*exp.list).first, n = e ? e.next : null;
1353 // e = n, n = n?(n.next) : null)
1355 for(e = exp.list->first; e; e = n)
1360 OldList * list = exp.list;
1361 DebugComputeExpression(e);
1362 //if(ExpressionIsError(e)) //.type == ExpSymbolError
1363 // CarryExpressionError(exp, e);
1364 //FreeExpContents(exp);
1365 FreeType(exp.expType);
1366 FreeType(exp.destType);
1383 exp.isConstant = true;
1385 DebugComputeExpression(exp.index.exp);
1386 if(ExpressionIsError(exp.index.exp)) //.type == ExpSymbolError
1387 CarryExpressionError(exp, exp.index.exp);
1390 Expression prev = exp.prev, next = exp.next;
1391 char * evaluation = null;
1392 ExpressionType evalError = dummyExp;
1394 if(!exp.index.exp.isConstant)
1395 exp.isConstant = false;
1398 // 4 == size = ComputeTypeSize(exp.expType);
1399 // 0 == size = ComputeTypeSize(exp.expType.arrayType);
1400 // 4 == size = ComputeTypeSize(exp.index.exp.expType);
1401 // 0 == size = ComputeTypeSize(exp.index.exp.expType.arrayType);
1403 size = ComputeTypeSize(exp.expType);
1404 if(exp.expType && exp.expType.type && exp.expType.kind == arrayType)
1405 // For multilevels arrays
1408 format = GetGdbFormatChar(exp.expType);
1410 for(e = exp.index.index->first; e; e = e.next)
1412 DebugComputeExpression(e);
1413 if(ExpressionIsError(e)) //.type == ExpSymbolError
1415 CarryExpressionError(exp, e);
1420 // Check if this type is int
1423 exp.isConstant = false;
1425 if(!ExpressionIsError(exp))
1427 // Is this necessary here? pass15 had done this already...
1428 if(exp.expType) FreeType(exp.expType);
1429 exp.expType = Dereference(exp.index.exp.expType);
1434 FreeExpContents(exp);
1435 exp.type = dereferenceErrorExp;
1437 else if(exp.index.index && exp.index.index->last && ((Expression)exp.index.index->last) && ((Expression)exp.index.index->last).expType)
1439 Type type = ((Expression)exp.index.index->last).expType;
1440 if(type.kind == intType || type.kind == charType || type.kind == shortType || type.kind == int64Type || type.kind == intPtrType ||
1441 type.kind == intSizeType || type.kind == longType || type.kind == _BoolType || type.kind == enumType ||
1442 (type.kind == classType && type._class && type._class.registered &&
1443 type._class.registered.type == enumClass))
1445 bool gotAddress = false;
1446 uint64 address = 0, offset = 0;
1447 Expression expNew, last = (Expression)exp.index.index->last;
1448 Expression e = exp.index.exp;
1450 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
1452 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
1454 if(e.type == extensionCompoundExp)
1455 e = ((Statement)e.compound.compound.statements->last).expressions->last;
1459 else if(e.type == castExp)
1463 //GetUInt(exp.index.exp, &address);
1465 GetUInt64(last, &offset);
1467 // TOFIX: Check if it has address: TESTING
1468 if(exp.index.exp.hasAddress && exp.index.exp.expType.kind == arrayType)
1470 address = exp.index.exp.address;
1473 else if(exp.index.exp.type == constantExp)
1474 gotAddress = GetUInt64(exp.index.exp, &address);
1476 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
1478 Expression e1 = e.op.exp1, e2 = e.op.exp2;
1479 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1481 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1483 if(e1.type == extensionCompoundExp)
1484 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1488 else if(e1.type == castExp)
1491 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1493 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1495 if(e2.type == extensionCompoundExp)
1496 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1500 else if(e2.type == castExp)
1504 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1506 offset += strtol(e.op.exp2.constant, null, 0);
1509 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1511 offset += strtol(e.op.exp1.constant, null, 0);
1518 //size = ComputeTypeSize(exp.expType.arrayType); //exp.expType.arrayType.size;
1519 address += offset * size;
1521 if(e.type == stringExp)
1524 String string = e.string;
1526 Type expType = exp.index.exp.expType.type;
1527 if(expType) expType.refCount++;
1531 int len = string ? strlen(string) : 0;
1532 tmp = new char[len-2+1];
1533 len = UnescapeString(tmp, string + 1, len - 2);
1534 if(len >= 0 && offset * size + size-1 <= len)
1538 FreeExpContents(exp);
1540 exp.type = dereferenceErrorExp;
1543 exp.type = constantExp;
1544 exp.isConstant = true;
1545 switch(expType.kind)
1547 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1548 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1549 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1550 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1551 case floatType: exp.constant = PrintFloat(((float *)tmp)[offset]); break;
1552 case doubleType: exp.constant = PrintDouble(((double *)tmp)[offset]); break;
1554 exp.type = unknownErrorExp;
1558 exp.type = unknownErrorExp;
1562 else if(gotAddress && exp.expType.kind == arrayType)
1564 FreeExpContents(exp);
1565 exp.type = constantExp;
1566 exp.isConstant = true;
1567 exp.constant = PrintHexUInt64(address);
1568 exp.address = address;
1569 exp.hasAddress = true;
1573 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1579 expNew = ParseExpressionString(evaluation);
1581 expNew.destType = exp.expType;
1582 FreeType(exp.destType);
1583 FreeExpContents(exp);
1584 ProcessExpressionType(expNew);
1585 DebugComputeExpression(expNew);
1587 // TOFIX: Only for Array Types
1588 expNew.address = address;
1590 expNew.hasAddress = true;
1593 expNew.isConstant = true;
1599 // Unhandled code path, evaluation is null
1600 FreeExpContents(exp);
1601 exp.type = unknownErrorExp;
1604 case memoryErrorExp:
1606 FreeExpContents(exp);
1607 exp.type = evalError;
1608 exp.constant = PrintHexUInt64(address);
1612 FreeExpContents(exp);
1613 exp.type = evalError;
1619 FreeExpContents(exp);
1620 exp.type = unknownErrorExp;
1630 Expression callExp = exp.call.exp;
1631 Identifier id = (callExp && callExp.type == identifierExp) ? callExp.identifier : null;
1632 bool resolved = false;
1635 if(!strcmp(id.string, "nan") || !strcmp(id.string, "inf"))
1637 String s = id.string;
1639 FreeExpContents(exp);
1640 exp.type = constantExp;
1644 else if(exp.call.arguments)
1646 if(exp.call.arguments->count == 1)
1648 double (* fn1)(double) = (void *)oneArgFns[id.string];
1651 Expression arg = exp.call.arguments->first;
1652 DebugComputeExpression(arg);
1653 if(ExpressionIsError(arg))
1654 CarryExpressionError(exp, arg);
1655 else if(arg.isConstant && arg.type == constantExp)
1658 if(GetDouble(arg, &v))
1660 FreeExpContents(exp);
1661 exp.type = constantExp;
1663 exp.constant = PrintDouble(v);
1664 exp.isConstant = true;
1670 else if(exp.call.arguments->count == 2)
1672 double (* fn2)(double, double) = (void *)twoArgFns[id.string];
1675 Expression arg1 = exp.call.arguments->first;
1676 Expression arg2 = exp.call.arguments->last;
1677 DebugComputeExpression(arg1);
1678 DebugComputeExpression(arg2);
1679 if(ExpressionIsError(arg1))
1680 CarryExpressionError(exp, arg1);
1681 else if(ExpressionIsError(arg2))
1682 CarryExpressionError(exp, arg2);
1683 else if(arg1.isConstant && arg1.type == constantExp && arg2.isConstant && arg2.type == constantExp)
1686 if(GetDouble(arg1, &v1) && GetDouble(arg2, &v2))
1688 FreeExpContents(exp);
1689 exp.type = constantExp;
1691 exp.constant = PrintDouble(v1);
1692 exp.isConstant = true;
1701 exp.type = functionCallErrorExp;
1706 Expression memberExp = exp.member.exp;
1707 Identifier memberID = exp.member.member;
1709 Property prop = null;
1710 DataMember member = null;
1711 Class convertTo = null;
1712 uint offset = 0; // THIS WASN'T INITIALIZED... IS IT ALWAYS SET?
1714 Type type; // = memberExp.expType;
1715 DebugComputeExpression(memberExp);
1716 type = memberExp.expType;
1717 if(ExpressionIsError(memberExp))
1718 CarryExpressionError(exp, memberExp);
1721 // _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
1722 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);
1725 char string[256] = "";
1727 PrintTypeNoConst(type, string, false, true);
1728 classSym = FindClass(string);
1729 _class = classSym ? classSym.registered : null;
1732 if(memberID && _class)
1735 prop = eClass_FindProperty(_class, memberID.string);
1737 member = eClass_FindDataMember(_class, memberID.string);
1739 // member = eClass_FindDataMember(_class, memberID.string);
1740 member = eClass_FindDataMemberAndOffset(_class, memberID.string, &offset, _class.module.application, null, null);
1742 prop = eClass_FindProperty(_class, memberID.string, _class.module.application);
1744 if(!prop && !member && _class && memberID)
1746 Symbol classSym = FindClass(memberID.string);
1748 _class = classSym ? classSym.registered : null;
1750 prop = eClass_FindProperty(_class, convertTo.fullName, _class.module.application);
1753 //DebugComputeExpression(memberExp);
1754 if(ExpressionIsError(memberExp))
1755 CarryExpressionError(exp, memberExp);
1758 if(exp.member.memberType == methodMember)
1760 FreeExpContents(exp);
1761 exp.type = unknownErrorExp;
1765 bool supported = false;
1768 Type type = prop.dataType;
1769 // TODO: Assuming same base type for units...
1770 if(_class.type == unitClass)
1772 if(type.kind == classType)
1774 Class _class = type._class.registered;
1775 if(_class.type == unitClass)
1777 if(!_class.dataType)
1778 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
1779 type = _class.dataType;
1787 float (*Get)(float) = (convertTo ? (void *)prop.Set : (void *)prop.Get);
1788 GetFloat(memberExp, &value);
1790 FreeExpContents(exp);
1791 exp.constant = PrintFloat(Get ? Get(value) : value);
1792 exp.type = constantExp;
1793 exp.isConstant = true;
1800 double (*Get)(double) = (convertTo ? (void *)prop.Set : (void *)prop.Get);
1801 GetDouble(memberExp, &value);
1803 FreeExpContents(exp);
1804 exp.constant = PrintDouble(Get ? Get(value) : value);
1805 exp.isConstant = true;
1806 exp.type = constantExp;
1816 Expression value = memberExp;
1817 Type type = prop.dataType;
1818 exp.member.exp = null;
1820 if(_class.type == structClass)
1826 Class propertyClass = type._class.registered;
1827 if(propertyClass.type == structClass && value.type == instanceExp)
1829 void (*Set)(void *, void *) = (void *)prop.Set;
1830 FreeExpContents(exp);
1831 exp.instance = Instantiation
1833 data = new0 byte[_class.structSize];
1834 _class = MkSpecifierName(_class.name);
1837 exp.type = instanceExp;
1839 Set(exp.instance.data, value.instance.data);
1840 PopulateInstance(exp.instance);
1848 void (*Set)(void *, int) = (void *)prop.Set;
1850 GetInt(value, &intValue);
1851 FreeExpContents(exp);
1852 exp.instance = Instantiation
1854 data = new0 byte[_class.structSize];
1855 _class = MkSpecifierName/*MkClassName*/(_class.name);
1858 exp.type = instanceExp;
1860 Set(exp.instance.data, intValue);
1861 PopulateInstance(exp.instance);
1868 void (*Set)(void *, int64) = (void *)prop.Set;
1870 GetInt64(value, &intValue);
1871 FreeExpContents(exp);
1872 exp.instance = Instantiation
1874 data = new0 byte[_class.structSize];
1875 _class = MkSpecifierName/*MkClassName*/(_class.name);
1878 exp.type = instanceExp;
1880 Set(exp.instance.data, intValue);
1881 PopulateInstance(exp.instance);
1888 void (*Set)(void *, float) = (void *)prop.Set;
1890 GetFloat(value, &floatValue);
1891 FreeExpContents(exp);
1892 exp.instance = Instantiation
1894 data = new0 byte[_class.structSize];
1895 _class = MkSpecifierName/*MkClassName*/(_class.name);
1898 exp.type = instanceExp;
1900 Set(exp.instance.data, floatValue);
1901 PopulateInstance(exp.instance);
1908 void (*Set)(void *, double) = (void *)prop.Set;
1910 GetDouble(value, &doubleValue);
1911 FreeExpContents(exp);
1912 exp.instance = Instantiation
1914 data = new0 byte[_class.structSize];
1915 _class = MkSpecifierName/*MkClassName*/(_class.name);
1918 exp.type = instanceExp;
1920 Set(exp.instance.data, doubleValue);
1921 PopulateInstance(exp.instance);
1927 else if(_class.type == bitClass)
1933 Class propertyClass = type._class.registered;
1934 if(propertyClass.type == structClass && value.instance.data)
1936 unsigned int (*Set)(void *) = (void *)prop.Set;
1937 unsigned int bits = Set(value.instance.data);
1938 FreeExpContents(exp);
1939 exp.constant = PrintHexUInt(bits);
1940 exp.type = constantExp;
1944 else if(_class.type == bitClass)
1947 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
1950 GetUInt(memberExp, &value);
1952 FreeExpContents(exp);
1953 exp.constant = PrintHexUInt(bits);
1954 exp.type = constantExp;
1960 FreeExpression(value);
1964 if(_class.type == bitClass)
1967 GetUInt(memberExp, &value);
1973 Class _class = type._class.registered;
1974 if(_class.type == structClass)
1976 void (*Get)(unsigned int, void *) = (void *)prop.Get;
1978 FreeExpContents(exp);
1979 exp.instance = Instantiation
1981 data = new0 byte[_class.structSize];
1982 _class = MkSpecifierName/*MkClassName*/(_class.name);
1985 //exp.instance.fullSet = true;
1986 exp.type = instanceExp;
1987 Get(value, exp.instance.data);
1988 PopulateInstance(exp.instance);
1991 else if(_class.type == bitClass)
1993 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
1994 uint64 bits = Get(value);
1995 exp.constant = PrintHexUInt64(bits);
1996 exp.type = constantExp;
2003 else if(_class.type == structClass)
2005 byte * value = (memberExp.type == instanceExp ) ? memberExp.instance.data : null;
2007 memberExp.instance.data = null;
2013 Class _class = type._class.registered;
2014 if(_class.type == structClass && value)
2016 void (*Get)(void *, void *) = (void *)prop.Get;
2018 FreeExpContents(exp);
2019 exp.instance = Instantiation
2021 data = new0 byte[_class.structSize];
2022 _class = MkSpecifierName/*MkClassName*/(_class.name);
2025 //exp.instance.fullSet = true;
2026 exp.type = instanceExp;
2027 Get(value, exp.instance.data);
2028 PopulateInstance(exp.instance);
2039 char * value = memberExp.instance.data;
2044 Class _class = type._class.registered;
2045 if(_class.type == normalClass)
2047 void *(*Get)(void *) = (void *)prop.Get;
2049 FreeExpContents(exp);
2050 exp.instance = Instantiation
2052 data = Get(value, exp.instance.data); ?????
2053 _class = MkSpecifierName(_class.name); //MkClassName(_class.name);
2056 exp.type = instanceExp;
2068 exp.type = memberPropertyErrorExp;
2069 exp.isConstant = false;
2074 if(memberExp.hasAddress || memberExp.type == constantExp || (memberExp.type == instanceExp && memberExp.instance && memberExp.instance.data))
2075 //if(memberExp.expType && memberExp.expType.kind == intType) // && !exp.index.exp.expType.isSigned
2077 if(_class.type == bitClass)
2079 if(memberExp.type == constantExp)
2081 // Unfinished business...
2082 BitMember bitMember = (BitMember)member;
2084 GetUInt64(memberExp, &bits);
2085 bits &= bitMember.mask;
2086 bits >>= bitMember.pos;
2088 FreeExpression(exp.member.exp);
2089 FreeIdentifier(exp.member.member);
2091 exp.constant = PrintUInt64(bits);
2093 exp.isConstant = true;
2094 exp.type = constantExp;
2095 exp.hasAddress = false;
2100 char * evaluation = null;
2101 ExpressionType evalError = dummyExp;
2102 bool gotAddress = false;
2104 Expression prev = exp.prev, next = exp.next;
2108 Type dataType = member.dataType;
2111 dataType = member.dataType = ProcessTypeString(member.dataTypeString, false);
2113 if(dataType.kind == classType && dataType._class.registered &&
2114 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
2116 if(dataType._class.registered.dataTypeString)
2117 dataType._class.registered.dataType = ProcessTypeString(dataType._class.registered.dataTypeString, false);
2118 dataType = dataType._class.registered.dataType;
2120 dataType = ProcessTypeString("int", false);
2123 size = ComputeTypeSize(member.dataType);
2125 format = GetGdbFormatChar(dataType);
2126 //if(memberExp.address)
2128 //GetInt(memberExp, &address);
2129 //offset = member.offset;
2131 // TESTING NOHEAD HERE?
2132 if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass)
2133 offset += member._class.offset;
2135 // VERIFY THIS: (trying to fix primitive.type)
2136 // if(memberExp.type == constantExp)
2137 if(memberExp.hasAddress && (_class.type != normalClass && _class.type != noHeadClass && _class.type != systemClass))
2139 address = memberExp.address;
2142 else if(memberExp.type == constantExp)
2143 gotAddress = GetUInt64(memberExp, &address);
2146 gotAddress = GetUInt64(memberExp, &address);
2147 //printf("Unhandled !!\n");
2149 //printf("memberExp.hasAddress = %d\n", memberExp.hasAddress);
2150 //printf("memberExp.type = %d\n", memberExp.type);
2151 //printf("_class.name = %s, _class.type = %d\n", _class.name, _class.type);
2156 if(memberExp.type == instanceExp)
2158 String constant = null;
2159 byte * data = memberExp.instance.data + offset;
2160 switch(dataType.kind)
2163 if(dataType.isSigned)
2164 constant = PrintChar(*(char *)data);
2166 constant = PrintUChar(*(byte *)data);
2169 if(dataType.isSigned)
2170 constant = PrintShort(*(short *)data);
2172 constant = PrintUShort(*(uint16 *)data);
2175 if(dataType.isSigned)
2176 constant = PrintInt(*(int *)data);
2178 constant = PrintUInt(*(uint *)data);
2182 if(dataType.isSigned)
2183 constant = PrintInt64(*(int64 *)data);
2185 constant = PrintUInt64(*(uint64 *)data);
2187 case floatType: constant = PrintFloat(*(float *)data); break;
2188 case doubleType: constant = PrintDouble(*(double *)data); break;
2192 FreeExpContents(exp);
2193 exp.constant = constant;
2194 exp.type = constantExp;
2195 exp.isConstant = true;
2198 exp.type = unknownErrorExp;
2200 else if(!gotAddress)
2202 FreeExpContents(exp);
2203 exp.type = unknownErrorExp;
2205 else if((dataType.kind == classType && dataType._class &&
2206 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
2207 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
2209 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
2210 if(evalError != dummyExp)
2212 exp.type = evalError;
2213 exp.constant = PrintHexUInt64(address);
2217 //printf("evaluation = %s\n", evaluation);
2218 expNew = ParseExpressionString(evaluation);
2220 expNew.destType = exp.expType;
2222 exp.expType.refCount++;
2223 //FreeType(memberExp.destType);
2224 FreeType(exp.expType);
2225 FreeType(exp.destType);
2226 FreeExpContents(exp);
2227 ProcessExpressionType(expNew);
2228 DebugComputeExpression(expNew);
2231 expNew.isConstant = true;
2232 expNew.address = address;
2233 expNew.hasAddress = true;
2239 FreeExpContents(exp);
2240 exp.type = unknownErrorExp;
2245 // TESTING THIS HERE...
2246 exp.type = constantExp;
2247 exp.constant = PrintHexUInt64(address);
2249 exp.address = address;
2250 exp.hasAddress = true;
2251 exp.isConstant = true;
2256 // exp.type = ExpUnknownError;
2258 //FreeExpContents(exp);
2259 //exp.constant = PrintUInt64(value);
2260 //exp.type = constantExp;
2265 if(type && (type.kind == structType || type.kind == unionType))
2268 Type memberType = exp.member.member ? FindMemberAndOffset(type, exp.member.member.string, &offset) : null;
2271 char * evaluation = null;
2272 ExpressionType evalError = dummyExp;
2274 bool gotAddress = false;
2275 Expression prev = exp.prev, next = exp.next;
2277 int size = memberType.size;
2279 Type dataType = memberType;
2281 if(dataType.kind == classType && dataType._class.registered &&
2282 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
2283 dataType = dataType._class.registered.dataType;
2285 format = GetGdbFormatChar(dataType);
2287 if(memberExp.hasAddress)
2289 address = memberExp.address;
2292 else if(memberExp.type == constantExp)
2293 gotAddress = GetUInt64(memberExp, &address);
2299 FreeExpContents(exp);
2300 exp.type = unknownErrorExp;
2302 else if((dataType.kind == classType && dataType._class &&
2303 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
2304 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
2306 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
2307 if(evalError != dummyExp)
2309 exp.type = evalError;
2310 exp.constant = PrintHexUInt64(address);
2314 expNew = ParseExpressionString(evaluation);
2316 expNew.destType = exp.expType;
2318 exp.expType.refCount++;
2319 //FreeType(memberExp.destType);
2320 FreeType(exp.expType);
2321 FreeType(exp.destType);
2322 FreeExpContents(exp);
2323 ProcessExpressionType(expNew);
2324 DebugComputeExpression(expNew);
2327 expNew.isConstant = true;
2328 expNew.address = address;
2329 expNew.hasAddress = true;
2335 FreeExpContents(exp);
2336 exp.type = unknownErrorExp;
2341 FreeExpContents(exp);
2343 // TESTING THIS HERE...
2344 exp.type = constantExp;
2345 exp.constant = PrintHexUInt64(address);
2347 exp.address = address;
2348 exp.hasAddress = true;
2349 exp.isConstant = true;
2353 exp.type = memberSymbolErrorExp;
2356 exp.type = memberSymbolErrorExp;
2360 //if(exp.type != memberExp)
2362 //FreeExpression(memberExp);
2363 //FreeIdentifier(memberID);
2368 exp.type = memberSymbolErrorExp;
2374 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
2375 FreeExpContents(exp);
2376 exp.constant = PrintUInt(ComputeTypeSize(type));
2377 exp.type = constantExp;
2383 Symbol classSym = FindClass(exp._class.name);
2384 if(classSym && classSym.registered)
2386 //exp.constant = PrintUInt(classSym.registered.size);
2387 //exp.type = constantExp;
2389 char className[1024];
2390 sprintf(className, "__ecereClass_%s", classSym.string);
2391 FreeExpContents(exp);
2392 exp.type = pointerExp;
2393 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
2394 exp.member.member = MkIdentifier("size");
2400 DebugComputeExpression(exp.cast.exp);
2402 if(ExpressionIsError(exp.cast.exp)) //.type == ExpSymbolError
2403 CarryExpressionError(exp, exp.cast.exp);
2406 exp.hasAddress = exp.cast.exp.hasAddress;
2407 exp.address = exp.cast.exp.address;
2408 if(exp.cast.exp.type == instanceExp && exp.cast.exp.expType && exp.expType && exp.cast.exp.expType.kind == classType && exp.expType.kind == classType &&
2409 exp.cast.exp.expType._class && exp.expType._class && exp.cast.exp.expType._class.registered && exp.expType._class.registered &&
2410 exp.cast.exp.expType._class.registered == exp.expType._class.registered)
2412 Instantiation inst = exp.cast.exp.instance;
2413 exp.cast.exp.instance = null;
2414 FreeExpContents(exp);
2415 exp.instance = inst;
2416 exp.type = instanceExp;
2418 else if(exp.cast.exp.type == constantExp && exp.expType)
2420 Type type = exp.expType;
2421 if(type.kind == classType && type._class && type._class.registered)
2423 Class _class = type._class.registered;
2424 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
2426 if(!_class.dataType)
2427 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
2428 type = _class.dataType;
2430 else if(_class.type == structClass && !type.byReference)
2432 FreeExpContents(exp);
2433 exp.type = unknownErrorExp;
2444 if(GetChar(exp.cast.exp, &value))
2446 FreeExpContents(exp);
2447 exp.constant = PrintChar(value);
2448 exp.type = constantExp;
2449 exp.isConstant = true;
2454 unsigned char value = 0;
2455 if(GetUChar(exp.cast.exp, &value))
2457 FreeExpContents(exp);
2458 exp.constant = PrintUChar(value);
2459 exp.type = constantExp;
2460 exp.isConstant = true;
2468 if(GetShort(exp.cast.exp, &value))
2470 FreeExpContents(exp);
2471 exp.constant = PrintShort(value);
2472 exp.type = constantExp;
2473 exp.isConstant = true;
2478 unsigned short value = 0;
2479 if(GetUShort(exp.cast.exp, &value))
2481 FreeExpContents(exp);
2482 exp.constant = PrintUShort(value);
2483 exp.type = constantExp;
2484 exp.isConstant = true;
2492 if(GetInt(exp.cast.exp, &value))
2494 FreeExpContents(exp);
2495 exp.constant = PrintInt(value);
2496 exp.type = constantExp;
2497 exp.isConstant = true;
2502 unsigned int value = 0;
2503 if(GetUInt(exp.cast.exp, &value))
2505 FreeExpContents(exp);
2506 exp.constant = PrintUInt(value);
2507 exp.type = constantExp;
2508 exp.isConstant = true;
2516 if(GetInt64(exp.cast.exp, &value))
2518 FreeExpContents(exp);
2519 exp.constant = PrintInt64(value);
2520 exp.type = constantExp;
2521 exp.isConstant = true;
2527 if(GetUInt64(exp.cast.exp, &value))
2529 FreeExpContents(exp);
2530 exp.constant = PrintUInt64(value);
2531 exp.type = constantExp;
2532 exp.isConstant = true;
2540 if(GetUInt64(exp.cast.exp, &value))
2542 FreeExpContents(exp);
2543 if(type.kind == pointerType || type.kind == classType)
2544 exp.constant = PrintHexUInt64(value);
2546 exp.constant = PrintUInt64(value);
2547 exp.type = constantExp;
2548 exp.isConstant = true;
2555 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
2556 (!strcmpi(exp.cast.exp.constant, "nan") ||
2557 !strcmpi(exp.cast.exp.constant, "-nan") ||
2558 !strcmpi(exp.cast.exp.constant, "inf") ||
2559 !strcmpi(exp.cast.exp.constant, "-inf")))
2561 String constant = exp.cast.exp.constant;
2562 exp.cast.exp.constant = null;
2563 FreeExpContents(exp);
2564 exp.constant = constant;
2565 exp.type = constantExp;
2566 exp.isConstant = true;
2568 else if(GetFloat(exp.cast.exp, &value))
2570 FreeExpContents(exp);
2571 exp.constant = PrintFloat(value);
2572 exp.type = constantExp;
2573 exp.isConstant = true;
2580 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
2581 (!strcmpi(exp.cast.exp.constant, "nan") ||
2582 !strcmpi(exp.cast.exp.constant, "-nan") ||
2583 !strcmpi(exp.cast.exp.constant, "inf") ||
2584 !strcmpi(exp.cast.exp.constant, "-inf")))
2586 String constant = exp.cast.exp.constant;
2587 exp.cast.exp.constant = null;
2588 FreeExpContents(exp);
2589 exp.constant = constant;
2590 exp.type = constantExp;
2591 exp.isConstant = true;
2593 else if(GetDouble(exp.cast.exp, &value))
2595 FreeExpContents(exp);
2596 exp.constant = PrintDouble(value);
2597 exp.type = constantExp;
2598 exp.isConstant = true;
2611 DebugComputeExpression(exp.cond.cond);
2613 if(ExpressionIsError(exp.cond.cond))
2614 CarryExpressionError(exp, exp.cond.cond);
2615 else if(exp.cond.cond.type == constantExp && exp.cond.cond.constant)
2617 Expression e = null;
2618 if(strtol(exp.cond.cond.constant, null, 0))
2620 for(e = exp.cond.exp ? exp.cond.exp->first : null; e; e = e.next)
2622 DebugComputeExpression(e);
2627 if(ExpressionIsError(e))
2629 CarryExpressionError(exp, e);
2633 exp.cond.exp->Remove(e);
2638 e = exp.cond.elseExp;
2641 DebugComputeExpression(e);
2642 if(ExpressionIsError(e))
2644 CarryExpressionError(exp, e);
2648 exp.cond.elseExp = null;
2653 FreeType(exp.expType);
2654 FreeType(exp.destType);
2657 FreeExpContents(exp);
2661 else if(!ExpressionIsError(exp))
2663 FreeExpContents(exp);
2664 exp.type = unknownErrorExp;
2669 FreeExpContents(exp);
2670 exp.type = unknownErrorExp;
2675 FreeExpContents(exp);
2676 exp.type = unknownErrorExp;
2683 void ApplyUnitConverters(Expression exp)
2685 Property convert = null;
2686 Type type = exp.expType;
2687 bool useGet = false;
2688 if(type.kind == classType && type._class && type._class.registered)
2690 Class _class = type._class.registered;
2691 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
2693 if(_class.type == unitClass && _class.base.type == unitClass)
2696 for(p = _class.conversions.first; p; p = p.next)
2698 if(!strcmp(p.name, _class.base.fullName))
2705 Class c = eSystem_FindClass(_class.module, p.name);
2709 for(p2 = c.conversions.first; p2; p2 = p2.next)
2711 if(!strcmp(p2.name, _class.base.fullName))
2724 if(!_class.dataType)
2725 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
2726 type = _class.dataType;
2737 if(GetChar(exp, &value))
2739 FreeExpContents(exp);
2740 exp.constant = PrintChar(value);
2741 exp.type = constantExp;
2742 exp.isConstant = true;
2747 unsigned char value = 0;
2748 if(GetUChar(exp, &value))
2750 FreeExpContents(exp);
2751 exp.constant = PrintUChar(value);
2752 exp.type = constantExp;
2753 exp.isConstant = true;
2761 if(GetShort(exp, &value))
2763 FreeExpContents(exp);
2764 exp.constant = PrintShort(value);
2765 exp.type = constantExp;
2766 exp.isConstant = true;
2771 unsigned short value = 0;
2772 if(GetUShort(exp, &value))
2774 FreeExpContents(exp);
2775 exp.constant = PrintUShort(value);
2776 exp.type = constantExp;
2777 exp.isConstant = true;
2785 if(GetInt(exp, &value))
2787 FreeExpContents(exp);
2788 exp.constant = PrintInt(value);
2789 exp.type = constantExp;
2790 exp.isConstant = true;
2795 unsigned int value = 0;
2796 if(GetUInt(exp, &value))
2798 FreeExpContents(exp);
2799 exp.constant = PrintUInt(value);
2800 exp.type = constantExp;
2801 exp.isConstant = true;
2809 if(GetInt64(exp, &value))
2811 FreeExpContents(exp);
2812 exp.constant = PrintInt64(value);
2813 exp.type = constantExp;
2814 exp.isConstant = true;
2820 if(GetUInt64(exp, &value))
2822 FreeExpContents(exp);
2823 exp.constant = PrintUInt64(value);
2824 exp.type = constantExp;
2825 exp.isConstant = true;
2833 if(GetUInt64(exp, &value))
2835 FreeExpContents(exp);
2836 if(type.kind == pointerType || type.kind == classType)
2837 exp.constant = PrintHexUInt64(value);
2839 exp.constant = PrintUInt64(value);
2840 exp.type = constantExp;
2841 exp.isConstant = true;
2848 if(exp.type == constantExp && exp.constant &&
2849 (!strcmpi(exp.constant, "nan") ||
2850 !strcmpi(exp.constant, "-nan") ||
2851 !strcmpi(exp.constant, "inf") ||
2852 !strcmpi(exp.constant, "-inf")))
2854 String constant = exp.constant;
2855 exp.constant = null;
2856 FreeExpContents(exp);
2857 exp.constant = constant;
2858 exp.type = constantExp;
2859 exp.isConstant = true;
2861 else if(GetFloat(exp, &value))
2865 float (*convertFn)(float) = (useGet ? (void *)convert.Get : (void *)convert.Set);
2867 value = convertFn(value);
2869 FreeExpContents(exp);
2870 exp.constant = PrintFloat(value);
2871 exp.type = constantExp;
2872 exp.isConstant = true;
2879 if(exp.type == constantExp && exp.constant &&
2880 (!strcmpi(exp.constant, "nan") ||
2881 !strcmpi(exp.constant, "-nan") ||
2882 !strcmpi(exp.constant, "inf") ||
2883 !strcmpi(exp.constant, "-inf")))
2885 String constant = exp.constant;
2886 exp.constant = null;
2887 FreeExpContents(exp);
2888 exp.constant = constant;
2889 exp.type = constantExp;
2890 exp.isConstant = true;
2892 else if(GetDouble(exp, &value))
2896 double (*convertFn)(double) = (useGet ? (void *)convert.Get : (void *)convert.Set);
2898 value = convertFn(value);
2900 FreeExpContents(exp);
2901 exp.constant = PrintDouble(value);
2902 exp.type = constantExp;
2903 exp.isConstant = true;