Class: AdLint::Cc1::UnionSpecifier

Inherits:
TypeSpecifier show all
Defined in:
lib/adlint/cc1/syntax.rb

Instance Attribute Summary collapse

Attributes inherited from SyntaxNode

#head_token, #subsequent_sequence_point, #tail_token

Instance Method Summary collapse

Methods inherited from SyntaxNode

#head_location, #short_class_name, #tail_location

Methods included from LocationHolder

#analysis_target?

Methods included from Visitable

#accept

Constructor Details

#initialize(id, struct_dcls, anonymous = false) ⇒ UnionSpecifier

Returns a new instance of UnionSpecifier.



2806
2807
2808
2809
2810
2811
# File 'lib/adlint/cc1/syntax.rb', line 2806

def initialize(id, struct_dcls, anonymous = false)
  super()
  @identifier = id
  @struct_declarations = struct_dcls
  @anonymous = anonymous
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



2813
2814
2815
# File 'lib/adlint/cc1/syntax.rb', line 2813

def identifier
  @identifier
end

#struct_declarationsObject (readonly)

Returns the value of attribute struct_declarations.



2814
2815
2816
# File 'lib/adlint/cc1/syntax.rb', line 2814

def struct_declarations
  @struct_declarations
end

Instance Method Details

#anonymous?Boolean

Returns:

  • (Boolean)


2820
2821
2822
# File 'lib/adlint/cc1/syntax.rb', line 2820

def anonymous?
  @anonymous
end

#inspect(indent = 0) ⇒ Object



2838
2839
2840
# File 'lib/adlint/cc1/syntax.rb', line 2838

def inspect(indent = 0)
  " " * indent + short_class_name
end

#locationObject



2816
2817
2818
# File 'lib/adlint/cc1/syntax.rb', line 2816

def location
  @identifier.location
end

#to_sObject



2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
# File 'lib/adlint/cc1/syntax.rb', line 2824

def to_s
  if @struct_declarations
    if @struct_declarations.empty?
      "union #{identifier.value} {}"
    else
      "union #{identifier.value} { " +
        @struct_declarations.map { |dcl| dcl.to_s }.join(" ") +
        " }"
    end
  else
    "union #{identifier.value}"
  end
end