Added assembly header detection.

This commit is contained in:
Johanne Schock 2020-03-14 14:36:47 +01:00 committed by patacongo
parent 23db3b2a48
commit cdf615855a

View File

@ -116,6 +116,10 @@ enum pptype_e
{
PPLINE_NONE = 0,
PPLINE_DEFINE,
PPLINE_IF,
PPLINE_ELIF,
PPLINE_ELSE,
PPLINE_ENDIF,
PPLINE_OTHER
};
@ -526,6 +530,8 @@ int main(int argc, char **argv, char **envp)
int dnest; /* Data declaration nesting level on this line */
int prevdnest; /* Data declaration nesting level on the previous line */
int pnest; /* Parenthesis nesting level on this line */
int ppifnest; /* #if nesting level on this line */
int inasm; /* > 0: Within #ifdef __ASSEMBLY__ */
int comment_lineno; /* Line on which the last comment was closed */
int blank_lineno; /* Line number of the last blank line */
int noblank_lineno; /* A blank line is not needed after this line */
@ -643,6 +649,8 @@ int main(int argc, char **argv, char **envp)
bnest = 0; /* Brace nesting level on this line */
dnest = 0; /* Data declaration nesting level on this line */
pnest = 0; /* Parenthesis nesting level on this line */
ppifnest = 0; /* #if nesting level on this line */
inasm = 0; /* > 0: Within #ifdef __ASSEMBLY__ */
comment_lineno = -1; /* Line on which the last comment was closed */
blank_lineno = -1; /* Line number of the last blank line */
noblank_lineno = -1; /* A blank line is not needed after this line */
@ -851,14 +859,15 @@ int main(int argc, char **argv, char **envp)
* line.
*/
ii = indent + 1;
if (ppline == PPLINE_NONE)
{
/* Skip to the pre-processor command following the '#' */
for (ii = indent + 1;
line[ii] != '\0' && isspace(line[ii]);
ii++)
while (line[ii] != '\0' && isspace(line[ii]))
{
ii++;
}
if (line[ii] != '\0')
@ -915,6 +924,81 @@ int main(int argc, char **argv, char **envp)
lineno, ii);
}
}
else if (strncmp(&line[ii], "if", 2) == 0)
{
ppifnest++;
ppline = PPLINE_IF;
ii += 2;
}
else if (strncmp(&line[ii], "elif", 4) == 0)
{
if (ppifnest == inasm)
{
inasm = 0;
}
ppline = PPLINE_ELIF;
ii += 4;
}
else if (strncmp(&line[ii], "else", 4) == 0)
{
if (ppifnest == inasm)
{
inasm = 0;
}
ppline = PPLINE_ELSE;
}
else if (strncmp(&line[ii], "endif", 4) == 0)
{
if (ppifnest == inasm)
{
inasm = 0;
}
ppifnest--;
ppline = PPLINE_ENDIF;
}
}
}
if (ppline == PPLINE_IF || ppline == PPLINE_ELIF)
{
int bdef = 0;
if (strncmp(&line[ii], "def", 3) == 0)
{
bdef = 1;
ii += 3;
}
else
{
while (line[ii] != '\0' && isspace(line[ii]))
{
ii++;
}
if (strncmp(&line[ii], "defined", 7) == 0)
{
bdef = 1;
ii += 7;
}
}
if (bdef)
{
while (line[ii] != '\0' &&
(isspace(line[ii]) || line[ii] == '('))
{
ii++;
}
if (strncmp(&line[ii], "__ASSEMBLY__", 12) == 0)
{
inasm = ppifnest;
}
}
}
@ -968,10 +1052,12 @@ int main(int argc, char **argv, char **envp)
rhcomment = -1;
if (ncomment > 0 && (strncmp(&line[ii], "if", 2) == 0 ||
strncmp(&line[ii], "el", 2) == 0))
if (ncomment > 0 &&
(ppline == PPLINE_IF ||
ppline == PPLINE_ELSE ||
ppline == PPLINE_ELIF))
{
/* in #if... and #el.. */
/* in #if... and #el... */
ERROR("No multiline comment right of code allowed here",
lineno, n);
@ -1047,7 +1133,9 @@ int main(int argc, char **argv, char **envp)
* example.
*/
else if (strncmp(&line[indent], "auto ", 5) == 0 ||
else if (inasm == 0)
{
if (strncmp(&line[indent], "auto ", 5) == 0 ||
strncmp(&line[indent], "bool ", 5) == 0 ||
strncmp(&line[indent], "char ", 5) == 0 ||
strncmp(&line[indent], "CODE ", 5) == 0 ||
@ -1082,8 +1170,8 @@ int main(int argc, char **argv, char **envp)
strncmp(&line[indent], "void ", 5) == 0 ||
strncmp(&line[indent], "volatile ", 9) == 0)
{
/* Check if this is extern "C"; We don't typically indent following
* this.
/* Check if this is extern "C"; We don't typically indent
* following this.
*/
if (strncmp(&line[indent], "extern \"C\"", 10) == 0)
@ -1217,6 +1305,7 @@ int main(int argc, char **argv, char **envp)
ERROR("Missing whitespace after keyword", lineno, n);
bswitch = true;
}
}
/* STEP 3: Parse each character on the line */
@ -1590,14 +1679,14 @@ int main(int argc, char **argv, char **envp)
bquote = false;
}
/* The reset of the line is only examined of we are not in a comment
* or a string.
/* The rest of the line is only examined of we are not in a comment,
* in a string or in assembly.
*
* REVISIT: Should still check for whitespace at the end of the
* line.
*/
if (ncomment == 0 && !bstring)
if (ncomment == 0 && !bstring && inasm == 0)
{
switch (line[n])
{