Scope.h revision a4b53d0da8c1c6889c361fd30b913adc364163bc
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 Formatter;
29struct Interface;
30struct LocalIdentifier;
31
32struct 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
56    status_t emitJavaTypeDeclarations(
57            Formatter &out, bool atTopLevel) const override;
58
59    status_t emitTypeDefinitions(
60            Formatter &out, const std::string prefix) const override;
61
62    const std::vector<NamedType *> &getSubTypes() const;
63
64    status_t emitVtsTypeDeclarations(Formatter &out) const override;
65
66    bool isJavaCompatible() const override;
67
68    void appendToExportedTypesVector(
69            std::vector<const Type *> *exportedTypes) const override;
70
71private:
72    std::vector<NamedType *> mTypes;
73    std::map<std::string, size_t> mTypeIndexByName;
74
75    DISALLOW_COPY_AND_ASSIGN(Scope);
76};
77
78struct LocalIdentifier {
79    LocalIdentifier();
80    virtual ~LocalIdentifier();
81    virtual bool isEnumValue() const;
82};
83
84}  // namespace android
85
86#endif  // SCOPE_H_
87
88