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 
17 #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_PRAGMA_HANDLER_H_  // NOLINT
18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_PRAGMA_HANDLER_H_
19 
20 #include <string>
21 
22 #include "clang/Lex/Pragma.h"
23 
24 namespace clang {
25   class Token;
26   class IdentifierInfo;
27   class Preprocessor;
28 }
29 
30 namespace slang {
31 
32   class RSContext;
33 
34 class RSPragmaHandler : public clang::PragmaHandler {
35  protected:
36   RSContext *mContext;
37 
RSPragmaHandler(llvm::StringRef Name,RSContext * Context)38   RSPragmaHandler(llvm::StringRef Name, RSContext *Context)
39       : clang::PragmaHandler(Name),
40         mContext(Context) {
41   }
getContext()42   RSContext *getContext() const {
43     return this->mContext;
44   }
45 
handleItem(const std::string & Item)46   virtual void handleItem(const std::string &Item) { }
handleInt(clang::Preprocessor & PP,clang::Token & Tok,const int v)47   virtual void handleInt(clang::Preprocessor &PP, clang::Token &Tok,
48                          const int v) { }
49 
50   // Handle pragma like #pragma rs [name] ([item #1],[item #2],...,[item #i])
51   void handleItemListPragma(clang::Preprocessor &PP,
52                             clang::Token &FirstToken);
53 
54   // Handle pragma like #pragma rs [name]
55   void handleNonParamPragma(clang::Preprocessor &PP,
56                             clang::Token &FirstToken);
57 
58   // Handle pragma like #pragma rs [name] ("string literal")
59   void handleOptionalStringLiteralParamPragma(clang::Preprocessor &PP,
60                                               clang::Token &FirstToken);
61 
62   // Handle pragma like #pragma version (integer)
63   void handleIntegerParamPragma(clang::Preprocessor &PP,
64                                 clang::Token &FirstToken);
65 
66  public:
67   virtual void HandlePragma(clang::Preprocessor &PP,
68                             clang::PragmaIntroducerKind Introducer,
69                             clang::Token &FirstToken) = 0;
70 };
71 
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 
76 }   // namespace slang
77 
78 #endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_PRAGMA_HANDLER_H_  NOLINT
79