ilikecats567 / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

mismatched line numbers: compiler vs tabbed IDE #907

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compiling code that uses more than one tab in the IDE
2.
3.

What is the expected output? What do you see instead?
Compiler errors report a line number, but each tab has its own line number 
system starting at zero, so unless the error is on the primary tab, it will not 
match the line number shown in the lower left corner of the IDE.

What version of the Arduino software are you using? On what operating
system?  Which Arduino board are you using?
Arduino 1.0/ RBBB 328 from Modern Devices

Please provide any additional information below.
I really don't get why the Arduino IDE doesn't have the option of displaying 
line numbers; It's not like I want to go back to the days of BASIC GOTO 
commands, it's just that when the compiler spits out error messages for a 
particular line number in code, it's nice to be able to find that line in your 
code. If you use a single tab in the IDE for all of your code, the line number 
shows up in the lower left corner of the IDE for the line your cursor is on, 
but if you use multiple tabs to make large programs easier to work with, the 
line numbering starts over again at zero for each tab that you're working on.

I'm resuming work on a program that I started last Summer that has over 1,000 
lines of code and is broken up into 8 tabs to make it easier to work with. Upon 
compiling, I get the following error messages:

Mashtech.cpp:586:14: error: expected initializer before ‘/’ token
Mashtech.cpp:702:16: error: expected initializer before ‘%’ token

I can track down the "%" character just because they are uncommon, but the "/" 
characters are everywhere because of commenting and division operations.

Are there any suggestions on how to track down where the lines are that are 
causing compiler errors? Do I have to go back to using one tab with all of the 
code lobbed together? It sure is nice to have multiple tabs to organize the 
code, but if it makes tracking down compiler errors difficult, then it's not 
worth it.

Brett 

Original issue reported on code.google.com by bre...@teleport.com on 6 May 2012 at 5:14

GoogleCodeExporter commented 9 years ago
Here is a patch which fixes this issue, and also issue 281, and many other 
unreported problems where Arduino fails to report the correct line number, file 
and/or highlight the error in the editor!

Original comment by paul.sto...@gmail.com on 6 May 2012 at 7:26

Attachments:

GoogleCodeExporter commented 9 years ago
Here's some explanation about what my patch does....

First, #line directives are added to the preprocessed sketch.  These let the 
compiler report the correct file and accurate line number, regardless of how 
many tabs are open.

When errors are reported, the complex code which tried to match up offsets is 
replaced by a very simple search to match the file with its tab in the editor.  
Because the compiler gives dependable results, pde, ino, cpp, h, and c files 
are all handled the same way.

A flag is added, to distinguish between compiling the user sketch versus 
lirbaries and the core.  The attempt to select the errorenous line (and correct 
tab) in the editor is skipped if the file is not part of the user's sketch.  
This avoids a bug where errors are reported incorrectly if the user's sketch 
contains a .cpp file which has the same filename as any file in any library.

An off-by-one error is fixed in code which attempts to show the error using 
only the "pretty name" (without trailing .ino or .pde).  The editor's 
zero-based index is now properly put back to the one-based line number 
counting, so the error reported in the console has a line number which matches 
the line automatically selected in the editor.

The "pretty name" reporting is now applied to both .ino and .pde extensions.

This patch does NOT remove lots of code which tracked various offsets created 
during preprocessing.  It also does not alter the API between the Compiler and 
Sketch objects, which no longer needs to be able to modify what information the 
error will print.  I tried to keep the scope of changes limited to only fixing 
the bugs which prevent proper error messages and properly selecting the 
offending line in the editor.

Original comment by paul.sto...@gmail.com on 6 May 2012 at 10:30

GoogleCodeExporter commented 9 years ago
Also, because any .cpp, .c and .h files in the user's sketch are handled the 
same way, if there is a compile error in any of those files, it will be 
correctly selected, just like the .ino files are.

Original comment by paul.sto...@gmail.com on 6 May 2012 at 10:32

GoogleCodeExporter commented 9 years ago
This patch works beautifully!  This will make debugging much easier.  ADMINS, 
please add this patch to the next Arduino release!

Thanks for your work, Paul!

Brett

Original comment by bre...@teleport.com on 6 May 2012 at 11:26

GoogleCodeExporter commented 9 years ago
Looks good (although I didn't examine it in detail).  This may be too late for 
1.0.1 but I'll definitely get it in for the next version.

Original comment by dmel...@gmail.com on 7 May 2012 at 3:56

GoogleCodeExporter commented 9 years ago
Yeah, if you're building the final 1.0.1 now, it definitely makes sense to wait 
for 1.0.2.

But next time you have Arduino open and there's any error, please glance at the 
line number on error message in the console and the editor's line number (in 
the blue region between the code editor and console).  They don't match.  We've 
all grown very accustomed to Arduino's many bugs.

The more serious bugs, which make Arduino difficult to use, are only 
encountered with a multi-tab sketch.  Most people use only a single tab.

Original comment by paul.sto...@gmail.com on 7 May 2012 at 6:08

GoogleCodeExporter commented 9 years ago
https://github.com/arduino/Arduino/commit/77ed2f4d62d51ca9d79f3353936e9d359d886c
cb

Thanks!

Original comment by dmel...@gmail.com on 27 May 2012 at 4:34

GoogleCodeExporter commented 9 years ago
I'm also having the problem that the IDE editor is not stopping at the correct 
line number when errors are flagged. How do I obtain this patch, and what is 
the procedure for applying it?

Thanks,

Original comment by craighal...@gmail.com on 13 Aug 2012 at 12:07

GoogleCodeExporter commented 9 years ago
The easy answer is just wait for 1.0.2.

But you can get the latest source code and compile it.  You'll need the Java 
JDK, Ant, and if using Windows, lots of cygwin stuff.  Instructions are here:

http://code.google.com/p/arduino/wiki/BuildingArduino

Original comment by paul.sto...@gmail.com on 13 Aug 2012 at 4:03

GoogleCodeExporter commented 9 years ago
I'm very sorry, there was a bug in my patch, where it didn't properly handle 
comments and white space that offsets the insertion point.

This tiny patch fixes the problem.

Original comment by paul.sto...@gmail.com on 28 Sep 2012 at 12:26

Attachments: