Skip to content

Commit

Permalink
preprocessor: split preprocessor into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Jul 7, 2024
1 parent 434920a commit a19e02b
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 30 deletions.
2 changes: 2 additions & 0 deletions cmake.ysfx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ add_library(ysfx-private
"sources/ysfx_api_gfx_lice.hpp"
"sources/ysfx_eel_utils.cpp"
"sources/ysfx_eel_utils.hpp"
"sources/ysfx_preprocess.cpp"
"sources/ysfx_preprocess.hpp"
"sources/utility/sync_bitset.hpp"
"sources/base64/Base64.hpp")
target_compile_definitions(ysfx-private
Expand Down
1 change: 1 addition & 0 deletions sources/ysfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ysfx_config.hpp"
#include "ysfx_eel_utils.hpp"
#include "ysfx_api_eel.hpp"
#include "ysfx_preprocess.hpp"
#include <type_traits>
#include <algorithm>
#include <functional>
Expand Down
27 changes: 0 additions & 27 deletions sources/ysfx_api_eel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ static ysfx::mutex atomic_mutex;
#include "WDL/eel2/eel_fft.h"
#include "WDL/eel2/eel_mdct.h"
#include "WDL/eel2/eel_atomic.h"
#include "WDL/eel2/eel_pproc.h"

//------------------------------------------------------------------------------
void ysfx_api_init_eel()
Expand Down Expand Up @@ -146,29 +145,3 @@ void NSEEL_HOSTSTUB_EnterMutex()
void NSEEL_HOSTSTUB_LeaveMutex()
{
}

bool ysfx_preprocess(ysfx::text_reader &reader, ysfx_parse_error *error, std::string& in_str)
{
std::string line;
uint32_t lineno = 0;

line.reserve(256);

WDL_FastString file_str, pp_str;
while (reader.read_next_line(line)) {
line += "\n";
const char *linep = line.c_str();
file_str.Append(linep);
}

EEL2_PreProcessor pproc;
const char *err = pproc.preprocess(file_str.Get(), &pp_str);
if (err) {
error->line = 0;
error->message = std::string("Invalid section: ") + err;
return false;
}

in_str.append(pp_str.Get(), pp_str.GetLength());
return true;
}
2 changes: 0 additions & 2 deletions sources/ysfx_api_eel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,3 @@ struct ysfx_string_scoped_lock {
#define EEL_STRING_GET_FOR_INDEX(x, wr) (ysfx_string_access_unlocked((ysfx_t *)(opaque), x, wr, false))
#define EEL_STRING_GET_FOR_WRITE(x, wr) (ysfx_string_access_unlocked((ysfx_t *)(opaque), x, wr, true))
#define EEL_STRING_MUTEXLOCK_SCOPE ysfx_string_scoped_lock lock{(ysfx_t *)(opaque)};

bool ysfx_preprocess(ysfx::text_reader &reader, ysfx_parse_error *error, std::string &str);
53 changes: 53 additions & 0 deletions sources/ysfx_preprocess.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2024 Joep Vanlier
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//

#include "ysfx.hpp"
#include "ysfx_utils.hpp"

#include "WDL/ptrlist.h"
#include "WDL/assocarray.h"
#include "WDL/mutex.h"

#include "WDL/wdlstring.h"
#include "WDL/eel2/eel_pproc.h"


bool ysfx_preprocess(ysfx::text_reader &reader, ysfx_parse_error *error, std::string& in_str)
{
std::string line;
uint32_t lineno = 0;

line.reserve(256);

WDL_FastString file_str, pp_str;
while (reader.read_next_line(line)) {
line += "\n";
const char *linep = line.c_str();
file_str.Append(linep);
}

EEL2_PreProcessor pproc;
const char *err = pproc.preprocess(file_str.Get(), &pp_str);
if (err) {
error->line = 0;
error->message = std::string("Invalid section: ") + err;
return false;
}

in_str.append(pp_str.Get(), pp_str.GetLength());
return true;
}
5 changes: 5 additions & 0 deletions sources/ysfx_preprocess.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include "ysfx.h"
#include <string>

bool ysfx_preprocess(ysfx::text_reader &reader, ysfx_parse_error *error, std::string& in_str);
1 change: 1 addition & 0 deletions tests/ysfx_test_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//

#include "ysfx.hpp"
#include "ysfx_preprocess.hpp"
#include "ysfx_parse.hpp"
#include "ysfx_test_utils.hpp"
#include <catch.hpp>
Expand Down
2 changes: 1 addition & 1 deletion tests/ysfx_test_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ TEST_CASE("save and load", "[serialization]")
REQUIRE(ysfx::unpack_f32le(&state->data[2 * sizeof(float)]) == 200);
REQUIRE(ysfx::unpack_f32le(&state->data[3 * sizeof(float)]) == 300);
REQUIRE(ysfx::unpack_f32le(&state->data[4 * sizeof(float)]) == 400);
};
};
}

0 comments on commit a19e02b

Please sign in to comment.