Add new coding style rules and fix appeared issues.

JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
Andrey Shitov
2015-05-12 19:17:07 +03:00
parent ca12c16607
commit 9763a93df3
89 changed files with 1152 additions and 626 deletions
+2 -1
View File
@@ -476,7 +476,8 @@ ecma_gc_run (void)
obj_prev_p = obj_iter_p; obj_prev_p = obj_iter_p;
} }
} }
} while (marked_anything_during_current_iteration); }
while (marked_anything_during_current_iteration);
/* Sweeping objects that are currently unmarked */ /* Sweeping objects that are currently unmarked */
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ECMA_GC_COLOR_WHITE_GRAY], *obj_next_p; for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ECMA_GC_COLOR_WHITE_GRAY], *obj_next_p;
+1 -2
View File
@@ -22,8 +22,7 @@ typedef struct
uint8_t element_size; uint8_t element_size;
size_t len; size_t len;
size_t size; size_t size;
} } array_list_header;
array_list_header;
static array_list_header * static array_list_header *
extract_header (array_list al) extract_header (array_list al)
+1 -2
View File
@@ -26,8 +26,7 @@ typedef struct
uint8_t key_size; uint8_t key_size;
uint8_t value_size; uint8_t value_size;
mem_heap_alloc_term_t alloc_term; mem_heap_alloc_term_t alloc_term;
} } hash_table_int;
hash_table_int;
static hash_table_int * static hash_table_int *
extract_header (hash_table ht) extract_header (hash_table ht)
@@ -23,8 +23,7 @@ typedef struct linked_list_header
{ {
struct linked_list_header *next; struct linked_list_header *next;
uint16_t element_size; uint16_t element_size;
} } linked_list_header;
linked_list_header;
#define ASSERT_LIST(list) \ #define ASSERT_LIST(list) \
do { \ do { \
@@ -25,8 +25,7 @@ typedef struct
size_t current_bucket_pos; size_t current_bucket_pos;
literal_index_t *raw_buckets; literal_index_t *raw_buckets;
literal_index_t **buckets; literal_index_t **buckets;
} } lit_id_hash_table;
lit_id_hash_table;
lit_id_hash_table *lit_id_hash_table_init (size_t, size_t); lit_id_hash_table *lit_id_hash_table_init (size_t, size_t);
void lit_id_hash_table_free (lit_id_hash_table *); void lit_id_hash_table_free (lit_id_hash_table *);
+1 -2
View File
@@ -24,8 +24,7 @@ typedef struct
const ecma_char_t *str; const ecma_char_t *str;
ecma_length_t length; ecma_length_t length;
ecma_string_hash_t hash; ecma_string_hash_t hash;
} } lp_string;
lp_string;
bool lp_string_equal (lp_string, lp_string); bool lp_string_equal (lp_string, lp_string);
bool lp_string_equal_s (lp_string, const char *); bool lp_string_equal_s (lp_string, const char *);
+1 -2
View File
@@ -124,8 +124,7 @@ static TYPE *convert_##NAME##_to_raw_data (void) { \
{ \ { \
return NULL; \ return NULL; \
} \ } \
size_t size = mem_heap_recommend_allocation_size ( \ size_t size = mem_heap_recommend_allocation_size (array_list_len (NAME.data) * sizeof (NAME##_stack_value_type)); \
array_list_len (NAME.data) * sizeof (NAME##_stack_value_type)); \
TYPE *DATA = (TYPE *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM); \ TYPE *DATA = (TYPE *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_LONG_TERM); \
if (DATA == NULL) \ if (DATA == NULL) \
{ \ { \
+3 -6
View File
@@ -76,8 +76,7 @@ typedef enum __attr_packed___
KW_WHILE, KW_WHILE,
KW_WITH, KW_WITH,
KW_YIELD KW_YIELD
} } keyword;
keyword;
/* Type of tokens. */ /* Type of tokens. */
@@ -152,8 +151,7 @@ typedef enum __attr_packed___
TOK_DIV, // / TOK_DIV, // /
TOK_DIV_EQ, // /= TOK_DIV_EQ, // /=
TOK_EMPTY, TOK_EMPTY,
} } token_type;
token_type;
typedef size_t locus; typedef size_t locus;
@@ -163,8 +161,7 @@ typedef struct
locus loc; locus loc;
token_type type; token_type type;
literal_index_t uid; literal_index_t uid;
} } token;
token;
void lexer_init (const char *, size_t, bool); void lexer_init (const char *, size_t, bool);
void lexer_free (void); void lexer_free (void);
+3 -6
View File
@@ -25,8 +25,7 @@ typedef enum __attr_packed___
LIT_STR, LIT_STR,
LIT_MAGIC_STR, LIT_MAGIC_STR,
LIT_NUMBER LIT_NUMBER
} } literal_type;
literal_type;
typedef struct typedef struct
{ {
@@ -36,11 +35,9 @@ typedef struct
ecma_number_t num; ecma_number_t num;
lp_string lp; lp_string lp;
void *none; void *none;
} } data;
data;
literal_type type; literal_type type;
} } literal;
literal;
#define LITERAL_TO_REWRITE (INVALID_VALUE - 1) #define LITERAL_TO_REWRITE (INVALID_VALUE - 1)
+4 -8
View File
@@ -24,8 +24,7 @@ typedef enum __attr_packed___
{ {
OPERAND_LITERAL, OPERAND_LITERAL,
OPERAND_TMP OPERAND_TMP
} } operand_type;
operand_type;
typedef struct typedef struct
{ {
@@ -34,10 +33,8 @@ typedef struct
{ {
idx_t uid; idx_t uid;
literal_index_t lit_id; literal_index_t lit_id;
} } data;
data; } operand;
}
operand;
typedef enum __attr_packed___ typedef enum __attr_packed___
{ {
@@ -47,8 +44,7 @@ typedef enum __attr_packed___
VARG_OBJ_DECL, VARG_OBJ_DECL,
VARG_CONSTRUCT_EXPR, VARG_CONSTRUCT_EXPR,
VARG_CALL_EXPR VARG_CALL_EXPR
} } varg_list_type;
varg_list_type;
operand empty_operand (void); operand empty_operand (void);
operand literal_operand (literal_index_t); operand literal_operand (literal_index_t);
+3 -6
View File
@@ -29,16 +29,14 @@ typedef struct
{ {
literal_index_t lit_id[3]; literal_index_t lit_id[3];
opcode_t op; opcode_t op;
} } op_meta;
op_meta;
typedef struct tree_header typedef struct tree_header
{ {
struct tree_header *parent; struct tree_header *parent;
linked_list children; linked_list children;
uint8_t children_num; uint8_t children_num;
} } tree_header;
tree_header;
typedef struct typedef struct
{ {
@@ -46,8 +44,7 @@ typedef struct
linked_list opcodes; linked_list opcodes;
opcode_counter_t opcodes_num; opcode_counter_t opcodes_num;
unsigned strict_mode:1; unsigned strict_mode:1;
} } scopes_tree_int;
scopes_tree_int;
typedef scopes_tree_int * scopes_tree; typedef scopes_tree_int * scopes_tree;
+1 -2
View File
@@ -24,8 +24,7 @@ typedef struct
{ {
prop_type type; prop_type type;
literal lit; literal lit;
} } prop_literal;
prop_literal;
enum enum
{ {
+1 -2
View File
@@ -85,8 +85,7 @@ typedef enum __attr_packed___
PROP_SET, PROP_SET,
PROP_GET, PROP_GET,
VARG VARG
} } prop_type;
prop_type;
void syntax_init (void); void syntax_init (void);
void syntax_free (void); void syntax_free (void);
+1 -2
View File
@@ -279,7 +279,6 @@ OP_ARGS_LIST (GETOP_DECL)
typedef struct typedef struct
{ {
uint8_t uids[4]; uint8_t uids[4];
} } raw_opcode;
raw_opcode;
#endif /* OPCODES_H */ #endif /* OPCODES_H */
+10
View File
@@ -1,4 +1,14 @@
set rules { set rules {
jerry_always_curly
jerry_braces_on_separate_line
jerry_braces_same_line_or_column
jerry_funcname_space_parentheses
jerry_identifier_no_space_bracket
jerry_indentation jerry_indentation
jerry_max_line_length
jerry_no_space_after_opening_parentheses
jerry_no_space_before_closing_parentheses
jerry_no_tabs
jerry_no_trailing_spaces
jerry_switch_case jerry_switch_case
} }
@@ -0,0 +1,87 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
foreach file_name [getSourceFileNames] {
set state "control"
set do_marks {}
set prev_tok_type ""
set prev_ctrl ""
set expect_while false
set expect_open_brace false
set paren_count 0
foreach token [getTokens $file_name 1 0 -1 -1 {if do while else for leftparen rightparen semicolon leftbrace rightbrace}] {
set tok_val [lindex $token 0]
set line_num [lindex $token 1]
set col_num [lindex $token 2]
set tok_type [lindex $token 3]
if {$state == "expression"} {
# puts "expression $paren_count $tok_type ($line_num , $col_num)"
if {$tok_type == "leftparen"} {
incr paren_count
} elseif {$tok_type == "rightparen"} {
incr paren_count -1
if {$paren_count == 0} {
set state "control"
set expect_open_brace true
} elseif {$paren_count < 0 } {
report $file_name $line_num "unexpected right parentheses"
}
} elseif {$tok_type != "semicolon"} {
report $file_name $line_num "unexpected token: $tok_type"
}
} else {
if {$expect_open_brace == true} {
if {$tok_type == "if" && $prev_tok_type == "else"} {
# empty
} elseif {$tok_type != "leftbrace"} {
report $file_name [lindex $prev_ctrl 1] "brace after \'[lindex $prev_ctrl 3]\' required"
}
set expect_open_brace false
}
if {$tok_type == "while" && ($expect_while == true || [lindex $prev_ctrl 3] == "do")} {
set expect_while false
set prev_ctrl ""
} elseif {$tok_type in {if for while}} {
set state "expression"
set prev_ctrl $token
} elseif {$tok_type in {do else}} {
set expect_open_brace true
set prev_ctrl $token
} elseif {$tok_type == "leftbrace"} {
if {[lindex $prev_ctrl 3] == "do"} {
lappend do_marks 1
} else {
lappend do_marks 0
}
set prev_ctrl ""
} elseif {$tok_type == "rightbrace"} {
if {[llength $do_marks] > 0} {
if {[lindex $do_marks end] == 1} {
set expect_while true
}
set do_marks [lreplace $do_marks end end]
} else {
report $file_name $line_num "unmatched brace"
}
}
}
set prev_tok_type $tok_type
}
}
@@ -0,0 +1,115 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
foreach file_name [getSourceFileNames] {
set state "normal"
set lines {}
set cols {}
set struct_marks {}
set expect_struct_name false
set prev_tok ""
set def_start false
set expect_newline false
set check_newline true
foreach token [getTokens $file_name 1 0 -1 -1 {}] {
set tok_val [lindex $token 0]
set line_num [lindex $token 1]
set col_num [lindex $token 2]
set tok_type [lindex $token 3]
if {$state == "macro"} {
if {$col_num == 0} {
set state "normal"
} else {
continue
}
}
if {$tok_type in {space ccomment cppcomment newline}} {
continue
}
if {$tok_type == "pp_define"} {
set state "macro"
set prev_tok ""
set def_start false
continue
}
if {$expect_struct_name == true} {
if {$tok_type == "identifier" && $line_num != [lindex $prev_tok 1]} {
report $file_name $line_num "type name should be on the same line with the rightbrace"
}
set expect_struct_name false
}
# check that rightbrace and typename (in struct, union and enum definitons) are on the same line
if {$tok_type in {struct enum union}} {
set def_start true
} elseif {$tok_type == "semicolon"} {
set def_start false
} elseif {$tok_type == "leftbrace"} {
lappend cols $col_num
lappend lines $line_num
if {$def_start == true} {
lappend struct_marks 1
set def_start false
} elseif {[lindex $prev_tok 3] == "assign"} {
lappend struct_marks 2
set check_newline false
} else {
lappend struct_marks 0
}
} elseif {$tok_type == "rightbrace"} {
if {[llength $lines] > 0} {
if {[lindex $struct_marks end] == 1} {
set expect_struct_name true
set check_newline false
} elseif {[lindex $struct_marks end] == 2} {
set check_newline false
}
set lines [lreplace $lines end end]
set cols [lreplace $cols end end]
set struct_marks [lreplace $struct_marks end end]
} else {
report $file_name $line_num "unmatched brace"
}
}
# check that braces are on separate lines
if {$check_newline == true} {
if {$expect_newline == true} {
if {$tok_type == "semicolon"} {
# empty
} elseif {[lindex $prev_tok 1] == $line_num} {
report $file_name $line_num "brace should be placed on a separate line"
} else {
set expect_newline false
}
} elseif {$tok_type in {leftbrace rightbrace}} {
if {[lindex $prev_tok 1] == $line_num} {
report $file_name $line_num "brace should be placed on a separate line"
}
set expect_newline true
}
} else {
set check_newline true
}
set prev_tok $token
}
}
@@ -0,0 +1,61 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
foreach file_name [getSourceFileNames] {
set state "normal"
set lines {}
set cols {}
foreach token [getTokens $file_name 1 0 -1 -1 {}] {
set tok_val [lindex $token 0]
set line_num [lindex $token 1]
set col_num [lindex $token 2]
set tok_type [lindex $token 3]
if {$state == "macro"} {
if {$col_num == 0} {
set state "normal"
} else {
set prev_tok_line $line_num
continue
}
}
if {$tok_type in {space ccomment cppcomment newline}} {
continue
}
if {$tok_type == "pp_define"} {
set state "macro"
continue
}
if {$tok_type == "leftbrace"} {
lappend cols $col_num
lappend lines $line_num
} elseif {$tok_type == "rightbrace"} {
if {[llength $lines] > 0} {
if {[lindex $lines end] != $line_num && [lindex $cols end] != $col_num} {
report $file_name $line_num "matching braces should be on the same line or column"
}
set lines [lreplace $lines end end]
set cols [lreplace $cols end end]
} else {
report $file_name $line_num "unmatched brace"
}
}
}
}
@@ -0,0 +1,60 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
proc check_part_of_the_file {file line_num col_start col_end} {
if {$col_start == $col_end} {
return
}
set line [getLine $file $line_num]
if {[regexp {^\s*#[ ]*define} $line]} {
return
}
set line [string range $line $col_start $col_end]
if {[regexp {([[:alnum:]][\s]{2,}\()|([[:alnum:]]\()} $line]} {
report $file $line_num "there should be exactly one space before left parentheses"
}
}
foreach fileName [getSourceFileNames] {
set checkLine 1
set checkColStart 0
set seenOmitToken false
foreach token [getTokens $fileName 1 0 -1 -1 {}] {
set lineNumber [lindex $token 1]
set colNumber [lindex $token 2]
set tokenType [lindex $token 3]
if {$checkLine != $lineNumber} {
if {!$seenOmitToken} {
check_part_of_the_file $fileName $checkLine $checkColStart end
}
set checkColStart $colNumber
set checkLine $lineNumber
} elseif {$seenOmitToken} {
set checkColStart $colNumber
}
if {$tokenType in {ccomment cppcomment stringlit}} {
check_part_of_the_file $fileName $checkLine $checkColStart $colNumber
set seenOmitToken true
} else {
set seenOmitToken false
}
}
}
@@ -0,0 +1,56 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
proc check_part_of_the_file {file line_num col_start col_end} {
if {$col_start == $col_end} {
return
}
set line [getLine $file $line_num]
set line [string range $line $col_start $col_end]
if {[regexp {[[:alnum:]_][\s]+\[} $line]} {
report $file $line_num "there should be no spaces between identifier and left bracket"
}
}
foreach fileName [getSourceFileNames] {
set checkLine 1
set checkColStart 0
set seenOmitToken false
foreach token [getTokens $fileName 1 0 -1 -1 {}] {
set lineNumber [lindex $token 1]
set colNumber [lindex $token 2]
set tokenType [lindex $token 3]
if {$checkLine != $lineNumber} {
if {!$seenOmitToken} {
check_part_of_the_file $fileName $checkLine $checkColStart end
}
set checkColStart $colNumber
set checkLine $lineNumber
} elseif {$seenOmitToken} {
set checkColStart $colNumber
}
if {$tokenType in {ccomment cppcomment stringlit}} {
check_part_of_the_file $fileName $checkLine $checkColStart $colNumber
set seenOmitToken true
} else {
set seenOmitToken false
}
}
}
@@ -0,0 +1,27 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set maxLen 120
foreach f [getSourceFileNames] {
set lineNumber 1
foreach line [getAllLines $f] {
if {[string length $line] > $maxLen} {
report $f $lineNumber "line is longer than ${maxLen} characters"
}
incr lineNumber
}
}
@@ -0,0 +1,56 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
proc check_part_of_the_file {file line_num col_start col_end} {
if {$col_start == $col_end} {
return
}
set line [getLine $file $line_num]
set line [string range $line $col_start $col_end]
if {[regexp {\(+[[:blank:]]} $line]} {
report $file $line_num "there should be no blank characters after opening parentheses"
}
}
foreach fileName [getSourceFileNames] {
set checkLine 1
set checkColStart 0
set seenOmitToken false
foreach token [getTokens $fileName 1 0 -1 -1 {}] {
set lineNumber [lindex $token 1]
set colNumber [lindex $token 2]
set tokenType [lindex $token 3]
if {$checkLine != $lineNumber} {
if {!$seenOmitToken} {
check_part_of_the_file $fileName $checkLine $checkColStart end
}
set checkColStart $colNumber
set checkLine $lineNumber
} elseif {$seenOmitToken} {
set checkColStart $colNumber
}
if {$tokenType in {ccomment cppcomment stringlit}} {
check_part_of_the_file $fileName $checkLine $checkColStart $colNumber
set seenOmitToken true
} else {
set seenOmitToken false
}
}
}
@@ -0,0 +1,25 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
foreach f [getSourceFileNames] {
set lineNumber 1
foreach line [getAllLines $f] {
if {[regexp {[[:graph:]][[:blank:]]+\)} $line]} {
report $f $lineNumber "there should be no blank characters before closing parentheses"
}
incr lineNumber
}
}
@@ -0,0 +1,25 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
foreach f [getSourceFileNames] {
set lineNumber 1
foreach line [getAllLines $f] {
if {[regexp {\t} $line]} {
report $f $lineNumber "tabs are not allowed"
}
incr lineNumber
}
}
@@ -0,0 +1,25 @@
#!/usr/bin/tclsh
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
foreach f [getSourceFileNames] {
set lineNumber 1
foreach line [getAllLines $f] {
if {[regexp {[[:blank:]]$} $line]} {
report $f $lineNumber "trailing space is not allowed"
}
incr lineNumber
}
}