// public override Reference GetReference() // { // throw MyParams.GetException("should not be invoked"); // } public override ExpressionCompilationResult TryGetSetter(AbstractILCompilerParams @params, Reference referenceToAssign) { var invocationTarget = new ClassMethodTarget(new ClassMethodReference(myReference, "set_Item")); var returnedValues = new Dictionary <ParameterIndex, Reference> { { ParameterIndex.ReturnValueIndex, @params.LocalVariableIndexer.GetNextVariable() } }; var passedValues = new Dictionary <ParameterIndex, Reference> { { new ParameterIndex(1), referenceToAssign } }; if (myArgument != null) { passedValues.Add(new ParameterIndex(0), myArgument); } var statement = new InvocationStatement(GetLocation(), invocationTarget, passedValues, returnedValues); var invocationInstruction = new Instruction(statement, @params.GetNewInstructionId()); var summaryBlock = ElementCompiler.GetInstructionsConnectedSequentially(new List <IInstructionsContainer> { this, invocationInstruction }); var invocationResultReference = returnedValues[ParameterIndex.ReturnValueIndex]; return(new ExpressionCompilationResult(summaryBlock, GetLocation(), invocationResultReference)); }
public Statement GetStatement() { var method = statementInterpreterHandler.GetStatement(ies.Expression); if (method is NameOfStatement) { //nameof() var arguments1 = ies.ArgumentList.Arguments.Select(x => statementInterpreterHandler.GetStatement(x)); return(new ConstantStatement(arguments1.Cast <IdentifierStatement>().First().Name)); } var invocationStatement = new InvocationStatement(); var methodSymbolInfo = semanticModel.GetSymbolInfo(ies.Expression); var arguments = new List <Statement>(); if (methodSymbolInfo.Symbol is IMethodSymbol methodSymbol) { for (int i = 0; i < methodSymbol.Parameters.Length; i++) { var parameter = methodSymbol.Parameters[i]; if (!parameter.IsOptional) { arguments.Add(statementInterpreterHandler.GetStatement(ies.ArgumentList.Arguments[i])); } else { var argumentSyntax = ies.ArgumentList.Arguments.FirstOrDefault(x => x.NameColon != null && x.NameColon.Name.Identifier.ValueText == parameter.Name); if (argumentSyntax == null) { if (ies.ArgumentList.Arguments.Count <= i) { //use default value arguments.Add(new ConstantStatement(parameter.ExplicitDefaultValue)); } else { arguments.Add(statementInterpreterHandler.GetStatement(ies.ArgumentList.Arguments[i])); } } else { arguments.Add(statementInterpreterHandler.GetStatement(argumentSyntax)); } } } invocationStatement.ParametersSignature = methodSymbol.Parameters.Select(x => x.Type.GetClassType()).ToArray(); } invocationStatement.Method = method as MethodMemberStatement; invocationStatement.Arguments.AddRange(arguments); return(invocationStatement); }
public ResolvedInvocationStatement( InvocationStatement source, Dictionary <SecondaryEntity, ParameterIndex> passedParameters, Dictionary <ParameterIndex, SecondaryEntity> returnedValues, Entity resolvedEntity, ResolvedMethodId resolvedMethodId) : base(source.Location) { TargetEntity = resolvedEntity; TargetMethodId = resolvedMethodId; PassedParameters = passedParameters; ReturnedValues = returnedValues; IsConstructor = source.IsConstructor; }
public virtual ExpressionCompilationResult TryGetSetter(AbstractILCompilerParams @params, Reference referenceToAssign) { if (!(myReference is ClassPropertyReference propertyReference)) { return(null); } var invocationTarget = new ClassMethodTarget(new ClassMethodReference(propertyReference.Owner, $"set_{propertyReference.Name}")); var returnedValues = new Dictionary <ParameterIndex, Reference>(); returnedValues.Add(ParameterIndex.ReturnValueIndex, @params.LocalVariableIndexer.GetNextVariable()); var passedValues = new Dictionary <ParameterIndex, Reference> { { new ParameterIndex(0), referenceToAssign } }; var statement = new InvocationStatement(GetLocation(), invocationTarget, passedValues, returnedValues); var invocationInstruction = new Instruction(statement, @params.GetNewInstructionId()); var summaryBlock = ElementCompiler.GetInstructionsConnectedSequentially(new List <IInstructionsContainer> { this, invocationInstruction }); var invocationResultReference = returnedValues[ParameterIndex.ReturnValueIndex]; return(new ExpressionCompilationResult(summaryBlock, GetLocation(), invocationResultReference)); }
public InvocationExpressionInterpreter(ExpressionInterpreterHandler expressionInterpreterHandler, InvocationStatement invocationStatement) { this.expressionInterpreterHandler = expressionInterpreterHandler; this.invocationStatement = invocationStatement; }
public override ICompilationResult GetResult() { var location = GetLocation(myInvocationExpression); var argumentListResult = MyChildToResult[myInvocationExpression.ArgumentList] as ArgumentListCompilationResult; var invokedExpressionCompilationResult = MyChildToResult[myInvocationExpression.InvokedExpression]; var delegateParameters = new Dictionary <int, Reference>(); var arguments = new Dictionary <ParameterIndex, Reference>(); foreach (var(inParameter, result) in argumentListResult.ArgumentsResults) { // call getter var passedVariable = result.GetReference(); if (passedVariable != null) { arguments.Add(inParameter, passedVariable); } } var argumentsInstructionBlock = GetInstructionsConnectedSequentially(argumentListResult.ArgumentsResults.Select(kv => kv.Value)); if (!(invokedExpressionCompilationResult is IExpressionCompilationResult expressionCompilationResult)) { throw MyParams.CreateException("invoked expression result in not an expression compilation result"); } var returnedValues = GetVariablePairsFromInvoked(myInvocationExpression.InvokedExpression); // call getter var expressionResult = expressionCompilationResult.TryConvertToGetter(MyParams); var invokedVar = expressionResult.GetReference(); InvocationStatement fakeInvocation = null; var needToInvoke = true; if (invokedVar != null) { InvocationTarget invocationTarget; switch (invokedVar) { case LocalVariableReference localVariableReference: invocationTarget = new LocalVariableTarget(localVariableReference); break; case LocalFunctionReference localFunctionReference: invocationTarget = new LocalFunctionTarget(localFunctionReference); MyParams.CheckExistenceOfLocalFunction(localFunctionReference); break; case ClassMethodReference classMethodReference: invocationTarget = new ClassMethodTarget(classMethodReference); if (myInvocationExpression.Reference == null) { throw MyParams.CreateException("invocation reference is null"); } if (myInvocationExpression.Reference.Resolve().DeclaredElement == null || myInvocationExpression.Reference.Resolve().DeclaredElement.GetType().ToString() != "JetBrains.ReSharper.Psi.CSharp.Impl.DeclaredElement.CSharpMethod") { needToInvoke = false; if (arguments.TryGetValue(new ParameterIndex(0), out var reference) && reference is LocalFunctionReference funRef) { fakeInvocation = new InvocationStatement(location, new LocalFunctionTarget(funRef), new Dictionary <ParameterIndex, Reference>(), new Dictionary <ParameterIndex, Reference>()); } } break; case ClassFieldReference classFieldReference: invocationTarget = new ClassFieldTarget(classFieldReference); break; case ClassPropertyReference classPropertyReference: Trace.Assert(false, "invocation target is property"); invocationTarget = new ClassPropertyTarget(classPropertyReference); break; default: throw MyParams.CreateException($"{invokedVar.GetType()}: unsupported reference type to invoke"); } // if (invocationTarget is ClassMethodTarget classMethodTarget && // CompilerUtils.IsAddToCollectionMethod(classMethodTarget)) // { // myInvocationExpression.InvokedExpression. // var statement = new InvocationStatement(location, // invocationTarget, // arguments, // returnedValues); // // } myReference = returnedValues[ParameterIndex.ReturnValueIndex]; var summaryBlock = GetInstructionsConnectedSequentially(new List <IInstructionsContainer> { expressionResult, argumentsInstructionBlock }); if (needToInvoke || fakeInvocation != null) { var statement = fakeInvocation ?? new InvocationStatement(location, invocationTarget, arguments, returnedValues); var invocationInstruction = new Instruction(statement, MyParams.GetNewInstructionId()); summaryBlock = GetInstructionsConnectedSequentially(new List <IInstructionsContainer> { summaryBlock, invocationInstruction }); } return(new ExpressionCompilationResult(summaryBlock, location, reference: myReference)); } return(new ExpressionCompilationResult(expressionResult.GetInstructionBlock(), location, reference: myReference)); }
public override ICompilationResult GetResult() { IReference reference; var location = GetLocation(myObjectCreationExpression); switch (myObjectCreationExpression.TypeUsage) { case IUserTypeUsage userDeclaredTypeUsage: reference = userDeclaredTypeUsage.ScalarTypeName.Reference; break; case IPredefinedTypeUsage predefinedDeclaredTypeUsage: reference = predefinedDeclaredTypeUsage.ScalarPredefinedTypeName.Reference; break; case IDynamicTypeUsage dynamicDeclaredTypeUsage: throw MyParams.CreateException("found dynamicDeclaredTypeUsage"); case ITupleTypeUsage tupleDeclaredTypeUsage: throw MyParams.CreateException("found tupleDeclaredTypeUsage"); break; default: throw MyParams.CreateException($"{myObjectCreationExpression.TypeUsage.GetType()} is unexpected type"); } var declaredElement = reference.Resolve().DeclaredElement; if (declaredElement == null) { return(new ExpressionCompilationResult(new InstructionBlock(), location)); } if (!(declaredElement is ITypeElement typeElement)) { throw MyParams.CreateException("In object creation declared element " + declaredElement.GetElementType().PresentableName + " is not a type element"); } var classRef = typeElement.GetClassReference(); var constructor = myObjectCreationExpression.ConstructorReference.Resolve().DeclaredElement as IConstructor; if (constructor == null) { return(new ExpressionCompilationResult(new InstructionBlock(), location, reference: classRef)); } var invokedFun = new ClassMethodTarget(new ClassMethodReference(classRef, constructor.GetNameWithHash())); var passedParameters = new Dictionary <ParameterIndex, Reference>(); if (myObjectCreationExpression.ArgumentList != null) { if (MyChildToResult[myObjectCreationExpression.ArgumentList] is ArgumentListCompilationResult argumentListResult) { foreach (var(inParameter, result) in argumentListResult.ArgumentsResults) { // call getter var passedVariable = result.GetReference(); if (passedVariable != null) { passedParameters.Add(inParameter, passedVariable); } } } } var returnedValues = GetVariablePairsFromInvoked(myObjectCreationExpression); var statement = new InvocationStatement(location, invokedFun, passedParameters, returnedValues, true); var instruction = new Instruction(statement, MyParams.GetNewInstructionId()); var returned = (LocalVariableReference)statement.ReturnedValues[new ParameterIndex(-1)]; returned.DefaultType = classRef.ClassId; return(new ExpressionCompilationResult(new InstructionBlock(instruction), location, reference: returned)); }
public virtual void VisitInvocationStatement(InvocationStatement node) => DefaultVisit(node);