Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/cppparser/cppExpression.h

Go to the documentation of this file.
00001 // Filename: cppExpression.h
00002 // Created by:  drose (25Oct99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef CPPEXPRESSION_H
00020 #define CPPEXPRESSION_H
00021 
00022 #include <dtoolbase.h>
00023 
00024 #include "cppDeclaration.h"
00025 
00026 class CPPIdentifier;
00027 class CPPType;
00028 class CPPPreprocessor;
00029 class CPPFunctionGroup;
00030 
00031 ///////////////////////////////////////////////////////////////////
00032 //       Class : CPPExpression
00033 // Description :
00034 ////////////////////////////////////////////////////////////////////
00035 class CPPExpression : public CPPDeclaration {
00036 public:
00037   CPPExpression(int value);
00038   CPPExpression(const string &value);
00039   CPPExpression(double value);
00040   CPPExpression(CPPIdentifier *ident, CPPScope *current_scope,
00041                 CPPScope *global_scope, CPPPreprocessor *error_sink = NULL);
00042   CPPExpression(int unary_operator, CPPExpression *op1);
00043   CPPExpression(int binary_operator, CPPExpression *op1, CPPExpression *op2);
00044   CPPExpression(int trinary_operator, CPPExpression *op1, CPPExpression *op2, CPPExpression *op3);
00045 
00046   static CPPExpression typecast_op(CPPType *type, CPPExpression *op1);
00047   static CPPExpression construct_op(CPPType *type, CPPExpression *op1);
00048   static CPPExpression new_op(CPPType *type, CPPExpression *op1 = NULL);
00049   static CPPExpression sizeof_func(CPPType *type);
00050 
00051   ~CPPExpression();
00052 
00053   enum ResultType {
00054     RT_integer,
00055     RT_real,
00056     RT_pointer,
00057     RT_error
00058   };
00059 
00060   class Result {
00061   public:
00062     Result();
00063     Result(int value);
00064     Result(double value);
00065     Result(void *value);
00066 
00067     int as_integer() const;
00068     double as_real() const;
00069     void *as_pointer() const;
00070     void output(ostream &out) const;
00071 
00072     ResultType _type;
00073     union {
00074       int _integer;
00075       double _real;
00076       void *_pointer;
00077     } _u;
00078   };
00079 
00080 
00081   Result evaluate() const;
00082   CPPType *determine_type() const;
00083   bool is_tbd() const;
00084 
00085   virtual CPPDeclaration *substitute_decl(SubstDecl &subst,
00086                                           CPPScope *current_scope,
00087                                           CPPScope *global_scope);
00088 
00089   virtual void output(ostream &out, int indent_level, CPPScope *scope,
00090                       bool complete) const;
00091   virtual SubType get_subtype() const;
00092 
00093   virtual CPPExpression *as_expression();
00094 
00095 
00096   enum Type {
00097     T_integer,
00098     T_real,
00099     T_string,
00100     T_variable,
00101     T_function,
00102     T_unknown_ident,
00103     T_typecast,
00104     T_construct,
00105     T_default_construct,
00106     T_new,
00107     T_default_new,
00108     T_sizeof,
00109     T_unary_operation,
00110     T_binary_operation,
00111     T_trinary_operation,
00112   };
00113 
00114   Type _type;
00115   string _str;
00116   union {
00117     int _integer;
00118     double _real;
00119     CPPInstance *_variable;
00120     CPPFunctionGroup *_fgroup;
00121     CPPIdentifier *_ident;
00122     class {
00123     public:
00124       CPPType *_to;
00125       CPPExpression *_op1;
00126     } _typecast;
00127     class {
00128     public:
00129       // One of the yytoken values: a character, or something
00130       // like EQCOMPARE.
00131       int _operator;
00132       CPPExpression *_op1;
00133       CPPExpression *_op2;
00134       CPPExpression *_op3;
00135     } _op;
00136   } _u;
00137 
00138 protected:
00139   static CPPType *elevate_type(CPPType *t1, CPPType *t2);
00140   virtual bool is_equal(const CPPDeclaration *other) const;
00141   virtual bool is_less(const CPPDeclaration *other) const;
00142 };
00143 
00144 inline ostream &
00145 operator << (ostream &out, const CPPExpression::Result &result) {
00146   result.output(out);
00147   return out;
00148 }
00149 
00150 #endif
00151 
00152 

Generated on Thu May 1 22:12:51 2003 for DTool by doxygen1.3