Class: IDL::RubyServantWriter
- Inherits:
-
RubyWriterBase
- Object
- RubyWriterBase
- IDL::RubyServantWriter
- Defined in:
- lib/ridlbe/ruby/walker.rb
Overview
RubyStubWriter
Instance Method Summary collapse
- #declare_interface(node) ⇒ Object
- #declare_struct(node) ⇒ Object
- #declare_union(node) ⇒ Object
- #declare_valuetype(node) ⇒ Object
- #enter_exception(node) ⇒ Object
- #enter_include(node) ⇒ Object
- #enter_interface(node) ⇒ Object
- #enter_module(node) ⇒ Object
- #enter_struct(node) ⇒ Object
- #enter_union(node) ⇒ Object
- #enter_valuetype(node) ⇒ Object
- #expression_to_s(exp) ⇒ Object
- #get_arg_type(_idl_argtype) ⇒ Object
- #get_typecode(_type) ⇒ Object
-
#initialize(output = STDOUT, params = {}, indent = ' ') ⇒ RubyServantWriter
constructor
A new instance of RubyServantWriter.
- #leave_exception(node) ⇒ Object
- #leave_include(node) ⇒ Object
- #leave_interface(node) ⇒ Object
- #leave_module(node) ⇒ Object
- #leave_struct(node) ⇒ Object
- #leave_union(node) ⇒ Object
- #leave_valuetype(node) ⇒ Object
- #operation_to_s(exp) ⇒ Object
- #post_visit(parser) ⇒ Object
- #pre_visit(parser) ⇒ Object
- #value_to_s(exp) ⇒ Object
- #visit_attribute(node) ⇒ Object
- #visit_const(node) ⇒ Object
- #visit_enum(node) ⇒ Object
- #visit_enumerator(node) ⇒ Object
- #visit_include(node) ⇒ Object
- #visit_operation(node) ⇒ Object
- #visit_typedef(node) ⇒ Object
- #visit_valuebox(node) ⇒ Object
Methods inherited from RubyWriterBase
#indent, #nest, #print, #printi, #printiln, #println, #visit_nodes
Constructor Details
#initialize(output = STDOUT, params = {}, indent = ' ') ⇒ RubyServantWriter
Returns a new instance of RubyServantWriter.
1120 1121 1122 1123 |
# File 'lib/ridlbe/ruby/walker.rb', line 1120 def initialize(output = STDOUT, params = {}, indent = ' ') super @stub_root = '::' end |
Instance Method Details
#declare_interface(node) ⇒ Object
1191 1192 1193 |
# File 'lib/ridlbe/ruby/walker.rb', line 1191 def declare_interface(node) printiln("class #{node.rubyname} < PortableServer::Servant; end ## servant forward") end |
#declare_struct(node) ⇒ Object
1569 |
# File 'lib/ridlbe/ruby/walker.rb', line 1569 def declare_struct(node); end |
#declare_union(node) ⇒ Object
1579 |
# File 'lib/ridlbe/ruby/walker.rb', line 1579 def declare_union(node); end |
#declare_valuetype(node) ⇒ Object
1245 |
# File 'lib/ridlbe/ruby/walker.rb', line 1245 def declare_valuetype(node); end |
#enter_exception(node) ⇒ Object
1575 |
# File 'lib/ridlbe/ruby/walker.rb', line 1575 def enter_exception(node); end |
#enter_include(node) ⇒ Object
1167 1168 1169 1170 1171 |
# File 'lib/ridlbe/ruby/walker.rb', line 1167 def enter_include(node) printiln('## include') printiln("CORBA.implement('#{node.filename}', {}, CORBA::IDL::SERVANT_INTF) {") println end |
#enter_interface(node) ⇒ Object
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 |
# File 'lib/ridlbe/ruby/walker.rb', line 1195 def enter_interface(node) unless node.is_local? println printiln("class #{node.rubyname} < PortableServer::Servant ## servant") println @nest += 1 printiln('module Intf') @nest += 1 printiln(format("Id = '%s'.freeze", node.repository_id)) printi('Ids = [ Id') if node.is_abstract? print(", 'IDL:omg.org/CORBA/AbstractBase:1.0'") end println(' ]') printiln('Operations = {}') println end end |
#enter_module(node) ⇒ Object
1179 1180 1181 1182 1183 |
# File 'lib/ridlbe/ruby/walker.rb', line 1179 def enter_module(node) printiln('module ' + node.rubyname) println @nest += 1 end |
#enter_struct(node) ⇒ Object
1571 |
# File 'lib/ridlbe/ruby/walker.rb', line 1571 def enter_struct(node); end |
#enter_union(node) ⇒ Object
1581 |
# File 'lib/ridlbe/ruby/walker.rb', line 1581 def enter_union(node); end |
#enter_valuetype(node) ⇒ Object
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 |
# File 'lib/ridlbe/ruby/walker.rb', line 1247 def enter_valuetype(node) println printiln("class #{node.rubyname} < PortableServer::Servant ## servant") @nest += 1 printiln('## valuetype interface') printiln("include #{@stub_root}#{node.scoped_rubyname}") println printiln('## object interfaces') node.interfaces.each do |intf| # printiln("include #{@stub_root}#{intf.scoped_rubyname}") printiln("include #{intf.scoped_rubyname}") end end |
#expression_to_s(exp) ⇒ Object
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 |
# File 'lib/ridlbe/ruby/walker.rb', line 1489 def expression_to_s(exp) case exp when Expression::Value value_to_s(exp) when Expression::Operation operation_to_s(exp) when Expression::ScopedName @stub_root + exp.node.scoped_rubyname else raise "unknown expression type: #{exp.class.name}" end end |
#get_arg_type(_idl_argtype) ⇒ Object
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 |
# File 'lib/ridlbe/ruby/walker.rb', line 1478 def get_arg_type(_idl_argtype) case _idl_argtype when IDL::AST::Parameter::IN 'CORBA::ARG_IN' when IDL::AST::Parameter::OUT 'CORBA::ARG_OUT' else 'CORBA::ARG_INOUT' end end |
#get_typecode(_type) ⇒ Object
1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 |
# File 'lib/ridlbe/ruby/walker.rb', line 1419 def get_typecode(_type) case _type when Type::Octet, Type::UShort, Type::Short, Type::ULong, Type::Long, Type::ULongLong, Type::LongLong, Type::Boolean, Type::Char, Type::WChar, Type::Float, Type::Double, Type::LongDouble, Type::Void, Type::Any s = _type.class.name.split('::') # IDL::Type::Octet -> [IDL, Type, Octet] s = s[s.length - 1] s.downcase! format('CORBA._tc_%s', s) when Type::Object 'CORBA._tc_Object' when Type::String if not _type.length.nil? format('CORBA::TypeCode::String.new(%d)', _type.length) else 'CORBA._tc_string' end when Type::WString if not _type.length.nil? format('CORBA::TypeCode::WString.new(%d)', _type.length) else 'CORBA._tc_wstring' end when Type::ScopedName @stub_root + _type.node.scoped_rubyname + '._tc' when Type::Array sep = '' tc = 'CORBA::TypeCode::Array.new(' + get_typecode(_type.basetype) + ', ' _type.sizes.each do |sz| tc += "#{sep}#{sz.to_s}" sep = ', ' end tc + ')' when Type::Sequence if _type.is_recursive? "CORBA::TypeCode::Sequence.new(CORBA::TypeCode::Recursive.new('#{_type.basetype.resolved_type.node.repository_id}'))" else 'CORBA::TypeCode::Sequence.new(' + get_typecode(_type.basetype) + if not _type.length.nil? then format(', %d)', _type.length) else ')' end + '.freeze' end else raise "invalid type for (un)marshalling: #{_type.typename}" end end |
#leave_exception(node) ⇒ Object
1577 |
# File 'lib/ridlbe/ruby/walker.rb', line 1577 def leave_exception(node); end |
#leave_include(node) ⇒ Object
1173 1174 1175 1176 1177 |
# File 'lib/ridlbe/ruby/walker.rb', line 1173 def leave_include(node) println printiln("} ## end of include '#{node.filename}'") println end |
#leave_interface(node) ⇒ Object
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 |
# File 'lib/ridlbe/ruby/walker.rb', line 1215 def leave_interface(node) unless node.is_local? name = node.rubyname @nest -= 1 printiln('end #of Intf') println printiln('Id = Intf::Id') println if node.bases.size > 0 node.bases.each do |n| printiln("include_interface(#{n.scoped_rubyname}::Intf)") end else printiln('include_interface(PortableServer::Servant::Intf)') end println printiln('include Intf') println printiln("def _this; #{@stub_root}#{node.scoped_rubyname}._narrow(super); end") @nest -= 1 printiln("end #of servant #{name}") end end |
#leave_module(node) ⇒ Object
1185 1186 1187 1188 1189 |
# File 'lib/ridlbe/ruby/walker.rb', line 1185 def leave_module(node) @nest -= 1 printiln("end #of module #{node.rubyname}") println end |
#leave_struct(node) ⇒ Object
1573 |
# File 'lib/ridlbe/ruby/walker.rb', line 1573 def leave_struct(node); end |
#leave_union(node) ⇒ Object
1583 |
# File 'lib/ridlbe/ruby/walker.rb', line 1583 def leave_union(node); end |
#leave_valuetype(node) ⇒ Object
1261 1262 1263 1264 |
# File 'lib/ridlbe/ruby/walker.rb', line 1261 def leave_valuetype(node) @nest -= 1 printiln("end #of servant #{node.rubyname}") end |
#operation_to_s(exp) ⇒ Object
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 |
# File 'lib/ridlbe/ruby/walker.rb', line 1533 def operation_to_s(exp) s = nil op = exp.operands case exp when Expression::UnaryPlus s = expression_to_s(op[0]) when Expression::UnaryMinus s = '-' + expression_to_s(op[0]) when Expression::UnaryNot s = '~' + expression_to_s(op[0]) when Expression::Xor s = expression_to_s(op[0]) + ' ^ ' + expression_to_s(op[1]) when Expression::Or s = expression_to_s(op[0]) + ' | ' + expression_to_s(op[1]) when Expression::And s = expression_to_s(op[0]) + ' & ' + expression_to_s(op[1]) when Expression::LShift s = expression_to_s(op[0]) + ' << ' + expression_to_s(op[1]) when Expression::RShift s = expression_to_s(op[0]) + ' >> ' + expression_to_s(op[1]) when Expression::Add s = expression_to_s(op[0]) + ' + ' + expression_to_s(op[1]) when Expression::Minus s = expression_to_s(op[0]) + ' - ' + expression_to_s(op[1]) when Expression::Mult s = expression_to_s(op[0]) + ' * ' + expression_to_s(op[1]) when Expression::Div s = expression_to_s(op[0]) + ' / ' + expression_to_s(op[1]) when Expression::Mod s = expression_to_s(op[0]) + ' % ' + expression_to_s(op[1]) else raise "unknown operation: #{exp.type.name}" end '(' + s + ')' end |
#post_visit(parser) ⇒ Object
1152 1153 1154 1155 1156 1157 1158 1159 1160 |
# File 'lib/ridlbe/ruby/walker.rb', line 1152 def post_visit(parser) idleval = @params[:idl_eval] || false unless idleval printiln("} ## end of '#{@params[:idlfile]}'") end @nest -= 1 printiln('end #of module POA') println('# -*- END -*-') end |
#pre_visit(parser) ⇒ Object
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 |
# File 'lib/ridlbe/ruby/walker.rb', line 1125 def pre_visit(parser) print( %Q{# -*- Ruby -*- # # **** Code generated by the R2CORBA IDL Compiler **** # R2CORBA has been developed by: # Remedy IT Expertise BV # The Netherlands # https://www.remedy.nl # }) idleval = @params[:idl_eval] || false println("require 'corba/poa.rb'") if @params[:libinit] unless @params[:expand_includes] println("require '" + @params[:idlfile].sub(/\.[^\.]*$/, @params[:stub_pfx]) + "'") end println printiln('module POA') @nest += 1 unless idleval printiln("CORBA.implement('#{@params[:idlfile]}', {}, CORBA::IDL::SERVANT_INTF) {") println end ## register explicit (*not* IDL derived) rootnamespace used for client stubs @stub_root = "#{parser.root_namespace.rubyname}::" unless parser.root_namespace.nil? end |
#value_to_s(exp) ⇒ Object
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 |
# File 'lib/ridlbe/ruby/walker.rb', line 1502 def value_to_s(exp) s = nil v = exp.value case exp.idltype when Type::Void s = 'nil' when Type::Char s = "'#{v.chr}'" when Type::Integer, Type::Boolean, Type::Octet, Type::Float, Type::WChar s = v.to_s when Type::Enum s = v.to_s when Type::String s = "'#{v.to_s}'" when Type::WString s = "[#{v.join(',')}]" # when Type::Fixed # when Type::Any # when Type::Object when Type::ScopedName s = value_to_s(Expression::Value.new(exp.idltype.node.idltype, v)) else raise "#{exp.typename}'s not been supported yet." end s end |
#visit_attribute(node) ⇒ Object
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 |
# File 'lib/ridlbe/ruby/walker.rb', line 1346 def visit_attribute(node) _intf = node.enclosure ## do nothing for valuetypes or local interfaces return nil if _intf.is_a?(IDL::AST::Valuetype) || _intf.is_local? printiln("Operations.store(:_get_#{node.name}, {") nest { nest { printiln(":result_type => #{get_typecode(node.idltype)},") if node.get_raises.size > 0 printi(':exc_list => [') pfx = '' nest { node.get_raises.each { |ex| println(pfx) pfx = ',' printi(get_typecode(ex)) } println('],') } end printiln(":op_sym => :#{node.rubyname} })") } } println printiln("def #{node.rubyname}()") nest { printiln('raise ::CORBA::NO_IMPLEMENT.new(') printiln(" 'unimplemented servant attribute get',") printiln(' 1, ::CORBA::COMPLETED_NO)') } printiln("end #of attribute get_#{node.name}") println unless node.readonly printiln("Operations.store(:_set_#{node.name}, {") nest { nest { printiln(':arg_list => [') nest { printiln("['val', CORBA::ARG_IN, #{get_typecode(node.idltype)}]],"); } printiln(':result_type => CORBA._tc_void,') if node.set_raises.size > 0 printi(':exc_list => [') pfx = '' nest { node.set_raises.each { |ex| println(pfx) pfx = ',' printi(get_typecode(ex)) } println('],') } end printiln(":op_sym => :#{node.rubyname}= })") } } println printiln("def #{node.rubyname}=(val)") nest { printiln('raise ::CORBA::NO_IMPLEMENT.new(') printiln(" 'unimplemented servant attribute set',") printiln(' 1, ::CORBA::COMPLETED_NO)') } printiln("end #of attribute set_#{node.name}") println end end |
#visit_const(node) ⇒ Object
1268 |
# File 'lib/ridlbe/ruby/walker.rb', line 1268 def visit_const(node); end |
#visit_enum(node) ⇒ Object
1585 |
# File 'lib/ridlbe/ruby/walker.rb', line 1585 def visit_enum(node); end |
#visit_enumerator(node) ⇒ Object
1587 |
# File 'lib/ridlbe/ruby/walker.rb', line 1587 def visit_enumerator(node); end |
#visit_include(node) ⇒ Object
1162 1163 1164 1165 |
# File 'lib/ridlbe/ruby/walker.rb', line 1162 def visit_include(node) printiln(format("require '%s'", node.filename.sub(/\.[^\.]*$/, @params[:srv_pfx]))) println end |
#visit_operation(node) ⇒ Object
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 |
# File 'lib/ridlbe/ruby/walker.rb', line 1270 def visit_operation(node) _parm = node.params _in = node.in_params _out = node.out_params _intf = node.enclosure ## do nothing for valuetypes or local interfaces return nil if _intf.is_a?(IDL::AST::Valuetype) || _intf.is_local? printi("Operations.store(:#{node.name}, {") newln = '' if _parm.size > 0 println(newln) nest do printi(':arg_list => [') nest { pfx = '' _parm.each do |p| println(pfx) printi("['#{p.rubyname}', #{get_arg_type(p.attribute)}, "); print(get_typecode(p.idltype)) print(']') pfx = ',' end print(']') } end newln = ',' end unless node.oneway println(newln) nest { printi(":result_type => #{get_typecode(node.idltype)}") } newln = ',' end if node.raises.size > 0 println(newln) nest { printi(':exc_list => [') pfx = '' nest { node.raises.each { |ex| println(pfx) pfx = ',' printi(get_typecode(ex)) } print(']') } } newln = ',' end if node.rubyname != node.name println(newln) nest { printi(":op_sym => :#{node.rubyname}") } end println('})') println printi("def #{node.rubyname}(") print(_in.collect{ |p| p.rubyname }.join(', ')) if node.oneway println(') # oneway') else println(')') end nest { printiln('raise ::CORBA::NO_IMPLEMENT.new(') printiln(" 'unimplemented servant operation',") printiln(' 1, ::CORBA::COMPLETED_NO)') } printiln('end') println end |
#visit_typedef(node) ⇒ Object
1589 |
# File 'lib/ridlbe/ruby/walker.rb', line 1589 def visit_typedef(node); end |
#visit_valuebox(node) ⇒ Object
1266 |
# File 'lib/ridlbe/ruby/walker.rb', line 1266 def visit_valuebox(node); end |