blob: dfeb59e55a053ae23c61901ac13c58a4baeb7dab [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
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 Huber3599d922016-08-09 10:42:57 -070017#ifndef ANNOTATION_H_
18
19#define ANNOTATION_H_
20
21#include <android-base/macros.h>
Steven Morelandd537ab02016-09-12 10:32:01 -070022#include <map>
Andreas Huber3599d922016-08-09 10:42:57 -070023#include <string>
Timur Iskhakov891a8662017-08-25 21:53:48 -070024#include <vector>
Andreas Huber3599d922016-08-09 10:42:57 -070025
Yifan Hongf24fa852016-09-23 11:03:15 -070026#include "ConstantExpression.h"
27
Andreas Huber3599d922016-08-09 10:42:57 -070028namespace android {
29
30struct Formatter;
Steven Morelandd537ab02016-09-12 10:32:01 -070031
32struct AnnotationParam {
Timur Iskhakov7a85dc22017-08-10 19:06:41 -070033 virtual ~AnnotationParam() {}
Steven Morelandd537ab02016-09-12 10:32:01 -070034
Timur Iskhakov7a85dc22017-08-10 19:06:41 -070035 const std::string& getName() const;
Steven Morelandd537ab02016-09-12 10:32:01 -070036
Timur Iskhakov7a85dc22017-08-10 19:06:41 -070037 virtual std::vector<std::string> getValues() const = 0;
38 virtual std::string getSingleValue() const = 0;
Steven Morelanddb1b1b62017-01-10 09:50:55 -080039
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 Iskhakovb58f4182017-08-29 15:19:24 -070046 std::vector<ConstantExpression*> getConstantExpressions();
47 virtual std::vector<const ConstantExpression*> getConstantExpressions() const;
Timur Iskhakovcec46c42017-08-09 00:22:02 -070048
Timur Iskhakov7a85dc22017-08-10 19:06:41 -070049 protected:
Steven Morelandd537ab02016-09-12 10:32:01 -070050 const std::string mName;
Timur Iskhakov7a85dc22017-08-10 19:06:41 -070051
52 AnnotationParam(const std::string& name);
Steven Morelandd537ab02016-09-12 10:32:01 -070053};
54
Timur Iskhakov7a85dc22017-08-10 19:06:41 -070055struct 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
65struct 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 Iskhakovb58f4182017-08-29 15:19:24 -070072 std::vector<const ConstantExpression*> getConstantExpressions() const override;
Timur Iskhakovcec46c42017-08-09 00:22:02 -070073
Timur Iskhakov7a85dc22017-08-10 19:06:41 -070074 private:
75 std::vector<ConstantExpression*>* const mValues;
Timur Iskhakov7a85dc22017-08-10 19:06:41 -070076};
77
78using AnnotationParamVector = std::vector<AnnotationParam*>;
Andreas Huber3599d922016-08-09 10:42:57 -070079
80struct Annotation {
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070081 Annotation(const char *name, AnnotationParamVector *params);
Andreas Huber3599d922016-08-09 10:42:57 -070082
83 std::string name() const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070084 const AnnotationParamVector &params() const;
Andreas Huber019d21d2016-10-03 12:59:47 -070085 const AnnotationParam *getParam(const std::string &name) const;
Andreas Huber3599d922016-08-09 10:42:57 -070086
Timur Iskhakovb58f4182017-08-29 15:19:24 -070087 std::vector<ConstantExpression*> getConstantExpressions();
88 std::vector<const ConstantExpression*> getConstantExpressions() const;
Timur Iskhakovcec46c42017-08-09 00:22:02 -070089
Andreas Huber3599d922016-08-09 10:42:57 -070090 void dump(Formatter &out) const;
91
Timur Iskhakovcec46c42017-08-09 00:22:02 -070092 private:
Andreas Huber3599d922016-08-09 10:42:57 -070093 std::string mName;
Steven Morelandd537ab02016-09-12 10:32:01 -070094 AnnotationParamVector *mParams;
Andreas Huber3599d922016-08-09 10:42:57 -070095
96 DISALLOW_COPY_AND_ASSIGN(Annotation);
97};
98
99} // namespace android
100
101#endif // ANNOTATION_H_