Changes in / [543159b:43ee2a8]


Ignore:
Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r543159b r43ee2a8  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:17:07 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 11 15:13:48 2015
    13 // Update Count     : 200
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 12 13:51:11 2015
     13// Update Count     : 254
    1414//
    1515
     
    3232ExpressionNode::ExpressionNode() : ParseNode(), argName( 0 ) {}
    3333
    34 ExpressionNode::ExpressionNode( const string *name_ ) : ParseNode( name_ ), argName( 0 ) {}
     34ExpressionNode::ExpressionNode( const string *name ) : ParseNode( name ), argName( 0 ) {}
    3535
    3636ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.name ) {
     
    290290DesignatorNode::DesignatorNode( ExpressionNode *expr, bool isArrayIndex ) : isArrayIndex( isArrayIndex ) {
    291291        set_argName( expr );
     292        assert( get_argName() );
     293
     294        if ( ! isArrayIndex ) {
     295                if ( VarRefNode * var = dynamic_cast< VarRefNode * >( expr ) ) {
     296
     297                        stringstream ss( var->get_name() );
     298                        double value;
     299                        if ( ss >> value ) {
     300                                // this is a floating point constant. It MUST be
     301                                // ".0" or ".1", otherwise the program is invalid
     302                                if ( ! (var->get_name() == ".0" || var->get_name() == ".1") ) {
     303                                        throw SemanticError( "invalid designator name: " + var->get_name() );
     304                                } // if
     305                                var->set_name( var->get_name().substr(1) );
     306                        } // if
     307                } // if
     308        } // if
    292309}
    293310
     
    295312}
    296313
     314class DesignatorFixer : public Mutator {
     315public:
     316        virtual Expression* mutate( NameExpr *nameExpr ) {
     317                if ( nameExpr->get_name() == "0" || nameExpr->get_name() == "1" ) {
     318                        Constant val( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nameExpr->get_name() );
     319                        delete nameExpr;
     320                        return new ConstantExpr( val );
     321                }
     322                return nameExpr;
     323        }
     324};
     325
    297326Expression *DesignatorNode::build() const {
     327        Expression * ret = get_argName()->build();
     328
    298329        if ( isArrayIndex ) {
    299                 return new NameExpr( get_name(), maybeBuild< Expression >( get_argName() ) );
    300         } else {
    301                 return new NameExpr( get_name(), maybeBuild< Expression >( get_argName() ) );
    302         } // if
     330                // need to traverse entire structure and change any instances of 0 or 1 to
     331                // ConstantExpr
     332                DesignatorFixer fixer;
     333                ret = ret->acceptMutator( fixer );
     334        } // if
     335
     336        return ret;
    303337}
    304338
  • src/Parser/ParseNode.cc

    r543159b r43ee2a8  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:26:29 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 30 14:55:54 2015
    13 // Update Count     : 26
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 12 13:26:00 2015
     13// Update Count     : 36
    1414//
    1515
     
    2020int ParseNode::indent_by = 4;
    2121
    22 ParseNode::ParseNode() : name( 0 ), next( 0 ) {};
    23 ParseNode::ParseNode( const string *name_ ) : name( name_ ), next( 0 ) {}
     22ParseNode::ParseNode() : next( 0 ) {};
     23ParseNode::ParseNode( const string *name ) : name( *name ), next( 0 ) { delete name; }
     24ParseNode::ParseNode( const string &name ) : name( name ), next( 0 ) { }
    2425
    2526ParseNode::~ParseNode() {
    26         delete next; delete name;
     27        delete next;
    2728};
    2829
  • src/Parser/ParseNode.h

    r543159b r43ee2a8  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:28:16 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 11 15:11:29 2015
    13 // Update Count     : 145
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 12 13:27:11 2015
     13// Update Count     : 172
    1414//
    1515
     
    4040        ParseNode();
    4141        ParseNode( const std::string * );
     42        ParseNode( const std::string & );  // for copy constructing subclasses
    4243        virtual ~ParseNode();
    4344
     
    4950        virtual ParseNode *clone() const { return 0; };
    5051
    51         const std::string &get_name() const { return *name; }
     52        const std::string &get_name() const { return name; }
     53        void set_name( const std::string &newValue ) { name = newValue; }
     54
    5255        virtual void print( std::ostream &, int indent = 0 ) const;
    5356        virtual void printList( std::ostream &, int indent = 0 ) const;
     
    5558        ParseNode &operator,( ParseNode &);
    5659  protected:
    57         const std::string *name;
     60        std::string name;
    5861        ParseNode *next;
    5962        static int indent_by;
  • src/SynTree/ArrayType.cc

    r543159b r43ee2a8  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun  6 14:11:48 2015
    13 // Update Count     : 9
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 12 14:19:07 2015
     13// Update Count     : 11
    1414//
    1515
     
    5050        } // if
    5151        if ( dimension ) {
    52                 os << "with dimension of ";
    53                 dimension->print( os, indent );
     52                os << " with dimension of ";
     53                dimension->print( os, 0 );
    5454        } // if
    5555}
  • src/SynTree/BasicType.cc

    r543159b r43ee2a8  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jun  7 08:44:36 2015
    13 // Update Count     : 5
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 12 14:15:45 2015
     13// Update Count     : 6
    1414//
    1515
     
    2828
    2929        Type::print( os, indent );
    30         os << kindNames[ kind ] << ' ';
     30        os << kindNames[ kind ];
    3131}
    3232
  • src/SynTree/Expression.cc

    r543159b r43ee2a8  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 28 16:27:17 2015
    13 // Update Count     : 22
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 12 14:02:45 2015
     13// Update Count     : 30
    1414//
    1515
     
    7272
    7373void ConstantExpr::print( std::ostream &os, int indent ) const {
    74         os << "constant expression " ;
     74        os << std::string( indent, ' ' ) << "constant expression " ;
    7575        constant.print( os );
    7676        Expression::print( os, indent );
     77        os << std::endl;
    7778}
    7879
  • src/SynTree/Initializer.cc

    r543159b r43ee2a8  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 09:02:45 2015
    13 // Update Count     : 2
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 12 14:05:25 2015
     13// Update Count     : 14
    1414//
    1515
     
    4343
    4444void SingleInit::print( std::ostream &os, int indent ) {
    45         os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: ";
    46         value->print( os, indent+2 );
     45        os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;
     46        value->print( os, indent+4 );
    4747
    4848        if ( ! designators.empty() ) {
    49                 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: "  ;
    50                 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ )
     49                os << std::endl << std::string(indent + 2, ' ' ) << "designated by: "   << std::endl;
     50                for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) {
    5151                        ( *i )->print(os, indent + 4 );
     52                }
    5253        } // if
    5354}
Note: See TracChangeset for help on using the changeset viewer.