2024-03-17 07:58:28 +00:00
|
|
|
#include "ast_gen.h"
|
|
|
|
|
|
|
|
using namespace ast_gen;
|
|
|
|
|
2024-06-18 03:54:36 +00:00
|
|
|
GlobalElement* GlobalElement::UniquePtr = nullptr;
|
2024-03-17 07:58:28 +00:00
|
|
|
|
2024-06-18 03:54:36 +00:00
|
|
|
GlobalElement::GlobalElement(const QString& name) :names_store(name) {
|
|
|
|
UniquePtr = this;
|
2024-03-17 07:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalElement::clearCache() { node_cache.clear(); }
|
|
|
|
|
2024-06-20 13:36:46 +00:00
|
|
|
std::shared_ptr<const SyntaxElement> GlobalElement::appendToCache(std::shared_ptr<const SyntaxElement> named_node) {
|
2024-06-18 03:54:36 +00:00
|
|
|
auto mixed_key = QString(u8"%1<%2>").arg(named_node->signature()).arg(named_node->typeMark());
|
|
|
|
if (node_cache.contains(mixed_key))
|
2024-06-20 13:36:46 +00:00
|
|
|
return node_cache[mixed_key];
|
2024-06-18 03:54:36 +00:00
|
|
|
node_cache[mixed_key] = named_node;
|
2024-06-20 13:36:46 +00:00
|
|
|
return nullptr;
|
2024-03-17 07:58:28 +00:00
|
|
|
}
|
|
|
|
|
2024-06-22 10:53:51 +00:00
|
|
|
std::shared_ptr<const SyntaxElement> GlobalElement::getNamedNodeBy(int paramType, const QString& signature) const {
|
|
|
|
auto mixed_key = QString(u8"%1<%2>").arg(signature).arg(paramType);
|
2024-06-18 03:54:36 +00:00
|
|
|
if (!node_cache.contains(mixed_key))
|
2024-06-20 13:36:46 +00:00
|
|
|
return nullptr;
|
2024-06-18 03:54:36 +00:00
|
|
|
return node_cache[mixed_key];
|
2024-03-17 07:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GlobalElement::typeMark() const { return 0; }
|
|
|
|
|
|
|
|
bool ast_gen::GlobalElement::isAnonymous() const { return true; }
|
|
|
|
|
|
|
|
QString GlobalElement::signature() const { return u8"::global"; }
|
|
|
|
|
|
|
|
QString GlobalElement::path() const { return u8""; }
|
|
|
|
|
|
|
|
std::shared_ptr<const SyntaxElement> GlobalElement::parent() const { return nullptr; }
|
|
|
|
|
2024-06-18 03:54:36 +00:00
|
|
|
void ast_gen::GlobalElement::setParent(std::shared_ptr<const SyntaxElement> inst) {}
|
|
|
|
|
2024-03-17 07:58:28 +00:00
|
|
|
QList<std::shared_ptr<const TokenAccess>> GlobalElement::selfTokens() const { return QList<std::shared_ptr<const TokenAccess>>(); }
|
|
|
|
|
2024-06-18 03:54:36 +00:00
|
|
|
std::shared_ptr<const ast_basic::Expression> ast_gen::GlobalElement::bindExpression() const
|
|
|
|
{
|
|
|
|
return bind_exprs;
|
|
|
|
}
|
|
|
|
|
2024-06-18 04:44:18 +00:00
|
|
|
void ast_gen::GlobalElement::cacheLoad()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-06-18 03:54:36 +00:00
|
|
|
void GlobalElement::addChild(std::shared_ptr<ast_gen::SyntaxElement> citem) {
|
|
|
|
auto convx = std::dynamic_pointer_cast<ast_basic::Expression>(citem);
|
|
|
|
bind_exprs->addChild(convx);
|
|
|
|
}
|
|
|
|
|
2024-03-17 07:58:28 +00:00
|
|
|
ElementAccess::ElementAccess(std::shared_ptr<const SyntaxElement> point) { peers = point; }
|
|
|
|
|
|
|
|
std::shared_ptr<const SyntaxElement> ElementAccess::element() const { return peers; }
|
|
|
|
|
2024-06-18 03:54:36 +00:00
|
|
|
QList<std::shared_ptr<const ElementAccess>> ElementAccess::children() const {
|
|
|
|
auto expression_inst = element()->bindExpression();
|
|
|
|
auto children = expression_inst->children();
|
2024-03-17 07:58:28 +00:00
|
|
|
|
2024-06-18 03:54:36 +00:00
|
|
|
QList<std::shared_ptr<const ElementAccess>> retvalues;
|
|
|
|
for (auto item : children) {
|
|
|
|
auto elem_inst = std::dynamic_pointer_cast<const SyntaxElement>(item);
|
|
|
|
retvalues.append(std::make_shared<ElementAccess>(elem_inst));
|
|
|
|
}
|
|
|
|
return retvalues;
|
|
|
|
}
|
2024-03-17 07:58:28 +00:00
|
|
|
|
|
|
|
QList<std::shared_ptr<const TokenAccess>> ElementAccess::tokens() const {
|
2024-06-18 03:54:36 +00:00
|
|
|
return element()->selfTokens();
|
2024-03-17 07:58:28 +00:00
|
|
|
}
|
|
|
|
|
2024-06-20 13:36:46 +00:00
|
|
|
TokenAccess::TokenAccess(std::shared_ptr<const SyntaxElement> elm_inst, std::shared_ptr<const lib_token::IToken> token_inst)
|
2024-06-18 03:54:36 +00:00
|
|
|
: element_bind(elm_inst), token_store(token_inst) {}
|
2024-03-17 07:58:28 +00:00
|
|
|
|
|
|
|
std::shared_ptr<const SyntaxElement> TokenAccess::bind() const { return element_bind; }
|
|
|
|
|
2024-06-20 13:36:46 +00:00
|
|
|
std::shared_ptr<const lib_token::IToken> TokenAccess::token() const { return token_store; }
|
2024-03-17 07:58:28 +00:00
|
|
|
|