Class: Norikra::Query::ASTLibFunctionNode

Inherits:
ASTNode
  • Object
show all
Defined in:
lib/norikra/query/ast.rb

Overview

LIB_FUNCTION

Instance Attribute Summary

Attributes inherited from ASTNode

#children, #name, #tree

Instance Method Summary collapse

Methods inherited from ASTNode

#chain, #child, #find, #has_a?, #initialize, #listup, #to_a

Constructor Details

This class inherits a constructor from Norikra::Query::ASTNode

Instance Method Details

#fields(default_target = nil, known_targets_aliases = []) ⇒ Object



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
# File 'lib/norikra/query/ast.rb', line 1278

def fields(default_target=nil, known_targets_aliases=[])
  # class identifier is receiver: "IDENT.func()"
  identifier = self.find("classIdentifier")
  if identifier
    if identifier.children.size == 1 && Norikra::Query.imported_java_class?(identifier.find("escapableStr").child.name)
      # Java imported class name (ex: 'Math.abs(-1)')
      self.listup(:prop).map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
    else
      parts = identifier.listup('escapableStr').map{|node| node.child.name }
      target, fieldname = if parts.size == 1
                            [ default_target, parts.first ]
                          elsif known_targets_aliases.include?( parts.first )
                            [ parts[0], parts[1..-1].join(".") ]
                          else
                            [ default_target, parts.join(".") ]
                          end
      children_list = self.listup(:prop).map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
      [{f: fieldname, t: target}] + children_list
    end
  else
    if self.function_name.upcase == 'NULLABLE'
      props = self.listup(:prop).map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
      props.each do |def_item|
        def_item[:n] = true # nullable: true
      end
      props
    else
      self.listup(:prop).map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
    end
  end
end

#function_nameObject

escaped name access “‘T Table`.param.length()” [“libFunction”,

["libFunctionWithClass",
  ["classIdentifier",
    ["escapableStr", "`T Table`"],
    ".",
    ["escapableStr", "param"]],
  ".",
  ["funcIdentTop", ["escapableIdent", "length"]],
  "(",
  ")"]]


1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
# File 'lib/norikra/query/ast.rb', line 1256

def function_name
  if f = self.find("funcIdentTop")
    if e = f.find("escapableIdent")
      e.child.name
    else
      f.child.name
    end
  elsif f = self.find("funcIdentInner")
    if e = f.find("escapableIdent")
      e.child.name
    else
      f.child.name
    end
  else
    raise "BUG: unknown function AST"
  end
end

#nodetype?(*sym) ⇒ Boolean

Returns:

  • (Boolean)


1274
1275
1276
# File 'lib/norikra/query/ast.rb', line 1274

def nodetype?(*sym)
  sym.include?(:lib) || sym.include?(:libfunc)
end