source: src/AST/CVQualifiers.hpp@ 0f6a7752

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 0f6a7752 was 24afc53, checked in by Aaron Moss <a3moss@…>, 6 years ago

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

  • 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 Lvalue = 1 << 3,
30 Mutex = 1 << 4,
31 Atomic = 1 << 5,
32 NumQualifiers = 6
33 };
34
35 /// Mask for equivalence-preserving qualfiers
36 enum { EquivQualifiers = ~(Restrict | Lvalue) };
37
38 /// Underlying data for qualifiers
39 struct qualifier_flags {
40 union {
41 unsigned int val;
42 struct {
43 bool is_const : 1;
44 bool is_restrict : 1;
45 bool is_volatile : 1;
46 bool is_lvalue : 1;
47 bool is_mutex : 1;
48 bool is_atomic : 1;
49 };
50 };
51
52 constexpr qualifier_flags( unsigned int val = 0 ) : val(val) {}
53 };
54
55 /// Type qualifiers
56 using Qualifiers = bitfield<qualifier_flags>;
57
58 // `restrict` and `lvalue` are ignored by qualifier equivalence.
59 // ordering is a subtype relationship over qualifiers, e.g. `int` => `const int` is free
60
61 inline bool operator== ( Qualifiers a, Qualifiers b ) {
62 return (a.val & EquivQualifiers) == (b.val & EquivQualifiers);
63 }
64 inline bool operator!= ( Qualifiers a, Qualifiers b ) {
65 return !(a == b);
66 }
67 inline bool operator<= ( Qualifiers a, Qualifiers b ) {
68 return a.is_const <= b.is_const // non-const converts to const for free
69 && a.is_volatile <= b.is_volatile // non-volatile converts to volatile for free
70 && a.is_mutex >= b.is_mutex // mutex converts to non-mutex for free
71 && a.is_atomic == b.is_atomic; // atomicity must be preserved in free conversion
72 }
73 inline bool operator< ( Qualifiers a, Qualifiers b ) { return a != b && a <= b; }
74 inline bool operator>= ( Qualifiers a, Qualifiers b ) { return b <= a; }
75 inline bool operator> ( Qualifiers a, Qualifiers b ) { return b < a; }
76
77}
78
79}
80
81// Local Variables: //
82// tab-width: 4 //
83// mode: c++ //
84// compile-command: "make install" //
85// End: //
Note: See TracBrowser for help on using the repository browser.