-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
102 lines (96 loc) · 3.3 KB
/
example.c
File metadata and controls
102 lines (96 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Created by lokko on 12.05.20.
//
#include "library.h"
#include <z3.h>
void putTypeSpelling(pHCursor cursor);
static void enumVisitor(pHCursor cursor, void* userData) {
printf("\n %s = %lld,", getNameSpelling(cursor), enumConstantDeclValue(cursor));
}
static void structVisitor(pHCursor cursor, void* userData) {
fputs("\n\t", stdout);
putTypeSpelling(cursor);
putchar(' ');
fputs(getNameSpelling(cursor), stdout);
putchar(';');
}
void putTypeSpelling(pHCursor cursor) {
if(isVarDecl(cursor))
fputs(getTypeSpelling(cursor), stdout);
else if(isTypedef(cursor))
fputs(getTypeSpelling(cursor), stdout);
else if(isElaborated(cursor))
putTypeSpelling(elaboratedCursor(cursor));
else if(isEnum(cursor))
fputs(getTypeSpelling(cursor), stdout);
else if(isStruct(cursor))
fputs(getTypeSpelling(cursor), stdout);
else if(isPointer(cursor)) {
fputs("pointer to ", stdout);
putTypeSpelling(pointedToCursor(cursor));
}
else if(isFunction(cursor)) {
printf("function that has %d parameters and returns " , numParameters(cursor));
putTypeSpelling(returnCursor(cursor));
for(int i = 0; i < numParameters(cursor); i++){
printf(" |parameter %d ", i + 1);
putTypeSpelling(parameterCursor(cursor, i));
}
}
}
void TestVisitor(pHCursor cursor, void* userData) {
if(isVarDecl(cursor)) {
fputs("\nVarDecl ", stdout);
fputs(getNameSpelling(cursor), stdout);
putchar(' ');
if(isElaborated(cursor)) {
pHCursor c = elaboratedCursor(cursor);
fputs(getTypeSpelling(c), stdout);
}
else
fputs(getTypeSpelling(cursor), stdout);
}
else if(isPointer(cursor)) {
fputs("\nPointer ", stdout);
fputs(getNameSpelling(cursor), stdout);
fputs(" ultimately points to ", stdout);
fputs(getTypeSpelling(finalPointedToCursor(cursor)), stdout);
}
else if(isTypedef(cursor)) {
fputs("\nTypedef ", stdout);
fputs(getNameSpelling(cursor), stdout);
fputs(" is an alias for ", stdout);
putTypeSpelling(getTypedefCursor(cursor));
}
else if(isFunction(cursor)) {
printf("\nFunction %s that has %d parameters and returns " , getNameSpelling(cursor), numParameters(cursor));
putTypeSpelling(returnCursor(cursor));
for(int i = 0; i < numParameters(cursor); i++){
printf(" |parameter %d ", i + 1);
putTypeSpelling(parameterCursor(cursor, i));
}
}
else if(isEnum(cursor)) {
fputs("\nEnum ", stdout);
fputs(getNameSpelling(cursor), stdout);
putchar(' ');
typeSpelling(enumIntegerType(cursor));
putchar('{');
VisitEnum(cursor, enumVisitor, NULL);
fputs("\n}", stdout);
}
else if(isStruct(cursor)) {
printf("\nStruct %s ", getNameSpelling(cursor));
putchar('{');
VisitStruct(cursor, structVisitor, NULL);
fputs("\n}", stdout);
}
else if(isArray(cursor)) {
printf("\nArray %s of ", getNameSpelling(cursor));
putTypeSpelling(arrayElementTypeCursor(cursor));
printf(" of %lld elements",numArrayElements(cursor));
}
}
int main(){
ParseHeader("../library.h", TestVisitor, NULL);
}