Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working on adding declTypes and fixing some NYI #66

Merged
merged 7 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/lang/cpp/AST.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ data Declarator(list[Attribute] attributes = [], loc src = |unknown:///|, loc de

data DeclSpecifier(list[Attribute] attributes = [], loc src = |unknown:///|, bool isMacroExpansion = false)
= \declSpecifier(list[Modifier] modifiers, Type \type)
| \declSpecifier(list[Modifier] modifiers, Type \type, Expression expression) //decltype and type_of
| \etsEnum(list[Modifier] modifiers, Name name, loc decl = |unknown:///|) //no attributes
| \etsStruct(list[Modifier] modifiers, Name name, loc decl = |unknown:///|) //ElaboratedTypeSpecifier //no attributes
| \etsUnion(list[Modifier] modifiers, Name name, loc decl = |unknown:///|) //no attributes
Expand Down Expand Up @@ -304,10 +303,9 @@ data Name(loc src = |unknown:///|, bool isMacroExpansion = false) //no attribute
| \qualifiedName(list[Name] qualifiers, Name lastName, loc decl = |unknown:///|)
| \operatorName(str \value)
| \conversionName(str \value, Expression typeId)

| \templateId(Name name, list[Expression] argumentTypes, loc decl = |unknown:///|)

| \abstractEmptyName()
| decltypeName(Expression expression)
;

data Statement(list[Attribute] attributes = [], loc src = |unknown:///|, bool isMacroExpansion = false)
Expand Down Expand Up @@ -353,8 +351,8 @@ data Type(loc src = |unknown:///|, bool isMacroExpansion = false) //no attribute
| \double()
| \bool()
| \wchar_t()
| \typeof()
| \decltype()
| \typeof(Expression expression)
| \decltype(Expression expression)
| \auto()
| \char16_t()
| \char32_t()
Expand Down
41 changes: 0 additions & 41 deletions src/lang/cpp/M3.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ extend analysis::m3::Core;
import IO;
import Node;
import String;
import Set;
import lang::cpp::AST;
import lang::cpp::TypeSymbol;

Expand Down Expand Up @@ -299,43 +298,3 @@ rel[loc caller, loc callee] closeOverriddenVirtualCalls(M3 comp) {
- rangeR(comp.callGraph, comp.methodOverrides<0>); // remove the virtual intermediates
}

test bool modelConsistencyAddressBook() {
tm = createM3AndAstFromCppFile(|project://clair/src/test/phonebook.cpp|);
m = tm<0>;
t = tm<1>;
decls = m.declarations<name>;

// nothing that is contained here does not not have a declaration, except the outermost translationUnit
assert m.declarations<name> - m.containment<to> - top(m.containment) == {};

// everything in the containment relation has been declared somewhere
assert carrier(m.containment) - decls == {};

// everything in the declarations relation is contained somewhere
assert decls - carrier(m.containment) == {};

// all uses point to actual declarations
assert m.uses<name> - m.declarations<name> - m.implicitDeclarations == {};

// in this example, all declarations are used at least once
assert m.declarations<name> - m.uses<name> == {};

// m.declarations is one-to-one
assert size(m.declarations<name>) == size(m.declarations);

// nothing in the AST that has a decl is not declared
assert all(/node n := t && n.decl? && n.decl in decls);

// all nodes have a .src attribute
assert all(/node n := t && loc _ := n.src?|unknown:///|);

// helper function for getting src location of a node
loc \loc(node n) = loc f := (n.src?|unknown:///|(0,0)) ? f : |unknown:///|(0,0);

// all sibling ast's are next to each other in the right order
for(/[*_,node a, node b, *_] := t) {
assert \loc(a).offset + \loc(a).length <= \loc(b).offset;
}

return true;
}
120 changes: 59 additions & 61 deletions src/lang/cpp/internal/AST.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public AST (IValueFactory vf) {
= tf.constructor(typestore,_DeclSpecifier,"classFinal",tf.listType(_Modifier),"modifiers",_Name,"name",tf.listType(_Declaration),"baseSpecifiers",tf.listType(_Declaration),"members");
private static final Type _DeclSpecifier_struct_3
= tf.constructor(typestore,_DeclSpecifier,"struct",tf.listType(_Modifier),"modifiers",_Name,"name",tf.listType(_Declaration),"members");
private static final Type _DeclSpecifier_declSpecifier_3
= tf.constructor(typestore,_DeclSpecifier,"declSpecifier",tf.listType(_Modifier),"modifiers",_Type,"type",_Expression,"expression");
private static final Type _DeclSpecifier_msThrowEllipsis_0
= tf.constructor(typestore,_DeclSpecifier,"msThrowEllipsis");
private static final Type _DeclSpecifier_union_3
Expand Down Expand Up @@ -498,12 +496,12 @@ public AST (IValueFactory vf) {
= tf.constructor(typestore,_Type,"decimal128");
private static final Type _Type_nullptr_0
= tf.constructor(typestore,_Type,"nullptr");
private static final Type _Type_decltype_0
= tf.constructor(typestore,_Type,"decltype");
private static final Type _Type_wchar_t_0
= tf.constructor(typestore,_Type,"wchar_t");
private static final Type _Type_integer_0
= tf.constructor(typestore,_Type,"integer");
private static final Type _Type_decltype_1
= tf.constructor(typestore,_Type,"decltype",_Expression,"expression");
private static final Type _Type_float_0
= tf.constructor(typestore,_Type,"float");
private static final Type _Type_float128_0
Expand All @@ -516,10 +514,14 @@ public AST (IValueFactory vf) {
= tf.constructor(typestore,_Type,"unspecified");
private static final Type _Type_unionType_1
= tf.constructor(typestore,_Type,"unionType",_Name,"name");
private static final Type _Type_double_0
= tf.constructor(typestore,_Type,"double");
private static final Type _Type_decimal64_0
= tf.constructor(typestore,_Type,"decimal64");
private static final Type _Type_auto_0
= tf.constructor(typestore,_Type,"auto");
private static final Type _Type_typeof_1
= tf.constructor(typestore,_Type,"typeof",_Expression,"expression");
private static final Type _Type_char32_t_0
= tf.constructor(typestore,_Type,"char32_t");
private static final Type _Type_bool_0
Expand All @@ -536,10 +538,6 @@ public AST (IValueFactory vf) {
= tf.constructor(typestore,_Type,"decimal32");
private static final Type _Type_char16_t_0
= tf.constructor(typestore,_Type,"char16_t");
private static final Type _Type_typeof_0
= tf.constructor(typestore,_Type,"typeof");
private static final Type _Type_double_0
= tf.constructor(typestore,_Type,"double");


private static final Type _Statement_nullStatement_0
Expand Down Expand Up @@ -834,6 +832,8 @@ public AST (IValueFactory vf) {
= tf.constructor(typestore,_Name,"templateId",_Name,"name",tf.listType(_Expression),"argumentTypes");
private static final Type _Name_conversionName_2
= tf.constructor(typestore,_Name,"conversionName",tf.stringType(),"value",_Expression,"typeId");
private static final Type _Name_decltypeName_1
= tf.constructor(typestore,_Name,"decltypeName",_Expression,"expression");
private static final Type _Name_operatorName_1
= tf.constructor(typestore,_Name,"operatorName",tf.stringType(),"value");
private static final Type _Name_name_1
Expand Down Expand Up @@ -1520,31 +1520,6 @@ public IConstructor DeclSpecifier_struct(IList $modifiers, IConstructor $name, I
return vf.constructor(_DeclSpecifier_struct_3 , $modifiers, $name, $members).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor DeclSpecifier_declSpecifier(IList $modifiers, IConstructor $type, IConstructor $expression, IList $attributes, ISourceLocation $loc, boolean $isMacroExpansion) {

if (!$modifiers.getType().isSubtypeOf(tf.listType(_Modifier))) {
throw new IllegalArgumentException("Expected " + tf.listType(_Modifier) + " but got " + $modifiers.getType() + " for $modifiers:" + $modifiers);
}

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

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

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(_DeclSpecifier_declSpecifier_3 , $modifiers, $type, $expression).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor DeclSpecifier_msThrowEllipsis(ISourceLocation $loc, ISourceLocation $decl, boolean $isMacroExpansion) {

Map<String, IValue> kwParams = new HashMap<String, IValue>();
Expand Down Expand Up @@ -5017,37 +4992,41 @@ public IConstructor Type_nullptr(ISourceLocation $loc, boolean $isMacroExpansion
return vf.constructor(_Type_nullptr_0 ).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Type_decltype(ISourceLocation $loc, boolean $isMacroExpansion) {
public IConstructor Type_wchar_t(ISourceLocation $loc, boolean $isMacroExpansion) {

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

kwParams.put("src", $loc);


if ($isMacroExpansion) kwParams.put("isMacroExpansion", vf.bool(true));
return vf.constructor(_Type_decltype_0 ).asWithKeywordParameters().setParameters(kwParams);
return vf.constructor(_Type_wchar_t_0 ).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Type_wchar_t(ISourceLocation $loc, boolean $isMacroExpansion) {
public IConstructor Type_integer(ISourceLocation $loc, boolean $isMacroExpansion) {

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

kwParams.put("src", $loc);


if ($isMacroExpansion) kwParams.put("isMacroExpansion", vf.bool(true));
return vf.constructor(_Type_wchar_t_0 ).asWithKeywordParameters().setParameters(kwParams);
return vf.constructor(_Type_integer_0 ).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Type_integer(ISourceLocation $loc, boolean $isMacroExpansion) {
public IConstructor Type_decltype(IConstructor $expression, ISourceLocation $loc, boolean $isMacroExpansion) {

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

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

kwParams.put("src", $loc);


if ($isMacroExpansion) kwParams.put("isMacroExpansion", vf.bool(true));
return vf.constructor(_Type_integer_0 ).asWithKeywordParameters().setParameters(kwParams);
return vf.constructor(_Type_decltype_1 , $expression).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Type_float(ISourceLocation $loc, boolean $isMacroExpansion) {
Expand Down Expand Up @@ -5128,6 +5107,17 @@ public IConstructor Type_unionType(IConstructor $name, ISourceLocation $loc, boo
return vf.constructor(_Type_unionType_1 , $name).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Type_double(ISourceLocation $loc, boolean $isMacroExpansion) {

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

kwParams.put("src", $loc);


if ($isMacroExpansion) kwParams.put("isMacroExpansion", vf.bool(true));
return vf.constructor(_Type_double_0 ).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Type_decimal64(ISourceLocation $loc, boolean $isMacroExpansion) {

Map<String, IValue> kwParams = new HashMap<String, IValue>();
Expand All @@ -5150,6 +5140,21 @@ public IConstructor Type_auto(ISourceLocation $loc, boolean $isMacroExpansion) {
return vf.constructor(_Type_auto_0 ).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Type_typeof(IConstructor $expression, ISourceLocation $loc, boolean $isMacroExpansion) {

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

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

kwParams.put("src", $loc);


if ($isMacroExpansion) kwParams.put("isMacroExpansion", vf.bool(true));
return vf.constructor(_Type_typeof_1 , $expression).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Type_char32_t(ISourceLocation $loc, boolean $isMacroExpansion) {

Map<String, IValue> kwParams = new HashMap<String, IValue>();
Expand Down Expand Up @@ -5250,28 +5255,6 @@ public IConstructor Type_char16_t(ISourceLocation $loc, boolean $isMacroExpansio
return vf.constructor(_Type_char16_t_0 ).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Type_typeof(ISourceLocation $loc, boolean $isMacroExpansion) {

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

kwParams.put("src", $loc);


if ($isMacroExpansion) kwParams.put("isMacroExpansion", vf.bool(true));
return vf.constructor(_Type_typeof_0 ).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Type_double(ISourceLocation $loc, boolean $isMacroExpansion) {

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

kwParams.put("src", $loc);


if ($isMacroExpansion) kwParams.put("isMacroExpansion", vf.bool(true));
return vf.constructor(_Type_double_0 ).asWithKeywordParameters().setParameters(kwParams);
}


public IConstructor Statement_nullStatement(IList $attributes, ISourceLocation $loc, boolean $isMacroExpansion) {

Expand Down Expand Up @@ -7353,6 +7336,21 @@ public IConstructor Name_conversionName(String $value, IConstructor $typeId, ISo
return vf.constructor(_Name_conversionName_2 , vf.string($value), $typeId).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Name_decltypeName(IConstructor $expression, ISourceLocation $loc, boolean $isMacroExpansion) {

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

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

kwParams.put("src", $loc);


if ($isMacroExpansion) kwParams.put("isMacroExpansion", vf.bool(true));
return vf.constructor(_Name_decltypeName_1 , $expression).asWithKeywordParameters().setParameters(kwParams);
}

public IConstructor Name_operatorName(String $value, ISourceLocation $loc, boolean $isMacroExpansion) {

if (!vf.string($value).getType().isSubtypeOf(tf.stringType())) {
Expand Down
Loading
Loading