blob: 3c8491497700371efe472f644a4539cb8ef98613 [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 Morelandef1a9fe2016-10-06 17:19:09 -070046 void setSerialId(size_t serial);
47 size_t getSerialId() const;
48
Steven Morelanda7a421a2016-09-07 08:35:18 -070049 void generateCppSignature(Formatter &out,
Steven Moreland979e0992016-09-07 09:18:08 -070050 const std::string &className,
51 bool specifyNamespaces) const;
Steven Morelanda7a421a2016-09-07 08:35:18 -070052
Steven Moreland979e0992016-09-07 09:18:08 -070053 static std::string GetArgSignature(const std::vector<TypedVar *> &args,
54 bool specifyNamespaces);
Steven Morelanda7a421a2016-09-07 08:35:18 -070055 static std::string GetJavaArgSignature(const std::vector<TypedVar *> &args);
Andreas Huber881227d2016-08-02 14:20:21 -070056
Iliyan Malchev40d474a2016-08-16 06:20:17 -070057 const TypedVar* canElideCallback() const;
58
Andreas Huber3599d922016-08-09 10:42:57 -070059 void dumpAnnotations(Formatter &out) const;
60
Andreas Huber70a59e12016-08-16 12:57:01 -070061 bool isJavaCompatible() const;
62
Andreas Huberc9410c72016-07-28 12:18:40 -070063private:
64 std::string mName;
Steven Morelandef1a9fe2016-10-06 17:19:09 -070065 size_t mSerial = 0;
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;
Steven Morelandd537ab02016-09-12 10:32:01 -070069 std::vector<Annotation *> *mAnnotations;
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