| 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 | |
| Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 31 | bool is_java_keyword(const char* str) { |
| 32 | static const std::vector<std::string> kJavaKeywords{ |
| 33 | "abstract", "assert", "boolean", "break", "byte", |
| 34 | "case", "catch", "char", "class", "const", |
| 35 | "continue", "default", "do", "double", "else", |
| 36 | "enum", "extends", "final", "finally", "float", |
| 37 | "for", "goto", "if", "implements", "import", |
| 38 | "instanceof", "int", "interface", "long", "native", |
| 39 | "new", "package", "private", "protected", "public", |
| 40 | "return", "short", "static", "strictfp", "super", |
| 41 | "switch", "synchronized", "this", "throw", "throws", |
| 42 | "transient", "try", "void", "volatile", "while", |
| 43 | "true", "false", "null", |
| 44 | }; |
| 45 | return std::find(kJavaKeywords.begin(), kJavaKeywords.end(), str) != |
| 46 | kJavaKeywords.end(); |
| 47 | } |
| 48 | |
| Casey Dahlin | 030977a | 2015-09-29 11:29:35 -0700 | [diff] [blame] | 49 | char* cpp_strdup(const char* in) |
| 50 | { |
| 51 | char *out = new char[std::strlen(in) + 1]; |
| 52 | strcpy(out, in); |
| 53 | return out; |
| 54 | } |
| 55 | |
| Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 56 | std::string gather_comments(extra_text_type* extra) { |
| 57 | std::string s; |
| 58 | for (; extra; extra = extra->next) { |
| 59 | if (extra->which == SHORT_COMMENT) { |
| 60 | s += extra->data; |
| 61 | } |
| 62 | else if (extra->which == LONG_COMMENT) { |
| 63 | s += "/*"; |
| 64 | s += extra->data; |
| 65 | s += "*/"; |
| 66 | } |
| 67 | } |
| 68 | return s; |
| 69 | } |
| 70 | |
| Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 71 | } // namespace android |
| 72 | } // namespace aidl |