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/Occurs.cc

    rb87a5ed ra32b204  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: Occurs.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// Occurs.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sun May 17 09:47:41 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 09:49:26 2015
     13// Update Count     : 2
     14//
    715
    816#include <set>
     
    1321#include "TypeEnvironment.h"
    1422
     23namespace ResolvExpr {
     24        class Occurs : public Visitor {
     25          public:
     26                Occurs( std::string varName, const TypeEnvironment &env );
     27                bool get_result() const { return result; }
     28                virtual void visit( TypeInstType *typeInst );
     29          private:
     30                bool result;
     31                std::set< std::string > eqvVars;
     32                const TypeEnvironment &env;
     33        };
    1534
    16 namespace ResolvExpr {
     35        bool occurs( Type *type, std::string varName, const TypeEnvironment &env ) {
     36                Occurs occur( varName, env );
     37                type->accept( occur );
     38                return occur.get_result();
     39        }
    1740
    18 class Occurs : public Visitor
    19 {
    20 public:
    21   Occurs( std::string varName, const TypeEnvironment &env );
    22  
    23   bool get_result() const { return result; }
     41        Occurs::Occurs( std::string varName, const TypeEnvironment &env ) : result( false ), env( env ) {
     42                EqvClass eqvClass;
     43                if ( env.lookup( varName, eqvClass ) ) {
     44                        eqvVars = eqvClass.vars;
     45                } else {
     46                        eqvVars.insert( varName );
     47                } // if
     48        }
    2449
    25   virtual void visit( TypeInstType *typeInst );
    26 
    27 private:
    28   bool result;
    29   std::set< std::string > eqvVars;
    30   const TypeEnvironment &env;
    31 };
    32 
    33 bool
    34 occurs( Type *type, std::string varName, const TypeEnvironment &env )
    35 {
    36   Occurs occur( varName, env );
    37   type->accept( occur );
    38   return occur.get_result();
    39 }
    40 
    41 Occurs::Occurs( std::string varName, const TypeEnvironment &env )
    42   : result( false ), env( env )
    43 {
    44   EqvClass eqvClass;
    45   if( env.lookup( varName, eqvClass ) ) {
    46     eqvVars = eqvClass.vars;
    47   } else {
    48     eqvVars.insert( varName );
    49   }
    50 }
    51 
    52 void
    53 Occurs::visit( TypeInstType *typeInst )
    54 {
    55   EqvClass eqvClass;
     50        void Occurs::visit( TypeInstType *typeInst ) {
     51                EqvClass eqvClass;
    5652///   std::cout << "searching for vars: ";
    5753///   std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cout, " " ) );
    5854///   std::cout << std::endl;
    59   if( eqvVars.find( typeInst->get_name() ) != eqvVars.end() ) {
    60     result = true;
    61   } else if( env.lookup( typeInst->get_name(), eqvClass ) ) {
    62     if( eqvClass.type ) {
     55                if ( eqvVars.find( typeInst->get_name() ) != eqvVars.end() ) {
     56                        result = true;
     57                } else if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
     58                        if ( eqvClass.type ) {
    6359///       std::cout << typeInst->get_name() << " is bound to";
    6460///       eqvClass.type->print( std::cout );
    6561///       std::cout << std::endl;
    66       eqvClass.type->accept( *this );
    67     }
    68   }
    69 }
     62                                eqvClass.type->accept( *this );
     63                        } // if
     64                } // if
     65        }
     66} // namespace ResolvExpr
    7067
    71 } // namespace ResolvExpr
     68// Local Variables: //
     69// tab-width: 4 //
     70// mode: c++ //
     71// compile-command: "make install" //
     72// End: //
Note: See TracChangeset for help on using the changeset viewer.