@@ -786,13 +786,13 @@ def type(symtab)
786786
787787 sym = symtab . get ( name )
788788 # @type =
789- if sym . is_a? ( Type )
790- sym
791- elsif sym . is_a? ( Var )
792- sym . type
793- else
794- internal_error "Unexpected object on the symbol table"
795- end
789+ if sym . is_a? ( Type )
790+ sym
791+ elsif sym . is_a? ( Var )
792+ sym . type
793+ else
794+ internal_error "Unexpected object on the symbol table"
795+ end
796796 end
797797
798798 # @return [Boolean] whether or not the Id represents a const
@@ -995,16 +995,16 @@ def globals = definitions.select { |d| d.is_a?(GlobalWithInitializationAst) || d
995995 def enums = definitions . select { |e | e . is_a? ( EnumDefinitionAst ) || e . is_a? ( BuiltinEnumDefinitionAst ) }
996996
997997 # @return {Array<AstNode>] List of all bitfield definitions
998- def bitfields = definitions . select { | e | e . is_a? ( BitfieldDefinitionAst ) }
998+ def bitfields = definitions . grep ( BitfieldDefinitionAst )
999999
10001000 # @return [Array<AstNode>] List of all struct definitions
1001- def structs = definitions . select { | e | e . is_a? ( StructDefinitionAst ) }
1001+ def structs = definitions . grep ( StructDefinitionAst )
10021002
10031003 # @return [Array<AstNode>] List of all function definitions
1004- def functions = definitions . select { | e | e . is_a? ( FunctionDefAst ) }
1004+ def functions = definitions . grep ( FunctionDefAst )
10051005
10061006 # @return [FetchAst] Fetch body
1007- def fetch = definitions . select { | e | e . is_a? ( FetchAst ) } [ 0 ]
1007+ def fetch = definitions . grep ( FetchAst ) [ 0 ]
10081008
10091009 # Add all the global symbols to symtab
10101010 #
@@ -1037,7 +1037,7 @@ def replace_include!(include_ast, isa_ast)
10371037 def type_check ( symtab )
10381038 definitions . each { |d | d . type_check ( symtab ) }
10391039
1040- fetch_blocks = definitions . select { | d | d . is_a? ( FetchAst ) }
1040+ fetch_blocks = definitions . grep ( FetchAst )
10411041 type_error "Multiple fetch blocks defined" if fetch_blocks . size > 1
10421042 type_error "No fetch block defined" if fetch_blocks . size . zero?
10431043 end
@@ -1305,7 +1305,7 @@ class EnumDefinitionAst < AstNode
13051305 def const_eval? ( symtab ) = true
13061306
13071307 def initialize ( input , interval , user_type , element_names , element_values )
1308- super ( input , interval , [ user_type ] + element_names + element_values . reject { |e | e . nil? } )
1308+ super ( input , interval , [ user_type ] + element_names + element_values . reject { |e | e . nil? } )
13091309 @user_type = user_type
13101310 @element_name_asts = element_names
13111311 @element_value_asts = element_values
@@ -1572,7 +1572,7 @@ def element_names
15721572 def element_ranges ( symtab )
15731573 return @element_ranges unless @element_ranges . nil?
15741574
1575- @element_ranges = @fields . map { |f | f . range ( symtab ) }
1575+ @element_ranges = @fields . map { |f | f . range ( symtab ) }
15761576 end
15771577
15781578 # @!macro type_check
@@ -3788,7 +3788,7 @@ def value(symtab)
37883788 # even if we don't know the exact value of @lhs and @rhs, we can still
37893789 # know that != is true if the possible values of lhs are all <= the possible values of rhs
37903790 rhs_values = rhs . values ( symtab )
3791- if lhs . values ( symtab ) . all? { |lhs_value | rhs_values . all? { |rhs_value | lhs_value <= rhs_value } }
3791+ if lhs . values ( symtab ) . all? { |lhs_value | rhs_values . all? { |rhs_value | lhs_value <= rhs_value } }
37923792 true
37933793 else
37943794 value_error "Some value of lhs is not <= some value of rhs"
@@ -3802,7 +3802,7 @@ def value(symtab)
38023802 # even if we don't know the exact value of @lhs and @rhs, we can still
38033803 # know that != is true if the possible values of lhs are all >= the possible values of rhs
38043804 rhs_values = rhs . values ( symtab )
3805- if lhs . values ( symtab ) . all? { |lhs_value | rhs_values . all? { |rhs_value | lhs_value >= rhs_value } }
3805+ if lhs . values ( symtab ) . all? { |lhs_value | rhs_values . all? { |rhs_value | lhs_value >= rhs_value } }
38063806 true
38073807 else
38083808 value_error "Some value of lhs is not >= some value of rhs"
@@ -3816,7 +3816,7 @@ def value(symtab)
38163816 # even if we don't know the exact value of @lhs and @rhs, we can still
38173817 # know that != is true if the possible values of lhs are all < the possible values of rhs
38183818 rhs_values = rhs . values ( symtab )
3819- if lhs . values ( symtab ) . all? { |lhs_value | rhs_values . all? { |rhs_value | lhs_value < rhs_value } }
3819+ if lhs . values ( symtab ) . all? { |lhs_value | rhs_values . all? { |rhs_value | lhs_value < rhs_value } }
38203820 true
38213821 else
38223822 value_error "Some value of lhs is not < some value of rhs"
@@ -3830,7 +3830,7 @@ def value(symtab)
38303830 # even if we don't know the exact value of @lhs and @rhs, we can still
38313831 # know that != is true if the possible values of lhs are all > the possible values of rhs
38323832 rhs_values = rhs . values ( symtab )
3833- if lhs . values ( symtab ) . all? { |lhs_value | rhs_values . all? { |rhs_value | lhs_value > rhs_value } }
3833+ if lhs . values ( symtab ) . all? { |lhs_value | rhs_values . all? { |rhs_value | lhs_value > rhs_value } }
38343834 true
38353835 else
38363836 value_error "Some value of lhs is not > some value of rhs"
@@ -3992,7 +3992,7 @@ def to_idl = "[#{element_nodes.map(&:to_idl).join(',')}]"
39923992
39933993 class ConcatenationExpressionSyntaxNode < SyntaxNode
39943994 def to_ast
3995- ConcatenationExpressionAst . new ( input , interval , [ send ( :first ) . to_ast ] + send ( :rest ) . elements . map { |e | e . expression . to_ast } )
3995+ ConcatenationExpressionAst . new ( input , interval , [ send ( :first ) . to_ast ] + send ( :rest ) . elements . map { |e | e . expression . to_ast } )
39963996 end
39973997 end
39983998
@@ -4038,17 +4038,20 @@ def type(symtab)
40384038 sum
40394039 end
40404040
4041+ qualifiers = is_const ? [ :const ] : [ ]
4042+
40414043 if all_known_values
4044+ qualifiers << :known
40424045 if width_known
4043- Type . new ( :bits , width : total_width , qualifiers : [ :known ] )
4046+ Type . new ( :bits , width : total_width , qualifiers :)
40444047 else
4045- Type . new ( :bits , width : :unknown , qualifiers : [ :known ] )
4048+ Type . new ( :bits , width : :unknown , qualifiers :)
40464049 end
40474050 else
40484051 if width_known
4049- Type . new ( :bits , width : total_width )
4052+ Type . new ( :bits , width : total_width , qualifiers : )
40504053 else
4051- Type . new ( :bits , width : :unknown )
4054+ Type . new ( :bits , width : :unknown , qualifiers : )
40524055 end
40534056 end
40544057 end
@@ -4814,9 +4817,9 @@ def execute(symtab)
48144817 end
48154818
48164819 # @!macro execute
4817- def execute_unknown ( symtab )
4818- action . execute_unknown ( symtab )
4819- end
4820+ def execute_unknown ( symtab )
4821+ action . execute_unknown ( symtab )
4822+ end
48204823
48214824 # @!macro to_idl
48224825 sig { override . returns ( String ) }
@@ -5007,7 +5010,7 @@ def return_types(symtab)
50075010 elsif return_value_nodes [ 0 ] . type ( symtab ) . kind == :tuple
50085011 return_value_nodes [ 0 ] . type ( symtab ) . tuple_types
50095012 else
5010- return_value_nodes . map { |v | v . type ( symtab ) }
5013+ return_value_nodes . map { |v | v . type ( symtab ) }
50115014 end
50125015 end
50135016
@@ -5335,12 +5338,12 @@ def to_s
53355338 v = [ ]
53365339 ( [ known_str . size , x . size ] . max ) . times do |i |
53375340 if i >= known_str . size
5338- v << ( ( x [ i ] == '1' ) ? 'x' : '0' )
5341+ v << ( ( x [ i ] == "1" ) ? "x" : "0" )
53395342 elsif i >= x . size
53405343 v << known_str [ i ]
53415344 else
5342- if x [ i ] == '1'
5343- v << 'x'
5345+ if x [ i ] == "1"
5346+ v << "x"
53445347 else
53455348 v << known_str [ i ]
53465349 end
@@ -5409,7 +5412,7 @@ def type(symtab)
54095412 end
54105413
54115414 qualifiers = signed == "s" ? [ :signed , :const ] : [ :const ]
5412- qualifiers << :known unless T . must ( value ) . include? ( 'x' )
5415+ qualifiers << :known unless T . must ( value ) . include? ( "x" )
54135416 @type = Type . new ( :bits , width :, qualifiers :)
54145417 when /^0([bdx]?)([0-9a-fA-F]*)(s?)$/
54155418 # C++-style literal
@@ -5567,16 +5570,16 @@ def unsigned_value
55675570 radix_id = "o" if radix_id . empty?
55685571
55695572 # @unsigned_value =
5570- case radix_id
5571- when "b"
5572- value . to_i ( 2 )
5573- when "o"
5574- value . to_i ( 8 )
5575- when "d"
5576- value . to_i ( 10 )
5577- when "x"
5578- value . to_i ( 16 )
5579- end
5573+ case radix_id
5574+ when "b"
5575+ value . to_i ( 2 )
5576+ when "o"
5577+ value . to_i ( 8 )
5578+ when "d"
5579+ value . to_i ( 10 )
5580+ when "x"
5581+ value . to_i ( 16 )
5582+ end
55805583
55815584 when /^([0-9]*)(s?)$/
55825585 # basic decimal
@@ -5963,7 +5966,7 @@ def return_value(symtab)
59635966 stmts . each do |s |
59645967 if s . is_a? ( Returns )
59655968 v = s . return_value ( symtab )
5966- return v unless v == nil
5969+ return v unless v . nil?
59675970 else
59685971 s . execute ( symtab )
59695972 end
@@ -6057,8 +6060,12 @@ def to_ast
60576060 interval ,
60586061 send ( :function_name ) . text_value ,
60596062 ( !respond_to? ( :targs ) || send ( :targs ) . empty? ) ? [ ] : [ send ( :targs ) . first . to_ast ] + send ( :targs ) . rest . elements . map { |r | r . single_declaration . to_ast } ,
6060- send ( :ret ) . empty? ? [ ] : [ send ( :ret ) . first . to_ast ] + ( send ( :ret ) . respond_to? ( :rest ) ? send ( :ret ) . rest . elements . map { |r | r . type_name . to_ast } : [ ] ) ,
6061- send ( :args ) . empty? ? [ ] : [ send ( :args ) . first . to_ast ] + send ( :args ) . rest . elements . map { |r | r . single_declaration . to_ast } ,
6063+ if send ( :ret ) . empty?
6064+ [ ]
6065+ else
6066+ [ send ( :ret ) . first . to_ast ] + ( send ( :ret ) . respond_to? ( :rest ) ? send ( :ret ) . rest . elements . map { |r | r . type_name . to_ast } : [ ] )
6067+ end ,
6068+ send ( :args ) . empty? ? [ ] : [ send ( :args ) . first . to_ast ] + send ( :args ) . rest . elements . map { |r | r . single_declaration . to_ast } ,
60626069 send ( :desc ) . text_value ,
60636070 respond_to? ( :type ) ? send ( :type ) . text_value . strip . to_sym : :normal ,
60646071 respond_to? ( :body_block ) ? send ( :body_block ) . function_body . to_ast : nil
@@ -6881,7 +6888,7 @@ def if_body = T.cast(@children.fetch(1), IfBodyAst)
68816888 sig { returns ( T ::Array [ ElseIfAst ] ) }
68826889 def elseifs = T . cast ( T . must ( @children [ 2 ..-2 ] ) , T ::Array [ ElseIfAst ] )
68836890
6884- sig { returns ( IfBodyAst ) }
6891+ sig { returns ( IfBodyAst ) }
68856892 def final_else_body = T . cast ( T . must ( @children . last ) , IfBodyAst )
68866893
68876894 def initialize ( input , interval , if_cond , if_body , elseifs , final_else_body )
@@ -7194,7 +7201,7 @@ def calc_type(symtab)
71947201 internal_error "Could not find #{ @csr . text_value } .#{ @field_name } " if fd . nil?
71957202
71967203 if fd . defined_in_all_bases?
7197- Type . new ( :bits , width : symtab . possible_xlens . map { |xlen | fd . width ( xlen ) } . max )
7204+ Type . new ( :bits , width : symtab . possible_xlens . map { |xlen | fd . width ( xlen ) } . max )
71987205 elsif fd . base64_only?
71997206 if symtab . possible_xlens . include? ( 64 )
72007207 Type . new ( :bits , width : fd . width ( 64 ) )
0 commit comments