コード例 #1
0
        public void ReverseSortBy()
        {
            ArrayList arrayList = new ArrayList();
            arrayList.Add(new BELInteger(1));
            arrayList.Add(new BELInteger(2));
            arrayList.Add(new BELInteger(3));
            arrayList.Add(new BELInteger(0));

            BELArray unsorted = new BELArray(arrayList);

            // Create a simple arithmetic mapping for the sort
            BehaviorParser parser = new BehaviorParser("");
            ExposableParseTreeNode block = parser.Parse("4.Subtract(e)");

            ArrayList parameters = new ArrayList();
            BlockParameter parameter = new BlockParameter(null, "e");
            parameters.Add(parameter);

            BELArray sorted = unsorted.ReverseSortBy(new ExecutionContext(), new Block(block, parameters, null));

            Assert.AreEqual(4, sorted.Count, "Checking that the length was preserved.");

            for (int i = 0; i < 4; ++i)
            {
                Assert.AreEqual(i, ((BELInteger)sorted.Item(i)).Value, "Checking that sort order was correct.");
            }
        }
コード例 #2
0
        public void writeAllBehaviors(ArtifactsVO allArtifacts)
        {
            Console.Write("inserting table for behaviors ");

            try
            {
                conn.Open();
                recreateBehaviorTable();

                behaviorRecCount = 0;
                bhvParser        = new BehaviorParser();

                // トランザクションの開始
                // (トランザクションのcommitは指定行数がINSERTされる度にループ内で実施)
                transaction = conn.BeginTransaction();

                // 実装モデルを除いてインデックスに登録
                foreach (ArtifactVO atf in allArtifacts.getArtifactsExcludeImplModel())
                {
                    // ふるまいテーブルの書き込み(成果物フォルダ配下のクラス要素)
                    insertBehaviorsInArtifact(atf);
                }

                transaction.Commit();
                Console.WriteLine(".  done(" + behaviorRecCount + "records)");

                conn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #3
0
ファイル: ExecutionTests.cs プロジェクト: nuxleus/flexwiki
		string Run(string input, int wikiTalkVersion)
		{
			BehaviorParser parser = new BehaviorParser();
			ExposableParseTreeNode obj = parser.Parse(input);
			Assert.IsNotNull(obj);
			ExecutionContext ctx = new ExecutionContext();
			ctx.WikiTalkVersion = wikiTalkVersion;
			IBELObject evaluated = obj.Expose(ctx);
			IOutputSequence seq = evaluated.ToOutputSequence();
			return OutputSequenceToString(seq);
		}
コード例 #4
0
        private void exportMethodCallingGraph(List <MethodVO> methods)
        {
            StreamWriter     grphsw     = null;
            string           dbFileName = ProjectSetting.getVO().projectPath + "\\" + ProjectSetting.getVO().dbName;
            SQLiteConnection conn       = new SQLiteConnection("Data Source=" + dbFileName);

            try
            {
                grphsw = new StreamWriter(outputDir + "\\" + "graphdata_l.dat", false, System.Text.Encoding.GetEncoding("utf-8"));


                conn.Open();

                BehaviorParser parser = new BehaviorParser();

                foreach (MethodVO mth in methods)
                {
                    List <MethodCallingInfo> callingInfos = searchForMethodLinks(mth, conn, parser);

                    foreach (MethodCallingInfo ci in callingInfos)
                    {
                        // Methodノードとのリレーション(:Call) の追加
                        grphsw.Write("MATCH (src:Method{id:" + ci.methodId + "}), ");
                        grphsw.Write("(dst:Method{id:" + ci.destMethodId + "}) ");
                        grphsw.WriteLine("CREATE (src)-[:Call{ row:" + ci.row + " }]->(dst)");
                        grphsw.WriteLine(";");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Message=" + ex.Message);
                Console.WriteLine(ex.StackTrace);

                Console.WriteLine("-------改行の入力で終了します");

                Console.ReadLine();
            }
            finally
            {
                if (grphsw != null)
                {
                    grphsw.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
コード例 #5
0
        private static string getParsedBehavior(MethodVO mth)
        {
            BehaviorParser       parser    = new BehaviorParser();
            List <BehaviorChunk> chunkList = parser.parseBehavior(mth);

            StringWriter outsw = new StringWriter();

            foreach (var bc in chunkList)
            {
                outsw.WriteLine(generateIndentStr(bc.indLv) + bc.behavior);
            }

            return(outsw.ToString());
        }
コード例 #6
0
        public void ReverseSortByEmpty()
        {
            BELArray unsorted = new BELArray();

            // Create a simple arithmetic mapping for the sort
            BehaviorParser parser = new BehaviorParser("");
            ExposableParseTreeNode block = parser.Parse("4.Subtract(e)");

            ArrayList parameters = new ArrayList();
            BlockParameter parameter = new BlockParameter(null, "e");
            parameters.Add(parameter);

            BELArray sorted = unsorted.ReverseSortBy(new ExecutionContext(), new Block(block, parameters, null));

            Assert.IsNotNull(sorted, "Checking that result was returned for an empty array.");
            Assert.AreEqual(0, sorted.Count, "Checking that the result array was empty.");
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="methods"></param>
        private List <MethodCallingInfo> searchForMethodLinks(MethodVO mth, SQLiteConnection conn, BehaviorParser parser)
        {
            List <BehaviorChunk> chunks          = readBehaviorChunks(conn, mth.methodId);
            List <BehaviorChunk> tokenizedChunks = parser.tokenizeChunk(chunks);

            List <MethodCallingInfo> retCallingInfos = new List <MethodCallingInfo>();

            Console.WriteLine("■■MethodID:" + mth.methodId);
            foreach (BehaviorChunk tchk in tokenizedChunks)
            {
                MethodVO hitMethod = null;
                Console.Write(tchk.dottedNum + " ");
                if (tchk.behaviorToken != null)
                {
                    Console.Write(tchk.behaviorToken.token + tchk.behavior);

                    BehaviorToken tkn = tchk.behaviorToken;

                    // 最初のトークン(命令タイプ識別子)による判断分岐
                    switch (tkn.token)
                    {
                    // call-method 文なら
                    case BehaviorParser.STMT_TYPE_CALL_METHOD:
                        hitMethod = tryGetMethodIdFromCandidateString(getNumberedTokenValue(tkn, 1), mth.elementId);
                        break;

                    // call-method-take-return 文なら
                    case BehaviorParser.STMT_TYPE_CALL_METHOD_TAKE_RETURN:
                        hitMethod = tryGetMethodIdFromCandidateString(getNumberedTokenValue(tkn, 3), mth.elementId);
                        break;

                    // let 文なら
                    case BehaviorParser.STMT_TYPE_LET:
                        hitMethod = tryGetMethodIdFromCandidateString(getNumberedTokenValue(tkn, 1), mth.elementId);
                        if (hitMethod == null)
                        {
                            hitMethod = tryGetMethodIdFromCandidateString(getNumberedTokenValue(tkn, 3), mth.elementId);
                        }
                        break;

                    // let-with-cast 文なら
                    case BehaviorParser.STMT_TYPE_LET_WITH_CAST:
                        hitMethod = tryGetMethodIdFromCandidateString(getNumberedTokenValue(tkn, 6), mth.elementId);
                        break;
                    }
                }
                else
                {
                    Console.Write("[cant-tokenize]" + tchk.behavior);
                }

                //
                if (hitMethod != null)
                {
                    MethodCallingInfo ci = new MethodCallingInfo();
                    ci.chunkId      = tchk.chunkId;
                    ci.methodId     = mth.methodId;
                    ci.row          = tchk.pos;
                    ci.matchedChunk = tchk.behavior;
                    ci.destMethodId = hitMethod.methodId;
                    retCallingInfos.Add(ci);

                    Console.WriteLine("\t" + hitMethod.name);
                }
                else
                {
                    Console.WriteLine("");
                }
            }

            return(retCallingInfos);
        }