public override TranslationResult Translate(TranslationContext context) { var symbol = context.Semantics.GetDeclaredSymbol(this.variable); var identifier = context.Process.IdentifierTranslator.RegisterAndGetIdentifier(symbol); Error err; List <Error> errors = new List <Error>(); VarStatementSilvernode intro = new VarStatementSilvernode(identifier, TypeTranslator.TranslateType( context.Semantics.GetSymbolInfo(this.typeSyntax).Symbol as ITypeSymbol, this.typeSyntax, out err), this.OriginalNode); if (err != null) { errors.Add(err); } if (this.initialValue == null) { return(TranslationResult.FromSilvernode(intro, errors)); } // Add assignment if there is an initial value. var res = this.initialValue.Translate(context.ChangePurityContext(PurityContext.Purifiable)); AssignmentSilvernode assignmentSilvernode = new AssignmentSilvernode(new IdentifierSilvernode(identifier), res.Silvernode, this.OriginalNode); errors.AddRange(res.Errors); return(TranslationResult.FromSilvernode(new StatementsSequenceSilvernode(this.OriginalNode, intro, new StatementsSequenceSilvernode(null, res.PrependTheseSilvernodes.ToArray()), assignmentSilvernode), errors)); }
public override void CollectTypesInto(TranslationProcess translationProcess, SemanticModel semantics) { var classSymbol = semantics.GetDeclaredSymbol(this.OriginalNode as ClassDeclarationSyntax); // Should translate at all? var attributes = classSymbol.GetAttributes(); switch (VerificationSettings.ShouldVerify(attributes, translationProcess.Configuration.VerifyUnmarkedItems)) { case VerificationSetting.DoNotVerify: return; case VerificationSetting.Contradiction: return; } this.TypeIfCollected = translationProcess.AddToCollectedTypes(this, semantics); foreach (Sharpnode node in this.children) { // Collect fields if (node is FieldDeclarationSharpnode) { FieldDeclarationSharpnode fieldDeclaration = (FieldDeclarationSharpnode)node; var fieldSymbol = fieldDeclaration.GetSymbol(semantics); if (fieldSymbol.IsConst) { continue; // Constants are inlined. } if (fieldSymbol.IsStatic) { translationProcess.AddError(new Error(Diagnostics.SSIL108_FeatureNotSupported, node.OriginalNode, "static fields")); continue; } var typeSymbol = fieldSymbol.Type; Error error; this.TypeIfCollected.InstanceFields.Add( new CollectedField( translationProcess.IdentifierTranslator.RegisterAndGetIdentifier(((FieldDeclarationSharpnode)node).GetSymbol(semantics)), TypeTranslator.TranslateType(typeSymbol, node.OriginalNode, out error) )); if (error != null) { translationProcess.AddError(error); } } } }
public override void Run(List <ExpressionSharpnode> arguments, SyntaxNode originalNode, TranslationContext context) { // Get the symbol var methodSymbol = this._method.Symbol as IMethodSymbol; var identifier = context.Process.IdentifierTranslator.GetIdentifierReference(this._method.Symbol as IMethodSymbol); IMethodSymbol theMethod = (this._method.Symbol as IMethodSymbol); // Determine purity this.Impure = !(ContractsTranslator.IsMethodPureOrPredicate(theMethod)); // Add the receiver if (!theMethod.IsStatic) { if (this.methodGroupSharpnode is IdentifierExpressionSharpnode) { arguments.Insert(0, new DirectSilvercodeExpressionSharpnode(Constants.SilverThis, this.methodGroup)); } else if (this.methodGroupSharpnode is MemberAccessExpressionSharpnode) { arguments.Insert(0, ((MemberAccessExpressionSharpnode)this.methodGroupSharpnode).Container); } else { this.Errors.Add(new Error(Diagnostics.SSIL102_UnexpectedNode, this.methodGroup, this.methodGroup.Kind())); } } // Determine return type Error error; this.SilverType = TypeTranslator.TranslateType(methodSymbol.ReturnType, this.methodGroup, out error); if (error != null) { this.Errors.Add(error); } // Translate arguments var expressions = ConvertToSilver(arguments, context); // Put it together this.Silvernode = new CallSilvernode( identifier, expressions, this.SilverType, originalNode ); }
/// <summary> /// Prepares for insertion into quantifier. /// Returns true if this lambda expression is valid for translation inside a ForAll or Exists call; false otherwise. /// </summary> /// <param name="context">The context.</param> public bool PrepareForInsertionIntoQuantifier(TranslationContext context) { if (this.errorneousResult != null) { this.failedResult = TranslationResult.Error(this.errorneousResult.Node, this.errorneousResult.Diagnostic, this.errorneousResult.DiagnosticArguments); return(false); } // Translate the single parameter's type var parameterSymbol = context.Semantics.GetDeclaredSymbol(this.parameter.ParameterSyntax); this.VariableIdentifier = context.Process.IdentifierTranslator.RegisterAndGetIdentifier(parameterSymbol); this.VariableSilverType = TypeTranslator.TranslateType(parameterSymbol.Type, this.parameter.OriginalNode, out this.errorneousResult); if (this.errorneousResult != null) { this.failedResult = TranslationResult.Error(this.errorneousResult.Node, this.errorneousResult.Diagnostic, this.errorneousResult.DiagnosticArguments); return(false); } // Translate the lambda's body TranslationResult res = this.body.Translate(context.ChangePurityContext(PurityContext.PureOrFail)); if (res.WasTranslationSuccessful) { this.BodySilvernode = res.Silvernode; } else { this.failedResult = res; return(false); } // Nothing went wrong. return(true); }
public TranslationResult Translate(TranslationContext context, IParameterSymbol symbol) { Error err; ISymbol parameterSymbol = context.Semantics.GetDeclaredSymbol(this.ParameterSyntax); Identifier identifier = context.Process.IdentifierTranslator.RegisterAndGetIdentifier(parameterSymbol); ParameterSilvernode ps = new ParameterSilvernode(identifier, new TypeSilvernode(this.Type.TypeSyntax, TypeTranslator.TranslateType(symbol.Type, this.Type.TypeSyntax, out err)), this.OriginalNode); var errlist = new List <Error>(); if (err != null) { errlist.Add(err); } return(TranslationResult.FromSilvernode(ps, errlist)); }