Changeset a01f7c94


Ignore:
Timestamp:
Sep 1, 2017, 3:24:37 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
78a0b88
Parents:
681c764
Message:

Implement multi-declaration if conditional and update test

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r681c764 ra01f7c94  
    9999        } // if
    100100
    101         Expression * cond = ctl->condition ? maybeMoveBuild< Expression >(ctl->condition) : new VariableExpr( dynamic_cast<DeclarationWithType *>( dynamic_cast<DeclStmt *>( init.back() )->decl ) );
     101        Expression * cond = nullptr;
     102        if ( ctl->condition ) {
     103                // compare the provided condition against 0
     104                cond =  notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) );
     105        } else {
     106                for ( Statement * stmt : init ) {
     107                        // build the && of all of the declared variables compared against 0
     108                        DeclStmt * declStmt = safe_dynamic_cast< DeclStmt * >( stmt );
     109                        DeclarationWithType * dwt = safe_dynamic_cast< DeclarationWithType * >( declStmt->decl );
     110                        Expression * nze = notZeroExpr( new VariableExpr( dwt ) );
     111                        cond = cond ? new LogicalExpr( cond, nze, true ) : nze;
     112                }
     113        }
    102114        delete ctl;
    103         return new IfStmt( noLabels, notZeroExpr( cond ), thenb, elseb, init );
     115        return new IfStmt( noLabels, cond, thenb, elseb, init );
    104116}
    105117
  • src/tests/.expect/ifcond.txt

    r681c764 ra01f7c94  
    11x != 0 correct
    2 x != 0 && y == 0 incorrect
     2x != 0 && y != 0 correct
    33x == y correct
  • src/tests/ifcond.c

    r681c764 ra01f7c94  
    1 // 
     1//
    22// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // ifcond.c -- 
    8 // 
     6//
     7// ifcond.c --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Aug 26 10:13:11 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 30 07:55:24 2017
    13 // Update Count     : 13
    14 // 
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Fri Sep 01 15:22:19 2017
     13// Update Count     : 14
     14//
    1515
    16 #include<fstream>
     16#include <fstream>
    1717
    1818int f( int r ) { return r; }
     
    2727        } // if
    2828
    29         if ( int x = 4, y = 0 ) {                                                       // FIXME && distribution
     29        if ( int x = 4, y = 0 ) {
     30                sout | "x != 0 && y != 0 incorrect" | endl;
     31        } else if ( int x = 4, y = 1 ) {
    3032                sout | "x != 0 && y != 0 correct" | endl;
    31     } else {
    32                 sout | "x != 0 && y == 0 incorrect" | endl;
     33        } else {
     34                sout | "x == 0 || y == 0 incorrect" | endl;
    3335        } // if
    3436
Note: See TracChangeset for help on using the changeset viewer.