深入研究Clang(六) Clang Lexer代码阅读笔记之Preprocesser
来源:互联网 发布:屏幕检测软件 编辑:程序博客网 时间:2024/05/16 12:45
作者:史宁宁(snsn1984)
clang/include/clang/Lex/Preprocesser.h
这个文件是包含clang::Preprocesser类的定义的头文件。它是类C语言(C、C++、Object C)的预处理的头文件。也就是说,类C语言的预处理都会用到此处的代码。
00082 /// \brief Context in which macro name is used.00083 enum MacroUse {00084 MU_Other = 0, // other than #define or #undef00085 MU_Define = 1, // macro name specified in #define00086 MU_Undef = 2 // macro name specified in #undef00087 };这个枚举很简单,就是通过枚举值来确定到底使用了哪些宏。除了define和undef之外,其他的都分类到MU_Other类别下边了。
00089 /// \brief Engages in a tight little dance with the lexer to efficiently00090 /// preprocess tokens.00091 ///00092 /// Lexers know only about tokens within a single source file, and don't00093 /// know anything about preprocessor-level issues like the \#include stack,00094 /// token expansion, etc.00095 class Preprocessor : public RefCountedBase<Preprocessor> {00096 IntrusiveRefCntPtr<PreprocessorOptions> PPOpts;00097 DiagnosticsEngine *Diags;00098 LangOptions &LangOpts;00099 const TargetInfo *Target;00100 FileManager &FileMgr;00101 SourceManager &SourceMgr;00102 std::unique_ptr<ScratchBuffer> ScratchBuf;00103 HeaderSearch &HeaderInfo;00104 ModuleLoader &TheModuleLoader;这里可以看到Preprocessor的类的定义,而它是模板类RefCountedBase<Preprocessor>的子类。同时可以看看这几个类的几个成员变量,DiagnosticsEngine-诊断引擎,LangOptions-接收的编译选项,TargetInfo-存储目标信息,FileManager-文件管理器,SourceManager-源码管理器,ModuleLoader-module加载器。
00118 /// Identifiers for builtin macros and other builtins.00119 IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__00120 IdentifierInfo *Ident__DATE__, *Ident__TIME__; // __DATE__, __TIME__00121 IdentifierInfo *Ident__INCLUDE_LEVEL__; // __INCLUDE_LEVEL__00122 IdentifierInfo *Ident__BASE_FILE__; // __BASE_FILE__00123 IdentifierInfo *Ident__TIMESTAMP__; // __TIMESTAMP__00124 IdentifierInfo *Ident__COUNTER__; // __COUNTER__00125 IdentifierInfo *Ident_Pragma, *Ident__pragma; // _Pragma, __pragma00126 IdentifierInfo *Ident__identifier; // __identifier00127 IdentifierInfo *Ident__VA_ARGS__; // __VA_ARGS__00128 IdentifierInfo *Ident__has_feature; // __has_feature00129 IdentifierInfo *Ident__has_extension; // __has_extension00130 IdentifierInfo *Ident__has_builtin; // __has_builtin00131 IdentifierInfo *Ident__has_attribute; // __has_attribute00132 IdentifierInfo *Ident__has_include; // __has_include00133 IdentifierInfo *Ident__has_include_next; // __has_include_next00134 IdentifierInfo *Ident__has_warning; // __has_warning00135 IdentifierInfo *Ident__is_identifier; // __is_identifier00136 IdentifierInfo *Ident__building_module; // __building_module00137 IdentifierInfo *Ident__MODULE__; // __MODULE__00138 IdentifierInfo *Ident__has_cpp_attribute; // __has_cpp_attribute另外Preprocesser类中包含了使用IdentifierInfo指针所保存的内建宏以及其他的内建的标示符。所以如果要修改或者扩展内建宏或者其他内建标示符,这里也是必须要修改的地方。
00148 // State that is set before the preprocessor begins.00149 bool KeepComments : 1;00150 bool KeepMacroComments : 1;00151 bool SuppressIncludeNotFoundError : 1;00152 00153 // State that changes while the preprocessor runs:00154 bool InMacroArgs : 1; // True if parsing fn macro invocation args.00155 00156 /// Whether the preprocessor owns the header search object.00157 bool OwnsHeaderSearch : 1;00158 00159 /// True if macro expansion is disabled.00160 bool DisableMacroExpansion : 1;00161 00162 /// Temporarily disables DisableMacroExpansion (i.e. enables expansion)00163 /// when parsing preprocessor directives.00164 bool MacroExpansionInDirectivesOverride : 1;00165 00166 class ResetMacroExpansionHelper;00167 00168 /// \brief Whether we have already loaded macros from the external source.00169 mutable bool ReadMacrosFromExternalSource : 1;00170 00171 /// \brief True if pragmas are enabled.00172 bool PragmasEnabled : 1;00173 00174 /// \brief True if the current build action is a preprocessing action.00175 bool PreprocessedOutput : 1;另外在Preprocesser类中,还出现了一部分这样的代码,这种给成员变量制定位域的形式还是第一次见到,一度让我以为是要给成员变量赋值。这种使用位域节省空间的方式,在结构体中比在类中稍微常见点,为了节省空间,在这么大的类中使用还是第一次见。:后面的数字是为了指定一定的bit位去保存变量的值。其中,这里里面还有一个更特殊的一行代码:
00168 /// \brief Whether we have already loaded macros from the external source.00169 mutable bool ReadMacrosFromExternalSource : 1;这个成员变量,不仅仅用到了位域,还用到了mutable。一般使用mutable修饰变量,是为了在const成员函数中可以修改这个成员变量。
2 0
- 深入研究Clang(六) Clang Lexer代码阅读笔记之Preprocesser
- 深入研究Clang(五) Clang Lexer代码阅读笔记之Lexer
- 深入研究Clang(七) Clang Lexer代码阅读笔记之Lexer
- 深入研究Clang(八) Clang代码阅读之打log读流程1
- 深入研究Clang(九) Clang代码阅读之打log读流程2
- 深入研究Clang(四) Clang编译器的简单分析
- 深入研究Clang(四) Clang编译器的简单分析
- 深入研究Clang(三) libclang
- 深入研究Clang(一)Clang和LLVM的关系及整体架构
- 深入研究Clang(二)Abstract Syntax Tree
- clang
- Clang
- clang
- clang
- clang
- Clang以及LLVM研究
- clang 分析OpenCL 代码
- clang++诡异之处(续)
- Linux下进程之间通过消息队列通信小程序示例
- 第十四周项目三多科成绩单(3)
- Oracle 内存管理
- ORACLE学习之旅——分组取每组数据中最近的一条记录
- 深入Cocos2d-x】使用MVC架构搭建游戏Four
- 深入研究Clang(六) Clang Lexer代码阅读笔记之Preprocesser
- Java初学习 - Java中的异常[Exception]public class NeverCaught { static void f() throws ExceptionB{
- 使用pt-heartbeat监控主从复制延迟
- 从一家电子商务网站学到的经验教训
- 爱立信与微软联合开发移动电话
- 润乾——润乾报表跨域问题解决方案
- 截成圆角矩阵图片
- Bug追踪的五个原则
- 第11周项目 7 泰勒??太乐