blob: 9f60c53d84358d6b6dd8e93d1a3d2a677cb509a0 [file] [log] [blame]
/*
* Copyright (C) 2015, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "parse_helpers.h"
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdlib.h>
#include <string>
#include <vector>
#include "aidl_language.h"
namespace android {
namespace aidl {
bool is_java_keyword(const char* str) {
static const std::vector<std::string> kJavaKeywords{
"abstract", "assert", "boolean", "break", "byte",
"case", "catch", "char", "class", "const",
"continue", "default", "do", "double", "else",
"enum", "extends", "final", "finally", "float",
"for", "goto", "if", "implements", "import",
"instanceof", "int", "interface", "long", "native",
"new", "package", "private", "protected", "public",
"return", "short", "static", "strictfp", "super",
"switch", "synchronized", "this", "throw", "throws",
"transient", "try", "void", "volatile", "while",
"true", "false", "null",
};
return std::find(kJavaKeywords.begin(), kJavaKeywords.end(), str) !=
kJavaKeywords.end();
}
char* cpp_strdup(const char* in)
{
char *out = new char[std::strlen(in) + 1];
strcpy(out, in);
return out;
}
std::string gather_comments(extra_text_type* extra) {
std::string s;
for (; extra; extra = extra->next) {
if (extra->which == SHORT_COMMENT) {
s += extra->data;
}
else if (extra->which == LONG_COMMENT) {
s += "/*";
s += extra->data;
s += "*/";
}
}
return s;
}
} // namespace android
} // namespace aidl