summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarphaman <arphaman@gmail.com>2013-09-20 10:48:52 +0100
committerarphaman <arphaman@gmail.com>2013-09-20 10:48:52 +0100
commitc0ed80175fcf599a6afee4282c322f4998a4903e (patch)
tree652cf0dcb98b18306d503423c63755dcb565c38e
parent3000ac6a9047461463cd159f263a3509411a9e47 (diff)
downloadflang-c0ed80175fcf599a6afee4282c322f4998a4903e.tar.gz
added parsing for COMMON statement
-rw-r--r--include/flang/Sema/Sema.h4
-rw-r--r--lib/Parse/ParseSpecStmt.cpp67
-rw-r--r--lib/Parse/Parser.cpp14
-rw-r--r--lib/Sema/SemaDecl.cpp6
-rw-r--r--test/Parser/common.f9515
5 files changed, 93 insertions, 13 deletions
diff --git a/include/flang/Sema/Sema.h b/include/flang/Sema/Sema.h
index 1e9da62e70..a7eb4813a2 100644
--- a/include/flang/Sema/Sema.h
+++ b/include/flang/Sema/Sema.h
@@ -377,6 +377,10 @@ public:
bool CheckEquivalenceType(QualType ExpectedType, const Expr *E);
+ void ActOnCOMMON(ASTContext &C, SourceLocation Loc, SourceLocation BlockLoc,
+ SourceLocation IDLoc, const IdentifierInfo *BlockID,
+ const IdentifierInfo *IDInfo, ArrayRef<ArraySpec *> Dimensions);
+
// DATA statement:
StmtResult ActOnDATA(ASTContext &C, SourceLocation Loc,
ArrayRef<Expr*> LHS, ArrayRef<Expr*> Values,
diff --git a/lib/Parse/ParseSpecStmt.cpp b/lib/Parse/ParseSpecStmt.cpp
index c9bd985f73..9e39d0e5ac 100644
--- a/lib/Parse/ParseSpecStmt.cpp
+++ b/lib/Parse/ParseSpecStmt.cpp
@@ -130,6 +130,73 @@ Parser::StmtResult Parser::ParseEQUIVALENCEStmt() {
return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel);
}
+/// ParseCOMMONStmt - Parse the COMMON statement.
+///
+/// [5.5.2] R557:
+/// common-stmt :=
+/// COMMON #
+/// # [ / [common-block-name] / ] common-block-object-list #
+/// # [ [,] / [common-block-name / #
+/// # common-block-object-list ] ...
+Parser::StmtResult Parser::ParseCOMMONStmt() {
+ // Check if this is an assignment.
+ if (IsNextToken(tok::equal))
+ return StmtResult();
+
+ auto Loc = ConsumeToken();
+ SmallVector<Stmt*, 8> StmtList;
+ SmallVector<Expr*, 8> ObjectList;
+
+ SourceLocation BlockIDLoc;
+ const IdentifierInfo *BlockID = nullptr;
+
+ bool Error = false;
+ do {
+ if(ConsumeIfPresent(tok::slash)) {
+ if(ConsumeIfPresent(tok::slash))
+ BlockID = nullptr;
+ else {
+ BlockIDLoc = Tok.getLocation();
+ BlockID = Tok.getIdentifierInfo();
+ if(!ExpectAndConsume(tok::identifier)) {
+ Error = true;
+ break;
+ }
+ if(!ExpectAndConsume(tok::slash)) {
+ Error = true;
+ break;
+ }
+ }
+ } else if(ConsumeIfPresent(tok::slashslash))
+ BlockID = nullptr;
+
+ auto IDLoc = Tok.getLocation();
+ auto IDInfo = Tok.getIdentifierInfo();
+ SmallVector<ArraySpec*, 8> Dimensions;
+
+ if(!ExpectAndConsume(tok::identifier)) {
+ Error = true;
+ break;
+ }
+ if(IsPresent(tok::l_paren)) {
+ if(ParseArraySpec(Dimensions)) {
+ Error = true;
+ break;
+ }
+ }
+
+ Actions.ActOnCOMMON(Context, Loc, BlockIDLoc,
+ IDLoc, BlockID, IDInfo,
+ Dimensions);
+ } while(ConsumeIfPresent(tok::comma));
+
+
+ if(Error) SkipUntilNextStatement();
+ else ExpectStatementEnd();
+
+ return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel);
+}
+
/// ParsePARAMETERStmt - Parse the PARAMETER statement.
///
/// [R548]:
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index f78af6a444..4202ead4c1 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -1462,7 +1462,7 @@ bool Parser::ParseSpecificationStmt() {
goto notImplemented;
case tok::kw_COMMON:
Result = ParseCOMMONStmt();
- goto notImplemented;
+ break;
case tok::kw_PARAMETER:
Result = ParsePARAMETERStmt();
break;
@@ -1594,18 +1594,6 @@ Parser::StmtResult Parser::ParseBINDStmt() {
return StmtResult();
}
-/// ParseCOMMONStmt - Parse the COMMON statement.
-///
-/// [5.5.2] R557:
-/// common-stmt :=
-/// COMMON #
-/// # [ / [common-block-name] / ] common-block-object-list #
-/// # [ [,] / [common-block-name / #
-/// # common-block-object-list ] ...
-Parser::StmtResult Parser::ParseCOMMONStmt() {
- return StmtResult();
-}
-
/// ParseDATAStmt - Parse the DATA statement.
///
/// [R524]:
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 6c39ce2166..ddb059a159 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -395,6 +395,12 @@ Decl *Sema::ActOnEntityDecl(ASTContext &C, DeclSpec &DS, SourceLocation IDLoc,
return ActOnEntityDecl(C, T, IDLoc, IDInfo);
}
+void Sema::ActOnCOMMON(ASTContext &C, SourceLocation Loc, SourceLocation BlockLoc,
+ SourceLocation IDLoc, const IdentifierInfo *BlockID,
+ const IdentifierInfo *IDInfo, ArrayRef<ArraySpec*> Dimensions) {
+
+}
+
//
// derived types
//
diff --git a/test/Parser/common.f95 b/test/Parser/common.f95
new file mode 100644
index 0000000000..003d4ec6e8
--- /dev/null
+++ b/test/Parser/common.f95
@@ -0,0 +1,15 @@
+! RUN: %flang -fsyntax-only -verify < %s
+
+program test
+ integer x,y,z,w,i,j,k
+ real r
+
+ common x,y, /a/ z, /w/ w
+ common /a/ i(10,-5:8)
+ common // j,k
+ common / / r
+
+ common /a/ ! expected-error {{expected identifier}}
+ common ! expected-error {{expected identifier}}
+
+end program