Changeset 67cf18c for src/SynTree


Ignore:
Timestamp:
May 26, 2017, 6:37:49 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
01b9928
Parents:
ff03f5c
git-author:
Rob Schluntz <rschlunt@…> (05/26/17 18:34:50)
git-committer:
Rob Schluntz <rschlunt@…> (05/26/17 18:37:49)
Message:

implement default type arguments for generic types [closes #13]

Location:
src/SynTree
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Declaration.h

    rff03f5c r67cf18c  
    194194        };
    195195
    196         TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind );
     196        TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init = nullptr );
    197197        TypeDecl( const TypeDecl &other );
     198        virtual ~TypeDecl();
    198199
    199200        Kind get_kind() const { return kind; }
     201
     202        Type * get_init() const { return init; }
     203        TypeDecl * set_init( Type * newValue ) { init = newValue; return this; }
    200204
    201205        bool isComplete() const { return kind == Any || sized; }
     
    209213        virtual void accept( Visitor &v ) { v.visit( this ); }
    210214        virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     215        virtual void print( std::ostream &os, int indent = 0 ) const;
     216
    211217  private:
    212218        Kind kind;
     219        Type * init;
    213220        bool sized;
    214221};
  • src/SynTree/Mutator.cc

    rff03f5c r67cf18c  
    7777TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) {
    7878        handleNamedTypeDecl( typeDecl );
     79        typeDecl->set_init( maybeMutate( typeDecl->get_init(), *this ) );
    7980        return typeDecl;
    8081}
  • src/SynTree/TypeDecl.cc

    rff03f5c r67cf18c  
    1818#include "Common/utility.h"
    1919
    20 TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind ) : Parent( name, scs, type ), kind( kind ), sized( kind == Any || kind == Ttype ) {
     20TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init ) : Parent( name, scs, type ), kind( kind ), init( init ), sized( kind == Any || kind == Ttype ) {
    2121}
    2222
    23 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ), sized( other.sized ) {
     23TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ), init( maybeClone( other.init ) ), sized( other.sized ) {
     24}
     25
     26TypeDecl::~TypeDecl() {
     27  delete init;
    2428}
    2529
     
    3438}
    3539
     40void TypeDecl::print( std::ostream &os, int indent ) const {
     41  NamedTypeDecl::print( os, indent );
     42  if ( init ) {
     43    os << std::endl << std::string( indent, ' ' ) << "with type initializer: ";
     44    init->print( os, indent + 2 );
     45  }
     46}
     47
     48
    3649std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ) {
    3750  return os << data.kind << ", " << data.isComplete;
  • src/SynTree/Visitor.cc

    rff03f5c r67cf18c  
    6767void Visitor::visit( TypeDecl *typeDecl ) {
    6868        handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) );
     69        maybeAccept( typeDecl->get_init(), *this );
    6970}
    7071
Note: See TracChangeset for help on using the changeset viewer.