public static CompilerError Instantiate(string code, Node anchor, params object[] args) { return(Instantiate(code, AstUtil.SafeLexicalInfo(anchor), args)); }
public static CompilerWarning AssignmentToSameVariable(BinaryExpression node) { return(Instantiate("BCW0020", AstUtil.SafeLexicalInfo(node))); }
public static CompilerWarning ConstantExpression(Expression node) { return(Instantiate("BCW0022", AstUtil.SafeLexicalInfo(node))); }
public static CompilerWarning NamespaceNeverUsed(Import node) { return(Instantiate("BCW0016", AstUtil.SafeLexicalInfo(node.Expression), node.Expression.ToCodeString())); }
public static CompilerWarning OverridingFinalizeIsBadPractice(TypeMember member) { return(Instantiate("BCW0018", AstUtil.SafeLexicalInfo(member))); }
public static CompilerWarning Obsolete(Node node, IMember member, string message) { return(Instantiate("BCW0012", AstUtil.SafeLexicalInfo(node), member, message)); }
public static CompilerWarning PrivateMemberNeverUsed(TypeMember member) { return(Instantiate("BCW0014", AstUtil.SafeLexicalInfo(member), MemberVisibilityString(member), NodeTypeString(member), member.FullName)); }
public override string ToString() => "do\n" + "{" + $"{AstUtil.Indent(Body.ToString())}\n" + "}\n" + $"while ({Predicate});";
public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { AstUtil.RemoveModifierFrom(typeDeclaration, removableModifier); return(base.TrackedVisitTypeDeclaration(typeDeclaration, data)); }
public override void OnReferenceExpression(ReferenceExpression node) { if (AstUtil.IsStandaloneReference(node) && node.ParentNode.NodeType != NodeType.TypeofExpression && !AstUtil.IsTargetOfMethodInvocation(node)) { Node node2 = new ReferenceFinder(_inferredUnit).Resolve(node) as Node; if (node2 != null) { if (node2.Entity is IType) { node.Annotate(TypeInference.TypeLiteral); } } } }
public override Statement Expand(MacroStatement macro) { componentContextName = ComponentNaming.GetComponentContextName(macro); componentFactoryName = ComponentNaming.GetComponentFactoryName(macro); componentVariableName = ComponentNaming.GetComponentNameFor(macro); if (macro.Arguments.Count == 0) { throw new MonoRailException("Component must be called with a name"); } var block = new Block(); var method = (Method)macro.GetAncestor(NodeType.Method); var componentName = new StringLiteralExpression(macro.Arguments[0].ToString()); var dictionary = CreateParametersDictionary(macro); var macroBody = CodeBuilderHelper.CreateCallableFromMacroBody(CodeBuilder, macro); var initContext = new MethodInvocationExpression { Target = AstUtil.CreateReferenceExpression("Castle.MonoRail.Views.Brail.BrailViewComponentContext") }; initContext.Arguments.Extend( new[] { new SelfLiteralExpression(), macroBody, componentName, AstUtil.CreateReferenceExpression("OutputStream"), dictionary }); // compilerContext = BrailViewComponentContext(macroBodyClosure, "componentName", OutputStream, dictionary) block.Add(new BinaryExpression(BinaryOperatorType.Assign, new ReferenceExpression(componentContextName), initContext)); // AddViewComponentProperties( compilerContext.ComponentParams ) var addProperties = new MethodInvocationExpression(AstUtil.CreateReferenceExpression("AddViewComponentProperties")); addProperties.Arguments.Add(AstUtil.CreateReferenceExpression(componentContextName + ".ComponentParameters")); block.Add(addProperties); var viewComponentFactoryLocal = CodeBuilder.DeclareLocal(method, componentFactoryName, TypeSystemServices.Map( typeof(IViewComponentFactory))); // viewComponentFactory = context.GetService(IViewComponentFactory) var callService = new MethodInvocationExpression( AstUtil.CreateReferenceExpression("context.GetService")); callService.Arguments.Add(CodeBuilder.CreateTypeofExpression(typeof(IViewComponentFactory))); block.Add(new BinaryExpression(BinaryOperatorType.Assign, CodeBuilder.CreateLocalReference(componentFactoryName, viewComponentFactoryLocal), callService)); // component = viewComponentFactory.Create( componentName) var createComponent = new MethodInvocationExpression( new MemberReferenceExpression(CodeBuilder.CreateLocalReference(componentFactoryName, viewComponentFactoryLocal), "Create")); createComponent.Arguments.Add(componentName); block.Add(new BinaryExpression(BinaryOperatorType.Assign, new ReferenceExpression(componentVariableName), createComponent)); AddSections(block, macro); // component.Init(context, componentContext) var initComponent = new MethodInvocationExpression( AstUtil.CreateReferenceExpression(componentVariableName + ".Init")); initComponent.Arguments.Extend( new Expression[] { new ReferenceExpression("context"), new ReferenceExpression(componentContextName) }); block.Add(initComponent); // component.Render() block.Add(new MethodInvocationExpression( AstUtil.CreateReferenceExpression(componentVariableName + ".Render"))); // if component.ViewToRender is not null: // OutputSubView("/"+component.ViewToRender, context.CompnentParameters) var renderView = new Block(); var outputSubView = new MethodInvocationExpression( AstUtil.CreateReferenceExpression("OutputSubView")); outputSubView.Arguments.Add(new BinaryExpression(BinaryOperatorType.Addition, new StringLiteralExpression("/"), AstUtil.CreateReferenceExpression(componentContextName + ".ViewToRender"))); outputSubView.Arguments.Add(AstUtil.CreateReferenceExpression(componentContextName + ".ComponentParameters")); renderView.Add(outputSubView); block.Add(new IfStatement(AstUtil.CreateReferenceExpression(componentContextName + ".ViewToRender"), renderView, new Block())); // RemoveViewComponentProperties( compilerContext.ComponentParams ) var removeProperties = new MethodInvocationExpression(AstUtil.CreateReferenceExpression("RemoveViewComponentProperties")); removeProperties.Arguments.Add(AstUtil.CreateReferenceExpression(componentContextName + ".ComponentParameters")); block.Add(removeProperties); return(block); }
public override bool EnterBinaryExpression(BinaryExpression node) { FixBooleanExpressionTypeIfRequired(node); if (FixMixedBooleanExpressionComparison(node)) { return(false); } if (node.ExpressionType == TypeSystemServices.BoolType || (AstUtil.GetBinaryOperatorKind(node.Operator) != BinaryOperatorKind.Comparison && AstUtil.GetBinaryOperatorKind(node.Operator) != BinaryOperatorKind.Logical)) { return(true); } ConvertExpressionToBooleanIfNecessary(node, node.Right); ConvertExpressionToBooleanIfNecessary(node, node.Left); node.ExpressionType = TypeSystemServices.BoolType; return(false); }
private void ConvertExpressionToBooleanIfNecessary(Node parent, Expression expression) { var unaryExpression = expression as UnaryExpression; if (unaryExpression != null && unaryExpression.Operator == UnaryOperatorType.LogicalNot) { expression.Accept(this); return; } if (expression.ExpressionType == TypeSystemServices.BoolType) { expression.Accept(this); return; } var binaryExpression = expression as BinaryExpression; if (binaryExpression != null && (AstUtil.GetBinaryOperatorKind(binaryExpression) == BinaryOperatorKind.Logical || AstUtil.GetBinaryOperatorKind(binaryExpression) == BinaryOperatorKind.Comparison)) { expression.Accept(this); return; } var literalExpression = LiteralExpressionFor(expression.ExpressionType); if (literalExpression != null) { parent.Replace(expression, new BinaryExpression(BinaryOperatorType.Inequality, expression, literalExpression)); } }
override public void OnAstLiteralExpression(AstLiteralExpression node) { Type type = node.Node.GetType(); CastExpression ce = new CastExpression(CreateFromXmlInvocation(node.Node.LexicalInfo, type, AstUtil.ToXml(node.Node)), CodeBuilder.CreateTypeReference(type)); ce.LexicalInfo = node.LexicalInfo; ReplaceCurrentNode(ce); }
public static CompilerWarning HaveBothKeyNameAndAttribute(Node node) { return(Instantiate("BCW0010", AstUtil.SafeLexicalInfo(node))); }
private static T XmlRoundtripOf <T>(T node) where T : Node { return((T)AstUtil.FromXml(node.GetType(), AstUtil.ToXml(node))); }
public static CompilerWarning AbstractMemberNotImplementedStubCreated(Node node, IType type, IMember abstractMember) { return(Instantiate("BCW0011", AstUtil.SafeLexicalInfo(node), type, abstractMember)); }
protected virtual bool ShouldExpandArgs(IMethod method, ExpressionCollection args) { return(args.Count > 0 && !AstUtil.IsExplodeExpression(args[-1])); }
public static CompilerWarning StaticClassMemberRedundantlyMarkedStatic(Node node, string typeName, string memberName) { return(Instantiate("BCW0013", AstUtil.SafeLexicalInfo(node), typeName, memberName)); }
public override void OnRELiteralExpression(RELiteralExpression node) { int options = (int)AstUtil.GetRegexOptions(node); }
public static CompilerWarning UnreachableCodeDetected(Node node) { return(Instantiate("BCW0015", AstUtil.SafeLexicalInfo(node))); }
private IType TypeContaining(GeneratorExpression node) { return((IType)AstUtil.GetParentClass(node).Entity); }
public static CompilerWarning NewProtectedMemberInSealedType(TypeMember member) { return(Instantiate("BCW0017", AstUtil.SafeLexicalInfo(member), NodeTypeString(member), member.Name, member.DeclaringType.Name)); }
protected virtual MethodInvocationExpression CreateExtension() { return(new MethodInvocationExpression( AstUtil.CreateReferenceExpression(typeof(TExtension).FullName) )); }
public static CompilerWarning AmbiguousExceptionName(ExceptionHandler node) { return(Instantiate("BCW0019", AstUtil.SafeLexicalInfo(node), node.Declaration.Name)); }
override public void OnModule(Module node) { bool hasModuleClass = true; ClassDefinition moduleClass = FindModuleClass(node); if (null == moduleClass) { moduleClass = new ClassDefinition(); moduleClass.IsSynthetic = true; hasModuleClass = false; } Method entryPoint = moduleClass.Members["Main"] as Method; int removed = 0; TypeMember[] members = node.Members.ToArray(); for (int i = 0; i < members.Length; ++i) { TypeMember member = members[i]; if (member is TypeDefinition) { continue; } if (member.NodeType == NodeType.Method) { if (EntryPointMethodName == member.Name) { entryPoint = (Method)member; } member.Modifiers |= TypeMemberModifiers.Static; } node.Members.RemoveAt(i - removed); moduleClass.Members.Add(member); ++removed; } if (node.Globals.Statements.Count > 0) { Method method = new Method(node.Globals.LexicalInfo); method.IsSynthetic = true; method.Parameters.Add(new ParameterDeclaration("argv", new ArrayTypeReference(new SimpleTypeReference("string")))); method.ReturnType = CodeBuilder.CreateTypeReference(TypeSystemServices.VoidType); method.Body = node.Globals; method.Name = EntryPointMethodName; method.Modifiers = TypeMemberModifiers.Static | TypeMemberModifiers.Private; moduleClass.Members.Add(method); node.Globals = null; entryPoint = method; } if (null != entryPoint) { ContextAnnotations.SetEntryPoint(Context, entryPoint); } if (hasModuleClass || _forceModuleClass || (moduleClass.Members.Count > 0)) { if (!hasModuleClass) { moduleClass.Name = BuildModuleClassName(node); moduleClass.Attributes.Add(CreateBooModuleAttribute()); node.Members.Add(moduleClass); } moduleClass.Members.Add(AstUtil.CreateConstructor(node, TypeMemberModifiers.Private)); moduleClass.Modifiers = TypeMemberModifiers.Public | TypeMemberModifiers.Final | TypeMemberModifiers.Transient; ((ModuleEntity)node.Entity).InitializeModuleClass(moduleClass); } }
public static CompilerWarning ComparisonWithSameVariable(BinaryExpression node) { return(Instantiate("BCW0021", AstUtil.SafeLexicalInfo(node))); }
public static CompilerWarning DuplicateNamespace(Import import, string name) { return(Instantiate("BCW0008", AstUtil.SafeLexicalInfo(import.Expression), name)); }
public static CompilerWarning ImplicitReturn(Method node) { return(Instantiate(Codes.ImplicitReturn, AstUtil.SafeLexicalInfo(node))); }
public static CompilerError ExceptionAlreadyHandled(ExceptionHandler dupe, ExceptionHandler previous) { return(Instantiate("BCE0165", dupe.Declaration, dupe.Declaration.Type, previous.Declaration.Type, AstUtil.SafePositionOnlyLexicalInfo(previous.Declaration), LanguageAmbiance.ExceptKeyword)); }