Browse Source

Added reserved keywords checking helpers in `CCodeGenerator`.

pull/1174/head
Joao Matos 7 years ago committed by João Matos
parent
commit
1ef9bee970
  1. 6
      src/CppParser/Sources.h
  2. 33
      src/Generator/Generators/C/CCodeGenerator.cs

6
src/CppParser/Sources.h

@ -18,4 +18,10 @@ struct CS_API CS_VALUE_TYPE SourceLocation
unsigned ID; unsigned ID;
}; };
struct CS_API SourceRange
{
SourceLocation beginLoc;
SourceLocation endLoc;
};
} } } }

33
src/Generator/Generators/C/CCodeGenerator.cs

@ -244,5 +244,38 @@ namespace CppSharp.Generators.C
{ {
return true; return true;
} }
static readonly List<string> CReservedKeywords = new List<string> {
// C99 6.4.1: Keywords.
"auto", "break", "case", "char", "const", "continue", "default",
"do", "double", "else", "enum", "extern", "float", "for", "goto",
"if", "inline", "int", "long", "register", "restrict", "return",
"short", "signed", "sizeof", "static", "struct", "switch",
"typedef", "union", "unsigned", "void", "volatile", "while",
"_Alignas", "_Alignof", "_Atomic", "_Bool", "_Complex",
"_Generic", "_Imaginary", "_Noreturn", "_Static_assert",
"_Thread_local", "__func__", "__objc_yes", "__objc_no",
};
public bool IsReservedKeywordC(string id) => CReservedKeywords.Contains(id);
static readonly List<string> CppReservedKeywords = new List<string> {
// C++ 2.11p1: Keywords.
"asm", "bool", "catch", "class", "const_cast", "delete",
"dynamic_cast", "explicit", "export", "false", "friend",
"mutable", "namespace", "new", "operator", "private",
"protected", "public", "reinterpret_cast", "static_cast",
"template", "this", "throw", "true", "try", "typename",
"typeid", "using", "virtual", "wchar_t",
// C++11 Keywords
"alignas", "alignof", "char16_t", "char32_t", "constexpr",
"decltype", "noexcept", "nullptr", "static_assert",
"thread_local"
};
public bool IsReservedKeywordCpp(string id) => CppReservedKeywords.Contains(id);
public bool IsReservedKeyword(string id) => IsReservedKeywordC(id) || IsReservedKeywordCpp(id);
} }
} }

Loading…
Cancel
Save