Merged sunConstDefinition and sunVariableDefinition
Now sunVariableDefinition declares either a constant symbol or a variable symbol, depending on the appearance of the 'const' modifier.
This commit is contained in:
parent
d7ce89ca9a
commit
a676f9e8e5
2 changed files with 19 additions and 27 deletions
|
@ -53,9 +53,24 @@
|
|||
: base(location) { }
|
||||
|
||||
public override void Compile(sunCompiler compiler) {
|
||||
var symbol = compiler.Context.DeclareVariable(this);
|
||||
symbol.Modifiers = Modifiers;
|
||||
Operator.Compile(compiler, symbol, Expression);
|
||||
// create the right type of symbol based on the const modifier
|
||||
var isConst = (Modifiers & sunSymbolModifiers.Constant) != 0;
|
||||
if (isConst) {
|
||||
// analyze the expression. this does two things:
|
||||
// 1) prevents recursion (i.e. the const referencing itself)
|
||||
// 2) asserts actual constness
|
||||
var flags = Expression.Analyze(compiler.Context);
|
||||
if (flags.HasFlag(sunExpressionFlags.Dynamic)) {
|
||||
throw new sunConstantExpressionException(Expression);
|
||||
}
|
||||
var symbol = compiler.Context.DeclareConstant(this);
|
||||
symbol.Modifiers = Modifiers;
|
||||
}
|
||||
else {
|
||||
var symbol = compiler.Context.DeclareVariable(this);
|
||||
symbol.Modifiers = Modifiers;
|
||||
Operator.Compile(compiler, symbol, Expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,27 +90,4 @@
|
|||
Operator.Compile(compiler, symbol, Expression);
|
||||
}
|
||||
}
|
||||
|
||||
class sunConstantDefinition : sunNode {
|
||||
public sunIdentifier Name { get { return this[1] as sunIdentifier; } }
|
||||
public sunExpression Expression { get { return this[3] as sunExpression; } }
|
||||
|
||||
public sunSymbolModifiers Modifiers {
|
||||
get { return sunSymbol.GetModifiers(this[0]) | sunSymbolModifiers.Constant; }
|
||||
}
|
||||
|
||||
public sunConstantDefinition(sunSourceLocation location)
|
||||
: base(location) { }
|
||||
|
||||
public override void Compile(sunCompiler compiler) {
|
||||
// analyze the expression. this does two things:
|
||||
// 1) prevents recursion (i.e. the const referencing itself)
|
||||
// 2) asserts actual constness
|
||||
var flags = Expression.Analyze(compiler.Context);
|
||||
if (flags.HasFlag(sunExpressionFlags.Dynamic)) {
|
||||
throw new sunConstantExpressionException(Expression);
|
||||
}
|
||||
compiler.Context.DeclareConstant(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ namespace arookas {
|
|||
}
|
||||
return symbol;
|
||||
}
|
||||
public sunConstantSymbol DeclareConstant(sunConstantDefinition node) {
|
||||
public sunConstantSymbol DeclareConstant(sunVariableDefinition node) {
|
||||
return DeclareConstant(node.Name, node.Expression, node.Modifiers);
|
||||
}
|
||||
sunConstantSymbol DeclareConstant(sunIdentifier node, sunExpression expression, sunSymbolModifiers modifiers) {
|
||||
|
|
Loading…
Reference in a new issue