mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Moving LiteralScope to Scanner.cpp
This commit is contained in:
		
							parent
							
								
									a595464739
								
							
						
					
					
						commit
						21fdd84c09
					
				
							
								
								
									
										41
									
								
								Scanner.cpp
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								Scanner.cpp
									
									
									
									
									
								
							| @ -102,6 +102,47 @@ int hexValue(char c) | ||||
| } | ||||
| } // end anonymous namespace
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /// Scoped helper for literal recording. Automatically drops the literal
 | ||||
| /// if aborting the scanning before it's complete.
 | ||||
| enum LiteralType { | ||||
| 	LITERAL_TYPE_STRING, | ||||
| 	LITERAL_TYPE_NUMBER, // not really different from string type in behaviour
 | ||||
| 	LITERAL_TYPE_COMMENT | ||||
| }; | ||||
| 
 | ||||
| class LiteralScope | ||||
| { | ||||
| public: | ||||
| 	explicit LiteralScope(Scanner* _self, enum LiteralType _type): m_type(_type) | ||||
| 	, m_scanner(_self) | ||||
| 	, m_complete(false) | ||||
| 	{ | ||||
| 		if (_type == LITERAL_TYPE_COMMENT) | ||||
| 			m_scanner->m_nextSkippedComment.literal.clear(); | ||||
| 		else | ||||
| 			m_scanner->m_nextToken.literal.clear(); | ||||
| 	} | ||||
| 	~LiteralScope() | ||||
| 	{ | ||||
| 		if (!m_complete) | ||||
| 		{ | ||||
| 			if (m_type == LITERAL_TYPE_COMMENT) | ||||
| 				m_scanner->m_nextSkippedComment.literal.clear(); | ||||
| 			else | ||||
| 				m_scanner->m_nextToken.literal.clear(); | ||||
| 		} | ||||
| 	} | ||||
| 	void complete() { m_complete = true; } | ||||
| 
 | ||||
| private: | ||||
| 	enum LiteralType m_type; | ||||
| 	Scanner* m_scanner; | ||||
| 	bool m_complete; | ||||
| }; // end of LiteralScope class
 | ||||
| 
 | ||||
| 
 | ||||
| void Scanner::reset(CharStream const& _source) | ||||
| { | ||||
| 	m_source = _source; | ||||
|  | ||||
							
								
								
									
										42
									
								
								Scanner.h
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								Scanner.h
									
									
									
									
									
								
							| @ -96,45 +96,9 @@ private: | ||||
| 
 | ||||
| class Scanner | ||||
| { | ||||
| 	friend class LiteralScope; | ||||
| public: | ||||
| 
 | ||||
| 	enum LiteralType { | ||||
| 		LITERAL_TYPE_STRING, | ||||
| 		LITERAL_TYPE_NUMBER, // not really different from string type in behaviour
 | ||||
| 		LITERAL_TYPE_COMMENT | ||||
| 	}; | ||||
| 	/// Scoped helper for literal recording. Automatically drops the literal
 | ||||
| 	/// if aborting the scanning before it's complete.
 | ||||
| 	class LiteralScope | ||||
| 	{ | ||||
| 	public: | ||||
| 		explicit LiteralScope(Scanner* _self, enum LiteralType _type): m_type(_type) | ||||
| 		, m_scanner(_self) | ||||
| 		, m_complete(false) | ||||
| 		{ | ||||
| 			if (_type == LITERAL_TYPE_COMMENT) | ||||
| 				m_scanner->startNewCommentLiteral(); | ||||
| 			else | ||||
| 				m_scanner->startNewLiteral(); | ||||
| 		} | ||||
| 		~LiteralScope() | ||||
| 		{ | ||||
| 			if (!m_complete) | ||||
| 			{ | ||||
| 				if (m_type == LITERAL_TYPE_COMMENT) | ||||
| 					m_scanner->dropCommentLiteral(); | ||||
| 				else | ||||
| 					m_scanner->dropLiteral(); | ||||
| 			} | ||||
| 		} | ||||
| 		void complete() { m_complete = true; } | ||||
| 
 | ||||
| 	private: | ||||
| 		enum LiteralType m_type; | ||||
| 		Scanner* m_scanner; | ||||
| 		bool m_complete; | ||||
| 	}; | ||||
| 
 | ||||
| 	Scanner() { reset(CharStream()); } | ||||
| 	explicit Scanner(CharStream const& _source) { reset(_source); } | ||||
| 
 | ||||
| @ -194,12 +158,8 @@ private: | ||||
| 
 | ||||
| 	///@{
 | ||||
| 	///@name Literal buffer support
 | ||||
| 	inline void startNewLiteral() { m_nextToken.literal.clear(); } | ||||
| 	inline void startNewCommentLiteral() { m_nextSkippedComment.literal.clear(); } | ||||
| 	inline void addLiteralChar(char c) { m_nextToken.literal.push_back(c); } | ||||
| 	inline void addCommentLiteralChar(char c) { m_nextSkippedComment.literal.push_back(c); } | ||||
| 	inline void dropLiteral() { m_nextToken.literal.clear(); } | ||||
| 	inline void dropCommentLiteral() { m_nextSkippedComment.literal.clear(); } | ||||
| 	inline void addLiteralCharAndAdvance() { addLiteralChar(m_char); advance(); } | ||||
| 	///@}
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user