diff --git a/src/CppParser/Sources.h b/src/CppParser/Sources.h index cd9c168f..e3a127e4 100644 --- a/src/CppParser/Sources.h +++ b/src/CppParser/Sources.h @@ -18,4 +18,10 @@ struct CS_API CS_VALUE_TYPE SourceLocation unsigned ID; }; +struct CS_API SourceRange +{ + SourceLocation beginLoc; + SourceLocation endLoc; +}; + } } diff --git a/src/Generator/Generators/C/CCodeGenerator.cs b/src/Generator/Generators/C/CCodeGenerator.cs index 542a4363..93ba2666 100644 --- a/src/Generator/Generators/C/CCodeGenerator.cs +++ b/src/Generator/Generators/C/CCodeGenerator.cs @@ -244,5 +244,38 @@ namespace CppSharp.Generators.C { return true; } + + static readonly List CReservedKeywords = new List { + // 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 CppReservedKeywords = new List { + // 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); } }