| Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 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 | #include "parse_helpers.h" |
| 18 | |
| 19 | #include <algorithm> |
| 20 | #include <cctype> |
| 21 | #include <cstring> |
| 22 | #include <stdlib.h> |
| 23 | #include <string> |
| 24 | #include <vector> |
| 25 | |
| 26 | #include "aidl_language.h" |
| 27 | |
| 28 | namespace android { |
| 29 | namespace aidl { |
| 30 | |
| 31 | char* parse_import_statement(const char* text) { |
| 32 | const char* end; |
| 33 | int len; |
| 34 | |
| 35 | while (isspace(*text)) { |
| 36 | text++; |
| 37 | } |
| 38 | while (!isspace(*text)) { |
| 39 | text++; |
| 40 | } |
| 41 | while (isspace(*text)) { |
| 42 | text++; |
| 43 | } |
| 44 | end = text; |
| 45 | while (!isspace(*end) && *end != ';') { |
| 46 | end++; |
| 47 | } |
| 48 | len = end - text; |
| 49 | |
| Christopher Wiley | b211686 | 2015-09-29 16:08:57 +0000 | [diff] [blame] | 50 | char* rv = (char*)malloc(len + 1); |
| Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 51 | memcpy(rv, text, len); |
| 52 | rv[len] = '\0'; |
| 53 | |
| 54 | return rv; |
| 55 | } |
| 56 | |
| 57 | int convert_direction(const char* direction) { |
| 58 | if (direction == NULL) { |
| 59 | return IN_PARAMETER; |
| 60 | } |
| 61 | if (0 == strcmp(direction, "in")) { |
| 62 | return IN_PARAMETER; |
| 63 | } |
| 64 | if (0 == strcmp(direction, "out")) { |
| 65 | return OUT_PARAMETER; |
| 66 | } |
| 67 | return INOUT_PARAMETER; |
| 68 | } |
| 69 | |
| 70 | bool is_java_keyword(const char* str) { |
| 71 | static const std::vector<std::string> kJavaKeywords{ |
| 72 | "abstract", "assert", "boolean", "break", "byte", |
| 73 | "case", "catch", "char", "class", "const", |
| 74 | "continue", "default", "do", "double", "else", |
| 75 | "enum", "extends", "final", "finally", "float", |
| 76 | "for", "goto", "if", "implements", "import", |
| 77 | "instanceof", "int", "interface", "long", "native", |
| 78 | "new", "package", "private", "protected", "public", |
| 79 | "return", "short", "static", "strictfp", "super", |
| 80 | "switch", "synchronized", "this", "throw", "throws", |
| 81 | "transient", "try", "void", "volatile", "while", |
| 82 | "true", "false", "null", |
| 83 | }; |
| 84 | return std::find(kJavaKeywords.begin(), kJavaKeywords.end(), str) != |
| 85 | kJavaKeywords.end(); |
| 86 | } |
| 87 | |
| 88 | } // namespace android |
| 89 | } // namespace aidl |