2020-08-05 23:43:00 -07:00
|
|
|
#include "SourceLocation.h"
|
|
|
|
|
|
2021-08-28 22:26:15 +02:00
|
|
|
#include "bscript/compiler/Antlr4Inc.h"
|
2020-08-05 23:43:00 -07:00
|
|
|
|
2020-08-14 23:01:19 -07:00
|
|
|
#include "clib/logfacility.h"
|
2021-02-25 16:53:22 +01:00
|
|
|
#include "bscript/compiler/file/SourceFileIdentifier.h"
|
2020-08-05 23:43:00 -07:00
|
|
|
|
2020-08-10 03:20:29 -07:00
|
|
|
namespace Pol::Bscript::Compiler
|
2020-08-05 23:43:00 -07:00
|
|
|
{
|
|
|
|
|
SourceLocation::SourceLocation( const SourceFileIdentifier* source_file_identifier,
|
2020-08-06 01:43:55 -07:00
|
|
|
unsigned short line_number,
|
|
|
|
|
unsigned short character_column )
|
2020-08-05 23:43:00 -07:00
|
|
|
: source_file_identifier( source_file_identifier ),
|
|
|
|
|
line_number( line_number ),
|
|
|
|
|
character_column( character_column )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceLocation::SourceLocation( const SourceFileIdentifier* source_file_identifier,
|
|
|
|
|
antlr4::ParserRuleContext& ctx )
|
|
|
|
|
: source_file_identifier( source_file_identifier ),
|
2020-08-06 01:43:55 -07:00
|
|
|
line_number( static_cast<unsigned short>( ctx.getStart()->getLine() ) ),
|
|
|
|
|
character_column( static_cast<unsigned short>( ctx.getStart()->getCharPositionInLine()+1 ) )
|
2020-08-05 23:43:00 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceLocation::SourceLocation( const SourceFileIdentifier* source_file_identifier,
|
|
|
|
|
antlr4::tree::TerminalNode& ctx )
|
|
|
|
|
: source_file_identifier( source_file_identifier ),
|
2020-08-06 01:43:55 -07:00
|
|
|
line_number( static_cast<unsigned short>( ctx.getSymbol()->getLine() ) ),
|
|
|
|
|
character_column( static_cast<unsigned short>( ctx.getSymbol()->getCharPositionInLine()+1 ) )
|
2020-08-05 23:43:00 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourceLocation::debug( const std::string& msg ) const
|
|
|
|
|
{
|
|
|
|
|
ERROR_PRINT << ( *this ) << ": " << msg << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourceLocation::internal_error( const std::string& msg ) const
|
|
|
|
|
{
|
|
|
|
|
ERROR_PRINT << ( *this ) << ": " << msg << "\n";
|
|
|
|
|
throw std::runtime_error( msg );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourceLocation::internal_error( const std::string& msg, const SourceLocation& related ) const
|
|
|
|
|
{
|
|
|
|
|
ERROR_PRINT << ( *this ) << ": " << msg << "\n"
|
|
|
|
|
<< " See also: " << related << "\n";
|
|
|
|
|
throw std::runtime_error( msg );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt::Writer& operator<<( fmt::Writer& w, const SourceLocation& location )
|
|
|
|
|
{
|
|
|
|
|
w << location.source_file_identifier->pathname;
|
|
|
|
|
if ( location.line_number || location.character_column )
|
|
|
|
|
w << ":" << location.line_number << ":" << location.character_column;
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 03:20:29 -07:00
|
|
|
} // namespace Pol::Bscript::Compiler
|