source: src/SynTree/FunctionType.cc @ 25cdca5

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 25cdca5 was 50377a4, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Refactor tree print code to use Indenter

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[0dd3a2f]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//
[8bf784a]7// FunctionType.cc --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
[c0aa336]12// Last Modified On : Wed Feb  1 17:21:00 2017
13// Update Count     : 2
[0dd3a2f]14//
15
[ea6332d]16#include <list>              // for list
17#include <ostream>           // for operator<<, basic_ostream, ostream, endl
18#include <string>            // for operator<<, char_traits, string
[51b7345]19
[ea6332d]20#include "Common/utility.h"  // for cloneAll, deleteAll, printAll
21#include "Declaration.h"     // for DeclarationWithType
22#include "Tuples/Tuples.h"   // for isTtype
23#include "Type.h"            // for FunctionType, Type, Type::Qualifiers
24
25class Attribute;
[51b7345]26
[c0aa336]27FunctionType::FunctionType( const Type::Qualifiers &tq, bool isVarArgs, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), isVarArgs( isVarArgs ) {
[51b7345]28}
29
[c8ffe20b]30FunctionType::FunctionType( const FunctionType &other ) : Type( other ), isVarArgs( other.isVarArgs ) {
[0dd3a2f]31        cloneAll( other.returnVals, returnVals );
32        cloneAll( other.parameters, parameters );
[51b7345]33}
34
[c8ffe20b]35FunctionType::~FunctionType() {
[0dd3a2f]36        deleteAll( returnVals );
37        deleteAll( parameters );
[51b7345]38}
39
[8bf784a]40namespace {
41        bool containsTtype( const std::list<DeclarationWithType * > & l ) {
42                if ( ! l.empty() ) {
43                        return Tuples::isTtype( l.back()->get_type() );
44                }
45                return false;
46        }
47}
48
49bool FunctionType::isTtype() const {
50        return containsTtype( returnVals ) || containsTtype( parameters );
51}
52
[50377a4]53void FunctionType::print( std::ostream &os, Indenter indent ) const {
[0dd3a2f]54        using std::string;
55        using std::endl;
56
57        Type::print( os, indent );
58        os << "function" << endl;
59        if ( ! parameters.empty() ) {
[50377a4]60                os << indent << "... with parameters" << endl;
61                printAll( parameters, os, indent+1 );
[0dd3a2f]62                if ( isVarArgs ) {
[50377a4]63                        os << indent+1 << "and a variable number of other arguments" << endl;
[0dd3a2f]64                } // if
65        } else if ( isVarArgs ) {
[50377a4]66                os << indent+1 << "accepting unspecified arguments" << endl;
[0dd3a2f]67        } // if
[50377a4]68        os << indent << "... returning ";
[0dd3a2f]69        if ( returnVals.empty() ) {
[50377a4]70                os << "nothing " << endl;
[0dd3a2f]71        } else {
72                os << endl;
[50377a4]73                printAll( returnVals, os, indent+1 );
[0dd3a2f]74        } // if
[51b7345]75}
76
[0dd3a2f]77// Local Variables: //
78// tab-width: 4 //
79// mode: c++ //
80// compile-command: "make install" //
81// End: //
Note: See TracBrowser for help on using the repository browser.