Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r984dce6 r630a82a  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Mar 13 12:34:38 2016
    13 // Update Count     : 272
     12// Last Modified On : Fri Apr  8 15:43:05 2016
     13// Update Count     : 296
    1414//
    1515
     
    2222
    2323#include "ParseNode.h"
     24#include "TypeData.h"
    2425#include "SynTree/Constant.h"
    2526#include "SynTree/Expression.h"
     27#include "SynTree/Declaration.h"
    2628#include "Common/UnimplementedError.h"
    2729#include "parseutility.h"
     
    872874}
    873875
     876
     877CompoundLiteralNode::CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids ) : type( type ), kids( kids ) {}
     878CompoundLiteralNode::CompoundLiteralNode( const CompoundLiteralNode &other ) : ExpressionNode( other ), type( other.type ), kids( other.kids ) {}
     879
     880CompoundLiteralNode::~CompoundLiteralNode() {
     881        delete kids;
     882        delete type;
     883}
     884
     885CompoundLiteralNode *CompoundLiteralNode::clone() const {
     886        return new CompoundLiteralNode( *this );
     887}
     888
     889void CompoundLiteralNode::print( std::ostream &os, int indent ) const {
     890        os << string( indent,' ' ) << "CompoundLiteralNode:" << endl;
     891
     892        os << string( indent + 2, ' ' ) << "type:" << endl;
     893        if ( type != 0 )
     894                type->print( os, indent + 4 );
     895
     896        os << string( indent + 2, ' ' ) << "initialization:" << endl;
     897        if ( kids != 0 )
     898                kids->printList( os, indent + 4 );
     899}
     900
     901void CompoundLiteralNode::printOneLine( std::ostream &os, int indent ) const {
     902        os << "( ";
     903        if ( type ) type->print( os );
     904        os << ", ";
     905        if ( kids ) kids->printOneLine( os );
     906        os << ") ";
     907}
     908
     909Expression *CompoundLiteralNode::build() const {
     910        Declaration * newDecl = type->build();                          // compound literal type
     911        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
     912                return new CompoundLiteralExpr( newDeclWithType->get_type(), kids->build() );
     913        // these types do not have associated type information
     914        } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl )  ) {
     915                return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), kids->build() );
     916        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl )  ) {
     917                return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), kids->build() );
     918        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl )  ) {
     919                return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), kids->build() );
     920        } else {
     921                assert( false );
     922        } // if
     923}
     924
     925
    874926ExpressionNode *flattenCommas( ExpressionNode *list ) {
    875927        if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( list ) ) {
Note: See TracChangeset for help on using the changeset viewer.