-
Notifications
You must be signed in to change notification settings - Fork 49
Semantic checks for C702 #973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
test/semantics/resolve69.f90
Outdated
@@ -0,0 +1,45 @@ | |||
subroutine s1() | |||
! C701 (R701) The type-param-value for a kind type parameter shall be a | |||
! constant expression. This constraint looks like a mistake in the standard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you think that C701 is a mistake? Kind type parameter values must be constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I can't remember why, but when I first started looking at type parameters, I thought I saw an inconsistency and added this comment. I'll remove it.
test/semantics/modfile28.f90
Outdated
@@ -3,20 +3,20 @@ | |||
! Note: Module files are encoded in UTF-8. | |||
|
|||
module m | |||
character(kind=4,len=:), parameter :: c4 = 4_"Hi! 你好!" | |||
character(kind=4,len=7), parameter :: c4 = 4_"Hi! 你好!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*
would be better than explicit lengths here as a replacement for :
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Peter. I'll change it.
lib/semantics/resolve-names.cpp
Outdated
@@ -1483,6 +1484,9 @@ Attrs AttrsVisitor::GetAttrs() { | |||
CHECK(attrs_); | |||
return *attrs_; | |||
} | |||
bool AttrsVisitor::HasPointerOrAllocatable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this function improves upon the original predicate expression in terms of readability or isolating complexity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This surprises me. To be clear, there are three places in resolve-names.cpp where we test to see if the POINTER or ALLOCATABLE attribute is present. You're saying that it would be better to repeat the code in these three instances than to have a separate function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the benefit of wrapping that simple predicate up in a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It reduces the size of the code.
If you'd rather eliminate this function, I'm happy to do that. It seemed wrong to me to copy/paste existing code rather than sharing it. I'll remove the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining the function increases the number of lines of code by 3, yes? That's not a big deal, but it's surely not a reduction in code size. Is there some other benefit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I know of.
C702 (R701) A colon shall not be used as a type-param-value except in the declaration of an entity that has the POINTER or ALLOCATABLE attribute. I added code to the visitor for a TypeDeclarationStmt to check for the 'LEN' type parameter for strings and to loop over the type parameters for derived types. I also ran into a few situations where previous tests had erroneously used a colon for type parameters without either the POINTER or ALLOCATABLE attribute and fixed them up.
C702 (R701) A colon shall not be used as a type-param-value except in the declaration of an entity that has the POINTER or ALLOCATABLE attribute. I added code to the visitor for a TypeDeclarationStmt to check for the 'LEN' type parameter for strings and to loop over the type parameters for derived types. I also ran into a few situations where previous tests had erroneously used a colon for type parameters without either the POINTER or ALLOCATABLE attribute and fixed them up. Original-commit: flang-compiler/f18@a1a95bf Reviewed-on: flang-compiler/f18#973
…/ps-c702 Semantic checks for C702 Original-commit: flang-compiler/f18@351a7d5 Reviewed-on: flang-compiler/f18#973
C702 (R701) A colon shall not be used as a type-param-value except in the declaration of an entity that has the POINTER or ALLOCATABLE attribute. I added code to the visitor for a TypeDeclarationStmt to check for the 'LEN' type parameter for strings and to loop over the type parameters for derived types. I also ran into a few situations where previous tests had erroneously used a colon for type parameters without either the POINTER or ALLOCATABLE attribute and fixed them up. Original-commit: flang-compiler/f18@a1a95bf Reviewed-on: flang-compiler/f18#973
C702 (R701) A colon shall not be used as a type-param-value except in the
declaration of an entity that has the POINTER or ALLOCATABLE attribute.
I added code to the visitor for a TypeDeclarationStmt to check for the
'LEN' type parameter for strings and to loop over the type parameters
for derived types.
I also ran into a few situations where previous tests had erroneously
used a colon for type parameters without either the POINTER or
ALLOCATABLE attribute and fixed them up.