public override string ProduceBeforeEof()
        {
            var data = T4FailureRawData.FromElement(FirstElement, "Unexpected element after feature");

            Interrupter.InterruptAfterProblem(data);
            return(Builder.ToString());
        }
Пример #2
0
        public override IT4InfoCollectorState GetNextState(IT4TreeNode element)
        {
            switch (element)
            {
            case IT4FeatureBlock _: return(this);

            case IT4ExpressionBlock _:
                return(new T4InfoCollectorStateSeenFeatureAndExpressionBlock(Interrupter));

            default:
                if (element.NodeType == T4TokenNodeTypes.NEW_LINE)
                {
                    return(new T4InfoCollectorStateSeenFeatureAndNewLine(Interrupter));
                }
                else if (element.NodeType == T4TokenNodeTypes.RAW_TEXT)
                {
                    // At this point, LastToken is initialized through ConsumeTokenSafe call
                    var builder = new StringBuilder(Convert(LastToken));
                    return(new T4InfoCollectorStateSeenFeatureAndText(builder, Interrupter, element));
                }

                var data = T4FailureRawData.FromElement(element, "Unexpected element after feature");
                Interrupter.InterruptAfterProblem(data);
                return(this);
            }
        }
        public override IT4InfoCollectorState GetNextState(IT4TreeNode element)
        {
            switch (element)
            {
            case IT4FeatureBlock:
                return(new T4InfoCollectorStateSeenFeature(Interrupter));

            case IT4ExpressionBlock:
                return(new T4InfoCollectorStateSeenFeatureAndExpressionBlock(Interrupter));

            default:
                if (element.NodeType == T4TokenNodeTypes.NEW_LINE)
                {
                    return(this);
                }
                else if (element.NodeType == T4TokenNodeTypes.RAW_TEXT)
                {
                    return(new T4InfoCollectorStateSeenFeatureAndText(Builder, Interrupter, element));
                }

                var data = T4FailureRawData.FromElement(element, "Unexpected element after feature");
                Interrupter.InterruptAfterProblem(data);
                return(this);
            }
        }
		public void ProcessBeforeInterior(ITreeNode element)
		{
			AppendRemainingMessage(element);
			if (!(element is IT4IncludeDirective include)) return;
			var file = (IT4File) element.GetContainingFile().NotNull();
			Results.Push(new T4CSharpCodeGenerationIntermediateResult(file, Interrupter));
			var sourceFile = IncludeResolver.Resolve(include.ResolvedPath);
			if (sourceFile == null)
			{
				var target = include.GetFirstAttribute(T4DirectiveInfoManager.Include.FileAttribute)?.Value ?? element;
				var data = T4FailureRawData.FromElement(target, $"Unresolved include: {target.GetText()}");
				Interrupter.InterruptAfterProblem(data);
				Guard.StartProcessing(file.LogicalPsiSourceFile.GetLocation());
				return;
			}

			if (include.Once && Guard.HasSeenFile(sourceFile.GetLocation())) return;
			if (!Guard.CanProcess(sourceFile.GetLocation()))
			{
				var target = include.GetFirstAttribute(T4DirectiveInfoManager.Include.FileAttribute)?.Value ?? element;
				var data = T4FailureRawData.FromElement(target, "Recursion in includes");
				Interrupter.InterruptAfterProblem(data);
				Guard.StartProcessing(sourceFile.GetLocation());
				return;
			}

			var resolved = include.IncludedFile;
			Guard.StartProcessing(sourceFile.GetLocation());
			resolved?.ProcessDescendants(this);
		}
Пример #5
0
        public override IT4InfoCollectorState GetNextState(IT4TreeNode element)
        {
            switch (element)
            {
            case IT4FeatureBlock _:
                return(new T4InfoCollectorStateSeenFeature(Interrupter));

            case IT4ExpressionBlock _:
                return(this);

            default:
                if (element.NodeType == T4TokenNodeTypes.NEW_LINE)
                {
                    var builder = new StringBuilder(StringLiteralConverter.EscapeToRegular(Environment.NewLine));
                    return(new T4InfoCollectorStateSeenFeatureAndText(builder, Interrupter, element));
                }
                else if (element.NodeType == T4TokenNodeTypes.RAW_TEXT)
                {
                    var builder = new StringBuilder(Convert(LastToken));
                    return(new T4InfoCollectorStateSeenFeatureAndText(builder, Interrupter, element));
                }

                var data = T4FailureRawData.FromElement(element, "Unexpected element after feature");
                Interrupter.InterruptAfterProblem(data);
                return(this);
            }
        }
        public IEnumerable <T4AssemblyReferenceInfo> ExtractReferenceLocationsTransitive(IT4File file)
        {
            file.AssertContainsNoIncludeContext();
            var sourceFile  = file.PhysicalPsiSourceFile.NotNull();
            var projectFile = sourceFile.ToProjectFile().NotNull();
            var directives  = file.GetThisAndIncludedFilesRecursive()
                              .SelectMany(it => it.Blocks)
                              .OfType <IT4AssemblyDirective>();
            var errors             = new FrugalLocalList <T4FailureRawData>();
            var directDependencies = directives.SelectNotNull(
                directive =>
            {
                var resolved = AssemblyReferenceResolver.Resolve(directive);
                if (resolved == null)
                {
                    errors.Add(T4FailureRawData.FromElement(directive, "Unresolved assembly reference"));
                }

                return(resolved);
            }
                ).AsList();

            if (!errors.IsEmpty)
            {
                throw new T4OutputGenerationException(errors);
            }
            AddBaseReferences(directDependencies, file);
            return(LowLevelReferenceExtractionManager.ResolveTransitiveDependencies(
                       directDependencies,
                       projectFile.SelectResolveContext()
                       ));
        }
Пример #7
0
        private static T4FailureRawData CreateError([NotNull] IT4AssemblyDirective directive)
        {
            var attribute = directive.GetFirstAttribute(T4DirectiveInfoManager.Assembly.NameAttribute);

            if (attribute == null)
            {
                return(T4FailureRawData.FromElement(directive, "Missing assembly name"));
            }
            string message = $"Unresolved assembly reference: {attribute.Value.GetText()}";

            return(T4FailureRawData.FromElement(directive, message));
        }
Пример #8
0
        private FileSystemPath ResolveBaseReference(
            [NotNull] IT4File file,
            [NotNull] string assemblyName
            )
        {
            var resolved = AssemblyReferenceResolver.Resolve(assemblyName, file.LogicalPsiSourceFile);

            if (resolved != null)
            {
                return(resolved);
            }
            var    node    = FindSuitableNodeForErrorReporting(file);
            string message = $"Could not find standard assembly: {assemblyName}";

            throw new T4OutputGenerationException(T4FailureRawData.FromElement(node, message));
        }
        public override IT4InfoCollectorState GetNextState(IT4TreeNode element)
        {
            switch (element)
            {
            case IT4FeatureBlock _:
                return(new T4InfoCollectorStateSeenFeature(Interrupter));

            case IT4ExpressionBlock _:
                return(new T4InfoCollectorStateSeenFeatureAndExpressionBlock(Interrupter));

            case IT4Token _: return(this);

            default:
                var data = T4FailureRawData.FromElement(FirstElement, "Unexpected element after feature");
                Interrupter.InterruptAfterProblem(data);
                return(this);
            }
        }
Пример #10
0
        public string FindEncoding([NotNull] IT4OutputDirective directive, [NotNull] IT4CodeGenerationInterrupter interrupter)
        {
            var attribute = directive.GetFirstAttribute(T4DirectiveInfoManager.Output.EncodingAttribute);
            var value     = attribute?.Value;

            if (value == null)
            {
                return(null);
            }
            string rawEncoding = value.GetText();

            if (IsCodePage(rawEncoding))
            {
                return(rawEncoding);                                     // Insert unquoted
            }
            if (IsEncodingName(rawEncoding))
            {
                return($"\"{rawEncoding}\"");
            }
            interrupter.InterruptAfterProblem(T4FailureRawData.FromElement(value, "Unknown encoding"));
            return(null);
        }
		public override void VisitUnknownDirectiveNode(IT4UnknownDirective unknownDirectiveParam)
		{
			var data = T4FailureRawData.FromElement(unknownDirectiveParam, "Custom directives are not supported");
			Interrupter.InterruptAfterProblem(data);
		}