Esempio n. 1
0
        public TableOfContentsWorker(CobolFile cobolFile)
        {
            _cobolFile = cobolFile;

            if (_cobolFile.CobolTree == null)
            {
                Logger.Error("PerformTree could not be built because CobolTree is null.");
                return;
            }

            var performTreeWorker = new BackgroundWorker();

            performTreeWorker.DoWork += delegate(object sender, DoWorkEventArgs args)
            {
                args.Result = GetPerformTree();
            };

            performTreeWorker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs args)
            {
                _performsTree = (TreeNode)args.Result;
                if (PerformTreeIsBuilt != null)
                {
                    PerformTreeIsBuilt(this, args);
                }
            };

            performTreeWorker.RunWorkerAsync();
        }
Esempio n. 2
0
        public ProgramInfo(CobolFile cobolFile, FileControl parent)
        {
            InitializeComponent();
            _parent = parent;

            FillCallTreeView(cobolFile);
        }
Esempio n. 3
0
        /// <summary>
        /// Tries to find all four division statements and, for all that miss, tries to find them in copy references
        /// and inserts them into the code.
        /// </summary>
        private static void FixMissingDivision(CobolFile cobolFile)
        {
            foreach (var copyReference in cobolFile.CopyReferences)
            {
                copyReference.CobolFile.DivisionsAndSection = TextUtil.Instance.FindDivisions(copyReference.CobolFile.Text);
            }

            if (!cobolFile.DivisionsAndSection.Identification.HasValue)
            {
                var missingCopy =
                    cobolFile.CopyReferences.FirstOrDefault(reference => reference.CobolFile.DivisionsAndSection.Identification.HasValue);
                TextUtil.Instance.Insert(cobolFile, missingCopy);
            }

            if (!cobolFile.DivisionsAndSection.Environment.HasValue)
            {
                var missingCopy =
                    cobolFile.CopyReferences.FirstOrDefault(reference => reference.CobolFile.DivisionsAndSection.Environment.HasValue);
                TextUtil.Instance.Insert(cobolFile, missingCopy);
            }

            if (!cobolFile.DivisionsAndSection.Data.HasValue)
            {
                var missingCopy =
                    cobolFile.CopyReferences.FirstOrDefault(reference => reference.CobolFile.DivisionsAndSection.Data.HasValue);
                TextUtil.Instance.Insert(cobolFile, missingCopy);
            }

            if (!cobolFile.DivisionsAndSection.Procedure.HasValue)
            {
                var missingCopy =
                    cobolFile.CopyReferences.FirstOrDefault(reference => reference.CobolFile.DivisionsAndSection.Procedure.HasValue);
                TextUtil.Instance.Insert(cobolFile, missingCopy);
            }
        }
Esempio n. 4
0
 public LineDto(string text, int number, Variable foundVariable, CobolFile containingFile)
 {
     Text           = text;
     Number         = number;
     FoundVariable  = foundVariable;
     ContainingFile = containingFile;
 }
Esempio n. 5
0
        /// <summary>
        /// Create a new file and add it to the project
        /// </summary>
        public CobolFile CreateNewFile(string cobolFileName)
        {
            CobolFile cobolFile = rootDirectoryLibrary.CreateNewFile(cobolFileName, RootDirectory + "/" + cobolFileName);

            CobolFiles.Add(cobolFileName, cobolFile);
            return(cobolFile);
        }
Esempio n. 6
0
 /// <summary>
 /// Remove a file from the project
 /// </summary>
 public void RemoveFile(CobolFile cobolFile)
 {
     if (rootDirectoryLibrary.ContainsFile(cobolFile.Name))
     {
         rootDirectoryLibrary.RemoveFile(cobolFile.Name, cobolFile.FullPath);
     }
     CobolFiles.Remove(cobolFile.Name);
 }
Esempio n. 7
0
        /// <summary>
        /// Import an existing file in the project
        /// </summary>
        public CobolFile ImportExistingFile(string cobolFileName)
        {
            CobolFile cobolFile = null;

            if (rootDirectoryLibrary.TryGetFile(cobolFileName, out cobolFile))
            {
                CobolFiles.Add(cobolFileName, cobolFile);
            }
            return(cobolFile);
        }
Esempio n. 8
0
        /// <summary>
        /// Add a Cobol program call found while compiling one file of the project
        /// </summary>
        public CobolFile AddCobolProgramCalls(string cobolProgramName)
        {
            CobolFile cobolFile = null;

            if (SourceFileProvider.TryGetFile(cobolProgramName, out cobolFile))
            {
                CobolTextReferences.Add(cobolProgramName, cobolFile);
            }
            return(cobolFile);
        }
        private void BuildRootVariableTree(CobolFile cobolFile)
        {
            AddRootVariable("Local", cobolFile.GetLocalRootVariables());

            foreach (var group in cobolFile.GetCopiedRootVariables().GroupBy(vari => vari.CopyReference.ProgramName))
            {
                AddRootVariable(group.Key, group);
            }

            VariableTreeView.ExpandAll();
        }
Esempio n. 10
0
        /// <summary>
        /// Monitor changes to the source Cobol file and automatically update TextDocument contents after each file update
        /// </summary>
        public virtual void StartContinuousFileProcessing()
        {
            // Reload text document each time an external change is applied to the cobol file
            ObserverTextDocument observerTextDocument = new ObserverTextDocument(CobolFile, TextDocument);

            CobolFile.CobolFileChanged += observerTextDocument.OnCobolFileChanged;

            // Start compilation process
            TextDocument.StartSendingChangeEvents();
            CobolFile.StartMonitoringExternalChanges();
        }
Esempio n. 11
0
        private void AnalyzeVariables(Procedure procedure, CobolFile cobolFile)
        {
            var foundTokens = VariablesUtil.Instance.GetIdentifierLiterals(procedure.GetCode());

            foreach (Literal token in foundTokens)
            {
                Variable variable;
                if (cobolFile.Variables.TryGetValue(token.Name, out variable))
                {
                    procedure.VariableUsages.AddOrUpdate(variable, token.UsedAs, (vari, usedAs) => usedAs.MergeUsages(token));
                }
            }
        }
Esempio n. 12
0
        public VariableUsageAnalyzerMain(Variable variable, CobolFile file)
        {
            InitializeComponent();
            Text = string.Format("CANAL - Variable Usage Analyzer (Origin: {0} -> {1})", file.Name, variable.VariableName);

            _file = file;

            var variableSelectionControl = new VariableSelectionControl(variable);

            variableSelectionControl.VariableSelectionOrSearchConfigChanged += UpdateFindingsControl;

            splitContainer1.Panel1.Controls.Add(variableSelectionControl);
            splitContainer1.FixedPanel = FixedPanel.Panel1;
        }
Esempio n. 13
0
        private void BuildCobolTree(CobolFile cobolFile)
        {
            try
            {
                Logger.Info("Building CobolTree for file {0}.", cobolFile.Name);

                var builder = new CobolTreeBuilder();
                cobolFile.CobolTree = builder.Build(cobolFile);
            }
            catch (Exception exception)
            {
                Logger.Error("Error building CobolTree: {0}.", exception.Message);
                throw new CanalException("Error building CobolTree: " + exception.Message, exception);
            }
        }
Esempio n. 14
0
        public void SetCobolFile(CobolFile cobolFile)
        {
            if (IsDisposed)
            {
                return;
            }

            _cobolFile             = cobolFile;
            _tableOfContentsWorker = new TableOfContentsWorker(_cobolFile);
            SortToc(Util.Properties.Settings.Default.TocSort);

            if (tocTreeView.Controls.Contains(_loader))
            {
                tocTreeView.Controls.Remove(_loader);
            }
        }
Esempio n. 15
0
        public CobolTree Build(CobolFile file)
        {
            var tree = new CobolTree();

            if (!file.DivisionsAndSection.AllDivisionsFound())
            {
                return(tree);
            }

            // IDENTIFICATION DIVISION
            tree.IdentificationDivision = new IdentificationDivision(file);

            // ENVIRONMENT DIVISION
            tree.EnvironmentDivision = new EnvironmentDivision(file);

            // DATA DIVISION
            tree.DataDivision = new DataDivision(file)
            {
                WorkingStorageSection = new WorkingStorageSection(file),
                LinkageSection        = new LinkageSection(file)
            };

            // PROCEDURE DIVISION
            tree.ProcedureDivision          = new ProcedureDivision(file);
            tree.ProcedureDivision.Sections = BuildSections(tree.ProcedureDivision);

            foreach (var procedure in tree.GetAllProcedures())
            {
                AnalyzeVariables(procedure, file);
                AnalyzePerformReferences(procedure);
                AnalyzeGoTos(procedure);
                AnalyzeCalls(procedure);
            }

            BuildReferences(tree.ProcedureDivision);

            // fix deeper references
            foreach (var performReference in tree.GetAllProcedures().SelectMany(procedure => procedure.PerformReferences.Where(pref => pref.Procedure == null)))
            {
                performReference.Procedure = tree.GetAllProcedures().FirstOrDefault(p => p.Name == performReference.ReferencedProcedure);
            }

            return(tree);
        }
        public CodeGeneratorMainWindow(CobolFile cobolFile)
        {
            InitializeComponent();

            InitDataGridView();

            BuildRootVariableTree(cobolFile);

            // Business Object Tab
            BusinessObjectCodeBox.Language = Language.CSharp;

            // Mapper Tab
            MapperCodeBox.Language = Language.CSharp;

            // Extensions Tab
            ExtensionsCodeBox.Language = Language.CSharp;

            // Enums Tab
            EnumsCodeBox.Language = Language.CSharp;
        }
Esempio n. 17
0
        /// <summary>
        /// Loads the text from the file given in the reference and creates a new CobolFile object.
        /// </summary>
        public CobolFile Build(FileReference fileReference)
        {
            Logger.Info("Loading text for reference {0}.", fileReference);
            var text = FileUtil.Instance.GetText(fileReference);

            var name = Path.GetFileNameWithoutExtension(fileReference.FilePath);

            // Create new CobolFile
            var file = new CobolFile(text, name)
            {
                FileReference = fileReference,
            };

            // Set relation: reference <=> file
            fileReference.CobolFile = file;

            Logger.Info("Built new CobolFile {0}.", file.Name);

            return(file);
        }
Esempio n. 18
0
        /// <summary>
        /// Analyzes source text and source text of all copy references and fills the CobolFile.Variables property.
        /// </summary>
        private void AnalyzeVariables(CobolFile cobolFile)
        {
            try
            {
                cobolFile.Variables = VariablesUtil.Instance.AnalyzeVariables(cobolFile);

                foreach (var copyReference in cobolFile.CopyReferences.AsParallel())
                {
                    copyReference.CobolFile.Variables = VariablesUtil.Instance.AnalyzeVariables(copyReference.CobolFile);
                    foreach (var variablePair in copyReference.CobolFile.Variables)
                    {
                        cobolFile.Variables.TryAdd(variablePair.Key, variablePair.Value);
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Error("Error analyzing variable for file '{0}': {1}", cobolFile.Name, exception.Message);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Finds all copy references, creates CobolFile-objects for each one and adds them to the CobolFile.CopyReferences List
        /// </summary>
        private void LoadCopyReferences(CobolFile cobolFile)
        {
            Logger.Info("Resolving copy references for file {0}.", cobolFile.Name);

            var refs = TextUtil.Instance.FindCopyReferences(cobolFile.Text);

            foreach (var copyReference in refs.AsParallel())
            {
                // Load text and create CobolFile
                copyReference.CobolFile = new CobolFileBuilder().Build(copyReference);

                // Look for Identification, Environment, Data and Procedure Divion
                copyReference.CobolFile.DivisionsAndSection = TextUtil.Instance.FindDivisions(copyReference.CobolFile.Text);

                // Add to parent's copy-list
                cobolFile.CopyReferences.Add(copyReference);
            }

            Logger.Info("Finished loading copy references for file {0}.", cobolFile.Name);
        }
Esempio n. 20
0
        public void Insert(CobolFile file, FileReference copyReference)
        {
            var newText = new StringBuilder();

            // Index of "COPY" in text might have changed, since other copys were resolved
            var copyRegex          = new Regex(@"^.{6} +COPY +" + copyReference.ProgramName, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            var updatedIndexOfCopy = copyRegex.Match(file.Text).Index;

            var lineBeforeCopy = file.Text.LastIndexOf(Environment.NewLine, updatedIndexOfCopy, StringComparison.Ordinal);
            var lineAfterCopy  = file.Text.IndexOf(Environment.NewLine, updatedIndexOfCopy, StringComparison.Ordinal);

            newText.Append(file.Text.Substring(0, lineBeforeCopy + 8));
            newText.Append("*"); // Comment out COPY
            newText.Append(file.Text.Substring(lineBeforeCopy + 8, lineAfterCopy - (lineBeforeCopy + 8)).TrimEnd());
            newText.AppendLine("  *> COPY resolved by Canal");
            newText.Append(copyReference.CobolFile.Text + Environment.NewLine);
            newText.Append(file.Text.Substring(lineAfterCopy));

            file.Text = newText.ToString();
        }
Esempio n. 21
0
        public void LoadFiles(object sender, DoWorkEventArgs e)
        {
            var project = e.Argument as CobolProject;

            if (project == null)
            {
                return;
            }

            var worker = (BackgroundWorker)sender;

            worker.WorkerReportsProgress = true;

            FileUtil.Instance.AnalyzeFolder(project.FilesRoot);

            var references = FileUtil.Instance.GetFileReferences(project.FilesRoot);

            Parallel.ForEach(references, fileReference =>
            {
                var text = File.ReadAllText(fileReference.FilePath);

                var name = Path.GetFileNameWithoutExtension(fileReference.FilePath);

                // Create new CobolFile
                var cobolFile = new CobolFile(text, name)
                {
                    FileReference = fileReference,
                };

                // Set relation: reference <=> file
                fileReference.CobolFile = cobolFile;

                project.Files.TryAdd(fileReference, cobolFile);

                var progress = (int)((float)project.Files.Count / references.Count * 100);
                worker.ReportProgress(progress);
            });

            e.Result = project;
        }
Esempio n. 22
0
        /// <summary>
        /// Loads the content of a source file in the editor
        /// </summary>
        public TypeCobolEditor(CobolFile sourceFile)
        {
            TextView textView = TextArea.TextView;

            // Default text style
            FontFamily = new FontFamily("Consolas");
            FontSize   = 13;

            // Show line numbers
            ShowLineNumbers = true;

            // Activate search box
            SearchPanel.Install(this);

            // Plug in TypeCobol syntax highlighting
            syntaxHighlighter = new SyntaxHighlighter();
            textView.LineTransformers.Add(syntaxHighlighter);

            // Plug in TypeCobol error marker
            errorMarker = new ErrorMarker(this);
            textView.BackgroundRenderers.Add(errorMarker);
            textView.LineTransformers.Add(errorMarker);

            // Tooltip management
            tooltipManager               = new TooltipManager(this, errorMarker);
            textView.MouseHover         += tooltipManager.MouseHover;
            textView.MouseHoverStopped  += tooltipManager.MouseHoverStopped;
            textView.VisualLinesChanged += tooltipManager.VisualLinesChanged;

            // Initial load of the cobol file if necessary
            if (sourceFile != null)
            {
                Document = new ICSharpCode.AvalonEdit.Document.TextDocument(sourceFile.ReadChars());
            }

            // Wrap the AvalonEdit.Document in a ITextDocument interface
            textDocument = new AvalonEditTextDocument(Document, IBMCodePages.GetDotNetEncodingFromIBMCCSID(1147), ColumnsLayout.CobolReferenceFormat);
        }
Esempio n. 23
0
        private void FillCallTreeView(CobolFile cobolFile)
        {
            if (cobolFile == null || cobolFile.CobolTree == null)
            {
                return;
            }

            var callNode = new TreeNode("Calls");

            wordInfoTreeView.Nodes.Add(callNode);

            var uniqueFolders = new HashSet <string>(cobolFile.CobolTree.CallReferences.Select(cr => cr.Directory));

            foreach (var folder in uniqueFolders)
            {
                var folderNode = new TreeNode(folder);
                callNode.Nodes.Add(folderNode);
                var folder1 = folder;
                foreach (var fileRef in cobolFile.CobolTree.CallReferences.Where(cr => cr.Directory == folder1))
                {
                    folderNode.Nodes.Add(new TreeNode(fileRef.ProgramName)
                    {
                        Tag = fileRef
                    });
                }
            }

            wordInfoTreeView.ExpandAll();

            wordInfoTreeView.NodeMouseDoubleClick += (sender, args) =>
            {
                var fileRef = wordInfoTreeView.SelectedNode.Tag as FileReference;
                if (fileRef != null)
                {
                    _parent.MainWindow.OpenFile(fileRef.FilePath);
                }
            };
        }
Esempio n. 24
0
        private static List <LineDto> FindVariablesInFile(CobolFile file, List <Variable> variableList)
        {
            var findings = new List <LineDto>();

            using (var fileText = new StringReader(file.Text))
            {
                var    currLineNumber = 1;
                string currLineText;
                while ((currLineText = fileText.ReadLine()) != null)
                {
                    foreach (var currVariable in variableList)
                    {
                        if (currLineText.Contains(currVariable.VariableName))
                        {
                            findings.Add(new LineDto(currLineText, currLineNumber, currVariable, file));
                            break;
                        }
                    }
                    currLineNumber++;
                }
            }
            return(findings);
        }
Esempio n. 25
0
        public ConcurrentDictionary <string, Variable> AnalyzeVariables(CobolFile cobolFile, bool trim = true)
        {
            // FILLER; REDEFINES; OCCURS; SPACES; 66
            // [ "USAGE" [ "IS" ] ] ( "BINARY" | "COMP" | "COMP-1" | "COMP-2" | "COMP-3" | "COMP-4" | "COMPUTATIONAL" | "COMPUTATIONAL-1" | "COMPUTATIONAL-2" | "COMPUTATIONAL-3" | "COMPUTATIONAL-4" | "DISPLAY" | "DISPLAY-1" | "INDEX" | "PACKED-DECIMAL" | "POINTER" )
            // ( "VALUE" [ "IS" ] | "VALUES" [ "ARE" ] ) { literal [ ( "THROUGH" | "THRU" ) literal ] }+
            // "RENAMES" qualified-data-name [ ( "THROUGH" | "THRU" ) qualified-data-name ]
            var result = new ConcurrentDictionary <string, Variable>();

            try
            {
                var trimmedText = trim ? TextUtil.Instance.TrimAllLines(cobolFile.Text) : cobolFile.Text;

                var      regex        = new Regex(Constants.Variable, Constants.CompiledMultilineCaseInsensitive);
                var      preparedText = trimmedText.Replace("\t", " ");
                Variable lastVariable = null;

                foreach (Match match in regex.Matches(preparedText))
                {
                    // Read properties from RegEx
                    var valLevel     = int.Parse(match.Groups["level"].Value);
                    var valLiteral   = match.Groups["literal"].Value;
                    var valRedefines = match.Groups["redefines"].Value;
                    var valType      = match.Groups["type"].Value;
                    var valComp      = match.Groups["comp"].Value;
                    var valValue     = match.Groups["value"].Value;
                    var valOccurs    = match.Groups["occurs"].Value;
                    var valIndex     = match.Index;

                    // Create type definition ("PIC")
                    var picture = match.Groups[2].ToString().ToUpperInvariant() == "BINARY"
                        ? new PicBinary()
                        : PicParser.Instance.ParsePicture(valType, valComp, valValue, valLevel);

                    if (picture == null)
                    {
                        // variable incomplete => ignore it before it troubles
                        Logger.Warning("Ignoring variable definition '{0}' because of previous errors in picture clause.", match.Value);
                        continue;
                    }


                    // Find redefined variables
                    Variable redefined = null;
                    if (!string.IsNullOrWhiteSpace(valRedefines))
                    {
                        if (!result.ContainsKey(valRedefines))
                        {
                            Logger.Error("Redefined variable {0} not found in file {1} (variable definition: {2}).", valRedefines, cobolFile.Name, match.Value);
                        }
                        else
                        {
                            redefined = result[valRedefines];
                        }
                    }

                    // Create Variable
                    var currentVariable = new Variable(valLevel, valLiteral, picture, match.Value, null)
                    {
                        Redefines     = redefined,
                        Occurs        = !string.IsNullOrWhiteSpace(valOccurs) ? int.Parse(valOccurs) : 1,
                        CopyReference = cobolFile.FileReference,
                        Index         = valIndex
                    };

                    // Save result to dictionary
                    result.TryAdd(currentVariable.VariableName, currentVariable);

                    // Create references between variables
                    if (lastVariable == null || currentVariable.VariableLevel == 1 || currentVariable.VariableLevel == 77)
                    {
                        lastVariable = currentVariable;
                    }
                    else if (currentVariable.VariableLevel > lastVariable.VariableLevel)
                    {
                        currentVariable.ParentVariable = lastVariable;
                        lastVariable.Variables.Add(currentVariable);
                        lastVariable = currentVariable;
                    }
                    else if (currentVariable.VariableLevel < lastVariable.VariableLevel || (currentVariable.VariableLevel != 88 && lastVariable.VariableLevel == 88))
                    {
                        while (lastVariable != null && lastVariable.ParentVariable != null && currentVariable.VariableLevel <= lastVariable.VariableLevel)
                        {
                            lastVariable = lastVariable.ParentVariable;
                        }

                        currentVariable.ParentVariable = lastVariable;
                        lastVariable.Variables.Add(currentVariable);
                        lastVariable = currentVariable;
                    }
                    else if (lastVariable.VariableLevel == currentVariable.VariableLevel)
                    {
                        currentVariable.ParentVariable = lastVariable.ParentVariable;
                        if (lastVariable.ParentVariable != null)
                        {
                            lastVariable.ParentVariable.Variables.Add(currentVariable);
                        }
                        lastVariable = currentVariable;
                    }
                }

                foreach (var variable in result.Values.Where(vari => vari.VariableLevel == 1))
                {
                    variable.ByteLength = GetByteLength(variable, 0);
                }

                return(result);
            }
            catch (Exception exception)
            {
                Logger.Error("Error analysing variables for file '{0}': {1} Result may be incomplete.", cobolFile.Name, exception.Message);
                return(result);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Common internal implementation for all constructors above
        /// </summary>
        private FileCompiler(string libraryName, string fileName, CobolFile loadedCobolFile, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, ColumnsLayout columnsLayout, ITextDocument textDocument, TypeCobolOptions compilerOptions, SymbolTable customSymbols, bool isCopyFile,
                             [CanBeNull] MultilineScanState scanState, CompilationProject compilationProject, List <RemarksDirective.TextNameVariation> copyTextNameVariations)
        {
            var chrono = new Stopwatch();

            chrono.Start();

            // 1.a Find the Cobol source file
            CobolFile sourceFile = null;

            CompilationProject = compilationProject;

            if (fileName != null)
            {
                if (sourceFileProvider.TryGetFile(libraryName, fileName, out sourceFile))
                {
                    CobolFile = sourceFile;
                }
                else
                {
                    var message = string.IsNullOrEmpty(libraryName) ? string.Format("Cobol source file not found: {0}", fileName)
                                                                    : string.Format("Cobol source file not found: {0} in {1}", fileName, libraryName);
                    throw new Exception(message);
                }
            }
            // 1.b Register a Cobol source file which was already loaded
            else if (loadedCobolFile != null)
            {
                CobolFile = loadedCobolFile;
            }

            chrono.Stop();
            SourceFileSearchTime = (int)chrono.ElapsedMilliseconds;
            chrono.Reset();

            // 2.a Load it in a new text document in memory
            chrono.Start();
            if (textDocument == null)
            {
                TextDocument = new ReadOnlyTextDocument(sourceFile?.Name, sourceFile?.Encoding, columnsLayout, sourceFile?.ReadChars());
            }
            // 2.b Load it in an existing text document in memory
            else if (sourceFile != null)
            {
                TextDocument = textDocument;
                textDocument.LoadChars(sourceFile.ReadChars());
            }
            // 2.c Use a pre-existing text document
            //     - not yet associated with a Cobol source file
            //     - with a Cobol source file already loaded
            else if (sourceFile == null || loadedCobolFile != null)
            {
                TextDocument = textDocument;
            }

            chrono.Stop();
            SourceFileLoadTime = (int)chrono.ElapsedMilliseconds;
            chrono.Reset();

            // 3. Prepare the data structures used by the different steps of the compiler
            if (isCopyFile)
            {
                CompilationResultsForCopy = new CompilationDocument(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider, scanState, copyTextNameVariations);
                CompilationResultsForCopy.CustomSymbols = customSymbols;
            }
            else
            {
                CompilationResultsForProgram = new CompilationUnit(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider, copyTextNameVariations);
                CompilationResultsForProgram.CustomSymbols = customSymbols;
            }
            CompilerOptions = compilerOptions;
        }
Esempio n. 27
0
        /// <summary>
        /// Common internal implementation for all 4 constructors above
        /// </summary>
        private FileCompiler(string libraryName, string fileName, CobolFile loadedCobolFile, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, ColumnsLayout columnsLayout, ITextDocument textDocument, TypeCobolOptions compilerOptions, SymbolTable customSymbols, bool isCopyFile,
                             [CanBeNull] MultilineScanState scanState, CompilationProject compilationProject, List <RemarksDirective.TextNameVariation> copyTextNameVariations)
        {
            // 1.a Find the Cobol source file
            CobolFile sourceFile = null;

            CompilationProject = compilationProject;

            if (fileName != null)
            {
                if (sourceFileProvider.TryGetFile(libraryName, fileName, out sourceFile))
                {
                    CobolFile = sourceFile;
                }
                else
                {
                    if (isCopyFile)
                    {
                        compilationProject.MissingCopys.Add(fileName);
                    }

                    throw new Exception(string.Format("Could not find a Cobol source file named {0} in {1}", fileName, libraryName));
                }
            }
            // 1.b Register a Cobol source file which was already loaded
            else if (loadedCobolFile != null)
            {
                CobolFile = loadedCobolFile;
            }

            // 2.a Load it in a new text document in memory
            if (textDocument == null)
            {
                TextDocument = new ReadOnlyTextDocument(sourceFile.Name, sourceFile.Encoding, columnsLayout, sourceFile.ReadChars());
            }
            // 2.b Load it in an existing text document in memory
            else if (sourceFile != null)
            {
                TextDocument = textDocument;
                textDocument.LoadChars(sourceFile.ReadChars());
            }
            // 2.c Use a pre-existing text document
            //     - not yet associated with a Cobol source file
            //     - with a Cobol source file already loaded
            else if (sourceFile == null || loadedCobolFile != null)
            {
                TextDocument = textDocument;
            }

            // 3. Prepare the data structures used by the different steps of the compiler
            if (isCopyFile)
            {
                CompilationResultsForCopy = new CompilationDocument(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider, scanState, copyTextNameVariations);
                CompilationResultsForCopy.CustomSymbols = customSymbols;
            }
            else
            {
                CompilationResultsForProgram = new CompilationUnit(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider, copyTextNameVariations);
                CompilationResultsForProgram.CustomSymbols = customSymbols;
            }
            CompilerOptions = compilerOptions;
        }
Esempio n. 28
0
 public ObserverTextDocument(CobolFile cobolFile, ITextDocument textDocument)
 {
     this.cobolFile    = cobolFile;
     this.textDocument = textDocument;
 }
Esempio n. 29
0
 protected Division(CobolFile cobolFile, string nodeName, int beginIndex, int endIndex)
     : base(cobolFile, nodeName)
 {
     StartIndex = beginIndex;
     EndIndex   = endIndex;
 }
Esempio n. 30
0
 public VariableListControl(Variable variable, CobolFile file, bool includeDirectAndIndirectChildVariables, bool includeRedefines)
     : this(variable, new List <CobolFile> {
     file
 }, includeDirectAndIndirectChildVariables, includeRedefines)
 {
 }