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 17 #ifndef SCOPE_H_ 18 19 #define SCOPE_H_ 20 21 #include "NamedType.h" 22 23 #include <map> 24 #include <vector> 25 26 namespace android { 27 28 struct Formatter; 29 struct Interface; 30 struct LocalIdentifier; 31 32 struct Scope : public NamedType { 33 Scope(const char *localName, 34 const Location &location); 35 virtual ~Scope(); 36 37 bool addType(NamedType *type, std::string *errorMsg); 38 39 // lookup a type given an FQName. 40 // Assume fqName.package(), fqName.version(), fqName.valueName() is empty. 41 NamedType *lookupType(const FQName &fqName) const; 42 43 virtual LocalIdentifier *lookupIdentifier(const std::string &name) const; 44 45 bool isScope() const override; 46 47 // Returns the single interface or NULL. 48 Interface *getInterface() const; 49 50 bool containsSingleInterface(std::string *ifaceName) const; 51 bool containsInterfaces() const; 52 53 status_t emitTypeDeclarations(Formatter &out) const override; 54 status_t emitGlobalTypeDeclarations(Formatter &out) const override; 55 status_t emitGlobalHwDeclarations(Formatter &out) const override; 56 57 status_t emitJavaTypeDeclarations( 58 Formatter &out, bool atTopLevel) const override; 59 60 status_t emitTypeDefinitions( 61 Formatter &out, const std::string prefix) const override; 62 63 const std::vector<NamedType *> &getSubTypes() const; 64 65 status_t emitVtsTypeDeclarations(Formatter &out) const override; 66 67 bool isJavaCompatible() const override; 68 bool containsPointer() const override; 69 70 void appendToExportedTypesVector( 71 std::vector<const Type *> *exportedTypes) const override; 72 73 private: 74 std::vector<NamedType *> mTypes; 75 std::map<std::string, size_t> mTypeIndexByName; 76 77 status_t forEachType(std::function<status_t(Type *)> func) const; 78 79 DISALLOW_COPY_AND_ASSIGN(Scope); 80 }; 81 82 struct LocalIdentifier { 83 LocalIdentifier(); 84 virtual ~LocalIdentifier(); 85 virtual bool isEnumValue() const; 86 }; 87 88 } // namespace android 89 90 #endif // SCOPE_H_ 91 92