File: Children.h

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (59 lines) | stat: -rw-r--r-- 1,587 bytes parent folder | download | duplicates (2)
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);
	}
}