|
1 | 1 | /* |
2 | | - * Copyright (C) 2013-2016 Samuel Audet |
| 2 | + * Copyright (C) 2013-2017 Samuel Audet |
3 | 3 | * |
4 | 4 | * Licensed either under the Apache License, Version 2.0, or (at your option) |
5 | 5 | * under the terms of the GNU General Public License as published by |
@@ -451,7 +451,9 @@ Type type(Context context) throws ParserException { |
451 | 451 | } |
452 | 452 | type.cppName += type.cppName.endsWith(">") ? " >" : ">"; |
453 | 453 | } else if (token.match(Token.CONST, Token.CONSTEXPR)) { |
454 | | - if (type.cppName.length() == 0) { |
| 454 | + int template = type.cppName.lastIndexOf('<'); |
| 455 | + String simpleName = template >= 0 ? type.cppName.substring(0, template) : type.cppName; |
| 456 | + if (!simpleName.trim().contains(" ") || type.simple) { |
455 | 457 | type.constValue = true; |
456 | 458 | } else { |
457 | 459 | type.constPointer = true; |
@@ -1003,8 +1005,8 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole |
1003 | 1005 | needCast |= info.cast && !type.cppName.equals(type.javaName); |
1004 | 1006 | } |
1005 | 1007 |
|
1006 | | - if (!valueType) { |
1007 | | - if (dcl.indirections == 0 && !dcl.reference) { |
| 1008 | + if (!valueType || context.virtualize) { |
| 1009 | + if (!valueType && dcl.indirections == 0 && !dcl.reference) { |
1008 | 1010 | type.annotations += "@ByVal "; |
1009 | 1011 | } else if (dcl.indirections == 0 && dcl.reference) { |
1010 | 1012 | if (type.javaName.contains("@ByPtrPtr ")) { |
@@ -1389,7 +1391,8 @@ String commentAfter() throws ParserException { |
1389 | 1391 | } |
1390 | 1392 |
|
1391 | 1393 | Attribute attribute() throws ParserException { |
1392 | | - if (!tokens.get().match(Token.IDENTIFIER)) { |
| 1394 | + // attributes might have arguments that start with '(', but not '<' |
| 1395 | + if (!tokens.get().match(Token.IDENTIFIER) || tokens.get(1).match('<')) { |
1393 | 1396 | return null; |
1394 | 1397 | } |
1395 | 1398 | Attribute attr = new Attribute(); |
@@ -1555,6 +1558,12 @@ Parameters parameters(Context context, int infoNumber, boolean useDefaults) thro |
1555 | 1558 | tokens.next(); |
1556 | 1559 | } |
1557 | 1560 | } |
| 1561 | + if (dcls.size() == 1 && (dcls.get(0) == null || dcls.get(0).type == null |
| 1562 | + || dcls.get(0).type.cppName == null || dcls.get(0).type.cppName.length() == 0)) { |
| 1563 | + // this looks more like a variable initialization |
| 1564 | + tokens.index = backIndex; |
| 1565 | + return null; |
| 1566 | + } |
1558 | 1567 | params.declarators = dcls.toArray(new Declarator[dcls.size()]); |
1559 | 1568 | return params; |
1560 | 1569 | } |
@@ -1828,7 +1837,7 @@ boolean variable(Context context, DeclarationList declList) throws ParserExcepti |
1828 | 1837 | Declaration decl = new Declaration(); |
1829 | 1838 | String cppName = dcl.cppName; |
1830 | 1839 | String javaName = dcl.javaName; |
1831 | | - if (javaName == null || !tokens.get().match('[', '=', ',', ':', ';')) { |
| 1840 | + if (javaName == null || !tokens.get().match('(', '[', '=', ',', ':', ';')) { |
1832 | 1841 | tokens.index = backIndex; |
1833 | 1842 | return false; |
1834 | 1843 | } else if (!dcl.type.staticMember && context.javaName != null) { |
@@ -2138,11 +2147,22 @@ boolean macro(Context context, DeclarationList declList) throws ParserException |
2138 | 2147 |
|
2139 | 2148 | boolean typedef(Context context, DeclarationList declList) throws ParserException { |
2140 | 2149 | String spacing = tokens.get().spacing; |
2141 | | - if (!tokens.get().match(Token.TYPEDEF)) { |
| 2150 | + // the "using" token can also act as a "typedef" |
| 2151 | + String usingDefName = tokens.get().match(Token.USING) && tokens.get(1).match(Token.IDENTIFIER) |
| 2152 | + && tokens.get(2).match('=') ? tokens.get(1).value : null; |
| 2153 | + if (!tokens.get().match(Token.TYPEDEF) && usingDefName == null) { |
2142 | 2154 | return false; |
2143 | 2155 | } |
2144 | 2156 | Declaration decl = new Declaration(); |
| 2157 | + if (usingDefName != null) { |
| 2158 | + tokens.next().expect(Token.IDENTIFIER); |
| 2159 | + tokens.next().expect('='); |
| 2160 | + tokens.next(); |
| 2161 | + } |
2145 | 2162 | Declarator dcl = declarator(context, null, 0, false, 0, true, false); |
| 2163 | + if (usingDefName != null) { |
| 2164 | + dcl.cppName = usingDefName; |
| 2165 | + } |
2146 | 2166 | tokens.next(); |
2147 | 2167 |
|
2148 | 2168 | String typeName = dcl.type.cppName, defName = dcl.cppName; |
@@ -2210,7 +2230,14 @@ boolean typedef(Context context, DeclarationList declList) throws ParserExceptio |
2210 | 2230 | info.pointerTypes(typeName); |
2211 | 2231 | } |
2212 | 2232 | if (info.annotations == null) { |
2213 | | - info.cast(!dcl.cppName.equals(info.pointerTypes[0])); |
| 2233 | + if (dcl.type.annotations != null && dcl.type.annotations.length() > 0 |
| 2234 | + && !dcl.type.annotations.startsWith("@ByVal ") |
| 2235 | + && !dcl.type.annotations.startsWith("@Cast(") |
| 2236 | + && !dcl.type.annotations.startsWith("@Const ")) { |
| 2237 | + info.annotations(dcl.type.annotations.trim()); |
| 2238 | + } else { |
| 2239 | + info.cast(!dcl.cppName.equals(info.pointerTypes[0])); |
| 2240 | + } |
2214 | 2241 | } |
2215 | 2242 | infoMap.put(info); |
2216 | 2243 | } |
|
0 commit comments