-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathFormalsUtil.h
47 lines (43 loc) · 1.47 KB
/
FormalsUtil.h
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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
template <class Fn, bool mapRest>
void MapFormalsImpl(ParseNodeFnc *pnodeFunc, Fn fn)
{
for (ParseNode *pnode = pnodeFunc->pnodeParams; pnode != nullptr; pnode = pnode->GetFormalNext())
{
fn(pnode);
}
if (mapRest && pnodeFunc->pnodeRest != nullptr)
{
fn(pnodeFunc->pnodeRest);
}
}
template <class Fn>
void MapFormalsWithoutRest(ParseNodeFnc *pnodeFunc, Fn fn)
{
return MapFormalsImpl<Fn, false>(pnodeFunc, fn);
}
template <class Fn>
void MapFormals(ParseNodeFnc *pnodeFunc, Fn fn)
{
return MapFormalsImpl<Fn, true>(pnodeFunc, fn);
}
template <class Fn>
void MapFormalsFromPattern(ParseNodeFnc *pnodeFunc, Fn fn)
{
for (ParseNode *pnode = pnodeFunc->pnodeParams; pnode != nullptr; pnode = pnode->GetFormalNext())
{
if (pnode->nop == knopParamPattern)
{
Parser::MapBindIdentifier(pnode->AsParseNodeParamPattern()->pnode1, fn);
}
}
ParseNodePtr rest = pnodeFunc->pnodeRest;
if (rest != nullptr && rest->nop == knopParamPattern)
{
Parser::MapBindIdentifier(rest->AsParseNodeParamPattern()->pnode1, fn);
}
}