Skip to content

Commit

Permalink
Merge 7e21187 into f426a5b
Browse files Browse the repository at this point in the history
  • Loading branch information
turleypol committed Aug 26, 2021
2 parents f426a5b + 7e21187 commit c29eb5f
Show file tree
Hide file tree
Showing 34 changed files with 275 additions and 167 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ cmake_fake_target()
include(cmake/Antlr.cmake)
include(cmake/Boost.cmake)
include(cmake/Benchmark.cmake)
include(cmake/EscriptGrammarLib.cmake)
include(cmake/escript_grammar.cmake)
include(cmake/Format.cmake)
include(cmake/Kaitai.cmake)
Expand Down
50 changes: 50 additions & 0 deletions cmake/EscriptGrammarLib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
set(escriptgrammarlib_sources
${POL_EXT_LIB_DIR}/EscriptGrammar/EscriptLexer.cpp
${POL_EXT_LIB_DIR}/EscriptGrammar/EscriptLexer.h
${POL_EXT_LIB_DIR}/EscriptGrammar/EscriptParser.cpp
${POL_EXT_LIB_DIR}/EscriptGrammar/EscriptParser.h
${POL_EXT_LIB_DIR}/EscriptGrammar/EscriptParserBaseListener.cpp
${POL_EXT_LIB_DIR}/EscriptGrammar/EscriptParserBaseListener.h
${POL_EXT_LIB_DIR}/EscriptGrammar/EscriptParserListener.cpp
${POL_EXT_LIB_DIR}/EscriptGrammar/EscriptParserListener.h
)

set(lib_name escriptgrammarlib)

add_library(${lib_name} STATIC
${${lib_name}_sources}
)
set_compile_flags(${lib_name} 0)

target_include_directories(${lib_name} PRIVATE
"${POL_EXT_LIB_DIR}/EscriptGrammar"
)
target_include_directories(${lib_name} PUBLIC
${ANTLR_INCLUDE_DIR}
)

if (NOT EXISTS ${ANTLR_LIB})
add_dependencies(${lib_name} libantlr_ex)
endif()

target_compile_definitions(${lib_name} PUBLIC
-DANTLR4CPP_STATIC
)

target_link_libraries(${lib_name} PUBLIC
${ANTLR_LIB}
)

warning_suppression(${lib_name})

target_compile_options(${lib_name} PRIVATE
$<${windows}:
/wd4100 #unreferenced formal parameter
>
$<${linux}:
-Wno-unused-parameter
-Wno-attributes
>
)

set_target_properties (${lib_name} PROPERTIES FOLDER 3rdParty)
2 changes: 2 additions & 0 deletions cmake/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ macro(cmake_fake_target)
cmake/Benchmark.cmake
cmake/Boost.cmake
cmake/Curl.cmake
cmake/EscriptGrammarLib.cmake
cmake/escript_grammar.cmake
cmake/Format.cmake
cmake/Kaitai.cmake
Expand All @@ -233,6 +234,7 @@ macro(cmake_fake_target)
cmake/Benchmark.cmake
cmake/Boost.cmake
cmake/Curl.cmake
cmake/EscriptGrammarLib.cmake
cmake/escript_grammar.cmake
cmake/Format.cmake
cmake/Kaitai.cmake
Expand Down
8 changes: 1 addition & 7 deletions pol-core/bscript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ set_compile_flags(${lib_name} 0)
warning_suppression(${lib_name})
enable_pch(${lib_name})

target_include_directories(${lib_name} PUBLIC ${ANTLR_INCLUDE_DIR})
if (NOT EXISTS ${ANTLR_LIB})
add_dependencies(${lib_name} libantlr_ex)
endif()
target_compile_definitions(${lib_name} PUBLIC -DANTLR4CPP_STATIC)

target_link_libraries(${lib_name} PUBLIC
${ANTLR_LIB}
clib
escriptgrammarlib
)
if (${linux})
target_link_libraries(${lib_name} PUBLIC
Expand Down
9 changes: 1 addition & 8 deletions pol-core/bscript/CMakeSources.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
set (bscript_sources # sorted !
../../lib/EscriptGrammar/EscriptLexer.cpp
../../lib/EscriptGrammar/EscriptLexer.h
../../lib/EscriptGrammar/EscriptParser.cpp
../../lib/EscriptGrammar/EscriptParser.h
../../lib/EscriptGrammar/EscriptParserBaseListener.cpp
../../lib/EscriptGrammar/EscriptParserBaseListener.h
../../lib/EscriptGrammar/EscriptParserListener.cpp
../../lib/EscriptGrammar/EscriptParserListener.h
CMakeSources.cmake
StdAfx.h
StoredToken.cpp
StoredToken.h
compiler/Antlr4Inc.h
compiler/Compiler.cpp
compiler/Compiler.h
compiler/analyzer/Constants.cpp
Expand Down
15 changes: 15 additions & 0 deletions pol-core/bscript/compiler/Antlr4Inc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef POLSERVER_ANTLR4INC_H
#define POLSERVER_ANTLR4INC_H

#if defined( __GNUC__ )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
#endif

#include <antlr4-runtime.h>

#if defined( __GNUC__ )
#pragma GCC diagnostic pop
#endif

#endif
2 changes: 1 addition & 1 deletion pol-core/bscript/compiler/astbuilder/ExpressionBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ std::unique_ptr<Expression> ExpressionBuilder::expression( EscriptParser::Expres
{
result = expression_suffix( expression( ctx->expression()[0] ), suffix );
}
else if ( auto conditional = ctx->QUESTION() )
else if ( ctx->QUESTION() )
{
result = conditional_operator( ctx );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ void SimpleStatementBuilder::add_intrusive_debug_marker(
antlr4::ParserRuleContext* ctx, std::vector<std::unique_ptr<Statement>>& statements )
{
statements.push_back( std::make_unique<DebugStatementMarker>(
location_for( *ctx ), ctx->getText(), ctx->start->getStartIndex() ) );
location_for( *ctx ), ctx->getText(),
static_cast<unsigned>( ctx->start->getStartIndex() ) ) );
}

void SimpleStatementBuilder::add_var_statements(
Expand Down
7 changes: 5 additions & 2 deletions pol-core/bscript/compiler/astbuilder/SourceFileProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void SourceFileProcessor::use_module( const std::string& module_name,
return;

auto ident = std::make_unique<SourceFileIdentifier>(
workspace.compiler_workspace.referenced_source_file_identifiers.size(), pathname );
static_cast<unsigned>(
workspace.compiler_workspace.referenced_source_file_identifiers.size() ),
pathname );

Pol::Tools::HighPerfTimer load_timer;
auto sf = workspace.em_cache.load( *ident, report );
Expand Down Expand Up @@ -147,7 +149,8 @@ void SourceFileProcessor::handle_include_declaration( EscriptParser::IncludeDecl
if ( workspace.source_files.count( canonical_include_pathname ) == 0 )
{
auto ident = std::make_unique<SourceFileIdentifier>(
workspace.compiler_workspace.referenced_source_file_identifiers.size(),
static_cast<unsigned int>(
workspace.compiler_workspace.referenced_source_file_identifiers.size() ),
canonical_include_pathname );
auto sf = workspace.inc_cache.load( *ident, report );
if ( !sf )
Expand Down
3 changes: 1 addition & 2 deletions pol-core/bscript/compiler/astbuilder/TreeBuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "TreeBuilder.h"

#include <antlr4-runtime.h>

#include "bscript/compiler/Antlr4Inc.h"
#include "bscript/compiler/ast/ValueConsumer.h"
#include "bscript/compiler/astbuilder/BuilderWorkspace.h"
#include "bscript/compiler/file/SourceLocation.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ void CaseDispatchGroupVisitor::visit_case_dispatch_default_selector( CaseDispatc

void CaseDispatchGroupVisitor::visit_integer_value( IntegerValue& integer_node )
{
data_block.on_integer_value_jump_to( integer_node.value, group_block_label.address() );
data_block.on_integer_value_jump_to( integer_node.value,
static_cast<unsigned short>( group_block_label.address() ) );
}

void CaseDispatchGroupVisitor::visit_string_value( StringValue& string_node )
{
data_block.on_string_value_jump_to( string_node.value, group_block_label.address() );
data_block.on_string_value_jump_to( string_node.value,
static_cast<unsigned short>( group_block_label.address() ) );
}

} // namespace Pol::Bscript::Compiler
2 changes: 1 addition & 1 deletion pol-core/bscript/compiler/codegen/CodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ unsigned CodeEmitter::append( const StoredToken& st )

void CodeEmitter::update_offset( unsigned index, unsigned offset )
{
code[index].offset = offset;
code[index].offset = static_cast<unsigned short>( offset );
}

unsigned CodeEmitter::next_address() const
Expand Down
2 changes: 1 addition & 1 deletion pol-core/bscript/compiler/codegen/DataEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ unsigned DataEmitter::find( const std::byte* data, size_t len )
++start; // offset=0 means no data, not data at offset 0
auto itr = std::search( start, data_section.end(), data, data + len );
if ( itr != data_section.end() )
return itr - data_section.begin();
return static_cast<unsigned>( itr - data_section.begin() );
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion pol-core/bscript/compiler/codegen/InstructionEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void InstructionEmitter::call_modulefunc(
module_id, function_index );
unsigned sympos = include_debug ? emit_data( module_function_declaration.name ) : 0;
StoredToken token(
module_id, TOK_FUNC,
static_cast<unsigned char>( module_id ), TOK_FUNC,
static_cast<BTokenType>(
function_index ), // function index, stored in Token.lval, saved in StoredToken.type
sympos );
Expand Down
4 changes: 2 additions & 2 deletions pol-core/bscript/compiler/codegen/InstructionGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void InstructionGenerator::visit_case_statement( CaseStatement& node )
if ( !default_label.has_address() )
emit.label( default_label );

data_block.on_default_jump_to( default_label.address() );
data_block.on_default_jump_to( static_cast<unsigned short>( default_label.address() ) );

emit.label( *node.break_label );

Expand Down Expand Up @@ -727,7 +727,7 @@ void InstructionGenerator::visit_interpolate_string( InterpolateString& node )
visit_children( node );

update_debug_location( node );
emit.interpolate_string( node.children.size() );
emit.interpolate_string( static_cast<unsigned>( node.children.size() ) );
}

void InstructionGenerator::visit_format_expression( FormatExpression& node )
Expand Down
2 changes: 1 addition & 1 deletion pol-core/bscript/compiler/file/ConformingCharStream.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef POLSERVER_CONFORMINGCHARSTREAM_H
#define POLSERVER_CONFORMINGCHARSTREAM_H

#include <antlr4-runtime.h>
#include "bscript/compiler/Antlr4Inc.h"

namespace Pol::Bscript::Compiler
{
Expand Down
4 changes: 2 additions & 2 deletions pol-core/bscript/compiler/file/ErrorListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void ErrorListener::propagate_errors_to( Report& report, const SourceFileIdentif
{
for ( auto& msg : error_messages )
{
SourceLocation location( &ident, static_cast<unsigned>( msg.line_number ),
static_cast<unsigned>( msg.char_column ) );
SourceLocation location( &ident, static_cast<unsigned short>( msg.line_number ),
static_cast<unsigned short>( msg.char_column ) );
report.error( location, msg.message, "\n" );
}
}
Expand Down
2 changes: 1 addition & 1 deletion pol-core/bscript/compiler/file/ErrorListener.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef POLSERVER_ERRORLISTENER_H
#define POLSERVER_ERRORLISTENER_H

#include <antlr4-runtime.h>
#include "bscript/compiler/Antlr4Inc.h"

namespace Pol::Bscript::Compiler
{
Expand Down
2 changes: 1 addition & 1 deletion pol-core/bscript/compiler/file/SourceLocation.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "SourceLocation.h"

#include <antlr4-runtime.h>
#include "bscript/compiler/Antlr4Inc.h"

#include "clib/logfacility.h"
#include "bscript/compiler/file/SourceFileIdentifier.h"
Expand Down
4 changes: 2 additions & 2 deletions pol-core/bscript/str.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void String::toUpper()
static_cast<int>( str.size() ), 0, 0 );
if ( !len )
return;
else if ( len == str.size() )
else if ( len == static_cast<int>( str.size() ) )
{
LCMapStringW( LOCALE_USER_DEFAULT, LCMAP_UPPERCASE | LCMAP_LINGUISTIC_CASING, &str[0],
static_cast<int>( str.size() ), &str[0], static_cast<int>( str.size() ) );
Expand Down Expand Up @@ -466,7 +466,7 @@ void String::toLower()
static_cast<int>( str.size() ), 0, 0 );
if ( !len )
return;
else if ( len == str.size() )
else if ( len == static_cast<int>( str.size() ) )
{
LCMapStringW( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE | LCMAP_LINGUISTIC_CASING, &str[0],
static_cast<int>( str.size() ), &str[0], static_cast<int>( str.size() ) );
Expand Down
10 changes: 6 additions & 4 deletions pol-core/clib/Debugging/ExceptionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void getSignalDescription( int signal, string& signalName, string& signalDescrip
}
}

#if !defined( _WIN32 ) && !defined( __APPLE__ )
void logExceptionSignal( int signal )
{
string signalName;
Expand All @@ -142,6 +143,7 @@ void logExceptionSignal( int signal )
printf( "Signal \"%s\"(%d: %s) detected.\n", signalName.c_str(), signal,
signalDescription.c_str() );
}
#endif

string getCompilerVersion()
{
Expand Down Expand Up @@ -280,7 +282,7 @@ void doHttpPOST( const string& host, const string& url, const string& content )
/**
* send the request
*/
#if !defined(_WIN32) && !defined(__APPLE__)
#if !defined( _WIN32 ) && !defined( __APPLE__ )
send( socketFD, request, strlen( request ), MSG_NOSIGNAL );
#else
send( socketFD, request, (int)strlen( request ), 0 );
Expand All @@ -293,7 +295,7 @@ void doHttpPOST( const string& host, const string& url, const string& content )
ssize_t readBytes;
char answer[MAXLINE + 1];

#if !defined(_WIN32) && !defined(__APPLE__)
#if !defined( _WIN32 ) && !defined( __APPLE__ )
while ( ( readBytes = recv( socketFD, answer, MAXLINE, MSG_NOSIGNAL ) ) > 0 )
{
#else
Expand Down Expand Up @@ -399,7 +401,7 @@ void ExceptionParser::handleExceptionSignal( int signal )
printf( "Compile time: %s\n", ProgramConfig::build_datetime().c_str() );
printf( "Build target: %s\n", ProgramConfig::build_target().c_str() );
printf( "Build revision: %s\n", POL_VERSION_ID );
#if defined(__GLIBC__)
#if defined( __GLIBC__ )
printf( "GNU C library (compile time): %d.%d\n", __GLIBC__, __GLIBC_MINOR__ );
#endif
printf( "\n" );
Expand Down Expand Up @@ -438,7 +440,7 @@ ExceptionParser::~ExceptionParser() {}

///////////////////////////////////////////////////////////////////////////////

#if!defined(_WIN32) && !defined(__APPLE__)
#if !defined( _WIN32 ) && !defined( __APPLE__ )
string ExceptionParser::getTrace()
{
string result;
Expand Down
6 changes: 2 additions & 4 deletions pol-core/clib/cfgfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ std::string ConfigElem::remove_string( const char* propname )
}
else
{
prop_not_found( propname );
return ""; // this is not reached, prop_not_found throws
prop_not_found( propname ); // prop_not_found throws
}
}

Expand All @@ -401,8 +400,7 @@ std::string ConfigElem::read_string( const char* propname ) const
}
else
{
prop_not_found( propname );
return ""; // this is not reached, prop_not_found throws
prop_not_found( propname ); // prop_not_found throws
}
}
std::string ConfigElem::read_string( const char* propname, const char* dflt ) const
Expand Down
2 changes: 2 additions & 0 deletions pol-core/clib/network/wnsckt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ void Socket::HandleError()
{
#ifdef _WIN32
int ErrVal;
#if SCK_WATCH
static char ErrorBuffer[80];
#endif

ErrVal = WSAGetLastError();
WSASetLastError( 0 );
Expand Down
6 changes: 2 additions & 4 deletions pol-core/pol/containr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,7 @@ Items::Item* UContainer::clone() const
unsigned short UContainer::max_items() const
{
const auto max_items = desc.max_items + max_items_mod();

return std::max( 1, std::min<decltype( max_items )>( max_items, MAX_CONTAINER_ITEMS ) );
return static_cast<u16>( std::clamp( max_items, 1, MAX_CONTAINER_ITEMS ) );
}

unsigned short UContainer::max_weight() const
Expand All @@ -970,8 +969,7 @@ unsigned short UContainer::max_weight() const
u8 UContainer::max_slots() const
{
const auto max_slots = desc.max_slots + max_slots_mod();

return std::max( 0, std::min<decltype( max_slots )>( max_slots, MAX_SLOTS ) );
return static_cast<u8>( std::clamp( max_slots, 0, MAX_SLOTS ) );
}

bool UContainer::no_drop_exception() const
Expand Down

0 comments on commit c29eb5f

Please sign in to comment.