[fpc-devel] Macro Patch

2011-05-10 Thread Joerg Schuelke
This third revision with additional %FUNC% macro and 'unknown' strings
changed to internalerror.

Regards
Jörg
Index: scanner.pas
===
--- scanner.pas	(Revision 17417)
+++ scanner.pas	(Arbeitskopie)
@@ -237,7 +237,7 @@
   systems,
   switches,
   symbase,symtable,symtype,symsym,symconst,symdef,defutil,
-  fmodule;
+  procinfo,fmodule;
 
 var
   { dictionaries with the supported directives }
@@ -1712,11 +1712,33 @@
  hs:=getdatestr
else
 if hs='FILE' then
- hs:=current_module.sourcefiles.get_file_name(current_filepos.fileindex)
+ begin
+   hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+   if assigned(hp) then hs:=hp.name^ else internalerror(201105101)
+ end
else
 if hs='LINE' then
- hs:=tostr(current_filepos.line)
+ begin
+   hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+   if assigned(hp) then hs:=tostr(hp.saveline_no) else internalerror(201105102)
+ end
else
+   if hs='PATH' then
+begin
+  hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+  if assigned(hp) then hs:=hp.path^ else internalerror(201105103);
+  if hs='' then hs:=CurDirRelPath(target_info)
+end
+   else
+   if hs='FUNC' then
+begin
+  if assigned(current_procinfo) then
+   if assigned(current_procinfo.procdef) then
+if assigned(current_procinfo.procdef.procsym) then
+  hs:=current_procinfo.procdef.procsym.realname
+else internalerror(201105104);
+end
+   else
 if hs='FPCVERSION' then
  hs:=version_string
else
@@ -3473,7 +3495,7 @@
mac.is_used:=true;
inc(yylexcount);
insertmacro(pattern,mac.buftext,mac.buflen,
- mac.fileinfo.line,mac.fileinfo.fileindex);
+ current_scanner.line_no,current_scanner.inputfile.ref_index);
  { handle empty macros }
if c=#0 then
  reload;
Index: fmodule.pas
===
--- fmodule.pas	(Revision 17417)
+++ fmodule.pas	(Arbeitskopie)
@@ -235,6 +235,7 @@
 function get_source_file(moduleindex,fileindex : longint) : tinputfile;
 procedure addloadedunit(hp:tmodule);
 function find_module_from_symtable(st:tsymtable):tmodule;
+function ascend_from_macros(f:tinputfile) : tinputfile;
 
 
 implementation
@@ -336,6 +337,13 @@
   end;
 
 
+function ascend_from_macros(f:tinputfile) : tinputfile;
+  begin
+while assigned(f) and f.is_macro do f:=f.next;
+ascend_from_macros:=f;
+  end;
+
+
 procedure addloadedunit(hp:tmodule);
   begin
 hp.moduleid:=loaded_units.count;
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


[fpc-devel] Macro Patch

2011-05-09 Thread Joerg Schuelke
Some days ago I stated that the build-in macros %LINE% and %FILE%, used
inside a macro, expand to the wrong (in my opinion) info from the
defining context and not to those from the expanding context.

That makes them nearly useless, because using them inside a macro for
debugging purposes is their main benefit.

I wrote two small changes for scanner.pas and fmodule.pas which solve
the problem. Maybe the devils are interested in applying it, or
something similar.

The 'unknown' from my changes are in real Internal-Errors, which should
never occur. But changing this let's trying him to find an Environment-
Variable with the same name, which gives a Warning. So ...

Best regards
Jörg
Index: compiler/fmodule.pas
===
--- compiler/fmodule.pas	(Revision 17417)
+++ compiler/fmodule.pas	(Arbeitskopie)
@@ -235,6 +235,7 @@
 function get_source_file(moduleindex,fileindex : longint) : tinputfile;
 procedure addloadedunit(hp:tmodule);
 function find_module_from_symtable(st:tsymtable):tmodule;
+function ascend_from_macros(f:tinputfile) : tinputfile;
 
 
 implementation
@@ -336,6 +337,13 @@
   end;
 
 
+function ascend_from_macros(f:tinputfile) : tinputfile;
+  begin
+while assigned(f) and f.is_macro do f:=f.next;
+ascend_from_macros:=f;
+  end;
+
+
 procedure addloadedunit(hp:tmodule);
   begin
 hp.moduleid:=loaded_units.count;
Index: compiler/scanner.pas
===
--- compiler/scanner.pas	(Revision 17417)
+++ compiler/scanner.pas	(Arbeitskopie)
@@ -1712,11 +1712,24 @@
  hs:=getdatestr
else
 if hs='FILE' then
- hs:=current_module.sourcefiles.get_file_name(current_filepos.fileindex)
+ begin
+   hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+   if assigned(hp) then hs:=hp.name^ else hs:='unknown'
+ end
else
 if hs='LINE' then
- hs:=tostr(current_filepos.line)
+ begin
+   hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+   if assigned(hp) then hs:=tostr(hp.saveline_no) else hs:='unknown'
+ end
else
+if hs='PATH' then
+ begin
+   hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+   if assigned(hp) then hs:=hp.path^ else hs:='unknown';
+   if hs='' then hs:=CurDirRelPath(target_info)
+ end
+   else
 if hs='FPCVERSION' then
  hs:=version_string
else
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


[fpc-devel] Macro Patch

2011-05-09 Thread Joerg Schuelke
A little further changing is needed to let it work as suspected. Even
if the macro is included via include file. In my first writing I didn't
recognize that the calling of insertmacro for _ID token is done with
mac.fileinfo.line and .fileindex, which is the point of definition.

Changed to current_scanner.line_no and
current_scanner.inputfile.ref_index.

Is this a problem for error recognition?, I think not, because the info
from the defining context is saved in the tmacro class.

Best regards
Jörg
Index: compiler/fmodule.pas
===
--- compiler/fmodule.pas	(Revision 17417)
+++ compiler/fmodule.pas	(Arbeitskopie)
@@ -235,6 +235,7 @@
 function get_source_file(moduleindex,fileindex : longint) : tinputfile;
 procedure addloadedunit(hp:tmodule);
 function find_module_from_symtable(st:tsymtable):tmodule;
+function ascend_from_macros(f:tinputfile) : tinputfile;
 
 
 implementation
@@ -336,6 +337,13 @@
   end;
 
 
+function ascend_from_macros(f:tinputfile) : tinputfile;
+  begin
+while assigned(f) and f.is_macro do f:=f.next;
+ascend_from_macros:=f;
+  end;
+
+
 procedure addloadedunit(hp:tmodule);
   begin
 hp.moduleid:=loaded_units.count;
Index: compiler/scanner.pas
===
--- compiler/scanner.pas	(Revision 17417)
+++ compiler/scanner.pas	(Arbeitskopie)
@@ -1712,11 +1712,24 @@
  hs:=getdatestr
else
 if hs='FILE' then
- hs:=current_module.sourcefiles.get_file_name(current_filepos.fileindex)
+ begin
+   hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+   if assigned(hp) then hs:=hp.name^ else hs:='unknown'
+ end
else
 if hs='LINE' then
- hs:=tostr(current_filepos.line)
+ begin
+   hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+   if assigned(hp) then hs:=tostr(hp.saveline_no) else hs:='unknown'
+ end
else
+if hs='PATH' then
+ begin
+   hp:=ascend_from_macros(current_module.sourcefiles.get_file(current_filepos.fileindex));
+   if assigned(hp) then hs:=hp.path^ else hs:='unknown';
+   if hs='' then hs:=CurDirRelPath(target_info)
+ end
+   else
 if hs='FPCVERSION' then
  hs:=version_string
else
@@ -3473,7 +3486,7 @@
mac.is_used:=true;
inc(yylexcount);
insertmacro(pattern,mac.buftext,mac.buflen,
- mac.fileinfo.line,mac.fileinfo.fileindex);
+ current_scanner.line_no,current_scanner.inputfile.ref_index);
  { handle empty macros }
if c=#0 then
  reload;
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel