浏览代码

Allow attributes on local methods

Brian Fiete 3 年之前
父节点
当前提交
f081365dab

+ 12 - 4
IDEHelper/Compiler/BfReducer.cpp

@@ -4134,7 +4134,7 @@ BfAstNode* BfReducer::DoCreateStatement(BfAstNode* node, CreateStmtFlags createS
 		}
 		else if (token == BfToken_LBracket)
 		{
-			return CreateAttributedStatement(tokenNode);
+			return CreateAttributedStatement(tokenNode, createStmtFlags);
 		}
 	}
 
@@ -5663,15 +5663,23 @@ Do_RBracket:
 	return attributeDirective;
 }
 
-BfStatement* BfReducer::CreateAttributedStatement(BfTokenNode* tokenNode)
+BfStatement* BfReducer::CreateAttributedStatement(BfTokenNode* tokenNode, CreateStmtFlags createStmtFlags)
 {
 	auto attrib = CreateAttributeDirective(tokenNode);
 	if (attrib == NULL)
 		return NULL;
 	
-	BfAstNode* stmt = CreateStatementAfter(attrib);
+	BfAstNode* stmt = CreateStatementAfter(attrib, createStmtFlags);
 	if (stmt != NULL)
-	{		
+	{	
+		if (auto localMethodDecl = BfNodeDynCastExact<BfLocalMethodDeclaration>(stmt))
+		{
+			BF_ASSERT(localMethodDecl->mMethodDeclaration->mAttributes == NULL);
+			localMethodDecl->mSrcStart = attrib->mSrcStart;			
+			MEMBER_SET(localMethodDecl->mMethodDeclaration, mAttributes, attrib);
+			return localMethodDecl;
+		}
+
 		bool isValid = true;
 
 		auto checkNode = stmt;

+ 1 - 1
IDEHelper/Compiler/BfReducer.h

@@ -196,7 +196,7 @@ public:
 	BfFieldDtorDeclaration* CreateFieldDtorDeclaration(BfAstNode* srcNode);
 	BfFieldDeclaration* CreateFieldDeclaration(BfTokenNode* tokenNode, BfTypeReference* typeRef, BfIdentifierNode* nameIdentifier, BfFieldDeclaration* prevFieldDeclaration);
 	BfAttributeDirective* CreateAttributeDirective(BfTokenNode* startToken);	
-	BfStatement* CreateAttributedStatement(BfTokenNode* tokenNode);
+	BfStatement* CreateAttributedStatement(BfTokenNode* tokenNode, CreateStmtFlags createStmtFlags = CreateStmtFlags_None);
 	BfExpression* CreateAttributedExpression(BfTokenNode* tokenNode, bool onlyAllowIdentifier);
 	BfDelegateBindExpression* CreateDelegateBindExpression(BfAstNode* allocNode);
 	BfLambdaBindExpression* CreateLambdaBindExpression(BfAstNode* allocNode, BfTokenNode* parenToken = NULL);

+ 10 - 3
IDEHelper/Compiler/BfSourceClassifier.cpp

@@ -17,6 +17,7 @@ BfSourceClassifier::BfSourceClassifier(BfParser* bfParser, CharData* charData)
 	mEnabled = true;
 	mPrevNode = NULL;
 	mCurMember = NULL;
+	mCurLocalMethodDeclaration = NULL;
 }
 
 void BfSourceClassifier::ModifyFlags(BfAstNode* node, uint8 andFlags, uint8 orFlags)
@@ -213,10 +214,13 @@ void BfSourceClassifier::Visit(BfAttributeDirective* attributeDirective)
 				return;
 		}
 
-		if (auto methodDecl = BfNodeDynCast<BfMethodDeclaration>(mCurMember))
+		if (mCurLocalMethodDeclaration == NULL)
 		{
-			if (methodDecl->mAttributes == attributeDirective)
-				return;
+			if (auto methodDecl = BfNodeDynCast<BfMethodDeclaration>(mCurMember))
+			{
+				if (methodDecl->mAttributes == attributeDirective)
+					return;
+			}
 		}
 
 		if (auto propDecl = BfNodeDynCast<BfPropertyDeclaration>(mCurMember))
@@ -384,7 +388,10 @@ void BfSourceClassifier::Visit(BfGenericInstanceTypeRef* genericInstTypeRef)
 void BfSourceClassifier::Visit(BfLocalMethodDeclaration* methodDecl)
 {
 	if (IsInterestedInMember(methodDecl, true))
+	{
+		SetAndRestoreValue<BfLocalMethodDeclaration*> prevLocalMethodDecl(mCurLocalMethodDeclaration, methodDecl);
 		BfElementVisitor::Visit(methodDecl);
+	}
 }
 
 void BfSourceClassifier::Visit(BfLiteralExpression* literalExpr)

+ 1 - 0
IDEHelper/Compiler/BfSourceClassifier.h

@@ -69,6 +69,7 @@ public:
 	uint8 mClassifierPassId;
 	BfAstNode* mPrevNode;
 	BfAstNode* mCurMember;
+	BfLocalMethodDeclaration* mCurLocalMethodDeclaration;
 
 public:
 	void HandleLeafNode(BfAstNode* node);