From 26f2de28c61cd7ecd8111f2f320cf515eb941b7b Mon Sep 17 00:00:00 2001 From: Ke Ming Jiang <389185764@qq.com> Date: Fri, 4 Dec 2020 15:04:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=85=B3=E4=BA=8E=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E8=BF=94=E5=9B=9E=E5=80=BC=E7=9A=84TypeEncode?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E4=BB=A5=E5=8F=8A=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OCRunner/ORTypeVarPair+TypeEncode.m | 3 --- OCRunnerTests/ORTestWithObjc.m | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/OCRunner/ORTypeVarPair+TypeEncode.m b/OCRunner/ORTypeVarPair+TypeEncode.m index 41242f7..910b220 100644 --- a/OCRunner/ORTypeVarPair+TypeEncode.m +++ b/OCRunner/ORTypeVarPair+TypeEncode.m @@ -17,9 +17,6 @@ - (const char *)typeEncode{ // Block的typeEncode if (self.var.isBlock) { return @"@?".UTF8String; - // 函数指针的typeEncode - }else if (self.var.ptCount > 0){ - type = TypeUnKnown; } } if (type == TypeStruct && self.var.ptCount == 0) { diff --git a/OCRunnerTests/ORTestWithObjc.m b/OCRunnerTests/ORTestWithObjc.m index 17a5bc7..bda0b8e 100644 --- a/OCRunnerTests/ORTestWithObjc.m +++ b/OCRunnerTests/ORTestWithObjc.m @@ -499,14 +499,27 @@ - (void)testMutiTypeCalculate{ - (void)testCFunctionReturnTypeEncode{ NSString * source = @"CGFloat testFunctionReturnType(int arg);" - @"CGFloat (***testFunctionReturnType)(int arg);"; + @"CGFloat (***testFunctionReturnType)(int arg);" + @"CGFloat *testFunctionReturnType(int arg);" + @"XCTestCase *testFunctionReturnType(int arg);" + @"XCTestCase *(^testFunctionReturnType)(int arg);" + ; AST *ast = [OCParser parseSource:source]; - ORDeclareExpression *declare1 = ast.globalStatements.firstObject; - ORDeclareExpression *declare2 = ast.globalStatements.lastObject; + ORDeclareExpression *declare1 = ast.globalStatements[0]; + ORDeclareExpression *declare2 = ast.globalStatements[1]; + ORDeclareExpression *declare3 = ast.globalStatements[2]; + ORDeclareExpression *declare4 = ast.globalStatements[3]; + ORDeclareExpression *declare5 = ast.globalStatements[4]; NSString *returnType1 = [NSString stringWithUTF8String:declare1.pair.typeEncode]; XCTAssert([returnType1 isEqualToString:@"d"], @"%@", returnType1); NSString *returnType2 = [NSString stringWithUTF8String:declare2.pair.typeEncode]; - XCTAssert([returnType2 isEqualToString:@"^^^"], @"%@", returnType2); + XCTAssert([returnType2 isEqualToString:@"^^^d"], @"%@", returnType2); + NSString *returnType3 = [NSString stringWithUTF8String:declare3.pair.typeEncode]; + XCTAssert([returnType3 isEqualToString:@"^d"], @"%@", returnType3); + NSString *returnType4 = [NSString stringWithUTF8String:declare4.pair.typeEncode]; + XCTAssert([returnType4 isEqualToString:@"@"], @"%@", returnType4); + NSString *returnType5 = [NSString stringWithUTF8String:declare5.pair.typeEncode]; + XCTAssert([returnType5 isEqualToString:@"@?"], @"%@", returnType5); } - (void)testOCRecursiveFunctionPerformanceExample { [self measureBlock:^{