ConceptCore/ccl/rslang/header/ASTNormalizer.h

47 lines
1.4 KiB
C
Raw Normal View History

2024-04-15 22:16:14 +03:00
#pragma once
#include "ccl/rslang/SyntaxTree.h"
#include <unordered_map>
namespace ccl::rslang {
//! Converter for AST into standard form
class Normalizer {
public:
using TupleSubstitutes = std::unordered_map<std::string, std::vector<Index>>;
using NodeSubstitutes = std::unordered_map<std::string, const SyntaxTree::Node*>;
using NameSubstitutes = std::unordered_map<std::string, std::string>;
2024-04-15 22:16:14 +03:00
private:
SyntaxTreeContext termFuncs;
TupleSubstitutes tupleSubstitutes{};
NodeSubstitutes nodeSubstitutes{};
NameSubstitutes nameSubstitutes{};
2024-04-15 22:16:14 +03:00
uint32_t localVarBase{ 0 };
public:
explicit Normalizer(SyntaxTreeContext termFuncs)
: termFuncs{ std::move(termFuncs) } {}
public:
void Normalize(SyntaxTree::Node& root);
private:
void Quantifier(SyntaxTree::Node& quant);
void Imperative(SyntaxTree::Node& root);
void Recursion(SyntaxTree::Node& root);
void Declarative(SyntaxTree::Node& root);
void Function(SyntaxTree::Node& func);
2024-04-15 22:16:14 +03:00
static void EnumDeclaration(SyntaxTree::Node& quant);
2024-05-06 15:02:37 +03:00
void TupleDeclaration(SyntaxTree::Node& declaration, SyntaxTree::Node& predicate);
2024-04-15 22:16:14 +03:00
[[nodiscard]] std::string ProcessTupleDeclaration(SyntaxTree::Node& root);
2024-04-15 22:16:14 +03:00
void SubstituteTupleVariables(SyntaxTree::Node& target, const std::string& newName);
2024-04-15 22:16:14 +03:00
[[nodiscard]] static std::vector<std::string> ArgNames(const SyntaxTree::Node& declaration);
void SubstituteArgs(SyntaxTree::Node& target, StrRange pos);
};
} // namespace ccl::rslang