// global assign public AssignVariableNode(String name, List<AbstractNode> indexes, AbstractNode expression, int line) { this.name = name; this.indexes = (indexes == null) ? new List<AbstractNode>() : indexes; this.expression = expression; scope = GlobalMemory.Instance.GlobalScope; this.line = line; }
public AssignVariableNode(String name, List<AbstractNode> indexes, AbstractNode expression, Scope scope, int line) { this.name = name; this.indexes = (indexes == null) ? new List<AbstractNode>() : indexes; this.expression = expression; this.scope = scope; this.line = line; }
public string Render(AbstractNode node, object model) { dynamic localModel = model; Document document = new Document { Children = localModel.Children }; return document.Render(localModel.Model); }
public void Build() { //Assert.isTrue(!built); if (!_built) { throw new InvalidOperationException("Needs to be built."); } _root = _itemBoundables.Count <= 0 ?CreateNode(0) :CreateHigherLevels(_itemBoundables, -1); _built = true; }
public override string Render(AbstractNode node, object model) { var modelValueProviderFactory = Host.DependencyResolver.Resolve<IModelValueProviderFactory>(); if (node == null) { throw new ArgumentNullException("node"); } var blockNode = node as Statement; if (blockNode == null) { throw new InvalidCastException("node"); } object localModel = model; if (blockNode.Parameters != null && blockNode.Parameters.Any()) { localModel = modelValueProviderFactory.Get(model.GetType()).GetValue(model, blockNode.Parameters.First().ValueType, blockNode.Parameters.First().Value); } //get the parameter string layout = ""; if (blockNode.Parameters != null && blockNode.Parameters.Any()) { //assume only the first is the path //second is the argument (model) layout = blockNode.Parameters[0].Value; } //ok...we need to load the layoutpage //then pass the node's children into the layout page //then return the result var result = _engine.FindView(null, layout, null, false); if (result != null) { var parrotView = (result.View as ParrotView); using (var stream = parrotView.LoadStream()) { string contents = new StreamReader(stream).ReadToEnd(); var document = parrotView.LoadDocument(contents); return Host.DependencyResolver.Resolve<DocumentRenderer>().Render(document, localModel); } } throw new InvalidOperationException(); }
public string Render(AbstractNode node, object model) { if (node == null) { throw new ArgumentNullException("node"); } var blockNode = node as Statement; if (blockNode == null) { throw new InvalidCastException("node"); } //get the parameter string layout = ""; if (blockNode.Parameters != null && blockNode.Parameters.Any()) { //assume only the first is the path //second is the argument (model) layout = blockNode.Parameters[0].Value; } //ok...we need to load the view //then pass the model to it and //then return the result var engine = _host.DependencyResolver.Resolve<IViewEngine>(); var result = engine.FindView(null, layout, null, false); if (result != null) { var parrotView = (result.View as ParrotView); using (var stream = parrotView.LoadStream()) { string contents = new StreamReader(stream).ReadToEnd(); var document = parrotView.LoadDocument(contents); var renderer = _host.DependencyResolver.Resolve<DocumentRenderer>(); return renderer.Render(document, new { Children = new StatementList(_host, blockNode.Children.ToArray()), Model = model }); } } throw new InvalidOperationException(); }
public string Render(AbstractNode node, object model) { if (node == null) { throw new ArgumentNullException("node"); } var blockNode = node as BlockNode; if (blockNode == null) { throw new InvalidCastException("node"); } //get the parameter string layout = ""; if (blockNode.Parameters != null && blockNode.Parameters.Any()) { //assume only the first is the path //second is the argument (model) layout = blockNode.Parameters[0].Value; } //ok...we need to load the layoutpage //then pass the node's children into the layout page //then return the result var result = engine.FindView(null, layout, null, false); if (result != null) { var parrotView = (result.View as ParrotView); using (var stream = parrotView.LoadStream()) { string contents = new StreamReader(stream).ReadToEnd(); var document = ParrotView.LoadDocument(contents); return document.Render(new { Children = new BlockNodeList(blockNode.Children.ToArray()), Model = model }); } } throw new InvalidOperationException(); }
public override string Render(AbstractNode node, object model) { var modelValueProviderFactory = Host.DependencyResolver.Resolve<IModelValueProviderFactory>(); object localModel = model; if (node == null) { throw new ArgumentNullException("node"); } var blockNode = node as Statement; if (blockNode == null) { //somehow we're not rendering a blockNode throw new InvalidCastException("node"); } //use the passed in parameter property or use the page model if (blockNode.Parameters.Any()) { localModel = modelValueProviderFactory.Get(model.GetType()).GetValue(model, blockNode.Parameters[0].ValueType, blockNode.Parameters[0].Value); } //Assert that we're looping over something IEnumerable loop = localModel as IEnumerable; if (loop == null) { throw new InvalidCastException("model is not IEnumerable"); } StringBuilder sb = new StringBuilder(); var documentRenderer = Host.DependencyResolver.Resolve<DocumentRenderer>(); foreach (var item in loop) { sb.Append(documentRenderer.Render(blockNode.Children, item)); //sb.Append(blockNode.Children.Render(item)); } return sb.ToString(); }
public string Render(AbstractNode node, object model) { object localModel = model; if (node == null) { throw new ArgumentNullException("node"); } var blockNode = node as BlockNode; if (blockNode == null) { //somehow we're not rendering a blockNode throw new InvalidCastException("node"); } //use the passed in parameter property or use the page model if (blockNode.Parameters.Any()) { blockNode.Parameters[0].SetModel(model); localModel = blockNode.Parameters[0].GetPropertyValue(); } //Assert that we're looping over something IEnumerable loop = localModel as IEnumerable; if (loop == null) { throw new InvalidCastException("model is not IEnumerable"); } StringBuilder sb = new StringBuilder(); foreach (var item in loop) { sb.Append(blockNode.Children.Render(item)); } return sb.ToString(); }
public WebNodeDetails(AbstractNode node) { m_Node = node; }
public override void VisitRoot(AbstractNode root) { SymbolTable.SetCurrentNode(root); root.Accept(this); }
public string Render(AbstractNode node) { return(Render(node, null)); }
public DefaultControlView(DefaultControlAttribute attribute, AbstractNode node, ReflectionProperty property) { var viewCont = new VisualElement(); viewCont.AddToClassList("ControlField"); if (!string.IsNullOrEmpty(attribute.label)) { viewCont.Add(new Label(attribute.label) { name = ControlLabelName }); } var propertyType = property.PropertyType; if (propertyType == typeof(bool)) { var toggle = new Toggle() { name = ValueFieldName }; toggle.value = (bool)property.GetValue(node); toggle.RegisterValueChangedCallback((e) => { node.owner.owner.RegisterCompleteObjectUndo("Boolean Change"); property.SetValue(node, e.newValue); node.Dirty(ModificationScope.Node); }); viewCont.Add(toggle); } #if UNITY_EDITOR else if (propertyType == typeof(float)) { viewCont.Add(AddControl(node, new FloatField() { name = ValueFieldName }, property)); } else if (propertyType == typeof(double)) { viewCont.Add(AddControl(node, new DoubleField() { name = ValueFieldName }, property)); } else if (propertyType == typeof(int)) { viewCont.Add(AddControl(node, new IntegerField() { name = ValueFieldName }, property)); } else if (propertyType == typeof(Color)) { viewCont.Add(AddControl(node, new ColorField() { name = ValueFieldName }, property)); } else if (propertyType == typeof(Bounds)) { viewCont.Add(AddControl(node, new BoundsField() { name = ValueFieldName }, property)); } else if (propertyType == typeof(Rect)) { viewCont.Add(AddControl(node, new RectField() { name = ValueFieldName }, property)); } else if (propertyType == typeof(string)) { viewCont.Add(AddControl(node, new TextField() { name = ValueFieldName }, property)); } else if (propertyType == typeof(Gradient)) { viewCont.Add(AddControl(node, new GradientField() { name = ValueFieldName }, property)); } else if (propertyType == typeof(AnimationCurve)) { viewCont.Add(AddControl(node, new CurveField() { name = ValueFieldName }, property)); } else if (propertyType == typeof(Vector2)) { viewCont.Add(new MultiFloatSlotControlView(node, new[] { "x", "y" }, () => (Vector2)property.GetValue(node), v => property.SetValue(node, (Vector2)v)) { name = ValueFieldName }); } else if (propertyType == typeof(Vector3)) { viewCont.Add(new MultiFloatSlotControlView(node, new[] { "x", "y", "z" }, () => (Vector3)property.GetValue(node), v => property.SetValue(node, (Vector3)v)) { name = ValueFieldName }); } else if (propertyType == typeof(Vector4)) { viewCont.Add(new MultiFloatSlotControlView(node, new[] { "x", "y", "z", "w" }, () => (Vector4)property.GetValue(node), v => property.SetValue(node, v)) { name = ValueFieldName }); } else if (propertyType == typeof(Quaternion)) { viewCont.Add(new MultiFloatSlotControlView(node, new[] { "x", "y", "z" }, () => ((Quaternion)property.GetValue(node)).eulerAngles, v => property.SetValue(node, Quaternion.Euler(v))) { name = ValueFieldName }); } #endif if (viewCont.childCount > 0) { Add(viewCont); } }
public DivNode(AbstractNode node1, AbstractNode node2) : base(node1, node2) { }
public OrNode(AbstractNode node1, AbstractNode node2) : base(node1, node2) { }
public NegateBoolNode(AbstractNode node) : base(node) { }
public string Render(AbstractNode node) { throw new InvalidOperationException(); }
/// <see cref="Translator.Translate"/> public override void Translate(ScriptCompiler compiler, AbstractNode node) { var obj = (ObjectAbstractNode)node; // Create the technique from the material var material = (Material)obj.Parent.Context; this._technique = material.CreateTechnique(); obj.Context = this._technique; // Get the name of the technique if (!string.IsNullOrEmpty(obj.Name)) { this._technique.Name = obj.Name; } // Set the properties for the technique foreach (var i in obj.Children) { if (i is PropertyAbstractNode) { var prop = (PropertyAbstractNode)i; switch ((Keywords)prop.Id) { #region ID_SCHEME case Keywords.ID_SCHEME: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "scheme only supports 1 argument"); } else { string scheme; if (getString(prop.Values[0], out scheme)) { this._technique.Scheme = scheme; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "scheme must have 1 string argument"); } } break; #endregion ID_SCHEME #region ID_LOD_INDEX case Keywords.ID_LOD_INDEX: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "lod_index only supports 1 argument"); } else { int val; if (getInt(prop.Values[0], out val)) { this._technique.LodIndex = val; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "lod_index cannot accept argument \"" + prop.Values[0].Value + "\""); } } break; #endregion ID_LOD_INDEX #region ID_SHADOW_CASTER_MATERIAL case Keywords.ID_SHADOW_CASTER_MATERIAL: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "shadow_caster_material only accepts 1 argument"); } else { string matName; if (getString(prop.Values[0], out matName)) { var evtMatName = string.Empty; ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent(ProcessResourceNameScriptCompilerEvent.ResourceType.Material, matName); compiler._fireEvent(ref evt); evtMatName = ((ProcessResourceNameScriptCompilerEvent)evt).Name; this._technique.ShadowCasterMaterial = (Material)MaterialManager.Instance[evtMatName]; // Use the processed name } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "shadow_caster_material cannot accept argument \"" + prop.Values[0].Value + "\""); } } break; #endregion ID_SHADOW_CASTER_MATERIAL #region ID_SHADOW_RECEIVER_MATERIAL case Keywords.ID_SHADOW_RECEIVER_MATERIAL: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "shadow_receiver_material only accepts 1 argument"); } else { var i0 = getNodeAt(prop.Values, 0); var matName = string.Empty; if (getString(i0, out matName)) { var evtName = string.Empty; ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent(ProcessResourceNameScriptCompilerEvent.ResourceType.Material, matName); compiler._fireEvent(ref evt); evtName = ((ProcessResourceNameScriptCompilerEvent)evt).Name; this._technique.ShadowReceiverMaterial = (Material)MaterialManager.Instance[evtName]; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "shadow_receiver_material_name cannot accept argument \"" + i0.Value + "\""); } } break; #endregion ID_SHADOW_RECEIVER_MATERIAL #region ID_GPU_VENDOR_RULE case Keywords.ID_GPU_VENDOR_RULE: if (prop.Values.Count < 2) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line, "gpu_vendor_rule must have 2 arguments"); } else if (prop.Values.Count > 2) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "gpu_vendor_rule must have 2 arguments"); } else { var i0 = getNodeAt(prop.Values, 0); var i1 = getNodeAt(prop.Values, 1); var rule = new Technique.GPUVendorRule(); if (i0 is AtomAbstractNode) { var atom0 = (AtomAbstractNode)i0; var atom0Id = (Keywords)atom0.Id; if (atom0Id == Keywords.ID_INCLUDE) { rule.Include = true; } else if (atom0Id == Keywords.ID_EXCLUDE) { rule.Include = false; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_vendor_rule cannot accept \"" + i0.Value + "\" as first argument"); } var vendor = string.Empty; if (!getString(i1, out vendor)) { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_vendor_rule cannot accept \"" + i1.Value + "\" as second argument"); } rule.Vendor = RenderSystemCapabilities.VendorFromString(vendor); if (rule.Vendor != GPUVendor.Unknown) { this._technique.AddGPUVenderRule(rule); } } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_vendor_rule cannot accept \"" + i0.Value + "\" as first argument"); } } break; #endregion ID_GPU_VENDOR_RULE #region ID_GPU_DEVICE_RULE case Keywords.ID_GPU_DEVICE_RULE: if (prop.Values.Count < 2) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line, "gpu_device_rule must have at least 2 arguments"); } else if (prop.Values.Count > 3) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line, "gpu_device_rule must have at most 3 arguments"); } else { var i0 = getNodeAt(prop.Values, 0); var i1 = getNodeAt(prop.Values, 1); var rule = new Technique.GPUDeviceNameRule(); if (i0 is AtomAbstractNode) { var atom0 = (AtomAbstractNode)i0; var atom0Id = (Keywords)atom0.Id; if (atom0Id == Keywords.ID_INCLUDE) { rule.Include = true; } else if (atom0Id == Keywords.ID_EXCLUDE) { rule.Include = false; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule cannot accept \"" + i0.Value + "\" as first argument"); } if (!getString(i1, out rule.DevicePattern)) { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule cannot accept \"" + i1.Value + "\" as second argument"); } if (prop.Values.Count == 3) { var i2 = getNodeAt(prop.Values, 2); if (!getBoolean(i2, out rule.CaseSensitive)) { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule third argument must be \"true\", \"false\", \"yes\", \"no\", \"on\", or \"off\""); } } this._technique.AddGPUDeviceNameRule(rule); } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "gpu_device_rule cannot accept \"" + i0.Value + "\" as first argument"); } } break; #endregion ID_GPU_DEVICE_RULE default: compiler.AddError(CompileErrorCode.UnexpectedToken, prop.File, prop.Line, "token \"" + prop.Name + "\" is not recognized"); break; } //end of switch statement } // end of if ( i is PropertyAbstractNode ) else if (i is ObjectAbstractNode) { processNode(compiler, i); } } }
public static Func <BaseUrlRelativePath, Task <OneOf <AbstractNode, None> > > RouteByWalkingNode(AbstractNode root) { return(async path => { var parts = path.GetParts(); Task <OneOf <AbstractNode, None> > fetchRoot = Task.FromResult <OneOf <AbstractNode, None> >(root); return await parts .Aggregate(fetchRoot, async (node, part) => { var oneOf = (await node); return await oneOf.Match(async abstractNode => { var childNodes = (abstractNode as IHasChildNodes)?.ChildNodes ?? ChildNodes.Empty; var child = childNodes.GetChild(part); if (child == null) { return new None(); } var childNode = child.Item5(); return await childNode; }, none => Task.FromResult((OneOf <AbstractNode, None>)none)); }); }); }
/// <see cref="Translator.Translate"/> public override void Translate(ScriptCompiler compiler, AbstractNode node) { var obj = (ObjectAbstractNode)node; // Must have a type as the first value if (obj.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, obj.File, obj.Line); return; } var type = string.Empty; if (!getString(obj.Values[0], out type)) { compiler.AddError(CompileErrorCode.InvalidParameters, obj.File, obj.Line); return; } var system = (ParticleSystem)obj.Parent.Context; this._Affector = system.AddAffector(type); foreach (var i in obj.Children) { if (i is PropertyAbstractNode) { var prop = (PropertyAbstractNode)i; var value = string.Empty; // Glob the values together foreach (var it in prop.Values) { if (it is AtomAbstractNode) { if (string.IsNullOrEmpty(value)) { value = ((AtomAbstractNode)it).Value; } else { value = value + " " + ((AtomAbstractNode)it).Value; } } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); break; } } if (!this._Affector.SetParam(prop.Name, value)) { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } else { processNode(compiler, i); } } }
public ObjectAbstractNode(AbstractNode ptr) : this(OgrePINVOKE.new_ObjectAbstractNode(AbstractNode.getCPtr(ptr)), true) { if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } }
public GreaterThanNode(AbstractNode node1, AbstractNode node2) : base(node1, node2) { }
public SentenceNode(AbstractNode direction, AbstractNode action, AbstractNode distance) { this.direction = direction; this.action = action; this.distance = distance; }
public ReturnNode(AbstractNode expression) { this.expression = expression; }
public void AddChoice(AbstractNode expression, AbstractNode block) { choices.Add(new Choice(expression, block)); }
/// <summary> /// Generates code for the NRefactory node. /// </summary> public abstract string GenerateCode(AbstractNode node, string indentation);
public WebNodeAttributes(AbstractNode node) : base(node) { this.node = node; }
protected void _translateGpuProgram(ScriptCompiler compiler, ObjectAbstractNode obj) { var customParameters = new NameValuePairList(); string syntax = string.Empty, source = string.Empty; AbstractNode parameters = null; foreach (var i in obj.Children) { if (i is PropertyAbstractNode) { var prop = (PropertyAbstractNode)i; if (prop.Id == (uint)Keywords.ID_SOURCE) { if (prop.Values.Count != 0) { if (prop.Values[0] is AtomAbstractNode) { source = ((AtomAbstractNode)prop.Values[0]).Value; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "source file expected"); } } else { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line, "source file expected"); } } else if (prop.Id == (uint)Keywords.ID_SYNTAX) { if (prop.Values.Count != 0) { if (prop.Values[0] is AtomAbstractNode) { syntax = ((AtomAbstractNode)prop.Values[0]).Value; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line, "syntax string expected"); } } else { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line, "syntax string expected"); } } else { string name = prop.Name, value = string.Empty; var first = true; foreach (var it in prop.Values) { if (it is AtomAbstractNode) { if (!first) { value += " "; } else { first = false; } value += ((AtomAbstractNode)it).Value; } } customParameters.Add(name, value); } } else if (i is ObjectAbstractNode) { if (((ObjectAbstractNode)i).Id == (uint)Keywords.ID_DEFAULT_PARAMS) { parameters = i; } else { processNode(compiler, i); } } } if (!GpuProgramManager.Instance.IsSyntaxSupported(syntax)) { compiler.AddError(CompileErrorCode.UnsupportedByRenderSystem, obj.File, obj.Line); //Register the unsupported program so that materials that use it know that //it exists but is unsupported var unsupportedProg = GpuProgramManager.Instance.Create(obj.Name, compiler.ResourceGroup, _translateIDToGpuProgramType(obj.Id), syntax); return; } // Allocate the program object progObj; GpuProgram prog = null; ScriptCompilerEvent evt = new CreateGpuProgramScriptCompilerEvent(obj.File, obj.Name, compiler.ResourceGroup, source, syntax, _translateIDToGpuProgramType(obj.Id)); var processed = compiler._fireEvent(ref evt, out progObj); if (!processed) { prog = (GpuProgram) GpuProgramManager.Instance.CreateProgram(obj.Name, compiler.ResourceGroup, source, _translateIDToGpuProgramType(obj.Id), syntax); } else { prog = (GpuProgram)progObj; } // Check that allocation worked if (prog == null) { compiler.AddError(CompileErrorCode.ObjectAllocationError, obj.File, obj.Line, "gpu program \"" + obj.Name + "\" could not be created"); return; } obj.Context = prog; prog.IsMorphAnimationIncluded = false; prog.PoseAnimationCount = 0; prog.IsSkeletalAnimationIncluded = false; prog.IsVertexTextureFetchRequired = false; prog.Origin = obj.File; // Set the custom parameters prog.SetParameters(customParameters); // Set up default parameters if (prog.IsSupported && parameters != null) { var ptr = prog.DefaultParameters; GpuProgramTranslator.TranslateProgramParameters(compiler, ptr, (ObjectAbstractNode)parameters); } }
/** * @param level -1 to get items */ private void BoundablesAtLevel(int level, AbstractNode top, ArrayList boundables) { //Assert.isTrue(level > -2); if (level <= -2) { throw new InvalidOperationException(); } if (top.GetLevel() == level) { boundables.Add(top); return; } //for (Iterator i = top.GetChildBoundables().iterator(); i.hasNext(); ) foreach(object obj in top.GetChildBoundables()) { IBoundable boundable = (IBoundable) obj; if (boundable is AbstractNode) { BoundablesAtLevel(level, (AbstractNode)boundable, boundables); } else { //Assert.isTrue(boundable is ItemBoundable); if (!(boundable is ItemBoundable)) { throw new InvalidOperationException(); } if (level == -1) { boundables.Add(boundable); } } } return; }
protected void _translateUnifiedGpuProgram(ScriptCompiler compiler, ObjectAbstractNode obj) { var customParameters = new NameValuePairList(); AbstractNode parameters = null; foreach (var i in obj.Children) { if (i is PropertyAbstractNode) { var prop = (PropertyAbstractNode)i; if (prop.Name == "delegate") { var value = string.Empty; if (prop.Values.Count != 0 && prop.Values[0] is AtomAbstractNode) { value = ((AtomAbstractNode)prop.Values[0]).Value; } ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent(ProcessResourceNameScriptCompilerEvent.ResourceType.GpuProgram, value); compiler._fireEvent(ref evt); customParameters["delegate"] = ((ProcessResourceNameScriptCompilerEvent)evt).Name; } else { var name = prop.Name; var value = string.Empty; var first = true; foreach (var it in prop.Values) { if (it is AtomAbstractNode) { if (!first) { value += " "; } else { first = false; } value += ((AtomAbstractNode)it).Value; } } customParameters.Add(name, value); } } else if (i is ObjectAbstractNode) { if (((ObjectAbstractNode)i).Id == (uint)Keywords.ID_DEFAULT_PARAMS) { parameters = i; } else { processNode(compiler, i); } } } // Allocate the program Object progObj; HighLevelGpuProgram prog = null; ScriptCompilerEvent evnt = new CreateHighLevelGpuProgramScriptCompilerEvent(obj.File, obj.Name, compiler.ResourceGroup, string.Empty, "unified", _translateIDToGpuProgramType(obj.Id)); var processed = compiler._fireEvent(ref evnt, out progObj); if (!processed) { prog = (HighLevelGpuProgram) (HighLevelGpuProgramManager.Instance.CreateProgram(obj.Name, compiler.ResourceGroup, "unified", _translateIDToGpuProgramType(obj.Id))); } else { prog = (HighLevelGpuProgram)progObj; } // Check that allocation worked if (prog == null) { compiler.AddError(CompileErrorCode.ObjectAllocationError, obj.File, obj.Line, "gpu program \"" + obj.Name + "\" could not be created"); return; } obj.Context = prog; prog.IsMorphAnimationIncluded = false; prog.PoseAnimationCount = 0; prog.IsSkeletalAnimationIncluded = false; prog.IsVertexTextureFetchRequired = false; prog.Origin = obj.File; // Set the custom parameters prog.SetParameters(customParameters); // Set up default parameters if (prog.IsSupported && parameters != null) { var ptr = prog.DefaultParameters; GpuProgramTranslator.TranslateProgramParameters(compiler, ptr, (ObjectAbstractNode)parameters); } }
public void NotImplementedError(AbstractNode node) { string errormessage = "This node is visited, but its not implemented! - " + node.ToString(); PrintError(errormessage); }
public static List <TypeDeclaration> types(this AbstractNode abstractNode) { return(abstractNode.types(false)); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AbstractNode obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
private void WriteGreenType(TreeType node) { WriteComment(node.TypeComment, " "); if (node is AbstractNode) { AbstractNode nd = (AbstractNode)node; WriteLine(" public abstract partial class {0} : {1}", node.Name, node.Base); WriteLine(" {"); var concreteFields = nd.Fields.Where(f => !IsAbstract(f)).ToList(); var abstractFields = nd.Fields.Where(f => IsAbstract(f)).ToList(); foreach (var field in concreteFields) { var type = GetFieldType(field); WriteLine(" private readonly {0} {1};", type, CamelCase(field.Name)); } var fieldArgs = string.Empty; if (concreteFields.Any()) { fieldArgs = concreteFields.Aggregate("", (str, a) => str + $", {a.Type} {CamelCase(a.Name)}"); } // ctor with diagnostics WriteLine(" protected {0}(SyntaxKind kind{1}, IEnumerable<Diagnostic> diagnostics)", node.Name, fieldArgs); WriteLine(" : base(kind, diagnostics)"); WriteLine(" {"); var valueFields = concreteFields.Where(n => !IsNodeOrNodeList(n.Type)).ToList(); var nodeFields = concreteFields.Where(n => IsNodeOrNodeList(n.Type)).ToList(); WriteCtorBody(valueFields, nodeFields); WriteLine(" }"); // ctor without diagnostics WriteLine(" protected {0}(SyntaxKind kind{1})", node.Name, fieldArgs); WriteLine(" : base(kind)"); WriteLine(" {"); WriteCtorBody(valueFields, nodeFields); WriteLine(" }"); foreach (var field in concreteFields) { WriteLine(); WriteComment(field.PropertyComment, " "); WriteLine(" public {0}{1} {2} => {3};", (IsNew(field) ? "new " : ""), field.Type, field.Name, CamelCase(field.Name)); } foreach (var field in abstractFields) { WriteLine(); WriteComment(field.PropertyComment, " "); WriteLine(" public abstract {0}{1} {2} {{ get; }}", (IsNew(field) ? "new " : ""), field.Type, field.Name); } WriteLine(" }"); } else if (node is Node) { Node nd = (Node)node; var baseFields = GetBaseFields(nd); var hasDerivedTypes = nd.Fields.Any(IsDerived); WriteLine(" public sealed partial class {0} : {1}", node.Name, node.Base); WriteLine(" {"); var valueFields = nd.Fields.Where(n => !IsNodeOrNodeList(n.Type)).ToList(); var nodeFields = nd.Fields.Where(n => IsNodeOrNodeList(n.Type)).ToList(); for (int i = 0, n = nodeFields.Count; i < n; i++) { var field = nodeFields[i]; var type = GetFieldType(field); WriteLine(" private readonly {0} {1};", type, CamelCase(field.Name)); } for (int i = 0, n = valueFields.Count; i < n; i++) { var field = valueFields[i]; WriteLine(" private readonly {0} {1};", field.Type, CamelCase(field.Name)); } var ctorAccess = hasDerivedTypes ? "private" : "public"; // write constructor with diagnostics WriteLine(); if (HasOneKind(nd)) { Write(" {0} {1}(", ctorAccess, node.Name); } else { Write(" {0} {1}(SyntaxKind kind, ", ctorAccess, node.Name); } if (baseFields.Any()) { Write(baseFields.Aggregate("", (str, a) => str + $"{a.Type} {CamelCase(a.Name)}, ")); } WriteGreenNodeConstructorArgs(nodeFields, valueFields); var baseFieldsStr = (baseFields.Any() ? ", " : string.Empty) + string.Join(", ", baseFields.Select(a => CamelCase(a.Name))); WriteLine(", IEnumerable<Diagnostic> diagnostics)"); if (HasOneKind(nd)) { WriteLine(" : base(SyntaxKind.{0}{1}, diagnostics)", nd.Kinds[0].Name, baseFieldsStr); } else { WriteLine(" : base(kind{0}, diagnostics)", baseFieldsStr); } WriteLine(" {"); WriteCtorBody(valueFields, nodeFields); WriteLine(" }"); WriteLine(); // write constructor without diagnostics WriteLine(); if (HasOneKind(nd)) { Write(" {0} {1}(", ctorAccess, node.Name); } else { Write(" {0} {1}(SyntaxKind kind, ", ctorAccess, node.Name); } if (baseFields.Any()) { Write(baseFields.Aggregate("", (str, a) => str + $"{a.Type} {CamelCase(a.Name)}, ")); } WriteGreenNodeConstructorArgs(nodeFields, valueFields); WriteLine(")"); if (HasOneKind(nd)) { WriteLine(" : base(SyntaxKind.{0}{1})", nd.Kinds[0].Name, baseFieldsStr); } else { WriteLine(" : base(kind{0})", baseFieldsStr); } WriteLine(" {"); WriteCtorBody(valueFields, nodeFields); WriteLine(" }"); WriteLine(); // property accessors for (int i = 0, n = nodeFields.Count; i < n; i++) { var field = nodeFields[i]; WriteComment(field.PropertyComment, " "); WriteLine(" public {0}{1} {2} {{ get {{ return this.{3}; }} }}", OverrideOrNewModifier(field), field.Type, field.Name, CamelCase(field.Name) ); // additional getters foreach (var getter in field.Getters) { WriteLine(" public {0}{1} {2} {{ get {{ return this.{3}; }} }}", OverrideOrNewModifier(getter), field.Type, getter.Name, CamelCase(field.Name) ); } } for (int i = 0, n = valueFields.Count; i < n; i++) { var field = valueFields[i]; WriteComment(field.PropertyComment, " "); WriteLine(" public {0}{1} {2} {{ get {{ return this.{3}; }} }}", OverrideOrNewModifier(field), field.Type, field.Name, CamelCase(field.Name) ); // additional getters foreach (var getter in field.Getters) { WriteLine(" public {0}{1} {2} {{ get {{ return this.{3}; }} }}", OverrideOrNewModifier(getter), field.Type, getter.Name, CamelCase(field.Name) ); } } this.WriteGreenAcceptMethods(nd); this.WriteGreenUpdateMethod(nd); this.WriteRedSetters(nd); this.WriteSetDiagnostics(nd); WriteLine(" }"); } }
public override void Visit(AbstractNode node) { SymbolTable.SetCurrentNode(node); SymbolTable.NotImplementedError(node); }
public void AddStatement(AbstractNode stat) { statements.Add(stat); }
public void BuildSymbolTable(AbstractNode root) { VisitRoot(root); }
public static bool isLastChild(this AbstractNode abstractNode, Type type) { var lastChild = abstractNode.lastChild(); return((lastChild != null) && lastChild.GetType() == type); }
public LookupNode(AbstractNode e, List<AbstractNode> i) { expression = e; indexes = i; }
public static List <ReturnStatement> returnStatements(this AbstractNode abstractNode) { return(abstractNode.notNull() ? abstractNode.iNodes <ReturnStatement>() : new List <ReturnStatement> ()); }
public VariableGetAbstractNode( AbstractNode parent ) : base( parent ) { }
AbstractNode generate(AbstractNode f, String end, bool flag, bool isCycle, String subName, String thread) { while (isCycle || (f != null && (flag ? !f.ElemName.StartsWith(end) : !f.ElemName.Equals(end)))) { if (!isCycle && !(f is FinishNode) && (f is IterationsNode && f.SourceAbstractNode.Count == 3 || (f is EndIfNode) && f.SourceAbstractNode.Count == 3 || !(f is IterationsNode) && !(f is EndIfNode) && !(f is EndParallelNode) && f.SourceAbstractNode.Count == 2)) { writer.WriteLine("while(true) {"); writer.PushIndent(" "); f = generate(f, f.ElemName, false, true, subName, thread); writer.PopIndent(); writer.WriteLine("}"); //f = null; } else if (f is FinishNode) { writer.WriteLine("return;"); break; } //Warning(f.GetType().ToString()); else if (f is IfNode) { AbstractNode g = null; for (int i = 0; i < f.TargetAbstractNode.Count; i++) { String cond = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f)[i].Condition; if (cond.Equals("out")) { continue; } else if (cond.Equals("true")) { writer.WriteLine("if (" + (f as IfNode).condition + ") {"); writer.PushIndent(" "); g = generate(f.TargetAbstractNode[i], "EndIfNode", true, false, subName, thread); writer.PopIndent(); writer.WriteLine("}"); } } for (int i = 0; i < f.TargetAbstractNode.Count; i++) { String cond = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f)[i].Condition; if (cond.Equals("out")) { continue; } else if (!cond.Equals("true")) { writer.WriteLine("else {"); writer.PushIndent(" "); f = generate(f.TargetAbstractNode[i], "EndIfNode", true, false, subName, thread); writer.PopIndent(); writer.WriteLine("}"); break; } } if (f == null) { f = g; } } else if (f is SubprogramCallNode) { writer.WriteLine(((SubprogramCallNode)f).Subprogram + "();"); for (int i = 0; i < f.TargetAbstractNode.Count; i++) { String cond = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f)[i].Condition; if (cond.Equals("out")) { continue; } f = f.TargetAbstractNode[i]; } } else if (f is IterationsNode) { writer.WriteLine(String.Format("for ({0} = 0; {0} < {1}; {0}++) {{", f.ElemName, (f as IterationsNode).number)); writer.PushIndent(" "); for (int i = 0; i < f.TargetAbstractNode.Count; i++) { String cond = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f)[i].Condition; if (cond.Equals("out")) { continue; } f = generate(f.TargetAbstractNode[i], f.ElemName, false, false, subName, thread); } writer.PopIndent(); writer.WriteLine("}"); } else if (f is EndParallelNode) { if (!AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f)[0].Condition.Equals(thread)) { writer.WriteLine("return;"); break; } else { var list = AbstractNodeReferencesTargetAbstractNode.GetLinksToSourceAbstractNode(f); for (int i = 0; i < list.Count; i++) { if (!thread.Equals(list[i].Condition)) { writer.WriteLine("Threading.joinThread(\"{0}\");", list[i].Condition.Equals("") ? "main" : list[i].Condition); } } f = f.TargetAbstractNode[0]; } } else if (f is ParallelNode) { var list = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f); AbstractNode g = null; int cur = 0; for (int i = 0; i < list.Count; i++) { if (!thread.Equals(list[i].Condition)) { writer.WriteLine("Threading.startThread(\"{0}\", \"{1}\");", list[i].Condition, subName + f.ElemName + "_" + cur); cur++; } else { g = f.TargetAbstractNode[i]; } } f = g; } else if (f is BreakNode) { writer.WriteLine("break;"); break; } else if (f is SwitchNode) { writer.WriteLine(String.Format("switch ({0}) {{", ((SwitchNode)f).Condition)); AbstractNode g, g0 = null; writer.PushIndent(" "); for (int i = 0; i < f.TargetAbstractNode.Count; i++) { String cond = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f)[i].Condition; if (cond.Equals("out")) { continue; } else if (cond.Equals("")) { writer.WriteLine("default:"); } else { writer.WriteLine(String.Format("case {0}:", AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f)[i].Condition)); } writer.PushIndent(" "); g = generate(f.TargetAbstractNode[i], "EndSwitch", true, false, subName, thread); writer.WriteLine("break;"); writer.PopIndent(); if (g != null) { g0 = g; } } writer.PopIndent(); writer.WriteLine("}"); f = g0; } else if (f is MotorsNode) { String[] ports = ((MotorsNode)f).Ports.Split(','); int power = ((MotorsNode)f).Power; foreach (String s in ports) { writer.WriteLine("brick.motor({0}).setPower({1});", s, power); } f = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f).First(obj => obj.Condition != "out").TargetAbstractNode; } else if (f is DelayNode) { int ms = ((DelayNode)f).Time; writer.WriteLine("script.wait({0});", ms); f = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f).First(obj => obj.Condition != "out").TargetAbstractNode; } else if (f is WaitSensorNode) { int dist = ((WaitSensorNode)f).Distance; string rv = ((WaitSensorNode)f).ReceivedValue; string port = ((WaitSensorNode)f).Port; writer.WriteLine("while (!(brick.sensor({0}).read() {1} {2})) {{", port, rv, dist); writer.PushIndent(" "); writer.WriteLine("script.wait(10);"); writer.PopIndent(); writer.WriteLine("}"); f = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f).First(obj => obj.Condition != "out").TargetAbstractNode; } else if (f is WaitTouchNode) { string port = ((WaitTouchNode)f).Port; writer.WriteLine("while (brick.sensor({0}).read() < 0) {{", port); writer.PushIndent(" "); writer.WriteLine("script.wait(10);"); writer.PopIndent(); writer.WriteLine("}"); f = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f).First(obj => obj.Condition != "out").TargetAbstractNode; } else if (f is MotorsOffNode) { String[] ports = ((MotorsOffNode)f).Ports.Split(','); foreach (String s in ports) { writer.WriteLine("brick.motor({0}).powerOff();", s); } f = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f).First(obj => obj.Condition != "out").TargetAbstractNode; } isCycle = false; } if (f is FinishNode && end.StartsWith("FinishNode")) { writer.WriteLine("return;"); } if (f == null) { return(null); } for (int i = 0; i < f.TargetAbstractNode.Count; i++) { String cond = AbstractNodeReferencesTargetAbstractNode.GetLinksToTargetAbstractNode(f)[i].Condition; if (cond.Equals("out")) { return(f.TargetAbstractNode[i]); } } return(f.TargetAbstractNode.Count > 0 ? f.TargetAbstractNode[f.TargetAbstractNode.Count - 1] : null); }
public Choice(AbstractNode expression, AbstractNode block) { this.expression = expression; this.block = block; }
public string Render(AbstractNode node, object model) { var modelValueProviderFactory = _host.DependencyResolver.Resolve <IModelValueProviderFactory>(); if (node == null) { throw new ArgumentNullException("node"); } var blockNode = node as Statement; //this tag can't have any children if (blockNode.Children.Any()) { throw new Exception("Block can't have any children"); } var localModel = model; TagBuilder tag = new TagBuilder("input"); foreach (var attribute in blockNode.Attributes) { object attributeValue = model; if (attributeValue != null) { attributeValue = modelValueProviderFactory.Get(model.GetType()).GetValue(model, attribute.ValueType, attribute.Value); } else { attributeValue = modelValueProviderFactory.Get(typeof(object)).GetValue(model, attribute.ValueType, attribute.Value); } if (attribute.Key == "class") { tag.AddCssClass((string)attributeValue); } else { Func <object, Parrot.Infrastructure.ValueType, bool> noOutput = (a, v) => { if (a is bool && !(bool)attributeValue) { return(true); } if (attributeValue == null && v == Parrot.Infrastructure.ValueType.Keyword) { return(true); } return(false); }; if (attributeValue is bool && (bool)attributeValue) { tag.MergeAttribute(attribute.Key, attribute.Key, true); } else if (noOutput(attributeValue, attribute.ValueType)) { //checked=false should not output the checked attribute //checked=null should not output the checked attribute } else { tag.MergeAttribute(attribute.Key, (string)attributeValue, true); } } } //check and see if there's a parameter and assign it to value if (blockNode.Parameters != null && blockNode.Parameters.Count == 1) { //grab only the first var parameter = blockNode.Parameters[0]; string value = parameter.Value; tag.MergeAttribute("value", value, true); } return(tag.ToString(TagRenderMode.SelfClosing)); }
public WhileNode(AbstractNode expression, AbstractNode block) { this.expression = expression; this.block = block; }
public override string GenerateCode(AbstractNode node, string indentation) { return(" - there is no code generator for this language - "); }
public NotEqualsNode(AbstractNode node1, AbstractNode node2) : base(node1, node2) { }
public AbstractTernaryOperatorNode(AbstractNode node1, AbstractNode node2, AbstractNode node3) { this.node1 = node1; this.node2 = node2; this.node2 = node3; }
private void Query(object searchBounds, AbstractNode node, ArrayList matches) { //for (Iterator i = node.getChildBoundables().iterator(); i.hasNext(); ) foreach(object obj in node.GetChildBoundables()) { IBoundable childBoundable = (IBoundable) obj; if (!GetIntersectsOp().Intersects(childBoundable.GetBounds(), searchBounds)) { continue; } if (childBoundable is AbstractNode) { Query(searchBounds, (AbstractNode) childBoundable, matches); } else if (childBoundable is ItemBoundable) { matches.Add(((ItemBoundable)childBoundable).GetItem()); } else { //Assert.shouldNeverReachHere(); throw new InvalidOperationException("Should never reach here."); } } }
protected void generateFormula(int solutionBounds, int difficulty) { formulaTree = AbstractNode.createTree(Difficulty.getRandomInt(solutionBounds), difficulty); solution = formulaTree.getValue().ToString(); //Debug.Log(formulaTree + " = " + formulaTree.getValue()); }
// Object graph visualizer: collection support temp disabled (porting to new NRefactory). /*void LoadNodeCollectionContent(AbstractNode node, GraphExpression thisObject, DebugType iListType) { var thisObjectAsIList = new GraphExpression(thisObject.Expr.CastToIList(), thisObject.GetValue); int listCount = thisObjectAsIList.GetValue().GetIListCount(); PropertyInfo indexerProp = iListType.GetProperty("Item"); var v = new List<String>(); for (int i = 0; i < listCount; i++) { var itemExpr = new GraphExpression( thisObjectAsIList.Expr.AppendIndexer(i), () => thisObjectAsIList.GetValue().GetIListItem(i) // EXPR-EVAL, Does a 'cast' to IList ); PropertyNode itemNode = new PropertyNode( new ObjectGraphProperty { Name = "[" + i + "]", MemberInfo = indexerProp, Expression = itemExpr, Value = "", IsAtomic = true, TargetNode = null }); node.AddChild(itemNode); } }*/ void LoadNodeObjectContent(AbstractNode node, GraphExpression expression, IType type) { // base var baseType = type.DirectBaseTypes.FirstOrDefault(); if (baseType != null) { var baseClassNode = new BaseClassNode(baseType.FullName, baseType.Name); node.AddChild(baseClassNode); LoadNodeObjectContent(baseClassNode, expression, baseType); } var members = type.GetFieldsAndNonIndexedProperties(GetMemberOptions.IgnoreInheritedMembers). Where(m => !m.IsStatic && !m.IsSynthetic && !m.Name.EndsWith(">k__BackingField")). ToList(); // non-public members var nonPublicProperties = createProperties(expression, members.Where(m => !m.IsPublic)); if (nonPublicProperties.Count > 0) { var nonPublicMembersNode = new NonPublicMembersNode(); node.AddChild(nonPublicMembersNode); foreach (var nonPublicProperty in nonPublicProperties) { nonPublicMembersNode.AddChild(new PropertyNode(nonPublicProperty)); } } // public members foreach (var property in createProperties(expression, members.Where(m => m.IsPublic))) { node.AddChild(new PropertyNode(property)); } }
public void Init() { Program.TestMode = true; CST = Program.BuildCST("kode_ast.giraph"); AST = Program.BuildAST(CST); }
public ClimatogramViewModel(Grade grade, Continent continent, Country country, Location location, double[] antwoorden, string[] vragen, double[][] antwoordOpties, AbstractNode determinatietabel, string[] climatogramSolution, List <Boolean> determinatiePad) { Grade = grade; Continent = continent; Country = country; Location = location; Determinatietabel = determinatietabel; ClimatogramSolution = climatogramSolution; DeterminatiePad = determinatiePad.ToArray(); Vragen = vragen; Antwoorden = antwoorden; AntwoordOpties = antwoordOpties; MonthLabels = Location.Climatogram.MonthlyDataList.Select(m => m.Month).ToArray(); PrecipitationData = Location.Climatogram.MonthlyDataList.Select(m => m.Percipitation).ToArray(); TemperatureData = Location.Climatogram.MonthlyDataList.Select(m => m.Temperature).ToArray(); SetChart(); }
public void SetCurrentNode(AbstractNode node) { _currentNode = node; }
public LowerThanNode(AbstractNode node1, AbstractNode node2) : base(node1, node2) { }
void AddModifiers (AbstractNode parent, LocationsBag.MemberLocations location) { if (location == null || location.Modifiers == null) return; foreach (var modifier in location.Modifiers) { parent.AddChild (new CSharpModifierToken (Convert (modifier.Item2), modifierTable[modifier.Item1]), AbstractNode.Roles.Modifier); } }
private INode CreateBehaviourNode(AbstractNode abstractNode, List <INode> childNodes) { var id = abstractNode.Raw[0].Value; if (id == "CALL") { //Special case for call lookups var type = typeof(Node.Decorator.Call); if (childNodes.Count != 0) { throw new GenerationException($"Node '{id}' cannot have any child nodes.", abstractNode.Raw[0].MatchIndex); } var node = new Node.Decorator.Call(); deferredCallNodes.Add(new KeyValuePair <AbstractNode, Node.Decorator.Call>(abstractNode, node)); return(node); } else if (builtInLookup.TryGetValue(id, out var type)) { //Built-in type var constructor = type.GetConstructors()[0]; var parameters = constructor.GetParameters(); var paramObjs = new object[parameters.Length]; if (parameters.Length > 0) { int paramsStart = 0; if (parameters[0].ParameterType == typeof(INode)) { paramsStart++; if (childNodes.Count != 1) { throw new GenerationException($"Node '{id}' needs exactly one child node.", abstractNode.Raw[0].MatchIndex); } paramObjs[0] = childNodes[0]; } else if (parameters[0].ParameterType == typeof(List <INode>)) { paramsStart++; if (childNodes.Count < 1) { throw new GenerationException($"Node '{id}' needs at least one child node.", abstractNode.Raw[0].MatchIndex); } paramObjs[0] = childNodes; } for (int i = paramsStart; i < parameters.Length; i++) { var p = parameters[i]; string nodeParamData = string.Empty; if (1 + i - paramsStart < abstractNode.Raw.Count) { var ptoken = abstractNode.Raw[1 + i - paramsStart]; if (ptoken.Id == "VALUE") { nodeParamData = ptoken.Value; } } //Expecting Func<T> only var isExpectedFunc = p.ParameterType.Name.Contains("Func") && p.ParameterType.BaseType == typeof(System.MulticastDelegate) && p.ParameterType.GenericTypeArguments.Length == 1; if (!isExpectedFunc) { throw new GenerationException($"Unexpected parameter type in constructor for node type '{type.Name}'. Only Func<T> is supported", abstractNode.Raw[0].MatchIndex); } else { if (nodeParamData == string.Empty) { paramObjs[i] = null; } else { var genericType = p.ParameterType.GenericTypeArguments[0]; var func = CreateFuncParameter(genericType, nodeParamData); if (func == null) { throw new GenerationException($"Parameter type ({genericType.Name}) in constructor for node type '{type.Name}' not supported.", abstractNode.Raw[0].MatchIndex); } paramObjs[i] = func; } } } } var node = (INode)Activator.CreateInstance(type, paramObjs); var labelToken = abstractNode.Raw.FirstOrDefault(t => t.Id == "LABEL"); if (labelToken != null) { var label = labelToken.Value.Replace(":", ""); if (labelLookup.ContainsKey(label)) { throw new GenerationException($"Label '{label}' is already assigned to another node.", labelToken.MatchIndex); } labelLookup.Add(label, node); } return(node); } else { throw new GenerationException($"Could not find node type '{id}'", abstractNode.Raw[0].MatchIndex); } }
public string Render(AbstractNode node) { return Render(node, null); }
private NodeView GetNodeElement(AbstractNode node) { return(GetNodeByGuid(node.guid) as NodeView); }