anjuta r4028 - in trunk: . plugins/document-manager plugins/symbol-browser



Author: jhs
Date: Wed Jun 18 09:03:08 2008
New Revision: 4028
URL: http://svn.gnome.org/viewvc/anjuta?rev=4028&view=rev

Log:
2008-06-17  SÃbastien Granjoux  <seb sfo free fr>

	* plugins/document-manager/anjuta-docman.c:
	Fix #538798: UI selected tab document differs from real one

Modified:
   trunk/ChangeLog
   trunk/plugins/document-manager/anjuta-docman.c
   trunk/plugins/symbol-browser/an_symbol_view.c

Modified: trunk/plugins/document-manager/anjuta-docman.c
==============================================================================
--- trunk/plugins/document-manager/anjuta-docman.c	(original)
+++ trunk/plugins/document-manager/anjuta-docman.c	Wed Jun 18 09:03:08 2008
@@ -1147,7 +1147,23 @@
 static AnjutaDocmanPage *
 anjuta_docman_get_nth_page (AnjutaDocman *docman, gint page_num)
 {
-	return g_list_nth_data (docman->priv->pages, page_num);
+	GtkWidget *widget;
+	GList *node;
+
+	widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (docman), page_num);
+	node = docman->priv->pages;
+	while (node)
+	{
+		AnjutaDocmanPage *page;
+
+		page = node->data;
+		g_assert (page);
+		if (page->widget == widget)
+			return page;
+		node = g_list_next (node);
+	}
+	
+	return NULL;
 }
 
 IAnjutaDocument *

Modified: trunk/plugins/symbol-browser/an_symbol_view.c
==============================================================================
--- trunk/plugins/symbol-browser/an_symbol_view.c	(original)
+++ trunk/plugins/symbol-browser/an_symbol_view.c	Wed Jun 18 09:03:08 2008
@@ -1501,1059 +1501,3 @@
 	}
 	return FALSE;
 }
-
-/*
- * for a given expression "myvar->getX().toFloat"
- * the function should just return "myvar"
- * and move the **expr pointer after the ident
- * returns NULL, if no identifier is found, and then the value of expr is undefined
- */
-static gchar* 
-sv_scan_for_ident(const gchar **expr)
-{
-	static gchar ident[1024];
-	/* number of identified characters in the ident string */
-    int valid_chars = 0; 
-
-	gchar c;
-	while ((c = **expr) != '\0')
-	{
-		if(valid_chars == 0 && isspace(c))
-		{
-			(*expr)++;
-			continue;
-		}
-		// XXX: Namespace support
-		else if(isalpha(c) || c == '_') // ???: || c == ':')
-		{
-			ident[valid_chars] = c;
-			if (++valid_chars == 1023)
-			{
-				ident[1023] = '\0';
-				return ident;
-			}
-		}
-		/* a digit may be part of an ident but not from the start */
-		else if (isdigit(c))
-		{
-			if (valid_chars)
-			{
-				ident[valid_chars] = c;
-				if (++valid_chars == 1023)
-				{
-					ident[1023] = '\0';
-					return ident;
-				}
-			}
-			else
-				return NULL;
-
-		}
-		else
-			break;
-
-		(*expr)++;
-	}
-
-	if (valid_chars)
-	{
-		ident[valid_chars] = '\0';
-		return ident;
-	}
-	else
-		return NULL;
-}
-
-
-static
-gchar* sv_extract_type_qualifier_from_expr (const gchar *string, const gchar *expr )
-{
-	/* check with a regular expression for the type */
-	regex_t re;
-	gint i;
-	regmatch_t pm[8]; // 7 sub expression -> 8 matches
-	memset (&pm, -1, sizeof(pm));
-	/*
-	 * this regexp catches things like:
-	 * a) std::vector<char*> exp1[124] [12], *exp2, expr;
-	 * b) QClass* expr1, expr2, expr;
-	 * c) int a,b; char r[12] = "test, argument", q[2] = { 't', 'e' }, expr;
-	 *
-	 * it CAN be fooled, if you really want it, but it should
-	 * work for 99% of all situations.
-	 *
-	 * QString
-	 * 		var;
-	 * in 2 lines does not work, because //-comments would often bring wrong results
-	 */
-
-	#define STRING      "\\\".*\\\""
-	#define BRACKETEXPR "\\{.*\\}"
-	#define IDENT       "[a-zA-Z_][a-zA-Z0-9_]*"
-	#define WS          "[ \t\n]*"
-	#define PTR         "[\\*&]?\\*?"
-	#define INITIALIZER "=(" WS IDENT WS ")|=(" WS STRING WS ")|=(" WS BRACKETEXPR WS ")" WS
-	#define ARRAY 		WS "\\[" WS "[0-9]*" WS "\\]" WS
-
-	gchar *res = NULL;
-	gchar pattern[512] =
-		"(" IDENT "\\>)" 	// the 'std' in example a)
-		"(::" IDENT ")*"	// ::vector
-		"(" WS "<[^>;]*>)?"	// <char *>
-		"(" WS PTR WS IDENT WS "(" ARRAY ")*" "(" INITIALIZER ")?," WS ")*" // other variables for the same ident (string i,j,k;)
-		"[ \t\\*&]*";		// check again for pointer/reference type
-
-	/* must add a 'termination' symbol to the regexp, otherwise
-	 * 'exp' would match 'expr' */
-	gchar regexp[512];
-	snprintf (regexp, 512, "%s\\<%s\\>", pattern, expr);
-
-	/* compile regular expression */
-	gint error = regcomp (&re, regexp, REG_EXTENDED) ;
-	if (error)
-		g_warning ("regcomp failed");
-
-	/* this call to regexec finds the first match on the line */
-	error = regexec (&re, string, 8, &pm[0], 0) ;
-	
-	/* while matches found. We'll find the *last* occurrence of the expr. This will
-	 * guarantee us that it is the right one we want to use. I.e.
-	 *
-	 * given:
-	 *
-	 *
-	 * int func_1 (void) {
-	 *
-	 *   MyClass *klass;
-	 *
-	 *
-	 *   for (int i=0; i < 20; i++) {
-	 *     YourClass *klass;
-	 *
-	 *     klass->
-	 *   }
-	 *
-	 *  / ... /
-	 *
-	 * Here the klass-> will be matched as YourClass [right], not the MyClass' ones [wrong]
-	 * 
-	 */
-	while (error == 0) 
-	{   
-		/* subString found between pm.rm_so and pm.rm_eo */
-		/* only include the ::vector part in the indentifier, if the second subpattern matches at all */
-		gint len = (pm[2].rm_so != -1 ? pm[2].rm_eo : pm[1].rm_eo) - pm[1].rm_so;
-		if (res)
-			free (res);
-		res = (gchar*) malloc (len + 1);
-		if (!res)
-		{
-			regfree (&re);
-			return NULL;
-		}
-		strncpy (res, string + pm[1].rm_so, len); 
-		res[len] = '\0';
-		
-		string += pm[0].rm_eo;
-		
-		/* This call to regexec finds the next match */
-		error = regexec (&re, string, 8, &pm[0], 0) ;
-	}
-	regfree(&re);
-
-	if (!res)
-		return NULL;
-	
-	/* if the proposed type is a keyword, we did something wrong, return NULL instead */	
-
-	i=0;
-	while (keywords[i] != NULL) {
-		if (strcmp(res, keywords[i]) == 0) {
-			return NULL;
-		}
-		i++;
-	}
-	
-	return res;
-}
-
-
-
-/* Sample class:
- * class QWidget {
- * public:
- *    QWidget();
- *    [..]
- *    QRect getRect();
- *
- * };
- * 
- * for ident=getRect and klass="QWidget" return a tag of type QRect.
- * 
- * */
-static TMTag* 
-sv_get_type_of_token (const gchar* ident, const gchar* klass, const TMTag* local_scope_of_ident, 
-					const TMTag* local_declaration_type)
-{
-	const GPtrArray *tags_array;
-	TMTag *klass_tag = NULL;
-	gint i;
-	
-	/* if we have a variable and already found a local definition, just return it */
-	if (local_declaration_type != NULL && strlen(local_declaration_type->name)) {
-		return (TMTag*)local_declaration_type;
-	}
-
-	/* if the identifier is this-> return the current class */
-	if (!strcmp (ident, "this")) {
-		const GPtrArray *tags_array;
-		TMTag* scope_tag = NULL;
-		gint i;
-		
-		scope_tag = (TMTag*)local_scope_of_ident;
-		
-		if (scope_tag == NULL || scope_tag->atts.entry.scope == NULL)
-			return NULL;
-		
-		tags_array = tm_workspace_find (scope_tag->atts.entry.scope, 
-				tm_tag_struct_t | tm_tag_typedef_t |tm_tag_union_t| tm_tag_class_t, 
-				NULL, FALSE, TRUE);
-		
-		if (tags_array  != NULL) {
-			for (i=0; i < tags_array ->len; i++) {
-				TMTag *cur_tag;
-			
-				cur_tag = (TMTag*)g_ptr_array_index (tags_array , i);
-				if ( strcmp (cur_tag->name, scope_tag->atts.entry.scope) == 0) {
-					scope_tag = cur_tag;
-					break;
-				}
-			}
-		}
-				
-		if (scope_tag)
-			DEBUG_PRINT ("scope_tag [class] %s", scope_tag->name);
-		return scope_tag;;
-	}
-	
-	/* ok, search the klass for the symbols in workspace */
-	if (klass == NULL || (strcmp("", klass) == 0))
-		return NULL;
-	
-	tags_array = tm_workspace_find_scope_members (NULL, klass, TRUE, TRUE);
-	
-	if (tags_array != NULL)
-	{
-		for (i=0; i < tags_array->len; i++) {
-			TMTag *tmp_tag;
-		
-			tmp_tag = (TMTag*)g_ptr_array_index (tags_array, i);
-		
-			/* store the klass_tag. It will be useful later */
-			if (strcmp (tmp_tag->name, klass) == 0) {
-				klass_tag = tmp_tag;
-			}
-		
-			if (strcmp (tmp_tag->name, ident) == 0 ) {
-				return tmp_tag;
-			}
-		}
-	}	
-		
-	/* checking for inherited members. We'll reach this point only if the right tag 
-     * hasn't been detected yet.
-	 */
-	GPtrArray *inherited_tags_array;
-	
-	inherited_tags_array = anjuta_symbol_view_get_completable_members (klass_tag, TRUE);
-	
-	if (inherited_tags_array != NULL)
-	{
-		for (i=0; i < inherited_tags_array->len; i++) {
-			TMTag *tmp_tag;
-		
-			tmp_tag = (TMTag*)g_ptr_array_index (inherited_tags_array, i);
-			DEBUG_PRINT ("parsing inherited member as %s ", tmp_tag->name);
-			if ( (strcmp (tmp_tag->name, ident) == 0) ) {
-				const GPtrArray *inherit_array;
-		
-				TMTagAttrType attrs[] = {
-					tm_tag_attr_type_t
-				};
-			
-				inherit_array = tm_workspace_find (tmp_tag->atts.entry.type_ref[1], 
-						tm_tag_class_t, attrs, FALSE, TRUE);
-					
-				if (inherit_array == NULL)
-					continue;
-								
-				gint j;
-				for (j=0; j < inherit_array->len; j++) {
-					TMTag *cur_tag = (TMTag*)g_ptr_array_index (inherit_array, j);
-				
-					if (strcmp(tmp_tag->atts.entry.type_ref[1], cur_tag->name) == 0 )
-						return cur_tag;
-				}
-			
-				return tmp_tag;
-			}
-		}
-		g_ptr_array_free (inherited_tags_array, TRUE);
-	}
-
-	DEBUG_PRINT ("returning NULL from get_type_of_token. ident %s", ident);
-	return NULL;
-}
-
-
-/*----------------------------------------------------------------------------
- * Lists the completable members given a klass_tag. I.e.: it returns all current
- * class members [private/protected/public] [or in case of a struct all its members]
- * and then it goes up for parents retrieving public/protected members.
- */
-
-GPtrArray*
-anjuta_symbol_view_get_completable_members (TMTag* klass_tag, gboolean include_parents) {
-	gchar *symbol_name;
-
-	if (klass_tag == NULL)
-		return NULL;
-	
-	
-	symbol_name = klass_tag->atts.entry.type_ref[1];
-	if (symbol_name == NULL)
-		symbol_name = klass_tag->name;
-	
-	DEBUG_PRINT ("get_completable_members --> scope of tag name %s is %s", klass_tag->name, klass_tag->atts.entry.scope);
-	// FIXME: comment this
-	tm_tag_print (klass_tag, stdout);
-
-	switch (klass_tag->type) {
-		case tm_tag_struct_t: 
-		case tm_tag_typedef_t: 
-		case tm_tag_union_t: 
-		{
-			const GPtrArray* tags_array;
-			GPtrArray *completable_array;
-			gint i;
-			/* we should list all members of our struct/typedef/union...*/
-			tags_array = tm_workspace_find_scope_members (NULL, symbol_name,
-														  TRUE, TRUE);
-			if (tags_array == NULL) {
-				DEBUG_PRINT ("returning NULL from struct-completable");
-				return NULL;
-			}
-
-			DEBUG_PRINT ("returning NULL from struct-completable. Tags array len %d", tags_array->len);
-			
-			completable_array = g_ptr_array_new ();
-			for (i=0; i < tags_array->len; i++)
-				g_ptr_array_add (completable_array, g_ptr_array_index (tags_array, i));
-				
-			return completable_array;
-		}
-		case tm_tag_class_t: 
-		case tm_tag_member_t:
-		case tm_tag_method_t:
-		case tm_tag_prototype_t:
-		{
-			
-			/* list all the public/protected members of super classes, if it's a class
-	  		obviously and if there are some super classes */
-			
-			GPtrArray *completable_array;			
-			const GPtrArray *tags_array;
-			gchar* tmp_str;
-			gint i;
-
-			DEBUG_PRINT ("completable: klass_tag is");
-			tm_tag_print (klass_tag, stdout);
-			
-			// FIXME: this part needs an improvement!
-			// It needs a search for symbols under a particular namespace. Infact right now 
-			// it cannot detect if a MyPrettyClass is defined under namespace1:: or under
-			// namespace2::. It just looks for the symbols of klass/struct/.. name
-			if (klass_tag->atts.entry.scope != NULL && 
-					(tmp_str=strstr(klass_tag->atts.entry.scope, "")) != NULL) {
-				DEBUG_PRINT ("scope with ::. FIXME");
-			}					
-			
-			tags_array = tm_workspace_find_scope_members (NULL, symbol_name,
-														  TRUE, TRUE);
-			if (tags_array == NULL) {
-				DEBUG_PRINT ("returning NULL from class&c-completable with symbol name %s [scope of klass_tag: %s]",
-							symbol_name, klass_tag->atts.entry.scope);
-				return NULL;
-			}
-
-			completable_array = g_ptr_array_new ();
-			/* we *must* duplicate the contents of the tags_array coz it will be 
-			 * overwritten the next call to tm_workspace_find_scope_members ().
-			 * Just the tag-pointers will be saved, not the entire struct behind them.
-			 */
-			for (i=0; i < tags_array->len; i++)
-				g_ptr_array_add (completable_array, g_ptr_array_index (tags_array, i));
-
-			/* should we go for parents [include_parents]? or is it a struct [inheritance == NULL]? */
-			if (!include_parents || klass_tag->atts.entry.inheritance == NULL)
-				return completable_array;
-				
-			DEBUG_PRINT ("parents from klass_tag [name] %s: %s", symbol_name, klass_tag->atts.entry.inheritance);
-			
-			const GPtrArray *parents_array = tm_workspace_get_parents (symbol_name);
-			if (parents_array == NULL) {
-				DEBUG_PRINT ("returning tags_array coz parents_array is null");
-				return completable_array;
-			}
-			
-			for (i=0; i < parents_array->len; i++) {
-				gint j;
-				const GPtrArray *tmp_parents_array;
-				TMTag* cur_parent_tag = g_ptr_array_index (parents_array, i);
-
-				/* we don't need the members for the symbols_name's class. We 
-				   already have them */
-				if ( (strcmp(cur_parent_tag->name, symbol_name) == 0) )
-					continue;
-				
-				if ( (tmp_parents_array = tm_workspace_find_scope_members (NULL, 
-						cur_parent_tag->name, TRUE, TRUE)) == NULL) {
-					continue;		
-				}
-					
-				gint length = tmp_parents_array->len;
-				for (j = 0; j < length; j++) {
-					TMTag *test_tag;
-					test_tag = (TMTag*)g_ptr_array_index (tmp_parents_array, j);
-					
-					if (test_tag->atts.entry.access == TAG_ACCESS_PUBLIC ||
-						test_tag->atts.entry.access == TAG_ACCESS_PROTECTED ||
-						test_tag->atts.entry.access == TAG_ACCESS_FRIEND) {
-
-						g_ptr_array_add (completable_array, test_tag);	
-					}					
-				}	
-			}			
-			
-			return completable_array;
-		}
-
-		case tm_tag_namespace_t:
-		{
-			const GPtrArray *namespace_classes;
-			GPtrArray *completable_array = NULL;
-			gint i;
-			
-			DEBUG_PRINT ("we got a namespace!, %s", klass_tag->name);
-
-			namespace_classes = tm_workspace_find_namespace_members (NULL, klass_tag->name, TRUE);
-
-			/* we *must* duplicate the contents of the tags_array coz it will be 
-			 * overwritten the next call to tm_workspace_find_scope_members ().
-			 * Just the tag-pointers will be saved, not the entire struct behind them.
-			 */
-			completable_array = g_ptr_array_new ();				
-			for (i=0; i < namespace_classes->len; i++) {
-				TMTag *cur_tag;
-			
-				cur_tag = (TMTag*)g_ptr_array_index (namespace_classes, i);
-				
-//				tm_tag_print (cur_tag, stdout);
-				g_ptr_array_add (completable_array, cur_tag);
-			}
-		
-			return completable_array;
-		}	
-		default: 
-			return NULL;
-	}
-	return NULL;
-}
-
-/* local_declaration_type_str must be NOT NULL.
- *
- */
-static TMTag * 
-sv_get_local_declaration_type (const gchar *local_declaration_type_str) {
-
-	const GPtrArray * loc_decl_tags_array;
-	TMTag* local_declaration_type = NULL;
-	
-	g_return_val_if_fail (local_declaration_type_str != NULL, NULL);
-	
-	/* local_declaration_type_str  != NULL */
-	gchar *occurrence;
-
-	DEBUG_PRINT ("local_declaration_type_str is %s", local_declaration_type_str);
-	DEBUG_PRINT ("checking for :: [namespace scoping] inside it...");
-			
-	if ( (occurrence=strstr(local_declaration_type_str, "::")) == NULL ) {
-		gint i;
-		DEBUG_PRINT ("No, it hasn't..");
-			
-		loc_decl_tags_array = tm_workspace_find (local_declaration_type_str, 
-			tm_tag_struct_t | tm_tag_typedef_t |tm_tag_union_t| tm_tag_class_t, 
-			NULL, FALSE, TRUE);
-
-		/* We should have a look at the tags_array for the correct tag. */
-		if (loc_decl_tags_array != NULL) {
-			for (i=0; i < loc_decl_tags_array->len; i++) {
-				TMTag *cur_tag;
-
-				cur_tag = (TMTag*)g_ptr_array_index (loc_decl_tags_array, i);
-				if ( strcmp(cur_tag->name, local_declaration_type_str) == 0) {
-					local_declaration_type = cur_tag;
-					break;
-				}
-			}
-			return local_declaration_type;
-		}
-		else 
-			return NULL;
-	}
-	else {			/* namespace string parsing */
-		/* This is the case of
-		 * void foo_func() {
-		 *
-		 *  namespace1::namespace2::MyClass *myclass;	
-	 	 *  
-	 	 *  myclass->
-	 	 *
-	 	 * }
-		 *
-		 * we should parse the "local_declaration_type_str" and retrieve the 
-		 * TMTag of MyClass under namespace1::namespace2.
-		 *
-		 */
-	
-		gchar **splitted_str;
-		const GPtrArray *tmp_tags_array;
-		gint indx;
-
-		DEBUG_PRINT ("Yes, it has!");
-		
-		splitted_str = g_strsplit (local_declaration_type_str, "::", -1);
-
-		DEBUG_PRINT ("Check for splitted_str[0] existence into workspace...");
-		tmp_tags_array =  tm_workspace_find (splitted_str[0], 
-									tm_tag_struct_t | tm_tag_union_t |
-									tm_tag_typedef_t | tm_tag_class_t |
-									tm_tag_macro_t | tm_tag_macro_with_arg_t |
-									tm_tag_namespace_t, NULL, FALSE, TRUE);
-		
-		
-		if (tmp_tags_array == NULL) {
-			DEBUG_PRINT ("tmp_tags_array is NULL");
-			g_strfreev (splitted_str);
-			return NULL;
-		}
-
-		
-		/* ok, we can start from index 1 to check the correctness of expression */
-		for (indx=1; splitted_str[indx] != NULL; indx++) {
-			gint i;
-			gboolean found_end_node;
-			TMTag *tmp_tag = NULL;
-				
-			DEBUG_PRINT ("===string %d is %s====", indx, splitted_str[indx]);
-				
-			/* check the availability of namespace2 under the members of namespace1 
-			 * and so on 
-			 */
-			tmp_tags_array = tm_workspace_find_namespace_members (NULL, splitted_str[indx-1], TRUE);
-
-			if (tmp_tags_array == NULL) {
-				local_declaration_type = NULL;
-				break;
-			}
-
-
-			for (i=0; i < tmp_tags_array->len; i++) {
-				TMTag *cur_tag;
-	
-				cur_tag = (TMTag*)g_ptr_array_index (tmp_tags_array, i);
-				DEBUG_PRINT ("cur_tag scanned to check scoping %d out of %d --> %s", 
-							 i, tmp_tags_array->len, cur_tag->name );
-				if ( strcmp(cur_tag->name, splitted_str[indx]) == 0) {
-					/* ok we found our tag */
-					tmp_tag = cur_tag;
-					break;
-				}
-			}
-			
-			found_end_node = FALSE;
-			if (tmp_tag == NULL)
-				break;
-			
-			switch (tmp_tag->type) {
-				case tm_tag_class_t:
-				case tm_tag_enum_t:
-				case tm_tag_struct_t:
-				case tm_tag_typedef_t:
-				case tm_tag_union_t:
-					/* are we at the end of the splitted_str[] parsing? Or
-				     * have we just found a class/struct/etc but there's something more
-					 * left in the stack? 
-				     */
-					if (splitted_str[indx +1] == NULL) {
-						found_end_node = TRUE;
-						break;
-					}
-					else {
-						continue;	
-					}
-						
-				case tm_tag_namespace_t:
-				default:
-					continue;
-			}
-			
-			if (found_end_node == TRUE) {
-				/* set the local declaration type*/
-				local_declaration_type = tmp_tag;
-				break;
-			}
-		}	
-			
-			
-		g_strfreev (splitted_str);
-		return local_declaration_type;
-	}
-	
-	
-	/* never reached */
-	return local_declaration_type;
-
-}
-
-TMTag* anjuta_symbol_view_get_type_of_expression(AnjutaSymbolView * sv,
-		const gchar* expr, int expr_len, const TMTag *func_scope_tag, gint *access_method)
-{
-	gchar *ident = NULL;
-	*access_method = COMPLETION_ACCESS_NONE;
-	
-	/* very basic stack implementation to keep track of tokens */
-	const int max_items = 30;
-	const gchar* stack[max_items];
-	int num_stack = 0;
-
-	memset (stack, 0, sizeof(stack));
-									
-	/* skip nested brackets */
-	int brackets = 0, square_brackets = 0;
-
-	/* if the current position is within an identifier */
-	gboolean in_ident = FALSE; 
-	
-	/* if we extract the next string which looks like an identifier - only after: . -> and ( */			
-	gboolean extract_ident = FALSE; 
-
-	if (strlen(expr) < 1)
-		return FALSE;
-
-	if (!expr_len)
-		return FALSE;
-
-	g_return_val_if_fail (func_scope_tag != NULL, NULL);
-	
-	/* check the access method */
-	if (*access_method == COMPLETION_ACCESS_NONE) {
-		switch (expr[expr_len-1]) {
-			case '.':
-				*access_method = COMPLETION_ACCESS_DIRECT;
-				DEBUG_PRINT ("access_method = COMPLETION_ACCESS_DIRECT;");
-				break;
-			case '>':
-				if (expr[expr_len-2]	== '-') {
-					*access_method = COMPLETION_ACCESS_POINTER;
-					DEBUG_PRINT ("access_method = COMPLETION_ACCESS_POINTER;");
-				}
-				break;
-			case ':':
-				if (expr[expr_len-2]	== ':') {
-					*access_method = COMPLETION_ACCESS_STATIC;
-					DEBUG_PRINT ("access_method = COMPLETION_ACCESS_STATIC;");
-				}
-				break;				
-			default:
-				*access_method = COMPLETION_ACCESS_NONE;
-		}		
-	}
-
-	const gchar *start = expr + expr_len;
-	while (--start >= expr )
-	{
-		/* skip brackets */
-		if (brackets > 0 || square_brackets > 0)
-		{
-			if (*start == '(')
-				--brackets;
-			else if (*start == ')')
-				++brackets;
-			else if (*start == '[')
-				--square_brackets;
-			else if (*start == ']')
-				++square_brackets;
-			continue;
-		}
-		/* identifier */
-		if (isdigit(*start))
-			in_ident = FALSE;
-		else if (isalpha(*start) || *start == '_')
-		{
-			in_ident = TRUE;
-		}
-		else
-		{
-			switch (*start)
-			{
-				/* skip whitespace */
-				case ' ':
-				case '\t':
-					if (in_ident)
-						goto extract;
-					else
-					{
-						in_ident = FALSE;
-						continue;
-					}
-
-				/* continue searching to the left, if we
-				 * have a . or -> accessor */
-				case '.':
-					if (in_ident && extract_ident)
-					{
-						const gchar *ident = start+1;
-						if (num_stack < max_items) {
-							stack[num_stack++] = ident;
-						}
-						else
-							return FALSE;
-					}
-					in_ident = FALSE;
-					extract_ident = TRUE;
-					continue;
-				case '>': /* pointer access */
-					if ((*start == '>' && (start-1 >= expr && (start-1)[0] == '-')))
-					{
-						if (in_ident && extract_ident)
-						{
-							const gchar *ident = start+1;
-							if (num_stack < max_items) {
-								stack[num_stack++] = ident;
-							}
-							else
-								return FALSE;
-						}
-						in_ident = FALSE;
-						extract_ident = TRUE;
-						--start;
-						continue;
-					}
-					else
-					{
-						start++;
-						goto extract;
-					}				
-				case ':': /* static access */
-					if ((*start == ':' && (start-1 >= expr && (start-1)[0] == ':')))
-					{
-						if (in_ident && extract_ident)
-						{
-							const gchar *ident = start+1;
-							if (num_stack < max_items) {
-								stack[num_stack++] = ident;
-							}
-							else
-								return FALSE;
-						}
-						in_ident = FALSE;
-						extract_ident = TRUE;
-						--start;
-						continue;
-					}
-					else
-					{
-						start++;
-						goto extract;
-					}
-				case '(': /* start of a function */
-					if (extract_ident)
-					{
-						start++;
-						goto extract;
-					}
-					else
-					{
-						extract_ident = TRUE;
-						in_ident = FALSE;
-						break;
-					}
-
-				case ')':
-					if (in_ident) /* probably a cast - (const char*)str */
-					{
-						start++;
-						goto extract;
-					}
-					brackets++;
-					break;
-
-				case ']':
-					if (in_ident)
-					{
-						start++;
-						goto extract;
-					}						
-					square_brackets++;
-					break;
-
-				default:
-					start++;
-					goto extract;
-			}
-		}
-	}
-
-extract:
-	/* ident is the leftmost token, stack[*] the ones to the right
-	 * Example: str.left(2,5).toUpper()
-	 *          ^^^ ^^^^      ^^^^^^^
-	 *        ident stack[1]  stack[0]
-	 */
-
-	ident = sv_scan_for_ident (&start);
-	if (!ident)
-		return FALSE;
-
-	DEBUG_PRINT("ident found: %s", ident);
-
-	TMTag *tag_type = NULL, *old_type = NULL;
-		
-	/* for static access, parsing is done, just return the identifier.
-	 * If this isn't the case we should process something like
-	 * my_class_instance->getValue()->...->lastFunc()->
-	 * and try to get the correct type of lastFunc token, so that we can have 
-	 * a completable list.
-	 */
-	if (*access_method != COMPLETION_ACCESS_STATIC) {
-		gchar *local_declaration_type_str;
-		const TMTag* local_scope_of_ident;
-		TMTag* local_declaration_type = NULL;
-				
-		local_scope_of_ident = func_scope_tag;
-		/* in a context like:
-		 * void foo_func() {
-		 *
-		 *  MyClass *myclass;
-		 *  
-		 *  myclass->
-		 *
-		 * }
-		 *
-		 * calling the following function should return the strings "MyClass".
-		 * FIXME: there would need a better regex which returns also the pointer
-		 * order of myclass, in this case should be "MyClass *", or better 1.
-		 *
-		 */
-		local_declaration_type_str = sv_extract_type_qualifier_from_expr (expr, ident);
-
-		/* check between the scope and parents members if "ident" is present */
-		if (local_declaration_type_str  == NULL) {
-
-			DEBUG_PRINT ("local_declaration_type_string is NULL, checking between its members "
-						 "if it's a class");
-			
-			local_declaration_type = sv_get_type_of_token (ident, local_scope_of_ident->atts.entry.scope,
-											local_scope_of_ident, NULL);
-			if (local_declaration_type) {
-				DEBUG_PRINT ("found local_declaration_type->name %s",local_declaration_type->name);
-			}
-		}
-		else {
-			local_declaration_type = sv_get_local_declaration_type (local_declaration_type_str);
-		}
-	
-				
-		if (local_declaration_type == NULL) {
-			DEBUG_PRINT ("warning: local_declaration_type is NULL");
-		}
-		else {
-			DEBUG_PRINT ("local_declaration_type detected:");
-			tm_tag_print (local_declaration_type, stdout);
-		}
-						
-		if (local_scope_of_ident != NULL && local_declaration_type != NULL ) {
-			DEBUG_PRINT ("found local_scope_of_ident->name  %s and local_declaration_type->name %s", 
-					local_scope_of_ident->name , local_declaration_type->name);
-		}
-
-
-		/* if we have the start of a function/method, don't return the type
-		 * of this function, but class, which it is member of */
-		tag_type = sv_get_type_of_token (ident, NULL, local_scope_of_ident, local_declaration_type);
-		
-		if (tag_type!=NULL)
-			DEBUG_PRINT ("type of token: %s : %s, var_type %s\n", ident, 
-						 tag_type->name, tag_type->atts.entry.type_ref[1]);
-		else
-			DEBUG_PRINT  ("WARNING: tag_type is null. cannot determine ident");
-
-
-		while (tag_type && tag_type->name && num_stack > 0) {
-			ident = sv_scan_for_ident (&stack[--num_stack]);
-			DEBUG_PRINT ("!!scanning for ident %s\n", ident );
-			
-			old_type = tag_type;
-		
-			/* Example: 
-			 * String str;
-			 * str->left(param1)
-			 *
-			 * We already parsed the "str" token. Now it's left() turn.
-			 * If we don't have the local_declaration_type nor the local_scope_of_ident let's find
-			 * the type of the member. Obviously we should also check the parent 
-			 * classes if we don't find it in the old_type->name class.
-			 */
-			
-			if (old_type->atts.entry.type_ref[1] == NULL )
-				tag_type = sv_get_type_of_token (ident, old_type->name, 
-												 local_scope_of_ident, NULL);
-			else
-				tag_type = sv_get_type_of_token (ident, old_type->atts.entry.type_ref[1], 
-												 local_scope_of_ident, NULL);
-
-			if (tag_type != NULL) {
-				DEBUG_PRINT ("tag_type of token: %s : [pointer order] %d\n", 
-							 ident, tag_type->atts.entry.pointerOrder);
-				DEBUG_PRINT ("we have setted a completion of %s", 
-					*access_method == COMPLETION_ACCESS_DIRECT ? "DIRECT ACCESS" : "POINTER ACCESS");
-				tm_tag_print (tag_type, stdout);
-				
-				if (tag_type->atts.entry.pointerOrder >= 1) {
-					/* we shouldn't permit a direct access on tags which are on
-					 * pointerOrder >=1. This means we can't complete with "."
-					 * on MyClass* variables */
-					if (*access_method == COMPLETION_ACCESS_DIRECT) {
-						DEBUG_PRINT ("completion not permitted. Pointer Order is wrong");
-						tag_type = NULL;
-					}
-				}
-				else if (tag_type->atts.entry.pointerOrder == 0) {
-					if (*access_method == COMPLETION_ACCESS_POINTER) {
-						DEBUG_PRINT ("completion not permitted. Pointer Order is wrong");
-						tag_type = NULL;
-					}
-				}
-			}
-		}
-	}
-	else { /* static member */
-		/* just return the ident's tag */
-		const GPtrArray * tags_array = NULL;
-		gint i;
-		
-		DEBUG_PRINT ("Gonna parsing static member section: ident %s", ident );
-		
-		if (ident != NULL) {
-			tags_array = tm_workspace_find (ident, 
-				tm_tag_struct_t | tm_tag_union_t |
-				tm_tag_typedef_t | tm_tag_class_t |
-				tm_tag_macro_t | tm_tag_macro_with_arg_t |
-				tm_tag_namespace_t, NULL, FALSE, TRUE);
-		}
-				
-		if (tags_array == NULL) {
-			DEBUG_PRINT ("tags_array is NULL");
-			return NULL;
-		}
-
-
-
-				
-		/* check if stack has members or not. For an expression like 
-		 * Gnome::Glade::Xml:: we have a stack of
-		 * stack[0] = Xml::
-		 * stack[1] = Glade::Xml::
-		 */
-		
-		//*/ DEBUG REMOVE ME
-		for (i=0; i < num_stack; i++ ) {
-			DEBUG_PRINT ("we have a stack[%d] = %s", i, stack[i]);
-		}
-		//*/
-		
-
-		// probably an useless loop
-		for (i=0; i < tags_array->len; i++) {
-			TMTag *cur_tag;
-
-			cur_tag = (TMTag*)g_ptr_array_index (tags_array, i);
-			DEBUG_PRINT ("cur_tag scanned %d out of %d --> %s", i, tags_array->len, cur_tag->name );
-			if ( strcmp(cur_tag->name, ident) == 0) {
-				/* ok we found our tag */
-				tag_type = cur_tag;
-				break;
-			}
-		}
-
-		
-		/* recursive expression parsing to check its correctness */
-		if (tag_type != NULL && num_stack > 0) {
-			gint indx;
-			
-			for (indx=0; indx < num_stack; indx++) {
-				switch (tag_type->type) {
-					case tm_tag_namespace_t:
-					{
-						const GPtrArray * tags_array = NULL;
-						
-						/* get next ident in stack */
-						gchar * ident_to_check;
-						gchar **new_idents;
-					
-						new_idents = g_strsplit (stack[num_stack - indx -1], ":", 0);
-	
-						ident_to_check = new_idents[0];
-						if (ident_to_check == NULL) {
-							g_strfreev (new_idents);
-							break;
-						}
-					
-						/* is our ident_to_check included into tag_type? 
-						 * Or better, in our example, is Glade included into Gnome:: ?
-						 */
-						tags_array = tm_workspace_find_namespace_members (NULL, 
-																		  tag_type->name, 
-																		  TRUE);
-						if (tags_array == NULL) {
-							g_strfreev (new_idents);
-							break;
-						}
-					
-						gint i;
-						for (i=0; i < tags_array->len; i++) {
-							TMTag *cur_tag;
-	
-							cur_tag = (TMTag*)g_ptr_array_index (tags_array, i);
-							DEBUG_PRINT ("cur_tag scanned to check correctness %d out of %d --> %s", 
-										 i, tags_array->len, cur_tag->name );
-							if ( strcmp(cur_tag->name, ident_to_check) == 0) {
-								/* ok we found our tag */
-								tag_type = cur_tag;
-								break;
-							}
-						}
-					
-					 	g_strfreev (new_idents);
-						break;
-					}
-					default:
-					break;
-				}	
-			}
-		}
-	}
-
-	return tag_type;
-}



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