patterns: Added while statement for array sizing

This commit is contained in:
WerWolv
2021-06-17 23:13:58 +02:00
parent 3cef784f75
commit 21f8fb4090
9 changed files with 156 additions and 76 deletions

View File

@@ -108,6 +108,9 @@ namespace hex {
template<typename T>
struct always_false : std::false_type {};
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template<typename T>
constexpr T changeEndianess(T value, std::endian endian) {
if (endian == std::endian::native)

View File

@@ -482,6 +482,30 @@ namespace hex::lang {
std::vector<ASTNode*> m_trueBody, m_falseBody;
};
class ASTNodeWhileStatement : public ASTNode {
public:
explicit ASTNodeWhileStatement(ASTNode *condition) : ASTNode(), m_condition(condition) { }
~ASTNodeWhileStatement() override {
delete this->m_condition;
}
ASTNodeWhileStatement(const ASTNodeWhileStatement &other) : ASTNode(other) {
this->m_condition = other.m_condition->clone();
}
[[nodiscard]] ASTNode* clone() const override {
return new ASTNodeWhileStatement(*this);
}
[[nodiscard]] ASTNode* getCondition() {
return this->m_condition;
}
private:
ASTNode *m_condition;
};
class ASTNodeFunctionCall : public ASTNode {
public:
explicit ASTNodeFunctionCall(std::string_view functionName, std::vector<ASTNode*> params)

View File

@@ -73,6 +73,7 @@ namespace hex::lang {
void parseAttribute(Attributable *currNode);
ASTNode* parseConditional();
ASTNode* parseWhileStatement();
ASTNode* parseType(s32 startIndex);
ASTNode* parseUsingDeclaration();
ASTNode* parsePadding();

View File

@@ -32,7 +32,8 @@ namespace hex::lang {
BigEndian,
If,
Else,
Parent
Parent,
While
};
enum class Operator {
@@ -225,6 +226,7 @@ namespace hex::lang {
#define KEYWORD_IF COMPONENT(Keyword, If)
#define KEYWORD_ELSE COMPONENT(Keyword, Else)
#define KEYWORD_PARENT COMPONENT(Keyword, Parent)
#define KEYWORD_WHILE COMPONENT(Keyword, While)
#define INTEGER hex::lang::Token::Type::Integer, hex::lang::Token::IntegerLiteral(hex::lang::Token::ValueType::Any, u64(0))
#define IDENTIFIER hex::lang::Token::Type::Identifier, ""