From b08195b68a46115faacc40f0637ae0dae40b9b98 Mon Sep 17 00:00:00 2001 From: dalance Date: Wed, 6 Nov 2019 12:49:04 +0900 Subject: [PATCH] Fix bugs --- CHANGELOG.md | 2 + .../src/expressions/expressions.rs | 2 +- .../src/expressions/subroutine_calls.rs | 4 +- sv-parser-parser/src/tests.rs | 66 ++++++++++++------- 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a23f46..02cb917 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * [Fixed] apply workaround for static class method call * [Fixed] randomize_call bug +* [Fixed] parameter override by class type bug +* [Fixed] hierarchical this bug ## [v0.3.6](https://github.com/dalance/sv-parser/compare/v0.3.5...v0.3.6) - 2019-11-05 diff --git a/sv-parser-parser/src/expressions/expressions.rs b/sv-parser-parser/src/expressions/expressions.rs index 6a5add2..f68ccc4 100644 --- a/sv-parser-parser/src/expressions/expressions.rs +++ b/sv-parser-parser/src/expressions/expressions.rs @@ -183,10 +183,10 @@ pub(crate) fn constant_param_expression(s: Span) -> IResult IResult { alt(( + map(data_type, |x| ParamExpression::DataType(Box::new(x))), map(mintypmax_expression, |x| { ParamExpression::MintypmaxExpression(Box::new(x)) }), - map(data_type, |x| ParamExpression::DataType(Box::new(x))), map(symbol("$"), |x| ParamExpression::Dollar(Box::new(x))), ))(s) } diff --git a/sv-parser-parser/src/expressions/subroutine_calls.rs b/sv-parser-parser/src/expressions/subroutine_calls.rs index b24df4a..c4a96bb 100644 --- a/sv-parser-parser/src/expressions/subroutine_calls.rs +++ b/sv-parser-parser/src/expressions/subroutine_calls.rs @@ -256,7 +256,6 @@ pub(crate) fn method_call_root(s: Span) -> IResult { #[packrat_parser] pub(crate) fn primary_method_call_root(s: Span) -> IResult { alt(( - map(keyword("this"), |x| Primary::This(Box::new(x))), map(keyword("$"), |x| Primary::Dollar(Box::new(x))), map(keyword("null"), |x| Primary::Null(Box::new(x))), map(assignment_pattern_expression, |x| { @@ -265,6 +264,7 @@ pub(crate) fn primary_method_call_root(s: Span) -> IResult { map(primary_literal, |x| Primary::PrimaryLiteral(Box::new(x))), map(cast, |x| Primary::Cast(Box::new(x))), terminated(primary_hierarchical_method_call_root, peek(none_of("("))), + map(keyword("this"), |x| Primary::This(Box::new(x))), map(empty_unpacked_array_concatenation, |x| { Primary::EmptyUnpackedArrayConcatenation(Box::new(x)) }), @@ -322,7 +322,7 @@ pub(crate) fn select_method_call_root(s: Span) -> IResult { symbol("."), member_identifier, ), - peek(symbol(".")), + peek(one_of(".[")), ))(s)?; let (s, b) = bit_select(s)?; let (s, c) = opt(bracket(part_select_range))(s)?; diff --git a/sv-parser-parser/src/tests.rs b/sv-parser-parser/src/tests.rs index 4704c1b..b596d26 100644 --- a/sv-parser-parser/src/tests.rs +++ b/sv-parser-parser/src/tests.rs @@ -363,6 +363,21 @@ mod unit { b, c) text goes here"##, Ok((_, _)) ); + test!( + source_text, + r##"class A; static uvm_pool#(string,uvm_resource#(T)) m_rsc[uvm_component]; endclass"##, + Ok((_, _)) + ); + test!( + source_text, + r##"module a; initial begin elements.push_back(urme_container.elements[i].clone()); end endmodule"##, + Ok((_, _)) + ); + test!( + source_text, + r##"class a; function a b(); return this.a.b(); endfunction endclass"##, + Ok((_, _)) + ); } } @@ -6449,34 +6464,35 @@ mod spec { endclass"##, Ok((_, _)) ); - // TODO + // BNF-WA + // reported at https://accellera.mantishub.io/view.php?id=1642 // class static method is denied because ps_or_hierarchical_tf_identifier doesn't have class_scope. - //test!( - // many1(module_item), - // r##"module top (); - // logic [7:0] encoder_in; - // logic [2:0] encoder_out; - // logic [1:0] decoder_in; - // logic [3:0] decoder_out; + test!( + many1(module_item), + r##"module top (); + logic [7:0] encoder_in; + logic [2:0] encoder_out; + logic [1:0] decoder_in; + logic [3:0] decoder_out; - // // Encoder and Decoder Input Assignments - // assign encoder_in = 8'b0100_0000; - // assign decoder_in = 2'b11; + // Encoder and Decoder Input Assignments + assign encoder_in = 8'b0100_0000; + assign decoder_in = 2'b11; - // // Encoder and Decoder Function calls - // assign encoder_out = C#(8)::ENCODER_f(encoder_in); - // assign decoder_out = C#(4)::DECODER_f(decoder_in); + // Encoder and Decoder Function calls + assign encoder_out = C#(8)::ENCODER_f(encoder_in); + assign decoder_out = C#(4)::DECODER_f(decoder_in); - // initial begin - // #50; - // $display("Encoder input = %b Encoder output = %b\n", - // encoder_in, encoder_out ); - // $display("Decoder input = %b Decoder output = %b\n", - // decoder_in, decoder_out ); - // end - // endmodule"##, - // Ok((_, _)) - //); + initial begin + #50; + $display("Encoder input = %b Encoder output = %b\n", + encoder_in, encoder_out ); + $display("Decoder input = %b Decoder output = %b\n", + decoder_in, decoder_out ); + end + endmodule"##, + Ok((_, _)) + ); } #[test] @@ -15822,7 +15838,7 @@ mod spec { fn debug() { test!( source_text, - r##"module top (); initial begin p.randomize() with { length == 1512;}; end endmodule"##, + r##"module a; initial begin this.a.b(); end endmodule"##, Ok((_, _)) ); nom_tracable::cumulative_histogram();