Skip to content

Commit

Permalink
Closed #235
Browse files Browse the repository at this point in the history
  • Loading branch information
N01ch committed Oct 5, 2021
1 parent 12bfd4f commit e263d96
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
5 changes: 4 additions & 1 deletion norminette/rules/is_func_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ def check_func_format(self, context):
i = context.skip_nest(i)
i += 1
i = context.skip_ws(i, nl=True)
while context.check_token(i, "LBRACKET"):
i = context.skip_nest(i)
i += 1
i = context.skip_ws(i, nl=True)
while context.check_token(i, "IDENTIFIER") is True and context.peek_token(i).value == "__attribute__":
i += 1
i = context.skip_ws(i)
Expand All @@ -216,7 +220,6 @@ def run(self, context):
"""
if type(context.scope) is not GlobalScope:
return False, 0

ret, read = self.check_func_format(context)
if ret is False:
return False, 0
Expand Down
28 changes: 27 additions & 1 deletion norminette/tests/rules/test_file_210923.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,30 @@ int main(void)
t_int * restrict d = 1;
t_int * restrict e = 1;
t_int * restrict f = 1;
}
}

int (*open_pipe(int nb_of_cmd))[2]
{
int i;
t_pipe pipe_fd;

pipe_fd = malloc(sizeof(int [2]) * (nb_of_cmd - 1));
if (error_catch(pipe_fd == 0, "system", "fail to malloc pipe table"))
return (NULL);
i = 0;
while (i < nb_of_cmd - 1)
{
if (error_catch(pipe(pipe_fd[i++]) == -1, "system",
"fail to open pipe"))
{
while (--i)
{
close(pipe_fd[i][0]);
close(pipe_fd[i][1]);
}
free(pipe_fd);
return (NULL);
}
}
return (pipe_fd);
}
55 changes: 53 additions & 2 deletions norminette/tests/rules/test_file_210923.out
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,58 @@
test_file_210923.c - IsVarDeclaration In "Function" from "GlobalScope" line 80":
<TAB> <IDENTIFIER=t_int> <SPACE> <MULT> <SPACE> <RESTRICT> <SPACE> <IDENTIFIER=f> <SPACE> <ASSIGN> <SPACE> <CONSTANT=1> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsBlockEnd In "Function" from "GlobalScope" line 81":
<RBRACE>
<RBRACE> <NEWLINE>
test_file_210923.c - IsEmptyLine In "GlobalScope" from "None" line 82":
<NEWLINE>
test_file_210923.c - IsFuncDeclaration In "GlobalScope" from "None" line 83":
<INT> <TAB> <LPARENTHESIS> <MULT> <IDENTIFIER=open_pipe> <LPARENTHESIS> <INT> <SPACE> <IDENTIFIER=nb_of_cmd> <RPARENTHESIS> <RPARENTHESIS> <LBRACKET> <CONSTANT=2> <RBRACKET> <NEWLINE>
test_file_210923.c - IsBlockStart In "Function" from "GlobalScope" line 84":
<LBRACE> <NEWLINE>
test_file_210923.c - IsVarDeclaration In "Function" from "GlobalScope" line 85":
<TAB> <INT> <TAB> <TAB> <IDENTIFIER=i> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsVarDeclaration In "Function" from "GlobalScope" line 86":
<TAB> <IDENTIFIER=t_pipe> <TAB> <IDENTIFIER=pipe_fd> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsEmptyLine In "Function" from "GlobalScope" line 87":
<NEWLINE>
test_file_210923.c - IsAssignation In "Function" from "GlobalScope" line 88":
<TAB> <IDENTIFIER=pipe_fd> <SPACE> <ASSIGN> <SPACE> <IDENTIFIER=malloc> <LPARENTHESIS> <SIZEOF> <LPARENTHESIS> <INT> <SPACE> <LBRACKET> <CONSTANT=2> <RBRACKET> <RPARENTHESIS> <SPACE> <MULT> <SPACE> <LPARENTHESIS> <IDENTIFIER=nb_of_cmd> <SPACE> <MINUS> <SPACE> <CONSTANT=1> <RPARENTHESIS> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsControlStatement In "Function" from "GlobalScope" line 89":
<TAB> <IF> <SPACE> <LPARENTHESIS> <IDENTIFIER=error_catch> <LPARENTHESIS> <IDENTIFIER=pipe_fd> <SPACE> <EQUALS> <SPACE> <CONSTANT=0> <COMMA> <SPACE> <STRING="system"> <COMMA> <SPACE> <STRING="fail to malloc pipe table"> <RPARENTHESIS> <RPARENTHESIS> <NEWLINE>
test_file_210923.c - IsExpressionStatement In "ControlStructure" from "Function" line 90":
<TAB> <TAB> <RETURN> <SPACE> <LPARENTHESIS> <NULL> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsAssignation In "Function" from "GlobalScope" line 91":
<TAB> <IDENTIFIER=i> <SPACE> <ASSIGN> <SPACE> <CONSTANT=0> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsControlStatement In "Function" from "GlobalScope" line 92":
<TAB> <WHILE> <SPACE> <LPARENTHESIS> <IDENTIFIER=i> <SPACE> <LESS_THAN> <SPACE> <IDENTIFIER=nb_of_cmd> <SPACE> <MINUS> <SPACE> <CONSTANT=1> <RPARENTHESIS> <NEWLINE>
test_file_210923.c - IsBlockStart In "ControlStructure" from "Function" line 93":
<TAB> <LBRACE> <NEWLINE>
test_file_210923.c - IsControlStatement In "ControlStructure" from "Function" line 94":
<TAB> <TAB> <IF> <SPACE> <LPARENTHESIS> <IDENTIFIER=error_catch> <LPARENTHESIS> <IDENTIFIER=pipe> <LPARENTHESIS> <IDENTIFIER=pipe_fd> <LBRACKET> <IDENTIFIER=i> <INC> <RBRACKET> <RPARENTHESIS> <SPACE> <EQUALS> <SPACE> <MINUS> <CONSTANT=1> <COMMA> <SPACE> <STRING="system"> <COMMA> <NEWLINE>
<TAB> <TAB> <TAB> <TAB> <STRING="fail to open pipe"> <RPARENTHESIS> <RPARENTHESIS> <NEWLINE>
test_file_210923.c - IsBlockStart In "ControlStructure" from "ControlStructure" line 96":
<TAB> <TAB> <LBRACE> <NEWLINE>
test_file_210923.c - IsControlStatement In "ControlStructure" from "ControlStructure" line 97":
<TAB> <TAB> <TAB> <WHILE> <SPACE> <LPARENTHESIS> <DEC> <IDENTIFIER=i> <RPARENTHESIS> <NEWLINE>
test_file_210923.c - IsBlockStart In "ControlStructure" from "ControlStructure" line 98":
<TAB> <TAB> <TAB> <LBRACE> <NEWLINE>
test_file_210923.c - IsFunctionCall In "ControlStructure" from "ControlStructure" line 99":
<TAB> <TAB> <TAB> <TAB> <IDENTIFIER=close> <LPARENTHESIS> <IDENTIFIER=pipe_fd> <LBRACKET> <IDENTIFIER=i> <RBRACKET> <LBRACKET> <CONSTANT=0> <RBRACKET> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsFunctionCall In "ControlStructure" from "ControlStructure" line 100":
<TAB> <TAB> <TAB> <TAB> <IDENTIFIER=close> <LPARENTHESIS> <IDENTIFIER=pipe_fd> <LBRACKET> <IDENTIFIER=i> <RBRACKET> <LBRACKET> <CONSTANT=1> <RBRACKET> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsBlockEnd In "ControlStructure" from "ControlStructure" line 101":
<TAB> <TAB> <TAB> <RBRACE> <NEWLINE>
test_file_210923.c - IsFunctionCall In "ControlStructure" from "ControlStructure" line 102":
<TAB> <TAB> <TAB> <IDENTIFIER=free> <LPARENTHESIS> <IDENTIFIER=pipe_fd> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsExpressionStatement In "ControlStructure" from "ControlStructure" line 103":
<TAB> <TAB> <TAB> <RETURN> <SPACE> <LPARENTHESIS> <NULL> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsBlockEnd In "ControlStructure" from "ControlStructure" line 104":
<TAB> <TAB> <RBRACE> <NEWLINE>
test_file_210923.c - IsBlockEnd In "ControlStructure" from "Function" line 105":
<TAB> <RBRACE> <NEWLINE>
test_file_210923.c - IsExpressionStatement In "Function" from "GlobalScope" line 106":
<TAB> <RETURN> <SPACE> <LPARENTHESIS> <IDENTIFIER=pipe_fd> <RPARENTHESIS> <SEMI_COLON> <NEWLINE>
test_file_210923.c - IsBlockEnd In "Function" from "GlobalScope" line 107":
<RBRACE> <NEWLINE>
test_file_210923.c: Error!
Error: INVALID_HEADER (line: 1, col: 1): Missing or invalid 42 header
Error: MULT_ASSIGN_LINE (line: 6, col: 16): Multiple assignations on a single line
Expand Down Expand Up @@ -208,4 +259,4 @@ Error: TOO_MANY_VARS_FUNC (line: 80, col: 1): Too many variables declaratio
Error: SPACE_REPLACE_TAB (line: 80, col: 10): Found space when expecting tab
Error: SPC_AFTER_POINTER (line: 80, col: 11): space after pointer
Error: DECL_ASSIGN_LINE (line: 80, col: 24): Declaration and assignation on a single line
Error: BRACE_SHOULD_EOL (line: 81, col: 1): Expected newline after brace
Error: TOO_MANY_FUNCS (line: 83, col: 1): Too many functions in file

0 comments on commit e263d96

Please sign in to comment.