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;
1079 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
1081 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
1083 if(e.type == extensionCompoundExp)
1084 e = ((Statement)e.compound.compound.statements->last).expressions->last;
1088 else if(e.type == castExp)
1092 if(e.expType.kind == structType)
1094 address = exp1.address;
1098 gotAddress = GetUInt64(e, &address);
1100 dataType = exp.expType;
1101 if(dataType && dataType.kind == classType && dataType._class.registered &&
1102 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
1104 if(!dataType._class.registered.dataType && dataType._class.registered.dataTypeString)
1105 dataType._class.registered.dataType = ProcessTypeString(dataType._class.registered.dataTypeString, false);
1106 dataType = dataType._class.registered.dataType;
1109 size = ComputeTypeSize(dataType); //exp.expType.arrayType.size;
1110 if(dataType && dataType.type && dataType.kind == arrayType)
1111 // For multilevels arrays
1114 format = GetGdbFormatChar(dataType);
1115 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
1117 Expression e1 = e.op.exp1, e2 = e.op.exp2;
1118 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1120 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1122 if(e1.type == extensionCompoundExp)
1123 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1127 else if(e1.type == castExp)
1130 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1132 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1134 if(e2.type == extensionCompoundExp)
1135 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1139 else if(e2.type == castExp)
1143 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1145 offset += strtol(e.op.exp2.constant, null, 0);
1148 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1150 offset += strtol(e.op.exp1.constant, null, 0);
1157 if(e.type == stringExp)
1160 String string = e.string;
1162 Type expType = exp1.expType.type;
1163 if(expType) expType.refCount++;
1167 int len = string ? strlen(string) : 0;
1168 tmp = new char[len-2+1];
1169 len = UnescapeString(tmp, string + 1, len - 2);
1170 if(len >= 0 && offset * size + size-1 <= len)
1174 FreeExpContents(exp);
1176 exp.type = dereferenceErrorExp;
1179 exp.type = constantExp;
1180 exp.isConstant = true;
1181 switch(expType.kind)
1183 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1184 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1185 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1186 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1187 case floatType: exp.constant = DebugPrintFloat(((float *)tmp)[offset]); break;
1188 case doubleType: exp.constant = DebugPrintDouble(((double *)tmp)[offset]); break;
1190 exp.type = unknownErrorExp;
1194 exp.type = unknownErrorExp;
1198 else if(gotAddress && exp.expType.kind == arrayType)
1200 FreeExpContents(exp);
1201 exp.type = constantExp;
1202 exp.isConstant = true;
1203 exp.constant = PrintHexUInt64(address);
1204 exp.address = address;
1205 exp.hasAddress = true;
1207 else if(gotAddress && format)
1209 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1215 expNew = ParseExpressionString(evaluation);
1216 expNew.address = address;
1217 expNew.hasAddress = true;
1219 expNew.destType = exp.expType;
1220 FreeType(exp.destType);
1221 FreeExpContents(exp);
1222 ProcessExpressionType(expNew);
1223 DebugComputeExpression(expNew);
1226 expNew.isConstant = true;
1232 // Unhandled code path, evaluation is null
1233 FreeExpContents(exp);
1234 exp.type = unknownErrorExp;
1237 case memoryErrorExp:
1239 FreeExpContents(exp1);
1240 exp1.type = evalError;
1241 exp1.constant = PrintHexUInt64(address);
1246 FreeExpContents(exp1);
1247 exp1.type = evalError;
1254 FreeExpContents(exp1);
1255 exp1.type = unknownErrorExp; // Not supported yet, generate error to fallback to GDB printout
1262 op1 = GetOperand(exp1);
1263 if(op1.type) op1.type.refCount++;
1268 CarryExpressionError(exp, expError);
1269 else if(exp.type == opExp)
1271 if(exp1 && exp2 && exp1.expType && exp2.expType &&
1272 ((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) ||
1273 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
1276 if((exp.op.op == '+' || exp.op.op == '-') && (op2.type || op1.type))
1278 Expression e1 = exp1, e2 = exp2;
1279 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1281 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1283 if(e1.type == extensionCompoundExp)
1284 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1288 else if(e1.type == castExp)
1291 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1293 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1295 if(e2.type == extensionCompoundExp)
1296 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1300 else if(e2.type == castExp)
1304 if((e1.type == stringExp && op2.type && op2.type.kind == intType) || (e2.type == stringExp && op1.type && op1.type.kind == intType))
1306 uint64 offset = ((exp.op.op == '+') ? 1 : -1) * (e1.type == stringExp ? op2.i64 : op1.i64);
1307 String newString = null;
1308 Expression e = e1.type == stringExp ? e1 : e2;
1311 int len = strlen(e.string) - 2;
1312 char * tmp = OffsetEscapedString(e.string + 1, len, (int)offset);
1315 len -= tmp - (e.string + 1);
1316 newString = new char[2 + len + 1];
1317 newString[0] = '\"';
1318 memcpy(newString + 1, tmp, len);
1319 newString[1 + len] = '\"';
1320 newString[1 + len + 1] = 0;
1324 FreeExpContents(exp);
1327 exp.type = stringExp;
1328 exp.string = newString;
1331 exp.type = dereferenceErrorExp;
1333 // Can't add 2 pointers...
1334 else if(exp.op.op != '+' ||
1335 !((exp1.expType.kind == pointerType || exp1.expType.kind == arrayType) &&
1336 (exp2.expType.kind == pointerType || exp2.expType.kind == arrayType)))
1338 bool op1IsPointer = exp1.expType.kind == pointerType || exp1.expType.kind == arrayType;
1339 bool op2IsPointer = exp2.expType.kind == pointerType || exp2.expType.kind == arrayType;
1340 bool addressResult = !op1IsPointer || !op2IsPointer;
1344 size = ComputeTypeSize(exp1.expType.type);
1345 else if(op2IsPointer)
1346 size = ComputeTypeSize(exp2.expType.type);
1348 if(addressResult && size)
1350 if(op1IsPointer) op2.ui64 *= size;
1351 else if(op1IsPointer) op1.ui64 *= size;
1354 CallOperator(exp, exp1, exp2, op1, op2);
1355 if(exp.type == constantExp)
1359 exp.address = _strtoui64(exp.constant, null, 0);
1360 delete exp.constant;
1361 exp.constant = PrintHexUInt64(exp.address);
1362 if(op1.type.kind == arrayType || op2.type.kind == arrayType)
1363 exp.hasAddress = true;
1367 int64 v = _strtoi64(exp.constant, null, 0);
1369 delete exp.constant;
1370 exp.constant = PrintInt(v);
1377 FreeExpContents(exp);
1378 exp.type = unknownErrorExp; // We should have an invalid operands error
1383 if(!exp2 && exp1 && exp1.type == constantExp && exp1.constant && !strcmp(exp1.constant, "nan") && exp.op.op == '-')
1385 FreeExpContents(exp);
1386 exp.constant = CopyString("-nan");
1387 exp.type = constantExp;
1391 if((exp.op.op == '/' || exp.op.op == '%') && op2.kind != doubleType && op1.kind != doubleType && op2.kind != floatType && op1.kind != floatType &&
1392 (((op2.kind == int64Type || op2.kind == intPtrType || op2.kind == intSizeType) && !op2.i64) ||
1393 (op2.kind == intType && !op2.i) || (op2.kind == shortType && !op2.s) || (op2.kind == charType && !op2.c)))
1395 FreeExpContents(exp);
1396 exp.type = divideBy0ErrorExp;
1399 CallOperator(exp, exp1, exp2, op1, op2);
1404 if(exp.type == constantExp)
1405 exp.isConstant = true;
1413 // e = (*exp.list).first, n = e ? e.next : null;
1415 // e = n, n = n?(n.next) : null)
1417 for(e = exp.list->first; e; e = n)
1422 OldList * list = exp.list;
1423 DebugComputeExpression(e);
1424 //if(ExpressionIsError(e)) //.type == ExpSymbolError
1425 // CarryExpressionError(exp, e);
1426 //FreeExpContents(exp);
1427 FreeType(exp.expType);
1428 FreeType(exp.destType);
1445 exp.isConstant = true;
1447 DebugComputeExpression(exp.index.exp);
1448 if(ExpressionIsError(exp.index.exp)) //.type == ExpSymbolError
1449 CarryExpressionError(exp, exp.index.exp);
1452 Expression prev = exp.prev, next = exp.next;
1453 char * evaluation = null;
1454 ExpressionType evalError = dummyExp;
1455 Type dataType = exp.index.exp.expType ? exp.index.exp.expType.type : null;
1457 if(!exp.index.exp.isConstant)
1458 exp.isConstant = false;
1461 // 4 == size = ComputeTypeSize(exp.expType);
1462 // 0 == size = ComputeTypeSize(exp.expType.arrayType);
1463 // 4 == size = ComputeTypeSize(exp.index.exp.expType);
1464 // 0 == size = ComputeTypeSize(exp.index.exp.expType.arrayType);
1466 if(dataType && dataType.kind == classType && dataType._class.registered &&
1467 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
1469 if(!dataType._class.registered.dataType && dataType._class.registered.dataTypeString)
1470 dataType._class.registered.dataType = ProcessTypeString(dataType._class.registered.dataTypeString, false);
1471 dataType = dataType._class.registered.dataType;
1474 size = ComputeTypeSize(dataType);
1475 if(dataType && dataType.type && dataType.kind == arrayType)
1476 // For multilevels arrays
1479 format = GetGdbFormatChar(dataType);
1481 for(e = exp.index.index->first; e; e = e.next)
1483 DebugComputeExpression(e);
1484 if(ExpressionIsError(e)) //.type == ExpSymbolError
1486 CarryExpressionError(exp, e);
1491 // Check if this type is int
1494 exp.isConstant = false;
1496 if(!ExpressionIsError(exp))
1498 // Is this necessary here? pass15 had done this already...
1499 if(exp.expType) FreeType(exp.expType);
1500 exp.expType = Dereference(exp.index.exp.expType);
1505 FreeExpContents(exp);
1506 exp.type = dereferenceErrorExp;
1508 else if(exp.index.index && exp.index.index->last && ((Expression)exp.index.index->last) && ((Expression)exp.index.index->last).expType)
1510 Type type = ((Expression)exp.index.index->last).expType;
1511 if(type.kind == intType || type.kind == charType || type.kind == shortType || type.kind == int64Type || type.kind == intPtrType ||
1512 type.kind == intSizeType || type.kind == longType || type.kind == _BoolType || type.kind == enumType ||
1513 (type.kind == classType && type._class && type._class.registered &&
1514 type._class.registered.type == enumClass))
1516 bool gotAddress = false;
1517 uint64 address = 0, offset = 0;
1518 Expression expNew, last = (Expression)exp.index.index->last;
1519 Expression e = exp.index.exp;
1521 while(((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list) || e.type == castExp)
1523 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
1525 if(e.type == extensionCompoundExp)
1526 e = ((Statement)e.compound.compound.statements->last).expressions->last;
1530 else if(e.type == castExp)
1534 //GetUInt(exp.index.exp, &address);
1536 GetUInt64(last, &offset);
1538 // TOFIX: Check if it has address: TESTING
1539 if(exp.index.exp.hasAddress && exp.index.exp.expType.kind == arrayType)
1541 address = exp.index.exp.address;
1544 else if(exp.index.exp.type == constantExp)
1545 gotAddress = GetUInt64(exp.index.exp, &address);
1547 while(e.type == opExp && e.op.op == '+' && e.op.exp1 && e.op.exp2)
1549 Expression e1 = e.op.exp1, e2 = e.op.exp2;
1550 while(((e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp) && e1.list) || e1.type == castExp)
1552 if(e1.type == bracketsExp || e1.type == extensionExpressionExp || e1.type == extensionCompoundExp)
1554 if(e1.type == extensionCompoundExp)
1555 e1 = ((Statement)e1.compound.compound.statements->last).expressions->last;
1559 else if(e1.type == castExp)
1562 while(((e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp) && e2.list) || e2.type == castExp)
1564 if(e2.type == bracketsExp || e2.type == extensionExpressionExp || e2.type == extensionCompoundExp)
1566 if(e2.type == extensionCompoundExp)
1567 e2 = ((Statement)e2.compound.compound.statements->last).expressions->last;
1571 else if(e2.type == castExp)
1575 if((e1.type == stringExp || e1.type == opExp) && e.op.exp2.isConstant && e.op.exp2.expType && e.op.exp2.expType.kind == intType)
1577 offset += strtol(e.op.exp2.constant, null, 0);
1580 else if((e2.type == stringExp || e2.type == opExp) && e.op.exp1.isConstant && e.op.exp1.expType && e.op.exp1.expType.kind == intType)
1582 offset += strtol(e.op.exp1.constant, null, 0);
1589 //size = ComputeTypeSize(exp.expType.arrayType); //exp.expType.arrayType.size;
1590 address += offset * size;
1592 if(e.type == stringExp)
1595 String string = e.string;
1597 Type expType = exp.index.exp.expType.type;
1598 if(expType) expType.refCount++;
1602 int len = string ? strlen(string) : 0;
1603 tmp = new char[len-2+1];
1604 len = UnescapeString(tmp, string + 1, len - 2);
1605 if(len >= 0 && offset * size + size-1 <= len)
1609 FreeExpContents(exp);
1611 exp.type = dereferenceErrorExp;
1614 exp.type = constantExp;
1615 exp.isConstant = true;
1616 switch(expType.kind)
1618 case charType: exp.constant = expType.isSigned ? PrintChar(((char *)tmp)[offset]) : PrintUChar(((byte *)tmp)[offset]); break;
1619 case shortType: exp.constant = expType.isSigned ? PrintShort(((short *)tmp)[offset]) : PrintUShort(((uint16 *)tmp)[offset]); break;
1620 case intType: exp.constant = expType.isSigned ? PrintInt(((int *)tmp)[offset]) : PrintUInt(((uint *)tmp)[offset]); break;
1621 case int64Type: exp.constant = expType.isSigned ? PrintInt64(((int64 *)tmp)[offset]) : PrintUInt64(((uint64 *)tmp)[offset]); break;
1622 case floatType: exp.constant = DebugPrintFloat(((float *)tmp)[offset]); break;
1623 case doubleType: exp.constant = DebugPrintDouble(((double *)tmp)[offset]); break;
1625 exp.type = unknownErrorExp;
1629 exp.type = unknownErrorExp;
1633 else if(gotAddress && exp.expType.kind == arrayType)
1635 FreeExpContents(exp);
1636 exp.type = constantExp;
1637 exp.isConstant = true;
1638 exp.constant = PrintHexUInt64(address);
1639 exp.address = address;
1640 exp.hasAddress = true;
1644 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
1650 expNew = ParseExpressionString(evaluation);
1652 expNew.destType = exp.expType;
1653 FreeType(exp.destType);
1654 FreeExpContents(exp);
1655 ProcessExpressionType(expNew);
1656 DebugComputeExpression(expNew);
1658 // TOFIX: Only for Array Types
1659 expNew.address = address;
1661 expNew.hasAddress = true;
1664 expNew.isConstant = true;
1670 // Unhandled code path, evaluation is null
1671 FreeExpContents(exp);
1672 exp.type = unknownErrorExp;
1675 case memoryErrorExp:
1677 FreeExpContents(exp);
1678 exp.type = evalError;
1679 exp.constant = PrintHexUInt64(address);
1683 FreeExpContents(exp);
1684 exp.type = evalError;
1690 FreeExpContents(exp);
1691 exp.type = unknownErrorExp;
1701 Expression callExp = exp.call.exp;
1702 Identifier id = (callExp && callExp.type == identifierExp) ? callExp.identifier : null;
1703 bool resolved = false;
1706 if(!strcmp(id.string, "nan") || !strcmp(id.string, "inf"))
1708 String s = id.string;
1710 FreeExpContents(exp);
1711 exp.type = constantExp;
1715 else if(exp.call.arguments)
1717 if(exp.call.arguments->count == 1)
1719 double (* fn1)(double) = (void *)oneArgFns[id.string];
1722 Expression arg = exp.call.arguments->first;
1723 DebugComputeExpression(arg);
1724 if(ExpressionIsError(arg))
1725 CarryExpressionError(exp, arg);
1726 else if(arg.isConstant && arg.type == constantExp)
1729 if(GetDouble(arg, &v))
1731 FreeExpContents(exp);
1732 exp.type = constantExp;
1734 exp.constant = DebugPrintDouble(v);
1735 exp.isConstant = true;
1741 else if(exp.call.arguments->count == 2)
1743 double (* fn2)(double, double) = (void *)twoArgFns[id.string];
1746 Expression arg1 = exp.call.arguments->first;
1747 Expression arg2 = exp.call.arguments->last;
1748 DebugComputeExpression(arg1);
1749 DebugComputeExpression(arg2);
1750 if(ExpressionIsError(arg1))
1751 CarryExpressionError(exp, arg1);
1752 else if(ExpressionIsError(arg2))
1753 CarryExpressionError(exp, arg2);
1754 else if(arg1.isConstant && arg1.type == constantExp && arg2.isConstant && arg2.type == constantExp)
1757 if(GetDouble(arg1, &v1) && GetDouble(arg2, &v2))
1759 FreeExpContents(exp);
1760 exp.type = constantExp;
1762 exp.constant = DebugPrintDouble(v1);
1763 exp.isConstant = true;
1772 exp.type = functionCallErrorExp;
1777 Expression memberExp = exp.member.exp;
1778 Identifier memberID = exp.member.member;
1780 Property prop = null;
1781 DataMember member = null;
1782 Class convertTo = null;
1783 uint offset = 0; // THIS WASN'T INITIALIZED... IS IT ALWAYS SET?
1785 Type type; // = memberExp.expType;
1786 DebugComputeExpression(memberExp);
1787 type = memberExp.expType;
1788 if(ExpressionIsError(memberExp))
1789 CarryExpressionError(exp, memberExp);
1792 // _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
1793 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);
1796 char string[256] = "";
1798 PrintTypeNoConst(type, string, false, true);
1799 classSym = FindClass(string);
1800 _class = classSym ? classSym.registered : null;
1803 if(memberID && _class)
1806 prop = eClass_FindProperty(_class, memberID.string);
1808 member = eClass_FindDataMember(_class, memberID.string);
1810 // member = eClass_FindDataMember(_class, memberID.string);
1811 member = eClass_FindDataMemberAndOffset(_class, memberID.string, &offset, _class.module.application, null, null);
1813 prop = eClass_FindProperty(_class, memberID.string, _class.module.application);
1815 if(!prop && !member && _class && memberID)
1817 Symbol classSym = FindClass(memberID.string);
1819 _class = classSym ? classSym.registered : null;
1821 prop = eClass_FindProperty(_class, convertTo.fullName, _class.module.application);
1824 //DebugComputeExpression(memberExp);
1825 if(ExpressionIsError(memberExp))
1826 CarryExpressionError(exp, memberExp);
1829 if(exp.member.memberType == methodMember)
1831 FreeExpContents(exp);
1832 exp.type = unknownErrorExp;
1836 bool supported = false;
1839 Type type = prop.dataType;
1840 // TODO: Assuming same base type for units...
1841 if(_class.type == unitClass)
1843 if(type.kind == classType)
1845 Class _class = type._class.registered;
1846 if(_class.type == unitClass)
1848 if(!_class.dataType)
1849 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
1850 type = _class.dataType;
1858 float (*Get)(float) = (convertTo ? (void *)prop.Set : (void *)prop.Get);
1859 GetFloat(memberExp, &value);
1861 FreeExpContents(exp);
1862 exp.constant = DebugPrintFloat(Get ? Get(value) : value);
1863 exp.type = constantExp;
1864 exp.isConstant = true;
1871 double (*Get)(double) = (convertTo ? (void *)prop.Set : (void *)prop.Get);
1872 GetDouble(memberExp, &value);
1874 FreeExpContents(exp);
1875 exp.constant = DebugPrintDouble(Get ? Get(value) : value);
1876 exp.isConstant = true;
1877 exp.type = constantExp;
1887 Expression value = memberExp;
1888 Type type = prop.dataType;
1889 exp.member.exp = null;
1891 if(_class.type == structClass)
1897 Class propertyClass = type._class.registered;
1898 if(propertyClass.type == structClass && value.type == instanceExp)
1900 void (*Set)(void *, void *) = (void *)prop.Set;
1901 FreeExpContents(exp);
1902 exp.instance = Instantiation
1904 data = new0 byte[_class.structSize];
1905 _class = MkSpecifierName(_class.name);
1908 exp.type = instanceExp;
1910 Set(exp.instance.data, value.instance.data);
1911 PopulateInstance(exp.instance);
1919 void (*Set)(void *, int) = (void *)prop.Set;
1921 GetInt(value, &intValue);
1922 FreeExpContents(exp);
1923 exp.instance = Instantiation
1925 data = new0 byte[_class.structSize];
1926 _class = MkSpecifierName/*MkClassName*/(_class.name);
1929 exp.type = instanceExp;
1931 Set(exp.instance.data, intValue);
1932 PopulateInstance(exp.instance);
1939 void (*Set)(void *, int64) = (void *)prop.Set;
1941 GetInt64(value, &intValue);
1942 FreeExpContents(exp);
1943 exp.instance = Instantiation
1945 data = new0 byte[_class.structSize];
1946 _class = MkSpecifierName/*MkClassName*/(_class.name);
1949 exp.type = instanceExp;
1951 Set(exp.instance.data, intValue);
1952 PopulateInstance(exp.instance);
1959 void (*Set)(void *, float) = (void *)prop.Set;
1961 GetFloat(value, &floatValue);
1962 FreeExpContents(exp);
1963 exp.instance = Instantiation
1965 data = new0 byte[_class.structSize];
1966 _class = MkSpecifierName/*MkClassName*/(_class.name);
1969 exp.type = instanceExp;
1971 Set(exp.instance.data, floatValue);
1972 PopulateInstance(exp.instance);
1979 void (*Set)(void *, double) = (void *)prop.Set;
1981 GetDouble(value, &doubleValue);
1982 FreeExpContents(exp);
1983 exp.instance = Instantiation
1985 data = new0 byte[_class.structSize];
1986 _class = MkSpecifierName/*MkClassName*/(_class.name);
1989 exp.type = instanceExp;
1991 Set(exp.instance.data, doubleValue);
1992 PopulateInstance(exp.instance);
1998 else if(_class.type == bitClass)
2004 Class propertyClass = type._class.registered;
2005 if(propertyClass.type == structClass && value.instance.data)
2007 unsigned int (*Set)(void *) = (void *)prop.Set;
2008 unsigned int bits = Set(value.instance.data);
2009 FreeExpContents(exp);
2010 exp.constant = PrintHexUInt(bits);
2011 exp.type = constantExp;
2015 else if(_class.type == bitClass)
2018 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
2021 GetUInt(memberExp, &value);
2023 FreeExpContents(exp);
2024 exp.constant = PrintHexUInt(bits);
2025 exp.type = constantExp;
2031 FreeExpression(value);
2035 if(_class.type == bitClass)
2038 GetUInt(memberExp, &value);
2044 Class _class = type._class.registered;
2045 if(_class.type == structClass)
2047 void (*Get)(unsigned int, void *) = (void *)prop.Get;
2049 FreeExpContents(exp);
2050 exp.instance = Instantiation
2052 data = new0 byte[_class.structSize];
2053 _class = MkSpecifierName/*MkClassName*/(_class.name);
2056 //exp.instance.fullSet = true;
2057 exp.type = instanceExp;
2058 Get(value, exp.instance.data);
2059 PopulateInstance(exp.instance);
2062 else if(_class.type == bitClass)
2064 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
2065 uint64 bits = Get(value);
2066 exp.constant = PrintHexUInt64(bits);
2067 exp.type = constantExp;
2074 else if(_class.type == structClass)
2076 byte * value = (memberExp.type == instanceExp ) ? memberExp.instance.data : null;
2078 memberExp.instance.data = null;
2084 Class _class = type._class.registered;
2085 if(_class.type == structClass && value)
2087 void (*Get)(void *, void *) = (void *)prop.Get;
2089 FreeExpContents(exp);
2090 exp.instance = Instantiation
2092 data = new0 byte[_class.structSize];
2093 _class = MkSpecifierName/*MkClassName*/(_class.name);
2096 //exp.instance.fullSet = true;
2097 exp.type = instanceExp;
2098 Get(value, exp.instance.data);
2099 PopulateInstance(exp.instance);
2110 char * value = memberExp.instance.data;
2115 Class _class = type._class.registered;
2116 if(_class.type == normalClass)
2118 void *(*Get)(void *) = (void *)prop.Get;
2120 FreeExpContents(exp);
2121 exp.instance = Instantiation
2123 data = Get(value, exp.instance.data); ?????
2124 _class = MkSpecifierName(_class.name); //MkClassName(_class.name);
2127 exp.type = instanceExp;
2139 exp.type = memberPropertyErrorExp;
2140 exp.isConstant = false;
2145 if(memberExp.hasAddress || memberExp.type == constantExp || (memberExp.type == instanceExp && memberExp.instance && memberExp.instance.data))
2146 //if(memberExp.expType && memberExp.expType.kind == intType) // && !exp.index.exp.expType.isSigned
2148 if(_class.type == bitClass)
2150 if(memberExp.type == constantExp)
2152 // Unfinished business...
2153 BitMember bitMember = (BitMember)member;
2155 GetUInt64(memberExp, &bits);
2156 bits &= bitMember.mask;
2157 bits >>= bitMember.pos;
2159 FreeExpression(exp.member.exp);
2160 FreeIdentifier(exp.member.member);
2162 exp.constant = PrintUInt64(bits);
2164 exp.isConstant = true;
2165 exp.type = constantExp;
2166 exp.hasAddress = false;
2171 char * evaluation = null;
2172 ExpressionType evalError = dummyExp;
2173 bool gotAddress = false;
2175 Expression prev = exp.prev, next = exp.next;
2179 Type dataType = member.dataType;
2182 dataType = member.dataType = ProcessTypeString(member.dataTypeString, false);
2184 if(dataType && dataType.kind == classType && dataType._class.registered &&
2185 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
2187 if(!dataType._class.registered.dataType && dataType._class.registered.dataTypeString)
2188 dataType._class.registered.dataType = ProcessTypeString(dataType._class.registered.dataTypeString, false);
2189 dataType = dataType._class.registered.dataType;
2191 dataType = ProcessTypeString("int", false);
2194 size = ComputeTypeSize(member.dataType);
2196 format = GetGdbFormatChar(dataType);
2197 //if(memberExp.address)
2199 //GetInt(memberExp, &address);
2200 //offset = member.offset;
2202 // TESTING NOHEAD HERE?
2203 if(_class.type == normalClass || _class.type == noHeadClass || _class.type == systemClass)
2204 offset += member._class.offset;
2206 // VERIFY THIS: (trying to fix primitive.type)
2207 // if(memberExp.type == constantExp)
2208 if(memberExp.hasAddress && (_class.type != normalClass && _class.type != noHeadClass && _class.type != systemClass))
2210 address = memberExp.address;
2213 else if(memberExp.type == constantExp)
2214 gotAddress = GetUInt64(memberExp, &address);
2217 gotAddress = GetUInt64(memberExp, &address);
2218 //printf("Unhandled !!\n");
2220 //printf("memberExp.hasAddress = %d\n", memberExp.hasAddress);
2221 //printf("memberExp.type = %d\n", memberExp.type);
2222 //printf("_class.name = %s, _class.type = %d\n", _class.name, _class.type);
2227 if(memberExp.type == instanceExp)
2229 String constant = null;
2230 byte * data = memberExp.instance.data + offset;
2231 switch(dataType.kind)
2234 if(dataType.isSigned)
2235 constant = PrintChar(*(char *)data);
2237 constant = PrintUChar(*(byte *)data);
2240 if(dataType.isSigned)
2241 constant = PrintShort(*(short *)data);
2243 constant = PrintUShort(*(uint16 *)data);
2246 if(dataType.isSigned)
2247 constant = PrintInt(*(int *)data);
2249 constant = PrintUInt(*(uint *)data);
2253 if(dataType.isSigned)
2254 constant = PrintInt64(*(int64 *)data);
2256 constant = PrintUInt64(*(uint64 *)data);
2258 case floatType: constant = DebugPrintFloat(*(float *)data); break;
2259 case doubleType: constant = DebugPrintDouble(*(double *)data); break;
2263 FreeExpContents(exp);
2264 exp.constant = constant;
2265 exp.type = constantExp;
2266 exp.isConstant = true;
2269 exp.type = unknownErrorExp;
2271 else if(!gotAddress)
2273 FreeExpContents(exp);
2274 exp.type = unknownErrorExp;
2276 else if((dataType.kind == classType && dataType._class &&
2277 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
2278 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
2280 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
2281 if(evalError != dummyExp)
2283 exp.type = evalError;
2284 exp.constant = PrintHexUInt64(address);
2288 //printf("evaluation = %s\n", evaluation);
2289 expNew = ParseExpressionString(evaluation);
2291 expNew.destType = exp.expType;
2294 exp.expType.refCount++;
2295 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == unitClass)
2297 expNew.expType = exp.expType;
2298 exp.expType.refCount++;
2301 //FreeType(memberExp.destType);
2302 FreeType(exp.expType);
2303 FreeType(exp.destType);
2304 FreeExpContents(exp);
2305 ProcessExpressionType(expNew);
2306 DebugComputeExpression(expNew);
2309 expNew.isConstant = true;
2310 expNew.address = address;
2311 expNew.hasAddress = true;
2317 FreeExpContents(exp);
2318 exp.type = unknownErrorExp;
2323 // TESTING THIS HERE...
2324 exp.type = constantExp;
2325 exp.constant = PrintHexUInt64(address);
2327 exp.address = address;
2328 exp.hasAddress = true;
2329 exp.isConstant = true;
2334 // exp.type = ExpUnknownError;
2336 //FreeExpContents(exp);
2337 //exp.constant = PrintUInt64(value);
2338 //exp.type = constantExp;
2343 if(type && (type.kind == structType || type.kind == unionType))
2346 Type memberType = exp.member.member ? FindMemberAndOffset(type, exp.member.member.string, &offset) : null;
2349 char * evaluation = null;
2350 ExpressionType evalError = dummyExp;
2352 bool gotAddress = false;
2353 Expression prev = exp.prev, next = exp.next;
2355 int size = memberType.size;
2357 Type dataType = memberType;
2359 if(dataType.kind == classType && dataType._class.registered &&
2360 (dataType._class.registered.type == enumClass || dataType._class.registered.type == bitClass || dataType._class.registered.type == unitClass))
2362 if(dataType._class.registered.dataTypeString && !dataType._class.registered.dataType)
2363 dataType._class.registered.dataType = ProcessTypeString(dataType._class.registered.dataTypeString, false);
2364 dataType = dataType._class.registered.dataType;
2367 format = GetGdbFormatChar(dataType);
2369 if(memberExp.hasAddress)
2371 address = memberExp.address;
2374 else if(memberExp.type == constantExp)
2375 gotAddress = GetUInt64(memberExp, &address);
2381 FreeExpContents(exp);
2382 exp.type = unknownErrorExp;
2384 else if((dataType.kind == classType && dataType._class &&
2385 (!dataType._class.registered || dataType._class.registered.type == normalClass || dataType._class.registered.type == noHeadClass || dataType._class.registered.type == systemClass)) ||
2386 (dataType.kind != classType && dataType.kind != arrayType && dataType.kind != structType && dataType.kind != unionType))
2388 evaluation = Debugger::ReadMemory(address, size, format, &evalError);
2389 if(evalError != dummyExp)
2391 exp.type = evalError;
2392 exp.constant = PrintHexUInt64(address);
2396 expNew = ParseExpressionString(evaluation);
2398 expNew.destType = exp.expType;
2400 exp.expType.refCount++;
2401 //FreeType(memberExp.destType);
2402 FreeType(exp.expType);
2403 FreeType(exp.destType);
2404 FreeExpContents(exp);
2405 ProcessExpressionType(expNew);
2406 DebugComputeExpression(expNew);
2409 expNew.isConstant = true;
2410 expNew.address = address;
2411 expNew.hasAddress = true;
2417 FreeExpContents(exp);
2418 exp.type = unknownErrorExp;
2423 FreeExpContents(exp);
2425 // TESTING THIS HERE...
2426 exp.type = constantExp;
2427 exp.constant = PrintHexUInt64(address);
2429 exp.address = address;
2430 exp.hasAddress = true;
2431 exp.isConstant = true;
2435 exp.type = memberSymbolErrorExp;
2438 exp.type = memberSymbolErrorExp;
2442 //if(exp.type != memberExp)
2444 //FreeExpression(memberExp);
2445 //FreeIdentifier(memberID);
2450 exp.type = memberSymbolErrorExp;
2456 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
2457 FreeExpContents(exp);
2458 exp.constant = PrintUInt(ComputeTypeSize(type));
2459 exp.type = constantExp;
2465 Symbol classSym = FindClass(exp._class.name);
2466 if(classSym && classSym.registered)
2468 //exp.constant = PrintUInt(classSym.registered.size);
2469 //exp.type = constantExp;
2471 char className[1024];
2472 sprintf(className, "__ecereClass_%s", classSym.string);
2473 FreeExpContents(exp);
2474 exp.type = pointerExp;
2475 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
2476 exp.member.member = MkIdentifier("size");
2482 DebugComputeExpression(exp.cast.exp);
2484 if(ExpressionIsError(exp.cast.exp)) //.type == ExpSymbolError
2485 CarryExpressionError(exp, exp.cast.exp);
2488 exp.hasAddress = exp.cast.exp.hasAddress;
2489 exp.address = exp.cast.exp.address;
2490 if(exp.cast.exp.type == instanceExp && exp.cast.exp.expType && exp.expType && exp.cast.exp.expType.kind == classType && exp.expType.kind == classType &&
2491 exp.cast.exp.expType._class && exp.expType._class && exp.cast.exp.expType._class.registered && exp.expType._class.registered &&
2492 exp.cast.exp.expType._class.registered == exp.expType._class.registered)
2494 Instantiation inst = exp.cast.exp.instance;
2495 exp.cast.exp.instance = null;
2496 FreeExpContents(exp);
2497 exp.instance = inst;
2498 exp.type = instanceExp;
2500 else if(exp.cast.exp.type == constantExp && exp.expType)
2502 Type type = exp.expType;
2503 if(type.kind == classType && type._class && type._class.registered)
2505 Class _class = type._class.registered;
2506 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
2508 if(!_class.dataType)
2509 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
2510 type = _class.dataType;
2512 else if(_class.type == structClass && !type.byReference)
2514 FreeExpContents(exp);
2515 exp.type = unknownErrorExp;
2526 if(GetChar(exp.cast.exp, &value))
2528 FreeExpContents(exp);
2529 exp.constant = PrintChar(value);
2530 exp.type = constantExp;
2531 exp.isConstant = true;
2536 unsigned char value = 0;
2537 if(GetUChar(exp.cast.exp, &value))
2539 FreeExpContents(exp);
2540 exp.constant = PrintUChar(value);
2541 exp.type = constantExp;
2542 exp.isConstant = true;
2550 if(GetShort(exp.cast.exp, &value))
2552 FreeExpContents(exp);
2553 exp.constant = PrintShort(value);
2554 exp.type = constantExp;
2555 exp.isConstant = true;
2560 unsigned short value = 0;
2561 if(GetUShort(exp.cast.exp, &value))
2563 FreeExpContents(exp);
2564 exp.constant = PrintUShort(value);
2565 exp.type = constantExp;
2566 exp.isConstant = true;
2574 if(GetInt(exp.cast.exp, &value))
2576 FreeExpContents(exp);
2577 exp.constant = PrintInt(value);
2578 exp.type = constantExp;
2579 exp.isConstant = true;
2584 unsigned int value = 0;
2585 if(GetUInt(exp.cast.exp, &value))
2587 FreeExpContents(exp);
2588 exp.constant = PrintUInt(value);
2589 exp.type = constantExp;
2590 exp.isConstant = true;
2598 if(GetInt64(exp.cast.exp, &value))
2600 FreeExpContents(exp);
2601 exp.constant = PrintInt64(value);
2602 exp.type = constantExp;
2603 exp.isConstant = true;
2609 if(GetUInt64(exp.cast.exp, &value))
2611 FreeExpContents(exp);
2612 exp.constant = PrintUInt64(value);
2613 exp.type = constantExp;
2614 exp.isConstant = true;
2622 if(GetUInt64(exp.cast.exp, &value))
2624 FreeExpContents(exp);
2625 if(type.kind == pointerType || type.kind == classType)
2626 exp.constant = PrintHexUInt64(value);
2628 exp.constant = PrintUInt64(value);
2629 exp.type = constantExp;
2630 exp.isConstant = true;
2637 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
2638 (!strcmpi(exp.cast.exp.constant, "nan") ||
2639 !strcmpi(exp.cast.exp.constant, "-nan") ||
2640 !strcmpi(exp.cast.exp.constant, "inf") ||
2641 !strcmpi(exp.cast.exp.constant, "-inf")))
2643 String constant = exp.cast.exp.constant;
2644 exp.cast.exp.constant = null;
2645 FreeExpContents(exp);
2646 exp.constant = constant;
2647 exp.type = constantExp;
2648 exp.isConstant = true;
2650 else if(GetFloat(exp.cast.exp, &value))
2652 FreeExpContents(exp);
2653 exp.constant = DebugPrintFloat(value);
2654 exp.type = constantExp;
2655 exp.isConstant = true;
2662 if(exp.cast.exp.type == constantExp && exp.cast.exp.constant &&
2663 (!strcmpi(exp.cast.exp.constant, "nan") ||
2664 !strcmpi(exp.cast.exp.constant, "-nan") ||
2665 !strcmpi(exp.cast.exp.constant, "inf") ||
2666 !strcmpi(exp.cast.exp.constant, "-inf")))
2668 String constant = exp.cast.exp.constant;
2669 exp.cast.exp.constant = null;
2670 FreeExpContents(exp);
2671 exp.constant = constant;
2672 exp.type = constantExp;
2673 exp.isConstant = true;
2675 else if(GetDouble(exp.cast.exp, &value))
2677 FreeExpContents(exp);
2678 exp.constant = DebugPrintDouble(value);
2679 exp.type = constantExp;
2680 exp.isConstant = true;
2693 DebugComputeExpression(exp.cond.cond);
2695 if(ExpressionIsError(exp.cond.cond))
2696 CarryExpressionError(exp, exp.cond.cond);
2697 else if(exp.cond.cond.type == constantExp && exp.cond.cond.constant)
2699 Expression e = null;
2700 if(strtol(exp.cond.cond.constant, null, 0))
2702 for(e = exp.cond.exp ? exp.cond.exp->first : null; e; e = e.next)
2704 DebugComputeExpression(e);
2709 if(ExpressionIsError(e))
2711 CarryExpressionError(exp, e);
2715 exp.cond.exp->Remove(e);
2720 e = exp.cond.elseExp;
2723 DebugComputeExpression(e);
2724 if(ExpressionIsError(e))
2726 CarryExpressionError(exp, e);
2730 exp.cond.elseExp = null;
2735 FreeType(exp.expType);
2736 FreeType(exp.destType);
2739 FreeExpContents(exp);
2743 else if(!ExpressionIsError(exp))
2745 FreeExpContents(exp);
2746 exp.type = unknownErrorExp;
2751 FreeExpContents(exp);
2752 exp.type = unknownErrorExp;
2757 FreeExpContents(exp);
2758 exp.type = unknownErrorExp;
2765 void ApplyUnitConverters(Expression exp)
2767 Property convert = null;
2768 Type type = exp.expType;
2769 bool useGet = false;
2770 if(type.kind == classType && type._class && type._class.registered)
2772 Class _class = type._class.registered;
2773 if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
2775 if(_class.type == unitClass && _class.base.type == unitClass)
2778 for(p = _class.conversions.first; p; p = p.next)
2780 if(!strcmp(p.name, _class.base.fullName))
2787 Class c = eSystem_FindClass(_class.module, p.name);
2791 for(p2 = c.conversions.first; p2; p2 = p2.next)
2793 if(!strcmp(p2.name, _class.base.fullName))
2806 if(!_class.dataType)
2807 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
2808 type = _class.dataType;
2819 if(GetChar(exp, &value))
2821 FreeExpContents(exp);
2822 exp.constant = PrintChar(value);
2823 exp.type = constantExp;
2824 exp.isConstant = true;
2829 unsigned char value = 0;
2830 if(GetUChar(exp, &value))
2832 FreeExpContents(exp);
2833 exp.constant = PrintUChar(value);
2834 exp.type = constantExp;
2835 exp.isConstant = true;
2843 if(GetShort(exp, &value))
2845 FreeExpContents(exp);
2846 exp.constant = PrintShort(value);
2847 exp.type = constantExp;
2848 exp.isConstant = true;
2853 unsigned short value = 0;
2854 if(GetUShort(exp, &value))
2856 FreeExpContents(exp);
2857 exp.constant = PrintUShort(value);
2858 exp.type = constantExp;
2859 exp.isConstant = true;
2867 if(GetInt(exp, &value))
2869 FreeExpContents(exp);
2870 exp.constant = PrintInt(value);
2871 exp.type = constantExp;
2872 exp.isConstant = true;
2877 unsigned int value = 0;
2878 if(GetUInt(exp, &value))
2880 FreeExpContents(exp);
2881 exp.constant = PrintUInt(value);
2882 exp.type = constantExp;
2883 exp.isConstant = true;
2891 if(GetInt64(exp, &value))
2893 FreeExpContents(exp);
2894 exp.constant = PrintInt64(value);
2895 exp.type = constantExp;
2896 exp.isConstant = true;
2902 if(GetUInt64(exp, &value))
2904 FreeExpContents(exp);
2905 exp.constant = PrintUInt64(value);
2906 exp.type = constantExp;
2907 exp.isConstant = true;
2915 if(GetUInt64(exp, &value))
2917 FreeExpContents(exp);
2918 if(type.kind == pointerType || type.kind == classType)
2919 exp.constant = PrintHexUInt64(value);
2921 exp.constant = PrintUInt64(value);
2922 exp.type = constantExp;
2923 exp.isConstant = true;
2930 if(exp.type == constantExp && exp.constant &&
2931 (!strcmpi(exp.constant, "nan") ||
2932 !strcmpi(exp.constant, "-nan") ||
2933 !strcmpi(exp.constant, "inf") ||
2934 !strcmpi(exp.constant, "-inf")))
2936 String constant = exp.constant;
2937 exp.constant = null;
2938 FreeExpContents(exp);
2939 exp.constant = constant;
2940 exp.type = constantExp;
2941 exp.isConstant = true;
2943 else if(GetFloat(exp, &value))
2947 float (*convertFn)(float) = (useGet ? (void *)convert.Get : (void *)convert.Set);
2949 value = convertFn(value);
2951 FreeExpContents(exp);
2952 exp.constant = DebugPrintFloat(value);
2953 exp.type = constantExp;
2954 exp.isConstant = true;
2961 if(exp.type == constantExp && exp.constant &&
2962 (!strcmpi(exp.constant, "nan") ||
2963 !strcmpi(exp.constant, "-nan") ||
2964 !strcmpi(exp.constant, "inf") ||
2965 !strcmpi(exp.constant, "-inf")))
2967 String constant = exp.constant;
2968 exp.constant = null;
2969 FreeExpContents(exp);
2970 exp.constant = constant;
2971 exp.type = constantExp;
2972 exp.isConstant = true;
2974 else if(GetDouble(exp, &value))
2978 double (*convertFn)(double) = (useGet ? (void *)convert.Get : (void *)convert.Set);
2980 value = convertFn(value);
2982 FreeExpContents(exp);
2983 exp.constant = DebugPrintDouble(value);
2984 exp.type = constantExp;
2985 exp.isConstant = true;