public override void EnterCopyCompilerStatementBody(CobolCompilerDirectivesParser.CopyCompilerStatementBodyContext context) { var copy = (CopyDirective)CompilerDirective; if (context.qualifiedTextName() != null) { var ctxt = context.qualifiedTextName(); copy.TextName = GetTextName(ctxt.textName()); copy.TextNameSymbol = ParseTreeUtils.GetFirstToken(ctxt.textName()); #if EUROINFO_LEGACY_REPLACING_SYNTAX if (copy.TextName != null) { // Find the list of copy text names variations declared by previous REMARKS compiler directives var variations = CopyTextNameVariations; if (TypeCobolOptions.AutoRemarksEnable && (variations == null || !variations.Any(v => string.Equals(v.TextNameWithSuffix, copy.TextName, StringComparison.InvariantCultureIgnoreCase)))) //If it does not exists, create the text variation (AutoRemarks mechanism Issue #440) { variations = new List <RemarksDirective.TextNameVariation> { new RemarksDirective.TextNameVariation(copy.TextName) }; CopyTextNameVariations.AddRange(variations); } if (variations != null) { var declaration = variations.Find(d => String.Equals(d.TextNameWithSuffix, copy.TextName, StringComparison.InvariantCultureIgnoreCase)); if (declaration != null) { // Declaration found => apply the legacy REPLACING semantics to the copy directive copy.RemoveFirst01Level = true; if (declaration.HasSuffix) { copy.TextName = declaration.TextName; copy.InsertSuffixChar = true; copy.Suffix = declaration.Suffix; copy.PreSuffix = declaration.PreSuffix; } } } } #endif copy.LibraryName = GetLibraryName(ctxt.libraryName()); copy.LibraryNameSymbol = ParseTreeUtils.GetFirstToken(ctxt.libraryName()); } copy.Suppress = (context.SUPPRESS() != null); // REPLACING if (context.copyReplacingOperand() != null) { // Data used to build the current replace operation Token comparisonToken = null; Token[] followingComparisonTokens = null; Token replacementToken = null; Token[] replacementTokens = null; // Used to distinguish pseudo-text1 and pseudo-text2 int pseudoTextIndex = 0; foreach (CobolCompilerDirectivesParser.CopyReplacingOperandContext replacingOperandContext in context.copyReplacingOperand()) { // Get relevant tokens IList <IToken> operandTokens = null; if (replacingOperandContext.pseudoText() != null) // Pseudo-text => List of tokens { if (replacingOperandContext.pseudoText()._pseudoTextTokens != null) { operandTokens = replacingOperandContext.pseudoText()._pseudoTextTokens; } } else // Single token { if (replacingOperandContext.literalOrUserDefinedWordOReservedWordExceptCopy() != null) { var terminalNode = ParseTreeUtils.GetFirstTerminalNode(replacingOperandContext.literalOrUserDefinedWordOReservedWordExceptCopy()); operandTokens = new List <IToken>(1); operandTokens.Add(terminalNode.Symbol); } } BuildReplaceOperation(copy.ReplaceOperations, ref comparisonToken, ref followingComparisonTokens, ref replacementToken, ref replacementTokens, ref pseudoTextIndex, operandTokens); } } }
public virtual void EnterCopyCompilerStatementBody(QualifiedTextName qualifiedTextName, TypeCobol.Compiler.Scanner.Token suppress, PairTokenListList replacingOperands) { var copy = (CopyDirective)CompilerDirective; bool isCopy = copy.COPYToken.TokenType == TokenType.COPY; copy.TextName = GetName(qualifiedTextName.TextName); copy.TextNameSymbol = qualifiedTextName.TextName; { #if EUROINFO_RULES if (TypeCobolOptions.UseEuroInformationLegacyReplacingSyntax) { if (copy.TextName != null) { // Find the list of copy text names variations declared by previous REMARKS compiler directives var variations = CopyTextNameVariations; if (TypeCobolOptions.AutoRemarksEnable && (variations == null || !variations.Any( v => string.Equals(v.TextNameWithSuffix, copy.TextName, StringComparison.InvariantCultureIgnoreCase)))) //If it does not exists, create the text variation (AutoRemarks mechanism Issue #440) { variations = new List <RemarksDirective.TextNameVariation> { new RemarksDirective.TextNameVariation(copy.TextName) }; CopyTextNameVariations.AddRange(variations); } if (variations != null) { var declaration = variations.Find(d => String.Equals(d.TextNameWithSuffix, copy.TextName, StringComparison.InvariantCultureIgnoreCase)); if (declaration != null && copy.TextName.StartsWith("Y", StringComparison.InvariantCultureIgnoreCase)) { // Declaration found and copy name starts with Y => apply the legacy REPLACING semantics to the copy directive copy.RemoveFirst01Level = true; if (declaration.HasSuffix) { copy.TextName = declaration.TextName; copy.InsertSuffixChar = true; copy.Suffix = declaration.Suffix; copy.PreSuffix = declaration.PreSuffix; } } } } } #endif } copy.LibraryName = GetName(qualifiedTextName.LibraryName); copy.LibraryNameSymbol = qualifiedTextName.LibraryName; copy.Suppress = suppress != null; // REPLACING if (replacingOperands != null) { // Data used to build the current replace operation Token comparisonToken = null; Token[] followingComparisonTokens = null; Token replacementToken = null; Token[] replacementTokens = null; foreach (Tuple <List <Token>, List <Token> > copyReplacingOperands in replacingOperands) { // Get relevant tokens List <Token> relevantTokens = copyReplacingOperands.Item1; List <Token> replaceTokens = copyReplacingOperands.Item2; BuildReplaceOperation(copy.ReplaceOperations, ref comparisonToken, ref followingComparisonTokens, ref replacementToken, ref replacementTokens, false, relevantTokens); BuildReplaceOperation(copy.ReplaceOperations, ref comparisonToken, ref followingComparisonTokens, ref replacementToken, ref replacementTokens, true, replaceTokens); } } }