Class: AdLint::Cpp::ConditionalExpression

Inherits:
Expression show all
Defined in:
lib/adlint/cpp/syntax.rb

Instance Attribute Summary collapse

Attributes inherited from Expression

#value

Instance Method Summary collapse

Methods inherited from SyntaxNode

#short_class_name

Methods included from LocationHolder

#analysis_target?

Methods included from Visitable

#accept

Constructor Details

#initialize(val, cond, fst_expr, snd_expr) ⇒ ConditionalExpression

Returns a new instance of ConditionalExpression.



884
885
886
887
888
889
# File 'lib/adlint/cpp/syntax.rb', line 884

def initialize(val, cond, fst_expr, snd_expr)
  super(val)
  @condition = cond
  @first_expression  = fst_expr
  @second_expression = snd_expr
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



891
892
893
# File 'lib/adlint/cpp/syntax.rb', line 891

def condition
  @condition
end

#first_expressionObject (readonly)

Returns the value of attribute first_expression.



892
893
894
# File 'lib/adlint/cpp/syntax.rb', line 892

def first_expression
  @first_expression
end

#second_expressionObject (readonly)

Returns the value of attribute second_expression.



893
894
895
# File 'lib/adlint/cpp/syntax.rb', line 893

def second_expression
  @second_expression
end

Instance Method Details

#inspect(indent = 0) ⇒ Object



904
905
906
907
908
# File 'lib/adlint/cpp/syntax.rb', line 904

def inspect(indent = 0)
  " " * indent + "#{short_class_name} (#{@condition.inspect})\n" +
    @first_expression.inspect(indent + 1) + "\n" +
      @second_expression.inspect(indent + 1)
end

#locationObject



895
896
897
# File 'lib/adlint/cpp/syntax.rb', line 895

def location
  @condition.location
end

#to_sObject



899
900
901
902
# File 'lib/adlint/cpp/syntax.rb', line 899

def to_s
  "#{@condition.to_s}? " +
    "#{@first_expression.to_s} : #{@second_expression.to_s}"
end