source: src/AST/CVQualifiers.hpp @ 7030dab

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 7030dab was 3f3bfe5a, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Merge from master to new-ast. Removing old lvalue support.

  • Property mode set to 100644
File size: 2.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// 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
20namespace ast {
21
22namespace CV {
23
24        /// Bitflags for qualifiers
25        enum {
26                Const    = 1 << 0,
27                Restrict = 1 << 1,
28                Volatile = 1 << 2,
29                Mutex    = 1 << 3,
30                Atomic   = 1 << 4,
31                NumQualifiers = 5
32        };
33
34        /// Mask for equivalence-preserving qualfiers
35        enum { EquivQualifiers = ~Restrict };
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
59        inline bool operator== ( Qualifiers a, Qualifiers b ) {
60                return (a.val & EquivQualifiers) == (b.val & EquivQualifiers);
61        }
62        inline bool operator!= ( Qualifiers a, Qualifiers b ) {
63                return !(a == b);
64        }
65        inline bool operator<= ( Qualifiers a, Qualifiers b ) {
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        }
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; }
74
75}
76
77}
78
79// Local Variables: //
80// tab-width: 4 //
81// mode: c++ //
82// compile-command: "make install" //
83// End: //
Note: See TracBrowser for help on using the repository browser.