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 | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 17 | #ifndef SCOPE_H_ |
| 18 | |
| 19 | #define SCOPE_H_ |
| 20 | |
| 21 | #include "NamedType.h" |
| 22 | |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 23 | #include <map> |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 24 | #include <vector> |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | |
Timur Iskhakov | e9ccfa2 | 2017-08-14 15:07:03 -0700 | [diff] [blame] | 28 | struct Annotation; |
Timur Iskhakov | 7296af1 | 2017-08-09 21:52:48 +0000 | [diff] [blame] | 29 | struct ConstantExpression; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 30 | struct Formatter; |
| 31 | struct Interface; |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 32 | struct LocalIdentifier; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 33 | |
| 34 | struct Scope : public NamedType { |
Timur Iskhakov | cb0ba52 | 2017-07-17 20:01:37 -0700 | [diff] [blame] | 35 | Scope(const char* localName, const Location& location, Scope* parent); |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 36 | virtual ~Scope(); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 37 | |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 38 | bool addType(NamedType *type, std::string *errorMsg); |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 39 | |
Yifan Hong | 327cfe1 | 2016-10-03 10:29:42 -0700 | [diff] [blame] | 40 | // lookup a type given an FQName. |
| 41 | // Assume fqName.package(), fqName.version(), fqName.valueName() is empty. |
Yifan Hong | ae16eed | 2016-09-23 13:25:25 -0700 | [diff] [blame] | 42 | NamedType *lookupType(const FQName &fqName) const; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 43 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 44 | virtual LocalIdentifier *lookupIdentifier(const std::string &name) const; |
| 45 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 46 | bool isScope() const override; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 47 | |
| 48 | // Returns the single interface or NULL. |
| 49 | Interface *getInterface() const; |
| 50 | |
Andreas Huber | 7c5ddfb | 2016-09-29 13:45:22 -0700 | [diff] [blame] | 51 | bool containsInterfaces() const; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 52 | |
Timur Iskhakov | e9ccfa2 | 2017-08-14 15:07:03 -0700 | [diff] [blame] | 53 | const std::vector<Annotation*>& annotations() const; |
| 54 | |
| 55 | void setAnnotations(std::vector<Annotation*>* annotations); |
| 56 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 57 | std::vector<const Type*> getDefinedTypes() const override; |
Timur Iskhakov | 33431e6 | 2017-08-21 17:31:23 -0700 | [diff] [blame] | 58 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 59 | std::vector<const ConstantExpression*> getConstantExpressions() const override; |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 60 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 61 | status_t emitTypeDeclarations(Formatter &out) const override; |
Andreas Huber | e3f769a | 2016-10-10 10:54:44 -0700 | [diff] [blame] | 62 | status_t emitGlobalTypeDeclarations(Formatter &out) const override; |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 63 | status_t emitGlobalHwDeclarations(Formatter &out) const override; |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 64 | |
| 65 | status_t emitJavaTypeDeclarations( |
| 66 | Formatter &out, bool atTopLevel) const override; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 67 | |
Chih-Hung Hsieh | 8c90cc5 | 2017-08-03 14:51:13 -0700 | [diff] [blame] | 68 | status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 69 | |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 70 | const std::vector<NamedType *> &getSubTypes() const; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 71 | |
| 72 | status_t emitVtsTypeDeclarations(Formatter &out) const override; |
| 73 | |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 74 | bool isJavaCompatible() const override; |
Andreas Huber | 60d3b22 | 2017-03-30 09:10:56 -0700 | [diff] [blame] | 75 | bool containsPointer() const override; |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 76 | |
Andreas Huber | 019d21d | 2016-10-03 12:59:47 -0700 | [diff] [blame] | 77 | void appendToExportedTypesVector( |
| 78 | std::vector<const Type *> *exportedTypes) const override; |
| 79 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 80 | private: |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 81 | std::vector<NamedType *> mTypes; |
| 82 | std::map<std::string, size_t> mTypeIndexByName; |
Timur Iskhakov | e9ccfa2 | 2017-08-14 15:07:03 -0700 | [diff] [blame] | 83 | std::vector<Annotation*> mAnnotations; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 84 | |
Chih-Hung Hsieh | 8c90cc5 | 2017-08-03 14:51:13 -0700 | [diff] [blame] | 85 | status_t forEachType(const std::function<status_t(Type*)>& func) const; |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 86 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 87 | DISALLOW_COPY_AND_ASSIGN(Scope); |
| 88 | }; |
| 89 | |
Steven Moreland | 0ecc7b8 | 2017-07-19 12:59:23 -0700 | [diff] [blame] | 90 | struct RootScope : public Scope { |
| 91 | RootScope(const char* localName, const Location& location, Scope* parent); |
| 92 | virtual ~RootScope(); |
| 93 | |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 94 | virtual status_t validate() const override; |
| 95 | |
Steven Moreland | 0ecc7b8 | 2017-07-19 12:59:23 -0700 | [diff] [blame] | 96 | std::string typeName() const override; |
| 97 | }; |
| 98 | |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 99 | struct LocalIdentifier { |
| 100 | LocalIdentifier(); |
| 101 | virtual ~LocalIdentifier(); |
| 102 | virtual bool isEnumValue() const; |
Timur Iskhakov | 7296af1 | 2017-08-09 21:52:48 +0000 | [diff] [blame] | 103 | |
Timur Iskhakov | dbaed33 | 2017-08-31 16:33:41 -0700 | [diff] [blame^] | 104 | const LocalIdentifier* resolve() const; |
| 105 | LocalIdentifier* resolve(); |
| 106 | |
Timur Iskhakov | 7296af1 | 2017-08-09 21:52:48 +0000 | [diff] [blame] | 107 | virtual ConstantExpression* constExpr() const; |
Yifan Hong | f24fa85 | 2016-09-23 11:03:15 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 110 | } // namespace android |
| 111 | |
| 112 | #endif // SCOPE_H_ |
| 113 | |