as2js: as2js::Compiler Class Reference

#include <compiler.h>

Classes class  RestoreFlags   Public Types typedef std::shared_ptr< Compilerpointer_t   Public Member Functions  Compiler (Options::pointer_t options)  Initialize the compiler object. More...
  virtual ~Compiler ()   int compile (Node::pointer_t &root)  "Compile" the code, which means optimize and make compatible. More...
  InputRetriever::pointer_t set_input_retriever (InputRetriever::pointer_t retriever)   Private Types typedef std::map< String, Node::pointer_tmodule_map_t   typedef uint32_t search_error_t   typedef uint32_t search_flag_t   Private Member Functions void add_variable (Node::pointer_t variable)   bool are_objects_derived_from_one_another (Node::pointer_t derived_class, Node::pointer_t super_class, Node::pointer_t &the_super_class)  Check whether derived_class is extending super_class. More...
  void assignment_operator (Node::pointer_t expr)   bool best_param_match (Node::pointer_t &best, Node::pointer_t match)   bool best_param_match_derived_from (Node::pointer_t &best, Node::pointer_t match)   void binary_operator (Node::pointer_t &expr)   void break_continue (Node::pointer_t &break_node)   void call_add_missing_params (Node::pointer_t call, Node::pointer_t params)   void can_instantiate_type (Node::pointer_t expr)   void case_directive (Node::pointer_t &case_node)   void catch_directive (Node::pointer_t &catch_node)   bool check_field (Node::pointer_t link, Node::pointer_t field, int &funcs, Node::pointer_t &resolution, Node::pointer_t params, int const search_flags)   bool check_final_functions (Node::pointer_t &function_node, Node::pointer_t &class_node)  Check whether that function was not marked as final before. More...
  bool check_function (Node::pointer_t function_node, Node::pointer_t &resolution, String const &name, Node::pointer_t params, int const search_flags)   int check_function_with_params (Node::pointer_t function_node, Node::pointer_t params)   bool check_import (Node::pointer_t &child, Node::pointer_t &resolution, String const &name, Node::pointer_t params, int const search_flags)   void check_member (Node::pointer_t ref, Node::pointer_t field, Node::pointer_t field_name)   bool check_name (Node::pointer_t list, int idx, Node::pointer_t &resolution, Node::pointer_t id, Node::pointer_t params, int const search_flags)   void check_super_validity (Node::pointer_t expr)   void check_this_validity (Node::pointer_t expr)   bool check_unique_functions (Node::pointer_t function_node, Node::pointer_t class_node, bool const all_levels)   void class_directive (Node::pointer_t &class_node)   Node::pointer_t class_of_member (Node::pointer_t parent)  Search for a class or interface node. More...
  bool compare_parameters (Node::pointer_t &lfunction, Node::pointer_t &rfunction)  Compare prototypes of two functions. More...
  void declare_class (Node::pointer_t class_node)   void default_directive (Node::pointer_t &default_node)   bool define_function_type (Node::pointer_t func)   void directive (Node::pointer_t &directive)   Node::pointer_t directive_list (Node::pointer_t directive_list)   void do_directive (Node::pointer_t &do_node)   void enum_directive (Node::pointer_t &enum_node)  Enum directive. More...
  void expression (Node::pointer_t expr, Node::pointer_t params=Node::pointer_t())   bool expression_new (Node::pointer_t expr)   void extend_class (Node::pointer_t class_node, bool const extend, Node::pointer_t extend_name)   void finally (Node::pointer_t &finally_node)   bool find_any_field (Node::pointer_t link, Node::pointer_t field, int &funcs, Node::pointer_t &resolution, Node::pointer_t params, int const search_flags)   Node::depth_t find_class (Node::pointer_t class_type, Node::pointer_t type, Node::depth_t depth)   bool find_external_package (Node::pointer_t import, String const &name, Node::pointer_t &program_node)   bool find_field (Node::pointer_t link, Node::pointer_t field, int &funcs, Node::pointer_t &resolution, Node::pointer_t params, int const search_flags)   bool find_final_functions (Node::pointer_t &function, Node::pointer_t &super)  Check whether that function was not marked as final before. More...
  bool find_in_extends (Node::pointer_t link, Node::pointer_t field, int &funcs, Node::pointer_t &resolution, Node::pointer_t params, int const search_flags)   void find_labels (Node::pointer_t function, Node::pointer_t node)   bool find_member (Node::pointer_t member, Node::pointer_t &resolution, Node::pointer_t params, int search_flags)   bool find_module (String const &filename, Node::pointer_t &result)  Find a module, load it if necessary. More...
  bool find_overloaded_function (Node::pointer_t class_node, Node::pointer_t function)   Node::pointer_t find_package (Node::pointer_t list, String const &name)   bool find_package_item (Node::pointer_t program, Node::pointer_t import, Node::pointer_t &resolution, String const &name, Node::pointer_t params, int const search_flags)   void find_packages (Node::pointer_t program)   void find_packages_add_database_entry (String const &package_name, Node::pointer_t &element, char const *type)   void find_packages_directive_list (Node::pointer_t list)   void find_packages_save_package_elements (Node::pointer_t package, String const &package_name)   void for_directive (Node::pointer_t &for_node)   bool funcs_name (int &funcs, Node::pointer_t resolution, bool const increment=true)   void function (Node::pointer_t function_node)   bool get_attribute (Node::pointer_t node, Node::attribute_t const a)   unsigned long get_attributes (Node::pointer_t &node)   search_error_t get_err_flags () const   String get_package_filename (char const *package_info)  Get the filename of a package. More...
  void goto_directive (Node::pointer_t &goto_node)  Compile the goto directive. More...
  bool has_abstract_functions (Node::pointer_t class_node, Node::pointer_t list, Node::pointer_t &func)   void identifier_to_attrs (Node::pointer_t node, Node::pointer_t a)   void if_directive (Node::pointer_t &if_node)   void import (Node::pointer_t &import)   void internal_imports ()   bool is_constructor (Node::pointer_t func, Node::pointer_t &the_class)  Check whether a function is a constructor. More...
  bool is_derived_from (Node::pointer_t derived_class, Node::pointer_t super_class)   bool is_dynamic_class (Node::pointer_t class_node)   bool is_function_abstract (Node::pointer_t function)   bool is_function_overloaded (Node::pointer_t class_node, Node::pointer_t function)   void link_type (Node::pointer_t type)   void load_internal_packages (char const *module)   Node::pointer_t load_module (char const *module, char const *file)  Load a module as specified by module and file. More...
  Node::depth_t match_type (Node::pointer_t t1, Node::pointer_t t2)  Check wether type t1 matches type t2. More...
  void node_to_attrs (Node::pointer_t node, Node::pointer_t a)   void object_literal (Node::pointer_t expr)   void parameters (Node::pointer_t parameters_node)   void prepare_attributes (Node::pointer_t node)   void print_search_errors (const Node::pointer_t name)   void program (Node::pointer_t program_node)   void read_db ()   bool replace_constant_variable (Node::pointer_t &replace, Node::pointer_t resolution)   bool resolve_call (Node::pointer_t call)   bool resolve_field (Node::pointer_t object, Node::pointer_t field, Node::pointer_t &resolution, Node::pointer_t params, int const search_flags)   void resolve_internal_type (Node::pointer_t parent, char const *type, Node::pointer_t &resolution)   void resolve_member (Node::pointer_t expr, Node::pointer_t params, int const search_flags)   bool resolve_name (Node::pointer_t list, Node::pointer_t id, Node::pointer_t &resolution, Node::pointer_t params, int const search_flags)   Node::pointer_t return_directive (Node::pointer_t return_node)   bool select_best_func (Node::pointer_t params, Node::pointer_t &resolution)  One or more function was found, select the best one. More...
  void set_err_flags (search_error_t flags)   bool special_identifier (Node::pointer_t expr)   void switch_directive (Node::pointer_t &switch_node)   void throw_directive (Node::pointer_t &throw_node)   void try_directive (Node::pointer_t &try_node)   void type_expr (Node::pointer_t expr)   void unary_operator (Node::pointer_t expr)   void use_namespace (Node::pointer_t &use_namespace_node)   void var (Node::pointer_t var_node)   void variable (Node::pointer_t variable_node, bool side_effects_only)   void variable_to_attrs (Node::pointer_t node, Node::pointer_t var)   void while_directive (Node::pointer_t &while_node)   void with (Node::pointer_t &with_node)   void write_db ()   Private Attributes search_error_t f_err_flags = 0   InputRetriever::pointer_t f_input_retriever = InputRetriever::pointer_t()   module_map_t f_modules = module_map_t()   Options::pointer_t f_options = Options::pointer_t()   Node::pointer_t f_program = Node::pointer_t()   Node::pointer_t f_scope = Node::pointer_t()   time_t f_time = 0   Static Private Attributes static search_error_t const SEARCH_ERROR_EXPECTED_STATIC_MEMBER = 0x00000040   static search_error_t const SEARCH_ERROR_NONE = 0x00000000   static search_error_t const SEARCH_ERROR_PRIVATE = 0x00000001   static search_error_t const SEARCH_ERROR_PRIVATE_PACKAGE = 0x00000020   static search_error_t const SEARCH_ERROR_PROTECTED = 0x00000002   static search_error_t const SEARCH_ERROR_PROTOTYPE = 0x00000004   static search_error_t const SEARCH_ERROR_WRONG_PRIVATE = 0x00000008   static search_error_t const SEARCH_ERROR_WRONG_PROTECTED = 0x00000010   static search_flag_t const SEARCH_FLAG_GETTER = 0x00000002   static search_flag_t const SEARCH_FLAG_NO_PARSING = 0x00000001   static search_flag_t const SEARCH_FLAG_PACKAGE_MUST_EXIST = 0x00000008   static search_flag_t const SEARCH_FLAG_SETTER = 0x00000004   Detailed Description

Definition at line 64 of file compiler.h.

Member Typedef Documentation

Definition at line 93 of file compiler.h.

typedef std::shared_ptr<Compiler> as2js::Compiler::pointer_t

Definition at line 67 of file compiler.h.

typedef uint32_t as2js::Compiler::search_error_t private

Definition at line 76 of file compiler.h.

typedef uint32_t as2js::Compiler::search_flag_t private

Definition at line 77 of file compiler.h.

Constructor & Destructor Documentation
as2js::Compiler::Compiler ( Options::pointer_t  options)

The compiler includes many sub-classes that it initializes here. Especially, it calls the internal_imports() function to load all the internal modules, database, resource file.

The options parameter represents the command line options setup by a user and within the code with the 'use' keyword (i.e. pragmas).

Parameters
[in]optionsThe options object to use while compiling.

Definition at line 57 of file compiler.cpp.

References internal_imports().

as2js::Compiler::~Compiler ( ) virtual

Definition at line 71 of file compiler.cpp.

Member Function Documentation
bool as2js::Compiler::are_objects_derived_from_one_another ( Node::pointer_t  derived_class, Node::pointer_t  super_class, Node::pointer_tthe_super_class  ) private

This function checks whether the object defined as derived_class has an extends or implements one that includes super_class.

The the_super_class parameter is set to the class of the super_class object. This can be used to determine different types of errors.

Note that if derived_class or super_class are not objects defined in a class, then the function always returns false.

Parameters
[in]derived_classThe class which is checked to know whether it derives from super_class. [in]super_classThe class that is expected to be in the extends or implements lists. [out]the_super_classThe actual class object in which super_class is defined.
Returns
true if derived_class is derived from super_class.

Definition at line 1130 of file compiler_class.cpp.

References class_of_member(), and is_derived_from().

Referenced by best_param_match_derived_from(), and check_name().

bool as2js::Compiler::best_param_match ( Node::pointer_tbest, Node::pointer_t  match  ) private

Definition at line 959 of file compiler_function.cpp.

References best_param_match_derived_from().

Referenced by select_best_func().

bool as2js::Compiler::best_param_match_derived_from ( Node::pointer_tbest, Node::pointer_t  match  ) private
void as2js::Compiler::call_add_missing_params ( Node::pointer_t  call, Node::pointer_t  params  ) private
bool as2js::Compiler::check_field ( Node::pointer_t  link, Node::pointer_t  field, int &  funcs, Node::pointer_tresolution, Node::pointer_t  params, int const  search_flags  ) private
bool as2js::Compiler::check_final_functions ( Node::pointer_tfunction_node, Node::pointer_tclass_node  ) private

This function searches the children of the class node for extends. If it has one or more extends, then it verifies that the super definition does not mark the function as final, if such is found, we may have an error.

Note
Since we do not limit the number of 'extends' used with a class, we check all the children to make sure we check all the possible extensions.
Parameters
[in]function_nodeThe function to check. [in]class_nodeThe class the function is defined in.
Returns
true if the function is marked as final in a super definition.

Definition at line 1475 of file compiler_function.cpp.

References find_final_functions(), and as2js::Node::NODE_EXTENDS.

Referenced by function().

bool as2js::Compiler::check_import ( Node::pointer_tchild, Node::pointer_tresolution, String const &  name, Node::pointer_t  params, int const  search_flags  ) private
bool as2js::Compiler::check_unique_functions ( Node::pointer_t  function_node, Node::pointer_t  class_node, bool const  all_levels  ) private
Node::pointer_t as2js::Compiler::class_of_member ( Node::pointer_t  class_node) private

This function searches for a node of type NODE_CLASS or NODE_INTERFACE starting with class_node. The search checks class_node and all of its parents.

The search stops prematuraly if a NODE_PACKAGE, NODE_PROGRAM, or NODE_ROOT is found first.

Parameters
[in]class_nodeThe object from which a class is to be searched.
Returns
The class or interface, or a null pointer if not found.

Definition at line 1085 of file compiler_class.cpp.

References as2js::Node::NODE_CLASS, as2js::Node::NODE_INTERFACE, as2js::Node::NODE_PACKAGE, as2js::Node::NODE_PROGRAM, and as2js::Node::NODE_ROOT.

Referenced by are_objects_derived_from_one_another(), check_name(), find_member(), is_function_overloaded(), and resolve_call().

bool as2js::Compiler::compare_parameters ( Node::pointer_tlfunction, Node::pointer_trfunction  ) private

This function goes through the list of prototypes of the left handed function and the right handed function and determines whether the prototypes do match.

Prototypes never match if the count is different (one function has no parameters and the other has three, for example.)

Parameters
[in,out]lfunctionLeft handed function to compare. [in,out]rfunctionRight handed function to compare.
Returns
true if the two functions prototypes are one to one equivalent.

Definition at line 1514 of file compiler_function.cpp.

References as2js::Node::NODE_PARAMETERS, and as2js::Node::NODE_TYPE.

Referenced by check_unique_functions(), and find_overloaded_function().

int as2js::Compiler::compile ( Node::pointer_troot)

The following functions "compile" the code:

  • It will optimize everything it can by reducing expressions that can be computed at "compile" time;
  • It transforms advanced features of as2js such as classes into JavaScript compatible code such as prototypes.

On other words, it means that the compiler (1) tries to resolve all the references that are found in the current tree; (2) loads the libraries referenced by the different import instructions which are necessary (or at least seem to be); (3) and run the optimizer against the code at various times.

The compiler calls the optimizer for you because it is important in various places and the optimizations applied will vary depending on the compiler changes and further changes may be applied after the optimizations. So on return the tree is expected to be 100% compatible with a JavaScript all browser interpreters and optimized as much as possible to be output as minimized as can be.

Parameters
[in,out]rootThe root node or program to compile.
Returns
The number of errors generated while compiling. If zero, no errors so you can proceed with the tree.

Definition at line 77 of file compiler_compile.cpp.

References as2js::AS_ERR_INTERNAL_ERROR, as2js::Message::error_count(), f_scope, as2js::MESSAGE_LEVEL_ERROR, as2js::Node::NODE_PROGRAM, as2js::Node::NODE_ROOT, as2js::Node::NODE_SCOPE, and program().

void as2js::Compiler::default_directive ( Node::pointer_tdefault_node) private
void as2js::Compiler::directive ( Node::pointer_tdirective) private
Node::pointer_t as2js::Compiler::directive_list ( Node::pointer_t  directive_list) private

Definition at line 44 of file compiler_directive.cpp.

References as2js::AS_ERR_INACCESSIBLE_STATEMENT, as2js::AS_ERR_INTERNAL_ERROR, break_continue(), case_directive(), catch_directive(), class_directive(), default_directive(), do_directive(), enum_directive(), expression(), f_scope, for_directive(), get_attribute(), goto_directive(), if_directive(), as2js::MESSAGE_LEVEL_ERROR, as2js::Node::NODE_ASSIGNMENT, as2js::Node::NODE_ASSIGNMENT_ADD, as2js::Node::NODE_ASSIGNMENT_BITWISE_AND, as2js::Node::NODE_ASSIGNMENT_BITWISE_OR, as2js::Node::NODE_ASSIGNMENT_BITWISE_XOR, as2js::Node::NODE_ASSIGNMENT_DIVIDE, as2js::Node::NODE_ASSIGNMENT_LOGICAL_AND, as2js::Node::NODE_ASSIGNMENT_LOGICAL_OR, as2js::Node::NODE_ASSIGNMENT_LOGICAL_XOR, as2js::Node::NODE_ASSIGNMENT_MAXIMUM, as2js::Node::NODE_ASSIGNMENT_MINIMUM, as2js::Node::NODE_ASSIGNMENT_MODULO, as2js::Node::NODE_ASSIGNMENT_MULTIPLY, as2js::Node::NODE_ASSIGNMENT_POWER, as2js::Node::NODE_ASSIGNMENT_ROTATE_LEFT, as2js::Node::NODE_ASSIGNMENT_ROTATE_RIGHT, as2js::Node::NODE_ASSIGNMENT_SHIFT_LEFT, as2js::Node::NODE_ASSIGNMENT_SHIFT_RIGHT, as2js::Node::NODE_ASSIGNMENT_SHIFT_RIGHT_UNSIGNED, as2js::Node::NODE_ASSIGNMENT_SUBTRACT, as2js::Node::NODE_ATTR_FALSE, as2js::Node::NODE_BREAK, as2js::Node::NODE_CALL, as2js::Node::NODE_CASE, as2js::Node::NODE_CATCH, as2js::Node::NODE_CLASS, as2js::Node::NODE_CONTINUE, as2js::Node::NODE_DECREMENT, as2js::Node::NODE_DEFAULT, as2js::Node::NODE_DELETE, as2js::Node::NODE_DIRECTIVE_LIST, as2js::Node::NODE_DIRECTIVE_LIST_FLAG_NEW_VARIABLES, as2js::Node::NODE_DO, as2js::Node::NODE_ENUM, as2js::Node::NODE_FINALLY, as2js::Node::NODE_FOR, as2js::Node::NODE_FUNCTION, as2js::Node::NODE_GOTO, as2js::Node::NODE_IF, as2js::Node::NODE_IMPORT, as2js::Node::NODE_INCREMENT, as2js::Node::NODE_INTERFACE, as2js::Node::NODE_LABEL, as2js::Node::NODE_MEMBER, as2js::Node::NODE_NEW, as2js::Node::NODE_PACKAGE, as2js::Node::NODE_POST_DECREMENT, as2js::Node::NODE_POST_INCREMENT, as2js::Node::NODE_RETURN, as2js::Node::NODE_SWITCH, as2js::Node::NODE_THROW, as2js::Node::NODE_TRY, as2js::Node::NODE_UNKNOWN, as2js::Node::NODE_USE, as2js::Node::NODE_VAR, as2js::Node::NODE_VARIABLE_FLAG_TOADD, as2js::Node::NODE_WHILE, as2js::Node::NODE_WITH, return_directive(), switch_directive(), throw_directive(), try_directive(), use_namespace(), var(), while_directive(), and with().

Referenced by catch_directive(), check_name(), do_directive(), finally(), find_package_item(), for_directive(), function(), if_directive(), import(), program(), switch_directive(), try_directive(), while_directive(), and with().

void as2js::Compiler::do_directive ( Node::pointer_tdo_node) private

Definition at line 392 of file compiler_statement.cpp.

References directive_list(), and expression().

Referenced by directive_list().

void as2js::Compiler::enum_directive ( Node::pointer_tenum_node) private

Enumerations are like classes defining a list of constant values.

Parameters
[in]enum_nodeThe enumeration node to work on.

Definition at line 1293 of file compiler_class.cpp.

References expression(), and as2js::Node::NODE_SET.

Referenced by declare_class(), and directive_list().

void as2js::Compiler::expression ( Node::pointer_t  expr, Node::pointer_t  params = Node::pointer_t()  ) private

Definition at line 1300 of file compiler_expression.cpp.

References as2js::AS_ERR_INTERNAL_ERROR, as2js::AS_ERR_NOT_FOUND, assignment_operator(), binary_operator(), can_instantiate_type(), check_super_validity(), check_this_validity(), expression_new(), as2js::MESSAGE_LEVEL_ERROR, as2js::Node::NODE_ADD, as2js::Node::NODE_ARRAY, as2js::Node::NODE_ARRAY_LITERAL, as2js::Node::NODE_AS, as2js::Node::NODE_ASSIGNMENT, as2js::Node::NODE_ASSIGNMENT_ADD, as2js::Node::NODE_ASSIGNMENT_BITWISE_AND, as2js::Node::NODE_ASSIGNMENT_BITWISE_OR, as2js::Node::NODE_ASSIGNMENT_BITWISE_XOR, as2js::Node::NODE_ASSIGNMENT_DIVIDE, as2js::Node::NODE_ASSIGNMENT_LOGICAL_AND, as2js::Node::NODE_ASSIGNMENT_LOGICAL_OR, as2js::Node::NODE_ASSIGNMENT_LOGICAL_XOR, as2js::Node::NODE_ASSIGNMENT_MAXIMUM, as2js::Node::NODE_ASSIGNMENT_MINIMUM, as2js::Node::NODE_ASSIGNMENT_MODULO, as2js::Node::NODE_ASSIGNMENT_MULTIPLY, as2js::Node::NODE_ASSIGNMENT_POWER, as2js::Node::NODE_ASSIGNMENT_ROTATE_LEFT, as2js::Node::NODE_ASSIGNMENT_ROTATE_RIGHT, as2js::Node::NODE_ASSIGNMENT_SHIFT_LEFT, as2js::Node::NODE_ASSIGNMENT_SHIFT_RIGHT, as2js::Node::NODE_ASSIGNMENT_SHIFT_RIGHT_UNSIGNED, as2js::Node::NODE_ASSIGNMENT_SUBTRACT, as2js::Node::NODE_BITWISE_AND, as2js::Node::NODE_BITWISE_NOT, as2js::Node::NODE_BITWISE_OR, as2js::Node::NODE_BITWISE_XOR, as2js::Node::NODE_CALL, as2js::Node::NODE_CONDITIONAL, as2js::Node::NODE_DECREMENT, as2js::Node::NODE_DELETE, as2js::Node::NODE_DIVIDE, as2js::Node::NODE_EQUAL, as2js::Node::NODE_FALSE, as2js::Node::NODE_FLOAT64, as2js::Node::NODE_FUNCTION, as2js::Node::NODE_GREATER, as2js::Node::NODE_GREATER_EQUAL, as2js::Node::NODE_IDENTIFIER, as2js::Node::NODE_IN, as2js::Node::NODE_INCREMENT, as2js::Node::NODE_INSTANCEOF, as2js::Node::NODE_INT64, as2js::Node::NODE_IS, as2js::Node::NODE_LESS, as2js::Node::NODE_LESS_EQUAL, as2js::Node::NODE_LIST, as2js::Node::NODE_LOGICAL_AND, as2js::Node::NODE_LOGICAL_NOT, as2js::Node::NODE_LOGICAL_OR, as2js::Node::NODE_LOGICAL_XOR, as2js::Node::NODE_MATCH, as2js::Node::NODE_MAXIMUM, as2js::Node::NODE_MEMBER, as2js::Node::NODE_MINIMUM, as2js::Node::NODE_MODULO, as2js::Node::NODE_MULTIPLY, as2js::Node::NODE_NAME, as2js::Node::NODE_NEW, as2js::Node::NODE_NOT_EQUAL, as2js::Node::NODE_NULL, as2js::Node::NODE_OBJECT_LITERAL, as2js::Node::NODE_POST_DECREMENT, as2js::Node::NODE_POST_INCREMENT, as2js::Node::NODE_POWER, as2js::Node::NODE_PRIVATE, as2js::Node::NODE_PUBLIC, as2js::Node::NODE_RANGE, as2js::Node::NODE_ROTATE_LEFT, as2js::Node::NODE_ROTATE_RIGHT, as2js::Node::NODE_SCOPE, as2js::Node::NODE_SHIFT_LEFT, as2js::Node::NODE_SHIFT_RIGHT, as2js::Node::NODE_SHIFT_RIGHT_UNSIGNED, as2js::Node::NODE_STRICTLY_EQUAL, as2js::Node::NODE_STRICTLY_NOT_EQUAL, as2js::Node::NODE_STRING, as2js::Node::NODE_SUBTRACT, as2js::Node::NODE_SUPER, as2js::Node::NODE_THIS, as2js::Node::NODE_TRUE, as2js::Node::NODE_TYPEOF, as2js::Node::NODE_UNDEFINED, as2js::Node::NODE_VIDENTIFIER, as2js::Node::NODE_VOID, object_literal(), as2js::Optimizer::optimize(), replace_constant_variable(), resolve_call(), resolve_member(), resolve_name(), SEARCH_FLAG_GETTER, special_identifier(), type_expr(), and unary_operator().

Referenced by assignment_operator(), case_directive(), define_function_type(), directive_list(), do_directive(), enum_directive(), expression_new(), extend_class(), find_class(), find_member(), for_directive(), function(), if_directive(), object_literal(), parameters(), resolve_call(), return_directive(), switch_directive(), throw_directive(), use_namespace(), variable(), variable_to_attrs(), while_directive(), and with().

bool as2js::Compiler::expression_new ( Node::pointer_t  expr) private
void as2js::Compiler::extend_class ( Node::pointer_t  class_node, bool const  extend, Node::pointer_t  extend_name  ) private
void as2js::Compiler::finally ( Node::pointer_tfinally_node) private
bool as2js::Compiler::find_any_field ( Node::pointer_t  link, Node::pointer_t  field, int &  funcs, Node::pointer_tresolution, Node::pointer_t  params, int const  search_flags  ) private

Definition at line 542 of file compiler_class.cpp.

References check_field(), and find_in_extends().

Referenced by find_field(), and find_in_extends().

bool as2js::Compiler::find_external_package ( Node::pointer_t  import, String const &  name, Node::pointer_tprogram_node  ) private
bool as2js::Compiler::find_field ( Node::pointer_t  link, Node::pointer_t  field, int &  funcs, Node::pointer_tresolution, Node::pointer_t  params, int const  search_flags  ) private
bool as2js::Compiler::find_final_functions ( Node::pointer_tfunction_node, Node::pointer_tsuper  ) private
Returns
true if the function is marked as final in a super definition.

Definition at line 1405 of file compiler_function.cpp.

References get_attribute(), as2js::Node::NODE_ATTR_FINAL, as2js::Node::NODE_DIRECTIVE_LIST, as2js::Node::NODE_EXTENDS, and as2js::Node::NODE_FUNCTION.

Referenced by check_final_functions().

bool as2js::Compiler::find_in_extends ( Node::pointer_t  link, Node::pointer_t  field, int &  funcs, Node::pointer_tresolution, Node::pointer_t  params, int const  search_flags  ) private
bool as2js::Compiler::find_module ( String const &  filename, Node::pointer_tresult  ) private

If the module was already loaded, return a pointer to the existing tree of nodes.

If the module was not yet loaded, try to load it. If the file cannot be found or the file cannot be compiled, a fatal error is emitted and the process stops.

Note
At this point this function either returns true because it found the named module, or it throws exception_exit. So the result parameter is always set on a normal return.
Parameters
[in]filenameThe name of the module to be loaded [in,out]resultThe shared pointer to the resulting root node.
Returns
true if the module was found.

Definition at line 186 of file compiler_package.cpp.

References as2js::AS_ERR_CANNOT_COMPILE, as2js::AS_ERR_NOT_FOUND, f_input_retriever, f_modules, f_options, and as2js::MESSAGE_LEVEL_FATAL.

Referenced by find_external_package(), and load_module().

Node::pointer_t as2js::Compiler::find_package ( Node::pointer_t  list, String const &  name  ) private

Definition at line 499 of file compiler_package.cpp.

References as2js::Node::NODE_DIRECTIVE_LIST, and as2js::Node::NODE_PACKAGE.

Referenced by find_package_item().

void as2js::Compiler::find_packages ( Node::pointer_t  program) private
void as2js::Compiler::find_packages_add_database_entry ( String const &  package_name, Node::pointer_telement, char const *  type  ) private
void as2js::Compiler::find_packages_directive_list ( Node::pointer_t  list) private
void as2js::Compiler::for_directive ( Node::pointer_tfor_node) private
bool as2js::Compiler::funcs_name ( int &  funcs, Node::pointer_t  resolution, bool const  increment = true  ) private
unsigned long as2js::Compiler::get_attributes ( Node::pointer_tnode) private
String as2js::Compiler::get_package_filename ( char const *  package_info) private

Definition at line 135 of file compiler_package.cpp.

References as2js::String::from_utf8().

void as2js::Compiler::goto_directive ( Node::pointer_tgoto_node) private

Note that JavaScript in browsers do not support the goto instruction. They have a similar behavior when using while() loop and either a continue (goto at the start) or the break (goto after the while() loop.).

This function is kept here, although we are very unlikely to implement the instruction in your browser, it may end up being useful in case we again work on ActionScript.

Parameters
[in]goto_nodeThe node representing the goto statement.

Definition at line 104 of file compiler_statement.cpp.

References as2js::AS_ERR_IMPROPER_STATEMENT, as2js::AS_ERR_INTERNAL_ERROR, as2js::AS_ERR_LABEL_NOT_FOUND, as2js::MESSAGE_LEVEL_ERROR, as2js::MESSAGE_LEVEL_FATAL, as2js::Node::NODE_CLASS, as2js::Node::NODE_FUNCTION, as2js::Node::NODE_INTERFACE, as2js::Node::NODE_PACKAGE, and as2js::Node::NODE_PROGRAM.

Referenced by directive_list(), and get_err_flags().

void as2js::Compiler::if_directive ( Node::pointer_tif_node) private

Definition at line 352 of file compiler_statement.cpp.

References directive_list(), and expression().

Referenced by directive_list(), and get_err_flags().

bool as2js::Compiler::is_constructor ( Node::pointer_t  function_node, Node::pointer_tthe_class  ) private

This function checks a node representing a function to determine whether it represents a constructor or not.

By default, if a function is marked as a constructor by the programmer, then this function considers the function as a constructor no matter what (outside of the fact that it has to be a function defined in a class, obviously.)

Parameters
[in]function_nodeA node representing a function definition. [out]the_classIf the function is a constructor, this is the class it was defined in.
Returns
true if the function is a constructor and in that case the_class is set to the class node pointer; otherwise the_class is set to nullptr.

Definition at line 179 of file compiler_class.cpp.

References as2js::AS_ERR_INVALID_ATTRIBUTES, get_attribute(), as2js::MESSAGE_LEVEL_ERROR, as2js::Node::NODE_ATTR_CONSTRUCTOR, as2js::Node::NODE_CLASS, as2js::Node::NODE_FUNCTION, as2js::Node::NODE_INTERFACE, as2js::Node::NODE_PACKAGE, and as2js::Node::NODE_PROGRAM.

Referenced by check_function(), check_name(), check_super_validity(), check_this_validity(), define_function_type(), function(), get_err_flags(), and return_directive().

bool as2js::Compiler::is_derived_from ( Node::pointer_t  derived_class, Node::pointer_t  super_class  ) private
bool as2js::Compiler::is_dynamic_class ( Node::pointer_t  class_node) private
bool as2js::Compiler::is_function_abstract ( Node::pointer_t  function) private

Definition at line 119 of file compiler_expression.cpp.

References as2js::Node::NODE_DIRECTIVE_LIST.

Referenced by get_err_flags(), and has_abstract_functions().

bool as2js::Compiler::is_function_overloaded ( Node::pointer_t  class_node, Node::pointer_t  function  ) private
Node::pointer_t as2js::Compiler::load_module ( char const *  module, char const *  file  ) private

This function loads the specified module. The filename is defined as the path found in the .rc file, followed by the module name, followed by the file name:

<rc.path>/<module>/<file>

The function always returns a pointer. If the module cannot be loaded, an error is generated and the compiler exists with a fatal error.

Parameters
[in]moduleThe name of the module to be loaded. [in]fileThe name of the file to load from that module.
Returns
The pointer to the module loaded.

Definition at line 258 of file compiler_package.cpp.

References find_module(), as2js::anonymous_namespace{compiler_package.cpp}::g_rc, and as2js::rc_t::get_scripts().

Referenced by internal_imports(), and load_internal_packages().

Node::depth_t as2js::Compiler::match_type ( Node::pointer_t  t1, Node::pointer_t  t2  ) private

This function checks whether the type defined as t1 matches the type defined as t2.

t1 or t2 may be a null pointer, in which case it never matches.

If t1 is not directly equal to t2, then all t1's ancestors are checked too. The ancestors are found as extends or implements of the t1 class.

It is expected that t2 will be a NODE_PARAM in which case we accept an empty node or a node without a type definition as a 'match any' special type.

Otherwise we make sure we transform the type expression in a usable type and compare it with t1 and its ancestors.

The function returns the depth at which the match occurs. If a match occurs because t2 is some form of 'match any' then LOWEST_DEPTH (INT_MAX / 2) is return as the depth. This means it has the lowest possible priority.

The function returns MATCH_HIGHEST_DEPTH (1) if t1 matches t2 directly. This is the highest possible priority so if no other function matches with that depth, this is the one which is going to be used.

The function returns MATCH_NOT_FOUND (0) if it cannot find a match between t1 and t2. That means no function was found here.

Parameters
[in]t1A type to match against. [in]t2A type that has to match t1.
Returns
The depth at which the type matched.

Definition at line 506 of file compiler_function.cpp.

References as2js::AS_ERR_MISSSING_VARIABLE_NAME, find_class(), as2js::Node::MATCH_HIGHEST_DEPTH, as2js::Node::MATCH_LOWEST_DEPTH, as2js::Node::MATCH_NOT_FOUND, as2js::MESSAGE_LEVEL_WARNING, as2js::Node::NODE_CLASS, as2js::Node::NODE_IDENTIFIER, as2js::Node::NODE_PARAM, as2js::Node::NODE_PARAM_FLAG_OUT, as2js::Node::NODE_SET, resolve_internal_type(), resolve_name(), and type_expr().

Referenced by check_function_with_params(), and get_err_flags().

void as2js::Compiler::object_literal ( Node::pointer_t  expr) private
void as2js::Compiler::program ( Node::pointer_t  program_node) private
void as2js::Compiler::read_db ( ) private
void as2js::Compiler::resolve_internal_type ( Node::pointer_t  parent, char const *  type, Node::pointer_tresolution  ) private
void as2js::Compiler::resolve_member ( Node::pointer_t  expr, Node::pointer_t  params, int const  search_flags  ) private
bool as2js::Compiler::select_best_func ( Node::pointer_t  params, Node::pointer_tresolution  ) private

This function checks all the functions we found and selects the best match according to the parameter types and count.

Parameters
[in]paramsThe parameters of the function. [out]resolutionThe function we consider to be the best.
Returns
true if a best function was found and resolution set to that node.

Definition at line 1032 of file compiler_function.cpp.

References best_param_match(), and as2js::Node::NODE_PARAM_MATCH.

Referenced by get_err_flags(), resolve_field(), and resolve_name().

InputRetriever::pointer_t as2js::Compiler::set_input_retriever ( InputRetriever::pointer_t  retriever)

Definition at line 76 of file compiler.cpp.

References f_input_retriever.

void as2js::Compiler::throw_directive ( Node::pointer_tthrow_node) private

Definition at line 495 of file compiler_statement.cpp.

References expression().

Referenced by directive_list(), and set_err_flags().

void as2js::Compiler::try_directive ( Node::pointer_ttry_node) private
void as2js::Compiler::use_namespace ( Node::pointer_tuse_namespace_node) private
void as2js::Compiler::var ( Node::pointer_t  var_node) private

Definition at line 112 of file compiler_variable.cpp.

References variable().

Referenced by declare_class(), directive_list(), for_directive(), and set_err_flags().

void as2js::Compiler::while_directive ( Node::pointer_twhile_node) private

Definition at line 375 of file compiler_statement.cpp.

References directive_list(), and expression().

Referenced by directive_list(), and set_err_flags().

void as2js::Compiler::with ( Node::pointer_twith_node) private
void as2js::Compiler::write_db ( ) private
Member Data Documentation
search_error_t as2js::Compiler::f_err_flags = 0 private

Definition at line 230 of file compiler.h.

Referenced by check_name(), get_err_flags(), print_search_errors(), and set_err_flags().

InputRetriever::pointer_t as2js::Compiler::f_input_retriever = InputRetriever::pointer_t() private

Definition at line 229 of file compiler.h.

Referenced by find_module(), internal_imports(), and set_input_retriever().

module_map_t as2js::Compiler::f_modules = module_map_t() private

Definition at line 232 of file compiler.h.

Referenced by find_module().

Options::pointer_t as2js::Compiler::f_options = Options::pointer_t() private

Definition at line 227 of file compiler.h.

Referenced by find_module().

Node::pointer_t as2js::Compiler::f_program = Node::pointer_t() private

Definition at line 228 of file compiler.h.

Referenced by check_import(), and program().

Node::pointer_t as2js::Compiler::f_scope = Node::pointer_t() private

Definition at line 231 of file compiler.h.

Referenced by compile(), directive_list(), and use_namespace().

time_t as2js::Compiler::f_time = 0 private

Definition at line 226 of file compiler.h.

Referenced by special_identifier().

search_error_t const as2js::Compiler::SEARCH_ERROR_EXPECTED_STATIC_MEMBER = 0x00000040 staticprivate

Definition at line 86 of file compiler.h.

search_error_t const as2js::Compiler::SEARCH_ERROR_NONE = 0x00000000 staticprivate

Definition at line 79 of file compiler.h.

Referenced by print_search_errors().

search_error_t const as2js::Compiler::SEARCH_ERROR_PRIVATE = 0x00000001 staticprivate

Definition at line 80 of file compiler.h.

Referenced by check_name(), and print_search_errors().

search_error_t const as2js::Compiler::SEARCH_ERROR_PRIVATE_PACKAGE = 0x00000020 staticprivate

Definition at line 85 of file compiler.h.

Referenced by check_name(), and print_search_errors().

search_error_t const as2js::Compiler::SEARCH_ERROR_PROTECTED = 0x00000002 staticprivate

Definition at line 81 of file compiler.h.

Referenced by check_name(), and print_search_errors().

search_error_t const as2js::Compiler::SEARCH_ERROR_PROTOTYPE = 0x00000004 staticprivate

Definition at line 82 of file compiler.h.

Referenced by print_search_errors().

search_error_t const as2js::Compiler::SEARCH_ERROR_WRONG_PRIVATE = 0x00000008 staticprivate

Definition at line 83 of file compiler.h.

Referenced by check_name(), and print_search_errors().

search_error_t const as2js::Compiler::SEARCH_ERROR_WRONG_PROTECTED = 0x00000010 staticprivate

Definition at line 84 of file compiler.h.

Referenced by check_name(), and print_search_errors().

search_flag_t const as2js::Compiler::SEARCH_FLAG_GETTER = 0x00000002 staticprivate

Definition at line 89 of file compiler.h.

Referenced by check_function(), expression(), expression_new(), and resolve_call().

search_flag_t const as2js::Compiler::SEARCH_FLAG_NO_PARSING = 0x00000001 staticprivate

Definition at line 88 of file compiler.h.

Referenced by check_name(), and identifier_to_attrs().

search_flag_t const as2js::Compiler::SEARCH_FLAG_PACKAGE_MUST_EXIST = 0x00000008 staticprivate

Definition at line 91 of file compiler.h.

Referenced by check_import(), and find_package_item().

search_flag_t const as2js::Compiler::SEARCH_FLAG_SETTER = 0x00000004 staticprivate

Definition at line 90 of file compiler.h.

Referenced by assignment_operator(), and check_function().


The documentation for this class was generated from the following files:

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