~dominik-burgdoerfer/webplodder/0.4

« back to all changes in this revision

Viewing changes to libwesl/src/wesl/elements/returnstatement.cpp

  • Committer: Dominik Burgdörfer
  • Date: 2010-07-07 14:35:20 UTC
  • Revision ID: dominik@domachine-20100707143520-wpywl29fsg9quz54
restructured sources

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// =======================================================================
 
2
// 
 
3
//       Filename:  returnstatement.cpp
 
4
// 
 
5
//    Description:  
 
6
// 
 
7
//        Version:  1.0
 
8
//        Created:  18.06.2010 12:37:56
 
9
//       Revision:  none
 
10
//       Compiler:  g++
 
11
// 
 
12
//         Author:  Dominik 'domachine' Burgdörfer (-), dominik.burgdoerfer@googlemail.com
 
13
//        Company:  -
 
14
// 
 
15
// =======================================================================
 
16
 
 
17
#include "returnstatement.hpp"
 
18
#include "../elementstack.hpp"
 
19
#include "../exceptions/returnexception.hpp"
 
20
#include "../types/void.hpp"
 
21
#include "objectwrapper.hpp"
 
22
 
 
23
using namespace boost;
 
24
 
 
25
namespace wesl {
 
26
    namespace elements {
 
27
        ReturnStatement::ReturnStatement(ElementStack& parent)
 
28
            : Element(parent),
 
29
            Callable(this)
 
30
        {
 
31
 
 
32
        }
 
33
 
 
34
        ReturnStatement::ReturnStatement(ElementStack& parent,
 
35
                                         ElementPtr element)
 
36
            : Element(parent), 
 
37
            Callable(this),
 
38
            m_element(element)
 
39
        {
 
40
 
 
41
        }
 
42
 
 
43
        void ReturnStatement::call() {
 
44
            if(m_element->is(Element::RESOLVABLE)) {
 
45
                ResolvablePtr ptr = 
 
46
                    dynamic_pointer_cast<Resolvable>(m_element);
 
47
 
 
48
                throw exceptions::ReturnException(ptr->resolve(),
 
49
                    "return statement outside of function",
 
50
                    parent().sourcePath(),
 
51
                    line());
 
52
            }
 
53
 
 
54
            throw exceptions::ProcessingError(
 
55
                    "return: Element is not resolvable",
 
56
                    parent().sourcePath(),
 
57
                    line());
 
58
        }
 
59
 
 
60
        void ReturnStatement::setElement(ElementPtr element)
 
61
        {
 
62
            m_element = element;
 
63
        }
 
64
    }
 
65
}