[anjuta/cxxparser] cxxparser: first simple completions (plain and cast struct) are working.



commit 994af3136463a3ab2491a7215a810d2aa5b6594a
Author: Massimo Corà <mcora src gnome org>
Date:   Mon Jul 27 01:01:29 2009 +0200

    cxxparser: first simple completions (plain and cast struct) are working.

 plugins/symbol-db/cxxparser/Makefile.am            |    3 +-
 plugins/symbol-db/cxxparser/engine-parser-priv.h   |   59 ++--
 plugins/symbol-db/cxxparser/engine-parser.cpp      |  330 ++++++--------------
 plugins/symbol-db/cxxparser/expression-parser.cpp  |   14 +-
 plugins/symbol-db/cxxparser/main.c                 |  123 ++++----
 .../cxxparser/sample-db/test-cast-simple-struct.c  |   15 +
 6 files changed, 212 insertions(+), 332 deletions(-)
---
diff --git a/plugins/symbol-db/cxxparser/Makefile.am b/plugins/symbol-db/cxxparser/Makefile.am
index bd1df9a..edf7e63 100644
--- a/plugins/symbol-db/cxxparser/Makefile.am
+++ b/plugins/symbol-db/cxxparser/Makefile.am
@@ -57,7 +57,8 @@ anjuta_cxxparser_SOURCES = \
 		../symbol-db-engine-iterator.h \
 		../symbol-db-engine-queries.h \
 		../symbol-db-engine.h \
-		../symbol-db-engine-utils.h
+		../symbol-db-engine-utils.h \
+		../symbol-db-engine-core.h
  
 anjuta_cxxparser_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/symbol-db/cxxparser/engine-parser-priv.h b/plugins/symbol-db/cxxparser/engine-parser-priv.h
index d998ab3..6ab07ef 100644
--- a/plugins/symbol-db/cxxparser/engine-parser-priv.h
+++ b/plugins/symbol-db/cxxparser/engine-parser-priv.h
@@ -41,38 +41,25 @@ public:
 
 	void DEBUG_printTokens (const string& text);
 
-	// setter for the IAnjutaSymbolManager.
+	/* setter for the IAnjutaSymbolManager. */
 	void setSymbolManager (SymbolDBEngine *manager);
 
-	// getter for the IAnjutaSymbolManager.
+	/* 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
-	 * placed within any namespace)
-	 * \param stmt c++ expression
-	 * \param text text where this expression was found
-	 * \param fn filename context
-	 * \param lineno current line number
-	 * \param typeName [output]
-	 * \param typeScope [output]
-	 * \param oper [output] return the operator used (::, ., ->)
-	 * \param scopeTemplateInitList [output] return the scope tempalte intialization (e.g. "std::auto_ptr<wxString> str;" -> <wxString>
-	 * \return true on success, false otherwise. The output fields are only to be checked with the return
-	 * valus is 'true'
-	 */
-	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);
-	
+	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);
 
 	void testParseExpression (const string &in);
 
-	string GetScopeName(const string &in, std::vector<string> *additionlNS);
+	/*string GetScopeName(const string &in, std::vector<string> *additionlNS);*/
 
 	
 protected:
@@ -80,25 +67,29 @@ protected:
 	EngineParser ();
 
 	/**
-	 * parse an expression and return the result. this functions uses
-	 * the sqlite database as its symbol table
-	 * \param in input string expression
-	 * \return ExpressionResult, if it fails to parse it, check result.m_name.empty() for success
+	 * Parse an expression and return the result. 
+	 * @param in Input string expression
+	 * @return An ExpressionResult struct. If it fails to parse it, 
+	 * check result.m_name.empty() for success
 	 */
 	ExpressionResult parseExpression(const string &in);
+	
 private:
+	
 	/**
 	 * Return the next token and the delimiter found, the source string is taken from the
-	 * m_tokenScanner member of this class
-	 * \param token next token
-	 * \param delim delimiter found
-	 * \return true if token was found false otherwise
+	 * _tokenizer member of this class.
+	 *
+	 * @param token Next token
+	 * @param delim Delimiter found (as ".", "::", or "->")
+	 * @return true If token was found false otherwise
 	 */	
 	bool nextToken (string &out_token, string &out_delimiter);
 
-
 	/**
-	 * trim () a string
+	 * Trim a string using some default chars.
+	 * The code is expected to run quite performantly, as STL doesn't provide
+	 * a method to trim a string.
 	 */
 	void trim (string& str, string trimChars = "{};\r\n\t\v ");
 
diff --git a/plugins/symbol-db/cxxparser/engine-parser.cpp b/plugins/symbol-db/cxxparser/engine-parser.cpp
index eff7783..46de909 100644
--- a/plugins/symbol-db/cxxparser/engine-parser.cpp
+++ b/plugins/symbol-db/cxxparser/engine-parser.cpp
@@ -31,7 +31,7 @@
 
 using namespace std;
 
-// Singleton
+// Singleton pattern.
 EngineParser* 
 EngineParser::getInstance ()
 {
@@ -163,7 +163,7 @@ EngineParser::getSymbolManager ()
 }
 
 void 
-EngineParser::trim (string& str, string trimChars)
+EngineParser::trim (string& str, string trimChars /* = "{};\r\n\t\v " */)
 {
   	string::size_type pos = str.find_last_not_of (trimChars);
 	
@@ -182,49 +182,57 @@ EngineParser::trim (string& str, string trimChars)
 	}
 }
 
-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)
+/* FIXME TODO: error processing. Find out a way to notify the caller of the occurred 
+ * error. The "cout" method cannot be used
+ */
+bool
+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)
 {
-	bool evaluation_succeed = false;
-	_tokenizer->setText(stmt.c_str ());
-
-	string word;
+	bool evaluation_succeed = false;	
+		
+	string current_token;
 	string op;
 	string scope_name;
 	ExpressionResult result;
+
+	_tokenizer->setText (stmt.c_str ());
 	
-	while (nextToken (word, op)) 
+	while (nextToken (current_token, op)) 
 	{
-		trim (word);
-		
-		cout << "--------\ngot word ->" << word << "<- op " << op << endl; 
-		out_oper = op;
-
+		trim (current_token);
 		
+		cout << "--------\nCurrent token ->" << current_token << "<- with op " << op << endl; 
+		out_oper = op;	
 		
-		// fill up ExpressionResult
-		result = parseExpression (word);
+		/* parse the current sub-expression of a statement and fill up 
+		 * ExpressionResult object
+		 */
+		result = parseExpression (current_token);
 
 		//parsing failed?
 		if (result.m_name.empty()) {
-			cout << "Failed to parse " << word << " from " << stmt << endl;
+			cout << "Failed to parse " << current_token << " from " << stmt << endl;
 			evaluation_succeed = false;
 			break;
 		}
-		
+
+		// DEBUG PRINT
 		result.print ();
 
 		// no tokens before this, what we need to do now, is find the TagEntry
 		// that corresponds to the result
 		if (result.m_isaType) 
 		{
-			//--------------------------------------------
-			// Handle type (usually when casting is found)
-			//--------------------------------------------
-
+			cout << "Found a cast expression" << endl;
+			/*
+			 * Handle type (usually when casting is found)
+			 */
 			if (result.m_isPtr && op == ".") 
 			{
 				cout << "Did you mean to use '->' instead of '.' ?" << endl;
@@ -241,12 +249,13 @@ EngineParser::processExpression(const string& stmt, const string& above_text,
 			
 			out_type_scope = result.m_scope.empty() ? "<global>" : result.m_scope.c_str();
 			out_type_name = result.m_name.c_str();
+			evaluation_succeed = true;
 		} 
 		else if (result.m_isThis) 
 		{
-			//-----------------------------------------
-			// special handle for 'this' keyword
-			//-----------------------------------------
+			/*
+			 * special handle for 'this' keyword
+			 */
 			out_type_scope = result.m_scope.empty() ? "<global>" : result.m_scope.c_str();
 			if (scope_name == "<global>") 
 			{
@@ -276,13 +285,13 @@ EngineParser::processExpression(const string& stmt, const string& above_text,
 				break;
 			}
 			out_type_name = scope_name;
+			evaluation_succeed = true;
 		}
-
  		else 
 		{
-			//-------------------------------------------
-			// found an identifier (can be a local variable, a global one etc)
-			//--------------------------------------------
+			/*
+			 * Found an identifier (can be a local variable, a global one etc)
+			 */
 			
 			cout << "found an identifier or local variable..." << endl;
 
@@ -308,8 +317,6 @@ EngineParser::processExpression(const string& stmt, const string& above_text,
 				} while (symbol_db_engine_iterator_move_next (iter) == TRUE);
 			}			
 						    
-
-			/* TODO */
 			/* optimize scope'll clear the scopes leaving the local variables */
 			string optimized_scope = optimizeScope(above_text);
 
@@ -319,44 +326,20 @@ EngineParser::processExpression(const string& stmt, const string& above_text,
 			std::map<std::string, std::string> ignoreTokens;
 			get_variables(optimized_scope, li, ignoreTokens, false);
 
+			// FIXME: start enumerating from the end.
 			cout << "variables found are..." << endl;
 			for (VariableList::iterator iter = li.begin(); iter != li.end(); iter++) {
 				Variable var = (*iter);
 				var.print ();				
 				
-				if (word == var.m_name) {
+				if (current_token == var.m_name) {
 					cout << "wh0a! we found the variable type to parse... it's ->" << 
 						var.m_type << "<-" << endl;
 
-					SymbolDBEngineIterator *iter = 
-						symbol_db_engine_find_symbol_by_name_pattern_filtered (
-						    _dbe, var.m_type.c_str (), TRUE, NULL, TRUE, -1, NULL, -1 , 
-						    -1, SYMINFO_SIMPLE);
-
-					if (iter != NULL) {
-						SymbolDBEngineIteratorNode *node = 
-							SYMBOL_DB_ENGINE_ITERATOR_NODE (iter);
-						cout << "SymbolDBEngine: Searched var got name: " << 
-							symbol_db_engine_iterator_node_get_symbol_name (node) << endl;
-						
-						// print the scope members
-						SymbolDBEngineIterator * children = 
-							symbol_db_engine_get_scope_members_by_symbol_id (_dbe, 
-								symbol_db_engine_iterator_node_get_symbol_id (node), 
-								-1,
-								-1,
-								SYMINFO_SIMPLE);
-						if (children != NULL)
-						{
-							cout << "scope children are: " << endl;
-							do {
-								SymbolDBEngineIteratorNode *child = 
-									SYMBOL_DB_ENGINE_ITERATOR_NODE (children);
-								cout << "SymbolDBEngine: Searched var got name: " << 
-									symbol_db_engine_iterator_node_get_symbol_name (child) << endl;
-							}while (symbol_db_engine_iterator_move_next (children) == TRUE);						
-						} 
-					}
+					out_type_name = var.m_type;
+					out_type_scope = var.m_typeScope;
+
+					evaluation_succeed = true;
 					break;
 				}
 			}			
@@ -364,168 +347,15 @@ EngineParser::processExpression(const string& stmt, const string& above_text,
 			/* TODO */
 			/* get the derivation list of the typename */
 		}
-#if 0					
-/*		
-			wxString scopeToSearch(scopeName);
-			if (parentTypeScope.IsEmpty() == false && parentTypeScope != wxT("<global>")) {
-				scopeToSearch = parentTypeScope + wxT("::") + parentTypeName;
-			} else if ((parentTypeScope.IsEmpty()|| parentTypeScope == wxT("<global>")) && !parentTypeName.IsEmpty()) {
-				scopeToSearch = parentTypeName;
-			}
-
-			//--------------------------------------------------------------------------------------------
-			//keep the scope that we searched so far. The accumumlated scope
-			//are used for types, for scenarios like:
-			//void Box::GetWidth()
-			// {
-			//	Rectangle::
-			//
-			//trying to process the above code, will yield searching Rectangle inside Box scope, since we are
-			//inside Box's GetWidth() function.
-			//the correct behavior shuold be searching for Rectangle in the global scope.
-			//to correct this, we do special handling for Qualifier followed by coloon:colon operator (::)
-			if (accumulatedScope.IsEmpty() == false) {
-				if (accumulatedScope == wxT("<global>")) {
-					accumulatedScope = scopeToSearch;
-				} else {
-					accumulatedScope << wxT("::");
-					accumulatedScope << scopeToSearch;
-				}
-			} else {
-				accumulatedScope << wxT("<global>");
-			}
-
-			wxString originalScopeName(scopeToSearch);
-			if (op == wxT("::")) {
-				//if the operator was something like 'Qualifier::', it is safe to assume
-				//that the secope to be searched is the full expression
-				scopeToSearch = accumulatedScope;
-			}
-*/
-			// get the derivation list of the typename
-			bool res(false);
-			wxString _name(_U(result.m_name.c_str()));
-			PERF_BLOCK("TypeFromName") {
-				for (int i=0; i<2; i++) {
-					res = TypeFromName(	_name, 
-					                    visibleScope,
-					                    lastFuncSig,
-					                    scopeToSearch,
-					                    additionalScopes,
-					                    parentTypeName.IsEmpty(),
-					                    typeName,   //output
-					                    typeScope); //output
-
-					if (!res && originalScopeName.IsEmpty() == false) {
-						// the scopeToSearch was modified earlier with the accumulated scope
-						// restore the search scope and try again
-						scopeToSearch = originalScopeName;
-						continue;
-					}
-					break;
-				}
-			}
-
-			if (!res) {
-				evaluationSucceeded = false;
-				break;
-			}
-
-			// do typedef subsitute
-			wxString tmp_name(typeName);
-			while (OnTypedef(typeName, typeScope, templateInitList, scopeName, scopeTemplateInitList)) {
-				if (tmp_name == typeName) {
-					//same type? break
-					break;
-				}
-				tmp_name = typeName;
-			}
-
-			//do template subsitute
-			if (OnTemplates(typeName, typeScope, parent)) {
-				//do typedef subsitute
-				wxString tmp_name(typeName);
-				while (OnTypedef(typeName, typeScope, templateInitList, scopeName, scopeTemplateInitList)) {
-					if (tmp_name == typeName) {
-						//same type? break
-						break;
-					}
-					tmp_name = typeName;
-				}
-			}
-
-			// try match any overloading operator to the typeName
-			wxString origTypeName(typeName);
-
-			// keep the typeScope in variable origTypeScope since it might be modified by
-			// the OnArrowOperatorOverloading() method, but we might need it again in case
-			// -> operator overloading is found
-			wxString origTypeScope(typeScope);
-			if ( op == wxT("->") && OnArrowOperatorOverloading(typeName, typeScope) ) {
-
-				// there is an operator overloading for ->
-				// do the whole typedef/template subsitute again
-				wxString tmp_name(typeName);
-				while (OnTypedef(typeName, typeScope, templateInitList, scopeName, scopeTemplateInitList)) {
-					if (tmp_name == typeName) {
-						//same type? break
-						break;
-					}
-					tmp_name = typeName;
-				}
-
-				// When template is found, replace the typeName with the temporary type name
-				// usually it will replace 'T' with the parent type, such as
-				// 'Singleton'
-				if (templateInitList.IsEmpty() == false) {
-					m_parentVar.m_isTemplate = true;
-					m_parentVar.m_templateDecl = _C(templateInitList);
-					m_parentVar.m_type = _C(origTypeName);
-					m_parentVar.m_typeScope = _C(origTypeScope); // we use the original type scope
-				}
-
-				// do template subsitute
-				if (OnTemplates(typeName, typeScope, m_parentVar)) {
-					//do typedef subsitute
-					wxString tmp_name(typeName);
-					while (OnTypedef(typeName, typeScope, templateInitList, scopeName, scopeTemplateInitList)) {
-						if (tmp_name == typeName) {
-							//same type? break
-							break;
-						}
-						tmp_name = typeName;
-					}
-				}
-			}
-		}
-
-		parent = m_parentVar;
-
-		//Keep the information about this token for next iteration
-		if (!parent.m_isTemplate && result.m_isTemplate) {
-
-			parent.m_isTemplate = true;
-			parent.m_templateDecl = result.m_templateInitList;
-			parent.m_type = _C(typeName);
-			parent.m_typeScope = _C(typeScope);
-
-		} else if (templateInitList.IsEmpty() == false) {
-
-			parent.m_isTemplate = true;
-			parent.m_templateDecl = _C(templateInitList);
-			parent.m_type = _C(typeName);
-			parent.m_typeScope = _C(typeScope);
-		}
-
+#if 0
 		parentTypeName = typeName;
 		parentTypeScope = typeScope;
 
 #endif		
-		word.clear ();
+		current_token.clear ();
 	}	
 
-	// FIXME
-	return NULL;
+	return evaluation_succeed;
 }
 
 
@@ -637,7 +467,7 @@ EngineParser::optimizeScope(const string& srcString)
 	return srcString;
 }
 
-
+/*
 string
 EngineParser::GetScopeName(const string &in, std::vector<string> *additionlNS)
 {
@@ -664,7 +494,7 @@ EngineParser::GetScopeName(const string &in, std::vector<string> *additionlNS)
 	}
 	return scope;
 }
-
+*/
 
 
 /************ C FUNCTIONS ************/
@@ -715,15 +545,53 @@ engine_parser_process_expression (const char *stmt, const char * above_text,
 	string out_type_name;
 	string out_type_scope;
 	string out_oper;
-	string out_scope_template_init_list;
 	
-	return EngineParser::getInstance ()->processExpression (stmt, above_text,  
-	    full_file_path, linenum, out_type_name,
-	    out_type_scope, out_oper, out_scope_template_init_list);
+	bool result = EngineParser::getInstance ()->processExpression (stmt, above_text,  
+	    full_file_path, linenum, out_type_name, out_type_scope, out_oper);
 
-/*
-	cout << "process expression result: " << endl << "out_type_name " << out_type_name <<  endl << 
-	    "out_type_scope " << out_type_scope << endl << "out_oper " << out_oper << endl <<
-		"out_scope_template_init_list " << out_scope_template_init_list << endl;
-*/	 
+	if (result == false)
+	{
+		cout << "Hey, something went wrong in processExpression, bailing out" << endl;
+		return NULL;		
+	}
+	
+	SymbolDBEngine * dbe = EngineParser::getInstance ()->getSymbolManager ();
+
+	cout << "process expression result: " << endl << "out_type_name " << out_type_name <<  
+		endl << 
+	    "out_type_scope " << out_type_scope << endl << "out_oper " << out_oper << endl;
+					
+	SymbolDBEngineIterator *iter = 
+		symbol_db_engine_find_symbol_by_name_pattern_filtered (
+		    dbe, out_type_name.c_str (), TRUE, NULL, TRUE, -1, NULL, -1 , 
+		    -1, SYMINFO_SIMPLE);
+
+	if (iter != NULL) {
+		SymbolDBEngineIteratorNode *node = 
+			SYMBOL_DB_ENGINE_ITERATOR_NODE (iter);
+		cout << "SymbolDBEngine: Searched var got name: " << 
+			symbol_db_engine_iterator_node_get_symbol_name (node) << endl;
+		
+		// print the scope members
+		SymbolDBEngineIterator * children = 
+			symbol_db_engine_get_scope_members_by_symbol_id (dbe, 
+				symbol_db_engine_iterator_node_get_symbol_id (node), 
+				-1,
+				-1,
+				SYMINFO_SIMPLE);
+		
+		if (children != NULL)
+		{
+			cout << "scope children are: " << endl;
+			do {
+				SymbolDBEngineIteratorNode *child = 
+					SYMBOL_DB_ENGINE_ITERATOR_NODE (children);
+				cout << "SymbolDBEngine: Searched var got name: " << 
+					symbol_db_engine_iterator_node_get_symbol_name (child) << endl;
+			}while (symbol_db_engine_iterator_move_next (children) == TRUE);						
+		} 
+	}	
+
+	//  FIXME
+	return NULL;
 }
diff --git a/plugins/symbol-db/cxxparser/expression-parser.cpp b/plugins/symbol-db/cxxparser/expression-parser.cpp
index 8eae6b0..e827bc4 100644
--- a/plugins/symbol-db/cxxparser/expression-parser.cpp
+++ b/plugins/symbol-db/cxxparser/expression-parser.cpp
@@ -738,7 +738,7 @@ case 23:
 						result.m_isaType = true;
 						result.m_name = yyvsp[-2];
 						result.m_isFunc = false;
-						printf("Rule 1\n");						
+						/*printf("Rule 1\n");	*/
 					}
 break;
 case 24:
@@ -749,7 +749,7 @@ case 24:
 						result.m_isFunc = false;
 						result.m_isThis = true;
 						result.m_isPtr = true;
-						printf("Rule 2\n");	
+						/*printf("Rule 2\n");	*/
 					}
 break;
 case 25:
@@ -759,7 +759,7 @@ case 25:
 						result.m_name = yyval;
 						result.m_isFunc = false;
 						result.m_isThis = true;
-						printf("Rule 3\n");		
+						/*printf("Rule 3\n");		*/
 					}
 break;
 case 26:
@@ -770,7 +770,7 @@ case 26:
 						result.m_isFunc = false;
 						result.m_isThis = false;
 						result.m_isPtr = false;
-						printf("Rule 4\n");		
+						/*printf("Rule 4\n");		*/
 					}
 break;
 case 27:
@@ -780,7 +780,7 @@ case 27:
 						result.m_name = yyval;
 						result.m_isFunc = false;
 						result.m_isThis = false;
-						printf("Rule 5\n");		
+						/*printf("Rule 5\n");		*/
 					}
 break;
 case 28:
@@ -792,7 +792,7 @@ case 28:
 						result.m_scope = yyvsp[-3];
 						result.m_isTemplate = yyvsp[-1].empty() ? false : true;
 						result.m_templateInitList = yyvsp[-1];
-						printf("Rule 6\n");		
+						/*printf("Rule 6\n");		*/
 					}
 break;
 case 29:
@@ -802,7 +802,7 @@ case 29:
 						result.m_name = yyval;
 						result.m_isFunc = false;
 						result.m_isThis = false;
-						printf("Rule 7\n");		
+						/*printf("Rule 7\n");		*/
 					}
 break;
 case 30:
diff --git a/plugins/symbol-db/cxxparser/main.c b/plugins/symbol-db/cxxparser/main.c
index 33600ae..8fa2b0e 100644
--- a/plugins/symbol-db/cxxparser/main.c
+++ b/plugins/symbol-db/cxxparser/main.c
@@ -64,90 +64,95 @@ load_file(const gchar *fileName)
 #define SAMPLE_DB_ABS_PATH "/home/pescio/gitroot/anjuta/plugins/symbol-db/cxxparser/sample-db/"
 #define ANJUTA_TAGS "/home/pescio/svnroot/svninstalled/usr/bin/anjuta-tags"
 
+
+
+/* source_file must be provided without extension */
+#define INIT_C_TEST(source_file,callback) { \
+	gchar *associated_source_file = SAMPLE_DB_ABS_PATH""source_file".c";	\
+	gchar *associated_db = source_file;	\
+	gchar *root_dir = SAMPLE_DB_ABS_PATH;	\
+	SymbolDBEngine *dbe = symbol_db_engine_new_full (ANJUTA_TAGS, associated_db);	\
+	symbol_db_engine_open_db (dbe, root_dir, root_dir);	\
+	symbol_db_engine_add_new_project (dbe, NULL, root_dir);	\
+	g_signal_connect (dbe, "scan-end", G_CALLBACK (callback), NULL);	\
+	\
+	GPtrArray *files_array = g_ptr_array_new ();	\
+	g_ptr_array_add (files_array, associated_source_file);	\
+	GPtrArray *source_array = g_ptr_array_new ();	\
+	g_ptr_array_add (source_array, "C");	\
+	\
+	if (symbol_db_engine_add_new_files_full (dbe, root_dir, files_array, source_array, TRUE) < 0)	\
+		g_warning ("Error on scanning");	\
+	\
+	engine_parser_init (dbe);	\
+}
+
+static void 
+on_test_cast_simple_struct_scan_end (SymbolDBEngine* dbe, gpointer user_data)
+{	
+	g_message ("dbe %p user data is %p", dbe, user_data);
+	gchar *associated_source_file = SAMPLE_DB_ABS_PATH"test-cast-simple-struct.c";	
+	gchar *file_content = load_file (associated_source_file);
+
+	engine_parser_process_expression ("((foo)var).", file_content, 
+	    associated_source_file, 15);
+
+	g_free (file_content);
+}
+
+
+static void
+test_cast_simple_struct ()
+{		
+	INIT_C_TEST("test-cast-simple-struct", on_test_cast_simple_struct_scan_end);
+}
+
+
+
 static void 
 on_test_simple_struct_scan_end (SymbolDBEngine* dbe, gpointer user_data)
 {	
 	gchar *associated_source_file = SAMPLE_DB_ABS_PATH"test-simple-struct.c";	
 	gchar *file_content = load_file (associated_source_file);
 
-	g_message ("above text: %s", file_content);
-
-	
 	engine_parser_process_expression ("var.", file_content, associated_source_file, 9);
 
-//	g_free (file_content);
+	g_free (file_content);
 }
 
 static void
 test_simple_struct ()
 {		
-	gchar *associated_source_file = SAMPLE_DB_ABS_PATH"test-simple-struct.c";	
-	gchar *associated_db_file = "test-simple-struct";
-	gchar *root_dir = SAMPLE_DB_ABS_PATH;
-	SymbolDBEngine *dbe = symbol_db_engine_new_full (ANJUTA_TAGS, 
-	    associated_db_file);	
-	symbol_db_engine_open_db (dbe, root_dir, root_dir);
-	symbol_db_engine_add_new_project (dbe, NULL, root_dir);
-
-	g_signal_connect (dbe, "scan-end", 
-	    G_CALLBACK (on_test_simple_struct_scan_end), NULL);
-	
-	GPtrArray *files_array = g_ptr_array_new ();
-	g_ptr_array_add (files_array, associated_source_file);
-	
-	GPtrArray *source_array = g_ptr_array_new ();
-	g_ptr_array_add (source_array, "C");
-	
-	if (symbol_db_engine_add_new_files (dbe, root_dir, files_array, source_array, TRUE) < 0)
-		g_warning ("Error on scanning");
-
-
-	engine_parser_init (dbe);
+	INIT_C_TEST("test-simple-struct", on_test_simple_struct_scan_end);
 }
 
+
 /**
  * This main simulate an anjuta glib/gtk process. We'll then call some functions
  * of the C++ parser to retrieve the type of an expression.
  */
 int	main (int argc, char *argv[])
 {
-  	gtk_init(&argc, &argv);
-  	g_thread_init (NULL);
+	GMainLoop * main_loop;
+  	//gtk_init(&argc, &argv);
+
+	if ( !g_thread_supported() )
+  		g_thread_init( NULL );	
+  	
+	g_type_init();
 	gda_init ();	
+
+	main_loop = g_main_loop_new (NULL, FALSE);
+	
  	g_test_init (&argc, &argv, NULL);
 
 	g_test_add_func ("/simple_c/test-simple-struct", test_simple_struct);
-	
+	g_test_add_func ("/simple_c/test-cast-simple-struct", test_cast_simple_struct);
 
-	g_test_run();
-	gtk_main ();
-	return 0;
-} 	
-#if 0
-	
-	// FIXME: an instance of symbolmanager should be passed instead of a dbe one.
-	engine_parser_init (dbe);
-	
-	//engine_parser_DEBUG_print_tokens (buf);
+	g_test_run ();
+	g_message ("test run finished");
 
-//	char *test_str = "str.";
-	char *test_str = "Std::String *asd";
 	
-//	char *test_str = "(wxString*)str.";
-//	char *test_str = "((Std::string*)eran)->";
-//	char *test_str = "((TypeDefFoo)((Std::string*)eran))->func_returning_klass ().";
-	//char *test_str = "((A*)((B*)(foo)))->"; // should return A* as m_name. Check here..
-//	char *test_str = "*this->"; // should return A* as m_name. Check here. 
-
-//	printf ("print tokens.....\n");
-//	engine_parser_DEBUG_print_tokens (test_str);
-
-	printf ("process expression..... %s\n", test_str);
-	engine_parser_process_expression (test_str);
-
-/*
-	engine_parser_test_optimize_scope (buf);
-	engine_parser_get_local_variables (buf);
-*/	
-	//gtk_main();
-#endif	
+	g_main_loop_run (main_loop);
+	return 0;
+} 	
diff --git a/plugins/symbol-db/cxxparser/sample-db/test-cast-simple-struct.c b/plugins/symbol-db/cxxparser/sample-db/test-cast-simple-struct.c
new file mode 100644
index 0000000..7f87eac
--- /dev/null
+++ b/plugins/symbol-db/cxxparser/sample-db/test-cast-simple-struct.c
@@ -0,0 +1,15 @@
+
+
+struct asd {
+	char a; 
+	int b; 
+};
+
+struct foo {
+	char c;
+	void *d;
+};
+
+void main () { 
+	asd var; 
+	((foo)var).



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