mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* fix enum classes entries without initializer * docs * update grammar to support scoped identifiers in case labels * add support for enum class constants in case statements * add ScopableName to ConstDeclaration; formatting fixes; tests * update docs
42 lines
1.2 KiB
C++
42 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 name = constant.name.string();
|
|
auto itr = constants.find( name );
|
|
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: {}",
|
|
name, ( *itr ).second->source_location );
|
|
return;
|
|
}
|
|
report.error( constant,
|
|
"Constant '{}' defined more than once.\n"
|
|
" Previous definition at: {}",
|
|
name, ( *itr ).second->source_location );
|
|
}
|
|
|
|
constants[name] = &constant;
|
|
}
|
|
|
|
} // namespace Pol::Bscript::Compiler
|