Scope.h revision cec46c48853a8c1246656d0095a9faa3fad5c4f9
11aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber/* 21aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Copyright (C) 2016 The Android Open Source Project 31aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * 41aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License"); 51aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * you may not use this file except in compliance with the License. 61aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * You may obtain a copy of the License at 71aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * 81aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * http://www.apache.org/licenses/LICENSE-2.0 91aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * 101aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Unless required by applicable law or agreed to in writing, software 111aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS, 121aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * See the License for the specific language governing permissions and 141aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * limitations under the License. 151aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber */ 161aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber 17c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#ifndef SCOPE_H_ 18c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 19c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#define SCOPE_H_ 20c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 21c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#include "NamedType.h" 22c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 23d537ab02e1707597d70665fd8c75ca1ec9f57326Steven Moreland#include <map> 2470a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber#include <vector> 25c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 26c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Hubernamespace android { 27c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 28e9ccfa2e9c177ead2b6ccb36dd20de294666abcdTimur Iskhakovstruct Annotation; 297296af19687b1c90dfd238398cd2c8ccb6bcd232Timur Iskhakovstruct ConstantExpression; 30881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberstruct Formatter; 31881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberstruct Interface; 32f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9Yifan Hongstruct LocalIdentifier; 33c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 34c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberstruct Scope : public NamedType { 35cb0ba5213057de39aa164f2f9a3691370bcbfe6bTimur Iskhakov Scope(const char* localName, const Location& location, Scope* parent); 36f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9Yifan Hong virtual ~Scope(); 37c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 38d537ab02e1707597d70665fd8c75ca1ec9f57326Steven Moreland bool addType(NamedType *type, std::string *errorMsg); 395a545440766886a1bbd09ed7221bb337705e5d14Andreas Huber 40327cfe12d51908469e1544db14a9232e0ddc6855Yifan Hong // lookup a type given an FQName. 41327cfe12d51908469e1544db14a9232e0ddc6855Yifan Hong // Assume fqName.package(), fqName.version(), fqName.valueName() is empty. 42ae16eeda35e175dbc3cb0651121854c5788e522eYifan Hong NamedType *lookupType(const FQName &fqName) const; 43c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 44f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9Yifan Hong virtual LocalIdentifier *lookupIdentifier(const std::string &name) const; 45f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9Yifan Hong 465345ec2b1b7e4126b77aa2131b231a9eb5ee811dAndreas Huber bool isScope() const override; 47881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber 48881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber // Returns the single interface or NULL. 49881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber Interface *getInterface() const; 50881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber 517c5ddfb41a806a7bf71581952d06b637a7670cf7Andreas Huber bool containsInterfaces() const; 52c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 53e9ccfa2e9c177ead2b6ccb36dd20de294666abcdTimur Iskhakov const std::vector<Annotation*>& annotations() const; 54e9ccfa2e9c177ead2b6ccb36dd20de294666abcdTimur Iskhakov 55e9ccfa2e9c177ead2b6ccb36dd20de294666abcdTimur Iskhakov void setAnnotations(std::vector<Annotation*>* annotations); 56e9ccfa2e9c177ead2b6ccb36dd20de294666abcdTimur Iskhakov 57cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov virtual status_t resolveInheritance() override; 58cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov virtual status_t evaluate() override; 59cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov virtual status_t validate() const override; 60cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov 61881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber status_t emitTypeDeclarations(Formatter &out) const override; 62e3f769aa75dd6be6bb1ba83904def47d9e464769Andreas Huber status_t emitGlobalTypeDeclarations(Formatter &out) const override; 63244e82d34bf0ef5d8d5b0730a9dea3e3fc4de7c5Yifan Hong status_t emitGlobalHwDeclarations(Formatter &out) const override; 6485eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber 6585eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber status_t emitJavaTypeDeclarations( 6685eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber Formatter &out, bool atTopLevel) const override; 67881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber 688c90cc59bf93bd0c08970b4488067a33015d4a1cChih-Hung Hsieh status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override; 69881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber 70d537ab02e1707597d70665fd8c75ca1ec9f57326Steven Moreland const std::vector<NamedType *> &getSubTypes() const; 715158db484e5ab302368f191d75d5b1334c270e52Zhuoyao Zhang 725158db484e5ab302368f191d75d5b1334c270e52Zhuoyao Zhang status_t emitVtsTypeDeclarations(Formatter &out) const override; 735158db484e5ab302368f191d75d5b1334c270e52Zhuoyao Zhang 7470a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber bool isJavaCompatible() const override; 7560d3b22101e911242d2d41c8dc8309e8706f1fe1Andreas Huber bool containsPointer() const override; 7670a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber 77019d21db821ee4ae6dd3858174a0a5cee4d33c25Andreas Huber void appendToExportedTypesVector( 78019d21db821ee4ae6dd3858174a0a5cee4d33c25Andreas Huber std::vector<const Type *> *exportedTypes) const override; 79019d21db821ee4ae6dd3858174a0a5cee4d33c25Andreas Huber 80c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberprivate: 81d537ab02e1707597d70665fd8c75ca1ec9f57326Steven Moreland std::vector<NamedType *> mTypes; 82d537ab02e1707597d70665fd8c75ca1ec9f57326Steven Moreland std::map<std::string, size_t> mTypeIndexByName; 83e9ccfa2e9c177ead2b6ccb36dd20de294666abcdTimur Iskhakov std::vector<Annotation*> mAnnotations; 84c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 858c90cc59bf93bd0c08970b4488067a33015d4a1cChih-Hung Hsieh status_t forEachType(const std::function<status_t(Type*)>& func) const; 86244e82d34bf0ef5d8d5b0730a9dea3e3fc4de7c5Yifan Hong 87c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber DISALLOW_COPY_AND_ASSIGN(Scope); 88c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber}; 89c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 900ecc7b8aca24a5618512610bb6371bdb91b5fdc2Steven Morelandstruct RootScope : public Scope { 910ecc7b8aca24a5618512610bb6371bdb91b5fdc2Steven Moreland RootScope(const char* localName, const Location& location, Scope* parent); 920ecc7b8aca24a5618512610bb6371bdb91b5fdc2Steven Moreland virtual ~RootScope(); 930ecc7b8aca24a5618512610bb6371bdb91b5fdc2Steven Moreland 94cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov virtual status_t validate() const override; 95cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov 960ecc7b8aca24a5618512610bb6371bdb91b5fdc2Steven Moreland std::string typeName() const override; 970ecc7b8aca24a5618512610bb6371bdb91b5fdc2Steven Moreland}; 980ecc7b8aca24a5618512610bb6371bdb91b5fdc2Steven Moreland 99f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9Yifan Hongstruct LocalIdentifier { 100f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9Yifan Hong LocalIdentifier(); 101f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9Yifan Hong virtual ~LocalIdentifier(); 102f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9Yifan Hong virtual bool isEnumValue() const; 1037296af19687b1c90dfd238398cd2c8ccb6bcd232Timur Iskhakov 104cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov virtual status_t evaluate(); 105cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov virtual status_t validate() const; 106cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov 1077296af19687b1c90dfd238398cd2c8ccb6bcd232Timur Iskhakov virtual ConstantExpression* constExpr() const; 108f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9Yifan Hong}; 109f24fa85b362d7eb66c7b880f48e1e2e9916bc8a9Yifan Hong 110c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber} // namespace android 111c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 112c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#endif // SCOPE_H_ 113c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 114