public static void A(MacroContext context) { if (context.Value == Decimal.MinValue) { context.Value = 1; } }
public static LNode LLLPG_lexer(LNode node, IMacroContext context) { return(LllpgMacro(node, context, _lexer, lexerCfg => { var helper = new IntStreamCodeGenHelper(); foreach (var option in MacroContext.GetOptions(lexerCfg.Args)) { LNode value = option.Value; string key = (option.Key ?? (Symbol)"??").Name; switch (key.ToLowerInvariant()) { case "inputsource": helper.InputSource = value; break; case "inputclass": helper.InputClass = value; break; case "terminaltype": helper.TerminalType = value; break; case "settype": helper.SetType = value; break; case "listinitializer": helper.SetListInitializer(value); break; default: context.Write(Severity.Error, value, "Unrecognized option '{0}'. Available options: " + "inputSource: var, inputClass: type, terminalType: type, setType: type, listInitializer: var _ = new List<T>()", key); break; } } return helper; })); }
public override Result VisitMacro([NotNull] MacroContext context) { return(_writer.UsingIndent("{", "}", () => { var id = context.SYNTAX().GetText(); if (id == "include") { var provider = $"{nameof(RuntimeProviders)}.{nameof(RuntimeProviders.GetEmiter)}"; _writer.WriteIndentLine($"var emiter = {provider}<{id}>();"); _writer.WriteIndentLine($"var result = emiter.{nameof(ISdmapEmiter.BuildText)}(self);"); } else { var provider = $"{nameof(RuntimeProviders)}.{nameof(RuntimeProviders.RuntimeMacros)}"; _writer.WriteIndent($"var result = {provider}.{context.SYNTAX()}("); WriteMacroParameters(context.macroParameter()); } _writer.WriteIndentLine($"if (result.{nameof(Result.IsSuccess)})"); _writer.UsingIndent("{", "}", () => { _writer.WriteIndentLine( $"sb.Append(result.{nameof(Result<int>.Value)});"); }); _writer.WriteIndentLine("else"); _writer.UsingIndent("{", "}", () => { _writer.WriteIndentLine("return result;"); }); return Result.Ok(); })); }
public static LNode LLLPG_lexer(LNode node, IMacroContext context) { return(LllpgMacro(node, context, _lexer, lexerCfg => { var helper = new IntStreamCodeGenHelper(); foreach (var option in MacroContext.GetOptions(lexerCfg.Args)) { LNode value = option.Value ?? LNode.Missing; string key = option.Key.Name.Name; switch (key.ToLowerInvariant()) { case "inputsource": helper.InputSource = value; break; case "inputclass": helper.InputClass = value; break; case "terminaltype": helper.TerminalType = value; break; case "settype": helper.SetType = value; break; case "listinitializer": helper.SetListInitializer(value); break; case "nocheckbydefault": SetOption <bool>(context, option.Key, value.Value, b => helper.NoCheckByDefault = b); break; default: context.Sink.Error(option.Key, "Unrecognized option '{0}'. Available options: " + "InputSource: var, InputClass: type, TerminalType: type, SetType: type, " + "ListInitializer: var _ = new List<T>(), NoCheckByDefault: true", key); break; } } return helper; })); }
private Result EmitMacroResult(MacroContext context, bool topLevel) { string macroName = context.GetToken(SYNTAX, 0).GetText(); _il.Emit(OpCodes.Ldarg_0); // ctx _il.Emit(OpCodes.Ldstr, macroName); // ctx name _il.Emit(OpCodes.Ldstr, _context.CurrentNs); // ctx name ns _il.Emit(OpCodes.Ldarg_0); // ctx name ns ctx _il.Emit(OpCodes.Call, OneCallContext.GetObj); // ctx name ns self var contexts = context.GetRuleContexts <MacroParameterContext>(); _il.Emit(OpCodes.Ldc_I4, contexts.Length); // ctx name ns self _il.Emit(OpCodes.Newarr, typeof(object)); // ctx name ns self args for (var i = 0; i < contexts.Length; ++i) { MacroParameterContext arg = contexts[i]; _il.Emit(OpCodes.Dup); // .. -> args _il.Emit(OpCodes.Ldc_I4, i); // .. -> args idx var result = EmitGetMacroParameter(arg); // .. -> args idx val if (!result.IsSuccess) { return(result); } _il.Emit(OpCodes.Stelem_Ref); // ctx name ns self args } _il.Emit(OpCodes.Call, typeof(MacroManager) .GetMethod(nameof(MacroManager.Execute))); // result<str> _il.Emit(OpCodes.Dup); // result<str> x 2 _il.Emit(OpCodes.Call, typeof(Result) .GetMethod("get_" + nameof(Result.IsSuccess))); // result<str> bool _il.Emit(OpCodes.Ldc_I4_1); // result<str> bool true var ifIsSuccess = _il.DefineLabel(); _il.Emit(OpCodes.Beq, ifIsSuccess); // result<str> (jmp if equal) if (topLevel) { _il.Emit(OpCodes.Ret); // [exit-returned] _il.MarkLabel(ifIsSuccess); // ifIsSuccess: _il.Emit(OpCodes.Call, typeof(Result <string>) .GetMethod("get_" + nameof(Result <string> .Value))); // str } else { var exit = _il.DefineLabel(); _il.Emit(OpCodes.Br_S, exit); _il.MarkLabel(ifIsSuccess); // ifIsSuccess: _il.Emit(OpCodes.Call, typeof(Result <string>) .GetMethod("get_" + nameof(Result <string> .Value))); // str _il.MarkLabel(exit); } return(Result.Ok()); }
internal MacroNode(string param, RollData data) { if (String.IsNullOrWhiteSpace(param)) { throw new DiceException(DiceErrorCode.InvalidMacro, new ArgumentException("Macro param cannot consist of only whitespace", nameof(param))); } Context = new MacroContext(param.Trim(), data); _values = new List <DieResult>(); }
public static void AddActionsToScheduler( ReportJobConfiguration config, CoreBusinessLayerService service) { if (!config.get_Enabled()) { return; } ReportingActionContext reportingActionContext = new ReportingActionContext(); reportingActionContext.set_AccountID(config.get_AccountID()); reportingActionContext.set_UrlsGroupedByLeftPart(ReportJobInitializer.GroupUrls(config)); reportingActionContext.set_WebsiteID(config.get_WebsiteID()); ReportingActionContext reportingContext = reportingActionContext; MacroContext macroContext = ((ActionContextBase)reportingContext).get_MacroContext(); ReportingContext reportingContext1 = new ReportingContext(); reportingContext1.set_AccountID(config.get_AccountID()); reportingContext1.set_ScheduleName(config.get_Name()); reportingContext1.set_ScheduleDescription(config.get_Description()); reportingContext1.set_LastRun(config.get_LastRun()); reportingContext1.set_WebsiteID(config.get_WebsiteID()); macroContext.Add((ContextBase)reportingContext1); ((ActionContextBase)reportingContext).get_MacroContext().Add((ContextBase) new GenericContext()); int num = 0; if (config.get_Schedules() == null) { return; } using (List <ReportSchedule> .Enumerator enumerator1 = config.get_Schedules().GetEnumerator()) { while (enumerator1.MoveNext()) { ReportSchedule current = enumerator1.Current; DateTime dateTime = !current.get_EndTime().HasValue ? DateTime.MaxValue : current.get_EndTime().Value; Scheduler.get_Instance().Add(new ScheduledTask(string.Format("ReportJob-{0}_{1}", (object)config.get_ReportJobID(), (object)num), (TimerCallback)(o => { ReportJobInitializer.log.Info((object)"Starting action execution"); using (List <ActionDefinition> .Enumerator enumerator = config.get_Actions().GetEnumerator()) { while (enumerator.MoveNext()) { service.ExecuteAction(enumerator.Current, (ActionContextBase)reportingContext); } } config.set_LastRun(new DateTime?(DateTime.Now.ToUniversalTime())); ReportJobDAL.UpdateLastRun(config.get_ReportJobID(), config.get_LastRun()); }), (object)null, current.get_CronExpression(), current.get_StartTime(), dateTime, config.get_LastRun(), current.get_CronExpressionTimeZoneInfo()), true); ++num; } } }
protected override void DoExpand(MacroContext context) { var perform = context.Factory.Call(context.Invocation.Position, EntityRef.Command.Create(Engine.CallSubPerformAlias), PCall.Get, context.Invocation.Arguments.ToArray()); var interpret = context.Factory.Expand(context.Invocation.Position, EntityRef.MacroCommand.Create(CallSubInterpret.Alias), context.Invocation.Call); interpret.Arguments.Add(perform); context.Block.Expression = interpret; }
protected override void DoExpand(MacroContext context) { if (context.Invocation.Arguments.Count == 0) { context.ReportMessage( Message.Error( string.Format(Resources.CallSubInterpret_OneArgument, Alias), context.Invocation.Position, MessageClasses.SubUsage)); return; } if (context.CurrentLoopBlock != null && !context.IsJustEffect) { context.ReportMessage( Message.Error( string.Format( Resources.CallSubInterpret_asExpressionInLoop, CallSub.Alias, Alias), context.Invocation.Position, MessageClasses.SubAsExpressionInLoop)); return; } //Store result of call var resultV = context.AllocateTemporaryVariable(); _storeResult(context, resultV); //Extract return variant as int into retVarV var retVarV = context.AllocateTemporaryVariable(); _extractReturnVariant(context, resultV, retVarV); Func<AstGetSet> retVar = () => context.CreateCall(EntityRef.Variable.Local.Create(retVarV)); //Extract return value into retValueV (which happens to be the same as resultV) var retValueV = resultV; _extractReturnValue(context, resultV, retValueV); // ReSharper disable ImplicitlyCapturedClosure // perfectly safe as neither lambda survives the method Func<AstGetSet> retValue = () => context.CreateCall(EntityRef.Variable.Local.Create(retValueV)); // ReSharper restore ImplicitlyCapturedClosure //Break and Continue behave differently outside loop blocks AstNode contStmt, breakStmt; _determineActions(context, retValue, out contStmt, out breakStmt); //Generate check for continue _genChecks(context, retVar, contStmt, breakStmt); context.Block.Expression = retValue(); context.FreeTemporaryVariable(retVarV); context.FreeTemporaryVariable(resultV); }
public static void Main() { ServerConnection sc = ConnectToDocs(); MacroContext mc = new MacroContext(sc); dynamic macro = new Cancelaria.Macro(mc); macro.Test(); return; //var project = References.ProjectManagementReference.Find(346161); //План ОПК //var dialog = new Report.Views.Report_View(project); //dialog.ShowDialog(); Console.ReadKey(); }
private void _expandPartialApplication(MacroContext context, int passThrough, List<AstExpr> arguments) { var flatArgs = new List<AstExpr>(arguments.Count); var directives = new List<int>(arguments.Count); //The call target is a "non-argument" in partial application terms. Do not include it in the // stream of directives. flatArgs.Add(arguments[0]); var opaqueSpan = 0; for (var i = 1; i < arguments.Count; i++) { var arg = arguments[i]; AstListLiteral lit; if (i < passThrough || !_isPartialList(arg, out lit)) { flatArgs.Add(arg); opaqueSpan++; } else { flatArgs.AddRange(lit.Elements); if (opaqueSpan > 0) { directives.Add(opaqueSpan); opaqueSpan = 0; } directives.Add(-lit.Elements.Count); } } var ppArgv = AstPartiallyApplicable.PreprocessPartialApplicationArguments(flatArgs); var argc = ppArgv.Count; var mappings8 = new int[argc + directives.Count + 1]; var closedArguments = new List<AstExpr>(argc); AstPartiallyApplicable.GetMapping(ppArgv, mappings8, closedArguments); _mergeDirectivesIntoMappings(directives, mappings8, argc); var mappings32 = PartialApplicationCommandBase.PackMappings32(mappings8); var implCall = context.Factory.Call(context.Invocation.Position, EntityRef.Command.Create(PartialCallStarImplCommand.Alias), context.Call); implCall.Arguments.AddRange(closedArguments); implCall.Arguments.AddRange(mappings32.Select(m => context.CreateConstant(m))); context.Block.Expression = implCall; }
private static void ApplyOptions(LNode node, LLParserGenerator lllpg, IMacroContext sink, IEnumerable <Rule> rules) { foreach (var pair in MacroContext.GetOptions(node.Attrs)) { LNode key = pair.Key; object value = pair.Value != null ? pair.Value.Value : null; switch (key.Name.Name) { case "FullLLk": SetOption <bool>(sink, key, value ?? G.BoxedTrue, v => lllpg.FullLLk = v); break; case "Verbosity": SetOption <int>(sink, key, value, v => lllpg.Verbosity = v); break; case "NoDefaultArm": SetOption <bool>(sink, key, value ?? G.BoxedTrue, v => lllpg.NoDefaultArm = v); break; case "LL": case "DefaultK": case "k": case "K": // [LL(k)] is preferred SetOption <int>(sink, key, value, v => lllpg.DefaultK = v); break; case "AddComments": SetOption <bool>(sink, key, value ?? G.BoxedTrue, v => lllpg.AddComments = v); break; case "AddCsLineDirectives": SetOption <bool>(sink, key, value ?? G.BoxedTrue, v => lllpg.AddCsLineDirectives = v); break; case "PrematchByDefault": SetOption <bool>(sink, key, value ?? G.BoxedTrue, v => lllpg.PrematchByDefault = v); break; default: if (!key.IsTrivia) { sink.Error(key, "Unrecognized attribute. LLLPG supports the following options: " + "FullLLk(bool), Verbosity(0..3), NoDefaultArm(bool), DefaultK(1..9), AddComments(bool), AddCsLineDirectives(bool), and PrematchByDefault(bool)"); } break; } } }
public static LNode LLLPG_parser(LNode node, IMacroContext context) { return(LllpgMacro(node, context, _parser, parserCfg => { // Scan options in parser(...) node var helper = new GeneralCodeGenHelper(); if (parserCfg == null) { return helper; } foreach (var option in MacroContext.GetOptions(parserCfg.Args)) { LNode value = option.Value ?? LNode.Missing; string key = option.Key.Name.Name; switch (key.ToLowerInvariant()) { case "inputsource": helper.InputSource = value; break; case "inputclass": helper.InputClass = value; break; case "terminaltype": helper.TerminalType = value; break; case "settype": helper.SetType = value; break; case "listinitializer": helper.SetListInitializer(value); break; case "nocheckbydefault": SetOption <bool>(context, option.Key, value.Value, b => helper.NoCheckByDefault = b); break; case "allowswitch": SetOption <bool>(context, option.Key, value.Value, b => helper.AllowSwitch = b); break; case "castla": SetOption <bool>(context, option.Key, value.Value, b => helper.CastLA = b); break; case "latype": helper.LaType = value; break; case "matchtype": // alternate name case "matchcast": helper.MatchCast = value; break; default: context.Sink.Error(option.Key, "Unrecognized option '{0}'. Available options: " + "InputSource: variable, InputClass: type, TerminalType: type, SetType: type, " + "ListInitializer: var _ = new List<T>(), NoCheckByDefault: true, AllowSwitch: bool, " + "CastLA: bool, LAType: type, MatchCast: type", key); break; } } return helper; }, isDefault: true)); }
protected override bool DoExpandPartialApplication(MacroContext context) { if (context.Invocation.Arguments.Count < 1) { context.ReportMessage(Message.Error( string.Format(Resources.CallStar_usage, Id), context.Invocation.Position, MessageClasses.CallStarUsage)); return true; } int passThrough; List<AstExpr> arguments; _determinePassThrough(context, out passThrough, out arguments); _expandPartialApplication(context, passThrough, arguments); return true; }
public override Result VisitMacro([NotNull] MacroContext context) { var result = EmitMacroResult(context, topLevel: true); // str if (!result.IsSuccess) { return(result); } var strValue = _il.DeclareLocal(typeof(string)); _il.Emit(OpCodes.Stloc, strValue); // [empty] _il.Emit(OpCodes.Ldloc_0); // list _il.Emit(OpCodes.Ldloc, strValue); // list str _il.Emit(OpCodes.Call, _addCall); // [empty] return(Result.Ok()); }
public static void ExecuteMacro(MacroContext context) { switch (context.Name) { case "one": context.Value = 1; break; case "two": context.Value = 2; break; case "twenty": context.Value = 20; break; case "x": context.Value = Decimal.Parse(context.Arguments[1]); break; } }
protected override void DoExpand(MacroContext context) { if (context.Invocation.Arguments.Count < 1) { context.ReportMessage( Message.Error( string.Format(Resources.Pack_Usage_obj_missing, Alias), context.Invocation.Position, MessageClasses.PackUsage)); return; } context.EstablishMacroContext(); // [| context.StoreForTransport(boxed($arg0)) |] var getContext = context.CreateIndirectCall(context.CreateCall( EntityRef.Variable.Local.Create(MacroAliases.ContextAlias))); var boxedArg0 = context.CreateCall(EntityRef.Command.Create(Engine.BoxedAlias),PCall.Get, context.Invocation.Arguments[0]); context.Block.Expression = context.CreateGetSetMember(getContext, PCall.Get, "StoreForTransport", boxedArg0); }
public static LNode LLLPG_lexer(LNode node, IMacroContext context) { var p = context.GetArgsAndBody(true); var args = p.A; var body = p.B; LNode lexerCfg; if (args.Count != 1 || (lexerCfg = args[0]).Name != _lexer) { return(null); } // Scan options in lexer(...) node var helper = new IntStreamCodeGenHelper(); foreach (var option in MacroContext.GetOptions(lexerCfg.Args)) { LNode value = option.Value; string key = (option.Key ?? (Symbol)"??").Name; switch (key.ToLowerInvariant()) { case "inputsource": helper.InputSource = value; break; case "inputclass": helper.InputClass = value; break; case "terminaltype": helper.TerminalType = value; break; case "settype": helper.SetType = value; break; case "listinitializer": helper.SetListInitializer(value); break; default: context.Write(Severity.Error, value, "Unrecognized option '{0}'. Available options: " + "inputSource: var, inputClass: type, terminalType: type, setType: type, listInitializer: var _ = new List<T>()", key); break; } } return(node.WithTarget(_run_LLLPG).WithArgs(F.Literal(helper), F.Braces(body))); }
protected override void DoExpand(MacroContext context) { if (context.Invocation.Arguments.Count < 1) { context.ReportMessage( Message.Error( string.Format( "{0} requires at least one argument, the id of the object to unpack.", Alias), context.Invocation.Position, MessageClasses.UnpackUsage)); return; } context.EstablishMacroContext(); // [| macro\unpack\impl(context, $arg0) |] var getContext = context.CreateIndirectCall(context.CreateCall(EntityRef.Variable.Local.Create(MacroAliases.ContextAlias))); context.Block.Expression = context.CreateCall(EntityRef.Command.Create(Impl.Alias), PCall.Get, getContext, context.Invocation.Arguments[0]); }
public MacroContext macro() { MacroContext _localctx = new MacroContext(Context, State); EnterRule(_localctx, 4, RULE_macro); try { EnterOuterAlt(_localctx, 1); { State = 37; macroName(); State = 38; macroParams(); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
private void RollMacro(MacroContext context) { // [roll:X] retrieves the Value of the Xth roll (first roll in the post is X=1). Can only retrieve values of past rolls. // [roll:X:Y] retrieves the Value of the Yth die on the Xth roll (actual die rolls only, aka normal/fudge/group). First die is Y=1. // [roll:X:critical] is the number of dice in the Xth roll that are critical. // [roll:X:Y:critical] is 1 if the Yth die is critical and 0 otherwise. // [roll:X:fumble] and [roll:X:Y:fumble] work the same way // as do [roll:X:success], [roll:X:Y:success], [roll:X:failure], and [roll:X:Y:failure] // for success/failure, it only counts number of successes or number of failures, returning an integer >= 0 for each. In other words, // [roll:X:success] doesn't deduct 1 whenever it sees a failure roll, unlike [roll:X] which will give successes - failures. // All other formulations of the macro are an error (which we pass down, as someone else may have their own roll macro which implements extended features) var args = context.Arguments; if (args.Count == 1) { return; // no X } if (!Int32.TryParse(args[1], out int rollIdx)) { return; // invalid X } if (rollIdx < 0) { // negative X means we count backwards from the current post rollIdx += Current.Count; } else { rollIdx--; // make 0-based instead of 1-based } if (rollIdx < 0 || rollIdx >= Current.Count) { return; // X is too big or small } if (args.Count == 2) { // only have 2 args, return the value of the Xth roll context.Value = Current[rollIdx].Value; context.ValueType = Current[rollIdx].ResultType; return; } int nextIdx = 2; var allRolls = Current[rollIdx].Values.Where(d => d.IsLiveDie() && d.DieType.IsRoll()).ToList(); if (Int32.TryParse(args[2], out int dieIdx)) { dieIdx--; nextIdx = 3; if (dieIdx < 0 || dieIdx >= allRolls.Count) { return; // Y is too big or small } if (args.Count == 3) { // only have 3 args, X and Y. Return the value of the Yth roll context.Value = allRolls[dieIdx].Value; return; } } else { dieIdx = -1; } DieFlags flag; switch (args[nextIdx].ToLower()) { case "critical": flag = DieFlags.Critical; break; case "fumble": flag = DieFlags.Fumble; break; case "success": flag = DieFlags.Success; break; case "failure": flag = DieFlags.Failure; break; default: return; // unrecognized flag } if (dieIdx >= 0) { context.Value = allRolls[dieIdx].Flags.HasFlag(flag) ? 1 : 0; } else { context.Value = allRolls.Count(d => d.Flags.HasFlag(flag)); } }
public AdministrationController(MacroContext context) { _context = context; }
/// <summary> /// Retrieves the specified resources and wraps them in an data container. /// </summary> /// <param name="settings">CSS settings</param> /// <param name="name">Resource name</param> /// <param name="cached">If true, the result will be cached</param> /// <returns>The data container with the resulting stylesheet data</returns> private static CMSOutputResource GetResource(CMSCssSettings settings, string name, bool cached) { List<CMSOutputResource> resources = new List<CMSOutputResource>(); // Add files if (settings.Files != null) { foreach (CMSItem item in settings.Files) { // Get the resource CMSOutputResource resource = GetFile(item, CSS_FILE_EXTENSION, true, false); resources.Add(resource); } } // Add stylesheets if (settings.Stylesheets != null) { foreach (CMSItem item in settings.Stylesheets) { // Get the resource CMSOutputResource resource = GetStylesheet(item); resources.Add(resource); } } // Add web part containers if (settings.Containers != null) { foreach (CMSItem item in settings.Containers) { // Get the resource CMSOutputResource resource = GetContainer(item); resources.Add(resource); } } // Add web parts if (settings.WebParts != null) { foreach (CMSItem item in settings.WebParts) { // Get the resource CMSOutputResource resource = GetWebPart(item); resources.Add(resource); } } // Add templates if (settings.Templates != null) { foreach (CMSItem item in settings.Templates) { // Get the resource CMSOutputResource resource = GetTemplate(item); resources.Add(resource); } } // Add layouts if (settings.Layouts != null) { foreach (CMSItem item in settings.Layouts) { // Get the resource CMSOutputResource resource = GetLayout(item); resources.Add(resource); } } // Add device layouts if (settings.DeviceLayouts != null) { foreach (CMSItem item in settings.DeviceLayouts) { // Get the resource CMSOutputResource resource = GetDeviceLayout(item); resources.Add(resource); } } // Add transformation containers if (settings.Transformations != null) { foreach (CMSItem item in settings.Transformations) { // Get the resource CMSOutputResource resource = GetTransformation(item); resources.Add(resource); } } // Add web part layouts if (settings.WebPartLayouts != null) { foreach (CMSItem item in settings.WebPartLayouts) { // Get the resource CMSOutputResource resource = GetWebPartLayout(item); resources.Add(resource); } } // Combine to a single output CMSOutputResource result = CombineResources(resources); settings.ComponentFiles = result.ComponentFiles; result.ContentType = MimeTypeHelper.GetMimetype(CSS_FILE_EXTENSION); // Resolve the macros if (CSSHelper.ResolveMacrosInCSS) { var context = new MacroContext() { TrackCacheDependencies = cached }; if (cached) { // Add the default dependencies context.AddCacheDependencies(settings.GetCacheDependencies()); context.AddFileCacheDependencies(settings.GetFileCacheDependencies()); } result.Data = CMSContext.ResolveMacros(result.Data, context); if (cached) { // Add cache dependency result.CacheDependency = CacheHelper.GetCacheDependency(context.FileCacheDependencies, context.CacheDependencies); } } else if (cached) { // Only the cache dependency from settings result.CacheDependency = settings.GetCacheDependency(); } result.Data = HTMLHelper.ResolveCSSClientUrls(result.Data, URLHelper.GetAbsoluteUrl("~/CMSPages/GetResource.ashx")); // Minify MinifyResource(result, new CssMinifier(), CSSHelper.StylesheetMinificationEnabled && settings.EnableMinification, settings.EnableCompression); return result; }
protected override bool DoExpandPartialApplication(MacroContext context) { DoExpand(context); return true; }
public CircuitsController(MacroContext context, IConfiguration config) { _context = context; _config = config; }
public static LNode LLLPG_parser(LNode node, IMacroContext context) { var p = context.GetArgsAndBody(true); var args = p.A; var body = p.B; LNode parserCfg = null; if (args.Count > 0) { if ((parserCfg = args[0]).Name != _parser || args.Count > 1) { return(null); } } // Scan options in parser(...) node var helper = new GeneralCodeGenHelper(); if (parserCfg != null) { foreach (var option in MacroContext.GetOptions(parserCfg.Args)) { LNode value = option.Value; string key = (option.Key ?? (Symbol)"??").Name; switch (key.ToLowerInvariant()) { case "inputsource": helper.InputSource = value; break; case "inputclass": helper.InputClass = value; break; case "terminaltype": helper.TerminalType = value; break; case "latype": helper.LaType = value; break; case "matchtype": // alternate name case "matchcast": helper.MatchCast = value; break; case "settype": helper.SetType = value; break; case "allowswitch": if (value.Value is bool) { helper.AllowSwitch = (bool)value.Value; } else { context.Write(Severity.Error, value, "AllowSwitch: expected literal boolean argument."); } break; case "castla": if (value.Value is bool) { helper.CastLA = (bool)value.Value; } else { context.Write(Severity.Error, value, "CastLA: expected literal boolean argument."); } break; case "listinitializer": helper.SetListInitializer(value); break; default: context.Write(Severity.Error, value, "Unrecognized option '{0}'. Available options: " + "inputSource: variable, inputClass: type, terminalType: type, laType: type, matchCast: type, setType: type, allowSwitch: bool, castLa: bool, listInitializer: var _ = new List<T>()", key); break; } } } return(node.WithTarget(_run_LLLPG).WithArgs(F.Literal(helper), F.Braces(body))); }
private static bool _parseReference(MacroContext context, AstExpr macroRef) { if (macroRef.IsPlaceholder()) { context.ReportMessage( Message.Error( Resources.CallMacro_notOnPlaceholder, context.Invocation.Position, MessageClasses.CallMacroNotOnPlaceholder)); return false; } return true; }
public override Result VisitMacro([NotNull] MacroContext context) { var macroName = context.GetToken(SYNTAX, 0).GetText(); _il.Emit(OpCodes.Ldarg_0); // ctx _il.Emit(OpCodes.Ldstr, macroName); // ctx name _il.Emit(OpCodes.Ldstr, _context.CurrentNs); // ctx name ns _il.Emit(OpCodes.Ldarg_1); // ctx name ns self var contexts = context.GetRuleContexts <MacroParameterContext>(); _il.Emit(OpCodes.Ldc_I4, contexts.Length); // ctx name ns self _il.Emit(OpCodes.Newarr, typeof(object)); // ctx name ns self args for (var i = 0; i < contexts.Length; ++i) { var arg = contexts[i]; _il.Emit(OpCodes.Dup); // .. -> args _il.Emit(OpCodes.Ldc_I4, i); // .. -> args idx if (arg.nsSyntax() != null) { _il.Emit(OpCodes.Ldstr, arg.nsSyntax().GetText()); // .. -> args idx ele } else if (arg.STRING() != null) { var result = StringUtil.Parse(arg.STRING().GetText()); // .. -> args idx ele if (result.IsSuccess) { _il.Emit(OpCodes.Ldstr, result.Value); // .. -> args idx ele } else { return(result); } } else if (arg.NUMBER() != null) { var result = NumberUtil.Parse(arg.NUMBER().GetText()); if (result.IsSuccess) { _il.Emit(OpCodes.Ldc_R8, result.Value); // .. -> args idx vele _il.Emit(OpCodes.Box, typeof(double)); // .. -> args idx rele } else { return(result); } } else if (arg.DATE() != null) { var result = DateUtil.Parse(arg.DATE().GetText()); if (result.IsSuccess) { _il.Emit(OpCodes.Ldc_I8, result.Value.ToBinary()); // .. -> args idx int64 var ctor = typeof(DateTime).GetTypeInfo().GetConstructor(new[] { typeof(long) }); _il.Emit(OpCodes.Newobj, ctor); // .. -> args idx date _il.Emit(OpCodes.Box, typeof(DateTime)); // .. -> args idx rele } else { return(result); } } else if (arg.Bool() != null) { _il.Emit(bool.Parse(arg.Bool().GetText()) ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); // .. -> args idx bool _il.Emit(OpCodes.Box, typeof(bool)); // .. -> args idx rele } else if (arg.unnamedSql() != null) { var parseTree = arg.unnamedSql(); var id = NameUtil.GetFunctionName(parseTree); var result = _context.TryGetEmiter(id, _context.CurrentNs); SqlEmiter emiter; if (result.IsSuccess) { emiter = result.Value; } else { emiter = SqlEmiterUtil.CreateUnnamed(parseTree, _context.CurrentNs); var ok = _context.TryAdd(id, emiter); if (ok.IsFailure) { return(ok); } } var compileResult = emiter.EnsureCompiled(_context); if (compileResult.IsFailure) { return(compileResult); } _il.Emit(OpCodes.Ldarg_0); // .. -> args idx ctx _il.Emit(OpCodes.Ldstr, id); // .. -> args idx ctx id _il.Emit(OpCodes.Ldstr, _context.CurrentNs); // .. -> args idx ctx id ns _il.Emit(OpCodes.Call, typeof(SqlEmiterUtil).GetTypeInfo() .GetMethod(nameof(SqlEmiterUtil.EmiterFromId))); // .. -> args idx emiter } else { throw new InvalidOperationException(); } _il.Emit(OpCodes.Stelem_Ref); // -> ctx name ns self args } _il.Emit(OpCodes.Call, typeof(MacroManager).GetTypeInfo() .GetMethod(nameof(MacroManager.Execute))); // result<str> _il.Emit(OpCodes.Dup); // result<str> x 2 _il.Emit(OpCodes.Call, typeof(Result).GetTypeInfo() .GetMethod("get_" + nameof(Result.IsSuccess))); // result<str> bool _il.Emit(OpCodes.Ldc_I4_1); // result<str> bool true var ifIsSuccess = _il.DefineLabel(); _il.Emit(OpCodes.Beq, ifIsSuccess); // result<str> (jmp if equal) _il.Emit(OpCodes.Ret); // [exit-returned] _il.MarkLabel(ifIsSuccess); // ifIsSuccess: _il.Emit(OpCodes.Call, typeof(Result <string>).GetTypeInfo() .GetMethod("get_" + nameof(Result <string> .Value))); // str var strValue = _il.DeclareLocal(typeof(string)); _il.Emit(OpCodes.Stloc, strValue); // [empty] _il.Emit(OpCodes.Ldloc_0); // sb _il.Emit(OpCodes.Ldloc, strValue); // sb str _il.Emit(OpCodes.Call, typeof(StringBuilder) .GetTypeInfo().GetMethod(nameof(StringBuilder.Append), new[] { typeof(string), })); // sb+str _il.Emit(OpCodes.Pop); // [empty] return(Result.Ok()); }
protected override void DoExpand(MacroContext context) { if (context.Invocation.Arguments.Count < 1) { context.ReportMessage( Message.Error( string.Format(Resources.CallStar_usage, Id), context.Invocation.Position, MessageClasses.CallStarUsage)); return; } int passThrough; List<AstExpr> arguments; _determinePassThrough(context, out passThrough, out arguments); if (arguments.Skip(passThrough).Any(_isPartialList)) { _expandPartialApplication(context, passThrough, arguments); return; } // "Fallback" direct invocation var ic = new AstIndirectCall(context.Invocation.File, context.Invocation.Line, context.Invocation.Column, context.Invocation.Call, arguments[0]); ic.Arguments.AddRange(arguments.Skip(1)); context.Block.Expression = ic; }
protected override void DoExpand(MacroContext context) { if (!context.CallerIsMacro()) { context.ReportMessage( Message.Error( string.Format(Resources.Reference_can_only_be_used_in_a_macro_context, Alias), context.Invocation.Position, MessageClasses.ReferenceUsage)); return; } if (context.Invocation.Arguments.Count == 0) { context.ReportMessage( Message.Error( string.Format(Resources.Reference_requires_at_least_one_argument, Alias), context.Invocation.Position, MessageClasses.ReferenceUsage)); return; } var prototype = context.Invocation.Arguments[0] as AstExpand; if (prototype == null) { context.ReportMessage( Message.Error( string.Format(Resources.Reference_requires_argument_to_be_a_prototype_of_a_macro_invocation, Alias), context.Invocation.Position, MessageClasses.ReferenceUsage)); } else { context.Block.Expression = _assembleImplCall(context, prototype.Entity.ToSymbolEntry(), prototype.Position); } }
/// <summary> /// Returns a trivial partial application of the call implementation (call\perform(?)) /// </summary> /// <param name="context">The macro context in which to create the AST node.</param> /// <returns>A trivial partial application of the call implementation.</returns> protected virtual AstGetSet GetTrivialPartialApplication(MacroContext context) { var cp = context.Factory.Call(context.Invocation.Position, _callImplementation, context.Call, new AstPlaceholder(context.Invocation.File, context.Invocation.Line, context.Invocation.Column, 0)); return cp; }
public void B(MacroContext context) { context.Value = b; }
/// <summary> /// Provides access to the call arguments, including the call target and any other /// parameters (like the member id for call\member). /// </summary> /// <param name="context">The context from which to derive the arguments.</param> /// <returns>The arguments to the call invocation.</returns> protected virtual IEnumerable<AstExpr> GetCallArguments(MacroContext context) { return context.Invocation.Arguments; }
protected override void DoExpand(MacroContext context) { if (context.Invocation.Arguments.Count == 0) { // Call with no arguments returns null. // The macro system will supply that null. return; } var p = context.Invocation.Arguments[0] as AstPlaceholder; if (context.Invocation.Arguments.Count == 1 && p != null && (p.Index.GetValueOrDefault(0) == 0)) { // call(?0) ⇒ call\perform(?0) context.Block.Expression = GetTrivialPartialApplication(context); return; } if (!context.Invocation.Arguments.Any(_hasPlaceholder)) { // no placeholders, invoke call\perform directly var call = context.Factory.IndirectCall(context.Invocation.Position, context.Factory.Reference(context.Invocation.Position, _callImplementation), context.Call); call.Arguments.AddRange(GetCallArguments(context)); context.Block.Expression = call; return; } // Assemble the invocation of call\*(passThrough,call\perform(?),callArguments...) // Note: this is a get-call in all cases, because we are computing a partial application // whether the programmer wrote a get or a set call needs to be captured by concrete // implementations of partial call wrapers (see Call_Member) var inv = context.Factory.Expand(context.Invocation.Position, EntityRef.MacroCommand.Create(CallStar.Instance.Id)); // Protect the first two arguments inv.Arguments.Add(context.CreateConstant(GetPassThroughArguments(context))); // Indicate the kind of call by passing `call\perform(?)`, a partial application of call var paCall = context.Factory.Call(context.Invocation.Position, _callImplementation, context.Call, new AstPlaceholder(context.Invocation.File, context.Invocation.Line, context.Invocation.Column, 0)); inv.Arguments.Add(paCall); // Pass all the other arguments through inv.Arguments.AddRange(GetCallArguments(context)); context.Block.Expression = inv; }
private static void _errorUsageFullRef(MacroContext context) { context.ReportMessage( Message.Error( Resources.CallMacro_errorUsageFullRef, context.Invocation.Position, MessageClasses.CallMacroUsage)); }
/// <summary> /// Retrieves the specified resources and wraps them in an data container. /// </summary> /// <param name="settings">CSS settings</param> /// <param name="name">Resource name</param> /// <param name="cached">If true, the result will be cached</param> /// <returns>The data container with the resulting stylesheet data</returns> private static CMSOutputResource GetResource(CMSCssSettings settings, string name, bool cached) { List<CMSOutputResource> resources = new List<CMSOutputResource>(); // Add files if (settings.Files != null) { foreach (string item in settings.Files) { // Get the resource CMSOutputResource resource = GetFile(item, CSS_FILE_EXTENSION); resources.Add(resource); } } // Add stylesheets if (settings.Stylesheets != null) { foreach (string item in settings.Stylesheets) { // Get the resource CMSOutputResource resource = GetStylesheet(item); resources.Add(resource); } } // Add web part containers if (settings.Containers != null) { foreach (string item in settings.Containers) { // Get the resource CMSOutputResource resource = GetContainer(item); resources.Add(resource); } } // Add web parts if (settings.WebParts != null) { foreach (string item in settings.WebParts) { // Get the resource CMSOutputResource resource = GetWebPart(item); resources.Add(resource); } } // Add templates if (settings.Templates != null) { foreach (string item in settings.Templates) { // Get the resource CMSOutputResource resource = GetTemplate(item); resources.Add(resource); } } // Add layouts if (settings.Layouts != null) { foreach (string item in settings.Layouts) { // Get the resource CMSOutputResource resource = GetLayout(item); resources.Add(resource); } } // Add transformation containers if (settings.Transformations != null) { foreach (string item in settings.Transformations) { // Get the resource CMSOutputResource resource = GetTransformation(item); resources.Add(resource); } } // Add web part layouts if (settings.WebPartLayouts != null) { foreach (string item in settings.WebPartLayouts) { // Get the resource CMSOutputResource resource = GetWebPartLayout(item); resources.Add(resource); } } // Combine to a single output CMSOutputResource result = CombineResources(resources); // Resolve the macros if (CSSHelper.ResolveMacrosInCSS) { MacroContext context = new MacroContext() { TrackCacheDependencies = cached }; if (cached) { // Add the default dependencies context.AddCacheDependencies(settings.GetCacheDependencies()); context.AddFileCacheDependencies(settings.GetFileCacheDependencies()); } result.Data = CMSContext.ResolveMacros(result.Data, context); if (cached) { // Add cache dependency result.CacheDependency = CacheHelper.GetCacheDependency(context.FileCacheDependencies, context.CacheDependencies); } } else if (cached) { // Only the cache dependency from settings result.CacheDependency = settings.GetCacheDependency(); } // Minify MinifyResource(result, mCssMinifier, CSSHelper.StylesheetMinificationEnabled && settings.EnableMinification, settings.EnableMinification); return result; }
public static LNodeList UseSymbolsCore(LNodeList symbolAttrs, LNodeList options, LNodeList body, IMacroContext context, bool inType) { // Decode options (TODO: invent a simpler approach) string prefix = "sy_"; var inherited = new HashSet <Symbol>(); foreach (var pair in MacroContext.GetOptions(options)) { if (pair.Key.Name.Name == "prefix" && pair.Value.IsId) { prefix = pair.Value.Name.Name; } else if (pair.Key.Name.Name == "inherit" && pair.Value.Value is Symbol) { inherited.Add((Symbol)pair.Value.Value); } else if (pair.Key.Name.Name == "inherit" && (pair.Value.Calls(S.Braces) || pair.Value.Calls(S.Tuple)) && pair.Value.Args.All(n => n.Value is Symbol)) { foreach (var arg in pair.Value.Args) { inherited.Add((Symbol)arg.Value); } } else { context.Sink.Warning(pair.Key, "Unrecognized parameter. Expected prefix:id or inherit:{@@A; @@B; ...})"); } } // Replace all symbols while collecting a list of them var symbols = new Dictionary <Symbol, LNode>(); LNodeList output = body.SmartSelect(stmt => stmt.ReplaceRecursive(n => { if (!inType && n.ArgCount == 3) { // Since we're outside any type, we must avoid creating symbol // fields. When we cross into a type then we can start making // Symbols by calling ourself recursively with inType=true var kind = EcsValidators.SpaceDefinitionKind(n); if (kind == S.Class || kind == S.Struct || kind == S.Interface || kind == S.Alias || kind == S.Trait) { var body2 = n.Args[2]; return(n.WithArgChanged(2, body2.WithArgs(UseSymbolsCore(symbolAttrs, options, body2.Args, context, true)))); } } var sym = n.Value as Symbol; if (n.IsLiteral && sym != null) { return(symbols[sym] = LNode.Id(prefix + sym.Name)); } return(null); }) ); // Return updated code with variable declaration at the top for all non-inherit symbols used. var _Symbol = F.Id("Symbol"); var vars = (from sym in symbols where !inherited.Contains(sym.Key) select F.Call(S.Assign, sym.Value, F.Call(S.Cast, F.Literal(sym.Key.Name), _Symbol))).ToList(); if (vars.Count > 0) { output.Insert(0, F.Call(S.Var, ListExt.Single(_Symbol).Concat(vars)) .WithAttrs(symbolAttrs.Add(F.Id(S.Static)).Add(F.Id(S.Readonly)))); } return(output); }
/// <summary> /// Attempts to expand the partial macro application. /// </summary> /// <param name = "context">The macro context for this macro expansion.</param> /// <returns>True, if the macro was successfully applied partially; false if partial application is illegal in this particular case.</returns> public bool ExpandPartialApplication(MacroContext context) { return DoExpandPartialApplication(context); }
public static LNode LLLPG_parser(LNode node, IMacroContext context) { return(LllpgMacro(node, context, _parser, parserCfg => { // Scan options in parser(...) node var helper = new GeneralCodeGenHelper(); if (parserCfg == null) { return helper; } foreach (var option in MacroContext.GetOptions(parserCfg.Args)) { LNode value = option.Value; string key = (option.Key ?? (Symbol)"??").Name; switch (key.ToLowerInvariant()) { case "inputsource": helper.InputSource = value; break; case "inputclass": helper.InputClass = value; break; case "terminaltype": helper.TerminalType = value; break; case "settype": helper.SetType = value; break; case "listinitializer": helper.SetListInitializer(value); break; case "latype": helper.LaType = value; break; case "matchtype": // alternate name case "matchcast": helper.MatchCast = value; break; case "allowswitch": if (value.Value is bool) { helper.AllowSwitch = (bool)value.Value; } else { context.Write(Severity.Error, value, "AllowSwitch: expected literal boolean argument."); } break; case "castla": if (value.Value is bool) { helper.CastLA = (bool)value.Value; } else { context.Write(Severity.Error, value, "CastLA: expected literal boolean argument."); } break; default: context.Write(Severity.Error, value, "Unrecognized option '{0}'. Available options: " + "inputSource: variable, inputClass: type, terminalType: type, laType: type, matchCast: type, setType: type, allowSwitch: bool, castLa: bool, listInitializer: var _ = new List<T>()", key); break; } } return helper; }, isDefault: true)); }
public HomeController(ILogger <HomeController> logger, IConfiguration config, MacroContext context) { _logger = logger; _config = config; _context = context; }
private static void _genChecks(MacroContext context, [InstantHandle] Func<AstGetSet> retVar, AstNode contStmt, AstNode breakStmt) { var inv = context.Invocation; //Generate check for continue AstCondition checkCont; { var contCond = _genCompare(context, retVar(), ReturnVariant.Continue); checkCont = new AstCondition(inv.Position, context.CurrentBlock, contCond); checkCont.IfBlock.Add(contStmt); } //Generate check for break AstCondition checkBreak; { var breakCond = _genCompare(context, retVar(), ReturnVariant.Break); checkBreak = new AstCondition(inv.Position, context.CurrentBlock, breakCond); checkBreak.IfBlock.Add(breakStmt); } //Connect break-check to continue check checkCont.ElseBlock.Add(checkBreak); context.Block.Add(checkCont); }
/// <summary> /// Determines the number of arguments that need to be protected when passed to call\star. /// </summary> /// <param name="context"></param> /// <returns></returns> /// <remarks> /// <para>For call and call\async, for instance, two arguments need to be passed to call\star /// unprocessed: the reference to the call implementation (<c>call(?)</c> or <c>call\async(?)</c>) /// and the call target.</para> /// <para>In the case of <c>call\member</c>, however, there is an additional argument to be /// protected: the member id.</para></remarks> protected virtual int GetPassThroughArguments(MacroContext context) { return 2; }
private static void _errorUsagePrototype(MacroContext context) { context.ReportMessage( Message.Error( string.Format(Resources.CallMacro_errorUsagePrototype, Alias), context.Invocation.Position, MessageClasses.CallMacroUsage)); }
private static void _extractReturnValue(MacroContext context, string resultV, string retValueV) { var getRetValue = context.CreateGetSetMember( context.CreateCall(EntityRef.Variable.Local.Create(resultV)), PCall.Get, "Value"); var setRetValue = context.CreateCall(EntityRef.Variable.Local.Create(retValueV), PCall.Set, getRetValue); context.Block.Add(setRetValue); }
private static void _storeResult(MacroContext context, string resultV) { var computeKvp = context.Invocation.Arguments[0]; var setResult = context.CreateCall(EntityRef.Variable.Local.Create(resultV), PCall.Set, computeKvp); context.Block.Add(setResult); }
protected override bool DoExpandPartialApplication(MacroContext context) { var prepareCall = _assembleCallPerform(context); //null indicates failure, error has already been reported. if (prepareCall == null) return true; context.Block.Expression = prepareCall; return true; }
private static void _determinePassThrough(MacroContext context, out int passThrough, out List<AstExpr> arguments) { var arg0 = context.Invocation.Arguments[0]; var passThroughNode = arg0 as AstConstant; if (passThroughNode != null && passThroughNode.Constant is int) { arguments = new List<AstExpr>(context.Invocation.Arguments.Skip(1)); passThrough = (int) passThroughNode.Constant; } else { arguments = new List<AstExpr>(context.Invocation.Arguments); passThrough = 1; } if (passThrough < 1) context.ReportMessage( Message.Error( string.Format(Resources.CallStar__invalid_PassThrough, passThrough), (ISourcePosition)passThroughNode ?? context.Invocation.Position, MessageClasses.CallStarPassThrough)); }
private static AstExpr _getMacroSpecExpr(MacroContext context, AstExpand proto) { return EntityRefTo.ToExpr(context.Factory, context.Invocation.Position, proto.Entity); }
private void C(MacroContext context) { }
/// <summary> /// Implements the expansion of the partially applied macro. May refuse certain partial applications. /// </summary> /// <param name = "context">The macro context for this macro expansion.</param> /// <returns>True, if the macro was successfully applied partially; false if partial application is illegal in this particular case.</returns> protected abstract bool DoExpandPartialApplication(MacroContext context);
private static AstGetSet _assembleImplCall(MacroContext context, SymbolEntry implementationSymbolEntry, ISourcePosition position) { var internalId = context.CreateConstant(implementationSymbolEntry.InternalId); var interpretation = implementationSymbolEntry.Interpretation.ToExpr(position); var moduleNameOpt = context.CreateConstantOrNull(implementationSymbolEntry.Module); var implCall = context.Factory.IndirectCall(context.Invocation.Position, context.Factory.Reference(context.Invocation.Position, EntityRef.Command.Create( Impl.Alias))); implCall.Arguments.Add(internalId); implCall.Arguments.Add(interpretation); implCall.Arguments.Add(moduleNameOpt); return implCall; }
public static int A(MacroContext context) { return(0); }
private static void _determineActions(MacroContext context, [InstantHandle] Func<AstGetSet> retValue, out AstNode contStmt, out AstNode breakStmt) { var inv = context.Invocation; var bl = context.CurrentLoopBlock; if (bl == null) { contStmt = new AstReturn(inv.File, inv.Line, inv.Column, ReturnVariant.Continue) {Expression = retValue()}; breakStmt = new AstReturn(inv.File, inv.Line, inv.Column, ReturnVariant.Break) {Expression = retValue()}; } else { contStmt = new AstExplicitGoTo(inv.File, inv.Line, inv.Column, bl.ContinueLabel); breakStmt = new AstExplicitGoTo(inv.File, inv.Line, inv.Column, bl.BreakLabel); } }
public void A(MacroContext context) { }
private static void _extractReturnVariant(MacroContext context, string resultV, string retVarV) { var inv = context.Invocation; var intT = new AstConstantTypeExpression(inv.File, inv.Line, inv.Column, IntPType.Literal); var getRetVar = context.CreateGetSetMember(context.CreateCall(EntityRef.Variable.Local.Create(resultV)), PCall.Get, "Key"); var asInt = new AstTypecast(inv.File, inv.Line, inv.Column, getRetVar, intT); var setRetVar = context.CreateCall(EntityRef.Variable.Local.Create(retVarV), PCall.Set, asInt); context.Block.Add(setRetVar); }
public static void B(MacroContext context) { }
private static AstExpr _genCompare(MacroContext context, AstExpr retVar, ReturnVariant expected) { var inv = context.Invocation; AstExpr expectedNode = new AstConstant(inv.File, inv.Line, inv.Column, (int) expected); return context.Factory.BinaryOperation(inv.Position, retVar, BinaryOperator.Equality, expectedNode); }
/// <summary> /// Retrieves the specified resources and wraps them in an data container. /// </summary> /// <param name="settings">CSS settings</param> /// <param name="name">Resource name</param> /// <param name="cached">If true, the result will be cached</param> /// <returns>The data container with the resulting stylesheet data</returns> private static CMSOutputResource GetResource(CMSCssSettings settings, string name, bool cached) { List <CMSOutputResource> resources = new List <CMSOutputResource>(); // Add files if (settings.Files != null) { foreach (string item in settings.Files) { // Get the resource CMSOutputResource resource = GetFile(item, CSS_FILE_EXTENSION); resources.Add(resource); } } // Add stylesheets if (settings.Stylesheets != null) { foreach (string item in settings.Stylesheets) { // Get the resource CMSOutputResource resource = GetStylesheet(item); resources.Add(resource); } } // Add web part containers if (settings.Containers != null) { foreach (string item in settings.Containers) { // Get the resource CMSOutputResource resource = GetContainer(item); resources.Add(resource); } } // Add web parts if (settings.WebParts != null) { foreach (string item in settings.WebParts) { // Get the resource CMSOutputResource resource = GetWebPart(item); resources.Add(resource); } } // Add templates if (settings.Templates != null) { foreach (string item in settings.Templates) { // Get the resource CMSOutputResource resource = GetTemplate(item); resources.Add(resource); } } // Add layouts if (settings.Layouts != null) { foreach (string item in settings.Layouts) { // Get the resource CMSOutputResource resource = GetLayout(item); resources.Add(resource); } } // Add transformation containers if (settings.Transformations != null) { foreach (string item in settings.Transformations) { // Get the resource CMSOutputResource resource = GetTransformation(item); resources.Add(resource); } } // Add web part layouts if (settings.WebPartLayouts != null) { foreach (string item in settings.WebPartLayouts) { // Get the resource CMSOutputResource resource = GetWebPartLayout(item); resources.Add(resource); } } // Combine to a single output CMSOutputResource result = CombineResources(resources); // Resolve the macros if (CSSHelper.ResolveMacrosInCSS) { MacroContext context = new MacroContext() { TrackCacheDependencies = cached }; if (cached) { // Add the default dependencies context.AddCacheDependencies(settings.GetCacheDependencies()); context.AddFileCacheDependencies(settings.GetFileCacheDependencies()); } result.Data = CMSContext.ResolveMacros(result.Data, context); if (cached) { // Add cache dependency result.CacheDependency = CacheHelper.GetCacheDependency(context.FileCacheDependencies, context.CacheDependencies); } } else if (cached) { // Only the cache dependency from settings result.CacheDependency = settings.GetCacheDependency(); } // Minify MinifyResource(result, mCssMinifier, CSSHelper.StylesheetMinificationEnabled && settings.EnableMinification, settings.EnableMinification); return(result); }
public Macro(MacroContext context) : base(context) { }
public SoftwaresController(MacroContext context) { _context = context; }