Changes in / [4389966:78dd0da]


Ignore:
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • doc/refrat/refrat.tex

    r4389966 r78dd0da  
    112112\lstset{
    113113language=CFA,
    114 columns=flexible,
     114columns=fullflexible,
    115115basicstyle=\sf\small,
    116116tabsize=4,
    117117xleftmargin=\parindent,
    118118escapechar=@,
     119%fancyvrb=true,
     120%showtabs=true,
    119121keepspaces=true,
    120 %showtabs=true,
    121 %tab=\rightarrowfill,
     122showtabs=true,
     123tab=,
    122124}%
    123125
  • src/GenPoly/Box.cc

    r4389966 r78dd0da  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 15 15:30:31 2015
    13 // Update Count     : 215
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Thu Nov 26 17:01:55 2015
     13// Update Count     : 191
    1414//
    1515
     
    5555                  public:
    5656                        Pass1();
    57                         virtual Expression * mutate( ApplicationExpr *appExpr );
    58                         virtual Expression * mutate( AddressExpr *addrExpr );
    59                         virtual Expression * mutate( UntypedExpr *expr );
    60                         virtual DeclarationWithType * mutate( FunctionDecl *functionDecl );
    61                         virtual TypeDecl * mutate( TypeDecl *typeDecl );
    62                         virtual Expression * mutate( CommaExpr *commaExpr );
    63                         virtual Expression * mutate( ConditionalExpr *condExpr );
    64                         virtual Statement * mutate( ReturnStmt *returnStmt );
    65                         virtual Type * mutate( PointerType *pointerType );
    66                         virtual Type * mutate( FunctionType *functionType );
     57                        virtual Expression *mutate( ApplicationExpr *appExpr );
     58                        virtual Expression *mutate( AddressExpr *addrExpr );
     59                        virtual Expression *mutate( UntypedExpr *expr );
     60                        virtual DeclarationWithType* mutate( FunctionDecl *functionDecl );
     61                        virtual TypeDecl *mutate( TypeDecl *typeDecl );
     62                        virtual Expression *mutate( CommaExpr *commaExpr );
     63                        virtual Expression *mutate( ConditionalExpr *condExpr );
     64                        virtual Statement *mutate(ReturnStmt *catchStmt);
     65                        virtual Type *mutate( PointerType *pointerType );
     66                        virtual Type *mutate( FunctionType *pointerType );
    6767 
    6868                        virtual void doBeginScope();
     
    192192                                                        if ( PointerType *pointer = dynamic_cast< PointerType *>( funType->get_parameters().front()->get_type() ) ) {
    193193                                                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( pointer->get_base() ) ) {
    194                                                                         if ( TypeInstType *typeInst2 = dynamic_cast< TypeInstType *>( funType->get_parameters().back()->get_type() ) ) {
    195                                                                                 if ( typeInst->get_name() == typeInst2->get_name() ) {
    196                                                                                         name = typeInst->get_name();
    197                                                                                         return true;
    198                                                                                 } // if
    199                                                                         } // if
     194                                                                        name = typeInst->get_name();
     195                                                                        return true;
    200196                                                                } // if
    201197                                                        } // if
     
    348344
    349345                Expression *Pass1::addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ) {
    350                         // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
    351                         // if ( useRetval ) {
    352                         //      assert( retval );
    353                         //      arg = appExpr->get_args().insert( arg, new VariableExpr( retval ) );
    354                         //      arg++;
    355                         // } else {
    356 
    357                         // Create temporary to hold return value of polymorphic function and produce that temporary as a result
    358                         // using a comma expression.  Possibly change comma expression into statement expression "{}" for multiple
    359                         // return values.
    360                         ObjectDecl *newObj = makeTemporary( retType->clone() );
    361                         Expression *paramExpr = new VariableExpr( newObj );
    362                         // If the type of the temporary is not polymorphic, box temporary by taking its address; otherwise the
    363                         // temporary is already boxed and can be used directly.
    364                         if ( ! isPolyType( newObj->get_type(), env, scopeTyVars ) ) {
    365                                 paramExpr = new AddressExpr( paramExpr );
    366                         } // if
    367                         arg = appExpr->get_args().insert( arg, paramExpr ); // add argument to function call
    368                         arg++;
    369                         // Build a comma expression to call the function and emulate a normal return.
    370                         CommaExpr *commaExpr = new CommaExpr( appExpr, new VariableExpr( newObj ) );
    371                         commaExpr->set_env( appExpr->get_env() );
    372                         appExpr->set_env( 0 );
    373                         return commaExpr;
    374                         // } // if
    375                         // return appExpr;
     346                        if ( useRetval ) {
     347                                assert( retval );
     348                                arg = appExpr->get_args().insert( arg, new VariableExpr( retval ) );
     349                                arg++;
     350                        } else {
     351                                ObjectDecl *newObj = makeTemporary( retType->clone() );
     352                                Expression *paramExpr = new VariableExpr( newObj );
     353                                if ( ! isPolyType( newObj->get_type(), env, scopeTyVars ) ) {
     354                                        paramExpr = new AddressExpr( paramExpr );
     355                                } // if
     356                                arg = appExpr->get_args().insert( arg, paramExpr );
     357                                arg++;
     358///     stmtsToAdd.push_back( new ExprStmt( noLabels, appExpr ) );
     359                                CommaExpr *commaExpr = new CommaExpr( appExpr, new VariableExpr( newObj ) );
     360                                commaExpr->set_env( appExpr->get_env() );
     361                                appExpr->set_env( 0 );
     362                                return commaExpr;
     363                        } // if
     364                        return appExpr;
    376365                }
    377366
     
    428417                        Type *newType = formal->clone();
    429418                        std::list< FunctionType *> functions;
    430                         // instead of functions needing adapters, this really ought to look for any function mentioning a
    431                         // polymorphic type
     419                        // instead of functions needing adapters, this really ought to look for
     420                        // any function mentioning a polymorphic type
    432421                        findAndReplaceFunction( newType, functions, tyVars, needsAdapter );
    433422                        if ( ! functions.empty() ) {
     
    867856                Expression *Pass1::mutate( AddressExpr *addrExpr ) {
    868857                        assert( ! addrExpr->get_arg()->get_results().empty() );
    869 
    870                         bool needs = false;
    871                         if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) {
    872                                 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars ) ) {
    873                                         if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    874                                                 if ( name->get_name() == "*?" ) {
    875                                                         if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) {
    876                                                                 assert( ! appExpr->get_function()->get_results().empty() );
    877                                                                 PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() );
    878                                                                 assert( pointer );
    879                                                                 FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() );
    880                                                                 assert( function );
    881                                                                 needs = needsAdapter( function, scopeTyVars );
    882                                                         } // if
    883                                                 } // if
    884                                         } // if
    885                                 } // if
    886                         } // if
    887858                        addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );
    888                         if ( isPolyType( addrExpr->get_arg()->get_results().front(), env, scopeTyVars ) || needs ) {
     859                        if ( isPolyType( addrExpr->get_arg()->get_results().front(), env, scopeTyVars ) ) {
    889860                                Expression *ret = addrExpr->get_arg();
    890861                                delete ret->get_results().front();
     
    898869                }
    899870
    900                 Statement * Pass1::mutate( ReturnStmt *returnStmt ) {
    901                         if ( retval && returnStmt->get_expr() ) {
    902                                 assert( ! returnStmt->get_expr()->get_results().empty() );
    903                                 // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
    904                                 // if ( returnStmt->get_expr()->get_results().front()->get_isLvalue() ) {
    905                                 // a cast expr on a polymorphic return value is either redundant or invalid
    906                                 while ( CastExpr *castExpr = dynamic_cast< CastExpr *>( returnStmt->get_expr() ) ) {
    907                                         returnStmt->set_expr( castExpr->get_arg() );
    908                                         returnStmt->get_expr()->set_env( castExpr->get_env() );
    909                                         castExpr->set_env( 0 );
    910                                         castExpr->set_arg( 0 );
    911                                         delete castExpr;
    912                                 } // while
    913                                 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() );
    914                                 assert( typeInst );
    915                                 std::map< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );
    916                                 if ( assignIter == assignOps.end() ) {
    917                                         throw SemanticError( "Attempt to return dtype or ftype object in ", returnStmt->get_expr() );
    918                                 } // if
    919                                 ApplicationExpr *assignExpr = new ApplicationExpr( new VariableExpr( assignIter->second ) );
    920                                 Expression *retParm = new NameExpr( retval->get_name() );
    921                                 retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
    922                                 assignExpr->get_args().push_back( retParm );
    923                                 assignExpr->get_args().push_back( returnStmt->get_expr() );
    924                                 stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( assignExpr ) ) );
    925                                 // } else {
    926                                 //      std::cerr << "THOMAS " << std::endl;
    927                                 //      useRetval = true;
    928                                 //      stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( returnStmt->get_expr() ) ) );
    929                                 //      useRetval = false;
    930                                 // } // if
    931                                 returnStmt->set_expr( 0 );
     871                Statement * Pass1::mutate(ReturnStmt *retStmt) {
     872                        // a cast expr on a polymorphic return value is either redundant or invalid
     873                        while ( CastExpr *castExpr = dynamic_cast< CastExpr *>( retStmt->get_expr() ) ) {
     874                                retStmt->set_expr( castExpr->get_arg() );
     875                                retStmt->get_expr()->set_env( castExpr->get_env() );
     876                                castExpr->set_env( 0 );
     877                                castExpr->set_arg( 0 );
     878                                delete castExpr;
     879                        }
     880                        if ( retval && retStmt->get_expr() ) {
     881                                assert( ! retStmt->get_expr()->get_results().empty() );
     882                                if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {
     883///       retStmt->set_expr( mutateExpression( retStmt->get_expr() ) );
     884                                        TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() );
     885                                        assert( typeInst );
     886                                        std::map< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );
     887                                        if ( assignIter == assignOps.end() ) {
     888                                                throw SemanticError( "Attempt to return dtype or ftype object in ", retStmt->get_expr() );
     889                                        } // if
     890                                        ApplicationExpr *assignExpr = new ApplicationExpr( new VariableExpr( assignIter->second ) );
     891                                        Expression *retParm = new NameExpr( retval->get_name() );
     892                                        retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
     893                                        assignExpr->get_args().push_back( retParm );
     894                                        assignExpr->get_args().push_back( retStmt->get_expr() );
     895                                        stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( assignExpr ) ) );
     896                                } else {
     897                                        useRetval = true;
     898                                        stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( retStmt->get_expr() ) ) );
     899                                        useRetval = false;
     900                                } // if
     901                                retStmt->set_expr( 0 );
    932902                        } else {
    933                                 returnStmt->set_expr( mutateExpression( returnStmt->get_expr() ) );
    934                         } // if
    935                         return returnStmt;
     903                                retStmt->set_expr( mutateExpression( retStmt->get_expr() ) );
     904                        } // if
     905                        return retStmt;
    936906                }
    937907
     
    11351105                        if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
    11361106                                if ( isPolyVal( objectDecl->get_type(), scopeTyVars ) ) {
    1137                                         // change initialization of a polymorphic value object to allocate storage with alloca
     1107                                        // change initialization of a polymorphic value object
     1108                                        // to allocate storage with alloca
    11381109                                        TypeInstType *typeInst = dynamic_cast< TypeInstType *>( objectDecl->get_type() );
    11391110                                        assert( typeInst );
  • src/GenPoly/GenPoly.cc

    r4389966 r78dd0da  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 15 16:11:18 2015
    13 // Update Count     : 13
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Nov 24 15:23:08 2015
     13// Update Count     : 11
    1414//
    1515
     
    2121
    2222namespace GenPoly {
    23         /// A function needs an adapter if it returns a polymorphic value or if any of its parameters have polymorphic type
     23        /// A function needs an adapter if it returns a polymorphic value or if any of its
     24        /// parameters have polymorphic type
    2425        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) {
    2526                if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
  • src/GenPoly/Lvalue.cc

    r4389966 r78dd0da  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 15 15:33:13 2015
    13 // Update Count     : 3
     12// Last Modified On : Tue May 19 07:41:33 2015
     13// Update Count     : 1
    1414//
    1515
     
    122122                        if ( retval && retStmt->get_expr() ) {
    123123                                assert( ! retStmt->get_expr()->get_results().empty() );
     124                                while ( CastExpr *castExpr = dynamic_cast< CastExpr* >( retStmt->get_expr() ) ) {
     125                                        retStmt->set_expr( castExpr->get_arg() );
     126                                        retStmt->get_expr()->set_env( castExpr->get_env() );
     127                                        castExpr->set_env( 0 );
     128                                        castExpr->set_arg( 0 );
     129                                        delete castExpr;
     130                                } // while
    124131                                if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {
    125                                         // ***** Code Removal ***** because casts may be stripped already
    126 
    127                                         // strip casts because not allowed to take address of cast
    128                                         // while ( CastExpr *castExpr = dynamic_cast< CastExpr* >( retStmt->get_expr() ) ) {
    129                                         //      retStmt->set_expr( castExpr->get_arg() );
    130                                         //      retStmt->get_expr()->set_env( castExpr->get_env() );
    131                                         //      castExpr->set_env( 0 );
    132                                         //      castExpr->set_arg( 0 );
    133                                         //      delete castExpr;
    134                                         // } // while
    135132                                        retStmt->set_expr( new AddressExpr( retStmt->get_expr()->acceptMutator( *this ) ) );
    136133                                } else {
  • src/InitTweak/RemoveInit.cc

    r4389966 r78dd0da  
    77// RemoveInit.cc --
    88//
    9 // Author           : Rob Schluntz
     9// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 15 15:37:26 2015
    13 // Update Count     : 15
     12// Last Modified On : Tue May 19 16:39:32 2015
     13// Update Count     : 1
    1414//
    1515
     
    2626                const std::list<Label> noLabels;
    2727        }
    28        
    29         class RemoveInit : public Mutator {
    30           public:
    31                 RemoveInit();
    32                 virtual ObjectDecl * mutate(ObjectDecl *objDecl);
    33                 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl );
    34 
    35                 virtual Statement * mutate( ReturnStmt * returnStmt );
    36                
    37                 virtual CompoundStmt * mutate(CompoundStmt * compoundStmt);
    38                
    39           protected:
    40                 std::list< Statement* > stmtsToAddBefore;
    41                 std::list< Statement* > stmtsToAddAfter;
    42                 void mutateStatementList( std::list< Statement* > &statements );
    43 
    44                 std::list<DeclarationWithType*> returnVals;
    45                 UniqueName tempNamer;
    46                 std::string funcName;
    47         };
    4828
    4929        void tweak( std::list< Declaration * > translationUnit ) {
     
    5232        }
    5333
    54         RemoveInit::RemoveInit() : tempNamer( "_retVal" ) {}
    55        
    5634        void RemoveInit::mutateStatementList( std::list< Statement* > &statements ) {
    5735                for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
     
    6038                        } // if
    6139                        *i = (*i)->acceptMutator( *this );
    62                         if ( ! stmtsToAddBefore.empty() ) {
    63                                 statements.splice( i, stmtsToAddBefore );
    64                         } // if
    6540                } // for
    6641                if ( ! stmtsToAddAfter.empty() ) {
     
    7449        }
    7550
    76         // in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the
    77         // declaration. This will (seemingly) cause the later phases to do the right thing with the assignment
     51// in the case where an object has an initializer and a polymorphic type, insert an assignment
     52// immediately after the declaration. This will (seemingly) cause the later phases to do the right
     53// thing with the assignment
    7854        ObjectDecl *RemoveInit::mutate( ObjectDecl *objDecl ) {
    7955                if (objDecl->get_init() && dynamic_cast<TypeInstType*>(objDecl->get_type())) {
     
    8763                return objDecl;
    8864        }
    89 
    90         Statement *RemoveInit::mutate( ReturnStmt *returnStmt ) {
    91                 // update for multiple return values
    92                 assert( returnVals.size() == 0 || returnVals.size() == 1 );
    93                 // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address
    94                 // is being returned
    95                 if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue()  ) {
    96                         ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 );
    97                         stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) );
    98                        
    99                         UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
    100                         assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) );
    101                         assign->get_args().push_back( returnStmt->get_expr() );
    102                         stmtsToAddBefore.push_back(new ExprStmt(noLabels, assign));
    103 
    104                         returnStmt->set_expr( new VariableExpr( newObj ) );
    105                 } // if
    106                 return returnStmt;
    107         }
    108 
    109         DeclarationWithType* RemoveInit::mutate( FunctionDecl *functionDecl ) {
    110                 std::list<DeclarationWithType*> oldReturnVals = returnVals;
    111                 std::string oldFuncName = funcName;
    112                
    113                 FunctionType * type = functionDecl->get_functionType();
    114                 returnVals = type->get_returnVals();
    115                 funcName = functionDecl->get_name();
    116                 DeclarationWithType * decl = Mutator::mutate( functionDecl );
    117                 returnVals = oldReturnVals;
    118                 funcName = oldFuncName;
    119                 return decl;
    120         }
    12165} // namespace InitTweak
    12266
  • src/InitTweak/RemoveInit.h

    r4389966 r78dd0da  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 27 17:00:47 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue May 19 16:40:11 2015
     13// Update Count     : 1
    1414//
    1515
     
    2727        /// Adds assignment statements for polymorphic type initializers
    2828        void tweak( std::list< Declaration * > translationUnit );
     29
     30        class RemoveInit : public Mutator {
     31          public:
     32                // RemoveInit();
     33                virtual ObjectDecl *mutate(ObjectDecl *objDecl);
     34                virtual CompoundStmt *mutate(CompoundStmt *compoundStmt);
     35          protected:
     36                std::list< Statement* > stmtsToAddAfter;
     37                void mutateStatementList( std::list< Statement* > &statements );
     38        };
    2939} // namespace
    3040
  • src/SynTree/PointerType.cc

    r4389966 r78dd0da  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 15 15:39:10 2015
    13 // Update Count     : 5
     12// Last Modified On : Mon May 18 10:15:16 2015
     13// Update Count     : 2
    1414//
    1515
     
    2020PointerType::PointerType( const Type::Qualifiers &tq, Type *base )
    2121        : Type( tq ), base( base ), dimension( 0 ), isVarLen( false ), isStatic( false ) {
     22        base->set_isLvalue( false );
    2223}
    2324
    2425PointerType::PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic )
    2526        : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) {
     27        base->set_isLvalue( false );
    2628}
    2729
  • src/SynTree/Type.h

    r4389966 r78dd0da  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 27 17:54:31 2015
    13 // Update Count     : 16
     12// Last Modified On : Fri Nov 20 12:54:09 2015
     13// Update Count     : 15
    1414//
    1515
     
    188188        virtual ~FunctionType();
    189189
    190         std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
    191         std::list<DeclarationWithType*> & get_parameters() { return parameters; }
     190        std::list<DeclarationWithType*>& get_returnVals() { return returnVals; }
     191        std::list<DeclarationWithType*>& get_parameters() { return parameters; }
    192192        bool get_isVarArgs() { return isVarArgs; }
    193193        void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
  • src/examples/fstream_test.c

    r4389966 r78dd0da  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Nov 23 14:43:32 2015
    13 // Update Count     : 40
     12// Last Modified On : Wed May 27 18:13:43 2015
     13// Update Count     : 2
    1414//
    1515
     
    2020        ifstream *sin = ifstream_stdin();
    2121        int nombre;
    22         sout | "Entrez un nombre, s'il vous plaît:\n";
    23         sin  | &nombre;
    24         sout | "Vous avez entré " | nombre | " stocké à l'adresse " | &nombre | endl;
    25         sout | "nombre " | nombre | " est "
    26                  | (nombre > 0 ? "plus grand que" :
    27                    nombre == 0 ? "égal à" : "moins de")
    28                  | " zéro" | endl;
    29 
    30         sout | "Entrez trois nombres, s'il vous plaît:\n";
    31         int i, j, k;
    32         sin  | &i | &j | &k;
    33         sout | "Vous avez entré " | "i:" | i | " j:" | j | " k:" | k | endl;
    34 
    35         sout | 3 | ' ' | 3.5 | ' ' | 'a' | ' ' | "abc" | endl;
     22        sout << "Appuyez un nombre, s'il vous plâit:\n";
     23        sin >> &nombre;
     24        sout << "Vous avez appuyé: " << nombre << "\n";
    3625}
    3726
  • src/examples/hello.c

    r4389966 r78dd0da  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Nov 22 17:40:37 2015
    13 // Update Count     : 5
     12// Last Modified On : Fri Nov 20 16:02:50 2015
     13// Update Count     : 3
    1414//
    1515
     
    1919        ofstream *sout = ofstream_stdout();
    2020        ifstream *sin = ifstream_stdin();
    21         sout | "Bonjour au monde!\n";
     21        sout << "Bonjour au monde!\n";
     22        sout << 3 << " " << 3.5 << " " << 'a' << " " << "abc" << "\n";
     23        int i, j, k;
     24        sin >> &i >> &j >> &k;
     25        sout << "i:" << i << " j:" << j << " k:" << k << "\n";
    2226}
    2327
  • src/examples/iostream.c

    r4389966 r78dd0da  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Dec  7 23:08:02 2015
    13 // Update Count     : 24
     12// Last Modified On : Fri Nov 20 13:19:19 2015
     13// Update Count     : 9
    1414//
    1515
     
    2121
    2222forall( dtype ostype | ostream( ostype ) )
    23 ostype * ?|?( ostype *os, char c ) {
     23ostype * ?<<?( ostype *os, char c ) {
    2424        return write( os, &c, 1 );
    25 } // ?|?
     25} // ?<<?
    2626
    2727forall( dtype ostype | ostream( ostype ) )
    28 ostype * ?|?( ostype *os, int i ) {
     28ostype * ?<<?( ostype *os, int i ) {
    2929        char buffer[32];                                                                        // larger than the largest integer
    3030        sprintf( buffer, "%d", i );
    3131        return write( os, buffer, strlen( buffer ) );
    32 } // ?|?
     32} // ?<<?
    3333
    3434forall( dtype ostype | ostream( ostype ) )
    35 ostype * ?|?( ostype *os, double d ) {
     35ostype * ?<<?( ostype *os, double d ) {
    3636        char buffer[32];                                                                        // larger than the largest double
    3737        sprintf( buffer, "%g", d );
    3838        return write( os, buffer, strlen( buffer ) );
    39 } // ?|?
     39} // ?<<?
    4040
    4141forall( dtype ostype | ostream( ostype ) )
    42 ostype * ?|?( ostype *os, const char *cp ) {
     42ostype * ?<<?( ostype *os, const char *cp ) {
    4343        return write( os, cp, strlen( cp ) );
    44 } // ?|?
     44} // ?<<?
    4545
    4646forall( dtype ostype | ostream( ostype ) )
    47 ostype * ?|?( ostype *os, const void *p ) {
     47ostype * ?<<?( ostype *os, const void *p ) {
    4848        char buffer[32];                                                                        // larger than the largest pointer
    4949        sprintf( buffer, "%p", p );
    5050        return write( os, buffer, strlen( buffer ) );
    51 } // ?|?
    52 
    53 
    54 forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) )
    55 retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) {
    56   return manip(os);
    57 }
    58 
    59 forall( dtype ostype | ostream( ostype ) )
    60 ostype * endl( ostype * os ) {
    61   os | "\n";
    62   // flush
    63   return os;
    64 } // endl
     51} // ?<<?
    6552
    6653forall( type elt_type | writeable( elt_type ),
     
    6956void write( iterator_type begin, iterator_type end, os_type *os ) {
    7057        void print( elt_type i ) {
    71                 os | i | ' ';
     58                os << i << ' ';
    7259        }
    7360        for_each( begin, end, print );
    74 } // ?|?
     61} // ?<<?
    7562
    7663forall( type elt_type | writeable( elt_type ),
     
    7865                dtype os_type | ostream( os_type ) )
    7966void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
    80         void print( elt_type i ) { os | i | ' '; }
     67        void print( elt_type i ) {
     68                os << i << ' ';
     69        }
    8170        for_each_reverse( begin, end, print );
    82 } // ?|?
     71} // ?<<?
    8372
    8473
    8574forall( dtype istype | istream( istype ) )
    86 istype * ?|?( istype *is, char *cp ) {
     75istype * ?>>?( istype *is, char *cp ) {
    8776        return read( is, cp, 1 );
    88 } // ?|?
     77} // ?>>?
    8978
    9079forall( dtype istype | istream( istype ) )
    91 istype * ?|?( istype *is, int *ip ) {
     80istype * ?>>?( istype *is, int *ip ) {
    9281        char cur;
    9382 
    9483        // skip some whitespace
    9584        do {
    96                 is | &cur;
     85                is >> &cur;
    9786                if ( fail( is ) || eof( is ) ) return is;
    9887        } while ( !( cur >= '0' && cur <= '9' ) );
     
    10291        while ( cur >= '0' && cur <= '9' ) {
    10392                *ip = *ip * 10 + ( cur - '0' );
    104                 is | &cur;
     93                is >> &cur;
    10594                if ( fail( is ) || eof( is ) ) return is;
    10695        }
     
    10897        unread( is, cur );
    10998        return is;
    110 } // ?|?
     99} // ?>>?
    111100
    112101// Local Variables: //
  • src/examples/iostream.h

    r4389966 r78dd0da  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Nov 23 14:15:25 2015
    13 // Update Count     : 17
     12// Last Modified On : Thu Nov 19 17:56:51 2015
     13// Update Count     : 5
    1414//
    1515
     
    2727
    2828context writeable( type T ) {
    29         forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
     29        forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, T );
    3030};
    3131
    3232// implement writable for some intrinsic types
    3333
    34 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, char );
    35 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, int );
    36 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double );
    37 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char * );
    38 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const void * );
    39 
    40 forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) ) retostype * ?|?( ostype *os, retostype * (* manip)(ostype*) );
    41 forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * );
     34forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, char );
     35forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, int );
     36forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, double );
     37forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, const char * );
     38forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, void * );
    4239
    4340// writes the range [begin, end) to the given stream
     
    5249void write_reverse( iterator_type begin, iterator_type end, os_type *os );
    5350
    54 //******************************************************************************
    5551
    5652context istream( dtype istype ) {
     
    6258
    6359context readable( type T ) {
    64         forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T );
     60        forall( dtype istype | istream( istype ) ) istype * ?<<?( istype *, T );
    6561};
    6662
    6763forall( dtype istype | istream( istype ) )
    68 istype * ?|?( istype *, char * );
     64istype * ?>>?( istype *, char * );
    6965
    7066forall( dtype istype | istream( istype ) )
    71 istype * ?|?( istype *, int * );
     67istype * ?>>?( istype *, int * );
    7268
    7369#endif // IOSTREAM_H
  • src/examples/sum.c

    r4389966 r78dd0da  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Nov 21 18:08:18 2015
    13 // Update Count     : 119
     12// Last Modified On : Mon Sep 28 15:09:55 2015
     13// Update Count     : 118
    1414//
    1515
     
    5353        }
    5454        sout << "sum from " << low << " to " << High << " is "
    55                  << (int)sum( size, a ) << ", check " << (int)s << endl;
     55                 << (int)sum( size, a ) << ", check " << (int)s << "\n";
    5656
    5757        int s = 0, a[size];
     
    6262        }
    6363        sout << "sum from " << low << " to " << High << " is "
    64                  << sum( size, (int *)a ) << ", check " << (int)s << endl;
     64                 << sum( size, (int *)a ) << ", check " << (int)s << "\n";
    6565
    6666        double s = 0.0, a[size];
     
    7272        printf( "%g\n", sum( size, (double *)a ) );
    7373//      sout << "sum from " << low / 10.0 << " to " << High / 10.0 << " is "
    74 //               << sum( size, (double *)a ) << ", check " << (double)s << endl;
     74//               << sum( size, (double *)a ) << ", check " << (double)s << "\n";
    7575
    7676        float s = 0.0, a[size];
     
    8282        printf( "%g\n", sum( size, (float *)a ) );
    8383//      sout << "sum from " << low / 10.0 << " to " << High / 10.0 << " is "
    84 //               << sum( size, (float *)a ) << ", check " << (float)s << endl;
     84//               << sum( size, (float *)a ) << ", check " << (float)s << "\n";
    8585}
    8686
  • src/examples/vector_test.c

    r4389966 r78dd0da  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 15 16:02:56 2015
    13 // Update Count     : 13
     12// Last Modified On : Thu Nov 19 17:54:34 2015
     13// Update Count     : 9
    1414//
    1515
     
    2727        int num;
    2828
    29         sout | "enter N elements and C-d on a separate line:" | endl;
     29        sout << "enter N elements and C-d on a separate line:\n";
    3030        for ( ;; ) {
    31                 sin | &num;
     31                sin >> &num;
    3232          if ( fail( sin ) || eof( sin ) ) break;
    3333                append( &vec, num );
     
    3535        // write out the numbers
    3636
    37         sout | "Array elements:" | endl;
     37        sout << "Array elements:\n";
    3838        write( begin( vec ), end( vec ), sout );
    39         sout | endl;
     39        sout << "\n";
    4040
    41         sout | "Array elements reversed:" | endl;
     41        sout << "Array elements reversed:\n";
    4242        write_reverse( begin( vec ), end( vec ), sout );
    43         sout | endl;
     43        sout << "\n";
    4444}
    4545
Note: See TracChangeset for help on using the changeset viewer.