Пример #1
0
 public override void Visit(VariableDeclaration node)
 {
     switch (node.VariableKind)
     {   // Local and formal variables can be referred to by their index.
         // Fields need to be stored as FieldBuilders for future reference.
         case VariableDeclaration.Kind.Formal:
             _currentMethod.DefineParameter(node.LocalIndex,
                 ParameterAttributes.In, node.Name);
             break;
         case VariableDeclaration.Kind.Local:
             // Do not generate the variable if it is never used (if optimization enabled).
             if (!_parent._optimize || node.Used)
             {
                 _currentMethod.GetILGenerator().DeclareLocal(
                     _parent.BuildType(node.TypeName, node.IsArray));
             }
             break;
         case VariableDeclaration.Kind.Class:
             var fieldBuilder = _currentType.DefineField(node.Name,
                 _parent.BuildType(node.TypeName, node.IsArray), FieldAttributes.Private);
             var sym = node.Scope.ResolveVariable(node.Name);
             _parent._fields[sym] = fieldBuilder;
             break;
     }
 }
Пример #2
0
            public override void Visit(VariableDeclaration node)
            {
                if (_pass != 1) return;

                if (_previousVarKind != node.VariableKind)
                {
                    _currentLocalIdx = 0;
                }
                if (node.VariableKind == VariableDeclaration.Kind.Formal)
                {
                    // Note: this does not take static methods into account
                    // since the only static method in MiniJava is the main
                    // method and it cannot have parameters.
                    node.LocalIndex = (short) (1 + _currentLocalIdx++);
                }
                else if (node.VariableKind == VariableDeclaration.Kind.Local &&
                    (!_optimize || node.Used))
                {
                    node.LocalIndex = _currentLocalIdx++;
                }
                _previousVarKind = node.VariableKind;
            }
Пример #3
0
        // Detects possible duplicate declaration of a variable identifier.
        public override void Visit(VariableDeclaration node)
        {
            Debug.Assert(CurrentScope is IVariableScope);

            node.Type = CheckDeclaredType(node);
            var variableSymbol = new VariableSymbol(node.Name, node.Type, CurrentScope);
            if ((CurrentScope as IVariableScope).Define(variableSymbol))
            {
                variableSymbol.Declaration = node;
                node.Scope = CurrentScope;
            }
            else
            {
                ReportSymbolDefinitionError(node);
            }
        }
Пример #4
0
 private bool ErrorsAlreadyReported(VariableReferenceExpression reference, VariableDeclaration declaration)
 {
     return _parent._errors.HasErrorReportForReferenceTo(ErrorTypes.UninitializedLocal, declaration) ||
         _parent._errors.HasErrorReportForNode(ErrorTypes.LvalueReference, reference);
 }