XML: better descriptions on a couple errors, more accurate line number reporting ( was overshooting ), better clean-up of memory

mingw/directory: move msvc fix for popen with the rest of the code that got moved
rbuild.dsp: added new files to project

svn path=/trunk/; revision=19611
This commit is contained in:
Royce Mitchell III 2005-11-26 04:24:17 +00:00
parent 78a317ae32
commit d8910a54b1
5 changed files with 66 additions and 21 deletions

View file

@ -348,6 +348,13 @@ XMLFile::get_token(string& token)
return true; return true;
} }
bool
XMLFile::get_token ( string& token, string& location )
{
location = Location();
return get_token ( token );
}
string string
XMLFile::Location() const XMLFile::Location() const
{ {
@ -547,8 +554,8 @@ XMLParse ( XMLFile& f,
const Path& path, const Path& path,
bool* pend_tag = NULL ) bool* pend_tag = NULL )
{ {
string token; string token, location;
if ( !f.get_token(token) ) if ( !f.get_token(token,location) )
return NULL; return NULL;
bool end_tag, is_include = false; bool end_tag, is_include = false;
@ -557,15 +564,15 @@ XMLParse ( XMLFile& f,
|| !strncmp ( token.c_str (), "<?", 2 ) ) || !strncmp ( token.c_str (), "<?", 2 ) )
{ {
if ( token[0] != '<' ) if ( token[0] != '<' )
throw XMLSyntaxErrorException ( f.Location (), throw XMLSyntaxErrorException ( location,
"expecting xml tag, not '%s'", "expecting xml tag, not '%s'",
token.c_str () ); token.c_str () );
if ( !f.get_token(token) ) if ( !f.get_token(token,location) )
return NULL; return NULL;
} }
XMLElement* e = new XMLElement ( &f, XMLElement* e = new XMLElement ( &f,
f.Location () ); location );
bool bNeedEnd = e->Parse ( token, end_tag ); bool bNeedEnd = e->Parse ( token, end_tag );
if ( e->name == "xi:include" && includes ) if ( e->name == "xi:include" && includes )
@ -586,7 +593,7 @@ XMLParse ( XMLFile& f,
else if ( end_tag ) else if ( end_tag )
{ {
delete e; delete e;
throw XMLSyntaxErrorException ( f.Location (), throw XMLSyntaxErrorException ( location,
"end tag '%s' not expected", "end tag '%s' not expected",
token.c_str() ); token.c_str() );
return NULL; return NULL;
@ -598,27 +605,27 @@ XMLParse ( XMLFile& f,
{ {
if ( f.next_is_text () ) if ( f.next_is_text () )
{ {
if ( !f.get_token ( token ) || token.size () == 0 ) if ( !f.get_token ( token, location ) || token.size () == 0 )
{ {
throw InvalidBuildFileException ( throw InvalidBuildFileException (
f.Location(), location,
"internal tool error - get_token() failed when more_tokens() returned true" ); "internal tool error - get_token() failed when more_tokens() returned true" );
break; break;
} }
if ( e->subElements.size() && !bThisMixingErrorReported ) if ( e->subElements.size() && !bThisMixingErrorReported )
{ {
throw XMLSyntaxErrorException ( f.Location (), throw XMLSyntaxErrorException ( location,
"mixing of inner text with sub elements" ); "mixing of inner text with sub elements" );
bThisMixingErrorReported = true; bThisMixingErrorReported = true;
} }
if ( strchr ( token.c_str (), '>' ) ) if ( strchr ( token.c_str (), '>' ) )
{ {
throw XMLSyntaxErrorException ( f.Location (), throw XMLSyntaxErrorException ( location,
"invalid symbol '>'" ); "invalid symbol '>'" );
} }
if ( e->value.size() > 0 ) if ( e->value.size() > 0 )
{ {
throw XMLSyntaxErrorException ( f.Location (), throw XMLSyntaxErrorException ( location,
"multiple instances of inner text" ); "multiple instances of inner text" );
e->value += " " + token; e->value += " " + token;
} }
@ -628,20 +635,33 @@ XMLParse ( XMLFile& f,
else else
{ {
XMLElement* e2 = XMLParse ( f, is_include ? NULL : includes, path, &end_tag ); XMLElement* e2 = XMLParse ( f, is_include ? NULL : includes, path, &end_tag );
if ( e->name == "project" && e2->name == "1" )
e = e;
if ( !e2 ) if ( !e2 )
{ {
string e_location = e->location;
string e_name = e->name;
delete e;
throw InvalidBuildFileException ( throw InvalidBuildFileException (
e->location, e_location,
"end of file found looking for end tag" ); "end of file found looking for end tag: </%s>",
e_name.c_str() );
break; break;
} }
if ( end_tag ) if ( end_tag )
{ {
if ( e->name != e2->name ) if ( e->name != e2->name )
{ {
string e2_location = e2->location;
string e_name = e->name;
string e2_name = e2->name;
delete e;
delete e2; delete e2;
throw XMLSyntaxErrorException ( f.Location (), throw XMLSyntaxErrorException (
"end tag name mismatch" ); e2_location,
"end tag name mismatch - found </%s> but was expecting </%s>",
e2_name.c_str(),
e_name.c_str() );
break; break;
} }
delete e2; delete e2;
@ -649,7 +669,9 @@ XMLParse ( XMLFile& f,
} }
if ( e->value.size () > 0 && !bThisMixingErrorReported ) if ( e->value.size () > 0 && !bThisMixingErrorReported )
{ {
throw XMLSyntaxErrorException ( f.Location (), string e_location = e->location;
delete e;
throw XMLSyntaxErrorException ( e_location,
"mixing of inner text with sub elements" ); "mixing of inner text with sub elements" );
bThisMixingErrorReported = true; bThisMixingErrorReported = true;
} }

View file

@ -81,7 +81,8 @@ public:
void next_token(); void next_token();
bool next_is_text(); bool next_is_text();
bool more_tokens(); bool more_tokens();
bool get_token(std::string& token); bool get_token ( std::string& token );
bool get_token ( std::string& token, std::string& location );
const std::string& filename() { return _filename; } const std::string& filename() { return _filename; }
std::string Location() const; std::string Location() const;

View file

@ -21,6 +21,11 @@
#include <assert.h> #include <assert.h>
#include "modulehandler.h" #include "modulehandler.h"
#ifdef _MSC_VER
#define popen _popen
#define pclose _pclose
#endif//_MSC_VER
using std::string; using std::string;
using std::vector; using std::vector;
using std::set; using std::set;

View file

@ -19,10 +19,7 @@
#include <assert.h> #include <assert.h>
#include "rbuild.h" #include "rbuild.h"
#ifdef _MSC_VER #ifndef _MSC_VER
#define popen _popen
#define pclose _pclose
#else
#include <dirent.h> #include <dirent.h>
#endif//_MSC_VER #endif//_MSC_VER

View file

@ -181,6 +181,14 @@ SOURCE=.\cdfile.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\compilationunit.cpp
# End Source File
# Begin Source File
SOURCE=.\compilationunitsupportcode.cpp
# End Source File
# Begin Source File
SOURCE=.\compilerflag.cpp SOURCE=.\compilerflag.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
@ -193,6 +201,10 @@ SOURCE=.\define.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\directory.cpp
# End Source File
# Begin Source File
SOURCE=.\exception.cpp SOURCE=.\exception.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
@ -201,6 +213,10 @@ SOURCE=.\filesupportcode.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\global.cpp
# End Source File
# Begin Source File
SOURCE=.\include.cpp SOURCE=.\include.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
@ -213,6 +229,10 @@ SOURCE=.\linkerflag.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\linkerscript.cpp
# End Source File
# Begin Source File
SOURCE=.\module.cpp SOURCE=.\module.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File