mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* use new formatter for ERROR_PRINT, added ERROR_PRINTLN * remove old log define * fix comments
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
#include "Constants.h"
|
|
|
|
#include "bscript/compiler/Report.h"
|
|
#include "bscript/compiler/ast/ConstDeclaration.h"
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
Constants::Constants( Report& report ) : report( report ) {}
|
|
|
|
ConstDeclaration* Constants::find( const std::string& name )
|
|
{
|
|
auto itr = constants.find( name );
|
|
return ( itr != constants.end() ) ? ( *itr ).second : nullptr;
|
|
}
|
|
|
|
void Constants::create( ConstDeclaration& constant )
|
|
{
|
|
auto itr = constants.find( constant.identifier );
|
|
if ( itr != constants.end() )
|
|
{
|
|
if ( constant.ignore_overwrite_attempt )
|
|
{
|
|
// The OG compiler ignores enum members with the same name as a
|
|
// constant or enum that was defined earlier.
|
|
|
|
report.warning( constant,
|
|
"Constant '{}' definition ignored due to an earlier definition.\n"
|
|
" Previous definition at: {}",
|
|
constant.identifier, ( *itr ).second->source_location );
|
|
return;
|
|
}
|
|
report.error( constant,
|
|
"Constant '{}' defined more than once.\n"
|
|
" Previous definition at: {}",
|
|
constant.identifier, ( *itr ).second->source_location );
|
|
}
|
|
|
|
constants[constant.identifier] = &constant;
|
|
}
|
|
|
|
} // namespace Pol::Bscript::Compiler
|