Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added error expression for invalid initializers.

  • Loading branch information...
commit 817a2da7d75890864b058de8de4ae8b6b28e872f 1 parent 4376927
@mkrueger mkrueger authored
View
2  ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
@@ -1457,7 +1457,7 @@ public override object Visit (StatementExpression statementExpression)
return result;
}
- public override object Visit (InvalidExpressionStatement statementExpression)
+ public override object Visit (InvalidStatementExpression statementExpression)
{
var result = new ExpressionStatement ();
if (statementExpression.Expression == null)
View
6,250 ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
3,161 additions, 3,089 deletions not shown
View
16 ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
@@ -4967,6 +4967,20 @@ opt_local_variable_initializer
current_variable.Initializer = (Expression) $2;
lbag.AppendTo (current_variable, GetLocation ($1));
}
+ | ASSIGN error
+ {
+ if (yyToken == Token.OPEN_BRACKET_EXPR) {
+ report.Error (650, lexer.Location,
+ "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type");
+ current_variable.Initializer = ErrorExpression.Create (650, lexer.Location,
+ "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type");
+ } else {
+ Error_SyntaxError (yyToken);
+ current_variable.Initializer = ErrorExpression.Create (0, lexer.Location,
+ "Syntax error");
+ }
+ lbag.AppendTo (current_variable, GetLocation ($1));
+ }
| error
{
if (yyToken == Token.OPEN_BRACKET_EXPR) {
@@ -5092,7 +5106,7 @@ statement_expression
ExpressionStatement s = $1 as ExpressionStatement;
if (s == null) {
Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
- $$ = new StatementExpression (new InvalidExpressionStatement ($1));
+ $$ = new InvalidStatementExpression ($1 as Expression);
} else {
$$ = new StatementExpression (s);
}
View
4 ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs
@@ -6288,14 +6288,14 @@ protected override void Error_TypeOrNamespaceNotFound (IMemberContext ec)
}
}
- public class InvalidExpressionStatement : Statement
+ public class InvalidStatementExpression : Statement
{
public Expression Expression {
get;
private set;
}
- public InvalidExpressionStatement (Expression expr)
+ public InvalidStatementExpression (Expression expr)
{
this.Expression = expr;
}
View
18 ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs
@@ -9157,14 +9157,28 @@ public override object Accept (StructuralVisitor visitor)
}
}
- class ErrorExpression : EmptyExpression
+ public class ErrorExpression : EmptyExpression
{
public static readonly ErrorExpression Instance = new ErrorExpression ();
-
+ public readonly int ErrorCode;
+ public readonly string Error;
+
private ErrorExpression ()
: base (InternalType.ErrorType)
{
}
+
+ ErrorExpression (int errorCode, Location location, string error) : base (InternalType.ErrorType)
+ {
+ this.ErrorCode = errorCode;
+ this.loc = location;
+ this.Error = error;
+ }
+
+ public static ErrorExpression Create (int errorCode, Location location, string error)
+ {
+ return new ErrorExpression (errorCode, location, error);
+ }
public override Expression CreateExpressionTree (ResolveContext ec)
{
View
2  ICSharpCode.NRefactory.CSharp/Parser/mcs/visit.cs
@@ -338,7 +338,7 @@ public virtual object Visit (YieldBreak yieldBreakStatement)
return null;
}
- public virtual object Visit (InvalidExpressionStatement invalidExpressionStatement)
+ public virtual object Visit (InvalidStatementExpression invalidStatementExpression)
{
return null;
}
Please sign in to comment.
Something went wrong with that request. Please try again.