as2js: /home/snapwebsites/snapcpp/contrib/as2js/lib/node_value.cpp Source File

as2js  0.1.14
AlexScript to JavaScript
node_value.cpp
Go to the documentation of this file.
1 /* lib/node_value.cpp
2 
3 Copyright (c) 2005-2019 Made to Order Software Corp. All Rights Reserved
4 
6 
7 Permission is hereby granted, free of charge, to any
8 person obtaining a copy of this software and
9 associated documentation files (the "Software"), to
10 deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify,
12 merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom
14 the Software is furnished to do so, subject to the
15 following conditions:
16 
17 The above copyright notice and this permission notice
18 shall be included in all copies or substantial
19 portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
22 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
23 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31 
32 */
33 
34 #include "as2js/node.h"
35 
36 #include "as2js/exceptions.h"
37 
38 
56 namespace as2js
57 {
58 
59 
60 
61 /**********************************************************************/
62 /**********************************************************************/
63 /*** NODE VALUE *****************************************************/
64 /**********************************************************************/
65 /**********************************************************************/
66 
84 void Node::set_boolean(bool value)
85 {
86  // only the corresponding node type accepts a set() call
87  switch(f_type)
88  {
89  case node_t::NODE_TRUE:
90  case node_t::NODE_FALSE:
91  break;
92 
93  default:
94  throw exception_internal_error("set_boolean() called with a non-Boolean node type");
95 
96  }
97 
99 }
100 
101 
117 {
118  // only the corresponding node type accepts a set() call
119  switch(f_type)
120  {
121  case node_t::NODE_INT64:
122  break;
123 
124  default:
125  throw exception_internal_error("set_int64() called with a non-int64 node type");
126 
127  }
128 
129  f_int = value;
130 }
131 
132 
148 {
149  // only the corresponding node type accepts a set() call
150  switch(f_type)
151  {
153  break;
154 
155  default:
156  throw exception_internal_error("set_float64() called with a non-float64 node type");
157 
158  }
159 
160  f_float = value;
161 }
162 
163 
183 void Node::set_string(String const& value)
184 {
185  // only the corresponding node type accepts a set() call
186  switch(f_type)
187  {
188  case node_t::NODE_BREAK: // name of label: BREAK [IDENTIFIER | DEFAULT];
189  case node_t::NODE_CLASS: // name of class: CLASS IDENTIFIER
190  case node_t::NODE_CONTINUE: // name of label: CONTINUE [IDENTIFIER | DEFAULT];
191  case node_t::NODE_ENUM: // name of enumeration: ENUM [IDENTIFIER] ...;
192  case node_t::NODE_FUNCTION: // name of function: FUNCTION [[GET | SET] IDENTIFIER | STRING] ...;
193  case node_t::NODE_GOTO: // name of label: GOTO IDENTIFIER;
194  case node_t::NODE_IDENTIFIER: // the identifier string: IDENTIFIER
195  case node_t::NODE_IMPORT: // name of package: IMPORT [IDENTIFIER ('.' IDENTIFIER)* | STRING] ...;
196  case node_t::NODE_INTERFACE: // name of interface: INTERFACE IDENTIFIER
197  case node_t::NODE_LABEL: // name of label: IDENTIFIER ':'
198  case node_t::NODE_NAME: // name of object field: { IDENTIFIER ':' ... }
199  case node_t::NODE_NAMESPACE: // name of namespace: NAMESPACE IDENTIFIER
200  case node_t::NODE_PACKAGE: // name of package: PACKAGE [IDENTIFIER ('.' IDENTIFIER)* | STRING] ...;
201  case node_t::NODE_PARAM: // name of parameter: FUNCTION '(' IDENTIFIER ... ')' ...
202  case node_t::NODE_REGULAR_EXPRESSION: // name of parameter: `...` or /.../...
203  case node_t::NODE_STRING: // the string itself: STRING
204  case node_t::NODE_VARIABLE: // name of variable: VAR <name> [':' type_expr] ['=' expression], ...;
205  case node_t::NODE_VAR_ATTRIBUTES: // name of variable: VAR <name> [':' type_expr] ['=' expression], ...; (transformed to VAR_ATTRIBUTES)
206  case node_t::NODE_VIDENTIFIER: // the identifier string: IDENTIFIER (transformed to VIDENTIFIER)
207  break;
208 
209  default:
210  throw exception_internal_error("set_string() called with a non-string node type");
211 
212  }
213 
214  f_str = value;
215 }
216 
217 
229 bool Node::get_boolean() const
230 {
231  // only the corresponding node type accepts a get() call
232  switch(f_type)
233  {
234  case node_t::NODE_TRUE:
235  return true;
236 
237  case node_t::NODE_FALSE:
238  return false;
239 
240  default:
241  throw exception_internal_error("get_boolean() called with a non-Boolean node type");
242 
243  }
244  /*NOTREACHED*/
245 }
246 
247 
263 {
264  // only the corresponding node type accepts a get() call
265  switch(f_type)
266  {
267  case node_t::NODE_INT64:
268  break;
269 
270  default:
271  throw exception_internal_error("get_int64() called with a non-int64 node type");
272 
273  }
274 
275  return f_int;
276 }
277 
278 
294 {
295  // only the corresponding node type accepts a get() call
296  switch(f_type)
297  {
299  break;
300 
301  default:
302  throw exception_internal_error("get_float64() called with a non-float64 node type");
303 
304  }
305 
306  return f_float;
307 }
308 
309 
329 String const& Node::get_string() const
330 {
331  // only the corresponding node type accepts a get() call
332  switch(f_type)
333  {
334  case node_t::NODE_BREAK: // name of label: BREAK [IDENTIFIER | DEFAULT];
335  case node_t::NODE_CLASS: // name of class: CLASS IDENTIFIER
336  case node_t::NODE_CONTINUE: // name of label: CONTINUE [IDENTIFIER | DEFAULT];
337  case node_t::NODE_ENUM: // name of enumeration: ENUM [IDENTIFIER] ...;
338  case node_t::NODE_FUNCTION: // name of function: FUNCTION [[GET | SET] IDENTIFIER | STRING] ...;
339  case node_t::NODE_GOTO: // name of label: GOTO IDENTIFIER;
340  case node_t::NODE_IDENTIFIER: // the identifier string: IDENTIFIER
341  case node_t::NODE_IMPORT: // name of package: IMPORT [IDENTIFIER ('.' IDENTIFIER)* | STRING] ...;
342  case node_t::NODE_INTERFACE: // name of interface: INTERFACE IDENTIFIER
343  case node_t::NODE_LABEL: // name of label: IDENTIFIER ':'
344  case node_t::NODE_NAME: // name of object field: { IDENTIFIER ':' ... }
345  case node_t::NODE_NAMESPACE: // name of namespace: NAMESPACE IDENTIFIER
346  case node_t::NODE_PACKAGE: // name of package: PACKAGE [IDENTIFIER ('.' IDENTIFIER)* | STRING] ...;
347  case node_t::NODE_PARAM: // name of parameter: FUNCTION '(' IDENTIFIER ... ')' ...
348  case node_t::NODE_REGULAR_EXPRESSION: // name of parameter: `...` or /.../...
349  case node_t::NODE_STRING: // the string itself: "..." or '...'
350  case node_t::NODE_VARIABLE: // name of variable: VAR <name> [':' type_expr] ['=' expression], ...;
351  case node_t::NODE_VAR_ATTRIBUTES: // name of variable: VAR <name> [':' type_expr] ['=' expression], ...; (transformed to VAR_ATTRIBUTES)
352  case node_t::NODE_VIDENTIFIER: // the identifier string: IDENTIFIER (transformed to VIDENTIFIER)
353  break;
354 
355  default:
356  throw exception_internal_error(std::string("get_string() called with non-string node type: ") + get_type_name());
357 
358  }
359 
360  return f_str;
361 }
362 
363 
364 }
365 // namespace as2js
366 
367 // vim: ts=4 sw=4 et
node_t f_type
Definition: node.h:594
String const & get_string() const
Get the string of this node.
Definition: node_value.cpp:329
void set_boolean(bool value)
Set the Boolean value of this node.
Definition: node_value.cpp:84
Float64 get_float64() const
Get the Float64 of this node.
Definition: node_value.cpp:293
String f_str
Definition: node.h:610
void set_int64(Int64 value)
Set the Int64 of this node.
Definition: node_value.cpp:116
void set_float64(Float64 value)
Set the Float64 of this node.
Definition: node_value.cpp:147
bool get_boolean() const
Get the Boolean value of this node.
Definition: node_value.cpp:229
Float64 f_float
Definition: node.h:609
Int64 get_int64() const
Get the Int64 of this node.
Definition: node_value.cpp:262
Int64 f_int
Definition: node.h:608
The AlexScript to JavaScript namespace.
Definition: compiler.cpp:37
void set_string(String const &value)
Set the string of this node.
Definition: node_value.cpp:183
char const * get_type_name() const
Retrieve the type of this node.
Definition: node_type.cpp:475

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly