public void BeforeEmit(PhpCodeModule module, TranslationInfo info) { //var a = info.CurrentAssembly.GetCustomAttributes(false); var assemblyTI = info.GetOrMakeTranslationInfo(info.CurrentAssembly); // var c = info.ClassTranslations.Values.Where(u => u.ModuleName != null && u.ModuleName.Library == assemblyTI.LibraryName).ToArray(); var typesInThisModule = info.ClassTranslations.Values.Where(u => u.ModuleName != null && u.ModuleName == module.Name).ToArray(); var typesWithAttribute = from i in typesInThisModule let attribute = i.Type.GetCustomAttribute<MainPluginModuleAttribute>(false) where attribute != null select i; if (typesWithAttribute.Any()) { var PluginName = "Please fill AssemblyTrademark attribute"; { var a = info.CurrentAssembly.GetCustomAttribute<AssemblyTrademarkAttribute>(); if (a != null && !string.IsNullOrEmpty(a.Trademark)) PluginName = a.Trademark; } var Author = ""; { var a = info.CurrentAssembly.GetCustomAttribute<AssemblyCompanyAttribute>(); if (a != null && !string.IsNullOrEmpty(a.Company)) Author = a.Company; } var Description = ""; { var a = info.CurrentAssembly.GetCustomAttribute<AssemblyDescriptionAttribute>(); if (a != null && !string.IsNullOrEmpty(a.Description)) Description = a.Description; } List<string> l = new List<string>(); l.Add("Plugin Name: " + PluginName); l.Add("Author: " + Author); l.Add("Author URI: " + "???"); l.Add("Description: " + Description); module.TopComments = string.Join("\r\n", l) + "\r\n" + module.TopComments; } // throw new NotImplementedException(); }
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(); } } }
// Private Methods /// <summary> /// Gets existing or creates code module for given name /// </summary> /// <param name="requiredModuleName"></param> /// <returns></returns> PhpCodeModule GetOrMakeModuleByName(PhpCodeModuleName requiredModuleName) { var mod = _modules.FirstOrDefault(i => i.Name == requiredModuleName); if (mod != null) return mod; mod = new PhpCodeModule(requiredModuleName); _modules.Add(mod); return mod; }
void AppendCodeReq(PhpCodeModuleName req, PhpCodeModule current) { if (req == current.Name) return; if (req.Name == PhpCodeModuleName.CS2PHP_CONFIG_MODULE_NAME) { var phpModule = CurrentConfigModule(); req = phpModule.Name; } if (req.AssemblyInfo != null && !string.IsNullOrEmpty(req.AssemblyInfo.IncludePathConstOrVarName)) { var isCurrentAssembly = _info.CurrentAssembly == req.AssemblyInfo.Assembly; if (!isCurrentAssembly) { var tmp = req.AssemblyInfo.IncludePathConstOrVarName; if (tmp.StartsWith("$")) throw new NotSupportedException(); // leading slash is not necessary -> config is in global namespace // but full name is a key in dictionary var phpModule = CurrentConfigModule(); if (phpModule.DefinedConsts.All(i => i.Key != tmp)) { KnownConstInfo value; if (_info.KnownConstsValues.TryGetValue(tmp, out value)) { if (!value.UseFixedValue) { var expression = PathUtil.MakePathValueRelatedToFile(value, _info); phpModule.DefinedConsts.Add(new KeyValuePair<string, IPhpValue>(tmp, expression)); } else throw new NotImplementedException(); } else { _info.Log(MessageLevels.Error, string.Format("const {0} defined in {1} has no known value", tmp, phpModule.Name)); phpModule.DefinedConsts.Add(new KeyValuePair<string, IPhpValue>(tmp, new PhpConstValue("UNKNOWN"))); } } } } var fileNameExpression = req.MakeIncludePath(current.Name); if (fileNameExpression == null) return; if (current.RequiredFiles.Any()) { var s = new PhpEmitStyle(); var code = fileNameExpression.GetPhpCode(s); var a = current.RequiredFiles.Select(i => i.GetPhpCode(s)).ToArray(); if (a.Any(i => i == code)) return; } // if (fileNameExpression1 !=null) { var fileNameExpressionICodeRelated = fileNameExpression as ICodeRelated; // scan nested requests var nestedCodeRequests = fileNameExpressionICodeRelated.GetCodeRequests().ToArray(); if (nestedCodeRequests.Any()) { var nestedModuleCodeRequests = nestedCodeRequests.OfType<ModuleCodeRequest>(); foreach (var nested in nestedModuleCodeRequests) AppendCodeReq(nested.ModuleName, current); } } current.RequiredFiles.Add(fileNameExpression); }