2020-11-10 20:31:04 +00:00
|
|
|
#include "views/view_pattern.hpp"
|
|
|
|
|
2020-11-17 01:31:51 +00:00
|
|
|
#include "lang/preprocessor.hpp"
|
|
|
|
#include "lang/parser.hpp"
|
|
|
|
#include "lang/lexer.hpp"
|
|
|
|
#include "lang/validator.hpp"
|
2020-11-10 20:31:04 +00:00
|
|
|
#include "utils.hpp"
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
ViewPattern::ViewPattern(prv::Provider* &dataProvider, std::vector<hex::PatternData*> &patternData)
|
|
|
|
: View(), m_dataProvider(dataProvider), m_patternData(patternData) {
|
2020-11-13 13:35:52 +00:00
|
|
|
|
|
|
|
this->m_buffer = new char[0xFF'FFFF];
|
|
|
|
std::memset(this->m_buffer, 0x00, 0xFF'FFFF);
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
ViewPattern::~ViewPattern() {
|
2020-11-13 12:50:59 +00:00
|
|
|
if (this->m_buffer != nullptr)
|
|
|
|
delete[] this->m_buffer;
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPattern::createMenu() {
|
|
|
|
if (ImGui::BeginMenu("File")) {
|
|
|
|
if (ImGui::MenuItem("Load pattern...")) {
|
2020-11-17 14:38:24 +00:00
|
|
|
View::doLater([]{ ImGui::OpenPopup("Open Hex Pattern"); });
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
|
2020-11-11 08:22:55 +00:00
|
|
|
if (ImGui::BeginMenu("View")) {
|
2020-11-10 20:31:04 +00:00
|
|
|
ImGui::MenuItem("Pattern View", "", &this->m_windowOpen);
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPattern::createView() {
|
|
|
|
if (!this->m_windowOpen)
|
|
|
|
return;
|
|
|
|
|
2020-11-11 09:47:02 +00:00
|
|
|
if (ImGui::Begin("Pattern", &this->m_windowOpen, ImGuiWindowFlags_None)) {
|
2020-11-13 13:35:52 +00:00
|
|
|
if (this->m_buffer != nullptr && this->m_dataProvider != nullptr && this->m_dataProvider->isReadable()) {
|
2020-11-13 12:06:22 +00:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-13 12:06:22 +00:00
|
|
|
auto size = ImGui::GetWindowSize();
|
|
|
|
size.y -= 50;
|
|
|
|
ImGui::InputTextMultiline("Pattern", this->m_buffer, 0xFFFF, size,
|
|
|
|
ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_CallbackEdit,
|
|
|
|
[](ImGuiInputTextCallbackData *data) -> int {
|
|
|
|
auto _this = static_cast<ViewPattern *>(data->UserData);
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-13 12:06:22 +00:00
|
|
|
_this->parsePattern(data->Buf);
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-13 12:06:22 +00:00
|
|
|
return 0;
|
|
|
|
}, this
|
|
|
|
);
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-13 12:06:22 +00:00
|
|
|
ImGui::PopStyleVar(2);
|
|
|
|
}
|
2020-11-11 09:47:02 +00:00
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
ImGui::End();
|
2020-11-12 20:20:51 +00:00
|
|
|
|
2020-11-17 14:38:24 +00:00
|
|
|
if (this->m_fileBrowser.showFileDialog("Open Hex Pattern", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(0, 0), ".hexpat")) {
|
2020-11-12 20:20:51 +00:00
|
|
|
|
2020-11-17 14:38:24 +00:00
|
|
|
FILE *file = fopen(this->m_fileBrowser.selected_path.c_str(), "rb");
|
2020-11-12 20:20:51 +00:00
|
|
|
|
2020-11-13 13:35:52 +00:00
|
|
|
if (file != nullptr) {
|
|
|
|
fseek(file, 0, SEEK_END);
|
|
|
|
size_t size = ftell(file);
|
|
|
|
rewind(file);
|
2020-11-12 20:20:51 +00:00
|
|
|
|
2020-11-13 13:35:52 +00:00
|
|
|
if (size >= 0xFF'FFFF) {
|
|
|
|
fclose(file);
|
|
|
|
return;
|
|
|
|
}
|
2020-11-12 20:20:51 +00:00
|
|
|
|
2020-11-13 13:35:52 +00:00
|
|
|
fread(this->m_buffer, size, 1, file);
|
2020-11-12 20:20:51 +00:00
|
|
|
|
2020-11-13 13:35:52 +00:00
|
|
|
fclose(file);
|
2020-11-12 20:20:51 +00:00
|
|
|
|
2020-11-13 13:35:52 +00:00
|
|
|
this->parsePattern(this->m_buffer);
|
|
|
|
}
|
2020-11-12 20:20:51 +00:00
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
void ViewPattern::addPatternData(PatternData *patternData) {
|
|
|
|
this->m_patternData.push_back(patternData);
|
|
|
|
}
|
2020-11-13 11:07:05 +00:00
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
void ViewPattern::clearPatternData() {
|
|
|
|
for (auto &data : this->m_patternData)
|
|
|
|
delete data;
|
2020-11-13 11:07:05 +00:00
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
this->m_patternData.clear();
|
2020-11-17 01:31:51 +00:00
|
|
|
PatternData::resetPalette();
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<std::derived_from<lang::ASTNode> T>
|
|
|
|
static std::vector<T*> findNodes(const lang::ASTNode::Type type, const std::vector<lang::ASTNode*> &nodes) {
|
|
|
|
std::vector<T*> result;
|
|
|
|
|
|
|
|
for (const auto & node : nodes)
|
|
|
|
if (node->getType() == type)
|
|
|
|
result.push_back(static_cast<T*>(node));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPattern::parsePattern(char *buffer) {
|
2020-11-17 01:31:51 +00:00
|
|
|
static hex::lang::Preprocessor preprocessor;
|
2020-11-10 20:31:04 +00:00
|
|
|
static hex::lang::Lexer lexer;
|
|
|
|
static hex::lang::Parser parser;
|
2020-11-16 21:54:39 +00:00
|
|
|
static hex::lang::Validator validator;
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
this->clearPatternData();
|
2020-11-14 23:46:18 +00:00
|
|
|
this->postEvent(Events::PatternChanged);
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-17 01:31:51 +00:00
|
|
|
auto [preprocessingResult, preprocesedCode] = preprocessor.preprocess(buffer);
|
|
|
|
if (preprocessingResult.failed())
|
|
|
|
return;
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-17 01:31:51 +00:00
|
|
|
auto [lexResult, tokens] = lexer.lex(preprocesedCode);
|
2020-11-10 20:31:04 +00:00
|
|
|
if (lexResult.failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto [parseResult, ast] = parser.parse(tokens);
|
|
|
|
if (parseResult.failed()) {
|
|
|
|
for(auto &node : ast) delete node;
|
|
|
|
return;
|
2020-11-16 21:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto validatorResult = validator.validate(ast);
|
|
|
|
if (!validatorResult) {
|
|
|
|
for(auto &node : ast) delete node;
|
|
|
|
return;
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &varNode : findNodes<lang::ASTNodeVariableDecl>(lang::ASTNode::Type::VariableDecl, ast)) {
|
|
|
|
if (!varNode->getOffset().has_value())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
u64 offset = varNode->getOffset().value();
|
|
|
|
if (varNode->getVariableType() != lang::Token::TypeToken::Type::CustomType) {
|
2020-11-14 13:42:21 +00:00
|
|
|
size_t size = getTypeSize(varNode->getVariableType()) * varNode->getArraySize();
|
|
|
|
|
|
|
|
if (isUnsigned(varNode->getVariableType()))
|
|
|
|
this->addPatternData(new PatternDataUnsigned(offset, size, varNode->getVariableName()));
|
|
|
|
else if (isSigned(varNode->getVariableType())) {
|
|
|
|
if (getTypeSize(varNode->getVariableType()) == 1 && varNode->getArraySize() == 1)
|
|
|
|
this->addPatternData(new PatternDataCharacter(offset, size, varNode->getVariableName()));
|
|
|
|
else if (getTypeSize(varNode->getVariableType()) == 1 && varNode->getArraySize() > 1)
|
|
|
|
this->addPatternData(new PatternDataString(offset, size, varNode->getVariableName()));
|
|
|
|
else
|
|
|
|
this->addPatternData(new PatternDataSigned(offset, size, varNode->getVariableName()));
|
|
|
|
}
|
|
|
|
else if (isFloatingPoint(varNode->getVariableType()))
|
|
|
|
this->addPatternData(new PatternDataFloat(offset, size, varNode->getVariableName()));
|
2020-11-10 20:31:04 +00:00
|
|
|
} else {
|
2020-11-14 13:42:21 +00:00
|
|
|
for (auto &structNode : findNodes<lang::ASTNodeStruct>(lang::ASTNode::Type::Struct, ast)) {
|
2020-11-13 10:15:34 +00:00
|
|
|
if (varNode->getCustomVariableTypeName() == structNode->getName()) {
|
|
|
|
for (u32 i = 0; i < varNode->getArraySize(); i++) {
|
2020-11-13 10:37:43 +00:00
|
|
|
std::string name = varNode->getVariableName();
|
|
|
|
if (varNode->getArraySize() > 1)
|
|
|
|
name += "[" + std::to_string(varNode->getArraySize()) + "]";
|
|
|
|
|
|
|
|
if (size_t size = this->highlightStruct(ast, structNode, offset, name); size == -1)
|
2020-11-14 13:42:21 +00:00
|
|
|
this->clearPatternData();
|
2020-11-13 10:15:34 +00:00
|
|
|
else
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
}
|
2020-11-14 13:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &enumNode : findNodes<lang::ASTNodeEnum>(lang::ASTNode::Type::Enum, ast)) {
|
|
|
|
if (varNode->getCustomVariableTypeName() == enumNode->getName()) {
|
|
|
|
for (u32 i = 0; i < varNode->getArraySize(); i++) {
|
|
|
|
std::string name = varNode->getVariableName();
|
|
|
|
if (varNode->getArraySize() > 1)
|
|
|
|
name += "[" + std::to_string(varNode->getArraySize()) + "]";
|
|
|
|
|
|
|
|
if (size_t size = this->highlightEnum(ast, enumNode, offset, name); size == -1)
|
|
|
|
this->clearPatternData();
|
|
|
|
else
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 10:15:34 +00:00
|
|
|
|
|
|
|
for (auto &usingNode : findNodes<lang::ASTNodeTypeDecl>(lang::ASTNode::Type::TypeDecl, ast)) {
|
|
|
|
if (varNode->getCustomVariableTypeName() == usingNode->getTypeName()) {
|
|
|
|
for (u32 i = 0; i < varNode->getArraySize(); i++) {
|
2020-11-13 10:37:43 +00:00
|
|
|
std::string name = varNode->getVariableName();
|
|
|
|
if (varNode->getArraySize() > 1)
|
|
|
|
name += "[" + std::to_string(varNode->getArraySize()) + "]";
|
|
|
|
|
|
|
|
if (size_t size = this->highlightUsingDecls(ast, usingNode, varNode, offset, name); size == -1)
|
2020-11-14 13:42:21 +00:00
|
|
|
this->clearPatternData();
|
2020-11-13 10:15:34 +00:00
|
|
|
else
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto &node : ast) delete node;
|
2020-11-14 23:46:18 +00:00
|
|
|
this->postEvent(Events::PatternChanged);
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 10:37:43 +00:00
|
|
|
s32 ViewPattern::highlightUsingDecls(std::vector<lang::ASTNode*> &ast, lang::ASTNodeTypeDecl* currTypeDeclNode, lang::ASTNodeVariableDecl* currVarDecl, u64 offset, std::string name) {
|
2020-11-13 10:15:34 +00:00
|
|
|
u64 startOffset = offset;
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
if (currTypeDeclNode->getAssignedType() != lang::Token::TypeToken::Type::CustomType) {
|
2020-11-12 23:42:29 +00:00
|
|
|
size_t size = (static_cast<u32>(currTypeDeclNode->getAssignedType()) >> 4);
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
if (isUnsigned(currTypeDeclNode->getAssignedType()))
|
2020-11-14 23:46:18 +00:00
|
|
|
this->addPatternData(new PatternDataUnsigned(offset, size, name));
|
2020-11-14 13:42:21 +00:00
|
|
|
else if (isSigned(currTypeDeclNode->getAssignedType()))
|
2020-11-14 23:46:18 +00:00
|
|
|
this->addPatternData(new PatternDataSigned(offset, size, name));
|
2020-11-14 13:42:21 +00:00
|
|
|
else if (isFloatingPoint(currTypeDeclNode->getAssignedType()))
|
2020-11-14 23:46:18 +00:00
|
|
|
this->addPatternData(new PatternDataFloat(offset, size, name));
|
2020-11-14 13:42:21 +00:00
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
offset += size;
|
|
|
|
} else {
|
|
|
|
bool foundType = false;
|
2020-11-14 13:42:21 +00:00
|
|
|
for (auto &structNode : findNodes<lang::ASTNodeStruct>(lang::ASTNode::Type::Struct, ast)) {
|
2020-11-10 20:31:04 +00:00
|
|
|
if (structNode->getName() == currTypeDeclNode->getAssignedCustomTypeName()) {
|
2020-11-13 10:15:34 +00:00
|
|
|
for (size_t i = 0; i < currVarDecl->getArraySize(); i++) {
|
2020-11-13 10:37:43 +00:00
|
|
|
size_t size = this->highlightStruct(ast, structNode, offset, name);
|
2020-11-13 10:15:34 +00:00
|
|
|
|
|
|
|
if (size == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
foundType = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-11-14 13:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &enumNode : findNodes<lang::ASTNodeEnum>(lang::ASTNode::Type::Enum, ast)) {
|
|
|
|
if (enumNode->getName() == currTypeDeclNode->getAssignedCustomTypeName()) {
|
|
|
|
for (size_t i = 0; i < currVarDecl->getArraySize(); i++) {
|
|
|
|
size_t size = this->highlightEnum(ast, enumNode, offset, name);
|
|
|
|
|
|
|
|
if (size == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
foundType = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-13 10:15:34 +00:00
|
|
|
for (auto &typeDeclNode : findNodes<lang::ASTNodeTypeDecl>(lang::ASTNode::Type::TypeDecl, ast)) {
|
2020-11-10 20:31:04 +00:00
|
|
|
if (typeDeclNode->getTypeName() == currTypeDeclNode->getAssignedCustomTypeName()) {
|
2020-11-13 10:15:34 +00:00
|
|
|
for (size_t i = 0; i < currVarDecl->getArraySize(); i++) {
|
2020-11-13 10:37:43 +00:00
|
|
|
size_t size = this->highlightUsingDecls(ast, typeDeclNode, currVarDecl, offset, name);
|
2020-11-13 10:15:34 +00:00
|
|
|
|
|
|
|
if (size == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
foundType = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-11-13 10:15:34 +00:00
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
|
|
|
|
if (!foundType)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-11-13 10:15:34 +00:00
|
|
|
return offset - startOffset;
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 10:37:43 +00:00
|
|
|
s32 ViewPattern::highlightStruct(std::vector<lang::ASTNode*> &ast, lang::ASTNodeStruct* currStructNode, u64 offset, std::string name) {
|
2020-11-10 20:31:04 +00:00
|
|
|
u64 startOffset = offset;
|
|
|
|
|
|
|
|
for (auto &node : currStructNode->getNodes()) {
|
2020-11-14 13:42:21 +00:00
|
|
|
auto varNode = static_cast<lang::ASTNodeVariableDecl*>(node);
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
if (varNode->getVariableType() != lang::Token::TypeToken::Type::CustomType) {
|
|
|
|
size_t size = (static_cast<u32>(varNode->getVariableType()) >> 4);
|
|
|
|
for (size_t i = 0; i < varNode->getArraySize(); i++) {
|
|
|
|
std::string memberName = name + "." + varNode->getVariableName();
|
|
|
|
if (varNode->getArraySize() > 1)
|
2020-11-13 10:37:43 +00:00
|
|
|
memberName += "[" + std::to_string(i) + "]";
|
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
if (isUnsigned(varNode->getVariableType()))
|
|
|
|
this->addPatternData(new PatternDataUnsigned(offset, size, memberName));
|
|
|
|
else if (isSigned(varNode->getVariableType())) {
|
|
|
|
if (getTypeSize(varNode->getVariableType()) == 1 && varNode->getArraySize() == 1)
|
|
|
|
this->addPatternData(new PatternDataCharacter(offset, size, memberName));
|
|
|
|
else if (getTypeSize(varNode->getVariableType()) == 1 && varNode->getArraySize() > 1) {
|
|
|
|
this->addPatternData(new PatternDataString(offset, size * varNode->getArraySize(), name + "." + varNode->getVariableName()));
|
|
|
|
offset += size * varNode->getArraySize();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this->addPatternData(new PatternDataSigned(offset, size, memberName));
|
|
|
|
}
|
|
|
|
else if (isFloatingPoint(varNode->getVariableType()))
|
|
|
|
this->addPatternData(new PatternDataFloat(offset, size, memberName));
|
|
|
|
|
2020-11-13 10:37:43 +00:00
|
|
|
offset += size;
|
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
} else {
|
|
|
|
bool foundType = false;
|
2020-11-13 10:37:43 +00:00
|
|
|
for (auto &structNode : findNodes<lang::ASTNodeStruct>(lang::ASTNode::Type::Struct, ast)) {
|
2020-11-14 13:42:21 +00:00
|
|
|
if (structNode->getName() == varNode->getCustomVariableTypeName()) {
|
|
|
|
for (size_t i = 0; i < varNode->getArraySize(); i++) {
|
|
|
|
std::string memberName = name + "." + varNode->getVariableName();
|
|
|
|
if (varNode->getArraySize() > 1)
|
2020-11-13 10:37:43 +00:00
|
|
|
memberName += "[" + std::to_string(i) + "]";
|
|
|
|
|
|
|
|
size_t size = this->highlightStruct(ast, structNode, offset, memberName);
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-12 22:57:43 +00:00
|
|
|
if (size == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
|
|
|
|
foundType = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-11-13 10:37:43 +00:00
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
for (auto &enumNode : findNodes<lang::ASTNodeEnum>(lang::ASTNode::Type::Enum, ast)) {
|
|
|
|
if (enumNode->getName() == varNode->getCustomVariableTypeName()) {
|
|
|
|
for (size_t i = 0; i < varNode->getArraySize(); i++) {
|
|
|
|
std::string memberName = name + "." + varNode->getVariableName();
|
|
|
|
if (varNode->getArraySize() > 1)
|
|
|
|
memberName += "[" + std::to_string(i) + "]";
|
|
|
|
|
|
|
|
size_t size = this->highlightEnum(ast, enumNode, offset, memberName);
|
|
|
|
|
|
|
|
if (size == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
foundType = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 10:15:34 +00:00
|
|
|
for (auto &typeDeclNode : findNodes<lang::ASTNodeTypeDecl>(lang::ASTNode::Type::TypeDecl, ast)) {
|
2020-11-14 13:42:21 +00:00
|
|
|
if (typeDeclNode->getTypeName() == varNode->getCustomVariableTypeName()) {
|
|
|
|
for (size_t i = 0; i < varNode->getArraySize(); i++) {
|
|
|
|
std::string memberName = name + "." + varNode->getVariableName();
|
|
|
|
if (varNode->getArraySize() > 1)
|
2020-11-13 10:37:43 +00:00
|
|
|
memberName += "[" + std::to_string(i) + "]";
|
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
size_t size = this->highlightUsingDecls(ast, typeDeclNode, varNode, offset, memberName);
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-12 23:42:29 +00:00
|
|
|
if (size == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
|
|
|
|
foundType = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-11-13 10:15:34 +00:00
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
|
|
|
|
if (!foundType)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset - startOffset;
|
|
|
|
}
|
|
|
|
|
2020-11-14 13:42:21 +00:00
|
|
|
s32 ViewPattern::highlightEnum(std::vector<lang::ASTNode*> &ast, lang::ASTNodeEnum* currEnumNode, u64 offset, std::string name) {
|
|
|
|
if (!isUnsigned(currEnumNode->getUnderlyingType()))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
s32 size = static_cast<u32>(currEnumNode->getUnderlyingType()) >> 4;
|
|
|
|
|
|
|
|
if (size > 8)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
this->addPatternData(new PatternDataEnum(offset, size, name, currEnumNode->getName(), currEnumNode->getValues()));
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|