@@ -1107,56 +1107,13 @@ private static bool InjectedProcessNeeded(MethodInfo methodInfo)
11071107 }
11081108
11091109 protected override void VisitObjectProcedureCall ( BslSyntaxNode node )
1110- {
1111- var target = _statementBuildParts . Pop ( ) ;
1112- var call = ( CallNode ) node ;
1113-
1114- var targetType = target . Type ;
1115- var name = call . Identifier . GetIdentifier ( ) ;
1116- if ( targetType . IsObjectValue ( ) )
1117- {
1118- var methodInfo = FindMethodOfType ( node , targetType , name ) ;
1119- var injectProcess = InjectedProcessNeeded ( methodInfo ) ;
1120- var args = PrepareCallArguments ( call . ArgumentList , methodInfo . GetParameters ( ) , injectProcess ) ;
1121-
1122- _blocks . Add ( Expression . Call ( target , methodInfo , args ) ) ;
1123- }
1124- else if ( targetType . IsContext ( ) )
1125- {
1126- var contextCall = ExpressionHelpers . CallContextMethod ( target , name , _processParameter ,
1127- PrepareDynamicCallArguments ( call . ArgumentList ) ) ;
1128- _blocks . Add ( contextCall ) ;
1129- }
1130- else if ( targetType . IsValue ( ) )
1131- {
1132- var contextCall = ExpressionHelpers . TryCallContextMethod ( target , name , _processParameter ,
1133- PrepareDynamicCallArguments ( call . ArgumentList ) ) ;
1134- _blocks . Add ( contextCall ) ;
1135- }
1136- else if ( target is DynamicExpression )
1137- {
1138- var args = new List < Expression > ( ) ;
1139- args . Add ( target ) ;
1140- args . AddRange ( PrepareDynamicCallArguments ( call . ArgumentList ) ) ;
1141-
1142- var csharpArgs = new List < CSharpArgumentInfo > ( ) ;
1143- csharpArgs . Add ( CSharpArgumentInfo . Create ( CSharpArgumentInfoFlags . None , default ) ) ;
1144- csharpArgs . AddRange ( args . Select ( x => CSharpArgumentInfo . Create ( CSharpArgumentInfoFlags . None , default ) ) ) ;
1145-
1146- var binder = Microsoft . CSharp . RuntimeBinder . Binder . InvokeMember (
1147- CSharpBinderFlags . InvokeSimpleName ,
1148- name ,
1149- null ,
1150- typeof ( BslObjectValue ) ,
1151- csharpArgs ) ;
1110+ {
1111+ _blocks . Add ( CreateObjectMethodCall ( node ) ) ;
1112+ }
11521113
1153- var objectExpr = Expression . Dynamic ( binder , typeof ( object ) , args ) ;
1154- _blocks . Add ( ExpressionHelpers . ConvertToType ( objectExpr , typeof ( BslValue ) ) ) ;
1155- }
1156- else
1157- {
1158- AddError ( NativeCompilerErrors . TypeIsNotAnObjectType ( targetType ) , node . Location ) ;
1159- }
1114+ protected override void VisitObjectFunctionCall ( BslSyntaxNode node )
1115+ {
1116+ _statementBuildParts . Push ( CreateObjectMethodCall ( node , true ) ) ;
11601117 }
11611118
11621119 private IEnumerable < Expression > PrepareDynamicCallArguments ( BslSyntaxNode argList )
@@ -1167,44 +1124,48 @@ private IEnumerable<Expression> PrepareDynamicCallArguments(BslSyntaxNode argLis
11671124 : Expression . Constant ( BslSkippedParameterValue . Instance ) ) ;
11681125 }
11691126
1170- protected override void VisitObjectFunctionCall ( BslSyntaxNode node )
1171- {
1127+ private Expression CreateObjectMethodCall ( BslSyntaxNode node , bool asFunction = false )
1128+ {
11721129 var target = _statementBuildParts . Pop ( ) ;
1173- var call = ( CallNode ) node ;
1174-
1130+ var call = ( CallNode ) node ;
11751131 var targetType = target . Type ;
11761132 var name = call . Identifier . GetIdentifier ( ) ;
1133+
11771134 if ( targetType . IsObjectValue ( ) )
11781135 {
11791136 var methodInfo = FindMethodOfType ( node , targetType , name ) ;
1180- if ( methodInfo . ReturnType == typeof ( void ) )
1137+ if ( asFunction && methodInfo . ReturnType == typeof ( void ) )
11811138 {
11821139 throw new NativeCompilerException ( BilingualString . Localize (
11831140 $ "Метод { targetType } .{ name } не является функцией",
11841141 $ "Method { targetType } .{ name } is not a function") , ToCodePosition ( node . Location ) ) ;
11851142 }
11861143
11871144 var args = PrepareCallArguments ( call . ArgumentList , methodInfo . GetParameters ( ) , InjectedProcessNeeded ( methodInfo ) ) ;
1188- _statementBuildParts . Push ( Expression . Call ( target , methodInfo , args ) ) ;
1145+ return Expression . Call ( target , methodInfo , args ) ;
11891146 }
11901147 else if ( targetType . IsContext ( ) )
11911148 {
1192- _statementBuildParts . Push ( ExpressionHelpers . CallContextMethod ( target , name , _processParameter , PrepareDynamicCallArguments ( call . ArgumentList ) ) ) ;
1149+ return ExpressionHelpers . CallContextMethod ( target , name , _processParameter ,
1150+ PrepareDynamicCallArguments ( call . ArgumentList ) ) ;
11931151 }
11941152 else if ( targetType . IsValue ( ) )
11951153 {
1196- var contextCall = ExpressionHelpers . TryCallContextMethod ( target , name , _processParameter ,
1154+ return ExpressionHelpers . TryCallContextMethod ( target , name , _processParameter ,
11971155 PrepareDynamicCallArguments ( call . ArgumentList ) ) ;
1198- _statementBuildParts . Push ( contextCall ) ;
11991156 }
12001157 else if ( target is DynamicExpression )
12011158 {
1202- var args = new List < Expression > ( ) ;
1203- args . Add ( target ) ;
1159+ var args = new List < Expression >
1160+ {
1161+ target
1162+ } ;
12041163 args . AddRange ( PrepareDynamicCallArguments ( call . ArgumentList ) ) ;
12051164
1206- var csharpArgs = new List < CSharpArgumentInfo > ( ) ;
1207- csharpArgs . Add ( CSharpArgumentInfo . Create ( CSharpArgumentInfoFlags . None , default ) ) ;
1165+ var csharpArgs = new List < CSharpArgumentInfo >
1166+ {
1167+ CSharpArgumentInfo . Create ( CSharpArgumentInfoFlags . None , default )
1168+ } ;
12081169 csharpArgs . AddRange ( args . Select ( x => CSharpArgumentInfo . Create ( CSharpArgumentInfoFlags . None , default ) ) ) ;
12091170
12101171 var binder = Microsoft . CSharp . RuntimeBinder . Binder . InvokeMember (
@@ -1215,12 +1176,11 @@ protected override void VisitObjectFunctionCall(BslSyntaxNode node)
12151176 csharpArgs ) ;
12161177
12171178 var objectExpr = Expression . Dynamic ( binder , typeof ( object ) , args ) ;
1218- _statementBuildParts . Push ( ExpressionHelpers . ConvertToType ( objectExpr , typeof ( BslValue ) ) ) ;
1219- }
1220- else
1221- {
1222- AddError ( NativeCompilerErrors . TypeIsNotAnObjectType ( targetType ) , node . Location ) ;
1179+ return ExpressionHelpers . ConvertToType ( objectExpr , typeof ( BslValue ) ) ;
12231180 }
1181+
1182+ AddError ( NativeCompilerErrors . TypeIsNotAnObjectType ( targetType ) , node . Location ) ;
1183+ return null ;
12241184 }
12251185
12261186 private MethodInfo FindMethodOfType ( BslSyntaxNode node , Type targetType , string name )
0 commit comments