protected override void VisitFunctionDefinition(FunctionDefinitionNode node) { _initializedLocalsPaths = new HashSet <string>(); _currentBlockSymbol = (BlockSymbol)node.Symbol; base.VisitFunctionDefinition(node); _currentBlockSymbol = null; }
public BlockSymbol Create(Sheet sheet) { var id = IdGenerator.GetNextId(); var blockSymbol = new BlockSymbol(id, _undoService, _connectorFactory, bs => Remove(bs.Id), sheet); _cache[id] = blockSymbol; return(blockSymbol); }
private void OnBlockSymbolsRemoveAtEventHandler(int indexAt, BlockSymbol blockSymbol) { var toBeRemoved = _symbolVms.OfType <BlockViewModel>().FirstOrDefault(b => b.Id == blockSymbol.Id); if (toBeRemoved != null) { SymbolVms.Remove(toBeRemoved); } }
public UninitializedSymbolUsageDetectionVisitor() { _node2InitializedAttributesPaths = new Dictionary <SubclassNode, HashSet <string> >(); _initializedAttributesPaths = null; _initializedLocalsPaths = null; _currentBlockSymbol = null; _visitedNodes = new HashSet <ASTNode>(); }
private void BuildConst(ConstDefinitionNode constDefinitionNode, bool buildArray = false) { string constName = constDefinitionNode.NameNode.Value; string constTypeName = constDefinitionNode.TypeNameCapitalized; BlockSymbol parentBlockSymbol = GetParentBlockSymbol(constDefinitionNode); ConstSymbol constSymbol = buildArray ? new ConstArraySymbol(parentBlockSymbol, constTypeName, constName, constDefinitionNode) : new ConstSymbol(parentBlockSymbol, constTypeName, constName, constDefinitionNode); AddSymbol(constSymbol); }
public BlockSymbol Create(int id, Sheet sheet) { BlockSymbol blockSymbol; if (_cache.TryGetValue(id, out blockSymbol)) { return(blockSymbol); } blockSymbol = new BlockSymbol(id, _undoService, _connectorFactory, bs => Remove(bs.Id), sheet); _cache[id] = blockSymbol; return(blockSymbol); }
public BlockViewModel(BlockSymbol blockSymbol, Client client, IInspectorTool inspectorTool) { Id = blockSymbol.Id; _blockSymbol = blockSymbol; _client = client; _inspectorTool = inspectorTool; _x = _blockSymbol.PositionX; _y = _blockSymbol.PositionY; _blockSymbol.PositionXChangeEventHandler += x => X = x; _blockSymbol.PositionYChangeEventHandler += y => Y = y; }
protected override void VisitInstanceDefinition(InstanceDefinitionNode node) { InstanceSymbol symbol = (InstanceSymbol)node.Symbol; if (symbol?.InheritanceParentSymbol?.Node != null) { Visit(symbol.InheritanceParentSymbol.Node); } _initializedAttributesPaths = new HashSet <string>(); _initializedLocalsPaths = new HashSet <string>(); _node2InitializedAttributesPaths[node] = _initializedAttributesPaths; _currentBlockSymbol = symbol; base.VisitInstanceDefinition(node); _currentBlockSymbol = null; }
/// <summary> /// Initializes a new instance of the <see cref="PdbLocalScope"/> class. /// </summary> /// <param name="function">Function that contains this scope.</param> /// <param name="block">Block symbol read from PDB.</param> /// <param name="parent">Parent scope.</param> internal PdbLocalScope(PdbFunction function, BlockSymbol block, PdbLocalScope parent = null) { Function = function; Block = block; Parent = parent; childrenCache = SimpleCache.CreateStruct(() => { IEnumerable <BlockSymbol> blocks = Block.Children.OfType <BlockSymbol>(); int count = blocks.Count(); IPdbLocalScope[] children = new IPdbLocalScope[count]; int i = 0; foreach (BlockSymbol b in blocks) { children[i++] = new PdbLocalScope(Function, b, this); } return(children); }); constantsCache = SimpleCache.CreateStruct(() => { IEnumerable <ConstantSymbol> symbols = Block.Children.OfType <ConstantSymbol>(); int count = symbols.Count(); IPdbLocalConstant[] constants = new IPdbLocalConstant[count]; int i = 0; foreach (ConstantSymbol symbol in symbols) { constants[i++] = new PdbLocalConstant(this, symbol); } return(constants); }); variablesCache = SimpleCache.CreateStruct(() => { IEnumerable <AttributeSlotSymbol> slots = Block.Children.OfType <AttributeSlotSymbol>(); int count = slots.Count(); IPdbLocalVariable[] variables = new IPdbLocalVariable[count]; int i = 0; foreach (AttributeSlotSymbol slot in slots) { variables[i++] = new PdbLocalVariable(this, slot); } return(variables); }); }
private void BuildVar(VarDeclarationNode varDeclarationNode, bool buildArray = false) { string varName = varDeclarationNode.NameNode.Value; string varTypeName = varDeclarationNode.TypeNameCapitalized; BlockSymbol parentBlockSymbol = GetParentBlockSymbol(varDeclarationNode); VarSymbol varSymbol; if (parentBlockSymbol is ClassSymbol) { varSymbol = buildArray ? new AttributeArraySymbol(parentBlockSymbol, varTypeName, varName, varDeclarationNode) : new AttributeSymbol(parentBlockSymbol, varTypeName, varName, varDeclarationNode); } else { varSymbol = buildArray ? new VarArraySymbol(parentBlockSymbol, varTypeName, varName, varDeclarationNode) : new VarSymbol(parentBlockSymbol, varTypeName, varName, varDeclarationNode); } AddSymbol(varSymbol); }
private void OnBlockSymbolsInsertAtEventHandler(int insertAt, BlockSymbol newBlockSymbol) { var block = new BlockViewModel(newBlockSymbol, _client, _inspectorTool); SymbolVms.Insert(insertAt, block); }
private void OnBlockSymbolsAddEventHandler(BlockSymbol blockSymbol) { SymbolVms.Add(new BlockViewModel(blockSymbol, _client, _inspectorTool)); }
private List <DatToken> GetTokens(BlockSymbol blockSymbol) { List <DatToken> tokens = new List <DatToken>(); foreach (AssemblyElement it in blockSymbol.Instructions) { AssemblyElement instruction = it; if (instruction is AssemblyLabel) { continue; } int? intParam = null; byte?byteParam = null; switch (instruction) { case Call call: { intParam = ((BlockSymbol)call.Symbol).FirstTokenAddress; break; } case PushArrayVar pushArrVar: { intParam = pushArrVar.Symbol.Index; byteParam = (byte)pushArrVar.Index; break; } case JumpToLabel jumpToLabel: { intParam = blockSymbol.Label2Address[jumpToLabel.Label]; break; } case SymbolInstruction symbolInstruction: { intParam = symbolInstruction.Symbol.Index; break; } case ValueInstruction valueInstruction: { intParam = (int)valueInstruction.Value; break; } case AddressInstruction addressInstruction: { intParam = addressInstruction.Address; break; } case PushNullInstance _: intParam = 0; break; } string tokenName = instruction.GetType().Name; if (instruction is JumpToLabel) { tokenName = tokenName.Substring(0, tokenName.Length - "ToLabel".Length); } DatTokenType datTokenType = Enum.Parse <DatTokenType>(tokenName); tokens.Add(new DatToken { TokenType = datTokenType, IntParam = intParam, ByteParam = byteParam }); } return(tokens); }
/// <summary> /// Reads symbol record from symbol references for the specified index. /// </summary> /// <param name="index">Index of the symbol record.</param> private SymbolRecord GetSymbol(int index) { // Since DictionaryCache is allowing only single thread to call this function, we don't need to lock reader here. SymbolRecordReference reference = references[index]; Reader.Position = reference.DataOffset; switch (reference.Kind) { case SymbolRecordKind.S_GPROC32: case SymbolRecordKind.S_LPROC32: case SymbolRecordKind.S_GPROC32_ID: case SymbolRecordKind.S_LPROC32_ID: case SymbolRecordKind.S_LPROC32_DPC: case SymbolRecordKind.S_LPROC32_DPC_ID: return(ProcedureSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_PUB32: return(Public32Symbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_CONSTANT: case SymbolRecordKind.S_MANCONSTANT: return(ConstantSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_LDATA32: case SymbolRecordKind.S_GDATA32: case SymbolRecordKind.S_LMANDATA: case SymbolRecordKind.S_GMANDATA: return(DataSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_PROCREF: case SymbolRecordKind.S_LPROCREF: return(ProcedureReferenceSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_TOKENREF: return(TokenReferenceSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_UDT: case SymbolRecordKind.S_COBOLUDT: return(UdtSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_LTHREAD32: case SymbolRecordKind.S_GTHREAD32: return(ThreadLocalDataSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_GMANPROC: case SymbolRecordKind.S_LMANPROC: return(ManagedProcedureSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_BLOCK32: return(BlockSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_OEM: return(OemSymbol.Read(Reader, this, index, reference.Kind, reference.DataLen)); case SymbolRecordKind.S_UNAMESPACE: return(NamespaceSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_MANSLOT: return(AttributeSlotSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_END: case SymbolRecordKind.S_INLINESITE_END: return(EndSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_ANNOTATION: return(AnnotationSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_ANNOTATIONREF: return(AnnotationReferenceSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_REGREL32: return(RegisterRelativeSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_OBJNAME: return(ObjectNameSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_COMPILE2: return(Compile2Symbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_COMPILE3: return(Compile3Symbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_ENVBLOCK: return(EnvironmentBlockSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_BUILDINFO: return(BuildInfoSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_FRAMEPROC: return(FrameProcedureSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_LABEL32: return(LabelSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_HEAPALLOCSITE: return(HeapAllocationSiteSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_CALLSITEINFO: return(CallSiteInfoSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_FRAMECOOKIE: return(FrameCookieSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_THUNK32: return(Thunk32Symbol.Read(Reader, this, index, reference.Kind, reference.DataLen)); case SymbolRecordKind.S_LOCAL: return(LocalSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_DEFRANGE_REGISTER: return(DefRangeRegisterSymbol.Read(Reader, this, index, reference.Kind, reference.DataLen)); case SymbolRecordKind.S_DEFRANGE_REGISTER_REL: return(DefRangeRegisterRelativeSymbol.Read(Reader, this, index, reference.Kind, reference.DataLen)); case SymbolRecordKind.S_DEFRANGE_SUBFIELD_REGISTER: return(DefRangeSubfieldRegisterSymbol.Read(Reader, this, index, reference.Kind, reference.DataLen)); case SymbolRecordKind.S_DEFRANGE_FRAMEPOINTER_REL: return(DefRangeFramePointerRelativeSymbol.Read(Reader, this, index, reference.Kind, reference.DataLen)); case SymbolRecordKind.S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE: return(DefRangeFramePointerRelativeFullScopeSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_CALLEES: case SymbolRecordKind.S_CALLERS: return(FunctionListSymbol.Read(Reader, this, index, reference.Kind, reference.DataLen)); case SymbolRecordKind.S_FILESTATIC: return(FileStaticSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_TRAMPOLINE: return(TrampolineSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_SECTION: return(SectionSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_COFFGROUP: return(CoffGroupSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_EXPORT: return(ExportSymbol.Read(Reader, this, index, reference.Kind)); case SymbolRecordKind.S_INLINESITE: return(InlineSiteSymbol.Read(Reader, this, index, reference.Kind, reference.DataLen)); default: #if DEBUG throw new NotImplementedException($"Unknown reference kind: {reference.Kind}"); #else return(null); #endif } }