[69bafd2] | 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 | // CVQualifiers.hpp --
|
---|
| 8 | //
|
---|
| 9 | // Author : Aaron B. Moss
|
---|
| 10 | // Created On : Mon May 13 15:00:00 2019
|
---|
| 11 | // Last Modified By : Aaron B. Moss
|
---|
| 12 | // Last Modified On : Mon May 13 15:00:00 2019
|
---|
| 13 | // Update Count : 1
|
---|
| 14 | //
|
---|
| 15 |
|
---|
| 16 | #pragma once
|
---|
| 17 |
|
---|
| 18 | #include "Bitfield.hpp"
|
---|
| 19 |
|
---|
| 20 | namespace ast {
|
---|
| 21 |
|
---|
| 22 | namespace CV {
|
---|
| 23 |
|
---|
| 24 | /// Bitflags for qualifiers
|
---|
| 25 | enum {
|
---|
| 26 | Const = 1 << 0,
|
---|
| 27 | Restrict = 1 << 1,
|
---|
| 28 | Volatile = 1 << 2,
|
---|
[3f3bfe5a] | 29 | Mutex = 1 << 3,
|
---|
| 30 | Atomic = 1 << 4,
|
---|
| 31 | NumQualifiers = 5
|
---|
[69bafd2] | 32 | };
|
---|
| 33 |
|
---|
| 34 | /// Mask for equivalence-preserving qualfiers
|
---|
[3f3bfe5a] | 35 | enum { EquivQualifiers = ~Restrict };
|
---|
[69bafd2] | 36 |
|
---|
| 37 | /// Underlying data for qualifiers
|
---|
| 38 | struct qualifier_flags {
|
---|
| 39 | union {
|
---|
| 40 | unsigned int val;
|
---|
| 41 | struct {
|
---|
| 42 | bool is_const : 1;
|
---|
| 43 | bool is_restrict : 1;
|
---|
| 44 | bool is_volatile : 1;
|
---|
| 45 | bool is_mutex : 1;
|
---|
| 46 | bool is_atomic : 1;
|
---|
| 47 | };
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 | constexpr qualifier_flags( unsigned int val = 0 ) : val(val) {}
|
---|
| 51 | };
|
---|
| 52 |
|
---|
| 53 | /// Type qualifiers
|
---|
| 54 | using Qualifiers = bitfield<qualifier_flags>;
|
---|
| 55 |
|
---|
| 56 | // `restrict` and `lvalue` are ignored by qualifier equivalence.
|
---|
| 57 | // ordering is a subtype relationship over qualifiers, e.g. `int` => `const int` is free
|
---|
| 58 |
|
---|
[24afc53] | 59 | inline bool operator== ( Qualifiers a, Qualifiers b ) {
|
---|
[8a5530c] | 60 | return (a.val & EquivQualifiers) == (b.val & EquivQualifiers);
|
---|
[69bafd2] | 61 | }
|
---|
[24afc53] | 62 | inline bool operator!= ( Qualifiers a, Qualifiers b ) {
|
---|
[8a5530c] | 63 | return !(a == b);
|
---|
[69bafd2] | 64 | }
|
---|
[24afc53] | 65 | inline bool operator<= ( Qualifiers a, Qualifiers b ) {
|
---|
[69bafd2] | 66 | return a.is_const <= b.is_const // non-const converts to const for free
|
---|
| 67 | && a.is_volatile <= b.is_volatile // non-volatile converts to volatile for free
|
---|
| 68 | && a.is_mutex >= b.is_mutex // mutex converts to non-mutex for free
|
---|
| 69 | && a.is_atomic == b.is_atomic; // atomicity must be preserved in free conversion
|
---|
| 70 | }
|
---|
[24afc53] | 71 | inline bool operator< ( Qualifiers a, Qualifiers b ) { return a != b && a <= b; }
|
---|
| 72 | inline bool operator>= ( Qualifiers a, Qualifiers b ) { return b <= a; }
|
---|
| 73 | inline bool operator> ( Qualifiers a, Qualifiers b ) { return b < a; }
|
---|
[69bafd2] | 74 |
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | // Local Variables: //
|
---|
| 80 | // tab-width: 4 //
|
---|
| 81 | // mode: c++ //
|
---|
| 82 | // compile-command: "make install" //
|
---|
[3f3bfe5a] | 83 | // End: //
|
---|