Ejemplo n.º 1
0
        private void WaddleDeclStmt(DeclStmtSyntax declStmt)
        {
            if (_currentFunction == null)
            {
                throw new SemanticErrorException($"can not use declare statement outside of function.");
            }

            if (_currentFunction?.Variables.ContainsKey(declStmt.ParameterDeclSyntax.Name) == false)
            {
                throw new SemanticErrorException($"{declStmt.ParameterDeclSyntax.Name} is not an available variable at this position.");
            }

            var variable = _currentFunction?.Variables[declStmt.ParameterDeclSyntax.Name] !;
            var exprType = WaddleExpression(declStmt.Expression);

            if (IsAssignableFrom(variable.Type !, exprType) == false)
            {
                throw new SemanticErrorException($"type {variable.Type} is not assignable from {exprType}.");
            }
        }
Ejemplo n.º 2
0
        public bool EnterDeclStmt(DeclStmtSyntax declStmt, WaddleContext ctx)
        {
            if (_currentFunction == null)
            {
                throw new SemanticErrorException($"can not use declare statement outside of function.");
            }

            if (_currentFunction?.Variables.ContainsKey(declStmt.ParameterDeclSyntax.Name) == false)
            {
                throw new SemanticErrorException($"{declStmt.ParameterDeclSyntax.Name} is not an available variable at this position.");
            }

            var variable = _currentFunction?.Variables[declStmt.ParameterDeclSyntax.Name] !;
            var exprType = declStmt.Expression.Accept(TypeVisitor);

            if (variable.Type != exprType)
            {
                throw new SemanticErrorException($"type {variable.Type} is not assignable from {exprType}.");
            }

            return(true);
        }
Ejemplo n.º 3
0
 public virtual TResult Visit(DeclStmtSyntax syntax)
 {
     return(DefaultResult);
 }
Ejemplo n.º 4
0
 public void LeaveDeclStmt(DeclStmtSyntax declStmt, WaddleContext ctx)
 {
 }