Skip to content

Commit

Permalink
Merge pull request #71 from usethesource/alias-templates
Browse files Browse the repository at this point in the history
Taking on every NYI we hit while parsing a large code base
  • Loading branch information
jurgenvinju authored Dec 21, 2023
2 parents 7bdfb15 + 3b10dfb commit 9e48227
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 150 deletions.
4 changes: 3 additions & 1 deletion src/lang/cpp/AST.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -552,4 +553,5 @@ 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";

3 changes: 2 additions & 1 deletion src/lang/cpp/TypeSymbol.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ data TypeSymbol
| \functionTemplate(loc decl, list[loc] templateParameters)
| \variableTemplate(loc decl, list[loc] templateParameters)

| \aliasTemplate(loc decl, list[loc] templateParameters)
| \aliasTemplate(loc decl, list[loc] templateParameters, TypeSymbol \type)

| \functionSetType(loc decl, list[TypeSymbol] templateArguments)
| \functionSetTypePointer(loc decl, list[TypeSymbol] templateArguments)

| \transformToUnderlyingType(TypeSymbol operand)
| \unresolved()
| \any()

Expand Down
163 changes: 112 additions & 51 deletions src/lang/cpp/internal/AST.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -672,20 +674,18 @@ 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
= 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
= 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 @@ -748,6 +748,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
Expand All @@ -770,12 +774,14 @@ 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_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_decimal128_0
Expand Down Expand Up @@ -5315,6 +5321,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<String, IValue> kwParams = new HashMap<String, IValue>();
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)) {
Expand Down Expand Up @@ -6204,49 +6227,49 @@ public IConstructor TypeSymbol_float() {
return vf.constructor(_TypeSymbol_float_0 ).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor TypeSymbol_unspecified() {
public IConstructor TypeSymbol_transformToUnderlyingType(IConstructor $operand) {

if (!$operand.getType().isSubtypeOf(_TypeSymbol)) {
throw new IllegalArgumentException("Expected " + _TypeSymbol + " but got " + $operand.getType() + " for $operand:" + $operand);
}

Map<String, IValue> kwParams = new HashMap<String, IValue>();





return vf.constructor(_TypeSymbol_unspecified_0 ).asWithKeywordParameters().setParameters(kwParams);
return vf.constructor(_TypeSymbol_transformToUnderlyingType_1 , $operand).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor TypeSymbol_eUnionTemplate(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_unspecified() {

Map<String, IValue> kwParams = new HashMap<String, IValue>();





return vf.constructor(_TypeSymbol_eUnionTemplate_2 , $decl, $templateParameters).asWithKeywordParameters().setParameters(kwParams);
return vf.constructor(_TypeSymbol_unspecified_0 ).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor TypeSymbol_class(ISourceLocation $decl) {
public IConstructor TypeSymbol_eUnionTemplate(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_class_1 , $decl).asWithKeywordParameters().setParameters(kwParams);
return vf.constructor(_TypeSymbol_eUnionTemplate_2 , $decl, $templateParameters).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor TypeSymbol___nullType() {
Expand Down Expand Up @@ -6298,25 +6321,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 @@ -6790,6 +6794,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<String, IValue> kwParams = new HashMap<String, IValue>();





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





return vf.constructor(_TypeSymbol_class_1 , $decl).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor TypeSymbol_typeOfDependentExpression(String $name) {

if (!vf.string($name).getType().isSubtypeOf(tf.stringType())) {
Expand Down Expand Up @@ -6959,29 +6997,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,17 +7036,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_aliasTemplate(ISourceLocation $decl, IList $templateParameters) {
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_struct_1 , $decl).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor TypeSymbol_array(IConstructor $baseType, IValue $size) {

if (!$templateParameters.getType().isSubtypeOf(tf.listType(tf.sourceLocationType()))) {
throw new IllegalArgumentException("Expected " + tf.listType(tf.sourceLocationType()) + " but got " + $templateParameters.getType() + " for $templateParameters:" + $templateParameters);
if (!$baseType.getType().isSubtypeOf(_TypeSymbol)) {
throw new IllegalArgumentException("Expected " + _TypeSymbol + " but got " + $baseType.getType() + " for $baseType:" + $baseType);
}

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 @@ -7009,7 +7070,7 @@ public IConstructor TypeSymbol_aliasTemplate(ISourceLocation $decl, IList $templ



return vf.constructor(_TypeSymbol_aliasTemplate_2 , $decl, $templateParameters).asWithKeywordParameters().setParameters(kwParams);
return vf.constructor(_TypeSymbol_array_2 , $baseType, $size).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor TypeSymbol_nullPtr() {
Expand Down
12 changes: 11 additions & 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 Expand Up @@ -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));
}
Expand Down
Loading

0 comments on commit 9e48227

Please sign in to comment.