1. 程式人生 > >Creating and using Clang plugin with Xcode

Creating and using Clang plugin with Xcode

連結:https://railsware.com/blog/2014/02/28/creation-and-using-clang-plugin-with-xcode/

如何寫一個clang plugin,很不錯的文章,記錄一下。

This tutorial describes how to create Clang plugin and covers the next things:

  • environment setup
  • basic plugin setup
  • setup Xcode project for plugin development
  • warnings reporting
  • errors reporting
  • Xcode integration
  • interactive hints for errors/warnings riddance

tl;dr

Clang Rocks!!!

You can find the plugin here.

Intro

While working on BloodMagic, I realised that it’d be nice to have a tool for checking semantic errors related to BM usage. For example: in the interface property marked as lazy

, but not defined as @dynamic in the implementation, or property marked as lazy, but class container doesn’t support injections.

I concluded that I need to work with and I need a full-featured parser.

I’ve tried different approaches: flex+bisonlibclang, but ultimately I decided to write a Clang plugin.

Just for testing purposes I’ve started a simple plugin with the following goals:

  • use Xcode for development
  • integrate ready plugin into Xcode and use it workaday
  • plugin should report warnings, errors and propose interactive hints for fixes (via Xcode UI)

Features of the test plugin:

  • report warning in case of class’ name starts with lowercase letter
  • report error in case of class’ name contains underscore _
  • propose hints for fixes

Environment setup

For plugin development we need llvm/clang, built from source

12345cd/optsudo mkdirllvmsudo chown`whoami`llvmcdllvmexport LLVM_HOME=`pwd`

Current clang version on my system – 3.3.1, so let’s build respective version:

1 2 3 4 5 6 7 8 9 git clone-brelease_33 https://github.com/llvm-mirror/llvm.gitllvm git clone-brelease_33 https://github.com/llvm-mirror/clang.gitllvm/tools/clang git clone-brelease_33 https://github.com/llvm-mirror/clang-tools-extra.gitllvm/tools/clang/tools/extra git clone-brelease_33 https://github.com/llvm-mirror/compiler-rt.gitllvm/projects/compiler-rt mkdirllvm_build cdllvm_build cmake../llvm-DCMAKE_BUILD_TYPE:STRING=Release make-j`sysctl-nhw.logicalcpu`

Basic plugin setup

Create directory for plugin

12cd$LLVM_HOMEmkdirtoy_clang_plugin;cdtoy_clang_plugin

Our plugin based on example from Clang repo and here is it’s structure:

1 2 3 ToyClangPlugin.exports CMakeLists.txt ToyClangPlugin.cpp

We’ll use one source file for simplification

ToyClangPlugin.cpp C++
123

相關推薦

Creating and using Clang plugin with Xcode

連結:https://railsware.com/blog/2014/02/28/creation-and-using-clang-plugin-with-xcode/ 如何寫一個clang plugin,很不錯的文章,記錄一下。 This tutorial

Simpler ways of creating and using Segue in Xcode

To create and use segue, first of all, we will require two view controllers. And I have created two of them namely ViewController and SecondViewController

How to use Kata Containers and CRI (containerd plugin) with Kubernetes

bsp use k8s doc ner blob ber uber net https://github.com/kata-containers/documentation/blob/master/how-to/how-to-use-k8s-with-cri-contain

Segmenting brain tissue using Apache MXNet with Amazon SageMaker and AWS Greengrass ML Inference

In Part 1 of this blog post, we demonstrated how to train and deploy neural networks to automatically segment brain tissue from an MRI scan in a s

Creating a dataset using an API with Python

Whenever we begin a Machine Learning project, the first thing that we need is a dataset. While there are many datasets that you can find online with varied

Creating and Manipulating PDFs with pdfrw

Patrick Maupin created a package he called pdfrw and released it back in 2012. The pdfrw package is a pure-Python library that you can use to read and writ

Local Authentication Using Challenge Response with Yubikey for CentOS 7

fail ins path api -m ica all use debug Connect Yubikey ,then initialize YubiKey slot 2: ykpersonalize -2 -ochal-resp -ochal-hmac -ohmac

Extracting and composing robust features with denosing autoencoders 論文

重要 style add 論文 是把 任務 生成 改進 編碼器 這是一篇發表於2008年初的論文。 文章主要講了利用 denosing autoencoder來學習 robust的中間特征。。進上步,說明,利用這個方法,可以初始化神經網絡的權值。。這就相當於一種非監督學習的

Plugin with id 'com.novoda.bintray-release' not found.的解決方案

添加 pan mage nbsp file eas 分享 pat img import Module的時候,有時候會提示Plugin with id ‘com.novoda.bintray-release‘ not found. 點擊Open File,定位到該Mod

Android studio 導入項目錯誤Plugin with id‘com.XXXX

repos enc mage 圖片 gin build spa include ppc 1.打開AS ,展開項目列表打開方框中的build.gradle。2.添加 buildscript { repositories { mavenCentral(

Plugin with id 'com.novoda.bintray-release' not found的解決方法

comment and pre 目錄 解決方法 roi -s path ase 我們一般在在github上下載下來的代碼,有時候會提示Plugin with id ‘com.novoda.bintray-release’ not found的錯誤,這

Using Custom Domains With IIS Express In Asp.Net Core

using hosts core system32 drive host 修改 ive not IIS Express是一個Mini版的IIS,能夠支持所有的Web開發任務,但是這種設計有一些缺陷,例如只能通過localhost:<port>的方式來訪問我們的應

MySQL Crash Course #13# Chapter 21. Creating and Manipulating Tables

hat enforce tro 自定義 dev comm enc chap ide 之前 manipulate 表裏的數據,現在則是 manipulate 表本身。 INDEX 創建多列構成的主鍵 自動增長的規定 查看上一次插入的自增 id 盡量用默認值替代

Renewed Red Hat and updated the system with yum up

ren style In cti lba round nor SM then Renewed Red Hat and updated the system with yum update, the following error:Not using downloaded r

Plugin with id 'com.android.application' not found. Open File

Plugin with id ‘com.android.application’ not found. Open File 解決方法: 將下面的配置拷貝到build.gradle裡面 buildscript { repositories { jcenter()

Coupled Dictionary and Feature Space Learning with Applications to Cross-Domain Image Synthesis and

聯合字典學習的目標函式: 和是來自兩個不同領域的n個無標籤資料對,維度分別為。  表示字典學習的能量項,它典型地關於資料重構誤差。聯合能量項調整觀察到的字典和,或結果係數和之間的關係。注意分別是的字典原子的數目。 在我們的工作中,我們考慮的稀疏表示的公式,因為它已被證明在

clang 開發應用xcode 編譯檢查的外掛 二:開發篇

1.抽象語法樹AST 在實現語法檢測之前,需要了解一個叫AST(抽象語法樹)的東西 抽象語法樹(abstract syntax code,AST)是原始碼的抽象語法結構的樹狀表示,樹上的每個節點都表示原始碼中的一種結構,之所以說是抽象的,是因為抽象語法樹並不會表示出真實語法出現的每

clang 開發應用xcode 編譯檢查的外掛 一:構建篇

Clang是llvm的編譯器前端,非常適合進行原始碼分析.目前開源的oclint就是基於clang進行的程式碼靜態檢查.工作中遇到了一些問題需要進行程式碼分析,所以學習了外掛的開發流程.既然開發外掛就要有合適的IDE,Mac上最合適的無疑是xcode了.本文將講述如何使用xcode開發c

CLANG技術分享系列二:程式碼風格檢查(A CLANG PLUGIN APPROACH)

轉:http://kangwang1988.github.io/tech/2016/10/31/check-code-style-using-clang-plugin.html 背景 一致的程式碼風格檢查已經是老生常談了,統一規範的程式碼風格不僅可提高程式碼的可讀性,可維護性,減少問題