public VariableInfo(
     VariableSymbol variableSymbol,
     VariableStyle variableStyle,
     bool useAsReturnValue = false)
 {
     _variableSymbol = variableSymbol;
     _variableStyle = variableStyle;
     _useAsReturnValue = useAsReturnValue;
 }
Exemple #2
0
    protected Dictionary<string, VariableSymbol> variables; //tabla de variables de instancia o globales

    #endregion Fields

    #region Methods

    public virtual void defineVariable(string variableName, VariableSymbol variableSymbol)
    {
        verifyVariableIsNotDefined(variableName);
        try
        {
            variableSymbol.address = calculateAddress(variableSymbol);
        }
        catch(Exception e) {
            ReptileParser.manageException(e);
        }
        variables.Add(variableName, variableSymbol);
    }
Exemple #3
0
 private int calculateAddress(VariableSymbol variableSymbol)
 {
     if (variableSymbol is ArrayVariableSymbol)
     {
         ArrayVariableSymbol arrayVarSymbol = (ArrayVariableSymbol)variableSymbol;
         int totalSlots = arrayVarSymbol.getTotalNumberOfSlots();
         return memory.nextArrayAddress(totalSlots);
     }
     else
     {
         return memory.nextAddress();
     }
 }
        public override Node Analyze(AffeCompilerState state)
        {
            this.Rvalue = (Expression) this.Rvalue.Analyze(state);

            Type dtype = null;

            TypeSymbol ts = state.Scope.GetSymbol(this.Type.Name) as TypeSymbol;

            if (ts == null)
                throw new AffeException("Not a type.", this.Type);

            if (ts.Type == typeof(void)) {
                // Void TypeSymbol means this is our inferencing type.
                dtype = this.Rvalue.Type;
            } else {
                dtype = ts.Type;
            }

            string name = ((IdentifierExpression) this.Lvalue).Identifier.Name;

            if (state.Scope.GetSymbol(name) != null)
                throw new AffeException("Identifier previously declared.", this.Lvalue);

            VariableSymbol vs = new VariableSymbol(name, dtype);
            vs.Local = state.ILGenerator.DeclareLocal(dtype);
            state.Scope.AddSymbol(vs);

            this.Rvalue = state.CastTo(this.Rvalue, dtype);

            return this;
        }
        public override Node Analyze(AffeCompilerState state)
        {
            TypeSymbol ts = state.Scope.GetSymbol(this.Type.Name) as TypeSymbol;

            if (ts == null)
                throw new AffeException("Not a type.", this.Type);

            if (ts.Type == typeof(void)) {
                // Void TypeSymbol means this is our inferencing type.
                throw new AffeException("Persistent variables cannot be type-inferenced.", this);
            }

            Type dtype = ts.Type;

            string name = this.Name.Name;

            if (state.Scope.GetSymbol(name) != null)
                throw new AffeException("Identifier previously declared.", this.Name);

            VariableSymbol vs = new VariableSymbol(name, dtype);
            vs.Local = state.ILGenerator.DeclareLocal(dtype);
            state.Scope.AddSymbol(vs);
            state.MakePersistent(vs);

            return this;
        }
Exemple #6
0
 public static BoundAssignmentExpression Assignment(SyntaxNode syntax, VariableSymbol variable, BoundExpression expression)
 => new BoundAssignmentExpression(syntax, variable, expression);
Exemple #7
0
 public VariableSymbol getNewTemporal(ClassSymbol type)
 {
     int addressTemp = memory.nextAddress();
     VariableSymbol temp = new VariableSymbol("@_" + addressTemp, type);
     temp.address = addressTemp;
     return temp;
     //al parecer no sera necesario definir (registrar) la var temporal en el metodo
 }
Exemple #8
0
 public void defineLocalVariable(string variableName, VariableSymbol variableSymbol)
 {
     verifyVariableIsNotDefined(variableName);
     defineVariable(variableName, variableSymbol);
     localVariables.AddLast(variableSymbol);
 }
        private static void AppendVariableSymbolInfo(this ICollection<SymbolMarkupToken> markup, VariableSymbol symbol)
        {
            VariableType variableType;
            if (symbol.Parent == null)
                variableType = VariableType.Global;
            else if (symbol.Parent.Kind == SymbolKind.ConstantBuffer)
                variableType = VariableType.ConstantBuffer;
            else
                variableType = VariableType.Local;

            switch (variableType)
            {
                case VariableType.Local:
                    markup.AppendPlainText("(local variable)");
                    break;
                case VariableType.ConstantBuffer:
                    markup.AppendPlainText("(constant buffer variable)");
                    break;
                case VariableType.Global:
                    markup.AppendPlainText("(global variable)");
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            markup.AppendSpace();
            markup.AppendType(symbol.ValueType, true);
            markup.AppendSpace();

            switch (variableType)
            {
                case VariableType.Local:
                    markup.AppendName(SymbolMarkupKind.LocalVariableName, symbol.Name);
                    break;
                case VariableType.ConstantBuffer:
                    markup.AppendName(SymbolMarkupKind.ConstantBufferVariableName, symbol.Name);
                    break;
                case VariableType.Global:
                    markup.AppendName(SymbolMarkupKind.GlobalVariableName, symbol.Name);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Exemple #10
0
 public BoundVariableDeclaration(SyntaxNode syntax, VariableSymbol variable, BoundExpression initializer)
     : base(syntax)
 {
     Variable    = variable;
     Initializer = initializer;
 }
Exemple #11
0
        private object EvaluateFunctionCall(BoundFunctionCall statement)
        {
            FunctionSymbol function = null;

            if (statement.Function != null)
            {
                function = statement.Function;
            }
            else if (statement.PointerSymbol != null)
            {
                object varEval = EvaluateVariable(statement.PointerSymbol.BaseSymbol);

                if (!(varEval is FunctionPointerObject pointer))
                {
                    return(null);
                }

                function = pointer.Function;
            }

            if (function == null)
            {
                return(null);
            }

            if (function == BuiltInFunctions.Print)
            {
                string text = (string)EvaluateExpression(statement.Parameters[0]);
                Console.WriteLine(text);
            }
            else if (function == BuiltInFunctions.Input)
            {
                string input = Console.ReadLine();
                return(input);
            }
            else if (Program.FunctionBodies.TryGetValue(function, out var boundBlock))
            {
                var newScope   = new Dictionary <VariableSymbol, object>();
                var parameters = new VariableSymbol[function.Parameters.Length];
                int index      = 0;

                foreach (var param in function.Parameters)
                {
                    parameters[index] = new VariableSymbol(param.Name, false, param.ValueType);
                    newScope.Add(parameters[index], null);
                    index++;
                }

                for (index = 0; index < parameters.Length; index++)
                {
                    newScope[parameters[index]] = EvaluateExpression(statement.Parameters[index]);
                }

                locals.Push(newScope);

                var value = EvaluateBlock(boundBlock);

                locals.Pop();

                return(value);
            }

            return(null);
        }
 public BoundElementAccessExpression(VariableSymbol variable, BoundExpression?index) :
     base(variable, BoundNodeKind.ElementAccessExpression)
 {
     Index = index;
 }
Exemple #13
0
 public override void defineVariable(string variableName, VariableSymbol variableSymbol)
 {
     base.defineVariable(variableName, variableSymbol);
     instanceVariablesList.AddLast(variableSymbol);
 }
Exemple #14
0
 public BoundVariableExpression(VariableSymbol variable, bool isValid) : base(isValid)
 {
     Variable   = variable;
     ResultType = variable.Type;
     Constant   = variable.Constant;
 }
Exemple #15
0
 public override void AddSymbol(VariableSymbol symbol)
 {
     HookFunction(symbol);
     base.AddSymbol(symbol);
 }
Exemple #16
0
 public static BoundFieldAssignmentExpression Assignment(SyntaxNode syntax, BoundExpression structInstance, VariableSymbol structMember, BoundExpression expression)
 => new BoundFieldAssignmentExpression(syntax, structInstance, structMember, expression);
Exemple #17
0
 VariableSymbol CreateVariableDefinition(string variableName, bool isConst, IType type)
 // ^(VariableDef[$ID,"VariableDef"] ^(Name ID) typeSpec expression?)
     {
     VariableSymbol symVariable = new VariableSymbol(variableName, isConst, type);
     //
     NadirAST nodeVarDef = new NadirAST(NadirParser.VariableDef);
     nodeVarDef.AddChild(CreateNameNode(variableName));
     NadirAST nodeType = CreateBuiltinTypeNode(type);
     nodeVarDef.AddChild(nodeType);
     //
     NadirASTDefineSymbols.LinkSymbolWithDefinition(nodeVarDef, symVariable);
     NadirASTDefineTypes.SetResolvedTypeOfDefinition(nodeVarDef, type);
     //
     return symVariable;
     }
Exemple #18
0
 protected override int CompareTo(VariableSymbol right)
 {
     return(this.CompareTo((ParameterVariableSymbol)right));
 }
Exemple #19
0
 private void defineThisImplicitParameter()
 {
     VariableSymbol implicit_this_param = new VariableSymbol(this_param_name, (ClassSymbol)enclosingScope);
     defineParameter(this_param_name, implicit_this_param);
 }
Exemple #20
0
 protected override int CompareTo(VariableSymbol right)
 {
     return(this.CompareTo((LocalVariableSymbol <T>)right));
 }
Exemple #21
0
 public void defineParameter(string variableName, VariableSymbol variableSymbol)
 {
     verifyVariableIsNotDefined(variableName);
     defineVariable(variableName, variableSymbol);
     parametros.AddLast(variableSymbol);
 }
Exemple #22
0
 protected override int CompareTo(VariableSymbol right)
 {
     return(this.CompareTo((QueryVariableSymbol)right));
 }
Exemple #23
0
 public static int Compare(VariableInfo left, VariableInfo right)
 {
     return(VariableSymbol.Compare(left.variableSymbol, right.variableSymbol));
 }
Exemple #24
0
 public static BoundFieldAccessExpression Field(SyntaxNode syntax, BoundExpression structInstance, VariableSymbol structMember)
 => new BoundFieldAccessExpression(syntax, structInstance, structMember);