Added boolean patterns
This commit is contained in:
parent
bef20f7808
commit
5d1e53f469
@ -359,6 +359,32 @@ namespace hex::lang {
|
||||
}
|
||||
};
|
||||
|
||||
class PatternDataBoolean : public PatternData {
|
||||
public:
|
||||
explicit PatternDataBoolean(u64 offset, u32 color = 0)
|
||||
: PatternData(offset, 1, color) { }
|
||||
|
||||
PatternData* clone() override {
|
||||
return new PatternDataBoolean(*this);
|
||||
}
|
||||
|
||||
void createEntry(prv::Provider* &provider) override {
|
||||
u8 boolean;
|
||||
provider->read(this->getOffset(), &boolean, 1);
|
||||
|
||||
if (boolean == 0)
|
||||
this->createDefaultEntry("false");
|
||||
else if (boolean == 1)
|
||||
this->createDefaultEntry("true");
|
||||
else
|
||||
this->createDefaultEntry("true*");
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getFormattedName() const override {
|
||||
return "bool";
|
||||
}
|
||||
};
|
||||
|
||||
class PatternDataCharacter : public PatternData {
|
||||
public:
|
||||
explicit PatternDataCharacter(u64 offset, u32 color = 0)
|
||||
@ -376,7 +402,7 @@ namespace hex::lang {
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getFormattedName() const override {
|
||||
return "Character";
|
||||
return "char";
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -71,6 +71,7 @@ namespace hex::lang {
|
||||
Unsigned128Bit = 0x100,
|
||||
Signed128Bit = 0x101,
|
||||
Character = 0x13,
|
||||
Boolean = 0x14,
|
||||
Float = 0x42,
|
||||
Double = 0x82,
|
||||
CustomType = 0x00,
|
||||
|
@ -56,7 +56,7 @@ namespace hex::lang {
|
||||
case 4: return new ASTNodeIntegerLiteral({ Token::ValueType::Unsigned32Bit, hex::changeEndianess(*reinterpret_cast<u32*>(value), 4, this->getCurrentEndian()) });
|
||||
case 8: return new ASTNodeIntegerLiteral({ Token::ValueType::Unsigned64Bit, hex::changeEndianess(*reinterpret_cast<u64*>(value), 8, this->getCurrentEndian()) });
|
||||
case 16: return new ASTNodeIntegerLiteral({ Token::ValueType::Unsigned128Bit, hex::changeEndianess(*reinterpret_cast<u128*>(value), 16, this->getCurrentEndian()) });
|
||||
default: throwEvaluateError("invalid rvalue size", 1);
|
||||
default: throwEvaluateError("invalid read size", 1);
|
||||
}
|
||||
}, address, size);
|
||||
}
|
||||
@ -81,7 +81,7 @@ namespace hex::lang {
|
||||
case 4: return new ASTNodeIntegerLiteral({ Token::ValueType::Signed32Bit, hex::changeEndianess(*reinterpret_cast<s32*>(value), 4, this->getCurrentEndian()) });
|
||||
case 8: return new ASTNodeIntegerLiteral({ Token::ValueType::Signed64Bit, hex::changeEndianess(*reinterpret_cast<s64*>(value), 8, this->getCurrentEndian()) });
|
||||
case 16: return new ASTNodeIntegerLiteral({ Token::ValueType::Signed128Bit, hex::changeEndianess(*reinterpret_cast<s128*>(value), 16, this->getCurrentEndian()) });
|
||||
default: throwEvaluateError("invalid rvalue size", 1);
|
||||
default: throwEvaluateError("invalid read size", 1);
|
||||
}
|
||||
}, address, size);
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ namespace hex::lang {
|
||||
}
|
||||
|
||||
ASTNodeIntegerLiteral* Evaluator::evaluateRValue(ASTNodeRValue *node) {
|
||||
if (this->m_currMembers.empty())
|
||||
throwEvaluateError("no variables available", node->getLineNumber());
|
||||
|
||||
const std::vector<PatternData*>* currMembers = this->m_currMembers.back();
|
||||
|
||||
@ -298,6 +300,8 @@ namespace hex::lang {
|
||||
|
||||
if (type == Token::ValueType::Character)
|
||||
pattern = new PatternDataCharacter(this->m_currOffset);
|
||||
else if (type == Token::ValueType::Boolean)
|
||||
pattern = new PatternDataBoolean(this->m_currOffset);
|
||||
else if (Token::isUnsigned(type))
|
||||
pattern = new PatternDataUnsigned(this->m_currOffset, typeSize);
|
||||
else if (Token::isSigned(type))
|
||||
|
@ -318,6 +318,10 @@ namespace hex::lang {
|
||||
tokens.emplace_back(TOKEN(Keyword, If));
|
||||
else if (identifier == "else")
|
||||
tokens.emplace_back(TOKEN(Keyword, Else));
|
||||
else if (identifier == "false")
|
||||
tokens.emplace_back(VALUE_TOKEN(Integer, Token::IntegerLiteral({ Token::ValueType::Unsigned8Bit, u8(0) })));
|
||||
else if (identifier == "true")
|
||||
tokens.emplace_back(VALUE_TOKEN(Integer, Token::IntegerLiteral({ Token::ValueType::Unsigned8Bit, u8(1) })));
|
||||
|
||||
// Check for built-in types
|
||||
else if (identifier == "u8")
|
||||
@ -346,6 +350,8 @@ namespace hex::lang {
|
||||
tokens.emplace_back(TOKEN(ValueType, Double));
|
||||
else if (identifier == "char")
|
||||
tokens.emplace_back(TOKEN(ValueType, Character));
|
||||
else if (identifier == "bool")
|
||||
tokens.emplace_back(TOKEN(ValueType, Boolean));
|
||||
else if (identifier == "padding")
|
||||
tokens.emplace_back(TOKEN(ValueType, Padding));
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace hex {
|
||||
static TextEditor::LanguageDefinition langDef;
|
||||
if (!initialized) {
|
||||
static const char* const keywords[] = {
|
||||
"using", "struct", "union", "enum", "bitfield", "be", "le", "if", "else"
|
||||
"using", "struct", "union", "enum", "bitfield", "be", "le", "if", "else", "false", "true"
|
||||
};
|
||||
for (auto& k : keywords)
|
||||
langDef.mKeywords.insert(k);
|
||||
@ -26,7 +26,7 @@ namespace hex {
|
||||
static std::pair<const char* const, size_t> builtInTypes[] = {
|
||||
{ "u8", 1 }, { "u16", 2 }, { "u32", 4 }, { "u64", 8 }, { "u128", 16 },
|
||||
{ "s8", 1 }, { "s16", 2 }, { "s32", 4 }, { "s64", 8 }, { "s128", 16 },
|
||||
{ "float", 4 }, { "double", 8 }, { "char", 1 }, { "padding", 1 }
|
||||
{ "float", 4 }, { "double", 8 }, { "char", 1 }, { "bool", 1 }, { "padding", 1 }
|
||||
};
|
||||
for (const auto &[name, size] : builtInTypes) {
|
||||
TextEditor::Identifier id;
|
||||
|
Loading…
x
Reference in New Issue
Block a user