Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Equivalent to C's #line directive?

Reply
Thread Tools

Equivalent to C's #line directive?

 
 
M. Uli Kusterer
Guest
Posts: n/a
 
      09-20-2004
Hi,

I'm writing a program that generates Java code from source code written
in another language. Now, when an error occurs, I'd like to have Java
report the file name and line number in the source file the user wrote.

C has a #line directive for that. Does Java have something similar?

In case I'm not clear, an example:

UserCode.p:

1: PROCEDURE Main
2: begin
4: logFilePathsStartingAt( "/dev" );
5: end


GeneratedCode.java

1: public static class UserCode
2: {
3: public static void main( String[] argv )
4: {
5: CreateLogWindow();
6:
7: PUtilityCode.LogFilePathsStartingAt( "/dev" );
8: }
9: }


Now, when an error occurs in line 7 of GeneratedCode.java, I would like
Java to tell the user "there was an error on line 4 in UserCode.p".
C has a "#line" preprocessor directive which I could write on line 6 as:

6: #line 4

and from then on any errors would be reported to be in line 4.

Thanks for any clues,
-- Uli
http://www.zathras.de
 
Reply With Quote
 
 
 
 
Daniel Bonniot
Guest
Posts: n/a
 
      09-20-2004
> I'm writing a program that generates Java code from source code written
> in another language. Now, when an error occurs, I'd like to have Java
> report the file name and line number in the source file the user wrote.
>
> C has a #line directive for that. Does Java have something similar?


Yes, this is covered by jsr 45. See
http://jcp.org/aboutJava/communitypr...045/index.html

From memory, you can generate an auxiliary file with the mappings between the
line numbers in your source language and the Java source.

Cheers,

Daniel
--
The Nice programming language: http://nice.sf.net
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      09-20-2004
M. Uli Kusterer wrote:
> I'm writing a program that generates Java code from source code written
> in another language. Now, when an error occurs, I'd like to have Java
> report the file name and line number in the source file the user wrote.
>
> C has a #line directive for that. Does Java have something similar?


There is no such thing in the Java language. It would be more typical
to translate your other language directly to bytecode (since bytecode is
perfectly portable), in which case you can include debug information for
whatever line numbering scheme you desire (and JSR 45 may help).

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
M. Uli Kusterer
Guest
Posts: n/a
 
      09-20-2004
In article <cimo2h$ltj$(E-Mail Removed)>,
Daniel Bonniot <(E-Mail Removed)> wrote:

> Yes, this is covered by jsr 45. See
> http://jcp.org/aboutJava/communitypr...045/index.html
>
> From memory, you can generate an auxiliary file with the mappings between
> the
> line numbers in your source language and the Java source.


Thanks.

I'm not sure I grok these docs, but I've DLed them and I'll look at the
stuff. Thanks.

Cheers,
-- Uli
http://www.zathras.de
 
Reply With Quote
 
M. Uli Kusterer
Guest
Posts: n/a
 
      09-20-2004
In article <(E-Mail Removed)>,
Chris Smith <(E-Mail Removed)> wrote:

> > C has a #line directive for that. Does Java have something similar?

>
> There is no such thing in the Java language. It would be more typical
> to translate your other language directly to bytecode (since bytecode is
> perfectly portable), in which case you can include debug information for
> whatever line numbering scheme you desire (and JSR 45 may help).


Well, I'd love to translate to bytecode directly, but I doubt I could
pull that off. At least not without a "Java Bytecode for dummies" guide.


JSR 45 only works for byte code, does it? The docs look way too complex
and weird to be for Java source code. I guess I'll chicken out for now
and just leave out the line numbers and implement the parser that
compiles to Java source, and then I can always swap out the code
generator object and generate something else.

Thanks for the pointer,
-- Uli
http://www.zathras.de
 
Reply With Quote
 
Daniel Bonniot
Guest
Posts: n/a
 
      09-21-2004
> JSR 45 only works for byte code, does it?

No, I definitely remember there are two ways to feed the numbers, one when you
generate bytecode (SourceDebugExtension), one when you generate source Java code.

Daniel
--
The Nice programming language: http://nice.sf.net
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning:Xst:382 - Register A is equivalent to B mag VHDL 1 05-19-2005 05:10 PM
instancename of current entity/architecture -- equivalent to C++ this??? Eric Peers VHDL 2 11-18-2004 05:23 PM
VHDL equivalent of verilog trireg Sanjeev VHDL 4 07-23-2004 09:55 AM
equivalent types in different packages Lolo VHDL 3 09-22-2003 03:23 PM
Re: Image Scanning - TWAIN equivalent Brendan Duffy ASP .Net 0 07-24-2003 08:29 AM



Advertisments