/// <summary> /// 関数呼び出しから,定義を探します /// </summary> /// <param name="callNode"> 関数呼び出しノード </param> /// <param name="topNode"> 検索対象のトップノード </param> /// <returns> 呼び出された関数の定義 </returns> public static UnifiedFunctionDefinition FindDefinition( UnifiedCall callNode, UnifiedElement topNode) { var belongingNamespace = GetBelongingNamespace(callNode); var callingFuncName = ((UnifiedVariableIdentifier)callNode.Function).Name; UnifiedFunctionDefinition parent = null; foreach (var ns in belongingNamespace.YieldParents()) { var unifiedElement = FindUnifiedElementByNamespace( ns.GetNamespaceString(), topNode); var element = unifiedElement.First(); var found = element.Descendants<UnifiedFunctionDefinition>().Where( e => e.Name.Name == callingFuncName); if (found.Count() > 0) { parent = found.First(); break; } } // 呼び出しがあるのに,定義がない場合(標準関数など)は null が変える return parent; }
private static UnifiedExpression CreateZsuper(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "zsuper"); // 引数を省略するとコンストラクタと同じ引数を渡す return(UnifiedCall.Create( UnifiedSuperIdentifier.Create("super"))); }
public UnifiedElement VisitInvocationExpression( InvocationExpression invoc, object data) { var target = invoc.Target.TryAcceptForExpression(this); var uArgs = invoc.Arguments.AcceptVisitorAsArgs(this, data); return(UnifiedCall.Create(target, uArgs)); }
private static IEnumerable <UnifiedExpression> CreateCallExpression(StaticCallExpression statement) { var args = from ph in statement.Phrases.OfType <ActualComplementPhrase>() let arg = CreatePhrase(ph.PrefixExpression) let sfx = ph.Particle.Text select UnifiedArgument.Create(arg, UnifiedIdentifier.CreateVariable(sfx)); yield return (UnifiedCall.Create( UnifiedIdentifier.CreateVariable(statement.MethodInfo.Name), args.ToSet())); }
private static UnifiedExpression CreateSuper(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "super"); // 引数を省略するとコンストラクタと同じ引数を渡す return(UnifiedCall.Create( UnifiedSuperIdentifier.Create("super"), node.Elements() .Select(CreateExpresion) .Select(e => UnifiedArgument.Create(e)) .ToSet() )); }
public static UnifiedCall CreateCall(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "call"); // TODO: 演算子への変換 var receiver = CreateExpresion(node.NthElement(0)); var secondNode = node.NthElement(1); return(UnifiedCall.Create( receiver != null ? UnifiedProperty.Create( ".", receiver, CreateExpresion(secondNode)) : CreateExpresion(secondNode), CreateArglist(node.NthElement(2)))); }
// 関数呼び出し(UnifiedCall) public override bool Visit(UnifiedCall element, VisitorArgument arg) { var prop = element.Function as UnifiedProperty; // TODO これに該当するケースがあるか調べる if (prop != null) { prop.Owner.TryAccept(this, arg); Writer.Write(prop.Delimiter); prop.Name.TryAccept(this, arg); } else { element.Function.TryAccept(this, arg); } element.Arguments.TryAccept(this, arg.Set(Paren)); return true; }
//関数呼び出し public override bool Visit(UnifiedCall element, VisitorArgument arg) { //JavaScriptではTypeArgumentsが存在しない var prop = element.Function as UnifiedProperty; //呼び出し式がプロパティの場合 if (prop != null) { prop.Owner.TryAccept(this, arg); Writer.Write(prop.Delimiter); prop.Name.TryAccept(this, arg); } else { element.Function.TryAccept(this, arg); } element.Arguments.TryAccept(this, arg.Set(Paren)); return true; }
public void compares_different_calls() { var o1 = UnifiedCall.Create( UnifiedVariableIdentifier.Create("f"), UnifiedSet <UnifiedArgument> .Create( UnifiedArgument.Create( UnifiedVariableIdentifier.Create( "a"), null, null), UnifiedArgument.Create( UnifiedBinaryExpression.Create( UnifiedVariableIdentifier. Create("n"), UnifiedBinaryOperator.Create ( "-", UnifiedBinaryOperatorKind .Add), UnifiedInt32Literal.Create( 1) ), null, null))); var o2 = UnifiedCall.Create( UnifiedVariableIdentifier.Create("f"), UnifiedSet <UnifiedArgument> .Create( UnifiedArgument.Create( UnifiedVariableIdentifier.Create( "a"), null, null), UnifiedArgument.Create( UnifiedBinaryExpression.Create( UnifiedVariableIdentifier. Create("n2"), UnifiedBinaryOperator.Create ( "-", UnifiedBinaryOperatorKind .Add), UnifiedInt32Literal.Create( 1)), null, null))); Assert.That( StructuralEqualityComparer.StructuralEquals(o1, o2), Is.False); }
public override bool Visit(UnifiedCall element, VisitorArgument arg) { var prop = element.Function as UnifiedProperty; if (prop != null) { prop.Owner.TryAccept(this, arg); Writer.Write(prop.Delimiter); element.GenericArguments.TryAccept(this, arg); prop.Name.TryAccept(this, arg); } else { // Javaでifが実行されるケースは存在しないが、言語変換のため if (element.GenericArguments != null) { Writer.Write("this."); } element.GenericArguments.TryAccept(this, arg); element.Function.TryAccept(this, arg); } element.Arguments.TryAccept(this, arg.Set(Paren)); return false; }
//関数呼び出し public override bool Visit(UnifiedCall element, VisitorArgument arg) { //JavaScriptではTypeArgumentsが存在しない var prop = element.Function as UnifiedProperty; //呼び出し式がプロパティの場合 if (prop != null) { prop.Owner.TryAccept(this, arg); Writer.Write(prop.Delimiter); prop.Name.TryAccept(this, arg); } else { element.Function.TryAccept(this, arg); } element.Arguments.TryAccept(this, arg.Set(Paren)); return(true); }
public override bool Visit(UnifiedCall element, VisitorArgument arg) { var prop = element.Function as UnifiedProperty; if (prop != null) { prop.Owner.TryAccept(this, arg); Writer.Write(prop.Delimiter); element.GenericArguments.TryAccept(this, arg); prop.Name.TryAccept(this, arg); } else { // Javaでifが実行されるケースは存在しないが、言語変換のため if (element.GenericArguments != null) { Writer.Write("this."); } element.GenericArguments.TryAccept(this, arg); element.Function.TryAccept(this, arg); } element.Arguments.TryAccept(this, arg.Set(Paren)); return(false); }
public static UnifiedExpression CreatePostfixExpression(XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "postfix_expression"); /* * postfix_expression * : primary_expression * ( '[' expression ']' | '(' ')' | '(' argument_expression_list ')' | '.' IDENTIFIER | '->' IDENTIFIER | '++' | '--' | )* */ var result = CreatePrimaryExpression(node.Element("primary_expression")); var elements = node.Elements().Skip(1); //先頭以外のすべての要素を取得 var length = elements.Count(); for (var i = 0; i < length; i++) { switch (elements.ElementAt(i++).Value) { case "[": result = UnifiedIndexer.Create( result, UnifiedSet <UnifiedArgument> .Create( UnifiedArgument.Create( CreateExpression( elements.ElementAt(i++)). ElementAt(0)))); i++; // ']'読み飛ばし break; case "(": if (elements.ElementAt(i).Name == "argument_expression_list") { result = UnifiedCall.Create( result, CreateArgumentExpressionList( elements.ElementAt(i++))); } else { result = UnifiedCall.Create( result, UnifiedSet <UnifiedArgument> .Create()); } i++; // ')'読み飛ばし break; case ".": result = UnifiedProperty.Create( ".", result, UnifiedIdentifier.CreateVariable( elements.ElementAt(i++).Value)); break; case "->": result = UnifiedProperty.Create( "->", result, UnifiedIdentifier.CreateVariable( elements.ElementAt(i++).Value)); // TODO ポインタ型に展開してから処理するのか? break; case "++": result = UnifiedUnaryExpression.Create( result, UnifiedUnaryOperator.Create( "++", UnifiedUnaryOperatorKind.PostIncrementAssign)); break; case "--": result = UnifiedUnaryExpression.Create( result, UnifiedUnaryOperator.Create( "--", UnifiedUnaryOperatorKind.PostDecrementAssign)); break; default: throw new InvalidOperationException(); } } return(result); }
/// <summary> /// 関数呼び出しがされている,名前空間を特定する /// </summary> /// <param name="callNode"> </param> /// <returns> </returns> public static Namespace GetBelongingNamespace(UnifiedCall callNode) { var upperTypes = new[] { NamespaceType.Function, NamespaceType.TemporaryScope }; var unifiedtTypes = upperTypes.Select( e => DetectorHelper.Namespace2UnifiedType(e)); var firstFound = DetectorHelper.GetFirstFoundNode( callNode, unifiedtTypes); if (firstFound == null) { return null; } var belongingSpace = Detector.Dispatcher(firstFound); return belongingSpace; }