Browse Source

Obsolete managed expression class machinery.

pull/1177/head
Joao Matos 6 years ago committed by João Matos
parent
commit
aa73692543
  1. 60
      src/AST/Expression.cs
  2. 6
      src/AST/Function.cs
  3. 2
      src/AST/IExpressionPrinter.cs
  4. 2
      src/AST/LayoutField.cs
  5. 2
      src/AST/Template.cs
  6. 34
      src/CppParser/Parser.cpp
  7. 2
      src/CppParser/Parser.h
  8. 10
      src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs
  9. 12
      src/Generator/Passes/HandleDefaultParamValuesPass.cs
  10. 16
      src/Parser/ASTConverter.cs

60
src/AST/Expression.cs

@ -4,16 +4,16 @@ using System.Linq; @@ -4,16 +4,16 @@ using System.Linq;
namespace CppSharp.AST
{
public abstract class Expression : Statement
public abstract class ExpressionObsolete : Statement
{
public string DebugText;
public abstract TV Visit<TV>(IExpressionVisitor<TV> visitor);
public abstract TV Visit<TV>(IExpressionVisitorObsolete<TV> visitor);
public abstract Expression Clone();
public abstract ExpressionObsolete Clone();
}
public class BuiltinTypeExpression : Expression
public class BuiltinTypeExpressionObsolete : ExpressionObsolete
{
public long Value { get; set; }
@ -39,14 +39,14 @@ namespace CppSharp.AST @@ -39,14 +39,14 @@ namespace CppSharp.AST
return printAsHex ? "0x" + value : value;
}
public override T Visit<T>(IExpressionVisitor<T> visitor)
public override T Visit<T>(IExpressionVisitorObsolete<T> visitor)
{
return visitor.VisitExpression(this);
}
public override Expression Clone()
public override ExpressionObsolete Clone()
{
return new BuiltinTypeExpression
return new BuiltinTypeExpressionObsolete
{
Value = this.Value,
Type = this.Type,
@ -58,9 +58,9 @@ namespace CppSharp.AST @@ -58,9 +58,9 @@ namespace CppSharp.AST
}
}
public class BinaryOperator : Expression
public class BinaryOperatorObsolete : ExpressionObsolete
{
public BinaryOperator(Expression lhs, Expression rhs, string opcodeStr)
public BinaryOperatorObsolete(ExpressionObsolete lhs, ExpressionObsolete rhs, string opcodeStr)
{
Class = StatementClass.BinaryOperator;
LHS = lhs;
@ -68,18 +68,18 @@ namespace CppSharp.AST @@ -68,18 +68,18 @@ namespace CppSharp.AST
OpcodeStr = opcodeStr;
}
public Expression LHS { get; set; }
public Expression RHS { get; set; }
public ExpressionObsolete LHS { get; set; }
public ExpressionObsolete RHS { get; set; }
public string OpcodeStr { get; set; }
public override T Visit<T>(IExpressionVisitor<T> visitor)
public override T Visit<T>(IExpressionVisitorObsolete<T> visitor)
{
return visitor.VisitExpression(this);
}
public override Expression Clone()
public override ExpressionObsolete Clone()
{
return new BinaryOperator(LHS.Clone(), RHS.Clone(), OpcodeStr)
return new BinaryOperatorObsolete(LHS.Clone(), RHS.Clone(), OpcodeStr)
{
DebugText = this.DebugText,
Declaration = this.Declaration,
@ -88,24 +88,24 @@ namespace CppSharp.AST @@ -88,24 +88,24 @@ namespace CppSharp.AST
}
}
public class CallExpr : Expression
public class CallExprObsolete : ExpressionObsolete
{
public CallExpr()
public CallExprObsolete()
{
Class = StatementClass.Call;
Arguments = new List<Expression>();
Arguments = new List<ExpressionObsolete>();
}
public List<Expression> Arguments { get; private set; }
public List<ExpressionObsolete> Arguments { get; private set; }
public override T Visit<T>(IExpressionVisitor<T> visitor)
public override T Visit<T>(IExpressionVisitorObsolete<T> visitor)
{
return visitor.VisitExpression(this);
}
public override Expression Clone()
public override ExpressionObsolete Clone()
{
var clone = new CallExpr
var clone = new CallExprObsolete
{
DebugText = this.DebugText,
Declaration = this.Declaration,
@ -116,24 +116,24 @@ namespace CppSharp.AST @@ -116,24 +116,24 @@ namespace CppSharp.AST
}
}
public class CXXConstructExpr : Expression
public class CXXConstructExprObsolete : ExpressionObsolete
{
public CXXConstructExpr()
public CXXConstructExprObsolete()
{
Class = StatementClass.ConstructorReference;
Arguments = new List<Expression>();
Arguments = new List<ExpressionObsolete>();
}
public List<Expression> Arguments { get; private set; }
public List<ExpressionObsolete> Arguments { get; private set; }
public override T Visit<T>(IExpressionVisitor<T> visitor)
public override T Visit<T>(IExpressionVisitorObsolete<T> visitor)
{
return visitor.VisitExpression(this);
}
public override Expression Clone()
public override ExpressionObsolete Clone()
{
var clone = new CXXConstructExpr
var clone = new CXXConstructExprObsolete
{
DebugText = this.DebugText,
Declaration = this.Declaration,
@ -144,8 +144,8 @@ namespace CppSharp.AST @@ -144,8 +144,8 @@ namespace CppSharp.AST
}
}
public interface IExpressionVisitor<out T>
public interface IExpressionVisitorObsolete<out T>
{
T VisitExpression(Expression exp);
T VisitExpression(ExpressionObsolete exp);
}
}

6
src/AST/Function.cs

@ -63,7 +63,7 @@ namespace CppSharp.AST @@ -63,7 +63,7 @@ namespace CppSharp.AST
public ParameterUsage Usage { get; set; }
public bool HasDefaultValue { get; set; }
public Expression DefaultArgument
public ExpressionObsolete DefaultArgument
{
get
{
@ -77,7 +77,7 @@ namespace CppSharp.AST @@ -77,7 +77,7 @@ namespace CppSharp.AST
}
}
public Expression OriginalDefaultArgument { get; set; }
public ExpressionObsolete OriginalDefaultArgument { get; set; }
public bool IsIn => Usage == ParameterUsage.In;
public bool IsOut => Usage == ParameterUsage.Out;
@ -100,7 +100,7 @@ namespace CppSharp.AST @@ -100,7 +100,7 @@ namespace CppSharp.AST
get { return DebugText.StartsWith("const ", System.StringComparison.Ordinal); }
}
Expression defaultArgument;
ExpressionObsolete defaultArgument;
}
public class ParameterTypeComparer : IEqualityComparer<Parameter>

2
src/AST/IExpressionPrinter.cs

@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
string ToString(Type type);
}
public interface IExpressionPrinter<out T> : IExpressionPrinter, IExpressionVisitor<T>
public interface IExpressionPrinter<out T> : IExpressionPrinter, IExpressionVisitorObsolete<T>
{
}
}

2
src/AST/LayoutField.cs

@ -9,7 +9,7 @@ namespace CppSharp.AST @@ -9,7 +9,7 @@ namespace CppSharp.AST
public string Name { get; set; }
public IntPtr FieldPtr { get; set; }
public bool IsVTablePtr { get { return FieldPtr == IntPtr.Zero; } }
public Expression Expression { get; set; }
public ExpressionObsolete Expression { get; set; }
public override string ToString()
{

2
src/AST/Template.cs

@ -93,7 +93,7 @@ namespace CppSharp.AST @@ -93,7 +93,7 @@ namespace CppSharp.AST
/// </summary>
public bool IsParameterPack { get; set; }
public Expression DefaultArgument { get; set; }
public ExpressionObsolete DefaultArgument { get; set; }
/// <summary>
/// Get the position of the template parameter within its parameter list.

34
src/CppParser/Parser.cpp

@ -1365,7 +1365,7 @@ NonTypeTemplateParameter* Parser::WalkNonTypeTemplateParameter(const clang::NonT @@ -1365,7 +1365,7 @@ NonTypeTemplateParameter* Parser::WalkNonTypeTemplateParameter(const clang::NonT
NTP->name = GetDeclName(NTTPD);
HandleDeclaration(NTTPD, NTP);
if (NTTPD->hasDefaultArgument())
NTP->defaultArgument = WalkExpression(NTTPD->getDefaultArgument());
NTP->defaultArgument = WalkExpressionObsolete(NTTPD->getDefaultArgument());
NTP->depth = NTTPD->getDepth();
NTP->index = NTTPD->getIndex();
NTP->isParameterPack = NTTPD->isParameterPack();
@ -2980,9 +2980,9 @@ Parameter* Parser::WalkParameter(const clang::ParmVarDecl* PVD, @@ -2980,9 +2980,9 @@ Parameter* Parser::WalkParameter(const clang::ParmVarDecl* PVD,
if (PVD->hasDefaultArg() && !PVD->hasUnparsedDefaultArg())
{
if (PVD->hasUninstantiatedDefaultArg())
P->defaultArgument = WalkExpression(PVD->getUninstantiatedDefaultArg());
P->defaultArgument = WalkExpressionObsolete(PVD->getUninstantiatedDefaultArg());
else
P->defaultArgument = WalkExpression(PVD->getDefaultArg());
P->defaultArgument = WalkExpressionObsolete(PVD->getDefaultArg());
}
HandleDeclaration(PVD, P);
walkedParameters[PVD] = P;
@ -3020,10 +3020,10 @@ static bool IsInvalid(clang::Stmt* Body, std::unordered_set<clang::Stmt*>& Bodie @@ -3020,10 +3020,10 @@ static bool IsInvalid(clang::Stmt* Body, std::unordered_set<clang::Stmt*>& Bodie
switch (Body->getStmtClass())
{
case clang::Stmt::StmtClass::DeclRefExprClass:
D = cast<DeclRefExpr>(Body)->getDecl();
D = cast<clang::DeclRefExpr>(Body)->getDecl();
break;
case clang::Stmt::StmtClass::MemberExprClass:
D = cast<MemberExpr>(Body)->getMemberDecl();
D = cast<clang::MemberExpr>(Body)->getMemberDecl();
break;
}
if (D)
@ -3512,7 +3512,7 @@ void Parser::HandlePreprocessedEntities(Declaration* Decl) @@ -3512,7 +3512,7 @@ void Parser::HandlePreprocessedEntities(Declaration* Decl)
}
}
AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr)
AST::ExpressionObsolete* Parser::WalkExpressionObsolete(const clang::Expr* Expr)
{
using namespace clang;
@ -3522,7 +3522,7 @@ AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr) @@ -3522,7 +3522,7 @@ AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr)
{
auto BinaryOperator = cast<clang::BinaryOperator>(Expr);
return new AST::BinaryOperatorObsolete(GetStringFromStatement(Expr),
WalkExpression(BinaryOperator->getLHS()), WalkExpression(BinaryOperator->getRHS()),
WalkExpressionObsolete(BinaryOperator->getLHS()), WalkExpressionObsolete(BinaryOperator->getRHS()),
BinaryOperator->getOpcodeStr().str());
}
case clang::Stmt::CallExprClass:
@ -3532,13 +3532,13 @@ AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr) @@ -3532,13 +3532,13 @@ AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr)
CallExpr->getCalleeDecl() ? WalkDeclaration(CallExpr->getCalleeDecl()) : 0);
for (auto arg : CallExpr->arguments())
{
CallExpression->Arguments.push_back(WalkExpression(arg));
CallExpression->Arguments.push_back(WalkExpressionObsolete(arg));
}
return CallExpression;
}
case clang::Stmt::DeclRefExprClass:
return new AST::ExpressionObsolete(GetStringFromStatement(Expr), StatementClassObsolete::DeclRefExprClass,
WalkDeclaration(cast<DeclRefExpr>(Expr)->getDecl()));
WalkDeclaration(cast<clang::DeclRefExpr>(Expr)->getDecl()));
case clang::Stmt::CStyleCastExprClass:
case clang::Stmt::CXXConstCastExprClass:
case clang::Stmt::CXXDynamicCastExprClass:
@ -3546,10 +3546,10 @@ AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr) @@ -3546,10 +3546,10 @@ AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr)
case clang::Stmt::CXXReinterpretCastExprClass:
case clang::Stmt::CXXStaticCastExprClass:
case clang::Stmt::ImplicitCastExprClass:
return WalkExpression(cast<CastExpr>(Expr)->getSubExprAsWritten());
return WalkExpressionObsolete(cast<clang::CastExpr>(Expr)->getSubExprAsWritten());
case clang::Stmt::CXXOperatorCallExprClass:
{
auto OperatorCallExpr = cast<CXXOperatorCallExpr>(Expr);
auto OperatorCallExpr = cast<clang::CXXOperatorCallExpr>(Expr);
return new AST::ExpressionObsolete(GetStringFromStatement(Expr), StatementClassObsolete::CXXOperatorCallExpr,
OperatorCallExpr->getCalleeDecl() ? WalkDeclaration(OperatorCallExpr->getCalleeDecl()) : 0);
}
@ -3564,11 +3564,11 @@ AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr) @@ -3564,11 +3564,11 @@ AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr)
if (TemporaryExpr)
{
auto SubTemporaryExpr = TemporaryExpr->GetTemporaryExpr();
auto Cast = dyn_cast<CastExpr>(SubTemporaryExpr);
auto Cast = dyn_cast<clang::CastExpr>(SubTemporaryExpr);
if (!Cast ||
(Cast->getSubExprAsWritten()->getStmtClass() != clang::Stmt::IntegerLiteralClass &&
Cast->getSubExprAsWritten()->getStmtClass() != clang::Stmt::CXXNullPtrLiteralExprClass))
return WalkExpression(SubTemporaryExpr);
return WalkExpressionObsolete(SubTemporaryExpr);
return new AST::CXXConstructExprObsolete(GetStringFromStatement(Expr),
WalkDeclaration(ConstructorExpr->getConstructor()));
}
@ -3577,16 +3577,16 @@ AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr) @@ -3577,16 +3577,16 @@ AST::ExpressionObsolete* Parser::WalkExpression(const clang::Expr* Expr)
WalkDeclaration(ConstructorExpr->getConstructor()));
for (auto arg : ConstructorExpr->arguments())
{
ConstructorExpression->Arguments.push_back(WalkExpression(arg));
ConstructorExpression->Arguments.push_back(WalkExpressionObsolete(arg));
}
return ConstructorExpression;
}
case clang::Stmt::CXXBindTemporaryExprClass:
return WalkExpression(cast<CXXBindTemporaryExpr>(Expr)->getSubExpr());
return WalkExpressionObsolete(cast<clang::CXXBindTemporaryExpr>(Expr)->getSubExpr());
case clang::Stmt::CXXDefaultArgExprClass:
return WalkExpression(cast<CXXDefaultArgExpr>(Expr)->getExpr());
return WalkExpressionObsolete(cast<clang::CXXDefaultArgExpr>(Expr)->getExpr());
case clang::Stmt::MaterializeTemporaryExprClass:
return WalkExpression(cast<MaterializeTemporaryExpr>(Expr)->GetTemporaryExpr());
return WalkExpressionObsolete(cast<clang::MaterializeTemporaryExpr>(Expr)->GetTemporaryExpr());
default:
break;
}

2
src/CppParser/Parser.h

@ -118,7 +118,7 @@ private: @@ -118,7 +118,7 @@ private:
VTableComponent WalkVTableComponent(const clang::VTableComponent& Component);
PreprocessedEntity* WalkPreprocessedEntity(Declaration* Decl,
clang::PreprocessedEntity* PPEntity);
AST::ExpressionObsolete* WalkExpression(const clang::Expr* Expression);
AST::ExpressionObsolete* WalkExpressionObsolete(const clang::Expr* Expression);
std::string GetStringFromStatement(const clang::Stmt* Statement);
std::string GetFunctionBody(const clang::FunctionDecl* FD);

10
src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs

@ -8,7 +8,7 @@ namespace CppSharp.Generators.CSharp @@ -8,7 +8,7 @@ namespace CppSharp.Generators.CSharp
{
public static class CSharpExpressionPrinterExtensions
{
public static string CSharpValue(this Expression value, CSharpExpressionPrinter printer)
public static string CSharpValue(this ExpressionObsolete value, CSharpExpressionPrinter printer)
{
return value.Visit(printer);
}
@ -37,12 +37,12 @@ namespace CppSharp.Generators.CSharp @@ -37,12 +37,12 @@ namespace CppSharp.Generators.CSharp
return expression;
}
public string VisitExpression(Expression expr)
public string VisitExpression(ExpressionObsolete expr)
{
switch (expr.Class)
{
case StatementClass.Call:
var callExpr = (CallExpr) expr;
var callExpr = (CallExprObsolete) expr;
switch (callExpr.Declaration.GenerationKind)
{
case GenerationKind.Generate:
@ -65,7 +65,7 @@ namespace CppSharp.Generators.CSharp @@ -65,7 +65,7 @@ namespace CppSharp.Generators.CSharp
return expr.Declaration.Visit(typePrinter).Type;
goto default;
case StatementClass.BinaryOperator:
var binaryOperator = (BinaryOperator) expr;
var binaryOperator = (BinaryOperatorObsolete) expr;
var lhsResult = binaryOperator.LHS.String;
if (binaryOperator.LHS.Declaration is Enumeration.Item)
@ -77,7 +77,7 @@ namespace CppSharp.Generators.CSharp @@ -77,7 +77,7 @@ namespace CppSharp.Generators.CSharp
return $"{lhsResult} {binaryOperator.OpcodeStr} {rhsResult}";
case StatementClass.ConstructorReference:
var constructorExpr = (CXXConstructExpr) expr;
var constructorExpr = (CXXConstructExprObsolete) expr;
if (constructorExpr.Arguments.Count == 1 &&
constructorExpr.Arguments[0].Declaration is Enumeration.Item)
return constructorExpr.Arguments[0].Declaration.Visit(typePrinter).Type;

12
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -62,7 +62,7 @@ namespace CppSharp.Passes @@ -62,7 +62,7 @@ namespace CppSharp.Passes
return true;
}
private bool? PrintExpression(Function function, Type type, Expression expression, ref string result)
private bool? PrintExpression(Function function, Type type, ExpressionObsolete expression, ref string result)
{
var desugared = type.Desugar();
@ -111,7 +111,7 @@ namespace CppSharp.Passes @@ -111,7 +111,7 @@ namespace CppSharp.Passes
return CheckForSimpleExpressions(expression, ref result, desugared);
}
private bool CheckForSimpleExpressions(Expression expression, ref string result, Type desugared)
private bool CheckForSimpleExpressions(ExpressionObsolete expression, ref string result, Type desugared)
{
return CheckFloatSyntax(desugared, expression, ref result) ||
CheckForEnumValue(desugared, expression, ref result) ||
@ -136,7 +136,7 @@ namespace CppSharp.Passes @@ -136,7 +136,7 @@ namespace CppSharp.Passes
return false;
}
private bool? CheckForDefaultConstruct(Type desugared, Expression expression,
private bool? CheckForDefaultConstruct(Type desugared, ExpressionObsolete expression,
ref string result)
{
var type = desugared.GetFinalPointee() ?? desugared;
@ -145,7 +145,7 @@ namespace CppSharp.Passes @@ -145,7 +145,7 @@ namespace CppSharp.Passes
if (!type.TryGetClass(out decl))
return false;
var ctor = expression as CXXConstructExpr;
var ctor = expression as CXXConstructExprObsolete;
var typePrinter = new CSharpTypePrinter(Context);
typePrinter.PushMarshalKind(MarshalKind.DefaultExpression);
@ -299,8 +299,8 @@ namespace CppSharp.Passes @@ -299,8 +299,8 @@ namespace CppSharp.Passes
return false;
var defaultArgument = function.Parameters[0].OriginalDefaultArgument;
return defaultArgument is BuiltinTypeExpression &&
((BuiltinTypeExpression) defaultArgument).Value == 0;
return defaultArgument is BuiltinTypeExpressionObsolete &&
((BuiltinTypeExpressionObsolete) defaultArgument).Value == 0;
}
private bool CheckForDefaultChar(Type desugared, ref string result)

16
src/Parser/ASTConverter.cs

@ -1121,21 +1121,21 @@ namespace CppSharp @@ -1121,21 +1121,21 @@ namespace CppSharp
return _param;
}
private AST.Expression VisitStatement(StatementObsolete statement)
private AST.ExpressionObsolete VisitStatement(StatementObsolete statement)
{
if (statement == null)
return null;
AST.Expression expression;
AST.ExpressionObsolete expression;
switch (statement.Class)
{
case StatementClassObsolete.BinaryOperator:
var binaryOperator = BinaryOperatorObsolete.__CreateInstance(statement.__Instance);
expression = new AST.BinaryOperator(VisitStatement(binaryOperator.LHS),
expression = new AST.BinaryOperatorObsolete(VisitStatement(binaryOperator.LHS),
VisitStatement(binaryOperator.RHS), binaryOperator.OpcodeStr);
break;
case StatementClassObsolete.CallExprClass:
var callExpression = new AST.CallExpr();
var callExpression = new AST.CallExprObsolete();
var callExpr = CallExprObsolete.__CreateInstance(statement.__Instance);
for (uint i = 0; i < callExpr.ArgumentsCount; i++)
{
@ -1145,15 +1145,15 @@ namespace CppSharp @@ -1145,15 +1145,15 @@ namespace CppSharp
expression = callExpression;
break;
case StatementClassObsolete.DeclRefExprClass:
expression = new AST.BuiltinTypeExpression();
expression = new AST.BuiltinTypeExpressionObsolete();
expression.Class = AST.StatementClass.DeclarationReference;
break;
case StatementClassObsolete.CXXOperatorCallExpr:
expression = new AST.BuiltinTypeExpression();
expression = new AST.BuiltinTypeExpressionObsolete();
expression.Class = AST.StatementClass.CXXOperatorCall;
break;
case StatementClassObsolete.CXXConstructExprClass:
var constructorExpression = new AST.CXXConstructExpr();
var constructorExpression = new AST.CXXConstructExprObsolete();
var constructorExpr = CXXConstructExprObsolete.__CreateInstance(statement.__Instance);
for (uint i = 0; i < constructorExpr.ArgumentsCount; i++)
{
@ -1163,7 +1163,7 @@ namespace CppSharp @@ -1163,7 +1163,7 @@ namespace CppSharp
expression = constructorExpression;
break;
default:
expression = new AST.BuiltinTypeExpression();
expression = new AST.BuiltinTypeExpressionObsolete();
break;
}
expression.Declaration = Visit(statement.Decl);

Loading…
Cancel
Save