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_mappings(const Options& options, const IoDelegate& io_delegate);
51 
52 // main entry point to AIDL
53 int aidl_entry(const Options& options, const IoDelegate& io_delegate);
54 
55 const char kPreamble[] =
56     R"(///////////////////////////////////////////////////////////////////////////////
57 // THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
58 ///////////////////////////////////////////////////////////////////////////////
59 
60 // This file is a snapshot of an AIDL file. Do not edit it manually. There are
61 // two cases:
62 // 1). this is a frozen version file - do not edit this in any case.
63 // 2). this is a 'current' file. If you make a backwards compatible change to
64 //     the interface (from the latest frozen version), the build system will
65 //     prompt you to update this file with `m <name>-update-api`.
66 //
67 // You must not make a backward incompatible change to any AIDL file 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