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