as2js: as2js::Position Class Reference

#include <position.h>

Collaboration diagram for as2js::Position:
Public Types typedef int32_t counter_t   Public Member Functions String get_filename () const  Retrieve the filename. More...
  String get_function () const  Retrieve the function name. More...
  counter_t get_line () const  Retrieve the current line counter. More...
  counter_t get_page () const  Retrieve the current page counter. More...
  counter_t get_page_line () const  Retrieve the current page line counter. More...
  counter_t get_paragraph () const  Retrieve the current paragraph counter. More...
  void new_line ()  Increment the line counter by 1. More...
  void new_page ()  Increment the page counter by 1. More...
  void new_paragraph ()  Increments the paragraph counter by 1. More...
  void reset_counters (counter_t line=DEFAULT_COUNTER)  Reset the counter. More...
  void set_filename (String const &filename)  Set the filename being read. More...
  void set_function (String const &function)  Set the function being read. More...
  Static Public Attributes static counter_t const DEFAULT_COUNTER = 1   Private Attributes String f_filename = String()   String f_function = String()   counter_t f_line = DEFAULT_COUNTER   counter_t f_page = DEFAULT_COUNTER   counter_t f_page_line = DEFAULT_COUNTER   counter_t f_paragraph = DEFAULT_COUNTER   Detailed Description

Definition at line 44 of file position.h.

Member Typedef Documentation
typedef int32_t as2js::Position::counter_t

Definition at line 47 of file position.h.

Member Function Documentation
String as2js::Position::get_filename ( ) const

This function returns the filename as set by the set_filename() function.

It is possible for the filename to be empty (in case you are compiling a function from memory.)

Returns
The current filename.

Definition at line 143 of file position.cpp.

References f_filename.

Referenced by as2js::operator<<(), as2js::optimizer_details::anonymous_namespace{optimizer_optimize.cpp}::optimizer_func_MATCH(), and as2js::Message::~Message().

String as2js::Position::get_function ( ) const

This function returns the function name as set by the set_function() function.

It is possible for the function name to be empty (before it was ever set.)

Returns
The current function name.

Definition at line 158 of file position.cpp.

References f_function.

Referenced by as2js::Message::~Message().

Position::counter_t as2js::Position::get_line ( ) const

The line counter is reset to 1 (or some other value) at the start and then it increases by 1 each time a new line character is found. It does not get reset on anything. It is generally useful when using a text editor as it represents the line number in such an editor.

Returns
The current line number.

Definition at line 214 of file position.cpp.

References f_line.

Referenced by as2js::operator<<(), and as2js::optimizer_details::anonymous_namespace{optimizer_optimize.cpp}::optimizer_func_MATCH().

Position::counter_t as2js::Position::get_page ( ) const

The page counter is incremented by one after X number of lines or when a Ctrl-L character is found in the input stream.

Returns
The page number.

Definition at line 171 of file position.cpp.

References f_page.

Position::counter_t as2js::Position::get_page_line ( ) const

The page line counter is incremented by one every time a new line character is found. It starts at 1. It is reset back to one each time a new page is found.

Returns
The page line number.

Definition at line 185 of file position.cpp.

References f_page_line.

Position::counter_t as2js::Position::get_paragraph ( ) const

The paragraph counter is incremented by one every time empty lines are found between blocks of non empty lines. It starts at 1. It is reset back to one each time a new page is found.

Returns
The paragraph number.

Definition at line 199 of file position.cpp.

References f_paragraph.

void as2js::Position::new_line ( )

This function increases the file as a whole line counter by 1. It also increments the page line counter by 1.

Definition at line 127 of file position.cpp.

References f_line, and f_page_line.

void as2js::Position::new_page ( )

This function increments the page counter by one, resets the page line to 1 and the paragraph to 1.

Definition at line 103 of file position.cpp.

References DEFAULT_COUNTER, f_page, f_page_line, and f_paragraph.

void as2js::Position::new_paragraph ( )

When the compiler detects the end of a paragraph, it calls this function to increment that counter by one. Paragraphs are counted within one page.

Definition at line 116 of file position.cpp.

References f_paragraph.

void as2js::Position::reset_counters ( counter_t  line = DEFAULT_COUNTER)

This function resets all the counters to 1 except for the line which is set to the specified line parameter (which defaults to 1.)

Exceptions
exception_internal_errorThis exception is raised if the line prameter is smaller than 1.
Parameters
[in]lineThe line number to start with. Defaults to 1.

Definition at line 84 of file position.cpp.

References DEFAULT_COUNTER, f_line, f_page, f_page_line, and f_paragraph.

Referenced by as2js::StringInput::StringInput().

void as2js::Position::set_filename ( String const &  filename)

This function saves the name of the file being read if available.

Todo:
Test that the filename is valid (no '\0', mainly.)
Parameters
[in]filenameThe name of the file being compiled.

Definition at line 52 of file position.cpp.

References f_filename.

Referenced by as2js::Database::add_package(), as2js::Database::load(), as2js::JSON::load(), as2js::Compiler::load_internal_packages(), as2js::FileInput::open(), as2js::FileOutput::open(), as2js::StandardInput::StandardInput(), as2js::StandardOutput::StandardOutput(), and as2js::Message::~Message().

void as2js::Position::set_function ( String const &  function)

This function saves the name of the function being read if available. The compile is capable of detecting which function is being read and keeps a stack of such (since a function can be declared within another.) Functions without a name are given a system name for the purpose of displaying errors that give us as much information as possible.

Parameters
[in]functionThe name of the function being compiled.

Definition at line 68 of file position.cpp.

References f_function.

Referenced by as2js::Message::~Message().

Member Data Documentation
counter_t const as2js::Position::DEFAULT_COUNTER = 1 static

Definition at line 48 of file position.h.

Referenced by new_page(), and reset_counters().

String as2js::Position::f_filename = String() private

Definition at line 70 of file position.h.

Referenced by get_filename(), and set_filename().

String as2js::Position::f_function = String() private

Definition at line 71 of file position.h.

Referenced by get_function(), and set_function().

counter_t as2js::Position::f_line = DEFAULT_COUNTER private

Definition at line 75 of file position.h.

Referenced by get_line(), new_line(), and reset_counters().

counter_t as2js::Position::f_page = DEFAULT_COUNTER private

Definition at line 72 of file position.h.

Referenced by get_page(), new_page(), and reset_counters().

counter_t as2js::Position::f_page_line = DEFAULT_COUNTER private

Definition at line 73 of file position.h.

Referenced by get_page_line(), new_line(), new_page(), and reset_counters().

counter_t as2js::Position::f_paragraph = DEFAULT_COUNTER private

Definition at line 74 of file position.h.

Referenced by get_paragraph(), new_page(), new_paragraph(), and reset_counters().


The documentation for this class was generated from the following files:
  • /home/snapwebsites/snapcpp/contrib/as2js/include/as2js/position.h
  • /home/snapwebsites/snapcpp/contrib/as2js/lib/position.cpp

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