From b9e1e20ba43ea299739a5217cce2eea0288c9059 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 18 Dec 2023 13:18:37 +0100 Subject: [PATCH 01/11] added code for NYI alias templates in the type resolver, but also extended the AST to typesymbol mapper with the mapping id of the declared alias template --- src/lang/cpp/TypeSymbol.rsc | 2 +- src/lang/cpp/internal/AST.java | 32 +++++++++-------- src/lang/cpp/internal/BindingsResolver.java | 10 ++++++ src/lang/cpp/internal/TypeResolver.java | 39 +++++++++++++++------ 4 files changed, 58 insertions(+), 25 deletions(-) diff --git a/src/lang/cpp/TypeSymbol.rsc b/src/lang/cpp/TypeSymbol.rsc index 060b4349..6d567343 100644 --- a/src/lang/cpp/TypeSymbol.rsc +++ b/src/lang/cpp/TypeSymbol.rsc @@ -75,7 +75,7 @@ data TypeSymbol | \functionTemplate(loc decl, list[loc] templateParameters) | \variableTemplate(loc decl, list[loc] templateParameters) - | \aliasTemplate(loc decl, list[loc] templateParameters) + | \aliasTemplate(loc decl, list[TypeSymbol] templateArguments, TypeSymbol \type) | \functionSetType(loc decl, list[TypeSymbol] templateArguments) | \functionSetTypePointer(loc decl, list[TypeSymbol] templateArguments) diff --git a/src/lang/cpp/internal/AST.java b/src/lang/cpp/internal/AST.java index a276ad11..84c54534 100644 --- a/src/lang/cpp/internal/AST.java +++ b/src/lang/cpp/internal/AST.java @@ -774,10 +774,10 @@ public AST (IValueFactory vf) { = tf.constructor(typestore,_TypeSymbol,"struct",tf.sourceLocationType(),"decl"); private static final Type _TypeSymbol_array_2 = tf.constructor(typestore,_TypeSymbol,"array",_TypeSymbol,"baseType",tf.integerType(),"size"); - private static final Type _TypeSymbol_aliasTemplate_2 - = tf.constructor(typestore,_TypeSymbol,"aliasTemplate",tf.sourceLocationType(),"decl",tf.listType(tf.sourceLocationType()),"templateParameters"); private static final Type _TypeSymbol_nullPtr_0 = tf.constructor(typestore,_TypeSymbol,"nullPtr"); + private static final Type _TypeSymbol_aliasTemplate_3 + = tf.constructor(typestore,_TypeSymbol,"aliasTemplate",tf.sourceLocationType(),"decl",tf.listType(_TypeSymbol),"templateArguments",_TypeSymbol,"type"); private static final Type _TypeSymbol_decimal128_0 = tf.constructor(typestore,_TypeSymbol,"decimal128"); private static final Type _TypeSymbol_basicType_2 @@ -6993,15 +6993,7 @@ public IConstructor TypeSymbol_array(IConstructor $baseType, IValue $size) { return vf.constructor(_TypeSymbol_array_2 , $baseType, $size).asWithKeywordParameters().setParameters(kwParams); } - public IConstructor TypeSymbol_aliasTemplate(ISourceLocation $decl, IList $templateParameters) { - - if (!$decl.getType().isSubtypeOf(tf.sourceLocationType())) { - throw new IllegalArgumentException("Expected " + tf.sourceLocationType() + " but got " + $decl.getType() + " for $decl:" + $decl); - } - - if (!$templateParameters.getType().isSubtypeOf(tf.listType(tf.sourceLocationType()))) { - throw new IllegalArgumentException("Expected " + tf.listType(tf.sourceLocationType()) + " but got " + $templateParameters.getType() + " for $templateParameters:" + $templateParameters); - } + public IConstructor TypeSymbol_nullPtr() { Map kwParams = new HashMap(); @@ -7009,10 +7001,22 @@ public IConstructor TypeSymbol_aliasTemplate(ISourceLocation $decl, IList $templ - return vf.constructor(_TypeSymbol_aliasTemplate_2 , $decl, $templateParameters).asWithKeywordParameters().setParameters(kwParams); + return vf.constructor(_TypeSymbol_nullPtr_0 ).asWithKeywordParameters().setParameters(kwParams); } - public IConstructor TypeSymbol_nullPtr() { + public IConstructor TypeSymbol_aliasTemplate(ISourceLocation $decl, IList $templateArguments, IConstructor $type) { + + if (!$decl.getType().isSubtypeOf(tf.sourceLocationType())) { + throw new IllegalArgumentException("Expected " + tf.sourceLocationType() + " but got " + $decl.getType() + " for $decl:" + $decl); + } + + if (!$templateArguments.getType().isSubtypeOf(tf.listType(_TypeSymbol))) { + throw new IllegalArgumentException("Expected " + tf.listType(_TypeSymbol) + " but got " + $templateArguments.getType() + " for $templateArguments:" + $templateArguments); + } + + if (!$type.getType().isSubtypeOf(_TypeSymbol)) { + throw new IllegalArgumentException("Expected " + _TypeSymbol + " but got " + $type.getType() + " for $type:" + $type); + } Map kwParams = new HashMap(); @@ -7020,7 +7024,7 @@ public IConstructor TypeSymbol_nullPtr() { - return vf.constructor(_TypeSymbol_nullPtr_0 ).asWithKeywordParameters().setParameters(kwParams); + return vf.constructor(_TypeSymbol_aliasTemplate_3 , $decl, $templateArguments, $type).asWithKeywordParameters().setParameters(kwParams); } public IConstructor TypeSymbol_decimal128() { diff --git a/src/lang/cpp/internal/BindingsResolver.java b/src/lang/cpp/internal/BindingsResolver.java index 4ad73acd..f9d886cc 100644 --- a/src/lang/cpp/internal/BindingsResolver.java +++ b/src/lang/cpp/internal/BindingsResolver.java @@ -840,6 +840,16 @@ public ISourceLocation resolveBinding(IASTNameOwner node, ISourceLocation origin return failedBinding("unknown"); } + public ISourceLocation resolveBinding(ICPPBinding binding, ISourceLocation origin) { + try { + return resolveICPPBinding(binding, origin); + } catch (URISyntaxException e) { + err(e.getMessage()); + } + + return failedBinding("unknown"); + } + private ISourceLocation resolveUsingDeclaration(ICPPASTUsingDeclaration node) throws URISyntaxException { return resolveBinding(node, node.getName().resolveBinding(), getSourceLocation(node)); } diff --git a/src/lang/cpp/internal/TypeResolver.java b/src/lang/cpp/internal/TypeResolver.java index f569c080..bf99ce53 100644 --- a/src/lang/cpp/internal/TypeResolver.java +++ b/src/lang/cpp/internal/TypeResolver.java @@ -49,6 +49,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance; @@ -61,6 +62,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTypeSpecialization; @@ -116,24 +118,32 @@ private ISourceLocation getDecl(IBinding binding, ISourceLocation origin) { } private IList handleTemplateParameters(ICPPASTTemplateDeclaration declaration) { - IListWriter parameters = vf.listWriter(); - Stream.of(declaration.getTemplateParameters()).forEach(it -> { + return handleTemplateParameters(declaration.getTemplateParameters()); + } + + private IList handleTemplateParameters(ICPPASTTemplateParameter[] params) { + return Stream.of(params).map(it -> { if (it instanceof ICPPASTSimpleTypeTemplateParameter) { - parameters.append(br.resolveBinding(((ICPPASTSimpleTypeTemplateParameter) it), locs.forNode(it))); + return br.resolveBinding(((ICPPASTSimpleTypeTemplateParameter) it), locs.forNode(it)); } else if (it instanceof ICPPASTTemplatedTypeTemplateParameter) { - parameters.append(br.resolveBinding((ICPPASTTemplatedTypeTemplateParameter) it, locs.forNode(it))); + return br.resolveBinding((ICPPASTTemplatedTypeTemplateParameter) it, locs.forNode(it)); } else if (it instanceof ICPPASTParameterDeclaration) { // default values needed? - parameters.append(getDecl(((ICPPASTParameterDeclaration) it).getDeclarator().getName().resolveBinding(), locs.forNode(it))); + return getDecl(((ICPPASTParameterDeclaration) it).getDeclarator().getName().resolveBinding(), locs.forNode(it)); } else { throw new RuntimeException( - "Encountered unknown template parameter type " + it.getClass().getSimpleName() + " @ " + locs.forNode(declaration)); + "Encountered unknown template parameter type " + it.getClass().getSimpleName() + " @ " + locs.forNode(it)); } - }); - return parameters.done(); + }).collect(vf.listWriter()); + } + + private IList handleTemplateParameters(ICPPTemplateParameter[] params, ISourceLocation origin) { + return Stream.of(params) + .map(it -> br.resolveBinding(it, origin)) + .collect(vf.listWriter()); } public IConstructor resolveType(IASTNode node) { @@ -235,7 +245,11 @@ private IConstructor resolveICPPASTTemplateDeclaration(ICPPASTTemplateDeclaratio return builder.TypeSymbol_templateTemplate(templatedTemplate, handleTemplateParameters(node)); } else if (declaration instanceof ICPPASTAliasDeclaration) { IBinding binding = ((ICPPASTAliasDeclaration) declaration).getAlias().resolveBinding(); - return builder.TypeSymbol_aliasTemplate(getDecl(binding, locs.forNode(declaration)), handleTemplateParameters(node)); + return builder.TypeSymbol_aliasTemplate( + getDecl(binding, locs.forNode(declaration)), + handleTemplateParameters(node), + resolveType(((ICPPASTAliasDeclaration) declaration).getMappingTypeId()) + ); } else { throw new RuntimeException("Unknown template declaree at " + locs.forNode(node)); } @@ -550,7 +564,12 @@ private IConstructor resolveICPPUnknownMemberClass(ICPPUnknownMemberClass type, } private IConstructor resolveICPPAliasTemplate(ICPPAliasTemplate type, ISourceLocation origin) { - throw new RuntimeException("NYI: resolveICPPAliasTemplate @ " + origin); + IList params = handleTemplateParameters(type.getTemplateParameters(), origin); + + ISourceLocation decl = br.resolveBinding(type, origin); + IConstructor definedType = resolveType(type.getType(), origin); + + return builder.TypeSymbol_aliasTemplate(decl, params, definedType); } private IConstructor resolveICPPParameterPackType(ICPPParameterPackType type, ISourceLocation origin) { From aa17e71293951885ed22aca109eacab67adde434 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 18 Dec 2023 13:43:36 +0100 Subject: [PATCH 02/11] fixed another NYI --- src/lang/cpp/internal/TypeResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang/cpp/internal/TypeResolver.java b/src/lang/cpp/internal/TypeResolver.java index bf99ce53..2cf37a25 100644 --- a/src/lang/cpp/internal/TypeResolver.java +++ b/src/lang/cpp/internal/TypeResolver.java @@ -484,7 +484,7 @@ private IConstructor resolveICompositeType(ICompositeType type, ISourceLocation return resolveICPPUnknownMemberClass((ICPPUnknownMemberClass) type, origin); } if (type instanceof IPDOMCPPClassType) { - throw new RuntimeException("NYI: resolveICompositeType " + type + " @ " + origin); + return resolveICPPClassType((ICPPClassType) type, origin); } if (type instanceof ICPPClassType) { return resolveICPPClassType((ICPPClassType) type, origin); From ecf94ac8aefbc04cf4c81db5039592a16dfd86e0 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Mon, 18 Dec 2023 14:05:30 +0100 Subject: [PATCH 03/11] minor refactoring --- src/lang/cpp/internal/TypeResolver.java | 55 +++++++++++-------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/src/lang/cpp/internal/TypeResolver.java b/src/lang/cpp/internal/TypeResolver.java index 2cf37a25..35466fa1 100644 --- a/src/lang/cpp/internal/TypeResolver.java +++ b/src/lang/cpp/internal/TypeResolver.java @@ -515,20 +515,10 @@ private IConstructor resolveICPPClassType(ICPPClassType type, ISourceLocation or private IConstructor resolveICPPClassSpecialization(ICPPClassSpecialization type, ISourceLocation origin) { ISourceLocation decl = getDecl(type.getSpecializedBinding(), origin); - IListWriter templateParameters = vf.listWriter(); ICPPTemplateParameterMap parameterMap = type.getTemplateParameterMap(); - Stream.of(parameterMap.getAllParameterPositions()).forEach(it -> { - ICPPTemplateArgument arg = parameterMap.getArgument(it); - if (arg != null) { - if (arg.isTypeValue()) { - templateParameters.append(resolveType(arg.getTypeValue(), origin)); - } - else { - templateParameters.append(resolveType(arg.getNonTypeEvaluation().getType(), origin)); - } - } - }); - return builder.TypeSymbol_classSpecialization(decl, templateParameters.done()); + IList templateParameters = resolveArguments(streamArguments(parameterMap), origin).collect(vf.listWriter()); + + return builder.TypeSymbol_classSpecialization(decl, templateParameters); } private IConstructor resolveICPPClassTemplate(ICPPClassTemplate type, ISourceLocation origin) { @@ -708,28 +698,31 @@ private IConstructor resolveITypeContainer(ITypeContainer type, ISourceLocation return builder.TypeSymbol_typeContainer(resolveType(type.getType(), origin)); } - private IConstructor resolveITypedef(ITypedef type, ISourceLocation origin) { - if (type instanceof ICPPAliasTemplateInstance) { - ICPPAliasTemplateInstance ati = (ICPPAliasTemplateInstance) type; - IListWriter templateParameters = vf.listWriter(); - - ICPPTemplateParameterMap parameterMap = ati.getTemplateParameterMap(); - Stream.of(parameterMap.getAllParameterPositions()).forEach(it -> { - ICPPTemplateArgument arg = parameterMap.getArgument(it); - if (arg != null) { - if (arg.isTypeValue()) { - templateParameters.append(resolveType(arg.getTypeValue(), origin)); - } - else { - templateParameters.append(resolveType(arg.getNonTypeEvaluation().getType(), origin)); - } - } + private Stream resolveArguments(Stream stream, ISourceLocation origin) { + return stream + .filter(arg -> arg != null) + .map(arg -> { + if (arg.isTypeValue()) { + return resolveType(arg.getTypeValue(), origin); + } else { - stdOut.println("WARNING: ignoring 'null' parameter in alias template instance at " + origin); + return resolveType(arg.getNonTypeEvaluation().getType(), origin); } }); + } + + private Stream streamArguments(ICPPTemplateParameterMap parameterMap) { + return Stream.of(parameterMap.getAllParameterPositions()).map(it -> parameterMap.getArgument(it)); + } - return builder.TypeSymbol_aliasTemplateInstance(getDecl(ati.getSpecializedBinding(), origin), templateParameters.done()); + private IConstructor resolveITypedef(ITypedef type, ISourceLocation origin) { + if (type instanceof ICPPAliasTemplateInstance) { + ICPPAliasTemplateInstance ati = (ICPPAliasTemplateInstance) type; + IList templateParameters = + resolveArguments(streamArguments(ati.getTemplateParameterMap()), origin) + .collect(vf.listWriter()); + + return builder.TypeSymbol_aliasTemplateInstance(getDecl(ati.getSpecializedBinding(), origin), templateParameters); } return builder.TypeSymbol_typedef(resolveType(type.getType(), origin)); From 395b6823cc137a5037c8aed74a0d41c2239327ba Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 19 Dec 2023 14:04:21 +0100 Subject: [PATCH 04/11] testing and fixing with real code example from @linus --- src/lang/cpp/AST.rsc | 59 +++++++++++++- src/lang/cpp/TypeSymbol.rsc | 2 +- src/lang/cpp/internal/AST.java | 86 ++++++++++----------- src/lang/cpp/internal/BindingsResolver.java | 2 +- src/lang/cpp/internal/Parser.java | 31 -------- 5 files changed, 103 insertions(+), 77 deletions(-) diff --git a/src/lang/cpp/AST.rsc b/src/lang/cpp/AST.rsc index b7933eff..e8a26f8c 100644 --- a/src/lang/cpp/AST.rsc +++ b/src/lang/cpp/AST.rsc @@ -552,4 +552,61 @@ java list[loc] parseForComments(loc file, str charset=DEFAULT_CHARSET, bool infe java rel[loc,loc] parseForMacros(loc file, str charset=DEFAULT_CHARSET, bool inferCharset=!(charset?), list[loc] includePaths = classPaths["vs12"], map[str,str] standardMacros=provideStandardMacros(), map[str,str] additionalMacros = ()); @synopsis{All functions in this module that have a charset parameter use this as default.} -public str DEFAULT_CHARSET = "UTF-8"; \ No newline at end of file +public str DEFAULT_CHARSET = "UTF-8"; + +public map[str, str] linusMacros = ( + "_M_IX86": "600", + //"_WIN32": "1", + // "_MSC_VER": "1400" + "__cdecl": "", + "__fastcall": "", + "__restrict": "", + "__sptr": "", + "__stdcall": "", + + + "__unaligned": "", + "__uptr": "", + "__w64": "", + "__forceinline": "__inline", + "__int8": "char", + "__int16": "short", + "__int32": "int", + "__int64": "long long", + + // additional: + //"_MSC_VER": "1700", + "__cplusplus": "199711L", + "__thiscall": "", + "_CHAR16T": "", + "_NATIVE_WCHAR_T_DEFINED": "1", + "__nullptr": "nullptr", + //"_MSC_EXTENSIONS": "1", + "__inline": "inline", + "__ptr32": "", + "__ptr64": "", + "__interface": "struct", + + "__pragma(A)": "", + "__identifier(A)": "A", + + +// "__declspec(A)": "", + "_stdcall": "", + + "_USE_DECLSPECS_FOR_SAL": "0", + //"_DLL": "1", + + "NDEBUG": "", + //"WIN32": "", + //"_WINDOWS": "", + //"_WIN32_DCOM": "", + //"_USRDLL": "", + "SSCF1_INCLUDED": "", + "LOGGINGTRACING_INCLUDED": "", + //"_WINDLL": "", + "_UNICODE": "", + "UNICODE": "" + //"_AFXDLL": "" +// "__INTELLISENSE__": "1" +); diff --git a/src/lang/cpp/TypeSymbol.rsc b/src/lang/cpp/TypeSymbol.rsc index 6d567343..d6925ff1 100644 --- a/src/lang/cpp/TypeSymbol.rsc +++ b/src/lang/cpp/TypeSymbol.rsc @@ -75,7 +75,7 @@ data TypeSymbol | \functionTemplate(loc decl, list[loc] templateParameters) | \variableTemplate(loc decl, list[loc] templateParameters) - | \aliasTemplate(loc decl, list[TypeSymbol] templateArguments, TypeSymbol \type) + | \aliasTemplate(loc decl, list[loc] templateParameters, TypeSymbol \type) | \functionSetType(loc decl, list[TypeSymbol] templateArguments) | \functionSetTypePointer(loc decl, list[TypeSymbol] templateArguments) diff --git a/src/lang/cpp/internal/AST.java b/src/lang/cpp/internal/AST.java index 84c54534..5989d470 100644 --- a/src/lang/cpp/internal/AST.java +++ b/src/lang/cpp/internal/AST.java @@ -684,8 +684,6 @@ public AST (IValueFactory vf) { = tf.constructor(typestore,_TypeSymbol,"eClassTemplate",tf.sourceLocationType(),"decl",tf.listType(tf.sourceLocationType()),"templateParameters"); private static final Type _TypeSymbol_templateTypeParameter_2 = tf.constructor(typestore,_TypeSymbol,"templateTypeParameter",tf.sourceLocationType(),"owner",tf.sourceLocationType(),"decl"); - private static final Type _TypeSymbol_cClassTemplate_2 - = tf.constructor(typestore,_TypeSymbol,"cClassTemplate",tf.sourceLocationType(),"decl",tf.listType(tf.sourceLocationType()),"templateParameters"); private static final Type _TypeSymbol_deferredClassInstance_1 = tf.constructor(typestore,_TypeSymbol,"deferredClassInstance",tf.stringType(),"name"); private static final Type _TypeSymbol_functionType_2 @@ -770,14 +768,16 @@ public AST (IValueFactory vf) { = tf.constructor(typestore,_TypeSymbol,"aliasTemplateInstance",tf.sourceLocationType(),"instantiatedTemplate",tf.listType(_TypeSymbol),"templateArguments"); private static final Type _TypeSymbol_int_0 = tf.constructor(typestore,_TypeSymbol,"int"); + private static final Type _TypeSymbol_aliasTemplate_3 + = tf.constructor(typestore,_TypeSymbol,"aliasTemplate",tf.sourceLocationType(),"decl",tf.listType(tf.sourceLocationType()),"templateParameters",_TypeSymbol,"type"); + private static final Type _TypeSymbol_cClassTemplate_2 + = tf.constructor(typestore,_TypeSymbol,"cClassTemplate",tf.sourceLocationType(),"decl",tf.listType(tf.sourceLocationType()),"templateParameters"); private static final Type _TypeSymbol_struct_1 = tf.constructor(typestore,_TypeSymbol,"struct",tf.sourceLocationType(),"decl"); private static final Type _TypeSymbol_array_2 = tf.constructor(typestore,_TypeSymbol,"array",_TypeSymbol,"baseType",tf.integerType(),"size"); private static final Type _TypeSymbol_nullPtr_0 = tf.constructor(typestore,_TypeSymbol,"nullPtr"); - private static final Type _TypeSymbol_aliasTemplate_3 - = tf.constructor(typestore,_TypeSymbol,"aliasTemplate",tf.sourceLocationType(),"decl",tf.listType(_TypeSymbol),"templateArguments",_TypeSymbol,"type"); private static final Type _TypeSymbol_decimal128_0 = tf.constructor(typestore,_TypeSymbol,"decimal128"); private static final Type _TypeSymbol_basicType_2 @@ -6298,25 +6298,6 @@ public IConstructor TypeSymbol_templateTypeParameter(ISourceLocation $owner, ISo return vf.constructor(_TypeSymbol_templateTypeParameter_2 , $owner, $decl).asWithKeywordParameters().setParameters(kwParams); } - public IConstructor TypeSymbol_cClassTemplate(ISourceLocation $decl, IList $templateParameters) { - - if (!$decl.getType().isSubtypeOf(tf.sourceLocationType())) { - throw new IllegalArgumentException("Expected " + tf.sourceLocationType() + " but got " + $decl.getType() + " for $decl:" + $decl); - } - - if (!$templateParameters.getType().isSubtypeOf(tf.listType(tf.sourceLocationType()))) { - throw new IllegalArgumentException("Expected " + tf.listType(tf.sourceLocationType()) + " but got " + $templateParameters.getType() + " for $templateParameters:" + $templateParameters); - } - - Map kwParams = new HashMap(); - - - - - - return vf.constructor(_TypeSymbol_cClassTemplate_2 , $decl, $templateParameters).asWithKeywordParameters().setParameters(kwParams); - } - public IConstructor TypeSymbol_deferredClassInstance(String $name) { if (!vf.string($name).getType().isSubtypeOf(tf.stringType())) { @@ -6959,11 +6940,19 @@ public IConstructor TypeSymbol_int() { return vf.constructor(_TypeSymbol_int_0 ).asWithKeywordParameters().setParameters(kwParams); } - public IConstructor TypeSymbol_struct(ISourceLocation $decl) { + public IConstructor TypeSymbol_aliasTemplate(ISourceLocation $decl, IList $templateParameters, IConstructor $type) { if (!$decl.getType().isSubtypeOf(tf.sourceLocationType())) { throw new IllegalArgumentException("Expected " + tf.sourceLocationType() + " but got " + $decl.getType() + " for $decl:" + $decl); } + + if (!$templateParameters.getType().isSubtypeOf(tf.listType(tf.sourceLocationType()))) { + throw new IllegalArgumentException("Expected " + tf.listType(tf.sourceLocationType()) + " but got " + $templateParameters.getType() + " for $templateParameters:" + $templateParameters); + } + + if (!$type.getType().isSubtypeOf(_TypeSymbol)) { + throw new IllegalArgumentException("Expected " + _TypeSymbol + " but got " + $type.getType() + " for $type:" + $type); + } Map kwParams = new HashMap(); @@ -6971,17 +6960,17 @@ public IConstructor TypeSymbol_struct(ISourceLocation $decl) { - return vf.constructor(_TypeSymbol_struct_1 , $decl).asWithKeywordParameters().setParameters(kwParams); + return vf.constructor(_TypeSymbol_aliasTemplate_3 , $decl, $templateParameters, $type).asWithKeywordParameters().setParameters(kwParams); } - public IConstructor TypeSymbol_array(IConstructor $baseType, IValue $size) { + public IConstructor TypeSymbol_cClassTemplate(ISourceLocation $decl, IList $templateParameters) { - if (!$baseType.getType().isSubtypeOf(_TypeSymbol)) { - throw new IllegalArgumentException("Expected " + _TypeSymbol + " but got " + $baseType.getType() + " for $baseType:" + $baseType); + if (!$decl.getType().isSubtypeOf(tf.sourceLocationType())) { + throw new IllegalArgumentException("Expected " + tf.sourceLocationType() + " but got " + $decl.getType() + " for $decl:" + $decl); } - if (!$size.getType().isSubtypeOf(tf.integerType())) { - throw new IllegalArgumentException("Expected " + tf.integerType() + " but got " + $size.getType() + " for $size:" + $size); + if (!$templateParameters.getType().isSubtypeOf(tf.listType(tf.sourceLocationType()))) { + throw new IllegalArgumentException("Expected " + tf.listType(tf.sourceLocationType()) + " but got " + $templateParameters.getType() + " for $templateParameters:" + $templateParameters); } Map kwParams = new HashMap(); @@ -6990,10 +6979,14 @@ public IConstructor TypeSymbol_array(IConstructor $baseType, IValue $size) { - return vf.constructor(_TypeSymbol_array_2 , $baseType, $size).asWithKeywordParameters().setParameters(kwParams); + return vf.constructor(_TypeSymbol_cClassTemplate_2 , $decl, $templateParameters).asWithKeywordParameters().setParameters(kwParams); } - public IConstructor TypeSymbol_nullPtr() { + public IConstructor TypeSymbol_struct(ISourceLocation $decl) { + + if (!$decl.getType().isSubtypeOf(tf.sourceLocationType())) { + throw new IllegalArgumentException("Expected " + tf.sourceLocationType() + " but got " + $decl.getType() + " for $decl:" + $decl); + } Map kwParams = new HashMap(); @@ -7001,21 +6994,17 @@ public IConstructor TypeSymbol_nullPtr() { - return vf.constructor(_TypeSymbol_nullPtr_0 ).asWithKeywordParameters().setParameters(kwParams); + return vf.constructor(_TypeSymbol_struct_1 , $decl).asWithKeywordParameters().setParameters(kwParams); } - public IConstructor TypeSymbol_aliasTemplate(ISourceLocation $decl, IList $templateArguments, IConstructor $type) { - - if (!$decl.getType().isSubtypeOf(tf.sourceLocationType())) { - throw new IllegalArgumentException("Expected " + tf.sourceLocationType() + " but got " + $decl.getType() + " for $decl:" + $decl); - } + public IConstructor TypeSymbol_array(IConstructor $baseType, IValue $size) { - if (!$templateArguments.getType().isSubtypeOf(tf.listType(_TypeSymbol))) { - throw new IllegalArgumentException("Expected " + tf.listType(_TypeSymbol) + " but got " + $templateArguments.getType() + " for $templateArguments:" + $templateArguments); + if (!$baseType.getType().isSubtypeOf(_TypeSymbol)) { + throw new IllegalArgumentException("Expected " + _TypeSymbol + " but got " + $baseType.getType() + " for $baseType:" + $baseType); } - if (!$type.getType().isSubtypeOf(_TypeSymbol)) { - throw new IllegalArgumentException("Expected " + _TypeSymbol + " but got " + $type.getType() + " for $type:" + $type); + if (!$size.getType().isSubtypeOf(tf.integerType())) { + throw new IllegalArgumentException("Expected " + tf.integerType() + " but got " + $size.getType() + " for $size:" + $size); } Map kwParams = new HashMap(); @@ -7024,7 +7013,18 @@ public IConstructor TypeSymbol_aliasTemplate(ISourceLocation $decl, IList $templ - return vf.constructor(_TypeSymbol_aliasTemplate_3 , $decl, $templateArguments, $type).asWithKeywordParameters().setParameters(kwParams); + return vf.constructor(_TypeSymbol_array_2 , $baseType, $size).asWithKeywordParameters().setParameters(kwParams); + } + + public IConstructor TypeSymbol_nullPtr() { + + Map kwParams = new HashMap(); + + + + + + return vf.constructor(_TypeSymbol_nullPtr_0 ).asWithKeywordParameters().setParameters(kwParams); } public IConstructor TypeSymbol_decimal128() { diff --git a/src/lang/cpp/internal/BindingsResolver.java b/src/lang/cpp/internal/BindingsResolver.java index f9d886cc..102feca5 100644 --- a/src/lang/cpp/internal/BindingsResolver.java +++ b/src/lang/cpp/internal/BindingsResolver.java @@ -376,7 +376,7 @@ private ISourceLocation resolveIEnumeration(IEnumeration binding, ISourceLocatio throw new RuntimeException("NYI" + binding.getClass().getSimpleName() + ": " + binding + " @ " + origin); } - private ISourceLocation resolveICPPBinding(ICPPBinding binding, ISourceLocation origin) throws URISyntaxException { + public ISourceLocation resolveICPPBinding(ICPPBinding binding, ISourceLocation origin) throws URISyntaxException { if (binding instanceof ICPPAliasTemplateInstance) { return resolveICPPAliasTemplateInstance((ICPPAliasTemplateInstance) binding, origin); } diff --git a/src/lang/cpp/internal/Parser.java b/src/lang/cpp/internal/Parser.java index a9b28116..0ec42172 100644 --- a/src/lang/cpp/internal/Parser.java +++ b/src/lang/cpp/internal/Parser.java @@ -54,7 +54,6 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; -import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; @@ -142,7 +141,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression.CaptureDefault; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; @@ -1459,29 +1457,6 @@ private int visit(ICPPASTDesignatedInitializer initializer) { return PROCESS_ABORT; } - // InitializerClauses - private int visit(IASTInitializerClause initializerClause) { - at(initializerClause); - if (initializerClause instanceof IASTExpression) - visit((IASTExpression) initializerClause); - else if (initializerClause instanceof IASTInitializerList) - visit((IASTInitializerList) initializerClause); - else if (initializerClause instanceof ICASTDesignatedInitializer) - visit((ICASTDesignatedInitializer) initializerClause); - else if (initializerClause instanceof ICPPASTInitializerClause) - visit((ICPPASTInitializerClause) initializerClause); - else - throw new RuntimeException( - "Unknown IASTInitializerClause subclass " + initializerClause.getClass().getName() + " at " - + locs.forNode(initializerClause) + ". Exiting"); - return PROCESS_ABORT; - } - - private int visit(ICPPASTInitializerClause initializer) { - err("ICPPASTInitializerClause: " + initializer.getRawSignature()); - throw new RuntimeException("NYI at " + locs.forNode(initializer)); - } - // Declarators @Override @@ -1557,12 +1532,6 @@ private int visit(IASTArrayDeclarator declarator) { return PROCESS_ABORT; } - private int visit(IASTFieldDeclarator declarator) { - at(declarator); - err("FieldDeclarator: " + declarator.getRawSignature()); - throw new RuntimeException("NYI at " + locs.forNode(declarator)); - } - private int visit(IASTFunctionDeclarator declarator) { at(declarator); if (declarator instanceof IASTStandardFunctionDeclarator) { From 14cefef2588282ecdeed4ab56d59c5bff4ca7737 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 19 Dec 2023 15:09:43 +0100 Subject: [PATCH 05/11] removed debug code --- src/lang/cpp/AST.rsc | 56 -------------------------------------------- 1 file changed, 56 deletions(-) diff --git a/src/lang/cpp/AST.rsc b/src/lang/cpp/AST.rsc index e8a26f8c..a786e776 100644 --- a/src/lang/cpp/AST.rsc +++ b/src/lang/cpp/AST.rsc @@ -554,59 +554,3 @@ java rel[loc,loc] parseForMacros(loc file, str charset=DEFAULT_CHARSET, bool inf @synopsis{All functions in this module that have a charset parameter use this as default.} public str DEFAULT_CHARSET = "UTF-8"; -public map[str, str] linusMacros = ( - "_M_IX86": "600", - //"_WIN32": "1", - // "_MSC_VER": "1400" - "__cdecl": "", - "__fastcall": "", - "__restrict": "", - "__sptr": "", - "__stdcall": "", - - - "__unaligned": "", - "__uptr": "", - "__w64": "", - "__forceinline": "__inline", - "__int8": "char", - "__int16": "short", - "__int32": "int", - "__int64": "long long", - - // additional: - //"_MSC_VER": "1700", - "__cplusplus": "199711L", - "__thiscall": "", - "_CHAR16T": "", - "_NATIVE_WCHAR_T_DEFINED": "1", - "__nullptr": "nullptr", - //"_MSC_EXTENSIONS": "1", - "__inline": "inline", - "__ptr32": "", - "__ptr64": "", - "__interface": "struct", - - "__pragma(A)": "", - "__identifier(A)": "A", - - -// "__declspec(A)": "", - "_stdcall": "", - - "_USE_DECLSPECS_FOR_SAL": "0", - //"_DLL": "1", - - "NDEBUG": "", - //"WIN32": "", - //"_WINDOWS": "", - //"_WIN32_DCOM": "", - //"_USRDLL": "", - "SSCF1_INCLUDED": "", - "LOGGINGTRACING_INCLUDED": "", - //"_WINDLL": "", - "_UNICODE": "", - "UNICODE": "" - //"_AFXDLL": "" -// "__INTELLISENSE__": "1" -); From 726d0d30f6a90530407a6ce8a2c24497ffad406d Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 20 Dec 2023 13:36:08 +0100 Subject: [PATCH 06/11] added support for logical URIs that resolve to the file scheme in the bridge between Rascal and CDT --- src/lang/cpp/internal/CDTParser.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lang/cpp/internal/CDTParser.java b/src/lang/cpp/internal/CDTParser.java index 562438c3..856eb70d 100644 --- a/src/lang/cpp/internal/CDTParser.java +++ b/src/lang/cpp/internal/CDTParser.java @@ -13,6 +13,7 @@ package lang.cpp.internal; import java.io.File; +import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; @@ -39,6 +40,7 @@ import org.eclipse.core.runtime.CoreException; import org.rascalmpl.exceptions.RuntimeExceptionFactory; import org.rascalmpl.library.Prelude; +import org.rascalmpl.uri.URIResolverRegistry; import io.usethesource.vallang.IBool; import io.usethesource.vallang.IList; @@ -144,6 +146,12 @@ public IASTTranslationUnit parseFileAsCpp(ISourceLocation file, IString charset, } private String locToPath(ISourceLocation loc) { + try { + loc = URIResolverRegistry.getInstance().logicalToPhysical(loc); + } catch (IOException e) { + // do nothing + } + if (!loc.getScheme().equals("file")) throw new IllegalArgumentException("Will not convert non-file loc"); return loc.getAuthority() + loc.getPath(); From e69f51637ea2c4c907784c784e53a16fef14c06c Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 20 Dec 2023 13:37:07 +0100 Subject: [PATCH 07/11] finished implementation of resolveICPPEnumerationSpecialization with non type-value arguments as template parameters --- src/lang/cpp/internal/TypeResolver.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/lang/cpp/internal/TypeResolver.java b/src/lang/cpp/internal/TypeResolver.java index 35466fa1..6839103c 100644 --- a/src/lang/cpp/internal/TypeResolver.java +++ b/src/lang/cpp/internal/TypeResolver.java @@ -595,22 +595,9 @@ private IConstructor resolveICPPTypeSpecialization(ICPPTypeSpecialization type, private IConstructor resolveICPPEnumerationSpecialization(ICPPEnumerationSpecialization type, ISourceLocation origin) { ISourceLocation specializedBinding = getDecl(type.getSpecializedBinding(), origin); ICPPTemplateParameterMap templateParameterMap = type.getTemplateParameterMap(); - IListWriter templateArguments = vf.listWriter(); - Stream.of(templateParameterMap.getAllParameterPositions()).forEach(it -> { - ICPPTemplateArgument arg = templateParameterMap.getArgument(it); - if (arg.isNonTypeValue()) { - // TODO - throw new RuntimeException("NonTypeValue argument in template parameters NYI @ " + origin); - } - // IType typeValue = arg.getTypeValue(); - // err("TemplateArgument " + typeValue.getClass().getSimpleName()); - // err("typeValue " + type); - - // templateArguments - // .append(builder.TypeSymbol_templateArgument(it, - // getDecl(templateParameterMap.getArgument(it)))); - }); - return builder.TypeSymbol_enumerationSpecialization(specializedBinding, templateArguments.done()); + IList templateArguments = resolveArguments(streamArguments(templateParameterMap), origin).collect(vf.listWriter()); + + return builder.TypeSymbol_enumerationSpecialization(specializedBinding, templateArguments); } private IConstructor resolveICPPUnaryTypeTransformation(ICPPUnaryTypeTransformation type, ISourceLocation origin) { From beb322671554b646817753349798ad6bd6b98e79 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 20 Dec 2023 16:11:17 +0100 Subject: [PATCH 08/11] added implementation for ICPPUnaryTypeTransformation --- src/lang/cpp/AST.rsc | 56 +++++++++++++++++++++++++ src/lang/cpp/TypeSymbol.rsc | 1 + src/lang/cpp/internal/AST.java | 55 ++++++++++++++++-------- src/lang/cpp/internal/TypeResolver.java | 10 +++-- 4 files changed, 101 insertions(+), 21 deletions(-) diff --git a/src/lang/cpp/AST.rsc b/src/lang/cpp/AST.rsc index a786e776..e8a26f8c 100644 --- a/src/lang/cpp/AST.rsc +++ b/src/lang/cpp/AST.rsc @@ -554,3 +554,59 @@ java rel[loc,loc] parseForMacros(loc file, str charset=DEFAULT_CHARSET, bool inf @synopsis{All functions in this module that have a charset parameter use this as default.} public str DEFAULT_CHARSET = "UTF-8"; +public map[str, str] linusMacros = ( + "_M_IX86": "600", + //"_WIN32": "1", + // "_MSC_VER": "1400" + "__cdecl": "", + "__fastcall": "", + "__restrict": "", + "__sptr": "", + "__stdcall": "", + + + "__unaligned": "", + "__uptr": "", + "__w64": "", + "__forceinline": "__inline", + "__int8": "char", + "__int16": "short", + "__int32": "int", + "__int64": "long long", + + // additional: + //"_MSC_VER": "1700", + "__cplusplus": "199711L", + "__thiscall": "", + "_CHAR16T": "", + "_NATIVE_WCHAR_T_DEFINED": "1", + "__nullptr": "nullptr", + //"_MSC_EXTENSIONS": "1", + "__inline": "inline", + "__ptr32": "", + "__ptr64": "", + "__interface": "struct", + + "__pragma(A)": "", + "__identifier(A)": "A", + + +// "__declspec(A)": "", + "_stdcall": "", + + "_USE_DECLSPECS_FOR_SAL": "0", + //"_DLL": "1", + + "NDEBUG": "", + //"WIN32": "", + //"_WINDOWS": "", + //"_WIN32_DCOM": "", + //"_USRDLL": "", + "SSCF1_INCLUDED": "", + "LOGGINGTRACING_INCLUDED": "", + //"_WINDLL": "", + "_UNICODE": "", + "UNICODE": "" + //"_AFXDLL": "" +// "__INTELLISENSE__": "1" +); diff --git a/src/lang/cpp/TypeSymbol.rsc b/src/lang/cpp/TypeSymbol.rsc index d6925ff1..922ffb75 100644 --- a/src/lang/cpp/TypeSymbol.rsc +++ b/src/lang/cpp/TypeSymbol.rsc @@ -80,6 +80,7 @@ data TypeSymbol | \functionSetType(loc decl, list[TypeSymbol] templateArguments) | \functionSetTypePointer(loc decl, list[TypeSymbol] templateArguments) + | \unaryTypeTransformation(str operator, TypeSymbol operand) | \unresolved() | \any() diff --git a/src/lang/cpp/internal/AST.java b/src/lang/cpp/internal/AST.java index 5989d470..f93004b0 100644 --- a/src/lang/cpp/internal/AST.java +++ b/src/lang/cpp/internal/AST.java @@ -676,8 +676,6 @@ public AST (IValueFactory vf) { = tf.constructor(typestore,_TypeSymbol,"unspecified"); private static final Type _TypeSymbol_eUnionTemplate_2 = tf.constructor(typestore,_TypeSymbol,"eUnionTemplate",tf.sourceLocationType(),"decl",tf.listType(tf.sourceLocationType()),"templateParameters"); - private static final Type _TypeSymbol_class_1 - = tf.constructor(typestore,_TypeSymbol,"class",tf.sourceLocationType(),"decl"); private static final Type _TypeSymbol___nullType_0 = tf.constructor(typestore,_TypeSymbol,"__nullType"); private static final Type _TypeSymbol_eClassTemplate_2 @@ -746,6 +744,10 @@ public AST (IValueFactory vf) { = tf.constructor(typestore,_TypeSymbol,"cUnionTemplate",tf.sourceLocationType(),"decl",tf.listType(tf.sourceLocationType()),"templateParameters"); private static final Type _TypeSymbol_functionSetType_2 = tf.constructor(typestore,_TypeSymbol,"functionSetType",tf.sourceLocationType(),"decl",tf.listType(_TypeSymbol),"templateArguments"); + private static final Type _TypeSymbol_unaryTypeTransformation_2 + = tf.constructor(typestore,_TypeSymbol,"unaryTypeTransformation",tf.stringType(),"operator",_TypeSymbol,"operand"); + private static final Type _TypeSymbol_class_1 + = tf.constructor(typestore,_TypeSymbol,"class",tf.sourceLocationType(),"decl"); private static final Type _TypeSymbol_typeOfDependentExpression_1 = tf.constructor(typestore,_TypeSymbol,"typeOfDependentExpression",tf.stringType(),"name"); private static final Type _TypeSymbol_implicitTemplateTypeParameter_2 @@ -6234,21 +6236,6 @@ public IConstructor TypeSymbol_eUnionTemplate(ISourceLocation $decl, IList $temp return vf.constructor(_TypeSymbol_eUnionTemplate_2 , $decl, $templateParameters).asWithKeywordParameters().setParameters(kwParams); } - public IConstructor TypeSymbol_class(ISourceLocation $decl) { - - if (!$decl.getType().isSubtypeOf(tf.sourceLocationType())) { - throw new IllegalArgumentException("Expected " + tf.sourceLocationType() + " but got " + $decl.getType() + " for $decl:" + $decl); - } - - Map kwParams = new HashMap(); - - - - - - return vf.constructor(_TypeSymbol_class_1 , $decl).asWithKeywordParameters().setParameters(kwParams); - } - public IConstructor TypeSymbol___nullType() { Map kwParams = new HashMap(); @@ -6771,6 +6758,40 @@ public IConstructor TypeSymbol_functionSetType(ISourceLocation $decl, IList $tem return vf.constructor(_TypeSymbol_functionSetType_2 , $decl, $templateArguments).asWithKeywordParameters().setParameters(kwParams); } + public IConstructor TypeSymbol_unaryTypeTransformation(String $operator, IConstructor $operand) { + + if (!vf.string($operator).getType().isSubtypeOf(tf.stringType())) { + throw new IllegalArgumentException("Expected " + tf.stringType() + " but got " + vf.string($operator).getType() + " for vf.string($operator):" + vf.string($operator)); + } + + if (!$operand.getType().isSubtypeOf(_TypeSymbol)) { + throw new IllegalArgumentException("Expected " + _TypeSymbol + " but got " + $operand.getType() + " for $operand:" + $operand); + } + + Map kwParams = new HashMap(); + + + + + + return vf.constructor(_TypeSymbol_unaryTypeTransformation_2 , vf.string($operator), $operand).asWithKeywordParameters().setParameters(kwParams); + } + + public IConstructor TypeSymbol_class(ISourceLocation $decl) { + + if (!$decl.getType().isSubtypeOf(tf.sourceLocationType())) { + throw new IllegalArgumentException("Expected " + tf.sourceLocationType() + " but got " + $decl.getType() + " for $decl:" + $decl); + } + + Map kwParams = new HashMap(); + + + + + + return vf.constructor(_TypeSymbol_class_1 , $decl).asWithKeywordParameters().setParameters(kwParams); + } + public IConstructor TypeSymbol_typeOfDependentExpression(String $name) { if (!vf.string($name).getType().isSubtypeOf(tf.stringType())) { diff --git a/src/lang/cpp/internal/TypeResolver.java b/src/lang/cpp/internal/TypeResolver.java index 6839103c..a1612c37 100644 --- a/src/lang/cpp/internal/TypeResolver.java +++ b/src/lang/cpp/internal/TypeResolver.java @@ -67,6 +67,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTypeSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNaryTypeIdExpression.Operator; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.c.CStructure; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTemplateTypeParameter; @@ -600,10 +601,11 @@ private IConstructor resolveICPPEnumerationSpecialization(ICPPEnumerationSpecial return builder.TypeSymbol_enumerationSpecialization(specializedBinding, templateArguments); } - private IConstructor resolveICPPUnaryTypeTransformation(ICPPUnaryTypeTransformation type, ISourceLocation origin) { - // Operator operator = type.getOperator(); - // IType operand = type.getOperand(); - throw new RuntimeException("NYI: resolveICPPUnaryTypeTransformation @ " + origin); + private IConstructor resolveICPPUnaryTypeTransformation(ICPPUnaryTypeTransformation type, ISourceLocation origin) { + String op = type.getOperator().name(); + IConstructor operand = resolveType(type.getOperand(), origin); + + return builder.TypeSymbol_unaryTypeTransformation(op, operand); } private IConstructor resolveICPPUnknownType(ICPPUnknownType type, ISourceLocation origin) { From 059269754e4a21f60fdde5f67116cceb1dff71a1 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 20 Dec 2023 16:23:58 +0100 Subject: [PATCH 09/11] removed debug helper code again --- src/lang/cpp/AST.rsc | 56 -------------------------------------------- 1 file changed, 56 deletions(-) diff --git a/src/lang/cpp/AST.rsc b/src/lang/cpp/AST.rsc index e8a26f8c..a786e776 100644 --- a/src/lang/cpp/AST.rsc +++ b/src/lang/cpp/AST.rsc @@ -554,59 +554,3 @@ java rel[loc,loc] parseForMacros(loc file, str charset=DEFAULT_CHARSET, bool inf @synopsis{All functions in this module that have a charset parameter use this as default.} public str DEFAULT_CHARSET = "UTF-8"; -public map[str, str] linusMacros = ( - "_M_IX86": "600", - //"_WIN32": "1", - // "_MSC_VER": "1400" - "__cdecl": "", - "__fastcall": "", - "__restrict": "", - "__sptr": "", - "__stdcall": "", - - - "__unaligned": "", - "__uptr": "", - "__w64": "", - "__forceinline": "__inline", - "__int8": "char", - "__int16": "short", - "__int32": "int", - "__int64": "long long", - - // additional: - //"_MSC_VER": "1700", - "__cplusplus": "199711L", - "__thiscall": "", - "_CHAR16T": "", - "_NATIVE_WCHAR_T_DEFINED": "1", - "__nullptr": "nullptr", - //"_MSC_EXTENSIONS": "1", - "__inline": "inline", - "__ptr32": "", - "__ptr64": "", - "__interface": "struct", - - "__pragma(A)": "", - "__identifier(A)": "A", - - -// "__declspec(A)": "", - "_stdcall": "", - - "_USE_DECLSPECS_FOR_SAL": "0", - //"_DLL": "1", - - "NDEBUG": "", - //"WIN32": "", - //"_WINDOWS": "", - //"_WIN32_DCOM": "", - //"_USRDLL": "", - "SSCF1_INCLUDED": "", - "LOGGINGTRACING_INCLUDED": "", - //"_WINDLL": "", - "_UNICODE": "", - "UNICODE": "" - //"_AFXDLL": "" -// "__INTELLISENSE__": "1" -); From df3de2f6588bc1bc733e7b78c70676c74fc7fafd Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 21 Dec 2023 09:54:06 +0100 Subject: [PATCH 10/11] added GNU computed goto statement --- src/lang/cpp/AST.rsc | 1 + src/lang/cpp/internal/AST.java | 19 +++++++++++++++++++ src/lang/cpp/internal/Parser.java | 10 +++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/lang/cpp/AST.rsc b/src/lang/cpp/AST.rsc index a786e776..db2ce5ce 100644 --- a/src/lang/cpp/AST.rsc +++ b/src/lang/cpp/AST.rsc @@ -334,6 +334,7 @@ data Statement(list[Attribute] attributes = [], loc src = |unknown:///|, bool is | \nullStatement() | \label(Name name, Statement nestedStatement, loc decl = |unknown:///|) | \goto(Name name, loc decl = |unknown:///|) + | \computedGoto(Expression labelName) //note: this is a GNU extension | \tryBlock(Statement tryBody, list[Statement] catchHandlers) | \catch(Declaration declaration, Statement body) diff --git a/src/lang/cpp/internal/AST.java b/src/lang/cpp/internal/AST.java index f93004b0..a996a0a8 100644 --- a/src/lang/cpp/internal/AST.java +++ b/src/lang/cpp/internal/AST.java @@ -546,6 +546,8 @@ public AST (IValueFactory vf) { = tf.constructor(typestore,_Statement,"forWithDecl",_Statement,"sInitializer",_Declaration,"conditionDeclaration",_Expression,"iteration",_Statement,"body"); private static final Type _Statement_expressionStatement_1 = tf.constructor(typestore,_Statement,"expressionStatement",_Expression,"expression"); + private static final Type _Statement_computedGoto_1 + = tf.constructor(typestore,_Statement,"computedGoto",_Expression,"labelName"); private static final Type _Statement_for_4 = tf.constructor(typestore,_Statement,"for",_Statement,"sInitializer",_Expression,"condition",_Expression,"iteration",_Statement,"body"); private static final Type _Statement_return_0 @@ -5317,6 +5319,23 @@ public IConstructor Statement_expressionStatement(IConstructor $expression, ILis return vf.constructor(_Statement_expressionStatement_1 , $expression).asWithKeywordParameters().setParameters(kwParams); } + public IConstructor Statement_computedGoto(IConstructor $labelName, IList $attributes, ISourceLocation $loc, boolean $isMacroExpansion) { + + if (!$labelName.getType().isSubtypeOf(_Expression)) { + throw new IllegalArgumentException("Expected " + _Expression + " but got " + $labelName.getType() + " for $labelName:" + $labelName); + } + + Map kwParams = new HashMap(); + if (!$attributes.isEmpty()) { + kwParams.put("attributes", $attributes); + } + kwParams.put("src", $loc); + + + if ($isMacroExpansion) kwParams.put("isMacroExpansion", vf.bool(true)); + return vf.constructor(_Statement_computedGoto_1 , $labelName).asWithKeywordParameters().setParameters(kwParams); + } + public IConstructor Statement_for(IConstructor $sInitializer, IConstructor $condition, IConstructor $iteration, IConstructor $body, IList $attributes, ISourceLocation $loc, boolean $isMacroExpansion) { if (!$sInitializer.getType().isSubtypeOf(_Statement)) { diff --git a/src/lang/cpp/internal/Parser.java b/src/lang/cpp/internal/Parser.java index 0ec42172..62026f07 100644 --- a/src/lang/cpp/internal/Parser.java +++ b/src/lang/cpp/internal/Parser.java @@ -3590,9 +3590,13 @@ else if (statement instanceof IASTProblemStatement) private int visit(IGNUASTGotoStatement statement) { at(statement); - // requires decl keyword parameter - err("IGNUAstGotoStatement: " + statement.getRawSignature()); - throw new RuntimeException("NYI at " + locs.forNode(statement)); + visit(statement.getLabelNameExpression()); + IList attributes = getAttributes(statement); + ISourceLocation loc = locs.forNode(statement); + boolean isMacroExpansion = isMacroExpansion(statement); + + stack.push(builder.Statement_computedGoto(stack.pop(), attributes, loc, isMacroExpansion)); + return PROCESS_ABORT; } private int visit(ICPPASTCatchHandler statement) { From 3b10dfbd0a0b144a737fb4496bb2ed2a235ac44d Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 21 Dec 2023 11:23:20 +0100 Subject: [PATCH 11/11] changed unary type transformation representation --- src/lang/cpp/TypeSymbol.rsc | 2 +- src/lang/cpp/internal/AST.java | 17 +++++++++++++++++ src/lang/cpp/internal/TypeResolver.java | 5 +++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/lang/cpp/TypeSymbol.rsc b/src/lang/cpp/TypeSymbol.rsc index 922ffb75..a369d6a3 100644 --- a/src/lang/cpp/TypeSymbol.rsc +++ b/src/lang/cpp/TypeSymbol.rsc @@ -80,7 +80,7 @@ data TypeSymbol | \functionSetType(loc decl, list[TypeSymbol] templateArguments) | \functionSetTypePointer(loc decl, list[TypeSymbol] templateArguments) - | \unaryTypeTransformation(str operator, TypeSymbol operand) + | \transformToUnderlyingType(TypeSymbol operand) | \unresolved() | \any() diff --git a/src/lang/cpp/internal/AST.java b/src/lang/cpp/internal/AST.java index a996a0a8..71d7be5b 100644 --- a/src/lang/cpp/internal/AST.java +++ b/src/lang/cpp/internal/AST.java @@ -674,6 +674,8 @@ public AST (IValueFactory vf) { = tf.constructor(typestore,_TypeSymbol,"union",tf.sourceLocationType(),"decl"); private static final Type _TypeSymbol_float_0 = tf.constructor(typestore,_TypeSymbol,"float"); + private static final Type _TypeSymbol_transformToUnderlyingType_1 + = tf.constructor(typestore,_TypeSymbol,"transformToUnderlyingType",_TypeSymbol,"operand"); private static final Type _TypeSymbol_unspecified_0 = tf.constructor(typestore,_TypeSymbol,"unspecified"); private static final Type _TypeSymbol_eUnionTemplate_2 @@ -6225,6 +6227,21 @@ public IConstructor TypeSymbol_float() { return vf.constructor(_TypeSymbol_float_0 ).asWithKeywordParameters().setParameters(kwParams); } + public IConstructor TypeSymbol_transformToUnderlyingType(IConstructor $operand) { + + if (!$operand.getType().isSubtypeOf(_TypeSymbol)) { + throw new IllegalArgumentException("Expected " + _TypeSymbol + " but got " + $operand.getType() + " for $operand:" + $operand); + } + + Map kwParams = new HashMap(); + + + + + + return vf.constructor(_TypeSymbol_transformToUnderlyingType_1 , $operand).asWithKeywordParameters().setParameters(kwParams); + } + public IConstructor TypeSymbol_unspecified() { Map kwParams = new HashMap(); diff --git a/src/lang/cpp/internal/TypeResolver.java b/src/lang/cpp/internal/TypeResolver.java index a1612c37..9687a663 100644 --- a/src/lang/cpp/internal/TypeResolver.java +++ b/src/lang/cpp/internal/TypeResolver.java @@ -602,10 +602,11 @@ private IConstructor resolveICPPEnumerationSpecialization(ICPPEnumerationSpecial } private IConstructor resolveICPPUnaryTypeTransformation(ICPPUnaryTypeTransformation type, ISourceLocation origin) { - String op = type.getOperator().name(); + assert type.getOperator().equals(org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation.Operator.underlying_type); + IConstructor operand = resolveType(type.getOperand(), origin); - return builder.TypeSymbol_unaryTypeTransformation(op, operand); + return builder.TypeSymbol_transformToUnderlyingType(operand); } private IConstructor resolveICPPUnknownType(ICPPUnknownType type, ISourceLocation origin) {