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);
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;
837 CallOperator(exp, exp1, exp2, op1, op2);
841 if(exp.type == constantExp)
842 exp.isConstant = true;
850 // e = (*exp.list).first, n = e ? e.next : null;
852 // e = n, n = n?(n.next) : null)
854 for(e = exp.list->first; e; e = n)
859 OldList * list = exp.list;
860 DebugComputeExpression(e);
861 //if(ExpressionIsError(e)) //.type == ExpSymbolError
862 // CarryExpressionError(exp, e);
863 //FreeExpContents(exp);
864 FreeType(exp.expType);
865 FreeType(exp.destType);
882 exp.isConstant = true;
884 DebugComputeExpression(exp.index.exp);
885 if(ExpressionIsError(exp.index.exp)) //.type == ExpSymbolError
886 CarryExpressionError(exp, exp.index.exp);
889 Expression prev = exp.prev, next = exp.next;
890 char * evaluation = null;
891 ExpressionType evalError = dummyExp;
893 if(!exp.index.exp.isConstant)
894 exp.isConstant = false;
897 // 4 == size = ComputeTypeSize(exp.expType);
898 // 0 == size = ComputeTypeSize(exp.expType.arrayType);
899 // 4 == size = ComputeTypeSize(exp.index.exp.expType);
900 // 0 == size = ComputeTypeSize(exp.index.exp.expType.arrayType);
902 size = ComputeTypeSize(exp.expType);
903 if(exp.expType && exp.expType.type && exp.expType.kind == arrayType)
904 // For multilevels arrays
907 format = GetGdbFormatChar(exp.expType);
909 for(e = exp.index.index->first; e; e = e.next)
911 DebugComputeExpression(e);
912 if(ExpressionIsError(e)) //.type == ExpSymbolError
914 CarryExpressionError(exp, e);
919 // Check if this type is int
922 exp.isConstant = false;
924 if(!ExpressionIsError(exp))
926 // Is this necessary here? pass15 had done this already...
927 if(exp.expType) FreeType(exp.expType);
928 exp.expType = Dereference(exp.index.exp.expType);
933 FreeExpContents(exp);
934 exp.type = dereferenceErrorExp;
936 else if(exp.index.index && exp.index.index->last && ((Expression)exp.index.index->last) && ((Expression)exp.index.index->last).expType)
938 Type type = ((Expression)exp.index.index->last).expType;
939 if(type.kind == intType || type.kind == charType || type.kind == shortType || type.kind == int64Type || type.kind == intPtrType ||
940 type.kind == intSizeType || type.kind == longType || type.kind == _BoolType || type.kind == enumType ||
941 (type.kind == classType && type._class && type._class.registered &&
942 type._class.registered.type == enumClass))
944 bool gotAddress = false;
945 uint64 address = 0, offset = 0;
946 Expression expNew, last = (Expression)exp.index.index->last;
947 Expression e = exp.index.exp;
949 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
951 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
953 if(e.type == extensionCompoundExp)
954 e = ((Statement)e.compound.compound.statements->last).expressions->last;
958 else if(e.type == castExp)
962 //GetUInt(exp.index.exp, &address);
964 GetUInt64(last, &offset);
966 // TOFIX: Check if it has address: TESTING
967 if(exp.index.exp.hasAddress && exp.index.exp.expType.kind == arrayType)
969 address = exp.index.exp.address;
972 else if(exp.index.exp.type == constantExp)
973 gotAddress = GetUInt64(exp.index.exp, &address);
975 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
977 Expression e1 = e.op.exp1, e2 = e.op.exp2;
978 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
980 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
982 if(e1.type == extensionCompoundExp)
983 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
987 else if(e1.type == castExp)
990 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
992 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
994 if(e2.type == extensionCompoundExp)
995 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
999 else if(e2.type == castExp)
1003 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1005 offset += strtol(e.op.exp2.constant, null, 0);
1008 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1010 offset += strtol(e.op.exp1.constant, null, 0);
1017 //size = ComputeTypeSize(exp.expType.arrayType); //exp.expType.arrayType.size;
1018 address += offset * size;
1020 if(e.type == stringExp)
1023 String string = e.string;
1025 Type expType = exp.index.exp.expType.type;
1026 if(expType) expType.refCount++;
1030 int len = string ? strlen(string) : 0;
1031 tmp = new char[len-2+1];
1032 len = UnescapeString(tmp, string + 1, len - 2);
1033 if(len >= 0 && offset * size + size-1 <= len)
1037 FreeExpContents(exp);
1039 exp.type = dereferenceErrorExp;
1042 exp.type = constantExp;
1043 exp.isConstant = true;
1044 switch(expType.kind)
1046 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1047 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1048 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1049 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1050 case floatType: exp.constant = PrintFloat(((float *)tmp)[offset]); break;
1051 case doubleType: exp.constant = PrintDouble(((double *)tmp)[offset]); break;
1053 exp.type = unknownErrorExp;
1057 exp.type = unknownErrorExp;
1061 else if(gotAddress && exp.expType.kind == arrayType)
1063 FreeExpContents(exp);
1064 exp.type = constantExp;
1065 exp.isConstant = true;
1066 exp.constant = PrintHexUInt64(address);
1067 exp.address = address;
1068 exp.hasAddress = true;
1072 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1078 expNew = ParseExpressionString(evaluation);
1080 expNew.destType = exp.expType;
1081 FreeType(exp.destType);
1082 FreeExpContents(exp);
1083 ProcessExpressionType(expNew);
1084 DebugComputeExpression(expNew);
1086 // TOFIX: Only for Array Types
1087 expNew.address = address;
1089 expNew.hasAddress = true;
1092 expNew.isConstant = true;
1098 // Unhandled code path, evaluation is null
1099 FreeExpContents(exp);
1100 exp.type = unknownErrorExp;
1103 case memoryErrorExp:
1105 FreeExpContents(exp);
1106 exp.type = evalError;
1107 exp.constant = PrintHexUInt64(address);
1111 FreeExpContents(exp);
1112 exp.type = evalError;
1118 FreeExpContents(exp);
1119 exp.type = unknownErrorExp;
1129 Expression callExp = exp.call.exp;
1130 Identifier id = (callExp && callExp.type == identifierExp) ? callExp.identifier : null;
1131 bool resolved = false;
1134 if(!strcmp(id.string, "nan") || !strcmp(id.string, "inf"))
1136 String s = id.string;
1138 FreeExpContents(exp);
1139 exp.type = constantExp;
1143 else if(exp.call.arguments)
1145 if(exp.call.arguments->count == 1)
1147 double (* fn1)(double) = (void *)oneArgFns[id.string];
1150 Expression arg = exp.call.arguments->first;
1151 DebugComputeExpression(arg);
1152 if(ExpressionIsError(arg))
1153 CarryExpressionError(exp, arg);
1154 else if(arg.isConstant && arg.type == constantExp)
1157 if(GetDouble(arg, &v))
1159 FreeExpContents(exp);
1160 exp.type = constantExp;
1162 exp.constant = PrintDouble(v);
1163 exp.isConstant = true;
1169 else if(exp.call.arguments->count == 2)
1171 double (* fn2)(double, double) = (void *)twoArgFns[id.string];
1174 Expression arg1 = exp.call.arguments->first;
1175 Expression arg2 = exp.call.arguments->last;
1176 DebugComputeExpression(arg1);
1177 DebugComputeExpression(arg2);
1178 if(ExpressionIsError(arg1))
1179 CarryExpressionError(exp, arg1);
1180 else if(ExpressionIsError(arg2))
1181 CarryExpressionError(exp, arg2);
1182 else if(arg1.isConstant && arg1.type == constantExp && arg2.isConstant && arg2.type == constantExp)
1185 if(GetDouble(arg1, &v1) && GetDouble(arg2, &v2))
1187 FreeExpContents(exp);
1188 exp.type = constantExp;
1190 exp.constant = PrintDouble(v1);
1191 exp.isConstant = true;
1200 exp.type = functionCallErrorExp;
1205 Expression memberExp = exp.member.exp;
1206 Identifier memberID = exp.member.member;
1208 Property prop = null;
1209 DataMember member = null;
1210 Class convertTo = null;
1211 uint offset = 0; // THIS WASN'T INITIALIZED... IS IT ALWAYS SET?
1213 Type type; // = memberExp.expType;
1214 DebugComputeExpression(memberExp);
1215 type = memberExp.expType;
1216 if(ExpressionIsError(memberExp))
1217 CarryExpressionError(exp, memberExp);
1220 // _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
1221 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);
1224 char string[256] = "";
1226 PrintTypeNoConst(type, string, false, true);
1227 classSym = FindClass(string);
1228 _class = classSym ? classSym.registered : null;
1231 if(memberID && _class)
1234 prop = eClass_FindProperty(_class, memberID.string);
1236 member = eClass_FindDataMember(_class, memberID.string);
1238 // member = eClass_FindDataMember(_class, memberID.string);
1239 member = eClass_FindDataMemberAndOffset(_class, memberID.string, &offset, _class.module.application, null, null);
1241 prop = eClass_FindProperty(_class, memberID.string, _class.module.application);
1243 if(!prop && !member && _class && memberID)
1245 Symbol classSym = FindClass(memberID.string);
1247 _class = classSym ? classSym.registered : null;
1249 prop = eClass_FindProperty(_class, convertTo.name, _class.module.application);
1252 //DebugComputeExpression(memberExp);
1253 if(ExpressionIsError(memberExp))
1254 CarryExpressionError(exp, memberExp);
1257 if(exp.member.memberType == methodMember)
1259 FreeExpContents(exp);
1260 exp.type = unknownErrorExp;
1264 bool supported = false;
1267 Type type = prop.dataType;
1268 // TODO: Assuming same base type for units...
1269 if(_class.type == unitClass)
1271 if(type.kind == classType)
1273 Class _class = type._class.registered;
1274 if(_class.type == unitClass)
1276 if(!_class.dataType)
1277 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
1278 type = _class.dataType;
1286 float (*Get)(float) = (void *)prop.Get;
1287 GetFloat(memberExp, &value);
1288 exp.constant = PrintFloat(Get ? Get(value) : value);
1289 exp.type = constantExp;
1296 double (*Get)(double);
1297 GetDouble(memberExp, &value);
1300 Get = (void *)prop.Set;
1302 Get = (void *)prop.Get;
1303 exp.constant = PrintDouble(Get ? Get(value) : value);
1304 exp.type = constantExp;
1314 Expression value = memberExp;
1315 Type type = prop.dataType;
1316 if(_class.type == structClass)
1322 Class propertyClass = type._class.registered;
1323 if(propertyClass.type == structClass && value.type == instanceExp)
1325 void (*Set)(void *, void *) = (void *)prop.Set;
1326 exp.instance = Instantiation
1328 data = new0 byte[_class.structSize];
1329 _class = MkSpecifierName/*MkClassName*/(_class.name);
1331 exp.type = instanceExp;
1333 Set(exp.instance.data, value.instance.data);
1334 PopulateInstance(exp.instance);
1342 void (*Set)(void *, int) = (void *)prop.Set;
1344 exp.instance = Instantiation
1346 data = new0 byte[_class.structSize];
1347 _class = MkSpecifierName/*MkClassName*/(_class.name);
1350 exp.type = instanceExp;
1352 GetInt(value, &intValue);
1354 Set(exp.instance.data, intValue);
1355 PopulateInstance(exp.instance);
1362 void (*Set)(void *, int64) = (void *)prop.Set;
1364 exp.instance = Instantiation
1366 data = new0 byte[_class.structSize];
1367 _class = MkSpecifierName/*MkClassName*/(_class.name);
1370 exp.type = instanceExp;
1372 GetInt64(value, &intValue);
1374 Set(exp.instance.data, intValue);
1375 PopulateInstance(exp.instance);
1382 void (*Set)(void *, double) = (void *)prop.Set;
1384 exp.instance = Instantiation
1386 data = new0 byte[_class.structSize];
1387 _class = MkSpecifierName/*MkClassName*/(_class.name);
1390 exp.type = instanceExp;
1392 GetDouble(value, &doubleValue);
1394 Set(exp.instance.data, doubleValue);
1395 PopulateInstance(exp.instance);
1401 else if(_class.type == bitClass)
1407 Class propertyClass = type._class.registered;
1408 if(propertyClass.type == structClass && value.instance.data)
1410 unsigned int (*Set)(void *) = (void *)prop.Set;
1411 unsigned int bits = Set(value.instance.data);
1412 exp.constant = PrintHexUInt(bits);
1413 exp.type = constantExp;
1417 else if(_class.type == bitClass)
1420 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
1423 GetUInt(memberExp, &value);
1425 exp.constant = PrintHexUInt(bits);
1426 exp.type = constantExp;
1435 if(_class.type == bitClass)
1438 GetUInt(memberExp, &value);
1444 Class _class = type._class.registered;
1445 if(_class.type == structClass)
1447 void (*Get)(unsigned int, void *) = (void *)prop.Get;
1449 exp.instance = Instantiation
1451 data = new0 byte[_class.structSize];
1452 _class = MkSpecifierName/*MkClassName*/(_class.name);
1455 //exp.instance.fullSet = true;
1456 exp.type = instanceExp;
1457 Get(value, exp.instance.data);
1458 PopulateInstance(exp.instance);
1461 else if(_class.type == bitClass)
1463 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
1464 uint64 bits = Get(value);
1465 exp.constant = PrintHexUInt64(bits);
1466 exp.type = constantExp;
1473 else if(_class.type == structClass)
1475 char * value = (memberExp.type == instanceExp ) ? memberExp.instance.data : null;
1480 Class _class = type._class.registered;
1481 if(_class.type == structClass && value)
1483 void (*Get)(void *, void *) = (void *)prop.Get;
1485 exp.instance = Instantiation
1487 data = new0 byte[_class.structSize];
1488 _class = MkSpecifierName/*MkClassName*/(_class.name);
1491 //exp.instance.fullSet = true;
1492 exp.type = instanceExp;
1493 Get(value, exp.instance.data);
1494 PopulateInstance(exp.instance);
1503 char * value = memberExp.instance.data;
1508 Class _class = type._class.registered;
1509 if(_class.type == normalClass)
1511 void *(*Get)(void *) = (void *)prop.Get;
1513 exp.instance = Instantiation
1515 data = Get(value, exp.instance.data); ?????
1516 _class = MkSpecifierName(_class.name); //MkClassName(_class.name);
1519 exp.type = instanceExp;
1531 exp.type = memberPropertyErrorExp;
1532 exp.isConstant = false;
1537 if(memberExp.hasAddress || memberExp.type == constantExp)
1538 //if(memberExp.expType && memberExp.expType.kind == intType) // && !exp.index.exp.expType.isSigned
1540 if(_class.type == bitClass)
1542 if(memberExp.type == constantExp)
1544 // Unfinished business...
1545 BitMember bitMember = (BitMember)member;
1547 GetUInt64(memberExp, &bits);
1548 bits &= bitMember.mask;
1549 bits >>= bitMember.pos;
1551 FreeExpression(exp.member.exp);
1552 FreeIdentifier(exp.member.member);
1554 exp.constant = PrintUInt64(bits);
1556 exp.isConstant = true;
1557 exp.type = constantExp;
1558 exp.hasAddress = false;
1563 char * evaluation = null;
1564 ExpressionType evalError = dummyExp;
1565 bool gotAddress = false;
1567 Expression prev = exp.prev, next = exp.next;
1571 TypeKind kind = dummyType;
1572 Type dataType = member.dataType;
1575 dataType = member.dataType = ProcessTypeString(member.dataTypeString, false);
1577 if(dataType.kind == classType && dataType._class.registered &&
1578 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
1580 if(dataType._class.registered.dataTypeString)
1581 dataType._class.registered.dataType = ProcessTypeString(dataType._class.registered.dataTypeString, false);
1582 dataType = dataType._class.registered.dataType;
1584 dataType = ProcessTypeString("int", false);
1587 size = ComputeTypeSize(member.dataType);
1589 format = GetGdbFormatChar(dataType);
1590 //if(memberExp.address)
1592 //GetInt(memberExp, &address);
1593 //offset = member.offset;
1595 // TESTING NOHEAD HERE?
1596 if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass)
1597 offset += member._class.offset;
1599 // VERIFY THIS: (trying to fix primitive.type)
1600 // if(memberExp.type == constantExp)
1601 if(memberExp.hasAddress && (_class.type != normalClass && _class.type != noHeadClass && _class.type != systemClass))
1603 address = memberExp.address;
1606 else if(memberExp.type == constantExp)
1607 gotAddress = GetUInt64(memberExp, &address);
1610 gotAddress = GetUInt64(memberExp, &address);
1611 //printf("Unhandled !!\n");
1613 //printf("memberExp.hasAddress = %d\n", memberExp.hasAddress);
1614 //printf("memberExp.type = %d\n", memberExp.type);
1615 //printf("_class.name = %s, _class.type = %d\n", _class.name, _class.type);
1621 exp.type = unknownErrorExp;
1622 else if((dataType.kind == classType && dataType._class &&
1623 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
1624 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
1626 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1627 if(evalError != dummyExp)
1629 exp.type = evalError;
1630 exp.constant = PrintHexUInt64(address);
1634 //printf("evaluation = %s\n", evaluation);
1635 expNew = ParseExpressionString(evaluation);
1637 expNew.destType = exp.expType;
1639 exp.expType.refCount++;
1640 //FreeType(memberExp.destType);
1641 FreeType(exp.expType);
1642 FreeType(exp.destType);
1643 FreeExpContents(exp);
1644 ProcessExpressionType(expNew);
1645 DebugComputeExpression(expNew);
1648 expNew.isConstant = true;
1649 expNew.address = address;
1650 expNew.hasAddress = true;
1656 FreeExpContents(exp);
1657 exp.type = unknownErrorExp;
1662 // TESTING THIS HERE...
1663 exp.type = constantExp;
1664 exp.constant = PrintHexUInt64(address);
1666 exp.address = address;
1667 exp.hasAddress = true;
1668 exp.isConstant = true;
1673 // exp.type = ExpUnknownError;
1675 //FreeExpContents(exp);
1676 //exp.constant = PrintUInt64(value);
1677 //exp.type = constantExp;
1682 if(type && (type.kind == structType || type.kind == unionType))
1685 Type memberType = exp.member.member ? FindMemberAndOffset(type, exp.member.member.string, &offset) : null;
1688 char * evaluation = null;
1689 ExpressionType evalError = dummyExp;
1691 bool gotAddress = false;
1692 Expression prev = exp.prev, next = exp.next;
1694 int size = memberType.size;
1696 Type dataType = memberType;
1697 TypeKind kind = dummyType;
1699 if(dataType.kind == classType && dataType._class.registered &&
1700 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
1701 dataType = dataType._class.registered.dataType;
1703 format = GetGdbFormatChar(dataType);
1705 if(memberExp.hasAddress)
1707 address = memberExp.address;
1710 else if(memberExp.type == constantExp)
1711 gotAddress = GetUInt64(memberExp, &address);
1717 FreeExpContents(exp);
1718 exp.type = unknownErrorExp;
1720 else if((dataType.kind == classType && dataType._class &&
1721 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
1722 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
1724 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1725 if(evalError != dummyExp)
1727 exp.type = evalError;
1728 exp.constant = PrintHexUInt64(address);
1732 expNew = ParseExpressionString(evaluation);
1734 expNew.destType = exp.expType;
1736 exp.expType.refCount++;
1737 //FreeType(memberExp.destType);
1738 FreeType(exp.expType);
1739 FreeType(exp.destType);
1740 FreeExpContents(exp);
1741 ProcessExpressionType(expNew);
1742 DebugComputeExpression(expNew);
1745 expNew.isConstant = true;
1746 expNew.address = address;
1747 expNew.hasAddress = true;
1753 FreeExpContents(exp);
1754 exp.type = unknownErrorExp;
1759 FreeExpContents(exp);
1761 // TESTING THIS HERE...
1762 exp.type = constantExp;
1763 exp.constant = PrintHexUInt64(address);
1765 exp.address = address;
1766 exp.hasAddress = true;
1767 exp.isConstant = true;
1771 exp.type = memberSymbolErrorExp;
1774 exp.type = memberSymbolErrorExp;
1778 //if(exp.type != memberExp)
1780 //FreeExpression(memberExp);
1781 //FreeIdentifier(memberID);
1786 exp.type = memberSymbolErrorExp;
1792 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
1793 FreeExpContents(exp);
1794 exp.constant = PrintUInt(ComputeTypeSize(type));
1795 exp.type = constantExp;
1801 Symbol classSym = FindClass(exp._class.name);
1802 if(classSym && classSym.registered)
1804 //exp.constant = PrintUInt(classSym.registered.size);
1805 //exp.type = constantExp;
1807 char className[1024];
1808 sprintf(className, "__ecereClass_%s", classSym.string);
1809 FreeExpContents(exp);
1810 exp.type = pointerExp;
1811 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
1812 exp.member.member = MkIdentifier("size");
1818 DebugComputeExpression(exp.cast.exp);
1820 if(ExpressionIsError(exp.cast.exp)) //.type == ExpSymbolError
1821 CarryExpressionError(exp, exp.cast.exp);
1824 exp.hasAddress = exp.cast.exp.hasAddress;
1825 exp.address = exp.cast.exp.address;
1826 if(exp.cast.exp.type == constantExp && exp.expType)
1828 Type type = exp.expType;
1829 if(type.kind == classType && type._class && type._class.registered)
1831 Class _class = type._class.registered;
1832 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
1834 if(!_class.dataType)
1835 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
1836 type = _class.dataType;
1838 else if(_class.type == structClass && !type.byReference)
1840 FreeExpContents(exp);
1841 exp.type = unknownErrorExp;
1852 if(GetChar(exp.cast.exp, &value))
1854 FreeExpContents(exp);
1855 exp.constant = PrintChar(value);
1856 exp.type = constantExp;
1857 exp.isConstant = true;
1862 unsigned char value = 0;
1863 if(GetUChar(exp.cast.exp, &value))
1865 FreeExpContents(exp);
1866 exp.constant = PrintUChar(value);
1867 exp.type = constantExp;
1868 exp.isConstant = true;
1876 if(GetShort(exp.cast.exp, &value))
1878 FreeExpContents(exp);
1879 exp.constant = PrintShort(value);
1880 exp.type = constantExp;
1881 exp.isConstant = true;
1886 unsigned short value = 0;
1887 if(GetUShort(exp.cast.exp, &value))
1889 FreeExpContents(exp);
1890 exp.constant = PrintUShort(value);
1891 exp.type = constantExp;
1892 exp.isConstant = true;
1900 if(GetInt(exp.cast.exp, &value))
1902 FreeExpContents(exp);
1903 exp.constant = PrintInt(value);
1904 exp.type = constantExp;
1905 exp.isConstant = true;
1910 unsigned int value = 0;
1911 if(GetUInt(exp.cast.exp, &value))
1913 FreeExpContents(exp);
1914 exp.constant = PrintUInt(value);
1915 exp.type = constantExp;
1916 exp.isConstant = true;
1924 if(GetInt64(exp.cast.exp, &value))
1926 FreeExpContents(exp);
1927 exp.constant = PrintInt64(value);
1928 exp.type = constantExp;
1929 exp.isConstant = true;
1935 if(GetUInt64(exp.cast.exp, &value))
1937 FreeExpContents(exp);
1938 exp.constant = PrintUInt64(value);
1939 exp.type = constantExp;
1940 exp.isConstant = true;
1948 if(GetUInt64(exp.cast.exp, &value))
1950 FreeExpContents(exp);
1951 if(type.kind == pointerType || type.kind == classType)
1952 exp.constant = PrintHexUInt64(value);
1954 exp.constant = PrintUInt64(value);
1955 exp.type = constantExp;
1956 exp.isConstant = true;
1963 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
1964 (!strcmpi(exp.cast.exp.constant, "nan") ||
1965 !strcmpi(exp.cast.exp.constant, "-nan") ||
1966 !strcmpi(exp.cast.exp.constant, "inf") ||
1967 !strcmpi(exp.cast.exp.constant, "-inf")))
1969 String constant = exp.cast.exp.constant;
1970 exp.cast.exp.constant = null;
1971 FreeExpContents(exp);
1972 exp.constant = constant;
1973 exp.type = constantExp;
1974 exp.isConstant = true;
1976 else if(GetFloat(exp.cast.exp, &value))
1978 FreeExpContents(exp);
1979 exp.constant = PrintFloat(value);
1980 exp.type = constantExp;
1981 exp.isConstant = true;
1988 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
1989 (!strcmpi(exp.cast.exp.constant, "nan") ||
1990 !strcmpi(exp.cast.exp.constant, "-nan") ||
1991 !strcmpi(exp.cast.exp.constant, "inf") ||
1992 !strcmpi(exp.cast.exp.constant, "-inf")))
1994 String constant = exp.cast.exp.constant;
1995 exp.cast.exp.constant = null;
1996 FreeExpContents(exp);
1997 exp.constant = constant;
1998 exp.type = constantExp;
1999 exp.isConstant = true;
2001 else if(GetDouble(exp.cast.exp, &value))
2003 FreeExpContents(exp);
2004 exp.constant = PrintDouble(value);
2005 exp.type = constantExp;
2006 exp.isConstant = true;
2019 DebugComputeExpression(exp.cond.cond);
2021 if(ExpressionIsError(exp.cond.cond))
2022 CarryExpressionError(exp, exp.cond.cond);
2023 else if(exp.cond.cond.type == constantExp && exp.cond.cond.constant)
2025 Expression e = null;
2026 if(strtol(exp.cond.cond.constant, null, 0))
2028 for(e = exp.cond.exp ? exp.cond.exp->first : null; e; e = e.next)
2030 DebugComputeExpression(e);
2035 if(ExpressionIsError(e))
2037 CarryExpressionError(exp, e);
2041 exp.cond.exp->Remove(e);
2046 e = exp.cond.elseExp;
2049 DebugComputeExpression(e);
2050 if(ExpressionIsError(e))
2052 CarryExpressionError(exp, e);
2056 exp.cond.elseExp = null;
2061 FreeType(exp.expType);
2062 FreeType(exp.destType);
2065 FreeExpContents(exp);
2069 else if(!ExpressionIsError(exp))
2071 FreeExpContents(exp);
2072 exp.type = unknownErrorExp;
2077 FreeExpContents(exp);
2078 exp.type = unknownErrorExp;
2083 FreeExpContents(exp);
2084 exp.type = unknownErrorExp;