HPCToolkit
MathMLExprParser.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 // ----------------------------------------------------------------------
48 //
49 // header file for the implementation of arithmetic evaluation of
50 // metrics
51 //
52 // ----------------------------------------------------------------------
53 
54 #ifndef profxml_MathMLExprParser_hpp
55 #define profxml_MathMLExprParser_hpp
56 
57 //************************ System Include Files ******************************
58 
59 #include <iostream>
60 #include <string>
61 
62 //************************ Xerces Include Files ******************************
63 
64 #include <xercesc/dom/DOMNode.hpp>
65 using XERCES_CPP_NAMESPACE::DOMNode;
66 
67 //************************* User Include Files *******************************
68 
70 #include <lib/prof/Metric-Mgr.hpp>
71 
72 //************************ Forward Declarations ******************************
73 
74 //****************************************************************************
75 
76 
77 // ----------------------------------------------------------------------
78 //
79 // class MathMLExprParser
80 // The expressive power of this MathMLExprParser class is determined by the
81 // kinds of nodes supported by class Prof::Metric::AExpr. Only the content
82 // markup part of the MathML is employed here. Currently, only the
83 // following is supported: (the corresponding MathML content mark up
84 // is include in the parenthesis)
85 // unary -- constant (<cn></cn>), variable (<ci></ci>) and
86 // minus (<minus/>)
87 // binary -- power (<power/>), divide (<divide/>) and minus (<minus/>)
88 // Nary -- plus (<plus/>) and times (<times/>)
89 //
90 // A sample of MathML expression is as follows:
91 // <apply>
92 // <plus/>
93 // <apply>
94 // <power/>
95 // <ci>x</ci>
96 // <cn>2</cn>
97 // </apply>
98 // <apply>
99 // <times/>
100 // <cn>4</cn>
101 // <ci>x</ci>
102 // </apply>
103 // <cn>4</cn>
104 // </apply>
105 // It is equal to: x ^ 2 + 4 * x + 4.
106 //
107 // ----------------------------------------------------------------------
108 
110 {
111 public:
112 
115 
116  // ------------------------------------------------------------
117  // Build a new MathMLExprParser object out of the specified input string.
118  // This string contains MathML expressions.
119  // -- params --
120  // inputSource: input string in XMLCh format
121  // -- exception --
122  // MathMLExprParserException could be thrown due to invalid or unsupported
123  // MathML expressions.
124  // ------------------------------------------------------------
125  static Prof::Metric::AExpr*
126  parse(DOMNode* mathMLExpr,
127  const Prof::Metric::Mgr& mMgr);
128 
129  // ------------------------------------------------------------
130  //
131  // ------------------------------------------------------------
132 #if 0
133  std::string toString() const;
134  std::ostream& dump(std::ostream& os = std::cout) const;
135 #endif
136 
137 private:
138  static Prof::Metric::AExpr*
139  buildEvalTree(DOMNode *node,
140  const Prof::Metric::Mgr& mMgr,
141  bool isNum);
142 };
143 
144 
145 
146 // ----------------------------------------------------------------------
147 // class MathMLException
148 // Exceptions thrown during the construction of MathMLExpr object or
149 // evaluation of MathMLExpr
150 // ----------------------------------------------------------------------
151 
152 #define MathML_Throw(streamArgs) DIAG_ThrowX(MathMLExprException, streamArgs)
153 
155 public:
156  MathMLExprException(const std::string x,
157  const char* filenm = NULL, unsigned int lineno = 0)
158  : Diagnostics::Exception(x, filenm, lineno)
159  { }
160 
161  virtual std::string message() const {
162  return "Math ML Exception: " + what();
163  }
164 
165 private:
166 };
167 
168 
169 
170 #endif /* profxml_MathMLExprParser_hpp */
static Prof::Metric::AExpr * parse(DOMNode *mathMLExpr, const Prof::Metric::Mgr &mMgr)
static Prof::Metric::AExpr * buildEvalTree(DOMNode *node, const Prof::Metric::Mgr &mMgr, bool isNum)
virtual std::string message() const
MathMLExprException(const std::string x, const char *filenm=NULL, unsigned int lineno=0)
cct_node_t * node
Definition: cct.c:128
#define NULL
Definition: ElfHelper.cpp:85