source: src/Parser/parserutility.cc @ 44adf1b

Last change on this file since 44adf1b was 61e362f, checked in by Andrew Beach <ajbeach@…>, 4 months ago

Changed notZeroExpr so that expressions with conditional contexts are handled in the resolver instead of the parser. Bugs kept the same from being done with statements. (Also a bit of clean-up from the last commit and a small fix in code-gen.)

  • Property mode set to 100644
File size: 1.2 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// parserutility.cc --
8//
9// Author           : Rodolfo G. Esteves
10// Created On       : Sat May 16 15:30:39 2015
11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Mar  1 10:42:00 2023
13// Update Count     : 9
14//
15
16#include "parserutility.h"
17
18#include <list>                  // for list
19#include <string>                // for string
20
21#include "AST/Expr.hpp"          // for UntypedExpr, CastExpr, ConstantExpr
22#include "AST/Type.hpp"          // for BasicType, ZeroType, BasicType::Kind...
23
24// rewrite
25//    if ( x ) ...
26// as
27//    if ( (int)(x != 0) ) ...
28
29ast::Expr * notZeroExpr( const ast::Expr * orig ) {
30        return ( !orig ) ? nullptr : new ast::CastExpr( orig->location,
31                ast::UntypedExpr::createCall( orig->location,
32                        "?!=?",
33                        {
34                                orig,
35                                new ast::ConstantExpr( orig->location,
36                                        new ast::ZeroType(),
37                                        "0",
38                                        std::optional<unsigned long long>( 0 )
39                                ),
40                        }
41                ),
42                new ast::BasicType( ast::BasicType::SignedInt )
43        );
44}
45
46// Local Variables: //
47// tab-width: 4 //
48// mode: c++ //
49// compile-command: "make install" //
50// End: //
Note: See TracBrowser for help on using the repository browser.