/// <summary> /// Initializes new instance of <see cref="MethodBodyGenerator"/> /// </summary> public MethodBodyGenerator(IMethodBase method, System.Reflection.Emit.ILGenerator generator, bool emitInfo = false) : base(generator, emitInfo) { Method = method; ReturnType = method.ReturnType; Context = method.Context; SyntaxTree = method.SyntaxBody; }
protected override void visitMethodBase(IMethodBase method) { if (method is Constructor const_) { const_.parentClass = ((Class)this.currentInterface); } else if (method is Method meth) { meth.parentInterface = this.currentInterface; } else if (method is GlobalFunction) { } else if (method is Lambda) { } else { } foreach (var param in method.parameters) { param.parentMethod = method; } this.parentNodeStack.push(method); base.visitMethodBase(method); this.parentNodeStack.pop(); }
private bool HandleGetComponent(MethodInvocationExpression node, IMethodBase method) { if ((method.Name != "GetComponent" && method.Name != "AddComponent") || node.Arguments.Count == 0) { return(false); } if (node.Arguments[0].ExpressionType != TypeSystemServices.StringType) { return(false); } var be = node.ParentNode as BinaryExpression; if (be != null && be.Operator == BinaryOperatorType.Assign && be.Right == node) { node.ParentNode.Replace(be.Right, CodeBuilder.CreateCast(be.Left.ExpressionType, be.Right)); return(true); } var castTarget = FindRelatedParameterDefinition(node.ParentNode, node); if (castTarget != null) { node.ParentNode.Replace(node, CodeBuilder.CreateCast(castTarget, node)); } return(false); }
private bool IsCalledByMethod(IMethodBody callerMethodBody, IMethodBase subjectMethod) { var localInvokedMethods = GetLocalInvokedMethods(callerMethodBody); var localInvokedMethodsName = localInvokedMethods.Select(a => a.Identifier.GetField()); return(localInvokedMethodsName.Any(a => a.Equals(subjectMethod.Name))); }
public override TypeName [] GetParameterTypes(IMethodBase method) { return(method.Value().Parameters.Select(p => new TypeName() { Namespace = p.ParameterType.GetCorrectNamespace(), Name = p.ParameterType.GetCorrectName() }).ToArray()); }
public override TypeName [] GetParameterTypes(IMethodBase method) { return(method.Value().Parameters.Select(p => new TypeName() { Name = p.Type }).ToArray()); }
private void RunAnalyzers(IMethodBase method) { foreach (var item in _methodAnalyzers.Where(a => a is ICodeAnalyzer <IMethodBase>)) { item.Analyze(method); _analyzeErrors.AddRange(item.GetResult()); } }
protected override void visitMethodBase(IMethodBase methodBase) { if (!(methodBase is Lambda)) { this.varNames.resetScope(); } base.visitMethodBase(methodBase); }
public CallableSignature(IMethodBase method) { if (null == method) { throw new ArgumentNullException("method"); } Initialize(method.GetParameters(), method.ReturnType, method.AcceptVarArgs); }
public MethodParameter(string name, IType type, Expression initializer, string leadingTrivia) { this.name = name; this.type = type; this.initializer = initializer; this.leadingTrivia = leadingTrivia; this.fieldDecl = null; this.parentMethod = null; this.references = new List <MethodParameterReference>(); }
public AstTransformer(string name) { this.name = name; this.errorMan = new ErrorManager(); this.currentFile = null; this.currentInterface = null; this.currentMethod = null; this.currentClosure = null; this.currentStatement = null; }
private bool AreConnected(IMethodBase method1, IMethodBase method2) { var intersectOfUsedFields = GetUsedClassFieldsIn(method1.MethodBody) .Intersect(GetUsedClassFieldsIn(method2.MethodBody)); var connectedBySharedClassField = intersectOfUsedFields.Any(); var connectedByCallMethod = IsCalledByMethod(method1.MethodBody, method2) || IsCalledByMethod(method2.MethodBody, method1); return(connectedBySharedClassField || connectedByCallMethod); }
private static string GetFileName(IStackFrame frame, IMethodBase method) { var returnVal = frame.GetFileName(); if (!string.IsNullOrWhiteSpace(returnVal)) { return(returnVal); } return(method.ReflectedType != null ? method.ReflectedType.FullName : "(unknown)"); }
private bool BinaryOperatorFor(IMethodBase method, out BinaryOperatorType op) { if (method == _methodCache.Instance.RuntimeServices_EqualityOperator) { op = BinaryOperatorType.Equality; return(true); } if (!method.Name.StartsWith("op_")) { op = BinaryOperatorType.None; return(false); } return(Enum.TryParse(method.Name.Substring("op_".Length), true, out op)); }
protected override void visitMethodBase(IMethodBase method) { if (this.stage != InferTypesStage.Methods) { return; } foreach (var plugin in this.plugins) { if (plugin.handleMethod(method)) { return; } } base.visitMethodBase(method); }
public override void LeaveMethodInvocationExpression(MethodInvocationExpression node) { IMethodBase methodBase = node.Target.Entity as IMethodBase; if (methodBase != null && methodBase.AcceptVarArgs) { IParameter[] parameters = methodBase.GetParameters(); if (parameters.Length == ((ICollection)node.Arguments).Count) { IType expressionType = node.Arguments[-1].ExpressionType; if (expressionType == parameters[parameters.Length + -1].Type) { node.Arguments[-1] = new UnaryExpression(UnaryOperatorType.Explode, node.Arguments[-1]); } } } }
private static string GetMethod(IMethodBase method) { var methodName = string.IsNullOrEmpty(method.Name) ? "unknown" : method.Name; if (method.ReflectedType != null) { methodName = string.Format("{0}.{1}", method.ReflectedType.FullName, methodName); } var parameters = method.GetParameters(); if (parameters.Length > 0) { return(string.Format("{0}({1})", methodName, string.Join(", ", parameters.Select(p => string.Format("{0} {1}", p.ParameterType, p.Name))))); } return(string.Format("{0}()", methodName)); }
/// <summary> /// Checks if the method is public or protected. /// </summary> /// <param name = "method"></param> /// <returns></returns> public static bool IsAccessible(this IMethodBase method) { // Accessibility supported by the full framework and CoreCLR if (method.IsPublic || method.IsFamily || method.IsFamilyOrAssembly) { return(true); } if (method.IsFamilyAndAssembly) { return(true); } if (method.DeclaringType.Assembly().IsInternalToDynamicProxy() && method.IsAssembly) { return(true); } return(false); }
void PushArguments(IMethodBase entity, ExpressionCollection args) { IParameter[] parameters = entity.GetParameters(); for (int i=0; i<args.Count; ++i) { IType parameterType = parameters[i].Type; Expression arg = args[i]; /* InternalParameter internalparam = parameters[i] as InternalParameter; if ((parameterType.IsByRef) || (internalparam != null && internalparam.Parameter.IsByRef) ) */ if (parameters[i].IsByRef) { LoadAddress(arg); } else { arg.Accept(this); EmitCastIfNeeded(parameterType, PopType()); } } }
public ICallableType GetCallableType(IMethodBase method) { var signature = new CallableSignature(method); return GetCallableType(signature); }
void PushArguments(IMethodBase entity, ExpressionCollection args) { var parameters = entity.GetParameters(); for (var i=0; i<args.Count; ++i) { var parameterType = parameters[i].Type; var arg = args[i]; if (parameters[i].IsByRef) LoadAddress(arg); else LoadExpressionWithType(parameterType, arg); } }
public abstract string GetParameterManagedTypeName(IMethodBase m, int index);
public abstract string GetMethodName(IMethodBase m);
public override string GetMethodName(IMethodBase m) { return(m.Value()?.Name); }
public string CreateMethod(IMethodBase sourceMethod) { if (sourceMethod == null) { throw new Exception("sourceMethod is null"); } if (sourceMethod.IsFinal) { throw new Exception("Final method could not be extended"); } if (!(sourceMethod.Visibility == CompilerVisibility.Protected || sourceMethod.Visibility == CompilerVisibility.Public)) { throw new Exception("Only protected and public methods can be extended"); } var attributes = sourceMethod.DataContractAttributes.OfType <IAttributeItem>(); if (attributes != null && attributes.Any(attribute => attribute.Name == "Wrappable" && string.Equals(attribute.Parameters[0].TypeValue, Boolean.FalseString))) { throw new Exception("Only Wrappable methods could be extended"); } if (attributes != null && attributes.Any(attribute => attribute.Name.Contains("InternalUseOnlyAttribute"))) { throw new Exception("Method is marked with InternalUseOnlyAttribute and can not be extended"); } string parametersString = string.Empty; string nextParameters = string.Empty; var parameters = sourceMethod.Parameters.OfType <IMethodParameter>(); if (parameters != null && parameters.Any()) { parametersString = string.Join(", ", parameters.Select(parameter => GetTypeNameFromCompilerType(parameter.TypeCompiler, parameter.TypeName) + " " + parameter.Name + (parameter.IsArray ? "[]" : string.Empty))); nextParameters = string.Join(", ", parameters.Select(parameter => parameter.Name + (parameter.IsArray ? "[]" : string.Empty))); } string nextString = $"next {sourceMethod.Name}({nextParameters});"; StringBuilder methodText = new StringBuilder(); string returnType = GetTypeNameFromCompilerType(sourceMethod.ReturnType.TypeCompiler, sourceMethod.ReturnType.TypeName); methodText.AppendLine( $"{sourceMethod.Visibility.ToString().ToLower()}{(sourceMethod.IsStatic ? StaticString : string.Empty)} {returnType} {sourceMethod.Name}({parametersString})"); methodText.AppendLine("{"); if (sourceMethod.ReturnType.TypeCompiler != CompilerBaseType.Void) { methodText.AppendLine($"\t{returnType} ret = {nextString}"); methodText.AppendLine(); methodText.AppendLine($"\treturn ret;"); } else { methodText.AppendLine($"\t{nextString}"); } methodText.AppendLine("}"); return(methodText.ToString()); }
public abstract TypeName [] GetParameterTypes(IMethodBase method);
public void SetParent(IMethodBase parent) { Parent = parent; }
public void processMethodBase(IMethodBase method) { base.visitMethodBase(method); }
public override string GetMethodReturnManagedTypeName(IMethodBase method) { var m = method.Value(); return(m is Ctor ? null : ((Method)m)?.ManagedReturn); }
public void CheckForSideEffects(IMethodBase method) { _method = method; FindUnsafeModifications(); }
public abstract string GetMethodReturnManagedTypeName(IMethodBase m);
public ICallableType GetCallableType(IMethodBase method) { var signature = new CallableSignature(method); return(GetCallableType(signature)); }
public override string GetParameterManagedTypeName(IMethodBase m, int index) { return(m.Value()?.Parameters [index]?.Type); }