Exemplo n.º 1
0
 /// <nodoc/>
 public SourceFile(DeserializationContext context, LineInfo location)
     : base(location)
 {
     Declarations = ReadArrayOf <Declaration>(context);
     Path         = context.Reader.ReadAbsolutePath();
 }
Exemplo n.º 2
0
 /// <nodoc />
 protected static FullSymbol ReadFullSymbol(DeserializationContext context)
 {
     return(context.Reader.ReadFullSymbol());
 }
Exemplo n.º 3
0
        public static Node Read(DeserializationContext context)
        {
            var reader = context.Reader;
            var kind   = (SyntaxKind)reader.ReadInt32Compact();

            // Empty node is special, because if the node is missing the only information that is stored in the stream is Kind and no location.
            if (kind == SyntaxKind.None)
            {
                return(null);
            }

            var location = LineInfo.Read(context.LineMap, reader);

            switch (kind)
            {
            case SyntaxKind.SourceFile:
                return(new SourceFile(context, location));

            case SyntaxKind.EnumMember:
                return(new EnumMemberDeclaration(context, location));

            case SyntaxKind.Parameter:
                return(new Parameter(context, location));

            case SyntaxKind.TypeParameter:
                return(new TypeParameter(context, location));

            case SyntaxKind.ApplyExpression:
                return(new NonGenericApplyExpression(context, location));

            case SyntaxKind.ApplyExpressionWithTypeArguments:
                return(new ApplyExpressionWithTypeArguments(context, location));

            case SyntaxKind.ArrayExpression:
                return(new ArrayExpression(context, location));

            case SyntaxKind.BinaryExpression:
                return(new BinaryExpression(context, location));

            case SyntaxKind.FullNameBasedSymbolReference:
                return(new FullNameBasedSymbolReference(context, location));

            case SyntaxKind.ModuleReferenceExpression:
                return(new ModuleReferenceExpression(context, location));

            case SyntaxKind.NameBasedSymbolReference:
                return(new NameBasedSymbolReference(context, location));

            case SyntaxKind.LocalReferenceExpression:
                return(new LocalReferenceExpression(context, location));

            case SyntaxKind.LocationBasedSymbolReference:
                return(new LocationBasedSymbolReference(context, location));

            case SyntaxKind.ModuleIdExpression:
                return(new ModuleIdExpression(context, location));

            case SyntaxKind.WithQualifierExpression:
                return(new WithQualifierExpression(context, location));

            case SyntaxKind.QualifierReferenceExpression:
                return(new QualifierReferenceExpression(location));

            case SyntaxKind.CoerceQualifierTypeExpression:
                return(new CoerceQualifierTypeExpression(context, location));

            case SyntaxKind.IndexExpression:
                return(new IndexExpression(context, location));

            case SyntaxKind.IteExpression:
                return(new ConditionalExpression(context, location));

            case SyntaxKind.SwitchExpression:
                return(new SwitchExpression(context, location));

            case SyntaxKind.SwitchExpressionClause:
                return(new SwitchExpressionClause(context, location));

            case SyntaxKind.LambdaExpression:
                return(new FunctionLikeExpression(context, location));

            case SyntaxKind.SelectorExpression:
                return(new SelectorExpression(context, location));

            case SyntaxKind.ResolvedSelectorExpression:
                return(new ResolvedSelectorExpression(context, location));

            case SyntaxKind.ModuleSelectorExpression:
                return(new ModuleSelectorExpression(context, location));

            case SyntaxKind.UnaryExpression:
                return(new UnaryExpression(context, location));

            case SyntaxKind.PropertyAssignment:
                return(new PropertyAssignment(context, location));

            case SyntaxKind.AssignmentExpression:
                return(new AssignmentExpression(context, location));

            case SyntaxKind.IncrementDecrementExpression:
                return(new IncrementDecrementExpression(context, location));

            case SyntaxKind.CastExpression:
                return(new CastExpression(context, location));

            case SyntaxKind.ImportAliasExpression:
                return(new ImportAliasExpression(context, location));

            case SyntaxKind.ModuleToObjectLiteral:
                return(new ModuleToObjectLiteral(context, location));

            case SyntaxKind.PathLiteral:
                return(new PathLiteral(context, location));

            case SyntaxKind.InterpolatedPaths:
                return(new InterpolatedPaths(context, location));

            case SyntaxKind.FileLiteral:
                return(new FileLiteral(context, location));

            case SyntaxKind.FileLiteralExpression:
                return(new FileLiteralExpression(context, location));

            case SyntaxKind.StringLiteralExpression:
                return(new StringLiteralExpression(context, location));

            case SyntaxKind.DirectoryLiteral:
                return(new DirectoryLiteralExpression(context, location));

            case SyntaxKind.PathAtomLiteral:
                return(new PathAtomLiteral(context, location));

            case SyntaxKind.RelativePathLiteral:
                return(new RelativePathLiteral(context, location));

            case SyntaxKind.StringLiteral:
                return(new StringLiteral(reader, location));

            case SyntaxKind.BoolLiteral:
                return(new BoolLiteral(context, location));

            case SyntaxKind.NumberLiteral:
                return(new NumberLiteral(reader, location));

            case SyntaxKind.UndefinedLiteral:
                return(UndefinedLiteral.Instance);

            case SyntaxKind.ResolvedStringLiteral:
                return(new ResolvedStringLiteral(context, location));

            case SyntaxKind.ImportDeclaration:
                return(new ImportDeclaration(context, location));

            case SyntaxKind.ExportDeclaration:
                return(new ExportDeclaration(context, location));

            case SyntaxKind.VarDeclaration:
                return(new VarDeclaration(context, location));

            case SyntaxKind.BlockStatement:
                return(new BlockStatement(context, location));

            case SyntaxKind.BreakStatement:
                return(new BreakStatement(location));

            case SyntaxKind.ContinueStatement:
                return(new ContinueStatement(location));

            case SyntaxKind.CaseClause:
                return(new CaseClause(context, location));

            case SyntaxKind.DefaultClause:
                return(new DefaultClause(context, location));

            case SyntaxKind.ExpressionStatement:
                return(new ExpressionStatement(context, location));

            case SyntaxKind.IfStatement:
                return(new IfStatement(context, location));

            case SyntaxKind.ReturnStatement:
                return(new ReturnStatement(context, location));

            case SyntaxKind.SwitchStatement:
                return(new SwitchStatement(context, location));

            case SyntaxKind.VarStatement:
                return(new VarStatement(context, location));

            case SyntaxKind.ForStatement:
                return(new ForStatement(context, location));

            case SyntaxKind.ForOfStatement:
                return(new ForOfStatement(context, location));

            case SyntaxKind.WhileStatement:
                return(new WhileStatement(context, location));

            case SyntaxKind.ArrayType:
                return(new ArrayType(context, location));

            case SyntaxKind.FunctionType:
                return(new FunctionType(context, location));

            case SyntaxKind.NamedTypeReference:
                return(new NamedTypeReference(context, location));

            case SyntaxKind.ObjectType:
                return(new ObjectType(context, location));

            case SyntaxKind.PredefinedType:
                return(new PrimitiveType(context, location));

            case SyntaxKind.TupleType:
                return(new TupleType(context, location));

            case SyntaxKind.UnionType:
                return(new UnionType(context, location));

            case SyntaxKind.TypeQuery:
                return(new TypeQuery(context, location));

            case SyntaxKind.PropertySignature:
                return(new PropertySignature(context, location));

            case SyntaxKind.CallSignature:
                return(new CallSignature(context, location));

            case SyntaxKind.TypeOrNamespaceModuleLiteral:
                return(TypeOrNamespaceModuleLiteral.Deserialize(context, location));

            case SyntaxKind.ObjectLiteral0:
            case SyntaxKind.ObjectLiteralN:
            case SyntaxKind.ObjectLiteralSlim:
                return(ObjectLiteral.Create(context, location));

            case SyntaxKind.ArrayLiteral:
                return(ArrayLiteral.Create(context, location));

            case SyntaxKind.ArrayLiteralWithSpreads:
                return(new ArrayLiteralWithSpreads(context, location));

            // Serialization is not needed for configurations.
            case SyntaxKind.ConfigurationDeclaration:
                return(new ConfigurationDeclaration(context, location));

            case SyntaxKind.PackageDeclaration:
                return(new PackageDeclaration(context, location));

            // Types are not used at runtime, so we can skip these if their serialization becomes troublesome
            case SyntaxKind.InterfaceDeclaration:
                return(new InterfaceDeclaration(context, location));

            case SyntaxKind.ModuleDeclaration:
                return(new ModuleDeclaration(context, location));

            case SyntaxKind.NamespaceImport:
                return(new NamespaceImport(context, location));

            case SyntaxKind.NamespaceAsVarImport:
                return(new NamespaceAsVarImport(context, location));

            case SyntaxKind.ImportOrExportModuleSpecifier:
                return(new ImportOrExportModuleSpecifier(context, location));

            case SyntaxKind.ImportOrExportVarSpecifier:
                return(new ImportOrExportVarSpecifier(context, location));

            case SyntaxKind.NamedImportsOrExports:
                return(new NamedImportsOrExports(context, location));

            case SyntaxKind.ImportOrExportClause:
                return(new ImportOrExportClause(context, location));

            case SyntaxKind.TypeAliasDeclaration:
                return(new TypeAliasDeclaration(context, location));

            // Enum declarations are represented as TypeOrNamespace instances at runtime
            case SyntaxKind.EnumDeclaration:
                return(new EnumDeclaration(context, location));

            // Enum members are stored as constants.
            case SyntaxKind.EnumMemberDeclaration:
                return(new EnumMemberDeclaration(context, location));

            // LambdaExpressions are serialized instead.
            case SyntaxKind.FunctionDeclaration:
                return(new FunctionDeclaration(context, location));

            // Supported only in V1 and V1 modules are not serializable.
            case SyntaxKind.QualifierSpaceDeclaration:
                return(new QualifierSpaceDeclaration(context, location));

            // Serialized separately
            case SyntaxKind.FileModuleLiteral:

            // Prelude is not serializable
            case SyntaxKind.GlobalModuleLiteral:

            // Closures are not serializable, only LambdaExpressions are
            case SyntaxKind.Closure:
            case SyntaxKind.Function0:
            case SyntaxKind.Function1:
            case SyntaxKind.Function2:
            case SyntaxKind.FunctionN:
            case SyntaxKind.BoundFunction:

            // Not serializable.
            case SyntaxKind.ImportValue:

            // Not serializable.
            case SyntaxKind.MergeModuleValue:
            case SyntaxKind.ImportExpression:
            case SyntaxKind.QualifiedLocationBasedSymbolReference:
            case SyntaxKind.ObjectLiteralOverride:

            // Added for completeness
            case SyntaxKind.None:
                break;

            // We will hit this exception if we are missing one value from the enum
            default:
                throw new BuildXLException(I($"Unable to deserialize syntax kind {kind.ToString()}"));
            }

            string message = I($"The node {kind} is not deserializable yet.");

            throw new InvalidOperationException(message);
        }
Exemplo n.º 4
0
 /// <nodoc />
 protected static SymbolAtom ReadSymbolAtom(DeserializationContext context)
 {
     return(context.Reader.ReadSymbolAtom());
 }
Exemplo n.º 5
0
 /// <nodoc />
 protected static Expression[] ReadExpressions(DeserializationContext context)
 {
     return(ReadArrayOf <Expression>(context));
 }
Exemplo n.º 6
0
 public static TNode Read <TNode>(DeserializationContext context) where TNode : Node
 {
     return((TNode)Read(context));
 }
Exemplo n.º 7
0
 public static Types.Type ReadType(DeserializationContext context) => Read <Types.Type>(context);
Exemplo n.º 8
0
 public static Expression ReadExpression(DeserializationContext context) => Read <Expression>(context);