public static IWorkshopTree Call(ActionSet actionSet, MacroVar macro) { MacroVarBuilder builder = new MacroVarBuilder(actionSet, macro); builder.AssignParameters(); return(builder.ParseInner()); }
public void AddMacro(MacroVar macro, FileDiagnostics diagnostics, DocRange range, bool checkConflicts = true) { if (macro == null) { throw new ArgumentNullException(nameof(macro)); } if (Variables.Contains(macro)) { throw new Exception("macro reference is already in scope."); } if (checkConflicts && HasConflict(macro)) { string message = "A macro with the same name and parameter types was already defined in this scope."; if (diagnostics != null && range != null) { diagnostics.Error(message, range); return; } else { throw new Exception(message); } } Variables.Add(macro); }
public MacroVar(ParseInfo parseInfo, Scope objectScope, Scope staticScope, MacroVarDeclaration macroContext, CodeType returnType) { _context = macroContext; Name = macroContext.Identifier.Text; // Get the attributes. FunctionAttributesGetter attributeResult = new MacroAttributesGetter(macroContext, new MacroVarAttribute(this)); attributeResult.GetAttributes(parseInfo.Script.Diagnostics); DocRange nameRange = macroContext.Identifier.Range; ContainingType = (Static ? staticScope : objectScope).This; DefinedAt = new Location(parseInfo.Script.Uri, nameRange); _recursiveCallHandler = new RecursiveCallHandler(this); CallInfo = new CallInfo(_recursiveCallHandler, parseInfo.Script); CodeType = returnType; _expressionToParse = macroContext.Value; _scope = Static ? staticScope : objectScope; this._parseInfo = parseInfo; _scope.AddMacro(this, parseInfo.Script.Diagnostics, nameRange, !Override); parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, DefinedAt, true); parseInfo.Script.AddHover(nameRange, GetLabel(true)); parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.Variable, DefinedAt.range)); if (Override) { MacroVar overriding = (MacroVar)objectScope.GetMacroOverload(Name, DefinedAt); if (overriding == this) { parseInfo.Script.Diagnostics.Error("Overriding itself!", nameRange); } // No method with the name and parameters found. if (overriding == null) { parseInfo.Script.Diagnostics.Error("Could not find a macro to override.", nameRange); } else if (!overriding.IsOverridable) { parseInfo.Script.Diagnostics.Error("The specified macro is not marked as virtual.", nameRange); } else { overriding.Overriders.Add(this); } if (overriding != null && overriding.DefinedAt != null) { // Make the override keyword go to the base method. parseInfo.Script.AddDefinitionLink( attributeResult.ObtainedAttributes.First(at => at.Type == MethodAttributeType.Override).Range, overriding.DefinedAt ); } } }
public MacroVar GetMacro(Scope objectScope, Scope staticScope, MacroVarDeclaration macroContext) { // Get the return type. CodeType returnType = CodeType.GetCodeTypeFromContext(this, macroContext.Type); MacroVar newMacro = new MacroVar(this, objectScope, staticScope, macroContext, returnType); TranslateInfo.ApplyBlock((IApplyBlock)newMacro); return(newMacro); }
public static void GetMacro(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Define_macroContext macroContext, List <IApplyBlock> applyMethods) { if (macroContext.LEFT_PAREN() != null || macroContext.RIGHT_PAREN() != null) { var newMacro = new DefinedMacro(parseInfo, scope, macroContext); scope.AddMethod(newMacro, parseInfo.Script.Diagnostics, DocRange.GetRange(macroContext.name)); applyMethods.Add(newMacro); } else { var newMacro = new MacroVar(parseInfo, scope, macroContext); scope.AddVariable(newMacro, parseInfo.Script.Diagnostics, DocRange.GetRange(macroContext.name)); applyMethods.Add(newMacro); } }
public static IScopeable GetMacro(ParseInfo parseInfo, Scope objectScope, Scope staticScope, DeltinScriptParser.Define_macroContext macroContext) { // If the ; is missing, syntax error. if (macroContext.STATEMENT_END() == null) { parseInfo.Script.Diagnostics.Error("Expected ;", DocRange.GetRange((object)macroContext.TERNARY_ELSE() ?? (object)macroContext.name ?? (object)macroContext).end.ToRange()); } // If the : is missing, syntax error. if (macroContext.TERNARY_ELSE() == null) { parseInfo.Script.Diagnostics.Error("Expected :", DocRange.GetRange(macroContext).end.ToRange()); } else { // Get the expression that will be parsed. if (macroContext.expr() == null) { parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(macroContext.TERNARY_ELSE())); } } // Get the return type. CodeType returnType = CodeType.GetCodeTypeFromContext(parseInfo, macroContext.code_type()); IScopeable newMacro; if (macroContext.LEFT_PAREN() != null || macroContext.RIGHT_PAREN() != null) { newMacro = new DefinedMacro(parseInfo, objectScope, staticScope, macroContext, returnType); } else { newMacro = new MacroVar(parseInfo, objectScope, staticScope, macroContext, returnType); } parseInfo.TranslateInfo.ApplyBlock((IApplyBlock)newMacro); return(newMacro); }
public bool HasConflict(MacroVar macro) { return(GetMacroOverload(macro.Name, macro.DefinedAt) != null); }
public MacroVarRestrictedCallHandler(MacroVar macroVar, IRestrictedCallHandler callHandler, Location callLocation) { _macroVar = macroVar; _callHandler = callHandler; _callLocation = callLocation; }
public MacroVarAttribute(MacroVar macro) { _macro = macro; }
public bool HasConflict(MacroVar macro) => GetMacroOverload(macro.Name, macro.DefinedAt) != null;
public MacroVarOption(MacroVar macroVar) { _macroVar = macroVar; }
public MacroVarBuilder(ActionSet builderSet, MacroVar macro) : base(builderSet) { _macro = macro; }