Browse Source

Added managed AST conversion code for statements and expressions.

pull/1179/head
Joao Matos 6 years ago committed by João Matos
parent
commit
06ddf85b4f
  1. 1
      src/AST/Function.cs
  2. 4
      src/AST/SourceLocation.cs
  3. 2925
      src/Parser/ASTConverter.Expr.cs
  4. 1098
      src/Parser/ASTConverter.Stmt.cs
  5. 68
      src/Parser/ASTConverter.cs

1
src/AST/Function.cs

@ -250,6 +250,7 @@ namespace CppSharp.AST
public string Mangled { get; set; } public string Mangled { get; set; }
public string Signature { get; set; } public string Signature { get; set; }
public string Body { get; set; } public string Body { get; set; }
public Stmt BodyStmt { get; set; }
public override T Visit<T>(IDeclVisitor<T> visitor) public override T Visit<T>(IDeclVisitor<T> visitor)
{ {

4
src/AST/SourceLocation.cs

@ -87,4 +87,8 @@
return IsMacroID ? "Macro ID: " + ID : "File ID: " + Offset; return IsMacroID ? "Macro ID: " + ID : "File ID: " + Offset;
} }
} }
public struct SourceRange
{
}
} }

2925
src/Parser/ASTConverter.Expr.cs

File diff suppressed because it is too large Load Diff

1098
src/Parser/ASTConverter.Stmt.cs

File diff suppressed because it is too large Load Diff

68
src/Parser/ASTConverter.cs

@ -381,14 +381,24 @@ namespace CppSharp
readonly TypeConverter typeConverter; readonly TypeConverter typeConverter;
readonly DeclConverter declConverter; readonly DeclConverter declConverter;
readonly CommentConverter commentConverter; readonly CommentConverter commentConverter;
readonly StmtConverter stmtConverter;
readonly ExprConverter exprConverter;
public ASTConverter(ASTContext context) public ASTConverter(ASTContext context)
{ {
Context = context; Context = context;
typeConverter = new TypeConverter(); typeConverter = new TypeConverter();
commentConverter = new CommentConverter(); commentConverter = new CommentConverter();
declConverter = new DeclConverter(typeConverter, commentConverter); stmtConverter = new StmtConverter();
declConverter = new DeclConverter(typeConverter, commentConverter, stmtConverter);
typeConverter.declConverter = declConverter; typeConverter.declConverter = declConverter;
exprConverter = new ExprConverter();
ConversionUtils.typeConverter = typeConverter;
ConversionUtils.declConverter = declConverter;
ConversionUtils.stmtConverter = stmtConverter;
ConversionUtils.exprConverter = exprConverter;
} }
public AST.ASTContext Convert() public AST.ASTContext Convert()
@ -813,16 +823,18 @@ namespace CppSharp
{ {
readonly TypeConverter typeConverter; readonly TypeConverter typeConverter;
readonly CommentConverter commentConverter; readonly CommentConverter commentConverter;
readonly StmtConverter stmtConverter;
readonly Dictionary<IntPtr, AST.Declaration> Declarations; readonly Dictionary<IntPtr, AST.Declaration> Declarations;
readonly Dictionary<IntPtr, AST.PreprocessedEntity> PreprocessedEntities; readonly Dictionary<IntPtr, AST.PreprocessedEntity> PreprocessedEntities;
readonly Dictionary<IntPtr, AST.FunctionTemplateSpecialization> FunctionTemplateSpecializations; readonly Dictionary<IntPtr, AST.FunctionTemplateSpecialization> FunctionTemplateSpecializations;
public DeclConverter(TypeConverter type, CommentConverter comment) public DeclConverter(TypeConverter type, CommentConverter comment, StmtConverter stmt)
{ {
NativeObjects = new HashSet<IDisposable>(); NativeObjects = new HashSet<IDisposable>();
typeConverter = type; typeConverter = type;
commentConverter = comment; commentConverter = comment;
stmtConverter = stmt;
Declarations = new Dictionary<IntPtr, AST.Declaration>(); Declarations = new Dictionary<IntPtr, AST.Declaration>();
PreprocessedEntities = new Dictionary<IntPtr, AST.PreprocessedEntity>(); PreprocessedEntities = new Dictionary<IntPtr, AST.PreprocessedEntity>();
FunctionTemplateSpecializations = new Dictionary<IntPtr, AST.FunctionTemplateSpecialization>(); FunctionTemplateSpecializations = new Dictionary<IntPtr, AST.FunctionTemplateSpecialization>();
@ -1202,6 +1214,12 @@ namespace CppSharp
_function.Parameters.Add(_param); _function.Parameters.Add(_param);
} }
if (function.BodyStmt != null)
{
var _stmt = stmtConverter.Visit(function.BodyStmt);
_function.BodyStmt = _stmt;
}
_function.FunctionType = typeConverter.VisitQualified(function.QualifiedType); _function.FunctionType = typeConverter.VisitQualified(function.QualifiedType);
if (function.SpecializationInfo != null) if (function.SpecializationInfo != null)
_function.SpecializationInfo = VisitFunctionTemplateSpecialization( _function.SpecializationInfo = VisitFunctionTemplateSpecialization(
@ -2124,5 +2142,51 @@ namespace CppSharp
} }
} }
public static class ConversionUtils
{
public static TypeConverter typeConverter;
public static DeclConverter declConverter;
public static StmtConverter stmtConverter;
public static ExprConverter exprConverter;
public static AST.QualifiedType VisitQualifiedType(
QualifiedType qualifiedType)
{
return typeConverter.VisitQualified(qualifiedType);
}
public static AST.SourceRange VisitSourceRange(Parser.SourceRange loc)
{
return new AST.SourceRange();
}
public static AST.SourceLocation VisitSourceLocation(
Parser.SourceLocation loc)
{
return new AST.SourceLocation(loc.ID);
}
public static AST.Declaration VisitDeclaration(Parser.AST.Declaration decl)
{
return declConverter.Visit(decl);
}
public static AST.Stmt VisitStatement(Parser.AST.Stmt stmt)
{
return stmtConverter.Visit(stmt);
}
public static AST.Expr VisitExpression(Parser.AST.Expr expr)
{
return exprConverter.Visit(expr);
}
public static AST.TemplateArgument VisitTemplateArgument(
Parser.AST.TemplateArgument templateArg)
{
return new AST.TemplateArgument();
}
}
#endregion #endregion
} }

Loading…
Cancel
Save