Skip to content

Commit

Permalink
testing and fixing with real code example from @linus
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Dec 19, 2023
1 parent ecf94ac commit 395b682
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 77 deletions.
59 changes: 58 additions & 1 deletion src/lang/cpp/AST.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
public str DEFAULT_CHARSET = "UTF-8";

public map[str, str] linusMacros = (

This comment has been minimized.

Copy link
@linuswagner

linuswagner Dec 19, 2023

Collaborator

while I feel honored, I think, we can remove this one from the release

This comment has been minimized.

Copy link
@jurgenvinju

jurgenvinju Dec 19, 2023

Author Member

oops..

"_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"
);
2 changes: 1 addition & 1 deletion src/lang/cpp/TypeSymbol.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
86 changes: 43 additions & 43 deletions src/lang/cpp/internal/AST.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<String, IValue> kwParams = new HashMap<String, IValue>();





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())) {
Expand Down Expand Up @@ -6959,29 +6940,37 @@ 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<String, IValue> kwParams = new HashMap<String, IValue>();





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<String, IValue> kwParams = new HashMap<String, IValue>();
Expand All @@ -6990,32 +6979,32 @@ 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<String, IValue> kwParams = new HashMap<String, IValue>();





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<String, IValue> kwParams = new HashMap<String, IValue>();
Expand All @@ -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<String, IValue> kwParams = new HashMap<String, IValue>();





return vf.constructor(_TypeSymbol_nullPtr_0 ).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor TypeSymbol_decimal128() {
Expand Down
2 changes: 1 addition & 1 deletion src/lang/cpp/internal/BindingsResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
31 changes: 0 additions & 31 deletions src/lang/cpp/internal/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 395b682

Please sign in to comment.