public LambdaFunctionExpr(SourceUnit/*!*/ sourceUnit, Position position, Position entireDeclarationPosition, ShortPosition headingEndPosition, ShortPosition declarationBodyPosition, Scope scope, NamespaceDecl ns, bool aliasReturn, List<FormalParam>/*!*/ formalParams, List<FormalParam> useParams, List<Statement>/*!*/ body) : base(position) { Debug.Assert(formalParams != null && body != null); // inject use parameters at the begining of formal parameters if (useParams != null && useParams.Count > 0) { if (formalParams.Count == 0) formalParams = useParams; // also we don't want to modify Parser.emptyFormalParamListIndex singleton. else formalParams.InsertRange(0, useParams); } //this.ns = ns; this.signature = new Signature(aliasReturn, formalParams); this.useParams = useParams; //this.typeSignature = new TypeSignature(genericParams); //this.attributes = new CustomAttributes(attributes); this.body = body; this.entireDeclarationPosition = entireDeclarationPosition; this.headingEndPosition = headingEndPosition; this.declarationBodyPosition = declarationBodyPosition; //QualifiedName qn = (ns != null) ? new QualifiedName(this.name, ns.QualifiedName) : new QualifiedName(this.name); //function = new PhpFunction(qn, memberAttributes, signature, typeSignature, isConditional, scope, sourceUnit, position); function = new PhpLambdaFunction(this.signature, sourceUnit, position); function.WriteUp(new TypeSignature(FormalTypeParam.EmptyList).ToPhpRoutineSignature(function)); }
public LambdaFunctionExpr(SourceUnit/*!*/ sourceUnit, Text.Span span, Text.Span entireDeclarationPosition, int headingEndPosition, int declarationBodyPosition, Scope scope, NamespaceDecl ns, bool aliasReturn, List<FormalParam>/*!*/ formalParams, List<FormalParam> useParams, List<Statement>/*!*/ body) : base(span) { Debug.Assert(formalParams != null && body != null); // inject use parameters at the begining of formal parameters if (useParams != null && useParams.Count > 0) { if (formalParams.Count == 0) formalParams = useParams; // also we don't want to modify Parser.emptyFormalParamListIndex singleton. else formalParams.InsertRange(0, useParams); } //this.ns = ns; this.signature = new Signature(aliasReturn, formalParams); this.useParams = useParams; //this.typeSignature = new TypeSignature(genericParams); //this.attributes = new CustomAttributes(attributes); this.body = body; this.entireDeclarationPosition = entireDeclarationPosition; this.headingEndPosition = headingEndPosition; this.declarationBodyPosition = declarationBodyPosition; }
public IncludingEx(SourceUnit/*!*/ sourceUnit, Scope scope, bool isConditional, Text.Span span, InclusionTypes inclusionType, Expression/*!*/ fileName) : base(span) { Debug.Assert(fileName != null); this.inclusionType = inclusionType; this.fileNameEx = fileName; this.scope = scope; this.isConditional = isConditional; this.sourceUnit = sourceUnit; }
public LambdaFunctionExpr(SourceUnit/*!*/ sourceUnit, Text.Span span, Text.Span entireDeclarationPosition, int headingEndPosition, int declarationBodyPosition, Scope scope, NamespaceDecl ns, bool aliasReturn, List<FormalParam>/*!*/ formalParams, List<FormalParam> useParams, IList<Statement>/*!*/ body) : base(span) { Debug.Assert(formalParams != null && body != null); Debug.Assert(sourceUnit != null); this.sourceUnit = sourceUnit; this.ns = ns; this.signature = new Signature(aliasReturn, formalParams); this.useParams = useParams; //this.typeSignature = new TypeSignature(genericParams); //this.attributes = new CustomAttributes(attributes); this.body = body.AsArray(); this.entireDeclarationPosition = entireDeclarationPosition; this.headingEndPosition = headingEndPosition; this.declarationBodyPosition = declarationBodyPosition; }
public override DRoutine GetVisibleFunction(QualifiedName qualifiedName, ref string fullName/*!*/, Scope currentScope) { // try unconditional types declared within the same eval (doesn't make a dependency): Declaration result; if (functions != null && functions.TryGetValue(qualifiedName, out result)) return (PhpFunction)result.Declaree; // try functions declared on AC (doesn't make dependency): return module.Assembly.ApplicationContext.GetFunction(qualifiedName, ref fullName); }
/// <summary> /// To be used by compiler. /// </summary> internal PhpFunction(QualifiedName qualifiedName, PhpMemberAttributes memberAttributes, Signature astSignature, TypeSignature astTypeSignature, bool isConditional, Scope scope, SourceUnit/*!*/ sourceUnit, Position position) : base(new PhpRoutineDesc(sourceUnit.CompilationUnit.Module, memberAttributes), astSignature, astTypeSignature) { Debug.Assert(sourceUnit != null && position.IsValid); this.declaration = new Declaration(sourceUnit, this, false, isConditional, scope, position); this.qualifiedName = qualifiedName; this.version = new VersionInfo(); this.signature = null; // to be written up }
/// <summary> /// Gets the type for specified attribute type name. /// </summary> public DType/*!*/ ResolveCustomAttributeType(QualifiedName qualifiedName, Scope referringScope, Position position) { if (qualifiedName.IsAppStaticAttributeName) { return CustomAttribute.AppStaticAttribute; } else if (qualifiedName.IsExportAttributeName) { return CustomAttribute.ExportAttribute; } else if (qualifiedName.IsOutAttributeName) { return CustomAttribute.OutAttribute; } else { QualifiedName? alias; QualifiedName name = new QualifiedName(new Name(qualifiedName.Name.Value + "Attribute"), qualifiedName.Namespaces); DType type = sourceUnit.ResolveTypeName(name, referringScope, out alias, ErrorSink, position, true); if (type.IsUnknown) type = sourceUnit.ResolveTypeName(qualifiedName, referringScope, out alias, ErrorSink, position, true); ReportUnknownType(type, alias, position); return type; } }
public FunctionDecl(SourceUnit/*!*/ sourceUnit, Position position, Position entireDeclarationPosition, ShortPosition headingEndPosition, ShortPosition declarationBodyPosition, bool isConditional, Scope scope, PhpMemberAttributes memberAttributes, string/*!*/ name, NamespaceDecl ns, bool aliasReturn, List<FormalParam>/*!*/ formalParams, List<FormalTypeParam>/*!*/ genericParams, List<Statement>/*!*/ body, List<CustomAttribute> attributes) : base(position) { Debug.Assert(genericParams != null && name != null && formalParams != null && body != null); this.name = new Name(name); this.ns = ns; this.signature = new Signature(aliasReturn, formalParams); this.typeSignature = new TypeSignature(genericParams); this.attributes = new CustomAttributes(attributes); this.body = body; this.entireDeclarationPosition = entireDeclarationPosition; this.headingEndPosition = headingEndPosition; this.declarationBodyPosition = declarationBodyPosition; QualifiedName qn = (ns != null) ? new QualifiedName(this.name, ns.QualifiedName) : new QualifiedName(this.name); function = new PhpFunction(qn, memberAttributes, signature, typeSignature, isConditional, scope, sourceUnit, position); function.WriteUp(typeSignature.ToPhpRoutineSignature(function)); function.Declaration.Node = this; }
public TypeDecl(SourceUnit/*!*/ sourceUnit, Text.Span span, Text.Span entireDeclarationPosition, int headingEndPosition, int declarationBodyPosition, bool isConditional, Scope scope, PhpMemberAttributes memberAttributes, bool isPartial, Name className, Text.Span classNamePosition, NamespaceDecl ns, List<FormalTypeParam>/*!*/ genericParams, Tuple<GenericQualifiedName, Text.Span> baseClassName, List<Tuple<GenericQualifiedName, Text.Span>>/*!*/ implementsList, List<TypeMemberDecl>/*!*/ elements, List<CustomAttribute> attributes) : base(span) { Debug.Assert(genericParams != null && implementsList != null && elements != null); Debug.Assert((memberAttributes & PhpMemberAttributes.Trait) == 0 || (memberAttributes & PhpMemberAttributes.Interface) == 0, "Interface cannot be a trait"); this.name = className; this.NamePosition = classNamePosition; this.ns = ns; this.typeSignature = new TypeSignature(genericParams); if (baseClassName != null) { this.baseClassName = baseClassName.Item1; this.BaseClassNamePosition = baseClassName.Item2; } this.MemberAttributes = memberAttributes; this.Scope = scope; this.SourceUnit = sourceUnit; this.IsConditional = isConditional; if (implementsList == null || implementsList.Count == 0) { this.ImplementsList = EmptyArray<GenericQualifiedName>.Instance; this.ImplementsListPosition = EmptyArray<Text.Span>.Instance; } else { this.ImplementsList = implementsList.Select(x => x.Item1).ToArray(); this.ImplementsListPosition = implementsList.Select(x => x.Item2).ToArray(); } this.members = elements; this.members.TrimExcess(); if (attributes != null && attributes.Count != 0) this.Attributes = new CustomAttributes(attributes); this.entireDeclarationSpan = entireDeclarationPosition; this.headingEndPosition = headingEndPosition; this.declarationBodyPosition = declarationBodyPosition; this.partialKeyword = isPartial; }
public TypeDecl(SourceUnit/*!*/ sourceUnit, Position position, Position entireDeclarationPosition, ShortPosition headingEndPosition, ShortPosition declarationBodyPosition, bool isConditional, Scope scope, PhpMemberAttributes memberAttributes, bool isPartial, Name className, Position classNamePosition, NamespaceDecl ns, List<FormalTypeParam>/*!*/ genericParams, Tuple<GenericQualifiedName, Position> baseClassName, List<KeyValuePair<GenericQualifiedName, Position>>/*!*/ implementsList, List<TypeMemberDecl>/*!*/ members, List<CustomAttribute> attributes) : base(position) { Debug.Assert(genericParams != null && implementsList != null && members != null); Debug.Assert((memberAttributes & PhpMemberAttributes.Trait) == 0 || (memberAttributes & PhpMemberAttributes.Interface) == 0, "Interface cannot be a trait"); this.name = className; this.NamePosition = classNamePosition; this.ns = ns; this.typeSignature = new TypeSignature(genericParams); if (baseClassName != null) { this.baseClassName = baseClassName.Item1; this.BaseClassNamePosition = baseClassName.Item2; } this.MemberAttributes = memberAttributes; this.Scope = scope; this.SourceUnit = sourceUnit; this.IsConditional = isConditional; this.implementsList = implementsList; this.members = members; if (attributes != null && attributes.Count != 0) this.Attributes = new CustomAttributes(attributes); this.entireDeclarationPosition = entireDeclarationPosition; this.headingEndPosition = headingEndPosition; this.declarationBodyPosition = declarationBodyPosition; this.partialKeyword = isPartial; // remember current aliases: var aliases = (ns != null) ? ns.Aliases : sourceUnit.Aliases; if (aliases.Count > 0) validAliases = new Dictionary<string, QualifiedName>(aliases); }
public abstract DConstant GetVisibleConstant(QualifiedName qualifiedName, ref string/*!*/ fullName, Scope currentScope);
public abstract DRoutine GetVisibleFunction(QualifiedName qualifiedName, ref string/*!*/ fullName, Scope currentScope);
public abstract DType GetVisibleType(QualifiedName qualifiedName, ref string/*!*/ fullName, Scope currentScope, bool mustResolve);
public override DConstant GetVisibleConstant(QualifiedName qualifiedName, ref string fullName/*!*/, Scope currentScope) { // try unconditional constants declared within the same eval (doesn't make a dependency): Declaration result; if (constants != null && constants.TryGetValue(qualifiedName, out result)) return (GlobalConstant)result.Declaree; // search application context: return module.Assembly.ApplicationContext.GetConstant(qualifiedName, ref fullName); }
public override DType GetVisibleType(QualifiedName qualifiedName, ref string fullName/*!*/, Scope currentScope, bool mustResolve) { // try unconditional types declared within the same eval (doesn't make a dependency): Declaration result; if (types != null && types.TryGetValue(qualifiedName, out result)) return (PhpType)result.Declaree; // search application context (doens't make a dependency): DType type = module.Assembly.ApplicationContext.GetType(qualifiedName, ref fullName); if (type != null) return type; // do not add a dependency if not necessary: if (!mustResolve) return null; // try types declared on SC (makes a dependency); // use referring type to allow resolving self and parent; autoload is available here; DTypeDesc desc = resolvingScriptContext.ResolveType(fullName, null, referringType, null, ResolveTypeFlags.UseAutoload | ResolveTypeFlags.SkipGenericNameParsing); if (desc != null) { // TODO: remember the dependency return desc.Type; } return null; }
/// <summary> /// Analyzes the attribute type. Parameters are left to the full analysis as we want to resolve global and class /// constants used there. Resolving attribute type during member analysis enables to them to influence the /// member and full analysis of their respective targets. /// </summary> public void AnalyzeMembers(Analyzer/*!*/ analyzer, Scope referringScope) { // resolve attribute type: type = analyzer.ResolveCustomAttributeType(node.QualifiedName, referringScope, node.Position); // let the Assembly Builder know that this attribute is defined on it; // we need the Builder to be able to count the defined attributes in analysis: if (node.TargetSelector == CustomAttribute.TargetSelectors.Assembly || node.TargetSelector == CustomAttribute.TargetSelectors.Module) { analyzer.SourceUnit.CompilationUnit.ModuleBuilder.AssemblyBuilder.CustomAttributeDefined(analyzer.ErrorSink, node); } }
public static void AnalyzeMembers(this CustomAttributes/*!*/node, Analyzer/*!*/ analyzer, Scope referringScope) { node.Compiler().AnalyzeMembers(node, analyzer, referringScope); }
/// <summary> /// Used by compiler. /// </summary> public GlobalConstant(QualifiedName qualifiedName, PhpMemberAttributes memberAttributes, CompilationSourceUnit/*!*/ sourceUnit, bool isConditional, Scope scope, Text.Span position) : base(new DConstantDesc(sourceUnit.CompilationUnit.Module, memberAttributes, null)) { Debug.Assert(sourceUnit != null); this.qualifiedName = qualifiedName; this.declaration = new Declaration(sourceUnit, this, false, isConditional, scope, position); //this.origin = origin; if (sourceUnit.CompilationUnit is ScriptCompilationUnit) // J: place the constant into <script> type so it can be reflected properly scriptTypeBuilder = ((ScriptCompilationUnit)sourceUnit.CompilationUnit).ScriptBuilder.ScriptTypeBuilder; }
public GlobalConstantDecl(SourceUnit/*!*/ sourceUnit, Text.Span span, bool isConditional, Scope scope, string/*!*/ name, NamespaceDecl ns, Expression/*!*/ initializer) : base(span, name, initializer) { this.ns = ns; this.IsConditional = IsConditional; this.Scope = scope; this.SourceUnit = sourceUnit; }
public override DType GetVisibleType(QualifiedName qualifiedName, ref string fullName, Scope currentScope, bool mustResolve) { throw new Exception("The method or operation is not implemented."); }
public FunctionDecl(SourceUnit/*!*/ sourceUnit, Text.Span span, Text.Span entireDeclarationPosition, int headingEndPosition, int declarationBodyPosition, bool isConditional, Scope scope, PhpMemberAttributes memberAttributes, string/*!*/ name, NamespaceDecl ns, bool aliasReturn, List<FormalParam>/*!*/ formalParams, List<FormalTypeParam>/*!*/ genericParams, IList<Statement>/*!*/ body, List<CustomAttribute> attributes) : base(span) { Debug.Assert(genericParams != null && name != null && formalParams != null && body != null); this.name = new Name(name); this.ns = ns; this.signature = new Signature(aliasReturn, formalParams); this.typeSignature = new TypeSignature(genericParams); if (attributes != null && attributes.Count != 0) this.Attributes = new CustomAttributes(attributes); this.body = body.AsArray(); this.entireDeclarationPosition = entireDeclarationPosition; this.headingEndPosition = headingEndPosition; this.declarationBodyPosition = declarationBodyPosition; this.IsConditional = isConditional; this.MemberAttributes = memberAttributes; this.Scope = scope; this.SourceUnit = sourceUnit; }
public override DConstant GetVisibleConstant(QualifiedName qualifiedName, ref string fullName, Scope currentScope) { throw new Exception("The method or operation is not implemented."); }
/// <summary> /// Gets the type for specified attribute type name. /// </summary> public DType/*!*/ ResolveCustomAttributeType(QualifiedName qualifiedName, Scope referringScope, Position position) { if (qualifiedName.IsAppStaticAttributeName) { return SpecialCustomAttribute.AppStaticAttribute; } else if (qualifiedName.IsExportAttributeName) { return SpecialCustomAttribute.ExportAttribute; } else if (qualifiedName.IsDllImportAttributeName) { return SpecialCustomAttribute.DllImportAttribute; } else if (qualifiedName.IsOutAttributeName) { return SpecialCustomAttribute.OutAttribute; } else { QualifiedName? alias; string attrname = qualifiedName.Name.Value; if (!attrname.EndsWith(Name.AttributeNameSuffix)) attrname += Name.AttributeNameSuffix; QualifiedName name = new QualifiedName(new Name(attrname), qualifiedName.Namespaces); DType type = sourceUnit.ResolveTypeName(name, referringScope, out alias, ErrorSink, position, true); if (type.IsUnknown) type = sourceUnit.ResolveTypeName(qualifiedName, referringScope, out alias, ErrorSink, position, true); ReportUnknownType(type, alias, position); return type; } }
internal void AnalyzeMembers(Analyzer/*!*/ analyzer, Scope referringScope) { foreach (FormalTypeParam param in typeParams) param.AnalyzeMembers(analyzer, referringScope); }
public TypeDecl(SourceUnit/*!*/ sourceUnit, Position position, Position entireDeclarationPosition, ShortPosition headingEndPosition, ShortPosition declarationBodyPosition, bool isConditional, Scope scope, PhpMemberAttributes memberAttributes, bool isPartial, Name className, Position classNamePosition, NamespaceDecl ns, List<FormalTypeParam>/*!*/ genericParams, Tuple<GenericQualifiedName, Position> baseClassName, List<KeyValuePair<GenericQualifiedName, Position>>/*!*/ implementsList, List<TypeMemberDecl>/*!*/ members, List<CustomAttribute> attributes) : base(position) { Debug.Assert(genericParams != null && implementsList != null && members != null); Debug.Assert((memberAttributes & PhpMemberAttributes.Trait) == 0 || (memberAttributes & PhpMemberAttributes.Interface) == 0, "Interface cannot be a trait"); this.name = className; this.NamePosition = classNamePosition; this.ns = ns; this.typeSignature = new TypeSignature(genericParams); if (baseClassName != null) { this.baseClassName = baseClassName.Item1; this.BaseClassNamePosition = baseClassName.Item2; } this.implementsList = implementsList; this.members = members; this.attributes = new CustomAttributes(attributes); this.entireDeclarationPosition = entireDeclarationPosition; this.headingEndPosition = headingEndPosition; this.declarationBodyPosition = declarationBodyPosition; this.partialKeyword = isPartial; // remember current aliases: var aliases = (ns != null) ? ns.Aliases : sourceUnit.Aliases; if (aliases.Count > 0) validAliases = new Dictionary<string, QualifiedName>(aliases); // create stuff necessary for inclusion resolving process, other structures are created duirng analysis: QualifiedName qn = (ns != null) ? new QualifiedName(name, ns.QualifiedName) : new QualifiedName(name); type = new PhpType(qn, memberAttributes, isPartial, typeSignature, isConditional, scope, sourceUnit, position); //// add alias for private classes (if not added yet by partial declaration): //if (type.IsPrivate) // sourceUnit.AddTypeAlias(qn, this.name); // member-analysis needs the node: type.Declaration.Node = this; }
internal void AnalyzeMembers(Analyzer/*!*/ analyzer, Scope referringScope) { attributes.AnalyzeMembers(analyzer, referringScope); }
/// <summary> /// Analyzes the AST of the source unit. /// </summary> internal void Analyze(SourceUnit/*!*/ sourceUnit) { state = States.FullAnalysisStarted; this.sourceUnit = sourceUnit; this.currentNamespace = sourceUnit.CurrentNamespace; this.currentScope = Scope.Global; sourceUnit.Ast.Analyze(this); this.currentScope = Scope.Invalid; }
public void AnalyzeMembers(CustomAttributes/*!*/node, Analyzer/*!*/ analyzer, Scope referringScope) { if (node.Attributes == null) return; foreach (CustomAttribute attribute in node.Attributes) attribute.AnalyzeMembers(analyzer, referringScope); }
public GlobalConstantDecl(SourceUnit/*!*/ sourceUnit, Position position, bool isConditional, Scope scope, string/*!*/ name, NamespaceDecl ns, Expression/*!*/ initializer) : base(position, name, initializer) { this.ns = ns; QualifiedName qn = (ns != null) ? new QualifiedName(new Name(name), ns.QualifiedName) : new QualifiedName(new Name(name)); constant = new GlobalConstant(qn, PhpMemberAttributes.Public, sourceUnit, isConditional, scope, position); constant.SetNode(this); }
internal void AnalyzeMembers(Analyzer/*!*/ analyzer, Scope referringScope) { if (attributes == null) return; foreach (CustomAttribute attribute in attributes) attribute.AnalyzeMembers(analyzer, referringScope); }