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"; 36 const string DEFAULT_ATOMS_INFO_CPP_HEADER_IMPORT = "atoms_info.h"; 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; 42 43 string make_constant_name(const string& str); 44 45 const char* cpp_type_name(java_type_t type); 46 47 const char* java_type_name(java_type_t type); 48 49 bool atom_needed_for_module(const AtomDecl& atomDecl, const string& moduleName); 50 51 bool signature_needed_for_module(const set<string>& modules, const string& moduleName); 52 53 // Common Native helpers 54 void write_namespace(FILE* out, const string& cppNamespaces); 55 56 void write_closing_namespace(FILE* out, const string& cppNamespaces); 57 58 void write_native_atom_constants(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl, 59 const string& moduleName); 60 61 void write_native_method_signature(FILE* out, const string& methodName, 62 const vector<java_type_t>& signature, const AtomDecl& attributionDecl, 63 const string& closer); 64 65 void write_native_method_call(FILE* out, const string& methodName, 66 const vector<java_type_t>& signature, const AtomDecl& attributionDecl, int argIndex = 1); 67 68 // Common Java helpers. 69 void write_java_atom_codes(FILE* out, const Atoms& atoms, const string& moduleName); 70 71 void write_java_enum_values(FILE* out, const Atoms& atoms, const string& moduleName); 72 73 void write_java_usage(FILE* out, const string& method_name, const string& atom_code_name, 74 const AtomDecl& atom); 75 76 int write_java_non_chained_methods(FILE* out, const map<vector<java_type_t>, 77 set<string>>& signatures_to_modules, 78 const string& moduleName); 79 80 int write_java_work_source_methods( 81 FILE* out, 82 const map<vector<java_type_t>, set<string>>& signatures_to_modules, 83 const string& moduleName); 84 85 } // namespace stats_log_api_gen 86 } // namespace android 87