[anjuta] language-support-cpp-java: better handling of stmts and cxxparser improvement.



commit 7032929ad394955f5261bc2b8f901d7999893194
Author: Massimo Corà <mcora src gnome org>
Date:   Sat Jan 2 00:37:35 2010 +0100

    language-support-cpp-java: better handling of stmts and cxxparser improvement.
    
    Statements are now mostly got as the parser wants. "foo_klass1->get_foo_klass2 ()->"
    is an example of the expression to get.
    Despite this there's still some work to do to exclude cases like
    
    for (foo_klass1->get_foo_klass2 ()->
    
    which isn't parsed correctly by cpp-java-assist.
    Cxxparser: added function return type parsing.

 .../language-support-cpp-java/cpp-java-assist.c    |   36 +++++++++++--
 .../cxxparser/Makefile.am                          |    3 +-
 .../cxxparser/engine-parser.cpp                    |   58 +++++++++++++++++---
 .../cxxparser/engine-parser.h                      |    3 +-
 .../cxxparser/function-parser.cpp                  |    2 +-
 .../cxxparser/function-parser.h                    |   36 ++++++++++++
 .../cxxparser/function-result.cpp                  |   10 ++--
 .../cxxparser/function-result.h                    |    8 ++--
 plugins/language-support-cpp-java/plugin.c         |    2 +-
 9 files changed, 132 insertions(+), 26 deletions(-)
---
diff --git a/plugins/language-support-cpp-java/cpp-java-assist.c b/plugins/language-support-cpp-java/cpp-java-assist.c
index 01be5ab..977b102 100644
--- a/plugins/language-support-cpp-java/cpp-java-assist.c
+++ b/plugins/language-support-cpp-java/cpp-java-assist.c
@@ -719,6 +719,18 @@ is_word_or_operator(gchar c)
 	return FALSE;
 }
 
+/* FIXME: find a better tester */
+static gboolean
+is_expression_separator (gchar c)
+{
+	if (c == ';' || c == '\n' || c == '\r' || c == '\t' || /*c == '(' || c == ')' || */
+	    c == '{' || c == '}' || c == '=' || c == '<' /*|| c == '>'*/ || c == '\v' || c == '!')
+	{
+		return TRUE;
+	}
+
+	return FALSE;
+}
 
 static IAnjutaIterable*
 cpp_java_parse_expression (CppJavaAssist* assist, IAnjutaIterable* iter, IAnjutaIterable** start_iter)
@@ -737,8 +749,10 @@ cpp_java_parse_expression (CppJavaAssist* assist, IAnjutaIterable* iter, IAnjuta
 
 		DEBUG_PRINT ("ch == '%c'", ch);
 		
-		if (!is_word_or_operator (ch))
+		if (is_expression_separator(ch)) {
+			DEBUG_PRINT ("found char '%c' which is an expression_separator", ch);
 			break;
+		}
 
 		if (ch == '.' || (op_start && ch == '-') || (ref_start && ch == ':'))
 		{
@@ -747,6 +761,15 @@ cpp_java_parse_expression (CppJavaAssist* assist, IAnjutaIterable* iter, IAnjuta
 			IAnjutaIterable* pre_word_end = ianjuta_iterable_clone (iter, NULL);
 			IAnjutaIterable* stmt_end = ianjuta_iterable_clone (pre_word_start, NULL);
 
+			/* we need to pass to the parser all the statement included the last operator,
+			 * being it "." or "->" or "::"
+			 * Increase the end bound of the statement.
+			 */
+			ianjuta_iterable_next (stmt_end, NULL);
+			if (op_start == TRUE || ref_start == TRUE)
+				ianjuta_iterable_next (stmt_end, NULL);
+				
+			
 			/* Move one character forward so we have the start of the pre_word and
 			 * not the last operator */
 			ianjuta_iterable_next (pre_word_start, NULL);
@@ -766,8 +789,9 @@ cpp_java_parse_expression (CppJavaAssist* assist, IAnjutaIterable* iter, IAnjuta
 			while (ianjuta_iterable_previous (cur_pos, NULL))
 			{
 				gchar word_ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL(cur_pos), 0, NULL);
-				if (!is_word_character (word_ch))
-					break;
+				
+				if (is_expression_separator(word_ch)) 
+					break;				
 			}
 			ianjuta_iterable_next (cur_pos, NULL);
 			stmt = ianjuta_editor_get_text (editor,
@@ -813,6 +837,7 @@ cpp_java_parse_expression (CppJavaAssist* assist, IAnjutaIterable* iter, IAnjuta
 		lineno = ianjuta_editor_get_lineno (editor, NULL);
 		if (!ref_start)
 		{
+			DEBUG_PRINT ("calling engine_parser_process_expression stmt: %s ", stmt);
 			res = engine_parser_process_expression (stmt,
 			                                        above_text,
 			                                        filename,
@@ -938,8 +963,11 @@ cpp_java_assist_activate (IAnjutaProvider* self, IAnjutaIterable* iter, gpointer
 	gboolean add_brace_after_func = FALSE;
 	
 	//DEBUG_PRINT ("assist-chosen: %d", selection);
-	
+		
 	tag = data;	
+	
+	g_return_if_fail (tag != NULL);
+	
 	assistance = g_string_new (tag->name);
 	
 	if (tag->is_func)
diff --git a/plugins/language-support-cpp-java/cxxparser/Makefile.am b/plugins/language-support-cpp-java/cxxparser/Makefile.am
index 9399c6b..9bac345 100644
--- a/plugins/language-support-cpp-java/cxxparser/Makefile.am
+++ b/plugins/language-support-cpp-java/cxxparser/Makefile.am
@@ -34,7 +34,8 @@ libcxxparser_la_SOURCES = \
         engine-parser-priv.h \
         engine-parser.h \
         scope-parser.h \
-        variable-parser.h 
+        variable-parser.h \
+        function-parser.h
  
 libcxxparser_la_LIBADD = $(LIBANJUTA_LIBS) \
 	$(GTHREAD_LIBS)
diff --git a/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp b/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp
index e7836a2..3570826 100644
--- a/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp
+++ b/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp
@@ -24,6 +24,7 @@
 #include "expression-parser.h"
 #include "scope-parser.h"
 #include "variable-parser.h"
+#include "function-parser.h"
 
 #include <string>
 #include <vector>
@@ -256,7 +257,7 @@ EngineParser::getTypeNameAndScopeByToken (ExpressionResult &result,
 
 		/* optimize scope'll clear the scopes leaving the local variables */
 		string optimized_scope = optimizeScope(above_text);
-		cout << "here it is the optimized buffer scope " << optimized_scope << endl;
+/*		cout << "here it is the optimized buffer scope " << optimized_scope << endl;*/
 
 		VariableList li;
 		std::map<std::string, std::string> ignoreTokens;
@@ -473,11 +474,10 @@ EngineParser::processExpression(const string& stmt,
 	string type_name;
 	string type_scope;
 
-	/* first token */
 	cout << "setting text " << stmt.c_str () << " to the tokenizer " << endl;
 	_main_tokenizer->setText (stmt.c_str ());
 
-	/* get the fist one */
+	/* get the first token */
 	nextMainToken (current_token, op);		
 
 	cout << "--------" << endl << "First main token \"" << current_token << "\" with op \"" << op 
@@ -534,7 +534,7 @@ EngineParser::processExpression(const string& stmt,
 	 	 */
 		result = parseExpression (current_token);
 		
-		if (process_res == false)
+		if (process_res == false || curr_searchable_scope == NULL)
 		{
 			cout << "Well, you haven't much luck on the NEXT token, the NEXT token failed and then "  <<
 				"I cannot continue. " << endl;
@@ -575,13 +575,12 @@ EngineParser::processExpression(const string& stmt,
 		}
 		else 
 		{
-			const gchar *sym_kind;
+			gchar *sym_kind;
 			cout << "Good element " << result.m_name << endl;			
 			
 
 			node = IANJUTA_SYMBOL (iter);
-
-			sym_kind = ianjuta_symbol_get_extra_info_string (node, 
+			sym_kind = (gchar*)ianjuta_symbol_get_extra_info_string (node, 
 		    										IANJUTA_SYMBOL_FIELD_KIND, NULL);
 			
 			cout << ".. it has sym_kind \"" << sym_kind << "\"" << endl;
@@ -592,9 +591,10 @@ EngineParser::processExpression(const string& stmt,
 	    		g_strcmp0 (sym_kind, "field") == 0)
 			{
 				iter = switchMemberToContainer (iter);
+				node = IANJUTA_SYMBOL (iter);
+				sym_kind = (gchar*)ianjuta_symbol_get_extra_info_string (node, 
+		    										IANJUTA_SYMBOL_FIELD_KIND, NULL);				
 			}
-
-			node = IANJUTA_SYMBOL (iter);
 			
 			/* check for any typedef */
 			if (g_strcmp0 (ianjuta_symbol_get_extra_info_string (node, 
@@ -602,8 +602,48 @@ EngineParser::processExpression(const string& stmt,
 	    											"typedef") == 0)
 			{			
 				iter = switchTypedefToStruct (iter);
+				node = IANJUTA_SYMBOL (iter);
+				sym_kind = (gchar*)ianjuta_symbol_get_extra_info_string (node, 
+		    										IANJUTA_SYMBOL_FIELD_KIND, NULL);				
 			}
 			
+			/* is it a function or a method? */
+			if (g_strcmp0 (sym_kind, "function") == 0 ||
+			    g_strcmp0 (sym_kind, "method") == 0 ||
+			    g_strcmp0 (sym_kind, "prototype") == 0)
+			{
+
+				string func_ret_type_name = 
+					ianjuta_symbol_get_returntype (node, NULL);
+
+				string func_signature = 
+					ianjuta_symbol_get_args (node, NULL);
+				
+				func_ret_type_name += " " + result.m_name + func_signature + "{}";
+
+				FunctionList li;
+				std::map<std::string, std::string> ignoreTokens;
+				get_functions (func_ret_type_name, li, ignoreTokens);
+
+				cout << "functions found are..." << endl;
+				for (FunctionList::reverse_iterator func_iter = li.rbegin(); 
+				     func_iter != li.rend(); 
+				     func_iter++) 
+				{
+					Function var = (*func_iter);
+					var.print ();			
+				}
+				
+			
+				g_object_unref (iter);
+
+				cout << "going to look for the following function ret type " << 
+					func_ret_type_name << endl;
+
+				iter = getCurrentSearchableScope (li.front().m_returnValue.m_type,
+				                                  type_scope);
+			}			               
+			
 			/* remove the 'old' curr_searchable_scope and replace with 
 			 * this new one
 			 */			
diff --git a/plugins/language-support-cpp-java/cxxparser/engine-parser.h b/plugins/language-support-cpp-java/cxxparser/engine-parser.h
index e599a7c..d0e3644 100644
--- a/plugins/language-support-cpp-java/cxxparser/engine-parser.h
+++ b/plugins/language-support-cpp-java/cxxparser/engine-parser.h
@@ -31,7 +31,8 @@ void engine_parser_init (IAnjutaSymbolManager * manager);
 /**
  * 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)."
+ * @param stmt A statement like "((FooKlass*) B).", "foo_klass1->get_foo_klass2 ()->",
+ * "foo_klass1->member2->", etc.
  * @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.
diff --git a/plugins/language-support-cpp-java/cxxparser/function-parser.cpp b/plugins/language-support-cpp-java/cxxparser/function-parser.cpp
index 9f854c7..5d1381b 100644
--- a/plugins/language-support-cpp-java/cxxparser/function-parser.cpp
+++ b/plugins/language-support-cpp-java/cxxparser/function-parser.cpp
@@ -74,7 +74,7 @@ int cl_func_parse();
 void cl_func_error(char *string);
 
 static FunctionList *g_funcs = NULL;
-static clFunction curr_func;
+static Function curr_func;
 
 /*---------------------------------------------*/
 /* externs defined in the lexer*/
diff --git a/plugins/language-support-cpp-java/cxxparser/function-parser.h b/plugins/language-support-cpp-java/cxxparser/function-parser.h
new file mode 100644
index 0000000..ac5704a
--- /dev/null
+++ b/plugins/language-support-cpp-java/cxxparser/function-parser.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) Massimo Cora' 2009-2010 <maxcvs email it>
+ * 
+ * anjuta is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _FUNCTION_PARSER_H
+#define _FUNCTION_PARSER_H
+
+#include <string>
+#include <map>
+#include "function-result.h"
+
+using namespace std;
+
+
+void 
+get_functions(const std::string &in, 
+              FunctionList &li, 
+              const std::map<std::string, std::string> &ignoreTokens);
+
+#endif
+ 
diff --git a/plugins/language-support-cpp-java/cxxparser/function-result.cpp b/plugins/language-support-cpp-java/cxxparser/function-result.cpp
index f57cc08..ff1721e 100644
--- a/plugins/language-support-cpp-java/cxxparser/function-result.cpp
+++ b/plugins/language-support-cpp-java/cxxparser/function-result.cpp
@@ -2,7 +2,7 @@
 /*
  * anjuta
  * Copyright (C) Eran Ifrah (Main file for CodeLite www.codelite.org/ )
- * Copyright (C) Massimo Cora' 2009 <maxcvs email it> (Customizations for Anjuta)
+ * Copyright (C) Massimo Cora' 2009-2010 <maxcvs email it> (Customizations for Anjuta)
  * 
  * anjuta is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -20,16 +20,16 @@
 
 #include "function-result.h"
 
-clFunction::clFunction()
+Function::Function()
 {
 	reset();
 }
 
-clFunction::~clFunction()
+Function::~Function()
 {
 }
 
-void clFunction::reset()
+void Function::reset()
 {
 	m_name = "";
 	m_scope = "";
@@ -43,7 +43,7 @@ void clFunction::reset()
 	m_isConst = false;
 }
 
-void clFunction::print()
+void Function::print()
 {
 	fprintf(	
 				stdout, "{m_name=%s, m_isConst=%s, m_lineno=%d, m_scope=%s, m_signature=%s, m_isVirtual=%s, m_isPureVirtual=%s, m_retrunValusConst=%s\nm_returnValue=", 
diff --git a/plugins/language-support-cpp-java/cxxparser/function-result.h b/plugins/language-support-cpp-java/cxxparser/function-result.h
index 77d8c6a..6c34206 100644
--- a/plugins/language-support-cpp-java/cxxparser/function-result.h
+++ b/plugins/language-support-cpp-java/cxxparser/function-result.h
@@ -26,7 +26,7 @@
 #include "variable-result.h"
 #include <stdio.h>
 
-class clFunction
+class Function
 {
 public:
 	std::string     m_name;
@@ -40,8 +40,8 @@ public:
 	bool            m_isConst;
 
 public:
-	clFunction();
-	virtual ~clFunction();
+	Function();
+	virtual ~Function();
 
 	//clear the class content
 	void reset();
@@ -50,5 +50,5 @@ public:
 	void print();
 };
 
-typedef std::list<clFunction> FunctionList;
+typedef std::list<Function> FunctionList;
 #endif // _FUNCTION_H_
diff --git a/plugins/language-support-cpp-java/plugin.c b/plugins/language-support-cpp-java/plugin.c
index 295ac91..451cc63 100644
--- a/plugins/language-support-cpp-java/plugin.c
+++ b/plugins/language-support-cpp-java/plugin.c
@@ -1592,7 +1592,7 @@ install_support (CppJavaPlugin *lang_plugin)
 		ianjuta_language_get_name_from_editor (lang_manager, 
 											   IANJUTA_EDITOR_LANGUAGE (lang_plugin->current_editor), NULL);
 	
-	DEBUG_PRINT("Language support intalled for: %s",
+	DEBUG_PRINT("Language support installed for: %s",
 				lang_plugin->current_language);
 	
 	if (lang_plugin->current_language &&



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