Exemple #1
0
/**
 * On devices like wt41no and vc70 even if the sensor api is 
 * available, its still unsupported. Includes a present check as 
 * well. 
 * 
 * @author GXV738 (6/12/2013)
 * 
 * @return bool 
 */
bool screenorientation::CSensor::IsSupported()
{
	bool supported = false;
#if 0	
	if (IsPresent())
	{
		// Disable Auto rotation for VC70 and WT41N0
		//get the system OEM string
		TCHAR szPlatform[MAX_PATH+1] = {0};		
		SystemParametersInfo(SPI_GETOEMINFO, MAX_PATH, szPlatform, 0);
		
		for(UINT i=0; i<wcslen(szPlatform); i++)
			szPlatform[i] |= 0x20;
		
		if(wcsstr(szPlatform, L"wt41n0") || wcsstr(szPlatform, L"vc70"))
		{	
			LOG(INFO)+ "Device does not support IST/Sensor, autorotation will not be available";	
			supported = false;
		}
		else
		{
			supported = true;
		}
	}
#else
	supported = IsPresent();
#endif
	return supported;
}
Exemple #2
0
/// ParseDesignator - Parse a designator. Return null if current token is not a
/// designator.
///
///   [R601]:
///     designator :=
///         object-name
///      or array-element
///      or array-section
///      or coindexed-named-object
///      or complex-part-designator
///      or structure-component
///      or substring
///
/// FIXME: substring for a character array
ExprResult Parser::ParseDesignator(bool IsLvalue) {
  auto E = ParseNameOrCall();

  struct ScopedFlag {
    bool value;
    bool &dest;

    ScopedFlag(bool &flag) : dest(flag) {
      value = flag;
    }
    ~ScopedFlag() {
      dest = value;
    }
  };

  ScopedFlag Flag(DontResolveIdentifiers);
  if(DontResolveIdentifiersInSubExpressions)
    DontResolveIdentifiers = true;

  while(true) {
    if(!E.isUsable())
      break;
    if(IsPresent(tok::l_paren)) {
      auto EType = E.get()->getType();
      if(EType->isArrayType())
        E = ParseArraySubscript(E);
      else if(EType->isCharacterType())
        E = ParseSubstring(E);
      else {
        Diag.Report(Tok.getLocation(), diag::err_unexpected_lparen);
        return ExprError();
      }
    } else if(IsPresent(tok::percent)) {
      auto EType = E.get()->getType();
      if(EType->isRecordType())
        E = ParseStructureComponent(E);
      else {
        Diag.Report(Tok.getLocation(), diag::err_unexpected_percent);
        return ExprError();
      }
    } else if(IsPresent(tok::period)) {
      auto EType = E.get()->getType();
      if(EType->isRecordType())
        E = ParseStructureComponent(E);
      else {
        Diag.Report(Tok.getLocation(), diag::err_unexpected_period);
        return ExprError();
      }
    }
    else break;
  }

  return E;
}
//---------------------------------------------------------------------------
const bool SimState::IsPresent(const EnumCellType cellType) const
{
  if ( IsPresent(bloodStream,cellType) == false
    && IsPresent(boneMarrow ,cellType) == false
    && IsPresent(cellTissue ,cellType) == false
    && IsPresent(lymphNode  ,cellType) == false)
    return false;
  else
    return true;

}
Exemple #4
0
Parser::StmtResult Parser::ParseDoStmt() {
  auto Loc = ConsumeToken();
  auto CurStmtLoc = LocFirstStmtToken;

  ExprResult TerminalStmt;
  VarExpr *DoVar = nullptr;
  ExprResult E1, E2, E3;
  auto EqLoc = Loc;

  if(IsPresent(tok::int_literal_constant)) {
    TerminalStmt = ParseStatementLabelReference();
    if(TerminalStmt.isInvalid()) return StmtError();
  }
  bool isDo = ConsumeIfPresent(tok::comma);
  if(isDo && IsPresent(tok::kw_WHILE))
    return ParseDoWhileStmt(isDo);

  // the do var
  auto IDInfo = Tok.getIdentifierInfo();
  auto IDRange = getTokenRange();
  auto IDLoc = Tok.getLocation();
  if(!ExpectAndConsume(tok::identifier))
    goto error;

  EqLoc = getMaxLocationOfCurrentToken();
  if(Features.FixedForm && !isDo && IsPresent(tok::l_paren))
    return ReparseAmbiguousAssignmentStatement();
  if(!ExpectAndConsume(tok::equal))
    goto error;
  E1 = ParseExpectedFollowupExpression("=");
  if(E1.isInvalid()) goto error;
  if(Features.FixedForm && !isDo && Tok.isAtStartOfStatement())
    return ReparseAmbiguousAssignmentStatement(CurStmtLoc);
  if(!ExpectAndConsume(tok::comma)) goto error;
  E2 = ParseExpectedFollowupExpression(",");
  if(E2.isInvalid()) goto error;
  if(ConsumeIfPresent(tok::comma)) {
    E3 = ParseExpectedFollowupExpression(",");
    if(E3.isInvalid()) goto error;
  }

  if(auto VD = Actions.ExpectVarRefOrDeclImplicitVar(IDLoc, IDInfo))
    DoVar = VarExpr::Create(Context, IDRange, VD);
  return Actions.ActOnDoStmt(Context, Loc, EqLoc, TerminalStmt,
                             DoVar, E1, E2, E3, StmtConstructName, StmtLabel);
error:
  if(IDInfo) {
    if(auto VD = Actions.ExpectVarRefOrDeclImplicitVar(IDLoc, IDInfo))
      DoVar = VarExpr::Create(Context, IDRange, VD);
  }
  SkipUntilNextStatement();
  return Actions.ActOnDoStmt(Context, Loc, EqLoc, TerminalStmt,
                             DoVar, E1, E2, E3, StmtConstructName, StmtLabel);
}
Exemple #5
0
Parser::StmtResult Parser::ParseCaseStmt() {
  auto Loc = ConsumeToken();
  if(ConsumeIfPresent(tok::kw_DEFAULT)) {
    ParseTrailingConstructName();
    return Actions.ActOnCaseDefaultStmt(Context, Loc, StmtConstructName, StmtLabel);
  }

  SmallVector<Expr*, 8> Values;

  ExpectAndConsume(tok::l_paren);
  do {
    auto ColonLoc = Tok.getLocation();
    if(ConsumeIfPresent(tok::colon)) {
      auto E = ParseExpectedFollowupExpression(":");
      if(E.isInvalid()) goto error;
      if(E.isUsable())
        Values.push_back(RangeExpr::Create(Context, ColonLoc, nullptr, E.get()));
    } else {
      auto E = ParseExpectedExpression();
      if(E.isInvalid()) goto error;
      ColonLoc = Tok.getLocation();
      if(ConsumeIfPresent(tok::colon)) {
        if(!(IsPresent(tok::comma) || IsPresent(tok::r_paren))) {
          auto E2 = ParseExpectedFollowupExpression(":");
          if(E2.isInvalid()) goto error;
          if(E.isUsable() || E2.isUsable())
            Values.push_back(RangeExpr::Create(Context, ColonLoc, E.get(), E2.get()));
        } else {
          if(E.isUsable())
            Values.push_back(RangeExpr::Create(Context, ColonLoc, E.get(), nullptr));
        }
      } else {
        if(E.isUsable())
          Values.push_back(E.get());
      }
    }
  } while(ConsumeIfPresent(tok::comma));

  if(ExpectAndConsume(tok::r_paren)) {
    ParseTrailingConstructName();
  } else SkipUntilNextStatement();

  return Actions.ActOnCaseStmt(Context, Loc, Values, StmtConstructName, StmtLabel);

error:
  if(SkipUntil(tok::r_paren)) {
    ParseTrailingConstructName();
  } else SkipUntilNextStatement();
  return Actions.ActOnCaseStmt(Context, Loc, Values, StmtConstructName, StmtLabel);
}
/// ParseEQUIVALENCEStmt - Parse the EQUIVALENCE statement.
///
///   [R554]:
///     equivalence-stmt :=
///         EQUIVALENCE equivalence-set-list
Parser::StmtResult Parser::ParseEQUIVALENCEStmt() {
  // Check if this is an assignment.
  if (IsNextToken(tok::equal))
    return StmtResult();

  auto Loc = ConsumeToken();
  SmallVector<Stmt*, 8> StmtList;
  SmallVector<Expr*, 8> ObjectList;

  bool OuterError = false;
  while(true) {
    auto PartLoc = Tok.getLocation();
    if(!ExpectAndConsume(tok::l_paren)) {
      if(!SkipUntil(tok::l_paren)) {
        OuterError = true;
        break;
      }
    }

    ObjectList.clear();
    bool InnerError = false;
    do {
      auto E = ParseExpectedExpression();
      if(E.isInvalid()) {
        InnerError = true;
        break;
      } else if(E.isUsable())
        ObjectList.push_back(E.get());
    } while(ConsumeIfPresent(tok::comma));

    auto S = Actions.ActOnEQUIVALENCE(Context, Loc, PartLoc, ObjectList, nullptr);
    if(S.isUsable())
      StmtList.push_back(S.get());

    if(InnerError) {
      if(!SkipUntil(tok::r_paren, true, true)) {
        OuterError = true;
        break;
      }
    }
    if(!ExpectAndConsume(tok::r_paren)) {
      if(!SkipUntil(tok::r_paren)) {
        OuterError = true;
        break;
      }
    }

    if(ConsumeIfPresent(tok::comma)) continue;
    if(IsPresent(tok::l_paren)) {
      ExpectAndConsume(tok::comma);
      continue;
    }
    break;
  }

  if(OuterError) SkipUntilNextStatement();
  else ExpectStatementEnd();

  return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel);
}
/**
@return True if segment still exists, false if segment was deleted.
*/
TBool RPageArray::TSegment::Unlock(TSegment*& aSegment, TUint aCount)
	{
	__NK_ASSERT_DEBUG(MmuLock::IsHeld());

	TSegment* s = aSegment;
	__NK_ASSERT_DEBUG(s);

	TUint oldCounts = (TUint)__e32_atomic_add_ord32(&s->iCounts, (TUint32)-(TInt)aCount);
	__NK_ASSERT_DEBUG(oldCounts&KPageArraySegmentLockCountMask); // alloc count must have been non-zero before decrementing

#ifdef _DEBUG
	if((oldCounts&KPageArraySegmentLockCountMask)==aCount)
		{
		// check alloc count is consistent...
		TUint allocCount = s->iCounts>>KPageArraySegmentAllocCountShift;
		__NK_ASSERT_DEBUG(allocCount<=KPageArraySegmentSize);
		TUint realAllocCount = 0;
		TPhysAddr* p = s->iPages;
		TPhysAddr* pEnd = p+KPageArraySegmentSize;
		do
			{
			if(IsPresent(*p++))
				++realAllocCount;
			}
		while(p<pEnd);
		if(realAllocCount!=allocCount)
			{
			Kern::Printf("TSegment::Unlock alloc count missmatch %u!=%u",realAllocCount,allocCount);
			__NK_ASSERT_DEBUG(0);
			}
		}
void TypedNodeFactoryRegistry::Register(aafUID_t AUID, boost::shared_ptr<TypedNodeFactory> spFactory)
{
    //only add a factory into Map if it is not already present
    if(!IsPresent(AUID))
    {
        _Map[AUID] = spFactory;
    }
}
/// ParseCOMMONStmt - Parse the COMMON statement.
///
///   [5.5.2] R557:
///     common-stmt :=
///         COMMON #
///         # [ / [common-block-name] / ] common-block-object-list #
///         # [ [,] / [common-block-name / #
///         #   common-block-object-list ] ...
Parser::StmtResult Parser::ParseCOMMONStmt() {
  // Check if this is an assignment.
  if (IsNextToken(tok::equal))
    return StmtResult();

  auto Loc = ConsumeToken();
  SmallVector<Stmt*, 8> StmtList;
  SmallVector<Expr*, 8> ObjectList;

  SourceLocation BlockIDLoc;
  const IdentifierInfo *BlockID = nullptr;

  bool Error = false;
  do {
    if(ConsumeIfPresent(tok::slash)) {
      if(ConsumeIfPresent(tok::slash))
        BlockID = nullptr;
      else {
        BlockIDLoc = Tok.getLocation();
        BlockID = Tok.getIdentifierInfo();
        if(!ExpectAndConsume(tok::identifier)) {
          Error = true;
          break;
        }
        if(!ExpectAndConsume(tok::slash)) {
          Error = true;
          break;
        }
      }
    } else if(ConsumeIfPresent(tok::slashslash))
      BlockID = nullptr;

    auto IDLoc = Tok.getLocation();
    auto IDInfo = Tok.getIdentifierInfo();
    SmallVector<ArraySpec*, 8> Dimensions;

    if(!ExpectAndConsume(tok::identifier)) {
      Error = true;
      break;
    }
    if(IsPresent(tok::l_paren)) {
      if(ParseArraySpec(Dimensions)) {
        Error = true;
        break;
      }
    }

    Actions.ActOnCOMMON(Context, Loc, BlockIDLoc,
                        IDLoc, BlockID, IDInfo,
                        Dimensions);
  } while(ConsumeIfPresent(tok::comma));


  if(Error) SkipUntilNextStatement();
  else ExpectStatementEnd();

  return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel);
}
bool Parser::ParseObjectArraySpec(SourceLocation Loc, DeclSpec &DS) {
  if(IsPresent(tok::l_paren)) {
    SmallVector<ArraySpec*, 8> Dimensions;
    if (ParseArraySpec(Dimensions))
      return true;
    Actions.ActOnObjectArraySpec(Context, Loc, DS, Dimensions);
  }
  return false;
}
Exemple #11
0
Parser::StmtResult Parser::ParseGotoStmt() {
  SourceLocation Loc = ConsumeToken();
  if(ConsumeIfPresent(tok::l_paren)) {
    // computed goto.
    SmallVector<Expr*, 4> Targets;
    do {
      auto E = ParseStatementLabelReference();
      if(E.isInvalid()) break;
      Targets.append(1, E.get());
    } while(ConsumeIfPresent(tok::comma));
    ExprResult Operand;
    bool ParseOperand = true;
    if(!ExpectAndConsume(tok::r_paren)) {
      if(!SkipUntil(tok::r_paren)) ParseOperand = false;
    }
    if(ParseOperand) Operand = ParseExpectedExpression();
    return Actions.ActOnComputedGotoStmt(Context, Loc, Targets, Operand, StmtLabel);
  }

  auto Destination = ParseStatementLabelReference();
  if(Destination.isInvalid()) {
    if(!IsPresent(tok::identifier)) {
      Diag.Report(getExpectedLoc(), diag::err_expected_stmt_label_after)
          << "GO TO";
      return StmtError();
    }
    auto IDInfo = Tok.getIdentifierInfo();
    auto IDLoc = ConsumeToken();
    auto VD = Actions.ExpectVarRef(IDLoc, IDInfo);
    if(!VD) return StmtError();
    auto Var = VarExpr::Create(Context, IDLoc, VD);

    // Assigned goto
    SmallVector<Expr*, 4> AllowedValues;
    if(ConsumeIfPresent(tok::l_paren)) {
      do {
        auto E = ParseStatementLabelReference();
        if(E.isInvalid()) {
          Diag.Report(getExpectedLoc(), diag::err_expected_stmt_label);
          SkipUntilNextStatement();
          return Actions.ActOnAssignedGotoStmt(Context, Loc, Var, AllowedValues, StmtLabel);
        }
        AllowedValues.append(1, E.get());
      } while(ConsumeIfPresent(tok::comma));
      ExpectAndConsume(tok::r_paren);
    }
    return Actions.ActOnAssignedGotoStmt(Context, Loc, Var, AllowedValues, StmtLabel);
  }
  // Uncoditional goto
  return Actions.ActOnGotoStmt(Context, Loc, Destination, StmtLabel);
}
Exemple #12
0
ERTFToken RTFtime::WriteGroup(LPCSTR szGroupName, CRtfWriter* fp)
{
	if (IsPresent())
	{
		fp->StartGroup();
		fp->WriteTag(szGroupName);

		Write(fp);

		fp->EndGroup();
	}

	return rtfec_OK;
}
Exemple #13
0
ExprResult Parser::ParseRecursiveCallExpression(SourceRange IDRange) {
  auto Func = Actions.CurrentContextAsFunction();
  auto IDLoc = IDRange.Start;
  if(Func->isSubroutine()) {
    Diag.Report(IDLoc, diag::err_invalid_subroutine_use)
     << Func->getIdentifier() << getTokenRange(IDLoc);
    return ExprError();
  }
  if(!Actions.CheckRecursiveFunction(IDLoc))
    return ExprError();

  if(!IsPresent(tok::l_paren))
    return FunctionRefExpr::Create(Context, IDRange, Func);
  return ParseCallExpression(IDLoc, Func);
}
Exemple #14
0
// ParseExpression - Expressions are level-5 expressions optionally involving
// defined binary operators.
//
//   R722:
//     expr :=
//         [ expr defined-binary-op ] level-5-expr
//
//   R723:
//     defined-binary-op :=
//         . letter [ letter ] ... .
Parser::ExprResult Parser::ParseExpression() {
  ExprResult LHS = ParseLevel5Expr();
  if (LHS.isInvalid()) return LHS;

  if (!IsPresent(tok::defined_operator))
    return LHS;

  SourceLocation OpLoc = Tok.getLocation();
  IdentifierInfo *II = Tok.getIdentifierInfo();
  Lex();

  ExprResult RHS = ParseLevel5Expr();
  if (RHS.isInvalid()) return RHS;

  return DefinedBinaryOperatorExpr::Create(Context, OpLoc, LHS.take(), RHS.take(), II);
}
Exemple #15
0
// ParseLevel1Expr - Level-1 expressions are primaries optionally operated on by
// defined unary operators.
//
//   R702:
//     level-1-expr :=
//         [ defined-unary-op ] primary
//   R703:
//     defined-unary-op :=
//         . letter [ letter ] ... .
Parser::ExprResult Parser::ParseLevel1Expr() {
  SourceLocation OpLoc = Tok.getLocation();
  IdentifierInfo *II = 0;
 if (IsPresent(tok::defined_operator) && !IsNextToken(tok::l_paren)) {
    II = Tok.getIdentifierInfo();
    Lex();
  }

  ExprResult E = ParsePrimaryExpr();
  if (E.isInvalid()) return E;

  if (II)
    E = DefinedUnaryOperatorExpr::Create(Context, OpLoc, E.take(), II);

  return E;
}
Exemple #16
0
ERTFToken RTFtime::Write (CRtfWriter* fp)
{
	CRtfWriter_NestingCheck _cfp(this, fp);

	if (IsPresent())
	{
 		if (m_uiYear   != -1) fp->WriteTag("yr" , m_uiYear   );
 		if (m_uiMonth  != -1) fp->WriteTag("mo" , m_uiMonth  );
 		if (m_uiDay    != -1) fp->WriteTag("dy" , m_uiDay    );
 		if (m_uiHour   != -1) fp->WriteTag("hr" , m_uiHour   );
 		if (m_uiMinute != -1) fp->WriteTag("min", m_uiMinute );
 		if (m_uiSecond != -1) fp->WriteTag("sec", m_uiSecond );
	}

	return rtfec_OK;
}
void Parser::ParseEndTypeStmt() {
  if(Tok.isNot(tok::kw_ENDTYPE)) {
    Diag.Report(Tok.getLocation(), diag::err_expected_kw)
      << "end type";
    Diag.Report(cast<NamedDecl>(Actions.CurContext)->getLocation(), diag::note_matching)
      << "type";
    return;
  }

  auto Loc = ConsumeToken();
  if(IsPresent(tok::identifier)) {
    auto ID = Tok.getIdentifierInfo();
    Actions.ActOnENDTYPE(Context, Loc, ConsumeToken(), ID);
  } else
    Actions.ActOnENDTYPE(Context, Loc, Loc, nullptr);
  ExpectStatementEnd();
}
Exemple #18
0
void Adapter::json( json_object *entry ) const
{
  json_object_object_add( entry, "name", json_object_new_string( name.c_str( )));
  json_object_object_add( entry, "id",   json_object_new_int( GetKey( )));
  json_object_object_add( entry, "path", json_object_new_string( uid.c_str( )));
  json_object_object_add( entry, "present", json_object_new_int( IsPresent( )));
  json_object *a = json_object_new_array();

  for( std::vector<Frontend *>::const_iterator it = frontends.begin( ); it != frontends.end( ); it++ )
  {
    json_object *entry = json_object_new_object( );
    (*it)->json( entry );
    json_object_array_add( a, entry );
  }

  json_object_object_add( entry, "frontends", a );
}
boost::shared_ptr<TypedNodeFactory> TypedNodeFactoryRegistry::LookUp(AxClassDef& clsDef)
{
    //Find the Auid for the IAAFObject in question, if none exists look to its parent and continue
    //upwards until an Auid is found.  An exception will be thrown if no Auid is found at the
    //topmost level (i.e. no parent exists for IAAFObject).  This is not handled because it should
    //not happen in a correct file.
    aafUID_t Auid = clsDef.GetAUID();

    //Base Case:
    if(IsPresent(Auid))
    {
        return _Map[Auid];
    }
    //Recursive Case:
    AxClassDef clsParent(clsDef.GetParent());

    return LookUp(clsParent);//Use Tail Recursion to avoid potential problem of stack overflow
}
Exemple #20
0
bool Frontend::Open()
{
  if( fe )
    return true;
  if( !IsPresent( ))
  {
    LogWarn( "device not present '%s'", name.c_str( ));
    return false;
  }
  //Log( "Opening /dev/dvb/adapter%d/frontend%d", adapter_id, frontend_id );
  fe = dvb_fe_open2( adapter_id, frontend_id, 0, 0, TVD_Log );
  if( !fe )
  {
    LogError( "Error opening /dev/dvb/adapter%d/frontend%d", adapter_id, frontend_id );
    return false;
  }
  state = State_Opened;
  return true;
}
RPageArray::TSegment* RPageArray::TSegment::Delete(TSegment* aSegment)
	{
	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
	__NK_ASSERT_DEBUG(aSegment->iCounts==0);
#ifdef _DEBUG
	TPhysAddr* p = aSegment->iPages;
	TPhysAddr* pEnd = p+KPageArraySegmentSize;
	do
		{
		TPhysAddr a = *p++;
		if(IsPresent(a))
			{
			Kern::Printf("TSegment Delete with allocated pages! [%d]=0x%08x",p-aSegment->iPages-1,a);
			__NK_ASSERT_DEBUG(0);
			}
		}
	while(p<pEnd);
#endif
	PageSegmentAllocator.Free(aSegment);
	return 0;
	}
Exemple #22
0
ExprResult Parser::ParseArraySection(const char *PunctuationTok) {
  ExprResult LB, UB, Stride;
  bool Range = false;

  auto ColonLoc = Tok.getLocation();
  if(ConsumeIfPresent(tok::colon)) {
    Range = true;
    if(!IsPresent(tok::colon) && !IsPresent(tok::comma) && !IsPresent(tok::r_paren)) {
      UB = ParseExpectedFollowupExpression(":");
      if(UB.isInvalid())
        return UB;
    }
  } else {
    LB = ParseExpectedFollowupExpression(PunctuationTok);
    if(LB.isInvalid())
      return LB;
    ColonLoc = Tok.getLocation();
    if(ConsumeIfPresent(tok::colon)) {
      Range = true;
      if(!IsPresent(tok::colon) && !IsPresent(tok::comma) && !IsPresent(tok::r_paren)) {
        UB = ParseExpectedFollowupExpression(":");
        if(UB.isInvalid())
          return UB;
      }
    }
  }
  if(ConsumeIfPresent(tok::colon)) {
    Stride = ParseExpectedFollowupExpression(":");
    if(Stride.isInvalid())
      return Stride;
  }
  if(Stride.isUsable())
    return StridedRangeExpr::Create(Context, ColonLoc, LB.get(),
                                    UB.get(), Stride.get());
  if(Range)
    return RangeExpr::Create(Context, ColonLoc, LB.get(), UB.get());
  return LB;
}
Exemple #23
0
/// ParseSAVEStmt - Parse the SAVE statement.
///
///   [R543]:
///     save-stmt :=
///         SAVE [ [::] saved-entity-list ]
Parser::StmtResult Parser::ParseSAVEStmt() {
  // Check if this is an assignment.
  if (IsNextToken(tok::equal))
    return StmtResult();

  auto Loc = ConsumeToken();
  if(Tok.isAtStartOfStatement())
    return Actions.ActOnSAVE(Context, Loc, StmtLabel);

  bool IsSaveStmt = ConsumeIfPresent(tok::coloncolon);
  SmallVector<Stmt *,8> StmtList;
  bool ListParsedOk = true;

  auto IDLoc = Tok.getLocation();
  auto II = Tok.getIdentifierInfo();
  StmtResult Stmt;
  if(ConsumeIfPresent(tok::slash)) {
    IDLoc = Tok.getLocation();
    II = Tok.getIdentifierInfo();
    if(ExpectAndConsume(tok::identifier)) {
      if(!ExpectAndConsume(tok::slash))
        ListParsedOk = false;
      Stmt = Actions.ActOnSAVECommonBlock(Context, Loc, IDLoc, II);
    }
    else ListParsedOk = false;
  }
  else if(ExpectAndConsume(tok::identifier)) {
    if(!IsSaveStmt && Features.FixedForm && (IsPresent(tok::equal) || IsPresent(tok::l_paren)))
      return ReparseAmbiguousAssignmentStatement();
    Stmt = Actions.ActOnSAVE(Context, Loc, IDLoc, II, nullptr);
  } else ListParsedOk = false;

  if(Stmt.isUsable())
    StmtList.push_back(Stmt.get());
  if(ListParsedOk) {
    while(ConsumeIfPresent(tok::comma)) {
      IDLoc = Tok.getLocation();
      II = Tok.getIdentifierInfo();
      if(ConsumeIfPresent(tok::slash)) {
        IDLoc = Tok.getLocation();
        II = Tok.getIdentifierInfo();
        if(!ExpectAndConsume(tok::identifier)) {
          ListParsedOk = false;
          break;
        }
        if(!ExpectAndConsume(tok::slash)) {
          ListParsedOk = false;
          break;
        }
        Stmt = Actions.ActOnSAVECommonBlock(Context, Loc, IDLoc, II);
      }
      else if(ExpectAndConsume(tok::identifier))
        Stmt = Actions.ActOnSAVE(Context, Loc, IDLoc, II, nullptr);
      else {
        ListParsedOk = false;
        break;
      }

      if(Stmt.isUsable())
        StmtList.push_back(Stmt.get());
    }
  }

  if(ListParsedOk) ExpectStatementEnd();
  else SkipUntilNextStatement();

  return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel);
}
bool ImageDescriptor::LoadFromFile(FileSpecifier& File, int ImgMode, int flags, int actual_width, int actual_height, int maxSize)
{
	if (flags & ImageLoader_ImageIsAlreadyPremultiplied)
		PremultipliedAlpha = true;

	// Don't load opacity if there is no color component:
	switch(ImgMode) {
		case ImageLoader_Colors:
			if (LoadDDSFromFile(File, flags, actual_width, actual_height, maxSize)) return true;
			break;
		
		case ImageLoader_Opacity:
			if (!IsPresent())
				return false;
			break;
		
		default:
			vassert(false, csprintf(temporary,"Bad image mode for loader: %d",ImgMode));
	}

	// Load image to surface
#ifndef SDL_RFORK_HACK
#ifdef HAVE_SDL_IMAGE
	SDL_Surface *s = IMG_Load(File.GetPath());
#else
	SDL_Surface *s = SDL_LoadBMP(File.GetPath());
#endif
#else
SDL_Surface *s = NULL;
#endif
	if (s == NULL)
		return false;

	// Get image dimensions and set its size
	int Width = s->w, Height = s->h;
	int OriginalWidth = (actual_width) ? actual_width : Width;
	int OriginalHeight = (actual_height) ? actual_height : Height;
	if (flags & ImageLoader_ResizeToPowersOfTwo) {
		Width = NextPowerOfTwo(Width);
		Height = NextPowerOfTwo(Height);
	}
	switch (ImgMode) {
		case ImageLoader_Colors:
			Resize(Width, Height);
			VScale = ((double) OriginalWidth / (double) Width);
			UScale = ((double) OriginalHeight / (double) Height);
			MipMapCount = 0;
			break;

		case ImageLoader_Opacity:
			// If the wrong size, then bug out
			if (Width != this->Width || Height != this->Height || ((double) OriginalWidth / Width != VScale || ((double) OriginalHeight / Height != UScale))) {
				SDL_FreeSurface(s);
				return false;
			}
			break;
	}

	// Convert to 32-bit OpenGL-friendly RGBA surface
#ifdef ALEPHONE_LITTLE_ENDIAN
	SDL_Surface *rgba = SDL_CreateRGBSurface(SDL_SWSURFACE, Width, Height, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#else
	SDL_Surface *rgba = SDL_CreateRGBSurface(SDL_SWSURFACE, Width, Height, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#endif
	if (rgba == NULL) {
		SDL_FreeSurface(s);
		return false;
	}

	SDL_SetAlpha(s, 0, 0xff); // disable SDL_SRCALPHA
	SDL_BlitSurface(s, NULL, rgba, NULL);
	SDL_FreeSurface(s);

	// Convert surface to RGBA texture
	switch (ImgMode) {
		case ImageLoader_Colors:
			memcpy(GetPixelBasePtr(), rgba->pixels, Width * Height * 4);
			break;

		case ImageLoader_Opacity: {
			uint8 *p = (uint8 *)rgba->pixels;
			uint8 *q = (uint8 *)GetPixelBasePtr();
			for (int h=0; h<Height; h++) {
				for (int w=0; w<Width; w++) {
					// RGB to greyscale value, and then to the opacity
					float Red = float(*p++);
					float Green = float(*p++);
					float Blue = float(*p++);
					p++;
					float Opacity = (Red + Green + Blue) / 3.0F;
					q[3] = PIN(int(Opacity + 0.5), 0, 255);
					q += 4;
				}
			}
			break;
		}
	}

	SDL_FreeSurface(rgba);
	return true;
}
Exemple #25
0
void Frontend::Run( )
{
  Channel *channel;
  while( up )
  {
    if( !IsPresent( ))
    {
      sleep( 1 );
      continue;
    }

    // FIXME: combine activity lock with frontend, port and other mutexes
    bool idle = true;
    switch( state )
    {
      case State_Ready:
        {
          activity_lock.Lock( );
          Activity_Scan *act = new Activity_Scan( );
          act->SetFrontend( this );
          for( std::map<int, Port *>::const_iterator it = ports.begin( ); it != ports.end( ); it++ )
          {
            if( it->second->Scan( *act ))
            {
              activity_lock.Unlock( );
              act->Run( );
              idle = false;
              break;
            }
          }
          delete act;

          if( !idle )
            break;
          activity_lock.Unlock( );
          state = State_ScanEPG;
        }
        break;

      case State_ScanEPG:
        {
          activity_lock.Lock( );
          Activity_UpdateEPG *act = new Activity_UpdateEPG( );
          act->SetFrontend( this );
          for( std::map<int, Port *>::const_iterator it = ports.begin( ); it != ports.end( ); it++ )
          {
            if( it->second->ScanEPG( *act ))
            {
              activity_lock.Unlock( );
              act->Run( );
              idle = false;
              break;
            }
          }
          delete act;
          if( !idle )
            break;
          activity_lock.Unlock( );
          state = State_Ready;
        }
        break;
    }

    if( idle )
      sleep( 1 );
  }
}
Exemple #26
0
bool Frontend::Tune( Transponder &t )
{
  if( !IsPresent( ))
  {
    LogWarn( "device not present '%s'", name.c_str( ));
    return false;
  }
  Lock( );
  if( transponder )
  {
    if( transponder == &t )
    {
      usecount++;
      Unlock( );
      return true;
    }
    Log( "Frontend busy" );
    Unlock( );
    return false;
  }

  if( !Open( ))
  {
    Unlock( );
    return false;
  }

  state = State_Tuning;
  transponder = &t;
  usecount++;
  Unlock( );

  t.SetState( Transponder::State_Tuning );
  Log( "Tuning %s", t.toString( ).c_str( ));

  uint8_t signal, noise;
  LogWarn( "dvb_set_compat_delivery_system %d", t.GetDelSys( ));
  int r = dvb_set_compat_delivery_system( fe, t.GetDelSys( ));
  if( r != 0 )
  {
    LogError( "dvb_set_compat_delivery_system return %d", r );
    goto fail;
  }

  SetTuneParams( t );
  t.GetParams( fe );
  LogWarn( "dvb_estimate_freq_shift");
  dvb_estimate_freq_shift( fe );

  r = dvb_fe_set_parms( fe );
  if( r != 0 )
  {
    LogError( "dvb_fe_set_parms failed with %d.", r );
    dvb_fe_prt_parms( fe );
    goto fail;
  }
  dvb_fe_prt_parms( fe );

	/* As the DVB core emulates it, better to always use auto */
	dvb_fe_store_parm(fe, DTV_INVERSION, INVERSION_AUTO);

	uint32_t freq;
	dvb_fe_retrieve_parm(fe, DTV_FREQUENCY, &freq);
	dvb_fe_prt_parms(fe);

  if( !GetLockStatus( signal, noise, tune_timeout ))
  {
    LogError( "Tuning failed" );
    goto fail;
  }

  t.SetState( Transponder::State_Tuned );
  t.SetSignal( signal, noise );
  return true;

fail:
  t.SetState( Transponder::State_TuningFailed );
  t.SaveConfig( );
  Release( );
  return false;
}
/***************************************************************************
 ** ReadSites --
 **    This function asks the user for the name of the data
 ** file to be used, opens it, reads the website Addresses and
 ** sorts them. The totals are then computed and the tables printed using
 ** other functions within this one.
 **      Inputs: None
 **      Outputs: 4 arrays fll of websites and printed results.
 ***************************************************************************/
void ReadSites()
{
   FILE *ifp;
   char filename[SIZE] = "cat";
   char temp[SIZE] = "dog";
   int j = 0;

   /*The  four arrays are declared*/
   WEBSITE t, comSites[SIZE], govSites[SIZE], eduSites[SIZE], netSites[SIZE];

   int TotalNonUniqueSites = 0, TotalUniqueSites = 0, TotalTimeLogged = 0;
   int TotalFunSites = 0, TotalSearchSites = 0, TotalEducationSites = 0;
   int  TotalNewsSites = 0, *pTotalNewsSites, *pTotalNonUniqueSites;
   int *pTotalUniqueSites, *pTotalTimeLogged, *pTotalFunSites; 
   int *pTotalSearchSites, *pTotalEducationSites;

   /*The pointers are set to point to the their corresponding values*/
   pTotalNonUniqueSites = &TotalNonUniqueSites;
   pTotalUniqueSites = &TotalUniqueSites;
   pTotalTimeLogged = &TotalTimeLogged;
   pTotalFunSites = &TotalFunSites;
   pTotalSearchSites = &TotalSearchSites;
   pTotalEducationSites = &TotalEducationSites;
   pTotalNewsSites = &TotalNewsSites;

   /*The are filled with dummy values*/
   FillArray(comSites);
   FillArray(netSites);
   FillArray(eduSites);
   FillArray(govSites);

   /*Asks the user for the file name*/
   fprintf(stdout, "\nPlease enter the file name: ");
   fscanf(stdin, "%s", filename);
   ifp = fopen(filename, "r");

   /*If the file cannot exit and give error message*/
   if(ifp == NULL)
   {
      fprintf(stderr, "The file could not be opened.");
      exit(-1);
   }

   /*Scans every thing in the file until it reaches the end*/
   while(fscanf(ifp, "%s %s %d", temp, t.siteType, &t.seconds) != EOF)
     {
	/*Breaks the string temp  into access code, domain name*/
	/* and domain ending and stores the in the temporary structure*/
	t.webAddress = CreateAddress(temp);
	
	/*Depending on the first letter of the domain ending, stores*/
	/*them into the appropriate array*/
	if(t.webAddress.domainEnding[0] == 'c')
	{
	   /*Finds the index of wherever the website is supposed to go*/
	   j = IsPresent(comSites, t);
	   
	   /*Stores the website in the proper location*/
	   comSites[j].webAddress = t.webAddress;
	   
	   /*Stores the siteType in the corresponding location*/
	   strcpy(comSites[j].siteType, t.siteType);
	   
	   /*Adds the number of hits and the seconds*/
	   comSites[j].hits += 1;
	   comSites[j].seconds += t.seconds;
	} 
	else if(t.webAddress.domainEnding[0] == 'g')
	{
	   j = IsPresent(govSites, t);
	   
	   govSites[j].webAddress = t.webAddress;
	   strcpy(govSites[j].siteType, t.siteType);
	   govSites[j].hits += 1;
	   govSites[j].seconds += t.seconds;
	}
	else if(t.webAddress.domainEnding[0] == 'n')
	{
	   j = IsPresent(netSites, t);
	   
	   netSites[j].webAddress = t.webAddress;
	   strcpy(netSites[j].siteType, t.siteType);
	   netSites[j].hits += 1;
	   netSites[j].seconds += t.seconds;
	 }
       else
	 {
	   j = IsPresent(eduSites, t);
	   
	   eduSites[j].webAddress = t.webAddress;
	   strcpy(eduSites[j].siteType, t.siteType);
	   eduSites[j].hits += 1;
	   eduSites[j].seconds += t.seconds;
	 } 
     }  
   
   /*Sorts the arrays*/
   SortArray(eduSites, ArrayLength(eduSites));
   SortArray(govSites, ArrayLength(govSites));
   SortArray(comSites, ArrayLength(comSites));
   SortArray(netSites, ArrayLength(netSites));
   
   /*Computes the totals using data from all the arrays*/
   ComputeTotals(comSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(eduSites, pTotalUniqueSites, pTotalNonUniqueSites, 
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(netSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(govSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   /*Prints the results of the read*/
   PrintTable(comSites, netSites, eduSites, govSites);
   
   /*Caclulates the percentages and prints them*/
   CalcStats(TotalUniqueSites, TotalFunSites, TotalSearchSites,
	     TotalNewsSites, TotalEducationSites, TotalTimeLogged,
	     TotalNonUniqueSites);
   
   return;
}
Exemple #28
0
 bool                          IsPresent(Address::SharedPtr spAddr) const { return IsPresent(*spAddr.get()); }
Exemple #29
0
// ParsePrimaryExpr - Parse a primary expression.
//
//   [R701]:
//     primary :=
//         constant
//      or designator
//      or array-constructor
//      or structure-constructor
//      or function-reference
//      or type-param-inquiry
//      or type-param-name
//      or ( expr )
Parser::ExprResult Parser::ParsePrimaryExpr(bool IsLvalue) {
  ExprResult E;
  SourceLocation Loc = Tok.getLocation();

  // FIXME: Add rest of the primary expressions.
  switch (Tok.getKind()) {
  default:
    if (isTokenIdentifier())
      goto possible_keyword_as_ident;
    Diag.Report(getExpectedLoc(), diag::err_expected_expression);
    return ExprError();
  case tok::error:
    Lex();
    return ExprError();
  case tok::l_paren: {
    ConsumeParen();

    E = ParseExpression();
    // complex constant.
    if(ConsumeIfPresent(tok::comma)) {
      if(E.isInvalid()) return E;
      auto ImPart = ParseExpectedFollowupExpression(",");
      if(ImPart.isInvalid()) return ImPart;
      E = Actions.ActOnComplexConstantExpr(Context, Loc,
                                           getMaxLocationOfCurrentToken(),
                                           E, ImPart);
    }

    ExpectAndConsume(tok::r_paren, 0, "", tok::r_paren);
    break;
  }
  case tok::l_parenslash : {
    return ParseArrayConstructor();
    break;
  }
  case tok::logical_literal_constant: {
    std::string NumStr;
    CleanLiteral(Tok, NumStr);

    StringRef Data(NumStr);
    std::pair<StringRef, StringRef> StrPair = Data.split('_');
    E = LogicalConstantExpr::Create(Context, getTokenRange(),
                                    StrPair.first, Context.LogicalTy);
    SetKindSelector(cast<ConstantExpr>(E.get()), StrPair.second);
    ConsumeToken();
    break;
  }
  case tok::binary_boz_constant:
  case tok::octal_boz_constant:
  case tok::hex_boz_constant: {
    std::string NumStr;
    CleanLiteral(Tok, NumStr);

    StringRef Data(NumStr);
    std::pair<StringRef, StringRef> StrPair = Data.split('_');
    E = BOZConstantExpr::Create(Context, Loc,
                                getMaxLocationOfCurrentToken(),
                                StrPair.first);
    SetKindSelector(cast<ConstantExpr>(E.get()), StrPair.second);
    ConsumeToken();
    break;
  }
  case tok::char_literal_constant: {
    std::string NumStr;
    CleanLiteral(Tok, NumStr);
    E = CharacterConstantExpr::Create(Context, getTokenRange(),
                                      StringRef(NumStr), Context.CharacterTy);
    ConsumeToken();
    // Possible substring
    if(IsPresent(tok::l_paren))
      return ParseSubstring(E);
    break;
  }
  case tok::int_literal_constant: {
    std::string NumStr;
    CleanLiteral(Tok, NumStr);

    StringRef Data(NumStr);
    std::pair<StringRef, StringRef> StrPair = Data.split('_');
    E = IntegerConstantExpr::Create(Context, getTokenRange(),
                                    StrPair.first);
    SetKindSelector(cast<ConstantExpr>(E.get()), StrPair.second);

    Lex();
    break;
  }
  case tok::real_literal_constant: {
    std::string NumStr;
    CleanLiteral(Tok, NumStr);

    StringRef Data(NumStr);
    std::pair<StringRef, StringRef> StrPair = Data.split('_');
    E = RealConstantExpr::Create(Context, getTokenRange(),
                                 NumStr, Context.RealTy);
    SetKindSelector(cast<ConstantExpr>(E.get()), StrPair.second);
    ConsumeToken();
    break;
  }
  case tok::double_precision_literal_constant: {
    std::string NumStr;
    CleanLiteral(Tok, NumStr);
    // Replace the d/D exponent into e exponent
    for(size_t I = 0, Len = NumStr.length(); I < Len; ++I) {
      if(NumStr[I] == 'd' || NumStr[I] == 'D') {
        NumStr[I] = 'e';
        break;
      } else if(NumStr[I] == '_') break;
    }

    StringRef Data(NumStr);
    std::pair<StringRef, StringRef> StrPair = Data.split('_');
    E = RealConstantExpr::Create(Context, getTokenRange(),
                                 NumStr, Context.DoublePrecisionTy);
    SetKindSelector(cast<ConstantExpr>(E.get()), StrPair.second);
    ConsumeToken();
    break;
  }
  case tok::identifier:
    possible_keyword_as_ident:
    E = Parser::ParseDesignator(IsLvalue);
    if (E.isInvalid()) return E;
    break;
  case tok::minus:
    Lex();
    E = Parser::ParsePrimaryExpr();
    if (E.isInvalid()) return E;
    E = Actions.ActOnUnaryExpr(Context, Loc, UnaryExpr::Minus, E);
    break;
  case tok::plus:
    Lex();
    E = Parser::ParsePrimaryExpr();
    if (E.isInvalid()) return E;
    E = Actions.ActOnUnaryExpr(Context, Loc, UnaryExpr::Plus, E);
    break;
  }

  return E;
}
Exemple #30
0
/// ParseNameOrCall - Parse a name or a call expression
ExprResult Parser::ParseNameOrCall() {
  auto IDInfo = Tok.getIdentifierInfo();
  assert(IDInfo && "Token isn't an identifier");
  auto IDRange = getTokenRange();
  auto IDLoc = ConsumeToken();

  if(DontResolveIdentifiers)
    return UnresolvedIdentifierExpr::Create(Context,
                                            IDRange, IDInfo);

  // [R504]:
  //   object-name :=
  //       name
  auto Declaration = Actions.ResolveIdentifier(IDInfo);
  if(!Declaration) {
    if(IsPresent(tok::l_paren))
      Declaration = Actions.ActOnImplicitFunctionDecl(Context, IDLoc, IDInfo);
    else
      Declaration = Actions.ActOnImplicitEntityDecl(Context, IDLoc, IDInfo);
    if(!Declaration)
      return ExprError();
  } else {
    // INTEGER f
    // X = f(10) <-- implicit function declaration.
    if(IsPresent(tok::l_paren))
      Declaration = Actions.ActOnPossibleImplicitFunctionDecl(Context, IDLoc, IDInfo, Declaration);
  }

  if(VarDecl *VD = dyn_cast<VarDecl>(Declaration)) {
    // FIXME: function returing array
    if(IsPresent(tok::l_paren) &&
       VD->isFunctionResult() && isa<FunctionDecl>(Actions.CurContext)) {
      // FIXME: accessing function results from inner recursive functions
      return ParseRecursiveCallExpression(IDRange);
    }
    // the VarDecl is obtained from a NamedDecl which does not have a type
    // apply implicit typing rules in case VD does not have a type
    // FIXME: there should be a way to avoid re-applying the implicit rules
    // by returning a VarDecl instead of a NamedDecl when looking up a name in
    // the scope
    if (VD->getType().isNull()) Actions.ApplyImplicitRulesToArgument(VD,IDRange);
    return VarExpr::Create(Context, IDRange, VD);
  }
  else if(IntrinsicFunctionDecl *IFunc = dyn_cast<IntrinsicFunctionDecl>(Declaration)) {
    SmallVector<Expr*, 8> Arguments;
    SourceLocation RParenLoc = Tok.getLocation();
    auto Result = ParseFunctionCallArgumentList(Arguments, RParenLoc);
    if(Result.isInvalid())
      return ExprError();
    return Actions.ActOnIntrinsicFunctionCallExpr(Context, IDLoc, IFunc, Arguments);
  } else if(FunctionDecl *Func = dyn_cast<FunctionDecl>(Declaration)) {
    // FIXME: allow subroutines, but errors in sema
    if(!IsPresent(tok::l_paren))
      return FunctionRefExpr::Create(Context, IDRange, Func);
    if(!Func->isSubroutine()) {
      return ParseCallExpression(IDLoc, Func);
    }
  } else if(isa<SelfDecl>(Declaration) && isa<FunctionDecl>(Actions.CurContext))
    return ParseRecursiveCallExpression(IDRange);
  else if(auto Record = dyn_cast<RecordDecl>(Declaration))
    return ParseTypeConstructor(IDLoc, Record);
  Diag.Report(IDLoc, diag::err_expected_var);
  return ExprError();
}