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