forked from Samsung/escargot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramNode.h
More file actions
82 lines (70 loc) · 2.89 KB
/
ProgramNode.h
File metadata and controls
82 lines (70 loc) · 2.89 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Copyright (c) 2016-present Samsung Electronics Co., Ltd
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#ifndef ProgramNode_h
#define ProgramNode_h
#include "Node.h"
#include "StatementNode.h"
#include "parser/ScriptParser.h"
#include "parser/Script.h"
namespace Escargot {
class ProgramNode : public StatementNode {
public:
ProgramNode(StatementContainer* body, ASTScopeContext* scopeContext, Script::ModuleData* moduleData, NumeralLiteralVector&& numeralLiteralVector)
: StatementNode()
, m_container(body)
, m_scopeContext(scopeContext)
, m_moduleData(moduleData)
, m_numeralLiteralVector(std::move(numeralLiteralVector))
{
}
virtual ASTNodeType type() override { return ASTNodeType::Program; }
ASTScopeContext* scopeContext() { return m_scopeContext; }
Script::ModuleData* moduleData() { return m_moduleData; }
NumeralLiteralVector& numeralLiteralVector() { return m_numeralLiteralVector; }
virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) override
{
InterpretedCodeBlock::BlockInfo* bi = codeBlock->m_codeBlock->blockInfo(0);
ByteCodeBlock::ByteCodeLexicalBlockContext blockContext = codeBlock->pushLexicalBlock(context, bi, this);
size_t start = codeBlock->currentCodeSize();
m_container->generateStatementByteCode(codeBlock, context);
codeBlock->finalizeLexicalBlock(context, blockContext);
#ifdef ESCARGOT_DEBUGGER
if (context->m_breakpointContext->m_breakpointLocations.size() == 0) {
if (context->m_isEvalCode) {
context->insertBreakpointAt(1, this);
} else {
insertBreakpoint(context);
}
}
#endif /* ESCARGOT_DEBUGGER */
codeBlock->pushCode(End(ByteCodeLOC(SIZE_MAX), 0), context, this);
}
virtual void iterateChildren(const std::function<void(Node* node)>& fn) override
{
fn(this);
m_container->iterateChildren(fn);
}
private:
StatementContainer* m_container;
ASTScopeContext* m_scopeContext;
Script::ModuleData* m_moduleData;
NumeralLiteralVector m_numeralLiteralVector;
};
} // namespace Escargot
#endif