blob: 1b6fbe61238684c4291ca5064c223b15b977ad61 [file] [log] [blame]
Zonr Changc383a502010-10-12 01:52:08 +08001/*
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 Hinese639eb52010-11-08 19:27:20 -080017#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_PRAGMA_HANDLER_H_ // NOLINT
18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_PRAGMA_HANDLER_H_
Shih-wei Liao462aefd2010-06-04 15:32:04 -070019
20#include <string>
21
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070022#include "clang/Lex/Pragma.h"
Shih-wei Liao462aefd2010-06-04 15:32:04 -070023
24namespace clang {
zonr6315f762010-10-05 15:35:14 +080025 class Token;
26 class IdentifierInfo;
27 class Preprocessor;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070028}
Shih-wei Liao462aefd2010-06-04 15:32:04 -070029
30namespace slang {
31
zonr6315f762010-10-05 15:35:14 +080032 class RSContext;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070033
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070034class RSPragmaHandler : public clang::PragmaHandler {
35 protected:
36 RSContext *mContext;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070037
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070038 RSPragmaHandler(llvm::StringRef Name, RSContext *Context)
39 : clang::PragmaHandler(Name),
40 mContext(Context) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070041 }
42 RSContext *getContext() const {
43 return this->mContext;
44 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070045
Jean-Luc Brouillet796e7b12014-05-27 11:35:17 -070046 virtual void handleItem(const std::string &Item) { }
Stephen Hines7aff4a02011-12-08 18:34:27 -080047 virtual void handleInt(clang::Preprocessor &PP, clang::Token &Tok,
Jean-Luc Brouillet796e7b12014-05-27 11:35:17 -070048 const int v) { }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070049
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070050 // Handle pragma like #pragma rs [name] ([item #1],[item #2],...,[item #i])
51 void handleItemListPragma(clang::Preprocessor &PP,
52 clang::Token &FirstToken);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070053
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070054 // Handle pragma like #pragma rs [name]
55 void handleNonParamPragma(clang::Preprocessor &PP,
56 clang::Token &FirstToken);
Victor Hsiehc6718b32010-06-23 09:29:44 +080057
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070058 // Handle pragma like #pragma rs [name] ("string literal")
Stephen Hines9d2c0fa2011-01-05 14:55:18 -080059 void handleOptionalStringLiteralParamPragma(clang::Preprocessor &PP,
Stephen Hines96ab06c2011-01-05 15:29:26 -080060 clang::Token &FirstToken);
61
62 // Handle pragma like #pragma version (integer)
63 void handleIntegerParamPragma(clang::Preprocessor &PP,
64 clang::Token &FirstToken);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070065
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070066 public:
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070067 virtual void HandlePragma(clang::Preprocessor &PP,
Shih-wei Liaodf5bcce2011-02-28 18:39:23 -080068 clang::PragmaIntroducerKind Introducer,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070069 clang::Token &FirstToken) = 0;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070070};
71
Jean-Luc Brouillet109e90a2014-07-07 17:36:07 -070072// Add handlers for the RS pragmas to the preprocessor. These handlers
73// validate the pragmas and, if valid, set fields of the RSContext.
74void AddPragmaHandlers(clang::Preprocessor &PP, RSContext *RsContext);
75
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070076} // namespace slang
Shih-wei Liao462aefd2010-06-04 15:32:04 -070077
Stephen Hinese639eb52010-11-08 19:27:20 -080078#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_PRAGMA_HANDLER_H_ NOLINT