Lazarus

Miscellaneous => Suggestions => Topic started by: joho on September 26, 2017, 12:17:31 am

Title: $I or $INCLUDE : Include compiler info
Post by: joho on September 26, 2017, 12:17:31 am

Could we have %FUNC% or %FUNCTION% here too?

https://www.freepascal.org/docs-html/prog/progsu41.html
Title: Re: $I or $INCLUDE : Include compiler info
Post by: Almir.Bispo on September 26, 2017, 04:04:37 am
Yes ! You can put a full proggram there (and function too) like this:
This is on txt file
Code: Pascal  [Select][+][-]
  1. procedure Hello;
  2. begin
  3. showmessage('Hello !');
  4. end;
  5.  

on your main program call so:
Code: Pascal  [Select][+][-]
  1. begin
  2. {$i fullpath\your_hello_code.txt}
  3. end;
  4.  

My project (Nosql database manager) uses ILDE-Pascal like this:
{$i cql_to_pascal.txt}
 and it calls all function on ILDE-Pascal
To know more :http://adltecnologia.blogspot.com.br/p/macros.html (http://adltecnologia.blogspot.com.br/p/macros.html)
Title: Re: $I or $INCLUDE : Include compiler info
Post by: molly on September 26, 2017, 10:28:04 am
@joho:
Did you mean like the name of the procedure or function ?

That already exists in trunk, see here (https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&revision=30873) it is used with %CURRENTROUTINE%

Title: Re: $I or $INCLUDE : Include compiler info
Post by: molly on September 26, 2017, 11:13:21 am
@Almir.Bispo
Excellent example on how to get frustrated with include files   ;D
Title: Re: $I or $INCLUDE : Include compiler info
Post by: joho on September 26, 2017, 05:35:29 pm
@joho:
Did you mean like the name of the procedure or function ?

That already exists in trunk, see here (https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&revision=30873) it is used with %CURRENTROUTINE%

Yes, the name of the procedure/function.

__LINE__
__FILE__
__CLASS__
__FUNC__
__CAR__
__DRINK__


and other current life variables ;)
Title: Re: $I or $INCLUDE : Include compiler info
Post by: molly on September 27, 2017, 09:30:46 am
Well... line is already present (twofold), file (unit name) and class could probably be solved with rtti. Procedure/function name as well as line number can be obtained at runtime as well.

Now, car and drink.... That would be an interesting statistic... what was the programmer drinking and/or eating at the time the code was implemented and what vehicle (if any) was used during that process. That would give some managers a severe headache :D
Title: Re: $I or $INCLUDE : Include compiler info
Post by: joho on September 27, 2017, 10:48:24 am
Well... line is already present (twofold), file (unit name) and class could probably be solved with rtti. Procedure/function name as well as line number can be obtained at runtime as well.

Now, car and drink.... That would be an interesting statistic... what was the programmer drinking and/or eating at the time the code was implemented and what vehicle (if any) was used during that process. That would give some managers a severe headache :D

1) But this requires RTTI to be "enabled", yes? A static, at-compile-time-method, may be preferred at times.

2) It would explain a lot of things I think :)

Title: Re: $I or $INCLUDE : Include compiler info
Post by: marcov on September 27, 2017, 10:51:43 am
Well... line is already present (twofold), file (unit name) and class could probably be solved with rtti. Procedure/function name as well as line number can be obtained at runtime as well.

Now, car and drink.... That would be an interesting statistic... what was the programmer drinking and/or eating at the time the code was implemented and what vehicle (if any) was used during that process. That would give some managers a severe headache :D

Read the help, if not a known builtin, it is assumed to be an environment variable. Make sure your drinking status and vehicle choice are correctly entered into the relevant environment variables. One could create a small lazarus extension to do so and update them before executing the compiler to make it easier.

p.s. class is hard to do statically, unless you mean only current scope.
Title: Re: $I or $INCLUDE : Include compiler info
Post by: joho on September 27, 2017, 10:59:14 am
(Current scope)
Title: Re: $I or $INCLUDE : Include compiler info
Post by: Almir.Bispo on September 27, 2017, 04:09:31 pm

"Excellent example on how to get frustrated with include files "

This include file function was created for this purpose.
Title: Re: $I or $INCLUDE : Include compiler info
Post by: molly on September 27, 2017, 05:46:01 pm
@Almir.Bispo:

I think you misunderstood me.

Your example expands to:

Code: Pascal  [Select][+][-]
  1. begin
  2.   procedure Hello;
  3.   begin
  4.     showmessage('Hello !');
  5.   end;
  6. end;
  7.  

.. and which doesn't compile as was intended.  :'(

Code: [Select]
your_hello_code.inc(1,1) Error: Illegal expression
your_hello_code.inc(1,11) Fatal: Syntax error, ";" expected but "identifier HELLO" found
Fatal: Compilation aborted
Title: Re: $I or $INCLUDE : Include compiler info
Post by: molly on September 27, 2017, 06:06:20 pm
Read the help, if not a known builtin, it is assumed to be an environment variable.
Thank you for reminding me to that.

Quote
Make sure your drinking status and vehicle choice are correctly entered into the relevant environment variables. One could create a small lazarus extension to do so and update them before executing the compiler to make it easier.
You are right, i did not considered that. That could indeed work, although perhaps a bit clumsy because eating and traveling habits changes during a hard-days work.

So what to put where exactly ? Would be nice to pinpoint whatever was consumed or traveled during the implementation and/or changing of a routine. Perhaps a small db where user can keep track of what is currently consumed or what travel-method is being used. Date and time could then f.i. linked to svn commits .... wasn't there someone working on statistics integration for Lazarus ?  8-)
TinyPortal © 2005-2018