5 static Map<String, uintptr> oneArgFns
7 { "sqrt", (uintptr)sqrt },
8 { "log", (uintptr)log },
9 { "log10", (uintptr)log10 },
10 { "sin", (uintptr)sin },
11 { "cos", (uintptr)cos },
12 { "tan", (uintptr)tan },
13 { "asin", (uintptr)asin },
14 { "acos", (uintptr)acos },
15 { "atan", (uintptr)atan },
16 { "sinh", (uintptr)sinh },
17 { "cosh", (uintptr)cosh },
18 { "tanh", (uintptr)tanh },
19 { "asinh", (uintptr)asinh },
20 { "acosh", (uintptr)acosh },
21 { "atanh", (uintptr)atanh },
22 { "exp", (uintptr)exp },
23 { "floor", (uintptr)floor },
24 { "ceil", (uintptr)ceil },
25 { "fabs", (uintptr)sqrt }
29 static Map<String, uintptr> twoArgFns
31 { "pow", (uintptr)pow },
32 { "atan2", (uintptr)atan2 },
33 { "fmod", (uintptr)fmod }
36 static void CarryExpressionError(Expression exp, Expression expError)
40 // This function assumes that expError is contained within exp,
41 // and therefore these types will be freed when freeing the old contents
42 // of the expression we're carying into.
44 if(expError.destType) expError.destType.refCount++;
45 if(expError.expType) expError.expType.refCount++;
49 // -- Careful: this could be problematic as FreeExpContents will free the contents of expError
50 // Nulling things that may be freed now, but this is all overly messy/complex
53 case functionCallErrorExp:
54 expError.call.exp = null;
55 expError.call.arguments = null;
58 expError.identifier = null;
61 expError.constant = null;
63 case memberPropertyErrorExp:
64 case memberSymbolErrorExp:
65 expError.member.exp = null;
66 expError.member.member = null;
71 Identifier identifier = expError.identifier;
72 expError.identifier = null;
74 exp.identifier = identifier;
75 exp.type = expError.type;
77 if(exp.expType) FreeType(exp.expType);
78 if(exp.destType) FreeType(exp.destType);
80 *exp = *temp; //*expError;
82 // memset(expError, 0, sizeof(class Expression));
85 static char GetGdbFormatChar(Type type)
87 // x : Regard the bits of the value as an integer, and print the integer in hexadecimal.
88 // d : Print as integer in signed decimal.
89 // u : Print as integer in unsigned decimal.
90 // o : Print as integer in octal.
91 // t : Print as integer in binary. The letter `t' stands for "two". (4)
92 // 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:
93 // 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.
94 // f : Regard the bits of the value as a floating point number and print using typical floating point syntax.
124 // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
134 /*static */bool ExpressionIsError(Expression exp)
136 return (exp.type == dereferenceErrorExp || exp.type == symbolErrorExp ||
137 exp.type == memberSymbolErrorExp || exp.type == memoryErrorExp || exp.type == unknownErrorExp ||
138 exp.type == noDebuggerErrorExp || exp.type == memberPropertyErrorExp || exp.type == functionCallErrorExp || exp.type == divideBy0ErrorExp);
141 void DebugComputeExpression(Expression exp)
144 char expString[1024] = "";
147 PrintExpression(exp, expString);
148 // printf("%s (exp.type = %s)\n", expString, exp.type.OnGetString(temp, null, null));
154 Expression prev = exp.prev, next = exp.next;
155 char * evaluation = null;
156 ExpressionType evalError = dummyExp;
158 TypeKind kind = dummyType;
159 Type dataType = exp.expType;
164 bool isPointer = false;
166 if(dataType && dataType.kind == classType && dataType._class.registered)
168 Class _class = dataType._class.registered;
169 if(_class.type == bitClass || _class.type == unitClass || _class.type == enumClass)
172 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
173 dataType = _class.dataType;
175 else if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass) // Added systemClass here for Instance
180 else if(dataType && dataType.kind == classType && !dataType._class.registered)
183 kind = dataType.kind;
185 exp.type = symbolErrorExp;
189 case intPtrType: case intSizeType: case _BoolType:
190 case charType: case shortType: case intType: case int64Type: case longType: case floatType: case doubleType:
196 sprintf(temp, "&%s", exp.identifier.string);
199 if(exp.byReference && dataType._class && dataType._class.registered && dataType._class.registered.type == structClass)
200 // if(!dataType._class || !dataType._class.registered || dataType._class.registered.type != structClass || exp.byReference)
201 strcpy(temp, exp.identifier.string);
203 sprintf(temp, "&%s", exp.identifier.string);
209 // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
215 evaluation = Debugger::EvaluateExpression(temp, &evalError);
218 address = _strtoui64(evaluation, null, 0);
229 if(evalError == dummyExp)
235 evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
240 temp = strstr(evaluation, " '");
241 //len = strlen(temp);
245 for(c = 0; c < len; c++)
247 eString_TrimRSpaces(evaluation, evaluation);
263 evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
266 if(kind == pointerType)
269 value = _strtoui64(evaluation, null, 0);
271 evaluation = PrintHexUInt64(value);
281 //evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
282 size = ComputeTypeSize(exp.expType); //exp.expType.arrayType.size;
283 format = GetGdbFormatChar(exp.expType);
284 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
286 StripQuotes(evaluation, evaluation);
292 //evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
297 // for classType --> if(_class.type == structClass) ?
299 //sprintf(temp, "&%s", exp.identifier.string);
300 //evaluation = Debugger::EvaluateExpression(temp, &evalError);
306 // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
309 evaluation = Debugger::EvaluateExpression(exp.identifier.string, &evalError);
318 // Going back to parsing the expression string so as to catch inf/-inf/nan/-nan etc.
319 expNew = ParseExpressionString(evaluation);
320 //expNew = MkExpConstant(evaluation);
321 //printf("Evaluation = %s\n", evaluation);
323 expNew.destType = exp.expType;
325 // WHY EXACTLY MUST WE PROCESS THIS EXPRESSION TYPE AGAIN ? ADDED THIS FOR 0x00000000
326 if(exp.expType && (exp.expType.kind == pointerType || exp.expType.kind == classType) && expNew.destType)
328 expNew.expType = expNew.destType;
329 expNew.destType.refCount++;
332 ProcessExpressionType(expNew);
333 FreeType(exp.destType);
334 FreeExpContents(exp);
336 DebugComputeExpression(expNew);
339 expNew.isConstant = true;
340 expNew.address = address;
341 expNew.hasAddress = hasAddress;
347 // Unhandled code path, evaluation is null
348 FreeExpContents(exp);
349 exp.type = unknownErrorExp;
353 // Keep the identifier
354 exp.type = evalError;
357 FreeExpContents(exp);
358 exp.type = evalError;
365 ComputeInstantiation(exp);
374 Expression expError = null;
375 Expression exp1, exp2 = null;
376 Operand op1 = { 0 }, op2 = { 0 };
379 if(exp.op.op == '&' || exp.op.op == '*')
381 if(!exp.op.exp1 && exp.op.exp2)
383 if(exp.op.exp2.type == identifierExp)
385 Expression prev = exp.prev, next = exp.next;
386 char * evaluation = null;
387 ExpressionType evalError = dummyExp;
390 sprintf(temp, "%c%s", exp.op.op, exp.op.exp2.identifier.string);
391 evaluation = Debugger::EvaluateExpression(temp, &evalError);
392 if(evalError != dummyExp)
394 exp.type = evalError;
395 exp.constant = CopyString("");
399 expNew = ParseExpressionString(evaluation);
401 expNew.destType = exp.expType;
402 FreeType(exp.destType);
403 FreeExpContents(exp);
404 ProcessExpressionType(expNew);
405 DebugComputeExpression(expNew);
408 expNew.isConstant = true;
413 exp.type = ExpUnknownError;
423 DebugComputeExpression(exp.op.exp2);
424 size = ComputeTypeSize(exp.op.exp2.expType);
425 format = GetGdbFormatChar(exp.op.exp2.expType);
426 GetInt(exp.op.exp2, &address);
427 //sprintf(temp, "%c%s", exp.op.op, exp.op.exp2.constant);
428 evaluation = Debug_ReadMemory(address, size, format, &evalError);
431 evalError = ExpUnknownError;
437 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
440 Expression e = exp.op.exp2;
442 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
444 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
446 if(e.type == extensionCompoundExp)
447 e = ((Statement)e.compound.compound.statements->last).expressions->last;
452 if(exp.op.op == TokenType::sizeOf && e && e.expType)
454 if(e.type == stringExp && e.string)
456 char * string = e.string;
457 int len = strlen(string);
458 char * tmp = new char[len-2+1];
459 len = UnescapeString(tmp, string + 1, len - 2);
461 FreeExpContents(exp);
462 exp.type = constantExp;
463 exp.constant = PrintUInt(len + 1);
467 Type type = e.expType;
469 FreeExpContents(exp);
470 exp.type = constantExp;
471 exp.constant = PrintUInt(ComputeTypeSize(type));
478 DebugComputeExpression(exp.op.exp2);
479 if(ExpressionIsError(exp.op.exp2))
480 expError = exp.op.exp2;
487 DebugComputeExpression(exp.op.exp1);
488 if(ExpressionIsError(exp.op.exp1))
489 expError = exp.op.exp1;
494 if(ExpressionIsError(exp.op.exp2))
495 expError = exp.op.exp2;
500 op1 = GetOperand(exp1);
501 if(op1.type) op1.type.refCount++;
502 op2 = GetOperand(exp2);
503 if(op2.type) op2.type.refCount++;
510 if(ExpressionIsError(exp.op.exp2))
511 expError = exp.op.exp2;
515 if(exp.op.op == '&' || exp.op.op == '*')
517 Expression prev = exp1.prev, next = exp1.next;
519 ExpressionType evalError = dummyExp;
520 char * evaluation = null;
526 //sprintf(temp, "%u", exp1.address);
527 temp = PrintHexUInt64(exp1.address);
528 expNew = ParseExpressionString(temp);
530 //expNew.address = exp1.address;
531 expNew.expType = exp.expType;
533 expNew.destType = exp.expType;
534 expNew.destType.refCount++;
536 FreeType(exp.destType);
537 FreeExpContents(exp);
538 ProcessExpressionType(expNew);
539 DebugComputeExpression(expNew);
542 expNew.isConstant = true;
549 else if(exp.op.op == '*')
551 // TODO: Common pathway for * and [ ]
555 FreeExpContents(exp1);
556 exp1.type = dereferenceErrorExp;
566 bool gotAddress = false;
568 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
570 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
572 if(e.type == extensionCompoundExp)
573 e = ((Statement)e.compound.compound.statements->last).expressions->last;
577 else if(e.type == castExp)
581 if(e.expType.kind == structType)
583 address = exp1.address;
587 gotAddress = GetUInt64(e, &address);
588 size = ComputeTypeSize(exp.expType); //exp.expType.arrayType.size;
589 if(exp.expType && exp.expType.type && exp.expType.kind == arrayType)
590 // For multilevels arrays
593 format = GetGdbFormatChar(exp.expType);
594 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
596 Expression e1 = e.op.exp1, e2 = e.op.exp2;
597 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
599 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
601 if(e1.type == extensionCompoundExp)
602 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
606 else if(e1.type == castExp)
609 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
611 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
613 if(e2.type == extensionCompoundExp)
614 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
618 else if(e2.type == castExp)
622 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
624 offset += strtol(e.op.exp2.constant, null, 0);
627 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
629 offset += strtol(e.op.exp1.constant, null, 0);
636 if(e.type == stringExp)
639 String string = e.string;
641 Type expType = exp1.expType.type;
642 if(expType) expType.refCount++;
646 int len = string ? strlen(string) : 0;
647 tmp = new char[len-2+1];
648 len = UnescapeString(tmp, string + 1, len - 2);
649 if(len >= 0 && offset * size + size-1 <= len)
653 FreeExpContents(exp);
655 exp.type = dereferenceErrorExp;
658 exp.type = constantExp;
659 exp.isConstant = true;
662 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
663 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
664 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
665 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
666 case floatType: exp.constant = PrintFloat(((float *)tmp)[offset]); break;
667 case doubleType: exp.constant = PrintDouble(((double *)tmp)[offset]); break;
669 exp.type = unknownErrorExp;
673 exp.type = unknownErrorExp;
677 else if(gotAddress && exp.expType.kind == arrayType)
679 FreeExpContents(exp);
680 exp.type = constantExp;
681 exp.isConstant = true;
682 exp.constant = PrintHexUInt64(address);
683 exp.address = address;
684 exp.hasAddress = true;
686 else if(gotAddress && format)
688 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
694 expNew = ParseExpressionString(evaluation);
695 expNew.address = address;
696 expNew.hasAddress = true;
698 expNew.destType = exp.expType;
699 FreeType(exp.destType);
700 FreeExpContents(exp);
701 ProcessExpressionType(expNew);
702 DebugComputeExpression(expNew);
705 expNew.isConstant = true;
711 // Unhandled code path, evaluation is null
712 FreeExpContents(exp);
713 exp.type = unknownErrorExp;
718 FreeExpContents(exp1);
719 exp1.type = evalError;
720 exp1.constant = PrintHexUInt64(address);
725 FreeExpContents(exp1);
726 exp1.type = evalError;
733 FreeExpContents(exp1);
734 exp1.type = unknownErrorExp; // Not supported yet, generate error to fallback to GDB printout
741 op1 = GetOperand(exp1);
742 if(op1.type) op1.type.refCount++;
747 CarryExpressionError(exp, expError);
748 else if(exp.type == opExp)
750 if(exp1 && exp2 && exp1.expType && exp2.expType &&
751 ((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) ||
752 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
755 // TODO: Support 1 + pointer
756 if((exp.op.op == '+' || exp.op.op == '-') && exp2.expType && op2.type && op2.type.kind == intType)
759 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
761 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
763 if(e.type == extensionCompoundExp)
764 e = ((Statement)e.compound.compound.statements->last).expressions->last;
768 else if(e.type == castExp)
772 if(e.type == stringExp)
774 uint64 offset = (exp.op.op == '+') ? op2.i64 : -op2.i64;
775 String newString = null;
778 int len = strlen(e.string) - 2;
779 char * tmp = OffsetEscapedString(e.string + 1, len, (int)offset);
782 len -= tmp - (e.string + 1);
783 newString = new char[2 + len];
785 memcpy(newString + 1, tmp, len);
786 newString[1 + len] = '\"';
787 newString[1 + len + 1] = 0;
791 FreeExpContents(exp);
794 exp.type = stringExp;
795 exp.string = newString;
798 exp.type = dereferenceErrorExp;
802 // TODO: Do pointer operations
803 if(exp1.expType && exp1.expType.type)
805 uint size = ComputeTypeSize(exp1.expType.type);
809 op1.ui64 /= exp1.expType.type.size;
810 CallOperator(exp, exp1, exp2, op1, op2);
811 if(exp.type == constantExp)
813 exp.address = _strtoui64(exp.constant, null, 0);
815 if(op1.type.kind == arrayType)
816 exp.hasAddress = true;
824 FreeExpContents(exp);
825 exp.type = unknownErrorExp; // We should have an invalid operands error
830 if(!exp2 && exp1 && exp1.type == constantExp && exp1.constant && !strcmp(exp1.constant, "nan") && exp.op.op == '-')
832 FreeExpContents(exp);
833 exp.constant = CopyString("-nan");
834 exp.type = constantExp;
838 if((exp.op.op == '/' || exp.op.op == '%') && op2.kind != doubleType && op1.kind != doubleType && op2.kind != floatType && op1.kind != floatType &&
839 (((op2.kind == int64Type || op2.kind == intPtrType || op2.kind == intSizeType) && !op2.i64) ||
840 (op2.kind == intType && !op2.i) || (op2.kind == shortType && !op2.s) || (op2.kind == charType && !op2.c)))
842 FreeExpContents(exp);
843 exp.type = divideBy0ErrorExp;
846 CallOperator(exp, exp1, exp2, op1, op2);
851 if(exp.type == constantExp)
852 exp.isConstant = true;
860 // e = (*exp.list).first, n = e ? e.next : null;
862 // e = n, n = n?(n.next) : null)
864 for(e = exp.list->first; e; e = n)
869 OldList * list = exp.list;
870 DebugComputeExpression(e);
871 //if(ExpressionIsError(e)) //.type == ExpSymbolError
872 // CarryExpressionError(exp, e);
873 //FreeExpContents(exp);
874 FreeType(exp.expType);
875 FreeType(exp.destType);
892 exp.isConstant = true;
894 DebugComputeExpression(exp.index.exp);
895 if(ExpressionIsError(exp.index.exp)) //.type == ExpSymbolError
896 CarryExpressionError(exp, exp.index.exp);
899 Expression prev = exp.prev, next = exp.next;
900 char * evaluation = null;
901 ExpressionType evalError = dummyExp;
903 if(!exp.index.exp.isConstant)
904 exp.isConstant = false;
907 // 4 == size = ComputeTypeSize(exp.expType);
908 // 0 == size = ComputeTypeSize(exp.expType.arrayType);
909 // 4 == size = ComputeTypeSize(exp.index.exp.expType);
910 // 0 == size = ComputeTypeSize(exp.index.exp.expType.arrayType);
912 size = ComputeTypeSize(exp.expType);
913 if(exp.expType && exp.expType.type && exp.expType.kind == arrayType)
914 // For multilevels arrays
917 format = GetGdbFormatChar(exp.expType);
919 for(e = exp.index.index->first; e; e = e.next)
921 DebugComputeExpression(e);
922 if(ExpressionIsError(e)) //.type == ExpSymbolError
924 CarryExpressionError(exp, e);
929 // Check if this type is int
932 exp.isConstant = false;
934 if(!ExpressionIsError(exp))
936 // Is this necessary here? pass15 had done this already...
937 if(exp.expType) FreeType(exp.expType);
938 exp.expType = Dereference(exp.index.exp.expType);
943 FreeExpContents(exp);
944 exp.type = dereferenceErrorExp;
946 else if(exp.index.index && exp.index.index->last && ((Expression)exp.index.index->last) && ((Expression)exp.index.index->last).expType)
948 Type type = ((Expression)exp.index.index->last).expType;
949 if(type.kind == intType || type.kind == charType || type.kind == shortType || type.kind == int64Type || type.kind == intPtrType ||
950 type.kind == intSizeType || type.kind == longType || type.kind == _BoolType || type.kind == enumType ||
951 (type.kind == classType && type._class && type._class.registered &&
952 type._class.registered.type == enumClass))
954 bool gotAddress = false;
955 uint64 address = 0, offset = 0;
956 Expression expNew, last = (Expression)exp.index.index->last;
957 Expression e = exp.index.exp;
959 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
961 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
963 if(e.type == extensionCompoundExp)
964 e = ((Statement)e.compound.compound.statements->last).expressions->last;
968 else if(e.type == castExp)
972 //GetUInt(exp.index.exp, &address);
974 GetUInt64(last, &offset);
976 // TOFIX: Check if it has address: TESTING
977 if(exp.index.exp.hasAddress && exp.index.exp.expType.kind == arrayType)
979 address = exp.index.exp.address;
982 else if(exp.index.exp.type == constantExp)
983 gotAddress = GetUInt64(exp.index.exp, &address);
985 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
987 Expression e1 = e.op.exp1, e2 = e.op.exp2;
988 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
990 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
992 if(e1.type == extensionCompoundExp)
993 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
997 else if(e1.type == castExp)
1000 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1002 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1004 if(e2.type == extensionCompoundExp)
1005 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1009 else if(e2.type == castExp)
1013 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1015 offset += strtol(e.op.exp2.constant, null, 0);
1018 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1020 offset += strtol(e.op.exp1.constant, null, 0);
1027 //size = ComputeTypeSize(exp.expType.arrayType); //exp.expType.arrayType.size;
1028 address += offset * size;
1030 if(e.type == stringExp)
1033 String string = e.string;
1035 Type expType = exp.index.exp.expType.type;
1036 if(expType) expType.refCount++;
1040 int len = string ? strlen(string) : 0;
1041 tmp = new char[len-2+1];
1042 len = UnescapeString(tmp, string + 1, len - 2);
1043 if(len >= 0 && offset * size + size-1 <= len)
1047 FreeExpContents(exp);
1049 exp.type = dereferenceErrorExp;
1052 exp.type = constantExp;
1053 exp.isConstant = true;
1054 switch(expType.kind)
1056 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1057 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1058 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1059 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1060 case floatType: exp.constant = PrintFloat(((float *)tmp)[offset]); break;
1061 case doubleType: exp.constant = PrintDouble(((double *)tmp)[offset]); break;
1063 exp.type = unknownErrorExp;
1067 exp.type = unknownErrorExp;
1071 else if(gotAddress && exp.expType.kind == arrayType)
1073 FreeExpContents(exp);
1074 exp.type = constantExp;
1075 exp.isConstant = true;
1076 exp.constant = PrintHexUInt64(address);
1077 exp.address = address;
1078 exp.hasAddress = true;
1082 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1088 expNew = ParseExpressionString(evaluation);
1090 expNew.destType = exp.expType;
1091 FreeType(exp.destType);
1092 FreeExpContents(exp);
1093 ProcessExpressionType(expNew);
1094 DebugComputeExpression(expNew);
1096 // TOFIX: Only for Array Types
1097 expNew.address = address;
1099 expNew.hasAddress = true;
1102 expNew.isConstant = true;
1108 // Unhandled code path, evaluation is null
1109 FreeExpContents(exp);
1110 exp.type = unknownErrorExp;
1113 case memoryErrorExp:
1115 FreeExpContents(exp);
1116 exp.type = evalError;
1117 exp.constant = PrintHexUInt64(address);
1121 FreeExpContents(exp);
1122 exp.type = evalError;
1128 FreeExpContents(exp);
1129 exp.type = unknownErrorExp;
1139 Expression callExp = exp.call.exp;
1140 Identifier id = (callExp && callExp.type == identifierExp) ? callExp.identifier : null;
1141 bool resolved = false;
1144 if(!strcmp(id.string, "nan") || !strcmp(id.string, "inf"))
1146 String s = id.string;
1148 FreeExpContents(exp);
1149 exp.type = constantExp;
1153 else if(exp.call.arguments)
1155 if(exp.call.arguments->count == 1)
1157 double (* fn1)(double) = (void *)oneArgFns[id.string];
1160 Expression arg = exp.call.arguments->first;
1161 DebugComputeExpression(arg);
1162 if(ExpressionIsError(arg))
1163 CarryExpressionError(exp, arg);
1164 else if(arg.isConstant && arg.type == constantExp)
1167 if(GetDouble(arg, &v))
1169 FreeExpContents(exp);
1170 exp.type = constantExp;
1172 exp.constant = PrintDouble(v);
1173 exp.isConstant = true;
1179 else if(exp.call.arguments->count == 2)
1181 double (* fn2)(double, double) = (void *)twoArgFns[id.string];
1184 Expression arg1 = exp.call.arguments->first;
1185 Expression arg2 = exp.call.arguments->last;
1186 DebugComputeExpression(arg1);
1187 DebugComputeExpression(arg2);
1188 if(ExpressionIsError(arg1))
1189 CarryExpressionError(exp, arg1);
1190 else if(ExpressionIsError(arg2))
1191 CarryExpressionError(exp, arg2);
1192 else if(arg1.isConstant && arg1.type == constantExp && arg2.isConstant && arg2.type == constantExp)
1195 if(GetDouble(arg1, &v1) && GetDouble(arg2, &v2))
1197 FreeExpContents(exp);
1198 exp.type = constantExp;
1200 exp.constant = PrintDouble(v1);
1201 exp.isConstant = true;
1210 exp.type = functionCallErrorExp;
1215 Expression memberExp = exp.member.exp;
1216 Identifier memberID = exp.member.member;
1218 Property prop = null;
1219 DataMember member = null;
1220 Class convertTo = null;
1221 uint offset = 0; // THIS WASN'T INITIALIZED... IS IT ALWAYS SET?
1223 Type type; // = memberExp.expType;
1224 DebugComputeExpression(memberExp);
1225 type = memberExp.expType;
1226 if(ExpressionIsError(memberExp))
1227 CarryExpressionError(exp, memberExp);
1230 // _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
1231 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);
1234 char string[256] = "";
1236 PrintTypeNoConst(type, string, false, true);
1237 classSym = FindClass(string);
1238 _class = classSym ? classSym.registered : null;
1241 if(memberID && _class)
1244 prop = eClass_FindProperty(_class, memberID.string);
1246 member = eClass_FindDataMember(_class, memberID.string);
1248 // member = eClass_FindDataMember(_class, memberID.string);
1249 member = eClass_FindDataMemberAndOffset(_class, memberID.string, &offset, _class.module.application, null, null);
1251 prop = eClass_FindProperty(_class, memberID.string, _class.module.application);
1253 if(!prop && !member && _class && memberID)
1255 Symbol classSym = FindClass(memberID.string);
1257 _class = classSym ? classSym.registered : null;
1259 prop = eClass_FindProperty(_class, convertTo.fullName, _class.module.application);
1262 //DebugComputeExpression(memberExp);
1263 if(ExpressionIsError(memberExp))
1264 CarryExpressionError(exp, memberExp);
1267 if(exp.member.memberType == methodMember)
1269 FreeExpContents(exp);
1270 exp.type = unknownErrorExp;
1274 bool supported = false;
1277 Type type = prop.dataType;
1278 // TODO: Assuming same base type for units...
1279 if(_class.type == unitClass)
1281 if(type.kind == classType)
1283 Class _class = type._class.registered;
1284 if(_class.type == unitClass)
1286 if(!_class.dataType)
1287 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
1288 type = _class.dataType;
1296 float (*Get)(float) = (void *) (convertTo ? prop.Set : prop.Get);
1297 GetFloat(memberExp, &value);
1298 exp.constant = PrintFloat(Get ? Get(value) : value);
1299 exp.type = constantExp;
1300 exp.isConstant = true;
1307 double (*Get)(double) = (void *) (convertTo ? prop.Set : prop.Get);
1308 GetDouble(memberExp, &value);
1309 exp.constant = PrintDouble(Get ? Get(value) : value);
1310 exp.isConstant = true;
1311 exp.type = constantExp;
1321 Expression value = memberExp;
1322 Type type = prop.dataType;
1323 if(_class.type == structClass)
1329 Class propertyClass = type._class.registered;
1330 if(propertyClass.type == structClass && value.type == instanceExp)
1332 void (*Set)(void *, void *) = (void *)prop.Set;
1333 exp.instance = Instantiation
1335 data = new0 byte[_class.structSize];
1336 _class = MkSpecifierName(_class.name);
1339 exp.type = instanceExp;
1341 Set(exp.instance.data, value.instance.data);
1342 PopulateInstance(exp.instance);
1350 void (*Set)(void *, int) = (void *)prop.Set;
1352 exp.instance = Instantiation
1354 data = new0 byte[_class.structSize];
1355 _class = MkSpecifierName/*MkClassName*/(_class.name);
1358 exp.type = instanceExp;
1360 GetInt(value, &intValue);
1362 Set(exp.instance.data, intValue);
1363 PopulateInstance(exp.instance);
1370 void (*Set)(void *, int64) = (void *)prop.Set;
1372 exp.instance = Instantiation
1374 data = new0 byte[_class.structSize];
1375 _class = MkSpecifierName/*MkClassName*/(_class.name);
1378 exp.type = instanceExp;
1380 GetInt64(value, &intValue);
1382 Set(exp.instance.data, intValue);
1383 PopulateInstance(exp.instance);
1390 void (*Set)(void *, double) = (void *)prop.Set;
1392 exp.instance = Instantiation
1394 data = new0 byte[_class.structSize];
1395 _class = MkSpecifierName/*MkClassName*/(_class.name);
1398 exp.type = instanceExp;
1400 GetDouble(value, &doubleValue);
1402 Set(exp.instance.data, doubleValue);
1403 PopulateInstance(exp.instance);
1409 else if(_class.type == bitClass)
1415 Class propertyClass = type._class.registered;
1416 if(propertyClass.type == structClass && value.instance.data)
1418 unsigned int (*Set)(void *) = (void *)prop.Set;
1419 unsigned int bits = Set(value.instance.data);
1420 exp.constant = PrintHexUInt(bits);
1421 exp.type = constantExp;
1425 else if(_class.type == bitClass)
1428 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
1431 GetUInt(memberExp, &value);
1433 exp.constant = PrintHexUInt(bits);
1434 exp.type = constantExp;
1443 if(_class.type == bitClass)
1446 GetUInt(memberExp, &value);
1452 Class _class = type._class.registered;
1453 if(_class.type == structClass)
1455 void (*Get)(unsigned int, void *) = (void *)prop.Get;
1457 exp.instance = Instantiation
1459 data = new0 byte[_class.structSize];
1460 _class = MkSpecifierName/*MkClassName*/(_class.name);
1463 //exp.instance.fullSet = true;
1464 exp.type = instanceExp;
1465 Get(value, exp.instance.data);
1466 PopulateInstance(exp.instance);
1469 else if(_class.type == bitClass)
1471 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
1472 uint64 bits = Get(value);
1473 exp.constant = PrintHexUInt64(bits);
1474 exp.type = constantExp;
1481 else if(_class.type == structClass)
1483 char * value = (memberExp.type == instanceExp ) ? memberExp.instance.data : null;
1488 Class _class = type._class.registered;
1489 if(_class.type == structClass && value)
1491 void (*Get)(void *, void *) = (void *)prop.Get;
1493 exp.instance = Instantiation
1495 data = new0 byte[_class.structSize];
1496 _class = MkSpecifierName/*MkClassName*/(_class.name);
1499 //exp.instance.fullSet = true;
1500 exp.type = instanceExp;
1501 Get(value, exp.instance.data);
1502 PopulateInstance(exp.instance);
1511 char * value = memberExp.instance.data;
1516 Class _class = type._class.registered;
1517 if(_class.type == normalClass)
1519 void *(*Get)(void *) = (void *)prop.Get;
1521 exp.instance = Instantiation
1523 data = Get(value, exp.instance.data); ?????
1524 _class = MkSpecifierName(_class.name); //MkClassName(_class.name);
1527 exp.type = instanceExp;
1539 exp.type = memberPropertyErrorExp;
1540 exp.isConstant = false;
1545 if(memberExp.hasAddress || memberExp.type == constantExp)
1546 //if(memberExp.expType && memberExp.expType.kind == intType) // && !exp.index.exp.expType.isSigned
1548 if(_class.type == bitClass)
1550 if(memberExp.type == constantExp)
1552 // Unfinished business...
1553 BitMember bitMember = (BitMember)member;
1555 GetUInt64(memberExp, &bits);
1556 bits &= bitMember.mask;
1557 bits >>= bitMember.pos;
1559 FreeExpression(exp.member.exp);
1560 FreeIdentifier(exp.member.member);
1562 exp.constant = PrintUInt64(bits);
1564 exp.isConstant = true;
1565 exp.type = constantExp;
1566 exp.hasAddress = false;
1571 char * evaluation = null;
1572 ExpressionType evalError = dummyExp;
1573 bool gotAddress = false;
1575 Expression prev = exp.prev, next = exp.next;
1579 TypeKind kind = dummyType;
1580 Type dataType = member.dataType;
1583 dataType = member.dataType = ProcessTypeString(member.dataTypeString, false);
1585 if(dataType.kind == classType && dataType._class.registered &&
1586 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
1588 if(dataType._class.registered.dataTypeString)
1589 dataType._class.registered.dataType = ProcessTypeString(dataType._class.registered.dataTypeString, false);
1590 dataType = dataType._class.registered.dataType;
1592 dataType = ProcessTypeString("int", false);
1595 size = ComputeTypeSize(member.dataType);
1597 format = GetGdbFormatChar(dataType);
1598 //if(memberExp.address)
1600 //GetInt(memberExp, &address);
1601 //offset = member.offset;
1603 // TESTING NOHEAD HERE?
1604 if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass)
1605 offset += member._class.offset;
1607 // VERIFY THIS: (trying to fix primitive.type)
1608 // if(memberExp.type == constantExp)
1609 if(memberExp.hasAddress && (_class.type != normalClass && _class.type != noHeadClass && _class.type != systemClass))
1611 address = memberExp.address;
1614 else if(memberExp.type == constantExp)
1615 gotAddress = GetUInt64(memberExp, &address);
1618 gotAddress = GetUInt64(memberExp, &address);
1619 //printf("Unhandled !!\n");
1621 //printf("memberExp.hasAddress = %d\n", memberExp.hasAddress);
1622 //printf("memberExp.type = %d\n", memberExp.type);
1623 //printf("_class.name = %s, _class.type = %d\n", _class.name, _class.type);
1629 exp.type = unknownErrorExp;
1630 else if((dataType.kind == classType && dataType._class &&
1631 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
1632 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
1634 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1635 if(evalError != dummyExp)
1637 exp.type = evalError;
1638 exp.constant = PrintHexUInt64(address);
1642 //printf("evaluation = %s\n", evaluation);
1643 expNew = ParseExpressionString(evaluation);
1645 expNew.destType = exp.expType;
1647 exp.expType.refCount++;
1648 //FreeType(memberExp.destType);
1649 FreeType(exp.expType);
1650 FreeType(exp.destType);
1651 FreeExpContents(exp);
1652 ProcessExpressionType(expNew);
1653 DebugComputeExpression(expNew);
1656 expNew.isConstant = true;
1657 expNew.address = address;
1658 expNew.hasAddress = true;
1664 FreeExpContents(exp);
1665 exp.type = unknownErrorExp;
1670 // TESTING THIS HERE...
1671 exp.type = constantExp;
1672 exp.constant = PrintHexUInt64(address);
1674 exp.address = address;
1675 exp.hasAddress = true;
1676 exp.isConstant = true;
1681 // exp.type = ExpUnknownError;
1683 //FreeExpContents(exp);
1684 //exp.constant = PrintUInt64(value);
1685 //exp.type = constantExp;
1690 if(type && (type.kind == structType || type.kind == unionType))
1693 Type memberType = exp.member.member ? FindMemberAndOffset(type, exp.member.member.string, &offset) : null;
1696 char * evaluation = null;
1697 ExpressionType evalError = dummyExp;
1699 bool gotAddress = false;
1700 Expression prev = exp.prev, next = exp.next;
1702 int size = memberType.size;
1704 Type dataType = memberType;
1705 TypeKind kind = dummyType;
1707 if(dataType.kind == classType && dataType._class.registered &&
1708 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
1709 dataType = dataType._class.registered.dataType;
1711 format = GetGdbFormatChar(dataType);
1713 if(memberExp.hasAddress)
1715 address = memberExp.address;
1718 else if(memberExp.type == constantExp)
1719 gotAddress = GetUInt64(memberExp, &address);
1725 FreeExpContents(exp);
1726 exp.type = unknownErrorExp;
1728 else if((dataType.kind == classType && dataType._class &&
1729 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
1730 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
1732 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1733 if(evalError != dummyExp)
1735 exp.type = evalError;
1736 exp.constant = PrintHexUInt64(address);
1740 expNew = ParseExpressionString(evaluation);
1742 expNew.destType = exp.expType;
1744 exp.expType.refCount++;
1745 //FreeType(memberExp.destType);
1746 FreeType(exp.expType);
1747 FreeType(exp.destType);
1748 FreeExpContents(exp);
1749 ProcessExpressionType(expNew);
1750 DebugComputeExpression(expNew);
1753 expNew.isConstant = true;
1754 expNew.address = address;
1755 expNew.hasAddress = true;
1761 FreeExpContents(exp);
1762 exp.type = unknownErrorExp;
1767 FreeExpContents(exp);
1769 // TESTING THIS HERE...
1770 exp.type = constantExp;
1771 exp.constant = PrintHexUInt64(address);
1773 exp.address = address;
1774 exp.hasAddress = true;
1775 exp.isConstant = true;
1779 exp.type = memberSymbolErrorExp;
1782 exp.type = memberSymbolErrorExp;
1786 //if(exp.type != memberExp)
1788 //FreeExpression(memberExp);
1789 //FreeIdentifier(memberID);
1794 exp.type = memberSymbolErrorExp;
1800 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
1801 FreeExpContents(exp);
1802 exp.constant = PrintUInt(ComputeTypeSize(type));
1803 exp.type = constantExp;
1809 Symbol classSym = FindClass(exp._class.name);
1810 if(classSym && classSym.registered)
1812 //exp.constant = PrintUInt(classSym.registered.size);
1813 //exp.type = constantExp;
1815 char className[1024];
1816 sprintf(className, "__ecereClass_%s", classSym.string);
1817 FreeExpContents(exp);
1818 exp.type = pointerExp;
1819 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
1820 exp.member.member = MkIdentifier("size");
1826 DebugComputeExpression(exp.cast.exp);
1828 if(ExpressionIsError(exp.cast.exp)) //.type == ExpSymbolError
1829 CarryExpressionError(exp, exp.cast.exp);
1832 exp.hasAddress = exp.cast.exp.hasAddress;
1833 exp.address = exp.cast.exp.address;
1834 if(exp.cast.exp.type == constantExp && exp.expType)
1836 Type type = exp.expType;
1837 if(type.kind == classType && type._class && type._class.registered)
1839 Class _class = type._class.registered;
1840 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
1842 if(!_class.dataType)
1843 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
1844 type = _class.dataType;
1846 else if(_class.type == structClass && !type.byReference)
1848 FreeExpContents(exp);
1849 exp.type = unknownErrorExp;
1860 if(GetChar(exp.cast.exp, &value))
1862 FreeExpContents(exp);
1863 exp.constant = PrintChar(value);
1864 exp.type = constantExp;
1865 exp.isConstant = true;
1870 unsigned char value = 0;
1871 if(GetUChar(exp.cast.exp, &value))
1873 FreeExpContents(exp);
1874 exp.constant = PrintUChar(value);
1875 exp.type = constantExp;
1876 exp.isConstant = true;
1884 if(GetShort(exp.cast.exp, &value))
1886 FreeExpContents(exp);
1887 exp.constant = PrintShort(value);
1888 exp.type = constantExp;
1889 exp.isConstant = true;
1894 unsigned short value = 0;
1895 if(GetUShort(exp.cast.exp, &value))
1897 FreeExpContents(exp);
1898 exp.constant = PrintUShort(value);
1899 exp.type = constantExp;
1900 exp.isConstant = true;
1908 if(GetInt(exp.cast.exp, &value))
1910 FreeExpContents(exp);
1911 exp.constant = PrintInt(value);
1912 exp.type = constantExp;
1913 exp.isConstant = true;
1918 unsigned int value = 0;
1919 if(GetUInt(exp.cast.exp, &value))
1921 FreeExpContents(exp);
1922 exp.constant = PrintUInt(value);
1923 exp.type = constantExp;
1924 exp.isConstant = true;
1932 if(GetInt64(exp.cast.exp, &value))
1934 FreeExpContents(exp);
1935 exp.constant = PrintInt64(value);
1936 exp.type = constantExp;
1937 exp.isConstant = true;
1943 if(GetUInt64(exp.cast.exp, &value))
1945 FreeExpContents(exp);
1946 exp.constant = PrintUInt64(value);
1947 exp.type = constantExp;
1948 exp.isConstant = true;
1956 if(GetUInt64(exp.cast.exp, &value))
1958 FreeExpContents(exp);
1959 if(type.kind == pointerType || type.kind == classType)
1960 exp.constant = PrintHexUInt64(value);
1962 exp.constant = PrintUInt64(value);
1963 exp.type = constantExp;
1964 exp.isConstant = true;
1971 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
1972 (!strcmpi(exp.cast.exp.constant, "nan") ||
1973 !strcmpi(exp.cast.exp.constant, "-nan") ||
1974 !strcmpi(exp.cast.exp.constant, "inf") ||
1975 !strcmpi(exp.cast.exp.constant, "-inf")))
1977 String constant = exp.cast.exp.constant;
1978 exp.cast.exp.constant = null;
1979 FreeExpContents(exp);
1980 exp.constant = constant;
1981 exp.type = constantExp;
1982 exp.isConstant = true;
1984 else if(GetFloat(exp.cast.exp, &value))
1986 FreeExpContents(exp);
1987 exp.constant = PrintFloat(value);
1988 exp.type = constantExp;
1989 exp.isConstant = true;
1996 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
1997 (!strcmpi(exp.cast.exp.constant, "nan") ||
1998 !strcmpi(exp.cast.exp.constant, "-nan") ||
1999 !strcmpi(exp.cast.exp.constant, "inf") ||
2000 !strcmpi(exp.cast.exp.constant, "-inf")))
2002 String constant = exp.cast.exp.constant;
2003 exp.cast.exp.constant = null;
2004 FreeExpContents(exp);
2005 exp.constant = constant;
2006 exp.type = constantExp;
2007 exp.isConstant = true;
2009 else if(GetDouble(exp.cast.exp, &value))
2011 FreeExpContents(exp);
2012 exp.constant = PrintDouble(value);
2013 exp.type = constantExp;
2014 exp.isConstant = true;
2027 DebugComputeExpression(exp.cond.cond);
2029 if(ExpressionIsError(exp.cond.cond))
2030 CarryExpressionError(exp, exp.cond.cond);
2031 else if(exp.cond.cond.type == constantExp && exp.cond.cond.constant)
2033 Expression e = null;
2034 if(strtol(exp.cond.cond.constant, null, 0))
2036 for(e = exp.cond.exp ? exp.cond.exp->first : null; e; e = e.next)
2038 DebugComputeExpression(e);
2043 if(ExpressionIsError(e))
2045 CarryExpressionError(exp, e);
2049 exp.cond.exp->Remove(e);
2054 e = exp.cond.elseExp;
2057 DebugComputeExpression(e);
2058 if(ExpressionIsError(e))
2060 CarryExpressionError(exp, e);
2064 exp.cond.elseExp = null;
2069 FreeType(exp.expType);
2070 FreeType(exp.destType);
2073 FreeExpContents(exp);
2077 else if(!ExpressionIsError(exp))
2079 FreeExpContents(exp);
2080 exp.type = unknownErrorExp;
2085 FreeExpContents(exp);
2086 exp.type = unknownErrorExp;
2091 FreeExpContents(exp);
2092 exp.type = unknownErrorExp;