Browse Source

Merge branch 'api2021'

master
Tomasz Sowa 4 weeks ago
parent
commit
3b858650f2
  1. 78
      src/generator.h
  2. 8
      src/patternparser.cpp
  3. 2
      src/patternparser.h

78
src/generator.h

@ -154,8 +154,8 @@ private:
Vars * pvars;
// pointer to the output streams map (can be null)
// output stream will be created when [ezc out "stream_name"] statement is found
OutStreams<StreamType> * output_stream_map;
// output stream will be created when [ezc frame "stream_name"] statement is found
OutStreams<StreamType> * output_frames_streams;
// temporary error messages
std::wstring temp_msg;
@ -168,8 +168,8 @@ private:
bool trim_white;
bool skip_new_line;
size_t ezc_out_stack_index;
size_t ezc_out_stack_size;
size_t ezc_frames_stack_index;
size_t ezc_frames_stack_size;
size_t stack_index;
size_t stack_size;
@ -179,7 +179,7 @@ private:
// we have to use a pointers table because standard streams such
// as std::wostringstream are not copyable
std::vector<StreamType*> filter_tab;
std::vector<StreamType*> ezc_out_stack_tab;
std::vector<StreamType*> ezc_frame_stack_tab;
const StreamType empty_stream;
// temporary streams used in [if..] [for...] or [def ...]
@ -219,13 +219,13 @@ private:
void ResizeFilterTab();
void ResizeStack();
void ResizeBlockStack();
void ResizeEzcOutStack();
void ResizeEzcFrameStack();
void ClearStreamStack(std::vector<StreamType*> & stream_tab);
void ClearFilterTab();
void ClearForStack();
void ClearBlockStack();
void ClearEzcOutTab();
void ClearEzcFrameTab();
void ClearStream(StreamType & str);
void RemoveStackFunData(Stack & sitem);
@ -335,7 +335,7 @@ private:
void MakeTextEzc(Item & item);
void MakeTextReturn(Item & item);
void MakeText(Item & item);
void MakeEzcOut(Item & item);
void MakeEzcFrame(Item & item);
void Generate();
@ -366,7 +366,7 @@ Generator<StreamType>::Generator() : empty_stream()
is_generator_working = false;
stack_size = 300;
block_stack_size = 64;
ezc_out_stack_size = 16;
ezc_frames_stack_size = 16;
can_find_in_cache = true;
can_use_vars = true;
expression_parser = nullptr;
@ -403,7 +403,7 @@ Generator<StreamType> & Generator<StreamType>::operator=(const Generator<StreamT
filter_size = n.filter_size;
stack_size = n.stack_size;
block_stack_size = n.block_stack_size;
ezc_out_stack_size = n.ezc_out_stack_size;
ezc_frames_stack_size = n.ezc_frames_stack_size;
expression_parser = n.expression_parser;
program_mode = n.program_mode;
@ -411,8 +411,8 @@ Generator<StreamType> & Generator<StreamType>::operator=(const Generator<StreamT
// don't copy filter tab
// don't copy stack
// don't copy ezc_out_stack_tab
// don't copy output_stream and output_stream_map
// don't copy ezc_frame_stack_tab
// don't copy output_stream and output_frames_streams
// !! CHECK ME
// may copying should be denied when generator is working?
@ -430,7 +430,7 @@ Generator<StreamType>::~Generator()
ClearFilterTab();
ClearForStack();
ClearBlockStack();
ClearEzcOutTab();
ClearEzcFrameTab();
}
@ -584,9 +584,9 @@ void Generator<StreamType>::ResizeFilterTab()
template<class StreamType>
void Generator<StreamType>::ResizeEzcOutStack()
void Generator<StreamType>::ResizeEzcFrameStack()
{
ResizeStreamStack(ezc_out_stack_tab, ezc_out_stack_size);
ResizeStreamStack(ezc_frame_stack_tab, ezc_frames_stack_size);
}
@ -635,9 +635,9 @@ void Generator<StreamType>::ClearFilterTab()
template<class StreamType>
void Generator<StreamType>::ClearEzcOutTab()
void Generator<StreamType>::ClearEzcFrameTab()
{
ClearStreamStack(ezc_out_stack_tab);
ClearStreamStack(ezc_frame_stack_tab);
}
@ -765,7 +765,7 @@ void Generator<StreamType>::Generate()
ResizeFilterTab();
ResizeStack();
ResizeBlockStack();
ResizeEzcOutStack();
ResizeEzcFrameStack();
filter_index = 0;
stack_index = 0;
block_stack_index = 0;
@ -793,7 +793,7 @@ template<class StreamType>
void Generator<StreamType>::Generate(StreamType & out)
{
output_stream = &out;
output_stream_map = 0;
output_frames_streams = 0;
Generate();
}
@ -803,7 +803,7 @@ template<class StreamType>
void Generator<StreamType>::Generate(StreamType & out, OutStreams<StreamType> & out_streams)
{
output_stream = &out;
output_stream_map = &out_streams;
output_frames_streams = &out_streams;
Generate();
}
@ -812,7 +812,7 @@ template<class StreamType>
void Generator<StreamType>::Generate(OutStreams<StreamType> & out_streams)
{
output_stream = 0;
output_stream_map = &out_streams;
output_frames_streams = &out_streams;
Generate();
}
@ -1380,7 +1380,7 @@ return res;
template<class StreamType>
void Generator<StreamType>::CopyTmpStreamToOutputStreams(Item::Function & fun, StreamType & ezc_out_tmp_stream, StreamType & previous_stream)
{
if( output_stream_map )
if( output_frames_streams )
{
#ifdef EZC_HAS_SPECIAL_STREAM
const std::wstring & str = ezc_out_tmp_stream.Str();
@ -1395,15 +1395,15 @@ void Generator<StreamType>::CopyTmpStreamToOutputStreams(Item::Function & fun, S
for(size_t s=0 ; s < fun.parameters.size() ; ++s)
{
std::wstring & name = fun.parameters[s]->name;
auto imap = output_stream_map->streams_map.find(name);
auto imap = output_frames_streams->streams_map.find(name);
if( imap == output_stream_map->streams_map.end() )
if( imap == output_frames_streams->streams_map.end() )
{
if( output_stream_map->streams_map.size() < output_stream_map->streams_tab.size() )
if( output_frames_streams->streams_map.size() < output_frames_streams->streams_tab.size() )
{
/* a new stream from the pool (output_stream_tab) is taken */
StreamType * stream = output_stream_map->streams_tab[ output_stream_map->streams_map.size() ];
output_stream_map->streams_map.insert(std::make_pair(name, stream));
StreamType * stream = output_frames_streams->streams_tab[ output_frames_streams->streams_map.size() ];
output_frames_streams->streams_map.insert(std::make_pair(name, stream));
ClearStream(*stream);
stream->write(str.c_str(), str.size());
}
@ -1839,37 +1839,37 @@ void Generator<StreamType>::MakeTextFilter(Item & item)
/*
although we are using a stack for [etc out] there is no need for the stack now
although we are using a stack for [etc frame] there is no need for the stack now
because the output is only a one-level map (not nested structure)
but in the future we can use more complicated class like pt::Space
and then nested [ezc out] statements can product a better output
and then nested [ezc frame] statements can product a better output
*/
template<class StreamType>
void Generator<StreamType>::MakeEzcOut(Item & item)
void Generator<StreamType>::MakeEzcFrame(Item & item)
{
std::vector<std::wstring*> output_stream_names;
StreamType * old_stream;
bool stream_added = true;
if( ezc_out_stack_index >= ezc_out_stack_tab.size() )
if( ezc_frames_stack_index >= ezc_frame_stack_tab.size() )
{
CreateMsg(L"Generator exceeded allowed number of [ezc out] statements");
CreateMsg(L"Generator exceeded allowed number of [ezc frame] statements");
return;
}
/*
if we encounter the first ezc_out statement without arguments e.g. [ezc out] or just [out]
if we encounter the first ezc frame statement without arguments e.g. [ezc frame] or just [frame]
then we can simply ignore it
*/
if( item.function.parameters.empty() && ezc_out_stack_index == 0 )
if( item.function.parameters.empty() && ezc_frames_stack_index == 0 )
stream_added = false;
if( stream_added )
{
old_stream = output_stream;
output_stream = ezc_out_stack_tab[ezc_out_stack_index];
output_stream = ezc_frame_stack_tab[ezc_frames_stack_index];
ClearStream(*output_stream);
ezc_out_stack_index += 1;
ezc_frames_stack_index += 1;
}
if( !item.item_tab.empty() )
@ -1880,7 +1880,7 @@ bool stream_added = true;
CopyTmpStreamToOutputStreams(item.function, *output_stream, *old_stream);
ClearStream(*output_stream);
output_stream = old_stream;
ezc_out_stack_index -= 1;
ezc_frames_stack_index -= 1;
}
}
@ -1889,8 +1889,8 @@ bool stream_added = true;
template<class StreamType>
void Generator<StreamType>::MakeTextEzc(Item & item)
{
if( item.function.name == L"out" )
MakeEzcOut(item);
if( item.function.name == L"frame" )
MakeEzcFrame(item);
// in the future we can use more builtin functions
}

8
src/patternparser.cpp

@ -878,15 +878,15 @@ void PatternParser::ReadDirectiveEzc(Item & item)
/*
[out] is a shorthand for [ezc out]
[frame] is a shorthand for [ezc frame]
*/
void PatternParser::ReadDirectiveOut(Item & item)
void PatternParser::ReadDirectiveFrame(Item & item)
{
item.type = Item::item_ezc;
item.has_function = true;
item.function.Clear();
item.function.name = L"out";
item.function.name = L"frame";
item.function.is_function = true;
if( !ReadParams(item.function) )
@ -944,7 +944,7 @@ std::wstring name;
else if( name == L"let?" ) ReadDirectiveLetIfNotSet(item);
else if( name == L"filter" ) ReadDirectiveFilter(item);
else if( name == L"ezc" ) ReadDirectiveEzc(item);
else if( name == L"out" ) ReadDirectiveOut(item);
else if( name == L"frame" ) ReadDirectiveFrame(item);
else if( name == L"block" ) ReadDirectiveBlock(item);
else if( name == L"return" ) ReadDirectiveReturn(item);
else if( name == L"#" ) ReadDirectiveComment(item);

2
src/patternparser.h

@ -180,7 +180,7 @@ private:
void ReadDirectiveLetIfNotSet(Item & item);
void ReadDirectiveFilter(Item & item);
void ReadDirectiveEzc(Item & item);
void ReadDirectiveOut(Item & item);
void ReadDirectiveFrame(Item & item);
void ReadDirectiveBlock(Item & item);
void ReadDirectiveReturn(Item & item);
void ReadNormalStatement(Item & item);

Loading…
Cancel
Save