Exemplo n.º 1
0
        public void AccessClassFunction()
        {
            ParsedLine line = new ParsedLine("public: unsigned long long int testClass::testFunction() 0xFFFFFFFF");
            ParsedClass theClass = new ParsedClass(line);
            ParsedFunction func = new ParsedFunction(line, theClass);

            bool decorators = func.accessLevel.HasValue &&
                              func.accessLevel.Value == FuncAccessLevel.PUBLIC &&
                              !func.isStatic &&
                              !func.isVirtual &&
                              !func.isConstructor &&
                              !func.isDestructor &&
                              !func.callingConvention.HasValue;

            if (!decorators)
            {
                Assert.Fail("Decorators failed to pass");
            }

            bool returnType = func.returnType.isBaseType &&
                              func.returnType.baseType.Value == BuiltInCppTypes.UNSIGNED_LONG_LONG_INT &&
                              func.returnType.type == "unsigned long long int" &&
                              !func.returnType.isConst &&
                              !func.returnType.isPointer &&
                              !func.returnType.isConstPointer &&
                              !func.returnType.isReference;

            if (!returnType)
            {
                Assert.Fail("Return type failed to pass");
            }

            Assert.IsTrue(func.parameters.Count == 0, "Param count failed to pass");

            bool names = func.parentClass.name == "testClass" &&
                         func.name == "testFunction";

            if (!names)
            {
                Assert.Fail("Names failed to pass");
            }

            bool end = !func.isConst &&
                       func.address == 0xFFFFFFFF;

            if (!end)
            {
                Assert.Fail("End failed to pass");
            }
        }
Exemplo n.º 2
0
        private void insertPlatformData(List<ParsedClass> classes)
        {
            // Some platforms have weird data which we don't know the layout of but need to know the size
            // to properly resolve members.
            // This is hackery to handle it.

            if (CommandLine.args.target == CommandLineArgs.WINDOWS)
            {

            }
            else
            {
                ParsedClass pthread_cond_t = new ParsedClass("pthread_cond_t");
                pthread_cond_t.addData(new List<NamedCppType> { new NamedCppType("char m_placeholder[48];") });
                classes.Add(pthread_cond_t);

                ParsedClass pthread_mutex_t = new ParsedClass("pthread_mutex_t");
                pthread_mutex_t.addData(new List<NamedCppType> { new NamedCppType("char m_placeholder[24];") });
                classes.Add(pthread_mutex_t);
            }
        }
Exemplo n.º 3
0
        private List<ParsedClass> getClasses(List<ParsedLine> parsedLines, List<ParsedTypedef> typedefs)
        {
            var parsedClassDict = new Dictionary<string, ParsedClass>();
            var parsedFunctionDict = new Dictionary<ParsedClass, List<ParsedFunction>>();

            foreach (ParsedLine line in parsedLines)
            {
                if (line.className == null)
                {
                    continue;
                }

                ParsedClass thisClass = null;
                parsedClassDict.TryGetValue(handleTemplatedName(line.className), out thisClass);

                if (thisClass == null)
                {
                    thisClass = new ParsedClass(line);
                    parsedClassDict[thisClass.name] = thisClass;
                    parsedFunctionDict[thisClass] = new List<ParsedFunction>();
                }

                parsedFunctionDict[thisClass].Add(new ParsedFunction(line, thisClass, typedefs));
            }

            List<ParsedClass> parsedClasses = parsedClassDict.Values.OrderBy(theClass => theClass.name).ToList();

            foreach (KeyValuePair<ParsedClass, List<ParsedFunction>> pair in parsedFunctionDict)
            {
                pair.Key.addFunctions(pair.Value);
            }

            return parsedClasses;
        }
Exemplo n.º 4
0
        private void addStructsToClasses(List<ParsedStruct> structs, List<ParsedClass> classes)
        {
            List<ParsedClass> classesToAdd = new List<ParsedClass>();

            foreach (ParsedStruct theStruct in structs)
            {
                ParsedClass matchingClass = null;

                foreach (ParsedClass theClass in classes)
                {
                    if (theClass.name == theStruct.name)
                    {
                        matchingClass = theClass;
                        break;
                    }
                }

                List<NamedCppType> data = theStruct.members.Select(member => member.data).ToList();

                if (matchingClass == null)
                {
                    ParsedClass newParsedClass = new ParsedClass(theStruct.name);
                    newParsedClass.addData(data);
                    newParsedClass.addAttributes(theStruct.attributes);
                    classesToAdd.Add(newParsedClass);
                }
                else
                {
                    matchingClass.addData(data);
                    matchingClass.addAttributes(theStruct.attributes);
                }
            }

            classes.AddRange(classesToAdd);
            classes = classes.OrderBy(theClass => theClass.name).ToList();

            foreach (ParsedStruct theStruct in structs)
            {
                ParsedClass matchingClass = null;

                foreach (ParsedClass theClass in classes)
                {
                    if (theClass.name == theStruct.name)
                    {
                        matchingClass = theClass;
                        break;
                    }
                }

                Debug.Assert(matchingClass != null);

                foreach (string inh in theStruct.inheritsFrom)
                {
                    ParsedClass inheritsFromClass = null;

                    foreach (ParsedClass theClass in classes)
                    {
                        if (theClass.name == inh)
                        {
                            inheritsFromClass = theClass;
                            break;
                        }
                    }

                    Debug.Assert(inheritsFromClass != null);

                    if (matchingClass != null)
                    {
                        matchingClass.inherits.Add(inheritsFromClass);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private static void buildClassSource(List<string> body, ParsedClass theClass)
        {
            body.Add("#include \"" + theClass.name + ".hpp\"");
            body.Add("#include \"Functions.hpp\"");
            body.Add("");

            if (theClass.sourceDependencies.Count > 0)
            {
                body.AddRange(theClass.sourceDependencies.Select(dependency => String.Format("#include \"{0}.hpp\"", dependency.name)));
                body.Add("");
            }

            body.Add("namespace " + CommandLine.args.libNamespace + " {");
            body.Add("");
            body.Add("namespace " + CommandLine.args.classNamespace + " {");
            body.Add("");
            body.AddRange(theClass.asClassSource());
            body.Add("}");
            body.Add("");
            body.Add("}");
        }
Exemplo n.º 6
0
        private static void buildClassHeader(List<string> header, ParsedClass theClass)
        {
            header.Add("#pragma once");
            header.Add("");
            header.Add("#include <cstdint>");
            header.Add("");
            header.AddRange(theClass.headerDependencies.Select(dependency => String.Format("#include \"{0}.hpp\"", dependency.name)));
            header.AddRange(theClass.unknownDependencies.Select(dependency => String.Format("#include \"unknown_{0}.hpp\"", dependency.type)));

            if (theClass.headerDependencies.Count > 0 || theClass.unknownDependencies.Count > 0)
            {
                header.Add("");
            }

            header.Add("namespace " + CommandLine.args.libNamespace + " {");
            header.Add("");
            header.Add("namespace " + CommandLine.args.classNamespace + " {");
            header.Add("");

            if (theClass.sourceDependencies.Count > 0)
            {
                header.Add("// Forward class declarations (defined in the source file)");
                header.AddRange(theClass.sourceDependencies.Select(dependency => String.Format("class {0};", dependency.name)));
                header.Add("");
            }

            header.AddRange(theClass.asClassHeader());
            header.Add("}");
            header.Add("");
            header.Add("}");
        }
        public ParsedFunction(ParsedLine line, ParsedClass theClass, List<ParsedTypedef> typedefs)
        {
            name = SymbolParser.handleTemplatedName(line.functionName);

            if (theClass != null)
            {
                parentClass = theClass;
                accessLevel = stringToAccessLevel(line.accessLevel);

                int templateIndex = theClass.name.IndexOf("Templated", StringComparison.Ordinal);

                if (templateIndex != -1)
                {
                    // This is a template. Let's check for template ctor/dtor names.
                    string className = parentClass.name.Substring(0, templateIndex);

                    if (name == className)
                    {
                        name = theClass.name;
                        isConstructor = true;
                    }
                    else if (name == "~" + className)
                    {
                        name = theClass.name;
                        isDestructor = true;
                    }
                }

                if (name == parentClass.name)
                {
                    isConstructor = true;
                }
                else if (name == "~" + parentClass.name)
                {
                    isDestructor = true;
                }

                isVirtual = line.isVirtual;
                isConst = line.isConst;
            }

            isStatic = line.isStatic;

            friendlyName = makeFriendlyName();

            if (line.returnType != null)
            {
                returnType = new CppType(SymbolParser.handleTemplatedName(line.returnType), typedefs);
            }

            parameters = new List<CppType>();

            foreach (string parameter in line.parameters.Split(','))
            {
                CppType param = new CppType(SymbolParser.handleTemplatedName(parameter), typedefs);

                if (!param.isBaseType || param.isPointer || (param.baseType.HasValue && param.baseType.Value != BuiltInCppTypes.VOID))
                {
                    parameters.Add(param);
                }
            }

            callingConvention = stringToCallingConv(line.callingConvention);
            address = Convert.ToUInt32(line.address, 16);
        }
Exemplo n.º 8
0
 public void Types()
 {
     ParsedLine line = new ParsedLine("CExoLinkedList<unsigned long>::AddTail(unsigned long *) 0x80B1670");
     ParsedClass theClass = new ParsedClass(line);
     ParsedFunction func = new ParsedFunction(line, theClass);
 }
Exemplo n.º 9
0
 public void templateReturnType()
 {
     ParsedLine line = new ParsedLine("template<templateInner> testFunc()");
     ParsedClass theClass = new ParsedClass(line);
     ParsedFunction func = new ParsedFunction(line, theClass);
     Assert.IsTrue(func.returnType.type == SymbolParser.SymbolParser.handleTemplatedName("template<templateInner>"), "Return type was invalid.");
 }
Exemplo n.º 10
0
 public void templateParamType()
 {
     ParsedLine line = new ParsedLine("testFunc(template<templateInner>)");
     ParsedClass theClass = new ParsedClass(line);
     ParsedFunction func = new ParsedFunction(line, theClass);
     Assert.IsTrue(func.parameters[0].type == SymbolParser.SymbolParser.handleTemplatedName("template<templateInner>"), "Params type was invalid.");
 }
Exemplo n.º 11
0
 public void templateNestedBadThings()
 {
     ParsedLine line = new ParsedLine("template<template<template<unsigned long long int>>> template<template<template<unsigned long long int>>>::testFunc(template<template<template<unsigned long long int>>>, template<template<template<unsigned long long int>>>***, template<template<template<unsigned long long int>>>&)");
     ParsedClass theClass = new ParsedClass(line);
     ParsedFunction func = new ParsedFunction(line, theClass);
 }
Exemplo n.º 12
0
 public void templatedClassNameSpace()
 {
     ParsedLine line = new ParsedLine("template<unsigned long long int>::testFunc()");
     ParsedClass theClass = new ParsedClass(line);
     ParsedFunction func = new ParsedFunction(line, theClass);
     Assert.IsTrue(func.parentClass.name == SymbolParser.SymbolParser.handleTemplatedName("template<unsignedlonglongint>"), "Return type was invalid.");
 }
Exemplo n.º 13
0
 public void templateClassType()
 {
     ParsedLine line = new ParsedLine("template<templateInner>::testFunc()");
     ParsedClass theClass = new ParsedClass(line);
     ParsedFunction func = new ParsedFunction(line, theClass);
     Assert.IsTrue(func.parentClass.name == SymbolParser.SymbolParser.handleTemplatedName("template<templateInner>"), "Class name was invalid.");
 }
Exemplo n.º 14
0
        public void NoReturnTypeFreeStandingFunction()
        {
            ParsedLine line = new ParsedLine("testFunction() 0xFFFFFFFF");
            ParsedClass theClass = new ParsedClass(line);
            ParsedFunction func = new ParsedFunction(line, theClass);

            bool decorators = !func.accessLevel.HasValue &&
                              !func.isStatic &&
                              !func.isVirtual &&
                              !func.isConstructor &&
                              !func.isDestructor &&
                              !func.callingConvention.HasValue;

            if (!decorators)
            {
                Assert.Fail("Decorators failed to pass");
            }

            Assert.IsTrue(func.returnType == null, "Return type failed to pass.");
            Assert.IsTrue(func.parameters.Count == 0, "Param count failed to pass");

            bool names = func.parentClass.name == ParsedClass.FREE_STANDING_CLASS_NAME &&
                         func.name == "testFunction";

            if (!names)
            {
                Assert.Fail("Names failed to pass");
            }

            bool end = !func.isConst &&
                       func.address == 0xFFFFFFFF;

            if (!end)
            {
                Assert.Fail("End failed to pass");
            }
        }
Exemplo n.º 15
0
        public void FreeStandingFunctionParams()
        {
            ParsedLine line = new ParsedLine("unsigned long long int testFunction(unsigned char*** const, const bool, UserType&) 0xFFFFFFFF");
            ParsedClass theClass = new ParsedClass(line);
            ParsedFunction func = new ParsedFunction(line, theClass);

            bool decorators = !func.accessLevel.HasValue &&
                              !func.isStatic &&
                              !func.isVirtual &&
                              !func.isConstructor &&
                              !func.isDestructor &&
                              !func.callingConvention.HasValue;

            if (!decorators)
            {
                Assert.Fail("Decorators failed to pass");
            }

            bool returnType = func.returnType.isBaseType &&
                              func.returnType.baseType.Value == BuiltInCppTypes.UNSIGNED_LONG_LONG_INT &&
                              func.returnType.type == "unsigned long long int" &&
                              !func.returnType.isConst &&
                              !func.returnType.isPointer &&
                              !func.returnType.isConstPointer &&
                              !func.returnType.isReference;

            if (!returnType)
            {
                Assert.Fail("Return type failed to pass");
            }

            bool names = func.parentClass.name == ParsedClass.FREE_STANDING_CLASS_NAME &&
                         func.name == "testFunction";

            if (!names)
            {
                Assert.Fail("Names failed to pass");
            }

            Assert.IsTrue(func.parameters.Count == 3, "Param count failed to pass");

            bool param1 = func.parameters[0].isBaseType &&
                          func.parameters[0].baseType.Value == BuiltInCppTypes.UNSIGNED_CHAR &&
                          func.parameters[0].type == "unsigned char" &&
                          !func.parameters[0].isConst &&
                          func.parameters[0].isPointer &&
                          func.parameters[0].pointerDepth == 3 &&
                          func.parameters[0].isConstPointer &&
                          !func.parameters[0].isReference;

            if (!param1)
            {
                Assert.Fail("Param1 failed to pass");
            }

            bool param2 = func.parameters[1].isBaseType &&
                          func.parameters[1].baseType.Value == BuiltInCppTypes.BOOL &&
                          func.parameters[1].type == "bool" &&
                          func.parameters[1].isConst &&
                          !func.parameters[1].isPointer &&
                          !func.parameters[1].isConstPointer &&
                          !func.parameters[1].isReference;

            if (!param2)
            {
                Assert.Fail("Param2 failed to pass");
            }

            bool param3 = !func.parameters[2].isBaseType &&
                          func.parameters[2].type == "UserType" &&
                          !func.parameters[2].isConst &&
                          !func.parameters[2].isPointer &&
                          !func.parameters[2].isConstPointer &&
                          func.parameters[2].isReference;

            if (!param3)
            {
                Assert.Fail("Param3 failed to pass");
            }

            bool end = !func.isConst &&
                       func.address == 0xFFFFFFFF;

            if (!end)
            {
                Assert.Fail("End failed to pass");
            }
        }