From: <net...@us...> - 2004-01-13 22:29:31
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv10617/include/rfta/parser Added Files: FileSourceManager.h PositionTranslator.h PreProcessorContext.h Source.h SourceManager.h Log Message: preprocessor implementation --- NEW FILE: FileSourceManager.h --- // ////////////////////////////////////////////////////////////////////////// // Header file FileSourceManager.h for class FileSourceManager // (c)Copyright 2003, Andre Baresel. // Created: 2003/12/28 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_FILESOURCEMANAGER_H #define RFTA_FILESOURCEMANAGER_H #include <rfta/parser/Config.h> #include <boost/shared_ptr.hpp> #include <rfta/parser/SourceManager.h> #include <boost/filesystem/path.hpp> #include <vector> namespace Refactoring { /** * FileSourceManager. * A SourceManager implementation doing direct file system access. * This is only useful for console application based refactoring. */ class FileSourceManager: public SourceManager { public: /*! Constructs a FileSourceManager object. */ FileSourceManager() { } /// Destructor. virtual ~FileSourceManager() { } /** * create an source object for the given name. */ virtual SourcePtr open(std::string sourceName); void setRoot(const boost::filesystem::path& sourcePath); /** * set an additional include path. */ void setInclude(std::string includeDir); private: typedef std::vector<boost::filesystem::path> PathList; boost::filesystem::path sourcePath_; PathList includeDirList_; }; // Inlines methods for FileSourceManager: // ---------------------------------- inline void FileSourceManager::setRoot(const boost::filesystem::path& sourcePath) { sourcePath_ = sourcePath; } inline void FileSourceManager::setInclude(std::string includeDir) { includeDirList_.push_back(boost::filesystem::path( includeDir ,boost::filesystem::native )); } } // namespace Refactoring #endif // RFTA_FILESOURCEMANAGER_H --- NEW FILE: PositionTranslator.h --- // ////////////////////////////////////////////////////////////////////////// // Header file PositionTranslator.h for class PositionTranslator // (c)Copyright 2003, Andre Baresel. // Created: 2003/12/31 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_POSITIONTRANSLATOR_H #define RFTA_POSITIONTRANSLATOR_H #include <rfta/parser/Config.h> #include <boost/shared_ptr.hpp> #include <map> #include <rfta/parser/SourceRange.h> namespace Refactoring { class PositionTranslator; typedef boost::shared_ptr<PositionTranslator> PositionTranslatorPtr; /// PositionTranslator. class RFTAPARSER_API PositionTranslator { public: /*! Constructs a PositionTranslator object. */ PositionTranslator(); void addReplacement(const SourceRange& range, int replacementLen); /** * translates the position of preprocessed source code into * the original range. */ SourceRange translate(const SourceRange& range) const; /** * translates the position of original source code into * the range in preprocessed. */ SourceRange reverseTranslate(const SourceRange& range) const; private: struct Transposition { SourceRange origin_; int offsetDifference_; SourceRange preprocessed_; }; typedef std::map<int, Transposition> TranslationMap; TranslationMap translationMap_; TranslationMap::const_iterator getLower(int index) const; TranslationMap::const_iterator getUpper(int index) const; void changeFollowingTranslation(TranslationMap::iterator first, int moveBy); }; // Inlines methods for PositionTranslator: // ---------------------------------- inline PositionTranslator::PositionTranslator() { } } // namespace Refactoring #endif // RFTA_POSITIONTRANSLATOR_H --- NEW FILE: PreProcessorContext.h --- // ////////////////////////////////////////////////////////////////////////// // Header file PreProcessorContextContext.h for class PreProcessorContext // (c)Copyright 2003, Andre Baresel // Created: 2003/12/27 // ////////////////////////////////////////////////////////////////////////// #include <string> #include <stack> #ifndef REFACTORING_PREPROCESSORCONTEXT_H_INCLUDED #define REFACTORING_PREPROCESSORCONTEXT_H_INCLUDED #include <rfta/parser/Config.h> #include "SourceManager.h" namespace Refactoring { class RFTAPARSER_API PreProcessorContext { public: PreProcessorContext(SourceManager& manager); SourceManager& getSourceManager() const; /** * set 'source' as active source and store * the former source-ptr. */ void enterSource(SourcePtr source); /** * leave current source and return to parent. * (restore former source-ptr) */ void leaveSource(); /** * test for identifier in macro list. */ bool isMacroIdentifier( std::string identifier ); /** * returns the replacement text for macro identifier * @throw PreProcessorError if macro identifier is not defined. */ std::string getMacroReplacement( std::string macroident ); /** * inserts a none parameterized macro replacement entry */ void addMacro(std::string ident, std::string replacement); private: typedef std::map< std::string , std::string > MacroDefMap; /// storage for directives /// 1. include information /// 2. macro definitions MacroDefMap macroDef_; SourceManager& sourceManager_; SourcePtr source_; typedef std::stack<SourcePtr> SourceStack; SourceStack sources_; }; // INLINE CODE: inline PreProcessorContext::PreProcessorContext(SourceManager& manager) :sourceManager_(manager) { } inline SourceManager& PreProcessorContext::getSourceManager() const { return sourceManager_; } } #endif // REFACTORING_PREPROCESSORCONTEXT_H_INCLUDED --- NEW FILE: Source.h --- // ////////////////////////////////////////////////////////////////////////// // Header file Source.h for class Source // (c)Copyright 2003, Andre Baresel. // Created: 2003/12/21 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_SOURCE_H #define RFTA_SOURCE_H #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> #include <rfta/parser/TextDocument.h> #include <deque> #include "SourceRange.h" #include <rfta/parser/PositionTranslator.h> namespace Refactoring { class Source; typedef boost::shared_ptr<Source> SourcePtr; typedef boost::weak_ptr<Source> SourceWeakPtr; /// Source. class RFTAPARSER_API Source { public: /*! Constructs a Source object. */ Source(TextDocumentPtr document); /*! Constructs a Source object. */ Source(TextDocumentPtr document, std::string identifier); /** * store range of an include * * @param range source range within original source text */ void registerInclude(const SourceRange& range, int includeLength, const SourcePtr include); /** * store range of a text replacement (e.g. Macro) * * @param range source range within original source text */ void registerReplacement(const SourceRange& range, int replacementLen); /** * returns the range in preprocessed source */ SourceRange getRangePreProcessed(const SourceRange& range); /** * returns the range in original source */ SourceRange getRangeOrigin(const SourceRange& range) const; /** * returns the original source text. */ std::string getOriginalText() const; /** * returns the source that holds the range. * (does care about includes and forwards the request) * * @param range source range within preprocessed source text */ Source& getSourceOrigin(const SourceRange& range); /** * return the source text of the range in original file. * (does translate the position and uses the original source) * (does care about includes and forwards the request) * * @param range source range within preprocessed source text */ std::string getOriginalText(const SourceRange& range); /** * @param index position in preprocessed source text. * * @return line number */ int getLineNumberOf(int index) const; std::string getIdentifier() const; TextDocumentPtr getTextDocument(); /// Destructor. virtual ~Source(); private: struct IncludeEntry { SourceRange range_; SourceRange preprocessedRange_; SourcePtr include_; }; typedef std::deque<IncludeEntry> IncludeList; IncludeList includeList_; TextDocumentPtr document_; std::string identifier_; PositionTranslator translator_; IncludeList::const_iterator getSourceOriginInternal(const SourceRange& range) const; }; // Inlines methods for Source: // ---------------------------------- inline std::string Source::getOriginalText() const { return document_->getAllText(); } inline TextDocumentPtr Source::getTextDocument() { return document_; } inline std::string Source::getIdentifier() const { return identifier_; } } // namespace Refactoring #endif // RFTA_SOURCE_H --- NEW FILE: SourceManager.h --- // ////////////////////////////////////////////////////////////////////////// // Header file SourceManager.h for class SourceManager // (c)Copyright 2003, Andre Baresel. // Created: 2003/12/21 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_SOURCEMANAGER_H #define RFTA_SOURCEMANAGER_H #include <boost/shared_ptr.hpp> #include <rfta/parser/Config.h> #include <rfta/parser/TextDocument.h> namespace Refactoring { class Source; typedef boost::shared_ptr<Source> SourcePtr; /// SourceManager. class RFTAPARSER_API SourceManager { public: /*! Constructs a SourceManager object. */ SourceManager() { } /// Destructor. virtual ~SourceManager() { } /** * create an source object for the given name. */ virtual SourcePtr open(std::string sourceName) = 0; }; class NullSourceManager: public SourceManager { public: SourcePtr open(std::string sourceName); }; // Inlines methods for SourceManager: // ---------------------------------- inline SourcePtr NullSourceManager::open(std::string sourceName) { return SourcePtr(); } } // namespace Refactoring #endif // RFTA_SOURCEMANAGER_H |