clang 23.0.0git
ParseReflect.cpp
Go to the documentation of this file.
1//===--- ParseReflect.cpp - C++26 Reflection Parsing ---------------------===//
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 implements parsing for reflection facilities.
10//
11//===----------------------------------------------------------------------===//
12
15#include "clang/Parse/Parser.h"
17using namespace clang;
18
19ExprResult Parser::ParseCXXReflectExpression() {
20 // TODO(reflection) : support parsing for global namespace,
21 // reflection-name, id-expression and remaining supports for
22 // type-id (placeholder type, alias template, etc.)
23 EnterExpressionEvaluationContext Unevaluated(
25 assert(Tok.is(tok::caretcaret));
26 SourceLocation CaretCaretLoc = ConsumeToken();
27 SourceLocation OperandLoc = Tok.getLocation();
28
30 TypeResult TR = ParseTypeName(/*TypeOf=*/nullptr);
31 if (TR.isInvalid())
32 return ExprError();
33
34 TypeSourceInfo *TSI = nullptr;
35 QualType QT = Actions.GetTypeFromParser(TR.get(), &TSI);
36
37 if (QT.isNull())
38 return ExprError();
39
40 if (!TSI)
41 TSI = Actions.getASTContext().getTrivialTypeSourceInfo(QT, OperandLoc);
42
44 if (TSI && QT.getTypePtr()->isBuiltinType()) {
45 // Only supports builtin types for now
46 return Actions.ActOnCXXReflectExpr(CaretCaretLoc, TSI);
47 }
48 }
49
50 Diag(OperandLoc, diag::err_cannot_reflect_operand);
51 return ExprError();
52}
PtrTy get() const
Definition Ownership.h:171
bool isInvalid() const
Definition Ownership.h:167
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName.
Definition ParseDecl.cpp:44
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Definition Parser.cpp:88
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
Definition Parser.h:263
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8388
QualType getCanonicalType() const
Definition TypeBase.h:8440
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8482
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
Definition Sema.h:6758
bool isBuiltinType() const
Helper methods to distinguish type categories.
Definition TypeBase.h:8748
The JSON file list parser is used to communicate input to InstallAPI.
ActionResult< ParsedType > TypeResult
Definition Ownership.h:251
ExprResult ExprError()
Definition Ownership.h:265
ActionResult< Expr * > ExprResult
Definition Ownership.h:249