buildMacroCallArg iterates the expression and returns a new expression where all macros have been replaced by their IDs in MacroCalls
(expr ast.Expr)
| 232 | // buildMacroCallArg iterates the expression and returns a new expression |
| 233 | // where all macros have been replaced by their IDs in MacroCalls |
| 234 | func (p *parserHelper) buildMacroCallArg(expr ast.Expr) ast.Expr { |
| 235 | if _, found := p.sourceInfo.GetMacroCall(expr.ID()); found { |
| 236 | return p.exprFactory.NewUnspecifiedExpr(expr.ID()) |
| 237 | } |
| 238 | |
| 239 | switch expr.Kind() { |
| 240 | case ast.CallKind: |
| 241 | // Iterate the AST from `expr` recursively looking for macros. Because we are at most |
| 242 | // starting from the top level macro, this recursion is bounded by the size of the AST. This |
| 243 | // means that the depth check on the AST during parsing will catch recursion overflows |
| 244 | // before we get to here. |
| 245 | call := expr.AsCall() |
| 246 | macroArgs := make([]ast.Expr, len(call.Args())) |
| 247 | for index, arg := range call.Args() { |
| 248 | macroArgs[index] = p.buildMacroCallArg(arg) |
| 249 | } |
| 250 | if !call.IsMemberFunction() { |
| 251 | return p.exprFactory.NewCall(expr.ID(), call.FunctionName(), macroArgs...) |
| 252 | } |
| 253 | macroTarget := p.buildMacroCallArg(call.Target()) |
| 254 | return p.exprFactory.NewMemberCall(expr.ID(), call.FunctionName(), macroTarget, macroArgs...) |
| 255 | case ast.ListKind: |
| 256 | list := expr.AsList() |
| 257 | macroListArgs := make([]ast.Expr, list.Size()) |
| 258 | for i, elem := range list.Elements() { |
| 259 | macroListArgs[i] = p.buildMacroCallArg(elem) |
| 260 | } |
| 261 | return p.exprFactory.NewList(expr.ID(), macroListArgs, list.OptionalIndices()) |
| 262 | } |
| 263 | return expr |
| 264 | } |
| 265 | |
| 266 | // addMacroCall adds the macro the the MacroCalls map in source info. If a macro has args/subargs/target |
| 267 | // that are macros, their ID will be stored instead for later self-lookups. |
no test coverage detected