protected override object?Visit(Declaration.Const cons) { AllocateName(cons.Value, Push(cons.Name)); base.Visit(cons); currentName.Pop(); return(null); }
public Value EvaluateConst(Declaration.Const constDecl) { var symbol = (Symbol.Const)SymbolTable.DefinedSymbol(constDecl); // Check if there's a pre-stored value, if not, evaluate it if (symbol.Value == null) { symbol.Value = Evaluate(constDecl.Value); } return(symbol.Value); }
// Actual code-generation ////////////////////////////////////////////// protected override Value?Visit(Declaration.Const cons) { var constType = System.TypeOf(cons.Value); if (constType is Semantic.Types.Type.Proc procType && procType.GetDependency() != null) { // We don't compile this, contains dependent types return(null); } EvaluateConst(cons); return(null); }
protected override object?Visit(Declaration.Const cons) => WithCurrentProcReturnType(null, null, () => { // Type-check type and value base.Visit(cons); // First we assign the type to the symbol var symbol = (Symbol.Const)System.SymbolTable.DefinedSymbol(cons); symbol.Type = System.TypeOf(cons.Value); if (cons.Type != null) { // There's an explicit type, make sure they match var consType = System.EvaluateType(cons.Type); if (!symbol.Type.Equals(consType)) { System.Report(new TypeMismatchError(consType, symbol.Type) { Defined = cons.Type.ParseTreeNode, Wrong = cons.Value.ParseTreeNode, Context = "constant definition", }); } } });
private Value EvaluateConst(Declaration.Const constDecl) => System.EvaluateConst(constDecl);
protected override object?Visit(Declaration.Const cons) { base.Visit(cons); symbolTable.DefineSymbol(cons, new Symbol.Const(cons)); return(null); }
/// <summary> /// Initializes a new <see cref="Const"/> by a constant definition. /// </summary> /// <param name="definition">The constant definition node.</param> public Const(Declaration.Const definition) : this(definition, definition.Name, null, null) { }