Author Topic: Lexers for Fortran (77)  (Read 16768 times)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Lexers for Fortran (77)
« on: August 17, 2005, 03:26:46 pm »
Dear Code::Blocks-Team,

don't panic - I don't really like Fortran but I am forced to use it in a few of my projects. I've written lexers for Fortran77 which I would be willing to provide (lexer_f77.sample, lexer_f77.xml). I wonder if:
1.) You'd be interested in this at all?
2.) Where/how I should upload these files?

I am planning furthermore a compiler plugin for G77 which would allow Code::Blocks full Fortran development. This should (normally) be easy to to -> just use the GCC plugin and replace GCC with G77...?!

With regards,

Morten.

Ps: Keep up the good work!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Lexers for Fortran (77)
« Reply #1 on: August 17, 2005, 04:50:32 pm »
Don't think that is necessary. If you have gcc installed with Fortran, then gcc should actually compile your Fortran files right away, as gcc is only a compiler frontend (gcc calls g++ or g77 or whatever it needs to compile a certain file).

But replacing gcc with g77 should be fine, too. g77 is to support all of gcc's standard options and parameters, so it should just work.

Something that may be interesting, though, may be a compiler plugin that also offers Fortran-specific options :)

EDIT:
I have never used Fortran, nor do I have it installed here, but try this:



I would not be surprised at all if gcc just compiles after that. If so, all that needs to be done in code::blocks to support Fortran is include your syntax schema and make code::blocks treat .F files as source.
« Last Edit: August 17, 2005, 05:09:43 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Lexers for Fortran (77)
« Reply #2 on: August 17, 2005, 05:40:46 pm »
OK, first of all:

1) Does it work on your machine? Have you tested it?

2) Submit a patch at sourceforge (the links are on the left).

3) We'll tell you when we get it implemented.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Lexers for Fortran (77)
« Reply #3 on: August 18, 2005, 09:05:00 am »
Dear rickg22,

Concerning the lexer files:
> 1) Does it work on your machine? Have you tested it?
Yes, it works and yes, I've tested it thoroughly.
> 2) Submit a patch at sourceforge (the links are on the left).
I've done this by now.
> 3) We'll tell you when we get it implemented.
Ok. I stay tuned - there is no hurry.

Concerning hint with CPP environment variable (...) from above:
This rocks! It was indeed possible using this trick to compile the fortran files. However, there are still open "issues":
1.) One is required to install the F77 package from MinGW. GCC only does not work (missing the f2c library).
2.) Linking fails with:
D:\Devel\CodeBlocks\lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
This is true if linking without the "-lg2c" switch. However - even if I add this switch under "Other linker options" it still does not link. I am working on this - If I find a reason I'll tell. I believe that I am only missing a bit here. Is there a way to see the full compile/link command issued by Code::Blocks IDE?

With regards

Morten.

Ps.: I cannot stop to repeat: Code::Blocks rocks!!!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: Lexers for Fortran (77)
« Reply #4 on: August 18, 2005, 12:54:14 pm »
Concerning hint with CPP environment variable (...) from above:
This rocks! It was indeed possible using this trick to compile the fortran files. However, there are still open "issues":
1.) One is required to install the F77 package from MinGW. GCC only does not work (missing the f2c library).
Well, you can hardly expect Code::Blocks or MinGW.org to bundle support for every obscure language (no offence) into the default install. Most people don't need Fortran, those that do need it just have to install support for it separately.

Quote
2.) Linking fails with:
D:\Devel\CodeBlocks\lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
This is true if linking without the "-lg2c" switch. However - even if I add this switch under "Other linker options" it still does not link. I am working on this - If I find a reason I'll tell. I believe that I am only missing a bit here.
It looks like the linker thinks you want to compile a Windows GUI program, but your object files disagree and want to be a console program. Is your target set to "Console program" in your project properties?

Quote
Is there a way to see the full compile/link command issued by Code::Blocks IDE?
Settings -> Compiler -> tab "Other" -> Compiler Logging -> Full command line :)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Lexers for Fortran (77)
« Reply #5 on: August 18, 2005, 04:23:39 pm »
Well, you can hardly expect Code::Blocks or MinGW.org to bundle support for every obscure language (no offence) into the default install. Most people don't need Fortran, those that do need it just have to install support for it separately.
Sure - the last thing I am expecting from a professional IDE is Fortran support. I would never use Fortran if I didn't have to. I just said that as an addition to thomas' message. The only thing I am trying to is to enable the G77 compiler since it is based on GCC which is fully supported by Code::Blocks.

Quote
It looks like the linker thinks you want to compile a Windows GUI program, but your object files disagree and want to be a console program. Is your target set to "Console program" in your project properties?
Yes, it is set to a console program.

Quote
Settings -> Compiler -> tab "Other" -> Compiler Logging -> Full command line :)
Great! Thanks to this I was able to reproduce what is happening. One has to use the way as described by thomas (above) but use not CPP but CC instead for the compiler variable. After that the Fortran programs at least compile (using gcc). Unfortunately for linking "mingw32-g++.exe" is used (Why?) instead of g77 which should be. And that's it finally. If I copy/paste the linker command and replace "mingw32-g++.exe" with "g77.exe" (interestingly even without -lg2c switch) the linking is done correctly. But I don't know how to setup this in Code::Blocks. Any hints?

Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Lexers for Fortran (77)
« Reply #6 on: August 18, 2005, 05:31:58 pm »
In the Compiler Settings, programs, you can choose which program you're using for linking for your fortran compiler.

A warning tho: Be sure that the extra linker options _DO NOT_ have the "-w," (or was it "-m," ? ) argument, since that's what gcc uses to pass commands to the linker.

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Lexers for Fortran (77)
« Reply #7 on: August 18, 2005, 06:13:52 pm »
...Be sure that the extra linker options _DO NOT_ have the "-w," (or was it "-m," ? ) argument...

it is "-Wl,"

if you want to use the linker option "--export-all-symbols", you write
Code
-Wl,--export-all-symbols
in "Other linker options" when using normal gcc c++ compiler.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Lexers for Fortran (77)
« Reply #8 on: August 19, 2005, 01:15:23 pm »
In the Compiler Settings, programs, you can choose which program you're using for linking for your fortran compiler.
That was it! I made a copy of the GCC-Compiler and replaced the required programs with g77.exe. Sor far so (very!) good. There is only a minor drawback: It seems as if CodeBlocks can only handle C and C++ extensions, right? Or can I add somewhere additional extension for CodeBlocks to detect fortran files as sourcecode? Why I'm saying this:
One has to enable "Compile file" and "Link file" for each Fortran file seperately. Unfortunately after re-opening the project this setting has gone. I tracked back the reason to cbproject.cpp (in sdk) where it states:
  FileType ft = FileTypeOf(filename);
  localCompile = compile && (ft == ftSource || ft == ftResource);
  localLink = link && (ft == ftSource || ft == ftResource || ft == ftObject || ft == ftResourceBin || ft == ftStaticLib);
Since the extension does not match ftSource of ftResource the flag is being reset silently.

However... I wouldn't wonder if this can be setup as well somewhere...?! Because this is the last thing missing for full Fortran support.

Morten.

Ps.: By the way: In fact even if I hate Fortran but it is still widely used in engineering environments. So supporting Fortran makes the IDE attractive even for such places.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Lexers for Fortran (77)
« Reply #9 on: August 19, 2005, 01:35:02 pm »
This is hardcoded (unluckily).

You can:
1. go to the file src/sdk/settings.h, lines 100-117, and add
Code
#define FORT_EXT		"F"

2.change src/sdk/globals.h, lines 125-130

from
Code
else if (ext.Matches(CPP_EXT) ||
ext.Matches(C_EXT) ||
ext.Matches(CC_EXT) ||
ext.Matches(CXX_EXT)
)
return ftSource;
to
Code
else if (ext.Matches(CPP_EXT) ||
ext.Matches(C_EXT) ||
ext.Matches(CC_EXT) ||
ext.Matches(CXX_EXT) || ext.Matches(FORT_EXT)
)
return ftSource;


Rebuild code::blocks, and see it it works (it should, hopefully).

If it works, please make a patch upload it to sourceforge.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Lexers for Fortran (77)
« Reply #10 on: August 20, 2005, 10:23:40 am »
This is hardcoded (unluckily). [...]
please make a patch upload it to sourceforge.
Thanks for the hint. I'll give it a try and I'm quite sure it works. However - submitting a patch might not be a good idea. I believe this is clearely something to be generally thought of. I mean: Setting up (new) compilers is greatly modularised ind Code::Blocks. So should be for the file-extension. Another example: Some of my collegures using the ".c++" and ".h++" extension for their files so they are lost similary even if it's clearly a C++ domain. Why not making extension be generally freely defined? Maybe one could use the lexers (there are the extension provided anyway) to build ftSource and ftHeader...?!

I am going to post this a s a feature request for further discussion (with main developers of course).

How about that?!

Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

terje_a

  • Guest
Re: Lexers for Fortran (77)
« Reply #11 on: September 29, 2005, 06:37:08 am »
... after several hours of building, rebuilding, then rebuilding again the 2.6.2 wxWidget libraries, then eventually successfully building C::B from a CVS download I fetched the middle of last week...   

... alas, a development version of C::B complete with Fortran lexers... 

Very nicely done!!!

(I am not sure if I'll be able to duplicate again after my next CVS download, but hey, I'm willing to give it a try)

Now, there are a few more things I would like to see happen - for instance - the file properties should have sticky check boxes for compile and link...  Currently need to reselect them every time I reload the project...  not too much of a problem with one or two source files, but a major issue with more than that.  The other is probably an item to add to the enhancement request list - the ability to select multiple files in a project folder and modify properties for all selected files.  Use 3-state checkbox with gray to indicate setting not consistent across all selected files (similar to VC++ and possibly other IDEs)

Being a highly inexperienced C++ programmer - I am not sure what success I would have delving into to code to make the change - but then again, what were nights and weekends made for if not for playing software engineer...

[I plan to provide feedback for Fortran as well as mixed C/C++ and Fortran code as time goes on].

I am using the compilers from MinGW + MSYS and Cygwin for my unix shell on the Windows desktop...  Most of the Fortran code I will be working with is legacy IBM 360 mainframe and HP/SGI unix code.

C::B is very slick!

Keep up the great work!

terje