Exemplo n.º 1
0
 /// <summary>
 /// メンバーアクセス処理
 /// </summary>
 /// <param name="tokens"></param>
 /// <param name="parent"></param>
 /// <returns></returns>
 private KecaknoahMemberAccessExpressionAstNode ParsePrimaryMemberAccessExpression(Queue<KecaknoahToken> tokens, KecaknoahPrimaryExpressionAstNode parent)
 {
     var mnt = tokens.Dequeue();
     if (mnt.Type != KecaknoahTokenType.Identifer) throw new KecaknoahParseException(mnt.CreateErrorAt("有効なメンバー名を指定してください。"));
     var r = new KecaknoahMemberAccessExpressionAstNode();
     r.Target = parent;
     r.ExpressionType = KecaknoahOperatorType.MemberAccess;
     r.MemberName = mnt.TokenString;
     return r;
 }
Exemplo n.º 2
0
        private void ReplaceExpressionClassAccess(KecaknoahExpressionAstNode node, bool isStatic, string className, IList<string> instanceMethods, IList<string> staticMethods, IList<string> Locals)
        {
            Action<KecaknoahExpressionAstNode> curry = (p) => ReplaceExpressionClassAccess(p, isStatic, className, instanceMethods, staticMethods, Locals);
            if (node is KecaknoahBinaryExpressionAstNode)
            {
                var bn = (KecaknoahBinaryExpressionAstNode)node;
                curry(bn.FirstNode);
                curry(bn.SecondNode);
            }
            else if (node is KecaknoahFactorExpressionAstNode)
            {
                var f = (KecaknoahFactorExpressionAstNode)node;
                if (f.FactorType == KecaknoahFactorType.Identifer)
                {
                    if (!isStatic && (instanceMethods.Contains(f.StringValue) || Locals.Contains(f.StringValue)))
                    {
                        var newfac = new KecaknoahMemberAccessExpressionAstNode();
                        newfac.MemberName = f.StringValue;
                        newfac.Target = new KecaknoahFactorExpressionAstNode { FactorType = KecaknoahFactorType.Identifer, StringValue = "self" };
                        f.FactorType = KecaknoahFactorType.ParenExpression;
                        f.ExpressionNode = newfac;
                    }

                    if (staticMethods.Contains(f.StringValue))
                    {
                        //サブクラスも含む、そのうちね
                        var newfac = new KecaknoahMemberAccessExpressionAstNode();
                        newfac.MemberName = f.StringValue;
                        newfac.Target = new KecaknoahFactorExpressionAstNode { FactorType = KecaknoahFactorType.Identifer, StringValue = className };
                        f.FactorType = KecaknoahFactorType.ParenExpression;
                        f.ExpressionNode = newfac;
                    }
                }
            }
            else if (node is KecaknoahArgumentCallExpressionAstNode)
            {
                var ac = (KecaknoahArgumentCallExpressionAstNode)node;
                curry(ac.Target);
                foreach (var i in ac.Arguments) curry(i);
            }
            else if (node is KecaknoahPrimaryExpressionAstNode)
            {
                curry(((KecaknoahPrimaryExpressionAstNode)node).Target);
            }
            else if (node is KecaknoahUnaryExpressionAstNode)
            {
                curry(((KecaknoahUnaryExpressionAstNode)node).Target);
            }
        }