blob: 2c3e177a2461439a9a7a1fae76c54311923ae0bd [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
Timur Iskhakove9ccfa22017-08-14 15:07:03 -070028struct Annotation;
Timur Iskhakov7296af12017-08-09 21:52:48 +000029struct ConstantExpression;
Andreas Huber881227d2016-08-02 14:20:21 -070030struct Formatter;
31struct Interface;
Yifan Hongf24fa852016-09-23 11:03:15 -070032struct LocalIdentifier;
Andreas Huberc9410c72016-07-28 12:18:40 -070033
34struct Scope : public NamedType {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -070035 Scope(const char* localName, const Location& location, Scope* parent);
Yifan Hongf24fa852016-09-23 11:03:15 -070036 virtual ~Scope();
Andreas Huberc9410c72016-07-28 12:18:40 -070037
Steven Morelandd537ab02016-09-12 10:32:01 -070038 bool addType(NamedType *type, std::string *errorMsg);
Andreas Huber5a545442016-08-03 10:44:56 -070039
Yifan Hong327cfe12016-10-03 10:29:42 -070040 // lookup a type given an FQName.
41 // Assume fqName.package(), fqName.version(), fqName.valueName() is empty.
Yifan Hongae16eed2016-09-23 13:25:25 -070042 NamedType *lookupType(const FQName &fqName) const;
Andreas Huberc9410c72016-07-28 12:18:40 -070043
Yifan Hongf24fa852016-09-23 11:03:15 -070044 virtual LocalIdentifier *lookupIdentifier(const std::string &name) const;
45
Andreas Huber5345ec22016-07-29 13:33:27 -070046 bool isScope() const override;
Andreas Huber881227d2016-08-02 14:20:21 -070047
48 // Returns the single interface or NULL.
49 Interface *getInterface() const;
50
Andreas Huber7c5ddfb2016-09-29 13:45:22 -070051 bool containsInterfaces() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070052
Timur Iskhakove9ccfa22017-08-14 15:07:03 -070053 const std::vector<Annotation*>& annotations() const;
54
55 void setAnnotations(std::vector<Annotation*>* annotations);
56
Timur Iskhakov33431e62017-08-21 17:31:23 -070057 std::vector<Type*> getDefinedTypes() const override;
58
Timur Iskhakovcec46c42017-08-09 00:22:02 -070059 virtual status_t evaluate() override;
60 virtual status_t validate() const override;
61
Andreas Huber881227d2016-08-02 14:20:21 -070062 status_t emitTypeDeclarations(Formatter &out) const override;
Andreas Hubere3f769a2016-10-10 10:54:44 -070063 status_t emitGlobalTypeDeclarations(Formatter &out) const override;
Yifan Hong244e82d2016-11-11 11:13:57 -080064 status_t emitGlobalHwDeclarations(Formatter &out) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070065
66 status_t emitJavaTypeDeclarations(
67 Formatter &out, bool atTopLevel) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070068
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -070069 status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070070
Steven Morelandd537ab02016-09-12 10:32:01 -070071 const std::vector<NamedType *> &getSubTypes() const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070072
73 status_t emitVtsTypeDeclarations(Formatter &out) const override;
74
Andreas Huber70a59e12016-08-16 12:57:01 -070075 bool isJavaCompatible() const override;
Andreas Huber60d3b222017-03-30 09:10:56 -070076 bool containsPointer() const override;
Andreas Huber70a59e12016-08-16 12:57:01 -070077
Andreas Huber019d21d2016-10-03 12:59:47 -070078 void appendToExportedTypesVector(
79 std::vector<const Type *> *exportedTypes) const override;
80
Andreas Huberc9410c72016-07-28 12:18:40 -070081private:
Steven Morelandd537ab02016-09-12 10:32:01 -070082 std::vector<NamedType *> mTypes;
83 std::map<std::string, size_t> mTypeIndexByName;
Timur Iskhakove9ccfa22017-08-14 15:07:03 -070084 std::vector<Annotation*> mAnnotations;
Andreas Huberc9410c72016-07-28 12:18:40 -070085
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -070086 status_t forEachType(const std::function<status_t(Type*)>& func) const;
Yifan Hong244e82d2016-11-11 11:13:57 -080087
Andreas Huberc9410c72016-07-28 12:18:40 -070088 DISALLOW_COPY_AND_ASSIGN(Scope);
89};
90
Steven Moreland0ecc7b82017-07-19 12:59:23 -070091struct RootScope : public Scope {
92 RootScope(const char* localName, const Location& location, Scope* parent);
93 virtual ~RootScope();
94
Timur Iskhakovcec46c42017-08-09 00:22:02 -070095 virtual status_t validate() const override;
96
Steven Moreland0ecc7b82017-07-19 12:59:23 -070097 std::string typeName() const override;
98};
99
Yifan Hongf24fa852016-09-23 11:03:15 -0700100struct LocalIdentifier {
101 LocalIdentifier();
102 virtual ~LocalIdentifier();
103 virtual bool isEnumValue() const;
Timur Iskhakov7296af12017-08-09 21:52:48 +0000104
Timur Iskhakovcec46c42017-08-09 00:22:02 -0700105 virtual status_t evaluate();
106 virtual status_t validate() const;
107
Timur Iskhakov7296af12017-08-09 21:52:48 +0000108 virtual ConstantExpression* constExpr() const;
Yifan Hongf24fa852016-09-23 11:03:15 -0700109};
110
Andreas Huberc9410c72016-07-28 12:18:40 -0700111} // namespace android
112
113#endif // SCOPE_H_
114