Class: ParamList

Inherits:
BDNode show all
Defined in:
lib/tecsgen/core/syntaxobj.rb

Overview

関数パラメータリスト

Instance Method Summary collapse

Methods inherited from BDNode

#get_owner, #set_owner

Methods inherited from Node

#cdl_error, #cdl_error2, #cdl_error3, #cdl_info, #cdl_info2, #cdl_warning, #cdl_warning2, #get_locale, #locale_str, #set_locale

Constructor Details

#initialize(paramdecl) ⇒ ParamList

@param_list

NamedList : item: ParamDecl



1019
1020
1021
1022
1023
1024
1025
# File 'lib/tecsgen/core/syntaxobj.rb', line 1019

def initialize(paramdecl)
  super()
  @param_list = NamedList.new(paramdecl, "parameter")
  @param_list.get_items.each {|paramdecl|
    paramdecl.set_owner self # ParamDecl
  }
end

Instance Method Details

#add_param(paramdecl) ⇒ Object



1027
1028
1029
1030
1031
1032
# File 'lib/tecsgen/core/syntaxobj.rb', line 1027

def add_param(paramdecl)
  return if paramdecl.nil? # 既にエラー

  @param_list.add_item(paramdecl)
  paramdecl.set_owner self # ParamDecl
end

#check_paramObject

size_is, count_is, string の引数の式をチェック

変数は前方参照可能なため、関数頭部の構文解釈が終わった後にチェックする



1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
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
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'lib/tecsgen/core/syntaxobj.rb', line 1040

def check_param
  @param_list.get_items.each {|i|
    next if i.nil? # i == nil : エラー時

    if i.get_type.class == VoidType
      # 単一の void 型はここにはこない
      cdl_error("S2027 '$1' parameter cannot be void type", i.get_name)
    end

    size = i.get_size # Expression
    if size
      val = size.eval_const(@param_list)
      if val.nil? # 定数式でないか?
        # mikan 変数を含む式:単一の変数のみ OK
        type = size.get_type(@param_list)
        unless type.is_a?(IntType)
          cdl_error("S2017 size_is argument is not integer type")
        else
          size.check_dir_for_param(@param_list, i.get_direction, "size_is")
        end
      else
        if val != Integer(val)
          cdl_error("S2018 \'$1\' size_is parameter not integer", i.get_declarator.get_identifier)
        elsif val <= 0
          cdl_error("S2019 \'$1\' size_is parameter negative or zero", i.get_declarator.get_identifier)
        end
      end
    end

    max = i.get_max
    if max
      val2 = max.eval_const(@param_list)
      if val2.nil?
        cdl_error("S2028 '$1' max (size_is 2nd parameter) not constant", i.get_name)
      elsif val2 != Integer(val2) || val2 <= 0
        cdl_error("S2029 '$1' max (size_is 2nd parameter) negative or zero, or not integer", i.get_name)
      end
    end

    if !val.nil? && !val2.nil?
      if val < val2
        cdl_warning("W3005 '$1' size_is always lower than max. max is ignored", i.get_name)
        i.clear_max
      else
        cdl_error("S2030 '$1' both size_is and max are const. size_is larger than max", i.get_name)
      end
    end

    count = i.get_count # Expression
    if count
      val = count.eval_const(@param_list)
      if val.nil? # 定数式でないか?
        # mikan 変数を含む式:単一の変数のみ OK
        type = count.get_type(@param_list)
        unless type.is_a?(IntType)
          cdl_error("S2020 count_is argument is not integer type")
        else
          count.check_dir_for_param(@param_list, i.get_direction, "count_is")
        end
      else
        if val != Integer(val)
          cdl_error("S2021 \'$1\' count_is parameter not integer", i.get_declarator.get_identifier)
        elsif val <= 0
          cdl_error("S2022 \'$1\' count_is parameter negative or zero", i.get_declarator.get_identifier)
        end
      end
    end

    string = i.get_string # Expression
    if string != -1 && string
      val = string.eval_const(@param_list)
      if val.nil? # 定数式でないか?
        # mikan 変数を含む式:単一の変数のみ OK
        type = string.get_type(@param_list)
        unless type.is_a?(IntType)
          cdl_error("S2023 string argument is not integer type")
        else
          string.check_dir_for_param(@param_list, i.get_direction, "string")
        end
      else
        if val != Integer(val)
          cdl_error("S2024 \'$1\' string parameter not integer", i.get_declarator.get_identifier)
        elsif val <= 0
          cdl_error("S2025 \'$1\' string parameter negative or zero", i.get_declarator.get_identifier)
        end
      end
    end
  }
end

#check_struct_tag(kind) ⇒ Object



1130
1131
1132
1133
1134
# File 'lib/tecsgen/core/syntaxobj.rb', line 1130

def check_struct_tag(kind)
  @param_list.get_items.each{|p|
    p.check_struct_tag kind
  }
end

#find(name) ⇒ Object



1147
1148
1149
# File 'lib/tecsgen/core/syntaxobj.rb', line 1147

def find(name)
  @param_list.get_item(name)
end

#get_itemsObject



1034
1035
1036
# File 'lib/tecsgen/core/syntaxobj.rb', line 1034

def get_items
  @param_list.get_items
end

#need_PPAllocator?(b_opaque = false) ⇒ Boolean

Push Pop Allocator が必要か?

Transparent RPC の場合 (oneway かつ) in の配列(size_is, count_is, string のいずれかで修飾)がある

Returns:

  • (Boolean)


1138
1139
1140
1141
1142
1143
1144
1145
# File 'lib/tecsgen/core/syntaxobj.rb', line 1138

def need_PPAllocator?(b_opaque = false)
  @param_list.get_items.each {|i|
    if i.need_PPAllocator?(b_opaque)
      return true
    end
  }
  false
end

#show_tree(indent) ⇒ Object



1168
1169
1170
1171
1172
# File 'lib/tecsgen/core/syntaxobj.rb', line 1168

def show_tree(indent)
  indent.times { print "  " }
  puts "ParamList: #{locale_str}"
  @param_list.show_tree(indent + 1)
end

#to_str(b_name) ⇒ Object

ParamList# 文字列化

b_name

Bool: パラメータ名を含める



1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
# File 'lib/tecsgen/core/syntaxobj.rb', line 1153

def to_str(b_name)
  str = "("
  delim = ""
  @param_list.get_items.each{|paramdecl|
    decl = paramdecl.get_declarator
    str += delim + decl.get_type
    if b_name
      str += " " + decl.get_name
    end
    str += decl.get_type_post
    delim = ", "
  }
  str += ")"
end