diff --git a/src/Peachpie.CodeAnalysis/CommandLine/PhpCommandLineParser.cs b/src/Peachpie.CodeAnalysis/CommandLine/PhpCommandLineParser.cs index 999535b850..9cb2aaa2c4 100644 --- a/src/Peachpie.CodeAnalysis/CommandLine/PhpCommandLineParser.cs +++ b/src/Peachpie.CodeAnalysis/CommandLine/PhpCommandLineParser.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; using System.IO; using Pchp.CodeAnalysis.Utilities; -using Devsense.PHP.Syntax.Ast; +using AST = Devsense.PHP.Syntax.Ast; using Devsense.PHP.Syntax; namespace Pchp.CodeAnalysis.CommandLine @@ -167,7 +167,7 @@ internal override CommandLineArguments CommonParse(IEnumerable args, str var additionalFiles = new List(); var embeddedFiles = new List(); var managedResources = new List(); - var globalAttributes = new List(); + var assemblyAttributes = new List(); var defines = new Dictionary(StringComparer.OrdinalIgnoreCase); string outputDirectory = baseDirectory; string subDirectory = null; @@ -721,7 +721,7 @@ internal override CommandLineArguments CommonParse(IEnumerable args, str if (TryParseAttributeSpec(value.Trim(), out var attr)) { - globalAttributes.Add(attr); + assemblyAttributes.Add(attr); } else { @@ -864,6 +864,7 @@ internal override CommandLineArguments CommonParse(IEnumerable args, str Autoload_PSR4 = autoload_psr4, Autoload_ClassMapFiles = autoload_classmapfiles, Autoload_Files = autoload_files, + AssemblyAttributes = assemblyAttributes, }; if (debugPlus) @@ -1016,12 +1017,12 @@ private static void ParseDefine(string value, Dictionary defines } } - private static bool TryParseAttributeSpec(string value, out AttributeElement attr) + private static bool TryParseAttributeSpec(string value, out AST.IAttributeElement attr) { attr = null; ReadOnlySpan fqn; - var signature = new List(); + var signature = new List(); var span = Devsense.PHP.Text.Span.Invalid; // FQN("value1","value2") @@ -1042,9 +1043,9 @@ bool ConsumeChar(ref ReadOnlySpan text, char ch) return false; } - bool ConsumeArg(ref ReadOnlySpan text, out ActualParam p) + bool ConsumeArg(ref ReadOnlySpan text, out AST.ActualParam p) { - p = default(ActualParam); + p = default(AST.ActualParam); if (!ConsumeChar(ref text, '"')) return false; @@ -1068,9 +1069,9 @@ bool ConsumeArg(ref ReadOnlySpan text, out ActualParam p) return false; } - p = new ActualParam( + p = new AST.ActualParam( Devsense.PHP.Text.Span.Invalid, - new StringLiteral(Devsense.PHP.Text.Span.Invalid, str.ToString()) + new AST.StringLiteral(Devsense.PHP.Text.Span.Invalid, str.ToString()) ); return true; } @@ -1104,10 +1105,10 @@ bool ConsumeArg(ref ReadOnlySpan text, out ActualParam p) } // - attr = new AttributeElement( + attr = new AST.AttributeElement( span, - new ClassTypeRef(span, QualifiedName.Parse(fqn.Trim().ToString().Replace('.', QualifiedName.Separator), true)), - new CallSignature(signature, span) + new AST.ClassTypeRef(span, QualifiedName.Parse(fqn.Trim().ToString().Replace('.', QualifiedName.Separator), true)), + new AST.CallSignature(signature, span) ); return true; } diff --git a/src/Peachpie.CodeAnalysis/Compilation/PhpCompilationOptions.cs b/src/Peachpie.CodeAnalysis/Compilation/PhpCompilationOptions.cs index fa1c910c2e..60e6dd1dd7 100644 --- a/src/Peachpie.CodeAnalysis/Compilation/PhpCompilationOptions.cs +++ b/src/Peachpie.CodeAnalysis/Compilation/PhpCompilationOptions.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using System.Collections.Immutable; using Roslyn.Utilities; +using AST = Devsense.PHP.Syntax.Ast; namespace Pchp.CodeAnalysis { @@ -106,6 +107,11 @@ public sealed class PhpCompilationOptions : CompilationOptions, IEquatable public override NullableContextOptions NullableContextOptions { get; protected set; } + /// + /// Source module attributes. + /// + public IReadOnlyList AssemblyAttributes { get; internal set; } + ///// ///// Flags applied to the top-level binder created for each syntax tree in the compilation ///// as well as for the binder of global imports. @@ -277,6 +283,7 @@ private PhpCompilationOptions(PhpCompilationOptions other) : this( Autoload_ClassMapFiles = other.Autoload_ClassMapFiles; Autoload_Files = other.Autoload_Files; Autoload_PSR4 = other.Autoload_PSR4; + AssemblyAttributes = other.AssemblyAttributes; } public override string Language => Constants.PhpLanguageName; diff --git a/src/Peachpie.CodeAnalysis/Semantics/SemanticsBinder.cs b/src/Peachpie.CodeAnalysis/Semantics/SemanticsBinder.cs index c59b78d16f..9ca41de82c 100644 --- a/src/Peachpie.CodeAnalysis/Semantics/SemanticsBinder.cs +++ b/src/Peachpie.CodeAnalysis/Semantics/SemanticsBinder.cs @@ -301,7 +301,7 @@ protected ImmutableArray BindLambdaUseArguments(IList ContainingFile.GetLocation(expr); + protected Location GetLocation(AST.ITreeNode expr) => ContainingFile?.GetLocation(expr); #endregion @@ -320,14 +320,7 @@ public ImmutableArray BindAttributes(IReadOnlyList BindAttributes(IReadOnlyList tryScopes) { } diff --git a/src/Peachpie.CodeAnalysis/Symbols/Source/SourceModuleSymbol.cs b/src/Peachpie.CodeAnalysis/Symbols/Source/SourceModuleSymbol.cs index 131247946c..15f32f7e5e 100644 --- a/src/Peachpie.CodeAnalysis/Symbols/Source/SourceModuleSymbol.cs +++ b/src/Peachpie.CodeAnalysis/Symbols/Source/SourceModuleSymbol.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using System.Collections.Immutable; using System.Diagnostics; +using Pchp.CodeAnalysis.Semantics; namespace Pchp.CodeAnalysis.Symbols { @@ -162,6 +163,17 @@ IEnumerable CreateAttributesToEmit() ImmutableArray>.Empty); } } + + // user assembly attributes + if (DeclaringCompilation.Options.AssemblyAttributes != null) + { + var binder = new SemanticsBinder(DeclaringCompilation, file: null); + + foreach (var attr in DeclaringCompilation.Options.AssemblyAttributes) + { + yield return binder.BindAttribute(attr); + } + } // yield break;