Some more fine tuning
Handle #define different than other preprocessor lines Ignore backslash at the end of a comment right of a preprocessor line
This commit is contained in:
parent
5e5b6c2069
commit
745e0a4ca9
@ -112,6 +112,13 @@ enum section_s
|
|||||||
PUBLIC_FUNCTION_PROTOTYPES
|
PUBLIC_FUNCTION_PROTOTYPES
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum pptype_e
|
||||||
|
{
|
||||||
|
PPLINE_NONE = 0,
|
||||||
|
PPLINE_DEFINE,
|
||||||
|
PPLINE_OTHER
|
||||||
|
};
|
||||||
|
|
||||||
struct file_section_s
|
struct file_section_s
|
||||||
{
|
{
|
||||||
const char *name; /* File section name */
|
const char *name; /* File section name */
|
||||||
@ -503,10 +510,13 @@ int main(int argc, char **argv, char **envp)
|
|||||||
bool bstring; /* True: Within a string */
|
bool bstring; /* True: Within a string */
|
||||||
bool bquote; /* True: Backslash quoted character next */
|
bool bquote; /* True: Backslash quoted character next */
|
||||||
bool bblank; /* Used to verify block comment terminator */
|
bool bblank; /* Used to verify block comment terminator */
|
||||||
bool ppline; /* True: The next line the continuation of a pre-processor command */
|
|
||||||
bool bexternc; /* True: Within 'extern "C"' */
|
bool bexternc; /* True: Within 'extern "C"' */
|
||||||
int rhcomment; /* Indentation of Comment to the right of code */
|
enum pptype_e ppline; /* > 0: The next line the continuation of a
|
||||||
int prevrhcmt; /* Indentation of previous Comment to the right of code */
|
* pre-processor command */
|
||||||
|
int rhcomment; /* Indentation of Comment to the right of code
|
||||||
|
* (-1 -> don't check position) */
|
||||||
|
int prevrhcmt; /* Indentation of previous Comment to the right
|
||||||
|
* of code (-1 -> don't check position) */
|
||||||
int lineno; /* Current line number */
|
int lineno; /* Current line number */
|
||||||
int indent; /* Indentation level */
|
int indent; /* Indentation level */
|
||||||
int ncomment; /* Comment nesting level on this line */
|
int ncomment; /* Comment nesting level on this line */
|
||||||
@ -623,11 +633,13 @@ int main(int argc, char **argv, char **envp)
|
|||||||
bfunctions = false; /* True: In private or public functions */
|
bfunctions = false; /* True: In private or public functions */
|
||||||
bswitch = false; /* True: Within a switch statement */
|
bswitch = false; /* True: Within a switch statement */
|
||||||
bstring = false; /* True: Within a string */
|
bstring = false; /* True: Within a string */
|
||||||
ppline = false; /* True: Continuation of a pre-processor line */
|
|
||||||
bexternc = false; /* True: Within 'extern "C"' */
|
bexternc = false; /* True: Within 'extern "C"' */
|
||||||
rhcomment = 0; /* Indentation of Comment to the right of code */
|
ppline = PPLINE_NONE; /* > 0: The next line the continuation of a
|
||||||
|
* pre-processor command */
|
||||||
|
rhcomment = 0; /* Indentation of Comment to the right of code
|
||||||
|
* (-1 -> don't check position) */
|
||||||
prevrhcmt = 0; /* Indentation of previous Comment to the right
|
prevrhcmt = 0; /* Indentation of previous Comment to the right
|
||||||
* of code */
|
* of code (-1 -> don't check position) */
|
||||||
lineno = 0; /* Current line number */
|
lineno = 0; /* Current line number */
|
||||||
ncomment = 0; /* Comment nesting level on this line */
|
ncomment = 0; /* Comment nesting level on this line */
|
||||||
bnest = 0; /* Brace nesting level on this line */
|
bnest = 0; /* Brace nesting level on this line */
|
||||||
@ -827,7 +839,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
* lines as indicated by ppline)
|
* lines as indicated by ppline)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (line[indent] == '#' || ppline)
|
if (line[indent] == '#' || ppline != PPLINE_NONE)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
int ii;
|
int ii;
|
||||||
@ -840,7 +852,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
* line.
|
* line.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!ppline)
|
if (ppline == PPLINE_NONE)
|
||||||
{
|
{
|
||||||
/* Skip to the pre-processor command following the '#' */
|
/* Skip to the pre-processor command following the '#' */
|
||||||
|
|
||||||
@ -856,8 +868,12 @@ int main(int argc, char **argv, char **envp)
|
|||||||
* the pre-processor definitions section.
|
* the pre-processor definitions section.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ppline = PPLINE_OTHER;
|
||||||
|
|
||||||
if (strncmp(&line[ii], "define", 6) == 0)
|
if (strncmp(&line[ii], "define", 6) == 0)
|
||||||
{
|
{
|
||||||
|
ppline = PPLINE_DEFINE;
|
||||||
|
|
||||||
if (g_section != PRE_PROCESSOR_DEFINITIONS)
|
if (g_section != PRE_PROCESSOR_DEFINITIONS)
|
||||||
{
|
{
|
||||||
/* A complication is the header files always have
|
/* A complication is the header files always have
|
||||||
@ -913,14 +929,10 @@ int main(int argc, char **argv, char **envp)
|
|||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
ppline = (line[len] == '\\');
|
|
||||||
|
|
||||||
/* Propagate rhcomment over preprocessor lines Issue #120 */
|
/* Propagate rhcomment over preprocessor lines Issue #120 */
|
||||||
|
|
||||||
rhcomment = prevrhcmt;
|
rhcomment = prevrhcmt;
|
||||||
|
|
||||||
if (!ppline)
|
|
||||||
{
|
|
||||||
lptr = strstr(line, "/*");
|
lptr = strstr(line, "/*");
|
||||||
if (lptr != NULL)
|
if (lptr != NULL)
|
||||||
{
|
{
|
||||||
@ -941,16 +953,27 @@ int main(int argc, char **argv, char **envp)
|
|||||||
ncomment++;
|
ncomment++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ppline == PPLINE_DEFINE)
|
||||||
|
{
|
||||||
rhcomment = n;
|
rhcomment = n;
|
||||||
|
if (prevrhcmt > 0 && n != prevrhcmt)
|
||||||
if (!strncmp(&line[ii], "define", 6)
|
|
||||||
&& prevrhcmt != 0 && n != prevrhcmt)
|
|
||||||
{
|
{
|
||||||
rhcomment = prevrhcmt;
|
rhcomment = prevrhcmt;
|
||||||
WARN("Wrong column position of comment right of code",
|
WARN("Wrong column position of comment right of code",
|
||||||
lineno, n);
|
lineno, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Signal rhcomment, but ignore position */
|
||||||
|
|
||||||
|
rhcomment = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line[len] != '\\' || ncomment > 0)
|
||||||
|
{
|
||||||
|
ppline = PPLINE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -1413,7 +1436,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
rhcomment = n;
|
rhcomment = n;
|
||||||
if (n != prevrhcmt)
|
if (prevrhcmt > 0 && n != prevrhcmt)
|
||||||
{
|
{
|
||||||
rhcomment = prevrhcmt;
|
rhcomment = prevrhcmt;
|
||||||
WARN("Wrong column position of comment right of code",
|
WARN("Wrong column position of comment right of code",
|
||||||
|
Loading…
Reference in New Issue
Block a user