From ce2ab587d0ae2a0e5c92312aa9e6a6b50d0eb2df Mon Sep 17 00:00:00 2001 From: Jean-Francois Remacle <jean-francois.remacle@uclouvain.be> Date: Thu, 7 Dec 2000 16:24:59 +0000 Subject: [PATCH] Line numbers are now correct --- Parser/FunctionManager.cpp | 11 ++++++++--- Parser/FunctionManager.h | 6 +++--- Parser/Gmsh.tab.cpp | 8 ++++---- Parser/Gmsh.y | 8 ++++---- Parser/Gmsh.yy.cpp | 2 +- examples/function.geo | 2 ++ 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Parser/FunctionManager.cpp b/Parser/FunctionManager.cpp index 9c9dc8e713..d31ec25c84 100644 --- a/Parser/FunctionManager.cpp +++ b/Parser/FunctionManager.cpp @@ -14,6 +14,7 @@ struct ltstr class File_Position { public : + int lineno; fpos_t position; FILE *file; }; @@ -46,20 +47,22 @@ FunctionManager* FunctionManager::Instance() return instance; } -bool FunctionManager::enterFunction(char *name, FILE **f) const +bool FunctionManager::enterFunction(char *name, FILE **f, int &lno) const { if(functions->m.find(name) == functions->m.end())return false; File_Position fpold; + fpold.lineno = lno; fpold.file = *f; fgetpos(fpold.file,&fpold.position); calls->s.push(fpold); File_Position fp = (functions->m)[name]; fsetpos(fp.file,&fp.position); *f = fp.file; + lno = fp.lineno; return true; } -bool FunctionManager::leaveFunction(FILE **f) +bool FunctionManager::leaveFunction(FILE **f,int &lno) { if(!calls->s.size())return false; File_Position fp; @@ -67,13 +70,15 @@ bool FunctionManager::leaveFunction(FILE **f) calls->s.pop(); fsetpos(fp.file,&fp.position); *f = fp.file; + lno = fp.lineno; return true; } -bool FunctionManager::createFunction(char *name, FILE *f) +bool FunctionManager::createFunction(char *name, FILE *f, int lno) { File_Position fp; fp.file = f; + fp.lineno = lno; fgetpos(fp.file,&fp.position); (functions->m)[name] = fp; return true; diff --git a/Parser/FunctionManager.h b/Parser/FunctionManager.h index 6961f6dd17..e3befed6a5 100644 --- a/Parser/FunctionManager.h +++ b/Parser/FunctionManager.h @@ -17,9 +17,9 @@ class FunctionManager static FunctionManager *instance; public : static FunctionManager* Instance(); - bool enterFunction (char *name, FILE **f) const; - bool createFunction (char *name, FILE *f); - bool leaveFunction (FILE **f); + bool enterFunction (char *name, FILE **f, int &) const; + bool createFunction (char *name, FILE *f, int); + bool leaveFunction (FILE **f, int &); }; #endif diff --git a/Parser/Gmsh.tab.cpp b/Parser/Gmsh.tab.cpp index 2ca619ea49..e186dd3b05 100644 --- a/Parser/Gmsh.tab.cpp +++ b/Parser/Gmsh.tab.cpp @@ -164,7 +164,7 @@ #define tMINUSMINUS 414 #line 1 "Gmsh.y" - /* $Id: Gmsh.tab.cpp,v 1.26 2000-12-07 16:03:43 remacle Exp $ */ + /* $Id: Gmsh.tab.cpp,v 1.27 2000-12-07 16:24:58 remacle Exp $ */ #include <stdarg.h> @@ -4831,7 +4831,7 @@ case 208: case 209: #line 1743 "Gmsh.y" { - if(!FunctionManager::Instance()->leaveFunction(&yyin)) + if(!FunctionManager::Instance()->leaveFunction(&yyin,yylineno)) { vyyerror("Error while exiting function"); } @@ -4840,7 +4840,7 @@ case 209: case 210: #line 1750 "Gmsh.y" { - if(!FunctionManager::Instance()->enterFunction(yyvsp[-1].c,&yyin)) + if(!FunctionManager::Instance()->enterFunction(yyvsp[-1].c,&yyin,yylineno)) { vyyerror("Unknown Function %s",yyvsp[-1].c); } @@ -4850,7 +4850,7 @@ case 211: #line 1757 "Gmsh.y" { // skip everything until return is found - if(!FunctionManager::Instance()->createFunction(yyvsp[0].c,yyin)) + if(!FunctionManager::Instance()->createFunction(yyvsp[0].c,yyin,yylineno)) { vyyerror("Redefinition of function %s",yyvsp[0].c); } diff --git a/Parser/Gmsh.y b/Parser/Gmsh.y index 5ce893dd60..cdffecc205 100644 --- a/Parser/Gmsh.y +++ b/Parser/Gmsh.y @@ -1,4 +1,4 @@ -%{ /* $Id: Gmsh.y,v 1.26 2000-12-07 16:03:44 remacle Exp $ */ +%{ /* $Id: Gmsh.y,v 1.27 2000-12-07 16:24:58 remacle Exp $ */ #include <stdarg.h> @@ -1741,14 +1741,14 @@ Loop : } | tReturn { - if(!FunctionManager::Instance()->leaveFunction(&yyin)) + if(!FunctionManager::Instance()->leaveFunction(&yyin,yylineno)) { vyyerror("Error while exiting function"); } } | tCall tSTRING tEND { - if(!FunctionManager::Instance()->enterFunction($2,&yyin)) + if(!FunctionManager::Instance()->enterFunction($2,&yyin,yylineno)) { vyyerror("Unknown Function %s",$2); } @@ -1756,7 +1756,7 @@ Loop : | tFunction tSTRING { // skip everything until return is found - if(!FunctionManager::Instance()->createFunction($2,yyin)) + if(!FunctionManager::Instance()->createFunction($2,yyin,yylineno)) { vyyerror("Redefinition of function %s",$2); } diff --git a/Parser/Gmsh.yy.cpp b/Parser/Gmsh.yy.cpp index eac5173ed9..aa3608feb2 100644 --- a/Parser/Gmsh.yy.cpp +++ b/Parser/Gmsh.yy.cpp @@ -2,7 +2,7 @@ /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /cvsroot/gmsh/Parser/Gmsh.yy.cpp,v 1.26 2000-12-07 16:03:44 remacle Exp $ + * $Header: /cvsroot/gmsh/Parser/Gmsh.yy.cpp,v 1.27 2000-12-07 16:24:58 remacle Exp $ */ #define FLEX_SCANNER diff --git a/examples/function.geo b/examples/function.geo index 000e7e6b64..54ce6fe371 100644 --- a/examples/function.geo +++ b/examples/function.geo @@ -55,3 +55,5 @@ Line(10000) = {6,11}; Attractor Line {10000} = {1,.03,1}; Mesh.Algorithm = 2 ; // This is the new 2D anisotropic algorithm + + -- GitLab