Gyoji Compiler
|
Compiler Context. More...
#include <gyoji-context.hpp>
Public Member Functions | |
CompilerContext (std::string _filename) | |
bool | has_errors () const |
Errors & | get_errors () const |
TokenStream & | get_token_stream () const |
const std::string & | get_filename () const |
void | add_filename (const std::string &_filename) |
Compiler Context.
The compiler context is an object that holds the token stream used to tokenize the input and also hold references to the source-file that the data was read from. In addition, it holds the error reporting object which is the main mechanism where errors during parse, lowering, analysis, and code-generation are reported.
CompilerContext::CompilerContext | ( | std::string | _filename | ) |
Constructs a context that can be used for compiling a source file. The filename given here is used to provide context to the error system, but is not directly used in reading the file, only for producing context-driven error messages.
void CompilerContext::add_filename | ( | const std::string & | _filename | ) |
This allows us to declare that the source file is different than the actual physical source file we're reading from. This is used in situations where code is generated and that tool would like to trace the generated code back to the location where it was generated from. This allows errors to be traced all the way back to the 'original' location where they were generated from.
Errors & CompilerContext::get_errors | ( | ) | const |
This returns the errors object that holds all of the errors reported so far.
const std::string & CompilerContext::get_filename | ( | ) | const |
This returns the 'current' source file at this point in the compilation. Note that some statements like the #line directive in the pre-processor can be used to declare the source location to be physically different than where the source is actually read from. This is used for situations where code is generated, for example, and allows us to associate generated code with the source file/location where it was generated from.
TokenStream & CompilerContext::get_token_stream | ( | ) | const |
This returns the token stream which is a container for the input as it was directly read from the input source file. The token stream contains enough information to completely re-construct the input source file, so in that sense, there is no 'loss' of data as it is read into the token stream.
bool CompilerContext::has_errors | ( | ) | const |
This returns true if any errors were reported so far during the compilation process. Presence of errors usually stops the next stage of compilation from proceeding because there may be errors that would make the next stage nonsense or inconsistent.