Merge branch 'api2021'

This commit is contained in:
Tomasz Sowa 2021-05-28 16:11:50 +02:00
commit 3b858650f2
3 changed files with 44 additions and 44 deletions

View File

@ -154,8 +154,8 @@ private:
Vars * pvars; Vars * pvars;
// pointer to the output streams map (can be null) // pointer to the output streams map (can be null)
// output stream will be created when [ezc out "stream_name"] statement is found // output stream will be created when [ezc frame "stream_name"] statement is found
OutStreams<StreamType> * output_stream_map; OutStreams<StreamType> * output_frames_streams;
// temporary error messages // temporary error messages
std::wstring temp_msg; std::wstring temp_msg;
@ -168,8 +168,8 @@ private:
bool trim_white; bool trim_white;
bool skip_new_line; bool skip_new_line;
size_t ezc_out_stack_index; size_t ezc_frames_stack_index;
size_t ezc_out_stack_size; size_t ezc_frames_stack_size;
size_t stack_index; size_t stack_index;
size_t stack_size; size_t stack_size;
@ -179,7 +179,7 @@ private:
// we have to use a pointers table because standard streams such // we have to use a pointers table because standard streams such
// as std::wostringstream are not copyable // as std::wostringstream are not copyable
std::vector<StreamType*> filter_tab; std::vector<StreamType*> filter_tab;
std::vector<StreamType*> ezc_out_stack_tab; std::vector<StreamType*> ezc_frame_stack_tab;
const StreamType empty_stream; const StreamType empty_stream;
// temporary streams used in [if..] [for...] or [def ...] // temporary streams used in [if..] [for...] or [def ...]
@ -219,13 +219,13 @@ private:
void ResizeFilterTab(); void ResizeFilterTab();
void ResizeStack(); void ResizeStack();
void ResizeBlockStack(); void ResizeBlockStack();
void ResizeEzcOutStack(); void ResizeEzcFrameStack();
void ClearStreamStack(std::vector<StreamType*> & stream_tab); void ClearStreamStack(std::vector<StreamType*> & stream_tab);
void ClearFilterTab(); void ClearFilterTab();
void ClearForStack(); void ClearForStack();
void ClearBlockStack(); void ClearBlockStack();
void ClearEzcOutTab(); void ClearEzcFrameTab();
void ClearStream(StreamType & str); void ClearStream(StreamType & str);
void RemoveStackFunData(Stack & sitem); void RemoveStackFunData(Stack & sitem);
@ -335,7 +335,7 @@ private:
void MakeTextEzc(Item & item); void MakeTextEzc(Item & item);
void MakeTextReturn(Item & item); void MakeTextReturn(Item & item);
void MakeText(Item & item); void MakeText(Item & item);
void MakeEzcOut(Item & item); void MakeEzcFrame(Item & item);
void Generate(); void Generate();
@ -366,7 +366,7 @@ Generator<StreamType>::Generator() : empty_stream()
is_generator_working = false; is_generator_working = false;
stack_size = 300; stack_size = 300;
block_stack_size = 64; block_stack_size = 64;
ezc_out_stack_size = 16; ezc_frames_stack_size = 16;
can_find_in_cache = true; can_find_in_cache = true;
can_use_vars = true; can_use_vars = true;
expression_parser = nullptr; expression_parser = nullptr;
@ -403,7 +403,7 @@ Generator<StreamType> & Generator<StreamType>::operator=(const Generator<StreamT
filter_size = n.filter_size; filter_size = n.filter_size;
stack_size = n.stack_size; stack_size = n.stack_size;
block_stack_size = n.block_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; expression_parser = n.expression_parser;
program_mode = n.program_mode; 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 filter tab
// don't copy stack // don't copy stack
// don't copy ezc_out_stack_tab // don't copy ezc_frame_stack_tab
// don't copy output_stream and output_stream_map // don't copy output_stream and output_frames_streams
// !! CHECK ME // !! CHECK ME
// may copying should be denied when generator is working? // may copying should be denied when generator is working?
@ -430,7 +430,7 @@ Generator<StreamType>::~Generator()
ClearFilterTab(); ClearFilterTab();
ClearForStack(); ClearForStack();
ClearBlockStack(); ClearBlockStack();
ClearEzcOutTab(); ClearEzcFrameTab();
} }
@ -584,9 +584,9 @@ void Generator<StreamType>::ResizeFilterTab()
template<class StreamType> 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> 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(); ResizeFilterTab();
ResizeStack(); ResizeStack();
ResizeBlockStack(); ResizeBlockStack();
ResizeEzcOutStack(); ResizeEzcFrameStack();
filter_index = 0; filter_index = 0;
stack_index = 0; stack_index = 0;
block_stack_index = 0; block_stack_index = 0;
@ -793,7 +793,7 @@ template<class StreamType>
void Generator<StreamType>::Generate(StreamType & out) void Generator<StreamType>::Generate(StreamType & out)
{ {
output_stream = &out; output_stream = &out;
output_stream_map = 0; output_frames_streams = 0;
Generate(); Generate();
} }
@ -803,7 +803,7 @@ template<class StreamType>
void Generator<StreamType>::Generate(StreamType & out, OutStreams<StreamType> & out_streams) void Generator<StreamType>::Generate(StreamType & out, OutStreams<StreamType> & out_streams)
{ {
output_stream = &out; output_stream = &out;
output_stream_map = &out_streams; output_frames_streams = &out_streams;
Generate(); Generate();
} }
@ -812,7 +812,7 @@ template<class StreamType>
void Generator<StreamType>::Generate(OutStreams<StreamType> & out_streams) void Generator<StreamType>::Generate(OutStreams<StreamType> & out_streams)
{ {
output_stream = 0; output_stream = 0;
output_stream_map = &out_streams; output_frames_streams = &out_streams;
Generate(); Generate();
} }
@ -1380,7 +1380,7 @@ return res;
template<class StreamType> template<class StreamType>
void Generator<StreamType>::CopyTmpStreamToOutputStreams(Item::Function & fun, StreamType & ezc_out_tmp_stream, StreamType & previous_stream) 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 #ifdef EZC_HAS_SPECIAL_STREAM
const std::wstring & str = ezc_out_tmp_stream.Str(); 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) for(size_t s=0 ; s < fun.parameters.size() ; ++s)
{ {
std::wstring & name = fun.parameters[s]->name; 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 */ /* a new stream from the pool (output_stream_tab) is taken */
StreamType * stream = output_stream_map->streams_tab[ output_stream_map->streams_map.size() ]; StreamType * stream = output_frames_streams->streams_tab[ output_frames_streams->streams_map.size() ];
output_stream_map->streams_map.insert(std::make_pair(name, stream)); output_frames_streams->streams_map.insert(std::make_pair(name, stream));
ClearStream(*stream); ClearStream(*stream);
stream->write(str.c_str(), str.size()); 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) 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 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> template<class StreamType>
void Generator<StreamType>::MakeEzcOut(Item & item) void Generator<StreamType>::MakeEzcFrame(Item & item)
{ {
std::vector<std::wstring*> output_stream_names; std::vector<std::wstring*> output_stream_names;
StreamType * old_stream; StreamType * old_stream;
bool stream_added = true; 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; 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 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; stream_added = false;
if( stream_added ) if( stream_added )
{ {
old_stream = output_stream; 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); ClearStream(*output_stream);
ezc_out_stack_index += 1; ezc_frames_stack_index += 1;
} }
if( !item.item_tab.empty() ) if( !item.item_tab.empty() )
@ -1880,7 +1880,7 @@ bool stream_added = true;
CopyTmpStreamToOutputStreams(item.function, *output_stream, *old_stream); CopyTmpStreamToOutputStreams(item.function, *output_stream, *old_stream);
ClearStream(*output_stream); ClearStream(*output_stream);
output_stream = old_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> template<class StreamType>
void Generator<StreamType>::MakeTextEzc(Item & item) void Generator<StreamType>::MakeTextEzc(Item & item)
{ {
if( item.function.name == L"out" ) if( item.function.name == L"frame" )
MakeEzcOut(item); MakeEzcFrame(item);
// in the future we can use more builtin functions // in the future we can use more builtin functions
} }

View File

@ -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.type = Item::item_ezc;
item.has_function = true; item.has_function = true;
item.function.Clear(); item.function.Clear();
item.function.name = L"out"; item.function.name = L"frame";
item.function.is_function = true; item.function.is_function = true;
if( !ReadParams(item.function) ) if( !ReadParams(item.function) )
@ -944,7 +944,7 @@ std::wstring name;
else if( name == L"let?" ) ReadDirectiveLetIfNotSet(item); else if( name == L"let?" ) ReadDirectiveLetIfNotSet(item);
else if( name == L"filter" ) ReadDirectiveFilter(item); else if( name == L"filter" ) ReadDirectiveFilter(item);
else if( name == L"ezc" ) ReadDirectiveEzc(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"block" ) ReadDirectiveBlock(item);
else if( name == L"return" ) ReadDirectiveReturn(item); else if( name == L"return" ) ReadDirectiveReturn(item);
else if( name == L"#" ) ReadDirectiveComment(item); else if( name == L"#" ) ReadDirectiveComment(item);

View File

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