Module: AdLint::Cc1::ExpressionEvaluator::Impl

Included in:
AdLint::Cc1::ExpressionEvaluator, ValueDomainManipulator
Defined in:
lib/adlint/cc1/expr.rb

Instance Method Summary collapse

Instance Method Details

#eval_additive_expr(node, lhs_obj, rhs_obj) ⇒ Object



920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
# File 'lib/adlint/cc1/expr.rb', line 920

def eval_additive_expr(node, lhs_obj, rhs_obj)
  lhs_var = object_to_variable(lhs_obj, node.lhs_operand)
  if !lhs_var.type.scalar? && !lhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  rhs_var = object_to_variable(rhs_obj, node.rhs_operand)
  if !rhs_var.type.scalar? && !rhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  lhs_conved, rhs_conved =
    do_usual_arithmetic_conversion(lhs_var, rhs_var)

  unless lhs_conved == lhs_var
    notify_implicit_conv_performed(node.lhs_operand, lhs_var, lhs_conved)
  end
  unless rhs_conved == rhs_var
    notify_implicit_conv_performed(node.rhs_operand, rhs_var, rhs_conved)
  end

  lhs_val = lhs_conved.value
  rhs_val = rhs_conved.value

  case node.operator.type
  when "+"
    # NOTE: Domain of the arithmetic result value will be restricted by
    #       min-max of the variable type.
    rslt_var = create_tmpvar(lhs_conved.type, lhs_val + rhs_val)
  when "-"
    # NOTE: Domain of the arithmetic result value will be restricted by
    #       min-max of the variable type.
    rslt_var = create_tmpvar(lhs_conved.type, lhs_val - rhs_val)
  else
    __NOTREACHED__
  end
  _notify_variable_value_referred(node, lhs_var)
  _notify_variable_value_referred(node, rhs_var)

  notify_additive_expr_evaled(node, lhs_var, rhs_var, rslt_var)
  rslt_var
end

#eval_address_expr(node, obj) ⇒ Object



774
775
776
777
778
779
780
781
782
783
# File 'lib/adlint/cc1/expr.rb', line 774

def eval_address_expr(node, obj)
  # NOTE: An address-expression does not read the value of the object.
  #       But value reference should be notified to emphasize global
  #       variable cross-references.
  _notify_variable_value_referred(node, obj)

  ptr = object_to_pointer(obj, node)
  notify_address_expr_evaled(node, obj, ptr)
  ptr
end

#eval_and_expr(node, lhs_obj, rhs_obj) ⇒ Object



1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/adlint/cc1/expr.rb', line 1106

def eval_and_expr(node, lhs_obj, rhs_obj)
  lhs_var = object_to_variable(lhs_obj, node.lhs_operand)
  if !lhs_var.type.scalar? && !lhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  rhs_var = object_to_variable(rhs_obj, node.rhs_operand)
  if !rhs_var.type.scalar? && !rhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  lhs_conved, rhs_conved =
    do_usual_arithmetic_conversion(lhs_var, rhs_var)

  unless lhs_conved == lhs_var
    notify_implicit_conv_performed(node.lhs_operand, lhs_var, lhs_conved)
  end
  unless rhs_conved == rhs_var
    notify_implicit_conv_performed(node.rhs_operand, rhs_var, rhs_conved)
  end

  lhs_val = lhs_conved.value
  rhs_val = rhs_conved.value

  # NOTE: Domain of the arithmetic result value will be restricted by
  #       min-max of the variable type.
  rslt_var = create_tmpvar(lhs_conved.type, lhs_val & rhs_val)
  _notify_variable_value_referred(node, lhs_var)
  _notify_variable_value_referred(node, rhs_var)

  notify_and_expr_evaled(node, lhs_var, rhs_var, rslt_var)
  rslt_var
end

#eval_array_subscript_expr(node, obj, subs) ⇒ Object



476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/adlint/cc1/expr.rb', line 476

def eval_array_subscript_expr(node, obj, subs)
  unless obj.variable? and obj.type.array? || obj.type.pointer?
    return create_tmpvar
  end

  rslt_type = obj.type.unqualify.base_type

  case
  when obj.type.array?
    ary = obj
    # NOTE: An array-subscript-expression with an array object only
    #       refers the array object, never refer the value of the array
    #       object.
  when obj.type.pointer?
    ptr = obj
    if pointee = pointee_of(ptr) and pointee.type.array?
      ary = pointee
    end
    # NOTE: An array-subscript-expression with a pointer object do refers
    #       the value of the pointer object.
    _notify_variable_value_referred(node, ptr)
  end

  unless subs.variable? and
      subs.value.scalar? && subs.value.exist? or subs.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar(rslt_type)
  end
  _notify_variable_value_referred(node, subs)

  # NOTE: An array subscript converted to `int' implicitly.
  unless subs.type.same_as?(int_t)
    if int_subs = do_conversion(subs, int_t)
      notify_implicit_conv_performed(node.array_subscript,
                                     subs, int_subs)
      subs = int_subs
    else
      return create_tmpvar(rslt_type)
    end
  end

  rslt_var = _pick_array_element(node, ary, subs, rslt_type)
  notify_array_subscript_expr_evaled(node, obj, subs, ary, rslt_var)
  rslt_var
end

#eval_bit_access_by_pointer_expr(node, obj) ⇒ Object



648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'lib/adlint/cc1/expr.rb', line 648

def eval_bit_access_by_pointer_expr(node, obj)
  obj_type = obj.type.unqualify
  if obj.variable? && obj_type.pointer? && obj_type.base_type.composite?
    ptr = obj
  else
    return create_tmpvar
  end

  if pointee = pointee_of(ptr)
    if pointee.type.array?
      if first_elem = pointee.inner_variable_at(0)
        pointee = first_elem
      else
        pointee = create_tmpvar(obj_type.base_type)
      end
    end
  end
  # NOTE: A bit-access-by-pointer-expression do refers the value of the
  #       pointer object.
  _notify_variable_value_referred(node, ptr)

  # TODO: Should support the GCC extension.
  create_tmpvar.tap do |rslt_var|
    notify_bit_access_expr_evaled(node, ptr, rslt_var)
  end
end

#eval_bit_access_by_value_expr(node, obj) ⇒ Object



635
636
637
638
639
640
641
642
643
644
645
646
# File 'lib/adlint/cc1/expr.rb', line 635

def eval_bit_access_by_value_expr(node, obj)
  if obj.variable? && obj.type.composite?
    outer_var = obj
  else
    return create_tmpvar
  end

  # TODO: Should support the GCC extension.
  create_tmpvar.tap do |rslt_var|
    notify_bit_access_expr_evaled(node, outer_var, rslt_var)
  end
end

#eval_cast_expr(node, obj) ⇒ Object



848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
# File 'lib/adlint/cc1/expr.rb', line 848

def eval_cast_expr(node, obj)
  resolve_unresolved_type(node.type_name)

  var = object_to_variable(obj, node)
  rslt_var = do_conversion(var, node.type_name.type) ||
             create_tmpvar(node.type_name.type)

  notify_explicit_conv_performed(node, var, rslt_var)

  # NOTE: A cast-expression does not refer a source value essentially.
  #       But, to avoid misunderstand that a return value of a function
  #       is discarded when the return value is casted before assigning
  #       to a variable.
  _notify_variable_value_referred(node, var)

  notify_cast_expr_evaled(node, var, rslt_var)
  rslt_var
end

#eval_compound_assignment_expr(node, lhs_obj, rhs_obj) ⇒ Object



1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
# File 'lib/adlint/cc1/expr.rb', line 1240

def eval_compound_assignment_expr(node, lhs_obj, rhs_obj)
  lhs_var = object_to_variable(lhs_obj, node.lhs_operand)
  if !lhs_var.type.scalar? && !lhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return lhs_obj
  end

  rhs_var = object_to_variable(rhs_obj, node.rhs_operand)
  if !rhs_var.type.scalar? && !rhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return lhs_var
  end

  case node.operator.type
  when "*="
    _do_mul_then_assign(node, lhs_var, rhs_var)
  when "/="
    _do_div_then_assign(node, lhs_var, rhs_var)
  when "%="
    _do_mod_then_assign(node, lhs_var, rhs_var)
  when "+="
    _do_add_then_assign(node, lhs_var, rhs_var)
  when "-="
    _do_sub_then_assign(node, lhs_var, rhs_var)
  when "<<="
    _do_shl_then_assign(node, lhs_var, rhs_var)
  when ">>="
    _do_shr_then_assign(node, lhs_var, rhs_var)
  when "&="
    _do_and_then_assign(node, lhs_var, rhs_var)
  when "^="
    _do_xor_then_assign(node, lhs_var, rhs_var)
  when "|="
    _do_ior_then_assign(node, lhs_var, rhs_var)
  end

  lhs_var
end

#eval_compound_literal_expr(node) ⇒ Object



767
768
769
770
771
772
# File 'lib/adlint/cc1/expr.rb', line 767

def eval_compound_literal_expr(node)
  # TODO: Should support C99 features.
  create_tmpvar(node.type_name.type).tap do |rslt_var|
    notify_compound_literal_expr_evaled(node, rslt_var)
  end
end

#eval_equality_expr(node, lhs_obj, rhs_obj) ⇒ Object



1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
# File 'lib/adlint/cc1/expr.rb', line 1065

def eval_equality_expr(node, lhs_obj, rhs_obj)
  lhs_var = object_to_variable(lhs_obj, node.lhs_operand)
  if !lhs_var.type.scalar? && !lhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar(int_t, scalar_value_of_arbitrary)
  end

  rhs_var = object_to_variable(rhs_obj, node.rhs_operand)
  if !rhs_var.type.scalar? && !rhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar(int_t, scalar_value_of_arbitrary)
  end

  lhs_conved, rhs_conved =
    do_usual_arithmetic_conversion(lhs_var, rhs_var)

  unless lhs_conved == lhs_var
    notify_implicit_conv_performed(node.lhs_operand, lhs_var, lhs_conved)
  end
  unless rhs_conved == rhs_var
    notify_implicit_conv_performed(node.rhs_operand, rhs_var, rhs_conved)
  end

  lhs_val = lhs_conved.value
  rhs_val = rhs_conved.value

  case node.operator.type
  when "=="
    rslt_var = create_tmpvar(int_t, lhs_val == rhs_val)
  when "!="
    rslt_var = create_tmpvar(int_t, lhs_val != rhs_val)
  else
    __NOTREACHED__
  end
  _notify_variable_value_referred(node, lhs_var)
  _notify_variable_value_referred(node, rhs_var)

  notify_equality_expr_evaled(node, lhs_var, rhs_var, rslt_var)
  rslt_var
end

#eval_exclusive_or_expr(node, lhs_obj, rhs_obj) ⇒ Object



1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
# File 'lib/adlint/cc1/expr.rb', line 1142

def eval_exclusive_or_expr(node, lhs_obj, rhs_obj)
  lhs_var = object_to_variable(lhs_obj, node.lhs_operand)
  if !lhs_var.type.scalar? && !lhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  rhs_var = object_to_variable(rhs_obj, node.rhs_operand)
  if !rhs_var.type.scalar? && !rhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  lhs_conved, rhs_conved =
    do_usual_arithmetic_conversion(lhs_var, rhs_var)

  unless lhs_conved == lhs_var
    notify_implicit_conv_performed(node.lhs_operand, lhs_var, lhs_conved)
  end
  unless rhs_conved == rhs_var
    notify_implicit_conv_performed(node.rhs_operand, rhs_var, rhs_conved)
  end

  lhs_val = lhs_conved.value
  rhs_val = rhs_conved.value

  # NOTE: Domain of the arithmetic result value will be restricted by
  #       min-max of the variable type.
  rslt_var = create_tmpvar(lhs_conved.type, lhs_val ^ rhs_val)
  _notify_variable_value_referred(node, lhs_var)
  _notify_variable_value_referred(node, rhs_var)

  notify_exclusive_or_expr_evaled(node, lhs_var, rhs_var, rslt_var)
  rslt_var
end

#eval_function_call_expr(node, obj, args) ⇒ Object



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/adlint/cc1/expr.rb', line 522

def eval_function_call_expr(node, obj, args)
  if obj.function?
    fun = obj
  else
    return create_tmpvar unless obj.type.pointer?
    obj_base_type = obj.type.unqualify.base_type
    if obj_base_type.function?
      if pointee = pointee_of(obj) and pointee.function?
        fun = pointee
      else
        fun = define_anonymous_function(obj_base_type)
      end
    end
  end
  _notify_variable_value_referred(node, obj)

  # NOTE: The ISO C99 standard says;
  #
  # 6.5.2.2 Function calls
  #
  # Semantics
  #
  # 10 The order of evaluation of the function designator, the actual
  #    arguments, and subexpressions within the actual arguments is
  #    unspecified, but there is a sequence point before the actual call.
  unless args.empty?
    notify_sequence_point_reached(SequencePoint.new(node))
  end

  rslt_var = nil
  break_event = BreakEvent.catch {
    rslt_var = fun.call(interpreter, node, args)
  }

  unless fun.builtin?
    arg_vars = args.map { |arg_obj, arg_expr|
      object_to_variable(arg_obj, arg_expr)
    }
    notify_function_call_expr_evaled(node, fun, arg_vars, rslt_var)
  end

  if break_event
    break_event.throw
  else
    rslt_var
  end
end

#eval_inclusive_or_expr(node, lhs_obj, rhs_obj) ⇒ Object



1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
# File 'lib/adlint/cc1/expr.rb', line 1178

def eval_inclusive_or_expr(node, lhs_obj, rhs_obj)
  lhs_var = object_to_variable(lhs_obj, node.lhs_operand)
  if !lhs_var.type.scalar? && !lhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  rhs_var = object_to_variable(rhs_obj, node.rhs_operand)
  if !rhs_var.type.scalar? && !rhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  lhs_conved, rhs_conved =
    do_usual_arithmetic_conversion(lhs_var, rhs_var)

  unless lhs_conved == lhs_var
    notify_implicit_conv_performed(node.lhs_operand, lhs_var, lhs_conved)
  end
  unless rhs_conved == rhs_var
    notify_implicit_conv_performed(node.rhs_operand, rhs_var, rhs_conved)
  end

  lhs_val = lhs_conved.value
  rhs_val = rhs_conved.value

  # NOTE: Domain of the arithmetic result value will be restricted by
  #       min-max of the variable type.
  rslt_var = create_tmpvar(lhs_conved.type, lhs_val | rhs_val)
  _notify_variable_value_referred(node, lhs_var)
  _notify_variable_value_referred(node, rhs_var)

  notify_inclusive_or_expr_evaled(node, lhs_var, rhs_var, rslt_var)
  rslt_var
end

#eval_indirection_expr(node, obj) ⇒ Object



785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
# File 'lib/adlint/cc1/expr.rb', line 785

def eval_indirection_expr(node, obj)
  var = object_to_variable(obj, node)
  if var.type.pointer?
    ptr = var
  else
    return create_tmpvar
  end

  pointee = pointee_of(ptr)
  _notify_variable_value_referred(node, ptr)

  ptr_base_type = ptr.type.unqualify.base_type

  case
  when pointee
    _notify_object_referred(node, pointee)
    if pointee.type.array?
      if first_elem = pointee.inner_variable_at(0)
        pointee = first_elem
      else
        pointee = create_tmpvar(ptr_base_type)
      end
    end

    unless ptr_base_type.same_as?(pointee.type)
      pointee = do_conversion(pointee, ptr_base_type) ||
                create_tmpvar(ptr_base_type)
    end
  when ptr_base_type.function?
    pointee = define_anonymous_function(ptr_base_type)
  else
    pointee = create_tmpvar(ptr_base_type)
  end

  notify_indirection_expr_evaled(node, ptr, pointee)
  pointee
end

#eval_member_access_by_pointer_expr(node, obj) ⇒ Object



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
# File 'lib/adlint/cc1/expr.rb', line 593

def eval_member_access_by_pointer_expr(node, obj)
  obj_type = obj.type.unqualify
  if obj.variable? && obj_type.pointer? && obj_type.base_type.composite?
    ptr = obj
  else
    return create_tmpvar
  end

  if pointee = pointee_of(ptr)
    if pointee.type.array?
      if first_elem = pointee.inner_variable_at(0)
        pointee = first_elem
      else
        pointee = create_tmpvar(obj_type.base_type)
      end
    end
  end
  # NOTE: A member-access-by-pointer-expression do refers the value of
  #       the pointer object.
  _notify_variable_value_referred(node, ptr)

  if pointee && pointee.type.composite?
    outer_var = pointee
    memb_var = outer_var.inner_variable_named(node.identifier.value)
  else
    if memb = obj_type.base_type.member_named(node.identifier.value)
      memb_var = create_tmpvar(memb.type)
    end
  end

  # NOTE: `memb_var' is nil when this expression represents the direct
  #       member access extension.
  notify_member_access_expr_evaled(node, ptr, memb_var)

  if memb_var
    _notify_object_referred(node, memb_var)
    memb_var
  else
    create_tmpvar
  end
end

#eval_member_access_by_value_expr(node, obj) ⇒ Object



570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
# File 'lib/adlint/cc1/expr.rb', line 570

def eval_member_access_by_value_expr(node, obj)
  if obj.variable? && obj.type.composite?
    outer_var = obj
  else
    return create_tmpvar
  end

  memb_var = outer_var.inner_variable_named(node.identifier.value)
  # NOTE: A member-access-by-value-expression only refers the composite
  #       object, never refer the value of the composite object.

  # NOTE: `memb_var' is nil when this expression represents the direct
  #       member access extension.
  notify_member_access_expr_evaled(node, outer_var, memb_var)

  if memb_var
    _notify_object_referred(node, memb_var)
    memb_var
  else
    create_tmpvar
  end
end

#eval_multiplicative_expr(node, lhs_obj, rhs_obj) ⇒ Object



867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
# File 'lib/adlint/cc1/expr.rb', line 867

def eval_multiplicative_expr(node, lhs_obj, rhs_obj)
  lhs_var = object_to_variable(lhs_obj, node.lhs_operand)
  if !lhs_var.type.scalar? && !lhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  rhs_var = object_to_variable(rhs_obj, node.rhs_operand)
  if !rhs_var.type.scalar? && !rhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  lhs_conved, rhs_conved =
    do_usual_arithmetic_conversion(lhs_var, rhs_var)

  unless lhs_conved == lhs_var
    notify_implicit_conv_performed(node.lhs_operand, lhs_var, lhs_conved)
  end
  unless rhs_conved == rhs_var
    notify_implicit_conv_performed(node.rhs_operand, rhs_var, rhs_conved)
  end

  lhs_val = lhs_conved.value
  rhs_val = rhs_conved.value

  case node.operator.type
  when "*"
    # NOTE: Domain of the arithmetic result value will be restricted by
    #       min-max of the variable type.
    rslt_var = create_tmpvar(lhs_conved.type, lhs_val * rhs_val)
  when "/"
    # NOTE: Domain of the arithmetic result value will be restricted by
    #       min-max of the variable type.
    # NOTE: "Div by 0" semantics is implemented in value-value
    #       arithmetic.
    rslt_var = create_tmpvar(lhs_conved.type, lhs_val / rhs_val)
  when "%"
    # NOTE: Domain of the arithmetic result value will be restricted by
    #       min-max of the variable type.
    # NOTE: "Div by 0" semantics is implemented in value-value
    #       arithmetic.
    rslt_var = create_tmpvar(lhs_conved.type, lhs_val % rhs_val)
  else
    __NOTREACHED__
  end
  _notify_variable_value_referred(node, lhs_var)
  _notify_variable_value_referred(node, rhs_var)

  notify_multiplicative_expr_evaled(node, lhs_var, rhs_var, rslt_var)
  rslt_var
end

#eval_object_specifier(node) ⇒ Object

NOTE: Host class of this module must include InterpreterMediator,

NotifierMediator and Conversion.


446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/adlint/cc1/expr.rb', line 446

def eval_object_specifier(node)
  case
  when var = variable_named(node.identifier.value)
    var.declarations_and_definitions.each do |dcl_or_def|
      dcl_or_def.mark_as_referred_by(node.identifier)
    end
    _notify_object_referred(node, var)
    # NOTE: Array object will be converted into its start address by the
    #       outer expression.  So, it is correct to return an array
    #       object itself.
    rslt_obj = var
  when fun = function_named(node.identifier.value)
    fun.declarations_and_definitions.each do |dcl_or_def|
      dcl_or_def.mark_as_referred_by(node.identifier)
    end
    _notify_object_referred(node, fun)
    rslt_obj = fun
  when enum = enumerator_named(node.identifier.value)
    enum.mark_as_referred_by(node.identifier)
    rslt_obj = create_tmpvar(enum.type, scalar_value_of(enum.value))
  else
    fun = declare_implicit_function(node.identifier.value)
    _notify_implicit_function_declared(node, fun)
    _notify_object_referred(node, fun)
    rslt_obj = fun
  end
  notify_object_specifier_evaled(node, rslt_obj)
  rslt_obj
end

#eval_postfix_decrement_expr(node, obj) ⇒ Object



698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
# File 'lib/adlint/cc1/expr.rb', line 698

def eval_postfix_decrement_expr(node, obj)
  var = object_to_variable(obj, node)
  if !var.type.scalar? && !var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  rslt_var = create_tmpvar(var.type, var.value.dup)

  # NOTE: Value of the variable is referred at this point.  But value
  #       reference should not be notified not to confuse sequence-point
  #       warnings detections.
  # _notify_variable_value_referred(node, var)

  if var.value.scalar?
    var.assign!(var.value - scalar_value_of(1), node, current_branch)
    _notify_variable_value_updated(node, var)
  end

  notify_postfix_decrement_expr_evaled(node, var, rslt_var)
  rslt_var
end

#eval_postfix_increment_expr(node, obj) ⇒ Object



675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
# File 'lib/adlint/cc1/expr.rb', line 675

def eval_postfix_increment_expr(node, obj)
  var = object_to_variable(obj, node)
  if !var.type.scalar? && !var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  rslt_var = create_tmpvar(var.type, var.value.dup)

  # NOTE: Value of the variable is referred at this point.  But value
  #       reference should not be notified not to confuse sequence-point
  #       warning detections.
  # _notify_variable_value_referred(node, var)

  if var.value.scalar?
    var.assign!(var.value + scalar_value_of(1), node, current_branch)
    _notify_variable_value_updated(node, var)
  end

  notify_postfix_increment_expr_evaled(node, var, rslt_var)
  rslt_var
end

#eval_prefix_decrement_expr(node, obj) ⇒ Object



744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'lib/adlint/cc1/expr.rb', line 744

def eval_prefix_decrement_expr(node, obj)
  var = object_to_variable(obj, node)
  if !var.type.scalar? && !var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  orig_val = var.value.dup

  # NOTE: Value of the variable is referred at this point.  But value
  #       reference should not be notified not to confuse sequence-point
  #       warning detections.
  # _notify_variable_value_referred(node, var)

  if var.value.scalar?
    var.assign!(var.value - scalar_value_of(1), node, current_branch)
    _notify_variable_value_updated(node, var)
  end

  notify_prefix_decrement_expr_evaled(node, var, orig_val)
  create_tmpvar(var.type, var.value)
end

#eval_prefix_increment_expr(node, obj) ⇒ Object



721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
# File 'lib/adlint/cc1/expr.rb', line 721

def eval_prefix_increment_expr(node, obj)
  var = object_to_variable(obj, node)
  if !var.type.scalar? && !var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  orig_val = var.value.dup

  # NOTE: Value of the variable is referred at this point.  But value
  #       reference should not be notified not to confuse sequence-point
  #       warnings detections.
  # _notify_variable_value_referred(node, var)

  if var.value.scalar?
    var.assign!(var.value + scalar_value_of(1), node, current_branch)
    _notify_variable_value_updated(node, var)
  end

  notify_prefix_increment_expr_evaled(node, var, orig_val)
  create_tmpvar(var.type, var.value)
end

#eval_relational_expr(node, lhs_obj, rhs_obj) ⇒ Object



1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
# File 'lib/adlint/cc1/expr.rb', line 1020

def eval_relational_expr(node, lhs_obj, rhs_obj)
  lhs_var = object_to_variable(lhs_obj, node.lhs_operand)
  if !lhs_var.type.scalar? && !lhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar(int_t, scalar_value_of_arbitrary)
  end

  rhs_var = object_to_variable(rhs_obj, node.rhs_operand)
  if !rhs_var.type.scalar? && !rhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar(int_t, scalar_value_of_arbitrary)
  end

  lhs_conved, rhs_conved =
    do_usual_arithmetic_conversion(lhs_var, rhs_var)

  unless lhs_conved == lhs_var
    notify_implicit_conv_performed(node.lhs_operand, lhs_var, lhs_conved)
  end
  unless rhs_conved == rhs_var
    notify_implicit_conv_performed(node.rhs_operand, rhs_var, rhs_conved)
  end

  lhs_val = lhs_conved.value
  rhs_val = rhs_conved.value

  case node.operator.type
  when "<"
    rslt_var = create_tmpvar(int_t, lhs_val <  rhs_val)
  when ">"
    rslt_var = create_tmpvar(int_t, lhs_val >  rhs_val)
  when "<="
    rslt_var = create_tmpvar(int_t, lhs_val <= rhs_val)
  when ">="
    rslt_var = create_tmpvar(int_t, lhs_val >= rhs_val)
  else
    __NOTREACHED__
  end
  _notify_variable_value_referred(node, lhs_var)
  _notify_variable_value_referred(node, rhs_var)

  notify_relational_expr_evaled(node, lhs_var, rhs_var, rslt_var)
  rslt_var
end

#eval_shift_expr(node, lhs_obj, rhs_obj) ⇒ Object



965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
# File 'lib/adlint/cc1/expr.rb', line 965

def eval_shift_expr(node, lhs_obj, rhs_obj)
  lhs_var = object_to_variable(lhs_obj, node.lhs_operand)
  if !lhs_var.type.scalar? && !lhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  rhs_var = object_to_variable(rhs_obj, node.rhs_operand)
  if !rhs_var.type.scalar? && !rhs_var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  # NOTE: The ISO C99 standard says;
  #
  # 6.5.7 Bitwise shift operators
  #
  # 3 The integer promotions are performed on each of the operands.  The
  #   type of the result is that of the promoted left operand.  If the
  #   value of the right operand is negative or is greater than or equal
  #   to the width of the promoted left operand, the behavior is
  #   undefined.

  lhs_conved = do_integer_promotion(lhs_var)
  rhs_conved = do_integer_promotion(rhs_var)

  unless lhs_conved == lhs_var
    notify_implicit_conv_performed(node.lhs_operand, lhs_var, lhs_conved)
  end
  unless rhs_conved == rhs_var
    notify_implicit_conv_performed(node.rhs_operand, rhs_var, rhs_conved)
  end

  lhs_val = lhs_conved.value
  rhs_val = rhs_conved.value

  case node.operator.type
  when "<<"
    # NOTE: Domain of the arithmetic result value will be restricted by
    #       min-max of the variable type.
    rslt_var = create_tmpvar(lhs_conved.type, lhs_val << rhs_val)
  when ">>"
    # NOTE: Domain of the arithmetic result value will be restricted by
    #       min-max of the variable type.
    rslt_var = create_tmpvar(lhs_conved.type, lhs_val >> rhs_val)
  else
    __NOTREACHED__
  end
  _notify_variable_value_referred(node, lhs_var)
  _notify_variable_value_referred(node, rhs_var)

  notify_shift_expr_evaled(node, lhs_var, rhs_var, rslt_var)
  rslt_var
end

#eval_simple_assignment_expr(node, lhs_obj, rhs_obj) ⇒ Object



1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
# File 'lib/adlint/cc1/expr.rb', line 1214

def eval_simple_assignment_expr(node, lhs_obj, rhs_obj)
  lhs_var = object_to_variable(lhs_obj, node.lhs_operand)
  rhs_var = object_to_variable(rhs_obj, node.rhs_operand)

  if rhs_var.type.same_as?(lhs_var.type)
    rhs_conved = rhs_var
  else
    rhs_conved = do_conversion(rhs_var, lhs_var.type) ||
                 create_tmpvar(lhs_var.type)
    notify_implicit_conv_performed(node.rhs_operand, rhs_var, rhs_conved)
  end

  # NOTE: Domain of the arithmetic result value will be restricted by
  #       min-max of the variable type.
  # NOTE: Even if rhs_obj is a NamedVariable, new value will be
  #       instantiated in value-coercing.
  #       So, value-aliasing never occurs.
  defined_val = rhs_conved.value.to_defined_value
  lhs_var.assign!(defined_val, node, current_branch)
  _notify_variable_value_referred(node, rhs_var)
  _notify_variable_value_updated(node, lhs_var)

  notify_assignment_expr_evaled(node, lhs_var, rhs_var)
  lhs_var
end

#eval_unary_arithmetic_expr(node, obj) ⇒ Object



823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
# File 'lib/adlint/cc1/expr.rb', line 823

def eval_unary_arithmetic_expr(node, obj)
  var = object_to_variable(obj, node)
  if !var.type.scalar? && !var.type.void?
    # NOTE: To detect bad value reference of `void' expressions.
    return create_tmpvar
  end

  case node.operator.type
  when "+"
    rslt_var = create_tmpvar(var.type, +var.value)
  when "-"
    rslt_var = create_tmpvar(var.type, -var.value)
  when "~"
    rslt_var = create_tmpvar(var.type, ~var.value)
  when "!"
    rslt_var = create_tmpvar(int_t, !var.value)
  else
    __NOTREACHED__
  end
  _notify_variable_value_referred(node, var)

  notify_unary_arithmetic_expr_evaled(node, var, rslt_var)
  rslt_var
end