• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <unordered_map>
25 #include <vector>
26 
27 namespace android {
28 
29 struct Annotation;
30 struct ConstantExpression;
31 struct Formatter;
32 struct Interface;
33 struct LocalIdentifier;
34 
35 struct Scope : public NamedType {
36     Scope(const char* localName, const FQName& fullName, const Location& location, Scope* parent);
37     virtual ~Scope();
38 
39     void addType(NamedType* type);
40 
41     status_t validateUniqueNames() const;
42 
43     // lookup a type given an FQName.
44     // Assume fqName.package(), fqName.version(), fqName.valueName() is empty.
45     NamedType *lookupType(const FQName &fqName) const;
46 
47     virtual LocalIdentifier *lookupIdentifier(const std::string &name) const;
48 
49     bool isScope() const override;
50 
51     // Returns the single interface or NULL.
52     Interface *getInterface() const;
53 
54     bool definesInterfaces() const;
55 
56     const std::vector<Annotation*>& annotations() const;
57 
58     void setAnnotations(std::vector<Annotation*>* annotations);
59 
60     std::vector<const Type*> getDefinedTypes() const override;
61 
62     std::vector<const ConstantExpression*> getConstantExpressions() const override;
63 
64     void topologicalReorder(const std::unordered_map<const Type*, size_t>& reversedOrder);
65 
66     void emitTypeDeclarations(Formatter& out) const override;
67     void emitGlobalTypeDeclarations(Formatter& out) const override;
68     void emitPackageTypeDeclarations(Formatter& out) const override;
69     void emitPackageTypeHeaderDefinitions(Formatter& out) const override;
70     void emitPackageHwDeclarations(Formatter& out) const override;
71 
72     void emitJavaTypeDeclarations(Formatter& out, bool atTopLevel) const override;
73 
74     void emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
75 
76     const std::vector<NamedType *> &getSubTypes() const;
77 
78     void emitVtsTypeDeclarations(Formatter& out) const override;
79 
80     bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
81 
82     void appendToExportedTypesVector(
83             std::vector<const Type *> *exportedTypes) const override;
84 
85    private:
86     std::vector<NamedType *> mTypes;
87     std::map<std::string, size_t> mTypeIndexByName;
88     std::vector<Annotation*> mAnnotations;
89 
90     bool mTypeOrderChanged = false;
91 
92     DISALLOW_COPY_AND_ASSIGN(Scope);
93 };
94 
95 struct RootScope : public Scope {
96     RootScope(const char* localName, const FQName& fullName, const Location& location,
97               Scope* parent);
98     virtual ~RootScope();
99 
100     virtual status_t validate() const override;
101 
102     std::string typeName() const override;
103 };
104 
105 struct LocalIdentifier {
106     LocalIdentifier();
107     virtual ~LocalIdentifier();
108     virtual bool isEnumValue() const;
109 
110     const LocalIdentifier* resolve() const;
111     LocalIdentifier* resolve();
112 
113     virtual ConstantExpression* constExpr() const;
114 };
115 
116 }  // namespace android
117 
118 #endif  // SCOPE_H_
119 
120