blob: 8d26cacc6e66cbca0834354f814302aed3397e86 [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
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
Andreas Huberc9410c72016-07-28 12:18:40 -070017#ifndef SCOPE_H_
18
19#define SCOPE_H_
20
21#include "NamedType.h"
22
Steven Morelandd537ab02016-09-12 10:32:01 -070023#include <map>
Andreas Huber70a59e12016-08-16 12:57:01 -070024#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070025
26namespace android {
27
Andreas Huber881227d2016-08-02 14:20:21 -070028struct Formatter;
29struct Interface;
Yifan Hongf24fa852016-09-23 11:03:15 -070030struct LocalIdentifier;
Andreas Huberc9410c72016-07-28 12:18:40 -070031
32struct Scope : public NamedType {
Andreas Huber9ed827c2016-08-22 12:31:13 -070033 Scope(const char *localName);
Yifan Hongf24fa852016-09-23 11:03:15 -070034 virtual ~Scope();
Andreas Huberc9410c72016-07-28 12:18:40 -070035
Steven Morelandd537ab02016-09-12 10:32:01 -070036 bool addType(NamedType *type, std::string *errorMsg);
Andreas Huber5a545442016-08-03 10:44:56 -070037
Yifan Hong327cfe12016-10-03 10:29:42 -070038 // lookup a type given an FQName.
39 // Assume fqName.package(), fqName.version(), fqName.valueName() is empty.
Yifan Hongae16eed2016-09-23 13:25:25 -070040 NamedType *lookupType(const FQName &fqName) const;
Andreas Huberc9410c72016-07-28 12:18:40 -070041
Yifan Hongf24fa852016-09-23 11:03:15 -070042 virtual LocalIdentifier *lookupIdentifier(const std::string &name) const;
43
Andreas Huber5345ec22016-07-29 13:33:27 -070044 bool isScope() const override;
Andreas Huber881227d2016-08-02 14:20:21 -070045
46 // Returns the single interface or NULL.
47 Interface *getInterface() const;
48
Andreas Hubera2723d22016-07-29 15:36:07 -070049 bool containsSingleInterface(std::string *ifaceName) const;
Andreas Huber7c5ddfb2016-09-29 13:45:22 -070050 bool containsInterfaces() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070051
Andreas Huber881227d2016-08-02 14:20:21 -070052 status_t emitTypeDeclarations(Formatter &out) const override;
Andreas Hubere3f769a2016-10-10 10:54:44 -070053 status_t emitGlobalTypeDeclarations(Formatter &out) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070054
55 status_t emitJavaTypeDeclarations(
56 Formatter &out, bool atTopLevel) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070057
58 status_t emitTypeDefinitions(
59 Formatter &out, const std::string prefix) const override;
60
Steven Morelandd537ab02016-09-12 10:32:01 -070061 const std::vector<NamedType *> &getSubTypes() const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070062
63 status_t emitVtsTypeDeclarations(Formatter &out) const override;
64
Andreas Huber70a59e12016-08-16 12:57:01 -070065 bool isJavaCompatible() const override;
66
Andreas Huber019d21d2016-10-03 12:59:47 -070067 void appendToExportedTypesVector(
68 std::vector<const Type *> *exportedTypes) const override;
69
Andreas Huberc9410c72016-07-28 12:18:40 -070070private:
Steven Morelandd537ab02016-09-12 10:32:01 -070071 std::vector<NamedType *> mTypes;
72 std::map<std::string, size_t> mTypeIndexByName;
Andreas Huberc9410c72016-07-28 12:18:40 -070073
Andreas Huberc9410c72016-07-28 12:18:40 -070074 DISALLOW_COPY_AND_ASSIGN(Scope);
75};
76
Yifan Hongf24fa852016-09-23 11:03:15 -070077struct LocalIdentifier {
78 LocalIdentifier();
79 virtual ~LocalIdentifier();
80 virtual bool isEnumValue() const;
81};
82
Andreas Huberc9410c72016-07-28 12:18:40 -070083} // namespace android
84
85#endif // SCOPE_H_
86