예제 #1
0
파일: TypeDef.cs 프로젝트: zihotki/Excess
        private static SyntaxNode Typedef(SyntaxNode node, Scope scope)
        {
            var field = node
                        .AncestorsAndSelf()
                        .OfType <FieldDeclarationSyntax>()
                        .FirstOrDefault();

            if (field == null)
            {
                scope.AddError("xs01", "malformed typedef", node);
                //td: error, malformed typedef
                return(node);
            }


            if (field.Declaration.Variables.Count != 1)
            {
                scope.AddError("xs01", "malformed typedef", node);
                return(node);
            }

            var variable = field
                           .Declaration
                           .Variables[0];

            Debug.Assert(variable.Initializer == null || variable.Initializer.IsMissing);

            var type       = RoslynCompiler.UnMark(field.Declaration.Type);
            var identifier = variable.Identifier;

            var parentScope = scope.CreateScope <SyntaxToken, SyntaxNode, SemanticModel>(field.Parent);

            Debug.Assert(parentScope != null);

            parentScope.set("__tdef" + identifier.ToString(), type);

            //schedule deletion
            var document = scope.GetDocument <SyntaxToken, SyntaxNode, SemanticModel>();

            document.change(field.Parent, RoslynCompiler.RemoveMember(field));

            //return intact
            return(node);
        }