You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(37) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(15) |
Feb
(26) |
Mar
(97) |
Apr
(224) |
May
(226) |
Jun
|
Jul
(3) |
Aug
(22) |
Sep
(48) |
Oct
|
Nov
|
Dec
(38) |
2004 |
Jan
(28) |
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(37) |
Jul
|
Aug
(73) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <bl...@us...> - 2003-05-01 08:12:33
|
Update of /cvsroot/cpptool/rfta/bin In directory sc8-pr-cvs1:/tmp/cvs-serv6500/bin Modified Files: lister.py Log Message: * now generated an index.html page with link to all parsed result and statistics. Index: lister.py =================================================================== RCS file: /cvsroot/cpptool/rfta/bin/lister.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** lister.py 30 Apr 2003 22:10:49 -0000 1.1 --- lister.py 1 May 2003 08:12:30 -0000 1.2 *************** *** 46,49 **** --- 46,141 ---- os.makedirs( directory ) + class Tag: + def __init__( self, name, content = None ): + self.name = name + self.attributes = {} + if content == None: + self.content = '' + else: + self.content = content + self.children = [] + self.new_line_after = False + + def write( self, file ): + file.write( '<' + self.name + self.makeAttributesDeclaration() + '>' ) + file.write( self.getContent() ) + for child in self.children: + child.write( file ) + file.write( '</' + self.name + '>' ) + if self.new_line_after: + file.write( os.linesep ) + + def __repr__( self ): + return str( ["<" + self.name + self.makeAttributesDeclaration() + ">", self.content, self.children ] ) + + def makeAttributesDeclaration( self ): + if len( self.attributes ) == 0: + return '' + declaration = '' + for attribute in self.attributes.iteritems(): + declaration += ' ' + attribute[0] + '="' + attribute[1] + '"' + return declaration + + def getContent( self ): + content = '' + escaped_char = { '&' : '&', '<' : '<', '>' : '>', '"' : '"' } + for c in self.content: + if c in escaped_char: + content += escaped_char[c] + else: + content += c + return content + + def setAttribute( self, name, value ): + self.attributes[name] = value + return self + + def setAttributes( self, values ): + self.attributes.update( values ) + return self + + def addChild( self, child ): + self.children.append( child ) + return self + + def addChildren( self, children ): + self.children.extend( children ) + return self + + class ParagraphTag(Tag): + def __init__( self, content ): + Tag.__init__( self, 'P', content ) + self.new_line_after = True + + class LinkTag(Tag): + def __init__( self, url, content ): + Tag.__init__( self, 'A', content ) + self.setAttribute( 'HREF', url ) + + class LocalLinkTag(Tag): + def __init__( self, anchor_name, content ): + Tag.__init__( self, 'A', content ) + self.setAttribute( 'HREF', '#' + anchor_name ) + + class AnchorTag(Tag): + def __init__( self, anchor_name ): + Tag.__init__( self, 'A' ) + self.setAttribute( 'name', anchor_name ) + self.new_line_after = True + + class H2Tag(Tag): + def __init__( self, title ): + Tag.__init__( self, 'H2', title ) + + + PARSE_OK = 'Ok' + PARSE_FAILED = 'Failed' + PARSE_CRASH = "Crashed" + + class ParseResult: + def __init__( self, status, source_path, output_path ): + self.status = status + self.source_path = source_path + self.output_path = output_path class ASTGenerator: *************** *** 51,54 **** --- 143,147 ---- self.source_dir = source_dir self.output_dir = output_dir + self.parse_result = { } def generate( self, source_path ): *************** *** 59,66 **** Path(output_path).ensure_dir_exists() exit_code = os.spawnl( os.P_WAIT, "astdump", "astdump", source_path, output_path ) ! if exit_code != 0: ! print "Failed to generate AST for ", source_path ! --- 152,215 ---- Path(output_path).ensure_dir_exists() exit_code = os.spawnl( os.P_WAIT, "astdump", "astdump", source_path, output_path ) ! self.parse_result[ source_path ] = ParseResult( self.convertParseExitCode(exit_code), ! source_path, ! output_path ) ! ! def convertParseExitCode( self, code ): ! if code == 0: ! return PARSE_OK ! elif code == 2: ! return PARSE_FAILED ! else: ! return PARSE_CRASH ! ! def generateIndexPage( self, index_filename ): ! index_path = os.path.join( self.output_dir, index_filename ) ! html_file = open( index_path, 'w' ) ! title = 'AST dump of self.source_dir' ! html_tag = Tag('HTML') ! html_tag.addChild( Tag('HEAD').addChild( Tag('TITLE', title ) ) ) ! body_tag = Tag( 'BODY' ) ! html_tag.addChild( body_tag ) ! ! body_tag.addChildren( self.generateStatistics() ) ! body_tag.addChildren( self.generateResult() ) ! html_tag.write( html_file ) ! html_file.close() ! ! def generateStatistics( self ): ! test_passed = 0 ! test_failed = 0 ! test_crashed = 0 ! for test in self.parse_result.itervalues(): ! if test.status == PARSE_OK: ! test_passed += 1 ! elif test.status == PARSE_FAILED: ! test_failed += 1 ! else: ! test_crashed += 1 ! test_count = test_passed + test_failed + test_crashed ! ! if test_count == 0: ! return [ H2Tag( 'No test!' ) ] ! ! return [ H2Tag( 'Statistics:' ), ! ParagraphTag( 'Passed %d : %3d%%' % (test_passed, test_passed * 100 / test_count) ), ! ParagraphTag( 'Failed %d : %3d%%' % (test_failed, test_failed * 100 / test_count) ), ! ParagraphTag( 'Crashed %d : %3d%%' % (test_crashed, test_crashed * 100 / test_count) ), ! ParagraphTag( 'Total tests: %d' % test_count ) ] ! ! def generateResult( self ): ! tags = [ H2Tag( 'Results:' ) ] ! table_tag = Tag( 'TABLE' ).setAttributes( { 'WIDTH' : '100%', 'BORDER' : '0', 'COLS' : '2' } ) ! tags.append( table_tag ) ! for test in self.parse_result.itervalues(): ! row_tag = Tag( 'TR' ).setAttribute( 'ALIGN', 'left' ) ! relative_url = Path( test.output_path ).make_relative_to( self.output_dir ) ! row_tag.addChild( Tag( 'TD' ).addChild( LinkTag( relative_url, test.status ) ) ) ! row_tag.addChild( Tag( 'TD' ).addChild( ParagraphTag( test.source_path ) ) ) ! table_tag.addChild( row_tag ) ! return tags *************** *** 76,81 **** # os.path.walk(sys.argv[1], lister, None) # dir name in cmdline ! input_dir = "testdata" ! output_dir = "ast" x = Path( "tata" ) --- 225,230 ---- # os.path.walk(sys.argv[1], lister, None) # dir name in cmdline ! input_dir = 'testdata' ! output_dir = 'ast' x = Path( "tata" ) *************** *** 84,85 **** --- 233,236 ---- os.path.walk( input_dir, listFilesIgnoreCVSDir, generator ) + + generator.generateIndexPage( 'index.html' ) \ No newline at end of file |
Update of /cvsroot/cpptool/rfta/bin/testdata/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv10001/bin/testdata/rfta Added Files: ASTDumper.cpp CPPParser.cpp DeclarativeCondition.cpp ForDeclaration.cpp HTMLWriter.cpp KeyedString.h Main.cpp VariableDeclMutator.cpp Log Message: * moved test source to testdata/rfta --- NEW FILE: ASTDumper.cpp --- // ////////////////////////////////////////////////////////////////////////// // Implementation file ASTDumper.cpp for class ASTDumper // (c)Copyright 2000, Baptiste Lepilleur. // Created: 2002/10/20 // ////////////////////////////////////////////////////////////////////////// #include "ASTDumper.h" #include "HTMLWriter.h" #include <boost/format.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/filesystem/operations.hpp> #include <rfta/MaxLODMutator.h> #include <rfta/NonSemanticBlanker.h> #include <rfta/ParseContext.h> #include <rfta/ParserError.h> #include <rfta/SourceASTNode.h> #include <rfta/StatementsParser.h> namespace Refactoring { class ASTDumpVisitor : public ASTNodePropertyVisitor , public ASTNodeVisitor { public: ASTDumpVisitor( HTMLWriter &writer, const SourceASTNodePtr &source ); void visitProperty( const std::string &propertyName, const ASTNodePtr &propertyNode ); void visitNode( const ASTNodePtr &node ); private: HTMLWriter &writer_; SourceASTNodePtr sourceAST_; ASTNodePtr currentNode_; }; ASTDumpVisitor::ASTDumpVisitor( HTMLWriter &writer, const SourceASTNodePtr &source ) : writer_( writer ) , sourceAST_( source ) { } void ASTDumpVisitor::visitProperty( const std::string &propertyName, const ASTNodePtr &propertyNode ) { { HTMLWriter::Tagger row1Tagger( "TR", writer_.getStream(), "ALIGN=LEFT", HTMLWriter::newLine ); HTMLWriter::Tagger propertyTagger( "TD", writer_.getStream(), "COLSPAN=\"2\"" ); writer_.writeBold( "Property: " ); writer_.write( propertyName ); } HTMLWriter::Tagger row1Tagger( "TR", writer_.getStream(), "ALIGN=LEFT", HTMLWriter::newLine ); HTMLWriter::Tagger cell1Tagger( "TD", writer_.getStream(), "WIDTH=24 BGCOLOR=Navy", HTMLWriter::newLine ); cell1Tagger.end(); HTMLWriter::Tagger cell2Tagger( "TD", writer_.getStream(), "", HTMLWriter::newLine ); visitNode( propertyNode ); cell2Tagger.end(); } void ASTDumpVisitor::visitNode( const ASTNodePtr &node ) { HTMLWriter::Tagger tableTagger( "TABLE", writer_.getStream(), "WIDTH=\"100%\" BORDER=0 COLS=2", HTMLWriter::newLine ); { // Node type HTMLWriter::Tagger row1Tagger( "TR", writer_.getStream(), "ALIGN=LEFT", HTMLWriter::newLine ); HTMLWriter::Tagger typeTagger( "TD", writer_.getStream(), "COLSPAN=\"2\"" ); writer_.writeBold( "Type: " ); writer_.write( node->getType() ); writer_.lineBreak(); writer_.writePreformated( node->getOriginalText() ); } // Properties node->visitProperties( *this ); for ( int childIndex =0; childIndex < node->getChildCount(); ++childIndex ) { { HTMLWriter::Tagger row1Tagger( "TR", writer_.getStream(), "ALIGN=LEFT", HTMLWriter::newLine ); HTMLWriter::Tagger typeTagger( "TD", writer_.getStream(), "COLSPAN=\"2\"" ); std::string heading = (boost::format( "Child[%1%]" ) % (childIndex+1) ).str(); writer_.writeBold( heading ); } HTMLWriter::Tagger row2Tagger( "TR", writer_.getStream(), "ALIGN=LEFT", HTMLWriter::newLine ); HTMLWriter::Tagger cell1Tagger( "TD", writer_.getStream(), "WIDTH=24 BGCOLOR=Navy", HTMLWriter::newLine ); cell1Tagger.end(); HTMLWriter::Tagger cell2Tagger( "TD", writer_.getStream(), "", HTMLWriter::newLine ); visitNode( node->getChildAt( childIndex ) ); cell2Tagger.end(); } } ASTDumper::ASTDumper() { } ASTDumper::~ASTDumper() { } void ASTDumper::dump( const std::string &source, const boost::filesystem::path &logDir, const std::string &title ) { boost::filesystem::path filePath = makeUniquePath( logDir ); boost::filesystem::ofstream stream( filePath ); HTMLWriter writer( stream ); writer.writeHeader( title ); writer.writeH2( "Source:" ); writer.writePreformated( source ); writer.writeH2( "Abstract syntax tree:" ); writeAST( source, writer ); writer.writeFooter(); stream.close(); } const boost::filesystem::path ASTDumper::makeUniquePath( const boost::filesystem::path &logDir ) { int serialNo = 1; while ( true ) { std::string fileName = (boost::format( "dump-%05d.html" ) % serialNo).str(); boost::filesystem::path filePath = logDir << fileName; if ( !boost::filesystem::exists( filePath ) ) return filePath; ++serialNo; } } void ASTDumper::writeAST( const std::string &source, HTMLWriter &writer ) { NullPPDirectiveListener nullListener; std::string blankedSource; NonSemanticBlanker blanker( source, blankedSource, nullListener ); blanker.blank(); SourceASTNodePtr sourceAST = SourceASTNode::create( blankedSource, source ); ParseContext context( sourceAST ); StatementsParser parser( context, sourceAST->getBlankedSourceStart(), sourceAST->getBlankedSourceEnd() ); try { if ( !parser.tryParse() ) writer.writeError( "Failed to parse top-level statements." ); MaxLODMutator mutator; mutator.mutate( sourceAST, sourceAST ); ASTDumpVisitor visitor( writer, sourceAST ); visitor.visitNode( sourceAST ); } catch ( ParserError &e ) { writer.writeError( "Parsing failed:" ); writer.writePreformated( e.what() ); } } } // namespace Refactoring --- NEW FILE: CPPParser.cpp --- #include "stdafx.h" #include <rfta/parser/CPPParser.h> #include <rfta/parser/NonSemanticBlanker.h> #include <rfta/parser/MaxLODMutator.h> #include <rfta/parser/DeclarationListParser.h> #include <rfta/parser/ParseContext.h> #include <rfta/parser/ParserError.h> #include <rfta/parser/ASTNodeAndPropertyVisitor.h> #include <rfta/parser/ASTNodes.h> namespace Refactoring { namespace { class FunctionImplementationVisitor : public ASTNodeAndPropertyVisitor { public: FunctionImplementationVisitor( int functionBodyPosition ) : functionBodyPosition_( functionBodyPosition ) , foundFunction_( false ) { } ASTNodePtr findFunctionImplementation( const ASTNodePtr &node ) { visitNode( node ); if ( !foundFunction_ ) return ASTNodePtr(); return functionImplementationNode_; } protected: // overridden from ASTNodeAndPropertyVisitor bool canSkipNode( const ASTNodePtr &node ) const { return foundFunction_; } bool needsToVisitProperties( const ASTNodePtr &node ) const { return !foundFunction_; } bool needsToVisitChildren( const ASTNodePtr &node ) const { return node->getType().hasSomeFeatureOf( ASTNodeTypeFeatures::mayHaveFunctionImplChildren ); } bool needsToHandleNode( const ASTNodePtr& node ) const { return node->getType() == ASTNodeTypes::functionImplementation && !foundFunction_; } void handleNode( const ASTNodePtr& node ) { if ( node->getRange().contains( SourceRange( functionBodyPosition_,0 ) ) ) { foundFunction_ = true; functionImplementationNode_ = node; } } private: bool foundFunction_; int functionBodyPosition_; ASTNodePtr functionImplementationNode_; }; } CPPParser::CPPParser( const std::string &source ) { NullPPDirectiveListener nullListener; std::string blankedSource; NonSemanticBlanker blanker( source, blankedSource, nullListener ); blanker.blank(); sourceNode_ = SourceASTNode::create( blankedSource, source ); } SourceASTNodePtr CPPParser::getSourceNode() const { return sourceNode_; } ASTNodePtr CPPParser::parseForFunctionBodyAt( int position ) { parseAll(); FunctionImplementationVisitor visitor( position ); return visitor.findFunctionImplementation( sourceNode_ ); } void CPPParser::parseForFunctionDeclarations() { parseAll(); } void CPPParser::parseAll() { ParseContext context( sourceNode_ ); DeclarationListParser parser( context, sourceNode_->getBlankedSourceStart(), sourceNode_->getBlankedSourceEnd() ); if ( !parser.tryParse() ) throw ParserError( "top level source file parsing failed.", context ); MaxLODMutator mutator; mutator.mutate( sourceNode_, sourceNode_ ); } */ } // namespace Refactoring --- NEW FILE: DeclarativeCondition.cpp --- { if ( int x = 3 ) ; while ( char c = next() ) ; switch ( char token = nextToken() ) { default: } for ( int count =0; count < maxCount; ++count ) ; } --- NEW FILE: ForDeclaration.cpp --- { for ( int a, b;; ) //int a, b;; ) ; } --- NEW FILE: HTMLWriter.cpp --- // ////////////////////////////////////////////////////////////////////////// // Implementation file HTMLWriter.cpp for class HTMLWriter // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2002/10/20 // ////////////////////////////////////////////////////////////////////////// #include "HTMLWriter.h" #include <iostream> #include <string> namespace Refactoring { HTMLWriter::Tagger::Tagger( const std::string &tagName, std::ostream &stream, const std::string &attributes, EOLType eolType ) : tagName_( tagName ) , stream_( stream ) , tagClosed_( false ) , eolType_( eolType ) { stream_ << "<" << tagName_; if ( !attributes.empty() ) stream_ << " " << attributes; stream_ << ">"; if ( eolType_ == newLine ) stream_ << "\n"; } HTMLWriter::Tagger::~Tagger() { end(); } void HTMLWriter::Tagger::end() { if ( tagClosed_ ) return; tagClosed_ = true; stream_ << "</" << tagName_ << ">"; if ( eolType_ == newLine ) stream_ << "\n"; } HTMLWriter::HTMLWriter( std::ostream &stream ) : stream_( stream ) { } HTMLWriter::~HTMLWriter() { } void HTMLWriter::writeHeader( const std::string &title ) { stream_ << "<HTML>"; Tagger headTagger( "HEAD", stream_, "", newLine ); Tagger titleTagger( "TITLE", stream_ ); write( title ); titleTagger.end(); headTagger.end(); stream_ << "<BODY>\n"; } void HTMLWriter::writeFooter() { stream_ << "</BODY>\n"; stream_ << "</HTML>\n"; } void HTMLWriter::write( const std::string &text ) { for ( int index =0; index < text.length(); ++index ) { char c = text[index]; std::string escaped; switch ( c ) { case '<': escaped = "<"; break; case '>': escaped = ">"; break; case '&': escaped = "&"; break; // case '\'': escaped = "'"; break; case '"': escaped = """; break; case ' ': escaped = ' '; break; default: escaped = c; break; } stream_ << escaped; } } void HTMLWriter::writeH2( const std::string &heading ) { Tagger tagger( "H2", stream_, "", newLine ); write( heading ); } void HTMLWriter::writePreformated( const std::string &text ) { Tagger tagger( "PRE", stream_, "", newLine ); write( text ); } void HTMLWriter::writeError( const std::string &text ) { Tagger tagger( "P", stream_, "color=\"#ff0000\"" ); write( text ); } void HTMLWriter::writeBold( const std::string &text ) { Tagger tagger( "B", stream_, "" ); write( text ); } void HTMLWriter::lineBreak() { stream_ << "<BR>" << std::endl; } std::ostream & HTMLWriter::getStream() const { return stream_; } } // namespace Refactoring --- NEW FILE: KeyedString.h --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2003, Andre Baresel // Created: 2003/04/28 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_KEYEDSTRING_H #define RFTA_KEYEDSTRING_H #include <vector> #include <map> #include <string> namespace Refactoring { namespace Testing { class KeyedString { public: KeyedString& operator<< (std::string characters); operator std::string () const; KeyedString& addKeyed (std::string key , std::string word ); std::string asString() const; std::vector<int> getKeyedIndex(std::string key) const; std::vector<int> getKeyedLen(std::string key) const; int getKeyedIndex(std::string key,int index) const; int getKeyedLen(std::string key,int index) const; std::string getWord(std::string key, int index) const; int length() const; KeyedString& setKeyStart(std::string key); KeyedString& setKeyEnd(std::string key); protected: std::string sequence_; std::map<std::string,std::vector<int> > wordIndex_; std::map<std::string,std::vector<int> > wordLen_; std::map<std::string,std::vector<std::string> > word_; }; // INLINED MEMBERS: inline KeyedString& KeyedString::operator<<(std::string characters) { sequence_.append(characters); return *this; } inline KeyedString::operator std::string() const { return sequence_; } inline std::string KeyedString::asString() const { return sequence_; } inline std::vector<int> KeyedString::getKeyedIndex(std::string key) const { std::map<std::string,std::vector<int> >::const_iterator it; it = wordIndex_.find(key); if (it == wordIndex_.end()) return std::vector<int>(); return (*it).second; } inline std::vector<int> KeyedString::getKeyedLen(std::string key) const { std::map<std::string,std::vector<int> >::const_iterator it; it = wordLen_.find(key); if (it == wordLen_.end()) return std::vector<int>(); return (*it).second; } inline int KeyedString::getKeyedIndex(std::string key, int index) const { std::map<std::string,std::vector<int> >::const_iterator it; it = wordIndex_.find(key); if (it == wordIndex_.end()) throw std::logic_error("No string registered for this key."); if ((*it).second.size()<index) throw std::logic_error("Index out of range."); return (*it).second[index]; } inline int KeyedString::getKeyedLen(std::string key, int index) const { std::map<std::string,std::vector<int> >::const_iterator it; it = wordLen_.find(key); if (it == wordLen_.end()) throw std::logic_error("No string registered for this key."); if ((*it).second.size()<index) throw std::logic_error("Index out of range."); return (*it).second[index]; } inline std::string KeyedString::getWord(std::string key, int index) const { std::map<std::string,std::vector<std::string> >::const_iterator it; it = word_.find(key); if (it == word_.end()) throw std::logic_error("No string registered for this key."); if ((*it).second.size() < index) throw std::logic_error("Index out of range."); return ((*it).second)[index]; } inline KeyedString& KeyedString::addKeyed(std::string key,std::string word) { wordIndex_[key].push_back(sequence_.length()); wordLen_[key].push_back(word.length()); word_[key].push_back(word); sequence_.append(word); return *this; } inline int KeyedString::length() const { return sequence_.length(); } inline KeyedString& KeyedString::setKeyStart(std::string key) { wordIndex_[key].push_back(sequence_.length()); wordLen_[key].push_back(0); word_[key].push_back(""); return *this; } inline KeyedString& KeyedString::setKeyEnd(std::string key) { std::vector<int>& v1_ref = wordIndex_[key]; std::vector<int>& v2_ref = wordLen_[key]; if ( v1_ref.empty() || v2_ref.empty() || v2_ref.size() != v1_ref.size() ) throw std::logic_error("Key was not initialized correctly."); int idx = v1_ref.size()-1; v2_ref[idx] = sequence_.length() - v1_ref[idx]; return *this; } } // namespace Testing } // namespace Refactoring #endif // RFTA_KEYEDSTRING_H --- NEW FILE: Main.cpp --- #include "ASTDumper.h" #include <boost/lexical_cast.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/filesystem/path.hpp> #include <iostream> #include <stdexcept> #include <string> static void printUsage() { std::cout << "ASTDump Usage:\n" "ASTDump firstLine lastLine filePath [outputDirectory]\n" "\n" "ASTDump will dump the AST of the specified file range in an HTML\n" "file located in the specified directory. Default for ouput duirectory\n" "is ./astdump.\n" "\n" "Warning: the outputDirectory must exist!" ; } int main( int argc, char *argv[] ) { if ( argc < 4 || argc > 5 ) { printUsage(); return 1; } else { try { int firstLineNumber = boost::lexical_cast<int>( argv[1] ); int lastLineNumber = boost::lexical_cast<int>( argv[2] ); boost::filesystem::path path( argv[3], boost::filesystem::system_specific ); std::string outputPathName = "astdump"; if ( argc == 5 ) outputPathName = argv[4]; boost::filesystem::path outputPath( outputPathName, boost::filesystem::system_specific ); boost::filesystem::ifstream stream( path ); int currentLineNumber = 1; while ( currentLineNumber < firstLineNumber ) { std::string discard; std::getline( stream, discard ); ++currentLineNumber; } std::string source; while ( currentLineNumber <= lastLineNumber ) { std::string line; std::getline( stream, line ); source += line; source += '\n'; ++currentLineNumber; } Refactoring::ASTDumper dumper; dumper.dump( source, outputPath, path.generic_path() ); } catch ( std::exception &e ) { std::cerr << "Fatal error:\n" << "Unexpected exception of type " << typeid(e).name() << std::endl << e.what() << std::endl; return 2; } } return 0; } --- NEW FILE: VariableDeclMutator.cpp --- // ////////////////////////////////////////////////////////////////////////// // Implementation file VariableDeclMutator.cpp for class VariableDeclMutator // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2002/10/16 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ExpressionASTNode.h" #include <rfta/ParseContext.h> #include "StatementASTNode.h" #include "VariableDeclMutator.h" #include <boost/format.hpp> namespace Refactoring { /// @todo baptiste The declaration 'struct time_t stamp' is not parsed as a variable declaration. /// @todo baptiste Variable type are not allowed to contains number. VariableDeclMutator::VariableDeclMutator( ParseContext &context, const char *start, const char *end, const ASTNodePtr &node ) : Parser( context, start, end ) , node_( node ) { Tracker tracker( "VariableDeclMutator::VariableDeclMutator", *this ); if ( node_->getType() != StatementASTNode::declarationOrExpressionStatement ) throwFailure( "Bad node type: " + node_->getType() ); } VariableDeclMutator::~VariableDeclMutator() { } // - find the first occurence of either '=', ',' or ';'. The variable // declaration is before it. // - backtracking, skip over pairs of [], and capture (=> this is the type // suffix) // - backtracking, capture the identifier, this is the local variable name // - capture everything before the identifer, this is the type prefix of the // local variable. // - check that the captured type is valid: // - type does not contains characters others then id letters, "&* " and // :: outside of template parameters (skipping over <...>). // - type is not a keyword that may come before an identifier (new, sizeof) // (there might be other, we'll find out the hard way). /// @todo baptiste Capture initialization value ( =... ) and iterates over /// the list of declaration ( int x, y, z; ) bool VariableDeclMutator::tryMutate() { Tracker tracker( "VariableDeclMutator::tryMutate", *this ); const char *separatorPos = findFirstSeparatorBalancingTemplateBrackets( start_, end_ ); if ( separatorPos == end_ ) return false; /// @todo baptiste This should never happen, since ';' should at least be there current_ = separatorPos; backtrackSkippingSpaces(); int suffixEndIndex = getCurrentIndex(); if ( !backtrackSkippingOverArrayBrackets() ) return false; backtrackSkippingSpaces(); int suffixStartIndex = getCurrentIndex(); if ( !backtrackSkippingOverVariableIdentifier() ) return false; if ( current_ == start_ ) // no type before identifier ! return false; int prefixEndIndex = getCurrentIndex(); const char *prefixEnd = current_; current_ = start_; if ( !isValidTypePrefix( prefixEnd ) ) return false; current_ = separatorPos; // ok this is a valid variable declaration... node_->mutateType( StatementASTNode::declarationStatement ); node_->removeAllProperties(); ASTNodePtr variableDeclNode = addNodeVariableDecl( node_, prefixEndIndex, // prefix end prefixEndIndex, // secondary prefix start prefixEndIndex, // variable name start suffixStartIndex, suffixEndIndex ); // from now, throw parse failure if unexpected stuff happen continueParse( variableDeclNode, prefixEndIndex ); return true; } ASTNodePtr VariableDeclMutator::addNodeVariableDecl( const ASTNodePtr &declStatement, int prefixEnd, int secondaryPrefixStart, int variableNameStart, int suffixStart, int suffixEnd ) { ASTNodePtr variableDeclNode = ASTNode::create( ExpressionASTNode::variableDeclExpression, declStatement, getStartIndex(), suffixEnd - getStartIndex() ); // the correct length is set when the initializer is added. declStatement->addChild( variableDeclNode ); ASTNodePtr variableNameNode = ASTNode::create( ExpressionASTNode::variableNameExpression, variableDeclNode, variableNameStart, suffixStart - variableNameStart ); variableDeclNode->setPropertyNode( StatementASTNode::variableNameProperty, variableNameNode ); ASTNodePtr typePrefixNode = ASTNode::create( ExpressionASTNode::typeDeclPrefixExpression, variableDeclNode, getStartIndex(), prefixEnd - getStartIndex() ); variableDeclNode->setPropertyNode( StatementASTNode::typeDeclPrefixProperty, typePrefixNode ); if ( variableNameStart - secondaryPrefixStart > 0 ) { ASTNodePtr secondaryTypePrefixNode = ASTNode::create( ExpressionASTNode::typeDeclPrefixExpression, variableDeclNode, secondaryPrefixStart, variableNameStart - secondaryPrefixStart ); variableDeclNode->setPropertyNode( StatementASTNode::typeDeclSecondaryPrefixProperty, secondaryTypePrefixNode ); } if ( suffixEnd - suffixStart > 0 ) { ASTNodePtr suffixNode = ASTNode::create( ExpressionASTNode::typeDeclSuffixExpression, variableDeclNode, suffixStart, suffixEnd - suffixStart ); variableDeclNode->setPropertyNode( StatementASTNode::typeDeclSuffixProperty, suffixNode ); } return variableDeclNode; } bool VariableDeclMutator::backtrackSkippingOverArrayBrackets() { while ( hasPrevious() && current_[-1] == ']' ) { --current_; if ( !hasPrevious() ) return false; // missing '[' ! while ( *current_ != '[' ) { --current_; if ( !hasPrevious() ) return false; // missing '[' ! } } return hasPrevious(); } bool VariableDeclMutator::backtrackSkippingOverVariableIdentifier() { if ( !hasPrevious() ) return false; const char *identifierEnd = current_; --current_; while ( hasPrevious() && isIdentifierLetter( *current_ ) ) --current_; if ( !hasPrevious() ) return false; ++current_; if ( current_ == identifierEnd ) return false; return isValidIdentifierFirstLetter( *current_ ); } bool VariableDeclMutator::isValidTypePrefix( const char *prefixEnd ) { const char *it = start_; while ( it != prefixEnd ) { if ( *it == '<' ) { if ( !tryFindNextBalanced( it, prefixEnd ) ) return false; continue; } if ( *it == ':' ) // only :: is valid { ++it; if ( it == prefixEnd || *it != ':' ) return false; ++it; continue; } if ( isBadTypeChar( *it++ ) ) return false; } return isNotKeyword( std::string( start_, prefixEnd ) ); } bool VariableDeclMutator::isValidSecondaryTypePrefix( const char *prefixStart, const char *prefixEnd ) { const char *current = prefixStart; while ( current != prefixEnd ) { char c = *current++; if ( !isSymbolChar( c ) || !isKeywordLetter( c ) ) return false; } return true; } bool VariableDeclMutator::tryFindNextBalanced( const char *¤t, const char *end, char opening, char closing ) { int balance = 1; while ( ++current != end ) { char c = *current; if ( c == closing ) { --balance; if ( balance == 0 ) { ++current; return true; } } else if ( c == opening ) ++balance; } return false; } inline bool VariableDeclMutator::isBadTypeChar( char c ) { return !( isIdentifierLetter(c) || isSymbolChar(c) ); } inline bool VariableDeclMutator::isSymbolChar( char c ) { static const std::string allowedSymbol( "*& " ); return allowedSymbol.find( c ) != std::string::npos; } bool VariableDeclMutator::isNotKeyword( const std::string &type ) { std::string cleanType = stripTrailingSpaces( type ); return !( cleanType == "new" || cleanType == "sizeof" ); } const char * VariableDeclMutator::findFirstSeparatorBalancingTemplateBrackets( const char *start, const char *end ) { static const std::string separators( ";,=(" ); const char *current = start; while ( current != end ) { char c = *current; if ( separators.find_first_of( c ) != std::string::npos ) return current; else if ( c == '<' ) { if ( !tryFindNextBalanced( current, end ) ) return end; } else ++current; } return end; } std::string VariableDeclMutator::stripTrailingSpaces( const std::string &str ) { int index = str.find_last_not_of( ' ' ); if ( index == std::string::npos ) return str; return str.substr( 0, index+1 ); } bool VariableDeclMutator::skipOverAssignmentInitializer() { const char *start = current_; while ( current_ != end_ ) { char c = *current_; if ( c == ';' || c == ',' ) return current_ != (start+1); else if ( c == '(' ) { if ( !tryFindNextBalanced( current_, end_, '(', ')' ) ) return false; } else if ( c == '[' ) { if ( !tryFindNextBalanced( current_, end_, '[', ']' ) ) return false; } ++current_; } return false; } bool VariableDeclMutator::skipOverConstructorInitilizer() { if ( !tryFindNextBalanced( current_, end_, '(', ')' ) ) return false; if ( current_ == end_ ) return false; return *current_ == ',' || *current_ == ';'; } void VariableDeclMutator::continueParse( const ASTNodePtr &variableDeclNode, int prefixEndIndex ) { Tracker tracker( "VariableDeclMutator::continueParse", *this ); createAndAddInitializerNode( variableDeclNode ); int variableNumber = 2; while ( current_ != end_ ) { skipSpaces(); int secondaryPrefixStartIndex = getCurrentIndex(); const char *secondaryPrefixStart = current_; const char *separatorPos = findFirstSeparatorBalancingTemplateBrackets( current_, end_ ); if ( separatorPos == end_ ) { boost::format frmt( "failed to find expected variable declaration separator " "for declaration %1%: ',;=('. " "This may be due to balancing a '<..>'."); throwFailure( frmt % variableNumber ); } current_ = separatorPos; // Parse suffix int suffixEndIndex = getCurrentIndex(); if ( !backtrackSkippingOverArrayBrackets() ) { throwFailure( boost::format( "failed to find matching opening ']' for " "variable declaration %1%." ) % variableNumber ); } int suffixStartIndex = getCurrentIndex(); if ( suffixStartIndex <= secondaryPrefixStartIndex ) { throwFailure( boost::format( "failed to find matching opening ']' for " "variable declaration %1%." ) % variableNumber ); } if ( !backtrackSkippingOverVariableIdentifier() ) { throwFailure( boost::format( "no valid identifier found for " "variable declaration %1%" ) % variableNumber ); } int secondaryPrefixEndIndex = getCurrentIndex(); const char *secondaryPrefixEnd = current_; if ( !isValidSecondaryTypePrefix( secondaryPrefixStart, secondaryPrefixEnd ) ) { std::string prefix( secondaryPrefixStart, secondaryPrefixEnd - secondaryPrefixStart ); throwFailure( boost::format( "invalid secondary type prefix for " "variable declaration %1%: %2%" ) % variableNumber % prefix ); } ASTNodePtr variableDeclNode = addNodeVariableDecl( node_, prefixEndIndex, secondaryPrefixStartIndex, secondaryPrefixEndIndex, suffixStartIndex, suffixEndIndex ); current_ = separatorPos; createAndAddInitializerNode( variableDeclNode ); ++variableNumber; } } void VariableDeclMutator::createAndAddInitializerNode( const ASTNodePtr &variableDeclNode ) { Tracker tracker( "VariableDeclMutator::createAndAddInitializerNode", *this ); int initializerStartIndex = getCurrentIndex(); int initializerValueStartIndex; int initializerValueEndIndex; std::string initializerType; if( *current_ == '=' ) { initializerType = ExpressionASTNode::assignVariableInitializerExpression; ++current_; initializerValueStartIndex = getCurrentIndex(); skipOverAssignmentInitializer(); initializerValueEndIndex = getCurrentIndex() -1; } else if ( *current_ == '(' ) { ++current_; initializerType = ExpressionASTNode::constructorVariableInitializerExpression; initializerValueStartIndex = getCurrentIndex(); findNextBalanced( '(', ')' ); initializerValueEndIndex = getCurrentIndex() -1; } else if ( *current_ == ';' || *current_ == ',' ) ++current_; else { throwFailure( boost::format("unexpected character: '%1%'.") % *current_ ); } if ( !initializerType.empty() ) { int initializerLength = getCurrentIndex() - initializerStartIndex; int variableDeclEndIndex = initializerValueEndIndex+1; variableDeclNode->setLength( variableDeclEndIndex - variableDeclNode->getStartIndex() ); ASTNodePtr initializerNode = ASTNode::create( initializerType, variableDeclNode, initializerStartIndex, initializerLength ); variableDeclNode->setPropertyNode( ExpressionASTNode::variableInitializerProperty, initializerNode ); ASTNodePtr valueNode = ASTNode::create( ExpressionASTNode::valueExpression, initializerNode, initializerValueStartIndex, initializerValueEndIndex - initializerValueStartIndex ); initializerNode->setPropertyNode( ExpressionASTNode::valueProperty, valueNode ); skipSpaces(); if ( *current_ == ';' || *current_ == ',' ) ++current_; else throwFailure( boost::format("unexpected character: '%1%'.") % *current_ ); } } } // namespace Refactoring |
Update of /cvsroot/cpptool/rfta/bin In directory sc8-pr-cvs1:/tmp/cvs-serv10001/bin Removed Files: ASTDumper.cpp CPPParser.cpp DeclarativeCondition.cpp ForDeclaration.cpp HTMLWriter.cpp KeyedString.h Main.cpp VariableDeclMutator.cpp Log Message: * moved test source to testdata/rfta --- ASTDumper.cpp DELETED --- --- CPPParser.cpp DELETED --- --- DeclarativeCondition.cpp DELETED --- --- ForDeclaration.cpp DELETED --- --- HTMLWriter.cpp DELETED --- --- KeyedString.h DELETED --- --- Main.cpp DELETED --- --- VariableDeclMutator.cpp DELETED --- |
From: <bl...@us...> - 2003-04-30 22:19:30
|
Update of /cvsroot/cpptool/rfta/bin/testdata/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv8753/rfta Log Message: Directory /cvsroot/cpptool/rfta/bin/testdata/rfta added to the repository |
From: <bl...@us...> - 2003-04-30 22:18:03
|
Update of /cvsroot/cpptool/rfta/bin/testdata In directory sc8-pr-cvs1:/tmp/cvs-serv8186/testdata Log Message: Directory /cvsroot/cpptool/rfta/bin/testdata added to the repository |
From: <bl...@us...> - 2003-04-30 22:15:54
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv7610/src/rftaparser Modified Files: DeclarationParser.cpp Log Message: * refactored a bit Index: DeclarationParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationParser.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DeclarationParser.cpp 29 Apr 2003 10:03:30 -0000 1.6 --- DeclarationParser.cpp 30 Apr 2003 22:15:49 -0000 1.7 *************** *** 129,133 **** skipSpaces(); ! if (!hasNext()) return false; int startIndex = getCurrentIndex(); --- 129,134 ---- skipSpaces(); ! if ( !hasNext() ) ! return false; int startIndex = getCurrentIndex(); *************** *** 138,142 **** std::string identifier; - if (tryReadNextIdentifier(identifier)) { --- 139,142 ---- *************** *** 220,224 **** break; ! } while (1); /* if (*current_=='y') // special case 'try-function-body' --- 220,224 ---- break; ! } while ( true ); /* if (*current_=='y') // special case 'try-function-body' |
From: <bl...@us...> - 2003-04-30 22:14:53
|
Update of /cvsroot/cpptool/rfta/src/astdumper In directory sc8-pr-cvs1:/tmp/cvs-serv7218/src/astdumper Modified Files: Main.cpp Log Message: * astdump now takes the input and output file path as argument, and parse the whole file. * added python script to recursively generate ast dump for all files contained in testdata/ Index: Main.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/astdumper/Main.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Main.cpp 1 Apr 2003 08:29:05 -0000 1.2 --- Main.cpp 30 Apr 2003 22:14:50 -0000 1.3 *************** *** 12,20 **** std::cout << "ASTDump Usage:\n" ! "ASTDump firstLine lastLine filePath [outputDirectory]\n" "\n" ! "ASTDump will dump the AST of the specified file range in an HTML\n" "file located in the specified directory. Default for ouput duirectory\n" ! "is ./astdump.\n" "\n" "Warning: the outputDirectory must exist!" --- 12,20 ---- std::cout << "ASTDump Usage:\n" ! "ASTDump inputFilePath outputHTMLFilePath\n" "\n" ! "ASTDump will dump the AST of the specified file in a HTML\n" "file located in the specified directory. Default for ouput duirectory\n" ! "is .\n" "\n" "Warning: the outputDirectory must exist!" *************** *** 22,29 **** } int main( int argc, char *argv[] ) { ! if ( argc < 4 || argc > 5 ) { printUsage(); --- 22,46 ---- } + + static std::string readSourceFile( const boost::filesystem::path &path ) + { + boost::filesystem::ifstream stream( path ); + std::string source; + while ( !stream.eof() ) + { + std::string line; + std::getline( stream, line ); + source += line; + source += '\n'; + } + + return source; + } + + int main( int argc, char *argv[] ) { ! if ( argc > 3 ) { printUsage(); *************** *** 34,65 **** try { ! int firstLineNumber = boost::lexical_cast<int>( argv[1] ); ! int lastLineNumber = boost::lexical_cast<int>( argv[2] ); ! boost::filesystem::path path( argv[3], boost::filesystem::native ); ! std::string outputPathName = "astdump"; ! if ( argc == 5 ) ! outputPathName = argv[4]; ! boost::filesystem::path outputPath( outputPathName, boost::filesystem::native ); ! boost::filesystem::ifstream stream( path ); ! int currentLineNumber = 1; ! while ( currentLineNumber < firstLineNumber ) ! { ! std::string discard; ! std::getline( stream, discard ); ! ++currentLineNumber; ! } ! ! std::string source; ! while ( currentLineNumber <= lastLineNumber ) ! { ! std::string line; ! std::getline( stream, line ); ! source += line; ! source += '\n'; ! ++currentLineNumber; ! } Refactoring::ASTDumper dumper; --- 51,60 ---- try { ! boost::filesystem::path path( argv[1], boost::filesystem::native ); ! boost::filesystem::path outputPath( argv[2], boost::filesystem::native ); ! std::string source = readSourceFile( path ); Refactoring::ASTDumper dumper; |
From: <bl...@us...> - 2003-04-30 22:14:03
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv6947/src/rftaparser Modified Files: DeclarationParserTest.cpp DeclarationParserTest.h NamespaceParser.h Log Message: * added handling for anonymous namespace Index: DeclarationParserTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationParserTest.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DeclarationParserTest.cpp 29 Apr 2003 10:01:25 -0000 1.5 --- DeclarationParserTest.cpp 30 Apr 2003 22:13:59 -0000 1.6 *************** *** 19,23 **** DeclarationParserTest::DeclarationParserTest() - : CppUnit::TestFixture() { } --- 19,22 ---- *************** *** 115,118 **** --- 114,141 ---- endIndex-startIndex ); } + + + void + DeclarationParserTest::testAnonymousNamespace() + { + const std::string source( " namespace { } " ); + int startIndex = 2; + int endIndex = source.length()-1; + SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser, + source, + source.length()-1 ); + ASTNodePtr namespaceDecl = sourceAST->getChildAt(0); + RFTA_ASSERT_NODE_HAS( namespaceDecl, + ASTNodeTypes::namespaceDeclaration, + startIndex, + endIndex-startIndex ); + RFTA_ASSERT_NODE_PROPERTY_HAS( + namespaceDecl, + ASTNodeProperties::namespaceBodyProperty, + ASTNodeTypes::unparsedDeclarationList, + 12, + 3); + } + void Index: DeclarationParserTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationParserTest.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DeclarationParserTest.h 29 Apr 2003 10:01:25 -0000 1.3 --- DeclarationParserTest.h 30 Apr 2003 22:13:59 -0000 1.4 *************** *** 22,25 **** --- 22,26 ---- CPPUNIT_TEST( testLongUsingNamespace ); CPPUNIT_TEST( testNamespaceAlias ); + CPPUNIT_TEST( testAnonymousNamespace ); CPPUNIT_TEST( testSimpleLinkage ); CPPUNIT_TEST( testSingleLinkage ); *************** *** 48,51 **** --- 49,53 ---- void testLongUsingNamespace(); void testNamespaceAlias(); + void testAnonymousNamespace(); void testSimpleLinkage(); void testSingleLinkage(); Index: NamespaceParser.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/NamespaceParser.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NamespaceParser.h 30 Apr 2003 19:20:13 -0000 1.2 --- NamespaceParser.h 30 Apr 2003 22:13:59 -0000 1.3 *************** *** 18,22 **** { public: ! /*! Constructs a NamespaceParser object. */ NamespaceParser( ParseContext &context, --- 18,22 ---- { public: ! /*! Constructs a NamespaceParser object. */ NamespaceParser( ParseContext &context, |
From: <bl...@us...> - 2003-04-30 22:10:52
|
Update of /cvsroot/cpptool/rfta/bin In directory sc8-pr-cvs1:/tmp/cvs-serv5788/bin Added Files: lister.py Log Message: * astdump now takes the input and output file path as argument, and parse the whole file. * added python script to recursively generate ast dump for all files contained in testdata/ --- NEW FILE: lister.py --- # Recursively generate ast # Path.split_all function from http://www.jorendorff.com/articles/python/path import os class Path(str): def split_all( self ): """ Return a list of the path components in this path. The first item in the list will be a path. Its value will be either os.curdir, os.pardir, empty, or the root directory of this path (for example, '/' or 'C:\\'). The other items in the list will be strings. path.path.joinpath(*result) will yield the original path. """ parts = [] loc = self while loc != os.curdir and loc != os.pardir: prev = loc loc, child = prev.split_path() if loc == prev: break parts.append(child) parts.append(loc) parts.reverse() return parts def make_relative_to( self, base_path ): components = Path(os.path.normcase(self)).split_all() base_components = Path(os.path.normcase(base_path)).split_all() return Path( os.path.join( *components[len(base_components):] ) ) def change_extension( self, extension ): return Path( os.path.splitext( self )[0] + "." + extension ) def split_path( self ): """ p.splitpath() -> Return (p.parent, p.name). """ parent, child = os.path.split(self) return Path(parent), child def ensure_dir_exists( self ): directory = os.path.dirname( self ) if not os.path.exists( directory ): os.makedirs( directory ) class ASTGenerator: def __init__( self, source_dir, output_dir ): self.source_dir = source_dir self.output_dir = output_dir def generate( self, source_path ): relative_source_path = Path(source_path).make_relative_to( self.source_dir ) output_filename = Path( relative_source_path ).change_extension( "html" ) output_path = os.path.join( self.output_dir, output_filename ) print "Generating AST for ", source_path, " in ", output_path Path(output_path).ensure_dir_exists() exit_code = os.spawnl( os.P_WAIT, "astdump", "astdump", source_path, output_path ) if exit_code != 0: print "Failed to generate AST for ", source_path def listFilesIgnoreCVSDir( generator, dirName, fileNames ): if ( fileNames.count( 'CVS' ) > 0 ): fileNames.remove( 'CVS' ) for file in fileNames: file_path = os.path.join( dirName, file ) if os.path.isfile( file_path ): generator.generate( file_path ) #if __name__ == '__main__': # os.path.walk(sys.argv[1], lister, None) # dir name in cmdline input_dir = "testdata" output_dir = "ast" x = Path( "tata" ) generator = ASTGenerator( input_dir, output_dir ) os.path.walk( input_dir, listFilesIgnoreCVSDir, generator ) |
From: <bl...@us...> - 2003-04-30 22:10:52
|
Update of /cvsroot/cpptool/rfta/src/astdumper In directory sc8-pr-cvs1:/tmp/cvs-serv5788/src/astdumper Modified Files: ASTDumper.cpp ASTDumper.h Log Message: * astdump now takes the input and output file path as argument, and parse the whole file. * added python script to recursively generate ast dump for all files contained in testdata/ Index: ASTDumper.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/astdumper/ASTDumper.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ASTDumper.cpp 28 Apr 2003 20:53:20 -0000 1.6 --- ASTDumper.cpp 30 Apr 2003 22:10:48 -0000 1.7 *************** *** 135,143 **** void ASTDumper::dump( const std::string &source, ! const boost::filesystem::path &logDir, const std::string &title ) { - boost::filesystem::path filePath = makeUniquePath( logDir ); boost::filesystem::ofstream stream( filePath ); HTMLWriter writer( stream ); writer.writeHeader( title ); --- 135,145 ---- void ASTDumper::dump( const std::string &source, ! const boost::filesystem::path &filePath, const std::string &title ) { boost::filesystem::ofstream stream( filePath ); + if ( !stream.good() ) + throw std::runtime_error( "failed to create file: " + filePath.string() ); + HTMLWriter writer( stream ); writer.writeHeader( title ); *************** *** 150,169 **** writer.writeFooter(); stream.close(); - } - - - const boost::filesystem::path - ASTDumper::makeUniquePath( const boost::filesystem::path &logDir ) - { - int serialNo = 1; - while ( true ) - { - std::string fileName = (boost::format( "dump-%05d.html" ) % serialNo).str(); - boost::filesystem::path filePath = logDir / fileName; - if ( !boost::filesystem::exists( filePath ) ) - return filePath; - - ++serialNo; - } } --- 152,155 ---- Index: ASTDumper.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/astdumper/ASTDumper.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ASTDumper.h 23 Oct 2002 20:25:17 -0000 1.1.1.1 --- ASTDumper.h 30 Apr 2003 22:10:49 -0000 1.2 *************** *** 32,37 **** private: - const boost::filesystem::path makeUniquePath( const boost::filesystem::path &logDir ); - void writeAST( const std::string &source, HTMLWriter &writer ); --- 32,35 ---- |
From: <bl...@us...> - 2003-04-30 19:20:22
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv2847/src/rftaparser Modified Files: NamespaceParser.cpp NamespaceParser.h Log Message: * added handling for anonymous namespace * refactored a bit Index: NamespaceParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/NamespaceParser.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NamespaceParser.cpp 15 Apr 2003 19:05:19 -0000 1.3 --- NamespaceParser.cpp 30 Apr 2003 19:20:12 -0000 1.4 *************** *** 46,110 **** // named namespace or unnamed namespace: // "namespace x" or "namespace { ... }" ! int name_startIdx = getCurrentIndex(); ! std::string namespace_name; ! if (tryReadNextIdentifier(namespace_name)) { // namespace has an identifier which will be stored as child-node. ! ASTNodePtr namespace_identifier = createASTNode( ASTNodeTypes::localScopeIdentifier, namespaceNode, ! name_startIdx, getCurrentIndex() - name_startIdx + 1 ); ! namespaceNode->addChild( namespace_identifier ); } ! if (!namespace_name.empty()) ! { ! // check for definition of a namespace alias ! skipSpaces(); ! if (tryNextIs('=')) ! { ! // namespace alias: "namespace x = y;" ! skipSpaces(); ! int alias_startIdx = getCurrentIndex(); ! std::string alias_name = namespace_name; ! if (!tryReadNextIdentifier(namespace_name)) ! { ! throwFailure( std::string("expected identifier for namespace alias." )); ! } ! namespaceNode->mutateType(ASTNodeTypes::namespaceAlias); ! // store alias name in property ! context_.bindNextNodeToProperty(namespaceNode,ASTNodeProperties::namespaceAliasProperty ); ! ! ASTNodePtr namespace_identifier = ! createASTNode( ASTNodeTypes::localScopeIdentifier, ! namespaceNode, ! alias_startIdx, getCurrentIndex() - alias_startIdx ); ! ! context_.addNode(namespace_identifier); ! ! skipSpaces(); ! expect(';'); ! } else ! { ! // this is a usual namespace definition: ! // "namespace x { }" ! int body_startIdx = getCurrentIndex(); ! expect('{'); ! findNextBalanced('{','}'); ! // store body in namespace-body-property ! context_.bindNextNodeToProperty(namespaceNode,ASTNodeProperties::namespaceBodyProperty ); ! ! ASTNodePtr namespace_body = ! createASTNode( ASTNodeTypes::unparsedDeclarationList, ! namespaceNode, ! body_startIdx, getCurrentIndex() - body_startIdx ); ! context_.addNode(namespace_body); ! } ! } namespaceNode->setLength( getCurrentLength() ); } } // namespace Refactoring --- 46,122 ---- // named namespace or unnamed namespace: // "namespace x" or "namespace { ... }" ! int nameStartIndex = getCurrentIndex(); ! std::string namespaceName; ! if (tryReadNextIdentifier(namespaceName)) { // namespace has an identifier which will be stored as child-node. ! ASTNodePtr namespaceIdentifier = createASTNode( ASTNodeTypes::localScopeIdentifier, namespaceNode, ! nameStartIndex, getCurrentIndex() - nameStartIndex + 1 ); ! namespaceNode->addChild( namespaceIdentifier ); } ! skipSpaces(); ! // check for definition of a namespace alias ! if ( tryNextIs('=') ) ! parseNamespaceAlias( namespaceName, namespaceNode ); ! else ! parseNamespaceBody( namespaceNode ); namespaceNode->setLength( getCurrentLength() ); } + + + void + NamespaceParser::parseNamespaceAlias( const std::string &namespace_name, + const ASTNodePtr &namespaceNode ) + { + // namespace alias: "namespace x = y;" + skipSpaces(); + + int aliasStartIndex = getCurrentIndex(); + std::string originalNamespaceName; + if ( !tryReadNextIdentifier(originalNamespaceName) ) + throwFailure( "expected identifier for namespace alias." ); + + namespaceNode->mutateType(ASTNodeTypes::namespaceAlias); + // store alias name in property + context_.bindNextNodeToProperty(namespaceNode,ASTNodeProperties::namespaceAliasProperty ); + + ASTNodePtr namespace_identifier = + createASTNode( ASTNodeTypes::localScopeIdentifier, + namespaceNode, + aliasStartIndex, getCurrentIndex() - aliasStartIndex ); + + context_.addNode(namespace_identifier); + + skipSpaces(); + expect(';'); + } + + + void + NamespaceParser::parseNamespaceBody( const ASTNodePtr &namespaceNode ) + { + // this is a usual namespace definition: + // "namespace x { }" + int bodyStartIndex = getCurrentIndex(); + expect('{'); + findNextBalanced('{','}'); + + // store body in namespace-body-property + context_.bindNextNodeToProperty(namespaceNode,ASTNodeProperties::namespaceBodyProperty ); + + ASTNodePtr namespaceBody = + createASTNode( ASTNodeTypes::unparsedDeclarationList, + namespaceNode, + bodyStartIndex, getCurrentIndex() - bodyStartIndex ); + + context_.addNode(namespaceBody); + } + } // namespace Refactoring Index: NamespaceParser.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/NamespaceParser.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NamespaceParser.h 12 Apr 2003 19:08:40 -0000 1.1 --- NamespaceParser.h 30 Apr 2003 19:20:13 -0000 1.2 *************** *** 30,33 **** --- 30,37 ---- private: + void parseNamespaceAlias( const std::string &namespace_name, + const ASTNodePtr &namespaceNode ); + + void parseNamespaceBody( const ASTNodePtr &namespaceNode ); }; |
From: <bl...@us...> - 2003-04-30 08:22:39
|
Update of /cvsroot/cpptool/rfta/include/xtl In directory sc8-pr-cvs1:/tmp/cvs-serv31419/include/xtl Added Files: IteratorTraits.h Log Message: * portability fixes: now compile & works on Sun CC 5.3 & AIX visual age. --- NEW FILE: IteratorTraits.h --- #ifndef XTL_ITERATORTRAITS_H_INCLUDED #define XTL_ITERATORTRAITS_H_INCLUDED #include <iterator> // Rogue Wave library: does not define iterator_traits on sunpro cc 5.3 #if defined( __SUNPRO_CC ) # if defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER) namespace std { // Implementation below from rogue wave documentation provided with sunpro cc 5.3. template <class Iterator> struct iterator_traits { typedef typename Iterator::value_type value_type; typedef typename Iterator::difference_type difference_type; typedef typename Iterator::pointer pointer; typedef typename Iterator::reference reference; // line below does not work for std::map::iterator // typedef typename Iterator::iterator_category // iterator_category; }; // Specialization template <class T> struct iterator_traits<T*> { typedef T value_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef T& reference; typedef random_access_iterator_tag iterator_category; }; } // namespace std # endif #endif #endif // XTL_ITERATORTRAITS_H_INCLUDED |
From: <bl...@us...> - 2003-04-30 08:21:44
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv30955/src/rftaparser Modified Files: EnumeratorTest.cpp Log Message: * portability fixes: now compile & works on Sun CC 5.3 & AIX visual age. Index: EnumeratorTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/EnumeratorTest.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** EnumeratorTest.cpp 28 Apr 2003 22:18:02 -0000 1.3 --- EnumeratorTest.cpp 30 Apr 2003 08:21:39 -0000 1.4 *************** *** 146,155 **** map.insert( StringIntMap::value_type( "ghi", 345 ) ); - StringEnum e = Xtl::enumStlMapKeys( map ); - RFTA_ASSERT_EQUAL( "abc", e.getNext() ); - RFTA_ASSERT_EQUAL( "def", e.getNext() ); - RFTA_ASSERT_EQUAL( "ghi", e.getNext() ); - checkHasNoMoreElements( e ); - StringIntMap::iterator itEnd = map.end(); --itEnd; --- 146,149 ---- |
From: <bl...@us...> - 2003-04-30 08:21:44
|
Update of /cvsroot/cpptool/rfta/include/xtl In directory sc8-pr-cvs1:/tmp/cvs-serv30955/include/xtl Modified Files: EnumAdaptor.h Enumerator.h EnumeratorImpl.h NullEnumerator.h StlEnumerator.h Log Message: * portability fixes: now compile & works on Sun CC 5.3 & AIX visual age. Index: EnumAdaptor.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/xtl/EnumAdaptor.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EnumAdaptor.h 27 Apr 2003 21:59:49 -0000 1.1 --- EnumAdaptor.h 30 Apr 2003 08:21:38 -0000 1.2 *************** *** 6,13 **** namespace Xtl { ! template<typename EnumeratedType> struct EnumAdaptor { ! typedef EnumeratedType EnumeratedType; }; --- 6,13 ---- namespace Xtl { ! template<typename TheEnumeratedType> struct EnumAdaptor { ! typedef TheEnumeratedType EnumeratedType; }; *************** *** 70,73 **** --- 70,75 ---- struct TransformEnumAdaptor : public EnumAdaptor<BOOST_DEDUCED_TYPENAME Functor::result_type> { + typedef BOOST_DEDUCED_TYPENAME Functor::result_type EnumeratedType; // AIX work-around + TransformEnumAdaptor() { *************** *** 93,96 **** --- 95,100 ---- struct ComposeAdaptor : public EnumAdaptor<BOOST_DEDUCED_TYPENAME OutterAdaptor::EnumeratedType> { + typedef BOOST_DEDUCED_TYPENAME OutterAdaptor::EnumeratedType EnumeratedType; // AIX work-around + ComposeAdaptor() { Index: Enumerator.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/xtl/Enumerator.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Enumerator.h 27 Apr 2003 21:59:49 -0000 1.1 --- Enumerator.h 30 Apr 2003 08:21:39 -0000 1.2 *************** *** 10,14 **** { public: ! typedef boost::intrusive_ptr< EnumeratorImpl<EnumeratedType> > ImplPtr; Enumerator() --- 10,15 ---- { public: ! // typedef boost::intrusive_ptr< EnumeratorImpl<EnumeratedType> > ImplPtr; ! typedef BOOST_DEDUCED_TYPENAME EnumeratorImpl<EnumeratedType>::Ptr ImplPtr; // sunpro CC work-around (type is incomplete error otherwise !?) Enumerator() Index: EnumeratorImpl.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/xtl/EnumeratorImpl.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EnumeratorImpl.h 27 Apr 2003 21:59:49 -0000 1.1 --- EnumeratorImpl.h 30 Apr 2003 08:21:39 -0000 1.2 *************** *** 27,31 **** { public: ! typedef boost::intrusive_ptr<EnumeratorImpl> Ptr; virtual EnumeratedType getNext() =0; --- 27,31 ---- { public: ! typedef boost::intrusive_ptr<EnumeratorImpl<EnumeratedType> > Ptr; virtual EnumeratedType getNext() =0; Index: NullEnumerator.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/xtl/NullEnumerator.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullEnumerator.h 27 Apr 2003 21:59:49 -0000 1.1 --- NullEnumerator.h 30 Apr 2003 08:21:39 -0000 1.2 *************** *** 9,12 **** --- 9,15 ---- class NullEnumeratorImpl : public EnumeratorImpl<EnumeratedType> { + public: + typedef BOOST_DEDUCED_TYPENAME EnumeratorImpl<EnumeratedType>::Ptr Ptr; // work-around for AIX + public: // overridden from EnumeratorImpl EnumeratedType getNext() Index: StlEnumerator.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/xtl/StlEnumerator.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StlEnumerator.h 28 Apr 2003 08:45:08 -0000 1.2 --- StlEnumerator.h 30 Apr 2003 08:21:39 -0000 1.3 *************** *** 4,10 **** #include <xtl/Enumerator.h> #include <xtl/EnumAdaptor.h> - #include <xtl/Int2Type.h> #include <xtl/Type.h> ! #include <boost/type_traits.hpp> namespace Xtl { --- 4,9 ---- #include <xtl/Enumerator.h> #include <xtl/EnumAdaptor.h> #include <xtl/Type.h> ! #include "IteratorTraits.h" namespace Xtl { *************** *** 17,25 **** { public: typedef StlEnumeratorImpl<StlForwardIteratorType,EnumeratedType,Adaptor> ThisType; - enum { - isIdentityAdaptor = ::boost::is_convertible<IdendityEnumAdpator<EnumeratedType> - ,Adaptor>::value - }; StlEnumeratorImpl( StlForwardIteratorType first, --- 16,22 ---- { public: + typedef BOOST_DEDUCED_TYPENAME EnumeratorImpl<EnumeratedType>::Ptr Ptr; // work-around for AIX + typedef StlEnumeratorImpl<StlForwardIteratorType,EnumeratedType,Adaptor> ThisType; StlEnumeratorImpl( StlForwardIteratorType first, *************** *** 45,49 **** throw EnumeratorError(); ! return doGetNext( Int2Type<isIdentityAdaptor>() ); } --- 42,46 ---- throw EnumeratorError(); ! return adaptor_( *current_++ ); } *************** *** 59,73 **** private: - inline EnumeratedType doGetNext( Int2Type<true> ) - { - return *current_++; - } - - inline EnumeratedType doGetNext( Int2Type<false> ) - { - return adaptor_( *current_++ ); - } - - private: StlForwardIteratorType current_; StlForwardIteratorType last_; --- 56,59 ---- *************** *** 166,178 **** - template<typename StlMapType> - Enumerator<BOOST_DEDUCED_TYPENAME StlMapType::key_type> - enumStlMapKeys( const StlMapType &map ) - { - typedef BOOST_DEDUCED_TYPENAME StlMapType::key_type EnumeratedType; - return enumStlAdapt( map, FirstEnumAdaptor<EnumeratedType>() ); - } - - template<typename StlMapType ,typename Adaptor> --- 152,155 ---- *************** *** 180,184 **** enumStlMapKeysAdapt( const StlMapType &map, Adaptor adaptor ) { ! return enumStlAdapt( map, ComposeAdaptor<Adaptor,FirstEnumAdaptor>() ); } --- 157,163 ---- enumStlMapKeysAdapt( const StlMapType &map, Adaptor adaptor ) { ! typedef BOOST_DEDUCED_TYPENAME Adaptor::EnumeratedType EnumeratedType; ! return enumStlAdapt( map, ComposeAdaptor<Adaptor ! ,FirstEnumAdaptor<EnumeratedType> >() ); } *************** *** 224,231 **** template<typename StlMapType> ! Enumerator<BOOST_DEDUCED_TYPENAME StlMapType::referent_type> enumStlMapValues( const StlMapType &map ) { ! typedef BOOST_DEDUCED_TYPENAME StlMapType::referent_type EnumeratedType; return enumStlAdapt( map, SecondEnumAdaptor<EnumeratedType>() ); } --- 203,210 ---- template<typename StlMapType> ! Enumerator<BOOST_DEDUCED_TYPENAME StlMapType::value_type::second_type> enumStlMapValues( const StlMapType &map ) { ! typedef BOOST_DEDUCED_TYPENAME StlMapType::value_type::second_type EnumeratedType; return enumStlAdapt( map, SecondEnumAdaptor<EnumeratedType>() ); } |
From: <bl...@us...> - 2003-04-30 08:06:33
|
Update of /cvsroot/cpptool/rfta/src/pyrfta In directory sc8-pr-cvs1:/tmp/cvs-serv25288/src/pyrfta Modified Files: ExposeStatements.cpp pyrfta.dsp Log Message: * added ExposeEnumerator to expose a Enumerato as a python iterator. Index: ExposeStatements.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/pyrfta/ExposeStatements.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ExposeStatements.cpp 10 Apr 2003 08:40:34 -0000 1.3 --- ExposeStatements.cpp 30 Apr 2003 08:06:29 -0000 1.4 *************** *** 2,5 **** --- 2,6 ---- #include <boost/python.hpp> #include <rfta/refactoring/CodeModelStatements.h> + #include <xtl/python/ExposeEnumerator.h> using namespace boost::python; *************** *** 10,13 **** --- 11,16 ---- exposeStatements() { + Xtl::Python::ExposeEnumerator<StatementPtr>( "StatementEnumerator" ); + void (Statement::*mfAcceptStatementVisitor)( StatementVisitor & ) = &Statement::accept; class_<Statement, bases<Element>, boost::noncopyable >( "Statement", no_init ) *************** *** 25,28 **** --- 28,32 ---- .def( "getChangeAt", &CompoundStatement::getChangeAt ) .def( "getChangeStatementAt", &CompoundStatement::getChangeStatementAt ) + .def( "getStatements", &CompoundStatement::getStatements ) ; Index: pyrfta.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/pyrfta/pyrfta.dsp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** pyrfta.dsp 27 Apr 2003 13:00:53 -0000 1.5 --- pyrfta.dsp 30 Apr 2003 08:06:29 -0000 1.6 *************** *** 116,119 **** --- 116,123 ---- # Begin Source File + SOURCE=..\..\include\xtl\python\ExposeEnumerator.h + # End Source File + # Begin Source File + SOURCE=.\ExposeExpressions.cpp # End Source File |
From: <bl...@us...> - 2003-04-30 08:06:32
|
Update of /cvsroot/cpptool/rfta/include/xtl/python In directory sc8-pr-cvs1:/tmp/cvs-serv25288/include/xtl/python Added Files: ExposeEnumerator.h Log Message: * added ExposeEnumerator to expose a Enumerato as a python iterator. --- NEW FILE: ExposeEnumerator.h --- #ifndef PYRFTA_EXPOSE_ENUMERATOR_H_INCLUDED #define PYRFTA_EXPOSE_ENUMERATOR_H_INCLUDED #include <boost/python.hpp> #include <xtl/Enumerator.h> namespace Xtl { namespace Python { class ExposeEnumeratorInit { public: ExposeEnumeratorInit() { static Initializer dummy; } static void translate_EnumeratorError( const Xtl::EnumeratorError &e ) { // Use the Python 'C' API to set up an exception object PyErr_SetString( PyExc_StopIteration, e.what() ); } private: class Initializer { public: Initializer() { boost::python::register_exception_translator<Xtl::EnumeratorError>( &translate_EnumeratorError ); } }; }; /** Use this to expose a Xtl::Enumerator to python. * For example, * \code * Xtl::Python::ExposeEnumerator<StatementPtr>( "StatementEnumerator" ); * \endcode * will expose the class Xtl::Enumerator<StatementPtr> to python as a python iterator. */ template<typename EnumeratedType> class ExposeEnumerator : private ExposeEnumeratorInit { public: typedef Xtl::Enumerator<EnumeratedType> WrappedEnumerator; ExposeEnumerator( const char *name ) { boost::python::class_< WrappedEnumerator >( "StatementEnumerator" ) .def( "next", &WrappedEnumerator::getNext ) .def( "__iter__", &Enumerator_iter ) ; } private: static WrappedEnumerator Enumerator_iter( const WrappedEnumerator &enumerator ) { return enumerator; } }; } } // namespace Xtl { namespace Python #endif // PYRFTA_EXPOSE_ENUMERATOR_H_INCLUDED |
From: <bl...@us...> - 2003-04-30 08:03:24
|
Update of /cvsroot/cpptool/rfta/include/xtl/python In directory sc8-pr-cvs1:/tmp/cvs-serv24212/python Log Message: Directory /cvsroot/cpptool/rfta/include/xtl/python added to the repository |
From: <bl...@us...> - 2003-04-29 22:13:22
|
Update of /cvsroot/cpptool/rfta/bin In directory sc8-pr-cvs1:/tmp/cvs-serv23650/bin Modified Files: test.bat Added Files: CPPParser.cpp Log Message: * added a test using CPPParser.cpp (with class declaration in anonymous namespace and inline method implementation) --- NEW FILE: CPPParser.cpp --- #include "stdafx.h" #include <rfta/parser/CPPParser.h> #include <rfta/parser/NonSemanticBlanker.h> #include <rfta/parser/MaxLODMutator.h> #include <rfta/parser/DeclarationListParser.h> #include <rfta/parser/ParseContext.h> #include <rfta/parser/ParserError.h> #include <rfta/parser/ASTNodeAndPropertyVisitor.h> #include <rfta/parser/ASTNodes.h> namespace Refactoring { namespace { class FunctionImplementationVisitor : public ASTNodeAndPropertyVisitor { public: FunctionImplementationVisitor( int functionBodyPosition ) : functionBodyPosition_( functionBodyPosition ) , foundFunction_( false ) { } ASTNodePtr findFunctionImplementation( const ASTNodePtr &node ) { visitNode( node ); if ( !foundFunction_ ) return ASTNodePtr(); return functionImplementationNode_; } protected: // overridden from ASTNodeAndPropertyVisitor bool canSkipNode( const ASTNodePtr &node ) const { return foundFunction_; } bool needsToVisitProperties( const ASTNodePtr &node ) const { return !foundFunction_; } bool needsToVisitChildren( const ASTNodePtr &node ) const { return node->getType().hasSomeFeatureOf( ASTNodeTypeFeatures::mayHaveFunctionImplChildren ); } bool needsToHandleNode( const ASTNodePtr& node ) const { return node->getType() == ASTNodeTypes::functionImplementation && !foundFunction_; } void handleNode( const ASTNodePtr& node ) { if ( node->getRange().contains( SourceRange( functionBodyPosition_,0 ) ) ) { foundFunction_ = true; functionImplementationNode_ = node; } } private: bool foundFunction_; int functionBodyPosition_; ASTNodePtr functionImplementationNode_; }; } CPPParser::CPPParser( const std::string &source ) { NullPPDirectiveListener nullListener; std::string blankedSource; NonSemanticBlanker blanker( source, blankedSource, nullListener ); blanker.blank(); sourceNode_ = SourceASTNode::create( blankedSource, source ); } SourceASTNodePtr CPPParser::getSourceNode() const { return sourceNode_; } ASTNodePtr CPPParser::parseForFunctionBodyAt( int position ) { parseAll(); FunctionImplementationVisitor visitor( position ); return visitor.findFunctionImplementation( sourceNode_ ); } void CPPParser::parseForFunctionDeclarations() { parseAll(); } void CPPParser::parseAll() { ParseContext context( sourceNode_ ); DeclarationListParser parser( context, sourceNode_->getBlankedSourceStart(), sourceNode_->getBlankedSourceEnd() ); if ( !parser.tryParse() ) throw ParserError( "top level source file parsing failed.", context ); MaxLODMutator mutator; mutator.mutate( sourceNode_, sourceNode_ ); } */ } // namespace Refactoring Index: test.bat =================================================================== RCS file: /cvsroot/cpptool/rfta/bin/test.bat,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** test.bat 29 Apr 2003 10:06:11 -0000 1.9 --- test.bat 29 Apr 2003 21:46:55 -0000 1.10 *************** *** 7,9 **** --- 7,10 ---- rem astdump 0 15 DeclarativeCondition.cpp ast rem astdump 0 4 ForDeclaration.cpp ast + astdump 1 127 CPPParser.cpp ast |
From: <bl...@us...> - 2003-04-29 22:07:01
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv31276/src/rftaparser Modified Files: DeclarationListParser.cpp Log Message: * fixed typo in keyword 'signals' * refactored a bit Index: DeclarationListParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationListParser.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DeclarationListParser.cpp 28 Apr 2003 20:41:15 -0000 1.4 --- DeclarationListParser.cpp 29 Apr 2003 22:06:57 -0000 1.5 *************** *** 35,39 **** * unlike compound statement we seperate the file into ast nodes * as we understand the syntax now. ! */ bool DeclarationListParser::tryParse() --- 35,39 ---- * unlike compound statement we seperate the file into ast nodes * as we understand the syntax now. ! */ bool DeclarationListParser::tryParse() *************** *** 46,64 **** keywords.insert( "private" ); keywords.insert( "protected" ); ! keywords.insert( "signal" ); do { skipSpaces(); - if (!hasNext()) break; ! Xtl::CStringEnumerator en(Xtl::CStringView( current_, end_ ).enumerate() ); ! std::string ident; ! ident = ParserTools::tryReadKeyword(en,keywords); ! if (!ident.empty()) { ! ParserTools::skipUntil(en,':'); // @todo: store information on visibility ! current_ = en.getCurrentPos(); skipSpaces(); } --- 46,64 ---- keywords.insert( "private" ); keywords.insert( "protected" ); ! keywords.insert( "signals" ); do { skipSpaces(); ! if ( !hasNext() ) ! break; ! Xtl::CStringEnumerator current(Xtl::CStringView( current_, end_ ).enumerate() ); ! std::string keyword = ParserTools::tryReadKeyword(current,keywords); ! if (!keyword.empty()) { ! ParserTools::skipUntil(current,':'); // @todo: store information on visibility ! current_ = current.getCurrentPos(); skipSpaces(); } |
From: <bl...@us...> - 2003-04-29 22:04:33
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv30424/src/rftaparser Added Files: CPPParserTest.cpp CPPParserTest.h Log Message: * added --- NEW FILE: CPPParserTest.cpp --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2003/04/29 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "CPPParserTest.h" #include <rfta/parser/CPPParser.h> namespace Refactoring { CPPUNIT_TEST_SUITE_REGISTRATION( CPPParserTest ); CPPParserTest::CPPParserTest() : functionKey_( "Function" ) , selectionKey_( "Selection" ) { } CPPParserTest::~CPPParserTest() { } void CPPParserTest::setUp() { } void CPPParserTest::tearDown() { } void CPPParserTest::checkParseFunctionAt( const Testing::KeyedString &source ) { CPPParser parser( source ); int selectionIndex = source.getKeyedIndex( selectionKey_, 0 ); ASTNodePtr functionNode = parser.parseForFunctionBodyAt( selectionIndex ); CPPUNIT_ASSERT_MESSAGE( "Failed to find function implementation node", functionNode ); CPPUNIT_ASSERT( functionNode->getRange().contains( SourceRange( selectionIndex, 0 ) ) ); CPPUNIT_ASSERT( functionNode->getRange() == source.getKeyedRange( functionKey_, 0 ) ); } void CPPParserTest::addFunctionImplementation( Testing::KeyedString &source ) { source.setKeyStart( functionKey_ ); source << "int function() {\n"; source << "return "; source.addKeyed( selectionKey_, "10" ); source << ";\n}"; source.setKeyEnd( functionKey_ ); } void CPPParserTest::testParseFunction() { Testing::KeyedString source; source << "// source\n"; addFunctionImplementation( source ); source << " "; checkParseFunctionAt( source ); } void CPPParserTest::testParseFunctionInNamespace() { Testing::KeyedString source; source << "// source\n" << "namespace Source {"; addFunctionImplementation( source ); source << " } // namespace Source "; checkParseFunctionAt( source ); } void CPPParserTest::testParseFunctionInNestedNamespace() { Testing::KeyedString source; source << "// source\n" << "namespace Source {\n" << "namespace Nested { "; addFunctionImplementation( source ); source << " } // namespace Nested\n"; source << " } // namespace Source\n"; checkParseFunctionAt( source ); } void CPPParserTest::testParseFunctionInClassDeclaration() { } } // namespace Refactoring --- NEW FILE: CPPParserTest.h --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2003/04/29 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_CPPPARSERTEST_H #define RFTA_CPPPARSERTEST_H #include "UnitTesting.h" #include "KeyedString.h" namespace Refactoring { /// Unit tests for CPPParserTest class CPPParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( CPPParserTest ); CPPUNIT_TEST( testParseFunction ); CPPUNIT_TEST( testParseFunctionInNamespace ); CPPUNIT_TEST( testParseFunctionInNestedNamespace ); CPPUNIT_TEST( testParseFunctionInClassDeclaration ); CPPUNIT_TEST_SUITE_END(); public: /*! Constructs a CPPParserTest object. */ CPPParserTest(); /// Destructor. virtual ~CPPParserTest(); void setUp(); void tearDown(); void testParseFunction(); void testParseFunctionInNamespace(); void testParseFunctionInNestedNamespace(); void testParseFunctionInClassDeclaration(); private: void checkParseFunctionAt( const Testing::KeyedString &source ); void addFunctionImplementation( Testing::KeyedString &source ); const std::string functionKey_; const std::string selectionKey_; }; // Inlines methods for CPPParserTest: // ---------------------------------- } // namespace Refactoring #endif // RFTA_CPPPARSERTEST_H |
From: <bl...@us...> - 2003-04-29 22:03:48
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv30050/src/rftaparser Modified Files: rftaparser.dsp Log Message: * added missing file * added CPPParserTest Index: rftaparser.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** rftaparser.dsp 28 Apr 2003 22:18:06 -0000 1.45 --- rftaparser.dsp 29 Apr 2003 22:03:43 -0000 1.46 *************** *** 202,205 **** --- 202,213 ---- # Begin Source File + SOURCE=.\DeclarationDetailsParser.cpp + # End Source File + # Begin Source File + + SOURCE=.\DeclarationDetailsParser.h + # End Source File + # Begin Source File + SOURCE=.\DeclarationListParser.cpp # End Source File *************** *** 1227,1230 **** --- 1235,1246 ---- # Begin Source File + SOURCE=.\CPPParserTest.cpp + # End Source File + # Begin Source File + + SOURCE=.\CPPParserTest.h + # End Source File + # Begin Source File + SOURCE=.\NonSemanticBlankerTest.h *************** *** 1280,1287 **** --- 1296,1321 ---- SOURCE=.\ParserToolsTest.cpp + + !IF "$(CFG)" == "rftaparser - Win32 Release" + + # PROP Exclude_From_Build 1 + + !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug" + + !ENDIF + # End Source File # Begin Source File SOURCE=.\ParserToolsTest.h + + !IF "$(CFG)" == "rftaparser - Win32 Release" + + # PROP Exclude_From_Build 1 + + !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug" + + !ENDIF + # End Source File # Begin Source File |
From: <bl...@us...> - 2003-04-29 22:02:59
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv29682/src/rftaparser Modified Files: KeyedString.h Log Message: * added getKeyedRange() * refactored a bit Index: KeyedString.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/KeyedString.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** KeyedString.h 28 Apr 2003 11:05:20 -0000 1.2 --- KeyedString.h 29 Apr 2003 22:02:42 -0000 1.3 *************** *** 9,12 **** --- 9,13 ---- #include <map> #include <string> + #include <rfta/parser/SourceRange.h> *************** *** 18,37 **** public: KeyedString& operator<< (std::string characters); operator std::string () const; KeyedString& addKeyed (std::string key , std::string word ); std::string asString() const; std::vector<int> getKeyedIndex(std::string key) const; std::vector<int> getKeyedLen(std::string key) const; int getKeyedIndex(std::string key,int index) const; int getKeyedLen(std::string key,int index) const; std::string getWord(std::string key, int index) const; int length() const; KeyedString& setKeyStart(std::string key); KeyedString& setKeyEnd(std::string key); protected: std::string sequence_; ! std::map<std::string,std::vector<int> > wordIndex_; ! std::map<std::string,std::vector<int> > wordLen_; ! std::map<std::string,std::vector<std::string> > word_; }; --- 19,54 ---- public: KeyedString& operator<< (std::string characters); + operator std::string () const; + KeyedString& addKeyed (std::string key , std::string word ); + std::string asString() const; + + SourceRange getKeyedRange( const std::string &key, int index ) const; + std::vector<int> getKeyedIndex(std::string key) const; + std::vector<int> getKeyedLen(std::string key) const; + int getKeyedIndex(std::string key,int index) const; + int getKeyedLen(std::string key,int index) const; + std::string getWord(std::string key, int index) const; + int length() const; + KeyedString& setKeyStart(std::string key); + KeyedString& setKeyEnd(std::string key); + protected: std::string sequence_; ! typedef std::map<std::string,std::vector<int> > WordIndexes; ! WordIndexes wordIndex_; ! WordIndexes wordLen_; ! typedef std::map<std::string,std::vector<std::string> > Words; ! Words word_; }; *************** *** 54,62 **** } inline std::vector<int> KeyedString::getKeyedIndex(std::string key) const { ! std::map<std::string,std::vector<int> >::const_iterator it; ! it = wordIndex_.find(key); ! if (it == wordIndex_.end()) return std::vector<int>(); return (*it).second; } --- 71,87 ---- } + + inline SourceRange + KeyedString::getKeyedRange( const std::string &key, int index ) const + { + return SourceRange( getKeyedIndex( key, index), getKeyedLen( key, index ) ); + } + + inline std::vector<int> KeyedString::getKeyedIndex(std::string key) const { ! WordIndexes::const_iterator it = wordIndex_.find(key); ! if (it == wordIndex_.end()) ! return std::vector<int>(); return (*it).second; } *************** *** 64,69 **** inline std::vector<int> KeyedString::getKeyedLen(std::string key) const { ! std::map<std::string,std::vector<int> >::const_iterator it; ! it = wordLen_.find(key); if (it == wordLen_.end()) return std::vector<int>(); return (*it).second; --- 89,93 ---- inline std::vector<int> KeyedString::getKeyedLen(std::string key) const { ! WordIndexes::const_iterator it = wordLen_.find(key); if (it == wordLen_.end()) return std::vector<int>(); return (*it).second; *************** *** 72,101 **** inline int KeyedString::getKeyedIndex(std::string key, int index) const { ! std::map<std::string,std::vector<int> >::const_iterator it; ! it = wordIndex_.find(key); ! if (it == wordIndex_.end()) throw std::logic_error("No string registered for this key."); ! if ((*it).second.size()<index) throw std::logic_error("Index out of range."); ! return (*it).second[index]; } inline int KeyedString::getKeyedLen(std::string key, int index) const { ! std::map<std::string,std::vector<int> >::const_iterator it; ! it = wordLen_.find(key); ! if (it == wordLen_.end()) throw std::logic_error("No string registered for this key."); ! if ((*it).second.size()<index) throw std::logic_error("Index out of range."); ! return (*it).second[index]; } inline std::string KeyedString::getWord(std::string key, int index) const { ! std::map<std::string,std::vector<std::string> >::const_iterator it; ! it = word_.find(key); if (it == word_.end()) ! throw std::logic_error("No string registered for this key."); ! if ((*it).second.size() < index) ! throw std::logic_error("Index out of range."); ! ! return ((*it).second)[index]; } --- 96,118 ---- inline int KeyedString::getKeyedIndex(std::string key, int index) const { ! WordIndexes::const_iterator it = wordIndex_.find(key); ! if (it == wordIndex_.end()) ! throw std::logic_error("No string registered for key:" + key); ! return (*it).second.at(index); } inline int KeyedString::getKeyedLen(std::string key, int index) const { ! WordIndexes::const_iterator it = wordLen_.find(key); ! if (it == wordLen_.end()) throw std::logic_error("No string registered for key:" + key); ! return (*it).second.at(index); } inline std::string KeyedString::getWord(std::string key, int index) const { ! Words::const_iterator it = word_.find(key); if (it == word_.end()) ! throw std::logic_error("No string registered for key:" + key); ! return it->second.at(index); } |
From: <bl...@us...> - 2003-04-29 22:02:18
|
Update of /cvsroot/cpptool/rfta/include/xtl In directory sc8-pr-cvs1:/tmp/cvs-serv29515/include/xtl Modified Files: CStringView.h Log Message: * added implicit cast to const char * on enumerators * added setCurrent() method on enumerators. Index: CStringView.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/xtl/CStringView.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CStringView.h 26 Apr 2003 21:10:27 -0000 1.3 --- CStringView.h 29 Apr 2003 22:02:14 -0000 1.4 *************** *** 199,202 **** --- 199,217 ---- } + operator const char *() const + { + return current_; + } + + void setCurrent( const char *current ) + { + if ( current > string_.getEnd() ) + current_ = string_.getEnd(); + else if ( current_ < string_.getStart() ) + current_ = string_.getStart(); + else + current_ = current; + } + protected: CStringView string_; |
From: <bl...@us...> - 2003-04-29 22:01:25
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv28984/include/rfta/parser Modified Files: ASTNodeType.h CPPParser.h Log Message: * implemented CPPParser::parseFunctionImplementationAt() * added node type features to explorer up to function body level Index: ASTNodeType.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/ASTNodeType.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ASTNodeType.h 21 Nov 2002 21:07:27 -0000 1.6 --- ASTNodeType.h 29 Apr 2003 22:00:48 -0000 1.7 *************** *** 41,44 **** --- 41,46 ---- /// Indicates that the node may have scope generator children mayHaveScopeGeneratorChildren = (mayHaveScopeGeneratorProperties << 1), + /// Indicates that the node may contains a function implementation + mayHaveFunctionImplChildren = (mayHaveScopeGeneratorChildren << 1), isCompositeStatement = (isComposite | isStatement), Index: CPPParser.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/CPPParser.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CPPParser.h 27 Apr 2003 12:58:24 -0000 1.2 --- CPPParser.h 29 Apr 2003 22:00:50 -0000 1.3 *************** *** 14,22 **** SourceASTNodePtr getSourceNode() const; ! void parseForFunctionBodyAt( int position ); void parseForFunctionDeclarations(); void parseAll(); private: --- 14,34 ---- SourceASTNodePtr getSourceNode() const; ! /*! Search the function body at the specified location and parse it. ! * \return functionImplementation ASTNode if a function body was found ! * at the specified location, \c 0 otherwise. ! * \exception ParserError is throw if a failure occurs during parsing. ! */ ! ASTNodePtr parseForFunctionBodyAt( int position ); void parseForFunctionDeclarations(); + /*! Parse the source completely. + * \exception ParserError is throw if a failure occurs during parsing. + */ void parseAll(); + + private: + ASTNodePtr findFunctionImplementationAt( int position, + const ASTNodePtr &parentNode ) const; private: |
From: <bl...@us...> - 2003-04-29 22:01:00
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv28984/src/rftaparser Modified Files: ASTNodes.cpp CPPParser.cpp Log Message: * implemented CPPParser::parseFunctionImplementationAt() * added node type features to explorer up to function body level Index: ASTNodes.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ASTNodes.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** ASTNodes.cpp 29 Apr 2003 10:29:16 -0000 1.21 --- ASTNodes.cpp 29 Apr 2003 22:00:53 -0000 1.22 *************** *** 11,15 **** { ! const ASTNodeType ASTNodeTypes::source( "source-file", isCompositeStatement ); const ASTNodeType ASTNodeTypes::unknownConstruct ( "unknown-construct" , 0 ); --- 11,15 ---- { ! const ASTNodeType ASTNodeTypes::source( "source-file", isCompositeStatement | mayHaveFunctionImplChildren ); const ASTNodeType ASTNodeTypes::unknownConstruct ( "unknown-construct" , 0 ); *************** *** 19,24 **** const ASTNodeType ASTNodeTypes::usingNamespace ( "using-namespace" , 0 ); const ASTNodeType ASTNodeTypes::namespaceAlias ( "namespace-alias" , mayHaveLocalScopeIdentifierChildren ); ! const ASTNodeType ASTNodeTypes::namespaceDeclaration ( "namespace-declaration" , mayHaveLocalScopeIdentifierChildren ); ! const ASTNodeType ASTNodeTypes::declarationList ( "declaration-list" , mayHaveLocalScopeIdentifierChildren ); const ASTNodeType ASTNodeTypes::functionImplementation ( "function-implementation" , mayHaveLocalScopeIdentifierChildren ); const ASTNodeType ASTNodeTypes::unparsedDeclarationList ( "unparsed-declaration-list", mayHaveLocalScopeIdentifierChildren ); --- 19,24 ---- const ASTNodeType ASTNodeTypes::usingNamespace ( "using-namespace" , 0 ); const ASTNodeType ASTNodeTypes::namespaceAlias ( "namespace-alias" , mayHaveLocalScopeIdentifierChildren ); ! const ASTNodeType ASTNodeTypes::namespaceDeclaration ( "namespace-declaration" , mayHaveLocalScopeIdentifierChildren | mayHaveFunctionImplChildren ); ! const ASTNodeType ASTNodeTypes::declarationList ( "declaration-list" , mayHaveLocalScopeIdentifierChildren | mayHaveFunctionImplChildren ); const ASTNodeType ASTNodeTypes::functionImplementation ( "function-implementation" , mayHaveLocalScopeIdentifierChildren ); const ASTNodeType ASTNodeTypes::unparsedDeclarationList ( "unparsed-declaration-list", mayHaveLocalScopeIdentifierChildren ); Index: CPPParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/CPPParser.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CPPParser.cpp 26 Apr 2003 21:13:35 -0000 1.1 --- CPPParser.cpp 29 Apr 2003 22:00:54 -0000 1.2 *************** *** 7,14 **** --- 7,77 ---- #include <rfta/parser/ParseContext.h> #include <rfta/parser/ParserError.h> + #include <rfta/parser/ASTNodeAndPropertyVisitor.h> + #include <rfta/parser/ASTNodes.h> namespace Refactoring { + + namespace { + + class FunctionImplementationVisitor : public ASTNodeAndPropertyVisitor + { + public: + FunctionImplementationVisitor( int functionBodyPosition ) + : functionBodyPosition_( functionBodyPosition ) + , foundFunction_( false ) + { + } + + ASTNodePtr findFunctionImplementation( const ASTNodePtr &node ) + { + visitNode( node ); + + if ( !foundFunction_ ) + return ASTNodePtr(); + + return functionImplementationNode_; + } + + protected: // overridden from ASTNodeAndPropertyVisitor + bool canSkipNode( const ASTNodePtr &node ) const + { + return foundFunction_; + } + + bool needsToVisitProperties( const ASTNodePtr &node ) const + { + return !foundFunction_; + } + + bool needsToVisitChildren( const ASTNodePtr &node ) const + { + return node->getType().hasSomeFeatureOf( ASTNodeTypeFeatures::mayHaveFunctionImplChildren ); + } + + bool needsToHandleNode( const ASTNodePtr& node ) const + { + return node->getType() == ASTNodeTypes::functionImplementation && !foundFunction_; + } + + void handleNode( const ASTNodePtr& node ) + { + if ( node->getRange().contains( SourceRange( functionBodyPosition_,0 ) ) ) + { + foundFunction_ = true; + functionImplementationNode_ = node; + } + } + + private: + bool foundFunction_; + int functionBodyPosition_; + ASTNodePtr functionImplementationNode_; + }; + + } + + CPPParser::CPPParser( const std::string &source ) { *************** *** 29,35 **** ! void CPPParser::parseForFunctionBodyAt( int position ) { } --- 92,102 ---- ! ASTNodePtr CPPParser::parseForFunctionBodyAt( int position ) { + parseAll(); + + FunctionImplementationVisitor visitor( position ); + return visitor.findFunctionImplementation( sourceNode_ ); } *************** *** 38,41 **** --- 105,109 ---- CPPParser::parseForFunctionDeclarations() { + parseAll(); } *************** *** 49,66 **** sourceNode_->getBlankedSourceEnd() ); ! try ! { ! if ( !parser.tryParse() ) ! { ! } // should report error in some way... ! MaxLODMutator mutator; ! mutator.mutate( sourceNode_, sourceNode_ ); ! } ! catch ( ParserError & ) ! { ! // should report error in some way... ! } } ! } // namespace Refactoring \ No newline at end of file --- 117,127 ---- sourceNode_->getBlankedSourceEnd() ); ! if ( !parser.tryParse() ) ! throw ParserError( "top level source file parsing failed.", context ); ! MaxLODMutator mutator; ! mutator.mutate( sourceNode_, sourceNode_ ); } ! } // namespace Refactoring ! |