| 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 | // FunctionType.cc --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Richard C. Bilson
 | 
|---|
| 10 | // Created On       : Mon May 18 07:44:20 2015
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Mon May 18 09:01:28 2015
 | 
|---|
| 13 | // Update Count     : 1
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <algorithm>
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include "Type.h"
 | 
|---|
| 19 | #include "Declaration.h"
 | 
|---|
| 20 | #include "Common/utility.h"
 | 
|---|
| 21 | #include "Tuples/Tuples.h"
 | 
|---|
| 22 | 
 | 
|---|
| 23 | FunctionType::FunctionType( const Type::Qualifiers &tq, bool isVarArgs ) : Type( tq ), isVarArgs( isVarArgs ) {
 | 
|---|
| 24 | }
 | 
|---|
| 25 | 
 | 
|---|
| 26 | FunctionType::FunctionType( const FunctionType &other ) : Type( other ), isVarArgs( other.isVarArgs ) {
 | 
|---|
| 27 |         cloneAll( other.returnVals, returnVals );
 | 
|---|
| 28 |         cloneAll( other.parameters, parameters );
 | 
|---|
| 29 | }
 | 
|---|
| 30 | 
 | 
|---|
| 31 | FunctionType::~FunctionType() {
 | 
|---|
| 32 |         deleteAll( returnVals );
 | 
|---|
| 33 |         deleteAll( parameters );
 | 
|---|
| 34 | }
 | 
|---|
| 35 | 
 | 
|---|
| 36 | namespace {
 | 
|---|
| 37 |         bool containsTtype( const std::list<DeclarationWithType * > & l ) {
 | 
|---|
| 38 |                 if ( ! l.empty() ) {
 | 
|---|
| 39 |                         return Tuples::isTtype( l.back()->get_type() );
 | 
|---|
| 40 |                 }
 | 
|---|
| 41 |                 return false;
 | 
|---|
| 42 |         }
 | 
|---|
| 43 | }
 | 
|---|
| 44 | 
 | 
|---|
| 45 | bool FunctionType::isTtype() const {
 | 
|---|
| 46 |         return containsTtype( returnVals ) || containsTtype( parameters );
 | 
|---|
| 47 | }
 | 
|---|
| 48 | 
 | 
|---|
| 49 | void FunctionType::print( std::ostream &os, int indent ) const {
 | 
|---|
| 50 |         using std::string;
 | 
|---|
| 51 |         using std::endl;
 | 
|---|
| 52 | 
 | 
|---|
| 53 |         Type::print( os, indent );
 | 
|---|
| 54 |         os << "function" << endl;
 | 
|---|
| 55 |         if ( ! parameters.empty() ) {
 | 
|---|
| 56 |                 os << string( indent + 2, ' ' ) << "with parameters" << endl;
 | 
|---|
| 57 |                 printAll( parameters, os, indent + 4 );
 | 
|---|
| 58 |                 if ( isVarArgs ) {
 | 
|---|
| 59 |                         os << string( indent + 4, ' ' ) << "and a variable number of other arguments" << endl;
 | 
|---|
| 60 |                 } // if
 | 
|---|
| 61 |         } else if ( isVarArgs ) {
 | 
|---|
| 62 |                 os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl;
 | 
|---|
| 63 |         } // if
 | 
|---|
| 64 |         os << string( indent + 2, ' ' ) << "returning ";
 | 
|---|
| 65 |         if ( returnVals.empty() ) {
 | 
|---|
| 66 |                 os << endl << string( indent + 4, ' ' ) << "nothing " << endl;
 | 
|---|
| 67 |         } else {
 | 
|---|
| 68 |                 os << endl;
 | 
|---|
| 69 |                 printAll( returnVals, os, indent + 4 );
 | 
|---|
| 70 |         } // if
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | // Local Variables: //
 | 
|---|
| 74 | // tab-width: 4 //
 | 
|---|
| 75 | // mode: c++ //
 | 
|---|
| 76 | // compile-command: "make install" //
 | 
|---|
| 77 | // End: //
 | 
|---|