blob: aba775506ab2e771e4cc4faa29719f4f1753a713 [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 Huber881227d2016-08-02 14:20:21 -070023#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070024
25namespace android {
26
Andreas Huber3599d922016-08-09 10:42:57 -070027struct Annotation;
Andreas Huberc9410c72016-07-28 12:18:40 -070028struct Formatter;
Iliyan Malchev40d474a2016-08-16 06:20:17 -070029struct ScalarType;
Andreas Huberc9410c72016-07-28 12:18:40 -070030struct Type;
Andreas Huber31629bc2016-08-03 09:06:40 -070031struct TypedVar;
Andreas Huberc9410c72016-07-28 12:18:40 -070032
33struct Method {
34 Method(const char *name,
Andreas Huber881227d2016-08-02 14:20:21 -070035 std::vector<TypedVar *> *args,
Andreas Huber3599d922016-08-09 10:42:57 -070036 std::vector<TypedVar *> *results,
Iliyan Malchev639bff82016-08-13 14:24:11 -070037 bool oneway,
Steven Morelandd537ab02016-09-12 10:32:01 -070038 std::vector<Annotation *> *annotations);
Andreas Huberc9410c72016-07-28 12:18:40 -070039
Andreas Huber881227d2016-08-02 14:20:21 -070040 std::string name() const;
41 const std::vector<TypedVar *> &args() const;
42 const std::vector<TypedVar *> &results() const;
Iliyan Malchev639bff82016-08-13 14:24:11 -070043 bool isOneway() const { return mOneway; }
Steven Morelandd537ab02016-09-12 10:32:01 -070044 const std::vector<Annotation *> &annotations() const;
Andreas Huber881227d2016-08-02 14:20:21 -070045
Steven Morelanda7a421a2016-09-07 08:35:18 -070046 void generateCppSignature(Formatter &out,
Steven Moreland979e0992016-09-07 09:18:08 -070047 const std::string &className,
48 bool specifyNamespaces) const;
Steven Morelanda7a421a2016-09-07 08:35:18 -070049
Steven Moreland979e0992016-09-07 09:18:08 -070050 static std::string GetArgSignature(const std::vector<TypedVar *> &args,
51 bool specifyNamespaces);
Steven Morelanda7a421a2016-09-07 08:35:18 -070052 static std::string GetJavaArgSignature(const std::vector<TypedVar *> &args);
Andreas Huber881227d2016-08-02 14:20:21 -070053
Iliyan Malchev40d474a2016-08-16 06:20:17 -070054 const TypedVar* canElideCallback() const;
55
Andreas Huber3599d922016-08-09 10:42:57 -070056 void dumpAnnotations(Formatter &out) const;
57
Andreas Huber70a59e12016-08-16 12:57:01 -070058 bool isJavaCompatible() const;
59
Andreas Huberc9410c72016-07-28 12:18:40 -070060private:
61 std::string mName;
Andreas Huber881227d2016-08-02 14:20:21 -070062 std::vector<TypedVar *> *mArgs;
63 std::vector<TypedVar *> *mResults;
Iliyan Malchev639bff82016-08-13 14:24:11 -070064 bool mOneway;
Steven Morelandd537ab02016-09-12 10:32:01 -070065 std::vector<Annotation *> *mAnnotations;
Andreas Huberc9410c72016-07-28 12:18:40 -070066
67 DISALLOW_COPY_AND_ASSIGN(Method);
68};
69
Andreas Huber31629bc2016-08-03 09:06:40 -070070struct TypedVar {
71 TypedVar(const char *name, Type *type);
72
73 std::string name() const;
74 const Type &type() const;
75
Andreas Huber70a59e12016-08-16 12:57:01 -070076 bool isJavaCompatible() const;
77
Andreas Huber31629bc2016-08-03 09:06:40 -070078private:
79 std::string mName;
80 Type *mType;
81
82 DISALLOW_COPY_AND_ASSIGN(TypedVar);
83};
84
Andreas Huberc9410c72016-07-28 12:18:40 -070085} // namespace android
86
87#endif // METHOD_H_
88