source: src/Common/Eval.h @ b7b3e41

Last change on this file since b7b3e41 was 8f557161, checked in by Michael Brooks <mlbrooks@…>, 17 months ago

Clarify and fix accuracy in eval public API, on reporting "unable to evaluate."

While the eval internals always used the flag pair valid and cfavalid almost correctly, the public interface exposed the outcome as a single flag, and the various interpretations of this flag were a mess.

Old cfacc treated sizeof(whatever) in some contexts as "known to be zero," which is wrong.
The generally correct answer, which new cfacc now uses is, "unknown now, but GCC will see it as a fine constant."
New tests/eval.cfa captures this fact: is runnable and would fail on old cfacc; it passes with new cfacc.

  • Property mode set to 100644
File size: 958 bytes
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// Eval.h -- Evaluate parts of the ast at compile time.
8//
9// Author           : Andrew Beach
10// Created On       : Fri Feb 17 11:41:00 2023
11// Last Modified By : Andrew Beach
12// Last Modified On : Fri Feb 17 11:41:00 2023
13// Update Count     : 0
14//
15
16#pragma once
17
18#include <utility>                 // for pair
19
20class Expression;
21namespace ast {
22        class Expr;
23}
24
25struct Evaluation {
26        long long int knownValue;
27        bool hasKnownValue;
28        bool isEvaluableInGCC;
29};
30
31/// Evaluates expr as a long long int.
32/// If second is false, expr could not be evaluated.
33std::pair<long long int, bool> eval(const Expression * expr);
34Evaluation eval(const ast::Expr * expr);
35
36// Local Variables: //
37// tab-width: 4 //
38// mode: c++ //
39// compile-command: "make install" //
40// End: //
Note: See TracBrowser for help on using the repository browser.