blob: 0b341828f21356b1e2c9090c0abd8f4573eb1a08 [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 {
Yifan Honga4b53d02016-10-31 17:29:10 -070033 Scope(const char *localName,
34 const Location &location);
Yifan Hongf24fa852016-09-23 11:03:15 -070035 virtual ~Scope();
Andreas Huberc9410c72016-07-28 12:18:40 -070036
Steven Morelandd537ab02016-09-12 10:32:01 -070037 bool addType(NamedType *type, std::string *errorMsg);
Andreas Huber5a545442016-08-03 10:44:56 -070038
Yifan Hong327cfe12016-10-03 10:29:42 -070039 // lookup a type given an FQName.
40 // Assume fqName.package(), fqName.version(), fqName.valueName() is empty.
Yifan Hongae16eed2016-09-23 13:25:25 -070041 NamedType *lookupType(const FQName &fqName) const;
Andreas Huberc9410c72016-07-28 12:18:40 -070042
Yifan Hongf24fa852016-09-23 11:03:15 -070043 virtual LocalIdentifier *lookupIdentifier(const std::string &name) const;
44
Andreas Huber5345ec22016-07-29 13:33:27 -070045 bool isScope() const override;
Andreas Huber881227d2016-08-02 14:20:21 -070046
47 // Returns the single interface or NULL.
48 Interface *getInterface() const;
49
Andreas Hubera2723d22016-07-29 15:36:07 -070050 bool containsSingleInterface(std::string *ifaceName) const;
Andreas Huber7c5ddfb2016-09-29 13:45:22 -070051 bool containsInterfaces() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070052
Andreas Huber881227d2016-08-02 14:20:21 -070053 status_t emitTypeDeclarations(Formatter &out) const override;
Andreas Hubere3f769a2016-10-10 10:54:44 -070054 status_t emitGlobalTypeDeclarations(Formatter &out) const override;
Yifan Hong244e82d2016-11-11 11:13:57 -080055 status_t emitGlobalHwDeclarations(Formatter &out) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070056
57 status_t emitJavaTypeDeclarations(
58 Formatter &out, bool atTopLevel) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070059
60 status_t emitTypeDefinitions(
61 Formatter &out, const std::string prefix) const override;
62
Steven Morelandd537ab02016-09-12 10:32:01 -070063 const std::vector<NamedType *> &getSubTypes() const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070064
65 status_t emitVtsTypeDeclarations(Formatter &out) const override;
66
Andreas Huber70a59e12016-08-16 12:57:01 -070067 bool isJavaCompatible() const override;
68
Andreas Huber019d21d2016-10-03 12:59:47 -070069 void appendToExportedTypesVector(
70 std::vector<const Type *> *exportedTypes) const override;
71
Andreas Huberc9410c72016-07-28 12:18:40 -070072private:
Steven Morelandd537ab02016-09-12 10:32:01 -070073 std::vector<NamedType *> mTypes;
74 std::map<std::string, size_t> mTypeIndexByName;
Andreas Huberc9410c72016-07-28 12:18:40 -070075
Yifan Hong244e82d2016-11-11 11:13:57 -080076 status_t forEachType(std::function<status_t(Type *)> func) const;
77
Andreas Huberc9410c72016-07-28 12:18:40 -070078 DISALLOW_COPY_AND_ASSIGN(Scope);
79};
80
Yifan Hongf24fa852016-09-23 11:03:15 -070081struct LocalIdentifier {
82 LocalIdentifier();
83 virtual ~LocalIdentifier();
84 virtual bool isEnumValue() const;
85};
86
Andreas Huberc9410c72016-07-28 12:18:40 -070087} // namespace android
88
89#endif // SCOPE_H_
90