Esempio n. 1
0
 /// <summary>
 /// Creates false.
 /// </summary>
 public static BoolLiteral CreateFalse(LineInfo location)
 {
     return(new BoolLiteral(false, location));
 }
Esempio n. 2
0
 internal UnevaluatedArrayLiteral(Expression[] elements, LineInfo location, AbsolutePath path)
     : base(location, path)
 {
     m_data = elements;
 }
Esempio n. 3
0
 /// <nodoc />
 public QualifierSpaceDeclaration(DeserializationContext context, LineInfo location)
     : base(context, location)
 {
     QualifierSpaceKeyword    = ReadSymbolAtom(context);
     QualifierSpaceExpression = ReadExpression(context);
 }
Esempio n. 4
0
 /// <nodoc />
 public NumberLiteral(int value, LineInfo location)
     : base(location)
 {
     UnboxedValue = value;
 }
Esempio n. 5
0
 /// <summary>
 /// Constructor that takes path literal expression.
 /// </summary>
 public FileLiteral(AbsolutePath value, LineInfo location)
     : base(location)
 {
     Contract.Requires(value.IsValid);
     Value = FileArtifact.CreateSourceFile(value);
 }
Esempio n. 6
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);
        }
Esempio n. 7
0
 /// <nodoc />
 public TypeQuery(DeserializationContext context, LineInfo location)
     : base(location)
 {
     EntityName = Read <NamedTypeReference>(context);
 }
Esempio n. 8
0
        /// <nodoc />
        public void ReportMissingNamespace(ModuleLiteral env, FullSymbol name, ModuleLiteral relatedEnv, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(name.IsValid);
            Contract.Requires(relatedEnv != null);
            var relatedLocation = relatedEnv.Location.AsLoggingLocation(relatedEnv, Context).ToDisplayString();
            var relatedMessage  = env == relatedEnv ? string.Empty : I($", related location '{relatedLocation}'");

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportMissingNamespace(
                LoggingContext,
                location.AsLoggingLocation(),
                name.ToDisplayString(Context),
                relatedMessage,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 9
0
        public void ReportContractRequire(ModuleLiteral env, Expression expression, string message, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(expression != null);

            string additionalInformation = string.IsNullOrEmpty(message)
                ? string.Empty
                : I($" : {message}");

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportContractRequire(
                LoggingContext,
                location.AsLoggingLocation(),
                expression.ToDisplayString(Context),
                additionalInformation,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 10
0
        /// <nodoc />
        public void ReportMissingProperty(ModuleLiteral env, SymbolAtom selector, object receiver, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(receiver != null);

            var locationForLogging = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportMissingInstanceMember(
                LoggingContext,
                locationForLogging.AsLoggingLocation(),
                selector.ToDisplayString(Context),
                receiver.GetType().ToDisplayString(Context),
                Context.GetStackTraceAsString(locationForLogging));
        }
Esempio n. 11
0
        public void ReportFailResolveSelectorDueToUndefined(ModuleLiteral env, Expression thisExpression, SymbolAtom name, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(name.IsValid);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportFailResolveSelectorDueToUndefined(
                LoggingContext,
                location.AsLoggingLocation(),
                name.ToDisplayString(Context),
                thisExpression.ToDisplayString(Context),
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 12
0
        /// <nodoc />
        public void ReportArgumentIndexOutOfBound(ModuleLiteral env, int index, int numberOfArguments, LineInfo lineInfo)
        {
            Contract.Requires(env != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportArgumentIndexOutOfBound(
                LoggingContext,
                location.AsLoggingLocation(),
                index,
                numberOfArguments,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 13
0
        /// <nodoc />
        public void ReportStringIndexOufOfRange(ModuleLiteral env, int index, string target, LineInfo lineInfo)
        {
            Contract.Requires(env != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportStringIndexOufOfRange(
                LoggingContext,
                location.AsLoggingLocation(),
                index,
                target,
                target.Length,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 14
0
 /// <nodoc />
 public static UniversalLocation FromLineInfo(LineInfo lineInfo, AbsolutePath absolutePath, PathTable pathTable)
 {
     return(new UniversalLocation(null, lineInfo, absolutePath, pathTable));
 }
Esempio n. 15
0
        /// <inheritdoc />
        public override bool TryProject(Context context, SymbolAtom name, ModuleLiteral origin, out EvaluationResult result, LineInfo location)
        {
            if (name == context.ContextTree.CommonConstants.Length)
            {
                result = EvaluationResult.Create(Length);
                return(true);
            }

            var resolvedMember = ((ModuleRegistry)context.FrontEndHost.ModuleRegistry).PredefinedTypes.AmbientArray.ResolveMember(this, name);

            if (resolvedMember == null)
            {
                // Array literals could not have arbitrary members.
                // So if the name was not resolved, reporting an error.
                // var locationForLogging = LocationForLogging(context, origin);
                var locationForLogging = UniversalLocation.FromLineInfo(location, origin.Path, context.PathTable);

                context.Logger.ReportMissingInstanceMember(
                    context.LoggingContext,
                    locationForLogging.AsLoggingLocation(),
                    name.ToDisplayString(context),
                    DisplayStringHelper.TypeToString(GetType(), context),
                    context.GetStackTraceAsString(locationForLogging));

                result = EvaluationResult.Error;
            }
            else
            {
                result = EvaluationResult.Create(resolvedMember);
            }

            return(true);
        }
Esempio n. 16
0
        public void ReportInputValidationException(ModuleLiteral env, InputValidationException inputValidationException, LineInfo lineInfo)
        {
            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportInputValidationError(
                LoggingContext,
                location.AsLoggingLocation(),
                inputValidationException.ErrorContext.ToErrorString(Context),
                !string.IsNullOrEmpty(inputValidationException.Message) ? ": " + inputValidationException.Message : string.Empty,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 17
0
 /// <nodoc />
 protected ArrayLiteral(LineInfo location, AbsolutePath path)
     : base(location, path)
 {
 }
Esempio n. 18
0
        public void ReportSpreadIsNotAppliedToArrayValue(ModuleLiteral env, Expression expression, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(expression != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportSpreadIsNotAppliedToArrayValue(
                LoggingContext,
                location.AsLoggingLocation(),
                expression.ToDisplayString(Context),
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 19
0
 /// <nodoc />
 public TypeQuery(NamedTypeReference entityName, LineInfo location)
     : base(location)
 {
     Contract.Requires(entityName != null);
     EntityName = entityName;
 }
Esempio n. 20
0
        /// <nodoc />
        public void ReportUnexpectedAmbientException(ModuleLiteral env, Exception exception, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(exception != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            // TODO: print nested messages as well!!
            Logger.ReportUnexpectedAmbientException(
                LoggingContext,
                location.AsLoggingLocation(),
                exception.Message,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 21
0
 /// <nodoc />
 public UnaryExpression(DeserializationContext context, LineInfo location)
     : base(location)
 {
     OperatorKind = (UnaryOperator)context.Reader.ReadByte();
     Expression   = ReadExpression(context);
 }
Esempio n. 22
0
        public void ReportDivideByZeroException(ModuleLiteral env, Expression expression, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(expression != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportDivideByZero(
                LoggingContext,
                location.AsLoggingLocation(),
                expression.ToDisplayString(Context),
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 23
0
 /// <nodoc />
 public NumberLiteral(BuildXLReader reader, LineInfo location)
     : base(location)
 {
     UnboxedValue = reader.ReadInt32Compact();
 }
Esempio n. 24
0
 /// <inheritdoc/>
 public override void ReportError(EvaluationErrors errors, ModuleLiteral environment, LineInfo location, Expression expression, Context context)
 {
     errors.ReportDivideByZeroException(environment, expression, location);
 }
Esempio n. 25
0
 /// <nodoc />
 public FileLiteral(DeserializationContext context, LineInfo location)
     : base(location)
 {
     Value = context.Reader.ReadFileArtifact();
 }
 /// <nodoc />
 public ImportOrExportVarSpecifier(DeserializationContext context, LineInfo location)
     : base(context, location)
 {
     Name         = ReadSymbolAtom(context);
     PropertyName = ReadSymbolAtom(context);
 }
Esempio n. 27
0
        /// <nodoc/>
        public TypeOrNamespaceModuleLiteral(ModuleLiteralId id, QualifierValue qualifier, ModuleLiteral outerScope, LineInfo location)
            : base(id, qualifier, outerScope, location)
        {
            Contract.Requires(id.Name.IsValid, "id.Name.IsValid");
            Contract.Requires(outerScope != null, "outerScope != null");

            // Only in V1 type or namespace module literals are unqualified. In V2 unqualified is never used for type or namespace literals.
            Contract.Requires(qualifier == QualifierValue.Unqualified || outerScope.Qualifier.QualifierId == qualifier.QualifierId);
        }
Esempio n. 28
0
        /// <inheritdoc />
        public override EvaluationResult GetOrEvalField(Context context, StringId name, bool recurs, ModuleLiteral origin, LineInfo location)
        {
            Contract.Requires(name.IsValid);

            if (name == context.ContextTree.CommonConstants.Length.StringId)
            {
                return(EvaluationResult.Create(Length));
            }

            return(EvaluationResult.Undefined);
        }
Esempio n. 29
0
        /// <nodoc />
        public IfStatement(Expression condition, Statement thenStatement, Statement elseStatement, LineInfo location)
            : base(location)
        {
            Contract.Requires(condition != null);
            Contract.Requires(thenStatement != null);

            Condition     = condition;
            ThenStatement = thenStatement;
            ElseStatement = elseStatement;
        }
Esempio n. 30
0
 /// <summary>
 /// Creates true.
 /// </summary>
 public static BoolLiteral CreateTrue(LineInfo location)
 {
     return(new BoolLiteral(true, location));
 }