blob: 5475812acd8d401b1811a8d7c6f3e92fe0bbf70d [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 METHOD_H_
18
19#define METHOD_H_
20
21#include <android-base/macros.h>
22#include <string>
Andreas Huber3599d922016-08-09 10:42:57 -070023#include <utils/KeyedVector.h>
Andreas Huber881227d2016-08-02 14:20:21 -070024#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070025
26namespace android {
27
Andreas Huber3599d922016-08-09 10:42:57 -070028struct Annotation;
Andreas Huberc9410c72016-07-28 12:18:40 -070029struct Formatter;
Iliyan Malchev40d474a2016-08-16 06:20:17 -070030struct ScalarType;
Andreas Huberc9410c72016-07-28 12:18:40 -070031struct Type;
Andreas Huber31629bc2016-08-03 09:06:40 -070032struct TypedVar;
Andreas Huberc9410c72016-07-28 12:18:40 -070033
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070034using AnnotationVector =
35 DefaultKeyedVector<std::string, Annotation *>;
36
Andreas Huberc9410c72016-07-28 12:18:40 -070037struct Method {
38 Method(const char *name,
Andreas Huber881227d2016-08-02 14:20:21 -070039 std::vector<TypedVar *> *args,
Andreas Huber3599d922016-08-09 10:42:57 -070040 std::vector<TypedVar *> *results,
Iliyan Malchev639bff82016-08-13 14:24:11 -070041 bool oneway,
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070042 AnnotationVector *annotations);
Andreas Huberc9410c72016-07-28 12:18:40 -070043
Andreas Huber881227d2016-08-02 14:20:21 -070044 std::string name() const;
45 const std::vector<TypedVar *> &args() const;
46 const std::vector<TypedVar *> &results() const;
Iliyan Malchev639bff82016-08-13 14:24:11 -070047 bool isOneway() const { return mOneway; }
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070048 const AnnotationVector &annotations() const;
Andreas Huber881227d2016-08-02 14:20:21 -070049
50 static std::string GetSignature(const std::vector<TypedVar *> &args);
Andreas Huber2831d512016-08-15 09:33:47 -070051 static std::string GetJavaSignature(const std::vector<TypedVar *> &args);
Andreas Huber881227d2016-08-02 14:20:21 -070052
Iliyan Malchev40d474a2016-08-16 06:20:17 -070053 const TypedVar* canElideCallback() const;
54
Andreas Huber3599d922016-08-09 10:42:57 -070055 void dumpAnnotations(Formatter &out) const;
56
Andreas Huber70a59e12016-08-16 12:57:01 -070057 bool isJavaCompatible() const;
58
Andreas Huberc9410c72016-07-28 12:18:40 -070059private:
60 std::string mName;
Andreas Huber881227d2016-08-02 14:20:21 -070061 std::vector<TypedVar *> *mArgs;
62 std::vector<TypedVar *> *mResults;
Iliyan Malchev639bff82016-08-13 14:24:11 -070063 bool mOneway;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070064 AnnotationVector *mAnnotationsByName;
Andreas Huberc9410c72016-07-28 12:18:40 -070065
66 DISALLOW_COPY_AND_ASSIGN(Method);
67};
68
Andreas Huber31629bc2016-08-03 09:06:40 -070069struct TypedVar {
70 TypedVar(const char *name, Type *type);
71
72 std::string name() const;
73 const Type &type() const;
74
Andreas Huber70a59e12016-08-16 12:57:01 -070075 bool isJavaCompatible() const;
76
Andreas Huber31629bc2016-08-03 09:06:40 -070077private:
78 std::string mName;
79 Type *mType;
80
81 DISALLOW_COPY_AND_ASSIGN(TypedVar);
82};
83
Andreas Huberc9410c72016-07-28 12:18:40 -070084} // namespace android
85
86#endif // METHOD_H_
87