Re: [ooc-compiler] Module/Procedure name in a constant
Brought to you by:
mva
|
From: Stewart G. <sgr...@us...> - 2007-03-16 03:29:41
|
Hi Fitz, OO2C has a mechanism for declaring functions that do "raw" calls to C code. These calls don't assume that there is a "C" declaration for the function - they just emit the call code and let the C compiler take care of the rest. This is used in modules like RealMath to do fast calls to math functions. It works via procedure renaming. When the compiler sees a particular type of name, it just emits the procedure alias when it calls the function. For example, in RealMath we have this: PROCEDURE ["(float)sin"] sin* (x: REAL): REAL; So when you call RealMath.sin it just emits "(float)sin" allowing the type cast to be done at call-time, rather than in a separate function. So here's what you need to do - its a bit of a hack, but works. You can use this mechanism to get the values of constants and variables, but you need to remove the actual parameters that the compiler passes to the function. Add the following to /usr/local/lib/oo2c/src/__oo2c.h #define NOPARAMS() Now you can use the "raw calls" mechanism to get the values that you want. The variable _mid is the descriptor of the current module, so you can get the module name, or the descriptor itself like this: PROCEDURE ["(_mid.name)NOPARAMS"] ModName* () : RT0.Name; PROCEDURE ["(&_mid)NOPARAMS"] Module* () : RT0.Module; The following gives you the source file name, function name and line number. Of course, these are for the "C" source code emitted by OOC, but you might be able to maniuplate the values to give you what you want (eg. to strip OOC's function name decorations giving you the Oberon-2 function name). I don't know a good way to get the Oberon-2 source-code context without actually halting the program (eg. ASSERT, or run-time exception). PROCEDURE ["(__FILE__)NOPARAMS"] File* () : RT0.Name; PROCEDURE ["(__FUNCTION__)NOPARAMS"] Func* () : RT0.Name; PROCEDURE ["(__LINE__)NOPARAMS"] Line* () : LONGINT; Attached is some code for you to try. Hope this helps. Cheers, Stewart Fitzpatrick, Patrick-p98785 wrote: > Hi gang, > > Is there some way for me to get the Module and Procedure name into a > constant/string like this: > > String Module = __MODULE__; > > So I can Out.String( "You have entered Module: " ); Out.String( Module > ); Out.Ln; > > TIA. > > Have a great day, > Fitz > Rational Support > (480) 441-1805 > > > >> "This email message is for the sole use of the intended >>recipient(s) and may contain GDC4S confidential or privileged >>information. Any unauthorized review, use, disclosure or distribution >>is prohibited. If you are not an intended recipient, please contact >>the sender by reply email and destroy all copies of the original >>message." >> >> > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > ------------------------------------------------------------------------ > > _______________________________________________ > ooc-compiler mailing list > ooc...@li... > https://lists.sourceforge.net/lists/listinfo/ooc-compiler |