안녕하세요, 저는 새로운 컴파일러 개발 과정에서 AST가 어떻게 보이는지 궁금합니다. 작은 코드 섹션이 있으며 AST를 생성하기 위해 Clang을 사용합니다. 나는 그것에서 많은 정보를 얻지 않는다. 보이는 것부터, Syntax tree는 거의 모든 샘플에 추가 된 하나의 구조체를 제외하고는 소스와 정확히 동일합니다.Clang : AST (추상 구문 트리)는 어떻게 생겼습니까?
자료 :
class A {
public:
int *a, *b, *c;
int i;
void sum() {
a = new int[5];
b = new int[5];
c = new int[5];
for (i = 0; i < 5; i++) {
a[i] = i;
b[i] = i;
}
for (i = 0; i < 5; i++) {
c[i] = a[i] + b[i];
}
delete[] a; delete[] b; delete[] c;
}
};
class B : public A {
};
int main() {
B bclass;
bclass.sum();
return 0;
}
명령 생성 AST :
clang++ -cc1 -ast-print ~/sum.cpp
AST 출력 :
struct __va_list_tag {
unsigned int gp_offset;
unsigned int fp_offset;
void *overflow_arg_area;
void *reg_save_area;
};
typedef struct __va_list_tag __va_list_tag;
class A {
public:
int *a;
int *b;
int *c;
int i;
void sum() {
this->a = new int [5];
this->b = new int [5];
this->c = new int [5];
for (this->i = 0; this->i < 5; this->i++) {
this->a[this->i] = this->i;
this->b[this->i] = this->i;
}
for (this->i = 0; this->i < 5; this->i++) {
this->c[this->i] = this->a[this->i] + this->b[this->i];
}
delete [] this->a;
delete [] this->b;
delete [] this->c;
}
};
class B : public A {
};
int main() {
B bclass;
bclass.sum();
return 0;
}
감사
참고 : -ast-print 대신 -ast-dump를 시도해 볼 수 있습니다. 그 표현은 당신이 찾고있는 것과 더 가깝습니다. – servn
Clang의 AST가 아닌 AST가 무엇인지 묻는다면이 대답이 유용 할 것입니다. http://stackoverflow.com/questions/6376662/how-a-ast-for-an-object 지향 프로그래밍 언어로 보입니다/6378997 # 6378997 –