Gyoji Compiler
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Gyoji::frontend::ParseResult Class Reference

#include <parse-result.hpp>

Public Member Functions

 ParseResult (Gyoji::context::CompilerContext &_compiler_context, Gyoji::owned< Gyoji::frontend::namespaces::NS2Context > _ns2_context)
 
 ~ParseResult ()
 
const Gyoji::frontend::namespaces::NS2Contextget_ns2_context () const
 
bool has_errors () const
 
Gyoji::context::Errorsget_errors () const
 
bool has_translation_unit () const
 
const Gyoji::frontend::tree::TranslationUnitget_translation_unit () const
 
const Gyoji::context::TokenStreamget_token_stream () const
 
const Gyoji::context::CompilerContextget_compiler_context () const
 
Gyoji::frontend::namespaces::NS2Entityidentifier_get_or_create (std::string name, bool allow_placement_in_namespace, const Gyoji::context::SourceReference &_src_ref)
 
const Symbol * symbol_get (std::string name) const
 

Detailed Description

This class represents the result of parsing a source-file. This class holds all of the results relevant to that parse.

The syntax tree is held by the "translation_unit" which represents the parse-tree of any valid parse of the input.

In the event that some or all of the input could not be parsed correctly, the "errors" object contains detailed information about exactly what is wrong with the parse including any errors and descriptions as well as context information surrounding the site where the parse failed.

In addition, the source-file may make use of namespaces to define types, classes, functions inside them and organize them in a heirarchy. The "namespaces" object returns information about the types and namespaces they are defined inside of including the fully-qualified type names, for example, a primitive type will have name "::u32", for example, whereas another type may be defined in the "foo" namespace as "::foo::bar".

Finally, the "token_stream" contains the list of tokens parsed by the lexer including verbatim copies of the input. This data may be useful for code-formatters or producing rich error messages with the full context of the input.

Constructor & Destructor Documentation

◆ ParseResult()

ParseResult::ParseResult ( Gyoji::context::CompilerContext _compiler_context,
Gyoji::owned< Gyoji::frontend::namespaces::NS2Context _ns2_context 
)

The constructor requires the caller to pass a namespace context in order to define the built-in primitive types.

This is important because the primitive types are generally governed by the back-end code-generation layer which must inform the initial set of primitive types available.

◆ ~ParseResult()

ParseResult::~ParseResult ( )

Destructor, nothing special.

Member Function Documentation

◆ get_compiler_context()

const Gyoji::context::CompilerContext & ParseResult::get_compiler_context ( ) const

Returns the compiler context that this was parsed for.

◆ get_errors()

Errors & ParseResult::get_errors ( ) const

This returns an object containing the details of any parse errors that occurred during the parse.

◆ get_ns2_context()

const NS2Context & ParseResult::get_ns2_context ( ) const

This returns a reference to the namespace context containing the namespaces defined by the source-file and the types and classes defined in them. Note that this reference may only be accessed for as long as this (ParseResult) object is in scope since the namespace context is owned by this object.

◆ get_token_stream()

const TokenStream & ParseResult::get_token_stream ( ) const

This returns the token stream associated with the parse. The token stream is the series of tokens produced by the lexical analysis (gyoji.l) and represents the input data organized as tokens. This token stream can be used to reconstruct all of the input data, but also allows structured access to it for the purpose of producing structured error messages.

◆ get_translation_unit()

const TranslationUnit & ParseResult::get_translation_unit ( ) const

If the parse resulted in a valid parse, then the translation unit returns the strongly-typed parse tree for the source-file. This can be used for multiple purposes including to reproduce the input either identically or as a "pretty print" version. It can also be used to drive the intermediate representation and code-generation in order to compile output. The front-end does not perform any of those tasks, but the parse tree generated here is a faithful and strongly-typed representation of the input.

◆ has_errors()

bool ParseResult::has_errors ( ) const

This returns true if any parse errors occurred during the parse of the source-file.

◆ has_translation_unit()

bool ParseResult::has_translation_unit ( ) const

This returns true if the parse resulted in a valid TranslationUnit. That is to say, if the parse was able to parse correctly or recover from any recoverable errors and produce a parse tree. Note that if the has_errors() returns true, then the resulting parse tree may be inaccurate or incomplete.

◆ identifier_get_or_create()

NS2Entity * ParseResult::identifier_get_or_create ( std::string  name,
bool  allow_placement_in_namespace,
const Gyoji::context::SourceReference _src_ref 
)

Maybe we create it here. This is where we could look up symbols and create new ones when they don't exist and also return error messages when they are duplicated.

◆ symbol_get()

const Symbol * ParseResult::symbol_get ( std::string  name) const

Searches for the symbol 'name' in the current namespace context. Returns all possible symbol matches for the given name.

The name may be fully-qualified like '::foo::bar' and it may be a simple name like 'bar'. The namespace search path and 'using' clauses will be used to find all possible namespace prefixes and each namespace prefix will be used to search for the existence of the symbol. If found, it will return the symbol. If not found, it will return nullptr.


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