Muhammad Qureshi | 9effe48 | 2019-10-29 15:36:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019, 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 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include "Collation.h" |
| 20 | |
| 21 | #include <map> |
| 22 | #include <set> |
| 23 | #include <vector> |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | namespace android { |
| 29 | namespace stats_log_api_gen { |
| 30 | |
| 31 | using namespace std; |
| 32 | |
| 33 | const string DEFAULT_MODULE_NAME = "DEFAULT"; |
| 34 | const string DEFAULT_CPP_NAMESPACE = "android,util"; |
| 35 | const string DEFAULT_CPP_HEADER_IMPORT = "statslog.h"; |
Muhammad Qureshi | c8e2266 | 2019-11-20 17:18:03 -0800 | [diff] [blame] | 36 | const string DEFAULT_ATOMS_INFO_CPP_HEADER_IMPORT = "atoms_info.h"; |
Muhammad Qureshi | 9effe48 | 2019-10-29 15:36:44 -0700 | [diff] [blame] | 37 | const string DEFAULT_JAVA_PACKAGE = "android.util"; |
| 38 | const string DEFAULT_JAVA_CLASS = "StatsLogInternal"; |
| 39 | |
| 40 | const int JAVA_MODULE_REQUIRES_FLOAT = 0x01; |
| 41 | const int JAVA_MODULE_REQUIRES_ATTRIBUTION = 0x02; |
Muhammad Qureshi | b6b3995 | 2020-01-14 14:42:13 -0800 | [diff] [blame] | 42 | const int JAVA_MODULE_REQUIRES_KEY_VALUE_PAIRS = 0x04; |
Muhammad Qureshi | 9effe48 | 2019-10-29 15:36:44 -0700 | [diff] [blame] | 43 | |
| 44 | string make_constant_name(const string& str); |
| 45 | |
| 46 | const char* cpp_type_name(java_type_t type); |
| 47 | |
| 48 | const char* java_type_name(java_type_t type); |
| 49 | |
| 50 | bool atom_needed_for_module(const AtomDecl& atomDecl, const string& moduleName); |
| 51 | |
| 52 | bool signature_needed_for_module(const set<string>& modules, const string& moduleName); |
| 53 | |
Muhammad Qureshi | c8e2266 | 2019-11-20 17:18:03 -0800 | [diff] [blame] | 54 | // Common Native helpers |
| 55 | void write_namespace(FILE* out, const string& cppNamespaces); |
| 56 | |
| 57 | void write_closing_namespace(FILE* out, const string& cppNamespaces); |
| 58 | |
| 59 | void write_native_atom_constants(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl, |
Muhammad Qureshi | 4fdc7fd | 2019-11-24 22:14:38 -0800 | [diff] [blame] | 60 | const string& moduleName); |
| 61 | |
| 62 | void write_native_method_signature(FILE* out, const string& methodName, |
| 63 | const vector<java_type_t>& signature, const AtomDecl& attributionDecl, |
| 64 | const string& closer); |
| 65 | |
| 66 | void write_native_method_call(FILE* out, const string& methodName, |
| 67 | const vector<java_type_t>& signature, const AtomDecl& attributionDecl, int argIndex = 1); |
Muhammad Qureshi | 9effe48 | 2019-10-29 15:36:44 -0700 | [diff] [blame] | 68 | |
| 69 | // Common Java helpers. |
| 70 | void write_java_atom_codes(FILE* out, const Atoms& atoms, const string& moduleName); |
| 71 | |
| 72 | void write_java_enum_values(FILE* out, const Atoms& atoms, const string& moduleName); |
| 73 | |
| 74 | void write_java_usage(FILE* out, const string& method_name, const string& atom_code_name, |
| 75 | const AtomDecl& atom); |
| 76 | |
| 77 | int write_java_non_chained_methods(FILE* out, const map<vector<java_type_t>, |
| 78 | set<string>>& signatures_to_modules, |
Muhammad Qureshi | 4fdc7fd | 2019-11-24 22:14:38 -0800 | [diff] [blame] | 79 | const string& moduleName); |
Muhammad Qureshi | 9effe48 | 2019-10-29 15:36:44 -0700 | [diff] [blame] | 80 | |
| 81 | int write_java_work_source_methods( |
| 82 | FILE* out, |
| 83 | const map<vector<java_type_t>, set<string>>& signatures_to_modules, |
Muhammad Qureshi | 4fdc7fd | 2019-11-24 22:14:38 -0800 | [diff] [blame] | 84 | const string& moduleName); |
Muhammad Qureshi | 9effe48 | 2019-10-29 15:36:44 -0700 | [diff] [blame] | 85 | |
| 86 | } // namespace stats_log_api_gen |
| 87 | } // namespace android |