1 /*
2  * Copyright (C) 2015, 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 <limits>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "aidl_language.h"
25 #include "import_resolver.h"
26 #include "io_delegate.h"
27 #include "options.h"
28 
29 namespace android {
30 namespace aidl {
31 
32 enum class AidlError {
33   UNKOWN = std::numeric_limits<int32_t>::min(),
34   BAD_PRE_PROCESSED_FILE,
35   PARSE_ERROR,
36   FOUND_PARCELABLE,
37   BAD_PACKAGE,
38   BAD_IMPORT,
39   BAD_TYPE,
40   BAD_METHOD_ID,
41   GENERATION_ERROR,
42   BAD_INPUT,
43   NOT_STRUCTURED,
44 
45   OK = 0,
46 };
47 
48 int compile_aidl(const Options& options, const IoDelegate& io_delegate);
49 bool preprocess_aidl(const Options& options, const IoDelegate& io_delegate);
50 bool dump_api(const Options& options, const IoDelegate& io_delegate);
51 bool dump_mappings(const Options& options, const IoDelegate& io_delegate);
52 
53 // main entry point to AIDL
54 int aidl_entry(const Options& options, const IoDelegate& io_delegate);
55 
56 const char kPreamble[] =
57     R"(///////////////////////////////////////////////////////////////////////////////
58 // THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
59 ///////////////////////////////////////////////////////////////////////////////
60 
61 // This file is a snapshot of an AIDL interface (or parcelable). Do not try to
62 // edit this file. It looks like you are doing that because you have modified
63 // an AIDL interface in a backward-incompatible way, e.g., deleting a function
64 // from an interface or a field from a parcelable and it broke the build. That
65 // breakage is intended.
66 //
67 // You must not make a backward incompatible changes to the AIDL files built
68 // with the aidl_interface module type with versions property set. The module
69 // type is used to build AIDL files in a way that they can be used across
70 // independently updatable components of the system. If a device is shipped
71 // with such a backward incompatible change, it has a high risk of breaking
72 // later when a module using the interface is updated, e.g., Mainline modules.
73 
74 )";
75 
76 const string kGetInterfaceVersion("getInterfaceVersion");
77 const string kGetInterfaceHash("getInterfaceHash");
78 
79 namespace internals {
80 
81 AidlError load_and_validate_aidl(const std::string& input_file_name, const Options& options,
82                                  const IoDelegate& io_delegate, AidlTypenames* typenames,
83                                  vector<string>* imported_files);
84 
85 bool parse_preprocessed_file(const IoDelegate& io_delegate, const std::string& filename,
86                              AidlTypenames* typenames);
87 
88 } // namespace internals
89 
90 }  // namespace aidl
91 }  // namespace android
92