public static VariableDeclaration CreateDeclarator(Context cx, VariableDeclaratorSyntax d, AnnotatedType type, bool isVar, IExpressionParentEntity parent, int child) { var ret = Create(cx, d, type, isVar, parent, child); cx.Try(d, null, () => { var id = d.Identifier; var declSymbol = cx.GetModel(d).GetDeclaredSymbol(d); var location = cx.Create(id.GetLocation()); var localVar = LocalVariable.Create(cx, declSymbol, ret, isVar, location); if (d.Initializer != null) { Create(cx, d.Initializer.Value, ret, 0); // Create an access var access = new Expression(new ExpressionInfo(cx, type, location, ExprKind.LOCAL_VARIABLE_ACCESS, ret, 1, false, null)); cx.TrapWriter.Writer.expr_access(access, localVar); } var decl = d.Parent as VariableDeclarationSyntax; if (decl != null) { TypeMention.Create(cx, decl.Type, ret, type); } }); return(ret); }
protected override void PopulateExpression(TextWriter trapFile) { if (Syntax.ArgumentList != null) { PopulateArguments(trapFile, Syntax.ArgumentList, 0); } var target = cx.GetModel(Syntax).GetSymbolInfo(Syntax); var method = (IMethodSymbol)target.Symbol; if (method != null) { trapFile.expr_call(this, Method.Create(cx, method)); } if (IsDynamicObjectCreation(cx, Syntax)) { var name = GetDynamicName(Syntax.Type); if (name.HasValue) { trapFile.dynamic_member_name(this, name.Value.Text); } else { cx.ModelError(Syntax, "Unable to get name for dynamic object creation."); } } if (Syntax.Initializer != null) { switch (Syntax.Initializer.Kind()) { case SyntaxKind.CollectionInitializerExpression: CollectionInitializer.Create(new ExpressionNodeInfo(cx, Syntax.Initializer, this, -1) { Type = Type }); break; case SyntaxKind.ObjectInitializerExpression: ObjectInitializer.Create(new ExpressionNodeInfo(cx, Syntax.Initializer, this, -1) { Type = Type }); break; default: cx.ModelError("Unhandled initializer in object creation"); break; } } TypeMention.Create(cx, Syntax.Type, this, Type); }
public static VariableDeclaration Create(Context cx, ISymbol symbol, AnnotatedType type, TypeSyntax optionalSyntax, Extraction.Entities.Location exprLocation, Extraction.Entities.Location declLocation, bool isVar, IExpressionParentEntity parent, int child) { var ret = new VariableDeclaration(new ExpressionInfo(cx, type, exprLocation, ExprKind.LOCAL_VAR_DECL, parent, child, false, null)); cx.Try(null, null, () => { LocalVariable.Create(cx, symbol, ret, isVar, declLocation); if (optionalSyntax != null) { TypeMention.Create(cx, optionalSyntax, parent, type); } }); return(ret); }
public static VariableDeclaration Create(Context cx, CatchDeclarationSyntax d, bool isVar, IExpressionParentEntity parent, int child) { var type = Type.Create(cx, cx.Model(d).GetDeclaredSymbol(d).Type); var ret = Create(cx, d, type, isVar, parent, child); cx.Try(d, null, () => { var id = d.Identifier; var declSymbol = cx.Model(d).GetDeclaredSymbol(d); var location = cx.Create(id.GetLocation()); LocalVariable.Create(cx, declSymbol, ret, isVar, location); TypeMention.Create(cx, d.Type, ret, type); }); return(ret); }
protected override void PopulateExpression(TextWriter trapFile) { Create(Context, Syntax.Expression, this, ExpressionIndex); if (Kind == ExprKind.CAST) { // Type cast TypeAccess.Create(new ExpressionNodeInfo(Context, Syntax.Type, this, TypeAccessIndex)); } else { // Type conversion OperatorCall(trapFile, Syntax); TypeMention.Create(Context, Syntax.Type, this, Type); } }
public static VariableDeclaration Create(Context cx, CatchDeclarationSyntax d, bool isVar, IExpressionParentEntity parent, int child) { var symbol = cx.GetModel(d).GetDeclaredSymbol(d) !; var type = symbol.GetAnnotatedType(); var ret = Create(cx, d, type, parent, child); cx.Try(d, null, () => { var declSymbol = cx.GetModel(d).GetDeclaredSymbol(d) !; var l = LocalVariable.Create(cx, declSymbol); l.PopulateManual(ret, isVar); TypeMention.Create(cx, d.Type, ret, type); }); return(ret); }
protected override void Populate() { Create(cx, Syntax.Expression, this, 0); if (Kind == ExprKind.CAST) { // Type cast TypeAccess.Create(new ExpressionNodeInfo(cx, Syntax.Type, this, 1)); } else { // Type conversion OperatorCall(Syntax); TypeMention.Create(cx, Syntax.Type, this, Type); } }
protected override void Populate() { Expression.Create(cx, Stmt.Expression, this, 1); var typeSymbol = cx.Model(Stmt).GetDeclaredSymbol(Stmt); var type = Type.Create(cx, typeSymbol.Type); var location = cx.Create(Stmt.Identifier.GetLocation()); if (typeSymbol.Name != "_") { Expressions.VariableDeclaration.Create(cx, typeSymbol, type, location, location, Stmt.Type.IsVar, this, 0); } TypeMention.Create(cx, Stmt.Type, this, type); Statement.Create(cx, Stmt.Statement, this, 2); }
protected override void PopulateExpression(TextWriter trapFile) { var explicitlySized = false; if (TypeSyntax is null) { Context.ModelError(Syntax, "Array has unexpected type syntax"); return; } var firstLevelSizes = TypeSyntax.RankSpecifiers.First()?.Sizes ?? SyntaxFactory.SeparatedList <ExpressionSyntax>(); if (firstLevelSizes.OfType <ExpressionSyntax>().Any(s => s is OmittedArraySizeExpressionSyntax)) { SetArraySizes(Initializer, firstLevelSizes.Count); } else { for (var sizeIndex = 0; sizeIndex < firstLevelSizes.Count; sizeIndex++) { Create(Context, firstLevelSizes[sizeIndex], this, sizeIndex); } explicitlySized = true; } if (!(Initializer is null)) { ArrayInitializer.Create(new ExpressionNodeInfo(Context, Initializer, this, InitializerIndex)); } if (explicitlySized) { trapFile.explicitly_sized_array_creation(this); } TypeMention.Create(Context, TypeSyntax, this, Type); }
protected override void PopulateExpression(TextWriter trapFile) { switch (Syntax.Kind()) { case SyntaxKind.SimpleMemberAccessExpression: var maes = (MemberAccessExpressionSyntax)Syntax; if (Type?.Symbol.ContainingType is null) { // namespace qualifier TypeMention.Create(cx, maes.Name, this, Type, Syntax.GetLocation()); } else { // type qualifier TypeMention.Create(cx, maes.Name, this, Type); Create(cx, maes.Expression, this, -1); } return; default: TypeMention.Create(cx, (TypeSyntax)Syntax, this, Type); return; } }
protected override void PopulateExpression(TextWriter trapFile) { base.PopulateExpression(trapFile); TypeMention.Create(Context, Syntax.Type, this, Type); }