Skip to content

Commit

Permalink
Fixes #63: Make sure all parameters have at least one of in/out attri…
Browse files Browse the repository at this point in the history
…butes.

Fixes #139: Better deal with params marked with __RPC__ SAL annotations
  • Loading branch information
Steve Otteson committed Feb 25, 2021
1 parent 21b38e4 commit 42dfffe
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
34 changes: 34 additions & 0 deletions sources/ClangSharpSourceToWinmd/ClangSharpSourceWinmdGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,40 @@ public Parameter(ClangSharpSourceWinmdGenerator generator, IMethodSymbol methodS
parameterAttributes |= ParameterAttributes.Optional;
}

// If we don't have any in/out attributes, figure out some sensible values
if (parameterAttributes == ParameterAttributes.None)
{
// https://github.com/microsoft/win32metadata/issues/63
// * If it's a primitive or a COM pointer, it's In.
// * If it's a pointer it's In, Out, unless it's marked Const, then only In.
// * If it's a COM double pointer (e.g. IUnknown**), it's Out.
parameterAttributes |= ParameterAttributes.In;
if (paramType is IPointerTypeSymbol pointerTypeSymbol)
{
// If we're not pointing at an interface...
if (!generator.IsSymbolInterface(pointerTypeSymbol.PointedAtType))
{
bool isConst = symbolAttrs.Any(a => a.AttributeClass.Name == "ConstAttribute");

// Only add Out if it's not const
if (!isConst)
{
parameterAttributes |= ParameterAttributes.Out;
}
}

// If it's a double pointer...
if (pointerTypeSymbol.PointedAtType is IPointerTypeSymbol doublePointedAtType)
{
// Only use "Out" if it's a double COM pointer
if (generator.IsSymbolInterface(doublePointedAtType.PointedAtType))
{
parameterAttributes = ParameterAttributes.Out;
}
}
}
}

this.Name = paramName;
this.Attrs = parameterAttributes;
this.Type = paramType;
Expand Down
29 changes: 29 additions & 0 deletions sources/ClangSharpSourceToWinmd/MetadataSyntaxTreeCleaner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,35 @@ private SyntaxNode CreateAttributeListForSal(AttributeListSyntax cppAttrList)
isOut = true;
continue;
}
else if (salAttr.P1.StartsWith("__RPC__"))
{
// TODO: Handle ecount, xcount and others that deal with counts

string[] parts = salAttr.P1.Split('_');
foreach (var part in parts)
{
switch (part)
{
case "in":
isIn = true;
break;

case "out":
isOut = true;
break;

case "inout":
isIn = isOut = true;
break;

case "opt":
isOpt = true;
break;
}
}

break;
}
}

if (salAttr.Name == "SAL_null" && salAttr.P1 == "__maybe")
Expand Down

0 comments on commit 42dfffe

Please sign in to comment.