Some reformatting
This commit is contained in:
parent
952aad1e02
commit
8eefe21aae
1 changed files with 114 additions and 109 deletions
53
shaders.cc
53
shaders.cc
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const std::regex PreprocDirective_( "^\\s*//!\\s*([a-z]+(\\s+([^\\s]+))*)\\s*$" );
|
|
||||||
|
|
||||||
const std::map< std::string , E_ShaderInput > InputTypes_( ([] {
|
const std::regex PreprocDirective_( "^\\s*//!\\s*([a-z]+(\\s+([^\\s]+))*)\\s*$" );
|
||||||
|
|
||||||
|
const std::map< std::string , E_ShaderInput > InputTypes_( ([] {
|
||||||
std::map< std::string , E_ShaderInput > t;
|
std::map< std::string , E_ShaderInput > t;
|
||||||
t.emplace( "chunk" , E_ShaderInput::CHUNK );
|
t.emplace( "chunk" , E_ShaderInput::CHUNK );
|
||||||
t.emplace( "library" , E_ShaderInput::LIBRARY );
|
t.emplace( "library" , E_ShaderInput::LIBRARY );
|
||||||
|
@ -13,11 +14,13 @@ namespace {
|
||||||
t.emplace( "vertex" , E_ShaderInput::VERTEX );
|
t.emplace( "vertex" , E_ShaderInput::VERTEX );
|
||||||
t.emplace( "fragment" , E_ShaderInput::FRAGMENT );
|
t.emplace( "fragment" , E_ShaderInput::FRAGMENT );
|
||||||
return t;
|
return t;
|
||||||
})());
|
})());
|
||||||
|
|
||||||
|
/*============================================================================*/
|
||||||
|
|
||||||
struct T_InputReader_
|
// Input reader state and functions, used when loading a source file
|
||||||
{
|
struct T_InputReader_
|
||||||
|
{
|
||||||
using T_Tokens_ = std::vector< std::string >;
|
using T_Tokens_ = std::vector< std::string >;
|
||||||
|
|
||||||
FILE* const file;
|
FILE* const file;
|
||||||
|
@ -42,18 +45,20 @@ namespace {
|
||||||
void handleDirective(
|
void handleDirective(
|
||||||
__rd__ T_Tokens_ const& tokens );
|
__rd__ T_Tokens_ const& tokens );
|
||||||
void error( __rd__ std::string const& err );
|
void error( __rd__ std::string const& err );
|
||||||
};
|
};
|
||||||
|
|
||||||
T_InputReader_::~T_InputReader_( )
|
/*----------------------------------------------------------------------------*/
|
||||||
{
|
|
||||||
|
T_InputReader_::~T_InputReader_( )
|
||||||
|
{
|
||||||
if ( buffer ) {
|
if ( buffer ) {
|
||||||
free( buffer );
|
free( buffer );
|
||||||
}
|
}
|
||||||
fclose( file );
|
fclose( file );
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_InputReader_::read( )
|
void T_InputReader_::read( )
|
||||||
{
|
{
|
||||||
size_t bsz( 0 );
|
size_t bsz( 0 );
|
||||||
while ( ( readCount = getline( &buffer , &bsz , file ) ) != -1 ) {
|
while ( ( readCount = getline( &buffer , &bsz , file ) ) != -1 ) {
|
||||||
line ++;
|
line ++;
|
||||||
|
@ -72,16 +77,16 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addAccumulated( );
|
addAccumulated( );
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_InputReader_::nl( )
|
void T_InputReader_::nl( )
|
||||||
{
|
{
|
||||||
accumLines ++;
|
accumLines ++;
|
||||||
accumulator += '\n';
|
accumulator += '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_InputReader_::addAccumulated( )
|
void T_InputReader_::addAccumulated( )
|
||||||
{
|
{
|
||||||
if ( accumLines ) {
|
if ( accumLines ) {
|
||||||
auto& ck( input.chunks );
|
auto& ck( input.chunks );
|
||||||
ck.emplace_back( E_ShaderInputChunk::CODE ,
|
ck.emplace_back( E_ShaderInputChunk::CODE ,
|
||||||
|
@ -89,11 +94,11 @@ namespace {
|
||||||
accumulator = {};
|
accumulator = {};
|
||||||
accumLines = 0;
|
accumLines = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_InputReader_::handleDirective(
|
void T_InputReader_::handleDirective(
|
||||||
__rd__ T_Tokens_ const& tokens )
|
__rd__ T_Tokens_ const& tokens )
|
||||||
{
|
{
|
||||||
auto const& directive( tokens[ 0 ] );
|
auto const& directive( tokens[ 0 ] );
|
||||||
|
|
||||||
if ( directive == "include" ) {
|
if ( directive == "include" ) {
|
||||||
|
@ -123,14 +128,14 @@ namespace {
|
||||||
nl( );
|
nl( );
|
||||||
error( "unknown directive" );
|
error( "unknown directive" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_InputReader_::error(
|
void T_InputReader_::error(
|
||||||
__rd__ std::string const& err )
|
__rd__ std::string const& err )
|
||||||
{
|
{
|
||||||
input.errors.push_back( T_ShaderInputError{
|
input.errors.push_back( T_ShaderInputError{
|
||||||
line , err } );
|
line , err } );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue