Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 17 | #ifndef ANNOTATION_H_ |
| 18 | |
| 19 | #define ANNOTATION_H_ |
| 20 | |
| 21 | #include <android-base/macros.h> |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 22 | #include <map> |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 23 | #include <string> |
Timur Iskhakov | 891a866 | 2017-08-25 21:53:48 -0700 | [diff] [blame] | 24 | #include <vector> |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 25 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 26 | #include "ConstantExpression.h" |
| 27 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | |
| 30 | struct Formatter; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 31 | |
| 32 | struct AnnotationParam { |
Timur Iskhakov | 7a85dc2 | 2017-08-10 19:06:41 -0700 | [diff] [blame] | 33 | virtual ~AnnotationParam() {} |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 34 | |
Timur Iskhakov | 7a85dc2 | 2017-08-10 19:06:41 -0700 | [diff] [blame] | 35 | const std::string& getName() const; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 36 | |
Timur Iskhakov | 7a85dc2 | 2017-08-10 19:06:41 -0700 | [diff] [blame] | 37 | virtual std::vector<std::string> getValues() const = 0; |
| 38 | virtual std::string getSingleValue() const = 0; |
Steven Moreland | db1b1b6 | 2017-01-10 09:50:55 -0800 | [diff] [blame] | 39 | |
| 40 | /* Returns unquoted version of getSingleValue */ |
| 41 | std::string getSingleString() const; |
| 42 | |
| 43 | /* Returns value interpretted as a boolean */ |
| 44 | bool getSingleBool() const; |
| 45 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 46 | std::vector<ConstantExpression*> getConstantExpressions(); |
| 47 | virtual std::vector<const ConstantExpression*> getConstantExpressions() const; |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 48 | |
Timur Iskhakov | 7a85dc2 | 2017-08-10 19:06:41 -0700 | [diff] [blame] | 49 | protected: |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 50 | const std::string mName; |
Timur Iskhakov | 7a85dc2 | 2017-08-10 19:06:41 -0700 | [diff] [blame] | 51 | |
| 52 | AnnotationParam(const std::string& name); |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Timur Iskhakov | 7a85dc2 | 2017-08-10 19:06:41 -0700 | [diff] [blame] | 55 | struct StringAnnotationParam : AnnotationParam { |
| 56 | StringAnnotationParam(const std::string& name, std::vector<std::string>* values); |
| 57 | |
| 58 | std::vector<std::string> getValues() const override; |
| 59 | std::string getSingleValue() const override; |
| 60 | |
| 61 | private: |
| 62 | std::vector<std::string>* const mValues; |
| 63 | }; |
| 64 | |
| 65 | struct ConstantExpressionAnnotationParam : AnnotationParam { |
| 66 | ConstantExpressionAnnotationParam(const std::string& name, |
| 67 | std::vector<ConstantExpression*>* values); |
| 68 | |
| 69 | std::vector<std::string> getValues() const override; |
| 70 | std::string getSingleValue() const override; |
| 71 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 72 | std::vector<const ConstantExpression*> getConstantExpressions() const override; |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 73 | |
Timur Iskhakov | 7a85dc2 | 2017-08-10 19:06:41 -0700 | [diff] [blame] | 74 | private: |
| 75 | std::vector<ConstantExpression*>* const mValues; |
Timur Iskhakov | 7a85dc2 | 2017-08-10 19:06:41 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | using AnnotationParamVector = std::vector<AnnotationParam*>; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 79 | |
| 80 | struct Annotation { |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 81 | Annotation(const char *name, AnnotationParamVector *params); |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 82 | |
| 83 | std::string name() const; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 84 | const AnnotationParamVector ¶ms() const; |
Andreas Huber | 019d21d | 2016-10-03 12:59:47 -0700 | [diff] [blame] | 85 | const AnnotationParam *getParam(const std::string &name) const; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 86 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 87 | std::vector<ConstantExpression*> getConstantExpressions(); |
| 88 | std::vector<const ConstantExpression*> getConstantExpressions() const; |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 89 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 90 | void dump(Formatter &out) const; |
| 91 | |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 92 | private: |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 93 | std::string mName; |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 94 | AnnotationParamVector *mParams; |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 95 | |
| 96 | DISALLOW_COPY_AND_ASSIGN(Annotation); |
| 97 | }; |
| 98 | |
| 99 | } // namespace android |
| 100 | |
| 101 | #endif // ANNOTATION_H_ |