Scope.h revision 4c865b72b320a46f326a335cfd326b66b0e10f67
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;
30
31struct Scope : public NamedType {
32    Scope(const char *localName);
33
34    bool addType(NamedType *type, std::string *errorMsg);
35
36    NamedType *lookupType(const char *name) const;
37
38    bool isScope() const override;
39
40    // Returns the single interface or NULL.
41    Interface *getInterface() const;
42
43    bool containsSingleInterface(std::string *ifaceName) const;
44
45    std::string pickUniqueAnonymousName() const;
46
47    status_t emitTypeDeclarations(Formatter &out) const override;
48
49    status_t emitJavaTypeDeclarations(
50            Formatter &out, bool atTopLevel) const override;
51
52    status_t emitTypeDefinitions(
53            Formatter &out, const std::string prefix) const override;
54
55    const std::vector<NamedType *> &getSubTypes() const;
56
57    status_t emitVtsTypeDeclarations(Formatter &out) const override;
58
59    bool isJavaCompatible() const override;
60
61private:
62    std::vector<NamedType *> mTypes;
63    std::map<std::string, size_t> mTypeIndexByName;
64
65    DISALLOW_COPY_AND_ASSIGN(Scope);
66};
67
68}  // namespace android
69
70#endif  // SCOPE_H_
71
72