forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASTVisitor.h
78 lines (67 loc) · 2.7 KB
/
ASTVisitor.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
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
//===--- ASTVisitor.h - SILGen ASTVisitor specialization --------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines swift::Lowering::ASTVisitor.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_LOWERING_ASTVISITOR_H
#define SWIFT_LOWERING_ASTVISITOR_H
#include "swift/AST/ASTVisitor.h"
namespace swift {
namespace Lowering {
/// Lowering::ASTVisitor - This is a specialization of
/// swift::ASTVisitor which works only on resolved nodes and
/// which automatically ignores certain AST node kinds.
template<typename ImplClass,
typename ExprRetTy = void,
typename StmtRetTy = void,
typename DeclRetTy = void,
typename PatternRetTy = void,
typename... Args>
class ASTVisitor : public swift::ASTVisitor<ImplClass,
ExprRetTy,
StmtRetTy,
DeclRetTy,
PatternRetTy,
void,
void,
Args...>
{
public:
#define EXPR(Id, Parent)
#define UNCHECKED_EXPR(Id, Parent) \
ExprRetTy visit##Id##Expr(Id##Expr *E, Args...AA) { \
llvm_unreachable(#Id "Expr should not survive to SILGen"); \
}
#include "swift/AST/ExprNodes.def"
ExprRetTy visitErrorExpr(ErrorExpr *E, Args...AA) {
llvm_unreachable("expression kind should not survive to SILGen");
}
ExprRetTy visitCodeCompletionExpr(CodeCompletionExpr *E, Args...AA) {
llvm_unreachable("expression kind should not survive to SILGen");
}
ExprRetTy visitIdentityExpr(IdentityExpr *E, Args...AA) {
return static_cast<ImplClass*>(this)->visit(E->getSubExpr(),
std::forward<Args>(AA)...);
}
ExprRetTy visitTryExpr(TryExpr *E, Args...AA) {
return static_cast<ImplClass*>(this)->visit(E->getSubExpr(),
std::forward<Args>(AA)...);
}
};
template <typename ImplClass,
typename ExprRetTy = void,
typename... Args>
using ExprVisitor = ASTVisitor<ImplClass, ExprRetTy, void, void, void, Args...>;
} // end namespace Lowering
} // end namespace swift
#endif