Exemple #1
0
// Expand the concept by substituting the template arguments
// throughthe concept's definition and normalizing the result.
//
// TODO: Memoize the expansions.
Cons&
expand(Context& cxt, Concept_cons& c)
{
  Concept_decl& d = c.declaration();
  Decl_list& tparms = d.parameters();
  Term_list& targs = c.arguments();

  // NOTE: Template arguments must have been checked (in kind?)
  // prior to the formation of the constraint. It's should be
  // a semantic requirement of the original check expression.
  Substitution sub(tparms, targs);

  Def& def = d.definition();
  if (Expression_def* expr = as<Expression_def>(&def))
    return expand_expr(cxt, *expr, sub);
  if (Concept_def* body = as<Concept_def>(&def))
    return expand_def(cxt, *body, sub);
  banjo_unhandled_case(def);
}
Exemple #2
0
int preprocess_getc(void)
{
   int result = 0;
   int backslash = 0;

   do
   {
      int c;
      int haddigit;

      result = read_char();

      if (result != 0)
      {
         break;
      }

      c = Get();
      if (c == -1)
      {
         break;
      }
      if (backslash)
      {
         maybe_print(c);
         backslash = 0;
         continue;
      }
      if (!incldep && (isdigit((int) c) || (c == '.')))
      {
         haddigit = 0;
         while (isdigit((int) c) || (c == '.'))
         {
            haddigit |= isdigit((int) c);
            maybe_print(c);
            c = Get();
            if (c == -1)
            {
               return 0;
            }
         }
         if (haddigit && ((c == 'e') || (c == 'E')))
         {
            maybe_print(c);
            c = Get();
            if (c == -1)
            {
               return 0;
            }
            while (isdigit((int) c))
            {
               maybe_print(c);
               c = Get();
               if (c == -1)
               {
                  return 0;
               }
            }
         }
         Push(c);
         continue;
      }
      if (quote)
      {
         if (c == '\\')
         {
            maybe_print(c);
            backslash = 1;
            continue;
         }
         else if ((c == quote) || (c == '\n'))
         {
            maybe_print(c);
            quote = 0;
            continue;
         }
         else
         {
            maybe_print(c);
            continue;
         }
      }
      if (c == '\\') /* this weirdness is Reiser semantics.... */
      {
         backslash = 1;
         maybe_print(c);
         continue;
      }
      if ((c == '\'') || (c == '"'))
      {
         quote = c;
         maybe_print(c);
      }
      else if (linefirst && (c == '#'))
      {
         do_sharp();
      }
      else if (do_at_ctrls && (c == '@'))
      {
         do_at();
      }
      else if (! incldep)
      {
         if (isbsymchar(c) && !in_false_if())
         {
            char *cp;
            DEF *d;
            cp = init_accum();
            while (issymchar(c))
            {
               accum_char(cp, c);
               c = Get();
               if (c == -1)
               {
                  return 0;
               }
            }
            Push(c);
            cp = accum_result(cp);
#ifdef DEBUG_MAIN

            if (debugging)
            {
               outputs("<word:");
               outputs(cp);
               outputs(">");
            }
#endif
            d = find_def(cp);
            if (d)
            {
               expand_def(d);
            }
            else
            {
               for (;*cp;cp++)
               {
                  maybe_print(*cp);
               }
            }
         }
         else if (c == '/')
         {
            int d;
            d = Get();
            if (d == -1)
            {
               return 0;
            }
            if (d == '*')
            {
               d = '\0';
               if (keep_comments)
               {
                  maybe_print('/');
                  maybe_print('*');
               }
               do
               {
                  c = d;
                  d = Get();
                  if (d == -1)
                  {
                     return 0;
                  }
                  if ((d == '\n') || keep_comments)
                  {
                     maybe_print(d);
                  }
               }
               while ((c != '*') || (d != '/'));
            }
            else if (d == '/')
            {
               if (keep_comments)
               {
                  maybe_print('/');
                  maybe_print('/');
               }
               do
               {
                  c = Get();
                  if (c == -1)
                  {
                     return 0;
                  }
                  if ((c == '\n') || keep_comments)
                  {
                     maybe_print(c);
                  }
               }
               while (c != '\n');
            }
            else
            {
               Push(d);
               maybe_print(c);
            }
         }
         else
         {
            maybe_print(c);
         }
      }
   } while (result == 0);

   return result;
}