~eda-qa/leaflang/misc

« back to all changes in this revision

Viewing changes to include/ir/value.hpp

  • Committer: edA-qa mort-ora-y
  • Date: 2017-07-22 19:48:13 UTC
  • mfrom: (99.1.41 error)
  • Revision ID: eda-qa@disemia.com-20170722194813-h3yqkhe1j2ouwga4
merging error handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
struct value
12
12
{
13
 
        enum form_t
14
 
        {
 
13
        enum form_t {
15
14
                //the noref types
16
15
                f_import_code = 1,
17
16
                f_import_data,
22
21
                f_nullptr,
23
22
                f_temp,
24
23
                f_undefined,
 
24
                f_raw_binary,
25
25
                
26
26
                //the ref types
27
27
                f_return_ref,
31
31
                f_local,
32
32
        } form;
33
33
        
34
 
        value()
35
 
                : form( form_t(0) )
36
 
                , is_export(false)
37
 
                , need_pointer(false)
38
 
                , cref(0)
39
 
        { }
40
 
        value( form_t form )
41
 
                : form( form )
42
 
                , is_export( false )
43
 
                , need_pointer( false )
44
 
                , cref( 0 )
45
 
        { }
 
34
        value() : 
 
35
                form( form_t(0) ), 
 
36
                is_export(false), 
 
37
                need_pointer(false), 
 
38
                cref(0) { 
 
39
        }
 
40
        value( form_t form ) : 
 
41
                form( form ), 
 
42
                is_export( false ), 
 
43
                need_pointer( false ), 
 
44
                cref( 0 ) { 
 
45
        }
46
46
        
47
47
        virtual ~value() {}
48
 
        virtual void validate(util::validation_context & vctx) const;
 
48
        virtual void validate( util::validation_context & vctx) const;
49
49
        
50
50
        //is this directly usable as storage
51
 
        bool is_direct_storage() const
52
 
        { return form == f_return_ref || form == f_global || form == f_local || form == f_capture_ref; }
 
51
        bool is_direct_storage() const { 
 
52
                return form == f_return_ref || form == f_global || form == f_local || form == f_capture_ref; 
 
53
        }
53
54
        bool is_any_storage() const;
54
55
        
55
 
        bool is_noref() const
56
 
        { return form == f_import_code || form == f_import_data || form == f_const_integer 
 
56
        bool is_noref() const { 
 
57
                return form == f_import_code || form == f_import_data || form == f_const_integer 
57
58
                || form == f_const_float || form == f_const_boolean || form == f_temp 
58
 
                || form == f_const_binary; }
 
59
                || form == f_const_binary; 
 
60
        }
59
61
                
60
62
        std::string name;
61
63
        size_t anon_ref; //only relevant if name is empty
62
64
        shared_ptr<type const> direct_type; //if null then not yet initialized
63
65
        bool is_export;
64
66
        
 
67
        //TODO: a variant that includes the raw_binary
65
68
        union {
66
69
                //TODO: a larger data type is required for larger integers
67
70
                intmax_t int_value;
75
78
                        size_t parent;
76
79
                } capture;
77
80
        };
 
81
        std::vector<uint8_t> raw_binary;
78
82
        
79
83
        //a pointer will be required of this object
80
84
        bool need_pointer;
83
87
        mutable intptr_t cref;
84
88
};
85
89
 
86
 
struct value_defn
87
 
{
 
90
struct value_defn {
88
91
        shared_ptr<value> origin;
89
92
        
90
93
        template<typename T>
91
 
        value_defn( shared_ptr<T> origin )
92
 
                : origin( origin )
93
 
        { }
94
 
        
95
 
        shared_ptr<type const> result_type() const
96
 
        { return origin->direct_type; }
97
 
        
98
 
        value_defn()
99
 
        { }
100
 
        
101
 
        void validate(util::validation_context & vctx) const;
 
94
        value_defn( shared_ptr<T> origin ) : 
 
95
                origin( origin ) { 
 
96
        }
 
97
        
 
98
        shared_ptr<type const> result_type() const { 
 
99
                return origin->direct_type; 
 
100
        }
 
101
        
 
102
        value_defn() { 
 
103
        }
 
104
        
 
105
        void validate( util::validation_context & vctx) const;
102
106
};
103
107
 
104
108
/**
168
172
        */
169
173
        shared_ptr<type const> result_type() const;
170
174
        
171
 
        value_ref()
172
 
                : how( how_t(0) )
173
 
        { }
174
 
        value_ref( value_defn const & vd )
175
 
        { *this = as_value(vd); }
 
175
        value_ref() : 
 
176
                how( how_t(0) ) { 
 
177
        }
 
178
        value_ref( value_defn const & vd ) { 
 
179
                *this = as_value(vd); 
 
180
        }
176
181
        
177
182
        //simplify conversion from value_defn (used commonly and unambiguous)
178
 
        value_ref & operator=(value_defn const & vd )
179
 
        { 
 
183
        value_ref & operator=(value_defn const & vd ) { 
180
184
                *this = as_value( vd ); 
181
185
                return *this;
182
186
        }
183
187
        
184
 
        void validate(util::validation_context & vctx) const;
 
188
        void validate( util::validation_context & vctx) const;
185
189
        
 
190
        bool is_valid() const {
 
191
                return how != how_t(0);
 
192
        }
186
193
private:
187
 
        value_ref( shared_ptr<value> origin, how_t how )
188
 
                : origin( origin )
189
 
                , how( how )
190
 
        { }
 
194
        value_ref( shared_ptr<value> origin, how_t how ) : 
 
195
                origin( origin ), 
 
196
                how( how ) { 
 
197
        }
191
198
};
192
199
 
193
200
} //eon ir