Skip to content

Commit 5735ac3

Browse files
committed
Ruby: Regenerate raw AST
1 parent 5348c7d commit 5735ac3

1 file changed

Lines changed: 350 additions & 0 deletions

File tree

ruby/ql/lib/codeql/ruby/ast/internal/TreeSitter.qll

Lines changed: 350 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,340 @@ module Ruby {
19641964
/** Gets a field or child node of this node. */
19651965
final override AstNode getAFieldOrChild() { ruby_yield_child(this, result) }
19661966
}
1967+
1968+
/** Provides predicates for mapping AST nodes to their named children. */
1969+
module PrintAst {
1970+
/** Gets a child of `node` returned by the member predicate with the given `name`. If the predicate takes an index argument, `i` is bound to that index, otherwise `i` is `-1` (which is never a valid index). */
1971+
AstNode getChild(AstNode node, string name, int i) {
1972+
result = node.(Alias).getAlias() and i = -1 and name = "getAlias"
1973+
or
1974+
result = node.(Alias).getName() and i = -1 and name = "getName"
1975+
or
1976+
result = node.(AlternativePattern).getAlternatives(i) and name = "getAlternatives"
1977+
or
1978+
result = node.(ArgumentList).getChild(i) and name = "getChild"
1979+
or
1980+
result = node.(Array).getChild(i) and name = "getChild"
1981+
or
1982+
result = node.(ArrayPattern).getClass() and i = -1 and name = "getClass"
1983+
or
1984+
result = node.(ArrayPattern).getChild(i) and name = "getChild"
1985+
or
1986+
result = node.(AsPattern).getName() and i = -1 and name = "getName"
1987+
or
1988+
result = node.(AsPattern).getValue() and i = -1 and name = "getValue"
1989+
or
1990+
result = node.(Assignment).getLeft() and i = -1 and name = "getLeft"
1991+
or
1992+
result = node.(Assignment).getRight() and i = -1 and name = "getRight"
1993+
or
1994+
result = node.(BareString).getChild(i) and name = "getChild"
1995+
or
1996+
result = node.(BareSymbol).getChild(i) and name = "getChild"
1997+
or
1998+
result = node.(Begin).getChild(i) and name = "getChild"
1999+
or
2000+
result = node.(BeginBlock).getChild(i) and name = "getChild"
2001+
or
2002+
result = node.(Binary).getLeft() and i = -1 and name = "getLeft"
2003+
or
2004+
result = node.(Binary).getRight() and i = -1 and name = "getRight"
2005+
or
2006+
result = node.(Block).getBody() and i = -1 and name = "getBody"
2007+
or
2008+
result = node.(Block).getParameters() and i = -1 and name = "getParameters"
2009+
or
2010+
result = node.(BlockArgument).getChild() and i = -1 and name = "getChild"
2011+
or
2012+
result = node.(BlockBody).getChild(i) and name = "getChild"
2013+
or
2014+
result = node.(BlockParameter).getName() and i = -1 and name = "getName"
2015+
or
2016+
result = node.(BlockParameters).getLocals(i) and name = "getLocals"
2017+
or
2018+
result = node.(BlockParameters).getChild(i) and name = "getChild"
2019+
or
2020+
result = node.(BodyStatement).getChild(i) and name = "getChild"
2021+
or
2022+
result = node.(Break).getChild() and i = -1 and name = "getChild"
2023+
or
2024+
result = node.(Call).getArguments() and i = -1 and name = "getArguments"
2025+
or
2026+
result = node.(Call).getBlock() and i = -1 and name = "getBlock"
2027+
or
2028+
result = node.(Call).getMethod() and i = -1 and name = "getMethod"
2029+
or
2030+
result = node.(Call).getOperator() and i = -1 and name = "getOperator"
2031+
or
2032+
result = node.(Call).getReceiver() and i = -1 and name = "getReceiver"
2033+
or
2034+
result = node.(Case).getValue() and i = -1 and name = "getValue"
2035+
or
2036+
result = node.(Case).getChild(i) and name = "getChild"
2037+
or
2038+
result = node.(CaseMatch).getClauses(i) and name = "getClauses"
2039+
or
2040+
result = node.(CaseMatch).getElse() and i = -1 and name = "getElse"
2041+
or
2042+
result = node.(CaseMatch).getValue() and i = -1 and name = "getValue"
2043+
or
2044+
result = node.(ChainedString).getChild(i) and name = "getChild"
2045+
or
2046+
result = node.(Class).getBody() and i = -1 and name = "getBody"
2047+
or
2048+
result = node.(Class).getName() and i = -1 and name = "getName"
2049+
or
2050+
result = node.(Class).getSuperclass() and i = -1 and name = "getSuperclass"
2051+
or
2052+
result = node.(Complex).getChild() and i = -1 and name = "getChild"
2053+
or
2054+
result = node.(Conditional).getAlternative() and i = -1 and name = "getAlternative"
2055+
or
2056+
result = node.(Conditional).getCondition() and i = -1 and name = "getCondition"
2057+
or
2058+
result = node.(Conditional).getConsequence() and i = -1 and name = "getConsequence"
2059+
or
2060+
result = node.(DelimitedSymbol).getChild(i) and name = "getChild"
2061+
or
2062+
result = node.(DestructuredLeftAssignment).getChild(i) and name = "getChild"
2063+
or
2064+
result = node.(DestructuredParameter).getChild(i) and name = "getChild"
2065+
or
2066+
result = node.(Do).getChild(i) and name = "getChild"
2067+
or
2068+
result = node.(DoBlock).getBody() and i = -1 and name = "getBody"
2069+
or
2070+
result = node.(DoBlock).getParameters() and i = -1 and name = "getParameters"
2071+
or
2072+
result = node.(ElementReference).getBlock() and i = -1 and name = "getBlock"
2073+
or
2074+
result = node.(ElementReference).getObject() and i = -1 and name = "getObject"
2075+
or
2076+
result = node.(ElementReference).getChild(i) and name = "getChild"
2077+
or
2078+
result = node.(Else).getChild(i) and name = "getChild"
2079+
or
2080+
result = node.(Elsif).getAlternative() and i = -1 and name = "getAlternative"
2081+
or
2082+
result = node.(Elsif).getCondition() and i = -1 and name = "getCondition"
2083+
or
2084+
result = node.(Elsif).getConsequence() and i = -1 and name = "getConsequence"
2085+
or
2086+
result = node.(EndBlock).getChild(i) and name = "getChild"
2087+
or
2088+
result = node.(Ensure).getChild(i) and name = "getChild"
2089+
or
2090+
result = node.(ExceptionVariable).getChild() and i = -1 and name = "getChild"
2091+
or
2092+
result = node.(Exceptions).getChild(i) and name = "getChild"
2093+
or
2094+
result = node.(ExpressionReferencePattern).getValue() and i = -1 and name = "getValue"
2095+
or
2096+
result = node.(FindPattern).getClass() and i = -1 and name = "getClass"
2097+
or
2098+
result = node.(FindPattern).getChild(i) and name = "getChild"
2099+
or
2100+
result = node.(For).getBody() and i = -1 and name = "getBody"
2101+
or
2102+
result = node.(For).getPattern() and i = -1 and name = "getPattern"
2103+
or
2104+
result = node.(For).getValue() and i = -1 and name = "getValue"
2105+
or
2106+
result = node.(Hash).getChild(i) and name = "getChild"
2107+
or
2108+
result = node.(HashPattern).getClass() and i = -1 and name = "getClass"
2109+
or
2110+
result = node.(HashPattern).getChild(i) and name = "getChild"
2111+
or
2112+
result = node.(HashSplatArgument).getChild() and i = -1 and name = "getChild"
2113+
or
2114+
result = node.(HashSplatParameter).getName() and i = -1 and name = "getName"
2115+
or
2116+
result = node.(HeredocBody).getChild(i) and name = "getChild"
2117+
or
2118+
result = node.(If).getAlternative() and i = -1 and name = "getAlternative"
2119+
or
2120+
result = node.(If).getCondition() and i = -1 and name = "getCondition"
2121+
or
2122+
result = node.(If).getConsequence() and i = -1 and name = "getConsequence"
2123+
or
2124+
result = node.(IfGuard).getCondition() and i = -1 and name = "getCondition"
2125+
or
2126+
result = node.(IfModifier).getBody() and i = -1 and name = "getBody"
2127+
or
2128+
result = node.(IfModifier).getCondition() and i = -1 and name = "getCondition"
2129+
or
2130+
result = node.(In).getChild() and i = -1 and name = "getChild"
2131+
or
2132+
result = node.(InClause).getBody() and i = -1 and name = "getBody"
2133+
or
2134+
result = node.(InClause).getGuard() and i = -1 and name = "getGuard"
2135+
or
2136+
result = node.(InClause).getPattern() and i = -1 and name = "getPattern"
2137+
or
2138+
result = node.(Interpolation).getChild(i) and name = "getChild"
2139+
or
2140+
result = node.(KeywordParameter).getName() and i = -1 and name = "getName"
2141+
or
2142+
result = node.(KeywordParameter).getValue() and i = -1 and name = "getValue"
2143+
or
2144+
result = node.(KeywordPattern).getKey() and i = -1 and name = "getKey"
2145+
or
2146+
result = node.(KeywordPattern).getValue() and i = -1 and name = "getValue"
2147+
or
2148+
result = node.(Lambda).getBody() and i = -1 and name = "getBody"
2149+
or
2150+
result = node.(Lambda).getParameters() and i = -1 and name = "getParameters"
2151+
or
2152+
result = node.(LambdaParameters).getChild(i) and name = "getChild"
2153+
or
2154+
result = node.(LeftAssignmentList).getChild(i) and name = "getChild"
2155+
or
2156+
result = node.(MatchPattern).getPattern() and i = -1 and name = "getPattern"
2157+
or
2158+
result = node.(MatchPattern).getValue() and i = -1 and name = "getValue"
2159+
or
2160+
result = node.(Method).getBody() and i = -1 and name = "getBody"
2161+
or
2162+
result = node.(Method).getName() and i = -1 and name = "getName"
2163+
or
2164+
result = node.(Method).getParameters() and i = -1 and name = "getParameters"
2165+
or
2166+
result = node.(MethodParameters).getChild(i) and name = "getChild"
2167+
or
2168+
result = node.(Module).getBody() and i = -1 and name = "getBody"
2169+
or
2170+
result = node.(Module).getName() and i = -1 and name = "getName"
2171+
or
2172+
result = node.(Next).getChild() and i = -1 and name = "getChild"
2173+
or
2174+
result = node.(OperatorAssignment).getLeft() and i = -1 and name = "getLeft"
2175+
or
2176+
result = node.(OperatorAssignment).getRight() and i = -1 and name = "getRight"
2177+
or
2178+
result = node.(OptionalParameter).getName() and i = -1 and name = "getName"
2179+
or
2180+
result = node.(OptionalParameter).getValue() and i = -1 and name = "getValue"
2181+
or
2182+
result = node.(Pair).getKey() and i = -1 and name = "getKey"
2183+
or
2184+
result = node.(Pair).getValue() and i = -1 and name = "getValue"
2185+
or
2186+
result = node.(ParenthesizedPattern).getChild() and i = -1 and name = "getChild"
2187+
or
2188+
result = node.(ParenthesizedStatements).getChild(i) and name = "getChild"
2189+
or
2190+
result = node.(Pattern).getChild() and i = -1 and name = "getChild"
2191+
or
2192+
result = node.(Program).getChild(i) and name = "getChild"
2193+
or
2194+
result = node.(Range).getBegin() and i = -1 and name = "getBegin"
2195+
or
2196+
result = node.(Range).getEnd() and i = -1 and name = "getEnd"
2197+
or
2198+
result = node.(Rational).getChild() and i = -1 and name = "getChild"
2199+
or
2200+
result = node.(Redo).getChild() and i = -1 and name = "getChild"
2201+
or
2202+
result = node.(Regex).getChild(i) and name = "getChild"
2203+
or
2204+
result = node.(Rescue).getBody() and i = -1 and name = "getBody"
2205+
or
2206+
result = node.(Rescue).getExceptions() and i = -1 and name = "getExceptions"
2207+
or
2208+
result = node.(Rescue).getVariable() and i = -1 and name = "getVariable"
2209+
or
2210+
result = node.(RescueModifier).getBody() and i = -1 and name = "getBody"
2211+
or
2212+
result = node.(RescueModifier).getHandler() and i = -1 and name = "getHandler"
2213+
or
2214+
result = node.(RestAssignment).getChild() and i = -1 and name = "getChild"
2215+
or
2216+
result = node.(Retry).getChild() and i = -1 and name = "getChild"
2217+
or
2218+
result = node.(Return).getChild() and i = -1 and name = "getChild"
2219+
or
2220+
result = node.(RightAssignmentList).getChild(i) and name = "getChild"
2221+
or
2222+
result = node.(ScopeResolution).getName() and i = -1 and name = "getName"
2223+
or
2224+
result = node.(ScopeResolution).getScope() and i = -1 and name = "getScope"
2225+
or
2226+
result = node.(Setter).getName() and i = -1 and name = "getName"
2227+
or
2228+
result = node.(SingletonClass).getBody() and i = -1 and name = "getBody"
2229+
or
2230+
result = node.(SingletonClass).getValue() and i = -1 and name = "getValue"
2231+
or
2232+
result = node.(SingletonMethod).getBody() and i = -1 and name = "getBody"
2233+
or
2234+
result = node.(SingletonMethod).getName() and i = -1 and name = "getName"
2235+
or
2236+
result = node.(SingletonMethod).getObject() and i = -1 and name = "getObject"
2237+
or
2238+
result = node.(SingletonMethod).getParameters() and i = -1 and name = "getParameters"
2239+
or
2240+
result = node.(SplatArgument).getChild() and i = -1 and name = "getChild"
2241+
or
2242+
result = node.(SplatParameter).getName() and i = -1 and name = "getName"
2243+
or
2244+
result = node.(String).getChild(i) and name = "getChild"
2245+
or
2246+
result = node.(StringArray).getChild(i) and name = "getChild"
2247+
or
2248+
result = node.(Subshell).getChild(i) and name = "getChild"
2249+
or
2250+
result = node.(Superclass).getChild() and i = -1 and name = "getChild"
2251+
or
2252+
result = node.(SymbolArray).getChild(i) and name = "getChild"
2253+
or
2254+
result = node.(TestPattern).getPattern() and i = -1 and name = "getPattern"
2255+
or
2256+
result = node.(TestPattern).getValue() and i = -1 and name = "getValue"
2257+
or
2258+
result = node.(Then).getChild(i) and name = "getChild"
2259+
or
2260+
result = node.(Unary).getOperand() and i = -1 and name = "getOperand"
2261+
or
2262+
result = node.(Undef).getChild(i) and name = "getChild"
2263+
or
2264+
result = node.(Unless).getAlternative() and i = -1 and name = "getAlternative"
2265+
or
2266+
result = node.(Unless).getCondition() and i = -1 and name = "getCondition"
2267+
or
2268+
result = node.(Unless).getConsequence() and i = -1 and name = "getConsequence"
2269+
or
2270+
result = node.(UnlessGuard).getCondition() and i = -1 and name = "getCondition"
2271+
or
2272+
result = node.(UnlessModifier).getBody() and i = -1 and name = "getBody"
2273+
or
2274+
result = node.(UnlessModifier).getCondition() and i = -1 and name = "getCondition"
2275+
or
2276+
result = node.(Until).getBody() and i = -1 and name = "getBody"
2277+
or
2278+
result = node.(Until).getCondition() and i = -1 and name = "getCondition"
2279+
or
2280+
result = node.(UntilModifier).getBody() and i = -1 and name = "getBody"
2281+
or
2282+
result = node.(UntilModifier).getCondition() and i = -1 and name = "getCondition"
2283+
or
2284+
result = node.(VariableReferencePattern).getName() and i = -1 and name = "getName"
2285+
or
2286+
result = node.(When).getBody() and i = -1 and name = "getBody"
2287+
or
2288+
result = node.(When).getPattern(i) and name = "getPattern"
2289+
or
2290+
result = node.(While).getBody() and i = -1 and name = "getBody"
2291+
or
2292+
result = node.(While).getCondition() and i = -1 and name = "getCondition"
2293+
or
2294+
result = node.(WhileModifier).getBody() and i = -1 and name = "getBody"
2295+
or
2296+
result = node.(WhileModifier).getCondition() and i = -1 and name = "getCondition"
2297+
or
2298+
result = node.(Yield).getChild() and i = -1 and name = "getChild"
2299+
}
2300+
}
19672301
}
19682302

19692303
overlay[local]
@@ -2107,4 +2441,20 @@ module Erb {
21072441
/** Gets a field or child node of this node. */
21082442
final override AstNode getAFieldOrChild() { erb_template_child(this, _, result) }
21092443
}
2444+
2445+
/** Provides predicates for mapping AST nodes to their named children. */
2446+
module PrintAst {
2447+
/** Gets a child of `node` returned by the member predicate with the given `name`. If the predicate takes an index argument, `i` is bound to that index, otherwise `i` is `-1` (which is never a valid index). */
2448+
AstNode getChild(AstNode node, string name, int i) {
2449+
result = node.(CommentDirective).getChild() and i = -1 and name = "getChild"
2450+
or
2451+
result = node.(Directive).getChild() and i = -1 and name = "getChild"
2452+
or
2453+
result = node.(GraphqlDirective).getChild() and i = -1 and name = "getChild"
2454+
or
2455+
result = node.(OutputDirective).getChild() and i = -1 and name = "getChild"
2456+
or
2457+
result = node.(Template).getChild(i) and name = "getChild"
2458+
}
2459+
}
21102460
}

0 commit comments

Comments
 (0)