基于clang的中文编译前端,中文C++兼容语言 命名为《习大大》
Clone or download
#1 Compare This branch is 5 commits ahead, 4858 commits behind llvm-mirror:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
INPUTS
bindings
cmake
docs
examples
include
lib
runtime
test
tools
unittests
utils
www
.arcconfig
.clang-format
.clang-tidy
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
INSTALL.txt
LICENSE.TXT
ModuleInfo.txt
NOTES.txt
README.txt

README.txt

//===----------------------------------------------------------------------===//
// 基于clang的中文编译前端
//===----------------------------------------------------------------------===//

在 /include/clang/Basic/TokenKinds.def 中添加中文关键字

KEYWORD(auto                        , KEYALL)
ALIAS("自动", auto            , KEYALL)
KEYWORD(break                       , KEYALL)
ALIAS("破", break            , KEYALL)
KEYWORD(case                        , KEYALL)
ALIAS("例", case            , KEYALL)
KEYWORD(char                        , KEYALL)
ALIAS("字", char            , KEYALL)
KEYWORD(const                       , KEYALL)
ALIAS("常量", const            , KEYALL)
KEYWORD(continue                    , KEYALL)
ALIAS("续", continue            , KEYALL)
KEYWORD(default                     , KEYALL)
ALIAS("缺省", default            , KEYALL)
KEYWORD(do                          , KEYALL)
ALIAS("运行", do            , KEYALL)
KEYWORD(double                      , KEYALL)
ALIAS("双", double            , KEYALL)
KEYWORD(else                        , KEYALL)
ALIAS("另", else            , KEYALL)
KEYWORD(enum                        , KEYALL)
ALIAS("枚举", enum            , KEYALL)
KEYWORD(extern                      , KEYALL)
ALIAS("外部", extern            , KEYALL)
KEYWORD(float                       , KEYALL)
ALIAS("单", float            , KEYALL)
KEYWORD(for                         , KEYALL)
ALIAS("于", for            , KEYALL)
KEYWORD(goto                        , KEYALL)
ALIAS("跳到", goto            , KEYALL)
KEYWORD(if                          , KEYALL)
ALIAS("如", if            , KEYALL)
KEYWORD(inline                      , KEYC99|KEYCXX|KEYGNU)
ALIAS("内联", inline            , KEYC99|KEYCXX|KEYGNU)
KEYWORD(int                         , KEYALL)
ALIAS("整", int            , KEYALL)
KEYWORD(long                        , KEYALL)
ALIAS("长", long            , KEYALL)
KEYWORD(register                    , KEYALL)
ALIAS("注册", register            , KEYALL)
KEYWORD(restrict                    , KEYC99)
ALIAS("限制", restrict            , KEYC99)
KEYWORD(return                      , KEYALL)
ALIAS("回", return            , KEYALL)
KEYWORD(short                       , KEYALL)
ALIAS("短", short            , KEYALL)
KEYWORD(signed                      , KEYALL)
ALIAS("有符号", signed            , KEYALL)
KEYWORD(sizeof                      , KEYALL)
ALIAS("求长", sizeof            , KEYALL)
KEYWORD(static                      , KEYALL)
ALIAS("静态", static            , KEYALL)
KEYWORD(struct                      , KEYALL)
ALIAS("结构", struct            , KEYALL)
KEYWORD(switch                      , KEYALL)
ALIAS("转", switch            , KEYALL)
KEYWORD(typedef                     , KEYALL)
ALIAS("类型定义", typedef            , KEYALL)
KEYWORD(union                       , KEYALL)
ALIAS("联合", union            , KEYALL)
KEYWORD(unsigned                    , KEYALL)
ALIAS("无符号", unsigned            , KEYALL)
KEYWORD(void                        , KEYALL)
ALIAS("空", void            , KEYALL)
KEYWORD(volatile                    , KEYALL)
ALIAS("易变", volatile            , KEYALL)
KEYWORD(while                       , KEYALL)
ALIAS("当", while            , KEYALL)

// C++ 2.11p1: Keywords.
KEYWORD(asm                         , KEYCXX|KEYGNU)
ALIAS("汇编", asm            , KEYCXX|KEYGNU)
KEYWORD(bool                        , BOOLSUPPORT)
ALIAS("布尔", bool            , BOOLSUPPORT)
KEYWORD(catch                       , KEYCXX)
ALIAS("抓", catch            , KEYCXX)
KEYWORD(class                       , KEYCXX)
ALIAS("类", class            , KEYCXX)
KEYWORD(const_cast                  , KEYCXX)
ALIAS("常量转换", const_cast            , KEYCXX)
KEYWORD(delete                      , KEYCXX)
ALIAS("删", delete            , KEYCXX)
KEYWORD(dynamic_cast                , KEYCXX)
ALIAS("动态转换", dynamic_cast            , KEYCXX)
KEYWORD(explicit                    , KEYCXX)
ALIAS("明确", explicit            , KEYCXX)
KEYWORD(export                      , KEYCXX)
ALIAS("输出", export            , KEYCXX)
KEYWORD(false                       , BOOLSUPPORT)
ALIAS("假", false            , BOOLSUPPORT)
KEYWORD(friend                      , KEYCXX)
ALIAS("友", friend            , KEYCXX)
KEYWORD(mutable                     , KEYCXX)
ALIAS("可变", friend            , KEYCXX)
KEYWORD(namespace                   , KEYCXX)
ALIAS("名宇", namespace            , KEYCXX)
KEYWORD(new                         , KEYCXX)
ALIAS("新", new            , KEYCXX)
KEYWORD(operator                    , KEYCXX)
ALIAS("操作符", operator            , KEYCXX)
KEYWORD(private                     , KEYCXX)
ALIAS("私", public            , KEYCXX)
KEYWORD(protected                   , KEYCXX)
ALIAS("保", public            , KEYCXX)
KEYWORD(public                      , KEYCXX)
ALIAS("公", public            , KEYCXX)
KEYWORD(reinterpret_cast            , KEYCXX)
ALIAS("重释转换", reinterpret_cast            , KEYCXX)
KEYWORD(static_cast                 , KEYCXX)
ALIAS("静态转换", static_cast            , KEYCXX)
KEYWORD(template                    , KEYCXX)
ALIAS("模板", template            , KEYCXX)
KEYWORD(this                        , KEYCXX)
ALIAS("此", this            , KEYCXX)
KEYWORD(throw                       , KEYCXX)
ALIAS("抛", throw            , KEYCXX)
KEYWORD(true                        , BOOLSUPPORT)
ALIAS("真", true            , BOOLSUPPORT)
KEYWORD(try                         , KEYCXX)
ALIAS("试", try            , KEYCXX)
KEYWORD(typename                    , KEYCXX)
ALIAS("类型名", typename            , KEYCXX)
KEYWORD(typeid                      , KEYCXX)
ALIAS("类型号", typeid            , KEYCXX)
KEYWORD(using                       , KEYCXX)
ALIAS("使用", using            , KEYCXX)
KEYWORD(virtual                     , KEYCXX)
ALIAS("虚", virtual            , KEYCXX)
KEYWORD(wchar_t                     , WCHARSUPPORT)
ALIAS("宽字", wchar_t            , WCHARSUPPORT)

// C++11 keywords
CXX11_KEYWORD(alignas               , 0)
ALIAS("对齐按", alignas            , KEYCXX11)
CXX11_KEYWORD(alignof               , 0)
ALIAS("求对齐", alignof            , KEYCXX11)
CXX11_KEYWORD(char16_t              , KEYNOMS18)
ALIAS("字16", char16_t            , KEYCXX11|KEYNOMS18)
CXX11_KEYWORD(char32_t              , KEYNOMS18)
ALIAS("字32", char32_t            , KEYCXX11|KEYNOMS18)
CXX11_KEYWORD(constexpr             , 0)
ALIAS("常量表达式", constexpr            , KEYCXX11)
CXX11_KEYWORD(decltype              , 0)
ALIAS("推导类型", decltype            , KEYCXX11)
CXX11_KEYWORD(noexcept              , 0)
ALIAS("无异常", noexcept            , KEYCXX11)
CXX11_KEYWORD(nullptr               , 0)
ALIAS("空针", nullptr            , KEYCXX11)
CXX11_KEYWORD(static_assert         , 0)
ALIAS("静态断言", static_assert            , KEYCXX11)
CXX11_KEYWORD(thread_local          , 0)
ALIAS("线程局部", static_assert            , KEYCXX11)


在 /lib/Basic/IdentifierTable.cpp 中添加 中文宏

  //default: return tok::pp_not_keyword;
  default: return llvm::StringSwitch<tok::PPKeywordKind>(Name)
    .Case("如", tok::pp_if)
    .Case("另如", tok::pp_elif)
    .Case("另", tok::pp_else)
    .Case("行", tok::pp_line)
    .Case("了如", tok::pp_endif)
    .Case("错误", tok::pp_error)
    .Case("如定义", tok::pp_ifdef)
    .Case("消定义", tok::pp_undef)
    .Case("断言", tok::pp_assert)
    .Case("定义", tok::pp_define)
    .Case("如未定义", tok::pp_ifndef)
    .Case("输入", tok::pp_import)
    .Case("杂注", tok::pp_pragma)
    .Case("已定义", tok::pp_defined)
    .Case("含", tok::pp_include)
    .Case("告警", tok::pp_warning)
    .Case("消断言", tok::pp_unassert)
    .Case("含下个", tok::pp_include_next)
    .Default(tok::pp_not_keyword);