Changeset b91bfde for src/AST


Ignore:
Timestamp:
Apr 12, 2021, 11:53:30 AM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
73f4d08
Parents:
ecfd758
Message:

Added and used some helpers. The widely useful one is a from_string helper for constants.

Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/AST/Expr.cpp

    recfd758 rb91bfde  
    260260}
    261261
     262ConstantExpr * ConstantExpr::from_string( const CodeLocation & loc, const std::string & str ) {
     263        const Type * charType = new BasicType( BasicType::Char );
     264        // Adjust the length of the string for the terminator.
     265        const Expr * strSize = from_ulong( loc, str.size() + 1 );
     266        const Type * strType = new ArrayType( charType, strSize, FixedLen, StaticDim );
     267        const std::string strValue = "\"" + str + "\"";
     268        return new ConstantExpr( loc, strType, strValue, std::nullopt );
     269}
     270
    262271ConstantExpr * ConstantExpr::null( const CodeLocation & loc, const Type * ptrType ) {
    263272        return new ConstantExpr{
  • TabularUnified src/AST/Expr.hpp

    recfd758 rb91bfde  
    438438        long long int intValue() const;
    439439
    440         /// generates a boolean constant of the given bool
     440        /// Generates a boolean constant of the given bool.
    441441        static ConstantExpr * from_bool( const CodeLocation & loc, bool b );
    442         /// generates an integer constant of the given int
     442        /// Generates an integer constant of the given int.
    443443        static ConstantExpr * from_int( const CodeLocation & loc, int i );
    444         /// generates an integer constant of the given unsigned long int
     444        /// Generates an integer constant of the given unsigned long int.
    445445        static ConstantExpr * from_ulong( const CodeLocation & loc, unsigned long i );
    446         /// generates a null pointer value for the given type. void * if omitted.
     446        /// Generates a string constant from the given string (char type, unquoted string).
     447        static ConstantExpr * from_string( const CodeLocation & loc, const std::string & string );
     448        /// Generates a null pointer value for the given type. void * if omitted.
    447449        static ConstantExpr * null( const CodeLocation & loc, const Type * ptrType = nullptr );
    448450
Note: See TracChangeset for help on using the changeset viewer.