Exemplo n.º 1
0
        private static void CheckParseOfEventFile(SrcMLCppParser parser, string sourceFile, List <ProgramElement> elements)
        {
            bool seenGetTimeMethod = false;
            int  numMethods        = 0;

            foreach (ProgramElement pe in elements)
            {
                if (pe is CppUnresolvedMethodElement)
                {
                    numMethods++;

                    //Resolve
                    bool          isResolved = false;
                    MethodElement method     = null;
                    CppUnresolvedMethodElement unresolvedMethod = (CppUnresolvedMethodElement)pe;
                    foreach (String headerFile in unresolvedMethod.IncludeFileNames)
                    {
                        //it's reasonable to assume that the header file path is relative from the cpp file,
                        //as other included files are unlikely to be part of the same project and therefore
                        //should not need to be parsed
                        string headerPath = System.IO.Path.GetDirectoryName(sourceFile) + "\\" + headerFile;
                        if (!System.IO.File.Exists(headerPath))
                        {
                            continue;
                        }

                        isResolved = unresolvedMethod.TryResolve(unresolvedMethod, parser.Parse(headerPath), out method);
                        if (isResolved == true)
                        {
                            break;
                        }
                    }
                    Assert.IsTrue(isResolved);
                    Assert.IsNotNull(method);

                    //pick one of the resolved methods to see if it seems complete
                    if (method.Name == "getTime")
                    {
                        seenGetTimeMethod = true;
                        Assert.AreEqual(method.DefinitionLineNumber, 13);
                        Assert.AreEqual(method.ReturnType, "double");
                        Assert.AreEqual(method.AccessLevel, AccessLevel.Public);
                        Assert.AreEqual(method.Arguments, String.Empty);
                        Assert.AreEqual(method.Body, "{ \n  return _time; \n}");
                        Assert.AreNotEqual(method.ClassId, System.Guid.Empty);
                    }
                }
            }
            Assert.AreEqual(numMethods, 6);
            Assert.IsTrue(seenGetTimeMethod);
        }
Exemplo n.º 2
0
        public static SandoDocument GetDocumentForUnresolvedCppMethod(CppUnresolvedMethodElement unresolvedMethod, List <ProgramElement> headerElements)
        {
            bool          isResolved    = false;
            MethodElement methodElement = null;

            isResolved = unresolvedMethod.TryResolve(unresolvedMethod, headerElements, out methodElement);
            if (isResolved == true)
            {
                return(DocumentFactory.Create(methodElement));
            }
            else
            {
                Debug.WriteLine("????? " + unresolvedMethod.Name + " is not resolved, this is bad!!");
                methodElement = unresolvedMethod.Copy();
                return(DocumentFactory.Create(methodElement));
            }
        }
        public static SandoDocument GetDocumentForUnresolvedCppMethod(CppUnresolvedMethodElement unresolvedMethod, List<ProgramElement> headerElements)
        {
            bool isResolved = false;
            MethodElement methodElement = null;

            isResolved = unresolvedMethod.TryResolve(unresolvedMethod, headerElements, out methodElement);
            if(isResolved == true)
            {
                return DocumentFactory.Create(methodElement);
            }
            else
            {
                Debug.WriteLine("????? " + unresolvedMethod.Name + " is not resolved, this is bad!!");
                methodElement = unresolvedMethod.Copy();
                return DocumentFactory.Create(methodElement);
            }
        }
Exemplo n.º 4
0
        public static List <ProgramElement> GenerateCppHeaderElements(string filePath, List <ProgramElement> unresolvedElements)
        {
            List <ProgramElement> headerElements = new List <ProgramElement>();

            //first parse all the included header files. they are the same in all the unresolved elements
            CppUnresolvedMethodElement firstUnresolved = (CppUnresolvedMethodElement)unresolvedElements[0];

            foreach (String headerFile in firstUnresolved.IncludeFileNames)
            {
                //it's reasonable to assume that the header file path is relative from the cpp file,
                //as other included files are unlikely to be part of the same project and therefore
                //should not need to be parsed
                string headerPath = System.IO.Path.GetDirectoryName(filePath) + "\\" + headerFile;
                if (!System.IO.File.Exists(headerPath))
                {
                    Debug.WriteLine("????? header file -" + headerFile + "- was not found.. this can lead to issues");
                    continue;
                }
                Debug.WriteLine("*** parsing header = " + headerPath);
                var headerInfo = new FileInfo(headerPath);
                headerElements.AddRange(ExtensionPointsRepository.Instance.GetParserImplementation(headerInfo.Extension).Parse(headerPath));
            }
            return(headerElements);
        }