blob: 519e13d9e8cc08e134af5c8160c462f459c0eed3 [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
23#include <utils/KeyedVector.h>
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;
Andreas Huberc9410c72016-07-28 12:18:40 -070030
31struct Scope : public NamedType {
Andreas Huber9ed827c2016-08-22 12:31:13 -070032 Scope(const char *localName);
Andreas Huberc9410c72016-07-28 12:18:40 -070033
Andreas Huber39fa7182016-08-19 14:27:33 -070034 bool addType(const char *localName, Type *type, std::string *errorMsg);
Andreas Huber5a545442016-08-03 10:44:56 -070035
Andreas Huberc9410c72016-07-28 12:18:40 -070036 Type *lookupType(const char *name) const;
37
Andreas Huber5345ec22016-07-29 13:33:27 -070038 bool isScope() const override;
Andreas Huber881227d2016-08-02 14:20:21 -070039
40 // Returns the single interface or NULL.
41 Interface *getInterface() const;
42
Andreas Hubera2723d22016-07-29 15:36:07 -070043 bool containsSingleInterface(std::string *ifaceName) const;
Andreas Huberc9410c72016-07-28 12:18:40 -070044
Andreas Huberc7dfef32016-08-16 10:57:14 -070045 std::string pickUniqueAnonymousName() const;
46
Andreas Huber2831d512016-08-15 09:33:47 -070047 std::string getJavaType() const override;
48
Andreas Huber881227d2016-08-02 14:20:21 -070049 status_t emitTypeDeclarations(Formatter &out) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070050
51 status_t emitJavaTypeDeclarations(
52 Formatter &out, bool atTopLevel) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070053
54 status_t emitTypeDefinitions(
55 Formatter &out, const std::string prefix) const override;
56
Andreas Huber70a59e12016-08-16 12:57:01 -070057 const std::vector<Type *> &getSubTypes() const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070058
59 status_t emitVtsTypeDeclarations(Formatter &out) const override;
60
Andreas Huber70a59e12016-08-16 12:57:01 -070061 bool isJavaCompatible() const override;
62
Andreas Huber85eabdb2016-08-25 11:24:49 -070063 size_t countTypes() const;
64 const Type *typeAt(size_t index, std::string *name) const;
65
Andreas Huberc9410c72016-07-28 12:18:40 -070066private:
Andreas Huber70a59e12016-08-16 12:57:01 -070067 std::vector<Type *> mTypes;
Andreas Huberc9410c72016-07-28 12:18:40 -070068 KeyedVector<std::string, size_t> mTypeIndexByName;
69
Andreas Huberc9410c72016-07-28 12:18:40 -070070 DISALLOW_COPY_AND_ASSIGN(Scope);
71};
72
73} // namespace android
74
75#endif // SCOPE_H_
76