コード例 #1
0
ファイル: Coder.cs プロジェクト: mshakurov/OpenLR
 /// <summary>
 /// Encodes a location into an OpenLR string.
 /// </summary>
 public string Encode(ReferencedLocation location, EncodingSettings settings)
 {
     if (location is ReferencedCircle)
     {
         return(_rawCodec.Encode(Referenced.Codecs.ReferencedCircleCodec.Encode(location as ReferencedCircle)));
     }
     if (location is ReferencedGeoCoordinate)
     {
         return(_rawCodec.Encode(Referenced.Codecs.ReferencedGeoCoordinateCodec.Encode(location as ReferencedGeoCoordinate)));
     }
     if (location is ReferencedGrid)
     {
         return(_rawCodec.Encode(Referenced.Codecs.ReferencedGridCodec.Encode(location as ReferencedGrid)));
     }
     if (location is ReferencedLine)
     {
         return(_rawCodec.Encode(Referenced.Codecs.ReferencedLineCodec.Encode(location as ReferencedLine, this, settings)));
     }
     if (location is ReferencedPointAlongLine)
     {
         return(_rawCodec.Encode(Referenced.Codecs.ReferencedPointAlongLineCodec.Encode(location as ReferencedPointAlongLine, this)));
     }
     if (location is ReferencedPolygon)
     {
         return(_rawCodec.Encode(Referenced.Codecs.ReferencedPolygonCodec.Encode(location as ReferencedPolygon)));
     }
     if (location is ReferencedRectangle)
     {
         return(_rawCodec.Encode(Referenced.Codecs.ReferencedRectangleCodec.Encode(location as ReferencedRectangle)));
     }
     throw new ArgumentOutOfRangeException("location", "Unknow location type.");
 }
コード例 #2
0
        /// <summary>
        /// Serializes into the given writer.
        /// </summary>
        protected override void DoSerialize(BuildXLWriter writer)
        {
            TargetExpression.Serialize(writer);

            writer.Write(TargetQualifierSpaceId);
            writer.Write(ShouldUseDefaultsOnCoercion);

            // Force computation of line and column. When deserializing,
            // the wrong file map will be available.
            ReferencedLocation.DoSerialize(writer, forceLineAndColumn: true);
        }
コード例 #3
0
        /// <inheritdoc />
        protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame)
        {
            var moduleCandidate = TargetExpression.Eval(context, env, frame);

            if (moduleCandidate.IsErrorValue || moduleCandidate.IsUndefined)
            {
                return(moduleCandidate);
            }

            // Qualifier type coercion could happen on both namespaces and files when importFrom is used.
            var module = moduleCandidate.Value as ModuleLiteral;

            // Moving Assert into the if block to avoid relatively expensive message computation for non-error case.
            if (module == null)
            {
                Contract.Assert(
                    false,
                    I($"TargetExpression '{TargetExpression.ToDisplayString(context)}' should produce 'ModuleLiteral' but produced '{moduleCandidate.Value.GetType()}'"));
            }

            var pathTable = context.FrontEndContext.PathTable;

            // TODO: Consider if it is possible to use QualifierUtilities.CoerceQualifierValue instead.
            QualifierValue oldQualifierValue = module.Qualifier;

            if (
                !oldQualifierValue.TryCoerce(
                    TargetQualifierSpaceId,
                    context.FrontEndContext.QualifierTable,
                    context.QualifierValueCache,
                    pathTable,
                    context.FrontEndContext.StringTable,
                    context.FrontEndContext.LoggingContext,
                    out QualifierValue coercedQualifier,
                    Location,
                    ShouldUseDefaultsOnCoercion,
                    context.LastActiveUsedPath))
            {
                context.Errors.ReportQualifierCannotBeCoarcedToQualifierSpaceWithProvenance(
                    oldQualifierValue.QualifierId,
                    TargetQualifierSpaceId,
                    ReferencedLocation.AsLoggingLocation(),
                    Location.AsLoggingLocation(env, context));

                return(EvaluationResult.Error);
            }

            return(EvaluationResult.Create(module.Instantiate(context.ModuleRegistry, coercedQualifier)));
        }
コード例 #4
0
 /// <summary>
 /// Encodes the given referenced location.
 /// </summary>
 /// <param name="location"></param>
 /// <returns></returns>
 public abstract string Encode(ReferencedLocation location);
コード例 #5
0
ファイル: Coder.cs プロジェクト: mshakurov/OpenLR
 /// <summary>
 /// Encodes a location into an OpenLR string.
 /// </summary>
 public string Encode(ReferencedLocation location)
 {
     return(this.Encode(location, EncodingSettings.Default));
 }