bool HandleDecl(TemplateTypeParameter p, IdentifierDeclaration id, ISemantic r) { // Bottom-level reached if (id.InnerDeclaration == null && Contains(id.IdHash) && !id.ModuleScoped) { // Associate template param with r return Set((p != null && id.IdHash == p.NameHash) ? p : null, r, id.IdHash); } var deducee = DResolver.StripMemberSymbols(AbstractType.Get(r)) as DSymbol; if (id.InnerDeclaration != null && deducee != null && deducee.Definition.NameHash == id.IdHash) { var physicalParentType = TypeDeclarationResolver.HandleNodeMatch(deducee.Definition.Parent, ctxt, null, id.InnerDeclaration); if (HandleDecl(p, id.InnerDeclaration, physicalParentType)) { if (Contains(id.IdHash)) Set((p != null && id.IdHash == p.NameHash) ? p : null, deducee, id.IdHash); return true; } } /* * If not stand-alone identifier or is not required as template param, resolve the id and compare it against r */ var _r = TypeDeclarationResolver.ResolveSingle(id, ctxt); return _r != null && (EnforceTypeEqualityWhenDeducing ? ResultComparer.IsEqual(r,_r) : ResultComparer.IsImplicitlyConvertible(r,_r)); }
public static AbstractType Demangle(string mangledString, ResolutionContext ctxt, out ITypeDeclaration qualifier, out bool isCFunction) { if(string.IsNullOrEmpty(mangledString)) throw new ArgumentException("input string must not be null or empty!"); if (!mangledString.StartsWith("_D")) { isCFunction = true; if (mangledString.StartsWith ("__D")) mangledString = mangledString.Substring (1); // C Functions else if (mangledString.StartsWith ("_")) { qualifier = new IdentifierDeclaration (mangledString.Substring (1)); return null; } } //TODO: What about C functions that start with 'D'? isCFunction = false; var dmng = new Demangler(mangledString) { ctxt = ctxt }; return dmng.MangledName(out qualifier); }
public static void Run() { Parse (); var pcw = new LegacyParseCacheView (new[]{ srcDir }); var ctxt = new ResolutionContext (pcw, new ConditionalCompilationFlags(versions,0, true)); var mod = pcw.LookupModuleName (null, "botan.pubkey.algo.dsa").First(); var scope = ResolutionTests.N<DMethod> (mod, "DSAVerificationOperation.verify"); var scopedStmt = ResolutionTests.S (scope, 9); ctxt.Push (scope, scopedStmt.Location); ITypeDeclaration td = new IdentifierDeclaration ("q"){ Location = scopedStmt.Location }; AbstractType t; var sw = new Stopwatch (); Console.WriteLine ("Begin resolving..."); sw.Restart (); t = TypeDeclarationResolver.ResolveSingle(td, ctxt); sw.Stop (); Console.WriteLine ("Finished resolution. {0} ms.", sw.ElapsedMilliseconds); sw.Restart (); t = TypeDeclarationResolver.ResolveSingle(td, ctxt); sw.Stop (); Console.WriteLine ("Finished resolution. {0} ms.", sw.ElapsedMilliseconds); }
public static AbstractType getStringType(ResolverContextStack ctxt) { var str = new IdentifierDeclaration("string"); var sType = TypeDeclarationResolver.Resolve(str, ctxt); ctxt.CheckForSingleResult(sType, str); return sType != null && sType.Length != 0 ? sType[0] : null; }
public ImportSymbolAlias(ImportStatement impStmt, ImportStatement.ImportBinding imp, IBlockNode parentNode) : base(impStmt, parentNode) { ImportBinding = imp; var sym = imp.Symbol; Name = (imp.Alias ?? sym).Id; NameLocation = (imp.Alias ?? sym).Location; Location = imp.Symbol.Location; Type = new IdentifierDeclaration(sym.Id) { Location = sym.Location, EndLocation = sym.EndLocation, InnerDeclaration = impStmt.ImportBindList.Module.ModuleIdentifier }; }
static ResolveResult[] HandleIdDeclaration(IdentifierDeclaration typeId, ResolverContext lastResCtxt, IAbstractSyntaxTree SyntaxTree, CodeScanResult csr, Dictionary<string, ResolveResult> compDict) { var typeString = typeId.ToString(); bool WasAlreadyResolved = false; ResolveResult[] allCurrentResults = null; ResolveResult rr = null; /* * string,wstring,dstring are highlighted by the editor's syntax definition automatically.. * Anyway, allow to resolve e.g. "object.string" */ if (typeString == "" || typeString == "string" || typeString == "wstring" || typeString == "dstring") return null; lastResCtxt.ScopedBlock = DResolver.SearchBlockAt(SyntaxTree, typeId.Location, out lastResCtxt.ScopedStatement); if (typeString == "th" && typeId.Location.Line == 114) { } if (!(WasAlreadyResolved = compDict.TryGetValue(typeString, out rr))) { allCurrentResults = DResolver.ResolveType(typeId, lastResCtxt); if (allCurrentResults != null && allCurrentResults.Length > 0) rr = allCurrentResults[0]; } if (rr == null) { if (typeId is IdentifierDeclaration) csr.UnresolvedIdentifiers.Add(typeId as IdentifierDeclaration); } else { /* * Note: It is of course possible to highlight more than one type in one type declaration! * So, we scan down the result hierarchy for TypeResults and highlight all of them later. */ var curRes = rr; /* * Note: Since we want to use results multiple times, * we at least have to 'update' their type declarations * to ensure that the second, third, fourth etc. occurence of this result * are also highlit (and won't(!) cause an Already-Added-Exception of our finalDict-Array) */ var curTypeDeclBase = typeId as ITypeDeclaration; while (curRes != null) { if (curRes is MemberResult) { var mr = curRes as MemberResult; // If curRes is an alias or a template parameter, highlight it if (mr.ResolvedMember is TemplateParameterNode || (mr.ResolvedMember is DVariable && (mr.ResolvedMember as DVariable).IsAlias)) { try { csr.ResolvedIdentifiers.Add(curTypeDeclBase as IdentifierDeclaration, curRes); } catch { } // See performance reasons //if (curRes != rr && !WasAlreadyResolved && !) compDict.Add(curTypeDeclBase.ToString(), curRes); } } else if (curRes is TypeResult) { // Yeah, in quite all cases we do identify a class via its name ;-) if (curTypeDeclBase is IdentifierDeclaration && !(curTypeDeclBase is DTokenDeclaration) && !csr.ResolvedIdentifiers.ContainsKey(curTypeDeclBase as IdentifierDeclaration)) { csr.ResolvedIdentifiers.Add(curTypeDeclBase as IdentifierDeclaration, curRes); // See performance reasons //if (curRes != rr && !WasAlreadyResolved) compDict.Add(curTypeDeclBase.ToString(), curRes); } } else if (curRes is ModuleResult) { if (curTypeDeclBase is IdentifierDeclaration && !csr.ResolvedIdentifiers.ContainsKey(curTypeDeclBase as IdentifierDeclaration)) csr.ResolvedIdentifiers.Add(curTypeDeclBase as IdentifierDeclaration, curRes); } curRes = curRes.ResultBase; curTypeDeclBase = curTypeDeclBase.InnerDeclaration; } } return allCurrentResults; }
ISemantic E(UnaryExpression_Type x) { var uat = x as UnaryExpression_Type; if (uat.Type == null) return null; var types = TypeDeclarationResolver.Resolve(uat.Type, ctxt); ctxt.CheckForSingleResult(types, uat.Type); if (types != null && types.Length != 0) { var id = new IdentifierDeclaration(uat.AccessIdentifier) { EndLocation = uat.EndLocation }; // First off, try to resolve static properties var statProp = StaticPropertyResolver.TryResolveStaticProperties(types[0], uat.AccessIdentifier, ctxt, eval, id); if (statProp != null) return statProp; // If it's not the case, try the conservative way var res = TypeDeclarationResolver.Resolve(id, ctxt, types); ctxt.CheckForSingleResult(res, x); if (res != null && res.Length != 0) return res[0]; } return null; }
public static ArgumentsResolutionResult ResolveArgumentContext( string code, int caretOffset, CodeLocation caretLocation, DMethod MethodScope, IEnumerable<IAbstractSyntaxTree> parseCache, IEnumerable<IAbstractSyntaxTree> ImportCache) { var ctxt = new ResolverContext { ScopedBlock = MethodScope, ParseCache = parseCache, ImportCache=ImportCache }; #region Parse the code between the last block opener and the caret var curMethodBody = MethodScope.GetSubBlockAt(caretLocation); if (curMethodBody == null && MethodScope.Parent is DMethod) { MethodScope = MethodScope.Parent as DMethod; curMethodBody = MethodScope.GetSubBlockAt(caretLocation); } if (curMethodBody == null) return null; var blockOpenerLocation = curMethodBody.StartLocation; var blockOpenerOffset = blockOpenerLocation.Line <= 0 ? blockOpenerLocation.Column : DocumentHelper.LocationToOffset(code, blockOpenerLocation); if (blockOpenerOffset >= 0 && caretOffset - blockOpenerOffset > 0) { var codeToParse = code.Substring(blockOpenerOffset, caretOffset - blockOpenerOffset); curMethodBody = DParser.ParseBlockStatement(codeToParse, blockOpenerLocation, MethodScope); if (curMethodBody != null) ctxt.ScopedStatement = curMethodBody.SearchStatementDeeply(caretLocation); } if (curMethodBody == null || ctxt.ScopedStatement == null) return null; #endregion // Scan statement for method calls or template instantiations var e = DResolver.SearchForMethodCallsOrTemplateInstances(ctxt.ScopedStatement, caretLocation); /* * 1) foo( -- normal arguments only * 2) foo!(...)( -- normal arguments + template args * 3) foo!( -- template args only * 4) new myclass( -- ctor call * 5) new myclass!( -- ditto * 6) new myclass!(...)( * 7) mystruct( -- opCall call */ var res = new ArgumentsResolutionResult() { ParsedExpression = e }; ITypeDeclaration methodIdentifier = null; // 1), 2) if (e is PostfixExpression_MethodCall) { res.IsMethodArguments = true; var call = e as PostfixExpression_MethodCall; if (call.Arguments != null) { int i = 0; foreach (var arg in call.Arguments) { if (caretLocation >= arg.Location && caretLocation <= arg.EndLocation) { res.CurrentlyTypedArgumentIndex = i; break; } i++; } } methodIdentifier = call.PostfixForeExpression.ExpressionTypeRepresentation; } // 3) else if (e is TemplateInstanceExpression) { var templ = e as TemplateInstanceExpression; res.IsTemplateInstanceArguments = true; if (templ.Arguments != null) { int i = 0; foreach (var arg in templ.Arguments) { if (caretLocation >= arg.Location && caretLocation <= arg.EndLocation) { res.CurrentlyTypedArgumentIndex = i; break; } i++; } } methodIdentifier = new IdentifierDeclaration(templ.TemplateIdentifier.Value) { InnerDeclaration=templ.InnerDeclaration }; } else if (e is NewExpression) { var ne = e as NewExpression; if (ne.Arguments != null) { int i = 0; foreach (var arg in ne.Arguments) { if (caretLocation >= arg.Location && caretLocation <= arg.EndLocation) { res.CurrentlyTypedArgumentIndex = i; break; } i++; } } methodIdentifier = ne.ExpressionTypeRepresentation; } if (methodIdentifier == null) return null; // Resolve all types, methods etc. which belong to the methodIdentifier res.ResolvedTypesOrMethods = ResolveType(methodIdentifier, ctxt); if (res.ResolvedTypesOrMethods == null) return res; // 4),5),6) if (e is NewExpression) { var substitutionList = new List<ResolveResult>(); foreach (var rr in res.ResolvedTypesOrMethods) if (rr is TypeResult) { var classDef = (rr as TypeResult).ResolvedTypeDefinition as DClassLike; if (classDef == null) continue; //TODO: Regard protection attributes for ctor members foreach (var i in classDef) if (i is DMethod && (i as DMethod).SpecialType == DMethod.MethodType.Constructor) substitutionList.Add(HandleNodeMatch(i, ctxt, resultBase: rr)); } if (substitutionList.Count > 0) res.ResolvedTypesOrMethods = substitutionList.ToArray(); } // 7) else if (e is PostfixExpression_MethodCall) { var substitutionList = new List<ResolveResult>(); var nonAliases=TryRemoveAliasesFromResult(res.ResolvedTypesOrMethods); foreach (var rr in nonAliases) if (rr is TypeResult) { var classDef = (rr as TypeResult).ResolvedTypeDefinition as DClassLike; if (classDef == null) continue; //TODO: Regard protection attributes for opCall members foreach (var i in classDef) if (i is DMethod && i.Name == "opCall") substitutionList.Add(HandleNodeMatch(i, ctxt, resultBase: rr)); } if (substitutionList.Count > 0) nonAliases = substitutionList.ToArray(); res.ResolvedTypesOrMethods = nonAliases; } return res; }
public TemplateInstanceExpression TemplateInstance(IBlockNode Scope) { var loc = la.Location; var mod = INVALID; if (DTokens.IsStorageClass(laKind)) { mod = laKind; Step (); } if (!Expect (Identifier)) return null; ITypeDeclaration td = new IdentifierDeclaration (t.Value) { Location = t.Location, EndLocation = t.EndLocation }; td = new TemplateInstanceExpression(mod != DTokens.INVALID ? new MemberFunctionAttributeDecl(mod) { InnerType = td } : td) { Location = loc }; var args = new List<IExpression>(); if (!Expect(Not)) return td as TemplateInstanceExpression; if (laKind == (OpenParenthesis)) { Step(); if (laKind != CloseParenthesis) { bool init = true; while (laKind == Comma || init) { if (!init) Step(); init = false; if (laKind == CloseParenthesis) break; Lexer.PushLookAheadBackup(); bool wp = AllowWeakTypeParsing; AllowWeakTypeParsing = true; var typeArg = Type(); AllowWeakTypeParsing = wp; if (typeArg != null && (laKind == CloseParenthesis || laKind==Comma)){ Lexer.PopLookAheadBackup(); args.Add(new TypeDeclarationExpression(typeArg)); }else { Lexer.RestoreLookAheadBackup(); args.Add(AssignExpression(Scope)); } } } Expect(CloseParenthesis); } else { /* * TemplateSingleArgument: * Identifier * BasicTypeX * CharacterLiteral * StringLiteral * IntegerLiteral * FloatLiteral * true * false * null * this * __FILE__ * __MODULE__ * __LINE__ * __FUNCTION__ * __PRETTY_FUNCTION__ */ switch (laKind) { case Literal: case True: case False: case Null: case This: case __FILE__: case __MODULE__: case __LINE__: case __FUNCTION__: case __PRETTY_FUNCTION__: args.Add(PrimaryExpression(Scope)); break; case Identifier: Step(); args.Add(new IdentifierExpression(t.Value) { Location = t.Location, EndLocation = t.EndLocation }); break; default: if (IsBasicType(laKind)) { Step (); args.Add (new TypeDeclarationExpression (new DTokenDeclaration (t.Kind) { Location = t.Location, EndLocation = t.EndLocation })); break; } else if (IsEOF) goto case Literal; SynErr(laKind, "Illegal token found on template instance expression argument"); Step(); break; } if (laKind == Not && Peek(1).Kind != Is && Peek(1).Kind != In) { SynErr(laKind, "multiple ! arguments are not allowed"); Step(); } } (td as TemplateInstanceExpression).Arguments = args.ToArray(); td.EndLocation = t.EndLocation; return td as TemplateInstanceExpression; }
public override void Visit(IdentifierDeclaration id) { var resolvedSymbol = TryPopPFAStack (); if (id.IdHash == searchHash) { if(resolvedSymbol == null) resolvedSymbol = TypeDeclarationResolver.ResolveSingle (id, ctxt) as DSymbol; if (resolvedSymbol != null && resolvedSymbol.Definition == symbol) { l.Add (id); return; } } base.Visit (id); }
ImportStatement.ImportBindings ImportBindings(ImportStatement.Import imp) { var importBindings = new ImportStatement.ImportBindings { Module=imp }; LastParsedObject = importBindings; bool init = true; while (laKind == Comma || init) { if (init) init = false; else Step(); if (Expect(Identifier)) { var symbolAlias = new IdentifierDeclaration(t.Value){ Location = t.Location, EndLocation = t.EndLocation }; if (laKind == Assign) { Step(); if (Expect (Identifier)) importBindings.SelectedSymbols.Add (new ImportStatement.ImportBinding (new IdentifierDeclaration (t.Value) { Location = t.Location, EndLocation = t.EndLocation }, symbolAlias)); } else importBindings.SelectedSymbols.Add(new ImportStatement.ImportBinding(symbolAlias)); } } if (!IsEOF) LastParsedObject = null; return importBindings; }
public virtual void Visit(IdentifierDeclaration td) { VisitInner(td); }
public static AbstractType ResolveKey(ArrayDecl ad, out int fixedArrayLength, out ISymbolValue keyVal, ResolutionContext ctxt) { keyVal = null; fixedArrayLength = -1; AbstractType keyType = null; if (ad.KeyExpression != null) { //TODO: Template instance expressions? var id_x = ad.KeyExpression as IdentifierExpression; if (id_x != null && id_x.IsIdentifier) { var id = new IdentifierDeclaration((string)id_x.Value) { Location = id_x.Location, EndLocation = id_x.EndLocation }; keyType = TypeDeclarationResolver.ResolveSingle(id, ctxt); if (keyType != null) { var tt = DResolver.StripAliasSymbol(keyType) as MemberSymbol; if (tt == null || !(tt.Definition is DVariable) || ((DVariable)tt.Definition).Initializer == null) return keyType; } } try { keyVal = Evaluation.EvaluateValue(ad.KeyExpression, ctxt); if (keyVal != null) { // Take the value's type as array key type keyType = keyVal.RepresentedType; // It should be mostly a number only that points out how large the final array should be var pv = Evaluation.GetVariableContents(keyVal, new StandardValueProvider(ctxt)) as PrimitiveValue; if (pv != null) { fixedArrayLength = System.Convert.ToInt32(pv.Value); if (fixedArrayLength < 0) ctxt.LogError(ad, "Invalid array size: Length value must be greater than 0"); } //TODO Is there any other type of value allowed? } } catch { } } else { var t = Resolve(ad.KeyType, ctxt); ctxt.CheckForSingleResult(t, ad.KeyType); if (t != null && t.Length != 0) return t[0]; } return keyType; }
public static AbstractType[] Resolve(IdentifierDeclaration id, ResolutionContext ctxt, AbstractType[] resultBases = null, bool filterForTemplateArgs = true) { AbstractType[] res; if (id.InnerDeclaration == null && resultBases == null) res = ResolveIdentifier(id.IdHash, ctxt, id, id.ModuleScoped); else { var rbases = resultBases ?? Resolve(id.InnerDeclaration, ctxt); if (rbases == null || rbases.Length == 0) return null; res = ResolveFurtherTypeIdentifier(id.IdHash, rbases, ctxt, id); } if (filterForTemplateArgs && (ctxt.Options & ResolutionOptions.NoTemplateParameterDeduction) == 0) { var l_ = new List<AbstractType>(); if (res != null) foreach (var s in res) l_.Add(s); return TemplateInstanceHandler.DeduceParamsAndFilterOverloads(l_, null, false, ctxt); } else return res; }
public ImportBinding(IdentifierDeclaration symbol, IdentifierDeclaration alias = null) { Symbol = symbol; Alias = alias; }
bool HandleDecl(TemplateTypeParameter p, IdentifierDeclaration id, ISemantic r) { // Bottom-level reached if (id.InnerDeclaration == null && Contains(id.Id) && !id.ModuleScoped) { // Associate template param with r return Set(p, r, id.Id); } /* * If not stand-alone identifier or is not required as template param, resolve the id and compare it against r */ var _r = TypeDeclarationResolver.Resolve(id, ctxt); ctxt.CheckForSingleResult(_r, id); return _r != null && _r.Length != 0 && (EnforceTypeEqualityWhenDeducing ? ResultComparer.IsEqual(r,_r[0]) : ResultComparer.IsImplicitlyConvertible(r,_r[0])); }
public override void Visit(IdentifierDeclaration td) { if (td.IdHash == DTokens.IncompleteIdHash) { halt = true; if(td.InnerDeclaration != null) prv = new MemberCompletionProvider (cdgen, td.InnerDeclaration, scopedBlock, scopedStatement); } else base.Visit (td); }
public override void Visit (IdentifierDeclaration id) { if (id.IdHash == searchHash || resolveAnyway) { ctxt.CurrentContext.Set(id.Location); if (TryAdd(TypeDeclarationResolver.ResolveSingle(id, ctxt), id)) return; } base.Visit (id); }
/// <summary> /// See <see cref="Resolve"/> /// </summary> public static AbstractType ResolveSingle(IdentifierDeclaration id, ResolutionContext ctxt, AbstractType[] resultBases = null, bool filterForTemplateArgs = true) { var r = Resolve(id, ctxt, resultBases, filterForTemplateArgs); ctxt.CheckForSingleResult(r, id); return r != null && r.Length != 0 ? r[0] : null; }
public TemplateInstanceExpression TemplateInstance(IBlockNode Scope) { var loc = la.Location; var mod = INVALID; if (DTokens.StorageClass [laKind]) { mod = laKind; Step (); } if (!Expect (Identifier)) return null; ITypeDeclaration td = new IdentifierDeclaration (t.Value) { Location = t.Location, EndLocation = t.EndLocation }; td = new TemplateInstanceExpression(mod != DTokens.INVALID ? new MemberFunctionAttributeDecl(mod) { InnerType = td } : td) { Location = loc }; LastParsedObject = td; var args = new List<IExpression>(); if (!Expect(Not)) return td as TemplateInstanceExpression; if (laKind == (OpenParenthesis)) { Step(); if (laKind != CloseParenthesis) { bool init = true; while (laKind == Comma || init) { if (!init) Step(); init = false; if (laKind == CloseParenthesis) break; if (IsEOF) { args.Add(new TokenExpression(DTokens.INVALID) { Location= la.Location, EndLocation=la.EndLocation }); break; } Lexer.PushLookAheadBackup(); bool wp = AllowWeakTypeParsing; AllowWeakTypeParsing = true; var typeArg = Type(); AllowWeakTypeParsing = wp; if (typeArg != null && (laKind == CloseParenthesis || laKind==Comma)){ Lexer.PopLookAheadBackup(); args.Add(new TypeDeclarationExpression(typeArg)); }else { Lexer.RestoreLookAheadBackup(); args.Add(AssignExpression(Scope)); } } } Expect(CloseParenthesis); } else { Step(); /* * TemplateSingleArgument: * Identifier * BasicTypeX * CharacterLiteral * StringLiteral * IntegerLiteral * FloatLiteral * true * false * null * __FILE__ * __LINE__ */ IExpression arg= null; if (t.Kind == Literal) arg = new IdentifierExpression(t.LiteralFormat == LiteralFormat.StringLiteral || t.LiteralFormat == LiteralFormat.VerbatimStringLiteral ? t.Value : t.LiteralValue, t.LiteralFormat, t.Subformat) { Location = t.Location, EndLocation = t.EndLocation }; else if (t.Kind == Identifier) arg = new IdentifierExpression(t.Value) { Location = t.Location, EndLocation = t.EndLocation }; else if (BasicTypes[t.Kind]) arg = new TypeDeclarationExpression(new DTokenDeclaration(t.Kind) { Location = t.Location, EndLocation = t.EndLocation }); else if ( t.Kind == True || t.Kind == False || t.Kind == Null || t.Kind == __FILE__ || t.Kind == __LINE__) arg = new TokenExpression(t.Kind) { Location = t.Location, EndLocation = t.EndLocation }; else if (IsEOF) { TrackerVariables.ExpectingIdentifier = false; td.EndLocation = CodeLocation.Empty; return td as TemplateInstanceExpression; } args.Add(arg); } (td as TemplateInstanceExpression).Arguments = args.ToArray(); td.EndLocation = t.EndLocation; return td as TemplateInstanceExpression; }
/// <summary> /// Tries to resolve a static property's name. /// Returns a result describing the theoretical member (".init"-%gt;MemberResult; ".typeof"->TypeResult etc). /// Returns null if nothing was found. /// </summary> /// <param name="InitialResult"></param> /// <returns></returns> public static MemberSymbol TryResolveStaticProperties( ISemantic InitialResult, string propertyIdentifier, ResolverContextStack ctxt = null, bool Evaluate = false, IdentifierDeclaration idContainter = null) { // If a pointer'ed type is given, take its base type if (InitialResult is PointerType) InitialResult = ((PointerType)InitialResult).Base; if (InitialResult == null || InitialResult is ModuleSymbol) return null; INode relatedNode = null; if (InitialResult is DSymbol) relatedNode = ((DSymbol)InitialResult).Definition; #region init if (propertyIdentifier == "init") { var prop_Init = new DVariable { Name = "init", Description = "Initializer" }; if (relatedNode != null) { if (!(relatedNode is DVariable)) { prop_Init.Parent = relatedNode.Parent; prop_Init.Type = new IdentifierDeclaration(relatedNode.Name); } else { prop_Init.Parent = relatedNode; prop_Init.Initializer = (relatedNode as DVariable).Initializer; prop_Init.Type = relatedNode.Type; } } return new MemberSymbol(prop_Init, DResolver.StripAliasSymbol(AbstractType.Get(InitialResult)), idContainter); } #endregion #region sizeof if (propertyIdentifier == "sizeof") return new MemberSymbol(new DVariable { Name = "sizeof", Type = new DTokenDeclaration(DTokens.Int), Initializer = new IdentifierExpression(4), Description = "Size in bytes (equivalent to C's sizeof(type))" }, new PrimitiveType(DTokens.Int), idContainter); #endregion #region alignof if (propertyIdentifier == "alignof") return new MemberSymbol(new DVariable { Name = "alignof", Type = new DTokenDeclaration(DTokens.Int), Description = "Alignment size" }, new PrimitiveType(DTokens.Int),idContainter); #endregion #region mangleof if (propertyIdentifier == "mangleof") return new MemberSymbol(new DVariable { Name = "mangleof", Type = new IdentifierDeclaration("string"), Description = "String representing the ‘mangled’ representation of the type" }, getStringType(ctxt) , idContainter); #endregion #region stringof if (propertyIdentifier == "stringof") return new MemberSymbol(new DVariable { Name = "stringof", Type = new IdentifierDeclaration("string"), Description = "String representing the source representation of the type" }, getStringType(ctxt), idContainter); #endregion #region classinfo else if (propertyIdentifier == "classinfo") { var tr = DResolver.StripMemberSymbols(AbstractType.Get(InitialResult)) as TemplateIntermediateType; if (tr is ClassType || tr is InterfaceType) { var ci=new IdentifierDeclaration("TypeInfo_Class") { InnerDeclaration = new IdentifierDeclaration("object"), ExpressesVariableAccess = true, }; var ti = TypeDeclarationResolver.Resolve(ci, ctxt); ctxt.CheckForSingleResult(ti, ci); return new MemberSymbol(new DVariable { Name = "classinfo", Type = ci }, ti!=null && ti.Length!=0?ti[0]:null, idContainter); } } #endregion //TODO: Resolve the types of type-specific properties (floats, ints, arrays, assocarrays etc.) return null; }
ITypeDeclaration ModuleFullyQualifiedName() { if (!Expect(Identifier)) return null; var td = new IdentifierDeclaration(t.Value) { Location=t.Location,EndLocation=t.EndLocation }; while (laKind == Dot) { Step(); Expect(Identifier); td = new IdentifierDeclaration(t.Value) { Location=t.Location, EndLocation=t.EndLocation, InnerDeclaration = td }; } return td; }
public ITypeDeclaration IdentifierList() { ITypeDeclaration td = null; bool notInit = false; do { if (notInit) Step(); else notInit = true; ITypeDeclaration ttd; if (IsTemplateInstance) ttd = TemplateInstance(null); else if (Expect(Identifier)) ttd = new IdentifierDeclaration(t.Value) { Location = t.Location, EndLocation = t.EndLocation }; else if (IsEOF) return new DTokenDeclaration(DTokens.Incomplete, td); else ttd = null; if (ttd != null) ttd.InnerDeclaration = td; td = ttd; } while (laKind == Dot); return td; }
ITypeDeclaration QualifiedName() { ITypeDeclaration td = null; int n; while(PeekIsDecNumber) { // Read number of either the first LName or TemplateInstanceName n = (int)Number(); sb.Clear(); if((char)r.Peek() == '_') { r.Read(); sb.Append('_'); if((char)r.Peek() == '_') { r.Read(); sb.Append('_'); if((char)r.Peek() == 'T') { r.Read(); // We've got to handle a Template instance: // Number __T LName TemplateArgs Z var tpi = new TemplateInstanceExpression(new IdentifierDeclaration(LName())); tpi.InnerDeclaration = td; td = tpi; var xx = new List<IExpression>(); while(r.Peek() != -1) { var arg = TemplateArg(); if(arg == null) break; xx.Add(arg); } tpi.Arguments = xx.ToArray(); continue; } } } // Just an LName if(n > sb.Length) sb.Append(LName(n-sb.Length)); var ttd = new IdentifierDeclaration(sb.ToString()); ttd.InnerDeclaration = td; td = ttd; } return td; }
ITypeDeclaration ModuleFullyQualifiedName() { if (!Expect (Identifier)) return IsEOF ? new DTokenDeclaration(DTokens.Incomplete) : null; var td = new IdentifierDeclaration(t.Value) { Location=t.Location,EndLocation=t.EndLocation }; while (laKind == Dot) { Step(); if(Expect(Identifier)) td = new IdentifierDeclaration(t.Value) { Location=t.Location, EndLocation=t.EndLocation, InnerDeclaration = td }; else if(IsEOF) td = new IdentifierDeclaration(DTokens.IncompleteIdHash) { InnerDeclaration = td }; } return td; }
/// <summary> /// Tries to resolve a static property's name. /// Returns a result describing the theoretical member (".init"-%gt;MemberResult; ".typeof"->TypeResult etc). /// Returns null if nothing was found. /// </summary> /// <param name="InitialResult"></param> /// <returns></returns> public static ResolveResult TryResolveStaticProperties(ResolveResult InitialResult, IdentifierDeclaration Identifier, ResolverContext ctxt = null) { if (InitialResult == null || Identifier == null || InitialResult is ModuleResult) { return null; } var propertyName = Identifier.Value as string; if (propertyName == null) return null; INode relatedNode = null; if (InitialResult is MemberResult) relatedNode = (InitialResult as MemberResult).ResolvedMember; else if (InitialResult is TypeResult) relatedNode = (InitialResult as TypeResult).ResolvedTypeDefinition; #region init if (propertyName == "init") { var prop_Init = new DVariable { Name = "init", Description = "Initializer" }; if (relatedNode != null) { if (!(relatedNode is DVariable)) { prop_Init.Parent = relatedNode.Parent; prop_Init.Type = new IdentifierDeclaration(relatedNode.Name); } else { prop_Init.Parent = relatedNode; prop_Init.Initializer = (relatedNode as DVariable).Initializer; prop_Init.Type = relatedNode.Type; } } return new MemberResult { ResultBase = InitialResult, MemberBaseTypes = new[] { InitialResult }, TypeDeclarationBase = Identifier, ResolvedMember = prop_Init }; } #endregion #region sizeof if (propertyName == "sizeof") return new MemberResult { ResultBase = InitialResult, TypeDeclarationBase = Identifier, ResolvedMember = new DVariable { Name = "sizeof", Type = new DTokenDeclaration(DTokens.Int), Initializer = new IdentifierExpression(4), Description = "Size in bytes (equivalent to C's sizeof(type))" } }; #endregion #region alignof if (propertyName == "alignof") return new MemberResult { ResultBase = InitialResult, TypeDeclarationBase = Identifier, ResolvedMember = new DVariable { Name = "alignof", Type = new DTokenDeclaration(DTokens.Int), Description = "Alignment size" } }; #endregion #region mangleof if (propertyName == "mangleof") return new MemberResult { ResultBase = InitialResult, TypeDeclarationBase = Identifier, ResolvedMember = new DVariable { Name = "mangleof", Type = new IdentifierDeclaration("string"), Description = "String representing the ‘mangled’ representation of the type" }, MemberBaseTypes = ResolveType(new IdentifierDeclaration("string"), ctxt) }; #endregion #region stringof if (propertyName == "stringof") return new MemberResult { ResultBase = InitialResult, TypeDeclarationBase = Identifier, ResolvedMember = new DVariable { Name = "stringof", Type = new IdentifierDeclaration("string"), Description = "String representing the source representation of the type" }, MemberBaseTypes = ResolveType(new IdentifierDeclaration("string"), ctxt) }; #endregion bool isArray = false, isAssocArray = false, isInt = false, isFloat = false; #region See AbsractCompletionSupport.StaticPropertyAddition if (InitialResult is StaticTypeResult) { var srr = InitialResult as StaticTypeResult; var type = srr.TypeDeclarationBase; // on things like immutable(char), pass by the surrounding attribute.. while (type is MemberFunctionAttributeDecl) type = (type as MemberFunctionAttributeDecl).InnerType; if (type is ArrayDecl) { var ad = type as ArrayDecl; // Normal array if (ad.KeyType is DTokenDeclaration && DTokens.BasicTypes_Integral[(ad.KeyType as DTokenDeclaration).Token]) isArray = true; // Associative array else isAssocArray = true; } else if (!(type is PointerDecl)) { int TypeToken = srr.BaseTypeToken; if (TypeToken <= 0 && type is DTokenDeclaration) TypeToken = (type as DTokenDeclaration).Token; if (TypeToken > 0) { // Determine whether float by the var's base type isInt = DTokens.BasicTypes_Integral[srr.BaseTypeToken]; isFloat = DTokens.BasicTypes_FloatingPoint[srr.BaseTypeToken]; } } } else if (InitialResult is ExpressionResult) { var err = InitialResult as ExpressionResult; var expr = err.Expression; // 'Skip' surrounding parentheses while (expr is SurroundingParenthesesExpression) expr = (expr as SurroundingParenthesesExpression).Expression; var idExpr = expr as IdentifierExpression; if (idExpr != null) { // Char literals, Integrals types & Floats if ((idExpr.Format & LiteralFormat.Scalar) == LiteralFormat.Scalar || idExpr.Format == LiteralFormat.CharLiteral) { // Floats also imply integral properties isInt = true; isFloat = (idExpr.Format & LiteralFormat.FloatingPoint) == LiteralFormat.FloatingPoint; } // String literals else if (idExpr.Format == LiteralFormat.StringLiteral || idExpr.Format == LiteralFormat.VerbatimStringLiteral) { isArray = true; } } // Pointer conversions (e.g. (myInt*).sizeof) } #endregion //TODO: Resolve static [assoc] array props if (isArray || isAssocArray) { } return null; }
public override void Visit(IdentifierDeclaration td) { byte type; if (DoPrimaryIdCheck(td.IdHash, out type)) AddResult(td, type); base.Visit (td); }
public ITypeDeclaration IdentifierList() { ITypeDeclaration td = null; bool init = true; while (init|| laKind == Dot) { if(!init) Step(); init = false; ITypeDeclaration ttd = null; if (IsTemplateInstance) ttd = TemplateInstance(); else if (Expect(Identifier)) ttd = new IdentifierDeclaration(t.Value) { Location=t.Location, EndLocation=t.EndLocation }; if (ttd != null) ttd.InnerDeclaration = td; td = ttd; } ExpectingIdentifier = false; return td; }
public ITypeDeclaration IdentifierList(IBlockNode scope = null) { ITypeDeclaration td = null; switch (laKind) { case DTokens.This: case DTokens.Super: Step (); td = new DTokenDeclaration (t.Kind) { Location = t.Location, EndLocation = t.EndLocation }; if (!Expect (DTokens.Dot)) return td; break; } bool notInit = false; do { if (notInit) Step(); else notInit = true; ITypeDeclaration ttd; if (IsTemplateInstance) ttd = TemplateInstance(scope); else if (Expect(Identifier)) ttd = new IdentifierDeclaration(t.Value) { Location = t.Location, EndLocation = t.EndLocation }; else if (IsEOF) return new DTokenDeclaration(DTokens.Incomplete, td); else ttd = null; if (ttd != null) ttd.InnerDeclaration = td; td = ttd; } while (laKind == Dot); return td; }
public override void Visit(IdentifierDeclaration td) { if (DoPrimaryIdCheck(td.IdHash)) AddResult(td); base.Visit (td); }