gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
FunctionManager.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #include <map>
7 #include <stack>
8 #include <string>
9 #include "FunctionManager.h"
10 
12 {
13  public:
14  int lineno;
15  fpos_t position;
16  FILE *file;
17  std::string filename;
18 };
19 
21 {
22  public:
23  std::stack<File_Position> s;
24 };
25 
27 {
28  public:
29  std::map<std::string, File_Position> m;
30 };
31 
33 
35 {
38 }
39 
41 {
42  if(!instance) {
44  }
45  return instance;
46 }
47 
49 {
50  functions->m.clear();
51 }
52 
53 int FunctionManager::enterFunction(const std::string &name, FILE **f,
54  std::string &filename, int &lno) const
55 {
56  if(functions->m.find(name) == functions->m.end())
57  return 0;
58  File_Position fpold;
59  fpold.lineno = lno;
60  fpold.filename = filename;
61  fpold.file = *f;
62  fgetpos(fpold.file, &fpold.position);
63  calls->s.push(fpold);
64  File_Position fp = (functions->m)[name];
65  fsetpos(fp.file, &fp.position);
66  *f = fp.file;
67  filename = fp.filename;
68  lno = fp.lineno;
69  return 1;
70 }
71 
72 int FunctionManager::leaveFunction(FILE **f, std::string &filename, int &lno)
73 {
74  if(!calls->s.size())
75  return 0;
76  File_Position fp;
77  fp = calls->s.top();
78  calls->s.pop();
79  fsetpos(fp.file, &fp.position);
80  *f = fp.file;
81  filename = fp.filename;
82  lno = fp.lineno;
83  return 1;
84 }
85 
86 int FunctionManager::createFunction(const std::string &name, FILE *f,
87  const std::string &filename, int lno)
88 {
89  if(functions->m.find(name) != functions->m.end())
90  return 0;
91  File_Position fp;
92  fp.file = f;
93  fp.filename = filename;
94  fp.lineno = lno;
95  fgetpos(fp.file, &fp.position);
96  (functions->m)[name] = fp;
97  return 1;
98 }
FunctionManager::calls
FunctionManagerStack * calls
Definition: FunctionManager.h:20
File_Position::position
fpos_t position
Definition: FunctionManager.cpp:15
FunctionManagerMap
Definition: FunctionManager.cpp:27
File_Position::lineno
int lineno
Definition: FunctionManager.cpp:14
File_Position::filename
std::string filename
Definition: FunctionManager.cpp:17
LegendrePolynomials::f
void f(int n, double u, double *val)
Definition: orthogonalBasis.cpp:77
FunctionManager::Instance
static FunctionManager * Instance()
Definition: FunctionManager.cpp:40
FunctionManager::FunctionManager
FunctionManager()
Definition: FunctionManager.cpp:34
FunctionManager::createFunction
int createFunction(const std::string &name, FILE *f, const std::string &filename, int lineno)
Definition: FunctionManager.cpp:86
FunctionManagerStack::s
std::stack< File_Position > s
Definition: FunctionManager.cpp:23
FunctionManager.h
FunctionManager::clear
void clear()
Definition: FunctionManager.cpp:48
FunctionManager::instance
static FunctionManager * instance
Definition: FunctionManager.h:22
FunctionManager::functions
FunctionManagerMap * functions
Definition: FunctionManager.h:19
FunctionManagerMap::m
std::map< std::string, File_Position > m
Definition: FunctionManager.cpp:29
File_Position
Definition: FunctionManager.cpp:12
FunctionManager::leaveFunction
int leaveFunction(FILE **f, std::string &filename, int &lineno)
Definition: FunctionManager.cpp:72
FunctionManager::enterFunction
int enterFunction(const std::string &name, FILE **f, std::string &filename, int &lineno) const
Definition: FunctionManager.cpp:53
File_Position::file
FILE * file
Definition: FunctionManager.cpp:16
FunctionManager
Definition: FunctionManager.h:18
FunctionManagerStack
Definition: FunctionManager.cpp:21