예제 #1
0
        public SourceInfo(ComponentReader reader)
        {
            // todo: micro-optimize
            uriUtf8Bytes    = reader.ReadList(r => r.ReadByte());
            sourceUtf8Bytes = reader.ReadList(r => r.ReadByte());
            lineStarts      = reader.ReadList(r => r.ReadUint());

            uri    = Encoding.UTF8.GetString(uriUtf8Bytes.ToArray());
            source = Encoding.UTF8.GetString(sourceUtf8Bytes.ToArray());
            lines  = new string[lineStarts.Count];

            // todo: optimize -- this is _not_ efficient
            int p = 0;

            for (int i = 0; i < lineStarts.Count; i++)
            {
                p += (int)lineStarts[i];
                var line = p >= source.Length ? $"{p} > {source.Length}" :  source.Substring(p);
                var end  = line.IndexOf(Environment.NewLine, StringComparison.Ordinal);
                if (end != -1)
                {
                    line = line.Substring(0, end);
                }
                Console.WriteLine($"*** {line}");
                lines[i] = line;
            }
        }
예제 #2
0
 public ForStatement(ComponentReader reader)
 {
     fileOffset = new FileOffset(reader);
     variables  = reader.ReadList(r => new VariableDeclaration(r));
     condition  = reader.ReadOption(r => r.ReadExpression());
     updates    = reader.ReadList(r => r.ReadExpression());
     body       = reader.ReadStatement();
 }
예제 #3
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());
        }
예제 #4
0
        public FunctionType(ComponentReader reader)
        {
            typeParameters         = reader.ReadList(r => new TypeParameter(r));
            requiredParameterCount = reader.ReadUint();
            totalParameterCount    = reader.ReadUint();
            positionalParameters   = reader.ReadList(r => r.ReadDartType());
            namedParameters        = reader.ReadList(r => new NamedDartType(r));

            // #v12:   CanonicalNameReference typedefReference;
            // #v12+:  Option<TypedefType> typedef;
            typedefReference = new CanonicalNameReference(reader);
            //typedef = reader.ReadOption(r => new TypedefType(r));

            returnType = reader.ReadDartType();
        }
예제 #5
0
 public StringTable(ComponentReader reader)
 {
     // todo: optimize!
     endOffsets         = reader.ReadList((r) => (int)r.ReadUint());
     utf8Bytes          = reader.ReadBytes(endOffsets.LastOrDefault());
     reader.StringTable = this;
 }
예제 #6
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));
        }
예제 #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());
        }
예제 #8
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));
        }
예제 #9
0
        // Equivalent to a FunctionType with no type parameters or named parameters,
        // and where all positional parameters are required.

        public SimpleFunctionType(ComponentReader reader)
        {
            positionalParameters = reader.ReadList(r => r.ReadDartType());

            // https://github.com/dart-lang/sdk/blob/master/pkg/kernel/lib/binary/ast_from_binary.dart#L1889
            // MISSING!
            // positionalParameterNames = reader.ReadList(r => new StringReference(r));
            // Console.WriteLine(string.Join(", ", positionalParameterNames.Select(n => reader.GetString(n.index))));
            returnType = reader.ReadDartType();
        }
예제 #10
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));
        }
예제 #11
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)));
            }
        }
예제 #12
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());
        }
예제 #13
0
 public TypedefType(ComponentReader reader)
 {
     typedefReference = new TypedefReference(reader);
     typeArguments    = reader.ReadList(r => r.ReadDartType());
 }
예제 #14
0
 public TryCatch(ComponentReader reader)
 {
     body    = reader.ReadStatement();
     flags   = (Flag)reader.ReadByte();
     catches = reader.ReadList(r => new Catch(r));
 }
예제 #15
0
 public SwitchCase(ComponentReader reader)
 {
     expressions = reader.ReadList(r => new Pair <FileOffset, Expression>(new FileOffset(r), r.ReadExpression()));
     isDefault   = reader.ReadByte();
     body        = reader.ReadStatement();
 }
예제 #16
0
 public SwitchStatement(ComponentReader reader)
 {
     fileOffset = new FileOffset(reader);
     expression = reader.ReadExpression();
     cases      = reader.ReadList(r => new SwitchCase(r));
 }
예제 #17
0
 public AssertBlock(ComponentReader reader)
 {
     statements = reader.ReadList(r => r.ReadStatement());
 }
예제 #18
0
 public InterfaceType(ComponentReader reader)
 {
     classReference = new ClassReference(reader);
     typeArguments  = reader.ReadList(r => r.ReadDartType());
 }