11/*
2- * Copyright (C) 2013-2018 Samuel Audet
2+ * Copyright (C) 2013-2019 Samuel Audet
33 *
44 * Licensed either under the Apache License, Version 2.0, or (at your option)
55 * under the terms of the GNU General Public License as published by
@@ -207,9 +207,6 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
207207 if (valueType .constValue && !cast .startsWith ("const " )) {
208208 cast = "const " + cast ;
209209 }
210- if (valueType .constPointer && !cast .endsWith (" const" )) {
211- cast = cast + " const" ;
212- }
213210 if (valueType .indirections > 0 ) {
214211 for (int i = 0 ; i < valueType .indirections ; i ++) {
215212 cast += "*" ;
@@ -220,6 +217,9 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
220217 if (valueType .reference ) {
221218 cast += "&" ;
222219 }
220+ if (valueType .constPointer && !cast .endsWith (" const" )) {
221+ cast = cast + " const" ;
222+ }
223223 valueType .annotations = "@Cast(\" " + cast + "\" ) " + valueType .annotations ;
224224 }
225225 String arrayBrackets = "" ;
@@ -564,15 +564,15 @@ Type type(Context context, boolean definition) throws ParserException {
564564 if (t .constValue && !s .startsWith ("const " )) {
565565 s = "const " + s ;
566566 }
567- if (t .constPointer && !s .endsWith (" const" )) {
568- s = s + " const" ;
569- }
570567 for (int i = 0 ; i < t .indirections ; i ++) {
571568 s += "*" ;
572569 }
573570 if (t .reference ) {
574571 s += "&" ;
575572 }
573+ if (t .constPointer && !s .endsWith (" const" )) {
574+ s = s + " const" ;
575+ }
576576 type .cppName += s ;
577577 separator = "," ;
578578 }
@@ -709,6 +709,10 @@ Type type(Context context, boolean definition) throws ParserException {
709709 type .constValue = true ;
710710 type .cppName = type .cppName .substring (6 );
711711 }
712+ if (type .cppName .endsWith (" const" )) {
713+ type .constPointer = true ;
714+ type .cppName = type .cppName .substring (0 , type .cppName .length () - 6 );
715+ }
712716 if (type .cppName .endsWith ("*" )) {
713717 type .indirections ++;
714718 if (type .reference ) {
@@ -721,15 +725,16 @@ Type type(Context context, boolean definition) throws ParserException {
721725 type .cppName = type .cppName .substring (0 , type .cppName .length () - 1 );
722726 }
723727 if (type .cppName .endsWith (" const" )) {
724- type .constPointer = true ;
728+ type .constValue = true ;
725729 type .cppName = type .cppName .substring (0 , type .cppName .length () - 6 );
726730 }
727731
728732 Info info = null ;
729733 String shortName = type .cppName ;
730734 String [] names = context .qualify (type .cppName );
731735 if (definition && names .length > 0 ) {
732- String constName = type .constValue || type .constPointer ? "const " + names [0 ] : names [0 ];
736+ String constName = type .constValue ? "const " + names [0 ] : names [0 ];
737+ constName = type .constPointer ? constName + " const" : constName ;
733738 info = infoMap .getFirst (constName , false );
734739 type .cppName = names [0 ];
735740 } else {
@@ -745,7 +750,8 @@ Type type(Context context, boolean definition) throws ParserException {
745750 // skip, we would probably get Info for the constructors, not the type
746751 continue ;
747752 }
748- String constName = type .constValue || type .constPointer ? "const " + name : name ;
753+ String constName = type .constValue ? "const " + name : name ;
754+ constName = type .constPointer ? constName + " const" : constName ;
749755 if ((info = infoMap .getFirst (constName , false )) != null ) {
750756 type .cppName = name ;
751757 break ;
@@ -765,6 +771,10 @@ Type type(Context context, boolean definition) throws ParserException {
765771 type .constValue = true ;
766772 type .cppName = type .cppName .substring (6 );
767773 }
774+ if (type .cppName .endsWith (" const" )) {
775+ type .constPointer = true ;
776+ type .cppName = type .cppName .substring (0 , type .cppName .length () - 6 );
777+ }
768778 if (type .cppName .endsWith ("*" )) {
769779 type .indirections ++;
770780 if (type .reference ) {
@@ -777,7 +787,7 @@ Type type(Context context, boolean definition) throws ParserException {
777787 type .cppName = type .cppName .substring (0 , type .cppName .length () - 1 );
778788 }
779789 if (type .cppName .endsWith (" const" )) {
780- type .constPointer = true ;
790+ type .constValue = true ;
781791 type .cppName = type .cppName .substring (0 , type .cppName .length () - 6 );
782792 }
783793
@@ -1182,9 +1192,6 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole
11821192 if (type .constValue && !cast .startsWith ("const " )) {
11831193 cast = "const " + cast ;
11841194 }
1185- if (type .constPointer && !cast .endsWith (" const" )) {
1186- cast = cast + " const" ;
1187- }
11881195 if (type .indirections > 0 ) {
11891196 dcl .indirections += type .indirections ;
11901197 for (int i = 0 ; i < type .indirections ; i ++) {
@@ -1195,6 +1202,9 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole
11951202 dcl .reference = true ;
11961203 cast += "&" ;
11971204 }
1205+ if (type .constPointer && !cast .endsWith (" const" )) {
1206+ cast = cast + " const" ;
1207+ }
11981208 for (String s : info2 .annotations ) {
11991209 type .annotations += s + " " ;
12001210 }
@@ -1245,10 +1255,12 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole
12451255 }
12461256
12471257 if (!needCast && !type .javaName .contains ("@Cast" )) {
1248- if (type .constValue && !implicitConst && ! type . constPointer ) {
1258+ if (type .constValue && !implicitConst ) {
12491259 type .annotations = "@Const " + type .annotations ;
1250- } else if (type .constPointer ) {
1251- type .annotations = "@Const({" + type .constValue + ", " + type .constPointer + "}) " + type .annotations ;
1260+ }
1261+ if (type .constPointer ) {
1262+ // ignore, const pointers are not useful in generated code
1263+ // type.annotations = "@Const({" + type.constValue + ", " + type.constPointer + "}) " + type.annotations;
12521264 }
12531265 }
12541266 }
@@ -1371,6 +1383,13 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole
13711383 functionType = functionType .substring (functionType .lastIndexOf (' ' ) + 1 ); // get rid of pointer annotations
13721384 if (!functionType .equals ("Pointer" )) {
13731385 definition .type = new Type (functionType );
1386+ for (Info info2 : infoMap .get ("function/pointers" )) {
1387+ if (info2 != null && info2 .annotations != null ) {
1388+ for (String s : info2 .annotations ) {
1389+ definition .text += s + " " ;
1390+ }
1391+ }
1392+ }
13741393 definition .text += (tokens .get ().match (Token .CONST , Token .__CONST , Token .CONSTEXPR ) ? "@Const " : "" ) +
13751394 "public static class " + functionType + " extends FunctionPointer {\n " +
13761395 " static { Loader.load(); }\n " +
@@ -1923,9 +1942,6 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
19231942 if (d .type .constValue && !s .startsWith ("const " )) {
19241943 s = "const " + s ;
19251944 }
1926- if (d .type .constPointer && !s .endsWith (" const" )) {
1927- s = s + " const" ;
1928- }
19291945 if (d .indirections > 0 ) {
19301946 for (int i = 0 ; i < d .indirections ; i ++) {
19311947 s += "*" ;
@@ -1936,6 +1952,9 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
19361952 s += "&" ;
19371953 s2 += "&" ;
19381954 }
1955+ if (d .type .constPointer && !s .endsWith (" const" )) {
1956+ s = s + " const" ;
1957+ }
19391958 fullname += separator + s ;
19401959 fullname2 += separator + s2 ;
19411960 separator = ", " ;
@@ -2264,12 +2283,12 @@ boolean variable(Context context, DeclarationList declList) throws ParserExcepti
22642283 dcl .type .annotations = dcl .type .annotations .replaceAll ("@Name\\ (.*\\ ) " , "" );
22652284 javaName = metadcl .javaName + "_" + shortName ;
22662285 }
2267- if (dcl .type .constValue || dcl .constPointer ) {
2286+ if (( dcl .type .constValue && dcl . indirections == 0 ) || dcl .constPointer ) {
22682287 decl .text += "@MemberGetter " ;
22692288 }
22702289 decl .text += modifiers + dcl .type .annotations .replace ("@ByVal " , "@ByRef " )
22712290 + dcl .type .javaName + " " + javaName + "(" + indices + ");" ;
2272- if (!dcl .type .constValue && !dcl .constPointer ) {
2291+ if (!( dcl .type .constValue && dcl . indirections == 0 ) && !dcl .constPointer ) {
22732292 if (indices .length () > 0 ) {
22742293 indices += ", " ;
22752294 }
@@ -2650,9 +2669,6 @@ boolean typedef(Context context, DeclarationList declList) throws ParserExceptio
26502669 if (dcl .type .constValue && !s .startsWith ("const " )) {
26512670 s = "const " + s ;
26522671 }
2653- if (dcl .type .constPointer && !s .endsWith (" const" )) {
2654- s = s + " const" ;
2655- }
26562672 if (dcl .type .indirections > 0 ) {
26572673 for (int i = 0 ; i < dcl .type .indirections ; i ++) {
26582674 s += "*" ;
@@ -2661,6 +2677,9 @@ boolean typedef(Context context, DeclarationList declList) throws ParserExceptio
26612677 if (dcl .type .reference ) {
26622678 s += "&" ;
26632679 }
2680+ if (dcl .type .constPointer && !s .endsWith (" const" )) {
2681+ s = s + " const" ;
2682+ }
26642683 info .cppNames (defName , s ).cppTypes (s );
26652684 }
26662685 if (info .valueTypes == null && dcl .indirections > 0 ) {
@@ -3498,9 +3517,6 @@ void declarations(Context context, DeclarationList declList) throws ParserExcept
34983517 if (t .constValue && !s .startsWith ("const " )) {
34993518 s = "const " + s ;
35003519 }
3501- if (t .constPointer && !s .endsWith (" const" )) {
3502- s = s + " const" ;
3503- }
35043520 if (t .indirections > 0 ) {
35053521 for (int i = 0 ; i < t .indirections ; i ++) {
35063522 s += "*" ;
@@ -3509,6 +3525,9 @@ void declarations(Context context, DeclarationList declList) throws ParserExcept
35093525 if (t .reference ) {
35103526 s += "&" ;
35113527 }
3528+ if (t .constPointer && !s .endsWith (" const" )) {
3529+ s = s + " const" ;
3530+ }
35123531 t .cppName = s ;
35133532 e .setValue (t );
35143533 }
0 commit comments