LCOV - code coverage report
Current view: top level - builds/barbot/Cosmos/src/ModelGenerator/LhaParser - Lha-Reader.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 4 100.0 %
Date: 2021-06-16 15:43:28 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*******************************************************************************
       2             :  *                                                                             *
       3             :  * Cosmos:(C)oncept et (O)utils (S)tatistique pour les (Mo)deles               *
       4             :  * (S)tochastiques                                                             *
       5             :  *                                                                             *
       6             :  * Copyright (C) 2009-2012 LSV & LACL                                          *
       7             :  * Authors: Paolo Ballarini & Hilal Djafri                                     *
       8             :  * Website: http://www.lsv.ens-cachan.fr/Software/cosmos                       *
       9             :  *                                                                             *
      10             :  * This program is free software; you can redistribute it and/or modify        *
      11             :  * it under the terms of the GNU General Public License as published by        *
      12             :  * the Free Software Foundation; either version 3 of the License, or           *
      13             :  * (at your option) any later version.                                         *
      14             :  *                                                                             *
      15             :  * This program is distributed in the hope that it will be useful,             *
      16             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of              *
      17             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
      18             :  * GNU General Public License for more details.                                *
      19             :  *                                                                             *
      20             :  * You should have received a copy of the GNU General Public License along     *
      21             :  * with this program; if not, write to the Free Software Foundation, Inc.,     *
      22             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 *
      23             :  *******************************************************************************
      24             :  */
      25             : 
      26             : #ifndef LHA_READER_HH
      27             : #define LHA_READER_HH
      28             : #include <string>
      29             : #include <map>
      30             : #include <set>
      31             : #include <vector>
      32             : #include <algorithm>
      33             : 
      34             : #include "../parameters.hpp"
      35             : #include "Lha-parser.hh"
      36             : #include "../HaslFormula.hpp"
      37             : #include "../GspnParser/Gspn-Reader.hpp"
      38             : 
      39             : 
      40             : using namespace std;
      41             : 
      42             : struct _LhaEdge {
      43             :     unsigned int Index;
      44             :     unsigned int Source;
      45             :     unsigned int Target;
      46             : };
      47             : typedef struct _LhaEdge LhaEdge;
      48             : 
      49             : 
      50             : #define CONTINIOUS_VARIABLE 0
      51             : #define DISCRETE_VARIABLE 1
      52             : #define COLOR_VARIABLE 2
      53             : #define INT_INDEXED_DISC_ARRAY 3
      54             : #define COLOR_INDEXED_ARRAY 4
      55             : 
      56          66 : struct variables {
      57             :         vector<int> type;
      58             :         vector<string> label;
      59             :         vector<double> initialValue;
      60             :         vector<size_t> colorDomain;
      61             :     vector<bool> isTraced;
      62        1344 :         size_t find(const string &st){
      63        1344 :                 return (std::find(label.begin(), label.end(), st) - label.begin());
      64             :         };
      65             : };
      66             : 
      67             : bool is_simple(const string&);
      68             : 
      69          33 : struct LhaType {
      70             :         GspnType *MyGspn;
      71             :         LhaType(GspnType &Mspn);
      72             :     
      73             :         string label;
      74             :     size_t NbLoc; // number of locations
      75             :     bool isDeterministic;
      76             : 
      77             :     set <unsigned int, less<unsigned int> > InitLoc; // initial locations
      78             :     set <unsigned int, less<unsigned int> > FinalLoc; // final locations
      79             :         
      80             :     map <string, int> LocIndex; //for a given Location label returns its index among {0, 1, ..., NLoc-1}
      81             :     vector <string> LocLabel;
      82             :     vector <string> FuncLocProperty;
      83             :         
      84             :         
      85             :     map<string, int> EdgeIndex;
      86             :     vector <LhaEdge> Edge;
      87             :     LhaEdge AnEdge;
      88             :         
      89             :     vector <string> EdgeConstraints;
      90             :     vector < set<string> > EdgeActions; //return the set of actions associated for a given edge e, EdgeActions[e]{a1,a2, ...}
      91             :     vector < vector < string > > FuncEdgeUpdates;
      92             :     vector < vector < string > > FuncEdgeUpdatesIndex;
      93             :     vector <string> StrEdgeUpdates;
      94             :         
      95             :         vector <string> unTimeEdgeConstraints;
      96             :     vector < vector <vector <string> > > ConstraintsCoeffs;
      97             :     vector < vector <string> > ConstraintsRelOp;
      98             :     vector < vector <string> > ConstraintsConstants;
      99             :         
     100             :         
     101             :         
     102             :     vector < set <int> > Out_S_Edges; // for a given location l returns the set of synchronizing edges  starting from l
     103             :     vector < set <int> > Out_A_Edges; // for a given location l returns the set of autonomous edges  starting from l
     104             :     vector < vector < set <int> > > ActionEdges; // return the set of edges starting from location cl such that action a is an action for these edges, ActionsLoc[cl][a]={e1, e2, ...}
     105             :         
     106             :     size_t NbVar;
     107             :         variables Vars;
     108             :     /*vector <double> Var; // Var[i] initial value of the variable indexed by i
     109             :          map<string, int> VarIndex; //for a given variable label return its index among {0, 1, ..., NbVar-1}
     110             :          vector <string> VarLabel;*/
     111             :         
     112             :     vector < vector <string> > FuncFlow;
     113             :     vector < vector <string> > StrFlow;
     114             :         
     115             :     map <string, int> PlaceIndex; // for a given place label return its index among {0, 1, ..., pl-1}
     116             :     map <string, int> TransitionIndex; // for a given transition label return its index among {0, 1, ..., tr-1}
     117             :         
     118             :     map<string, int> LinearForm;
     119             :     vector<bool> SimplyUsedLinearForm;
     120             :     vector<int> LhaFuncArg;
     121             :     vector<string> LhaFuncType;
     122             :     vector<string> Algebraic;
     123             :     vector<string> FinalStateCond;
     124             :         double ConfidenceLevel;
     125             :         vector<string> HASLname;
     126             :         vector<HaslFormulasTop*> HASLtop;
     127             :         
     128             :     map <std::string, int> LhaIntConstant; //contains constants defined like int
     129             :     map <std::string, double> LhaRealConstant; //contains constants defined like double and constants defined linke int
     130             :     map <std::string, int> LhaFunction;
     131             :         
     132             :     map <std::string, int> LhaIntHybrid;
     133             :     map <std::string, double> LhaRealHybrid; //defined as LhaIntconstant and LhaReadConstant but for hybrid variables.
     134             : };
     135             : 
     136             : 
     137             : #define LHA_DECL                                            \
     138             : lha::Lha_parser::token_type                         \
     139             : lhalex (lha::Lha_parser::semantic_type* lhalval,      \
     140             : lha::Lha_parser::location_type* lhalloc,      \
     141             : Lha_Reader& Reader)
     142             : 
     143             : LHA_DECL;
     144             : 
     145             : class Lha_Reader {
     146             : public:
     147             :     Lha_Reader(GspnType &,parameters&);
     148             :     virtual ~Lha_Reader();
     149             :         
     150             :     LhaType MyLha;
     151             :         
     152             :         
     153             :         void error(const lha::location& l, const std::string& m);
     154             :         
     155             :         //!< Parse a string of an LHA.
     156             :         int parse(std::string&);
     157             :         
     158             :         //!< Parse a file in the lha file format.
     159             :     int parse_file(parameters&);
     160             :         
     161             :         //!< Parse a file in the GrML file format.
     162             :         int parse_gml_file(parameters&);
     163             :         
     164             :         //!< generate code for the LHA.
     165             :         void WriteFile(parameters&)const;
     166             :     void writeDotFile(const std::string &file)const;
     167             :     
     168             :         
     169             :         parameters P;
     170             : private:
     171             :     void scan_begin();
     172             :     void scan_end();
     173             :     void scan_expression(const string&);
     174             :         
     175             :     bool trace_scanning;
     176             :         
     177             :     string funDecl(const string &)const;
     178             :         
     179             :     string InvRelOp(const string &)const;
     180             :         
     181             :     bool trace_parsing;
     182             :         
     183             :         void error(const std::string& m);
     184             :         
     185             :     void view();
     186             : };
     187             : #endif

Generated by: LCOV version 1.13