coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
evaluation.h
Go to the documentation of this file.
1 #ifndef EVALUATION_H
2 #define EVALUATION_H
3 #pragma once
4 /***************************************************************************
5  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
6  * All rights reserved. *
7  * *
8  * Originally contributed by Mike Kinghan, imk@burroingroingjoing.com. *
9  * *
10  * Redistribution and use in source and binary forms, with or without *
11  * modification, are permitted provided that the following conditions *
12  * are met: *
13  * *
14  * Redistributions of source code must retain the above copyright *
15  * notice, this list of conditions and the following disclaimer. *
16  * *
17  * Redistributions in binary form must reproduce the above copyright *
18  * notice, this list of conditions and the following disclaimer in the *
19  * documentation and/or other materials provided with the distribution. *
20  * *
21  * Neither the name of Mike Kinghan nor the names of its contributors *
22  * may be used to endorse or promote products derived from this software *
23  * without specific prior written permission. *
24  * *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
32  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
33  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
34  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
35  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
36  * DAMAGE. *
37  * *
38  **************************************************************************/
39 #include "integer.h"
40 
48 struct evaluation {
49 
50  evaluation() = default;
51 
55  explicit evaluation(integer const & val)
56  : _value(val){}
57 
61  explicit evaluation(int val)
62  : _value(integer(INT_INT,val)){}
63 
65  bool resolved() const {
66  return _value.type() != INT_UNDEF;
67  }
68 
70  bool is_true() const {
71  return resolved() && _value.raw() != 0;
72  }
73 
75  bool is_false() const {
76  return resolved() && _value.raw() == 0;
77  }
78 
80  bool insoluble() const {
81  return _insoluble;
82  }
83 
85  bool empty() const {
86  return _empty;
87  }
88 
93  unsigned short & net_infix_ops() {
94  return _net_infix_ops;
95  }
96 
98  integer const & value() const {
99  return _value;
100  }
101 
103  void set_value(integer const & val) {
104  _value = val;
105  _net_infix_ops = 0;
106  }
107 
109  void set_value(int val) {
110  _value = integer(INT_INT,val);
111  _net_infix_ops = 0;
112  }
113 
115  void set_insoluble() {
117  _insoluble = true;
118  }
119 
121  void set_empty() {
122  _empty = true;
123  }
124 
126  void set_parens_off(size_t loff, size_t roff) {
127  _lparen_off = loff;
128  _rparen_off = roff;
129  }
130 
133  _lparen_off = size_t(-1);
134  _rparen_off = size_t(-1);
135  }
136 
138  size_t lparen_off() const {
139  return _lparen_off;
140  }
141 
143  size_t rparen_off() const {
144  return _rparen_off;
145  }
146 
147 private:
153  unsigned short _net_infix_ops = 0;
155  bool _empty = false;
157  bool _insoluble = false;
160  size_t _lparen_off = size_t(-1);
162  size_t _rparen_off = size_t(-1);
163 };
164 
165 #endif /* EOF*/
bool _empty
Is the expression empty?
Definition: evaluation.h:155
bool _insoluble
Is the expression insoluble;.
Definition: evaluation.h:157
unsigned long long raw() const
Get the bits comprising the integer as an unsigned long long
Definition: integer.h:93
void set_value(int val)
Set the integral value of the expression.
Definition: evaluation.h:109
integer const & value() const
Get the integral value of the expression.
Definition: evaluation.h:98
void set_parens_off(size_t loff, size_t roff)
Set the text offsets of surrounding parentheses.
Definition: evaluation.h:126
size_t lparen_off() const
Get the text offset of the left parenthesis, if any. -1 if none.
Definition: evaluation.h:138
size_t _lparen_off
Definition: evaluation.h:160
void set_insoluble()
Classify the expression as insoluble.
Definition: evaluation.h:115
Undetermined type or invalid.
Definition: integer.h:49
Class integer encapsulates an integer of some type.
Definition: integer.h:65
void clear_parens_off()
Clear the text offsets of surrounding parentheses.
Definition: evaluation.h:132
void set_empty()
Classify the expression as empty.
Definition: evaluation.h:121
void set_value(integer const &val)
Set the integral value of the expression.
Definition: evaluation.h:103
Type int
Definition: integer.h:51
size_t rparen_off() const
Get the text offset of the right parenthesis, if any. -1 if none.
Definition: evaluation.h:143
unsigned short _net_infix_ops
Number of binary operators remaining in the evaluated expression after simplification.
Definition: evaluation.h:153
bool resolved() const
Say whether the expression has been resolved.
Definition: evaluation.h:65
integer _value
The integer value of the evaluated expression if it is soluble.
Definition: evaluation.h:149
integer_type type() const
Get the type of the integer
Definition: integer.h:77
bool insoluble() const
Say whether the expression is insoluble.
Definition: evaluation.h:80
bool is_false() const
Say whether the expression is false.
Definition: evaluation.h:75
evaluation(int val)
Explicitly construct from int.
Definition: evaluation.h:61
bool empty() const
Say whether the expression is empty.
Definition: evaluation.h:85
bool is_true() const
Say whether the expression is true.
Definition: evaluation.h:70
struct evaluation represents the result of evaluating a putative expression.
Definition: evaluation.h:48
size_t _rparen_off
Text offset of right parenethesis, if any.
Definition: evaluation.h:162
evaluation(integer const &val)
Explicitly construct from an integer.
Definition: evaluation.h:55
unsigned short & net_infix_ops()
Get/set the residual number of binary operators in the expression, after simplification.
Definition: evaluation.h:93