(exprID int64, function string, target ast.Expr, args ...ast.Expr)
| 965 | } |
| 966 | |
| 967 | func (p *parser) expandMacro(exprID int64, function string, target ast.Expr, args ...ast.Expr) (ast.Expr, bool) { |
| 968 | macro, found := p.macros[makeMacroKey(function, len(args), target != nil)] |
| 969 | if !found { |
| 970 | macro, found = p.macros[makeVarArgMacroKey(function, target != nil)] |
| 971 | if !found { |
| 972 | return nil, false |
| 973 | } |
| 974 | } |
| 975 | if int(p.helper.expressionCount()) > p.maxExpressionNodeCount { |
| 976 | loc := p.helper.getLocation(exprID) |
| 977 | p.helper.deleteID(exprID) |
| 978 | return p.reportError(loc, "expression count exceeds limit of %d while expanding macro '%s'", p.maxExpressionNodeCount, function), true |
| 979 | } |
| 980 | eh := exprHelperPool.Get().(*exprHelper) |
| 981 | defer exprHelperPool.Put(eh) |
| 982 | eh.parserHelper = p.helper |
| 983 | eh.id = exprID |
| 984 | expr, err := macro.Expander()(eh, target, args) |
| 985 | if int(p.helper.expressionCount()) > p.maxExpressionNodeCount { |
| 986 | loc := p.helper.getLocation(exprID) |
| 987 | p.helper.deleteID(exprID) |
| 988 | return p.reportError(loc, "expression count exceeds limit of %d while expanding macro '%s'", p.maxExpressionNodeCount, function), true |
| 989 | } |
| 990 | // An error indicates that the macro was matched, but the arguments were not well-formed. |
| 991 | if err != nil { |
| 992 | loc := err.Location |
| 993 | if loc == nil { |
| 994 | loc = p.helper.getLocation(exprID) |
| 995 | } |
| 996 | p.helper.deleteID(exprID) |
| 997 | return p.reportError(loc, "%s", err.Message), true |
| 998 | } |
| 999 | // A nil value from the macro indicates that the macro implementation decided that |
| 1000 | // an expansion should not be performed. |
| 1001 | if expr == nil { |
| 1002 | return nil, false |
| 1003 | } |
| 1004 | if p.populateMacroCalls { |
| 1005 | p.helper.addMacroCall(expr.ID(), function, target, args...) |
| 1006 | } |
| 1007 | p.helper.deleteID(exprID) |
| 1008 | return expr, true |
| 1009 | } |
| 1010 | |
| 1011 | func (p *parser) checkAndIncrementRecursionDepth() { |
| 1012 | p.recursionDepth++ |
no test coverage detected