コード例 #1
0
        // Private Methods 

        private static int FieldOrderGroup(PhpClassFieldDefinition fieldDefinition)
        {
            return(fieldDefinition.IsConst ? 0 : (fieldDefinition.IsStatic ? 1 : 2));
        }
コード例 #2
0
        // Private Methods 

        static int FieldOrderGroup(PhpClassFieldDefinition fieldDefinition)
        {
            return fieldDefinition.IsConst ? 0 : (fieldDefinition.IsStatic ? 1 : 2);
        }
コード例 #3
0
ファイル: Translator.cs プロジェクト: exaphaser/cs2php
        private void TranslateField(PhpCodeModule module, PhpClassDefinition phpClass, FieldDeclaration field)
        {
            PhpValueTranslator phpValueTranslator = null;
            foreach (var item in field.Items)
            {
                if (item.OptionalFieldInfo == null) continue;
                var fti = _info.GetOrMakeTranslationInfo(item.OptionalFieldInfo);
                switch (fti.Destination)
                {
                    case FieldTranslationDestionations.DefinedConst:
                        if (item.Value == null)
                            throw new NotSupportedException();
                        if (phpValueTranslator == null)
                            phpValueTranslator = new PhpValueTranslator(_state);
                        var definedValue = phpValueTranslator.TransValue(item.Value);
                        {
                            if (fti.IncludeModule != module.Name)
                            {
                                module = GetOrMakeModuleByName(fti.IncludeModule);
                            }
                        }
                        module.DefinedConsts.Add(new KeyValuePair<string, IPhpValue>(fti.ScriptName, definedValue));
                        break;
                    case FieldTranslationDestionations.GlobalVariable:
                        if (item.Value != null)
                        {

                            IPhpValue value;
                            // muszę na chwilę wyłączyć current type, bo to jes poza klasą generowane
                            {
                                var saveCurrentType = _state.Principles.CurrentType;
                                _state.Principles.CurrentType = null;
                                try
                                {
                                    if (phpValueTranslator == null)
                                        phpValueTranslator = new PhpValueTranslator(_state);
                                    value = phpValueTranslator.TransValue(item.Value);
                                }
                                finally
                                {
                                    _state.Principles.CurrentType = saveCurrentType;
                                }
                            }

                            #region Tworzenie kodu
                            var assign = new PhpAssignExpression(PhpVariableExpression.MakeGlobal(fti.ScriptName), value);
                            module.TopCode.Statements.Add(new PhpExpressionStatement(assign));
                            #endregion
                        }
                        break;
                    case FieldTranslationDestionations.JustValue:
                        continue; // don't define
                    case FieldTranslationDestionations.NormalField:
                    case FieldTranslationDestionations.ClassConst:
                        {
                            var def = new PhpClassFieldDefinition();
                            var cti = _state.Principles.GetTi(_state.Principles.CurrentType, true);
                            if (cti.IsArray)
                                continue;
                            if (field.Modifiers.Has("const") ^ fti.Destination == FieldTranslationDestionations.ClassConst)
                                throw new Exception("beige lion");

                            def.IsConst = fti.Destination == FieldTranslationDestionations.ClassConst;// field.Modifiers.Has("const");
                            def.Name = fti.ScriptName;

                            def.IsStatic = def.IsConst || field.Modifiers.Has("static");
                            if (field.Modifiers.Has("public"))
                                def.Visibility = Visibility.Public;
                            else if (field.Modifiers.Has("protected"))
                                def.Visibility = Visibility.Protected;
                            else
                                def.Visibility = Visibility.Private;

                            if (item.Value != null)
                            {
                                if (phpValueTranslator == null)
                                    phpValueTranslator = new PhpValueTranslator(_state);
                                def.ConstValue = phpValueTranslator.TransValue(item.Value);
                            }
                            phpClass.Fields.Add(def);
                            break;
                        }
                    default:
                        throw new NotSupportedException();
                }
            }
        }