public ISymbolValue Visit(TypeDeclarationExpression x) { // should be containing a typeof() only; static properties etc. are parsed as access expressions var t = TypeDeclarationResolver.ResolveSingle(x.Declaration, ctxt); return(new TypeValue(t)); }
ISemantic E(TypeDeclarationExpression x) { if (eval) { throw new NotImplementedException("TODO: Handle static properties and ufcs functionality on type declaration expressions"); } return(TypeDeclarationResolver.ResolveSingle(((TypeDeclarationExpression)x).Declaration, ctxt)); }
ISemantic E(TypeDeclarationExpression x) { var t = TypeDeclarationResolver.ResolveSingle(x.Declaration, ctxt); if (eval) { return(new TypeValue(t)); } return(t); }
ITypeDeclaration VisitDSymbol(DSymbol t) { var def = t.Definition; ITypeDeclaration td = new IdentifierDeclaration(def != null ? def.NameHash : 0); if (def != null && t.DeducedTypes != null && def.TemplateParameters != null) { var args = new List <IExpression>(); foreach (var tp in def.TemplateParameters) { IExpression argEx = null; foreach (var tps in t.DeducedTypes) { if (tps != null && tps.Parameter == tp) { if (tps.ParameterValue != null) { //TODO: Convert ISymbolValues back to IExpression } else { argEx = new TypeDeclarationExpression(AcceptType(tps)); } break; } } args.Add(argEx ?? new IdentifierExpression(tp.NameHash)); } td = new TemplateInstanceExpression(td) { Arguments = args.ToArray() }; } var ret = td; while (def != null && def != (def = def.Parent as DNode) && def != null && !(def is DModule)) { td = td.InnerDeclaration = new IdentifierDeclaration(def.NameHash); } return(ret); }
public static void AddEnum(string enumName, TypeDeclarationExpression enumDeclaration) { if (ParsedInfo.Enums.Any(x => x.Name == enumName)) { return; } var enumMapping = new ObjectiveCParsedInfo.EnumInfo { Name = enumName }; var evaluatedEnum = EvaluatedTranslationUnit.Enums.FirstOrDefault(x => x.Original == enumDeclaration); foreach (var enumElement in evaluatedEnum.Items) { enumMapping.Elements.Add(new ObjectiveCParsedInfo.EnumInfo.ElementInfo { Name = enumElement.Key, Value = enumElement.Value }); } ParsedInfo.Enums.Add(enumMapping); }
public void Visit(TypeDeclarationExpression x) { }
public AbstractType Visit(TypeDeclarationExpression x) { // should be containing a typeof() only; static properties etc. are parsed as access expressions return(TypeDeclarationResolver.ResolveSingle(x.Declaration, ctxt)); }
public void Visit(TypeDeclarationExpression x) { }
public override object Visit(TypeDeclarationExpression node) { using (ASTScope.PushScoped(node)) { if (node.Type == TypeDeclarationExpression.TypeKind.Enum) { long value = 0; var @enum = new Enum(); @enum.Original = node; using (Scope.PushScoped(@enum)) foreach (EnumElementDeclaration element in node.Body) { if (element.InitializerExpression != null) { var evaluatedValue = element.InitializerExpression.AcceptVisitor(new ConstantEvaluator(this)); if (evaluatedValue == null) { Debugger.Break(); } value = ( long )evaluatedValue; } @enum.Items.Add(element.Name, value); value++; } TranslationUnit.Enums.Add(@enum); if (node.Name != null) { Types.Peek()[node.Name.ToString()] = @enum; } return(@enum); } else { LanguageType cppTypeNode; CppType cppType = null; if (node.Name != null && Types.Peek().TryGetValue(node.Name.ToString(), out cppTypeNode)) { cppType = ( CppType )cppTypeNode; } else { cppType = new CppType(); cppType.Name = node.Name != null?node.Name.ToString() : null; cppType.Original = node; } if (!cppType.IsDefined && !node.IsForwardDeclaration) { cppType.IsDefined = true; } else if (cppType.IsDefined && !node.IsForwardDeclaration) { Debugger.Break(); } if (node.Name != null) { Types.Peek()[node.Name.ToString()] = cppType; } TranslationUnit.CppTypes.Add(cppType); using (Scope.PushScoped(cppType)) base.Visit(node); return(cppType); } } }
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; }
public TemplateInstanceExpression TemplateInstance() { if (!Expect(Identifier)) return null; var td = new TemplateInstanceExpression() { TemplateIdentifier = new IdentifierDeclaration(t.Value) { Location=t.Location, EndLocation=t.EndLocation }, Location = t.Location }; LastParsedObject = td; var args = new List<IExpression>(); if (!Expect(Not)) return td; if (laKind == (OpenParenthesis)) { Step(); if (laKind != CloseParenthesis) { bool init = true; while (laKind == Comma || init) { if (!init) Step(); init = false; if (IsEOF) { args.Add(new TokenExpression(DTokens.INVALID) { Location= la.Location, EndLocation=la.EndLocation }); break; } var la_Backup = la; bool wp = AllowWeakTypeParsing; AllowWeakTypeParsing = true; var typeArg = Type(); AllowWeakTypeParsing = wp; if (typeArg != null && (laKind == CloseParenthesis || laKind==Comma)) args.Add(new TypeDeclarationExpression(typeArg)); else { la = la_Backup; Peek(1); args.Add(AssignExpression()); } } } 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.LiteralValue, LiteralFormat.Scalar) { 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) { ExpectingIdentifier = false; return td; } args.Add(arg); } td.Arguments = args.ToArray(); td.EndLocation = t.EndLocation; return td; }
public ISymbolValue Visit(TypeDeclarationExpression x) { // should be containing a typeof() only; static properties etc. are parsed as access expressions var t = TypeDeclarationResolver.ResolveSingle(x.Declaration, ctxt); return new TypeValue(t); }
IExpression PrimaryExpression(IBlockNode Scope=null) { bool isModuleScoped = false; // For minimizing possible overhead, skip 'useless' tokens like an initial dot <<< TODO if (isModuleScoped= laKind == Dot) Step(); if (laKind == __FILE__ || laKind == __LINE__) { Step(); object id = null; if (t.Kind == __FILE__ && doc != null) id = doc.FileName; else if(t.Kind==__LINE__) id = t.line; return new IdentifierExpression(id) { Location=t.Location, EndLocation=t.EndLocation }; } // Dollar (== Array length expression) if (laKind == Dollar) { Step(); return new TokenExpression(laKind) { Location = t.Location, EndLocation = t.EndLocation }; } // TemplateInstance if (laKind == (Identifier) && Lexer.CurrentPeekToken.Kind == (Not) && (Peek().Kind != Is && Lexer.CurrentPeekToken.Kind != In) /* Very important: The 'template' could be a '!is'/'!in' expression - With two tokens each! */) return TemplateInstance(); // Identifier if (laKind == (Identifier)) { Step(); return new IdentifierExpression(t.Value) { Location = t.Location, EndLocation = t.EndLocation }; } // SpecialTokens (this,super,null,true,false,$) // $ has been handled before if (laKind == (This) || laKind == (Super) || laKind == (Null) || laKind == (True) || laKind == (False)) { Step(); return new TokenExpression(t.Kind) { Location = t.Location, EndLocation = t.EndLocation }; } #region Literal if (laKind == Literal) { Step(); var startLoc = t.Location; // Concatenate multiple string literals here if (t.LiteralFormat == LiteralFormat.StringLiteral || t.LiteralFormat == LiteralFormat.VerbatimStringLiteral) { var a = t.LiteralValue as string; while (la.LiteralFormat == LiteralFormat.StringLiteral || la.LiteralFormat == LiteralFormat.VerbatimStringLiteral) { Step(); a += t.LiteralValue as string; } return new IdentifierExpression(a, t.LiteralFormat) { Location = startLoc, EndLocation = t.EndLocation }; } //else if (t.LiteralFormat == LiteralFormat.CharLiteral)return new IdentifierExpression(t.LiteralValue) { LiteralFormat=t.LiteralFormat,Location = startLoc, EndLocation = t.EndLocation }; return new IdentifierExpression(t.LiteralValue, t.LiteralFormat) { Location = startLoc, EndLocation = t.EndLocation }; } #endregion #region ArrayLiteral | AssocArrayLiteral if (laKind == (OpenSquareBracket)) { Step(); var startLoc = t.Location; // Empty array literal if (laKind == CloseSquareBracket) { Step(); return new ArrayLiteralExpression() {Location=startLoc, EndLocation = t.EndLocation }; } var firstExpression = AssignExpression(); // Associtative array if (laKind == Colon) { Step(); var ae = new AssocArrayExpression() { Location=startLoc}; LastParsedObject = ae; var firstValueExpression = AssignExpression(); ae.KeyValuePairs.Add(firstExpression, firstValueExpression); while (laKind == Comma) { Step(); var keyExpr = AssignExpression(); Expect(Colon); var valueExpr = AssignExpression(); ae.KeyValuePairs.Add(keyExpr, valueExpr); } Expect(CloseSquareBracket); ae.EndLocation = t.EndLocation; return ae; } else // Normal array literal { var ae = new ArrayLiteralExpression() { Location=startLoc}; LastParsedObject = ae; var expressions = new List<IExpression>(); expressions.Add(firstExpression); while (laKind == Comma) { Step(); if (laKind == CloseSquareBracket) // And again, empty expressions are allowed break; expressions.Add(AssignExpression()); } ae.Expressions = expressions; Expect(CloseSquareBracket); ae.EndLocation = t.EndLocation; return ae; } } #endregion #region FunctionLiteral if (laKind == Delegate || laKind == Function || laKind == OpenCurlyBrace || (laKind == OpenParenthesis && IsFunctionLiteral())) { var fl = new FunctionLiteral() { Location=la.Location}; LastParsedObject = fl; fl.AnonymousMethod.StartLocation = la.Location; if (laKind == Delegate || laKind == Function) { Step(); fl.LiteralToken = t.Kind; } // file.d:1248 /* listdir (".", delegate bool (DirEntry * de) { auto s = std.string.format("%s : c %s, w %s, a %s", de.name, toUTCString (de.creationTime), toUTCString (de.lastWriteTime), toUTCString (de.lastAccessTime)); return true; } ); */ if (laKind != OpenCurlyBrace) // foo( 1, {bar();} ); -> is a legal delegate { if (!MemberFunctionAttribute[laKind] && Lexer.CurrentPeekToken.Kind == OpenParenthesis) fl.AnonymousMethod.Type = BasicType(); else if (laKind != OpenParenthesis && laKind != OpenCurlyBrace) fl.AnonymousMethod.Type = Type(); if (laKind == OpenParenthesis) fl.AnonymousMethod.Parameters = Parameters(fl.AnonymousMethod); } FunctionBody(fl.AnonymousMethod); fl.EndLocation = t.EndLocation; if (Scope != null) Scope.Add(fl.AnonymousMethod); return fl; } #endregion #region AssertExpression if (laKind == (Assert)) { Step(); var startLoc = t.Location; Expect(OpenParenthesis); var ce = new AssertExpression() { Location=startLoc}; LastParsedObject = ce; var exprs = new List<IExpression>(); exprs.Add(AssignExpression()); if (laKind == (Comma)) { Step(); exprs.Add(AssignExpression()); } ce.AssignExpressions = exprs.ToArray(); Expect(CloseParenthesis); ce.EndLocation = t.EndLocation; return ce; } #endregion #region MixinExpression | ImportExpression if (laKind == Mixin) { Step(); var e = new MixinExpression() { Location=t.Location}; LastParsedObject = e; Expect(OpenParenthesis); e.AssignExpression = AssignExpression(); Expect(CloseParenthesis); e.EndLocation = t.EndLocation; return e; } if (laKind == Import) { Step(); var e = new ImportExpression() { Location=t.Location}; LastParsedObject = e; Expect(OpenParenthesis); e.AssignExpression = AssignExpression(); Expect(CloseParenthesis); e.EndLocation = t.EndLocation; return e; } #endregion if (laKind == (Typeof)) { var startLoc = la.Location; return new TypeDeclarationExpression(TypeOf()) {Location=startLoc,EndLocation=t.EndLocation}; } // TypeidExpression if (laKind == (Typeid)) { Step(); var ce = new TypeidExpression() { Location=t.Location}; LastParsedObject = ce; Expect(OpenParenthesis); AllowWeakTypeParsing = true; ce.Type = Type(); AllowWeakTypeParsing = false; if (ce.Type==null) ce.Expression = AssignExpression(); Expect(CloseParenthesis); ce.EndLocation = t.EndLocation; return ce; } #region IsExpression if (laKind == Is) { Step(); var ce = new IsExpression() { Location=t.Location}; LastParsedObject = ce; Expect(OpenParenthesis); var LookAheadBackup = la; AllowWeakTypeParsing = true; ce.TestedType = Type(); AllowWeakTypeParsing = false; if (ce.TestedType!=null && laKind == Identifier && (Lexer.CurrentPeekToken.Kind == CloseParenthesis || Lexer.CurrentPeekToken.Kind == Equal || Lexer.CurrentPeekToken.Kind == Colon)) { Step(); ce.TypeAliasIdentifier = strVal; } else // D Language specs mistake: In an IsExpression there also can be expressions! if(ce.TestedType==null || !(laKind==CloseParenthesis || laKind==Equal||laKind==Colon)) { // Reset lookahead token to prior position la = LookAheadBackup; // Reset wrongly parsed type declaration ce.TestedType = null; ce.TestedExpression = ConditionalExpression(); } if(ce.TestedExpression==null && ce.TestedType==null) SynErr(laKind,"In an IsExpression, either a type or an expression is required!"); if (laKind == CloseParenthesis) { Step(); ce.EndLocation = t.EndLocation; return ce; } if (laKind == Colon || laKind == Equal) { Step(); ce.EqualityTest = t.Kind == Equal; } else if (laKind == CloseParenthesis) { Step(); ce.EndLocation = t.EndLocation; return ce; } /* TypeSpecialization: Type struct union class interface enum function delegate super const immutable inout shared return */ if (ClassLike[laKind] || laKind==Typedef || // typedef is possible although it's not yet documented in the syntax docs laKind==Enum || laKind==Delegate || laKind==Function || laKind==Super || laKind==Return) { Step(); ce.TypeSpecializationToken = t.Kind; } else ce.TypeSpecialization = Type(); if (laKind == Comma) { Step(); ce.TemplateParameterList = TemplateParameterList(false); } Expect(CloseParenthesis); ce.EndLocation = t.EndLocation; return ce; } #endregion // ( Expression ) if (laKind == OpenParenthesis) { Step(); var ret = new SurroundingParenthesesExpression() {Location=t.Location }; LastParsedObject = ret; ret.Expression = Expression(); Expect(CloseParenthesis); ret.EndLocation = t.EndLocation; return ret; } // TraitsExpression if (laKind == (__traits)) return TraitsExpression(); #region BasicType . Identifier if (laKind == (Const) || laKind == (Immutable) || laKind == (Shared) || laKind == (InOut) || BasicTypes[laKind]) { Step(); var startLoc = t.Location; IExpression left = null; if (!BasicTypes[t.Kind]) { int tk = t.Kind; // Put an artificial parenthesis around the following type declaration if (laKind != OpenParenthesis) { var mttd = new MemberFunctionAttributeDecl(tk); LastParsedObject = mttd; mttd.InnerType = Type(); left = new TypeDeclarationExpression(mttd) { Location = startLoc, EndLocation = t.EndLocation }; } else { Expect(OpenParenthesis); var mttd = new MemberFunctionAttributeDecl(tk); LastParsedObject = mttd; mttd.InnerType = Type(); Expect(CloseParenthesis); left = new TypeDeclarationExpression(mttd) { Location = startLoc, EndLocation = t.EndLocation }; } } else left = new TokenExpression(t.Kind) {Location=startLoc,EndLocation=t.EndLocation }; if (laKind == (Dot) && Peek(1).Kind==Identifier) { Step(); Step(); var meaex = new PostfixExpression_Access() { PostfixForeExpression=left, TemplateOrIdentifier=new IdentifierDeclaration(t.Value),EndLocation=t.EndLocation }; return meaex; } return left; } #endregion // TODO? Expressions can of course be empty... //return null; SynErr(Identifier); Step(); return new TokenExpression(t.Kind) { Location = t.Location, EndLocation = t.EndLocation }; }
ISemantic E(TypeDeclarationExpression x) { var t = TypeDeclarationResolver.ResolveSingle(x.Declaration, ctxt); if (eval) return new TypeValue(t); return t; }
ISemantic E(TypeDeclarationExpression x) { if (eval) throw new NotImplementedException("TODO: Handle static properties and ufcs functionality on type declaration expressions"); return TypeDeclarationResolver.ResolveSingle(((TypeDeclarationExpression)x).Declaration, ctxt); }