Merge pull request #676 from luoliwoshang/xtool/ast/funcproto
castdump:funcproto type & computed enum value
This commit is contained in:
@@ -31,6 +31,16 @@ void wrap_clang_getTranslationUnitCursor(CXTranslationUnit uint, CXCursor *cur)
|
||||
|
||||
void wrap_clang_getCursorType(CXCursor *cur, CXType *typ) { *typ = clang_getCursorType(*cur); }
|
||||
|
||||
void wrap_clang_getCursorResultType(CXCursor *cur, CXType *typ) { *typ = clang_getCursorResultType(*cur); }
|
||||
|
||||
void wrap_clang_getResultType(CXType *typ, CXType *resultTyp) { *resultTyp = clang_getResultType(*typ); }
|
||||
|
||||
int wrap_clang_getNumArgTypes(CXType *typ) { return clang_getNumArgTypes(*typ); }
|
||||
|
||||
void wrap_clang_getArgType(CXType *typ, unsigned i, CXType *argTyp) { *argTyp = clang_getArgType(*typ, i); }
|
||||
|
||||
long long wrap_clang_getEnumConstantDeclValue(CXCursor *cur) { return clang_getEnumConstantDeclValue(*cur); }
|
||||
|
||||
void wrap_clang_getPointeeType(CXType *pointerTyp, CXType *pointeeTyp) {
|
||||
*pointeeTyp = clang_getPointeeType(*pointerTyp);
|
||||
}
|
||||
@@ -39,8 +49,6 @@ void wrap_clang_getArrayElementType(CXType *arrayTyp, CXType *elemTyp) {
|
||||
*elemTyp = clang_getArrayElementType(*arrayTyp);
|
||||
}
|
||||
|
||||
void wrap_clang_getCursorResultType(CXCursor *cur, CXType *typ) { *typ = clang_getCursorResultType(*cur); }
|
||||
|
||||
void wrap_clang_getCanonicalType(CXType *typ, CXType *canonicalType) { *canonicalType = clang_getCanonicalType(*typ); }
|
||||
|
||||
CXString wrap_clang_getTypeSpelling(CXType *typ) { return clang_getTypeSpelling(*typ); }
|
||||
|
||||
@@ -1608,6 +1608,22 @@ func (c Cursor) ResultType() (ret Type) {
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the integer value of an enum constant declaration as a signed
|
||||
* long long.
|
||||
*
|
||||
* If the cursor does not reference an enum constant declaration, LLONG_MIN is
|
||||
* returned. Since this is also potentially a valid constant value, the kind of
|
||||
* the cursor must be verified before calling this function.
|
||||
*/
|
||||
// llgo:link (*Cursor).wrapEnumConstantDeclValue C.wrap_clang_getEnumConstantDeclValue
|
||||
func (*Cursor) wrapEnumConstantDeclValue() (ret c.LongLong) {
|
||||
return 0
|
||||
}
|
||||
func (c Cursor) EnumConstantDeclValue() (ret c.LongLong) {
|
||||
return c.wrapEnumConstantDeclValue()
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the number of non-variadic arguments associated with a given
|
||||
* cursor.
|
||||
@@ -1788,6 +1804,47 @@ func (t Type) String() (ret String) {
|
||||
return t.wrapString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the return type associated with a function type.
|
||||
*
|
||||
* If a non-function type is passed in, an invalid type is returned.
|
||||
*/
|
||||
// llgo:link (*Type).wrapResultType C.wrap_clang_getResultType
|
||||
func (t *Type) wrapResultType(ret *Type) { return }
|
||||
|
||||
func (t Type) ResultType() (ret Type) {
|
||||
t.wrapResultType(&ret)
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the number of non-variadic parameters associated with a
|
||||
* function type.
|
||||
*
|
||||
* If a non-function type is passed in, -1 is returned.
|
||||
*/
|
||||
// llgo:link (*Type).wrapNumArgTypes C.wrap_clang_getNumArgTypes
|
||||
func (t *Type) wrapNumArgTypes() (num c.Int) { return 0 }
|
||||
|
||||
func (t Type) NumArgTypes() (num c.Int) {
|
||||
return t.wrapNumArgTypes()
|
||||
}
|
||||
|
||||
// void wrap_clang_getArgType(CXType *typ, unsigned i, CXType *argTyp) { *argTyp = clang_getArgType(*typ, i); }
|
||||
/**
|
||||
* Retrieve the type of a parameter of a function type.
|
||||
*
|
||||
* If a non-function type is passed in or the function does not have enough
|
||||
* parameters, an invalid type is returned.
|
||||
*/
|
||||
// llgo:link (*Type).wrapArgType C.wrap_clang_getArgType
|
||||
func (t *Type) wrapArgType(index c.Uint, argTyp *Type) { return }
|
||||
|
||||
func (t Type) ArgType(index c.Uint) (ret Type) {
|
||||
t.wrapArgType(index, &ret)
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* For pointer types, returns the type of the pointee.
|
||||
*/
|
||||
@@ -1806,6 +1863,7 @@ func (t Type) PointeeType() (ret Type) {
|
||||
*/
|
||||
// llgo:link (*Type).wrapArrayElementType C.wrap_clang_getArrayElementType
|
||||
func (t *Type) wrapArrayElementType(ret *Type) { return }
|
||||
|
||||
func (t Type) ArrayElementType() (ret Type) {
|
||||
t.wrapArrayElementType(&ret)
|
||||
return
|
||||
@@ -1821,6 +1879,7 @@ func (t Type) ArrayElementType() (ret Type) {
|
||||
*/
|
||||
// llgo:link (*Type).wrapCanonicalType C.wrap_clang_getCanonicalType
|
||||
func (t *Type) wrapCanonicalType(ret *Type) { return }
|
||||
|
||||
func (t Type) CanonicalType() (ret Type) {
|
||||
t.wrapCanonicalType(&ret)
|
||||
return
|
||||
|
||||
@@ -23,7 +23,7 @@ var accessMap = map[clang.CXXAccessSpecifier]string{
|
||||
}
|
||||
|
||||
func printIndent(depth c.Uint) {
|
||||
fmt.Print(strings.Repeat(" ", int(depth)))
|
||||
fmt.Print(strings.Repeat(" ", int(depth)))
|
||||
}
|
||||
|
||||
func accessToString(spec clang.CXXAccessSpecifier) string {
|
||||
@@ -44,7 +44,11 @@ func printType(t clang.Type, data *Data) {
|
||||
|
||||
typeSpell := t.String()
|
||||
typeKind := t.Kind.String()
|
||||
if t.Kind > clang.TypeFirstBuiltin && t.Kind < clang.TypeLastBuiltin {
|
||||
|
||||
if t.Kind == clang.TypeInvalid {
|
||||
} else if t.Kind == clang.TypeUnexposed {
|
||||
c.Printf(c.Str("<UnexposedType|%s>: %s\n"), typeKind.CStr(), typeSpell.CStr())
|
||||
} else if t.Kind >= clang.TypeFirstBuiltin && t.Kind <= clang.TypeLastBuiltin {
|
||||
c.Printf(c.Str("<BuiltinType|%s>: %s\n"), typeKind.CStr(), typeSpell.CStr())
|
||||
} else if t.Kind > clang.TypeComplex {
|
||||
c.Printf(c.Str("<ComplexType|%s>: %s\n"), typeKind.CStr(), typeSpell.CStr())
|
||||
@@ -58,6 +62,11 @@ func printType(t clang.Type, data *Data) {
|
||||
printType(t.ArrayElementType(), data)
|
||||
case clang.TypeTypedef:
|
||||
printType(t.CanonicalType(), data)
|
||||
case clang.TypeFunctionProto:
|
||||
printType(t.ResultType(), data)
|
||||
for i := 0; i < int(t.NumArgTypes()); i++ {
|
||||
printType(t.ArgType(c.Uint(i)), data)
|
||||
}
|
||||
}
|
||||
data.Depth--
|
||||
|
||||
@@ -83,7 +92,8 @@ func printAccess(cursor clang.Cursor) {
|
||||
defer kind.Dispose()
|
||||
defer spell.Dispose()
|
||||
|
||||
c.Printf(c.Str("%s: %s %s\n"), kind.CStr(), spell.CStr(), c.AllocaCStr(accessToString(cursor.CXXAccessSpecifier())))
|
||||
c.Printf(c.Str("%s: %s %s"), kind.CStr(), spell.CStr(), c.AllocaCStr(accessToString(cursor.CXXAccessSpecifier())))
|
||||
printLocation(cursor)
|
||||
}
|
||||
|
||||
func printMacro(cursor clang.Cursor, unit *clang.TranslationUnit) {
|
||||
@@ -101,20 +111,30 @@ func printMacro(cursor clang.Cursor, unit *clang.TranslationUnit) {
|
||||
c.Printf(c.Str("%s "), tokStr.CStr())
|
||||
tokStr.Dispose()
|
||||
}
|
||||
c.Printf(c.Str("\n"))
|
||||
printLocation(cursor)
|
||||
}
|
||||
|
||||
func printFunc(cursor clang.Cursor) {
|
||||
func printFunc(cursor clang.Cursor, data *Data) {
|
||||
kind := cursor.Kind.String()
|
||||
spell := cursor.String()
|
||||
symbol := cursor.Mangling()
|
||||
typ := cursor.Type().String()
|
||||
defer symbol.Dispose()
|
||||
defer kind.Dispose()
|
||||
defer spell.Dispose()
|
||||
defer typ.Dispose()
|
||||
|
||||
c.Printf(c.Str("%s: %s (Type: %s)(Symbol: %s)"), kind.CStr(), spell.CStr(), typ.CStr(), symbol.CStr())
|
||||
c.Printf(c.Str("%s: %s (Symbol: %s)"), kind.CStr(), spell.CStr(), symbol.CStr())
|
||||
printLocation(cursor)
|
||||
printType(cursor.Type(), data)
|
||||
}
|
||||
|
||||
func printEnumConstant(cursor clang.Cursor) {
|
||||
kind := cursor.Kind.String()
|
||||
spell := cursor.String()
|
||||
defer kind.Dispose()
|
||||
defer spell.Dispose()
|
||||
|
||||
c.Printf(c.Str("%s: %s:%lld"), kind.CStr(), spell.CStr(), cursor.EnumConstantDeclValue())
|
||||
printLocation(cursor)
|
||||
}
|
||||
|
||||
func printDefault(cursor clang.Cursor, data *Data) {
|
||||
@@ -142,13 +162,12 @@ func printAST(cursor clang.Cursor, data *Data) {
|
||||
switch cursor.Kind {
|
||||
case clang.CursorCXXAccessSpecifier:
|
||||
printAccess(cursor)
|
||||
printLocation(cursor)
|
||||
case clang.CursorMacroDefinition:
|
||||
printMacro(cursor, data.Unit)
|
||||
printLocation(cursor)
|
||||
case clang.CursorFunctionDecl, clang.CursorCXXMethod, clang.CursorConstructor, clang.CursorDestructor:
|
||||
printFunc(cursor)
|
||||
printLocation(cursor)
|
||||
printFunc(cursor, data)
|
||||
case clang.CursorEnumConstantDecl:
|
||||
printEnumConstant(cursor)
|
||||
default:
|
||||
printDefault(cursor, data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user