[anjuta/cxxparser] cxxparser: CppScanner refactoring, fixed some compiling issues.



commit 421cbf63bf879cf4de67af1e718c4725c58bf0aa
Author: Massimo Corà <mcora src gnome org>
Date:   Sun Jul 26 21:41:46 2009 +0200

    cxxparser: CppScanner refactoring, fixed some compiling issues.

 plugins/symbol-db/cxxparser/cpp-flex-tokenizer.cpp |   45 +++++++++++++--
 plugins/symbol-db/cxxparser/cpp-flex-tokenizer.h   |   41 +++++++--------
 plugins/symbol-db/cxxparser/engine-parser-priv.h   |   34 ++++++++----
 plugins/symbol-db/cxxparser/engine-parser.cpp      |   58 +++++++++-----------
 plugins/symbol-db/cxxparser/engine-parser.h        |   21 ++++++--
 plugins/symbol-db/cxxparser/main.c                 |    7 ---
 6 files changed, 124 insertions(+), 82 deletions(-)
---
diff --git a/plugins/symbol-db/cxxparser/cpp-flex-tokenizer.cpp b/plugins/symbol-db/cxxparser/cpp-flex-tokenizer.cpp
index 2d44528..4d44689 100644
--- a/plugins/symbol-db/cxxparser/cpp-flex-tokenizer.cpp
+++ b/plugins/symbol-db/cxxparser/cpp-flex-tokenizer.cpp
@@ -49,7 +49,7 @@
 #include <string.h>
 
 
-CppScanner::CppScanner()
+CppTokenizer::CppTokenizer()
 : m_curr(0)
 {
 	m_data = NULL;
@@ -59,12 +59,13 @@ CppScanner::CppScanner()
 	m_comment = "";
 }
 
-CppScanner::~CppScanner(void)
+CppTokenizer::~CppTokenizer(void)
 {
 	delete m_data;
 }
 
-int CppScanner::LexerInput(char *buf, int max_size)
+int 
+CppTokenizer::LexerInput(char *buf, int max_size)
 {
 	if( !m_data )
 		return 0;
@@ -80,17 +81,19 @@ int CppScanner::LexerInput(char *buf, int max_size)
 	return n;
 }
 
-void CppScanner::SetText(const char* data)
+void 
+CppTokenizer::setText(const char* data)
 {
 	// release previous buffer
-	Reset();
+	reset();
 
 	m_data = new char[strlen(data)+1];
 	strcpy(m_data, data);
 	m_pcurr = m_data;
 }
 
-void CppScanner::Reset()
+void 
+CppTokenizer::reset()
 {
 	if(m_data)
 	{
@@ -105,3 +108,33 @@ void CppScanner::Reset()
 	m_comment = "";
 	yylineno = 1;
 }
+
+const int& 
+CppTokenizer::lineNo() const
+{
+	return yylineno;
+}
+
+void 
+CppTokenizer::clearComment() 
+{ 
+	m_comment = ""; 
+}
+
+const char* 
+CppTokenizer::getComment () const 
+{
+	return m_comment.c_str ();
+}
+
+void 
+CppTokenizer::keepComment (const int& keep) 
+{ 
+	m_keepComments = keep; 
+}
+
+void 
+CppTokenizer::returnWhite (const int& rw) 
+{ 
+	m_returnWhite = rw; 
+}
diff --git a/plugins/symbol-db/cxxparser/cpp-flex-tokenizer.h b/plugins/symbol-db/cxxparser/cpp-flex-tokenizer.h
index e40aa9c..9b17adf 100644
--- a/plugins/symbol-db/cxxparser/cpp-flex-tokenizer.h
+++ b/plugins/symbol-db/cxxparser/cpp-flex-tokenizer.h
@@ -42,36 +42,33 @@
 //                                                                          
 //////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////
-#ifndef CODELITE_CPPSCANNER_H
-#define CODELITE_CPPSCANNER_H
+#ifndef _CPPTOKENIZER_H
+#define _CPPTOKENIZER_H
 
 #include "flex-lexer-klass.h"
 
-class CppScanner : public flex::yyFlexLexer
+class CppTokenizer : public flex::yyFlexLexer
 {
 public:
-	CppScanner();
-	~CppScanner(void);
+	CppTokenizer();
+	~CppTokenizer(void);
 	
-	/// Override the LexerInput function
+	/* Override the LexerInput function */
 	int LexerInput(char *buf, int max_size);
-	void SetText(const char* data);
-	void Reset();
+	void setText(const char* data);
+	void reset();
 
 	 
-	///	Note about comment and line number:
-	///	If the last text consumed is a comment, the line number 
-	///	returned is the line number of the last line of the comment
-	///	incase the comment spans over number of lines
-	///	(i.e. /* ... */ comment style)
-
-	// FIXME: move all the implementations into the .cpp file.
-	// FIXME: keeo coherent.
-	const int& LineNo() const { return yylineno; }
-	inline void ClearComment() { m_comment = ""; }
-	inline const char* GetComment() const { return m_comment.c_str (); }
-	inline void KeepComment(const int& keep) { m_keepComments = keep; }
-	inline void ReturnWhite(const int& rw) { m_returnWhite = rw; }
+	/*	Note about comment and line number:
+	 *	If the last text consumed is a comment, the line number 
+	 *	returned is the line number of the last line of the comment
+	 *	incase the comment spans over number of lines
+	 */
+	const int& lineNo() const; 
+	inline void clearComment();
+	inline const char* getComment() const;
+	inline void keepComment(const int& keep);
+	inline void returnWhite(const int& rw);
 
 private:
 	char *m_data;
@@ -80,4 +77,4 @@ private:
 	int   m_curr;
 };
 
-#endif // CODELITE_CPPSCANNER_H
+#endif // _CPPTOKENIZER_H
diff --git a/plugins/symbol-db/cxxparser/engine-parser-priv.h b/plugins/symbol-db/cxxparser/engine-parser-priv.h
index b57b863..d998ab3 100644
--- a/plugins/symbol-db/cxxparser/engine-parser-priv.h
+++ b/plugins/symbol-db/cxxparser/engine-parser-priv.h
@@ -47,6 +47,7 @@ public:
 	// getter for the IAnjutaSymbolManager.
 	SymbolDBEngine * getSymbolManager ();
 
+	// FIXME comments.
 	/**
 	 * Evaluate a C++ expression. for example, the following expression: '((Notebook*)book)->'
 	 * will be processed into typeName=Notebook, and typeScope=<global> (assuming Notebook is not
@@ -62,19 +63,17 @@ public:
 	 * \return true on success, false otherwise. The output fields are only to be checked with the return
 	 * valus is 'true'
 	 */
-	bool processExpression(const string& stmt, const string& above_text, 
-	    const string& full_file_path, unsigned long linenum, string &out_type_name, 
-	    string &out_type_scope, string &out_oper, 
-	    string &out_scope_template_init_list);
+	SymbolDBEngineIterator *
+		processExpression(const string& stmt, const string& above_text, 
+	    	const string& full_file_path, unsigned long linenum, 
+		    string &out_type_name, string &out_type_scope, 
+		    string &out_oper, string &out_scope_template_init_list);
 	
 
 	void testParseExpression (const string &in);
 
-	// ?!? unuseful, remove it sometime 
-	string OptimizeScope(const string& srcString);
 	string GetScopeName(const string &in, std::vector<string> *additionlNS);
 
-	void trim (string& str);
 	
 protected:
 
@@ -96,13 +95,28 @@ private:
 	 * \return true if token was found false otherwise
 	 */	
 	bool nextToken (string &out_token, string &out_delimiter);
-	
+
+
+	/**
+	 * trim () a string
+	 */
+	void trim (string& str, string trimChars = "{};\r\n\t\v ");
+
+	/**
+	 * This method reduces the various scopes/variables/functions in the buffer 
+	 * passed as parameter to a file where the only things left are the local
+	 * variables and the functions names. 
+	 * You can use this method to retrieve the type of a local variable, if it's
+	 * present in the passed buffer of course.
+	 */
+	string optimizeScope(const string& srcString);
 	
 	/*
 	 * D A T A
 	 */	
-	CppScanner *_tokenizer;	
-	static EngineParser *s_engine;
+	static EngineParser *s_engine;	
+
+	CppTokenizer *_tokenizer;
 	SymbolDBEngine *_dbe;
 };
 
diff --git a/plugins/symbol-db/cxxparser/engine-parser.cpp b/plugins/symbol-db/cxxparser/engine-parser.cpp
index 704daf0..c1a7cc2 100644
--- a/plugins/symbol-db/cxxparser/engine-parser.cpp
+++ b/plugins/symbol-db/cxxparser/engine-parser.cpp
@@ -45,7 +45,7 @@ EngineParser::getInstance ()
 
 EngineParser::EngineParser ()
 {	
-	_tokenizer = new CppScanner ();	
+	_tokenizer = new CppTokenizer ();	
 	_dbe = NULL;
 }
 
@@ -99,7 +99,7 @@ void
 EngineParser::DEBUG_printTokens (const string& text)
 {
 	// FIXME
-	_tokenizer->SetText (text.c_str ());
+	_tokenizer->setText (text.c_str ());
 
 	string op;
 	string token;
@@ -128,7 +128,7 @@ EngineParser::parseExpression(const string &in)
 void
 EngineParser::testParseExpression (const string &str)
 {
-	_tokenizer->SetText(str.c_str ());
+	_tokenizer->setText(str.c_str ());
 
 	string word;
 	string op;
@@ -163,29 +163,33 @@ EngineParser::getSymbolManager ()
 }
 
 void 
-EngineParser::trim (string& str)
+EngineParser::trim (string& str, string trimChars)
 {
-	string trim_str = "{};\r\n\t\v ";
-  	string::size_type pos = str.find_last_not_of(trim_str);
-  	if(pos != string::npos) 
+  	string::size_type pos = str.find_last_not_of (trimChars);
+	
+  	if (pos != string::npos) 
 	{
     	str.erase(pos + 1);
-    	pos = str.find_first_not_of(trim_str);
+    	pos = str.find_first_not_of (trimChars);
     	if(pos != string::npos) 
+		{			
 			  str.erase(0, pos);
+		}
   	}
   	else 
+	{
 		str.erase(str.begin(), str.end());
+	}
 }
 
-bool 
+SymbolDBEngineIterator *
 EngineParser::processExpression(const string& stmt, const string& above_text,
     const string& full_file_path, unsigned long linenum,
     string &out_type_name, string &out_type_scope, string &out_oper, 
 	    string &out_scope_template_init_list)
 {
 	bool evaluation_succeed = false;
-	_tokenizer->SetText(stmt.c_str ());
+	_tokenizer->setText(stmt.c_str ());
 
 	string word;
 	string op;
@@ -307,7 +311,7 @@ EngineParser::processExpression(const string& stmt, const string& above_text,
 
 			/* TODO */
 			/* optimize scope'll clear the scopes leaving the local variables */
-			string optimized_scope = OptimizeScope(above_text);
+			string optimized_scope = optimizeScope(above_text);
 
 			cout << "here it is the optimized scope " << optimized_scope << endl;
 
@@ -519,14 +523,15 @@ EngineParser::processExpression(const string& stmt, const string& above_text,
 #endif		
 		word.clear ();
 	}	
-	
-	return true;
+
+	// FIXME
+	return NULL;
 }
 
 
 /// Return the visible scope until pchStopWord is encountered
 string 
-EngineParser::OptimizeScope(const string& srcString)
+EngineParser::optimizeScope(const string& srcString)
 {
 	string wxcurrScope;
 	std::vector<std::string> scope_stack;
@@ -536,7 +541,7 @@ EngineParser::OptimizeScope(const string& srcString)
 
 	// Initialize the scanner with the string to search
 	const char * scannerText =  srcString.c_str ();
-	_tokenizer->SetText (scannerText);
+	_tokenizer->setText (scannerText);
 	bool changedLine = false;
 	bool prepLine = false;
 	int curline = 0;
@@ -613,7 +618,7 @@ EngineParser::OptimizeScope(const string& srcString)
 		}
 	}
 
-	_tokenizer->Reset();
+	_tokenizer->reset();
 
 	if (scope_stack.empty())
 		return srcString;
@@ -682,22 +687,11 @@ engine_parser_parse_expression (const char*str)
 {
 	EngineParser::getInstance ()->testParseExpression (str);
 }
-
-void 
-engine_parser_test_optimize_scope (const char*str)
-{
-	string res = EngineParser::getInstance ()->OptimizeScope (str);
-	cout << "OptimizeScope: " << res << endl;
-
-	res = EngineParser::getInstance ()->GetScopeName (str, NULL);
-	cout << "GetScopeName: " << res << endl;
-	
-}
-
+/*
 void
 engine_parser_get_local_variables (const char *str)
 {
-	string res = EngineParser::getInstance ()->OptimizeScope (str);
+	string res = EngineParser::getInstance ()->optimizeScope (str);
 
 	VariableList li;
 	std::map<std::string, std::string> ignoreTokens;
@@ -712,9 +706,9 @@ engine_parser_get_local_variables (const char *str)
 	//	printf("total time: %d\n", end-start);
 	printf("matches found: %d\n", li.size());	
 }
+*/
 
-
-void 
+SymbolDBEngineIterator *
 engine_parser_process_expression (const char *stmt, const char * above_text, 
     const char * full_file_path, unsigned long linenum)
 {
@@ -723,7 +717,7 @@ engine_parser_process_expression (const char *stmt, const char * above_text,
 	string out_oper;
 	string out_scope_template_init_list;
 	
-	EngineParser::getInstance ()->processExpression (stmt, above_text,  
+	return EngineParser::getInstance ()->processExpression (stmt, above_text,  
 	    full_file_path, linenum, out_type_name,
 	    out_type_scope, out_oper, out_scope_template_init_list);
 
diff --git a/plugins/symbol-db/cxxparser/engine-parser.h b/plugins/symbol-db/cxxparser/engine-parser.h
index ee3ac77..f7e6dde 100644
--- a/plugins/symbol-db/cxxparser/engine-parser.h
+++ b/plugins/symbol-db/cxxparser/engine-parser.h
@@ -33,16 +33,27 @@ void engine_parser_test_print_tokens (const char *str);
 
 void engine_parser_parse_expression (const char*str);	
 
-void engine_parser_process_expression (const char *stmt, const char * above_text,
+/**
+ * The function parse the C++ statement, try to get the type of objects to be
+ * completed and returns an iterator with those symbols.
+ * @param stmt A statement like "((FooKlass*) B)."
+ * @above_text Text of the buffer/file before the statement up to the first byte.
+ * @param full_file_path The full path to the file. This is for engine scanning purposes.
+ * @param linenum The line number where the statement is.
+ *	 
+ * @return SymbolDBEngineIterator * with the actual completions symbols.
+ */
+SymbolDBEngineIterator *
+engine_parser_process_expression (const char *stmt, const char * above_text,
     const char * full_file_path, unsigned long linenum);	
 
-void engine_parser_test_optimize_scope (const char*str);
-
+/*
 void engine_parser_get_local_variables (const char *buf);
-//*/	
+*/
+	
 #ifdef __cplusplus
 }	// extern "C" 
 #endif
-//*/
+
 
 #endif // _ENGINE_PARSER_H_
diff --git a/plugins/symbol-db/cxxparser/main.c b/plugins/symbol-db/cxxparser/main.c
index a493b10..33600ae 100644
--- a/plugins/symbol-db/cxxparser/main.c
+++ b/plugins/symbol-db/cxxparser/main.c
@@ -151,10 +151,3 @@ int	main (int argc, char *argv[])
 */	
 	//gtk_main();
 #endif	
-
-	return 0;
-}
-#endif
-
-
-



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]