[flang] Do not emit a prefix for a default-kind character constant in AsFortran

Original-commit: flang-compiler/f18@4a3db55727
Reviewed-on: https://github.com/flang-compiler/f18/pull/1078
This commit is contained in:
peter klausler 2020-03-17 12:35:31 -07:00
parent d2c87e0b36
commit f4faeefe3d
9 changed files with 15 additions and 21 deletions

View File

@ -26,8 +26,6 @@
namespace Fortran::evaluate {
extern bool formatForPGF90;
template<typename A>
auto operator<<(std::ostream &o, const A &x) -> decltype(x.AsFortran(o)) {
return x.AsFortran(o);

View File

@ -18,8 +18,6 @@
namespace Fortran::evaluate {
bool formatForPGF90{false};
static void ShapeAsFortran(std::ostream &o, const ConstantSubscripts &shape) {
if (GetRank(shape) > 1) {
o << ",shape=";
@ -87,7 +85,7 @@ std::ostream &Constant<Type<TypeCategory::Character, KIND>>::AsFortran(
if (j > 0) {
o << ',';
}
if (Result::kind != 1 || !formatForPGF90) {
if (Result::kind != 1) {
o << Result::kind << '_';
}
o << parser::QuoteCharacterLiteral(value);

View File

@ -22,16 +22,16 @@ end
!Expect: m.mod
!module m
! character(2_4,1),parameter::prefix=1_"c_"
! integer(4),bind(c, name=1_"c_a")::a
! procedure(sub),bind(c, name=1_"c_b"),pointer::b
! character(2_4,1),parameter::prefix="c_"
! integer(4),bind(c, name="c_a")::a
! procedure(sub),bind(c, name="c_b"),pointer::b
! type,bind(c)::t
! real(4)::c
! end type
! procedure(real(4)),bind(c, name=1_"dd")::d
! procedure(real(4)),bind(c, name=1_"ee")::e
! procedure(real(4)),bind(c, name=1_"ff")::f
! procedure(real(4)),bind(c, name="dd")::d
! procedure(real(4)),bind(c, name="ee")::e
! procedure(real(4)),bind(c, name="ff")::f
!contains
! subroutine sub() bind(c, name=1_"sub")
! subroutine sub() bind(c, name="sub")
! end
!end

View File

@ -26,7 +26,7 @@ end
! integer(8),parameter::i=2_8
! real(4)::r
! character(10_4,1)::c
! character(10_4,1),parameter::c2=1_"qwer "
! character(10_4,1),parameter::c2="qwer "
! complex(8),parameter::z=(1._8,2._8)
! complex(8),parameter::zn=(-1._8,2._8)
! type::t

View File

@ -30,6 +30,6 @@ end
! bind(c)::/cb2/
! common//t,w,u,v
! common/cb/x,y,z
! bind(c, name=1_"CB")::/cb/
! bind(c, name="CB")::/cb/
! common/b/cb
!end

View File

@ -18,6 +18,6 @@ end module m
!character(1_4,int(k,kind=8))::a
!character(3_4,int(k,kind=8))::b
!end type
!type(t(k=1_4)),parameter::p=t(k=1_4)(a=1_"x",b=1_"xx ")
!character(2_4,1),parameter::c2(1_8:3_8)=[CHARACTER(KIND=1,LEN=2)::1_"x ",1_"xx",1_"xx"]
!type(t(k=1_4)),parameter::p=t(k=1_4)(a="x",b="xx ")
!character(2_4,1),parameter::c2(1_8:3_8)=[CHARACTER(KIND=1,LEN=2)::"x ","xx","xx"]
!end

View File

@ -16,7 +16,7 @@ end module m
!Expect: m.mod
!module m
!character(*,4),parameter::c4=4_"Hi! \344\275\240\345\245\275!"
!character(*,1),parameter::c1=1_"Hi! \344\275\240\345\245\275!"
!character(*,1),parameter::c1="Hi! \344\275\240\345\245\275!"
!character(*,4),parameter::c4a(1_8:*)=[CHARACTER(KIND=4,LEN=1)::4_"\344\270\200",4_"\344\272\214",4_"\344\270\211",4_"\345\233\233",4_"\344\272\224"]
!integer(4),parameter::lc4=7_4
!intrinsic::len

View File

@ -75,7 +75,7 @@ end
!Expect: m4a.mod
!module m4a
! character(1_4,1),parameter::a=1_"\001"
! character(1_4,1),parameter::a="\001"
! intrinsic::achar
!end
@ -83,6 +83,6 @@ end
!module m4b
! use m4a,only:a
! use m4a,only:achar
! character(1_4,1),parameter::b=1_"\001"
! character(1_4,1),parameter::b="\001"
!end

View File

@ -333,13 +333,11 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options,
{
std::ofstream tmpSource;
tmpSource.open(tmpSourcePath);
Fortran::evaluate::formatForPGF90 = true;
Unparse(tmpSource, parseTree, driver.encoding, true /*capitalize*/,
options.features.IsEnabled(
Fortran::common::LanguageFeature::BackslashEscapes),
nullptr /* action before each statement */,
driver.unparseTypedExprsToPGF90 ? &asFortran : nullptr);
Fortran::evaluate::formatForPGF90 = false;
}
if (ParentProcess()) {