Ignore:
Timestamp:
May 17, 2015, 1:19:35 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
0dd3a2f
Parents:
b87a5ed
Message:

licencing: second groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/ResolvExpr/PolyCost.cc

    rb87a5ed ra32b204  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: PolyCost.cc,v 1.2 2005/08/29 20:14:16 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// PolyCost.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 09:50:12 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 09:52:02 2015
     13// Update Count     : 3
     14//
    715
    816#include "typeops.h"
     
    1220#include "TypeEnvironment.h"
    1321
     22namespace ResolvExpr {
     23        class PolyCost : public Visitor {
     24          public:
     25                PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer );
     26                int get_result() const { return result; }
     27          private:
     28                virtual void visit(TypeInstType *aggregateUseType);
     29                int result;
     30                const TypeEnvironment &env;
     31                const SymTab::Indexer &indexer;
     32        };
    1433
    15 namespace ResolvExpr {
     34        int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
     35                PolyCost coster( env, indexer );
     36                type->accept( coster );
     37                return coster.get_result();
     38        }
    1639
    17 class PolyCost : public Visitor
    18 {
    19 public:
    20   PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer );
     40        PolyCost::PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer ) : result( 0 ), env( env ), indexer( indexer ) {
     41        }
    2142
    22   int get_result() const { return result; }
    23 
    24 private:
    25   virtual void visit(TypeInstType *aggregateUseType);
    26  
    27   int result;
    28   const TypeEnvironment &env;
    29   const SymTab::Indexer &indexer;
    30 };
    31 
    32 int
    33 polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer )
    34 {
    35   PolyCost coster( env, indexer );
    36   type->accept( coster );
    37   return coster.get_result();
    38 }
    39 
    40 PolyCost::PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer )
    41   : result( 0 ), env( env ), indexer( indexer )
    42 {
    43 }
    44 
    45 void
    46 PolyCost::visit(TypeInstType *typeInst)
    47 {
    48   EqvClass eqvClass;
    49   if( env.lookup( typeInst->get_name(), eqvClass ) ) {
    50     if( eqvClass.type ) {
    51       if( TypeInstType *otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) {
    52         if( indexer.lookupType( otherTypeInst->get_name() ) ) {
    53           result += 1;
    54         }
    55       } else {
    56         result += 1;
    57       }
    58     }
    59   }
    60 }
     43        void PolyCost::visit(TypeInstType *typeInst) {
     44                EqvClass eqvClass;
     45                if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
     46                        if ( eqvClass.type ) {
     47                                if ( TypeInstType *otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) {
     48                                        if ( indexer.lookupType( otherTypeInst->get_name() ) ) {
     49                                                result += 1;
     50                                        } // if
     51                                } else {
     52                                        result += 1;
     53                                } // if
     54                        } // if
     55                } // if
     56        }
    6157
    6258} // namespace ResolvExpr
     59
     60// Local Variables: //
     61// tab-width: 4 //
     62// mode: c++ //
     63// compile-command: "make install" //
     64// End: //
Note: See TracChangeset for help on using the changeset viewer.