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 char * DebugPrintFloat(float result)
141 result.OnGetString(temp, null, null);
142 if(!strchr(temp, '.'))
145 return CopyString(temp);
148 char * DebugPrintDouble(double result)
151 result.OnGetString(temp, null, null);
152 if(!strchr(temp, '.'))
154 return CopyString(temp);
157 void DebugComputeExpression(Expression exp)
160 char expString[1024] = "";
163 PrintExpression(exp, expString);
164 // printf("%s (exp.type = %s)\n", expString, exp.type.OnGetString(temp, null, null));
170 Expression prev = exp.prev, next = exp.next;
171 char * evaluation = null;
172 ExpressionType evalError = dummyExp;
174 TypeKind kind = dummyType;
175 Type dataType = exp.expType;
178 bool isPointer = false;
179 bool evaluate = false;
180 bool evaluateAddress = false;
181 String idString = null;
182 if(exp.identifier.string)
184 const String start = (exp.identifier.string[0] == ':' && exp.identifier.string[1] == ':') ? exp.identifier.string + 2 : exp.identifier.string;
185 if(strstr(start, "::"))
187 char prefix[] = "__ecereNameSpace__";
188 int len = strlen(start);
189 idString = new char[len + sizeof(prefix)];
190 memcpy(idString, prefix, sizeof(prefix) - 1);
191 memcpy(idString + sizeof(prefix) - 1, start, len + 1);
192 ChangeCh(idString + sizeof(prefix) - 1, ':', '_');
195 idString = CopyString(exp.identifier.string);
198 if(dataType && dataType.kind == classType && dataType._class.registered)
200 Class _class = dataType._class.registered;
201 if(_class.type == bitClass || _class.type == unitClass || _class.type == enumClass)
204 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
205 dataType = _class.dataType;
207 else if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass) // Added systemClass here for Instance
212 else if(dataType && dataType.kind == classType && !dataType._class.registered)
215 kind = dataType.kind;
218 exp.type = symbolErrorExp;
219 evalError = symbolErrorExp;
223 case intPtrType: case intSizeType: case _BoolType:
224 case charType: case shortType: case intType: case int64Type: case longType: case floatType: case doubleType:
231 evaluateAddress = true;
234 if(exp.byReference && dataType._class && dataType._class.registered && dataType._class.registered.type == structClass)
235 // if(!dataType._class || !dataType._class.registered || dataType._class.registered.type != structClass || exp.byReference)
236 evaluateAddress = false;
238 evaluateAddress = true;
245 // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
255 strcpy(temp + 1, idString);
258 strcpy(temp, idString);
260 evaluation = Debugger::EvaluateExpression(temp, &evalError);
263 address = _strtoui64(evaluation, null, 0);
274 if(evalError == dummyExp)
280 evaluation = Debugger::EvaluateExpression(idString, &evalError);
285 temp = strstr(evaluation, " '");
286 //len = strlen(temp);
290 for(c = 0; c < len; c++)
292 eString_TrimRSpaces(evaluation, evaluation);
308 evaluation = Debugger::EvaluateExpression(idString, &evalError);
311 if(kind == pointerType)
314 value = _strtoui64(evaluation, null, 0);
316 evaluation = PrintHexUInt64(value);
326 //evaluation = Debugger::EvaluateExpression(idString, &evalError);
327 size = ComputeTypeSize(exp.expType); //exp.expType.arrayType.size;
328 format = GetGdbFormatChar(exp.expType);
329 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
331 StripQuotes(evaluation, evaluation);
337 //evaluation = Debugger::EvaluateExpression(idString, &evalError);
342 // for classType --> if(_class.type == structClass) ?
344 //sprintf(temp, "&%s", idString);
345 //evaluation = Debugger::EvaluateExpression(temp, &evalError);
351 // case TypeTypedObject, TypeAnyObject, TypeClassPointer:
354 evaluation = Debugger::EvaluateExpression(idString, &evalError);
361 if(evaluation && (exp.type != symbolErrorExp || !exp.identifier || !idString || strcmp(evaluation, idString)))
363 char * lt = strchr(evaluation, '<');
366 // Going back to parsing the expression string so as to catch inf/-inf/nan/-nan etc.
367 expNew = ParseExpressionString(evaluation);
368 //expNew = MkExpConstant(evaluation);
369 //printf("Evaluation = %s\n", evaluation);
371 expNew.destType = exp.expType;
373 // WHY EXACTLY MUST WE PROCESS THIS EXPRESSION TYPE AGAIN ? ADDED THIS FOR 0x00000000
374 if(exp.expType && (exp.expType.kind == pointerType || exp.expType.kind == classType) && expNew.destType)
376 expNew.expType = expNew.destType;
377 expNew.destType.refCount++;
378 // For negative values parsed as opExp
379 if(expNew.type == opExp && expNew.op.op == '-' && !expNew.op.exp1 && expNew.op.exp2)
381 expNew.op.exp2.expType = expNew.destType;
382 expNew.destType.refCount++;
383 expNew.op.exp2.isConstant = true;
387 ProcessExpressionType(expNew);
388 FreeType(exp.destType);
389 FreeExpContents(exp);
391 DebugComputeExpression(expNew);
394 expNew.isConstant = true;
395 expNew.address = address;
396 expNew.hasAddress = hasAddress;
402 // Unhandled code path, evaluation is null
403 FreeExpContents(exp);
404 exp.type = unknownErrorExp;
408 // Keep the identifier
409 exp.type = evalError;
412 FreeExpContents(exp);
413 exp.type = evalError;
420 Instantiation inst = exp.instance;
422 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
423 Class _class = classSym ? classSym.registered : null;
424 DataMember curMember = null;
425 Class curClass = null;
426 DataMember subMemberStack[256];
427 int subMemberStackPos = 0;
430 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
432 // Don't recompute the instantiation...
433 // Non Simple classes will have become constants by now
437 if(_class.type == normalClass || _class.type == noHeadClass)
439 inst.data = (byte *)eInstance_New(_class);
440 if(_class.type == normalClass)
441 ((Instance)inst.data)._refCount++;
444 inst.data = new0 byte[_class.structSize];
449 for(members = inst.members->first; members; members = members.next)
453 case dataMembersInit:
455 if(members.dataMembers)
458 for(member = members.dataMembers->first; member; member = member.next)
460 Identifier ident = member.identifiers ? member.identifiers->first : null;
463 Property prop = null;
464 DataMember dataMember = null;
465 uint dataMemberOffset;
469 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
472 if(curMember.isProperty)
474 prop = (Property)curMember; // TOFIX: (eC II ? THe mss
478 dataMember = curMember;
481 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, GetPrivateModule(), null, null);
483 // 2013/17/29 -- It seems that this was missing here!
484 if(_class.type == normalClass)
485 dataMemberOffset += _class.base.structSize;
486 // dataMemberOffset = dataMember.offset;
493 prop = eClass_FindProperty(_class, ident.string, GetPrivateModule());
497 if(prop.memberAccess == publicAccess)
499 curMember = (DataMember)prop;
500 curClass = prop._class;
505 DataMember _subMemberStack[256];
506 int _subMemberStackPos = 0;
509 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, GetPrivateModule(), _subMemberStack, &_subMemberStackPos);
514 if(dataMember.memberAccess == publicAccess)
516 curMember = dataMember;
517 curClass = dataMember._class;
518 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
519 subMemberStackPos = _subMemberStackPos;
525 if(found && member.initializer && member.initializer.type == expInitializer)
527 Expression value = member.initializer.exp;
529 bool deepMember = false;
532 type = prop.dataType;
536 if(!dataMember.dataType)
537 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
539 type = dataMember.dataType;
542 if(ident && ident.next)
546 // for(; ident && type; ident = ident.next)
547 for(ident = ident.next; ident && type; ident = ident.next)
549 if(type.kind == classType)
551 prop = eClass_FindProperty(type._class.registered,
552 ident.string, GetPrivateModule());
554 type = prop.dataType;
557 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
558 ident.string, &dataMemberOffset, GetPrivateModule(), null, null);
560 type = dataMember.dataType;
563 else if(type.kind == structType || type.kind == unionType)
566 for(memberType = type.members.first; memberType; memberType = memberType.next)
568 if(!strcmp(memberType.name, ident.string))
579 FreeType(value.destType);
580 value.destType = type;
581 if(type) type.refCount++;
582 DebugComputeExpression(value);
584 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
586 if(type.kind == classType)
588 Class _class = type._class.registered;
589 if(_class.type == bitClass || _class.type == unitClass ||
590 _class.type == enumClass)
593 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
594 type = _class.dataType;
600 void * ptr = inst.data + dataMemberOffset;
602 if(value.type == constantExp)
608 GetInt(value, (int*)ptr);
613 GetInt64(value, (int64*)ptr);
618 GetIntPtr(value, (intptr*)ptr);
623 GetIntSize(value, (intsize*)ptr);
628 GetFloat(value, (float*)ptr);
633 GetDouble(value, (double *)ptr);
638 else if(value.type == instanceExp)
640 if(type.kind == classType)
642 Class _class = type._class.registered;
643 if(_class.type == structClass)
645 ComputeTypeSize(type);
646 if(value.instance.data)
647 memcpy(ptr, value.instance.data, type.size);
654 if(value.type == instanceExp && value.instance.data)
656 if(type.kind == classType)
658 Class _class = type._class.registered;
659 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
661 void (*Set)(void *, void *) = (void *)prop.Set;
662 Set(inst.data, value.instance.data);
663 PopulateInstance(inst);
667 else if(value.type == constantExp)
673 void (*Set)(void *, double) = (void *)prop.Set;
674 Set(inst.data, strtod(value.constant, null) );
679 void (*Set)(void *, float) = (void *)prop.Set;
680 Set(inst.data, (float)(strtod(value.constant, null)));
685 void (*Set)(void *, int) = (void *)prop.Set;
686 Set(inst.data, (int)strtol(value.constant, null, 0));
691 void (*Set)(void *, int64) = (void *)prop.Set;
692 Set(inst.data, _strtoi64(value.constant, null, 0));
697 void (*Set)(void *, intptr) = (void *)prop.Set;
698 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
703 void (*Set)(void *, intsize) = (void *)prop.Set;
704 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
709 else if(value.type == stringExp)
712 ReadString(temp, value.string);
713 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
717 else if(!deepMember && type && _class.type == unitClass)
721 // Only support converting units to units for now...
722 if(value.type == constantExp)
724 if(type.kind == classType)
726 Class _class = type._class.registered;
727 if(_class.type == unitClass)
730 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
731 type = _class.dataType;
734 // TODO: Assuming same base type for units...
740 float (*Set)(float) = (void *)prop.Set;
741 GetFloat(member.initializer.exp, &fValue);
742 exp.constant = DebugPrintFloat(Set(fValue));
743 exp.type = constantExp;
749 double (*Set)(double) = (void *)prop.Set;
750 GetDouble(member.initializer.exp, &dValue);
751 exp.constant = DebugPrintDouble(Set(dValue));
752 exp.type = constantExp;
759 else if(!deepMember && type && _class.type == bitClass)
763 if(value.type == instanceExp && value.instance.data)
765 unsigned int (*Set)(void *) = (void *)prop.Set;
766 bits = Set(value.instance.data);
768 else if(value.type == constantExp)
774 BitMember bitMember = (BitMember) dataMember;
777 GetInt(value, &part);
778 bits = (bits & ~bitMember.mask);
779 if(!bitMember.dataType)
780 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
782 type = bitMember.dataType;
784 if(type.kind == classType && type._class && type._class.registered)
786 if(!type._class.registered.dataType)
787 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
788 type = type._class.registered.dataType;
796 bits |= ((char)part << bitMember.pos);
798 bits |= ((unsigned char)part << bitMember.pos);
802 bits |= ((short)part << bitMember.pos);
804 bits |= ((unsigned short)part << bitMember.pos);
809 bits |= ((int)part << bitMember.pos);
811 bits |= ((unsigned int)part << bitMember.pos);
815 bits |= ((int64)part << bitMember.pos);
817 bits |= ((uint64)part << bitMember.pos);
822 bits |= ((intptr)part << bitMember.pos);
826 bits |= ((uintptr)part << bitMember.pos);
832 bits |= ((ssize_t)(intsize)part << bitMember.pos);
836 bits |= ((size_t) (uintsize)part << bitMember.pos);
845 if(_class && _class.type == unitClass)
847 DebugComputeExpression(member.initializer.exp);
848 exp.constant = member.initializer.exp.constant;
849 exp.type = constantExp;
851 member.initializer.exp.constant = null;
861 if(_class && _class.type == bitClass)
863 exp.constant = PrintHexUInt(bits);
864 exp.type = constantExp;
866 if(exp.type != instanceExp)
878 Expression expError = null;
879 Expression exp1 = null, exp2 = null;
880 Operand op1 = { 0 }, op2 = { 0 };
883 if(exp.op.op == '&' || exp.op.op == '*')
885 if(!exp.op.exp1 && exp.op.exp2)
887 if(exp.op.exp2.type == identifierExp)
889 Expression prev = exp.prev, next = exp.next;
890 char * evaluation = null;
891 ExpressionType evalError = dummyExp;
894 sprintf(temp, "%c%s", exp.op.op, exp.op.exp2.identifier.string);
895 evaluation = Debugger::EvaluateExpression(temp, &evalError);
896 if(evalError != dummyExp)
898 exp.type = evalError;
899 exp.constant = CopyString("");
903 expNew = ParseExpressionString(evaluation);
905 expNew.destType = exp.expType;
906 FreeType(exp.destType);
907 FreeExpContents(exp);
908 ProcessExpressionType(expNew);
909 DebugComputeExpression(expNew);
912 expNew.isConstant = true;
917 exp.type = ExpUnknownError;
927 DebugComputeExpression(exp.op.exp2);
928 size = ComputeTypeSize(exp.op.exp2.expType);
929 format = GetGdbFormatChar(exp.op.exp2.expType);
930 GetInt(exp.op.exp2, &address);
931 //sprintf(temp, "%c%s", exp.op.op, exp.op.exp2.constant);
932 evaluation = Debug_ReadMemory(address, size, format, &evalError);
935 evalError = ExpUnknownError;
941 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
944 Expression e = exp.op.exp2;
946 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
948 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
950 if(e.type == extensionCompoundExp)
951 e = ((Statement)e.compound.compound.statements->last).expressions->last;
956 if(exp.op.op == TokenType::sizeOf && e && e.expType)
958 if(e.type == stringExp && e.string)
960 char * string = e.string;
961 int len = strlen(string);
962 char * tmp = new char[len-2+1];
963 len = UnescapeString(tmp, string + 1, len - 2);
965 FreeExpContents(exp);
966 exp.type = constantExp;
967 exp.constant = PrintUInt(len + 1);
971 Type type = e.expType;
973 FreeExpContents(exp);
974 exp.type = constantExp;
975 exp.constant = PrintUInt(ComputeTypeSize(type));
982 DebugComputeExpression(exp.op.exp2);
983 if(ExpressionIsError(exp.op.exp2))
984 expError = exp.op.exp2;
991 DebugComputeExpression(exp.op.exp1);
992 if(ExpressionIsError(exp.op.exp1))
993 expError = exp.op.exp1;
998 if(ExpressionIsError(exp.op.exp2))
999 expError = exp.op.exp2;
1004 op1 = GetOperand(exp1);
1005 if(op1.type) op1.type.refCount++;
1006 op2 = GetOperand(exp2);
1007 if(op2.type) op2.type.refCount++;
1013 op1 = GetOperand(exp1);
1014 if(op1.type) op1.type.refCount++;
1018 else if(exp.op.exp2)
1020 if(ExpressionIsError(exp.op.exp2))
1021 expError = exp.op.exp2;
1025 if(exp.op.op == '&' || exp.op.op == '*')
1027 Expression prev = exp1.prev, next = exp1.next;
1029 ExpressionType evalError = dummyExp;
1030 char * evaluation = null;
1031 if(exp.op.op == '&')
1036 //sprintf(temp, "%u", exp1.address);
1037 temp = PrintHexUInt64(exp1.address);
1038 expNew = ParseExpressionString(temp);
1040 //expNew.address = exp1.address;
1041 expNew.expType = exp.expType;
1043 expNew.destType = exp.expType;
1044 expNew.destType.refCount++;
1046 FreeType(exp.destType);
1047 FreeExpContents(exp);
1048 ProcessExpressionType(expNew);
1049 DebugComputeExpression(expNew);
1052 expNew.isConstant = true;
1059 else if(exp.op.op == '*')
1061 // TODO: Common pathway for * and [ ]
1065 FreeExpContents(exp1);
1066 exp1.type = dereferenceErrorExp;
1074 Expression e = exp1;
1076 bool gotAddress = false;
1078 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
1080 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
1082 if(e.type == extensionCompoundExp)
1083 e = ((Statement)e.compound.compound.statements->last).expressions->last;
1087 else if(e.type == castExp)
1091 if(e.expType.kind == structType)
1093 address = exp1.address;
1097 gotAddress = GetUInt64(e, &address);
1098 size = ComputeTypeSize(exp.expType); //exp.expType.arrayType.size;
1099 if(exp.expType && exp.expType.type && exp.expType.kind == arrayType)
1100 // For multilevels arrays
1103 format = GetGdbFormatChar(exp.expType);
1104 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
1106 Expression e1 = e.op.exp1, e2 = e.op.exp2;
1107 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1109 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1111 if(e1.type == extensionCompoundExp)
1112 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1116 else if(e1.type == castExp)
1119 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1121 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1123 if(e2.type == extensionCompoundExp)
1124 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1128 else if(e2.type == castExp)
1132 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1134 offset += strtol(e.op.exp2.constant, null, 0);
1137 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1139 offset += strtol(e.op.exp1.constant, null, 0);
1146 if(e.type == stringExp)
1149 String string = e.string;
1151 Type expType = exp1.expType.type;
1152 if(expType) expType.refCount++;
1156 int len = string ? strlen(string) : 0;
1157 tmp = new char[len-2+1];
1158 len = UnescapeString(tmp, string + 1, len - 2);
1159 if(len >= 0 && offset * size + size-1 <= len)
1163 FreeExpContents(exp);
1165 exp.type = dereferenceErrorExp;
1168 exp.type = constantExp;
1169 exp.isConstant = true;
1170 switch(expType.kind)
1172 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1173 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1174 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1175 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1176 case floatType: exp.constant = DebugPrintFloat(((float *)tmp)[offset]); break;
1177 case doubleType: exp.constant = DebugPrintDouble(((double *)tmp)[offset]); break;
1179 exp.type = unknownErrorExp;
1183 exp.type = unknownErrorExp;
1187 else if(gotAddress && exp.expType.kind == arrayType)
1189 FreeExpContents(exp);
1190 exp.type = constantExp;
1191 exp.isConstant = true;
1192 exp.constant = PrintHexUInt64(address);
1193 exp.address = address;
1194 exp.hasAddress = true;
1196 else if(gotAddress && format)
1198 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1204 expNew = ParseExpressionString(evaluation);
1205 expNew.address = address;
1206 expNew.hasAddress = true;
1208 expNew.destType = exp.expType;
1209 FreeType(exp.destType);
1210 FreeExpContents(exp);
1211 ProcessExpressionType(expNew);
1212 DebugComputeExpression(expNew);
1215 expNew.isConstant = true;
1221 // Unhandled code path, evaluation is null
1222 FreeExpContents(exp);
1223 exp.type = unknownErrorExp;
1226 case memoryErrorExp:
1228 FreeExpContents(exp1);
1229 exp1.type = evalError;
1230 exp1.constant = PrintHexUInt64(address);
1235 FreeExpContents(exp1);
1236 exp1.type = evalError;
1243 FreeExpContents(exp1);
1244 exp1.type = unknownErrorExp; // Not supported yet, generate error to fallback to GDB printout
1251 op1 = GetOperand(exp1);
1252 if(op1.type) op1.type.refCount++;
1257 CarryExpressionError(exp, expError);
1258 else if(exp.type == opExp)
1260 if(exp1 && exp2 && exp1.expType && exp2.expType &&
1261 ((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) ||
1262 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
1265 if((exp.op.op == '+' || exp.op.op == '-') && (op2.type || op1.type))
1267 Expression e1 = exp1, e2 = exp2;
1268 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1270 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1272 if(e1.type == extensionCompoundExp)
1273 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1277 else if(e1.type == castExp)
1280 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1282 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1284 if(e2.type == extensionCompoundExp)
1285 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1289 else if(e2.type == castExp)
1293 if((e1.type == stringExp && op2.type && op2.type.kind == intType) || (e2.type == stringExp && op1.type && op1.type.kind == intType))
1295 uint64 offset = ((exp.op.op == '+') ? 1 : -1) * (e1.type == stringExp ? op2.i64 : op1.i64);
1296 String newString = null;
1297 Expression e = e1.type == stringExp ? e1 : e2;
1300 int len = strlen(e.string) - 2;
1301 char * tmp = OffsetEscapedString(e.string + 1, len, (int)offset);
1304 len -= tmp - (e.string + 1);
1305 newString = new char[2 + len + 1];
1306 newString[0] = '\"';
1307 memcpy(newString + 1, tmp, len);
1308 newString[1 + len] = '\"';
1309 newString[1 + len + 1] = 0;
1313 FreeExpContents(exp);
1316 exp.type = stringExp;
1317 exp.string = newString;
1320 exp.type = dereferenceErrorExp;
1322 // Can't add 2 pointers...
1323 else if(exp.op.op != '+' ||
1324 !((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) &&
1325 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
1327 bool op1IsPointer = exp1.expType.kind == pointerType || exp1.expType.kind == arrayType;
1328 bool op2IsPointer = exp2.expType.kind == pointerType || exp2.expType.kind == arrayType;
1329 bool addressResult = !op1IsPointer || !op2IsPointer;
1333 size = ComputeTypeSize(exp1.expType.type);
1334 else if(op2IsPointer)
1335 size = ComputeTypeSize(exp2.expType.type);
1337 if(addressResult && size)
1339 if(op1IsPointer) op2.ui64 *= size;
1340 else if(op1IsPointer) op1.ui64 *= size;
1343 CallOperator(exp, exp1, exp2, op1, op2);
1344 if(exp.type == constantExp)
1348 exp.address = _strtoui64(exp.constant, null, 0);
1349 delete exp.constant;
1350 exp.constant = PrintHexUInt64(exp.address);
1351 if(op1.type.kind == arrayType || op2.type.kind == arrayType)
1352 exp.hasAddress = true;
1356 int64 v = _strtoi64(exp.constant, null, 0);
1358 delete exp.constant;
1359 exp.constant = PrintInt(v);
1366 FreeExpContents(exp);
1367 exp.type = unknownErrorExp; // We should have an invalid operands error
1372 if(!exp2 && exp1 && exp1.type == constantExp && exp1.constant && !strcmp(exp1.constant, "nan") && exp.op.op == '-')
1374 FreeExpContents(exp);
1375 exp.constant = CopyString("-nan");
1376 exp.type = constantExp;
1380 if((exp.op.op == '/' || exp.op.op == '%') && op2.kind != doubleType && op1.kind != doubleType && op2.kind != floatType && op1.kind != floatType &&
1381 (((op2.kind == int64Type || op2.kind == intPtrType || op2.kind == intSizeType) && !op2.i64) ||
1382 (op2.kind == intType && !op2.i) || (op2.kind == shortType && !op2.s) || (op2.kind == charType && !op2.c)))
1384 FreeExpContents(exp);
1385 exp.type = divideBy0ErrorExp;
1388 CallOperator(exp, exp1, exp2, op1, op2);
1393 if(exp.type == constantExp)
1394 exp.isConstant = true;
1402 // e = (*exp.list).first, n = e ? e.next : null;
1404 // e = n, n = n?(n.next) : null)
1406 for(e = exp.list->first; e; e = n)
1411 OldList * list = exp.list;
1412 DebugComputeExpression(e);
1413 //if(ExpressionIsError(e)) //.type == ExpSymbolError
1414 // CarryExpressionError(exp, e);
1415 //FreeExpContents(exp);
1416 FreeType(exp.expType);
1417 FreeType(exp.destType);
1434 exp.isConstant = true;
1436 DebugComputeExpression(exp.index.exp);
1437 if(ExpressionIsError(exp.index.exp)) //.type == ExpSymbolError
1438 CarryExpressionError(exp, exp.index.exp);
1441 Expression prev = exp.prev, next = exp.next;
1442 char * evaluation = null;
1443 ExpressionType evalError = dummyExp;
1444 Type dataType = exp.index.exp.expType ? exp.index.exp.expType.type : null;
1446 if(!exp.index.exp.isConstant)
1447 exp.isConstant = false;
1450 // 4 == size = ComputeTypeSize(exp.expType);
1451 // 0 == size = ComputeTypeSize(exp.expType.arrayType);
1452 // 4 == size = ComputeTypeSize(exp.index.exp.expType);
1453 // 0 == size = ComputeTypeSize(exp.index.exp.expType.arrayType);
1455 size = ComputeTypeSize(dataType);
1456 if(dataType && dataType.type && dataType.kind == arrayType)
1457 // For multilevels arrays
1460 format = GetGdbFormatChar(dataType);
1462 for(e = exp.index.index->first; e; e = e.next)
1464 DebugComputeExpression(e);
1465 if(ExpressionIsError(e)) //.type == ExpSymbolError
1467 CarryExpressionError(exp, e);
1472 // Check if this type is int
1475 exp.isConstant = false;
1477 if(!ExpressionIsError(exp))
1479 // Is this necessary here? pass15 had done this already...
1480 if(exp.expType) FreeType(exp.expType);
1481 exp.expType = Dereference(exp.index.exp.expType);
1486 FreeExpContents(exp);
1487 exp.type = dereferenceErrorExp;
1489 else if(exp.index.index && exp.index.index->last && ((Expression)exp.index.index->last) && ((Expression)exp.index.index->last).expType)
1491 Type type = ((Expression)exp.index.index->last).expType;
1492 if(type.kind == intType || type.kind == charType || type.kind == shortType || type.kind == int64Type || type.kind == intPtrType ||
1493 type.kind == intSizeType || type.kind == longType || type.kind == _BoolType || type.kind == enumType ||
1494 (type.kind == classType && type._class && type._class.registered &&
1495 type._class.registered.type == enumClass))
1497 bool gotAddress = false;
1498 uint64 address = 0, offset = 0;
1499 Expression expNew, last = (Expression)exp.index.index->last;
1500 Expression e = exp.index.exp;
1502 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
1504 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
1506 if(e.type == extensionCompoundExp)
1507 e = ((Statement)e.compound.compound.statements->last).expressions->last;
1511 else if(e.type == castExp)
1515 //GetUInt(exp.index.exp, &address);
1517 GetUInt64(last, &offset);
1519 // TOFIX: Check if it has address: TESTING
1520 if(exp.index.exp.hasAddress && exp.index.exp.expType.kind == arrayType)
1522 address = exp.index.exp.address;
1525 else if(exp.index.exp.type == constantExp)
1526 gotAddress = GetUInt64(exp.index.exp, &address);
1528 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
1530 Expression e1 = e.op.exp1, e2 = e.op.exp2;
1531 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1533 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1535 if(e1.type == extensionCompoundExp)
1536 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1540 else if(e1.type == castExp)
1543 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1545 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1547 if(e2.type == extensionCompoundExp)
1548 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1552 else if(e2.type == castExp)
1556 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1558 offset += strtol(e.op.exp2.constant, null, 0);
1561 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1563 offset += strtol(e.op.exp1.constant, null, 0);
1570 //size = ComputeTypeSize(exp.expType.arrayType); //exp.expType.arrayType.size;
1571 address += offset * size;
1573 if(e.type == stringExp)
1576 String string = e.string;
1578 Type expType = exp.index.exp.expType.type;
1579 if(expType) expType.refCount++;
1583 int len = string ? strlen(string) : 0;
1584 tmp = new char[len-2+1];
1585 len = UnescapeString(tmp, string + 1, len - 2);
1586 if(len >= 0 && offset * size + size-1 <= len)
1590 FreeExpContents(exp);
1592 exp.type = dereferenceErrorExp;
1595 exp.type = constantExp;
1596 exp.isConstant = true;
1597 switch(expType.kind)
1599 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1600 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1601 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1602 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1603 case floatType: exp.constant = DebugPrintFloat(((float *)tmp)[offset]); break;
1604 case doubleType: exp.constant = DebugPrintDouble(((double *)tmp)[offset]); break;
1606 exp.type = unknownErrorExp;
1610 exp.type = unknownErrorExp;
1614 else if(gotAddress && exp.expType.kind == arrayType)
1616 FreeExpContents(exp);
1617 exp.type = constantExp;
1618 exp.isConstant = true;
1619 exp.constant = PrintHexUInt64(address);
1620 exp.address = address;
1621 exp.hasAddress = true;
1625 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1631 expNew = ParseExpressionString(evaluation);
1633 expNew.destType = exp.expType;
1634 FreeType(exp.destType);
1635 FreeExpContents(exp);
1636 ProcessExpressionType(expNew);
1637 DebugComputeExpression(expNew);
1639 // TOFIX: Only for Array Types
1640 expNew.address = address;
1642 expNew.hasAddress = true;
1645 expNew.isConstant = true;
1651 // Unhandled code path, evaluation is null
1652 FreeExpContents(exp);
1653 exp.type = unknownErrorExp;
1656 case memoryErrorExp:
1658 FreeExpContents(exp);
1659 exp.type = evalError;
1660 exp.constant = PrintHexUInt64(address);
1664 FreeExpContents(exp);
1665 exp.type = evalError;
1671 FreeExpContents(exp);
1672 exp.type = unknownErrorExp;
1682 Expression callExp = exp.call.exp;
1683 Identifier id = (callExp && callExp.type == identifierExp) ? callExp.identifier : null;
1684 bool resolved = false;
1687 if(!strcmp(id.string, "nan") || !strcmp(id.string, "inf"))
1689 String s = id.string;
1691 FreeExpContents(exp);
1692 exp.type = constantExp;
1696 else if(exp.call.arguments)
1698 if(exp.call.arguments->count == 1)
1700 double (* fn1)(double) = (void *)oneArgFns[id.string];
1703 Expression arg = exp.call.arguments->first;
1704 DebugComputeExpression(arg);
1705 if(ExpressionIsError(arg))
1706 CarryExpressionError(exp, arg);
1707 else if(arg.isConstant && arg.type == constantExp)
1710 if(GetDouble(arg, &v))
1712 FreeExpContents(exp);
1713 exp.type = constantExp;
1715 exp.constant = DebugPrintDouble(v);
1716 exp.isConstant = true;
1722 else if(exp.call.arguments->count == 2)
1724 double (* fn2)(double, double) = (void *)twoArgFns[id.string];
1727 Expression arg1 = exp.call.arguments->first;
1728 Expression arg2 = exp.call.arguments->last;
1729 DebugComputeExpression(arg1);
1730 DebugComputeExpression(arg2);
1731 if(ExpressionIsError(arg1))
1732 CarryExpressionError(exp, arg1);
1733 else if(ExpressionIsError(arg2))
1734 CarryExpressionError(exp, arg2);
1735 else if(arg1.isConstant && arg1.type == constantExp && arg2.isConstant && arg2.type == constantExp)
1738 if(GetDouble(arg1, &v1) && GetDouble(arg2, &v2))
1740 FreeExpContents(exp);
1741 exp.type = constantExp;
1743 exp.constant = DebugPrintDouble(v1);
1744 exp.isConstant = true;
1753 exp.type = functionCallErrorExp;
1758 Expression memberExp = exp.member.exp;
1759 Identifier memberID = exp.member.member;
1761 Property prop = null;
1762 DataMember member = null;
1763 Class convertTo = null;
1764 uint offset = 0; // THIS WASN'T INITIALIZED... IS IT ALWAYS SET?
1766 Type type; // = memberExp.expType;
1767 DebugComputeExpression(memberExp);
1768 type = memberExp.expType;
1769 if(ExpressionIsError(memberExp))
1770 CarryExpressionError(exp, memberExp);
1773 // _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
1774 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);
1777 char string[256] = "";
1779 PrintTypeNoConst(type, string, false, true);
1780 classSym = FindClass(string);
1781 _class = classSym ? classSym.registered : null;
1784 if(memberID && _class)
1787 prop = eClass_FindProperty(_class, memberID.string);
1789 member = eClass_FindDataMember(_class, memberID.string);
1791 // member = eClass_FindDataMember(_class, memberID.string);
1792 member = eClass_FindDataMemberAndOffset(_class, memberID.string, &offset, _class.module.application, null, null);
1794 prop = eClass_FindProperty(_class, memberID.string, _class.module.application);
1796 if(!prop && !member && _class && memberID)
1798 Symbol classSym = FindClass(memberID.string);
1800 _class = classSym ? classSym.registered : null;
1802 prop = eClass_FindProperty(_class, convertTo.fullName, _class.module.application);
1805 //DebugComputeExpression(memberExp);
1806 if(ExpressionIsError(memberExp))
1807 CarryExpressionError(exp, memberExp);
1810 if(exp.member.memberType == methodMember)
1812 FreeExpContents(exp);
1813 exp.type = unknownErrorExp;
1817 bool supported = false;
1820 Type type = prop.dataType;
1821 // TODO: Assuming same base type for units...
1822 if(_class.type == unitClass)
1824 if(type.kind == classType)
1826 Class _class = type._class.registered;
1827 if(_class.type == unitClass)
1829 if(!_class.dataType)
1830 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
1831 type = _class.dataType;
1839 float (*Get)(float) = (convertTo ? (void *)prop.Set : (void *)prop.Get);
1840 GetFloat(memberExp, &value);
1842 FreeExpContents(exp);
1843 exp.constant = DebugPrintFloat(Get ? Get(value) : value);
1844 exp.type = constantExp;
1845 exp.isConstant = true;
1852 double (*Get)(double) = (convertTo ? (void *)prop.Set : (void *)prop.Get);
1853 GetDouble(memberExp, &value);
1855 FreeExpContents(exp);
1856 exp.constant = DebugPrintDouble(Get ? Get(value) : value);
1857 exp.isConstant = true;
1858 exp.type = constantExp;
1868 Expression value = memberExp;
1869 Type type = prop.dataType;
1870 exp.member.exp = null;
1872 if(_class.type == structClass)
1878 Class propertyClass = type._class.registered;
1879 if(propertyClass.type == structClass && value.type == instanceExp)
1881 void (*Set)(void *, void *) = (void *)prop.Set;
1882 FreeExpContents(exp);
1883 exp.instance = Instantiation
1885 data = new0 byte[_class.structSize];
1886 _class = MkSpecifierName(_class.name);
1889 exp.type = instanceExp;
1891 Set(exp.instance.data, value.instance.data);
1892 PopulateInstance(exp.instance);
1900 void (*Set)(void *, int) = (void *)prop.Set;
1902 GetInt(value, &intValue);
1903 FreeExpContents(exp);
1904 exp.instance = Instantiation
1906 data = new0 byte[_class.structSize];
1907 _class = MkSpecifierName/*MkClassName*/(_class.name);
1910 exp.type = instanceExp;
1912 Set(exp.instance.data, intValue);
1913 PopulateInstance(exp.instance);
1920 void (*Set)(void *, int64) = (void *)prop.Set;
1922 GetInt64(value, &intValue);
1923 FreeExpContents(exp);
1924 exp.instance = Instantiation
1926 data = new0 byte[_class.structSize];
1927 _class = MkSpecifierName/*MkClassName*/(_class.name);
1930 exp.type = instanceExp;
1932 Set(exp.instance.data, intValue);
1933 PopulateInstance(exp.instance);
1940 void (*Set)(void *, float) = (void *)prop.Set;
1942 GetFloat(value, &floatValue);
1943 FreeExpContents(exp);
1944 exp.instance = Instantiation
1946 data = new0 byte[_class.structSize];
1947 _class = MkSpecifierName/*MkClassName*/(_class.name);
1950 exp.type = instanceExp;
1952 Set(exp.instance.data, floatValue);
1953 PopulateInstance(exp.instance);
1960 void (*Set)(void *, double) = (void *)prop.Set;
1962 GetDouble(value, &doubleValue);
1963 FreeExpContents(exp);
1964 exp.instance = Instantiation
1966 data = new0 byte[_class.structSize];
1967 _class = MkSpecifierName/*MkClassName*/(_class.name);
1970 exp.type = instanceExp;
1972 Set(exp.instance.data, doubleValue);
1973 PopulateInstance(exp.instance);
1979 else if(_class.type == bitClass)
1985 Class propertyClass = type._class.registered;
1986 if(propertyClass.type == structClass && value.instance.data)
1988 unsigned int (*Set)(void *) = (void *)prop.Set;
1989 unsigned int bits = Set(value.instance.data);
1990 FreeExpContents(exp);
1991 exp.constant = PrintHexUInt(bits);
1992 exp.type = constantExp;
1996 else if(_class.type == bitClass)
1999 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
2002 GetUInt(memberExp, &value);
2004 FreeExpContents(exp);
2005 exp.constant = PrintHexUInt(bits);
2006 exp.type = constantExp;
2012 FreeExpression(value);
2016 if(_class.type == bitClass)
2019 GetUInt(memberExp, &value);
2025 Class _class = type._class.registered;
2026 if(_class.type == structClass)
2028 void (*Get)(unsigned int, void *) = (void *)prop.Get;
2030 FreeExpContents(exp);
2031 exp.instance = Instantiation
2033 data = new0 byte[_class.structSize];
2034 _class = MkSpecifierName/*MkClassName*/(_class.name);
2037 //exp.instance.fullSet = true;
2038 exp.type = instanceExp;
2039 Get(value, exp.instance.data);
2040 PopulateInstance(exp.instance);
2043 else if(_class.type == bitClass)
2045 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
2046 uint64 bits = Get(value);
2047 exp.constant = PrintHexUInt64(bits);
2048 exp.type = constantExp;
2055 else if(_class.type == structClass)
2057 byte * value = (memberExp.type == instanceExp ) ? memberExp.instance.data : null;
2059 memberExp.instance.data = null;
2065 Class _class = type._class.registered;
2066 if(_class.type == structClass && value)
2068 void (*Get)(void *, void *) = (void *)prop.Get;
2070 FreeExpContents(exp);
2071 exp.instance = Instantiation
2073 data = new0 byte[_class.structSize];
2074 _class = MkSpecifierName/*MkClassName*/(_class.name);
2077 //exp.instance.fullSet = true;
2078 exp.type = instanceExp;
2079 Get(value, exp.instance.data);
2080 PopulateInstance(exp.instance);
2091 char * value = memberExp.instance.data;
2096 Class _class = type._class.registered;
2097 if(_class.type == normalClass)
2099 void *(*Get)(void *) = (void *)prop.Get;
2101 FreeExpContents(exp);
2102 exp.instance = Instantiation
2104 data = Get(value, exp.instance.data); ?????
2105 _class = MkSpecifierName(_class.name); //MkClassName(_class.name);
2108 exp.type = instanceExp;
2120 exp.type = memberPropertyErrorExp;
2121 exp.isConstant = false;
2126 if(memberExp.hasAddress || memberExp.type == constantExp || (memberExp.type == instanceExp && memberExp.instance && memberExp.instance.data))
2127 //if(memberExp.expType && memberExp.expType.kind == intType) // && !exp.index.exp.expType.isSigned
2129 if(_class.type == bitClass)
2131 if(memberExp.type == constantExp)
2133 // Unfinished business...
2134 BitMember bitMember = (BitMember)member;
2136 GetUInt64(memberExp, &bits);
2137 bits &= bitMember.mask;
2138 bits >>= bitMember.pos;
2140 FreeExpression(exp.member.exp);
2141 FreeIdentifier(exp.member.member);
2143 exp.constant = PrintUInt64(bits);
2145 exp.isConstant = true;
2146 exp.type = constantExp;
2147 exp.hasAddress = false;
2152 char * evaluation = null;
2153 ExpressionType evalError = dummyExp;
2154 bool gotAddress = false;
2156 Expression prev = exp.prev, next = exp.next;
2160 Type dataType = member.dataType;
2163 dataType = member.dataType = ProcessTypeString(member.dataTypeString, false);
2165 if(dataType.kind == classType && dataType._class.registered &&
2166 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
2168 if(dataType._class.registered.dataTypeString)
2169 dataType._class.registered.dataType = ProcessTypeString(dataType._class.registered.dataTypeString, false);
2170 dataType = dataType._class.registered.dataType;
2172 dataType = ProcessTypeString("int", false);
2175 size = ComputeTypeSize(member.dataType);
2177 format = GetGdbFormatChar(dataType);
2178 //if(memberExp.address)
2180 //GetInt(memberExp, &address);
2181 //offset = member.offset;
2183 // TESTING NOHEAD HERE?
2184 if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass)
2185 offset += member._class.offset;
2187 // VERIFY THIS: (trying to fix primitive.type)
2188 // if(memberExp.type == constantExp)
2189 if(memberExp.hasAddress && (_class.type != normalClass && _class.type != noHeadClass && _class.type != systemClass))
2191 address = memberExp.address;
2194 else if(memberExp.type == constantExp)
2195 gotAddress = GetUInt64(memberExp, &address);
2198 gotAddress = GetUInt64(memberExp, &address);
2199 //printf("Unhandled !!\n");
2201 //printf("memberExp.hasAddress = %d\n", memberExp.hasAddress);
2202 //printf("memberExp.type = %d\n", memberExp.type);
2203 //printf("_class.name = %s, _class.type = %d\n", _class.name, _class.type);
2208 if(memberExp.type == instanceExp)
2210 String constant = null;
2211 byte * data = memberExp.instance.data + offset;
2212 switch(dataType.kind)
2215 if(dataType.isSigned)
2216 constant = PrintChar(*(char *)data);
2218 constant = PrintUChar(*(byte *)data);
2221 if(dataType.isSigned)
2222 constant = PrintShort(*(short *)data);
2224 constant = PrintUShort(*(uint16 *)data);
2227 if(dataType.isSigned)
2228 constant = PrintInt(*(int *)data);
2230 constant = PrintUInt(*(uint *)data);
2234 if(dataType.isSigned)
2235 constant = PrintInt64(*(int64 *)data);
2237 constant = PrintUInt64(*(uint64 *)data);
2239 case floatType: constant = DebugPrintFloat(*(float *)data); break;
2240 case doubleType: constant = DebugPrintDouble(*(double *)data); break;
2244 FreeExpContents(exp);
2245 exp.constant = constant;
2246 exp.type = constantExp;
2247 exp.isConstant = true;
2250 exp.type = unknownErrorExp;
2252 else if(!gotAddress)
2254 FreeExpContents(exp);
2255 exp.type = unknownErrorExp;
2257 else if((dataType.kind == classType && dataType._class &&
2258 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
2259 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
2261 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
2262 if(evalError != dummyExp)
2264 exp.type = evalError;
2265 exp.constant = PrintHexUInt64(address);
2269 //printf("evaluation = %s\n", evaluation);
2270 expNew = ParseExpressionString(evaluation);
2272 expNew.destType = exp.expType;
2274 exp.expType.refCount++;
2275 //FreeType(memberExp.destType);
2276 FreeType(exp.expType);
2277 FreeType(exp.destType);
2278 FreeExpContents(exp);
2279 ProcessExpressionType(expNew);
2280 DebugComputeExpression(expNew);
2283 expNew.isConstant = true;
2284 expNew.address = address;
2285 expNew.hasAddress = true;
2291 FreeExpContents(exp);
2292 exp.type = unknownErrorExp;
2297 // TESTING THIS HERE...
2298 exp.type = constantExp;
2299 exp.constant = PrintHexUInt64(address);
2301 exp.address = address;
2302 exp.hasAddress = true;
2303 exp.isConstant = true;
2308 // exp.type = ExpUnknownError;
2310 //FreeExpContents(exp);
2311 //exp.constant = PrintUInt64(value);
2312 //exp.type = constantExp;
2317 if(type && (type.kind == structType || type.kind == unionType))
2320 Type memberType = exp.member.member ? FindMemberAndOffset(type, exp.member.member.string, &offset) : null;
2323 char * evaluation = null;
2324 ExpressionType evalError = dummyExp;
2326 bool gotAddress = false;
2327 Expression prev = exp.prev, next = exp.next;
2329 int size = memberType.size;
2331 Type dataType = memberType;
2333 if(dataType.kind == classType && dataType._class.registered &&
2334 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
2335 dataType = dataType._class.registered.dataType;
2337 format = GetGdbFormatChar(dataType);
2339 if(memberExp.hasAddress)
2341 address = memberExp.address;
2344 else if(memberExp.type == constantExp)
2345 gotAddress = GetUInt64(memberExp, &address);
2351 FreeExpContents(exp);
2352 exp.type = unknownErrorExp;
2354 else if((dataType.kind == classType && dataType._class &&
2355 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
2356 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
2358 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
2359 if(evalError != dummyExp)
2361 exp.type = evalError;
2362 exp.constant = PrintHexUInt64(address);
2366 expNew = ParseExpressionString(evaluation);
2368 expNew.destType = exp.expType;
2370 exp.expType.refCount++;
2371 //FreeType(memberExp.destType);
2372 FreeType(exp.expType);
2373 FreeType(exp.destType);
2374 FreeExpContents(exp);
2375 ProcessExpressionType(expNew);
2376 DebugComputeExpression(expNew);
2379 expNew.isConstant = true;
2380 expNew.address = address;
2381 expNew.hasAddress = true;
2387 FreeExpContents(exp);
2388 exp.type = unknownErrorExp;
2393 FreeExpContents(exp);
2395 // TESTING THIS HERE...
2396 exp.type = constantExp;
2397 exp.constant = PrintHexUInt64(address);
2399 exp.address = address;
2400 exp.hasAddress = true;
2401 exp.isConstant = true;
2405 exp.type = memberSymbolErrorExp;
2408 exp.type = memberSymbolErrorExp;
2412 //if(exp.type != memberExp)
2414 //FreeExpression(memberExp);
2415 //FreeIdentifier(memberID);
2420 exp.type = memberSymbolErrorExp;
2426 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
2427 FreeExpContents(exp);
2428 exp.constant = PrintUInt(ComputeTypeSize(type));
2429 exp.type = constantExp;
2435 Symbol classSym = FindClass(exp._class.name);
2436 if(classSym && classSym.registered)
2438 //exp.constant = PrintUInt(classSym.registered.size);
2439 //exp.type = constantExp;
2441 char className[1024];
2442 sprintf(className, "__ecereClass_%s", classSym.string);
2443 FreeExpContents(exp);
2444 exp.type = pointerExp;
2445 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
2446 exp.member.member = MkIdentifier("size");
2452 DebugComputeExpression(exp.cast.exp);
2454 if(ExpressionIsError(exp.cast.exp)) //.type == ExpSymbolError
2455 CarryExpressionError(exp, exp.cast.exp);
2458 exp.hasAddress = exp.cast.exp.hasAddress;
2459 exp.address = exp.cast.exp.address;
2460 if(exp.cast.exp.type == instanceExp && exp.cast.exp.expType && exp.expType && exp.cast.exp.expType.kind == classType && exp.expType.kind == classType &&
2461 exp.cast.exp.expType._class && exp.expType._class && exp.cast.exp.expType._class.registered && exp.expType._class.registered &&
2462 exp.cast.exp.expType._class.registered == exp.expType._class.registered)
2464 Instantiation inst = exp.cast.exp.instance;
2465 exp.cast.exp.instance = null;
2466 FreeExpContents(exp);
2467 exp.instance = inst;
2468 exp.type = instanceExp;
2470 else if(exp.cast.exp.type == constantExp && exp.expType)
2472 Type type = exp.expType;
2473 if(type.kind == classType && type._class && type._class.registered)
2475 Class _class = type._class.registered;
2476 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
2478 if(!_class.dataType)
2479 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
2480 type = _class.dataType;
2482 else if(_class.type == structClass && !type.byReference)
2484 FreeExpContents(exp);
2485 exp.type = unknownErrorExp;
2496 if(GetChar(exp.cast.exp, &value))
2498 FreeExpContents(exp);
2499 exp.constant = PrintChar(value);
2500 exp.type = constantExp;
2501 exp.isConstant = true;
2506 unsigned char value = 0;
2507 if(GetUChar(exp.cast.exp, &value))
2509 FreeExpContents(exp);
2510 exp.constant = PrintUChar(value);
2511 exp.type = constantExp;
2512 exp.isConstant = true;
2520 if(GetShort(exp.cast.exp, &value))
2522 FreeExpContents(exp);
2523 exp.constant = PrintShort(value);
2524 exp.type = constantExp;
2525 exp.isConstant = true;
2530 unsigned short value = 0;
2531 if(GetUShort(exp.cast.exp, &value))
2533 FreeExpContents(exp);
2534 exp.constant = PrintUShort(value);
2535 exp.type = constantExp;
2536 exp.isConstant = true;
2544 if(GetInt(exp.cast.exp, &value))
2546 FreeExpContents(exp);
2547 exp.constant = PrintInt(value);
2548 exp.type = constantExp;
2549 exp.isConstant = true;
2554 unsigned int value = 0;
2555 if(GetUInt(exp.cast.exp, &value))
2557 FreeExpContents(exp);
2558 exp.constant = PrintUInt(value);
2559 exp.type = constantExp;
2560 exp.isConstant = true;
2568 if(GetInt64(exp.cast.exp, &value))
2570 FreeExpContents(exp);
2571 exp.constant = PrintInt64(value);
2572 exp.type = constantExp;
2573 exp.isConstant = true;
2579 if(GetUInt64(exp.cast.exp, &value))
2581 FreeExpContents(exp);
2582 exp.constant = PrintUInt64(value);
2583 exp.type = constantExp;
2584 exp.isConstant = true;
2592 if(GetUInt64(exp.cast.exp, &value))
2594 FreeExpContents(exp);
2595 if(type.kind == pointerType || type.kind == classType)
2596 exp.constant = PrintHexUInt64(value);
2598 exp.constant = PrintUInt64(value);
2599 exp.type = constantExp;
2600 exp.isConstant = true;
2607 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
2608 (!strcmpi(exp.cast.exp.constant, "nan") ||
2609 !strcmpi(exp.cast.exp.constant, "-nan") ||
2610 !strcmpi(exp.cast.exp.constant, "inf") ||
2611 !strcmpi(exp.cast.exp.constant, "-inf")))
2613 String constant = exp.cast.exp.constant;
2614 exp.cast.exp.constant = null;
2615 FreeExpContents(exp);
2616 exp.constant = constant;
2617 exp.type = constantExp;
2618 exp.isConstant = true;
2620 else if(GetFloat(exp.cast.exp, &value))
2622 FreeExpContents(exp);
2623 exp.constant = DebugPrintFloat(value);
2624 exp.type = constantExp;
2625 exp.isConstant = true;
2632 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
2633 (!strcmpi(exp.cast.exp.constant, "nan") ||
2634 !strcmpi(exp.cast.exp.constant, "-nan") ||
2635 !strcmpi(exp.cast.exp.constant, "inf") ||
2636 !strcmpi(exp.cast.exp.constant, "-inf")))
2638 String constant = exp.cast.exp.constant;
2639 exp.cast.exp.constant = null;
2640 FreeExpContents(exp);
2641 exp.constant = constant;
2642 exp.type = constantExp;
2643 exp.isConstant = true;
2645 else if(GetDouble(exp.cast.exp, &value))
2647 FreeExpContents(exp);
2648 exp.constant = DebugPrintDouble(value);
2649 exp.type = constantExp;
2650 exp.isConstant = true;
2663 DebugComputeExpression(exp.cond.cond);
2665 if(ExpressionIsError(exp.cond.cond))
2666 CarryExpressionError(exp, exp.cond.cond);
2667 else if(exp.cond.cond.type == constantExp && exp.cond.cond.constant)
2669 Expression e = null;
2670 if(strtol(exp.cond.cond.constant, null, 0))
2672 for(e = exp.cond.exp ? exp.cond.exp->first : null; e; e = e.next)
2674 DebugComputeExpression(e);
2679 if(ExpressionIsError(e))
2681 CarryExpressionError(exp, e);
2685 exp.cond.exp->Remove(e);
2690 e = exp.cond.elseExp;
2693 DebugComputeExpression(e);
2694 if(ExpressionIsError(e))
2696 CarryExpressionError(exp, e);
2700 exp.cond.elseExp = null;
2705 FreeType(exp.expType);
2706 FreeType(exp.destType);
2709 FreeExpContents(exp);
2713 else if(!ExpressionIsError(exp))
2715 FreeExpContents(exp);
2716 exp.type = unknownErrorExp;
2721 FreeExpContents(exp);
2722 exp.type = unknownErrorExp;
2727 FreeExpContents(exp);
2728 exp.type = unknownErrorExp;
2735 void ApplyUnitConverters(Expression exp)
2737 Property convert = null;
2738 Type type = exp.expType;
2739 bool useGet = false;
2740 if(type.kind == classType && type._class && type._class.registered)
2742 Class _class = type._class.registered;
2743 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
2745 if(_class.type == unitClass && _class.base.type == unitClass)
2748 for(p = _class.conversions.first; p; p = p.next)
2750 if(!strcmp(p.name, _class.base.fullName))
2757 Class c = eSystem_FindClass(_class.module, p.name);
2761 for(p2 = c.conversions.first; p2; p2 = p2.next)
2763 if(!strcmp(p2.name, _class.base.fullName))
2776 if(!_class.dataType)
2777 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
2778 type = _class.dataType;
2789 if(GetChar(exp, &value))
2791 FreeExpContents(exp);
2792 exp.constant = PrintChar(value);
2793 exp.type = constantExp;
2794 exp.isConstant = true;
2799 unsigned char value = 0;
2800 if(GetUChar(exp, &value))
2802 FreeExpContents(exp);
2803 exp.constant = PrintUChar(value);
2804 exp.type = constantExp;
2805 exp.isConstant = true;
2813 if(GetShort(exp, &value))
2815 FreeExpContents(exp);
2816 exp.constant = PrintShort(value);
2817 exp.type = constantExp;
2818 exp.isConstant = true;
2823 unsigned short value = 0;
2824 if(GetUShort(exp, &value))
2826 FreeExpContents(exp);
2827 exp.constant = PrintUShort(value);
2828 exp.type = constantExp;
2829 exp.isConstant = true;
2837 if(GetInt(exp, &value))
2839 FreeExpContents(exp);
2840 exp.constant = PrintInt(value);
2841 exp.type = constantExp;
2842 exp.isConstant = true;
2847 unsigned int value = 0;
2848 if(GetUInt(exp, &value))
2850 FreeExpContents(exp);
2851 exp.constant = PrintUInt(value);
2852 exp.type = constantExp;
2853 exp.isConstant = true;
2861 if(GetInt64(exp, &value))
2863 FreeExpContents(exp);
2864 exp.constant = PrintInt64(value);
2865 exp.type = constantExp;
2866 exp.isConstant = true;
2872 if(GetUInt64(exp, &value))
2874 FreeExpContents(exp);
2875 exp.constant = PrintUInt64(value);
2876 exp.type = constantExp;
2877 exp.isConstant = true;
2885 if(GetUInt64(exp, &value))
2887 FreeExpContents(exp);
2888 if(type.kind == pointerType || type.kind == classType)
2889 exp.constant = PrintHexUInt64(value);
2891 exp.constant = PrintUInt64(value);
2892 exp.type = constantExp;
2893 exp.isConstant = true;
2900 if(exp.type == constantExp && exp.constant &&
2901 (!strcmpi(exp.constant, "nan") ||
2902 !strcmpi(exp.constant, "-nan") ||
2903 !strcmpi(exp.constant, "inf") ||
2904 !strcmpi(exp.constant, "-inf")))
2906 String constant = exp.constant;
2907 exp.constant = null;
2908 FreeExpContents(exp);
2909 exp.constant = constant;
2910 exp.type = constantExp;
2911 exp.isConstant = true;
2913 else if(GetFloat(exp, &value))
2917 float (*convertFn)(float) = (useGet ? (void *)convert.Get : (void *)convert.Set);
2919 value = convertFn(value);
2921 FreeExpContents(exp);
2922 exp.constant = DebugPrintFloat(value);
2923 exp.type = constantExp;
2924 exp.isConstant = true;
2931 if(exp.type == constantExp && exp.constant &&
2932 (!strcmpi(exp.constant, "nan") ||
2933 !strcmpi(exp.constant, "-nan") ||
2934 !strcmpi(exp.constant, "inf") ||
2935 !strcmpi(exp.constant, "-inf")))
2937 String constant = exp.constant;
2938 exp.constant = null;
2939 FreeExpContents(exp);
2940 exp.constant = constant;
2941 exp.type = constantExp;
2942 exp.isConstant = true;
2944 else if(GetDouble(exp, &value))
2948 double (*convertFn)(double) = (useGet ? (void *)convert.Get : (void *)convert.Set);
2950 value = convertFn(value);
2952 FreeExpContents(exp);
2953 exp.constant = DebugPrintDouble(value);
2954 exp.type = constantExp;
2955 exp.isConstant = true;