[anjuta/sdb-queries] symbol-db: Eliminate scope chain query. Use it alternatively.



commit b62c5a98d4f7ac898110fb114b55ef0ef65d2f8c
Author: Naba Kumar <naba gnome org>
Date:   Sun Jun 13 14:48:00 2010 +0300

    symbol-db: Eliminate scope chain query. Use it alternatively.

 libanjuta/interfaces/libanjuta.idl                 |    4 +-
 .../cxxparser/engine-parser-priv.h                 |    6 +-
 .../cxxparser/engine-parser.cpp                    |   86 ++++++++------------
 plugins/symbol-db/symbol-db-query.c                |    8 --
 4 files changed, 37 insertions(+), 67 deletions(-)
---
diff --git a/libanjuta/interfaces/libanjuta.idl b/libanjuta/interfaces/libanjuta.idl
index 28610cc..8951a86 100644
--- a/libanjuta/interfaces/libanjuta.idl
+++ b/libanjuta/interfaces/libanjuta.idl
@@ -5358,8 +5358,7 @@ interface IAnjutaSymbolQuery
 		SEARCH_CLASS_PARENTS,
 		SEARCH_SCOPE,
 		SEARCH_PARENT_SCOPE,
-		SEARCH_PARENT_SCOPE_FILE,
-		SEARCH_SCOPE_CHAIN
+		SEARCH_PARENT_SCOPE_FILE
 	}
 
 	enum FileScope
@@ -5389,7 +5388,6 @@ interface IAnjutaSymbolQuery
 	IAnjutaIterable* search_scope (const gchar *file_path, gint line);
 	IAnjutaIterable* search_parent_scope (IAnjutaSymbol *symbol);
 	IAnjutaIterable* search_parent_scope_file (IAnjutaSymbol *symbol, const gchar *file_path);
-	IAnjutaIterable* search_scope_chain (const gchar *file, gint line);
 }
 
 /**
diff --git a/plugins/language-support-cpp-java/cxxparser/engine-parser-priv.h b/plugins/language-support-cpp-java/cxxparser/engine-parser-priv.h
index e9c1adc..6a6abd5 100644
--- a/plugins/language-support-cpp-java/cxxparser/engine-parser-priv.h
+++ b/plugins/language-support-cpp-java/cxxparser/engine-parser-priv.h
@@ -45,8 +45,9 @@ public:
 	/* setter for the IAnjutaSymbolManager. */
 	void setSymbolManager (IAnjutaSymbolManager *manager);
 
-	IAnjutaIterable * getCurrentScopeChainByFileLine (const char* full_file_path,
-	    											  unsigned long linenum);
+	void getNearestClassInCurrentScopeChainByFileLine (const char* full_file_path,
+	                                                   unsigned long linenum,
+	                                                   string &out_type_name);
 
 	IAnjutaIterable * getCurrentSearchableScope (string &type_name, string &type_scope);
 	
@@ -125,7 +126,6 @@ private:
 	IAnjutaSymbolQuery *query_search;
 	IAnjutaSymbolQuery *query_search_in_scope;
 	IAnjutaSymbolQuery *query_parent_scope;
-	IAnjutaSymbolQuery *query_scope_chain;
 };
 
 
diff --git a/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp b/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp
index e350602..0c0d8c7 100644
--- a/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp
+++ b/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp
@@ -119,7 +119,7 @@ EngineParser::parseExpression(const string &in)
 void 
 EngineParser::setSymbolManager (IAnjutaSymbolManager *manager)
 {
-	static IAnjutaSymbolField query_scope_chain_fields[] =
+	static IAnjutaSymbolField query_parent_scope_fields[] =
 	{
 		IANJUTA_SYMBOL_FIELD_ID, IANJUTA_SYMBOL_FIELD_NAME,
 		IANJUTA_SYMBOL_FIELD_KIND, IANJUTA_SYMBOL_FIELD_TYPE
@@ -147,12 +147,9 @@ EngineParser::setSymbolManager (IAnjutaSymbolManager *manager)
 	query_parent_scope = ianjuta_symbol_manager_create_query (manager,
 						IANJUTA_SYMBOL_QUERY_SEARCH_PARENT_SCOPE,
 						IANJUTA_SYMBOL_QUERY_DB_PROJECT, NULL);
-	query_scope_chain = ianjuta_symbol_manager_create_query (manager,
-						IANJUTA_SYMBOL_QUERY_SEARCH_SCOPE_CHAIN,
-						IANJUTA_SYMBOL_QUERY_DB_PROJECT, NULL);
-	ianjuta_symbol_query_set_fields (query_scope_chain,
-									 G_N_ELEMENTS (query_scope_chain_fields),
-									 query_scope_chain_fields, NULL);
+	ianjuta_symbol_query_set_fields (query_parent_scope,
+									 G_N_ELEMENTS (query_parent_scope_fields),
+									 query_parent_scope_fields, NULL);
 }
 
 void 
@@ -178,36 +175,40 @@ EngineParser::trim (string& str, string trimChars /* = "{};\r\n\t\v " */)
 /**
  * @return NULL on global 
  */
-IAnjutaIterable *
-EngineParser::getCurrentScopeChainByFileLine (const char* full_file_path, 
-    										  unsigned long linenum)
-{	
-	IAnjutaIterable *iter = 		
-		ianjuta_symbol_query_search_scope_chain (query_scope_chain, full_file_path, linenum, NULL);
+void
+EngineParser::getNearestClassInCurrentScopeChainByFileLine (const char* full_file_path, 
+                                                            unsigned long linenum,
+                                                            string &out_type_name)
+{
+	IAnjutaIterable *iter;
 
-	DEBUG_PRINT ("Checking for completion scope..");
-	/* it's a global one if it's NULL or if it has just only one element */
-	if (iter == NULL || ianjuta_iterable_get_length (iter, NULL) <= 1)
-	{
-		DEBUG_PRINT ("...we've a global completion scope");
-		if (iter != NULL)
-		{
-			g_object_unref (iter);
-		}
+	/* Find current scope of given file and line */
+	iter = ianjuta_symbol_query_search_scope (query_scope, full_file_path, linenum, NULL);
+	if (iter == NULL)
+		return;
 
-		iter = NULL;
-	}
-	else 
-	{		
+	/* FIXME: this method doesn't take into consideration 
+	 * classes with same name on multiple namespaces 
+	 */
+	if (iter != NULL)
+	{
 		do 
 		{
+			IAnjutaIterable *parent_iter;
 			IAnjutaSymbol *node = IANJUTA_SYMBOL (iter);
-			DEBUG_PRINT ("Got completion scope name: %s", 
-				ianjuta_symbol_get_string (node, IANJUTA_SYMBOL_FIELD_NAME, NULL));
-		} while (ianjuta_iterable_next (iter, NULL) == TRUE);
+			DEBUG_PRINT ("sym_name = %s", ianjuta_symbol_get_string (node, IANJUTA_SYMBOL_FIELD_NAME, NULL));
+			if (ianjuta_symbol_get_sym_type (node, NULL) == IANJUTA_SYMBOL_TYPE_CLASS)
+			{
+				out_type_name = ianjuta_symbol_get_string (node, IANJUTA_SYMBOL_FIELD_NAME, NULL);
+				break;
+			}
+			parent_iter = ianjuta_symbol_query_search_parent_scope (query_parent_scope, node, NULL);
+			g_object_unref (iter);
+			iter = parent_iter;
+		} while (iter);
+		if (iter)
+			g_object_unref (iter);
 	}
-	
-	return iter;
 }
 
 bool
@@ -269,33 +270,12 @@ EngineParser::getTypeNameAndScopeByToken (ExpressionResult &result,
 		 * calling are passed. Go on finding for the first symbol of type class that
 		 * is reachable through the scopes chain.
 		 */	
-		
-		IAnjutaIterable* scope_chain_iter = 
-			ianjuta_symbol_query_search_scope_chain (query_scope_chain, full_file_path.c_str (), linenum, NULL);
 
 		/* will we find a good class scope? */
 		out_type_scope = result.m_scope.empty() ? "" : result.m_scope.c_str();
 		out_type_name = ""; 
 
-		/* FIXME: this method doesn't take into consideration 
-		 * classes with same name on multiple namespaces 
-		 */
-		if (scope_chain_iter != NULL)
-		{
-			do 
-			{
-				IAnjutaSymbol *node = IANJUTA_SYMBOL (scope_chain_iter);
-				DEBUG_PRINT ("sym_name = %s", ianjuta_symbol_get_string (node, IANJUTA_SYMBOL_FIELD_NAME, NULL));
-				if (ianjuta_symbol_get_sym_type (node, NULL) == IANJUTA_SYMBOL_TYPE_CLASS)
-				{
-					out_type_name = ianjuta_symbol_get_string (node, IANJUTA_SYMBOL_FIELD_NAME, NULL);
-					break;
-				}				
-			} while (ianjuta_iterable_next (scope_chain_iter, NULL) == TRUE);
-
-			g_object_unref (scope_chain_iter);
-		}		
-		
+		getNearestClassInCurrentScopeChainByFileLine (full_file_path.c_str (), linenum, out_type_name);
 		if (out_type_name.empty ()) 
 		{
 			DEBUG_PRINT ("'this' has not a type name");
diff --git a/plugins/symbol-db/symbol-db-query.c b/plugins/symbol-db/symbol-db-query.c
index ef5fd3e..43681f6 100644
--- a/plugins/symbol-db/symbol-db-query.c
+++ b/plugins/symbol-db/symbol-db-query.c
@@ -1056,13 +1056,6 @@ sdb_query_search_parent_scope_file (IAnjutaSymbolQuery *query, IAnjutaSymbol *sy
 	return sdb_query_execute (SYMBOL_DB_QUERY (query));
 }
 
-static IAnjutaIterable*
-sdb_query_search_scope_chain (IAnjutaSymbolQuery *query, const gchar *file_path,
-                              gint file_line, GError **error)
-{
-	return NULL; /* FIXME */
-}
-
 static void
 ianjuta_symbol_query_iface_init (IAnjutaSymbolQueryIface *iface)
 {
@@ -1083,7 +1076,6 @@ ianjuta_symbol_query_iface_init (IAnjutaSymbolQueryIface *iface)
 	iface->search_scope = sdb_query_search_scope;
 	iface->search_parent_scope = sdb_query_search_parent_scope;
 	iface->search_parent_scope_file = sdb_query_search_parent_scope_file;
-	iface->search_scope_chain = sdb_query_search_scope_chain;
 }
 
 SymbolDBQuery *



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