Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:21:48

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /*
0027  * =============================================================================
0028  *
0029  *       Filename:  CexmcAST.hh
0030  *
0031  *    Description:  abstract syntax tree for custom filter scripting language
0032  *
0033  *        Version:  1.0
0034  *        Created:  17.07.2010 14:39:37
0035  *       Revision:  none
0036  *       Compiler:  gcc
0037  *
0038  *         Author:  Alexey Radkov (), 
0039  *        Company:  PNPI
0040  *
0041  * =============================================================================
0042  */
0043 
0044 #ifndef CEXMC_AST_HH
0045 #define CEXMC_AST_HH
0046 
0047 #ifdef CEXMC_USE_CUSTOM_FILTER
0048 
0049 #include <vector>
0050 #include <boost/variant/recursive_variant.hpp>
0051 
0052 
0053 namespace  CexmcAST
0054 {
0055     using boost::variant;
0056     using boost::recursive_wrapper;
0057 
0058     enum  OperatorType
0059     {
0060         Uninitialized,
0061         Top,
0062         UMinus,
0063         Not,
0064         Mult,
0065         Div,
0066         Plus,
0067         Minus,
0068         Less,
0069         LessEq,
0070         More,
0071         MoreEq,
0072         Eq,
0073         NotEq,
0074         And,
0075         Or
0076     };
0077 
0078 
0079     struct  Operator
0080     {
0081         Operator( OperatorType  type_ = Uninitialized, int  priority_ = 0,
0082                   bool  hasRLAssoc_ = false ) :
0083             type( type_ ), priority( priority_ ), hasRLAssoc( hasRLAssoc_ )
0084         {}
0085 
0086         OperatorType  type;
0087 
0088         int           priority;
0089 
0090         bool          hasRLAssoc;
0091     };
0092 
0093 
0094     struct  Variable
0095     {
0096         Variable() : index1( 0 ), index2( 0 ), addr( ( const int * ) NULL )
0097         {}
0098 
0099         std::string                             name;
0100 
0101         int                                     index1;
0102 
0103         int                                     index2;
0104 
0105         variant< const int *, const double * >  addr;
0106     };
0107 
0108 
0109     struct  Subtree;
0110 
0111     typedef std::string                    Function;
0112 
0113     typedef variant< int, double >         Constant;
0114 
0115     typedef variant< Variable, Constant >  Leaf;
0116 
0117     typedef recursive_wrapper< Subtree >   Tree;
0118 
0119     typedef variant< Tree, Leaf >          Node;
0120 
0121     typedef variant< Operator, Function >  NodeType;
0122 
0123 
0124     struct  Subtree
0125     {
0126         Subtree() : type( Operator( Uninitialized ) )
0127         {}
0128 
0129         void  Print( int  level = 0 ) const;
0130 
0131         void  PrintLeaf( const Leaf *  leaf, int  level = 0 ) const;
0132 
0133         std::vector< Node >  children;
0134 
0135         NodeType             type;
0136 
0137         static const int     printIndent = 4;
0138     };
0139 
0140 
0141     class  BasicEval
0142     {
0143         protected:
0144             typedef variant< int, double >  ScalarValueType;
0145 
0146         protected:
0147             virtual ~BasicEval();
0148 
0149         public:
0150             bool  operator()( const Subtree &  ast ) const;
0151 
0152         protected:
0153             ScalarValueType          GetScalarValue( const Node &  node ) const;
0154 
0155             virtual ScalarValueType  GetFunScalarValue( const Subtree &  ast )
0156                                                                         const;
0157 
0158             virtual ScalarValueType  GetVarScalarValue( const Variable &  var )
0159                                                                         const;
0160 
0161             ScalarValueType          GetBasicFunScalarValue(
0162                                         const Subtree &  ast, bool &  result )
0163                                                                         const;
0164     };
0165 }
0166 
0167 #endif
0168 
0169 #endif
0170