clang
20.0.0git
include
clang
Sema
ParsedTemplate.h
Go to the documentation of this file.
1
//===--- ParsedTemplate.h - Template Parsing Data Types ---------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file provides data structures that store the parsed representation of
10
// templates.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_SEMA_PARSEDTEMPLATE_H
15
#define LLVM_CLANG_SEMA_PARSEDTEMPLATE_H
16
17
#include "
clang/Basic/OperatorKinds.h
"
18
#include "
clang/Basic/SourceLocation.h
"
19
#include "
clang/Basic/TemplateKinds.h
"
20
#include "
clang/Sema/DeclSpec.h
"
21
#include "
clang/Sema/Ownership.h
"
22
#include "llvm/ADT/SmallVector.h"
23
#include <cassert>
24
#include <cstdlib>
25
#include <new>
26
27
namespace
clang
{
28
/// Represents the parsed form of a C++ template argument.
29
class
ParsedTemplateArgument
{
30
public
:
31
/// Describes the kind of template argument that was parsed.
32
enum
KindType
{
33
/// A template type parameter, stored as a type.
34
Type
,
35
/// A non-type template parameter, stored as an expression.
36
NonType
,
37
/// A template template argument, stored as a template name.
38
Template
39
};
40
41
/// Build an empty template argument.
42
///
43
/// This template argument is invalid.
44
ParsedTemplateArgument
() : Kind(
Type
), Arg(nullptr) { }
45
46
/// Create a template type argument or non-type template argument.
47
///
48
/// \param Arg the template type argument or non-type template argument.
49
/// \param Loc the location of the type.
50
ParsedTemplateArgument
(
KindType
Kind,
void
*Arg,
SourceLocation
Loc)
51
: Kind(Kind), Arg(Arg),
Loc
(
Loc
) { }
52
53
/// Create a template template argument.
54
///
55
/// \param SS the C++ scope specifier that precedes the template name, if
56
/// any.
57
///
58
/// \param Template the template to which this template template
59
/// argument refers.
60
///
61
/// \param TemplateLoc the location of the template name.
62
ParsedTemplateArgument
(
const
CXXScopeSpec
&SS,
63
ParsedTemplateTy
Template
,
64
SourceLocation
TemplateLoc)
65
: Kind(
ParsedTemplateArgument
::
Template
),
66
Arg(
Template
.getAsOpaquePtr()), SS(SS), Loc(TemplateLoc) {}
67
68
/// Determine whether the given template argument is invalid.
69
bool
isInvalid
()
const
{
return
Arg ==
nullptr
; }
70
71
/// Determine what kind of template argument we have.
72
KindType
getKind
()
const
{
return
Kind; }
73
74
/// Retrieve the template type argument's type.
75
ParsedType
getAsType
()
const
{
76
assert(Kind ==
Type
&&
"Not a template type argument"
);
77
return
ParsedType::getFromOpaquePtr
(Arg);
78
}
79
80
/// Retrieve the non-type template argument's expression.
81
Expr
*
getAsExpr
()
const
{
82
assert(Kind ==
NonType
&&
"Not a non-type template argument"
);