VapourSynth-llvmexpr
Loading...
Searching...
No Matches
InfixConverter.cpp File Reference
#include "InfixConverter.hpp"
#include "infix2postfix/AnalysisEngine.hpp"
#include "infix2postfix/Preprocessor.hpp"
#include "infix2postfix/Tokenizer.hpp"
#include <format>
#include <stdexcept>
Include dependency graph for InfixConverter.cpp:

Go to the source code of this file.

Functions

std::string convert_infix_to_postfix (const std::string &infix_expr, int num_inputs, infix2postfix::Mode mode, const std::map< std::string, std::string > *predefined_macros, int num_intermediate_inputs)

Function Documentation

◆ convert_infix_to_postfix()

std::string convert_infix_to_postfix ( const std::string & infix_expr,
int num_inputs,
infix2postfix::Mode mode,
const std::map< std::string, std::string > * predefined_macros,
int num_intermediate_inputs )

Copyright (C) 2025 yuygfgg

This file is part of Vapoursynth-llvmexpr.

Vapoursynth-llvmexpr is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Vapoursynth-llvmexpr is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Vapoursynth-llvmexpr. If not, see https://www.gnu.org/licenses/.

Definition at line 28 of file InfixConverter.cpp.

31 {
32 try {
33 std::string preprocessed_source = infix_expr;
34 std::vector<infix2postfix::LineMapping> line_map;
35 int library_line_count = 0;
36
37 if (predefined_macros != nullptr) {
38 infix2postfix::Preprocessor preprocessor(infix_expr);
39
40 for (const auto& [name, value] : *predefined_macros) {
41 preprocessor.addPredefinedMacro(name, value);
42 }
43
44 auto preprocess_result = preprocessor.process();
45
46 if (!preprocess_result.success) {
47 std::string error_msg = "Preprocessing errors:\n";
48 for (const auto& error : preprocess_result.errors) {
49 error_msg += error + "\n";
50 }
51 throw std::runtime_error(error_msg);
52 }
53
54 preprocessed_source = preprocess_result.source;
55 line_map = preprocess_result.line_map;
56 library_line_count = preprocess_result.library_line_count;
57 }
58
59 infix2postfix::Tokenizer tokenizer(preprocessed_source);
60 auto tokens = tokenizer.tokenize();
61
62 infix2postfix::AnalysisEngine engine(tokens, mode, num_inputs,
63 num_intermediate_inputs, line_map,
64 library_line_count);
65 bool success = engine.runAnalysis();
66
67 if (!success) {
68 std::string diagnostics = engine.formatDiagnostics();
69 throw std::runtime_error(diagnostics);
70 }
71
72 return engine.generateCode();
73 } catch (const std::exception& e) {
74 throw std::runtime_error(
75 std::format("Infix to postfix conversion error: {}", e.what()));
76 }
77}

References infix2postfix::Preprocessor::addPredefinedMacro(), infix2postfix::AnalysisEngine::formatDiagnostics(), infix2postfix::AnalysisEngine::generateCode(), infix2postfix::Preprocessor::process(), infix2postfix::AnalysisEngine::runAnalysis(), infix2postfix::PreprocessResult::source, and infix2postfix::Tokenizer::tokenize().