FYI: libclang: New API: Checking if macro is builtin/function

Kevin Funk kfunk at kde.org
Wed Jan 20 16:35:40 UTC 2016


On Wednesday, January 20, 2016 05:19:38 PM Milian Wolff wrote:
> On Wednesday, January 20, 2016 4:32:04 PM CET Kevin Funk wrote:
> > Heya,
> > 
> > New API in libclang [1].
> > 
> > Probably interesting to us:
> > * clang_Cursor_isMacroFunctionLike
> 
> Nice!
> 
> > * clang_Cursor_isMacroBuiltin
> 
> What would you use this for?

For ranking/grouping built-in macros in the completion list.

I remember a TODO item, from kdev-clang's context.cpp:
    // TODO: grouping of macros and built-in stuff

Could be helpful.
 
> > * clang_Cursor_isFunctionInlined

> How do you envision this being visualized? This is not "inline", is it? But
> rather if the function got inlined? In what context?

It is "inline" if I understood correctly, see apidocs:

    Determine whether a CXCursor that is a function declaration,
    is an inline declaration.

Cheers,
Kevin

> > Maybe someone's got the time to integrate this in kdev-clang.
> > 
> > Cheers,
> > Kevin
> > 
> > PS: I'll start to post these mails as soon as I encounter new useful API
> > we
> > could use in libclang, from now on.
> 
> Thanks! I for one appreciate that.
> 
> Cheers
> 
> > [1]
> > commit c5f92b66c89ee5446679b86e636bbb6813fcc22e
> > Author: Argyrios Kyrtzidis <akyrtzi at gmail.com>
> > Date:   Sat Jan 16 00:20:02 2016 +0000
> > 
> >     [libclang] Introduce APIs for evaluating a cursor and checking if a
> > 
> > macro is builtin/function.
> > 
> >     rdar://24091595
> >     
> >     git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257968
> > 
> > 91177308-0d34-0410-b5e6-96231b3b80d8
> > 
> > diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
> > index 09e2160..69c3844 100644
> > --- a/include/clang-c/Index.h
> > +++ b/include/clang-c/Index.h
> > @@ -32,7 +32,7 @@
> > 
> >   * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
> >   */
> >  
> >  #define CINDEX_VERSION_MAJOR 0
> > 
> > -#define CINDEX_VERSION_MINOR 32
> > +#define CINDEX_VERSION_MINOR 33
> > 
> >  #define CINDEX_VERSION_ENCODE(major, minor) ( \
> >  
> >        ((major) * 10000)                       \
> > 
> > @@ -2431,6 +2431,11 @@ CINDEX_LINKAGE unsigned clang_isStatement(enum
> > CXCursorKind);
> > 
> >  CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
> >  
> >  /**
> > 
> > + * \brief Determine whether the given cursor has any attributes.
> > + */
> > +CINDEX_LINKAGE unsigned clang_Cursor_hasAttrs(CXCursor C);
> > +
> > +/**
> > 
> >   * \brief Determine whether the given cursor kind represents an invalid
> >   * cursor.
> >   */
> > 
> > @@ -3170,6 +3175,24 @@ CINDEX_LINKAGE CXType clang_getCanonicalType(CXType
> > T); CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
> > 
> >  /**
> > 
> > + * \brief Determine whether a  CXCursor that is a macro, is
> > + * function like.
> > + */
> > +CINDEX_LINKAGE unsigned clang_Cursor_isMacroFunctionLike(CXCursor C);
> > +
> > +/**
> > + * \brief Determine whether a  CXCursor that is a macro, is a
> > + * builtin one.
> > + */
> > +CINDEX_LINKAGE unsigned clang_Cursor_isMacroBuiltin(CXCursor C);
> > +
> > +/**
> > + * \brief Determine whether a  CXCursor that is a function declaration,
> > is
> > an + * inline declaration.
> > + */
> > +CINDEX_LINKAGE unsigned clang_Cursor_isFunctionInlined(CXCursor C);
> > +
> > +/**
> > 
> >   * \brief Determine whether a CXType has the "volatile" qualifier set,
> >   * without looking through typedefs that may have added "volatile" at
> >   * a different level.
> > 
> > @@ -3199,6 +3222,11 @@ CINDEX_LINKAGE CXCursor
> > clang_getTypeDeclaration(CXType T);
> > 
> >  CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
> >  
> >  /**
> > 
> > + * Returns the Objective-C type encoding for the specified CXType.
> > + */
> > +CINDEX_LINKAGE CXString clang_Type_getObjCEncoding(CXType type);
> > +
> > +/**
> > 
> >   * \brief Retrieve the spelling of a given CXTypeKind.
> >   */
> >  
> >  CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
> > 
> > @@ -5077,6 +5105,59 @@ CINDEX_LINKAGE void
> > clang_getInclusions(CXTranslationUnit tu,
> > 
> >                                          CXInclusionVisitor visitor,
> >                                          CXClientData client_data);
> > 
> > +typedef enum {
> > +  CXEval_Int = 1 ,
> > +  CXEval_Float = 2,
> > +  CXEval_ObjCStrLiteral = 3,
> > +  CXEval_StrLiteral = 4,
> > +  CXEval_CFStr = 5,
> > +  CXEval_Other = 6,
> > +
> > +  CXEval_UnExposed = 0
> > +
> > +} CXEvalResultKind ;
> > +
> > +/**
> > + * \brief Evaluation result of a cursor
> > + */
> > +typedef void * CXEvalResult;
> > +
> > +/**
> > + * \brief If cursor is a statement declaration tries to evaluate the
> > + * statement and if its variable, tries to evaluate its initializer,
> > + * into its corresponding type.
> > + */
> > +CINDEX_LINKAGE CXEvalResult clang_Cursor_Evaluate(CXCursor C);
> > +
> > +/**
> > + * \brief Returns the kind of the evaluated result.
> > + */
> > +CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E);
> > +
> > +/**
> > + * \brief Returns the evaluation result as integer if the
> > + * kind is Int.
> > + */
> > +int clang_EvalResult_getAsInt(CXEvalResult E);
> > +
> > +/**
> > + * \brief Returns the evaluation result as double if the
> > + * kind is double.
> > + */
> > +double clang_EvalResult_getAsDouble(CXEvalResult E);
> > +
> > +/**
> > + * \brief Returns the evaluation result as a constant string if the
> > + * kind is other than Int or float. User must not free this pointer,
> > + * instead call clang_EvalResult_dispose on the CXEvalResult returned
> > + * by clang_Cursor_Evaluate.
> > + */
> > +const char* clang_EvalResult_getAsStr(CXEvalResult E);
> > +
> > +/**
> > + * \brief Disposes the created Eval memory.
> > + */
> > +void clang_EvalResult_dispose(CXEvalResult E);
> > 
> >  /**
> >  
> >   * @}
> >   */

-- 
Kevin Funk | kfunk at kde.org | http://kfunk.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20160120/bb2ad3a6/attachment.sig>


More information about the KDevelop-devel mailing list