| 1 |
itemization( |
| 2 |
it() Constructors: |
| 3 |
Default, copy and move constructors. No data can be retrieved from |
| 4 |
tt(SType) objects that were constructed by tt(SType)'s default |
| 5 |
constructors, but they can accept values of defined polymorphic types, |
| 6 |
which may then be retrieved from those objects. |
| 7 |
|
| 8 |
it() Operators: |
| 9 |
The standard overloaded assignment operators (copy and move assignment |
| 10 |
operators) are available. |
| 11 |
|
| 12 |
In addition the members |
| 13 |
verb( |
| 14 |
SType &operator=(Type const &value) |
| 15 |
and |
| 16 |
SType &operator=(Type &&tmp) |
| 17 |
) |
| 18 |
are defined for each of the polymorphic semantic value types. Up to |
| 19 |
version 6.03.00 these members were defined as member templates, but |
| 20 |
sometimes awkward compilation errors were encountered as with member |
| 21 |
templates tt(Type) must exactly match one of the defined polymorphic |
| 22 |
semantic types since tt(Type) is used to determine the appropriate |
| 23 |
tt(Meta_::Tag_) value. As a consequence, if, e.g., a polymorphic type |
| 24 |
tt(%polymorphic INT: int) is defined then an assignment like tt($$ = |
| 25 |
true) fails, since the inferred type is tt(bool) and no matching |
| 26 |
polymorphic type is available. Now that the assignment operators are |
| 27 |
defined as plain member functions this problem isn't encountered |
| 28 |
anymore because standard type conversions may then be applied by the |
| 29 |
compiler. Note that ambiguities may still be encountered. If, e.g., |
| 30 |
polymorphic types are defined for tt(int) and tt(char) and an |
| 31 |
expression like tt($$ = 30U) is used the compiler cannot tell whether |
| 32 |
tt($$) refers to the tt(int) or to the tt(char) semantic value. A |
| 33 |
standard (static) cast, or explicitly calling the tt(assign) member |
| 34 |
(see the next item) solves these kind of ambiguities. |
| 35 |
|
| 36 |
When tt(operator=(Type const &value)) is used, the left-hand side |
| 37 |
tt(SType) object receives a copy of tt(value); when tt(operator=(Type |
| 38 |
&&tmp)) is used, tt(tmp) is move-assigned to the left-hand side |
| 39 |
tt(SType) object; |
| 40 |
|
| 41 |
it() tt(void assign<tag>(Args &&...args)) |
| 42 |
The tt(tag) template argument must be a tt(Tag_) value. This member |
| 43 |
function constructs a semantic value of the type matching tt(tag) from |
| 44 |
the arguments that are passed to this member (zero arguments are OK if |
| 45 |
the type associated with tt(tag) supports default construction). The |
| 46 |
constructed value (not a copy of this value) is then stored in the |
| 47 |
tt(STYPE_) object for which tt(assign) has been called. |
| 48 |
|
| 49 |
As a tt(Meta_::Tag_) value must be specified when using tt(assign) |
| 50 |
the compiler can use the explicit tag to convert tt(assign's) arguments |
| 51 |
to an tt(SType) object of the type matching the specified tag. |
| 52 |
|
| 53 |
The member tt(assign) can be used to store a specific polymorphic |
| 54 |
semantic value in an tt(STYPE_) object. It differs from the set of |
| 55 |
tt(operator=(Type)) members in that tt(assign) accepts multiple |
| 56 |
arguments to construct the requested tt(SType) value from, whereas the |
| 57 |
tt(operator=) members only accept single arguments of defined |
| 58 |
polymorphic types. |
| 59 |
|
| 60 |
To initialize an tt(STYPE_) object with a default tt(STYPE_) value, |
| 61 |
direct assignment can be used (e.g., tt(d_lval_ = STYPE_{})). To |
| 62 |
assign a semantic value to a production rule using tt(assign) the |
| 63 |
tt(_$$) notation must be used, as tt($$) is interpreted as the |
| 64 |
polymorphic value type that is associated with the production |
| 65 |
rule: |
| 66 |
verb( |
| 67 |
_$$.assign<Tag_::CHAR>(30U); |
| 68 |
) |
| 69 |
|
| 70 |
it() tt(DataType &get<tag>()), and tt(DataType const &get<tag>() const) |
| 71 |
These members return references to the object's semantic values. The |
| 72 |
tt(tag) must be a tt(Tag_) value: its specification tells the |
| 73 |
compiler which semantic value type it must use. |
| 74 |
|
| 75 |
When the option/directive tt(tag-mismatches on) was specified then |
| 76 |
tt(get), when called from the generated tt(parse) function, performs a |
| 77 |
run-time check to confirm that the specified tag corresponds to |
| 78 |
object's actual tt(Tag_) value. If a mismatch is observed, then the |
| 79 |
parsing function aborts with a fatal error message. When |
| 80 |
shorthand notations (like tt($$) and tt($1)) are used in production |
| 81 |
rules' action blocks, then bic() can determine the correct tt(tag), |
| 82 |
preventing the run-time check from failing. |
| 83 |
|
| 84 |
But once a fatal error em(is) encountered, it can be difficult to |
| 85 |
determine which action block generated the error. If this happens, |
| 86 |
then consider regenerating the parser specifying the tt(--debug) |
| 87 |
option, calling |
| 88 |
verb(parser.setDebug(Parser::ACTIONCASES)) |
| 89 |
before calling the parser's tt(parse) function. |
| 90 |
|
| 91 |
Following this the case-entry numbers of the tt(switch) which is |
| 92 |
defined in the parser's tt(executeAction) member are inserted into the |
| 93 |
standard output stream just before the matching statements are |
| 94 |
executed. The action case number that's reported just before the |
| 95 |
program reports the fatal error tells you in which of the grammar's |
| 96 |
action block the error was encountered. |
| 97 |
|
| 98 |
it() tt(Tag_ tag() const) |
| 99 |
The tag matching the semantic value's polymorphic type is returned. The |
| 100 |
returned value is a valid tt(Tag_) value when the tt(SType) object's |
| 101 |
tt(valid) member returns tt(true); |
| 102 |
|
| 103 |
By default, or after assigning a plain (default) tt(STYPE_) object to |
| 104 |
an tt(STYPE_) object (e.g., using a statement like tt($$ = |
| 105 |
STYPE_{})), tt(valid) returns tt(false), and the tt(tag) member |
| 106 |
returns tt(Meta_::sizeofTag_). |
| 107 |
|
| 108 |
it() tt(bool valid() const) |
| 109 |
|
| 110 |
The value tt(true) is returned if the object contains a semantic |
| 111 |
value. Otherwise tt(false) is returned. Note that default tt(STYPE_) |
| 112 |
values can be assigned to tt(STYPE_) objects, but they do not |
| 113 |
represent valid semantic values. See also the previous description of |
| 114 |
the tt(tag) member. |
| 115 |
) |