|
From: <ma...@us...> - 2009-09-09 20:21:03
|
Revision: 298
http://scstudio.svn.sourceforge.net/scstudio/?rev=298&view=rev
Author: madzin
Date: 2009-09-09 20:20:52 +0000 (Wed, 09 Sep 2009)
Log Message:
-----------
Add new test and fix some errors
Modified Paths:
--------------
trunk/src/data/Z120/Context.cpp
trunk/src/data/Z120/Context.h
trunk/src/data/Z120/Z120.g
trunk/src/data/Z120/z120.h
trunk/src/data/Z120/z120_load.cpp
trunk/tests/z120_test/z120_test.cpp
Added Paths:
-----------
trunk/tests/z120_test/z120_test38.mpr
trunk/tests/z120_test/z120_test39.mpr
trunk/tests/z120_test/z120_test40.mpr
Modified: trunk/src/data/Z120/Context.cpp
===================================================================
--- trunk/src/data/Z120/Context.cpp 2009-09-09 14:17:15 UTC (rev 297)
+++ trunk/src/data/Z120/Context.cpp 2009-09-09 20:20:52 UTC (rev 298)
@@ -21,6 +21,9 @@
* see http://www.antlr.org
*/
+/*
+ * Maximal number of warning/error message is 19
+ */
#ifndef __ParserStruct__
#define __ParserStruct__
@@ -48,7 +51,7 @@
/*
* Textual file
*/
- std::map<std::string, MscPtr> mscs; //map of msc in the file
+ std::multimap<std::string, MscPtr> mscs; //map of msc in the file
std::set<std::string> nonpointed; //msc which is not refered
std::map<std::string, std::set<ReferenceNodePtr> > future_reference; //map of name of nodes on which was refered and does not exist
Z120* z;
@@ -67,6 +70,7 @@
EventPtr current_event; //event which was currently created
std::string event_name; //name of event
int not_create_event;
+ int no_message_label;
/*
* HMsc
@@ -118,6 +122,7 @@
context->named_events.clear();
context->current_event = NULL;
context->not_create_event = 0;
+ context->no_message_label = 0;
context->start_node = NULL;
context->end_node = std::make_pair("", context->end_node.second); //replaice context->end_node.second with NULL
@@ -143,11 +148,8 @@
return NULL;
}
-struct s_Msc* get_total_msc_fun(struct Context* context)
+struct s_Msc** get_total_msc_fun(struct Context* context)
{
- Msc* my_msc = NULL;
-
-printf("asdfasdfa %d", context->nonpointed.size());
if(context->nonpointed.size() > 1)
{
context->z->print_report(RS_WARNING, L"Warning 02: There are more unreferenced MSC\n");
@@ -157,33 +159,45 @@
context->z->print_report(RS_ERROR, L"Error 03: There is no MSC without reference\n");
return NULL;
}
+
+ s_Msc** result;
+
if(context->mscs.size() > 0){
- my_msc = context->mscs.find(*(context->nonpointed.begin()))->second.get();
- }
+ result = new s_Msc*[context->mscs.size()+1];
+ std::multimap<std::string, MscPtr>::iterator mscs_it;
+ std::set<std::string>::iterator nonpointed_it;
+
+ int position = 0;
+
+ while(context->nonpointed.size() != 0){
+ nonpointed_it = context->nonpointed.begin();
- if(my_msc != NULL)
- {
- intrusive_ptr_add_ref(my_msc);
- }
- return static_cast<s_Msc*> (my_msc);
-}
-/*
-struct s_Msc** get_total_msc_fun(struct context)
- if(mscs.size > 0)
- i = 0;
- s_Msc** result = new s_Msc* [mscs.size+1];
- for x in mscs
- my_msc = *x;
- if my_msc != NULL;
- intrusive_ptr_add_ref(my_msc)
- result[i++] = my_msc;
-
- result[i] = NULL;
-//zo zaciatku tam dat nonpointed a potom ostatne.
+ for(int i = context->mscs.count(*nonpointed_it); i > 0; i--){
+ mscs_it = context->mscs.find(*nonpointed_it);
+ Msc* my_msc = mscs_it->second.get();
+ if(my_msc != NULL){
+ intrusive_ptr_add_ref(my_msc);
+ result[position++] = my_msc;
+ }
+ context->mscs.erase(mscs_it);
+ }
+ context->nonpointed.erase(nonpointed_it);
+ }
+
+ for(mscs_it = context->mscs.begin(); mscs_it != context->mscs.end(); mscs_it++){
+ Msc* my_msc = mscs_it->second.get();
+ if(my_msc != NULL){
+ intrusive_ptr_add_ref(my_msc);
+ result[position++] = my_msc;
+ }
+ }
+ result[position] = NULL;
+ }
+ return result;
}
-*/
+
/*
* Memory initialization.
*/
@@ -251,8 +265,7 @@
void msc_was_read_fun(struct Context* context)
{
if(context->mscs.find(context->msc_name) != context->mscs.end()){
- context->z->print_report(RS_WARNING, stringize() << "Warning 17: Two mscs have the same name (" << TOWSTRING(context->msc_name) << ")\n");
-// return ;
+ context->z->print_report(RS_WARNING, stringize() << "Warning 18: Two mscs have the same name (" << TOWSTRING(context->msc_name) << ")\n");
}
context->mscs.insert(std::make_pair(context->msc_name, get_msc_fun(context)));
@@ -305,16 +318,24 @@
std::string msg_identification(msg_identifications);
std::string msg_name;
- size_t pos = msg_identification.rfind(',');
- if(pos != 0)
+ if(context->no_message_label == 1)
{
- msg_name = msg_identification.substr(0, pos);
+ msg_name = "";
+ context->no_message_label = 0;
}
else
{
- msg_name = msg_identification;
+ size_t pos = msg_identification.rfind(',');
+ if(pos != 0)
+ {
+ msg_name = msg_identification.substr(0, pos);
+ }
+ else
+ {
+ msg_name = msg_identification;
+ }
}
-
+
InstancePtr instance = context->instances.find(context->element_name)->second;
if (instance->get_last() == NULL ||
@@ -429,7 +450,8 @@
InstancePtr instance = context->instances.find(context->element_name)->second;
context->coregion_area_finished.insert(context->element_name);
context->coregion_area_opened.erase(context->element_name);
- }
+
+}
else
{
context->z->print_report(RS_WARNING, stringize() << "Warning 11: Instance " << TOWSTRING(context->element_name) << " does not have open any coregion\n"); //check
@@ -449,14 +471,23 @@
//message identification
std::string msg_identification(msg_identifications);
std::string msg_name;
- size_t pos = msg_identification.rfind(',');
- if(pos != 0)
+
+ if(context->no_message_label == 1)
{
- msg_name = msg_identification.substr(0, pos);
+ msg_name = "";
+ context->no_message_label = 0;
}
else
{
- msg_name = msg_identification;
+ size_t pos = msg_identification.rfind(',');
+ if(pos != 0)
+ {
+ msg_name = msg_identification.substr(0, pos);
+ }
+ else
+ {
+ msg_name = msg_identification;
+ }
}
InstancePtr instance = context->instances.find(context->element_name)->second;
@@ -595,6 +626,12 @@
context->not_create_event = 0;
}
+void missing_message_label(struct Context* context)
+{
+ context->no_message_label = 1;
+ context->z->print_report(RS_WARNING, stringize() << L"Warning 19: There is message without label on the " << TOWSTRING(context->element_name) << " instance\n");
+}
+
/*
* FUNCTIONS FOR HMSC
*/
Modified: trunk/src/data/Z120/Context.h
===================================================================
--- trunk/src/data/Z120/Context.h 2009-09-09 14:17:15 UTC (rev 297)
+++ trunk/src/data/Z120/Context.h 2009-09-09 20:20:52 UTC (rev 298)
@@ -41,7 +41,7 @@
void init(struct Context* context);
-struct s_Msc* get_total_msc_fun(struct Context* context);
+struct s_Msc** get_total_msc_fun(struct Context* context);
struct Context* new_context();
@@ -80,6 +80,8 @@
void set_not_create_event(struct Context* context);
+void missing_message_label(struct Context* context);
+
//HMsc
void new_hmsc_fun(struct Context* context);
Modified: trunk/src/data/Z120/Z120.g
===================================================================
--- trunk/src/data/Z120/Z120.g 2009-09-09 14:17:15 UTC (rev 297)
+++ trunk/src/data/Z120/Z120.g 2009-09-09 20:20:52 UTC (rev 298)
@@ -155,7 +155,7 @@
// ----- Message Sequence Chart Document
// non-standard: Z.120 doesn't define top-level nonterminal
-textual_msc_file [struct s_Z120* my_z120] returns [struct s_Msc* my_msc]:
+textual_msc_file [struct s_Z120* my_z120] returns [struct s_Msc** my_msc]:
{
context = new_context();
if(my_z120 != NULL)
@@ -489,7 +489,11 @@
;
msg_identification:
- NAME (',' NAME)? ('(' parameter_list ')')?
+ (NAME (',' NAME)? |
+ ',' NAME
+ {
+ missing_message_label(context);
+ }) ('(' parameter_list ')')?
;
output_address:
Modified: trunk/src/data/Z120/z120.h
===================================================================
--- trunk/src/data/Z120/z120.h 2009-09-09 14:17:15 UTC (rev 297)
+++ trunk/src/data/Z120/z120.h 2009-09-09 20:20:52 UTC (rev 298)
@@ -42,7 +42,7 @@
#ifdef HAVE_ANTLR
//! import MSC document
- virtual MscPtr load_msc(const std::string &filename);
+ virtual std::vector<MscPtr> load_msc(const std::string &filename);
#endif
//! Returns a list of preconditions for this format.
virtual PreconditionList get_preconditions(MscPtr msc) const;
Modified: trunk/src/data/Z120/z120_load.cpp
===================================================================
--- trunk/src/data/Z120/z120_load.cpp 2009-09-09 14:17:15 UTC (rev 297)
+++ trunk/src/data/Z120/z120_load.cpp 2009-09-09 20:20:52 UTC (rev 298)
@@ -21,35 +21,44 @@
#include "Z120Lexer.h"
#include "Z120Parser.h"
-MscPtr Z120::load_msc(const std::string &filename)
+std::vector<MscPtr> Z120::load_msc(const std::string &filename)
{
+ std::vector<MscPtr> result;
+
pANTLR3_INPUT_STREAM input =
antlr3AsciiFileStreamNew((pANTLR3_UINT8)filename.c_str());
if (input == NULL || input < 0)
{
print_report(RS_ERROR,
stringize() << "Cannot open file '" << TOWSTRING(filename) << "'.");
- return NULL;
+ return result;
}
pZ120Lexer lxr = Z120LexerNew(input);
if (lxr == NULL)
- return NULL;
+ return result;
pANTLR3_COMMON_TOKEN_STREAM tstream =
antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lxr));
if (tstream == NULL)
- return NULL;
+ return result;
pZ120Parser psr = Z120ParserNew(tstream);
if (psr == NULL)
- return NULL;
+ return result;
- Msc* my_msc = static_cast<Msc*>(psr->textual_msc_file(psr, static_cast<s_Z120*>(this)));
- MscPtr result = my_msc;
+ Msc** my_mscs = (Msc**)(psr->textual_msc_file(psr, static_cast<s_Z120*>(this)));
+
+ for(int i = 0; my_mscs[i] != NULL; i++)
+ {
+ MscPtr msc = my_mscs[i];
+ result.push_back(msc);
// my_msc is an extern "C" pointer to an object pointed by smart pointers
// the counter was increased in get_msc_fun() to avoid premature delete
- intrusive_ptr_release(my_msc);
+ intrusive_ptr_release(my_mscs[i]);
+ }
+
+ delete[] my_mscs;
psr->free(psr); psr = NULL;
tstream->free(tstream); tstream = NULL;
Modified: trunk/tests/z120_test/z120_test.cpp
===================================================================
--- trunk/tests/z120_test/z120_test.cpp 2009-09-09 14:17:15 UTC (rev 297)
+++ trunk/tests/z120_test/z120_test.cpp 2009-09-09 20:20:52 UTC (rev 298)
@@ -63,8 +63,9 @@
return 1;
}
- MscPtr msc = z120.load_msc(argv[1]);
- if(msc != NULL)
+ std::vector<MscPtr> msc = z120.load_msc(argv[1]);
+
+ if(!msc.empty())
{
if(satisfied)
std::cout << "OK: " << argv[1] << " is correct, should be correct" << std::endl;
@@ -79,7 +80,7 @@
std::cout << std::endl;
- z120.save_msc(std::cout, TOWSTRING(filename), msc);
+ z120.save_msc(std::cout, TOWSTRING(filename), msc[0], msc);
free(path);
}
Added: trunk/tests/z120_test/z120_test38.mpr
===================================================================
--- trunk/tests/z120_test/z120_test38.mpr (rev 0)
+++ trunk/tests/z120_test/z120_test38.mpr 2009-09-09 20:20:52 UTC (rev 298)
@@ -0,0 +1,84 @@
+/***************************************************
+Example of document where two mscs have the same name (msc TWO)
+
+Anticipated result:
+
+Warning 18: Two mscs have the same name (Two)
+
+Warning 02: There are more unreferenced MSC
+
+
+mscdocument z120_test38;
+msc Stranka_1;
+initial connect L0;
+L0: reference One connect L1;
+L1: reference Two connect L2;
+L2: final;
+endmsc;
+msc Trick;
+inst NAME;
+inst NAME2;
+NAME: instance;
+out NAME,0 to NAME2;
+endinstance;
+NAME2: instance;
+in NAME,0 from NAME;
+endinstance;
+endmsc;
+msc Two;
+inst Second;
+inst First;
+Second: instance;
+out true,0 to First;
+endinstance;
+First: instance;
+in true,0 from Second;
+endinstance;
+endmsc;
+msc One;
+initial connect L0;
+L0: condition access connect L1;
+L1: final;
+endmsc;
+
+***************************************************/
+
+mscdocument Vykres2;
+
+msc Stranka_1;
+initial connect L0;
+L0: reference One connect L1;
+L1: reference Two connect L2;
+L2: final;
+endmsc;
+
+msc One;
+initial connect L0;
+L0: condition access connect L1;
+L1: final;
+endmsc;
+
+msc Trick;
+inst NAME;
+inst NAME2;
+NAME: instance;
+out NAME,0 to NAME2;
+endinstance;
+NAME2: instance;
+in NAME,0 from NAME;
+endinstance;
+endmsc;
+
+msc Two;
+inst Second;
+inst First;
+Second: instance;
+out true,0 to First;
+endinstance;
+First: instance;
+in true,0 from Second;
+endinstance;
+endmsc;
+
+msc Two;
+endmsc;
Added: trunk/tests/z120_test/z120_test39.mpr
===================================================================
--- trunk/tests/z120_test/z120_test39.mpr (rev 0)
+++ trunk/tests/z120_test/z120_test39.mpr 2009-09-09 20:20:52 UTC (rev 298)
@@ -0,0 +1,28 @@
+/*************************************************
+Example of HMSC where the end node has defined successor.
+
+Anticipated result:
+
+Warning 20: The end node of HMSC has defined successor
+
+mscdocument z120_test39;
+msc Stranka_1;
+initial connect L0;
+L0: reference Trick connect L1;
+L1: final;
+endmsc;
+msc Trick;
+endmsc;
+
+
+*************************************************/
+
+msc Trick;
+endmsc;
+
+msc Stranka_1;
+initial connect L0;
+L0: reference Trick connect L1;
+L1: final connect L0;
+endmsc;
+
Added: trunk/tests/z120_test/z120_test40.mpr
===================================================================
--- trunk/tests/z120_test/z120_test40.mpr (rev 0)
+++ trunk/tests/z120_test/z120_test40.mpr 2009-09-09 20:20:52 UTC (rev 298)
@@ -0,0 +1,62 @@
+/***********************************************
+Example of MSC where two MSC has the same name and one reference is to nondefined MSC.
+
+Anticipated result:
+
+Warning 18: Two mscs have the same name (Stranka_1)
+
+Warning 09: There is reference to nonexisted MSC
+
+
+mscdocument z120_test40;
+msc Stranka_1;
+initial connect L0;
+L0: reference One connect L1;
+L1: reference Two connect L2;
+L2: final;
+endmsc;
+msc One;
+initial connect L0;
+L0: condition access connect L1;
+L1: final;
+endmsc;
+msc Two;
+inst Second;
+inst First;
+Second: instance;
+out true,0 to First;
+endinstance;
+First: instance;
+in true,0 from Second;
+endinstance;
+endmsc;
+
+***********************************************/
+
+mscdocument Vykres2;
+msc Two;
+inst Second;
+inst First;
+Second: instance;
+out true,0 to First;
+endinstance;
+First: instance;
+in true,0 from Second;
+endinstance;
+endmsc;
+msc Stranka_1;
+initial connect L0;
+L0: reference One connect L1;
+L1: reference Two connect L2;
+L2: final;
+endmsc;
+msc One;
+initial connect L0;
+L0: condition access connect L1;
+L1: final;
+endmsc;
+msc Stranka_1;
+initial connect L0;
+L0: reference Trick connect L1;
+L1: final;
+endmsc;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|