f62c0763bac039f16847bd36479909cfb4dd1338
[iec.git] / src / type3_AndroidCloud / anbox-master / external / android-emugl / host / tools / emugen / Parser.h
1 /*
2 * Copyright 2014 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 #ifndef PARSER_H
17 #define PARSER_H
18
19 #include <string>
20
21 // Normalize a type declaration. This gets rid of leading/trailing whitespace
22 // as well as ensure there is a single space separating all input tokens,
23 // with the exception of '*' which is treated specially by never being
24 // prepended with a space.
25 // |input| is the input type declaration. Return normalized form.
26 // Note that this doesn't try to validate the input.
27 std::string normalizeTypeDeclaration(const std::string& input);
28
29 // Parse a return type declaration. |input| is the type declaration
30 // (e.g. 'const char**'). On success return true and sets |*typeName| to
31 // the appropriate normalized type string. On failure, return false and
32 // sets |*error| with a human-friendly message explaining the reason for
33 // failure.
34 //
35 // Note that the returned type string is normalized, see comment for
36 // parseParameterDeclaration() for examples.
37 //
38 // NOTE: This does not support declarations of arrays or functions!
39 //
40 bool parseTypeDeclaration(const std::string& input,
41                           std::string* typeName,
42                           std::string* error);
43
44 // Parse a function parameter declaration and extract the type and variable
45 // name from it. |param| is the individual parameter declaration from the
46 // function's signature (e.g. 'const char *items')
47 //
48 // On success, returns true and sets |*vartype| and |*varname| to the
49 // appropriate type name and variable name. |varname| can be NULL if the caller
50 // isn't interested in the variable name.
51 //
52 // On failure, return false and sets |*error| to a human-friendly message
53 // explaining the reason for failure.
54 //
55 // Note that the returned type name is normalized with regards to whitespace
56 // and star location, e.g.:
57 //
58 //      const void *items           -> 'const void*'
59 //      char* *items                -> 'char**'
60 //      const void * const * items  -> 'const void* const*'
61 //      unsigned int *const data    -> 'unsigned int* const'
62 //
63 bool parseParameterDeclaration(const std::string& param,
64                                std::string* typeName,
65                                std::string* variableName,
66                                std::string* error);
67
68 #endif  // PARSER_H