Changeset 6250a312 for src


Ignore:
Timestamp:
May 10, 2017, 5:00:47 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
8514fe19, dbfb35d
Parents:
0f9bef3 (diff), 29cf9c8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
15 added
4 deleted
34 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r0f9bef3 r6250a312  
    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 : Thu Mar 30 16:38:01 2017
    13 // Update Count     : 482
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tus May  9 16:50:00 2017
     13// Update Count     : 484
    1414//
    1515
     
    4141namespace CodeGen {
    4242        int CodeGenerator::tabsize = 4;
     43
     44        // Pseudo Function: output << lineDirective(currentNode);
     45    struct lineDirective {
     46        CodeLocation const & loc;
     47                lineDirective(CodeLocation const & location) : loc(location) {}
     48                lineDirective(BaseSyntaxNode const * node) : loc(node->location) {}
     49        };
     50        std::ostream & operator<<(std::ostream & out, lineDirective const & ld) {
     51                if (ld.loc.isSet())
     52                        return out << "\n# " << ld.loc.linenumber << " \""
     53                                << ld.loc.filename << "\"\n";
     54                return out << "\n// Unset Location\n";
     55        }
    4356
    4457        // the kinds of statements that would ideally be followed by whitespace
     
    128141
    129142
    130         //*** Declarations
     143        // *** Declarations
    131144        void CodeGenerator::visit( FunctionDecl * functionDecl ) {
     145                output << lineDirective( functionDecl );
     146
    132147                extension( functionDecl );
    133148                genAttributes( functionDecl->get_attributes() );
     
    153168                }
    154169
     170                output << lineDirective( objectDecl );
     171
    155172                extension( objectDecl );
    156173                genAttributes( objectDecl->get_attributes() );
     
    192209                        cur_indent += CodeGenerator::tabsize;
    193210                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    194                                 output << indent;
     211                                output << lineDirective( *i ) << indent;
    195212                                (*i)->accept( *this );
    196213                                output << ";" << endl;
     
    204221
    205222        void CodeGenerator::visit( StructDecl * structDecl ) {
     223                output << lineDirective( structDecl );
     224
    206225                extension( structDecl );
    207226                handleAggregate( structDecl, "struct " );
     
    209228
    210229        void CodeGenerator::visit( UnionDecl * unionDecl ) {
     230                output << lineDirective( unionDecl );
     231
    211232                extension( unionDecl );
    212233                handleAggregate( unionDecl, "union " );
     
    215236        void CodeGenerator::visit( EnumDecl * enumDecl ) {
    216237                extension( enumDecl );
     238                output << lineDirective ( enumDecl );
    217239                output << "enum ";
    218240                genAttributes( enumDecl->get_attributes() );
     
    230252                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    231253                                assert( obj );
    232                                 output << indent << mangleName( obj );
     254                                output << lineDirective( obj ) << indent << mangleName( obj );
    233255                                if ( obj->get_init() ) {
    234256                                        output << " = ";
     
    248270        void CodeGenerator::visit( TypedefDecl * typeDecl ) {
    249271                assertf( ! genC, "Typedefs are removed and substituted in earlier passes." );
     272                output << lineDirective( typeDecl );
    250273                output << "typedef ";
    251274                output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl;
     
    262285                        } // if
    263286                } else {
    264                         output << typeDecl->typeString() << " " << typeDecl->get_name();
     287                        output << typeDecl->genTypeString() << " " << typeDecl->get_name();
     288                        if ( typeDecl->get_kind() != TypeDecl::Any && typeDecl->get_sized() ) {
     289                                output << " | sized(" << typeDecl->get_name() << ")";
     290                        }
    265291                        if ( ! typeDecl->get_assertions().empty() ) {
    266292                                output << " | { ";
     
    316342        }
    317343
    318         //*** Expressions
     344        // *** Expressions
    319345        void CodeGenerator::visit( ApplicationExpr * applicationExpr ) {
    320346                extension( applicationExpr );
     
    719745        void CodeGenerator::visit( StmtExpr * stmtExpr ) {
    720746                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
    721                 output << "({" << std::endl;
     747                output << lineDirective( stmtExpr) << "({" << std::endl;
    722748                cur_indent += CodeGenerator::tabsize;
    723749                unsigned int numStmts = stmts.size();
    724750                unsigned int i = 0;
    725751                for ( Statement * stmt : stmts ) {
    726                         output << indent << printLabels( stmt->get_labels() );
     752                        output << lineDirective( stmt ) << indent;
     753            output << printLabels( stmt->get_labels() );
    727754                        if ( i+1 == numStmts ) {
    728755                                // last statement in a statement expression needs to be handled specially -
     
    746773        }
    747774
    748         //*** Statements
     775        // *** Statements
    749776        void CodeGenerator::visit( CompoundStmt * compoundStmt ) {
    750777                std::list<Statement*> ks = compoundStmt->get_kids();
     
    769796        void CodeGenerator::visit( ExprStmt * exprStmt ) {
    770797                assert( exprStmt );
    771                 // cast the top-level expression to void to reduce gcc warnings.
    772                 Expression * expr = new CastExpr( exprStmt->get_expr() );
     798                Expression * expr = exprStmt->get_expr();
     799                if ( genC ) {
     800                        // cast the top-level expression to void to reduce gcc warnings.
     801                        expr = new CastExpr( expr );
     802                }
    773803                expr->accept( *this );
    774804                output << ";";
     
    807837
    808838        void CodeGenerator::visit( IfStmt * ifStmt ) {
     839                output << lineDirective( ifStmt );
    809840                output << "if ( ";
    810841                ifStmt->get_condition()->accept( *this );
     
    820851
    821852        void CodeGenerator::visit( SwitchStmt * switchStmt ) {
     853                output << lineDirective( switchStmt );
    822854                output << "switch ( " ;
    823855                switchStmt->get_condition()->accept( *this );
     
    832864
    833865        void CodeGenerator::visit( CaseStmt * caseStmt ) {
     866                output << lineDirective( caseStmt );
    834867                output << indent;
    835868                if ( caseStmt->isDefault()) {
  • src/CodeGen/Generate.cc

    r0f9bef3 r6250a312  
    2222#include "SynTree/Declaration.h"
    2323#include "CodeGenerator.h"
    24 #include "Tuples/Tuples.h"
     24#include "GenType.h"
     25#include "SynTree/SynTree.h"
     26#include "SynTree/Type.h"
     27#include "SynTree/BaseSyntaxNode.h"
     28// #include "Tuples/Tuples.h"
    2529
    2630using namespace std;
     
    3943                } // for
    4044        }
     45
     46        void generate( BaseSyntaxNode * node, std::ostream & os ) {
     47                if ( Type * type = dynamic_cast< Type * >( node ) ) {
     48                        os << CodeGen::genPrettyType( type, "" );
     49                } else {
     50                        CodeGen::CodeGenerator cgv( os, true, false );
     51                        node->accept( cgv );
     52                }
     53                os << std::endl;
     54        }
    4155} // namespace CodeGen
    4256
  • src/CodeGen/Generate.h

    r0f9bef3 r6250a312  
    2525        /// Generates code. doIntrinsics determines if intrinsic functions are printed, pretty formats output nicely (e.g., uses unmangled names, etc.), generateC is true when the output must consist only of C code (allows some assertions, etc.)
    2626        void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC = false );
     27
     28        /// Generate code for a single node -- helpful for debugging in gdb
     29        void generate( BaseSyntaxNode * node, std::ostream & os );
    2730} // namespace CodeGen
    2831
  • src/CodeTools/module.mk

    r0f9bef3 r6250a312  
    1515###############################################################################
    1616
    17 SRC += CodeTools/DeclStats.cc
     17SRC += CodeTools/DeclStats.cc \
     18        CodeTools/TrackLoc.cc
  • src/Common/utility.h

    r0f9bef3 r6250a312  
    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 : Wed Dec 14 21:25:25 2016
    13 // Update Count     : 31
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri May 5 11:03:00 2017
     13// Update Count     : 32
    1414//
    1515
     
    322322        std::string filename;
    323323
    324         CodeLocation()
     324    /// Create a new unset CodeLocation.
     325        CodeLocation()
    325326                : linenumber( -1 )
    326327                , filename("")
    327328        {}
    328329
     330    /// Create a new CodeLocation with the given values.
    329331        CodeLocation( const char* filename, int lineno )
    330332                : linenumber( lineno )
    331333                , filename(filename ? filename : "")
    332334        {}
     335
     336    bool isSet () const {
     337        return -1 != linenumber;
     338    }
     339
     340    bool isUnset () const {
     341        return !isSet();
     342    }
     343
     344        void unset () {
     345                linenumber = -1;
     346                filename = "";
     347        }
     348
     349        // Use field access for set.
    333350};
    334351
    335352inline std::string to_string( const CodeLocation& location ) {
    336         return location.linenumber >= 0 ? location.filename + ":" + std::to_string(location.linenumber) + " " : "";
     353        return location.isSet() ? location.filename + ":" + std::to_string(location.linenumber) + " " : "";
    337354}
    338355#endif // _UTILITY_H
  • src/Concurrency/Keywords.cc

    r0f9bef3 r6250a312  
    246246        //=============================================================================================
    247247        void ConcurrentSueKeyword::visit(StructDecl * decl) {
     248                Visitor::visit(decl);
    248249                if( decl->get_name() == type_name ) {
    249250                        assert( !type_decl );
     
    385386        //=============================================================================================
    386387        void MutexKeyword::visit(FunctionDecl* decl) {
     388                Visitor::visit(decl);           
     389
    387390                std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl );
    388391                if( mutexArgs.empty() ) return;
     
    402405
    403406        void MutexKeyword::visit(StructDecl* decl) {
     407                Visitor::visit(decl);
     408
    404409                if( decl->get_name() == "monitor_desc" ) {
    405410                        assert( !monitor_decl );
     
    504509        //=============================================================================================
    505510        void ThreadStarter::visit(FunctionDecl * decl) {
     511                Visitor::visit(decl);
     512               
    506513                if( ! InitTweak::isConstructor(decl->get_name()) ) return;
    507514
  • src/GenPoly/InstantiateGeneric.cc

    r0f9bef3 r6250a312  
    233233                                } else {
    234234                                        // normalize possibly dtype-static parameter type
    235                                         out.push_back( new TypeExpr{ 
     235                                        out.push_back( new TypeExpr{
    236236                                                ScrubTyVars::scrubAll( paramType->get_type()->clone() ) } );
    237237                                        gt |= genericType::concrete;
     
    369369                                DeclMutator::addDeclaration( concDecl );
    370370                                insert( inst, typeSubs, concDecl );
     371                                concDecl->acceptMutator( *this ); // recursively instantiate members
    371372                        }
    372373                        StructInstType *newInst = new StructInstType( inst->get_qualifiers(), concDecl->get_name() );
     
    423424                                DeclMutator::addDeclaration( concDecl );
    424425                                insert( inst, typeSubs, concDecl );
     426                                concDecl->acceptMutator( *this ); // recursively instantiate members
    425427                        }
    426428                        UnionInstType *newInst = new UnionInstType( inst->get_qualifiers(), concDecl->get_name() );
  • src/GenPoly/PolyMutator.cc

    r0f9bef3 r6250a312  
    5050
    5151        Statement * PolyMutator::mutateStatement( Statement *stmt ) {
     52                // don't want statements from outer CompoundStmts to be added to this CompoundStmt
     53                ValueGuard< std::list< Statement* > > oldStmtsToAdd( stmtsToAdd );
     54                ValueGuard< std::list< Statement* > > oldStmtsToAddAfter( stmtsToAddAfter );
     55                ValueGuard< TypeSubstitution * > oldEnv( env );
     56                stmtsToAdd.clear();
     57                stmtsToAddAfter.clear();
     58
    5259                Statement *newStmt = maybeMutate( stmt, *this );
    5360                if ( ! stmtsToAdd.empty() || ! stmtsToAddAfter.empty() ) {
     
    8390
    8491        Statement * PolyMutator::mutate(IfStmt *ifStmt) {
     92                ifStmt->set_condition(  mutateExpression( ifStmt->get_condition() ) );
    8593                ifStmt->set_thenPart(  mutateStatement( ifStmt->get_thenPart() ) );
    8694                ifStmt->set_elsePart(  mutateStatement( ifStmt->get_elsePart() ) );
    87                 ifStmt->set_condition(  mutateExpression( ifStmt->get_condition() ) );
    8895                return ifStmt;
    8996        }
    9097
    9198        Statement * PolyMutator::mutate(WhileStmt *whileStmt) {
     99                whileStmt->set_condition(  mutateExpression( whileStmt->get_condition() ) );
    92100                whileStmt->set_body(  mutateStatement( whileStmt->get_body() ) );
    93                 whileStmt->set_condition(  mutateExpression( whileStmt->get_condition() ) );
    94101                return whileStmt;
    95102        }
    96103
    97104        Statement * PolyMutator::mutate(ForStmt *forStmt) {
    98                 forStmt->set_body(  mutateStatement( forStmt->get_body() ) );
    99105                mutateAll( forStmt->get_initialization(), *this );
    100106                forStmt->set_condition(  mutateExpression( forStmt->get_condition() ) );
    101107                forStmt->set_increment(  mutateExpression( forStmt->get_increment() ) );
     108                forStmt->set_body(  mutateStatement( forStmt->get_body() ) );
    102109                return forStmt;
    103110        }
    104111
    105112        Statement * PolyMutator::mutate(SwitchStmt *switchStmt) {
     113                switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );
    106114                mutateStatementList( switchStmt->get_statements() );
    107                 switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );
    108115                return switchStmt;
    109116        }
    110117
    111118        Statement * PolyMutator::mutate(CaseStmt *caseStmt) {
     119                caseStmt->set_condition(  mutateExpression( caseStmt->get_condition() ) );
    112120                mutateStatementList( caseStmt->get_statements() );
    113                 caseStmt->set_condition(  mutateExpression( caseStmt->get_condition() ) );
    114121                return caseStmt;
    115122        }
  • src/Makefile.in

    r0f9bef3 r6250a312  
    108108        CodeGen/driver_cfa_cpp-OperatorTable.$(OBJEXT) \
    109109        CodeTools/driver_cfa_cpp-DeclStats.$(OBJEXT) \
     110        CodeTools/driver_cfa_cpp-TrackLoc.$(OBJEXT) \
    110111        Concurrency/driver_cfa_cpp-Keywords.$(OBJEXT) \
    111112        Common/driver_cfa_cpp-SemanticError.$(OBJEXT) \
     
    388389        CodeGen/FixNames.cc CodeGen/FixMain.cc \
    389390        CodeGen/OperatorTable.cc CodeTools/DeclStats.cc \
    390         Concurrency/Keywords.cc Common/SemanticError.cc \
    391         Common/UniqueName.cc Common/DebugMalloc.cc Common/Assert.cc \
     391        CodeTools/TrackLoc.cc Concurrency/Keywords.cc \
     392        Common/SemanticError.cc Common/UniqueName.cc \
     393        Common/DebugMalloc.cc Common/Assert.cc \
    392394        ControlStruct/LabelGenerator.cc ControlStruct/LabelFixer.cc \
    393395        ControlStruct/MLEMutator.cc ControlStruct/Mutate.cc \
     
    545547        @: > CodeTools/$(DEPDIR)/$(am__dirstamp)
    546548CodeTools/driver_cfa_cpp-DeclStats.$(OBJEXT):  \
     549        CodeTools/$(am__dirstamp) CodeTools/$(DEPDIR)/$(am__dirstamp)
     550CodeTools/driver_cfa_cpp-TrackLoc.$(OBJEXT):  \
    547551        CodeTools/$(am__dirstamp) CodeTools/$(DEPDIR)/$(am__dirstamp)
    548552Concurrency/$(am__dirstamp):
     
    843847        -rm -f CodeGen/driver_cfa_cpp-OperatorTable.$(OBJEXT)
    844848        -rm -f CodeTools/driver_cfa_cpp-DeclStats.$(OBJEXT)
     849        -rm -f CodeTools/driver_cfa_cpp-TrackLoc.$(OBJEXT)
    845850        -rm -f Common/driver_cfa_cpp-Assert.$(OBJEXT)
    846851        -rm -f Common/driver_cfa_cpp-DebugMalloc.$(OBJEXT)
     
    954959@AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/driver_cfa_cpp-OperatorTable.Po@am__quote@
    955960@AMDEP_TRUE@@am__include@ @am__quote@CodeTools/$(DEPDIR)/driver_cfa_cpp-DeclStats.Po@am__quote@
     961@AMDEP_TRUE@@am__include@ @am__quote@CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Po@am__quote@
    956962@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-Assert.Po@am__quote@
    957963@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-DebugMalloc.Po@am__quote@
     
    11951201@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o CodeTools/driver_cfa_cpp-DeclStats.obj `if test -f 'CodeTools/DeclStats.cc'; then $(CYGPATH_W) 'CodeTools/DeclStats.cc'; else $(CYGPATH_W) '$(srcdir)/CodeTools/DeclStats.cc'; fi`
    11961202
     1203CodeTools/driver_cfa_cpp-TrackLoc.o: CodeTools/TrackLoc.cc
     1204@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT CodeTools/driver_cfa_cpp-TrackLoc.o -MD -MP -MF CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Tpo -c -o CodeTools/driver_cfa_cpp-TrackLoc.o `test -f 'CodeTools/TrackLoc.cc' || echo '$(srcdir)/'`CodeTools/TrackLoc.cc
     1205@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Tpo CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Po
     1206@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='CodeTools/TrackLoc.cc' object='CodeTools/driver_cfa_cpp-TrackLoc.o' libtool=no @AMDEPBACKSLASH@
     1207@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1208@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o CodeTools/driver_cfa_cpp-TrackLoc.o `test -f 'CodeTools/TrackLoc.cc' || echo '$(srcdir)/'`CodeTools/TrackLoc.cc
     1209
     1210CodeTools/driver_cfa_cpp-TrackLoc.obj: CodeTools/TrackLoc.cc
     1211@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT CodeTools/driver_cfa_cpp-TrackLoc.obj -MD -MP -MF CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Tpo -c -o CodeTools/driver_cfa_cpp-TrackLoc.obj `if test -f 'CodeTools/TrackLoc.cc'; then $(CYGPATH_W) 'CodeTools/TrackLoc.cc'; else $(CYGPATH_W) '$(srcdir)/CodeTools/TrackLoc.cc'; fi`
     1212@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Tpo CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Po
     1213@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='CodeTools/TrackLoc.cc' object='CodeTools/driver_cfa_cpp-TrackLoc.obj' libtool=no @AMDEPBACKSLASH@
     1214@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1215@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o CodeTools/driver_cfa_cpp-TrackLoc.obj `if test -f 'CodeTools/TrackLoc.cc'; then $(CYGPATH_W) 'CodeTools/TrackLoc.cc'; else $(CYGPATH_W) '$(srcdir)/CodeTools/TrackLoc.cc'; fi`
     1216
    11971217Concurrency/driver_cfa_cpp-Keywords.o: Concurrency/Keywords.cc
    11981218@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Concurrency/driver_cfa_cpp-Keywords.o -MD -MP -MF Concurrency/$(DEPDIR)/driver_cfa_cpp-Keywords.Tpo -c -o Concurrency/driver_cfa_cpp-Keywords.o `test -f 'Concurrency/Keywords.cc' || echo '$(srcdir)/'`Concurrency/Keywords.cc
  • src/Parser/parser.yy

    r0f9bef3 r6250a312  
    393393        | '(' compound_statement ')'                                            // GCC, lambda expression
    394394                { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
     395        | primary_expression '{' argument_expression_list '}' // CFA
     396                {
     397                        Token fn;
     398                        fn.str = new std::string( "?{}" );                      // location undefined - use location of '{'?
     399                        $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
     400                }
    395401        ;
    396402
     
    425431        | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
    426432                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
    427         | postfix_expression '{' argument_expression_list '}' // CFA
     433        | '^' primary_expression '{' argument_expression_list '}' // CFA
    428434                {
    429435                        Token fn;
    430                         fn.str = new std::string( "?{}" );                      // location undefined - use location of '{'?
    431                         $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
     436                        fn.str = new string( "^?{}" );                          // location undefined
     437                        $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) );
    432438                }
    433439        ;
     
    730736        | exception_statement
    731737        | asm_statement
    732         | '^' postfix_expression '{' argument_expression_list '}' ';' // CFA
    733                 {
    734                         Token fn;
    735                         fn.str = new string( "^?{}" );                          // location undefined
    736                         $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );
    737                 }
    738         ;
    739738
    740739labeled_statement:
  • src/ResolvExpr/AlternativeFinder.cc

    r0f9bef3 r6250a312  
    766766                        } // if
    767767                } // for
    768                 // function may return struct or union value, in which case we need to add alternatives for implicit conversions to each of the anonymous members
     768
     769                candidates.clear();
     770                candidates.splice( candidates.end(), alternatives );
     771
     772                findMinCost( candidates.begin(), candidates.end(), std::back_inserter( alternatives ) );
     773
     774                // function may return struct or union value, in which case we need to add alternatives for implicit
     775                // conversions to each of the anonymous members, must happen after findMinCost since anon conversions
     776                // are never the cheapest expression
    769777                for ( const Alternative & alt : alternatives ) {
    770778                        addAnonConversions( alt );
    771779                }
    772 
    773                 candidates.clear();
    774                 candidates.splice( candidates.end(), alternatives );
    775 
    776                 findMinCost( candidates.begin(), candidates.end(), std::back_inserter( alternatives ) );
    777780
    778781                if ( alternatives.empty() && targetType && ! targetType->isVoid() ) {
  • src/SymTab/Validate.cc

    r0f9bef3 r6250a312  
    240240                ReturnTypeFixer::fix( translationUnit ); // must happen before autogen
    241241                acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
     242                acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist
     243                VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    242244                Concurrency::applyKeywords( translationUnit );
    243245                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecayPass
    244246                Concurrency::implementMutexFuncs( translationUnit );
    245247                Concurrency::implementThreadStarter( translationUnit );
    246                 acceptAll( translationUnit, epc );
    247248                ReturnChecker::checkFunctionReturns( translationUnit );
    248249                compoundliteral.mutateDeclarationList( translationUnit );
    249250                acceptAll( translationUnit, pass3 );
    250                 VerifyCtorDtorAssign::verify( translationUnit );
    251251                ArrayLength::computeLength( translationUnit );
    252252        }
     
    817817                                throw SemanticError( "Constructors, destructors, and assignment functions require at least one parameter ", funcDecl );
    818818                        }
    819                         if ( ! dynamic_cast< PointerType * >( params.front()->get_type() ) ) {
     819                        PointerType * ptrType = dynamic_cast< PointerType * >( params.front()->get_type() );
     820                        if ( ! ptrType || ptrType->is_array() ) {
    820821                                throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a pointer ", funcDecl );
    821822                        }
  • src/SynTree/BaseSyntaxNode.h

    r0f9bef3 r6250a312  
    1818
    1919#include "Common/utility.h"
     20#include "Visitor.h"
    2021
    2122class BaseSyntaxNode {
    2223  public:
    2324        CodeLocation location;
     25
     26        virtual void accept( Visitor & v ) = 0; // temporary -- needs to be here so that BaseSyntaxNode is polymorphic and can be dynamic_cast
    2427};
    2528
  • src/SynTree/Declaration.h

    r0f9bef3 r6250a312  
    204204
    205205        virtual std::string typeString() const;
     206        virtual std::string genTypeString() const;
    206207
    207208        virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
  • src/SynTree/PointerType.cc

    r0f9bef3 r6250a312  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // PointerType.cc -- 
     7// PointerType.cc --
    88//
    99// Author           : Richard C. Bilson
     
    3838void PointerType::print( std::ostream &os, int indent ) const {
    3939        Type::print( os, indent );
    40         os << "pointer to ";
    41         if ( isStatic ) {
    42                 os << "static ";
    43         } // if
    44         if ( isVarLen ) {
    45                 os << "variable length array of ";
    46         } else if ( dimension ) {
    47                 os << "array of ";
    48                 dimension->print( os, indent );
    49         } // if
     40        if ( ! is_array() ) {
     41                os << "pointer to ";
     42        } else {
     43                os << "decayed ";
     44                if ( isStatic ) {
     45                        os << "static ";
     46                } // if
     47                if ( isVarLen ) {
     48                        os << "variable length array of ";
     49                } else if ( dimension ) {
     50                        os << "array of ";
     51                        dimension->print( os, indent );
     52                        os << " ";
     53                } // if
     54        }
    5055        if ( base ) {
    5156                base->print( os, indent );
  • src/SynTree/SynTree.h

    r0f9bef3 r6250a312  
    2121#include <map>
    2222#include <iostream>
     23
     24class BaseSyntaxNode;
    2325
    2426class Declaration;
  • src/SynTree/Type.h

    r0f9bef3 r6250a312  
    247247        void set_isStatic( bool newValue ) { isStatic = newValue; }
    248248
     249        bool is_array() const { return isStatic || isVarLen || dimension; }
     250
    249251        virtual PointerType *clone() const { return new PointerType( *this ); }
    250252        virtual void accept( Visitor & v ) { v.visit( this ); }
  • src/SynTree/TypeDecl.cc

    r0f9bef3 r6250a312  
    2929}
    3030
     31std::string TypeDecl::genTypeString() const {
     32        static const std::string kindNames[] = { "otype", "dtype", "ftype", "ttype" };
     33        return kindNames[ kind ];
     34}
     35
    3136std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ) {
    3237  return os << data.kind << ", " << data.isComplete;
  • src/SynTree/Visitor.h

    r0f9bef3 r6250a312  
    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 : Thu Feb  9 14:23:24 2017
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed May  3 08:58:00 2017
    1313// Update Count     : 10
    1414//
     
    2626        virtual ~Visitor();
    2727  public:
     28        // visit: Default implementation of all functions visits the children
     29    // of the given syntax node, but performs no other action.
     30
    2831        virtual void visit( ObjectDecl *objectDecl );
    2932        virtual void visit( FunctionDecl *functionDecl );
  • src/benchmark/CorCtxSwitch.c

    r0f9bef3 r6250a312  
    33#include <thread>
    44
    5 #include <unistd.h>                                     // sysconf
    6 #include <sys/times.h>                                  // times
    7 #include <time.h>
     5#include "bench.h"
    86
    9 inline unsigned long long int Time() {
    10     timespec ts;
    11     clock_gettime(
    12 #if defined( __linux__ )
    13          CLOCK_THREAD_CPUTIME_ID,
    14 #elif defined( __freebsd__ )
    15          CLOCK_PROF,
    16 #elif defined( __solaris__ )
    17          CLOCK_HIGHRES,
    18 #else
    19     #error uC++ : internal error, unsupported architecture
    20 #endif
    21          &ts );
    22     return 1000000000LL * ts.tv_sec + ts.tv_nsec;
    23 } // Time
    24 
    25 struct GreatSuspender {
    26         coroutine_desc __cor;
    27 };
    28 
    29 DECL_COROUTINE(GreatSuspender);
     7coroutine GreatSuspender {};
    308
    319void ?{}( GreatSuspender * this ) {
     
    4624}
    4725
    48 #ifndef N
    49 #define N 100000000
    50 #endif
    51 
    5226int main() {
    5327        const unsigned int NoOfTimes = N;
  • src/benchmark/Makefile.am

    r0f9bef3 r6250a312  
    4444        @rm -f ./a.out
    4545
     46sched-int:
     47        ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 SchedInt.c
     48        @for number in 1 2 3 4 5 6 7 8 9 10; do \
     49                ./a.out ; \
     50        done
     51        @rm -f ./a.out
     52
     53monitor:
     54        ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 Monitor.c
     55        @for number in 1 2 3 4 5 6 7 8 9 10; do \
     56                ./a.out ; \
     57        done
     58        @rm -f ./a.out
     59
    4660csv-data:
    4761        @${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -quiet -DN=10000000 csv-data.c
  • src/benchmark/Makefile.in

    r0f9bef3 r6250a312  
    492492        @rm -f ./a.out
    493493
     494sched-int:
     495        ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 SchedInt.c
     496        @for number in 1 2 3 4 5 6 7 8 9 10; do \
     497                ./a.out ; \
     498        done
     499        @rm -f ./a.out
     500
     501monitor:
     502        ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 Monitor.c
     503        @for number in 1 2 3 4 5 6 7 8 9 10; do \
     504                ./a.out ; \
     505        done
     506        @rm -f ./a.out
     507
    494508csv-data:
    495509        @${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -quiet -DN=10000000 csv-data.c
  • src/benchmark/ThrdCtxSwitch.c

    r0f9bef3 r6250a312  
    33#include <thread>
    44
    5 #include <unistd.h>                                     // sysconf
    6 #include <sys/times.h>                                  // times
    7 #include <time.h>
    8 
    9 inline unsigned long long int Time() {
    10     timespec ts;
    11     clock_gettime(
    12 #if defined( __linux__ )
    13          CLOCK_THREAD_CPUTIME_ID,
    14 #elif defined( __freebsd__ )
    15          CLOCK_PROF,
    16 #elif defined( __solaris__ )
    17          CLOCK_HIGHRES,
    18 #else
    19     #error uC++ : internal error, unsupported architecture
    20 #endif
    21          &ts );
    22     return 1000000000LL * ts.tv_sec + ts.tv_nsec;
    23 } // Time
    24  
    25 #ifndef N
    26 #define N 100000000
    27 #endif
     5#include "bench.h"
    286
    297int main() {
  • src/benchmark/bench.c

    r0f9bef3 r6250a312  
    44#include <thread>
    55
    6 #include <unistd.h>                                     // sysconf
    7 #include <sys/times.h>                                  // times
    8 #include <time.h>
    9 
    10 inline unsigned long long int Time() {
    11     timespec ts;
    12     clock_gettime(
    13 #if defined( __linux__ )
    14          CLOCK_THREAD_CPUTIME_ID,
    15 #elif defined( __freebsd__ )
    16          CLOCK_PROF,
    17 #elif defined( __solaris__ )
    18          CLOCK_HIGHRES,
    19 #else
    20     #error uC++ : internal error, unsupported architecture
    21 #endif
    22          &ts );
    23     return 1000000000LL * ts.tv_sec + ts.tv_nsec;
    24 } // Time
     6#include "bench.h"
    257
    268//=======================================
     
    8668//=======================================
    8769
    88 struct CoroutineDummy { coroutine_desc __cor; };
    89 DECL_COROUTINE(CoroutineDummy);
     70coroutine CoroutineDummy {};
    9071void main(CoroutineDummy * this) {}
    9172
     
    11798}
    11899
    119 struct CoroutineResume {
     100coroutine CoroutineResume {
    120101    int N;
    121     coroutine_desc __cor;
    122102};
    123 
    124 DECL_COROUTINE(CoroutineResume);
    125103
    126104void ?{}(CoroutineResume* this, int N) {
     
    150128//=======================================
    151129
    152 struct ThreadDummy { thread_desc __thrd; };
    153 DECL_THREAD(ThreadDummy);
     130thread ThreadDummy {};
    154131void main(ThreadDummy * this) {}
    155132
     
    177154}
    178155
    179 struct ContextSwitch {
     156thread ContextSwitch {
    180157    int N;
    181158    long long result;
    182     thread_desc __thrd;
    183159};
    184 
    185 DECL_THREAD(ContextSwitch);
    186160
    187161void main(ContextSwitch * this) {   
     
    241215        DynamicTaskCreateDelete( NoOfTimes );
    242216        {
    243                 scoped(ContextSwitch) dummy = { (int)NoOfTimes };               // context switch
     217                ContextSwitch dummy = { (int)NoOfTimes };               // context switch
    244218        }
    245219        sout | "\t" | endl;
  • src/benchmark/csv-data.c

    r0f9bef3 r6250a312  
    11#include <fstream>
     2#include <monitor>
    23#include <stdlib>
    34#include <thread>
    45
    5 extern "C" {
    6 #include <unistd.h>                                     // sysconf
    7 #include <sys/times.h>                                  // times
    8 #include <time.h>
    9 }
    10 
    11 inline unsigned long long int Time() {
    12     timespec ts;
    13     clock_gettime(
    14 #if defined( __linux__ )
    15          CLOCK_THREAD_CPUTIME_ID,
    16 #elif defined( __freebsd__ )
    17          CLOCK_PROF,
    18 #elif defined( __solaris__ )
    19          CLOCK_HIGHRES,
    20 #else
    21     #error uC++ : internal error, unsupported architecture
    22 #endif
    23          &ts );
    24     return 1000000000LL * ts.tv_sec + ts.tv_nsec;
    25 } // Time
    26 
    27 struct GreatSuspender {
    28         coroutine_desc __cor;
    29 };
    30 
    31 DECL_COROUTINE(GreatSuspender);
     6#include "bench.h"
     7
     8coroutine GreatSuspender {};
    329
    3310void ?{}( GreatSuspender * this ) {
     
    5229#endif
    5330
    54 
    55 
     31//-----------------------------------------------------------------------------
     32// coroutine context switch
    5633long long int measure_coroutine() {
    5734        const unsigned int NoOfTimes = N;
     
    7148}
    7249
     50//-----------------------------------------------------------------------------
     51// thread context switch
    7352long long int measure_thread() {
    7453        const unsigned int NoOfTimes = N;
     
    8463}
    8564
     65//-----------------------------------------------------------------------------
     66// single monitor entry
     67monitor mon_t {};
     68void dummy( mon_t * mutex m ) {}
     69
     70long long int measure_1_monitor_entry() {
     71        const unsigned int NoOfTimes = N;
     72        long long int StartTime, EndTime;
     73        mon_t mon;
     74
     75        StartTime = Time();
     76        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
     77                dummy( &mon );
     78        }
     79        EndTime = Time();
     80
     81        return ( EndTime - StartTime ) / NoOfTimes;
     82}
     83
     84//-----------------------------------------------------------------------------
     85// multi monitor entry
     86void dummy( mon_t * mutex m1,  mon_t * mutex m2 ) {}
     87
     88long long int measure_2_monitor_entry() {
     89        const unsigned int NoOfTimes = N;
     90        long long int StartTime, EndTime;
     91        mon_t mon1, mon2;
     92
     93        StartTime = Time();
     94        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
     95                dummy( &mon1, &mon2 );
     96        }
     97        EndTime = Time();
     98
     99        return ( EndTime - StartTime ) / NoOfTimes;
     100}
     101
     102//-----------------------------------------------------------------------------
     103// single internal sched entry
     104mon_t mon1;
     105
     106condition cond1a;
     107condition cond1b;
     108
     109thread thrd1a { long long int * out; };
     110thread thrd1b {};
     111
     112void ?{}( thrd1a * this, long long int * out ) {
     113        this->out = out;
     114}
     115
     116void side1A( mon_t * mutex a, long long int * out ) {
     117        long long int StartTime, EndTime;
     118
     119        StartTime = Time();
     120        for( int i = 0;; i++ ) {
     121                signal(&cond1a);
     122                if( i > N ) break;
     123                wait(&cond1b);
     124        }
     125        EndTime = Time();
     126
     127        *out = ( EndTime - StartTime ) / N;
     128}
     129
     130void side1B( mon_t * mutex a ) {
     131        for( int i = 0;; i++ ) {
     132                signal(&cond1b);
     133                if( i > N ) break;
     134                wait(&cond1a);
     135        }
     136}
     137
     138void main( thrd1a * this ) { side1A( &mon1, this->out ); }
     139void main( thrd1b * this ) { side1B( &mon1 ); }
     140
     141long long int measure_1_sched_int() {
     142        long long int t;
     143        {
     144                thrd1a a = { &t };
     145                thrd1b b;
     146        }
     147        return t;
     148}
     149
     150//-----------------------------------------------------------------------------
     151// multi internal sched entry
     152mon_t mon2;
     153
     154condition cond2a;
     155condition cond2b;
     156
     157thread thrd2a { long long int * out; };
     158thread thrd2b {};
     159
     160void ?{}( thrd2a * this, long long int * out ) {
     161        this->out = out;
     162}
     163
     164void side2A( mon_t * mutex a, mon_t * mutex b, long long int * out ) {
     165        long long int StartTime, EndTime;
     166
     167        StartTime = Time();
     168        for( int i = 0;; i++ ) {
     169                signal(&cond2a);
     170                if( i > N ) break;
     171                wait(&cond2b);
     172        }
     173        EndTime = Time();
     174
     175        *out = ( EndTime - StartTime ) / N;
     176}
     177
     178void side2B( mon_t * mutex a, mon_t * mutex b ) {
     179        for( int i = 0;; i++ ) {
     180                signal(&cond2b);
     181                if( i > N ) break;
     182                wait(&cond2a);
     183        }
     184}
     185
     186void main( thrd2a * this ) { side2A( &mon1, &mon2, this->out ); }
     187void main( thrd2b * this ) { side2B( &mon1, &mon2 ); }
     188
     189long long int measure_2_sched_int() {
     190        long long int t;
     191        {
     192                thrd2a a = { &t };
     193                thrd2b b;
     194        }
     195        return t;
     196}
     197
     198//-----------------------------------------------------------------------------
     199// main loop
    86200int main()
    87201{
    88         sout | time(NULL) | ',' | measure_coroutine() | ',' | measure_thread() | endl;
    89 }
     202        sout | time(NULL) | ',';
     203        sout | measure_coroutine() | ',';
     204        sout | measure_thread() | ',';
     205        sout | measure_1_monitor_entry() | ',';
     206        sout | measure_2_monitor_entry() | ',';
     207        sout | measure_1_sched_int() | ',';
     208        sout | measure_2_sched_int() | endl;
     209}
  • src/libcfa/concurrency/monitor

    r0f9bef3 r6250a312  
    8181}
    8282
     83static inline void ^?{}( condition * this ) {
     84        free( this->monitors );
     85}
     86
    8387void wait( condition * this );
    8488void signal( condition * this );
  • src/libcfa/concurrency/monitor.c

    r0f9bef3 r6250a312  
    1717#include "monitor"
    1818
     19#include <stdlib>
     20
    1921#include "kernel_private.h"
    2022#include "libhdr.h"
     
    130132        this_thread()->current_monitors      = this->prev_mntrs;
    131133        this_thread()->current_monitor_count = this->prev_count;
     134}
     135
     136void debug_break() __attribute__(( noinline ))
     137{
     138       
    132139}
    133140
     
    171178
    172179        //Find the next thread(s) to run
    173         unsigned short thread_count = count;
     180        unsigned short thread_count = 0;
    174181        thread_desc * threads[ count ];
     182        for(int i = 0; i < count; i++) {
     183                threads[i] = 0;
     184        }
     185
     186        debug_break();
    175187
    176188        for( int i = 0; i < count; i++) {
    177189                thread_desc * new_owner = next_thread( this->monitors[i] );
    178                 thread_count = insert_unique( threads, i, new_owner );
    179         }
     190                thread_count = insert_unique( threads, thread_count, new_owner );
     191        }
     192
     193        debug_break();
    180194
    181195        LIB_DEBUG_PRINT_SAFE("Will unblock: ");
     
    339353                LIB_DEBUG_PRINT_SAFE("Branding\n");
    340354                assertf( thrd->current_monitors != NULL, "No current monitor to brand condition", thrd->current_monitors );
    341                 this->monitors = thrd->current_monitors;
    342355                this->monitor_count = thrd->current_monitor_count;
     356
     357                this->monitors = malloc( this->monitor_count * sizeof( *this->monitors ) );
     358                for( int i = 0; i < this->monitor_count; i++ ) {
     359                        this->monitors[i] = thrd->current_monitors[i];
     360                }
    343361        }
    344362}
    345363
    346364static inline unsigned short insert_unique( thread_desc ** thrds, unsigned short end, thread_desc * val ) {
    347         for(int i = 0; i < end; i++) {
     365        if( !val ) return end;
     366
     367        for(int i = 0; i <= end; i++) {
    348368                if( thrds[i] == val ) return end;
    349369        }
  • src/libcfa/concurrency/thread.c

    r0f9bef3 r6250a312  
    4040        this->next = NULL;
    4141
    42         this->current_monitors      = NULL;
    43         this->current_monitor_count = 0;
     42        this->current_monitors      = &this->mon;
     43        this->current_monitor_count = 1;
    4444}
    4545
  • src/libcfa/rational

    r0f9bef3 r6250a312  
    1212// Created On       : Wed Apr  6 17:56:25 2016
    1313// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Wed May  4 14:11:45 2016
    15 // Update Count     : 16
     14// Last Modified On : Mon May  1 08:25:06 2017
     15// Update Count     : 33
    1616//
     17
    1718#ifndef RATIONAL_H
    1819#define RATIONAL_H
     
    2122
    2223// implementation
     24typedef long int RationalImpl;
    2325struct Rational {
    24         long int numerator, denominator;                                        // invariant: denominator > 0
     26        RationalImpl numerator, denominator;                                    // invariant: denominator > 0
    2527}; // Rational
    2628
     
    3133// constructors
    3234void ?{}( Rational * r );
    33 void ?{}( Rational * r, long int n );
    34 void ?{}( Rational * r, long int n, long int d );
     35void ?{}( Rational * r, RationalImpl n );
     36void ?{}( Rational * r, RationalImpl n, RationalImpl d );
    3537
    36 // getter/setter for numerator/denominator
    37 long int numerator( Rational r );
    38 long int numerator( Rational r, long int n );
    39 long int denominator( Rational r );
    40 long int denominator( Rational r, long int d );
     38// getter for numerator/denominator
     39RationalImpl numerator( Rational r );
     40RationalImpl denominator( Rational r );
     41[ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational src );
     42// setter for numerator/denominator
     43RationalImpl numerator( Rational r, RationalImpl n );
     44RationalImpl denominator( Rational r, RationalImpl d );
    4145
    4246// comparison
     
    5761// conversion
    5862double widen( Rational r );
    59 Rational narrow( double f, long int md );
     63Rational narrow( double f, RationalImpl md );
    6064
    6165// I/O
  • src/libcfa/rational.c

    r0f9bef3 r6250a312  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul  9 11:18:04 2016
    13 // Update Count     : 40
     12// Last Modified On : Thu Apr 27 17:05:06 2017
     13// Update Count     : 51
    1414//
    1515
     
    3030// Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce rationals.
    3131// alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm
    32 static long int gcd( long int a, long int b ) {
     32static RationalImpl gcd( RationalImpl a, RationalImpl b ) {
    3333        for ( ;; ) {                                                                            // Euclid's algorithm
    34                 long int r = a % b;
     34                RationalImpl r = a % b;
    3535          if ( r == 0 ) break;
    3636                a = b;
     
    4040} // gcd
    4141
    42 static long int simplify( long int *n, long int *d ) {
     42static RationalImpl simplify( RationalImpl *n, RationalImpl *d ) {
    4343        if ( *d == 0 ) {
    4444                serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl;
     
    5656} // rational
    5757
    58 void ?{}( Rational * r, long int n ) {
     58void ?{}( Rational * r, RationalImpl n ) {
    5959        r{ n, 1 };
    6060} // rational
    6161
    62 void ?{}( Rational * r, long int n, long int d ) {
    63         long int t = simplify( &n, &d );                                        // simplify
     62void ?{}( Rational * r, RationalImpl n, RationalImpl d ) {
     63        RationalImpl t = simplify( &n, &d );                            // simplify
    6464        r->numerator = n / t;
    6565        r->denominator = d / t;
     
    6767
    6868
    69 // getter/setter for numerator/denominator
    70 
    71 long int numerator( Rational r ) {
     69// getter for numerator/denominator
     70
     71RationalImpl numerator( Rational r ) {
    7272        return r.numerator;
    7373} // numerator
    7474
    75 long int numerator( Rational r, long int n ) {
    76         long int prev = r.numerator;
    77         long int t = gcd( abs( n ), r.denominator );            // simplify
     75RationalImpl denominator( Rational r ) {
     76        return r.denominator;
     77} // denominator
     78
     79[ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational src ) {
     80        return *dest = src.[ numerator, denominator ];
     81}
     82
     83// setter for numerator/denominator
     84
     85RationalImpl numerator( Rational r, RationalImpl n ) {
     86        RationalImpl prev = r.numerator;
     87        RationalImpl t = gcd( abs( n ), r.denominator );                // simplify
    7888        r.numerator = n / t;
    7989        r.denominator = r.denominator / t;
     
    8191} // numerator
    8292
    83 long int denominator( Rational r ) {
    84         return r.denominator;
    85 } // denominator
    86 
    87 long int denominator( Rational r, long int d ) {
    88         long int prev = r.denominator;
    89         long int t = simplify( &r.numerator, &d );                      // simplify
     93RationalImpl denominator( Rational r, RationalImpl d ) {
     94        RationalImpl prev = r.denominator;
     95        RationalImpl t = simplify( &r.numerator, &d );                  // simplify
    9096        r.numerator = r.numerator / t;
    9197        r.denominator = d / t;
     
    170176
    171177// http://www.ics.uci.edu/~eppstein/numth/frap.c
    172 Rational narrow( double f, long int md ) {
     178Rational narrow( double f, RationalImpl md ) {
    173179        if ( md <= 1 ) {                                                                        // maximum fractional digits too small?
    174180                return (Rational){ f, 1};                                               // truncate fraction
     
    176182
    177183        // continued fraction coefficients
    178         long int m00 = 1, m11 = 1, m01 = 0, m10 = 0;
    179         long int ai, t;
     184        RationalImpl m00 = 1, m11 = 1, m01 = 0, m10 = 0;
     185        RationalImpl ai, t;
    180186
    181187        // find terms until denom gets too big
    182188        for ( ;; ) {
    183                 ai = (long int)f;
     189                ai = (RationalImpl)f;
    184190          if ( ! (m10 * ai + m11 <= md) ) break;
    185191                t = m00 * ai + m01;
     
    202208forall( dtype istype | istream( istype ) )
    203209istype * ?|?( istype *is, Rational *r ) {
    204         long int t;
     210        RationalImpl t;
    205211        is | &(r->numerator) | &(r->denominator);
    206212        t = simplify( &(r->numerator), &(r->denominator) );
  • src/main.cc

    r0f9bef3 r6250a312  
    3737#include "CodeGen/FixMain.h"
    3838#include "CodeTools/DeclStats.h"
     39#include "CodeTools/TrackLoc.h"
    3940#include "ControlStruct/Mutate.h"
    4041#include "SymTab/Validate.h"
     
    308309                } // if
    309310
     311                CodeTools::fillLocations( translationUnit );
    310312                CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true );
    311313
  • src/tests/Makefile.am

    r0f9bef3 r6250a312  
    2222concurrent=yes
    2323quick_test+= coroutine thread monitor
    24 concurrent_test=coroutine thread monitor multi-monitor sched-int sched-ext preempt
     24concurrent_test=coroutine thread monitor multi-monitor sched-int-disjoint sched-int-barge sched-int-wait sched-ext sched-ext-multi preempt
    2525else
    2626concurrent=no
  • src/tests/Makefile.in

    r0f9bef3 r6250a312  
    230230@BUILD_CONCURRENCY_TRUE@concurrent = yes
    231231@BUILD_CONCURRENCY_FALSE@concurrent_test =
    232 @BUILD_CONCURRENCY_TRUE@concurrent_test = coroutine thread monitor multi-monitor sched-int sched-ext preempt
    233 TEST_FLAGS = $(if $(test), 2> .err/${@}.log, )
     232@BUILD_CONCURRENCY_TRUE@concurrent_test = coroutine thread monitor multi-monitor sched-int-disjoint sched-int-barge sched-int-wait sched-ext sched-ext-multi preempt
    234233
    235234# applies to both programs
    236235EXTRA_FLAGS =
    237236BUILD_FLAGS = -g -Wall -Wno-unused-function @CFA_FLAGS@ ${EXTRA_FLAGS}
     237TEST_FLAGS = $(if $(test), 2> .err/${@}.log, )
    238238fstream_test_SOURCES = fstream_test.c
    239239vector_test_SOURCES = vector/vector_int.c vector/array.c vector/vector_test.c
  • src/tests/rational.c

    r0f9bef3 r6250a312  
    1010// Created On       : Mon Mar 28 08:43:12 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul  5 18:29:37 2016
    13 // Update Count     : 25
     12// Last Modified On : Tue May  2 22:11:05 2017
     13// Update Count     : 41
    1414//
    1515
     
    3636        b = (Rational){ -3, 2 };
    3737        sout | a | b | endl;
    38         sout | a == 1 | endl;
     38//      sout | a == 1 | endl; // FIX ME
    3939        sout | a != b | endl;
    4040        sout | a <  b | endl;
     
    6161        sout | narrow( 3.14159265358979, 256 ) | endl;
    6262
     63        sout | "decompose" | endl;
     64        RationalImpl n, d;
     65//      [n, d] = a;
     66//      sout | a | n | d | endl;
     67
     68        sout | "more tests" | endl;
    6369        Rational x = { 1, 2 }, y = { 2 };
    6470        sout | x - y | endl;
Note: See TracChangeset for help on using the changeset viewer.