blob: 3faab576357fec6ecfedb63455bab64206c89651 [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
Steven Morelanda7a421a2016-09-07 08:35:18 -070050 void generateCppSignature(Formatter &out,
Steven Moreland979e0992016-09-07 09:18:08 -070051 const std::string &className,
52 bool specifyNamespaces) const;
Steven Morelanda7a421a2016-09-07 08:35:18 -070053
Steven Moreland979e0992016-09-07 09:18:08 -070054 static std::string GetArgSignature(const std::vector<TypedVar *> &args,
55 bool specifyNamespaces);
Steven Morelanda7a421a2016-09-07 08:35:18 -070056 static std::string GetJavaArgSignature(const std::vector<TypedVar *> &args);
Andreas Huber881227d2016-08-02 14:20:21 -070057
Iliyan Malchev40d474a2016-08-16 06:20:17 -070058 const TypedVar* canElideCallback() const;
59
Andreas Huber3599d922016-08-09 10:42:57 -070060 void dumpAnnotations(Formatter &out) const;
61
Andreas Huber70a59e12016-08-16 12:57:01 -070062 bool isJavaCompatible() const;
63
Andreas Huberc9410c72016-07-28 12:18:40 -070064private:
65 std::string mName;
Andreas Huber881227d2016-08-02 14:20:21 -070066 std::vector<TypedVar *> *mArgs;
67 std::vector<TypedVar *> *mResults;
Iliyan Malchev639bff82016-08-13 14:24:11 -070068 bool mOneway;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070069 AnnotationVector *mAnnotationsByName;
Andreas Huberc9410c72016-07-28 12:18:40 -070070
71 DISALLOW_COPY_AND_ASSIGN(Method);
72};
73
Andreas Huber31629bc2016-08-03 09:06:40 -070074struct TypedVar {
75 TypedVar(const char *name, Type *type);
76
77 std::string name() const;
78 const Type &type() const;
79
Andreas Huber70a59e12016-08-16 12:57:01 -070080 bool isJavaCompatible() const;
81
Andreas Huber31629bc2016-08-03 09:06:40 -070082private:
83 std::string mName;
84 Type *mType;
85
86 DISALLOW_COPY_AND_ASSIGN(TypedVar);
87};
88
Andreas Huberc9410c72016-07-28 12:18:40 -070089} // namespace android
90
91#endif // METHOD_H_
92