T O P I C R E V I E W |
chjfth |
Posted - Oct 21 2006 : 08:45:23 AM I'm using VAX to parse Linux glibc headers(on SuSE Linux 10.1), but fustrated by one thing:
Quite a lot of function declarations ends with __THROW, which is a marco that defines in <sys/cdefs.h>. But the macro value of __THROW has three forms which is guarded by some #ifdef preprocessor directives.
#ifdef __GNUC__
/* GCC can always grok prototypes. For C++ programs we add throw()
to help it optimize the function calls. But this works only with
gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
as non-throwing using a function attribute since programs can use
the -fexceptions options for C code as well. */
# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
# define __THROW __attribute__ ((__nothrow__))
# define __NTH(fct) __attribute__ ((__nothrow__)) fct
# else
# if defined __cplusplus && __GNUC_PREREQ (2,8)
# define __THROW throw ()
# define __NTH(fct) fct throw ()
# else
# define __THROW
# define __NTH(fct) fct
# endif
# endif
#else /* Not GCC. */
# define __inline /* No inline functions. */
# define __THROW
# define __NTH(fct) fct
# define __const const
# define __signed signed
# define __volatile volatile
#endif /* GCC. */
Among the three values of __THROW:
* __attribute__ ((nothrow)) * throw () * [empty]
VAX seems not to choose the empty value, because:
for the declaration(in <sys/socket.h>):
extern int socket (int __domain, int __type, int __protocol) __THROW;
The function socket can not be recognized by VAX, but if I delete the trailing __THROW for socket declaration, socket can now be recognized as a function.
To purify the problem, I write a dedicated test program(socket_test.cpp), and from this program, you can see socket_test function can not be recognized.
You kind VAX developers please tell me: * how VAX reacts when it sees the unfamiliar __GNUC_PREREQ macro in some #if defined or #if !defined preprocessor conditions, * what __THROW macro finally results in in socket_test.cpp, * and why it results in that.
My dedicated test program is listed below:
// socket_test.cpp
// Start: Excerpt for glibc <sys/cdefs.h>
#ifdef __GNUC__
/* GCC can always grok prototypes. For C++ programs we add throw()
to help it optimize the function calls. But this works only with
gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
as non-throwing using a function attribute since programs can use
the -fexceptions options for C code as well. */
# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
# define __THROW __attribute__ ((__nothrow__))
# define __NTH(fct) __attribute__ ((__nothrow__)) fct
# else
# if defined __cplusplus && __GNUC_PREREQ (2,8)
# define __THROW throw ()
# define __NTH(fct) fct throw ()
# else
# define __THROW
# define __NTH(fct) fct
# endif
# endif
#else /* Not GCC. */
# define __inline /* No inline functions. */
# define __THROW
# define __NTH(fct) fct
#endif /* GCC. */
// End: Excerpt for glibc <sys/cdefs.h>
extern int socket_test (int __domain, int __type, int __protocol) __THROW;
void testfunc()
{
socket_test(); //!! VAX 10.3.1535.0: What this cannot be parsed?
}
And the screen capture:
VA_X.dll file version 10.3.1535.0 built 2006.09.15 Licensed to: <hidden> VAOpsWin.dll version 1.3.3.6 VATE.dll version 1.0.5.8 MSDev.exe version 6.0.9782.2 Devshl.dll version 6.0.9782.0 Devedit.pkg version 6.0.9782.0 Font: Courier -13(Pixels) Comctl32.dll version 5.81.3502.6601 Windows 2000 5.0 Build 2195 Service Pack 4 Single processor
Platform: Custom Stable Includes: F:\\include; F:\\local\\include\\atk-1.0; F:\\local\\include\\glib-2.0; F:\\local\\include\\gtk-2.0; F:\\local\\include\\pango-1.0;
Library Includes:
Other Includes:
|
5 L A T E S T R E P L I E S (Newest First) |
chjfth |
Posted - Oct 24 2006 : 01:05:34 AM Okay, I think I've got your idea, Misc/StdAfx.h could be treated specially by VAX. |
feline |
Posted - Oct 23 2006 : 1:22:05 PM We are in the process of expanding our FAQ to document more features.
Misc/StdAfx.h is one of two header files in the Misc directory. These are scanned before any code is scanned, and are used to give VA a "helping hand" with code that the parser finds difficult, mainly certain complex template code.
So it is very useful for a small number of cases, like this one, but most of our users never need to touch it. Also changes need to be re-applied after each new version of VA, so it is a little tricky to use.
For me placing the line:
#define __THROW
above this test code does not help, which suggests that Misc/StdAfx.h is treated slightly differently to other files. This makes sense, since VA cannot guarantee to parse the files in the "correct" order. A compiler has the luxury of fixed code, while VA is designed to work on code that is always changing and is often invalid. |
chjfth |
Posted - Oct 22 2006 : 01:41:21 AM But wait, I'm still confused, you support guy said that > if I add #define __THROW in Misc/StdAfx.h, then __THROW finally got empty (value). Does it mean that VAX use the first seen value if multiple #defines of __THROW exist.
If so, then: { Before __THROW was added to Misc/StdAfx.h, __THROW got its value as
# define __THROW __attribute__ ((__nothrow__))
and __attribute__ was anywhere in headers defined to be empty, which could have meant __THROW to be empty at first place. }
Then, why socket_test cannot be parsed before #define __THROW is added to Misc/StdAfx.h ?
By the way, you can add #define __attribute__(x) at the top of socket_test.cpp to produce the situation. |
chjfth |
Posted - Oct 22 2006 : 12:37:33 AM Well, thanks. It makes the accurate answer. And I'd still like to ask how we users of VAX can know the Misc/StdAfx.h thing without asking you this question explicitly -- it is not mentioned in "Tip of the Day", nor any clue about it can be found in VAX option dialog.
I hope that implicit features like this can be presented more explicitly. Thank you for your efforts.
|
feline |
Posted - Oct 21 2006 : 1:25:02 PM VA is designed to parse all of the #define code, ignoring the #if lines, so that it can offer you help with code that is not currently being compiled, due to your pre-processor settings.
In this case the solution is to edit the file "C:\\Program Files\\Visual Assist X\\Misc\\StdAfx.h" and add the line:
#define __THROW
at the end. Once you have done this tell VA to rebuild its symbol datatabase: VA Options -> Performance -> General -> Rebuild symbol databases
and restart the IDE. This file is parsed before any source code. Just be aware that you will have to reapply your edit to StdAfx.h after you install a new build of VA, since the installer ships with the latest version of this file. |
|
|