Compiler error and warning functions in compiler.c. In case of a compiler err...

Stephen Smith Answered 5 answers
Question by Stephen Smith 2 years ago

Question

Compiler error and warning functions in compiler.c.

In case of a compiler error, these should display messages containing the error message and the line, column and file where it was detected. These are values in compiler->pos.line, compiler->pos.col and compiler->pos.file.
While I can find the code where line and col are set, there doesn't seem to be any statement in the whole (completed) program where compiler->pos.file is set. This is confirmed by all specifically provoked compiler errors returning only a NULL string for the filename.. pos.file is set in the parser but does not make it into the compiler struct. Can you help here?

Regards
Steve Smith

Answers

Answered by Daniel McCarthy

Instructor

Hi Stephen,
When you think something is missing its best to first check the master repository as things do get added later throughout the course. Here is where it is set: https://github.com/nibblebits/PeachCompiler/blob/9348c6ee8fab335915468ddea583137b7019df9c/cprocess.c#L86

Thanks
Dan

Follow-up by Stephen Smith

Question author

Hi!
I checked the REPO you indicated.

The indicated line no. 86 in cprocess.c shows compiler->pos.col being set. Later, line nos. 90 and 91 show compiler->pos.col and compiler->pos.line being set/manipulated. This is OK, but there's no reference to compiler->pos.file being set. My problem is only getting a NULL string pointer in the (provoked) error messages, although line and col values are OK. This seems to indicate a missing operation.

Regards

Steve.

Answered by Daniel McCarthy

Instructor

Hey Stephen,
Yes I see what you mean its odd, can you please file an issue report on the Github repository so I can take a look further into this to ensure if its an actual bug or something I cant account for this moment in time, we can continue the thread on there when I have more information, I will take a good look this week for you

Thanks
Dan

Follow-up by Stephen Smith

Question author

Hallo Dan!

I must apologize for taking up your time. I found the error and it is absolutely my fault only!
I am running the compiler under Windows, using C++Builder to compile it and NASM to process the assembler files it generates. Builder is a GUI I'm very familiar with as opposed to VS Code.
Under windows,certain changes are needed in the code. There is no "realpath" function, I substituted the equicalent windows function "_fullpath" but I was calling it incorrectly, reversing the order of "filename" and "path" both char* values. So while id didn't complain, it didn't work. This was why I was missing "filename" output.
As soon as I corrected this, everything worked!
Thanks for looking!
By the way, I'm now also running Ubuntu in WSL to compile the original files with complete success.
Regards
Steve

Answered by Daniel McCarthy

Instructor

Ahh perfect and no apology needed when in doubt ask away im here to help you with any issues you face on the course. All the best
Dan