예제 #1
0
        private void WaddleReturnStmt(ReturnStmtSyntax returnStmt)
        {
            if (_currentFunction == null)
            {
                throw new SemanticErrorException($"can not use return statement outside of function.");
            }

            if (_currentFunction.Type == null)
            {
                //Ignore Type if function is typeless
                return;
            }

            // check IsAssignableFrom (function.type, expr.type)
            var exprType = WaddleExpression(returnStmt.Expression);

            if (IsAssignableFrom(_currentFunction.Type !, exprType) == false)
            {
                throw new SemanticErrorException(
                          $"Function result is of type {_currentFunction.Type!}, the type {exprType} can not be assigned as result.");
            }
        }
예제 #2
0
        public bool EnterReturnStmt(ReturnStmtSyntax returnStmt, WaddleContext ctx)
        {
            if (_currentFunction == null)
            {
                throw new SemanticErrorException($"can not use return statement outside of function.");
            }

            if (_currentFunction.Type == null)
            {
                //Ignore Type if function is typeless
                return(true);
            }

            // check IsAssignableFrom (function.type, expr.type)
            var exprType = returnStmt.Expression.Accept(TypeVisitor);

            if (_currentFunction.Type != exprType)
            {
                throw new SemanticErrorException(
                          $"Function result is of type {_currentFunction.Type!}, the type {exprType} can not be assigned as result.");
            }

            return(true);
        }
예제 #3
0
 public virtual TResult Visit(ReturnStmtSyntax syntax)
 {
     return(DefaultResult);
 }
예제 #4
0
 public void LeaveReturnStmt(ReturnStmtSyntax returnStmt, WaddleContext ctx)
 {
 }