Class: AdLint::Cc1::CommaSeparatedExpression

Inherits:
Expression 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 Expression

#constant?, #full=, #object_specifiers

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(fst_expr) ⇒ CommaSeparatedExpression

Returns a new instance of CommaSeparatedExpression.



2200
2201
2202
2203
2204
# File 'lib/adlint/cc1/syntax.rb', line 2200

def initialize(fst_expr)
  super()
  @expressions = []
  push(fst_expr)
end

Instance Attribute Details

#expressionsObject (readonly)

Returns the value of attribute expressions.



2206
2207
2208
# File 'lib/adlint/cc1/syntax.rb', line 2206

def expressions
  @expressions
end

Instance Method Details

#arithmetic?Boolean

Returns:

  • (Boolean)


2220
2221
2222
# File 'lib/adlint/cc1/syntax.rb', line 2220

def arithmetic?
  @expressions.last.arithmetic?
end

#bitwise?Boolean

Returns:

  • (Boolean)


2224
2225
2226
# File 'lib/adlint/cc1/syntax.rb', line 2224

def bitwise?
  @expressions.last.bitwise?
end

#have_side_effect?Boolean

Returns:

  • (Boolean)


2212
2213
2214
# File 'lib/adlint/cc1/syntax.rb', line 2212

def have_side_effect?
  @expressions.any? { |expr| expr.have_side_effect? }
end

#inspect(indent = 0) ⇒ Object



2265
2266
2267
2268
# File 'lib/adlint/cc1/syntax.rb', line 2265

def inspect(indent = 0)
  " " * indent + "#{short_class_name}\n" +
    @expressions.map { |expr| expr.inspect(indent + 1) }.join("\n")
end

#locationObject



2208
2209
2210
# File 'lib/adlint/cc1/syntax.rb', line 2208

def location
  head_location
end

#logical?Boolean

Returns:

  • (Boolean)


2216
2217
2218
# File 'lib/adlint/cc1/syntax.rb', line 2216

def logical?
  @expressions.last.logical?
end

#push(expr) ⇒ Object



2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
# File 'lib/adlint/cc1/syntax.rb', line 2245

def push(expr)
  self.head_token = expr.head_token if @expressions.empty?
  @expressions.push(expr)
  self.tail_token = expr.tail_token

  # NOTE: The ISO C99 standard says;
  #
  # 6.5.17 Comma operator
  #
  # Semantics
  #
  # 2 The left operand of a comma operator is evaluated as a void
  #   expression; there is a sequence point after its evaluation.  Then the
  #   right operand is evaluated; the result has its type and value.  If an
  #   attempt is made to modify the result of a comma operator or to access
  #   it after the next sequence point, the behavior is undefined.
  @expressions[-2].append_sequence_point! if @expressions.size > 1
  self
end

#to_complemental_logicalObject



2237
2238
2239
# File 'lib/adlint/cc1/syntax.rb', line 2237

def to_complemental_logical
  @expressions.last.to_complemental_logical
end

#to_normalized_logical(parent_expr = nil) ⇒ Object



2228
2229
2230
2231
2232
2233
2234
2235
# File 'lib/adlint/cc1/syntax.rb', line 2228

def to_normalized_logical(parent_expr = nil)
  case parent_expr
  when nil, LogicalAndExpression, LogicalOrExpression
    create_normalized_logical_of(@expressions.last)
  else
    self
  end
end

#to_sObject



2241
2242
2243
# File 'lib/adlint/cc1/syntax.rb', line 2241

def to_s
  @expressions.map { |expr| expr.to_s }.join(",")
end