- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Models/CCA/Io/Xmpl/XmplParser.h

    00001 //------------------------------------------------------------------------------
    00002 // Copyright 2001 The Johns Hopkins University Applied Physics Laboratory
    00003 // All Rights Reserved
    00004 //
    00005 // This software is provided "as is".  Neither the authors nor JHU/APL assume
    00006 // any responsibility for damages resulting from the use of this software.
    00007 //------------------------------------------------------------------------------
    00008 // Last updated: $Date: 2005-05-03 20:30:14 -0400 (Tue, 03 May 2005) $
    00009 // Revision:     $Revision: 5012 $
    00010 //------------------------------------------------------------------------------
    00011
    00012 #ifndef _XMPL_PARSER_H_
    00013 #define _XMPL_PARSER_H_
    00014
    00015 //------------------------------------------------------------------------------
    00016 // Includes
    00017 //------------------------------------------------------------------------------
    00018 #include <iostream>
    00019 #include <map>
    00020 #include <string>
    00021 #include <vector>
    00022 #include <cstdio>
    00023
    00024 #include <xercesc/sax/SAXException.hpp>
    00025 #include <xercesc/sax/SAXParseException.hpp>
    00026 #include <xercesc/sax/ErrorHandler.hpp>
    00027 #include <xercesc/parsers/XercesDOMParser.hpp>
    00028 #include <xercesc/dom/deprecated/DOMString.hpp>
    00029 #include <xercesc/dom/DOM.hpp>
    00030 #include <xercesc/util/XercesDefs.hpp>
    00031 #include <xercesc/util/XMLString.hpp>
    00032 #include <xercesc/util/PlatformUtils.hpp>
    00033
    00034 #include <Mers/Models/CCA/CCAModel.h>
    00035
    00036 #include "ParsingException.h"
    00037 #include "VariableInfoMap.h"
    00038
    00039 //------------------------------------------------------------------------------
    00040 // Namespaces
    00041 //------------------------------------------------------------------------------
    00042 using namespace std;
    00043 using namespace xercesc;
    00044
    00052 class XmplParser
    00053 {
    00054 private:
    00056         class MyErrorHandler : public DOMErrorHandler
    00057           {
    00058         public:
    00060                 MyErrorHandler() {}
    00061
    00063                 ~MyErrorHandler() {}
    00064
    00065                 // implementation of ErrorHandler
    00066                 bool handleError(const DOMError& domError);
    00067         };
    00068
    00070         friend class XmplParser::MyErrorHandler;
    00071
    00078         class AncestorList
    00079         {
    00080         private:
    00081                 vector<string> _ancestors;
    00082                 bool _fullyQualify;
    00083         public:
    00084                 enum qualificationLevel {ROOT = 0, ALL};
    00085
    00086                 AncestorList(bool fullyQualify = true)
    00087                         : _fullyQualify(fullyQualify) {}
    00088                 ~AncestorList() {}
    00089
    00090                 void unit_test();
    00091
    00092                 void push(const string ancestor);
    00093                 string peek() const;
    00094                 string pop();
    00095                 void popToRoot();
    00096                 string root() const;
    00097                 bool isEmpty() const;
    00098                 string qualify(const string & child, qualificationLevel level=ALL) const;
    00099         };
    00100
    00106         static int _numInstances;
    00107
    00109         MyErrorHandler _xmlErrorHandler;
    00110
    00112         DOMBuilder *_parser;
    00113
    00114
    00115 public:
    00117         XmplParser();
    00118
    00120         virtual ~XmplParser();
    00121
    00130         VariableInfoMap generateTitanModel(Mers::Models::CCA::CCAModel &titanModel,
    00131                         const string & xmplFile,
    00132                         const string & hrnFile,
    00133                         const string & iniFile)
    00134                 throw (ParsingException);
    00135
    00136 private:
    00137
    00138         class ParsedLiteral {
    00139         public:
    00140                 bool isPositive;
    00141                 bool valIsVariable;
    00142                 string var;
    00143                 string val;
    00144         };
    00145
    00151         static string getString(const XMLCh* const xmlString);
    00152
    00158         static string getString(const DOMString* const domString);
    00159
    00165         static string getString(const DOMString & domString);
    00166
    00171         void initXMLUtils();
    00172
    00176         void terminateXMLUtils();
    00177
    00184         static void printChildren(const DOMNode* parent, int depth);
    00185
    00192         static void printNode(const DOMNode* node, int depth);
    00193
    00199         void printXMLTree(const string &filename);
    00200
    00202         void parseHarnessTree(
    00203                         const DOMNode* node,
    00204                         VariableInfoMap &variableMap)
    00205                 throw (ParsingException);
    00206
    00208         string parseHarnessObservable(
    00209                         const DOMNode* node,
    00210                         VariableInfoMap &variableMap)
    00211                 throw (ParsingException);
    00212
    00214         string parseHarnessCommand(
    00215                         const DOMNode* node,
    00216                         VariableInfoMap &variableMap)
    00217                 throw (ParsingException);
    00218
    00220         void parseInitializationTree(
    00221                         const DOMNode* node,
    00222                         VariableInfoMap &initialModesMap)
    00223                 throw (ParsingException);
    00224
    00226         string parseInitializationAssignment(
    00227                         const DOMNode* node,
    00228                         VariableInfoMap &initialModesMap)
    00229                 throw (ParsingException);
    00230
    00237         void parseModelTree(
    00238                         const DOMNode* _node,
    00239                         Mers::Models::CCA::CCAModel &_model,
    00240                         VariableInfoMap &_variableMap,
    00241                         AncestorList &_ancestors)
    00242                 throw (ParsingException);
    00243
    00250         string parseComponentInstance(
    00251                         const DOMNode* _node)
    00252                 throw (ParsingException);
    00253
    00260         string parseComponentTree(
    00261                         const DOMNode* _node,
    00262                         Mers::Models::CCA::CCAModel &_model,
    00263                         AncestorList &_ancestors,
    00264                         VariableInfoMap &_variableMap)
    00265                 throw (ParsingException);
    00266
    00268         void createDomainConstraint(
    00269                   const string &_var,
    00270                   Mers::Models::CCA::CCAModel &_model)
    00271           throw (ParsingException);
    00272
    00280         string parseEnumeration(
    00281                         const DOMNode* node,
    00282                         Mers::Models::CCA::CCAModel &_model,
    00283                         const AncestorList &_ancestors)
    00284                 throw (ParsingException);
    00285
    00293         string parseMode(
    00294                         const DOMNode* node,
    00295                         Mers::Models::CCA::CCAModel &_model,
    00296                         const AncestorList &_ancestors)
    00297                 throw (ParsingException);
    00298
    00307         string parseVariable(
    00308                         const DOMNode* node,
    00309                         Mers::Models::CCA::CCAModel &_model,
    00310                         VariableInfoMap &_variableMap,
    00311                         const AncestorList &_ancestors,
    00312                         const string &_modeVariableName)
    00313                 throw (ParsingException);
    00314
    00316         string parseTransition(
    00317                         const DOMNode* _node,
    00318                         Mers::Models::CCA::CCAModel &_model,
    00319                         const AncestorList &_ancestors,
    00320                         const string &_modeVariableName)
    00321                 throw (ParsingException);
    00322
    00330         Mers::Models::CCA::CCAClause invertClause(Mers::Models::CCA::CCAClause guard);
    00331
    00335         bool parseClause(
    00336                         const DOMNode* _node,
    00337                         const Mers::Models::CCA::CCAModel &_model,
    00338                         const AncestorList &_ancestors,
    00339                         const string &_modeVariableName,
    00340                         vector<Mers::Models::CCA::CCAClause> &_clauses,
    00341                         Mers::Models::CCA::CCAClause::ClauseType _clauseType = Mers::Models::CCA::CCAClause::DISJUNCTIVE)
    00342
    00343                 throw (ParsingException);
    00344
    00348         bool parseClause(
    00349                         const DOMNode* _node,
    00350                         const Mers::Models::CCA::CCAModel &_model,
    00351                         const AncestorList &_ancestors,
    00352                         const string &_modeVariableName,
    00353                         vector<Mers::Models::CCA::CCAClause> &_clauses,
    00354                         string &_modeValueAssociation,
    00355                         bool _inspectForModeAssociation = true,
    00356                         Mers::Models::CCA::CCAClause::ClauseType _clauseType = Mers::Models::CCA::CCAClause::DISJUNCTIVE)
    00357                 throw (ParsingException);
    00358
    00360         ParsedLiteral parseLiteral(
    00361                         const DOMNode* _node,
    00362                         const AncestorList &_ancestors,
    00363                         const Mers::Models::CCA::CCAModel &_model)
    00364                 throw (ParsingException);
    00365
    00367         Mers::Models::CCA::CCAAssignment createSimpleLiteral(
    00368                 bool _isPositive,
    00369                 const string &_var,
    00370                 const string &_val,
    00371                 const Mers::Models::CCA::CCAModel &_model);
    00372
    00374         vector<Mers::Models::CCA::CCAClause> createCompoundLiteral(
    00375                         bool isPositive,
    00376                         const string &_lhVar,
    00377                         const string &_rhVar,
    00378                         const Mers::Models::CCA::CCAModel &_model)
    00379                 throw (ParsingException);
    00380
    00388         string getAttribute(const DOMNode* _node,
    00389                         const string &_attributeName,
    00390                         bool _failSilent = false)
    00391                 throw (ParsingException);
    00392
    00393         static const string VARIABLE_TYPE_TAG;
    00394         static const string MODE_TAG;
    00395         static const string VARIABLE_TAG;
    00396         static const string TRANSITION_TAG;
    00397         static const string CLAUSE_TAG;
    00398         static const string COMPONENT_INSTANCE_TAG;
    00399         static const string COMPONENT_TAG;
    00400         static const string TERM_TAG;
    00401
    00402 };
    00403
    00404 #endif