Skip to content

Commit

Permalink
parameterize mergeQualifiers by inh attr, Issue #106
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisCarlson committed May 1, 2018
1 parent ca97c84 commit d10f3e7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
2 changes: 1 addition & 1 deletion grammars/edu.umn.cs.melt.ableC/abstractsyntax/host/Name.sv
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function doValueRedeclarationCheckNoCompatible
function doValueMergeQualifiers
Type ::= t::Type n::Decorated Name
{
return foldr(\t1::Type t2::Type -> t2.mergeQualifiers(t1), t, map((.typerep), n.valueLocalLookup));
return foldr(\t1::Type t2::Type -> mergeQualifiers(t2, t1), t, map((.typerep), n.valueLocalLookup));
}

-- return
Expand Down
80 changes: 48 additions & 32 deletions grammars/edu.umn.cs.melt.ableC/abstractsyntax/host/Types.sv
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ grammar edu:umn:cs:melt:ableC:abstractsyntax:host;
- Variants: builtin, pointer, array, function, tagged, noncanonical.
- Noncanonical forwards, and so doesn't need any attributes, etc attached to it.
-}
nonterminal Type with lpp, rpp, host<Type>, baseTypeExpr, typeModifierExpr, mangledName, integerPromotions, defaultArgumentPromotions, defaultLvalueConversion, defaultFunctionArrayLvalueConversion, isIntegerType, isScalarType, isArithmeticType, withoutAttributes, withoutTypeQualifiers, withoutExtensionQualifiers<Type>, withTypeQualifiers, addedTypeQualifiers, qualifiers, mergeQualifiers<Type>, errors, freeVariables;
flowtype Type = decorate {}, baseTypeExpr {}, typeModifierExpr {}, integerPromotions {}, defaultArgumentPromotions {}, defaultLvalueConversion {}, defaultFunctionArrayLvalueConversion {}, isIntegerType {}, isScalarType {}, isArithmeticType {}, withoutAttributes {}, withoutTypeQualifiers {}, withoutExtensionQualifiers {}, withTypeQualifiers {addedTypeQualifiers}, qualifiers {}, mergeQualifiers {};
nonterminal Type with lpp, rpp, host<Type>, baseTypeExpr, typeModifierExpr, mangledName, integerPromotions, defaultArgumentPromotions, defaultLvalueConversion, defaultFunctionArrayLvalueConversion, isIntegerType, isScalarType, isArithmeticType, withoutAttributes, withoutTypeQualifiers, withoutExtensionQualifiers<Type>, withTypeQualifiers, addedTypeQualifiers, qualifiers, withMergedQualifiers<Type>, mergeQualifiersWith<Type>, errors, freeVariables;
flowtype Type = decorate {}, baseTypeExpr {}, typeModifierExpr {}, integerPromotions {}, defaultArgumentPromotions {}, defaultLvalueConversion {}, defaultFunctionArrayLvalueConversion {}, isIntegerType {}, isScalarType {}, isArithmeticType {}, withoutAttributes {}, withoutTypeQualifiers {}, withoutExtensionQualifiers {}, withTypeQualifiers {addedTypeQualifiers}, qualifiers {}, withMergedQualifiers {mergeQualifiersWith};

-- Used to turn a Type back into a TypeName
synthesized attribute baseTypeExpr :: BaseTypeExpr;
Expand Down Expand Up @@ -42,7 +42,8 @@ synthesized attribute withoutTypeQualifiers :: Type;
synthesized attribute withoutExtensionQualifiers<a> :: a;

-- To support accumulation of extension qualifiers on redeclaration
synthesized attribute mergeQualifiers<a> :: (a ::= a);
synthesized attribute withMergedQualifiers<a> :: a;
inherited attribute mergeQualifiersWith<a> :: a;

-- Used in addQualifiers to add qualifiers to a type
synthesized attribute withTypeQualifiers :: Type;
Expand Down Expand Up @@ -80,7 +81,7 @@ top::Type ::=
top.defaultFunctionArrayLvalueConversion = top;
top.withoutTypeQualifiers = top;
top.withoutExtensionQualifiers = top;
top.mergeQualifiers = \t2::Type -> errorType();
top.withMergedQualifiers = errorType();
top.qualifiers = [];
top.errors := [];
top.freeVariables = [];
Expand Down Expand Up @@ -118,8 +119,8 @@ top::Type ::= q::Qualifiers bt::BuiltinType
top.withoutExtensionQualifiers = builtinType(filterExtensionQualifiers(q), bt);
top.withTypeQualifiers = builtinType(foldQualifier(top.addedTypeQualifiers ++
q.qualifiers), bt);
top.mergeQualifiers = \t2::Type ->
case t2 of
top.withMergedQualifiers =
case top.mergeQualifiersWith of
builtinType(q2, bt2) -> builtinType(unionQualifiers(top.qualifiers, q2.qualifiers), bt)
| _ -> builtinType(q, bt)
end;
Expand Down Expand Up @@ -166,12 +167,13 @@ top::Type ::= q::Qualifiers target::Type
top.withoutExtensionQualifiers = pointerType(filterExtensionQualifiers(q), target.withoutExtensionQualifiers);
top.withTypeQualifiers = pointerType(foldQualifier(top.addedTypeQualifiers ++
q.qualifiers), target);
top.mergeQualifiers = \t2::Type ->
case t2 of
top.withMergedQualifiers =
case top.mergeQualifiersWith of
pointerType(q2, target2) ->
pointerType(unionQualifiers(top.qualifiers, q2.qualifiers), target.mergeQualifiers(target2))
pointerType(unionQualifiers(top.qualifiers, q2.qualifiers), mergeQualifiers(target, target2))
| _ -> pointerType(q, target)
end;

top.qualifiers = q.qualifiers;
top.errors := q.errors ++ target.errors;

Expand Down Expand Up @@ -240,10 +242,10 @@ top::Type ::= element::Type indexQualifiers::Qualifiers sizeModifier::ArraySiz
noncanonicalType(decayedType(top,
pointerType(indexQualifiers, element)));
top.withoutExtensionQualifiers = arrayType(element.withoutExtensionQualifiers, filterExtensionQualifiers(indexQualifiers), sizeModifier, sub);
top.mergeQualifiers = \t2::Type ->
case t2 of
top.withMergedQualifiers =
case top.mergeQualifiersWith of
arrayType(element2, q2, _, _) ->
arrayType(element.mergeQualifiers(element2),
arrayType(mergeQualifiers(element, element2),
unionQualifiers(top.qualifiers, q2.qualifiers), sizeModifier, sub)
| _ -> arrayType(element, indexQualifiers, sizeModifier, sub)
end;
Expand Down Expand Up @@ -323,10 +325,10 @@ top::Type ::= result::Type sub::FunctionType q::Qualifiers
top.defaultFunctionArrayLvalueConversion =
noncanonicalType(decayedType(top,
pointerType(nilQualifier(), top)));
top.mergeQualifiers = \t2::Type ->
case t2 of
top.withMergedQualifiers =
case top.mergeQualifiersWith of
functionType(result2, sub2, q2) ->
functionType(result.mergeQualifiers(result2), sub.mergeQualifiers(sub2), unionQualifiers(q.qualifiers, q2.qualifiers))
functionType(mergeQualifiers(result, result2), mergeQualifiersFunc(sub, sub2), unionQualifiers(q.qualifiers, q2.qualifiers))
| _ -> functionType(result, sub, q)
end;
top.qualifiers = q.qualifiers;
Expand All @@ -335,19 +337,19 @@ top::Type ::= result::Type sub::FunctionType q::Qualifiers
}

{-- The subtypes of functions -}
nonterminal FunctionType with lpp, rpp, host<FunctionType>, mangledName, withoutExtensionQualifiers<FunctionType>, mergeQualifiers<FunctionType>, errors, freeVariables;
flowtype FunctionType = decorate {};
nonterminal FunctionType with lpp, rpp, host<FunctionType>, mangledName, withoutExtensionQualifiers<FunctionType>, withMergedQualifiers<FunctionType>, mergeQualifiersWith<FunctionType>, errors, freeVariables;
flowtype FunctionType = decorate {}, withMergedQualifiers {mergeQualifiersWith};
-- clang has an 'extinfo' structure with calling convention, noreturn, 'produces'?, regparam

abstract production protoFunctionType
top::FunctionType ::= args::[Type] variadic::Boolean
{
top.host = protoFunctionType(map(\t::Type -> t.host, args), variadic);
top.withoutExtensionQualifiers = protoFunctionType(map(\t::Type -> t.withoutExtensionQualifiers, args), variadic);
top.mergeQualifiers = \t2::FunctionType ->
case t2 of
top.withMergedQualifiers =
case top.mergeQualifiersWith of
protoFunctionType(args2, _) ->
protoFunctionType(zipWith(\arg1::Type arg2::Type -> arg1.mergeQualifiers(arg2), args, args2), variadic)
protoFunctionType(zipWith(\arg1::Type arg2::Type -> mergeQualifiers(arg1, arg2), args, args2), variadic)
| _ -> protoFunctionType(args, variadic)
end;
top.lpp = notext();
Expand All @@ -370,7 +372,7 @@ abstract production noProtoFunctionType
top::FunctionType ::=
{
propagate host, withoutExtensionQualifiers;
top.mergeQualifiers = \t2::FunctionType -> noProtoFunctionType();
top.withMergedQualifiers = noProtoFunctionType();
top.lpp = notext();
top.rpp = text("()");
top.mangledName = "noproto";
Expand Down Expand Up @@ -417,8 +419,8 @@ top::Type ::= q::Qualifiers sub::TagType
top.withoutExtensionQualifiers = tagType(filterExtensionQualifiers(q), sub);
top.withTypeQualifiers = tagType(foldQualifier(top.addedTypeQualifiers ++
q.qualifiers), sub);
top.mergeQualifiers = \t2::Type ->
case t2 of
top.withMergedQualifiers =
case top.mergeQualifiersWith of
tagType(q2, _) ->
tagType(unionQualifiers(top.qualifiers, q2.qualifiers), sub)
| _ -> tagType(q, sub)
Expand Down Expand Up @@ -503,10 +505,10 @@ top::Type ::= q::Qualifiers bt::Type
top.withoutExtensionQualifiers = atomicType(filterExtensionQualifiers(q), bt.withoutExtensionQualifiers);
top.withTypeQualifiers = atomicType(foldQualifier(top.addedTypeQualifiers ++
q.qualifiers), bt);
top.mergeQualifiers = \t2::Type ->
case t2 of
top.withMergedQualifiers =
case top.mergeQualifiersWith of
atomicType(q2, bt2) ->
atomicType(unionQualifiers(top.qualifiers, q2.qualifiers), bt.mergeQualifiers(bt2))
atomicType(unionQualifiers(top.qualifiers, q2.qualifiers), mergeQualifiers(bt, bt2))
| _ -> atomicType(q, bt)
end;
top.qualifiers = q.qualifiers;
Expand Down Expand Up @@ -539,10 +541,10 @@ top::Type ::= attrs::Attributes bt::Type
top.withoutTypeQualifiers = attributedType(attrs, bt.withoutTypeQualifiers);
top.withTypeQualifiers = attributedType(attrs, bt.withTypeQualifiers);
bt.addedTypeQualifiers = top.addedTypeQualifiers;
top.mergeQualifiers = \t2::Type ->
case t2 of
top.withMergedQualifiers =
case top.mergeQualifiersWith of
attributedType(_, bt2) ->
attributedType(attrs, bt.mergeQualifiers(bt2))
attributedType(attrs, mergeQualifiers(bt, bt2))
| _ -> attributedType(attrs, bt)
end;
top.qualifiers = bt.qualifiers;
Expand Down Expand Up @@ -588,10 +590,10 @@ top::Type ::= bt::Type bytes::Integer
top.defaultLvalueConversion = top;
top.defaultFunctionArrayLvalueConversion = top;
top.withTypeQualifiers = top; -- TODO Discarding Qualifiers!
top.mergeQualifiers = \t2::Type ->
case t2 of
top.withMergedQualifiers =
case top.mergeQualifiersWith of
vectorType(bt2, _) ->
vectorType(bt.mergeQualifiers(bt2), bytes)
vectorType(mergeQualifiers(bt, bt2), bytes)
| _ -> vectorType(bt, bytes)
end;
top.qualifiers = [];
Expand Down Expand Up @@ -755,6 +757,20 @@ Qualifiers ::= q::Qualifiers
return foldQualifier(filter((.qualIsHost), q.qualifiers));
}

function mergeQualifiers
Type ::= t1::Type t2::Type
{
t1.mergeQualifiersWith = t2;
return t1.withMergedQualifiers;
}

function mergeQualifiersFunc
FunctionType ::= t1::FunctionType t2::FunctionType
{
t1.mergeQualifiersWith = t2;
return t1.withMergedQualifiers;
}

{-
NON_CANONICAL_UNLESS_DEPENDENT_TYPE(TypeOfExpr, Type)
NON_CANONICAL_UNLESS_DEPENDENT_TYPE(TypeOf, Type)
Expand Down

0 comments on commit d10f3e7

Please sign in to comment.