as2js: /home/snapwebsites/snapcpp/contrib/as2js/include/as2js/node.h Source File

node.h
Go to the documentation of this file.
1 #ifndef AS2JS_NODE_H
2 #define AS2JS_NODE_H
3 /* include/as2js/node.h
4 
5 Copyright (c) 2005-2019 Made to Order Software Corp. All Rights Reserved
6 
8 
9 Permission is hereby granted, free of charge, to any
10 person obtaining a copy of this software and
11 associated documentation files (the "Software"), to
12 deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify,
14 merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom
16 the Software is furnished to do so, subject to the
17 following conditions:
18 
19 The above copyright notice and this permission notice
20 shall be included in all copies or substantial
21 portions of the Software.
22 
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
24 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
25 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
26 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
27 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
29 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
31 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 SOFTWARE.
33 
34 */
35 
36 #include "string.h"
37 #include "int64.h"
38 #include "float64.h"
39 #include "position.h"
40 
41 #include <limits>
42 #include <bitset>
43 #include <map>
44 #include <memory>
45 #include <vector>
46 
47 
48 namespace as2js
49 {
50 
51 
52 
53 // NOTE: The attributes (Attrs) are defined in the second pass
54 // whenever we transform the identifiers in actual attribute
55 // flags. While creating the tree, the attributes are always
56 // set to 0.
57 
58 // Note: the std::enable_shared_from_this<> has no virtual destructor
59 #pragma GCC diagnostic push
60 #pragma GCC diagnostic ignored "-Weffc++"
61 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
62 
63 class Node
64  : public std::enable_shared_from_this<Node>
65 {
66 public:
67  typedef std::shared_ptr<Node> pointer_t;
68  typedef std::weak_ptr<Node> weak_pointer_t;
69  typedef std::map<String, weak_pointer_t> map_of_weak_pointers_t;
70  typedef std::vector<pointer_t> vector_of_pointers_t;
71  typedef std::vector<weak_pointer_t> vector_of_weak_pointers_t;
72 
73  // member related depth parameter
74  typedef ssize_t depth_t;
75 
76  static depth_t const MATCH_NOT_FOUND = 0;
77  static depth_t const MATCH_HIGHEST_DEPTH = 1;
78  static depth_t const MATCH_LOWEST_DEPTH = std::numeric_limits<int>::max() / 2;
79 
80  // the node type is often referenced as a token
81  enum class node_t
82  {
83  NODE_EOF = -1, // when reading after the end of the file
84  NODE_UNKNOWN = 0, // node still uninitialized
85 
86  // here are all the punctuation as themselves
87  // (i.e. '<', '>', '=', '+', '-', etc.)
88  NODE_ADD = '+', // 0x2B
89  NODE_ASSIGNMENT = '=', // 0x3D
90  NODE_BITWISE_AND = '&', // 0x26
91  NODE_BITWISE_NOT = '~', // 0x7E
92  NODE_BITWISE_OR = '|', // 0x7C
93  NODE_BITWISE_XOR = '^', // 0x5E
94  NODE_CLOSE_CURVLY_BRACKET = '}', // 0x7D
95  NODE_CLOSE_PARENTHESIS = ')', // 0x29
96  NODE_CLOSE_SQUARE_BRACKET = ']', // 0x5D
97  NODE_COLON = ':', // 0x3A
98  NODE_COMMA = ',', // 0x2C
99  NODE_CONDITIONAL = '?', // 0x3F
100  NODE_DIVIDE = '/', // 0x2F
101  NODE_GREATER = '>', // 0x3E
102  NODE_LESS = '<', // 0x3C
103  NODE_LOGICAL_NOT = '!', // 0x21
104  NODE_MODULO = '%', // 0x25
105  NODE_MULTIPLY = '*', // 0x2A
106  NODE_OPEN_CURVLY_BRACKET = '{', // 0x7B
107  NODE_OPEN_PARENTHESIS = '(', // 0x28
108  NODE_OPEN_SQUARE_BRACKET = '[', // 0x5B
109  NODE_MEMBER = '.', // 0x2E
110  NODE_SEMICOLON = ';', // 0x3B
111  NODE_SUBTRACT = '-', // 0x2D
112 
113  // The following are composed tokens
114  // (operators, keywords, strings, numbers...)
115  NODE_other = 1000,
116 
118  NODE_ARRAY,
120  NODE_AS,
141  NODE_AUTO,
142  NODE_BOOLEAN,
143  NODE_BREAK,
144  NODE_BYTE,
145  NODE_CALL,
146  NODE_CASE,
147  NODE_CATCH,
148  NODE_CHAR,
149  NODE_CLASS,
150  NODE_COMPARE,
151  NODE_CONST,
155  NODE_DEFAULT,
156  NODE_DELETE,
158  NODE_DO,
159  NODE_DOUBLE,
160  NODE_ELSE,
161  NODE_EMPTY,
162  NODE_ENSURE,
163  NODE_ENUM,
164  NODE_EQUAL,
165  NODE_EXCLUDE,
166  NODE_EXTENDS,
167  NODE_EXPORT,
168  NODE_FALSE,
169  NODE_FINAL,
170  NODE_FINALLY,
171  NODE_FLOAT, // "float" keyword
172  NODE_FLOAT64, // a literal float (i.e. 3.14159)
173  NODE_FOR,
175  NODE_GOTO,
178  NODE_IF,
180  NODE_IMPORT,
181  NODE_IN,
182  NODE_INCLUDE,
184  NODE_INLINE,
186  NODE_INT64, // a literal integer (i.e. 123)
189  NODE_IS,
190  NODE_LABEL,
192  NODE_LIST,
196  NODE_LONG,
197  NODE_MATCH,
198  NODE_MAXIMUM,
199  NODE_MINIMUM,
200  NODE_NAME,
202  NODE_NATIVE,
203  NODE_NEW,
206  NODE_NULL,
208  NODE_PACKAGE,
209  NODE_PARAM,
214  NODE_POWER,
215  NODE_PRIVATE,
216  NODE_PROGRAM,
218  NODE_PUBLIC,
219  NODE_RANGE,
221  NODE_REQUIRE,
222  NODE_REST,
223  NODE_RETURN,
224  NODE_ROOT,
227  NODE_SCOPE,
228  NODE_SET,
232  NODE_SHORT,
234  NODE_STATIC,
237  NODE_STRING,
238  NODE_SUPER,
239  NODE_SWITCH,
241  NODE_THEN,
242  NODE_THIS,
243  NODE_THROW,
244  NODE_THROWS,
246  NODE_TRUE,
247  NODE_TRY,
248  NODE_TYPE,
249  NODE_TYPEOF,
251  NODE_USE,
252  NODE_VAR,
256  NODE_VOID,
258  NODE_WHILE,
259  NODE_WITH,
260  NODE_YIELD,
261 
262  NODE_max // mark the limit
263  };
264 
265  // some nodes use flags, all of which are managed in one bitset
266  //
267  // (Note that our Nodes are smart and make use of the function named
268  // verify_flag() to make sure that this specific node can
269  // indeed be given such flag)
270  enum class flag_t
271  {
272  // NODE_CATCH
273  NODE_CATCH_FLAG_TYPED,
274 
275  // NODE_DIRECTIVE_LIST
276  NODE_DIRECTIVE_LIST_FLAG_NEW_VARIABLES,
277 
278  // NODE_ENUM
279  NODE_ENUM_FLAG_CLASS,
280  NODE_ENUM_FLAG_INUSE,
281 
282  // NODE_FOR
283  NODE_FOR_FLAG_CONST,
284  NODE_FOR_FLAG_FOREACH,
285  NODE_FOR_FLAG_IN,
286 
287  // NODE_FUNCTION
288  NODE_FUNCTION_FLAG_GETTER,
289  NODE_FUNCTION_FLAG_SETTER,
290  NODE_FUNCTION_FLAG_OUT,
291  NODE_FUNCTION_FLAG_VOID,
292  NODE_FUNCTION_FLAG_NEVER,
293  NODE_FUNCTION_FLAG_NOPARAMS,
294  NODE_FUNCTION_FLAG_OPERATOR,
295 
296  // NODE_IDENTIFIER, NODE_VIDENTIFIER, NODE_STRING
297  NODE_IDENTIFIER_FLAG_WITH,
298  NODE_IDENTIFIER_FLAG_TYPED,
299 
300  // NODE_IMPORT
301  NODE_IMPORT_FLAG_IMPLEMENTS,
302 
303  // NODE_PACKAGE
304  NODE_PACKAGE_FLAG_FOUND_LABELS,
305  NODE_PACKAGE_FLAG_REFERENCED,
306 
307  // NODE_PARAM
308  NODE_PARAM_FLAG_CONST,
309  NODE_PARAM_FLAG_IN,
310  NODE_PARAM_FLAG_OUT,
311  NODE_PARAM_FLAG_NAMED,
312  NODE_PARAM_FLAG_REST,
313  NODE_PARAM_FLAG_UNCHECKED,
314  NODE_PARAM_FLAG_UNPROTOTYPED,
315  NODE_PARAM_FLAG_REFERENCED, // referenced from a parameter or a variable
316  NODE_PARAM_FLAG_PARAMREF, // referenced from another parameter
317  NODE_PARAM_FLAG_CATCH, // a parameter defined in a catch()
318 
319  // NODE_PARAM_MATCH
320  NODE_PARAM_MATCH_FLAG_UNPROTOTYPED,
321 
322  // NODE_SWITCH
323  NODE_SWITCH_FLAG_DEFAULT, // we found a 'default:' label in that switch
324 
325  // NODE_TYPE
326  NODE_TYPE_FLAG_MODULO, // modulo numeric type declaration
327 
328  // NODE_VARIABLE, NODE_VAR_ATTRIBUTES
329  NODE_VARIABLE_FLAG_CONST,
330  NODE_VARIABLE_FLAG_FINAL,
331  NODE_VARIABLE_FLAG_LOCAL,
332  NODE_VARIABLE_FLAG_MEMBER,
333  NODE_VARIABLE_FLAG_ATTRIBUTES,
334  NODE_VARIABLE_FLAG_ENUM, // there is a NODE_SET and it somehow needs to be copied
335  NODE_VARIABLE_FLAG_COMPILED, // Expression() was called on the NODE_SET
336  NODE_VARIABLE_FLAG_INUSE, // this variable was referenced
337  NODE_VARIABLE_FLAG_ATTRS, // currently being read for attributes (to avoid loops)
338  NODE_VARIABLE_FLAG_DEFINED, // was already parsed
339  NODE_VARIABLE_FLAG_DEFINING, // currently defining, cannot read
340  NODE_VARIABLE_FLAG_TOADD, // to be added in the directive list
341 
342  NODE_FLAG_max
343  };
344 
345  typedef std::bitset<static_cast<size_t>(flag_t::NODE_FLAG_max)> flag_set_t;
346 
347  // some nodes use flags, all of which are managed in one bitset
348  //
349  // (Note that our Nodes are smart and make use of the function named
350  // verify_flag() to make sure that this specific node can
351  // indeed be given such flag)
352  enum class attribute_t
353  {
354  // member visibility
355  NODE_ATTR_PUBLIC,
356  NODE_ATTR_PRIVATE,
357  NODE_ATTR_PROTECTED,
358  NODE_ATTR_INTERNAL,
359  NODE_ATTR_TRANSIENT, // variables only, skip when serializing a class
360  NODE_ATTR_VOLATILE, // variable only
361 
362  // function member type
363  NODE_ATTR_STATIC,
364  NODE_ATTR_ABSTRACT,
365  NODE_ATTR_VIRTUAL,
366  NODE_ATTR_ARRAY,
367  NODE_ATTR_INLINE,
368 
369  // function contract
370  NODE_ATTR_REQUIRE_ELSE,
371  NODE_ATTR_ENSURE_THEN,
372 
373  // function/variable is defined in your system (execution env.)
374  // you won't find a body for these functions; the variables
375  // will likely be read-only
376  NODE_ATTR_NATIVE,
377 
378  // function/variable is still defined, but should not be used
379  // (using generates a "foo deprecated" warning or equivalent)
380  NODE_ATTR_DEPRECATED,
381  NODE_ATTR_UNSAFE, // i.e. eval()
382 
383  // TODO: add a way to mark functions/variables as browser specific
384  // so we can easily tell the user that it should not be used
385  // or with caution (i.e. #ifdef browser-name ...)
386 
387  // operator overload (function member)
388  // Contructor -> another way to construct this type of objects
389  NODE_ATTR_CONSTRUCTOR,
390 
391  // function & member constrains
392  // CONST is not currently available as an attribute (see flags instead)
393  //NODE_ATTR_CONST,
394  NODE_ATTR_FINAL,
395  NODE_ATTR_ENUMERABLE,
396 
397  // conditional compilation
398  NODE_ATTR_TRUE,
399  NODE_ATTR_FALSE,
400  NODE_ATTR_UNUSED, // if definition is used, error!
401 
402  // class attribute (whether a class can be enlarged at run time)
403  NODE_ATTR_DYNAMIC,
404 
405  // switch attributes
406  NODE_ATTR_FOREACH,
407  NODE_ATTR_NOBREAK,
408  NODE_ATTR_AUTOBREAK,
409 
410  // type attribute, to mark all the nodes within a type expression
411  NODE_ATTR_TYPE,
412 
413  // The following is to make sure we never define the attributes more
414  // than once. In itself it is not an attribute.
415  NODE_ATTR_DEFINED,
416 
417  // max used to know the number of entries and define our bitset
418  NODE_ATTR_max
419  };
420 
421  typedef std::bitset<static_cast<int>(attribute_t::NODE_ATTR_max)> attribute_set_t;
422 
423  //enum class link_t : uint32_t
424  //{
425  // LINK_INSTANCE = 0,
426  // LINK_TYPE,
427  // LINK_ATTRIBUTES, // this is the list of identifiers
428  // LINK_GOTO_EXIT,
429  // LINK_GOTO_ENTER,
430  // LINK_max
431  //};
432 
433  enum class compare_mode_t
434  {
435  COMPARE_STRICT, // ===
436  COMPARE_LOOSE, // ==
437  COMPARE_SMART // ~~
438  };
439 
440  Node(node_t type);
441  virtual ~Node() noexcept(false); // virtual because of shared pointers
442 
448  Node(Node const &) = delete;
449 
455  Node & operator = (Node const &) = delete;
456 
457  node_t get_type() const;
458  char const * get_type_name() const;
459  static char const * type_to_string(node_t type);
460  void set_type_node(Node::pointer_t node);
461  pointer_t get_type_node() const;
462 
463  bool is_number() const;
464  bool is_nan() const;
465  bool is_int64() const;
466  bool is_float64() const;
467  bool is_boolean() const;
468  bool is_true() const;
469  bool is_false() const;
470  bool is_string() const;
471  bool is_undefined() const;
472  bool is_null() const;
473  bool is_identifier() const;
474  bool is_literal() const;
475 
476  // basic conversions
477  void to_unknown();
478  bool to_as();
480  bool to_boolean();
481  bool to_call();
482  bool to_identifier();
483  bool to_int64();
484  bool to_float64();
485  bool to_label();
486  bool to_number();
487  bool to_string();
488  void to_videntifier();
489  void to_var_attributes();
490 
491  void set_boolean(bool value);
492  void set_int64(Int64 value);
493  void set_float64(Float64 value);
494  void set_string(String const& value);
495 
496  bool get_boolean() const;
497  Int64 get_int64() const;
498  Float64 get_float64() const;
499  String const& get_string() const;
500 
501  static compare_t compare(Node::pointer_t const lhs, Node::pointer_t const rhs, compare_mode_t const mode);
502 
503  pointer_t clone_basic_node() const;
504  pointer_t create_replacement(node_t type) const;
505 
506  // check flags
507  bool get_flag(flag_t f) const;
508  void set_flag(flag_t f, bool v);
509  bool compare_all_flags(flag_set_t const& s) const;
510 
511  // check attributes
512  void set_attribute_node(pointer_t node);
513  pointer_t get_attribute_node() const;
514  bool get_attribute(attribute_t const a) const;
515  void set_attribute(attribute_t const a, bool const v);
516  void set_attribute_tree(attribute_t const a, bool const v);
517  bool compare_all_attributes(attribute_set_t const& s) const;
518  static char const * attribute_to_string(attribute_t const attr);
519 
520  // various nodes are assigned an "instance" (direct link to actual declaration)
521  void set_instance(pointer_t node);
522  pointer_t get_instance() const;
523 
524  // switch operator: switch(...) with(<operator>)
525  node_t get_switch_operator() const;
526  void set_switch_operator(node_t op);
527 
528  // goto / label
529  void set_goto_enter(pointer_t node);
530  void set_goto_exit(pointer_t node);
531  pointer_t get_goto_enter() const;
532  pointer_t get_goto_exit() const;
533 
534  // handle function parameters (reorder and depth)
535  void set_param_size(size_t size);
536  size_t get_param_size() const;
537  depth_t get_param_depth(size_t j) const;
538  void set_param_depth(size_t j, depth_t depth);
539  size_t get_param_index(size_t idx) const; // returns 'j'
540  void set_param_index(size_t idx, size_t j);
541 
542  void set_position(Position const& position);
543  Position const& get_position() const;
544 
545  bool has_side_effects() const;
546 
547  bool is_locked() const;
548  void lock();
549  void unlock();
550 
551  size_t get_offset() const;
552 
553  void set_parent(pointer_t parent = pointer_t(), int index = -1);
554  pointer_t get_parent() const;
555 
556  size_t get_children_size() const;
557  void replace_with(pointer_t node);
558  void delete_child(int index);
559  void append_child(pointer_t child);
560  void insert_child(int index, pointer_t child);
561  void set_child(int index, pointer_t child);
562  pointer_t get_child(int index) const;
563  pointer_t find_first_child(node_t type) const;
564  pointer_t find_next_child(pointer_t start, node_t type) const;
565  void clean_tree();
566 
567  void add_variable(pointer_t variable);
568  size_t get_variable_size() const;
569  pointer_t get_variable(int index) const;
570 
571  void add_label(pointer_t label);
572  pointer_t find_label(String const& name) const;
573 
574  static char const * operator_to_string(node_t op);
575  static node_t string_to_operator(String const& str);
576 
577  void display(std::ostream& out, int indent, char c) const;
578  //String type_node_to_string() const;
579 
580 private:
581  typedef std::vector<int32_t> param_depth_t;
582  typedef std::vector<uint32_t> param_index_t;
583 
584  // verify different parameters
585  void verify_flag(flag_t f) const;
586  void verify_attribute(attribute_t const f) const;
588  void modifying() const;
589 
590  // output a node to out (on your end, use the << operator)
591  void display_data(std::ostream& out) const;
592 
593  // define the node type
595  weak_pointer_t f_type_node = weak_pointer_t();
600 
601  // whether this node is currently locked
602  int32_t f_lock = 0;
603 
604  // location where the node was found (filename, line #, etc.)
606 
607  // data of this node
611 
612  // function parameters
613  param_depth_t f_param_depth = param_depth_t();
614  param_index_t f_param_index = param_index_t();
615 
616  // parent children node tree handling
617  weak_pointer_t f_parent = weak_pointer_t();
618  int32_t f_offset = 0; // offset (index) in parent array of children -- set by compiler, should probably be removed...
619  vector_of_pointers_t f_children = vector_of_pointers_t();
620  weak_pointer_t f_instance = weak_pointer_t();
621 
622  // goto nodes
623  weak_pointer_t f_goto_enter = weak_pointer_t();
624  weak_pointer_t f_goto_exit = weak_pointer_t();
625 
626  // other connections between nodes
627  vector_of_weak_pointers_t f_variables = vector_of_weak_pointers_t();
628  map_of_weak_pointers_t f_labels = map_of_weak_pointers_t();
629 };
630 
631 #pragma GCC diagnostic pop
632 
633 
634 typedef std::vector<Node::pointer_t> node_pointer_vector_t;
635 
636 std::ostream& operator << (std::ostream& out, Node const& node);
637 
638 
639 
640 // Stack based locking of nodes
641 class NodeLock
642 {
643 public:
645  ~NodeLock();
646 
647  // premature unlock
648  void unlock();
649 
650 private:
652 };
653 
654 
655 }
656 // namespace as2js
657 
658 #endif
659 // #ifndef AS2JS_NODE_H
660 
661 // vim: ts=4 sw=4 et
bool has_side_effects() const
Check whether a node has side effects.
Definition: node_type.cpp:864
void set_goto_enter(pointer_t node)
Define the "Goto Enter" pointer.
Definition: node.cpp:774
void to_videntifier()
Transform an identifier into a NODE_VIDENTIFIER.
pointer_t get_type_node() const
Definition: node_type.cpp:455
pointer_t get_attribute_node() const
void add_label(pointer_t label)
Add a label to a function.
Definition: node.cpp:930
bool to_string()
Transform a node to a string.
static node_t string_to_operator(String const &str)
Transform a string in an operator.
weak_pointer_t f_goto_enter
Definition: node.h:623
void set_param_depth(size_t j, depth_t depth)
Set the depth of a parameter.
Definition: node_param.cpp:166
bool is_null() const
Check whether a node is the special value null.
Definition: node_type.cpp:741
bool is_literal() const
Check whether this node represents a literal.
Definition: node_type.cpp:800
void set_flag(flag_t f, bool v)
Set a flag.
Definition: node_flag.cpp:122
bool is_undefined() const
Check whether a node is the special value undefined.
Definition: node_type.cpp:717
static char const * type_to_string(node_t type)
Convert the specified type to a string.
Definition: node_type.cpp:396
param_index_t f_param_index
Definition: node.h:614
std::vector< weak_pointer_t > vector_of_weak_pointers_t
Definition: node.h:71
bool to_identifier()
Convert this node to a NODE_IDENTIFIER.
void append_child(pointer_t child)
Append a child to &#39;this&#39; node.
Definition: node_tree.cpp:524
depth_t get_param_depth(size_t j) const
Get the depth at the specified index.
Definition: node_param.cpp:140
param_depth_t f_param_depth
Definition: node.h:613
weak_pointer_t f_type_node
Definition: node.h:595
pointer_t get_goto_enter() const
Save a link in this node.
Definition: node.cpp:748
bool is_boolean() const
Check whether a node is a Boolean value.
Definition: node_type.cpp:621
size_t get_param_index(size_t idx) const
Get the index of the parameter.
Definition: node_param.cpp:216
pointer_t get_variable(int index) const
Retrieve the variable at the specified index.
Definition: node.cpp:888
weak_pointer_t f_goto_exit
Definition: node.h:624
bool to_call()
Convert a getter or setter to a function call.
pointer_t get_child(int index) const
Retrieve a child.
Definition: node_tree.cpp:709
node_t f_type
Definition: node.h:594
weak_pointer_t f_instance
Definition: node.h:620
bool to_float64()
Convert this node to a NODE_FLOAT64.
node_t get_switch_operator() const
Retrieve the switch operator.
Definition: node.cpp:369
int32_t f_offset
Definition: node.h:618
pointer_t get_goto_exit() const
Retrieve the "Goto Exit" pointer.
Definition: node.cpp:761
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
ssize_t depth_t
Definition: node.h:74
bool is_float64() const
Check whether a node is a floating point.
Definition: node_type.cpp:596
void set_type_node(Node::pointer_t node)
Definition: node_type.cpp:449
bool is_true() const
Check whether a node represents the true Boolean value.
Definition: node_type.cpp:645
std::vector< Node::pointer_t > node_pointer_vector_t
Definition: node.h:634
Float64 get_float64() const
Get the Float64 of this node.
Definition: node_value.cpp:293
bool to_boolean()
Convert this node to a Boolean node.
std::vector< pointer_t > vector_of_pointers_t
Definition: node.h:70
bool is_nan() const
Check whether this node represents a NaN if converted to a number.
Definition: node_type.cpp:539
bool to_number()
Convert this node to a number.
void set_attribute_node(pointer_t node)
bool to_as()
Transform a call in a NODE_AS node.
void display_data(std::ostream &out) const
Display a node.
String f_str
Definition: node.h:610
void lock()
Lock this node.
Definition: node_lock.cpp:164
void set_int64(Int64 value)
Set the Int64 of this node.
Definition: node_value.cpp:116
bool is_false() const
Check whether a node represents the false Boolean value.
Definition: node_type.cpp:669
void replace_with(pointer_t node)
Replace this node with the node parameter.
Definition: node_tree.cpp:655
size_t get_param_size() const
Return the size of the parameter index and depth vectors.
Definition: node_param.cpp:109
int32_t f_lock
Definition: node.h:602
flag_set_t f_flags
Definition: node.h:596
void set_attribute_tree(attribute_t const a, bool const v)
Set an attribute in a whole tree.
virtual ~Node() noexcept(false)
Verify that a node is clean when deleting it.
Definition: node.cpp:325
void verify_attribute(attribute_t const f) const
Verify that a corresponds to the Node type.
void set_parent(pointer_t parent=pointer_t(), int index=-1)
This function sets the parent of a node.
Definition: node_tree.cpp:160
void modifying() const
Test whether the node can be modified.
Definition: node_lock.cpp:91
bool to_int64()
Convert this node to a NODE_INT64.
static char const * attribute_to_string(attribute_t const attr)
Convert an attribute to a string.
Position const & get_position() const
The position of the node.
Definition: node.cpp:609
attribute_t
Definition: node.h:352
vector_of_pointers_t f_children
Definition: node.h:619
void display(std::ostream &out, int indent, char c) const
Display a node tree.
static compare_t compare(Node::pointer_t const lhs, Node::pointer_t const rhs, compare_mode_t const mode)
Compare two nodes together.
void set_float64(Float64 value)
Set the Float64 of this node.
Definition: node_value.cpp:147
bool verify_exclusive_attributes(attribute_t f) const
Verify that we can indeed set an attribute.
node_t to_boolean_type_only() const
Check whether a node can be converted to Boolean.
std::shared_ptr< Node > pointer_t
Definition: node.h:67
void set_param_size(size_t size)
Define the size of the parameter index and depth vectors.
Definition: node_param.cpp:81
size_t get_children_size() const
Return the number of children available in this node.
Definition: node_tree.cpp:461
bool is_identifier() const
Check whether a node is an identifier.
Definition: node_type.cpp:766
Node & operator=(Node const &)=delete
Do not allow direct copies of nodes.
bool to_label()
Convert this node to a label.
weak_pointer_t f_parent
Definition: node.h:617
void delete_child(int index)
Delete the specified child from the parent.
Definition: node_tree.cpp:495
bool get_boolean() const
Get the Boolean value of this node.
Definition: node_value.cpp:229
attribute_set_t f_attributes
Definition: node.h:598
void set_attribute(attribute_t const a, bool const v)
Set an attribute.
void verify_flag(flag_t f) const
Verify that f corresponds to the node type.
Definition: node_flag.cpp:150
std::bitset< static_cast< int >attribute_t::NODE_ATTR_max)> attribute_set_t
Definition: node.h:421
Node(node_t type)
Initialize a node.
Definition: node.cpp:104
std::ostream & operator<<(std::ostream &out, Node const &node)
Send a node to the specified output stream.
void set_param_index(size_t idx, size_t j)
Set the parameter index.
Definition: node_param.cpp:241
Float64 f_float
Definition: node.h:609
pointer_t get_parent() const
Get a pointer to the parent of this node.
Definition: node_tree.cpp:446
bool is_number() const
Return true if Node represents a number.
Definition: node_type.cpp:507
void unlock()
Unlock a node that was previously locked.
Definition: node_lock.cpp:202
std::bitset< static_cast< size_t >flag_t::NODE_FLAG_max)> flag_set_t
Definition: node.h:345
vector_of_weak_pointers_t f_variables
Definition: node.h:627
static depth_t const MATCH_LOWEST_DEPTH
Definition: node.h:78
map_of_weak_pointers_t f_labels
Definition: node.h:628
Int64 get_int64() const
Get the Int64 of this node.
Definition: node_value.cpp:262
pointer_t clone_basic_node() const
Create a clone of a basic node.
Definition: node.cpp:476
bool is_string() const
Check whether a node is a string.
Definition: node_type.cpp:693
std::map< String, weak_pointer_t > map_of_weak_pointers_t
Definition: node.h:69
bool compare_all_flags(flag_set_t const &s) const
Compare a set of flags with the current flags of this node.
Definition: node_flag.cpp:309
Int64 f_int
Definition: node.h:608
Position f_position
Definition: node.h:605
void set_position(Position const &position)
Change the position of the node.
Definition: node.cpp:587
node_t f_switch_operator
Definition: node.h:599
void insert_child(int index, pointer_t child)
Insert the specified child at the specified location.
Definition: node_tree.cpp:560
pointer_t get_instance() const
Definition: node_tree.cpp:872
The AlexScript to JavaScript namespace.
Definition: compiler.cpp:37
bool is_int64() const
Check whether a node is an integer.
Definition: node_type.cpp:572
void set_switch_operator(node_t op)
Set the switch statement operator.
Definition: node.cpp:421
void to_var_attributes()
Transform a variable into a variable of attributes.
void set_instance(pointer_t node)
Definition: node_tree.cpp:866
pointer_t f_attribute_node
Definition: node.h:597
void set_child(int index, pointer_t child)
Replace the current child at position index with child.
Definition: node_tree.cpp:594
bool get_attribute(attribute_t const a) const
Get the current status of an attribute.
size_t get_variable_size() const
Retrieve the number of variables defined in this node.
Definition: node.cpp:855
std::vector< int32_t > param_depth_t
Definition: node.h:581
void add_variable(pointer_t variable)
Add a variable to this node.
Definition: node.cpp:827
node_t get_type() const
Retrieve the type of the node.
Definition: node_type.cpp:367
std::weak_ptr< Node > weak_pointer_t
Definition: node.h:68
static char const * operator_to_string(node_t op)
Transform an operator to a string.
static depth_t const MATCH_HIGHEST_DEPTH
Definition: node.h:77
size_t get_offset() const
Find the offset of this node in its parent array of children.
Definition: node_tree.cpp:844
void to_unknown()
Transform any node to NODE_UNKNOWN.
compare_t
Definition: compare.h:41
pointer_t find_label(String const &name) const
Find a label previously added with the add_label() function.
Definition: node.cpp:964
compare_mode_t
Definition: node.h:433
bool is_locked() const
Check whether a node is locked.
Definition: node_lock.cpp:114
pointer_t find_first_child(node_t type) const
Find the first child of a given type.
Definition: node_tree.cpp:735
bool compare_all_attributes(attribute_set_t const &s) const
Compare a set of attributes with the current attributes of this node.
pointer_t create_replacement(node_t type) const
Create a new node with the given type.
Definition: node.cpp:554
bool get_flag(flag_t f) const
Get the current status of a flag.
Definition: node_flag.cpp:101
static depth_t const MATCH_NOT_FOUND
Definition: node.h:76
std::vector< uint32_t > param_index_t
Definition: node.h:582
pointer_t find_next_child(pointer_t start, node_t type) const
Find the next child with the specified type.
Definition: node_tree.cpp:766
void set_goto_exit(pointer_t node)
Define the "Goto Exit" pointer.
Definition: node.cpp:787
void clean_tree()
Remove all the unknown nodes.
Definition: node_tree.cpp:804
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