77import org .w3c .dom .Attr ;
88import org .w3c .dom .Element ;
99
10+ import fortran .ofp .parser .java .IActionEnums ;
1011import fortran .ofp .parser .java .IFortranParser ;
1112
1213/**
@@ -183,6 +184,15 @@ public void label(Token lbl) {
183184 contextOpen ("statement" );
184185 }
185186
187+ public void type_param_value (boolean hasExpr , boolean hasAsterisk , boolean hasColon ) {
188+ Element value = hasExpr ? contextNode (-1 ): null ;
189+ contextOpen ("type-attribute" );
190+ if (hasExpr )
191+ moveHere (value );
192+ super .type_param_value (hasExpr , hasAsterisk , hasColon );
193+ contextClose ();
194+ }
195+
186196 public void intrinsic_type_spec (Token keyword1 , Token keyword2 , int type , boolean hasKindSelector ) {
187197 if (!context .getTagName ().equals ("declaration" )) {
188198 // TODO: ensure being in body
@@ -240,10 +250,52 @@ public void real_literal_constant(Token realConstant, Token kindParam) {
240250 super .real_literal_constant (realConstant , kindParam );
241251 }
242252
253+ public void char_selector (Token tk1 , Token tk2 , int kindOrLen1 , int kindOrLen2 , boolean hasAsterisk ) {
254+ int [] attribute_types = new int []{kindOrLen2 , kindOrLen1 };
255+ contextOpen ("type-attributes" );
256+ Element localContext = context ;
257+ contextClose ();
258+ Element value = null ;
259+ for (int attribute_type : attribute_types ) {
260+ switch (attribute_type ) {
261+ case IActionEnums .KindLenParam_none :
262+ break ;
263+ case IActionEnums .KindLenParam_len :
264+ value = contextNode (-2 );
265+ moveTo (localContext , value );
266+ contextRename (value , "type-attribute" , "length" );
267+ break ;
268+ case IActionEnums .KindLenParam_kind :
269+ value = contextNode (-2 );
270+ Element prevContext = context ;
271+ context = localContext ;
272+ contextOpen ("kind" );
273+ moveHere (value );
274+ contextClose ();
275+ context = prevContext ;
276+ break ;
277+ default :
278+ throw new IllegalArgumentException (Integer .toString (attribute_type ));
279+ }
280+ }
281+ context = localContext ;
282+ if (value == null ) {
283+ contextClose ();
284+ context .removeChild (localContext );
285+ }
286+ super .char_selector (tk1 , tk2 , kindOrLen1 , kindOrLen2 , hasAsterisk );
287+ if (value != null )
288+ contextClose ();
289+ }
290+
243291 public void char_length (boolean hasTypeParamValue ) {
244292 Element value = contextNode (-1 );
245293 contextOpen ("length" );
246294 moveHere (value );
295+ if (hasTypeParamValue ) {
296+ moveHere (contextNodes (value ));
297+ context .removeChild (value );
298+ }
247299 super .char_length (hasTypeParamValue );
248300 contextClose ();
249301 }
@@ -353,6 +405,7 @@ public void declaration_type_spec(Token udtKeyword, int type) {
353405 contextOpen ("type" );
354406 setAttribute ("hasLength" , false );
355407 setAttribute ("hasKind" , false );
408+ setAttribute ("hasAttributes" , false );
356409 Attr n ;
357410 for (Element declaration : typeDeclarations ) {
358411 switch (declaration .getTagName ()) {
@@ -376,6 +429,9 @@ public void declaration_type_spec(Token udtKeyword, int type) {
376429 case "kind" :
377430 setAttribute ("hasKind" , true );
378431 break ;
432+ case "type-attributes" :
433+ setAttribute ("hasAttributes" , true );
434+ break ;
379435 default :
380436 break ;
381437 }
0 commit comments