Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 17 | #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_PRAGMA_HANDLER_H_ // NOLINT |
| 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_PRAGMA_HANDLER_H_ |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 19 | |
| 20 | #include <string> |
| 21 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 22 | #include "clang/Lex/Pragma.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 23 | |
| 24 | namespace clang { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 25 | class Token; |
| 26 | class IdentifierInfo; |
| 27 | class Preprocessor; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 28 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 29 | |
| 30 | namespace slang { |
| 31 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 32 | class RSContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 33 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 34 | class RSPragmaHandler : public clang::PragmaHandler { |
| 35 | protected: |
| 36 | RSContext *mContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 37 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 38 | RSPragmaHandler(llvm::StringRef Name, RSContext *Context) |
| 39 | : clang::PragmaHandler(Name), |
| 40 | mContext(Context) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 41 | } |
| 42 | RSContext *getContext() const { |
| 43 | return this->mContext; |
| 44 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 45 | |
Jean-Luc Brouillet | 796e7b1 | 2014-05-27 11:35:17 -0700 | [diff] [blame] | 46 | virtual void handleItem(const std::string &Item) { } |
Stephen Hines | 7aff4a0 | 2011-12-08 18:34:27 -0800 | [diff] [blame] | 47 | virtual void handleInt(clang::Preprocessor &PP, clang::Token &Tok, |
Jean-Luc Brouillet | 796e7b1 | 2014-05-27 11:35:17 -0700 | [diff] [blame] | 48 | const int v) { } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 49 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 50 | // Handle pragma like #pragma rs [name] ([item #1],[item #2],...,[item #i]) |
| 51 | void handleItemListPragma(clang::Preprocessor &PP, |
| 52 | clang::Token &FirstToken); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 53 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 54 | // Handle pragma like #pragma rs [name] |
| 55 | void handleNonParamPragma(clang::Preprocessor &PP, |
| 56 | clang::Token &FirstToken); |
Victor Hsieh | c6718b3 | 2010-06-23 09:29:44 +0800 | [diff] [blame] | 57 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 58 | // Handle pragma like #pragma rs [name] ("string literal") |
Stephen Hines | 9d2c0fa | 2011-01-05 14:55:18 -0800 | [diff] [blame] | 59 | void handleOptionalStringLiteralParamPragma(clang::Preprocessor &PP, |
Stephen Hines | 96ab06c | 2011-01-05 15:29:26 -0800 | [diff] [blame] | 60 | clang::Token &FirstToken); |
| 61 | |
| 62 | // Handle pragma like #pragma version (integer) |
| 63 | void handleIntegerParamPragma(clang::Preprocessor &PP, |
| 64 | clang::Token &FirstToken); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 65 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 66 | public: |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 67 | virtual void HandlePragma(clang::Preprocessor &PP, |
Shih-wei Liao | df5bcce | 2011-02-28 18:39:23 -0800 | [diff] [blame] | 68 | clang::PragmaIntroducerKind Introducer, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 69 | clang::Token &FirstToken) = 0; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Jean-Luc Brouillet | 109e90a | 2014-07-07 17:36:07 -0700 | [diff] [blame] | 72 | // Add handlers for the RS pragmas to the preprocessor. These handlers |
| 73 | // validate the pragmas and, if valid, set fields of the RSContext. |
| 74 | void AddPragmaHandlers(clang::Preprocessor &PP, RSContext *RsContext); |
| 75 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 76 | } // namespace slang |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 77 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 78 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_PRAGMA_HANDLER_H_ NOLINT |