Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
59 lines (48 loc) · 1.9 KB

File metadata and controls

59 lines (48 loc) · 1.9 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "hermes/AST/Context.h"
#include "hermes/IR/Analysis.h"
#include "hermes/IR/IRBuilder.h"
#include "hermes/IR/Instrs.h"
#include "gtest/gtest.h"
using namespace hermes;
namespace {
TEST(IRVerifierTest, ScopeAnalysisTest) {
auto Ctx = std::make_shared<Context>();
Module M(Ctx);
IRBuilder Builder(&M);
auto G = Builder.createTopLevelFunction(true);
auto F1 =
Builder.createFunction("f1", Function::DefinitionKind::ES5Function, true);
auto F2 =
Builder.createFunction("f2", Function::DefinitionKind::ES5Function, true);
auto orphan = Builder.createFunction(
"orphan", Function::DefinitionKind::ES5Function, true);
auto F11 = Builder.createFunction(
"f11", Function::DefinitionKind::ES5Function, true);
auto ES = Builder.createExternalScope(G, -5);
auto Gbb = Builder.createBasicBlock(G);
Builder.setInsertionBlock(Gbb);
Builder.createCreateFunctionInst(F1);
Builder.createCreateFunctionInst(F2);
auto F1bb = Builder.createBasicBlock(F1);
Builder.setInsertionBlock(F1bb);
Builder.createCreateFunctionInst(F11);
FunctionScopeAnalysis fsa{M.getTopLevelFunction()};
EXPECT_EQ(0, fsa.getScopeDepth(G->getFunctionScope()));
EXPECT_EQ(1, fsa.getScopeDepth(F1->getFunctionScope()));
EXPECT_EQ(1, fsa.getScopeDepth(F2->getFunctionScope()));
EXPECT_EQ(2, fsa.getScopeDepth(F11->getFunctionScope()));
EXPECT_EQ(-5, fsa.getScopeDepth(ES));
EXPECT_EQ(llvh::None, fsa.getScopeDepth(orphan->getFunctionScope()));
EXPECT_EQ(nullptr, fsa.getLexicalParent(G));
EXPECT_EQ(G, fsa.getLexicalParent(F1));
EXPECT_EQ(G, fsa.getLexicalParent(F2));
EXPECT_EQ(F1, fsa.getLexicalParent(F11));
EXPECT_EQ(llvh::None, fsa.getScopeDepth(orphan->getFunctionScope()));
}
} // end anonymous namespace
Morty Proxy This is a proxified and sanitized view of the page, visit original site.