public void typeCheck(Visitor visitor) {

        Template template = mUnit.getParseTree();
        Name name = template.getName();

        if (name != null) {
            if ( !(mUnit.getShortName().equals(name.getName())) ) {
                error("template.name", mUnit.getShortName(), name);
            }
        }

        // Convert some ExpressionStatements into ReturnStatements.
        template.accept(new ReturnConvertor());

        // Reduce the amount of concatenation operations.
        // It is important that this step be performed after using the
        // ReturnConvertor and before the main type checking. Otherwise, a
        // return may only capture a partial result or an expression may be
        // set to a type which is only appropriate for concatenation.
        //
        // Note: Decreasing the amount of concatenations can have a slight
        // impact on the language semantics depending on how the context is
        // defined. Generally, reducing the amount of concatenations improves
        // performance. If reducing the amount of concatenations hinders
        // performance, then the data buffering and/or output strategy in the
        // context may need to be improved.
        //
        template.accept(new ConcatenationReducer());

        // Increase the amount of concatenation operations.
        // It is important that this step be performed after using the
        // ReturnConvertor and before the main type checking. Otherwise, a
        // return may capture too large of a result or an expression may be
        // set to a type which is only appropriate for output.
        //
        // Note: Increasing the amount of concatenations can have a profound
        // impact on the language semantics depending on how the context is
        // defined. Generally, increasing the amount of concatenations hinders
        // performance. If increasing the amount of concatenations improves
        // performance, then the data buffering and/or output strategy in the
        // context may need to be improved.
        //
        //template.accept(new ConcatenationIncreaser());

        // Perform major type checking.
        visitor.check(template);

        if (mErrorCount == 0 && mExceptionGuardian) {
            // Equip the parse tree with ExceptionGuard statements.
            template.accept(new ExceptionGuardian());
        }
    }