Esempio n. 1
0
        /// <summary>
        /// Construct the method summarizer
        /// </summary>
        /// <param name="md"></param>
        public SwumSummary(MethodDefinition md)
        {
            this.Method = md;
            var classBelong = md.GetAncestors<TypeDefinition>().FirstOrDefault();

            //class name
            if (classBelong != null) {
                ClassName = classBelong.Name;
            }
            else {
                ClassName = "";
            }

            //return type
            string returnType = "void";
            if (md.ReturnType != null) {
                returnType = md.ReturnType.ToString();
            }

            //Check if md returns primitive
            bool IsPrimitive = IsPrimitiveType(md.ReturnType);

            HashSet<FormalParameterRecord> paras = new HashSet<FormalParameterRecord>();
            foreach (var para in md.Parameters) {
                var vType = para.VariableType;
                var tempPara = new FormalParameterRecord(vType.ToString(), BuiltInTypeFactory.IsBuiltIn(vType), para.Name);
                paras.Add(tempPara);
            }
            MethodContext mc = new MethodContext(returnType, IsPrimitive, ClassName, paras, false, md.IsConstructor, md.IsDestructor);
            this._mDeclarationNode = new MethodDeclarationNode(md.Name, mc);
            this._builder = new UnigramSwumBuilder();
            this.IsSummarized = false;
        }
Esempio n. 2
0
        public void TestToPlainString_NotParsed()
        {
            var                   formals = new FormalParameterRecord[] { new FormalParameterRecord("SGVData*", false, "p"), new FormalParameterRecord("ASSchedule*", false, "p2") };
            MethodContext         mc      = new MethodContext("int", true, "MyClass", formals, true, false, false);
            MethodDeclarationNode mdn     = new MethodDeclarationNode("CalcNewValue", mc);

            Assert.AreEqual("CalcNewValue", mdn.ToPlainString());
        }
Esempio n. 3
0
        public void TestBuildMethodContext_InlineFunction()
        {
            string   testSrcML = "<class>class <name>CBidMarkup</name><block>{<private type=\"default\"> <function><type><name>int</name></type> <name>run</name><parameter_list>(<param><decl><type><name>CGVDate</name> <type:modifier>&amp;</type:modifier></type> <name>CurrDate</name></decl></param>)</parameter_list> <block>{ <return>return <expr><op:operator>-</op:operator><lit:literal type=\"number\">1</lit:literal></expr>;</return>}</block></function> </private>}</block>;</class>";
            XElement xml       = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace);
            var      formals   = new FormalParameterRecord[] { new FormalParameterRecord("CGVDate&", false, "CurrDate") };

            MethodContext mc1 = new MethodContext("int", true, "CBidMarkup", formals, false, false, false);
            MethodContext mc2 = ContextBuilder.BuildMethodContext(xml.Descendants(SRC.Function).First());

            Assert.IsTrue(MethodContextsAreEqual(mc1, mc2));
        }
Esempio n. 4
0
        public void TestBuildMethodContext_Constructor()
        {
            string   testSrcML = "<constructor><name><name>CBidMarkup</name><op:operator>::</op:operator><name>CBidMarkup</name></name><parameter_list>(<param><decl><type><name>SGVData</name> <type:modifier>*</type:modifier></type> <name>p</name></decl></param>, <param><decl><type><name>ASSchedule</name> <type:modifier>*</type:modifier></type> <name>p2</name></decl></param>)</parameter_list> <block>{ }</block></constructor>";
            XElement xml       = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace);
            var      formals   = new FormalParameterRecord[] { new FormalParameterRecord("SGVData*", false, "p"), new FormalParameterRecord("ASSchedule*", false, "p2") };

            MethodContext mc1 = new MethodContext("", false, "CBidMarkup", formals, false, true, false);
            MethodContext mc2 = ContextBuilder.BuildMethodContext(xml.Element(SRC.Constructor));

            Assert.IsTrue(MethodContextsAreEqual(mc1, mc2));
        }
Esempio n. 5
0
        public void TestBuildMethodContext_StaticFunctionWithClassAndParams()
        {
            string   testSrcML = "<function><type><name>static</name> <name>char</name></type> <name><name>CBidMarkup</name><op:operator>::</op:operator><name>run</name></name><parameter_list>(<param><decl><type><name>CGVDate</name> <type:modifier>&amp;</type:modifier></type> <name>CurrDate</name></decl></param>)</parameter_list> <block>{ <return>return <expr><lit:literal type=\"char\">'a'</lit:literal></expr>;</return> }</block></function>";
            XElement xml       = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace);
            var      formals   = new FormalParameterRecord[] { new FormalParameterRecord("CGVDate&", false, "CurrDate") };

            MethodContext mc1 = new MethodContext("char", true, "CBidMarkup", formals, true, false, false);
            MethodContext mc2 = ContextBuilder.BuildMethodContext(xml.Element(SRC.Function));

            Assert.IsTrue(MethodContextsAreEqual(mc1, mc2));
        }
Esempio n. 6
0
        public void TestBuildMethodContext_FunctionWithClassAndParams()
        {
            string   testSrcML = "<function><type><name>int</name></type> <name><name>CBidMarkup</name><op:operator>::</op:operator><name>modifyBid</name></name><parameter_list>(<param><decl><type><name>bool</name></type> <name>Recalc</name></decl></param>, <param><decl><type><name>char</name><type:modifier>*</type:modifier></type> <name>Foo</name></decl></param>)</parameter_list><block>{ <return>return <expr><lit:literal type=\"number\">0</lit:literal></expr>;</return> }</block></function>";
            XElement xml       = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace);
            var      formals   = new FormalParameterRecord[] { new FormalParameterRecord("bool", true, "Recalc"), new FormalParameterRecord("char*", true, "Foo") };

            MethodContext mc1 = new MethodContext("int", true, "CBidMarkup", formals, false, false, false);
            MethodContext mc2 = ContextBuilder.BuildMethodContext(xml.Element(SRC.Function));

            Assert.IsTrue(MethodContextsAreEqual(mc1, mc2));
        }
Esempio n. 7
0
        public void TestToPlainString_Context()
        {
            var                   formals  = new FormalParameterRecord[] { new FormalParameterRecord("SGVData*", false, "p"), new FormalParameterRecord("ASSchedule*", false, "p2") };
            MethodContext         mc       = new MethodContext("int", true, "MyClass", formals, true, false, false);
            MethodDeclarationNode mdn      = new MethodDeclarationNode("CalcNewValue", mc);
            var                   splitter = new ConservativeIdSplitter();

            mdn.Parse(splitter);
            mdn.AssignStructuralInformation(splitter, new UnigramTagger());
            Assert.AreEqual("Calc New Value", mdn.ToPlainString());
        }
Esempio n. 8
0
        public void TestAssignStructuralInformation()
        {
            var                   formals = new FormalParameterRecord[] { new FormalParameterRecord("SGVData*", false, "p"), new FormalParameterRecord("ASSchedule*", false, "p2") };
            MethodContext         mc      = new MethodContext("int", true, "MyClass", formals, true, false, false);
            MethodDeclarationNode mdn     = new MethodDeclarationNode("MyMethod", mc);

            mdn.Parse(new NullSplitter());
            mdn.AssignStructuralInformation(new NullSplitter(), new NullTagger());
            Assert.AreEqual(Location.Name, mdn.ParsedName.Location);
            Assert.AreEqual("int", mdn.ReturnType.Name);
            Assert.IsTrue(mdn.ReturnType.IsPrimitive);
            Assert.AreEqual("MyClass", mdn.DeclaringClass.Name);
            Assert.AreEqual(2, mdn.FormalParameters.Count);
            Assert.AreEqual("SGVData*", mdn.FormalParameters[0].Type.Name);
            Assert.AreEqual("p", mdn.FormalParameters[0].Name);
            Assert.AreEqual("ASSchedule*", mdn.FormalParameters[1].Type.Name);
            Assert.AreEqual("p2", mdn.FormalParameters[1].Name);
        }
Esempio n. 9
0
        /// <summary>
        /// Construct the method summarizer
        /// </summary>
        /// <param name="md"></param>
        public SwumSummary(MethodDefinition md)
        {
            this.Method = md;
            var classBelong = md.GetAncestors <TypeDefinition>().FirstOrDefault();

            //class name
            if (classBelong != null)
            {
                ClassName = classBelong.Name;
            }
            else
            {
                ClassName = "";
            }

            //return type
            string returnType = "void";

            if (md.ReturnType != null)
            {
                returnType = md.ReturnType.ToString();
            }

            //Check if md returns primitive
            bool IsPrimitive = IsPrimitiveType(md.ReturnType);


            HashSet <FormalParameterRecord> paras = new HashSet <FormalParameterRecord>();

            foreach (var para in md.Parameters)
            {
                var vType    = para.VariableType;
                var tempPara = new FormalParameterRecord(vType.ToString(), BuiltInTypeFactory.IsBuiltIn(vType), para.Name);
                paras.Add(tempPara);
            }
            MethodContext mc = new MethodContext(returnType, IsPrimitive, ClassName, paras, false, md.IsConstructor, md.IsDestructor);

            this._mDeclarationNode = new MethodDeclarationNode(md.Name, mc);
            this._builder          = new UnigramSwumBuilder();
            this.IsSummarized      = false;
        }
 public void TestToPlainString_NotParsed() {
     var formals = new FormalParameterRecord[] { new FormalParameterRecord("SGVData*", false, "p"), new FormalParameterRecord("ASSchedule*", false, "p2") };
     MethodContext mc = new MethodContext("int", true, "MyClass", formals, true, false, false);
     MethodDeclarationNode mdn = new MethodDeclarationNode("CalcNewValue", mc);
     Assert.AreEqual("CalcNewValue", mdn.ToPlainString());
 }
 public void TestToPlainString_Context() {
     var formals = new FormalParameterRecord[] { new FormalParameterRecord("SGVData*", false, "p"), new FormalParameterRecord("ASSchedule*", false, "p2") };
     MethodContext mc = new MethodContext("int", true, "MyClass", formals, true, false, false);
     MethodDeclarationNode mdn = new MethodDeclarationNode("CalcNewValue", mc);
     var splitter = new ConservativeIdSplitter();
     mdn.Parse(splitter);
     mdn.AssignStructuralInformation(splitter, new UnigramTagger());
     Assert.AreEqual("Calc New Value", mdn.ToPlainString());
 }
 public void TestAssignStructuralInformation() {
     var formals = new FormalParameterRecord[] { new FormalParameterRecord("SGVData*", false, "p"), new FormalParameterRecord("ASSchedule*", false, "p2") };
     MethodContext mc = new MethodContext("int", true, "MyClass", formals, true, false, false);
     MethodDeclarationNode mdn = new MethodDeclarationNode("MyMethod", mc);
     mdn.Parse(new NullSplitter());
     mdn.AssignStructuralInformation(new NullSplitter(), new NullTagger());
     Assert.AreEqual(Location.Name, mdn.ParsedName.Location);
     Assert.AreEqual("int", mdn.ReturnType.Name);
     Assert.IsTrue(mdn.ReturnType.IsPrimitive);
     Assert.AreEqual("MyClass", mdn.DeclaringClass.Name);
     Assert.AreEqual(2, mdn.FormalParameters.Count);
     Assert.AreEqual("SGVData*", mdn.FormalParameters[0].Type.Name);
     Assert.AreEqual("p", mdn.FormalParameters[0].Name);
     Assert.AreEqual("ASSchedule*", mdn.FormalParameters[1].Type.Name);
     Assert.AreEqual("p2", mdn.FormalParameters[1].Name);
 }
Esempio n. 13
0
        public void TestBuildMethodContext_InlineFunction() {
            string testSrcML = "<class>class <name>CBidMarkup</name><block>{<private type=\"default\"> <function><type><name>int</name></type> <name>run</name><parameter_list>(<param><decl><type><name>CGVDate</name> <type:modifier>&amp;</type:modifier></type> <name>CurrDate</name></decl></param>)</parameter_list> <block>{ <return>return <expr><op:operator>-</op:operator><lit:literal type=\"number\">1</lit:literal></expr>;</return>}</block></function> </private>}</block>;</class>";
            XElement xml = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace);
            var formals = new FormalParameterRecord[] {new FormalParameterRecord("CGVDate&", false, "CurrDate")};

            MethodContext mc1 = new MethodContext("int", true, "CBidMarkup", formals, false, false, false);
            MethodContext mc2 = ContextBuilder.BuildMethodContext(xml.Descendants(SRC.Function).First());
            Assert.IsTrue(MethodContextsAreEqual(mc1, mc2));
        }
Esempio n. 14
0
        public void TestBuildMethodContext_Constructor() {
            string testSrcML = "<constructor><name><name>CBidMarkup</name><op:operator>::</op:operator><name>CBidMarkup</name></name><parameter_list>(<param><decl><type><name>SGVData</name> <type:modifier>*</type:modifier></type> <name>p</name></decl></param>, <param><decl><type><name>ASSchedule</name> <type:modifier>*</type:modifier></type> <name>p2</name></decl></param>)</parameter_list> <block>{ }</block></constructor>";
            XElement xml = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace);
            var formals = new FormalParameterRecord[] {new FormalParameterRecord("SGVData*", false, "p"), new FormalParameterRecord("ASSchedule*", false, "p2")};

            MethodContext mc1 = new MethodContext("", false, "CBidMarkup", formals, false, true, false);
            MethodContext mc2 = ContextBuilder.BuildMethodContext(xml.Element(SRC.Constructor));
            Assert.IsTrue(MethodContextsAreEqual(mc1, mc2));
        }
Esempio n. 15
0
        public void TestBuildMethodContext_StaticFunctionWithClassAndParams() {
            string testSrcML = "<function><type><name>static</name> <name>char</name></type> <name><name>CBidMarkup</name><op:operator>::</op:operator><name>run</name></name><parameter_list>(<param><decl><type><name>CGVDate</name> <type:modifier>&amp;</type:modifier></type> <name>CurrDate</name></decl></param>)</parameter_list> <block>{ <return>return <expr><lit:literal type=\"char\">'a'</lit:literal></expr>;</return> }</block></function>";
            XElement xml = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace);
            var formals = new FormalParameterRecord[] {new FormalParameterRecord("CGVDate&", false, "CurrDate")};

            MethodContext mc1 = new MethodContext("char", true, "CBidMarkup", formals, true, false, false);
            MethodContext mc2 = ContextBuilder.BuildMethodContext(xml.Element(SRC.Function));
            Assert.IsTrue(MethodContextsAreEqual(mc1, mc2));
        }
Esempio n. 16
0
        public void TestBuildMethodContext_FunctionWithClassAndParams() {
            string testSrcML = "<function><type><name>int</name></type> <name><name>CBidMarkup</name><op:operator>::</op:operator><name>modifyBid</name></name><parameter_list>(<param><decl><type><name>bool</name></type> <name>Recalc</name></decl></param>, <param><decl><type><name>char</name><type:modifier>*</type:modifier></type> <name>Foo</name></decl></param>)</parameter_list><block>{ <return>return <expr><lit:literal type=\"number\">0</lit:literal></expr>;</return> }</block></function>";
            XElement xml = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace);
            var formals = new FormalParameterRecord[] {new FormalParameterRecord("bool", true, "Recalc"), new FormalParameterRecord("char*", true, "Foo")};

            MethodContext mc1 = new MethodContext("int", true, "CBidMarkup", formals, false, false, false);
            MethodContext mc2 = ContextBuilder.BuildMethodContext(xml.Element(SRC.Function));
            Assert.IsTrue(MethodContextsAreEqual(mc1, mc2));
        }