Exemple #1
0
        public Procedure(ComponentReader reader)
        {
            var s = reader.Position;

            reader.CheckTag(Tag);

            canonicalName   = new CanonicalNameReference(reader);
            fileUri         = new UriReference(reader);
            startFileOffset = new FileOffset(reader);

            fileOffset    = new FileOffset(reader);
            fileEndOffset = new FileOffset(reader);
            kind          = (ProcedureKind)reader.ReadByte();
            flags         = (Flag)reader.ReadByte();
            name          = new Name(reader);
            annotations   = reader.ReadList(r => r.ReadExpression());

            // #V12
            forwardingStubSuperTarget     = reader.ReadOption(r => new MemberReference(r));
            forwardingStubInterfaceTarget = reader.ReadOption(r => new MemberReference(r));

            // #V18?
            //forwardingStubSuperTarget = new MemberReference(reader);
            //forwardingStubInterfaceTarget = new MemberReference(reader);

            function = reader.ReadOption(r => new FunctionNode(r));
        }
Exemple #2
0
        // https://github.com/dart-lang/sdk/blob/master/pkg/kernel/lib/binary/ast_from_binary.dart#L1852
        // we have much different concepts of what DartType is? ~ Will this lead to different functionality?
        // Is this just because of changes in binary.md?
        // TypedefType (we have, but not a type)
        // BottomType (not in binary.md)
        public static DartType ReadDartType(this ComponentReader reader)
        {
            var tag = reader.ReadByte();

            switch (tag)
            {
            case DynamicType.Tag: return(new DynamicType());

            case FunctionType.Tag: return(new FunctionType(reader));

            case InterfaceType.Tag: return(new InterfaceType(reader));

            case InvalidType.Tag: return(new InvalidType());

            case SimpleFunctionType.Tag: return(new SimpleFunctionType(reader));

            case SimpleInterfaceType.Tag: return(new SimpleInterfaceType(reader));

            case TypeParameterType.Tag: return(new TypeParameterType(reader));

            case VoidType.Tag: return(new VoidType());

            default: throw new Exception($"{nameof(DartType)}: unrecognized tag ({tag})");
            }
        }
Exemple #3
0
        public Class(ComponentReader reader)
        {
            reader.CheckTag(Tag);

            canonicalName = new CanonicalNameReference(reader);

            fileUri         = new UriReference(reader);
            startFileOffset = new FileOffset(reader);
            fileOffset      = new FileOffset(reader);
            fileEndOffset   = new FileOffset(reader);

            flags = (Flag)reader.ReadByte();

            name           = new StringReference(reader);
            annotations    = reader.ReadList(r => r.ReadExpression());
            typeParameters = reader.ReadList(r => new TypeParameter(r));

            superClass = reader.ReadOption(r => r.ReadDartType());

            mixedInType                    = reader.ReadOption(r => r.ReadDartType());
            implementedClasses             = reader.ReadList(r => r.ReadDartType());
            fields                         = reader.ReadList(r => new Field(r));
            constructors                   = reader.ReadList(r => new Constructor(r));
            procedures                     = reader.ReadList(r => new Procedure(r));
            redirectingFactoryConstructors = reader.ReadList(r => new RedirectingFactoryConstructor(r));
        }
Exemple #4
0
 public AssertInitializer(ComponentReader reader)
 {
     // #V12 - This is in the Binary.MD but not in the actual code.
     isSynthetic = reader.ReadByte();
     // statement = new AssertStatement(reader);
     statement = reader.ReadStatement() as AssertStatement;
 }
Exemple #5
0
        // https://github.com/dart-lang/sdk/blob/master/pkg/kernel/lib/binary/ast_from_binary.dart#L760
        public Library(ComponentReader reader)
        {
            // Read the Offsets and Counts in a backward fashion
            var p = reader.Length - sizeof(uint);

            reader.Position = p;
            procedureCount  = reader.ReadUint32();

            p -= sizeof(uint) * ((int)procedureCount + 1);
            reader.Position  = p;
            procedureOffsets = reader.ReadUint32s((int)procedureCount + 1);

            p -= sizeof(uint);
            reader.Position = p;
            classCount      = reader.ReadUint32();

            p -= sizeof(uint) * ((int)classCount + 1);
            reader.Position = p;
            classOffsets    = reader.ReadUint32s((int)classCount + 1);

            reader.Position = 0;
            flags           = reader.ReadByte();
            canonicalName   = new CanonicalNameReference(reader);
            name            = new StringReference(reader);

            // todo: remove!
            Console.WriteLine($"{reader.GetString(name)} :: {classOffsets.Length} :: {classCount} || {procedureOffsets.Length} :: {procedureCount};");

            fileUri = new UriReference(reader);

            //   List<String> problemsAsJson; // Described in problems.md.

            annotations         = reader.ReadList(r => r.ReadExpression());
            libraryDependencies = reader.ReadList(r => new LibraryDependency(r));
            additionalExports   = reader.ReadList(r => new CanonicalNameReference(r));
            libraryParts        = reader.ReadList(r => new LibraryPart(r));
            typedefs            = reader.ReadList(r => new Typedef(r));

            // https://github.com/dart-lang/sdk/blob/master/pkg/kernel/lib/binary/ast_from_binary.dart#L831
            // classes = reader.ReadList(r => new Class(r));
            classes = new List <Class>((int)classCount);
            for (int i = 0; i < classCount; i++)
            {
                var start = classOffsets[i];
                var end   = classOffsets[i + 1];
                classes.Add(new Class(reader.GetWindow(start, end - start)));
            }

            reader.Position = (int)classOffsets.Last() - reader.WindowOffset;
            fields          = reader.ReadList(r => new Field(r));

            // procedures = reader.ReadList(r => new Procedure(r));
            procedures = new List <Procedure>((int)procedureCount);
            for (int i = 0; i < procedureCount; i++)
            {
                var start = procedureOffsets[i];
                var end   = procedureOffsets[i + 1];
                procedures.Add(new Procedure(reader.GetWindow(start, end - start)));
            }
        }
Exemple #6
0
 public SuperInitializer(ComponentReader reader)
 {
     isSynthetic = reader.ReadByte();
     fileOffset  = new FileOffset(reader);
     target      = new ConstructorReference(reader);
     arguments   = new Arguments(reader);
 }
Exemple #7
0
        public readonly Option <DartType> defaultType; // type used when the parameter is not passed

        public TypeParameter(ComponentReader reader)
        {
            flags       = (Flag)reader.ReadByte();
            annotations = reader.ReadList(r => r.ReadExpression());
            name        = new StringReference(reader);
            bound       = reader.ReadDartType();
            defaultType = reader.ReadOption(r => r.ReadDartType());
        }
Exemple #8
0
        public static Statement ReadStatement(this ComponentReader reader)
        {
            var tag = reader.ReadByte();

            switch (tag)
            {
            case AssertBlock.Tag: return(new AssertBlock(reader));

            case AssertStatement.Tag: return(new AssertStatement(reader));

            case AsyncForInStatement.Tag: return(new AsyncForInStatement(reader));

            case Block.Tag: return(new Block(reader));

            case BreakStatement.Tag: return(new BreakStatement(reader));

            case ContinueSwitchStatement.Tag: return(new ContinueSwitchStatement(reader));

            case DoStatement.Tag: return(new DoStatement(reader));

            case EmptyStatement.Tag: return(new EmptyStatement());

            case ExpressionStatement.Tag: return(new ExpressionStatement(reader));

            case ForInStatement.Tag: return(new ForInStatement(reader));

            case ForStatement.Tag: return(new ForStatement(reader));

            case FunctionDeclaration.Tag: return(new FunctionDeclaration(reader));

            case IfStatement.Tag: return(new IfStatement(reader));

            case LabeledStatement.Tag: return(new LabeledStatement(reader));

            case ReturnStatement.Tag: return(new ReturnStatement(reader));

            case SwitchStatement.Tag: return(new SwitchStatement(reader));

            case TryCatch.Tag: return(new TryCatch(reader));

            case TryFinally.Tag: return(new TryFinally(reader));

            case VariableDeclarationStatement.Tag: return(new VariableDeclarationStatement(reader));

            case WhileStatement.Tag: return(new WhileStatement(reader));

            case YieldStatement.Tag: return(new YieldStatement(reader));

            default: throw new Exception($"{nameof(Statement)}: unrecognized tag ({tag})");
            }
        }
Exemple #9
0
        public Field(ComponentReader reader)
        {
            reader.CheckTag(Tag);

            canonicalName = new CanonicalNameReference(reader);
            fileUri       = new UriReference(reader);
            fileOffset    = new FileOffset(reader);
            fileEndOffset = new FileOffset(reader);
            flags         = (Flag)reader.ReadByte();
            name          = new Name(reader);
            annotations   = reader.ReadList(r => r.ReadExpression());
            type          = reader.ReadDartType();
            initializer   = reader.ReadOption(r => r.ReadExpression());
        }
Exemple #10
0
        public static Option <T> ReadOption <T>(this ComponentReader reader, Func <ComponentReader, T> valueReader)
        {
            var myTag = reader.ReadByte();

            if (myTag == Nothing <T> .Tag)
            {
                return(new Nothing <T>());
            }
            if (myTag == Something <T> .Tag)
            {
                return(new Something <T>(reader, valueReader));
            }

            throw new Exception($"Invalid Option Tag ({myTag})");
        }
Exemple #11
0
        public Constructor(ComponentReader reader)
        {
            reader.CheckTag(Tag);

            canonicalName   = new CanonicalNameReference(reader);
            fileUri         = new UriReference(reader);
            startFileOffset = new FileOffset(reader);
            fileOffset      = new FileOffset(reader);
            fileEndOffset   = new FileOffset(reader);
            flags           = (Flag)reader.ReadByte();
            name            = new Name(reader);
            annotations     = reader.ReadList(r => r.ReadExpression());
            function        = new FunctionNode(reader);
            initializers    = reader.ReadList(r => r.ReadInitializer());
        }
Exemple #12
0
        public static Constant ReadConstant(this ComponentReader reader)
        {
            var tag = reader.ReadByte();

            switch (tag)
            {
            case BoolConstant.Tag: return(new BoolConstant(reader));

            case DoubleConstant.Tag: return(new DoubleConstant(reader));

            case EnvironmentBoolConstant.Tag: return(new EnvironmentBoolConstant(reader));

            case EnvironmentIntConstant.Tag: return(new EnvironmentIntConstant(reader));

            case EnvironmentStringConstant.Tag: return(new EnvironmentStringConstant(reader));

            case InstanceConstant.Tag: return(new InstanceConstant(reader));

            case IntConstant.Tag: return(new IntConstant(reader));

            case ListConstant.Tag: return(new ListConstant(reader));

            case MapConstant.Tag: return(new MapConstant(reader));

            case NullConstant.Tag: return(new NullConstant());

            case PartialInstantiationConstant.Tag: return(new PartialInstantiationConstant(reader));

            case StringConstant.Tag: return(new StringConstant(reader));

            case SymbolConstant.Tag: return(new SymbolConstant(reader));

            case TearOffConstant.Tag: return(new TearOffConstant(reader));

            case TypeLiteralConstant.Tag: return(new TypeLiteralConstant(reader));

            case UnevaluatedConstant.Tag: return(new UnevaluatedConstant(reader));

            default: throw new Exception($"{nameof(Constant)}: unrecognized tag ({tag})");
            }
        }
Exemple #13
0
        public RedirectingFactoryConstructor(ComponentReader reader)
        {
            reader.CheckTag(Tag);

            canonicalName = new CanonicalNameReference(reader);
            fileUri       = new UriReference(reader);
            fileOffset    = new FileOffset(reader);
            fileEndOffset = new FileOffset(reader);

            flags = reader.ReadByte();

            name                   = new Name(reader);
            annotations            = reader.ReadList(r => r.ReadExpression());
            targetReference        = new MemberReference(reader);
            typeArguments          = reader.ReadList(r => r.ReadDartType());
            typeParameters         = reader.ReadList(r => new TypeParameter(r));
            parameterCount         = reader.ReadUint();
            requiredParameterCount = reader.ReadUint();
            positionalParameters   = reader.ReadList(r => new VariableDeclaration(r));
            namedParameters        = reader.ReadList(r => new VariableDeclaration(r));
        }
Exemple #14
0
        public static Initializer ReadInitializer(this ComponentReader reader)
        {
            var tag = reader.ReadByte();

            switch (tag)
            {
            case AssertInitializer.Tag: return(new AssertInitializer(reader));

            case FieldInitializer.Tag: return(new FieldInitializer(reader));

            case InvalidInitializer.Tag: return(new InvalidInitializer(reader));

            case LocalInitializer.Tag: return(new LocalInitializer(reader));

            case RedirectingInitializer.Tag: return(new RedirectingInitializer(reader));

            case SuperInitializer.Tag: return(new SuperInitializer(reader));

            default: throw new Exception($"{nameof(Initializer)}: unrecognized tag ({tag})");
            }
        }
Exemple #15
0
 public FieldInitializer(ComponentReader reader)
 {
     isSynthetic = reader.ReadByte();
     field       = new FieldReference(reader);
     value       = reader.ReadExpression();
 }
Exemple #16
0
 public InvalidInitializer(ComponentReader reader)
 {
     isSynthetic = reader.ReadByte();
 }
Exemple #17
0
 public BoolConstant(ComponentReader reader)
 {
     value = reader.ReadByte();
 }
Exemple #18
0
 public LocalInitializer(ComponentReader reader)
 {
     isSynthetic = reader.ReadByte();
     variable    = new VariableDeclaration(reader);
 }
Exemple #19
0
 public YieldStatement(ComponentReader reader)
 {
     fileOffset = new FileOffset(reader);
     flags      = (Flag)reader.ReadByte();
     expression = reader.ReadExpression();
 }
Exemple #20
0
 public TryCatch(ComponentReader reader)
 {
     body    = reader.ReadStatement();
     flags   = (Flag)reader.ReadByte();
     catches = reader.ReadList(r => new Catch(r));
 }
Exemple #21
0
 public SwitchCase(ComponentReader reader)
 {
     expressions = reader.ReadList(r => new Pair <FileOffset, Expression>(new FileOffset(r), r.ReadExpression()));
     isDefault   = reader.ReadByte();
     body        = reader.ReadStatement();
 }