怎樣操作clang的ast, 比如新增 修改 刪除節點,把乙個AST插入到另乙個AST,AST複製等

時間 2021-06-05 12:42:35

1樓:BinSys

先放個URL

這有乙個直接建立AST的,當然沒有source location ,所以沒法匯出為cpp

// Win32Project1.cpp : 定義控制台應用程式的入口點。

//#include

"stdafx.h"

#include

#include

#include

#include

#include

#include

#include

#define CS_FLAGS

#define CS_IGNORE

#if defined(_MSC_VER) && !defined(__clang__)

#define CS_API __declspec(dllexport)

#else

#define CS_API

#endif

#define CS_ABSTRACT

#define CS_VALUE_TYPE

// The expression ARRAY_SIZE(a) is a compile-time constant of type

// size_t which represents the number of elements of the given

// array. You should only use ARRAY_SIZE on statically allocated

// arrays.

#define ARRAY_SIZE(a

((sizeof(a) / sizeof(*(a

static_cast(!(sizeof(a) % sizeof(*(a)))))

#include

"llvm/Support/Host.h"

#include

"clang/AST/ASTContext.h"

#include

"clang/AST/ASTConsumer.h"

#include

"clang/AST/Decl.h"

#include

"clang/AST/Expr.h"

#include

"clang/AST/Stmt.h"

#include

"clang/Basic/IdentifierTable.h"

#include

"clang/Basic/Specifiers.h"

#include

"clang/Basic/TargetInfo.h"

#include

"clang/Frontend/ASTConsumers.h"

#include

"clang/Frontend/CompilerInstance.h"

#include

"clang/Lex/Preprocessor.h"

using

namespace

llvm

;using

namespace

std;

intmain

()/* function body */

// Decl printing

llvm

::outs

()<<

"-ast-print: \n"

;ASTContextInstance

.getTranslationUnitDecl

()->

print

(llvm

::outs

());

llvm

::outs

()<<"\n

";llvm

::outs

()<<

"-ast-dump: \n"

;ASTContextInstance

.getTranslationUnitDecl

()->

dump

(llvm

::outs

());

llvm

::outs

()<<"\n

";return0;}

我想寫乙個自己的作業系統,比如Unix或Linux,最起碼我需要具備些什麼?然後我需要怎麼做?

Hiraku ei 作業系統 從入門到放棄 unix,linux匯集了無數工程師,數以萬計的工時 軟體工程發展到今天別說乙個人做現代作業系統,是不可能的,寫個玩具式的超迷作業系統,熟悉下所謂作業系統原理還可以說說。 Github上的linux torvalds linux 知乎 現今Linux也並非...

大學刷分重修是個怎樣的操作?

能一次高分盡量不要刷分了,來自乙個沉迷遊戲小學渣的真誠勸告。因為你會發現重修和新的課程衝突,總也選不上,好不容易選上了,到了教室跟學弟學妹坐在一起又很尷尬,講課內容全都學過又一知半解,會的內容不想再聽一遍,拿出手機開始刷動態不會的也錯過了,多數都是上幾次課就不去了,期末之前瘋狂看書看資料,和之前熬夜...

怎樣才能培養自信,比如演講之類的?

表現自信,在話題準備上要找自己擅長的內容。同時在演講之前要多練習,可以找朋友當觀眾,演練自己的表情,身體姿態,語氣,語調等。以我的經驗不要死記硬背逐字稿,現場容易緊張忘詞兒。所以很自然的方式,就是台下多練習 多準備是不變的道理。 飛豬寫寫寫 1 學會愛惜自己 愛惜自己是最根本的要求,不論遇到任何事情...