300 lines
6.9 KiB
C++
300 lines
6.9 KiB
C++
#include "ast_novel.h"
|
||
#include <QtCore/QString>
|
||
|
||
using namespace example_novel;
|
||
using namespace lib_syntax;
|
||
using namespace ast_basic;
|
||
using namespace ast_gen;
|
||
|
||
|
||
TextSection::TextSection(std::shared_ptr<const ExprRule> rule_bind)
|
||
: AbstractImpl(rule_bind) { }
|
||
|
||
QString TextSection::content() const {
|
||
QString text;
|
||
for (auto& t : selfTokens()) {
|
||
text += t->token()->content() + " ";
|
||
}
|
||
return text;
|
||
}
|
||
|
||
QString TextSection::signature() const {
|
||
return u8"::section";
|
||
}
|
||
|
||
PointRefers::PointRefers(std::shared_ptr<const ExprRule> rule_bind)
|
||
: AbstractImpl(rule_bind) { }
|
||
|
||
QString PointRefers::storyRefer() const {
|
||
return story_refs;
|
||
}
|
||
|
||
void PointRefers::setStoryRefer(const QString& refer) {
|
||
this->story_refs = refer;
|
||
}
|
||
|
||
QString PointRefers::sliceRefer() const {
|
||
return story_refs;
|
||
}
|
||
|
||
void PointRefers::setSliceRefer(const QString& refer) {
|
||
story_refs = refer;
|
||
}
|
||
|
||
QString PointRefers::pointRefer() const {
|
||
return point_ref;
|
||
}
|
||
|
||
void PointRefers::setPointRefer(const QString& refer) {
|
||
this->point_ref = refer;
|
||
}
|
||
|
||
QString PointRefers::referSignature() const {
|
||
return storyRefer() + u8"&" + sliceRefer() + u8"&" + pointRefer();
|
||
}
|
||
|
||
QString PointRefers::signature() const {
|
||
QString signature = u8"@" + referSignature();
|
||
return parent().lock()->signature() + u8"&" + signature;
|
||
}
|
||
|
||
|
||
PointDefines::PointDefines(std::shared_ptr<const ExprRule> rule_bind)
|
||
: AbstractImpl(rule_bind) { }
|
||
|
||
QString PointDefines::name() const {
|
||
return name_store;
|
||
}
|
||
|
||
void PointDefines::setName(const QString& nm) {
|
||
this->name_store = nm;
|
||
}
|
||
|
||
QString PointDefines::signature() const {
|
||
return parent().lock()->signature() + u8"&" + name();
|
||
}
|
||
|
||
|
||
StoryDefine::StoryDefine(std::shared_ptr<const ExprRule> rule_bind)
|
||
: AbstractImpl(rule_bind), sort_index(0) { }
|
||
|
||
QString StoryDefine::name() const {
|
||
return name_store;
|
||
}
|
||
|
||
void StoryDefine::setName(const QString& nm) {
|
||
this->name_store = nm;
|
||
}
|
||
|
||
void StoryDefine::setSort(int value) {
|
||
sort_index = value;
|
||
}
|
||
|
||
int StoryDefine::sort() const {
|
||
return sort_index;
|
||
}
|
||
|
||
QString StoryDefine::signature() const {
|
||
return name();
|
||
}
|
||
|
||
#include "syntax_novel.h"
|
||
Document::Document(std::shared_ptr<const ExprRule> rule_bind)
|
||
: AbstractImpl(rule_bind) { }
|
||
|
||
QString Document::signature() const {
|
||
return QString(u8"::document<%1>").arg(path());
|
||
}
|
||
|
||
VolumeDefine::VolumeDefine(std::shared_ptr<const ExprRule> rule_bind)
|
||
: AbstractImpl(rule_bind) { }
|
||
|
||
QString VolumeDefine::name() const {
|
||
return name_store;
|
||
}
|
||
|
||
void VolumeDefine::setName(const QString& nm) {
|
||
this->name_store = nm;
|
||
}
|
||
|
||
QString VolumeDefine::signature() const {
|
||
return name();
|
||
}
|
||
|
||
ArticleDefine::ArticleDefine(std::shared_ptr<const ExprRule> rule_bind)
|
||
: AbstractImpl(rule_bind) { }
|
||
|
||
QString ArticleDefine::name() const {
|
||
return name_store;
|
||
}
|
||
|
||
void ArticleDefine::setName(const QString& nm) {
|
||
this->name_store = nm;
|
||
}
|
||
|
||
QString ArticleDefine::signature() const {
|
||
return parent().lock()->signature() + u8"&" + name();
|
||
}
|
||
|
||
RankDeclare::RankDeclare(std::shared_ptr<const ExprRule> rule)
|
||
: AbstractImpl(rule) { }
|
||
|
||
int RankDeclare::rankNumber() const {
|
||
return page_rank;
|
||
}
|
||
|
||
void RankDeclare::setRank(int nums) {
|
||
this->page_rank = nums;
|
||
}
|
||
|
||
QString RankDeclare::signature() const {
|
||
return u8"::rank";
|
||
}
|
||
|
||
FragmentSlice::FragmentSlice(std::shared_ptr<const ExprRule> rule)
|
||
:AbstractImpl(rule) {
|
||
_slice_name = QString(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>_%1").arg((uint64_t)this);
|
||
}
|
||
|
||
QString FragmentSlice::name() const {
|
||
return _slice_name;
|
||
}
|
||
|
||
void FragmentSlice::setName(const QString& nm) {
|
||
this->_slice_name = nm;
|
||
}
|
||
|
||
QString FragmentSlice::signature() const {
|
||
return parent().lock()->signature() + u8"&" + name();
|
||
}
|
||
|
||
std::shared_ptr<const IExprInstance> NGlobalElement::bindExpression() const {
|
||
return shared_from_this();
|
||
}
|
||
|
||
int NGlobalElement::typeMark() const {
|
||
return (int)NovelNode::GlobalElement;
|
||
}
|
||
|
||
bool NGlobalElement::isAnonymous() const {
|
||
return true;
|
||
}
|
||
|
||
QString NGlobalElement::path() const {
|
||
return ExprProgram::filePath();
|
||
}
|
||
|
||
QString NGlobalElement::signature() const {
|
||
return u8"::program";
|
||
}
|
||
|
||
std::weak_ptr<const SyntaxElement> NGlobalElement::parent() const {
|
||
return std::weak_ptr<const SyntaxElement>();
|
||
}
|
||
|
||
void NGlobalElement::setParent(std::shared_ptr<const SyntaxElement> inst) { }
|
||
|
||
QList<std::shared_ptr<const TokenAccess>> NGlobalElement::selfTokens() const {
|
||
return QList<std::shared_ptr<const TokenAccess>>();
|
||
}
|
||
|
||
NGlobalElement::NGlobalElement(const QString& root): ExprProgram(root) { }
|
||
|
||
|
||
|
||
using namespace ast_gen;
|
||
using namespace ast_basic;
|
||
|
||
|
||
GlobalElement* GlobalElement::UniquePtr = nullptr;
|
||
|
||
GlobalElement::GlobalElement(const QString& name) :names_store(name) {
|
||
UniquePtr = this;
|
||
}
|
||
|
||
void GlobalElement::clearCache() {
|
||
node_cache.clear();
|
||
}
|
||
|
||
std::shared_ptr<const SyntaxElement> GlobalElement::appendToCache(std::shared_ptr<const SyntaxElement> named_node) {
|
||
auto mixed_key = QString(u8"%1<%2>").arg(named_node->signature()).arg(named_node->typeMark());
|
||
if (node_cache.contains(mixed_key))
|
||
return node_cache[mixed_key];
|
||
node_cache[mixed_key] = named_node;
|
||
return nullptr;
|
||
}
|
||
|
||
std::shared_ptr<const SyntaxElement> GlobalElement::getNamedNodeBy(int paramType, const QString& signature) const {
|
||
auto mixed_key = QString(u8"%1<%2>").arg(signature).arg(paramType);
|
||
if (!node_cache.contains(mixed_key))
|
||
return nullptr;
|
||
return node_cache[mixed_key];
|
||
}
|
||
|
||
int GlobalElement::typeMark() const {
|
||
return 0;
|
||
}
|
||
|
||
bool GlobalElement::isAnonymous() const {
|
||
return true;
|
||
}
|
||
|
||
QString GlobalElement::signature() const {
|
||
return u8"::global";
|
||
}
|
||
|
||
QString GlobalElement::path() const {
|
||
return u8"";
|
||
}
|
||
|
||
std::weak_ptr<const SyntaxElement> GlobalElement::parent() const {
|
||
return std::weak_ptr<const SyntaxElement>();
|
||
}
|
||
|
||
void GlobalElement::setParent(std::shared_ptr<const SyntaxElement> inst) { }
|
||
|
||
QList<std::shared_ptr<const TokenAccess>> GlobalElement::selfTokens() const {
|
||
return QList<std::shared_ptr<const TokenAccess>>();
|
||
}
|
||
|
||
std::shared_ptr<const IExprInstance> GlobalElement::bindExpression() const {
|
||
return nullptr;
|
||
}
|
||
|
||
void GlobalElement::addChild(std::shared_ptr<SyntaxElement> citem) { }
|
||
|
||
ElementAccess::ElementAccess(std::shared_ptr<const SyntaxElement> point) {
|
||
peers = point;
|
||
}
|
||
|
||
std::shared_ptr<const SyntaxElement> ElementAccess::element() const {
|
||
return peers;
|
||
}
|
||
|
||
QList<std::shared_ptr<const ElementAccess>> ElementAccess::children() const {
|
||
auto expression_inst = element()->bindExpression();
|
||
auto children = expression_inst->children();
|
||
|
||
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;
|
||
}
|
||
|
||
QList<std::shared_ptr<const TokenAccess>> ElementAccess::tokens() const {
|
||
return element()->selfTokens();
|
||
}
|
||
|
||
TokenAccess::TokenAccess(std::shared_ptr<const SyntaxElement> elm_inst, std::shared_ptr<const lib_token::IToken> token_inst)
|
||
: element_bind(elm_inst), token_store(token_inst) { }
|
||
|
||
std::shared_ptr<const SyntaxElement> TokenAccess::bind() const {
|
||
return element_bind;
|
||
}
|
||
|
||
std::shared_ptr<const lib_token::IToken> TokenAccess::token() const {
|
||
return token_store;
|
||
}
|