Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign

Is it possible for the parser to support newlib prototypes?

(1/12) > >>

WinterMute:
Newlib function prototypes take the form
--- Code: ---FILE * _EXFUN(fopen, (const char *__restrict _name, const char *__restrict _type));
--- End code ---
which obviously isn't picked up by the codeblocks parser as a function prototype.

Is it possible to get the cb parser to interpret these prototypes and add them to the code completion list?

To clarify - the symbol browser shows many _EXFUN( ...  ) prototypes but the _EXFUN macro is just there to adjust the prototypes for various platforms. For instance on CYGWIN it's
--- Code: ---#define _EXFUN(name, proto) __cdecl name proto
--- End code ---
but for other platforms it's
--- Code: ---#define _EXFUN(name, proto) name proto
--- End code ---
Thus the above example for fopen ends up as
--- Code: ---FILE * fopen (const char *__restrict _name, const char *__restrict _type);
--- End code ---

It would be nice if it was possible to somehow get the parser to expand that particular macro, even if it's just a regex somewhere. I don't really expect it to be able to follow the newlib headers & pick the right macro to expand.

ollydbg:
Yes, it is possible, see my patch(a hack)

--- Code: --- src/plugins/codecompletion/parser/tokenizer.cpp | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/plugins/codecompletion/parser/tokenizer.cpp b/src/plugins/codecompletion/parser/tokenizer.cpp
index 2176ab8..fee843d 100644
--- a/src/plugins/codecompletion/parser/tokenizer.cpp
+++ b/src/plugins/codecompletion/parser/tokenizer.cpp
@@ -1236,6 +1236,9 @@ void Tokenizer::ReplaceMacro(wxString& str)
                 }
             }
         }
+        // if in macro expansion mode, we don't let the manually replacement rule
+        // executed again, so just returned
+        return;
     }
 
     wxStringHashMap::const_iterator it = s_Replacements.find(str);
@@ -1296,6 +1299,15 @@ void Tokenizer::ReplaceMacro(wxString& str)
             str = DoGetToken();
         }
     }
+    else if (it->second[0] == _T('@'))
+    {
+        // trigger the macro replacement, so that we can look up the keyword in TokenTree for a
+        // macro usage, note that ReplaceBufferText() below just move backword the index, but
+        // don't change the buffer
+        if(ReplaceBufferText(it->first, false))
+            str = DoGetToken();
+
+    }
     else // for other user defined rules, just do a buffer content replacement
     {
         if (it->second != str && ReplaceBufferText(it->second, false))
@@ -1686,7 +1698,8 @@ void Tokenizer::SplitArguments(wxArrayString& results)
         else if (token == _T(")"))
             --level;
 
-        if (token == _T(","))
+        // comma is a delimit only it is not wrapper by ()
+        if (token == _T(",") && level == 1)
         {
             results.Add(piece);
             piece.Clear();


--- End code ---
You need to add a replacement rule in CC setting: _EXFUN  -> @

And the result can be shown in the screen shot below:

ollydbg:
In trunk now.


--- Code: ---Revision: 9829
Author: ollydbg
Date: 2014-6-24 10:48:08
Message:
* CC: add a new CC replacement rule: XXXXX -> @, and document the ReplaceMacro() function. The new rule triggers the tokenizer to switch to macro replacement mode, thus a macro definition can be looked up in the token tree. This fixes a bug report here: http://forums.codeblocks.org/index.php/topic,19278.0.html.
-------------------------------
M(T ) : /trunk/src/plugins/codecompletion/parser/tokenizer.cpp

M(T ) : /trunk/src/plugins/codecompletion/parser/tokenizer.h
--- End code ---

I'm also updating the wiki page by adding this rule:
http://wiki.codeblocks.org/index.php?title=Code_Completion_Design

Teybeo:
Does this patch enables support for glew.h functions definitions ?

Example for the OpenGL function
--- Code: ---glMultiDrawElements(GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei drawcount);
--- End code ---


--- Code: ---typedef void (GLAPIENTRY * PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei drawcount);
...
GLEW_FUN_EXPORT PFNGLMULTIDRAWELEMENTSPROC __glewMultiDrawElements;
...
#define glMultiDrawElements GLEW_GET_FUN(__glewMultiDrawElements)


#define GLEW_FUN_EXPORT GLEWAPI
#define GLEW_GET_FUN(x) x

#ifdef GLEW_STATIC
#  define GLEWAPI extern
#else
#  ifdef GLEW_BUILD
#    define GLEWAPI extern __declspec(dllexport)
#  else
#    define GLEWAPI extern __declspec(dllimport)
#  endif
#endif

--- End code ---


ollydbg:

--- Quote from: Teybeo on July 30, 2014, 12:02:42 am ---Does this patch enables support for glew.h functions definitions ?

Example for the OpenGL function
--- Code: ---glMultiDrawElements(GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei drawcount);
--- End code ---


--- End quote ---
This is a function pointer, not a function declaration, right? EDIT, true, that this is a function pointer, but we can call it like a normal function call like glMultiDrawElements(...), see Function Pointers in C and C++ - Cprogramming.com

I just tested, and currently, CC only regard the glMultiDrawElements as a macro definition. What is the expect behavior do you want?

EDIT:
The correct test code could be:

--- Code: ---#ifdef GLEW_STATIC
#  define GLEWAPI extern
#else
#  ifdef GLEW_BUILD
#    define GLEWAPI extern __declspec(dllexport)
#  else
#    define GLEWAPI extern __declspec(dllimport)
#  endif
#endif

#define GLEW_FUN_EXPORT GLEWAPI
#define GLEW_GET_FUN(x) x

typedef void (GLAPIENTRY * PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei drawcount);

GLEW_FUN_EXPORT PFNGLMULTIDRAWELEMENTSPROC __glewMultiDrawElements;

#define glMultiDrawElements GLEW_GET_FUN(__glewMultiDrawElements)

glMultiDrawElements

--- End code ---

Or even simpiler

--- Code: ---#define GLEW_FUN_EXPORT extern
#define GLEW_GET_FUN(x) x

typedef void ( * PFNGLMULTIDRAWELEMENTSPROC) (int a);

GLEW_FUN_EXPORT PFNGLMULTIDRAWELEMENTSPROC __glewMultiDrawElements;

#define glMultiDrawElements GLEW_GET_FUN(__glewMultiDrawElements)

glMultiDrawElements

--- End code ---


Navigation

[0] Message Index

[#] Next page

Go to full version