예제 #1
0
        public IPhpValue MakeSetValueExpression(IPhpValue v)
        {
            if (translationInfo == null)
            {
                throw new ArgumentNullException("translationInfo");
            }
            if (translationInfo.IsStatic)
            {
                throw new NotSupportedException();
            }

            if (translationInfo.GetSetByMethod)
            {
                var a = new PhpMethodCallExpression(translationInfo.SetMethodName);
                a.Arguments.Add(new PhpMethodInvokeValue(v));
                a.TargetObject = targetObject;
                return(a);
            }
            else
            {
                var a = new PhpInstanceFieldAccessExpression(translationInfo.FieldScriptName, targetObject, null);
                var b = new PhpAssignExpression(a, v);
                return(b);
            }
        }
예제 #2
0
 public static PhpArrayCreateExpression MakeKeyValue(params IPhpValue[] key_values)
 {
     if (key_values.Length % 2 == 1)
         throw new ArgumentException("key_values");
     var a = new List<IPhpValue>();
     for (var i = 1; i < key_values.Length; i += 2)
     {
         if (key_values[i] == null)
             continue;
         var g = new PhpAssignExpression(key_values[i - 1], key_values[i]);
         a.Add(g);
     }
     return new PhpArrayCreateExpression(a.ToArray());
 }
예제 #3
0
        public static PhpArrayCreateExpression MakeKeyValue(params IPhpValue[] key_values)
        {
            if (key_values.Length % 2 == 1)
            {
                throw new ArgumentException("key_values");
            }
            var a = new List <IPhpValue>();

            for (var i = 1; i < key_values.Length; i += 2)
            {
                if (key_values[i] == null)
                {
                    continue;
                }
                var g = new PhpAssignExpression(key_values[i - 1], key_values[i]);
                a.Add(g);
            }
            return(new PhpArrayCreateExpression(a.ToArray()));
        }
        public IPhpValue MakeSetValueExpression(IPhpValue v)
        {
            if (translationInfo == null)
                throw new ArgumentNullException("translationInfo");
            if (translationInfo.IsStatic)
                throw new NotSupportedException();

            if (translationInfo.GetSetByMethod)
            {
                var a = new PhpMethodCallExpression(translationInfo.SetMethodName);
                a.Arguments.Add(new PhpMethodInvokeValue(v));
                a.TargetObject = targetObject;
                return a;
            }
            else
            {
                var a = new PhpInstanceFieldAccessExpression(translationInfo.FieldScriptName, targetObject, null);
                var b = new PhpAssignExpression(a, v);
                return b;
            }

        }
예제 #5
0
        /*
        /// <summary>
        /// Tworzy instancję obiektu
        /// </summary>
        public PhpForStatement()
        {
        }
        Przykłady użycia
        implement INotifyPropertyChanged
        implement INotifyPropertyChanged_Passive
        implement ToString ##InitVariables## ##Condition## ##Statement## ##Incrementors##
        implement ToString InitVariables=##InitVariables##, Condition=##Condition##, Statement=##Statement##, Incrementors=##Incrementors##
        implement equals InitVariables, Condition, Statement, Incrementors
        implement equals *
        implement equals *, ~exclude1, ~exclude2
        */


        #region Constructors
        /// <summary>
        /// Tworzy instancję obiektu
        /// <param name="InitVariables"></param>
        /// <param name="Condition"></param>
        /// <param name="Statement"></param>
        /// <param name="Incrementors"></param>
        /// </summary>
        public PhpForStatement(PhpAssignExpression[] InitVariables, IPhpValue Condition, IPhpStatement Statement, IPhpStatement[] Incrementors)
        {
            this.InitVariables = InitVariables;
            this.Condition = Condition;
            this.Statement = Statement;
            this.Incrementors = Incrementors;
        }
예제 #6
0
        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();
                }
            }
        }