Anonymous avatar Anonymous committed 00ce0cd

more cursor api + new token

Comments (0)

Files changed (2)

pkg/clang/cursor.go

 	return Cursor{o}
 }
 
+/**
+ * \defgroup CINDEX_CPP C++ AST introspection
+ *
+ * The routines in this group provide access information in the ASTs specific
+ * to C++ language features.
+ *
+ * @{
+ */
+
+/**
+ * \brief Determine if a C++ member function or member function template is 
+ * declared 'static'.
+ */
+func (c Cursor) CXXMethod_IsStatic() bool {
+	o := C.clang_CXXMethod_isStatic(c.c)
+	if o != C.uint(0) {
+		return true
+	}
+	return false
+}
+
+/**
+ * \brief Determine if a C++ member function or member function template is
+ * explicitly declared 'virtual' or if it overrides a virtual method from
+ * one of the base classes.
+ */
+func (c Cursor) CXXMethod_IsVirtual() bool {
+	o := C.clang_CXXMethod_isVirtual(c.c)
+	if o != C.uint(0) {
+		return true
+	}
+	return false
+}
+
+/**
+ * \brief Given a cursor that represents a template, determine
+ * the cursor kind of the specializations would be generated by instantiating
+ * the template.
+ *
+ * This routine can be used to determine what flavor of function template,
+ * class template, or class template partial specialization is stored in the
+ * cursor. For example, it can describe whether a class template cursor is
+ * declared with "struct", "class" or "union".
+ *
+ * \param C The cursor to query. This cursor should represent a template
+ * declaration.
+ *
+ * \returns The cursor kind of the specializations that would be generated
+ * by instantiating the template \p C. If \p C is not a template, returns
+ * \c CXCursor_NoDeclFound.
+ */
+func (c Cursor) TemplateCursorKind() CursorKind {
+	o := C.clang_getTemplateCursorKind(c.c)
+	return CursorKind(o)
+}
+
+/**
+ * \brief Given a cursor that may represent a specialization or instantiation
+ * of a template, retrieve the cursor that represents the template that it
+ * specializes or from which it was instantiated.
+ *
+ * This routine determines the template involved both for explicit 
+ * specializations of templates and for implicit instantiations of the template,
+ * both of which are referred to as "specializations". For a class template
+ * specialization (e.g., \c std::vector<bool>), this routine will return 
+ * either the primary template (\c std::vector) or, if the specialization was
+ * instantiated from a class template partial specialization, the class template
+ * partial specialization. For a class template partial specialization and a
+ * function template specialization (including instantiations), this
+ * this routine will return the specialized template.
+ *
+ * For members of a class template (e.g., member functions, member classes, or
+ * static data members), returns the specialized or instantiated member. 
+ * Although not strictly "templates" in the C++ language, members of class
+ * templates have the same notions of specializations and instantiations that
+ * templates do, so this routine treats them similarly.
+ *
+ * \param C A cursor that may be a specialization of a template or a member
+ * of a template.
+ *
+ * \returns If the given cursor is a specialization or instantiation of a 
+ * template or a member thereof, the template or member that it specializes or
+ * from which it was instantiated. Otherwise, returns a NULL cursor.
+ */
+func (c Cursor) SpecializedCursorTemplate() Cursor {
+	o := C.clang_getSpecializedCursorTemplate(c.c)
+	return Cursor{o}
+}
+
+/**
+ * \brief Given a cursor that references something else, return the source range
+ * covering that reference.
+ *
+ * \param C A cursor pointing to a member reference, a declaration reference, or
+ * an operator call.
+ * \param NameFlags A bitset with three independent flags: 
+ * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
+ * CXNameRange_WantSinglePiece.
+ * \param PieceIndex For contiguous names or when passing the flag 
+ * CXNameRange_WantSinglePiece, only one piece with index 0 is 
+ * available. When the CXNameRange_WantSinglePiece flag is not passed for a
+ * non-contiguous names, this index can be used to retreive the individual
+ * pieces of the name. See also CXNameRange_WantSinglePiece.
+ *
+ * \returns The piece of the name pointed to by the given cursor. If there is no
+ * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
+ */
+func (c Cursor) ReferenceNameRange(flags NameRefFlags, pieceIdx uint) SourceRange {
+	o := C.clang_getCursorReferenceNameRange(c.c,
+		C.uint(flags), C.uint(pieceIdx))
+	return SourceRange{o}
+}
+
+type NameRefFlags uint32
+
+const (
+	/**
+	 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
+	 * range.
+	 */
+	NR_WantQualifier = C.CXNameRange_WantQualifier
+
+	/**
+	 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in 
+	 * the range.
+	 */
+	NR_WantTemplateArgs = C.CXNameRange_WantTemplateArgs
+
+	/**
+	 * \brief If the name is non-contiguous, return the full spanning range.
+	 *
+	 * Non-contiguous names occur in Objective-C when a selector with two or more
+	 * parameters is used, or in C++ when using an operator:
+	 * \code
+	 * [object doSomething:here withValue:there]; // ObjC
+	 * return some_vector[1]; // C++
+	 * \endcode
+	 */
+	NR_WantSinglePiece = C.CXNameRange_WantSinglePiece
+)
 
 // EOF

pkg/clang/token.go

+package clang
+
+// #include <stdlib.h>
+// #cgo LDFLAGS: -L/opt/local/libexec/llvm-3.0/lib -L/usr/lib/llvm -lclang
+// #cgo CFLAGS: -I/opt/local/libexec/llvm-3.0/include -I.
+// #include "clang-c/Index.h"
+// #include "go-clang.h"
+// inline static
+// CXCursor _go_clang_ocursor_at(CXCursor *c, int idx) {
+//   return c[idx];
+// }
+//
+import "C"
+
+// TokenKind describes a kind of token
+type TokenKind uint32
+const (
+  /**
+   * \brief A token that contains some kind of punctuation.
+   */
+	TK_Punctuation = C.CXToken_Punctuation
+
+  /**
+   * \brief A language keyword.
+   */
+	TK_Keyword = C.CXToken_Keyword
+
+	/**
+	 * \brief An identifier (that is not a keyword).
+	 */
+	TK_Identifier = C.CXToken_Identifier
+
+	/**
+	 * \brief A numeric, string, or character literal.
+	 */
+	TK_Literal = C.CXToken_Literal
+
+	/**
+	 * \brief A comment.
+	 */
+	TK_Comment = C.CXToken_Comment
+)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.