public override void VisitIdentifier(Identifier n)
        {
            _lastWalkedIdentifier = n.Id;
            var field = _currentTypeBuilder.FieldMap[n.Id];

            if(!field.IsStatic)
            {
                if(IsSubClass(_currentTypeBuilder))
                    _gen.Emit(OpCodes.Ldloc, _internalListIndex);
                else
                    _gen.Emit(OpCodes.Ldarg_0);

                if(n.IsLeftHandSide)
                    _assignmentCallback = gen => gen.Emit(OpCodes.Stfld, field);
                else
                    _gen.Emit(OpCodes.Ldfld, field);
            }
            else
            {
                if (n.IsLeftHandSide)
                    _assignmentCallback = gen => gen.Emit(OpCodes.Stsfld, field);
                else if (_shouldLoadAddress)
                    _gen.Emit(OpCodes.Ldsflda, field);
                else
                    _gen.Emit(OpCodes.Ldsfld, field);
            }

            _lastWalkedType = field.FieldType;
        }
        private void SetupInternalClass(DeclarationClass n, string name)
        {
            _typeManager.AddClass(n);

            if (name.Equals(ENTRY_POINT, StringComparison.OrdinalIgnoreCase))
            {
                var methodInfo = CreateEntryPointMethod(n, name);
                _gen = methodInfo.Builder.GetILGenerator();

                foreach (var item in Enum.GetNames(typeof(InternalTrancheTypes)))
                {
                    var ident = new Identifier(n.Location, item);
                    var instantiate = new InstantiateClass(item, new ExpressionList());
                    var assign = new Assign(ident, instantiate) {InternalType = new TypeClass(item)};

                    VisitAssign(assign);
                }

                _assemblyBuilder.SetEntryPoint(methodInfo.Builder);
            }
            else
            {
                var ctorInfo = CreateInternalClassCtor(n, name);
                _gen = ctorInfo.Builder.GetILGenerator();

                var baseCtor = typeof(object).GetConstructor(Type.EmptyTypes);
                _gen.Emit(OpCodes.Ldarg_0); //this.
                if (baseCtor != null) _gen.Emit(OpCodes.Call, baseCtor);
            }
        }
예제 #3
0
        public override void VisitIdentifier(Identifier n)
        {
            if (_mgr.HasSymbol(n.Id))
            {
                var d = _mgr.GetType(n.Id);
                n.Descriptor = d;
                n.InternalType = d.Type;

                _lastSeenType = d.Type;
            }
            else
            {
                ReportError(n.Location, "Identifier '{0}' has not been declared.", n.Id);
            }
        }