-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Honor new-script markers in the preprocessor #2615
Honor new-script markers in the preprocessor #2615
Conversation
Compiler/preproc/preprocessor.cpp
Outdated
@@ -13,6 +13,7 @@ | |||
//============================================================================= | |||
#include <algorithm> | |||
#include <cctype> | |||
#include <string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a wrong header for "strlen", should be <string.h> instead.
Alternatively, there's std::strlen
in header <cstring>
.
Compiler/preproc/preprocessor.cpp
Outdated
@@ -245,7 +245,9 @@ namespace Preprocessor { | |||
size_t endOfString = FindIndexOfMatchingCharacter(text, i, text[i]); | |||
if (endOfString == NOT_FOUND) //size_t is unsigned but it's alright | |||
{ | |||
LogError(ErrorCode::UnterminatedString, "Unterminated string"); | |||
std::string msg = "Unterminated string: <char> is missing"; | |||
msg = msg.replace(msg.find("<char>"), 6, std::string(1, text[i])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting may be done using our String class, see String::Format or String::FromFormat.
like
String msg = String::FromFormat("Unterminated string: '%c' is missing", text[i]);
LogError(ErrorCode::UnterminatedString, msg);
In regards to the C++ preprocessor, the changes seem to fix the reporting of unterminated string, but neither the correct line counter, nor the section name are included into the reported error. The _lineNumber and _scriptName that you set in code are simply not propagated further into LogError. Instead it uses
After this is done in ags4 branch, the changes need to be backported to ags3 too. In any case, following are the tests which I propose to add to preprocessor tests.
|
To summarize, the quick fix for the C++ preprocessor would be to assign 2 global variables called
In the long run it would be better to refactor the code and get rid of global variables which contain error reporting details etc. Just like the new compiler does now. |
Updating the PR:
|
Compiler/preproc/preprocessor.h
Outdated
// TODO: Do away with '_scriptOfError' when 'Preprocessor' | ||
// is refactored so that it doesn't use 'cc_error()' for | ||
// error reporting | ||
static String _scriptOfError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to mention previously, but I pushed a fix to the ags4 branch, and you do not need a static buffer for the script name anymore:
3facb6a
This may be removed if you rebase on top of the ags4 branch.
Compiler/test/preprocessor_test.cpp
Outdated
@@ -25,7 +25,7 @@ namespace Preprocessor { | |||
std::vector<AGSString> SplitLines(const AGSString& str) | |||
{ | |||
std::vector<AGSString> str_lines = str.Split('\n'); | |||
for (int i = 0; i < str_lines.size(); i++) { | |||
for (int i = 0; i < (int) str_lines.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix this other way around, make "i" variable be of size_t
type instead.
Also, when the preprocessor finds unterminated strings, it tells what character is missing (quote or double-quote sign)
Also, when the preprocessor finds unterminated strings, it tells what character is missing (quote or double-quote sign)
- Include 'string.h' instead of 'string' - Delete external 'currentline' declaration, is already in 'cc_common'' - Introduce static buffer for script name for use in 'cc_error()' - Set 'currentline' and 'ccCurScriptName' before 'cc_error()' is called, and _only_ there - Use 'String::FromFormat()' for formatting the error messages Googletests: - Add external reference to 'ccCurScriptName' - Add googletests for multiple scripts in one file; unterminated strings - Add conversion to shut up 'signed/unsigned' warning
Also, remove '(int)' cast in favour of 'size_t' loop var
3eff26a
to
3f82698
Compare
Done. (Had to force-push due to the rebase) |
As a first attempt to mitigate #2609
The preprocessor tracks double-quoted strings that begin in the first column and start with
__NEWSCRIPTSTART_
. Whenever it detects such a string, it resets the line numbering and begins a new script. The new script name is whatever follows the new-script marker.In consequence, preprocessor errors in dialogs will be reported to the Editor in such a way that you can double-click the error message to get to the dialog that has the error.
Moreover, when the preprocessor encounters an unterminated string, it will state the missing character:
'
or"
.NOTE: AGS has two preprocessor files:
Preprocessor.cs
in the Editor project andpreprocessor.cpp
in the "classic" compiler project. I've tried to modify both in tandem, but the modifications in the "classic" compiler project are untested – mainly because I don't know how to set up appropriate tests for that compiler and preprocessor.