Changes in / [ae7f1e0:c44e622]


Ignore:
Location:
src
Files:
3 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rae7f1e0 rc44e622  
    2525#include "PolyMutator.h"
    2626#include "FindFunction.h"
     27#include "ScopedMap.h"
    2728#include "ScrubTyVars.h"
    2829
     
    3738
    3839#include "ResolvExpr/TypeEnvironment.h"
    39 #include "ResolvExpr/TypeMap.h"
    40 #include "ResolvExpr/typeops.h"
    4140
    4241#include "SymTab/Mangler.h"
     
    7473                        /// Makes a new temporary array holding the offsets of the fields of `type`, and returns a new variable expression referencing it
    7574                        Expression *makeOffsetArray( StructInstType *type );
    76                         /// Pass the extra type parameters from polymorphic generic arguments or return types into a function application
    77                         void passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes );
    7875                        /// passes extra type parameters into a polymorphic function application
    79                         void passTypeVars( ApplicationExpr *appExpr, ReferenceToType *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );
     76                        void passTypeVars( ApplicationExpr *appExpr, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );
    8077                        /// wraps a function application with a new temporary for the out-parameter return value
    8178                        Expression *addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg );
     
    10299                        typedef std::map< std::string, DeclarationWithType *> AdapterMap;
    103100                        std::map< std::string, DeclarationWithType *> assignOps;
    104                         ResolvExpr::TypeMap< DeclarationWithType > scopedAssignOps;
     101                        ScopedMap< std::string, DeclarationWithType *> scopedAssignOps;
    105102                        std::stack< AdapterMap > adapters;
    106103                        DeclarationWithType *retval;
     
    249246                }
    250247
    251                 /// Returns T if the given declaration is (*?=?)(T *, T) for some TypeInstType T (return not checked, but maybe should be), NULL otherwise
    252                 TypeInstType *isTypeInstAssignment( DeclarationWithType *decl ) {
     248                /// returns T if the given declaration is: (*?=?)(T *, T) for some T (return not checked, but maybe should be), NULL otherwise
     249                ReferenceToType *isAssignment( DeclarationWithType *decl ) {
    253250                        if ( decl->get_name() == "?=?" ) {
    254251                                if ( FunctionType *funType = getFunctionType( decl->get_type() ) ) {
    255252                                        if ( funType->get_parameters().size() == 2 ) {
    256253                                                if ( PointerType *pointer = dynamic_cast< PointerType *>( funType->get_parameters().front()->get_type() ) ) {
    257                                                         if ( TypeInstType *refType = dynamic_cast< TypeInstType *>( pointer->get_base() ) ) {
    258                                                                 if ( TypeInstType *refType2 = dynamic_cast< TypeInstType *>( funType->get_parameters().back()->get_type() ) ) {
     254                                                        if ( ReferenceToType *refType = dynamic_cast< ReferenceToType *>( pointer->get_base() ) ) {
     255                                                                if ( ReferenceToType *refType2 = dynamic_cast< ReferenceToType *>( funType->get_parameters().back()->get_type() ) ) {
    259256                                                                        if ( refType->get_name() == refType2->get_name() ) {
    260257                                                                                return refType;
     
    268265                        return 0;
    269266                }
    270                
    271                 /// returns T if the given declaration is: (*?=?)(T *, T) for some type T (return not checked, but maybe should be), NULL otherwise
    272                 /// Only picks assignments where neither parameter is cv-qualified
    273                 Type *isAssignment( DeclarationWithType *decl ) {
    274                         if ( decl->get_name() == "?=?" ) {
    275                                 if ( FunctionType *funType = getFunctionType( decl->get_type() ) ) {
    276                                         if ( funType->get_parameters().size() == 2 ) {
    277                                                 Type::Qualifiers defaultQualifiers;
    278                                                 Type *paramType1 = funType->get_parameters().front()->get_type();
    279                                                 if ( paramType1->get_qualifiers() != defaultQualifiers ) return 0;
    280                                                 Type *paramType2 = funType->get_parameters().back()->get_type();
    281                                                 if ( paramType2->get_qualifiers() != defaultQualifiers ) return 0;
    282                                                
    283                                                 if ( PointerType *pointerType = dynamic_cast< PointerType* >( paramType1 ) ) {
    284                                                         Type *baseType1 = pointerType->get_base();
    285                                                         if ( baseType1->get_qualifiers() != defaultQualifiers ) return 0;
    286                                                         SymTab::Indexer dummy;
    287                                                         if ( ResolvExpr::typesCompatible( baseType1, paramType2, dummy ) ) {
    288                                                                 return baseType1;
    289                                                         } // if
    290                                                 } // if
    291                                         } // if
    292                                 } // if
    293                         } // if
    294                         return 0;
    295                 }
    296267
    297268                void Pass1::findAssignOps( const std::list< TypeDecl *> &forall ) {
     
    301272                                for ( std::list< DeclarationWithType *>::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
    302273                                        std::string typeName;
    303                                         if ( TypeInstType *typeInst = isTypeInstAssignment( *assert ) ) {
     274                                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( isAssignment( *assert ) ) ) {
    304275                                                assignOps[ typeInst->get_name() ] = *assert;
    305276                                        } // if
     
    310281                DeclarationWithType *Pass1::mutate( FunctionDecl *functionDecl ) {
    311282                        // if this is a polymorphic assignment function, put it in the map for this scope
    312                         if ( Type *assignedType = isAssignment( functionDecl ) ) {
    313                                 if ( ! dynamic_cast< TypeInstType* >( assignedType ) ) {
    314                                         scopedAssignOps.insert( assignedType, functionDecl );
     283                        if ( ReferenceToType *refType = isAssignment( functionDecl ) ) {
     284                                if ( ! dynamic_cast< TypeInstType* >( refType ) ) {
     285                                        scopedAssignOps.insert( refType->get_name(), functionDecl );
    315286                                }
    316287                        }
     
    427398                }
    428399
    429                 void Pass1::passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes ) {
    430                         Type *polyBase = hasPolyBase( parmType, exprTyVars );
    431                         if ( polyBase && ! dynamic_cast< TypeInstType* >( polyBase ) ) {
    432                                 std::string sizeName = sizeofName( polyBase );
    433                                 if ( seenTypes.count( sizeName ) ) return;
    434 
    435                                 arg = appExpr->get_args().insert( arg, new SizeofExpr( argBaseType->clone() ) );
    436                                 arg++;
    437                                 arg = appExpr->get_args().insert( arg, new AlignofExpr( argBaseType->clone() ) );
    438                                 arg++;
    439                                 if ( dynamic_cast< StructInstType* >( polyBase ) ) {
    440                                         if ( StructInstType *argBaseStructType = dynamic_cast< StructInstType* >( argBaseType ) ) {
    441                                                 arg = appExpr->get_args().insert( arg, makeOffsetArray( argBaseStructType ) );
    442                                                 arg++;
    443                                         } else {
    444                                                 throw SemanticError( "Cannot pass non-struct type for generic struct" );
    445                                         }
    446                                 }
    447 
    448                                 seenTypes.insert( sizeName );
    449                         }
    450                 }
    451 
    452                 void Pass1::passTypeVars( ApplicationExpr *appExpr, ReferenceToType *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
     400                void Pass1::passTypeVars( ApplicationExpr *appExpr, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
    453401                        // pass size/align for type variables
    454402                        for ( TyVarMap::const_iterator tyParm = exprTyVars.begin(); tyParm != exprTyVars.end(); ++tyParm ) {
     
    476424                        std::list< Expression* >::const_iterator fnArg = arg;
    477425                        std::set< std::string > seenTypes; //< names for generic types we've seen
    478 
    479                         // a polymorphic return type may need to be added to the argument list
    480                         if ( polyRetType ) {
    481                                 Type *concRetType = replaceWithConcrete( appExpr, polyRetType );
    482                                 passArgTypeVars( appExpr, polyRetType, concRetType, arg, exprTyVars, seenTypes );
    483                         }
    484                        
    485                         // add type information args for presently unseen types in parameter list
    486426                        for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {
    487                                 VariableExpr *fnArgBase = getBaseVar( *fnArg );
    488                                 if ( ! fnArgBase || fnArgBase->get_results().empty() ) continue;
    489                                 passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_results().front(), arg, exprTyVars, seenTypes );
     427                                Type *polyBase = hasPolyBase( (*fnParm)->get_type(), exprTyVars );
     428                                if ( polyBase && ! dynamic_cast< TypeInstType* >( polyBase ) ) {
     429                                        std::string sizeName = sizeofName( polyBase );
     430                                        if ( seenTypes.count( sizeName ) ) continue;
     431
     432                                        VariableExpr *fnArgBase = getBaseVar( *fnArg );
     433                                        assert( fnArgBase && ! fnArgBase->get_results().empty() );
     434                                        Type *argBaseType = fnArgBase->get_results().front();
     435                                        arg = appExpr->get_args().insert( arg, new SizeofExpr( argBaseType->clone() ) );
     436                                        arg++;
     437                                        arg = appExpr->get_args().insert( arg, new AlignofExpr( argBaseType->clone() ) );
     438                                        arg++;
     439                                        if ( dynamic_cast< StructInstType* >( polyBase ) ) {
     440                                                if ( StructInstType *argBaseStructType = dynamic_cast< StructInstType* >( argBaseType ) ) {
     441                                                        arg = appExpr->get_args().insert( arg, makeOffsetArray( argBaseStructType ) );
     442                                                        arg++;
     443                                                } else {
     444                                                        throw SemanticError( "Cannot pass non-struct type for generic struct" );
     445                                                }
     446                                        }
     447
     448                                        seenTypes.insert( sizeName );
     449                                }
    490450                        }
    491451                }
     
    510470                        ObjectDecl *newObj = makeTemporary( retType->clone() );
    511471                        Expression *paramExpr = new VariableExpr( newObj );
    512 
    513                         // If the type of the temporary is not polymorphic, box temporary by taking its address;
    514                         // otherwise the temporary is already boxed and can be used directly.
     472                        // If the type of the temporary is not polymorphic, box temporary by taking its address; otherwise the
     473                        // temporary is already boxed and can be used directly.
    515474                        if ( ! isPolyType( newObj->get_type(), scopeTyVars, env ) ) {
    516475                                paramExpr = new AddressExpr( paramExpr );
     
    561520                        assert( env );
    562521                        Type *concrete = replaceWithConcrete( appExpr, polyType );
    563                         // add out-parameter for return value   
    564522                        return addRetParam( appExpr, function, concrete, arg );
    565523                }
     
    584542                        assert( ! arg->get_results().empty() );
    585543                        if ( isPolyType( param, exprTyVars ) ) {
    586                                 if ( isPolyType( arg->get_results().front() ) ) {
    587                                         // if the argument's type is polymorphic, we don't need to box again!
     544                                if ( dynamic_cast< TypeInstType *>( arg->get_results().front() ) ) {
     545                                        // if the argument's type is a type parameter, we don't need to box again!
    588546                                        return;
    589547                                } else if ( arg->get_results().front()->get_isLvalue() ) {
     
    664622                        assert( arg );
    665623                        if ( isPolyType( realParam->get_type(), tyVars ) ) {
    666                                 if ( ! isPolyType( arg->get_type() ) ) {
     624                                if ( dynamic_cast<TypeInstType *>(arg->get_type()) == NULL ) {
    667625                                        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    668626                                        deref->get_args().push_back( new CastExpr( new VariableExpr( param ), new PointerType( Type::Qualifiers(), arg->get_type()->clone() ) ) );
     
    959917                        std::list< Expression *>::iterator paramBegin = appExpr->get_args().begin();
    960918
    961                         TyVarMap exprTyVars;
    962                         makeTyVarMap( function, exprTyVars );
    963                         ReferenceToType *polyRetType = isPolyRet( function );
    964 
    965                         if ( polyRetType ) {
    966                                 ret = addPolyRetParam( appExpr, function, polyRetType, arg );
     919                        if ( ReferenceToType *polyType = isPolyRet( function ) ) {
     920                                ret = addPolyRetParam( appExpr, function, polyType, arg );
    967921                        } else if ( needsAdapter( function, scopeTyVars ) ) {
    968922                                // std::cerr << "needs adapter: ";
     
    976930                        arg = appExpr->get_args().begin();
    977931
    978                         passTypeVars( appExpr, polyRetType, arg, exprTyVars );
     932                        TyVarMap exprTyVars;
     933                        makeTyVarMap( function, exprTyVars );
     934
     935                        passTypeVars( appExpr, arg, exprTyVars );
    979936                        addInferredParams( appExpr, function, arg, exprTyVars );
    980937
     
    1035992                }
    1036993
    1037                 /// Wraps a function declaration in a new pointer-to-function variable expression
    1038                 VariableExpr *wrapFunctionDecl( DeclarationWithType *functionDecl ) {
    1039                         // line below cloned from FixFunction.cc
    1040                         ObjectDecl *functionObj = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0,
    1041                                                                   new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 );
    1042                         functionObj->set_mangleName( functionDecl->get_mangleName() );
    1043                         return new VariableExpr( functionObj );
    1044                 }
    1045                
    1046994                Statement * Pass1::mutate( ReturnStmt *returnStmt ) {
    1047995                        if ( retval && returnStmt->get_expr() ) {
     
    10591007
    10601008                                // find assignment operator for (polymorphic) return type
    1061                                 ApplicationExpr *assignExpr = 0;
     1009                                DeclarationWithType *assignDecl = 0;
    10621010                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() ) ) {
    1063                                         // find assignment operator for type variable
    10641011                                        std::map< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );
    10651012                                        if ( assignIter == assignOps.end() ) {
    10661013                                                throw SemanticError( "Attempt to return dtype or ftype object in ", returnStmt->get_expr() );
    10671014                                        } // if
    1068                                         assignExpr = new ApplicationExpr( new VariableExpr( assignIter->second ) );
     1015                                        assignDecl = assignIter->second;
    10691016                                } else if ( ReferenceToType *refType = dynamic_cast< ReferenceToType *>( retval->get_type() ) ) {
    1070                                         // find assignment operator for generic type
    1071                                         DeclarationWithType *functionDecl = scopedAssignOps.find( refType );
    1072                                         if ( ! functionDecl ) {
     1017                                        ScopedMap< std::string, DeclarationWithType *>::const_iterator assignIter = scopedAssignOps.find( refType->get_name() );
     1018                                        if ( assignIter == scopedAssignOps.end() ) {
    10731019                                                throw SemanticError( "Attempt to return dtype or ftype generic object in ", returnStmt->get_expr() );
    10741020                                        }
    1075 
    1076                                         // wrap it up in an application expression
    1077                                         assignExpr = new ApplicationExpr( wrapFunctionDecl( functionDecl ) );
    1078                                         assignExpr->set_env( env->clone() );
    1079 
    1080                                         // find each of its needed secondary assignment operators
    1081                                         std::list< Expression* > &tyParams = refType->get_parameters();
    1082                                         std::list< TypeDecl* > &forallParams = functionDecl->get_type()->get_forall();
    1083                                         std::list< Expression* >::const_iterator tyIt = tyParams.begin();
    1084                                         std::list< TypeDecl* >::const_iterator forallIt = forallParams.begin();
    1085                                         for ( ; tyIt != tyParams.end() && forallIt != forallParams.end(); ++tyIt, ++forallIt ) {
    1086                                                 if ( (*forallIt)->get_kind() != TypeDecl::Any ) continue; // skip types with no assign op (ftype/dtype)
    1087 
    1088                                                 std::list< DeclarationWithType* > &asserts = (*forallIt)->get_assertions();
    1089                                                 assert( ! asserts.empty() && "Type param needs assignment operator assertion" );
    1090                                                 DeclarationWithType *actualDecl = asserts.front();
    1091                                                 TypeInstType *actualType = isTypeInstAssignment( actualDecl );
    1092                                                 assert( actualType && "First assertion of type with assertions should be assignment operator" );
    1093                                                 TypeExpr *formalTypeExpr = dynamic_cast< TypeExpr* >( *tyIt );
    1094                                                 assert( formalTypeExpr && "type parameters must be type expressions" );
    1095                                                 Type *formalType = formalTypeExpr->get_type();
    1096                                                 assignExpr->get_env()->add( actualType->get_name(), formalType );
    1097                                                
    1098                                                 DeclarationWithType *assertAssign = 0;
    1099                                                 if ( TypeInstType *formalTypeInstType = dynamic_cast< TypeInstType* >( formalType ) ) {
    1100                                                         std::map< std::string, DeclarationWithType *>::const_iterator assertAssignIt = assignOps.find( formalTypeInstType->get_name() );
    1101                                                         if ( assertAssignIt == assignOps.end() ) {
    1102                                                                 throw SemanticError( "No assignment operation found for ", formalTypeInstType );
    1103                                                         }
    1104                                                         assertAssign = assertAssignIt->second;
    1105                                                 } else {
    1106                                                         assertAssign = scopedAssignOps.find( formalType );
    1107                                                         if ( ! assertAssign ) {
    1108                                                                 throw SemanticError( "No assignment operation found for ", formalType );
    1109                                                         }
    1110                                                 }
    1111                                                
    1112 
    1113                                                 assignExpr->get_inferParams()[ actualDecl->get_uniqueId() ]
    1114                                                         = ParamEntry( assertAssign->get_uniqueId(), assertAssign->get_type()->clone(), actualDecl->get_type()->clone(), wrapFunctionDecl( assertAssign ) );
    1115                                         }
     1021                                        DeclarationWithType *functionDecl = assignIter->second;
     1022                                        // line below cloned from FixFunction.cc
     1023                                        assignDecl = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0,
     1024                                                                     new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 );
     1025                                        assignDecl->set_mangleName( functionDecl->get_mangleName() );
    11161026                                }
    1117                                 assert( assignExpr );
     1027                                assert( assignDecl );
    11181028
    11191029                                // replace return statement with appropriate assignment to out parameter
     1030                                ApplicationExpr *assignExpr = new ApplicationExpr( new VariableExpr( assignDecl ) );
    11201031                                Expression *retParm = new NameExpr( retval->get_name() );
    11211032                                retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
     
    12691180                        }
    12701181
    1271                         // add size/align for generic parameter types to parameter list
     1182                        // add size/align for generic types to parameter list
    12721183                        std::set< std::string > seenTypes; // sizeofName for generic types we've seen
    12731184                        for ( std::list< DeclarationWithType* >::const_iterator fnParm = last; fnParm != funcType->get_parameters().end(); ++fnParm ) {
     
    13841295
    13851296                                if ( DeclarationWithType *declWithType = dynamic_cast< DeclarationWithType* >( *decl ) ) {
    1386                                         if ( memberDecl->get_mangleName().empty() || declWithType->get_mangleName().empty()
    1387                                              || memberDecl->get_mangleName() == declWithType->get_mangleName() ) return i;
     1297                                        if ( memberDecl->get_mangleName() == declWithType->get_mangleName() ) return i;
    13881298                                        else continue;
    13891299                                } else return i;
     
    14311341                        if ( ! objectType ) return memberExpr;
    14321342
    1433                         Expression *newMemberExpr = 0;
    14341343                        if ( StructInstType *structType = dynamic_cast< StructInstType* >( objectType ) ) {
    14351344                                // look up offset index
     
    14411350                                fieldLoc->get_args().push_back( makeDerefdVar( varExpr->clone(), varDepth ) );
    14421351                                fieldLoc->get_args().push_back( makeOffsetIndex( objectType, i ) );
    1443                                 newMemberExpr = fieldLoc;
    1444                         } else if ( dynamic_cast< UnionInstType* >( objectType ) ) {
     1352
     1353                                delete memberExpr;
     1354                                return fieldLoc;
     1355                        } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( objectType ) ) {
    14451356                                // union members are all at offset zero, so build appropriately-dereferenced variable
    1446                                 newMemberExpr = makeDerefdVar( varExpr->clone(), varDepth );
     1357                                Expression *derefdVar = makeDerefdVar( varExpr->clone(), varDepth );
     1358                                delete memberExpr;
     1359                                return derefdVar;
    14471360                        } else return memberExpr;
    1448                         assert( newMemberExpr );
    1449 
    1450                         Type *memberType = memberExpr->get_member()->get_type();
    1451                         if ( ! isPolyType( memberType, scopeTyVars ) ) {
    1452                                 // Not all members of a polymorphic type are themselves of polymorphic type; in this case the member expression should be wrapped and dereferenced to form an lvalue
    1453                                 CastExpr *ptrCastExpr = new CastExpr( newMemberExpr, new PointerType( Type::Qualifiers(), memberType->clone() ) );
    1454                                 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
    1455                                 derefExpr->get_args().push_back( ptrCastExpr );
    1456                                 newMemberExpr = derefExpr;
    1457                         }
    1458 
    1459                         delete memberExpr;
    1460                         return newMemberExpr;
    14611361                }
    14621362
     
    14791379                                delete offsetofExpr;
    14801380                                return offsetInd;
    1481                         } else if ( dynamic_cast< UnionInstType* >( ty ) ) {
     1381                        } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( ty ) ) {
    14821382                                // all union members are at offset zero
    14831383                                delete offsetofExpr;
  • src/ResolvExpr/AlternativeFinder.cc

    rae7f1e0 rc44e622  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // AlternativeFinder.cc --
     7// AlternativeFinder.cc -- 
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Sat May 16 23:52:08 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Feb 10 17:00:04 2016
    13 // Update Count     : 24
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Jul  3 17:58:39 2015
     13// Update Count     : 22
    1414//
    1515
     
    4141
    4242extern bool resolvep;
    43 #define PRINT( text ) if ( resolvep ) { text }
     43#define PRINT( text ) if ( resolvep ) { text } 
    4444//#define DEBUG_COST
    4545
     
    107107                                        if ( candidate->cost < mapPlace->second.candidate->cost ) {
    108108                                                PRINT(
    109                                                         std::cerr << "cost " << candidate->cost << " beats " << mapPlace->second.candidate->cost << std::endl;
     109                                                        std::cout << "cost " << candidate->cost << " beats " << mapPlace->second.candidate->cost << std::endl;
    110110                                                )
    111111                                                selected[ mangleName ] = current;
    112112                                        } else if ( candidate->cost == mapPlace->second.candidate->cost ) {
    113113                                                PRINT(
    114                                                         std::cerr << "marking ambiguous" << std::endl;
     114                                                        std::cout << "marking ambiguous" << std::endl;
    115115                                                )
    116116                                                mapPlace->second.isAmbiguous = true;
     
    122122
    123123                        PRINT(
    124                                 std::cerr << "there are " << selected.size() << " alternatives before elimination" << std::endl;
     124                                std::cout << "there are " << selected.size() << " alternatives before elimination" << std::endl;
    125125                        )
    126126
     
    182182                        begin++;
    183183                        PRINT(
    184                                 std::cerr << "findSubExprs" << std::endl;
    185                                 printAlts( finder.alternatives, std::cerr );
     184                                std::cout << "findSubExprs" << std::endl;
     185                                printAlts( finder.alternatives, std::cout );
    186186                        )
    187187                        *out++ = finder;
     
    204204                }
    205205                PRINT(
    206                         std::cerr << "alternatives before prune:" << std::endl;
    207                         printAlts( alternatives, std::cerr );
     206                        std::cout << "alternatives before prune:" << std::endl;
     207                        printAlts( alternatives, std::cout );
    208208                )
    209209                AltList::iterator oldBegin = alternatives.begin();
     
    221221                alternatives.erase( oldBegin, alternatives.end() );
    222222                PRINT(
    223                         std::cerr << "there are " << alternatives.size() << " alternatives after elimination" << std::endl;
     223                        std::cout << "there are " << alternatives.size() << " alternatives after elimination" << std::endl;
    224224                )
    225225        }
     
    261261                for ( std::list< Expression* >::iterator actualExpr = actuals.begin(); actualExpr != actuals.end(); ++actualExpr ) {
    262262                        PRINT(
    263                                 std::cerr << "actual expression:" << std::endl;
    264                                 (*actualExpr)->print( std::cerr, 8 );
    265                                 std::cerr << "--- results are" << std::endl;
    266                                 printAll( (*actualExpr)->get_results(), std::cerr, 8 );
     263                                std::cout << "actual expression:" << std::endl;
     264                                (*actualExpr)->print( std::cout, 8 );
     265                                std::cout << "--- results are" << std::endl;
     266                                printAll( (*actualExpr)->get_results(), std::cout, 8 );
    267267                        )
    268268                        std::list< DeclarationWithType* >::iterator startFormal = formal;
     
    278278                                }
    279279                                PRINT(
    280                                         std::cerr << std::endl << "converting ";
    281                                         (*actual)->print( std::cerr, 8 );
    282                                         std::cerr << std::endl << " to ";
    283                                         (*formal)->get_type()->print( std::cerr, 8 );
     280                                        std::cout << std::endl << "converting ";
     281                                        (*actual)->print( std::cout, 8 );
     282                                        std::cout << std::endl << " to ";
     283                                        (*formal)->get_type()->print( std::cout, 8 );
    284284                                )
    285285                                Cost newCost = conversionCost( *actual, (*formal)->get_type(), indexer, alt.env );
    286286                                PRINT(
    287                                         std::cerr << std::endl << "cost is" << newCost << std::endl;
     287                                        std::cout << std::endl << "cost is" << newCost << std::endl;
    288288                                )
    289289
     
    323323                for ( InferredParams::const_iterator assert = appExpr->get_inferParams().begin(); assert != appExpr->get_inferParams().end(); ++assert ) {
    324324                        PRINT(
    325                                 std::cerr << std::endl << "converting ";
    326                                 assert->second.actualType->print( std::cerr, 8 );
    327                                 std::cerr << std::endl << " to ";
    328                                 assert->second.formalType->print( std::cerr, 8 );
     325                                std::cout << std::endl << "converting ";
     326                                assert->second.actualType->print( std::cout, 8 );
     327                                std::cout << std::endl << " to ";
     328                                assert->second.formalType->print( std::cout, 8 );
    329329                                )
    330330                                Cost newCost = conversionCost( assert->second.actualType, assert->second.formalType, indexer, alt.env );
    331331                        PRINT(
    332                                 std::cerr << std::endl << "cost of conversion is " << newCost << std::endl;
     332                                std::cout << std::endl << "cost of conversion is " << newCost << std::endl;
    333333                                )
    334334                                if ( newCost == Cost::infinity ) {
     
    448448                std::list< DeclarationWithType* > candidates;
    449449                decls.lookupId( curDecl->get_name(), candidates );
    450 ///   if ( candidates.empty() ) { std::cerr << "no candidates!" << std::endl; }
     450///   if ( candidates.empty() ) { std::cout << "no candidates!" << std::endl; }
    451451                for ( std::list< DeclarationWithType* >::const_iterator candidate = candidates.begin(); candidate != candidates.end(); ++candidate ) {
    452452                        PRINT(
    453                                 std::cerr << "inferRecursive: candidate is ";
    454                                 (*candidate)->print( std::cerr );
    455                                 std::cerr << std::endl;
     453                                std::cout << "inferRecursive: candidate is ";
     454                                (*candidate)->print( std::cout );
     455                                std::cout << std::endl;
    456456                        )
    457457                        AssertionSet newHave, newerNeed( newNeed );
     
    482482                                varExpr->get_results().push_front( adjType->clone() );
    483483                                PRINT(
    484                                         std::cerr << "satisfying assertion " << curDecl->get_uniqueId() << " ";
    485                                         curDecl->print( std::cerr );
    486                                         std::cerr << " with declaration " << (*candidate)->get_uniqueId() << " ";
    487                                         (*candidate)->print( std::cerr );
    488                                         std::cerr << std::endl;
     484                                        std::cout << "satisfying assertion " << curDecl->get_uniqueId() << " ";
     485                                        curDecl->print( std::cout );
     486                                        std::cout << " with declaration " << (*candidate)->get_uniqueId() << " ";
     487                                        (*candidate)->print( std::cout );
     488                                        std::cout << std::endl;
    489489                                )
    490490                                ApplicationExpr *appExpr = static_cast< ApplicationExpr* >( newerAlt.expr );
     
    501501        void AlternativeFinder::inferParameters( const AssertionSet &need, AssertionSet &have, const Alternative &newAlt, OpenVarSet &openVars, OutputIterator out ) {
    502502//      PRINT(
    503 //          std::cerr << "inferParameters: assertions needed are" << std::endl;
    504 //          printAll( need, std::cerr, 8 );
     503//          std::cout << "inferParameters: assertions needed are" << std::endl;
     504//          printAll( need, std::cout, 8 );
    505505//          )
    506506                SymTab::Indexer decls( indexer );
    507507                PRINT(
    508                         std::cerr << "============= original indexer" << std::endl;
    509                         indexer.print( std::cerr );
    510                         std::cerr << "============= new indexer" << std::endl;
    511                         decls.print( std::cerr );
     508                        std::cout << "============= original indexer" << std::endl;
     509                        indexer.print( std::cout );
     510                        std::cout << "============= new indexer" << std::endl;
     511                        decls.print( std::cout );
    512512                )
    513513                addToIndexer( have, decls );
     
    515515                inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, 0, indexer, out );
    516516//      PRINT(
    517 //          std::cerr << "declaration 14 is ";
     517//          std::cout << "declaration 14 is ";
    518518//          Declaration::declFromId
    519519//          *out++ = newAlt;
     
    532532                        makeExprList( actualAlt, appExpr->get_args() );
    533533                        PRINT(
    534                                 std::cerr << "need assertions:" << std::endl;
    535                                 printAssertionSet( resultNeed, std::cerr, 8 );
     534                                std::cout << "need assertions:" << std::endl;
     535                                printAssertionSet( resultNeed, std::cout, 8 );
    536536                        )
    537537                        inferParameters( resultNeed, resultHave, newAlt, openVars, out );
     
    543543                AlternativeFinder funcOpFinder( indexer, env );
    544544
    545                 AlternativeFinder funcFinder( indexer, env );
    546 
    547                 {
     545                AlternativeFinder funcFinder( indexer, env ); {
    548546                        NameExpr *fname = 0;;
    549547                        if ( ( fname = dynamic_cast<NameExpr *>( untypedExpr->get_function()))
     
    575573                for ( AltList::const_iterator func = funcFinder.alternatives.begin(); func != funcFinder.alternatives.end(); ++func ) {
    576574                        PRINT(
    577                                 std::cerr << "working on alternative: " << std::endl;
    578                                 func->print( std::cerr, 8 );
     575                                std::cout << "working on alternative: " << std::endl;
     576                                func->print( std::cout, 8 );
    579577                        )
    580578                        // check if the type is pointer to function
     
    608606                                        }
    609607                                        PRINT(
    610                                                 std::cerr << "known function ops:" << std::endl;
    611                                                 printAlts( funcOpFinder.alternatives, std::cerr, 8 );
     608                                                std::cout << "known function ops:" << std::endl;
     609                                                printAlts( funcOpFinder.alternatives, std::cout, 8 );
    612610                                        )
    613611                                }
     
    641639                                FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
    642640                                assert( function );
    643                                 std::cerr << "Case +++++++++++++" << std::endl;
    644                                 std::cerr << "formals are:" << std::endl;
    645                                 printAll( function->get_parameters(), std::cerr, 8 );
    646                                 std::cerr << "actuals are:" << std::endl;
    647                                 printAll( appExpr->get_args(), std::cerr, 8 );
    648                                 std::cerr << "bindings are:" << std::endl;
    649                                 withFunc->env.print( std::cerr, 8 );
    650                                 std::cerr << "cost of conversion is:" << cvtCost << std::endl;
     641                                std::cout << "Case +++++++++++++" << std::endl;
     642                                std::cout << "formals are:" << std::endl;
     643                                printAll( function->get_parameters(), std::cout, 8 );
     644                                std::cout << "actuals are:" << std::endl;
     645                                printAll( appExpr->get_args(), std::cout, 8 );
     646                                std::cout << "bindings are:" << std::endl;
     647                                withFunc->env.print( std::cout, 8 );
     648                                std::cout << "cost of conversion is:" << cvtCost << std::endl;
    651649                        )
    652650                        if ( cvtCost != Cost::infinity ) {
     
    826824                }
    827825        }
    828 
     826       
    829827        void AlternativeFinder::visit( UntypedOffsetofExpr *offsetofExpr ) {
    830828                AlternativeFinder funcFinder( indexer, env );
     
    835833                }
    836834        }
    837 
     835       
    838836        void AlternativeFinder::visit( OffsetofExpr *offsetofExpr ) {
    839837                alternatives.push_back( Alternative( offsetofExpr->clone(), env, Cost::zero ) );
     
    845843                assert( function->get_parameters().size() == 1 );
    846844                PRINT(
    847                         std::cerr << "resolvAttr: funcDecl is ";
    848                         funcDecl->print( std::cerr );
    849                         std::cerr << " argType is ";
    850                         argType->print( std::cerr );
    851                         std::cerr << std::endl;
     845                        std::cout << "resolvAttr: funcDecl is ";
     846                        funcDecl->print( std::cout );
     847                        std::cout << " argType is ";
     848                        argType->print( std::cout );
     849                        std::cout << std::endl;
    852850                )
    853851                if ( typesCompatibleIgnoreQualifiers( argType, function->get_parameters().front()->get_type(), indexer, env ) ) {
  • src/ResolvExpr/CastCost.cc

    rae7f1e0 rc44e622  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 06:57:43 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  2 15:34:36 2016
    13 // Update Count     : 7
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Mon Oct 05 14:48:45 2015
     13// Update Count     : 5
    1414//
    1515
     
    6969                PointerType *destAsPointer = dynamic_cast< PointerType* >( dest );
    7070                if ( destAsPointer && basicType->isInteger() ) {
    71                         //cost = Cost( 1, 0, 0 );
    72                         cost = Cost::infinity;
     71                        cost = Cost( 1, 0, 0 );
    7372                } else {
    7473                        ConversionCost::visit( basicType );
     
    8887                                        cost = Cost( 0, 0, 1 );
    8988                                } else if ( castResult < 0 ) {
    90                                         cost = Cost::infinity;
    91                                         //cost = Cost( 1, 0, 0 );
     89                                        cost = Cost( 1, 0, 0 );
    9290                                } // if
    9391                        } // if
    9492                } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
    9593                        if ( destAsBasic->isInteger() ) {
    96                                 //cost = Cost( 1, 0, 0 );
    97                                 cost = Cost::infinity;
     94                                cost = Cost( 1, 0, 0 );
    9895                        } // if
    9996                }
  • src/ResolvExpr/Resolver.cc

    rae7f1e0 rc44e622  
    1010// Created On       : Sun May 17 12:17:01 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  9 21:57:52 2016
    13 // Update Count     : 179
     12// Last Modified On : Fri Jul 24 17:33:54 2015
     13// Update Count     : 178
    1414//
    1515
     
    322322                                                                                                BasicType::SignedInt);
    323323                                } else {
    324                                         DeclarationWithType * decl = lookupId( n );
     324                                        DeclarationWithType * decl = lookupId(n);
    325325                                        initContext = decl->get_type();
    326326                                }
     
    344344                                        if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_results().front() ) ) {
    345345                                                if ( isCharType( pt->get_base() ) ) {
    346                                                         // strip cast if we're initializing a char[] with a char *, e.g.  char x[] = "hello";
     346                                                        // strip cast if we're initializing a char[] with a char *, e.g.
     347                                                        // char x[] = "hello";
    347348                                                        CastExpr *ce = dynamic_cast< CastExpr * >( newExpr );
    348349                                                        singleInit->set_value( ce->get_arg() );
  • src/SymTab/Validate.cc

    rae7f1e0 rc44e622  
    382382                // it's not a semantic error if the struct is not found, just an implicit forward declaration
    383383                if ( st ) {
    384                         //assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );
     384                        assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );
    385385                        structInst->set_baseStruct( st );
    386386                } // if
     
    659659        }
    660660
    661         /// Creates a new type decl that's the same as src, but renamed and with only the ?=? assertion (for complete types only)
    662         TypeDecl *cloneAndRename( TypeDecl *src, const std::string &name ) {
    663                 TypeDecl *dst = new TypeDecl( name, src->get_storageClass(), 0, src->get_kind() );
    664 
    665                 if ( src->get_kind() == TypeDecl::Any ) {
    666                         // just include assignment operator assertion
    667                         TypeInstType *assignParamType = new TypeInstType( Type::Qualifiers(), name, dst );
    668                         FunctionType *assignFunctionType = new FunctionType( Type::Qualifiers(), false );
    669                         assignFunctionType->get_returnVals().push_back(
    670                                 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, assignParamType->clone(), 0 ) );
    671                         assignFunctionType->get_parameters().push_back(
    672                                 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), assignParamType->clone() ), 0 ) );
    673                         assignFunctionType->get_parameters().push_back(
    674                                 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, assignParamType, 0 ) );
    675                         FunctionDecl *assignAssert = new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignFunctionType, 0, false, false );
    676                         dst->get_assertions().push_back( assignAssert );
    677                 }
    678 
    679                 return dst;
    680         }
    681 
    682661        Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) {
    683662                FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
     
    687666                std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
    688667                std::list< Expression* > structParams;  // List of matching parameters to put on types
    689                 TypeSubstitution genericSubs; // Substitutions to make to member types of struct
    690668                for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
    691669                        isGeneric = true;
    692                         TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() );
     670                        TypeDecl *typeParam = (*param)->clone();
    693671                        assignType->get_forall().push_back( typeParam );
    694                         TypeInstType *newParamType = new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam );
    695                         genericSubs.add( (*param)->get_name(), newParamType );
    696                         structParams.push_back( new TypeExpr( newParamType ) );
     672                        structParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) );
    697673                }
    698674
     
    725701                                }
    726702
    727                                 if ( isGeneric ) {
    728                                         // rewrite member type in terms of the type variables on this operator
    729                                         DeclarationWithType *fixedMember = dwt->clone();
    730                                         genericSubs.apply( fixedMember );
    731 
    732                                         // assign to both destination and return value
    733                                         if ( ArrayType *array = dynamic_cast< ArrayType * >( fixedMember->get_type() ) ) {
    734                                                 makeArrayAssignment( srcParam, dstParam, fixedMember, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
    735                                                 makeArrayAssignment( srcParam, returnVal, fixedMember, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
    736                                         } else {
    737                                                 makeScalarAssignment( srcParam, dstParam, fixedMember, back_inserter( assignDecl->get_statements()->get_kids() ) );
    738                                                 makeScalarAssignment( srcParam, returnVal, fixedMember, back_inserter( assignDecl->get_statements()->get_kids() ) );
    739                                         } // if
     703                                if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) {
     704                                        makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
     705                                        if ( isGeneric ) makeArrayAssignment( srcParam, returnVal, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
    740706                                } else {
    741                                         // assign to destination
    742                                         if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) {
    743                                                 makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
    744                                         } else {
    745                                                 makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
    746                                         } // if
     707                                        makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
     708                                        if ( isGeneric ) makeScalarAssignment( srcParam, returnVal, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
    747709                                } // if
    748710                        } // if
     
    762724                for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
    763725                        isGeneric = true;
    764                         TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() );
     726                        TypeDecl *typeParam = (*param)->clone();
    765727                        assignType->get_forall().push_back( typeParam );
    766728                        unionParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) );
  • src/Tests/Makefile

    rae7f1e0 rc44e622  
    88OUTPUTS = ${addprefix ${OUTPUTDIR}/,${EXAMPLES:.c=.txt}}
    99
    10 #.SILENT :
     10.SILENT :
    1111
    1212all :
     
    1919
    2020${OUTPUTDIR}/%.txt : %.c ${CFA} Makefile
    21         -${CFA} -n ${CFAOPT} $< > $@ 2>&1
     21        -${CFA} -n ${CFAOPT} < $< > $@ 2>&1
    2222
    2323${OUTPUTDIR}/report : ${OUTPUTS} ${EXPECTDIR}
  • src/examples/abs.c

    rae7f1e0 rc44e622  
    1010// Created On       : Thu Jan 28 18:26:16 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 09:32:04 2016
    13 // Update Count     : 44
     12// Last Modified On : Wed Feb  3 11:14:58 2016
     13// Update Count     : 43
    1414//
    1515
     
    1818
    1919int main( void ) {
     20        ofstream *sout = ofstream_stdout();
     21
    2022        char ch = -65;
    2123        sout | "char\t\t\t"                                     | ch     | "\tabs " | abs( ch ) | endl;
  • src/examples/alloc.c

    rae7f1e0 rc44e622  
    1111// Created On       : Wed Feb  3 07:56:22 2016
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Wed Feb 17 11:43:23 2016
    14 // Update Count     : 40
     13// Last Modified On : Wed Feb  3 16:32:04 2016
     14// Update Count     : 38
    1515//
    1616
     
    2727
    2828int main( void ) {
     29    ofstream * sout = ofstream_stdout();
     30
    2931    size_t size = 10;
    3032    int * p;
     
    98100    free( x );
    99101#endif
     102    free( sout );
    100103}
    101104
  • src/examples/fstream_test.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 11:45:43 2016
    13 // Update Count     : 43
     12// Last Modified On : Tue Jan 26 17:11:33 2016
     13// Update Count     : 42
    1414//
    1515
     
    1717
    1818int main( void ) {
     19        ofstream *sout = ofstream_stdout();
     20        ifstream *sin = ifstream_stdin();
    1921        int nombre;
    2022        sout | "Entrez un nombre, s'il vous plaît:\n";
  • src/examples/hello.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 12:11:45 2016
    13 // Update Count     : 8
     12// Last Modified On : Tue Jan 26 17:11:49 2016
     13// Update Count     : 7
    1414//
    1515
     
    1717
    1818int main() {
     19        ofstream *sout = ofstream_stdout();
     20        ifstream *sin = ifstream_stdin();
    1921        sout | "Bonjour au monde!\n";
    2022}
  • src/examples/identity.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 12:17:32 2016
    13 // Update Count     : 10
     12// Last Modified On : Tue Jan 26 17:11:58 2016
     13// Update Count     : 8
    1414//
    1515
     
    2222
    2323int main() {
     24        ofstream *sout = ofstream_stdout();
    2425        sout | "char\t\t\t"                                     | identity( 'z' ) | endl;
    2526        sout | "signed int\t\t"                         | identity( 4 ) | endl;
     
    2930        sout | "signed long long int\t"         | identity( 4ll ) | endl;
    3031        sout | "unsigned long long int\t"       | identity( 4ull ) | endl;
    31         sout | "float\t\t\t"                            | identity( 4.1f ) | endl;
    32         sout | "double\t\t\t"                           | identity( 4.1 ) | endl;
    33         sout | "long double\t\t"                        | identity( 4.1l ) | endl;
     32        sout | "float\t\t\t"                            | identity( 4.0f ) | endl;
     33        sout | "double\t\t\t"                           | identity( 4.0 ) | endl;
     34        sout | "long double\t\t"                        | identity( 4.0l ) | endl;
    3435}
    3536
  • src/examples/minmax.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 12:17:53 2016
    13 // Update Count     : 47
     12// Last Modified On : Wed Feb  3 11:14:49 2016
     13// Update Count     : 46
    1414//
    1515
     
    1818
    1919int main( void ) {
     20        ofstream *sout = ofstream_stdout();
    2021        // char does not have less or greater than.
    2122        int ?<?( char op1, char op2 ) { return (int)op1 < (int)op2; }
  • src/examples/quad.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 12:19:24 2016
    13 // Update Count     : 6
     12// Last Modified On : Tue Jan 26 17:13:48 2016
     13// Update Count     : 5
    1414//
    1515
     
    2727
    2828int main() {
     29        ofstream *sout = ofstream_stdout();
    2930        int N = 2;
    3031        sout | "result of quad of " | N | " is " | quad( N ) | endl;
  • src/examples/quoted_keyword.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 12:19:45 2016
    13 // Update Count     : 9
     12// Last Modified On : Tue Jan 26 17:13:58 2016
     13// Update Count     : 8
    1414//
    1515
     
    2828
    2929int main() {
     30        ofstream *sout = ofstream_stdout();
    3031        sout | `catch` + st.`type` + st.`struct` + `throw` | endl;
    3132}
  • src/examples/random.c

    rae7f1e0 rc44e622  
    77
    88int main() {
     9        ofstream *sout = ofstream_stdout();
     10
    911        randseed( getpid() );                                                           // set random seed
    1012
  • src/examples/square.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 12:21:58 2016
    13 // Update Count     : 26
     12// Last Modified On : Tue Jan 26 17:14:16 2016
     13// Update Count     : 25
    1414//
    1515
     
    2323int main() {
    2424#if 0
     25        ofstream *sout = ofstream_stdout();
    2526        sout | "result of squaring 9 is " | endl;
    2627
  • src/examples/sum.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb 16 23:49:31 2016
    13 // Update Count     : 189
     12// Last Modified On : Fri Feb  5 16:47:44 2016
     13// Update Count     : 139
    1414//
    1515
     
    3333
    3434// Required to satisfy sumable as char does not have addition.
    35 const char 0;
    36 char ?+?( char t1, char t2 ) { return (int)t1 + t2; }   // cast forces integer addition, otherwise recursion
    37 char ?+=?( char *t1, char t2 ) { *t1 = *t1 + t2; return *t1; }
    38 char ++?( char *t ) { *t += 1; return *t; }
    39 char ?++( char *t ) { char temp = *t; *t += 1; return temp; }
     35// const char 0;
     36// char ?+?( char op1, char op2 ) { return (int)op1 + op2; } // cast forces integer addition or recursion
     37// char ++?( char *op ) { *op += 1; return *op; }
     38// char ?++( char *op ) { char temp = *op; *op += 1; return temp; }
    4039
    4140int main( void ) {
    4241        const int low = 5, High = 15, size = High - low;
     42        ofstream *sout = ofstream_stdout();
     43#if 0
    4344
    44         char s = 0, a[size], v = low;
     45        char s = 0, a[size];
     46        char v = low;
    4547        for ( int i = 0; i < size; i += 1, v += 1 ) {
    4648                s += v;
    4749                a[i] = v;
    48         } // for
     50        }
    4951        sout | "sum from " | low | " to " | High | " is "
    5052                 | (int)sum( size, a ) | ", check " | (int)s | endl;
    5153
    52         int s = 0, a[size], v = low;
     54        int s = 0, a[size];
     55        int v = low;
    5356        for ( int i = 0; i < size; i += 1, v += 1 ) {
    5457                s += (int)v;
    5558                a[i] = (int)v;
    56         } // for
     59        }
    5760        sout | "sum from " | low | " to " | High | " is "
    5861                 | sum( size, (int *)a ) | ", check " | (int)s | endl;
    5962
    60         float s = 0.0, a[size], v = low / 10.0;
     63        float s = 0.0, a[size];
     64        float v = low / 10.0;
    6165        for ( int i = 0; i < size; i += 1, v += 0.1f ) {
    6266                s += (float)v;
    6367                a[i] = (float)v;
    64         } // for
     68        }
    6569        sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is "
    6670                 | sum( size, (float *)a ) | ", check " | (float)s | endl;
     71#endif
     72        double s = 0, a[size];
     73        double v = low / 10.0;
    6774
    68         double s = 0, a[size], v = low / 10.0;
    6975        for ( int i = 0; i < size; i += 1, v += 0.1 ) {
    7076                s += (double)v;
    7177                a[i] = (double)v;
    72         } // for
     78        }
    7379        sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is "
    7480                 | sum( size, (double *)a ) | ", check " | (double)s | endl;
    7581
    76         struct S { int i, j; } 0 = { 0, 0 }, 1 = { 1, 1 };
    77         S ?+?( S t1, S t2 ) { S s = { t1.i + t2.i, t1.j + t2.j }; return s; }
    78         S ?+=?( S *t1, S t2 ) { *t1 = *t1 + t2; return *t1; }
    79         S ++?( S *t ) { *t += 1; return *t; }
    80         S ?++( S *t ) { S temp = *t; *t += 1; return temp; }
    81         ofstream * ?|?( ofstream * os, S v ) { return os | v.i | ' ' | v.j; }
    82 
    83         S s = 0, a[size], v = { low, low };
    84         for ( int i = 0; i < size; i += 1, v += (S)1 ) {
    85                 s += (S)v;
    86                 a[i] = (S)v;
    87         } // for
    88         sout | "sum from " | low | " to " | High | " is "
    89                  | sum( size, (S *)a ) | ", check " | (S)s | endl;
     82        // struct S { int i, j; } sarr[size];
     83        // struct S 0 = { 0, 0 };
     84        // struct S 1 = { 1, 1 };
     85        // S ?+?( S t1, S t2 ) { S s = { t1.i + t1.j, t2.i + t2.j }; return s; }
     86        // S ?+=?( S *t1, S t2 ) { *t1 = *t1 + t2; return *t1; }
     87        // S ++?( S *t ) { *t += 1; return *t; }
     88        // S ?++( S *t ) { S temp = *t; *t += 1; return temp; }
     89        // sum( size, sarr );
    9090} // main
    9191
  • src/examples/swap.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 12:22:12 2016
    13 // Update Count     : 64
     12// Last Modified On : Wed Feb  3 11:14:04 2016
     13// Update Count     : 63
    1414//
    1515
     
    1818
    1919int main( void ) {
     20        ofstream *sout = ofstream_stdout();
     21
    2022        char c1 = 'a', c2 = 'b';
    2123        sout | "char\t\t\t" | c1 | ' ' | c2 | "\t\t\tswap ";
  • src/examples/twice.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 12:23:25 2016
    13 // Update Count     : 13
     12// Last Modified On : Tue Jan 26 17:14:44 2016
     13// Update Count     : 12
    1414//
    1515
     
    2727        char ?++( char *op ) { char temp = *op; *op += 1; return temp; }
    2828
     29        ofstream *sout = ofstream_stdout();
    2930        sout | twice( 'a' ) | ' ' | twice( 1 ) | ' ' | twice( 3.2 ) | endl;
    3031}
  • src/examples/vector_test.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 12:23:55 2016
    13 // Update Count     : 18
     12// Last Modified On : Tue Jan 26 17:14:52 2016
     13// Update Count     : 17
    1414//
    1515
     
    2020
    2121int main( void ) {
     22        ofstream *sout = ofstream_stdout();
     23        ifstream *sin = ifstream_stdin();
    2224        vector_int vec = vector_int_allocate();
    2325
  • src/libcfa/fstream

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 14:02:01 2016
    13 // Update Count     : 22
     12// Last Modified On : Wed Jan 27 23:47:41 2016
     13// Update Count     : 3
    1414//
    1515
     
    1919#include "iostream"
    2020
     21typedef struct ofstream ofstream;
     22
    2123// implement context ostream
    22 struct ofstream;
     24ofstream *write( ofstream *, const char *, streamsize_type );
     25int fail( ofstream * );
    2326
    24 int fail( ofstream * os );
    25 int flush( ofstream * os );
    26 void open( ofstream ** os, const char * name, const char * mode );
    27 void close( ofstream * os );
    28 ofstream * write( ofstream * os, const char * data, streamsize_type size );
     27ofstream *ofstream_stdout();
     28ofstream *ofstream_stderr();
     29ofstream *ofstream_fromfile( const char *name );
     30void ofstream_close( ofstream *os );
    2931
    30 extern ofstream * sout, * serr;
     32typedef struct ifstream ifstream;
    3133
    3234// implement context istream
    33 struct ifstream;
     35ifstream *read( ifstream *, char *, streamsize_type );
     36ifstream *unread( ifstream *, char );
     37int fail( ifstream * );
     38int eof( ifstream * );
    3439
    35 int fail( ifstream * is );
    36 int eof( ifstream * is );
    37 void open( ifstream ** is, const char * name, const char * mode );
    38 void close( ifstream * is );
    39 ifstream * get( ifstream * is, int * data );
    40 ifstream * read( ifstream * is, char * data, streamsize_type size );
    41 ifstream * ungetc( ifstream * is, char c );
    42 
    43 extern ifstream *sin;
     40ifstream *ifstream_stdin();
     41ifstream *ifstream_fromfile( const char *name );
    4442
    4543#endif // __FSTREAM_H__
  • src/libcfa/fstream.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 14:03:05 2016
    13 // Update Count     : 76
     12// Last Modified On : Tue Jan 26 17:12:59 2016
     13// Update Count     : 6
    1414//
    1515
     
    2323struct ofstream {
    2424        FILE *file;
     25        int fail;
    2526};
    2627
    27 #define IO_MSG "I/O error "
    28 
    29 int fail( ofstream * os ) {
    30         return ferror( os->file );
    31 } // fail
    32 
    33 int flush( ofstream * os ) {
    34         return fflush( os->file );
    35 } // flush
    36 
    37 void open( ofstream ** os, const char * name, const char * mode ) {
    38         FILE *t = fopen( name, mode );
    39         if ( t == 0 ) {                                                                         // do not change unless successful
    40                 perror( IO_MSG "open output" );
    41                 exit( EXIT_FAILURE );
    42         } // if
    43         (*os)->file = t;
    44 } // open
    45 
    46 void close( ofstream * os ) {
    47         if ( os->file == stdout || os->file == stderr ) return;
    48 
    49         if ( fclose( os->file ) == EOF ) {
    50                 perror( IO_MSG "close output" );
    51         } // if
    52 } // close
    53 
    54 ofstream * write( ofstream * os, const char * data, streamsize_type size ) {
    55         if ( fail( os ) ) {
    56                 fprintf( stderr, "attempt write I/O on failed stream\n" );
    57                 exit( EXIT_FAILURE );
    58         } // if
    59 
    60         if ( fwrite( data, 1, size, os->file ) != size ) {
    61                 perror( IO_MSG "write" );
    62                 exit( EXIT_FAILURE );
     28ofstream *write( ofstream *os, const char *data, streamsize_type size ) {
     29        if ( ! os->fail ) {
     30                fwrite( data, size, 1, os->file );
     31                os->fail = ferror( os->file );
    6332        } // if
    6433        return os;
    6534} // write
    6635
    67 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_) };
    68 ofstream *sout = &soutFile;
    69 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_) };
    70 ofstream *serr = &serrFile;
     36int fail( ofstream *os ) {
     37        return os->fail;
     38} // fail
    7139
    72 //---------------------------------------
     40static ofstream *make_ofstream() {
     41        ofstream *new_stream = malloc( sizeof( ofstream ) );
     42        new_stream->fail = 0;
     43        return new_stream;
     44} // make_ofstream
     45
     46ofstream *ofstream_stdout() {
     47        ofstream *stdout_stream = make_ofstream();
     48        stdout_stream->file = stdout;
     49        return stdout_stream;
     50} // ofstream_stdout
     51
     52ofstream *ofstream_stderr() {
     53        ofstream *stderr_stream = make_ofstream();
     54        stderr_stream->file = stderr;
     55        return stderr_stream;
     56} // ofstream_stderr
     57
     58ofstream *ofstream_fromfile( const char *name ) {
     59        ofstream *file_stream = make_ofstream();
     60        file_stream->file = fopen( name, "w" );
     61        file_stream->fail = file_stream->file == 0;
     62        return file_stream;
     63}
     64
     65void ofstream_close( ofstream *os ) {
     66        if ( os->file != stdout && os->file != stderr ) {
     67                os->fail = fclose( os->file );
     68        }
     69        free( os );
     70}
    7371
    7472struct ifstream {
    7573        FILE *file;
     74        int fail;
     75        int eof;
    7676};
    7777
    78 int fail( ifstream * is ) {
    79         return ferror( is->file );
    80 } // fail
     78ifstream *read( ifstream *is, char *data, streamsize_type size ) {
     79        if ( ! is->fail && ! is->eof ) {
     80                fread( data, size, 1, is->file );
     81                is->fail = ferror( is->file );
     82                is->eof = feof( is->file );
     83        }
     84        return is;
     85}
     86 
     87ifstream *unread( ifstream *is, char c ) {
     88        if ( ! is->fail ) {
     89                if ( ! EOF == ungetc( c, is->file ) ) {
     90                        is->fail = 1;
     91                }
     92        }
     93        return is;
     94}
    8195
    82 int eof( ifstream * is ) {
    83         return feof( is->file );
    84 } // eof
     96int fail( ifstream *is ) {
     97        return is->fail;
     98}
    8599
    86 ifstream * get( ifstream * is, int * data ) {
    87         if ( fscanf( is->file, "%d", data ) == EOF ) {
    88                 if ( ferror( is->file ) ) {
    89                         fprintf( stderr, "invalid int read\n" );
    90                         exit( EXIT_FAILURE );
    91                 } // if
    92         } // if
    93         return is;
    94 } // read
     100int eof( ifstream *is ) {
     101        return is->eof;
     102}
    95103
    96 ifstream * read( ifstream * is, char * data, streamsize_type size ) {
    97         if ( fail( is ) ) {
    98                 fprintf( stderr, "attempt read I/O on failed stream\n" );
    99                 exit( EXIT_FAILURE );
    100         } // if
     104static ifstream *make_ifstream() {
     105        ifstream *new_stream = malloc( sizeof( ifstream ) );
     106        new_stream->fail = 0;
     107        new_stream->eof = 0;
     108        return new_stream;
     109}
    101110
    102         if ( fread( data, size, 1, is->file ) == 0 ) {
    103                 perror( IO_MSG "read" );
    104                 exit( EXIT_FAILURE );
    105         } // if
    106         return is;
    107 } // read
    108  
    109 ifstream *ungetc( ifstream * is, char c ) {
    110         if ( fail( is ) ) {
    111                 fprintf( stderr, "attempt ungetc I/O on failed stream\n" );
    112                 exit( EXIT_FAILURE );
    113         } // if
     111ifstream *ifstream_stdin() {
     112        ifstream *stdin_stream = make_ifstream();
     113        stdin_stream->file = stdin;
     114        return stdin_stream;
     115}
    114116
    115         if ( ungetc( c, is->file ) == EOF ) {
    116                 perror( IO_MSG "ungetc" );
    117                 exit( EXIT_FAILURE );
    118         } // if
    119         return is;
    120 } // ungetc
    121 
    122 void open( ifstream ** is, const char * name, const char * mode ) {
    123         FILE *t = fopen( name, mode );
    124         if ( t == 0 ) {                                                                         // do not change unless successful
    125                 perror( IO_MSG "open input" );
    126                 exit( EXIT_FAILURE );
    127         } // if
    128         (*is)->file = t;
    129 } // open
    130 
    131 void close( ifstream * is ) {
    132         if ( is->file == stdin ) return;
    133 
    134         if ( fclose( is->file ) == EOF ) {
    135                 perror( IO_MSG "close input" );
    136         } // if
    137 } // close
    138 
    139 static ifstream sinFile = { (FILE *)(&_IO_2_1_stdin_) };
    140 ifstream *sin = &sinFile;
     117ifstream *ifstream_fromfile( const char *name ) {
     118        ifstream *file_stream = make_ifstream();
     119        file_stream->file = fopen( name, "r" );
     120        file_stream->fail = file_stream->file == 0;
     121        return file_stream;
     122}
    141123
    142124// Local Variables: //
  • src/libcfa/iostream

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 14:04:24 2016
    13 // Update Count     : 32
     12// Last Modified On : Fri Jan 29 15:50:36 2016
     13// Update Count     : 29
    1414//
    1515
     
    2222
    2323context ostream( dtype ostype ) {
     24        ostype *write( ostype *, const char *, streamsize_type );
    2425        int fail( ostype * );
    25         int flush( ostype * );
    26         ostype * write( ostype *, const char *, streamsize_type );
    2726};
     27
    2828context writeable( type T ) {
    2929        forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
     
    5252
    5353// writes the range [begin, end) to the given stream
    54 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
     54forall( type elt_type | writeable( elt_type ),
     55                type iterator_type | iterator( iterator_type, elt_type ),
     56                dtype os_type | ostream( os_type ) )
    5557void write( iterator_type begin, iterator_type end, os_type *os );
    5658
    57 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
     59forall( type elt_type | writeable( elt_type ),
     60                type iterator_type | iterator( iterator_type, elt_type ),
     61                dtype os_type | ostream( os_type ) )
    5862void write_reverse( iterator_type begin, iterator_type end, os_type *os );
    5963
    60 //---------------------------------------
     64//******************************************************************************
    6165
    6266context istream( dtype istype ) {
     67        istype *read( istype *, char *, streamsize_type );
     68        istype *unread( istype *, char );
    6369        int fail( istype * );
    6470        int eof( istype * );
    65         istype * get( istype *, int * );
    66         istype * read( istype *, char *, streamsize_type );
    67         istype * ungetc( istype *, char );
    6871};
    6972
  • src/libcfa/iostream.c

    rae7f1e0 rc44e622  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 14:19:56 2016
    13 // Update Count     : 76
     12// Last Modified On : Mon Feb  1 14:20:30 2016
     13// Update Count     : 60
    1414//
    1515
     
    1919#include <stdio.h>
    2020#include <string.h>                                                                             // strlen
    21 #include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    2221#include <complex.h>                                                                    // creal, cimag
    2322}
     
    7372ostype * ?|?( ostype *os, double d ) {
    7473        char buffer[32];
    75         return write( os, buffer, sprintf( buffer, "%.*lg", DBL_DIG, d ) );
     74        return write( os, buffer, sprintf( buffer, "%g", d ) );
    7675} // ?|?
    7776
     
    7978ostype * ?|?( ostype *os, long double d ) {
    8079        char buffer[32];
    81         return write( os, buffer, sprintf( buffer, "%.*Lg", LDBL_DIG, d ) );
     80        return write( os, buffer, sprintf( buffer, "%Lg", d ) );
    8281} // ?|?
    8382
     
    111110forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) )
    112111retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) {
    113   return manip( os );
     112  return manip(os);
    114113}
    115114
    116115forall( dtype ostype | ostream( ostype ) )
    117116ostype * endl( ostype * os ) {
    118         os | "\n";
    119         flush( os );
    120         return os;
     117  os | "\n";
     118  // flush
     119  return os;
    121120} // endl
    122121
    123 //---------------------------------------
    124 
    125 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ),
     122forall( type elt_type | writeable( elt_type ),
     123                type iterator_type | iterator( iterator_type, elt_type ),
    126124                dtype os_type | ostream( os_type ) )
    127125void write( iterator_type begin, iterator_type end, os_type *os ) {
    128         void print( elt_type i ) { os | i | ' '; }
     126        void print( elt_type i ) {
     127                os | i | ' ';
     128        }
    129129        for_each( begin, end, print );
    130130} // ?|?
    131131
    132 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ),
     132forall( type elt_type | writeable( elt_type ),
     133                type iterator_type | iterator( iterator_type, elt_type ),
    133134                dtype os_type | ostream( os_type ) )
    134135void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
     
    137138} // ?|?
    138139
    139 //---------------------------------------
    140140
    141141forall( dtype istype | istream( istype ) )
     
    146146forall( dtype istype | istream( istype ) )
    147147istype * ?|?( istype *is, int *ip ) {
    148         return get( is, ip );
     148        char cur;
     149 
     150        // skip some whitespace
     151        do {
     152                is | &cur;
     153                if ( fail( is ) || eof( is ) ) return is;
     154        } while ( !( cur >= '0' && cur <= '9' ) );
     155 
     156        // accumulate digits
     157        *ip = 0;
     158        while ( cur >= '0' && cur <= '9' ) {
     159                *ip = *ip * 10 + ( cur - '0' );
     160                is | &cur;
     161                if ( fail( is ) || eof( is ) ) return is;
     162        }
     163 
     164        unread( is, cur );
     165        return is;
    149166} // ?|?
    150167
  • src/libcfa/stdlib.c

    rae7f1e0 rc44e622  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 10 15:45:56 2016
    13 // Update Count     : 140
     12// Last Modified On : Fri Feb  5 15:41:24 2016
     13// Update Count     : 128
    1414//
    1515
     
    2323#include <string.h>                                                                             // memset
    2424#include <malloc.h>                                                                             // malloc_usable_size
     25#include <stdio.h>
    2526#include <math.h>                                                                               // fabsf, fabs, fabsl
    2627#include <complex.h>                                                                    // _Complex_I, cabsf, cabs, cabsl
     
    105106long int ato( const char * ptr ) {
    106107        long int li;
    107         if ( sscanf( ptr, "%ld", &li ) == EOF ) {}                      // check return code
     108        if ( sscanf( ptr, "%ld", &li ) == EOF ) {};                     // check return code
    108109        return li;
    109110}
    110111unsigned long int ato( const char * ptr ) {
    111112        unsigned long int uli;
    112         if ( sscanf( ptr, "%lu", &uli ) == EOF ) {}                     // check return code
     113        if ( sscanf( ptr, "%lu", &uli ) == EOF ) {};            // check return code
    113114        return uli;
    114115}
    115116long long int ato( const char * ptr ) {
    116117        long long int lli;
    117         if ( sscanf( ptr, "%lld", &lli ) == EOF ) {}            // check return code
     118        if ( sscanf( ptr, "%lld", &lli ) == EOF ) {};           // check return code
    118119        return lli;
    119120}
    120121unsigned long long int ato( const char * ptr ) {
    121122        unsigned long long int ulli;
    122         if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {}           // check return code
     123        if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {};          // check return code
    123124        return ulli;
    124125}
    125126float ato( const char * ptr ) {
    126127        float f;
    127         if ( sscanf( ptr, "%f", &f ) == EOF ) {}                        // check return code
     128        if ( sscanf( ptr, "%f", &f ) == EOF ) {};                       // check return code
    128129        return f;
    129130}
    130131double ato( const char * ptr ) {
    131132        double d;
    132         if ( sscanf( ptr, "%lf", &d ) == EOF ) {}                       // check return code
     133        if ( sscanf( ptr, "%lf", &d ) == EOF ) {};                      // check return code
    133134        return d;
    134135}
    135136long double ato( const char * ptr ) {
    136137        long double ld;
    137         if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {}                      // check return code
     138        printf( "FRED " );
     139        if ( sscanf( ptr, "%.32Lf", &ld ) == EOF ) {};          // check return code
    138140        return ld;
    139141}
    140142float _Complex ato( const char * ptr ) {
    141143        float re, im;
    142         if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {}       // check return code
     144        if ( sscanf( ptr, "%g%g", &re, &im ) == EOF ) {};       // check return code
    143145        return re + im * _Complex_I;
    144146}
    145147double _Complex ato( const char * ptr ) {
    146148        double re, im;
    147         if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} // check return code
     149        if ( sscanf( ptr, "%.16lg%.16lg", &re, &im ) == EOF ) {}; // check return code
    148150        return re + im * _Complex_I;
    149151}
    150152long double _Complex ato( const char * ptr ) {
    151153        long double re, im;
    152         if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {}     // check return code
     154        if ( sscanf( ptr, "%.32Lg%.32Lg", &re, &im ) == EOF ) {}; // check return code
    153155        return re + im * _Complex_I;
    154156}       
Note: See TracChangeset for help on using the changeset viewer.