Пример #1
0
        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);
                    }
                }
            }
        }
Пример #2
0
        public override TranslationResult Translate(TranslationContext context)
        {
            var classSymbol = context.Semantics.GetDeclaredSymbol(this.OriginalNode as ClassDeclarationSyntax);

            // Should translate at all?
            var attributes = classSymbol.GetAttributes();

            switch (VerificationSettings.ShouldVerify(attributes, context.VerifyUnmarkedItems))
            {
            case VerificationSetting.DoNotVerify:
                return(TranslationResult.FromSilvernode(new SinglelineCommentSilvernode($"Class {classSymbol.GetQualifiedName()} skipped.", this.OriginalNode)));

            case VerificationSetting.Contradiction:
                return(TranslationResult.Error(this.OriginalNode,
                                               Diagnostics.SSIL113_VerificationSettingsContradiction));
            }

            // Combine all members
            return(CommonUtils.GetHighlevelSequence(this.children.Select(child => child.Translate(context))));
        }