Browse Source

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

pull/1/head
triton 13 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
if (!VisitDeclaration(function)) if (!VisitDeclaration(function))
return false; return false;
if (function.ReturnType != null) var retType = function.ReturnType;
function.ReturnType.Visit(this); if (retType.Type != null)
retType.Type.Visit(this, retType.Qualifiers);
foreach (var param in function.Parameters) foreach (var param in function.Parameters)
param.Visit(this); param.Visit(this);

7
src/Bridge/Function.cs

@ -55,7 +55,7 @@ namespace CppSharp
} }
} }
public class Function : Declaration public class Function : Declaration, ITypedDecl
{ {
public Function() public Function()
{ {
@ -65,7 +65,7 @@ namespace CppSharp
IsInline = false; IsInline = false;
} }
public Type ReturnType { get; set; } public QualifiedType ReturnType { get; set; }
public List<Parameter> Parameters { get; set; } public List<Parameter> Parameters { get; set; }
public bool IsVariadic { get; set; } public bool IsVariadic { get; set; }
public bool IsInline { get; set; } public bool IsInline { get; set; }
@ -108,5 +108,8 @@ namespace CppSharp
{ {
return visitor.VisitFunctionDecl(this); 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
/// <summary> /// <summary>
/// Represents a C++ record method declaration. /// Represents a C++ record method declaration.
/// </summary> /// </summary>
public class Method : Function public class Method : Function, ITypedDecl
{ {
public Method() public Method()
{ {

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

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

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

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

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

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

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

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

2
src/Generator/Generators/Marshal.cs

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

2
src/Generator/Passes/CheckAbiParameters.cs

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

2
src/Generator/Passes/ResolveIncompleteDeclsPass.cs

@ -54,7 +54,7 @@ namespace CppSharp.Passes
var ret = function.ReturnType; var ret = function.ReturnType;
string msg; string msg;
if (HasInvalidType(ret, out msg)) if (HasInvalidType(ret.Type, out msg))
{ {
function.ExplicityIgnored = true; function.ExplicityIgnored = true;
Console.WriteLine("Function '{0}' was ignored due to {1} return decl", 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
var elementCtx = new MarshalContext(ctx.Driver) var elementCtx = new MarshalContext(ctx.Driver)
{ {
ReturnVarName = "_element", ReturnVarName = "_element",
ReturnType = type.Type ReturnType = type
}; };
var marshal = new CLIMarshalNativeToManagedPrinter(elementCtx); var marshal = new CLIMarshalNativeToManagedPrinter(elementCtx);

2
src/Generator/Types/Types.cs

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

3
src/Parser/Parser.cpp

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

Loading…
Cancel
Save