const void* Stack::checkAndGetTopPointer(const char* what) { auto type = mStack[mTop].type(); switch (type) { case BaseType::AbsolutePointer: { return mStack[mTop].value<const void*>(); } case BaseType::ConstantPointer: { uint32_t offset = mStack[mTop].value<uint32_t>(); const void* pointer = mMemoryManager->constantToAbsolute(offset); if (!mMemoryManager->isConstantAddress(pointer)) { GAPID_WARNING("%s: Invalid constant address %p offset 0x%x", what, pointer, offset); mValid = false; return nullptr; } return pointer; } case BaseType::VolatilePointer: { uint32_t offset = mStack[mTop].value<uint32_t>(); void* pointer = mMemoryManager->volatileToAbsolute(offset); if (!mMemoryManager->isVolatileAddress(pointer)) { GAPID_WARNING("%s Invalid volatile address %p offset 0x%x", what, pointer, offset); mValid = false; return nullptr; } return pointer; } default: GAPID_WARNING("%s top was not a pointer type: %s", what, baseTypeName(type)); mValid = false; return nullptr; } return nullptr; }
/** * @brief Type::Type * @param name * @param scopeId * @param typeId */ Type::Type(const QString &name, const QString &scopeId, const QString &typeId) : BasicEntity(name) , m_Id(typeId.isEmpty() ? utility::genId() : typeId) , m_ScopeId(scopeId) { if (m_Name.isEmpty() || m_Name == DEFAULT_NAME) baseTypeName(); }
/* Print out a function as a parameter type in XML format */ int ParameterFunctions(FILE *fp, FunctionInfo *func, int indentation, int designator) { int type_number; int total_arguments = 0; int typeOne = 0; int typeTwo = 0; if (func->NumberOfArguments > 0) { type_number = func->ArgTypes[0]; typeOne = func->ArgTypes[0]; typeTwo = typeOne; /* if has exactly 2 arguments (checking for the special cases where * the function takes an index then a double as the actual value */ if (func->NumberOfArguments == 2) { typeTwo = func->ArgTypes[1]; } } else { type_number = func->ReturnType; } /*checking if it is primitive type*/ if (typeIsPrimitive(type_number) && /* checking to make sure is either a scalar or normal array/pointer */ (typeIsPointer(type_number) || !typeIsIndirect(type_number))) { /* for set Methods can check argument number by counting arguments */ if (designator == 0 || designator == 2) { total_arguments = countTotalArguments(func); } else if (designator == 1) /* for get methods check */ { /* has an array return without a hint so unknown size */ if (func->HaveHint == 0 && typeIsPointer(type_number)) { total_arguments = -1; } else if (func->HaveHint == 1) /* check if has a hint */ { total_arguments = func->HintSize; } else /* not an array so a simple type */ { total_arguments = 1; } } if (typeIsChar(type_number) || total_arguments != -1) { /* it's a char has a known array size (ex. not int* with unknown size) */ indent(fp, indentation); fprintf(fp, "<Parameter>\n"); indentation++; indent(fp, indentation); fprintf(fp, "<Parameter_Name>%s</Parameter_Name>\n", func->Name+3); indent(fp, indentation); fprintf(fp, "<Parameter_Type>"); if (typeIsUnsigned(type_number)) /* unsigned */ { fprintf(fp, "unsigned "); } fprintf(fp, "%s", baseTypeName(type_number)); if (typeOne != typeTwo) { fprintf(fp, ","); if (typeIsUnsigned(typeTwo)) /* unsigned */ { fprintf(fp, "unsigned "); } fprintf(fp, "%s", baseTypeName(typeTwo)); } fprintf(fp, "</Parameter_Type>\n"); indent(fp, indentation); fprintf(fp, "<Parameter_Size>"); /* if set function has multiple arguments, then the number of * acceptable parameters is same as number of arguments */ if (typeOne == typeTwo) /* normal old way */ { if (total_arguments > 0) { fprintf(fp, "%i", total_arguments); } else { /* for cases like char * where array size isn't given */ fprintf(fp, "N"); } if(typeIsPointer(type_number)) /* is an array */ { fprintf(fp, "*"); } } else { /* case where has index then value */ fprintf(fp, "1,%i", (total_arguments - 1)); if (typeIsPointer(typeTwo)) { fprintf(fp, "*"); } } fprintf(fp, "</Parameter_Size>\n"); if (designator == 0) { indent(fp, indentation); fprintf(fp, "<Parameter_Flag>Set</Parameter_Flag>\n"); } else if (designator == 1) { indent(fp, indentation); fprintf(fp, "<Parameter_Flag>Get</Parameter_Flag>\n"); } else if (designator == 2) { indent(fp, indentation); fprintf(fp, "<Parameter_Flag>Both</Parameter_Flag>\n"); } indentation--; indent(fp, indentation); fprintf(fp, "</Parameter>\n"); return 1; } } return 0; }