/// <summary>Notifies listeners about the creation of a new CodeElement.</summary>
 public void OnNode(Node node, TCtx context, CodeModel.Program program)
 {
     foreach (var listener in _listeners)
     {
         listener.OnNode(node, context, program);
     }
 }
示例#2
0
        public void OnNode([NotNull] Node node, ParserRuleContext context, CodeModel.Program program)
        {
            var header = node.CodeElement as FunctionDeclarationHeader;

            if (header == null)
            {
                return;                 //not my job
            }
            var filesection = node.Get <FileSection>("file");

            if (filesection != null)     // TCRFUN_DECLARATION_NO_FILE_SECTION
            {
                DiagnosticUtils.AddError(filesection.CodeElement, "Illegal FILE SECTION in function \"" + header.Name + "\" declaration", context);
            }

            CheckNoGlobalOrExternal(node.Get <DataDivision>("data-division"));

            CheckParameters(header.Profile, header, context, node);
            CheckNoLinkageItemIsAParameter(node.Get <LinkageSection>("linkage"), header.Profile);

            CheckNoPerform(node.SymbolTable.EnclosingScope, node);

            var headerNameURI = new URI(header.Name);
            var functions     = node.SymbolTable.GetFunction(headerNameURI, header.Profile);

            if (functions.Count > 1)
            {
                DiagnosticUtils.AddError(header, "A function \"" + headerNameURI.Head + "\" with the same profile already exists in namespace \"" + headerNameURI.Tail + "\".", context);
            }
//		foreach(var function in functions) {
//			if (!function.IsProcedure && !function.IsFunction)
//				DiagnosticUtils.AddError(header, "\""+header.Name.Head+"\" is neither procedure nor function.", context);
//		}
        }
示例#3
0
        public void OnNode([NotNull] Node node, ParserRuleContext context, [NotNull] CodeModel.Program program)
        {
            VariableWriter variableWriter = node as VariableWriter;

            if (variableWriter == null)
            {
                return; //not our job
            }
            var element = node.CodeElement as VariableWriter;
            var table   = program.SymbolTable;

            foreach (var pair in element.VariablesWritten)
            {
                if (pair.Key == null)
                {
                    continue;                           // no receiving item
                }
                var lr = table.GetVariable(pair.Key);
                if (lr.Count != 1)
                {
                    continue;                        // ambiguity or not referenced; not my job
                }
                var receiving = lr[0];
                checkReadOnly(node.CodeElement, receiving);
            }
        }
示例#4
0
        public void OnNode(Node node, ParserRuleContext context, CodeModel.Program program)
        {
            var redefinesNode = node as DataRedefines;

            if (redefinesNode == null)
            {
                return; //not my job
            }
            if (redefinesNode.IsPartOfATypeDef)
            {
                DiagnosticUtils.AddError(node.CodeElement, "Illegal REDEFINES as part of a TYPEDEF", MessageCode.SemanticTCErrorInParser);
                return;
            }
            var redefinesSymbolReference = redefinesNode.CodeElement().RedefinesDataName;
            var redefinedVariable        = node.SymbolTable.GetRedefinedVariable(redefinesNode, redefinesSymbolReference);

            if (redefinedVariable == null)
            {
                string message = "Illegal REDEFINES: Symbol \'" + redefinesSymbolReference + "\' is not referenced";
                DiagnosticUtils.AddError(node.CodeElement, message, MessageCode.SemanticTCErrorInParser);
                return;
            }

            if (redefinedVariable.IsStronglyTyped || redefinedVariable.IsStrictlyTyped)
            {
                string message = string.Format("Illegal REDEFINES: '{0}' is {1}", redefinesSymbolReference, redefinedVariable.IsStronglyTyped ? "strongly-typed" : "strictly-typed");
                DiagnosticUtils.AddError(node.CodeElement, message, MessageCode.SemanticTCErrorInParser);
            }
        }
        public void OnNode([NotNull] Node node, ParserRuleContext context, CodeModel.Program program)
        {
            var functionDeclaration = node as FunctionDeclaration;

            if (functionDeclaration == null)
            {
                return;                              //not my job
            }
            var header = node.CodeElement as FunctionDeclarationHeader;

            if (header == null)
            {
                return;                 //not my job
            }
            var filesection = node.Get <FileSection>("file");

            if (filesection != null)     // TCRFUN_DECLARATION_NO_FILE_SECTION
            {
                DiagnosticUtils.AddError(filesection,
                                         "Illegal FILE SECTION in function \"" + header.Name + "\" declaration",
                                         context);
            }

            CheckNoGlobalOrExternal(node.Get <DataDivision>("data-division"));
            CheckNoLinkageItemIsAParameter(node.Get <LinkageSection>("linkage"), header.Profile);
        }
示例#6
0
        public void OnNode(Node node, ParserRuleContext context, CodeModel.Program program)
        {
            var renames = node as DataRenames;

            if (renames == null)
            {
                return; //not my job
            }
            Check(renames.CodeElement().RenamesFromDataName, renames);
            Check(renames.CodeElement().RenamesToDataName, renames);
        }
        public void OnNode(Node node, ParserRuleContext context, CodeModel.Program program)
        {
            var redefinesNode = node as DataRedefines;

            if (redefinesNode == null)
            {
                return; //not my job
            }
            if (redefinesNode.IsPartOfATypeDef)
            {
                DiagnosticUtils.AddError(node, "Illegal REDEFINES as part of a TYPEDEF",
                                         MessageCode.SemanticTCErrorInParser);
            }
        }
示例#8
0
        public void OnNode([NotNull] Node node, ParserRuleContext context, CodeModel.Program program)
        {
            ProcedureDivision procedureDivision = node as ProcedureDivision;

            if (procedureDivision == null)
            {
                return; //not our job
            }
            var  pdiv            = procedureDivision.CodeElement as ProcedureDivisionHeader;
            bool isPublicLibrary = false;
            var  elementsInError = new List <CodeElement>();
            var  errorMessages   = new List <string>();

            foreach (var child in procedureDivision.Children)
            {
                if (child.CodeElement == null)
                {
                    elementsInError.Add(procedureDivision.CodeElement);
                    errorMessages.Add("Illegal default section in library. " + child);
                }
                else
                {
                    var function = child.CodeElement as FunctionDeclarationHeader;
                    if (function != null)
                    {
                        isPublicLibrary = isPublicLibrary || function.Visibility == AccessModifier.Public;
                    }
                    else
                    {
                        elementsInError.Add(child.CodeElement);
                        errorMessages.Add("Illegal non-function item in library");
                    }
                }
            }
            if (isPublicLibrary)
            {
//			if (copy == null || copy.CodeElement().Name == null) // TCRFUN_LIBRARY_COPY
//				DiagnosticUtils.AddError(pgm.CodeElement, "Missing library copy in IDENTIFICATION DIVISION.", context);

                if (pdiv.UsingParameters != null && pdiv.UsingParameters.Count > 0)
                {
                    DiagnosticUtils.AddError(pdiv, "Illegal " + pdiv.UsingParameters.Count + " USING in library PROCEDURE DIVISION.", context);
                }

                for (int c = 0; c < errorMessages.Count; c++)
                {
                    DiagnosticUtils.AddError(elementsInError[c], errorMessages[c], context);
                }
            }
        }
示例#9
0
        public void OnNode(Node node, ParserRuleContext context, CodeModel.Program program)
        {
            var variableWriter = node as VariableWriter;

            if (variableWriter == null)
            {
                return; //not our job
            }
            var variables = variableWriter.VariablesWritten;

            foreach (var variable in variables)
            {
                CheckVariable(node, variable.Key, variable.Value);
            }
        }
 public override void EnterCobolProgram(ProgramClassParser.CobolProgramContext context)
 {
     if (Program == null) {
         Program = new SourceProgram(TableOfGlobals);
         programsStack = new Stack<CodeModel.Program>();
         CurrentProgram = Program;
     } else {
         var enclosing = CurrentProgram;
         CurrentProgram = new NestedProgram(enclosing);
         Enter(CurrentProgram.SyntaxTree.Root, context, new SymbolTable(TableOfGlobals));
     }
     var terminal = context.ProgramIdentification();
     CurrentProgram.Identification = terminal != null? (ProgramIdentification)terminal.Symbol : null;
     Enter(new Nodes.Program(CurrentProgram.Identification), context, CurrentProgram.SymbolTable);
 }
示例#11
0
 public override void EnterCobolProgram(ProgramClassParser.CobolProgramContext context)
 {
     if (Program == null) {
         Program = new SourceProgram(TableOfGlobals);
         programsStack = new Stack<CodeModel.Program>();
         CurrentProgram = Program;
     } else {
         var enclosing = CurrentProgram;
         CurrentProgram = new NestedProgram(enclosing);
         Enter(CurrentProgram.SyntaxTree.Root, context, new SymbolTable(TableOfGlobals));
     }
     var pgm = context.programAttributes();
     if (pgm != null) CurrentProgram.Identification = (ProgramIdentification)pgm.ProgramIdentification().Symbol;
     Enter(new Nodes.Program(CurrentProgram.Identification), pgm, CurrentProgram.SymbolTable);
     if (pgm != null && pgm.LibraryCopy() != null) { // TCRFUN_LIBRARY_COPY
         var cnode = new Nodes.LibraryCopy((LibraryCopyCodeElement)pgm.LibraryCopy().Symbol);
         Enter(cnode, pgm, CurrentProgram.SymbolTable);
         Exit();
     }
 }