static MetaProperty ResolveMetaproperty(FunctionCompiler methodCompiler, AmbientParser.Node metaPropertyNode) { MetaProperty mp; var function = methodCompiler.Function as Method; if (function == null) { return(null); } foreach (var block in function.DrawBlocks) { mp = ResolveForEachMetaProperty(block.Members, metaPropertyNode); if (mp != null) { return(mp); } foreach (var item in block.Members) { var apply = item as Apply; if (apply != null && apply.Block != null) { mp = ResolveForEachMetaProperty(apply.Block.Members, metaPropertyNode); if (mp != null) { return(mp); } } } } return(null); }
void SuggestMetaproperty(FunctionCompiler methodCompiler, AmbientParser.Node c) { var mp = c.MetaProperty ?? ResolveMetaproperty(methodCompiler, c); if (mp == null) { return; } var m = new GetMetaProperty(_source, mp.ReturnType, c.Name); Suggest(SuggestItemType.MetaProperty, m, m.Name); }
public PartialExpression ResolveStringInFunctionContext(AmbientParser.Node methodNode, string memberExp, Source src, FunctionCompiler fc = null) { var funcCompiler = fc ?? CreateFunctionCompiler(methodNode); // Parse the member expression var dte = Parser.ParseExpression(_compiler.Log, src, memberExp, fc != null && fc.MetaProperty != null ? ParseContext.MetaProperty : ParseContext.Default); if (!dte.IsInvalid) { // Resolve the member expresion return(funcCompiler.ResolveExpression(dte, null)); } return(null); }
void SuggestForInlineBlock(FunctionCompiler methodCompiler, AmbientParser.Node lastInlineBlock) { foreach (var c in lastInlineBlock.Children) { switch (c.Type) { case NodeType.Apply: SuggestForApplyBlockItems(c); break; case NodeType.MetaProperty: SuggestMetaproperty(methodCompiler, c); break; } } }
void SuggestKeywordsIfCan(AmbientParser.Node last) { var metapropertyDef = last.Type == NodeType.MetaPropertyDefinitionScope || last.Type == NodeType.MetaPropertyDefinition; var childrenIsNotMetapropertyDef = last.Children == null || last.Children.LastOrDefault(x => x.Type == NodeType.MetaPropertyDefinition) == null; if (!metapropertyDef && childrenIsNotMetapropertyDef) { SuggestKeywords("drawable", "pixel", "vertex", "volatile", "init", "apply"); } if (last.Type == NodeType.MetaProperty) { SuggestKeywords("is", "as"); } }
public AstScope ParseFunctionBody(AmbientParser.Node methodNode, out int startOffset) { string funcCode = "{"; var funcStart = 0; if (methodNode != null) { funcStart = GetScopeStart(methodNode.StartOffset); if (funcStart <= _reader.Offset) { funcCode = _reader.PeekTextReverse(_reader.Offset - funcStart); } } startOffset = funcStart; return(Parser.ParseStatement(_compiler.Log, _source, funcCode) as AstScope); }
public FunctionCompiler CreateFunctionCompiler(AmbientParser.Node methodNode) { int startOffset; var functionBody = ParseFunctionBody(methodNode, out startOffset); // Find the function we are inside Function func = null; int funcDist = int.MaxValue; if (methodNode != null && _context.TypeOrNamespace is DataType) { foreach (var f in (_context.TypeOrNamespace as DataType).EnumerateFunctions() .Where(m => m.Source.FullPath == _source.FullPath)) { int dist = System.Math.Abs(f.Source.Offset - methodNode.StartOffset); if (dist < funcDist) { func = f; funcDist = dist; } } } // Construct a function compiler for the context FunctionCompiler funcCompiler; if (func != null) { funcCompiler = new FunctionCompiler(_compiler, func, _compiler.TypeBuilder.Parameterize(func.DeclaringType), functionBody); try { funcCompiler.Compile(); } catch (Exception) { } } else { funcCompiler = new FunctionCompiler(_compiler, _context.TypeOrNamespace); } return(funcCompiler); }
void SuggestForApplyBlockItems(AmbientParser.Node c) { var log = new Log(new StringWriter()); var dte = Parser.ParseExpression(log, _source, c.Name, ParseContext.MetaProperty); if (log.ErrorCount != 0) { return; } var b = _context.Compiler.NameResolver.GetBlock( _context.TypeOrNamespace as ClassType, dte); if (b != null) { SuggestBlockItems(b); } }
bool IsBeforeScopeStart(AmbientParser.Node n) { if (n == null) { return(false); } var offset = _reader.Offset; _reader.Offset = n.StartOffset; while (true) { var t = _reader.ReadToken(); if (t == TokenType.EndOfFile || t == TokenType.LeftCurlyBrace) { break; } } var res = _reader.Offset > offset; _reader.Offset = offset; return(res); }
static MetaProperty ResolveForEachMetaProperty(IEnumerable <BlockMember> blockItems, AmbientParser.Node metaPropertyNode) { return(blockItems.OfType <MetaProperty>() .FirstOrDefault( metaproperty => metaPropertyNode.StartOffset >= metaproperty.Source.Offset && metaproperty.Name == metaPropertyNode.Name )); }