📈
objective-c
  • 前言
  • 编译原理
    • 编译LLVM
    • 我的第一个Clang插件
    • 自定义LibTooling
    • 自定义属性
    • AST
    • Swift
  • Foundation
    • Number
    • NSString
    • Class
    • Category
    • 琐事
    • 多线程
    • ARC
    • RunLoop
    • 算法
  • Network
  • Animation
  • JavaScriptCore
  • 架构设计
  • 跨平台
    • Flutter
  • UIKit
    • UIView
    • AutoLayout
    • WebView
  • ApplePay
  • In-App Purchase
  • Reveal
  • Xcode
Powered by GitBook
On this page
  • 属性的结构
  • 属性的添加步骤
  • clang常用命令

Was this helpful?

  1. 编译原理

自定义属性

Previous自定义LibToolingNextAST

Last updated 5 years ago

Was this helpful?

属性的结构

属性定义在llvm源码:include/clang/Basic/Attr.td

示例

def Aligned : InheritableAttr {
  let Spellings = [GCC<"aligned">, Declspec<"align">, Keyword<"alignas">,
                   Keyword<"_Alignas">];
  let Args = [AlignedArgument<"Alignment", 1>];
  let Accessors = [Accessor<"isGNU", [GCC<"aligned">]>,
                   Accessor<"isC11", [Keyword<"_Alignas">]>,
                   Accessor<"isAlignas", [Keyword<"alignas">,
                                          Keyword<"_Alignas">]>,
                   Accessor<"isDeclspec",[Declspec<"align">]>];
  let Documentation = [Undocumented];
}

属性的添加步骤

  1. 在include/clang/Basic/Attr.td中添加属性的定义

  2. 在include/clang/Basic/AttrDocs.td中添加文档定义

  3. 在lib/Sema/SemaDeclAttr.cpp中添加语义操作

clang常用命令

展示抽象语法树

clang -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk -fmodules -fsyntax-only -Xclang -ast-dump TestClass.m

结果示例

|-ImportDecl 0x7f8b801f6000 <./TestClass.h:9:1> col:1 implicit Foundation
|-ObjCInterfaceDecl 0x7f8b801f6d30 <line:16:1, line:18:2> line:16:12 TestClass
| |-super ObjCInterface 0x7f8b801f61e8 'NSObject'
| |-ObjCImplementation 0x7f8b801f6ed0 'TestClass'
| `-ObjCRuntimeNameAttr 0x7f8b801f6e00 <line:15:16, col:68> "86d3cd67eed8590114cbfc3c8ab1d374"
|-ObjCImplementationDecl 0x7f8b801f6ed0 <TestClass.m:11:1, line:14:1> line:11:17 TestClass
| `-ObjCInterface 0x7f8b801f6d30 'TestClass'
`-<undeserialized declarations>
1 warning generated.
官方文档