(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Microsoft.JScript / Microsoft.JScript / ast.cs
blobe1f7403bfe646432117b2c84a76a5f996077e7ca
1 //
2 // ast.cs: Base class for the EcmaScript program tree representation.
3 //
4 // Author:
5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
6 //
7 // (C) 2003, Cesar Lopez Nataren
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.Collections;
33 using System.Reflection;
34 using System.Reflection.Emit;
36 namespace Microsoft.JScript {
38 public abstract class AST {
40 internal AST parent;
41 protected int line_number;
44 // Here the actual IL code generation happens.
46 internal abstract void Emit (EmitContext ec);
49 // Perform type checks and associates expressions
50 // with their declarations
52 internal abstract bool Resolve (IdentificationTable context);
54 private bool InLoop {
55 get {
56 if (parent == null || parent is ScriptBlock)
57 return false;
58 else if (parent is DoWhile || parent is While || parent is For || parent is ForIn)
59 return true;
60 else
61 return parent.InLoop;
65 private bool InSwitch {
66 get {
67 if (parent == null)
68 return false;
69 else if (parent is Switch)
70 return true;
71 else
72 return parent.InSwitch;
76 private bool InFunction {
77 get {
78 if (parent == null)
79 return false;
80 else if (parent is FunctionDeclaration || parent is FunctionExpression)
81 return true;
82 else
83 return parent.InFunction;
87 private Function GetContainerFunction {
88 get {
89 if (parent == null)
90 return null;
91 if (parent is Function)
92 return parent as Function;
93 return parent.GetContainerFunction;
99 public abstract class Function : AST
101 bool check_this;
102 bool ignore_dynamic_scope;
103 bool requires_activation;
105 internal string prefix;
106 internal FunctionObject func_obj;
107 internal JSFunctionAttributeEnum func_type;
109 internal DictionaryEntry [] locals;
110 internal LocalBuilder local_func;
112 protected bool not_void_return = false;
114 internal bool CheckThis {
115 get { return check_this; }
116 set { check_this = value; }
119 internal bool IgnoreDynamicScope {
120 get { return ignore_dynamic_scope; }
121 set { ignore_dynamic_scope = value; }
124 internal bool RequiresActivation {
125 get { return requires_activation; }
126 set { requires_activation = value; }
129 public void Init (Block body, FormalParameterList p)
131 func_obj.body = body;
132 func_obj.parameters = p;
135 internal void set_prefix ()
137 if (parent != null && parent is Function) {
138 Function tmp;
139 tmp = (Function) parent;
140 if (tmp.prefix != String.Empty)
141 prefix = tmp.prefix + "." + tmp.func_obj.name;
142 else
143 prefix = tmp.func_obj.name;
144 } else
145 prefix = String.Empty;
148 internal void set_function_type ()
150 if (parent == null || parent.GetType () == typeof (ScriptBlock))
151 func_type = JSFunctionAttributeEnum.ClassicFunction;
152 else if (parent is FunctionDeclaration)
153 func_type = JSFunctionAttributeEnum.NestedFunction;
156 internal void set_custom_attr (MethodBuilder mb)
158 CustomAttributeBuilder attr_builder;
159 Type func_attr = typeof (JSFunctionAttribute);
160 Type [] func_attr_enum = new Type [] {typeof (JSFunctionAttributeEnum)};
161 attr_builder = new CustomAttributeBuilder (func_attr.GetConstructor (func_attr_enum),
162 new object [] {func_type});
163 mb.SetCustomAttribute (attr_builder);
166 internal void NotVoidReturnHappened (object sender, NotVoidReturnEventArgs args)
168 not_void_return = true;
171 protected Type HandleReturnType {
172 get {
173 Type ret_type;
174 if (not_void_return)
175 ret_type = typeof (object);
176 else
177 ret_type = typeof (void);
178 return ret_type;
182 internal void emit_return_local_field (ILGenerator ig, ConstructorInfo ctr_info, int n)
184 ig.Emit (OpCodes.Dup);
185 ig.Emit (OpCodes.Ldc_I4, n);
186 ig.Emit (OpCodes.Ldstr, "return value");
187 ig.Emit (OpCodes.Ldtoken, typeof (object));
188 ig.Emit (OpCodes.Ldc_I4, n);
189 ig.Emit (OpCodes.Newobj, ctr_info);
190 ig.Emit (OpCodes.Stelem_Ref);