Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [cdt-dev] Debugging Text Hover in CDT.

 
Hi,

Problem  : 
----------
	Hovering on 'array_index', 'structure_var.fieldname' and
'structure_var -> fieldname' doesn't give the correct value.

Analysis :
---------
	I analysed the code in 'CWordFinder.java' (findWord() method),
which passes the offset and length to 'DebugTextHover.java'. The
document is parsed to get the word boundaries i.e. offset. Parsing stops
when a non Java identifier is found (Character.isJavaIdentifierPart at
line no. 65), which are not the actual delimiters in case of C/C++.

This breaks the field or an array index leading to an incorrect variable
name.

Solution :
----------
Following are the code changes required which gives the correct text
hover value.

  i) For 'structure_variable.fieldname' (To continue if "." is
encountered, i.e. displaying the structure field)
	
	if (character is not JavaIdentifier AND character is not '.')
					break;

 ii) For 'structure_variable->fieldname' (To continue if "->" is
encountered, i.e. pointers to structures)
	if (character is '>' and previous_character is '-') get
next_offset
	

iii) For 'array_name[index]' (To continue if its an array index)
	if(character or previous_character is ']' ) 
		do
			get next_offset
			get character at offset

		while character != ']'
 	

This is just the code fix for the above listed problems, I am not sure
if there would be any repercussions. 

If you think this is a correct fix, I have attached the patch. Please
apply the patch.

Regards,
Anita Birje

	
-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx]
On Behalf Of Mikhail Khodjaiants
Sent: Friday, November 11, 2005 1:37 AM
To: CDT General developers list.
Subject: Re: [cdt-dev] Debugging Text Hover in CDT.

This is a known issue. See
https://bugs.eclipse.org/bugs/show_bug.cgi?id=40101.
The expression selected in the editor has to be parsed to avoid
expressions like "++i". Currently we don't use parser for filtering.

----- Original Message -----
From: "Birje, Anita (STSD)" <anita.birje@xxxxxx>
To: <cdt-dev@xxxxxxxxxxx>
Sent: Thursday, November 10, 2005 9:37 AM
Subject: [cdt-dev] Debugging Text Hover in CDT.


> Hi,
>
> I am trying to investigate how hover works in CDT debug mode.
>
> When I hover over struct variable it gives field details as follows
> currentdate = {day = 10, month = 11, year = 2005}
>
> Whereas hovering over the struct fields, doesn't display its value.
> Message displayed at console is : 'No symbol "day" in current
> context'.
>
> I went through the CDT code, the "DebugTextHover.java" takes only the
> "fieldname" and not the "structure_variable.fieldname" to get the
value.
> (offset and length passed might be incorrect)
> For Eg: Line No. 64 -> String expression = document.get(
> hoverRegion.getOffset(), hoverRegion.getLength() );
> This returns "day" instead it should have been "currentdate.day".
>
> Is this an expected behaviour,a known issue or an unknown bug. Please
> help!
>
> Thanks & Regards,
> Anita Birje
>
> P.S. The program used for testing this functionality:
>
>
//**********************************************************************
> *****************
> struct date
> {
> int day;
> int month;
> int year;
> };
>
> #include <stdio.h>
> int main()
> {
> struct date currentdate = {10,11,2005};
>
> cout<<"\n\nPrinting day : "<<currentdate.day<<endl
> <<"Printing month : "<<currentdate.month<<endl
> <<"Printing year : "<<currentdate.year<<endl<<endl;
>
> return 0;
> }
>
//**********************************************************************
> ******************
>
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev 

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev
Index: CWordFinder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CWordFinder.java,v
retrieving revision 1.6
diff -u -r1.6 CWordFinder.java
--- CWordFinder.java	23 Jun 2005 16:01:24 -0000	1.6
+++ CWordFinder.java	14 Nov 2005 11:13:50 -0000
@@ -43,13 +43,26 @@
 		int start = -1;
 		int end = -1;
 
-		try {
+		try { 
 			int pos = offset;
-			char c;
-
+			char c, pc, nc;
+			
 			while (pos >= 0) {
 				c = document.getChar(pos);
-				if (!Character.isJavaIdentifierPart(c))
+				pc = document.getChar(pos-1);
+				if(c == '>' && pc == '-'){
+					--pos;
+				}
+				else if(c==']' || pc == ']'){
+					do{
+						--pos;
+						c=document.getChar(pos);
+						
+					}while(c!='[');
+				}
+				
+				else
+				if (!Character.isJavaIdentifierPart(c) && c!='.')
 					break;
 				--pos;
 			}
@@ -60,12 +73,14 @@
 			int length = document.getLength();
 
 			while (pos < length) {
+				
 				c = document.getChar(pos);
-				if (!Character.isJavaIdentifierPart(c))
+				
+				if (!Character.isJavaIdentifierPart(c) )
 					break;
 				++pos;
 			}
-
+			
 			end = pos;
 
 		} catch (BadLocationException x) {

Back to the top