mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
discard block comments delimited with /* */
This commit is contained in:
@@ -22,6 +22,7 @@ enum WarningID {
|
|||||||
WARNING_EMPTY_ENTRY, /* Empty entry in `db`, `dw` or `dl` */
|
WARNING_EMPTY_ENTRY, /* Empty entry in `db`, `dw` or `dl` */
|
||||||
WARNING_LARGE_CONSTANT, /* Constants too large */
|
WARNING_LARGE_CONSTANT, /* Constants too large */
|
||||||
WARNING_LONG_STR, /* String too long for internal buffers */
|
WARNING_LONG_STR, /* String too long for internal buffers */
|
||||||
|
WARNING_NESTED_COMMENT, /* Comment-start delimeter in a block comment */
|
||||||
WARNING_OBSOLETE, /* Obsolete things */
|
WARNING_OBSOLETE, /* Obsolete things */
|
||||||
WARNING_SHIFT, /* Shifting undefined behavior */
|
WARNING_SHIFT, /* Shifting undefined behavior */
|
||||||
WARNING_SHIFT_AMOUNT, /* Strange shift amount */
|
WARNING_SHIFT_AMOUNT, /* Strange shift amount */
|
||||||
|
|||||||
@@ -921,6 +921,33 @@ void lexer_DumpStringExpansions(void)
|
|||||||
free(stack);
|
free(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Discards an block comment */
|
||||||
|
static void discardBlockComment(void)
|
||||||
|
{
|
||||||
|
dbgPrint("Discarding block comment\n");
|
||||||
|
for (;;) {
|
||||||
|
switch (nextChar()) {
|
||||||
|
case EOF:
|
||||||
|
error("Unterminated block comment\n");
|
||||||
|
return;
|
||||||
|
case '/':
|
||||||
|
if (peek(0) == '*') {
|
||||||
|
warning(WARNING_NESTED_COMMENT,
|
||||||
|
"/* in block comment\n");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
case '*':
|
||||||
|
if (peek(0) == '/') {
|
||||||
|
shiftChars(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* fallthrough */
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Function to discard all of a line's comments */
|
/* Function to discard all of a line's comments */
|
||||||
|
|
||||||
static void discardComment(void)
|
static void discardComment(void)
|
||||||
@@ -1476,8 +1503,6 @@ static int yylex_NORMAL(void)
|
|||||||
return T_OP_ADD;
|
return T_OP_ADD;
|
||||||
case '-':
|
case '-':
|
||||||
return T_OP_SUB;
|
return T_OP_SUB;
|
||||||
case '/':
|
|
||||||
return T_OP_DIV;
|
|
||||||
case '~':
|
case '~':
|
||||||
return T_OP_NOT;
|
return T_OP_NOT;
|
||||||
|
|
||||||
@@ -1498,7 +1523,14 @@ static int yylex_NORMAL(void)
|
|||||||
|
|
||||||
/* Handle ambiguous 1- or 2-char tokens */
|
/* Handle ambiguous 1- or 2-char tokens */
|
||||||
char secondChar;
|
char secondChar;
|
||||||
|
case '/': /* Either division or a block comment */
|
||||||
|
secondChar = peek(0);
|
||||||
|
if (secondChar == '*') {
|
||||||
|
shiftChars(1);
|
||||||
|
discardBlockComment();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return T_OP_DIV;
|
||||||
case '|': /* Either binary or logical OR */
|
case '|': /* Either binary or logical OR */
|
||||||
secondChar = peek(0);
|
secondChar = peek(0);
|
||||||
if (secondChar == '|') {
|
if (secondChar == '|') {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ static enum WarningState const defaultWarnings[NB_WARNINGS] = {
|
|||||||
[WARNING_EMPTY_ENTRY] = WARNING_DISABLED,
|
[WARNING_EMPTY_ENTRY] = WARNING_DISABLED,
|
||||||
[WARNING_LARGE_CONSTANT] = WARNING_DISABLED,
|
[WARNING_LARGE_CONSTANT] = WARNING_DISABLED,
|
||||||
[WARNING_LONG_STR] = WARNING_DISABLED,
|
[WARNING_LONG_STR] = WARNING_DISABLED,
|
||||||
|
[WARNING_NESTED_COMMENT] = WARNING_ENABLED,
|
||||||
[WARNING_OBSOLETE] = WARNING_ENABLED,
|
[WARNING_OBSOLETE] = WARNING_ENABLED,
|
||||||
[WARNING_SHIFT] = WARNING_DISABLED,
|
[WARNING_SHIFT] = WARNING_DISABLED,
|
||||||
[WARNING_SHIFT_AMOUNT] = WARNING_DISABLED,
|
[WARNING_SHIFT_AMOUNT] = WARNING_DISABLED,
|
||||||
@@ -75,6 +76,7 @@ static char const *warningFlags[NB_WARNINGS_ALL] = {
|
|||||||
"empty-entry",
|
"empty-entry",
|
||||||
"large-constant",
|
"large-constant",
|
||||||
"long-string",
|
"long-string",
|
||||||
|
"nested-comment",
|
||||||
"obsolete",
|
"obsolete",
|
||||||
"shift",
|
"shift",
|
||||||
"shift-amount",
|
"shift-amount",
|
||||||
@@ -104,6 +106,7 @@ static uint8_t const _wallCommands[] = {
|
|||||||
/* Warnings that are less likely to indicate an error */
|
/* Warnings that are less likely to indicate an error */
|
||||||
static uint8_t const _wextraCommands[] = {
|
static uint8_t const _wextraCommands[] = {
|
||||||
WARNING_EMPTY_ENTRY,
|
WARNING_EMPTY_ENTRY,
|
||||||
|
WARNING_NESTED_COMMENT,
|
||||||
META_WARNING_DONE
|
META_WARNING_DONE
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -115,6 +118,7 @@ static uint8_t const _weverythingCommands[] = {
|
|||||||
WARNING_EMPTY_ENTRY,
|
WARNING_EMPTY_ENTRY,
|
||||||
WARNING_LARGE_CONSTANT,
|
WARNING_LARGE_CONSTANT,
|
||||||
WARNING_LONG_STR,
|
WARNING_LONG_STR,
|
||||||
|
WARNING_NESTED_COMMENT,
|
||||||
WARNING_OBSOLETE,
|
WARNING_OBSOLETE,
|
||||||
WARNING_SHIFT,
|
WARNING_SHIFT,
|
||||||
WARNING_SHIFT_AMOUNT,
|
WARNING_SHIFT_AMOUNT,
|
||||||
|
|||||||
2
test/asm/block-comment-contents-error.asm
Normal file
2
test/asm/block-comment-contents-error.asm
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/* block comments containing /* throw warnings */
|
||||||
|
PRINTT "reachable\n"
|
||||||
2
test/asm/block-comment-contents-error.err
Normal file
2
test/asm/block-comment-contents-error.err
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
warning: block-comment-contents-error.asm(1): [-Wnested-comment]
|
||||||
|
/* in block comment
|
||||||
1
test/asm/block-comment-contents-error.out
Normal file
1
test/asm/block-comment-contents-error.out
Normal file
@@ -0,0 +1 @@
|
|||||||
|
reachable
|
||||||
1
test/asm/block-comment-termination-error.asm
Normal file
1
test/asm/block-comment-termination-error.asm
Normal file
@@ -0,0 +1 @@
|
|||||||
|
PRINTT /* block comments must terminate before EOF
|
||||||
5
test/asm/block-comment-termination-error.err
Normal file
5
test/asm/block-comment-termination-error.err
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
ERROR: block-comment-termination-error.asm(1):
|
||||||
|
Unterminated block comment
|
||||||
|
ERROR: block-comment-termination-error.asm(1):
|
||||||
|
syntax error
|
||||||
|
error: Assembly aborted (2 errors)!
|
||||||
0
test/asm/block-comment-termination-error.out
Normal file
0
test/asm/block-comment-termination-error.out
Normal file
5
test/asm/block-comment.asm
Normal file
5
test/asm/block-comment.asm
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
PRINTT /* block comments are ignored // ** */ "hi\n"
|
||||||
|
PRINTT "block (/* ... */) comments at ends of line are fine\n" /* hi */
|
||||||
|
PRINTT /* block comments
|
||||||
|
can span multiple lines
|
||||||
|
*/ "mutliline\n"
|
||||||
0
test/asm/block-comment.err
Normal file
0
test/asm/block-comment.err
Normal file
3
test/asm/block-comment.out
Normal file
3
test/asm/block-comment.out
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
hi
|
||||||
|
block (/* ... */) comments at ends of line are fine
|
||||||
|
mutliline
|
||||||
2
test/asm/weird-comments.asm
Normal file
2
test/asm/weird-comments.asm
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
PRINTT /* // PRINTT "this is **comm //ented out\n" */ "this is not commented out\n"
|
||||||
|
PRINTT /*//*/ "this is not commented out\n"
|
||||||
2
test/asm/weird-comments.err
Normal file
2
test/asm/weird-comments.err
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
warning: weird-comments.asm(2): [-Wnested-comment]
|
||||||
|
/* in block comment
|
||||||
2
test/asm/weird-comments.out
Normal file
2
test/asm/weird-comments.out
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
this is not commented out
|
||||||
|
this is not commented out
|
||||||
Reference in New Issue
Block a user