1 //===--- PPEmbedParameters.h ------------------------------------*- 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 // Defines all of the preprocessor directive parmeters for #embed 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CLANG_LEX_PPEMBEDPARAMETERS_H 14 #define LLVM_CLANG_LEX_PPEMBEDPARAMETERS_H 15 16 #include "clang/Lex/PPDirectiveParameter.h" 17 #include "clang/Lex/Token.h" 18 #include "llvm/ADT/SmallVector.h" 19 20 namespace clang { 21 22 /// Preprocessor extension embed parameter "clang::offset" 23 /// `clang::offset( constant-expression )` 24 class PPEmbedParameterOffset : public PPDirectiveParameter { 25 public: 26 size_t Offset; 27 PPEmbedParameterOffset(size_t Offset,SourceRange R)28 PPEmbedParameterOffset(size_t Offset, SourceRange R) 29 : PPDirectiveParameter(R), Offset(Offset) {} 30 }; 31 32 /// Preprocessor standard embed parameter "limit" 33 /// `limit( constant-expression )` 34 class PPEmbedParameterLimit : public PPDirectiveParameter { 35 public: 36 size_t Limit; 37 PPEmbedParameterLimit(size_t Limit,SourceRange R)38 PPEmbedParameterLimit(size_t Limit, SourceRange R) 39 : PPDirectiveParameter(R), Limit(Limit) {} 40 }; 41 42 /// Preprocessor standard embed parameter "prefix" 43 /// `prefix( balanced-token-seq )` 44 class PPEmbedParameterPrefix : public PPDirectiveParameter { 45 public: 46 SmallVector<Token, 2> Tokens; 47 PPEmbedParameterPrefix(SmallVectorImpl<Token> && Tokens,SourceRange R)48 PPEmbedParameterPrefix(SmallVectorImpl<Token> &&Tokens, SourceRange R) 49 : PPDirectiveParameter(R), Tokens(std::move(Tokens)) {} 50 }; 51 52 /// Preprocessor standard embed parameter "suffix" 53 /// `suffix( balanced-token-seq )` 54 class PPEmbedParameterSuffix : public PPDirectiveParameter { 55 public: 56 SmallVector<Token, 2> Tokens; 57 PPEmbedParameterSuffix(SmallVectorImpl<Token> && Tokens,SourceRange R)58 PPEmbedParameterSuffix(SmallVectorImpl<Token> &&Tokens, SourceRange R) 59 : PPDirectiveParameter(R), Tokens(std::move(Tokens)) {} 60 }; 61 62 /// Preprocessor standard embed parameter "if_empty" 63 /// `if_empty( balanced-token-seq )` 64 class PPEmbedParameterIfEmpty : public PPDirectiveParameter { 65 public: 66 SmallVector<Token, 2> Tokens; 67 PPEmbedParameterIfEmpty(SmallVectorImpl<Token> && Tokens,SourceRange R)68 PPEmbedParameterIfEmpty(SmallVectorImpl<Token> &&Tokens, SourceRange R) 69 : PPDirectiveParameter(R), Tokens(std::move(Tokens)) {} 70 }; 71 72 struct LexEmbedParametersResult { 73 std::optional<PPEmbedParameterLimit> MaybeLimitParam; 74 std::optional<PPEmbedParameterOffset> MaybeOffsetParam; 75 std::optional<PPEmbedParameterIfEmpty> MaybeIfEmptyParam; 76 std::optional<PPEmbedParameterPrefix> MaybePrefixParam; 77 std::optional<PPEmbedParameterSuffix> MaybeSuffixParam; 78 int UnrecognizedParams; 79 PrefixTokenCountLexEmbedParametersResult80 size_t PrefixTokenCount() const { 81 if (MaybePrefixParam) 82 return MaybePrefixParam->Tokens.size(); 83 return 0; 84 } SuffixTokenCountLexEmbedParametersResult85 size_t SuffixTokenCount() const { 86 if (MaybeSuffixParam) 87 return MaybeSuffixParam->Tokens.size(); 88 return 0; 89 } 90 }; 91 } // end namespace clang 92 93 #endif 94