Browse Source

Changed the return type of functions to be a qualified type.

pull/1/head
triton 12 years ago
parent
commit
d37cca5ca1
  1. 5
      src/Bridge/ASTVisitor.cs
  2. 7
      src/Bridge/Function.cs
  3. 2
      src/Bridge/Method.cs
  4. 3
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  5. 2
      src/Generator/Generators/CLI/CLIMarshal.cs
  6. 19
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  7. 18
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  8. 2
      src/Generator/Generators/Marshal.cs
  9. 2
      src/Generator/Passes/CheckAbiParameters.cs
  10. 2
      src/Generator/Passes/ResolveIncompleteDeclsPass.cs
  11. 2
      src/Generator/Types/Std/Stdlib.cs
  12. 2
      src/Generator/Types/Types.cs
  13. 3
      src/Parser/Parser.cpp

5
src/Bridge/ASTVisitor.cs

@ -225,8 +225,9 @@ namespace CppSharp @@ -225,8 +225,9 @@ namespace CppSharp
if (!VisitDeclaration(function))
return false;
if (function.ReturnType != null)
function.ReturnType.Visit(this);
var retType = function.ReturnType;
if (retType.Type != null)
retType.Type.Visit(this, retType.Qualifiers);
foreach (var param in function.Parameters)
param.Visit(this);

7
src/Bridge/Function.cs

@ -55,7 +55,7 @@ namespace CppSharp @@ -55,7 +55,7 @@ namespace CppSharp
}
}
public class Function : Declaration
public class Function : Declaration, ITypedDecl
{
public Function()
{
@ -65,7 +65,7 @@ namespace CppSharp @@ -65,7 +65,7 @@ namespace CppSharp
IsInline = false;
}
public Type ReturnType { get; set; }
public QualifiedType ReturnType { get; set; }
public List<Parameter> Parameters { get; set; }
public bool IsVariadic { get; set; }
public bool IsInline { get; set; }
@ -108,5 +108,8 @@ namespace CppSharp @@ -108,5 +108,8 @@ namespace CppSharp
{
return visitor.VisitFunctionDecl(this);
}
public Type Type { get { return ReturnType.Type; } }
public QualifiedType QualifiedType { get { return ReturnType; } }
}
}

2
src/Bridge/Method.cs

@ -61,7 +61,7 @@ namespace CppSharp @@ -61,7 +61,7 @@ namespace CppSharp
/// <summary>
/// Represents a C++ record method declaration.
/// </summary>
public class Method : Function
public class Method : Function, ITypedDecl
{
public Method()
{

3
src/Generator/Generators/CLI/CLIHeadersTemplate.cs

@ -280,7 +280,8 @@ namespace CppSharp.Generators.CLI @@ -280,7 +280,8 @@ namespace CppSharp.Generators.CLI
printer.Context = typeCtx;
var typePrinter = new CLITypePrinter(Driver, typeCtx);
var retType = function.ReturnType.Visit(typePrinter);
var retType = function.ReturnType.Type.Visit(typePrinter,
function.ReturnType.Qualifiers);
WriteLine("generic<{0}>", string.Join(", ", typeNames));
WriteLine("{0} {1}({2});", retType, SafeIdentifier(function.Name),

2
src/Generator/Generators/CLI/CLIMarshal.cs

@ -170,7 +170,7 @@ namespace CppSharp.Generators.CLI @@ -170,7 +170,7 @@ namespace CppSharp.Generators.CLI
{
var instance = string.Empty;
if (!Context.ReturnType.IsPointer())
if (!Context.ReturnType.Type.IsPointer())
instance += "&";
instance += Context.ReturnVarName;

19
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -200,7 +200,8 @@ namespace CppSharp.Generators.CLI @@ -200,7 +200,8 @@ namespace CppSharp.Generators.CLI
printer.Context = typeCtx;
var typePrinter = new CLITypePrinter(Driver, typeCtx);
var retType = function.ReturnType.Visit(typePrinter);
var retType = function.ReturnType.Type.Visit(typePrinter,
function.ReturnType.Qualifiers);
WriteLine("generic<{0}>", string.Join(", ", typeNames));
WriteLine("{0} {1}::{2}({3})", retType, QualifiedIdentifier(@class),
@ -283,7 +284,7 @@ namespace CppSharp.Generators.CLI @@ -283,7 +284,7 @@ namespace CppSharp.Generators.CLI
{
ArgName = decl.Name,
ReturnVarName = variable,
ReturnType = decl.Type
ReturnType = decl.QualifiedType
};
var marshal = new CLIMarshalNativeToManagedPrinter(ctx);
@ -394,7 +395,7 @@ namespace CppSharp.Generators.CLI @@ -394,7 +395,7 @@ namespace CppSharp.Generators.CLI
var ctx = new MarshalContext(Driver)
{
ReturnVarName = param.Name,
ReturnType = param.Type
ReturnType = param.QualifiedType
};
var marshal = new CLIMarshalNativeToManagedPrinter(ctx);
@ -476,7 +477,7 @@ namespace CppSharp.Generators.CLI @@ -476,7 +477,7 @@ namespace CppSharp.Generators.CLI
{
ArgName = field.Name,
ReturnVarName = nativeField,
ReturnType = field.Type
ReturnType = field.QualifiedType
};
var marshal = new CLIMarshalNativeToManagedPrinter(ctx);
@ -604,7 +605,7 @@ namespace CppSharp.Generators.CLI @@ -604,7 +605,7 @@ namespace CppSharp.Generators.CLI
var ctx = new MarshalContext(Driver)
{
ReturnVarName = varName,
ReturnType = field.Type
ReturnType = field.QualifiedType
};
var marshal = new CLIMarshalNativeToManagedPrinter(ctx);
@ -649,7 +650,7 @@ namespace CppSharp.Generators.CLI @@ -649,7 +650,7 @@ namespace CppSharp.Generators.CLI
public void GenerateFunctionCall(Function function, Class @class = null)
{
var retType = function.ReturnType;
var needsReturn = !retType.IsPrimitiveType(PrimitiveType.Void);
var needsReturn = !retType.Type.IsPrimitiveType(PrimitiveType.Void);
const string valueMarshalName = "_this0";
var isValueType = @class != null && @class.IsValueType;
@ -670,7 +671,7 @@ namespace CppSharp.Generators.CLI @@ -670,7 +671,7 @@ namespace CppSharp.Generators.CLI
var @params = GenerateFunctionParamsMarshal(function.Parameters, function);
if (needsReturn)
Write("auto {0}ret = ",(function.ReturnType.IsReference())? "&": string.Empty);
Write("auto {0}ret = ",(function.ReturnType.Type.IsReference())? "&": string.Empty);
if (isValueType)
{
@ -706,7 +707,7 @@ namespace CppSharp.Generators.CLI @@ -706,7 +707,7 @@ namespace CppSharp.Generators.CLI
{
ArgName = nativeVarName,
ReturnVarName = nativeVarName,
ReturnType = param.Type
ReturnType = param.QualifiedType
};
var marshal = new CLIMarshalNativeToManagedPrinter(ctx);
@ -733,7 +734,7 @@ namespace CppSharp.Generators.CLI @@ -733,7 +734,7 @@ namespace CppSharp.Generators.CLI
};
var marshal = new CLIMarshalNativeToManagedPrinter(ctx);
function.ReturnType.Visit(marshal);
function.ReturnType.Type.Visit(marshal, function.ReturnType.Qualifiers);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);

18
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -366,7 +366,7 @@ namespace CppSharp.Generators.CSharp @@ -366,7 +366,7 @@ namespace CppSharp.Generators.CSharp
Kind = CSharpMarshalKind.NativeField,
ArgName = field.Name,
ReturnVarName = nativeField,
ReturnType = field.Type
ReturnType = field.QualifiedType
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
@ -962,7 +962,7 @@ namespace CppSharp.Generators.CSharp @@ -962,7 +962,7 @@ namespace CppSharp.Generators.CSharp
var ctx = new CSharpMarshalContext(Driver)
{
ReturnVarName = nativeField,
ReturnType = field.Type
ReturnType = field.QualifiedType
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
@ -986,7 +986,7 @@ namespace CppSharp.Generators.CSharp @@ -986,7 +986,7 @@ namespace CppSharp.Generators.CSharp
Function function, Class @class = null)
{
var retType = function.ReturnType;
var needsReturn = !retType.IsPrimitiveType(PrimitiveType.Void);
var needsReturn = !retType.Type.IsPrimitiveType(PrimitiveType.Void);
var method = function as Method;
var needsInstance = method != null && !method.IsStatic && !method.IsOperator;
@ -997,12 +997,12 @@ namespace CppSharp.Generators.CSharp @@ -997,12 +997,12 @@ namespace CppSharp.Generators.CSharp
Class retClass = null;
if (function.HasHiddenStructParameter)
{
function.ReturnType.IsTagDecl(out retClass);
function.ReturnType.Type.IsTagDecl(out retClass);
WriteLine("var {0} = new {1}.Internal();", GeneratedIdentifier("udt"),
retClass.OriginalName);
retType = new BuiltinType(PrimitiveType.Void);
retType.Type = new BuiltinType(PrimitiveType.Void);
needsReturn = false;
}
@ -1063,7 +1063,7 @@ namespace CppSharp.Generators.CSharp @@ -1063,7 +1063,7 @@ namespace CppSharp.Generators.CSharp
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
function.ReturnType.Visit(marshal);
function.ReturnType.Type.Visit(marshal, function.ReturnType.Qualifiers);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
@ -1104,7 +1104,7 @@ namespace CppSharp.Generators.CSharp @@ -1104,7 +1104,7 @@ namespace CppSharp.Generators.CSharp
{
ArgName = nativeVarName,
ReturnVarName = nativeVarName,
ReturnType = param.Type
ReturnType = param.QualifiedType
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
@ -1413,7 +1413,7 @@ namespace CppSharp.Generators.CSharp @@ -1413,7 +1413,7 @@ namespace CppSharp.Generators.CSharp
Helpers.ToCSharpCallConv(function.CallingConvention));
WriteLineIndent("EntryPoint=\"{0}\")]", function.Mangled);
if (function.ReturnType.Desugar().IsPrimitiveType(PrimitiveType.Bool))
if (function.ReturnType.Type.Desugar().IsPrimitiveType(PrimitiveType.Bool))
WriteLine("[return: MarshalAsAttribute(UnmanagedType.I1)]");
var @params = new List<string>();
@ -1421,7 +1421,7 @@ namespace CppSharp.Generators.CSharp @@ -1421,7 +1421,7 @@ namespace CppSharp.Generators.CSharp
var typePrinter = TypePrinter as CSharpTypePrinter;
var retType = typePrinter.VisitParameterDecl(new Parameter()
{
QualifiedType = new QualifiedType() { Type = function.ReturnType }
QualifiedType = function.ReturnType
});
var method = function as Method;

2
src/Generator/Generators/Marshal.cs

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
public TextGenerator Return { get; private set; }
public string ReturnVarName { get; set; }
public Type ReturnType { get; set; }
public QualifiedType ReturnType { get; set; }
public string ArgName { get; set; }
public Parameter Parameter { get; set; }

2
src/Generator/Passes/CheckAbiParameters.cs

@ -38,7 +38,7 @@ @@ -38,7 +38,7 @@
// http://blog.aaronballman.com/2012/02/describing-the-msvc-abi-for-structure-return-types/
Class retClass;
if (!method.ReturnType.IsTagDecl(out retClass))
if (!method.ReturnType.Type.IsTagDecl(out retClass))
return false;
// TODO: Add the various combinations for that need hidden parameter

2
src/Generator/Passes/ResolveIncompleteDeclsPass.cs

@ -54,7 +54,7 @@ namespace CppSharp.Passes @@ -54,7 +54,7 @@ namespace CppSharp.Passes
var ret = function.ReturnType;
string msg;
if (HasInvalidType(ret, out msg))
if (HasInvalidType(ret.Type, out msg))
{
function.ExplicityIgnored = true;
Console.WriteLine("Function '{0}' was ignored due to {1} return decl",

2
src/Generator/Types/Std/Stdlib.cs

@ -154,7 +154,7 @@ namespace CppSharp.Types.Std @@ -154,7 +154,7 @@ namespace CppSharp.Types.Std
var elementCtx = new MarshalContext(ctx.Driver)
{
ReturnVarName = "_element",
ReturnType = type.Type
ReturnType = type
};
var marshal = new CLIMarshalNativeToManagedPrinter(elementCtx);

2
src/Generator/Types/Types.cs

@ -38,7 +38,7 @@ namespace CppSharp @@ -38,7 +38,7 @@ namespace CppSharp
public override bool VisitFunctionDecl(Function function)
{
if (!function.ReturnType.Visit(this))
if (!function.ReturnType.Type.Visit(this, function.ReturnType.Qualifiers))
return false;
foreach (var param in function.Parameters)

3
src/Parser/Parser.cpp

@ -1211,7 +1211,8 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::Function^ F, @@ -1211,7 +1211,8 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::Function^ F,
//RTL = ResolveTypeLoc(TL).getAs<FunctionTypeLoc>.getResultLoc();
RTL = TL.getAs<FunctionTypeLoc>().getResultLoc();
}
F->ReturnType = WalkType(FD->getResultType(), &RTL);
F->ReturnType = GetQualifiedType(FD->getResultType(),
WalkType(FD->getResultType(), &RTL));
String Mangled = GetDeclMangledName(FD, TargetABI, IsDependent);
F->Mangled = marshalString<E_UTF8>(Mangled);

Loading…
Cancel
Save