DLRExpressionTree* ETSemanticsForLambdas::ConvertSymbol ( ILTree::Expression* Input, ExpressionFlags Flags, Type* TargetType ) { ThrowIfNull(Input); ThrowIfFalse(Input->bilop == SX_SYM); Declaration* Symbol = Input->AsSymbolReferenceExpression().pnamed; if(Symbol->IsVariable()) { Variable *Var = Symbol->PVariable(); // IsLocal check also required for Chimayo scenarios. if (Var->IsTemporary() || Var->IsFromScriptScope()) { DLRExpressionTree **TreeNode = NULL; if((TreeNode = m_VariablesMap->HashFind(Var)) && *TreeNode) { return *TreeNode; } if (Var->IsFromScriptScope()) { DLRExpressionTree *VarExprNode = m_ExprTreeGenerator->CreateVariableExpr( Var->GetEmittedName(), Var->GetType(), TargetType, Input->Loc ); // All variables need to be added to the map to ensure uniqueness. m_VariablesMap->HashAdd(Var, VarExprNode); return VarExprNode; } // Non-script scope variable should already exist from the outer block // since user lambdas in VB cannot result in creation of new locals. ThrowIfFalse(false); } } // fall back to the base implementation return ExpressionTreeSemantics<DLRExpressionTree>::ConvertSymbol( Input, Flags, TargetType ); }
DLRExpressionTree* ETSemanticsForLambdas::ConvertConstantValue ( ILTree::Expression* Input, ExpressionFlags Flags, Type* TargetType ) { // -----------------------------------Contract start------------------------------------ ThrowIfNull(Input); ThrowIfFalse(Input->bilop == SX_NOTHING || Input->bilop == SX_CNS_INT || Input->bilop == SX_CNS_FLT || Input->bilop == SX_CNS_DEC || Input->bilop == SX_CNS_STR || Input->bilop == SX_METATYPE); // // -----------------------------------Contract end------------------------------------ return ConvertConstantValueHelper( Input, Flags, TargetType, m_ExprTreeGenerator, GetFXSymbolProvider() ); }
/********** * Temporary &Temporarymanager::GetTemporary(Variable*) * Return the Temporary struct for the specified temporary ***********/ Temporary * TemporaryManager::GetTemporary(BCSYM_Variable *var) { ThrowIfNull(var); ThrowIfFalse(var->IsTemporary()); for (Temporary *cur = m_Temporaries; cur; cur = cur->Next) { if ( cur->Symbol == var ) { return cur; } } return NULL; }
void LineMarkerTable::AddOutOfProcBuildErrorLocation ( ErrorLocation* pErrorLocation ) { #if DEBUG bool inserted = m_outOfProcBuildErrorLocations.insert(pErrorLocation).second; ThrowIfFalse(inserted); #else m_outOfProcBuildErrorLocations.push_back(pErrorLocation); #endif pErrorLocation->m_locType = OutOfProcBuildErrorLoc; pErrorLocation->m_state = CS_NoState; // Set to a default value (not used for this error type) pErrorLocation->m_fForceRemove = false; // Set to a default value (not used for this error type) }
void LineMarkerTable::AddCodeBlock( TrackedCodeBlock *pblock, BCSYM *pSymbolForLocation ) { ThrowIfNull(pblock); CompilerIdeLock lock(m_lock); pblock->m_pSymbolForLocation = pSymbolForLocation; #if DEBUG bool inserted = m_trackedCodeBlockLocations.insert(pblock).second; ThrowIfFalse(inserted); #else m_trackedCodeBlockLocations.push_back(pblock); #endif pblock->m_locType = CodeBlockLoc; }
void LineMarkerTable::AddDeclLocation( _Out_ TrackedLocation *ploc, BCSYM *pSymbolForLocation ) { ThrowIfNull(ploc); CompilerIdeLock lock(m_lock); ploc->m_pSymbolForLocation = pSymbolForLocation; #if DEBUG bool inserted = m_declLocations.insert(ploc).second; ThrowIfFalse(inserted); #else m_declLocations.push_back(ploc); #endif ploc->m_locType = TrackedLoc; }
void LineMarkerTable::AddErrorLocation( _Out_ ErrorLocation * pErrorLocation, CompilationState state) { ThrowIfNull(pErrorLocation); CompilerIdeLock lock(m_lock); #if DEBUG bool inserted = m_errorLocations.insert(pErrorLocation).second; ThrowIfFalse(inserted); #else m_errorLocations.push_back(pErrorLocation); #endif pErrorLocation->m_locType = ErrorLoc; pErrorLocation->m_state = (state > CS_Bound) ? CS_Bound : CS_NoState; pErrorLocation->m_fForceRemove = false; }
DLRExpressionTree* ETSemanticsForLambdas::ConvertLambda ( ILTree::Expression* Input, ExpressionFlags Flags, Type* TargetType ) { ThrowIfNull(Input); ThrowIfFalse(Input->bilop == SX_LAMBDA); // Don't allow Sub lambdas to be converted to expression trees. if (Input->ResultType->IsDelegate()) { BCSYM_NamedRoot* proc = GetInvokeFromDelegate(Input->ResultType, m_Compiler); if(proc && proc->PProc() && (!proc->PProc()->GetType() || TypeHelpers::IsVoidType(proc->PProc()->GetType()))) { ReportErrorForExpressionTree( ERRID_StatementLambdaInExpressionTree, Input->Loc ); return NULL; } } return ExpressionTreeSemantics<DLRExpressionTree>::ConvertLambda(Input, Flags, TargetType); }
/********** *TemporaryManager::AllocateTemporary * Allocs temporary, looking in free stmt temp if appropriate ***********/ BCSYM_Variable * TemporaryManager::AllocateTemporary ( BCSYM *TypeRequested, LifetimeClass Lifetime, const Location *TextSpan, ILTree::ExecutableBlock *ExecutableBlock, _Out_opt_ bool *ExistingVariableReused ) { ThrowIfFalse(LifetimeLongLived != Lifetime || ExecutableBlock); // If it's a LongLived temporary a block must be provided ThrowIfFalse(LifetimeLongLived == Lifetime || !ExecutableBlock); // Likewise, if it's not LongLived Blocks cannot be provided if (ExistingVariableReused) { *ExistingVariableReused = false; } // Long lived temporaries are never reused, so don't bother searching if (Lifetime != LifetimeLongLived) { // Search for the first free temporary that matches the Type requested for (Temporary *Cursor = m_Temporaries; Cursor; Cursor = Cursor->Next) { VSASSERT(Cursor->Symbol, "this temporary doesn't have a symbol!"); if (!Cursor->IsCurrentlyInUse && !Cursor->IsLocked && Cursor->Lifetime == Lifetime && BCSYM::CompareReferencedTypes( TypeRequested->DigThroughNamedType(), (GenericBinding *)NULL, Cursor->Symbol->GetType()->DigThroughNamedType(), (GenericBinding *)NULL, &m_SymbolAllocator) == EQ_Match) { Cursor->UseCount++; // Temporaries with no lifetime are never "in use", i.e., they are always available from the pool. if (Cursor->Lifetime != LifetimeNone && Cursor->Lifetime != LifetimeDefaultValue) { Cursor->IsCurrentlyInUse = true; } if (ExistingVariableReused) { *ExistingVariableReused = true; } return Cursor->Symbol; } } } // If we get here, we didn't find a free temporary return DoAllocateTemporary( GetNextTemporaryName(TypeRequested, Lifetime, TextSpan), TypeRequested, Lifetime, TextSpan, ExecutableBlock); }
void Close(int inFD) { ThrowIfFalse(::CloseHandle((HANDLE)inFD)); }
DLRExpressionTree* ETSemanticsForLambdas::ConvertConstantValueHelper ( ILTree::Expression* Input, ExpressionFlags Flags, Type* TargetType, DLRTreeETGenerator *ExprTreeGenerator, FX::FXSymbolProvider *FXSymbolProvider ) { ThrowIfNull(Input); ThrowIfNull(ExprTreeGenerator); ThrowIfNull(FXSymbolProvider); DLRExpressionTree *Result = NULL; switch (Input->bilop) { case SX_NOTHING: Result = ExprTreeGenerator->CreateNothingConstantExpr( Input->ResultType, TargetType, Input->Loc ); break; case SX_CNS_INT: if (TypeHelpers::IsIntegralType(Input->ResultType)) { Result = ExprTreeGenerator->CreateIntegralConstantExpr( Input->AsIntegralConstantExpression().Value, Input->ResultType, TargetType, Input->Loc ); } else if (TypeHelpers::IsBooleanType(Input->ResultType)) { Result = ExprTreeGenerator->CreateBooleanConstantExpr( (bool)Input->AsIntegralConstantExpression().Value, TargetType, Input->Loc ); } else if (TypeHelpers::IsCharType(Input->ResultType)) { Result = ExprTreeGenerator->CreateCharConstantExpr( (WCHAR)Input->AsIntegralConstantExpression().Value, TargetType, Input->Loc ); } else if (TypeHelpers::IsDateType(Input->ResultType)) { Result = ExprTreeGenerator->CreateDateConstantExpr( Input->AsIntegralConstantExpression().Value, TargetType, Input->Loc ); } break; case SX_CNS_FLT: Result = ExprTreeGenerator->CreateFloatingPointConstantExpr( Input->AsFloatConstantExpression().Value, Input->ResultType, TargetType, Input->Loc ); break; case SX_CNS_DEC: Result = ExprTreeGenerator->CreateDecimalConstantExpr( Input->AsDecimalConstantExpression().Value, TargetType, Input->Loc ); break; case SX_CNS_STR: Result = ExprTreeGenerator->CreateStringConstantExpr( Input->AsStringConstant().Spelling, (unsigned int)Input->AsStringConstant().Length, //Cast on this line for 64bit compilation. Cast is safe because string will be truncated in the worst case. Only happens for 4GB+ strings. Input->ResultType, Input->Loc ); break; case SX_METATYPE: VSASSERT( Input->AsExpressionWithChildren().Left->bilop == SX_SYM || Input->AsExpressionWithChildren().Left->bilop == SX_NOTHING, "How did this metatype node get here?" ); ILTree::Expression *SymbolRef = Input->AsExpressionWithChildren().Left; if (SymbolRef->bilop == SX_NOTHING) { // Type reference ThrowIfFalse(FXSymbolProvider->GetTypeType() == Input->ResultType); Result = ExprTreeGenerator->CreateTypeRefExpr( SymbolRef->ResultType, TargetType, Input->Loc ); } else if (SymbolRef->AsSymbolReferenceExpression().Symbol->IsVariable()) { // Field reference ThrowIfFalse(FXSymbolProvider->GetFieldInfoType() == Input->ResultType); Result = ExprTreeGenerator->CreateFieldRefExpr( SymbolRef->AsSymbolReferenceExpression().Symbol->PVariable(), SymbolRef->AsSymbolReferenceExpression().GenericBindingContext->PGenericTypeBinding(), TargetType, Input->Loc ); } else { // Method reference ThrowIfFalse(FXSymbolProvider->GetMethodInfoType() == Input->ResultType || FXSymbolProvider->GetConstructorInfoType() == Input->ResultType); Result = ExprTreeGenerator->CreateMethodRefExpr( SymbolRef->AsSymbolReferenceExpression().Symbol->PProc(), SymbolRef->AsSymbolReferenceExpression().GenericBindingContext, TargetType, Input->Loc ); } break; } if (Result == NULL) { ASSERT(false,"[ETSemanticsForLambdas::ConvertConstant] non-constant expression unexpected"); ThrowIfFalse(false); } return Result; }
Type * GenericBindingArgumentIterator::Current() { ThrowIfFalse(m_nextIndex <= m_count && m_count); return m_ppArguments[m_nextIndex - 1]; }