1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#pragma once
#include "Decl.h"
#include "Token.h"
#include "Core/Array.h"
#include "Compiler/Basic/Function.h"
#include "Compiler/Basic/Expr.h"
#include "Compiler/Basic/Block.h"
namespace storm {
namespace syntax {
STORM_PKG(lang.bnf);
class Production;
class ProductionType;
/**
* Logic for generating code that extracts all children from a syntax tree into a plain
* array. Built on top of Basic Storm.
*/
class ChildrenFn : public bs::BSRawFn {
STORM_CLASS;
public:
// Create.
STORM_CTOR ChildrenFn(ProductionDecl *decl, ProductionType *owner, Rule *rule, Scope scope);
// Create the body of the function.
virtual bs::FnBody *STORM_FN createBody();
private:
// Scope.
Scope scope;
// The production we're extracting children from.
Production *source;
// Go through all tokens and add them to 'result'.
void addTokens(bs::ExprBlock *block, bs::Expr *result);
// Add a single token.
void addToken(bs::ExprBlock *block, bs::Expr *result, Token *token);
void addTokenIf(bs::ExprBlock *block, bs::Expr *result, Token *token);
void addTokenLoop(bs::ExprBlock *block, bs::Expr *result, Nat from, Nat to);
// Create 'result.push(tokenSrc)'.
bs::Expr *push(bs::Block *block, bs::Expr *result, bs::Expr *tokenSrc);
// Get 'this'.
bs::Expr *thisExpr(bs::ExprBlock *block);
// Treat the capture as a token:
Nat tokenCount();
Token *getToken(Nat pos);
};
// Create a children function.
Function *STORM_FN createChildrenFn(ProductionDecl *option, ProductionType *owner, Scope scope);
}
}
|